liaofei 2 лет назад
Родитель
Сommit
01afb0f6e7

+ 37 - 0
crmeb/app/adminapi/controller/v1/order/StoreOrder.php

@@ -766,4 +766,41 @@ class StoreOrder extends AuthController
         return app('json')->success(400121);
     }
 
+    /**
+     * 获取快递信息
+     * @param ServeServices $services
+     * @return \think\Response
+     * @author 等风来
+     * @email 136327134@qq.com
+     * @date 2023/5/15
+     */
+    public function getKuaidiComs(ServeServices $services)
+    {
+        return app('json')->success($services->express()->getKuaidiComs());
+    }
+
+    /**
+     * 取消商家寄件
+     * @param $id
+     * @return \think\Response
+     * @author 等风来
+     * @email 136327134@qq.com
+     * @date 2023/5/15
+     */
+    public function shipmentCancelOrder($id)
+    {
+        if (!$id) {
+            return app('json')->fail('缺少参数');
+        }
+
+        $msg = $this->request->post('msg', '');
+        if (!$msg) {
+            return app('json')->fail('请填写取消寄件原因');
+        }
+        if ($this->services->shipmentCancelOrder((int)$id, $msg)) {
+            return app('json')->success('取消成功');
+        } else {
+            return app('json')->fail('取消失败');
+        }
+    }
 }

+ 17 - 0
crmeb/app/adminapi/controller/v1/serve/Export.php

@@ -80,4 +80,21 @@ class Export extends AuthController
         }
         return app('json')->success(['isOpen' => $res]);
     }
+
+    /**
+     * @param ServeServices $services
+     * @return \think\Response
+     * @author 等风来
+     * @email 136327134@qq.com
+     * @date 2023/5/15
+     */
+    public function getShipmentOrderList(ServeServices $services)
+    {
+        $where = $this->request->getMore([
+            ['page', 1],
+            ['limit', 10],
+        ]);
+
+        return app('json')->success($services->express()->getShipmentOrderList($where));
+    }
 }

+ 4 - 0
crmeb/app/adminapi/route/order.php

@@ -14,6 +14,10 @@ use think\facade\Route;
  * 订单路由
  */
 Route::group('order', function () {
+    //获取快递信息
+    Route::get('kuaidi_coms', 'v1.order.StoreOrder/getKuaidiComs')->option(['real_name' => '获取快递信息']);
+    //取消商家寄件
+    Route::post('shipment_cancel_order/:id', 'v1.order.StoreOrder/shipmentCancelOrder')->option(['real_name' => '取消商家寄件']);
     //打印订单
     Route::get('print/:id', 'v1.order.StoreOrder/order_print')->name('StoreOrderPrint')->option(['real_name' => '打印订单']);
     //订单列表

+ 47 - 0
crmeb/app/services/order/StoreOrderDeliveryServices.php

@@ -473,6 +473,7 @@ class StoreOrderDeliveryServices extends BaseServices
         if (!$data['delivery_name']) {
             throw new AdminException(400007);
         }
+        $dump = [];
         $data['delivery_type'] = 'express';
         if ($data['express_record_type'] == 2) {//电子面单
             if (!$data['delivery_code']) {
@@ -522,6 +523,52 @@ class StoreOrderDeliveryServices extends BaseServices
             if (!empty($dump['label'])) {
                 $data['kuaidi_label'] = $dump['label'];
             }
+        } else if ($data['express_record_type'] == 3) {
+            //商家寄件
+            if (!$data['delivery_code']) {
+                throw new AdminException(400476);
+            }
+            if (!$data['express_temp_id']) {
+                throw new AdminException(400527);
+            }
+            if (!$data['to_name']) {
+                throw new AdminException(400008);
+            }
+            if (!$data['to_tel']) {
+                throw new AdminException(400477);
+            }
+            if (!$data['to_addr']) {
+                throw new AdminException(400478);
+            }
+            /** @var ServeServices $expressService */
+            $expressService = app()->make(ServeServices::class);
+            $expData['kuaidicom'] = $data['delivery_code'];
+            $expData['man_name'] = $orderInfo->real_name;
+            $expData['phone'] = $orderInfo->user_phone;
+            $expData['address'] = $orderInfo->user_address;
+            $expData['send_real_name'] = $data['to_name'];
+            $expData['send_phone'] = $data['to_tel'];
+            $expData['send_address'] = $data['to_addr'];
+            $expData['temp_id'] = $data['express_temp_id'];
+            $expData['weight'] = $this->getOrderSumWeight($id);
+            $expData['cargo'] = $orderInfoServices->getCarIdByProductTitle((int)$orderInfo->id, true);
+            if (!sys_config('config_shippment_open', 0)) {
+                throw new AdminException('商家寄件未开启无法寄件');
+            }
+            $dump = $expressService->express()->shippmentCreateOrder($expData);
+            $orderInfo->delivery_id = $dump['kuaidinum'] ?? '';
+            $data['express_dump'] = json_encode([
+                'com' => $expData['com'],
+                'from_name' => $expData['from_name'],
+                'from_tel' => $expData['from_tel'],
+                'from_addr' => $expData['from_addr'],
+                'temp_id' => $expData['temp_id'],
+                'cargo' => $expData['cargo'],
+            ]);
+            $data['delivery_id'] = $dump['kuaidinum'] ?? '';
+            $data['kuaidi_label'] = $dump['label'] ?? '';
+            $data['kuaidi_task_id'] = $dump['taskId'] ?? '';
+            $data['kuaidi_order_id'] = $dump['orderId'] ?? '';
         } else {
             if (!$data['delivery_id']) {
                 throw new AdminException(400531);

+ 54 - 0
crmeb/app/services/order/StoreOrderServices.php

@@ -20,6 +20,7 @@ use app\services\other\PosterServices;
 use app\services\pay\OrderPayServices;
 use app\services\pay\PayServices;
 use app\services\product\product\StoreProductLogServices;
+use app\services\serve\ServeServices;
 use app\services\system\attachment\SystemAttachmentServices;
 use app\services\system\store\SystemStoreServices;
 use app\services\user\UserInvoiceServices;
@@ -38,6 +39,7 @@ use crmeb\services\FormBuilder as Form;
 use crmeb\services\printer\Printer;
 use crmeb\services\SystemConfigService;
 use crmeb\utils\Arr;
+use think\exception\ValidateException;
 use think\facade\Log;
 
 /**
@@ -2643,4 +2645,56 @@ HTML;
 
         return $data;
     }
+
+    /**
+     * 取消商家寄件
+     * @author 等风来
+     * @email 136327134@qq.com
+     * @date 2023/5/15
+     * @param int $id
+     * @param string $msg
+     * @return array|mixed
+     * @throws \think\db\exception\DataNotFoundException
+     * @throws \think\db\exception\DbException
+     * @throws \think\db\exception\ModelNotFoundException
+     */
+    public function shipmentCancelOrder(int $id, string $msg)
+    {
+        $orderInfo = $this->dao->get($id);
+        if (!$orderInfo) {
+            throw new ValidateException('取消的订单不存在');
+        }
+        if (!$orderInfo->kuaidi_task_id || !$orderInfo->kuaidi_order_id) {
+            throw new ValidateException('商家寄件订单信息不存在,无法取消');
+        }
+        if ($orderInfo->status != 1) {
+            throw new ValidateException('订单状态不正确,无法取消寄件');
+        }
+
+        //发起取消商家寄件
+        $res = app()->make(ServeServices::class)->express()->shipmentCancelOrder([
+            'task_id' => $orderInfo->kuaidi_task_id,
+            'order_id' => $orderInfo->kuaidi_order_id,
+            'cancel_msg' => $msg,
+        ]);
+
+        if ($res['status'] != 200) {
+            throw new ValidateException($res['msg'] ?? '一号通:取消失败');
+        }
+
+        //订单返回原状态
+        $this->transaction(function () use ($id, $msg, $orderInfo) {
+            app()->make(StoreOrderStatusServices::class)->save([
+                'oid' => $id,
+                'change_time' => time(),
+                'change_type' => 'delivery_goods_cancel',
+                'change_message' => '已取消发货,取消原因:' . $msg
+            ]);
+
+            $orderInfo->status = 0;
+            $orderInfo->save();
+        });
+
+        return $res;
+    }
 }

+ 88 - 0
crmeb/crmeb/services/express/storage/Express.php

@@ -46,6 +46,15 @@ class Express extends BaseExpress
      */
     const EXPRESS_DUMP = 'expr/dump';
 
+    //获取物流公司信息
+    const SHIPMENT_KUAIDI_NUMS = 'shipment/get_kuaidi_coms';
+    //创建商家寄件订单
+    const SHIPMENT_CREATE_ORDER = 'shipment/create_order';
+    //取消商家寄件
+    const SHIPMENT_CANCEL_ORDER = 'shipment/cancel_order';
+    //获取商家寄件订单列表
+    const SHIPMENT_INDEX = 'shipment/index';
+
     /** 初始化
      * @param array $config
      * @return mixed|void
@@ -56,6 +65,85 @@ class Express extends BaseExpress
         parent::initialize($config); // TODO: Change the autogenerated stub
     }
 
+    /**
+     * 商家寄件获取快递公司
+     * @return array|mixed
+     * @author 等风来
+     * @email 136327134@qq.com
+     * @date 2023/5/15
+     */
+    public function getKuaidiComs()
+    {
+        return $this->accessToken->httpRequest(self::SHIPMENT_KUAIDI_NUMS, [], 'GET');
+    }
+
+    /**
+     * 商家寄件创建订单
+     * @param array $data
+     * @return array|mixed
+     * @author 等风来
+     * @email 136327134@qq.com
+     * @date 2023/5/15
+     */
+    public function shippmentCreateOrder(array $data)
+    {
+        $siid = sys_config('config_export_siid');
+        $param = [
+            'kuaidicom' => $data['kuaidicom'],
+            'man_name' => $data['man_name'],
+            'phone' => $data['phone'],
+            'address' => $data['address'],
+            'send_real_name' => $data['send_real_name'],
+            'send_phone' => $data['send_phone'],
+            'send_address' => $data['send_address'],
+            'call_back_url' => sys_config(''),
+            'return_type' => $siid ? '10' : '20',
+            'siid' => $siid,
+            'tempid' => $data['tempid'],
+            'cargo' => $data['cargo'],
+            'weight' => $data['weight'],
+        ];
+        return $this->accessToken->httpRequest(self::SHIPMENT_CREATE_ORDER, $param);
+    }
+
+    /**
+     * 取消商家寄件订单
+     * @param array $data
+     * @return array|mixed
+     * @author 等风来
+     * @email 136327134@qq.com
+     * @date 2023/5/15
+     */
+    public function shipmentCancelOrder(array $data)
+    {
+        $param = [
+            'task_id' => $data['task_id'],//快递100商家寄件任务id
+            'order_id' => $data['order_id'],//快递100商家寄件发起的订单号。并不是系统中的订单号
+            'cancel_msg' => $data['cancel_msg'],//取消原因
+        ];
+        return $this->accessToken->httpRequest(self::SHIPMENT_CANCEL_ORDER, $param);
+    }
+
+    /**
+     * 获取商家寄件订单列表
+     * @param array $data
+     * @return array|mixed
+     * @author 等风来
+     * @email 136327134@qq.com
+     * @date 2023/5/15
+     */
+    public function getShipmentOrderList(array $data)
+    {
+        $param = [
+            'kuaidi_num' => $data['kuaidi_num'] ?? '',
+            'courier_name' => $data['courier_name'] ?? '',
+            'page' => $data['page'] ?? 1,
+            'limit' => $data['limit'] ?? 10,
+        ];
+
+        return $this->accessToken->httpRequest(self::SHIPMENT_INDEX, $param, 'GET');
+    }
+
     /**
      * 开通物流服务
      * @return bool|mixed