| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306 |
- <?php
- namespace ghs\controllers;
- use bizGhs\custom\classes\CustomClass;
- use bizGhs\express\classes\ExpressClass;
- use bizGhs\express\classes\GhsExpressOrderClass;
- use bizGhs\order\classes\OrderClass;
- use common\components\dict;
- use common\components\imgUtil;
- use common\components\util;
- use Yii;
- //用于物流服务
- class ExpressController extends BaseController
- {
- public $guestAccess = ['get-has-map'];
- public function actionDetail()
- {
- $get = Yii::$app->request->get();
- $orderId = $get['orderId'] ?? 0;
- $order = OrderClass::getById($orderId, true);
- if (empty($order)) {
- util::fail('没有找到订单');
- }
- if ($order->mainId != $this->mainId) {
- util::fail('不是你的订单');
- }
- $express = GhsExpressOrderClass::getByCondition(['orderId' => $orderId, 'status' => 1], true);
- if (empty($express)) {
- util::fail('没有找到配送信息');
- }
- util::success($express);
- }
- // 获取字典中的 hasMap
- public function actionGetHasMap()
- {
- $shop = $this->shop;
- util::success(['hasMap' => dict::getDict('hasMap'), 'shop' => $shop]);
- }
- //获取采购单物流运单的轨迹 ssh 20250705
- public function actionGetCgExpressTrack()
- {
- $get = Yii::$app->request->get();
- $id = $get['id'] ?? 0;
- $order = OrderClass::getById($id, true);
- if (empty($order)) {
- util::fail('没有找到订单');
- }
- if ($order->mainId != $this->mainId) {
- util::fail('不是你的订单');
- }
- $mainId = $this->mainId;
- $bizIdMap = dict::getDict('expressBizIdMap');
- if (getenv('YII_ENV') == 'production') {
- $bizId = $bizIdMap[$mainId] ?? 0;
- if (empty($bizId)) {
- util::fail('没有找到月结账号');
- }
- //暂时只支持顺丰
- $deliveryId = 'SF';
- } else {
- $deliveryId = 'TEST';
- $bizId = 'test_biz_id';
- }
- $params = [
- 'deliveryId' => $deliveryId,
- ];
- $respond = ExpressClass::getTrack($params, $order);
- util::success($respond);
- }
- public function actionTestUpdate()
- {
- $get = Yii::$app->request->get();
- $id = $get['id'] ?? 0;
- $action = $get['action'] ?? 0;
- $order = OrderClass::getById($id, true);
- if (empty($order)) {
- util::fail('没有找到订单');
- }
- if ($order->mainId != $this->mainId) {
- util::fail('不是你的订单');
- }
- $fhWlNo = $order->fhWlNo ?? '';
- if (empty($fhWlNo)) {
- util::fail('没有找到物流单');
- }
- $orderSn = $order->orderSn;
- $wayBillId = $order->fhWlNo;
- $actionTime = time();
- $actionTypeMap = [
- 0 => 100001,
- 1 => 100002,
- 2 => 100003,
- 3 => 200001,
- 4 => 300002,
- 5 => 300003,
- 6 => 300004,
- 7 => 400001,
- 8 => 400002,
- ];
- $actionType = $actionTypeMap[$action] ?? 100001;
- $actionMsg = '编号' . rand(1111, 9999);
- $bizIdMap = dict::getDict('expressBizIdMap');
- if (getenv('YII_ENV') == 'production') {
- $bizId = $bizIdMap[$mainId] ?? 0;
- if (empty($bizId)) {
- util::fail('没有找到月结账号');
- }
- //暂时只支持顺丰
- $deliveryId = 'SF';
- } else {
- $deliveryId = 'TEST';
- $bizId = 'test_biz_id';
- }
- $params = [
- 'deliveryId' => $deliveryId,
- 'bizId' => $bizId,
- 'orderSn' => $orderSn,
- 'wayBillId' => $wayBillId,
- 'actionType' => $actionType,
- 'actionMsg' => $actionMsg,
- 'actionTime' => $actionTime,
- ];
- ExpressClass::testUpdate($params, $order);
- }
- public function actionCancelWayBill()
- {
- $get = Yii::$app->request->get();
- $id = $get['id'] ?? 0;
- $order = OrderClass::getById($id, true);
- if (empty($order)) {
- util::fail('没有找到订单');
- }
- if ($order->mainId != $this->mainId) {
- util::fail('不是你的订单');
- }
- $fhWlNo = $order->fhWlNo ?? '';
- if (empty($fhWlNo)) {
- util::fail('没有找到物流单');
- }
- $mainId = $this->mainId;
- $bizIdMap = dict::getDict('expressBizIdMap');
- if (getenv('YII_ENV') == 'production') {
- $bizId = $bizIdMap[$mainId] ?? 0;
- if (empty($bizId)) {
- util::fail('没有找到月结账号');
- }
- //暂时只支持顺丰
- $deliveryId = 'SF';
- } else {
- $deliveryId = 'TEST';
- $bizId = 'test_biz_id';
- }
- $params = [
- 'deliveryId' => $deliveryId,
- 'bizId' => $bizId,
- ];
- ExpressClass::cancel($params, $order);
- }
- //新建运单 ssh
- public function actionCreateWayBill()
- {
- $post = Yii::$app->request->post();
- $id = $post['id'] ?? 0;
- $weight = $post['weight'] ?? 0;
- if (empty($weight) || $weight <= 0) {
- util::fail('请填写重量');
- }
- $length = $post['length'] ? trim($post['length']) : 0;
- if (!is_numeric($length) || $length <= 0) {
- util::fail('请填写长度');
- }
- $width = $post['width'] ? trim($post['width']) : 0;
- if (!is_numeric($width) || $width <= 0) {
- util::fail('请填写宽度');
- }
- $height = $post['height'] ? trim($post['height']) : 0;
- if (!is_numeric($height) || $height <= 0) {
- util::fail('请填写高度');
- }
- $packageNum = $post['packageNum'] ? trim($post['packageNum']) : 0;
- if (!is_numeric($packageNum) || $packageNum <= 0) {
- util::fail('请填写包裹数量');
- }
- $order = OrderClass::getById($id, true);
- if (empty($order)) {
- util::fail('没有找到订单');
- }
- if ($order->mainId != $this->mainId) {
- util::fail('不是你的订单');
- }
- if ($order->payStatus == 0) {
- util::fail('订单没有付款');
- }
- if (in_array($order->status, [3, 4]) && $order->fhWlStatus == 1) {
- util::fail('已经发过快递了');
- }
- $orderSn = $order->orderSn ?? '';
- $customId = $order->customId ?? 0;
- $custom = CustomClass::getById($customId, true);
- if (empty($custom)) {
- util::fail('没有找到客户');
- }
- //要先去后台绑定,这里填写才有用,mainId对应月结账号
- $bizIdMap = dict::getDict('expressBizIdMap');
- $mainId = $this->mainId;
- if (getenv('YII_ENV') == 'production') {
- $bizId = $bizIdMap[$mainId] ?? 0;
- if (empty($bizId)) {
- util::fail('没有找到月结账号');
- }
- //暂时只支持顺丰
- $deliveryId = 'SF';
- $serviceType = 0;
- $serviceName = '标准快递';
- //销花宝移动应用的微信appId
- $wxAppId = 'wxb379c1f2f3ef705e';
- } else {
- $deliveryId = 'TEST';
- $bizId = 'test_biz_id';
- $serviceType = 1;
- $serviceName = 'test_service_name';
- $wxAppId = 'wx4bf74abf453eb789';
- }
- // $admin = $this->admin;
- // $openId = $admin->ghsMiniOpenId ?? '';
- // if (empty($openId)) {
- // util::fail('请用小程序发单');
- // }
- $shop = $this->shop;
- $shopName = $shop->shopName;
- $sjName = $shop->merchantName;
- $senderName = $shopName == '首店' ? $sjName : $sjName . ' ' . $shopName;
- $senderMobile = !empty($shop->telephone) ? $shop->telephone : $shop->mobile;
- $senderProvince = $shop->province;
- $senderCity = $shop->city;
- $senderAddress = $shop->address;
- if (empty($senderAddress)) {
- util::fail('你的门店地址还没有设置');
- }
- $receiverName = $custom->name;
- $receiverMobile = $custom->mobile;
- $receiverProvince = $custom->province;
- $receiverCity = $custom->city;
- $receiverAddress = $custom->address;
- $receiverFloor = $custom->floor;
- $goodsName = '鲜花花材';
- $customRemark = '鲜花花材,编号:' . $order->sendNum;
- $goodsCount = ceil($order->itemNum);;
- $shopImgUrl = imgUtil::groupImg('logo4.png') . "?x-oss-process=image/resize,m_fill,h_80,w_80";
- $staff = $this->shopAdmin;
- $staffId = $staff->id;
- $staffName = $staff->name ?? '';
- $params = [
- 'bizId' => $bizId,// 快递公司客户编码或月结账号
- //'openId' => $openId,
- 'senderName' => $senderName,
- 'senderMobile' => $senderMobile,
- 'senderProvince' => $senderProvince,
- 'senderCity' => $senderCity,
- 'senderAddress' => $senderAddress,
- 'receiverName' => $receiverName,
- 'receiverMobile' => $receiverMobile,
- 'receiverProvince' => $receiverProvince,
- 'receiverCity' => $receiverCity,
- 'receiverAddress' => $receiverAddress,
- 'receiverFloor' => $receiverFloor,
- 'goodsCount' => $goodsCount,
- 'goodsName' => $goodsName,
- 'customRemark' => $customRemark,
- 'weight' => $weight,
- 'length' => $length,
- 'width' => $width,
- 'height' => $height,
- 'packageNum' => $packageNum,
- 'deliveryId' => $deliveryId,
- 'serviceType' => $serviceType,
- 'serviceName' => $serviceName,
- 'orderSn' => $orderSn,
- 'shopImgUrl' => $shopImgUrl,
- 'staffId' => $staffId,
- 'staffName' => $staffName,
- 'wxAppId' => $wxAppId,
- ];
- ExpressClass::addWayBill($params, $order);
- util::complete('操作成功');
- }
- }
|