ExpressController.php 10 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306
  1. <?php
  2. namespace ghs\controllers;
  3. use bizGhs\custom\classes\CustomClass;
  4. use bizGhs\express\classes\ExpressClass;
  5. use bizGhs\express\classes\GhsExpressOrderClass;
  6. use bizGhs\order\classes\OrderClass;
  7. use common\components\dict;
  8. use common\components\imgUtil;
  9. use common\components\util;
  10. use Yii;
  11. //用于物流服务
  12. class ExpressController extends BaseController
  13. {
  14. public $guestAccess = ['get-has-map'];
  15. public function actionDetail()
  16. {
  17. $get = Yii::$app->request->get();
  18. $orderId = $get['orderId'] ?? 0;
  19. $order = OrderClass::getById($orderId, true);
  20. if (empty($order)) {
  21. util::fail('没有找到订单');
  22. }
  23. if ($order->mainId != $this->mainId) {
  24. util::fail('不是你的订单');
  25. }
  26. $express = GhsExpressOrderClass::getByCondition(['orderId' => $orderId, 'status' => 1], true);
  27. if (empty($express)) {
  28. util::fail('没有找到配送信息');
  29. }
  30. util::success($express);
  31. }
  32. // 获取字典中的 hasMap
  33. public function actionGetHasMap()
  34. {
  35. $shop = $this->shop;
  36. util::success(['hasMap' => dict::getDict('hasMap'), 'shop' => $shop]);
  37. }
  38. //获取采购单物流运单的轨迹 ssh 20250705
  39. public function actionGetCgExpressTrack()
  40. {
  41. $get = Yii::$app->request->get();
  42. $id = $get['id'] ?? 0;
  43. $order = OrderClass::getById($id, true);
  44. if (empty($order)) {
  45. util::fail('没有找到订单');
  46. }
  47. if ($order->mainId != $this->mainId) {
  48. util::fail('不是你的订单');
  49. }
  50. $mainId = $this->mainId;
  51. $bizIdMap = dict::getDict('expressBizIdMap');
  52. if (getenv('YII_ENV') == 'production') {
  53. $bizId = $bizIdMap[$mainId] ?? 0;
  54. if (empty($bizId)) {
  55. util::fail('没有找到月结账号');
  56. }
  57. //暂时只支持顺丰
  58. $deliveryId = 'SF';
  59. } else {
  60. $deliveryId = 'TEST';
  61. $bizId = 'test_biz_id';
  62. }
  63. $params = [
  64. 'deliveryId' => $deliveryId,
  65. ];
  66. $respond = ExpressClass::getTrack($params, $order);
  67. util::success($respond);
  68. }
  69. public function actionTestUpdate()
  70. {
  71. $get = Yii::$app->request->get();
  72. $id = $get['id'] ?? 0;
  73. $action = $get['action'] ?? 0;
  74. $order = OrderClass::getById($id, true);
  75. if (empty($order)) {
  76. util::fail('没有找到订单');
  77. }
  78. if ($order->mainId != $this->mainId) {
  79. util::fail('不是你的订单');
  80. }
  81. $fhWlNo = $order->fhWlNo ?? '';
  82. if (empty($fhWlNo)) {
  83. util::fail('没有找到物流单');
  84. }
  85. $orderSn = $order->orderSn;
  86. $wayBillId = $order->fhWlNo;
  87. $actionTime = time();
  88. $actionTypeMap = [
  89. 0 => 100001,
  90. 1 => 100002,
  91. 2 => 100003,
  92. 3 => 200001,
  93. 4 => 300002,
  94. 5 => 300003,
  95. 6 => 300004,
  96. 7 => 400001,
  97. 8 => 400002,
  98. ];
  99. $actionType = $actionTypeMap[$action] ?? 100001;
  100. $actionMsg = '编号' . rand(1111, 9999);
  101. $bizIdMap = dict::getDict('expressBizIdMap');
  102. if (getenv('YII_ENV') == 'production') {
  103. $bizId = $bizIdMap[$mainId] ?? 0;
  104. if (empty($bizId)) {
  105. util::fail('没有找到月结账号');
  106. }
  107. //暂时只支持顺丰
  108. $deliveryId = 'SF';
  109. } else {
  110. $deliveryId = 'TEST';
  111. $bizId = 'test_biz_id';
  112. }
  113. $params = [
  114. 'deliveryId' => $deliveryId,
  115. 'bizId' => $bizId,
  116. 'orderSn' => $orderSn,
  117. 'wayBillId' => $wayBillId,
  118. 'actionType' => $actionType,
  119. 'actionMsg' => $actionMsg,
  120. 'actionTime' => $actionTime,
  121. ];
  122. ExpressClass::testUpdate($params, $order);
  123. }
  124. public function actionCancelWayBill()
  125. {
  126. $get = Yii::$app->request->get();
  127. $id = $get['id'] ?? 0;
  128. $order = OrderClass::getById($id, true);
  129. if (empty($order)) {
  130. util::fail('没有找到订单');
  131. }
  132. if ($order->mainId != $this->mainId) {
  133. util::fail('不是你的订单');
  134. }
  135. $fhWlNo = $order->fhWlNo ?? '';
  136. if (empty($fhWlNo)) {
  137. util::fail('没有找到物流单');
  138. }
  139. $mainId = $this->mainId;
  140. $bizIdMap = dict::getDict('expressBizIdMap');
  141. if (getenv('YII_ENV') == 'production') {
  142. $bizId = $bizIdMap[$mainId] ?? 0;
  143. if (empty($bizId)) {
  144. util::fail('没有找到月结账号');
  145. }
  146. //暂时只支持顺丰
  147. $deliveryId = 'SF';
  148. } else {
  149. $deliveryId = 'TEST';
  150. $bizId = 'test_biz_id';
  151. }
  152. $params = [
  153. 'deliveryId' => $deliveryId,
  154. 'bizId' => $bizId,
  155. ];
  156. ExpressClass::cancel($params, $order);
  157. }
  158. //新建运单 ssh
  159. public function actionCreateWayBill()
  160. {
  161. $post = Yii::$app->request->post();
  162. $id = $post['id'] ?? 0;
  163. $weight = $post['weight'] ?? 0;
  164. if (empty($weight) || $weight <= 0) {
  165. util::fail('请填写重量');
  166. }
  167. $length = $post['length'] ? trim($post['length']) : 0;
  168. if (!is_numeric($length) || $length <= 0) {
  169. util::fail('请填写长度');
  170. }
  171. $width = $post['width'] ? trim($post['width']) : 0;
  172. if (!is_numeric($width) || $width <= 0) {
  173. util::fail('请填写宽度');
  174. }
  175. $height = $post['height'] ? trim($post['height']) : 0;
  176. if (!is_numeric($height) || $height <= 0) {
  177. util::fail('请填写高度');
  178. }
  179. $packageNum = $post['packageNum'] ? trim($post['packageNum']) : 0;
  180. if (!is_numeric($packageNum) || $packageNum <= 0) {
  181. util::fail('请填写包裹数量');
  182. }
  183. $order = OrderClass::getById($id, true);
  184. if (empty($order)) {
  185. util::fail('没有找到订单');
  186. }
  187. if ($order->mainId != $this->mainId) {
  188. util::fail('不是你的订单');
  189. }
  190. if ($order->payStatus == 0) {
  191. util::fail('订单没有付款');
  192. }
  193. if (in_array($order->status, [3, 4]) && $order->fhWlStatus == 1) {
  194. util::fail('已经发过快递了');
  195. }
  196. $orderSn = $order->orderSn ?? '';
  197. $customId = $order->customId ?? 0;
  198. $custom = CustomClass::getById($customId, true);
  199. if (empty($custom)) {
  200. util::fail('没有找到客户');
  201. }
  202. //要先去后台绑定,这里填写才有用,mainId对应月结账号
  203. $bizIdMap = dict::getDict('expressBizIdMap');
  204. $mainId = $this->mainId;
  205. if (getenv('YII_ENV') == 'production') {
  206. $bizId = $bizIdMap[$mainId] ?? 0;
  207. if (empty($bizId)) {
  208. util::fail('没有找到月结账号');
  209. }
  210. //暂时只支持顺丰
  211. $deliveryId = 'SF';
  212. $serviceType = 0;
  213. $serviceName = '标准快递';
  214. //销花宝移动应用的微信appId
  215. $wxAppId = 'wxb379c1f2f3ef705e';
  216. } else {
  217. $deliveryId = 'TEST';
  218. $bizId = 'test_biz_id';
  219. $serviceType = 1;
  220. $serviceName = 'test_service_name';
  221. $wxAppId = 'wx4bf74abf453eb789';
  222. }
  223. // $admin = $this->admin;
  224. // $openId = $admin->ghsMiniOpenId ?? '';
  225. // if (empty($openId)) {
  226. // util::fail('请用小程序发单');
  227. // }
  228. $shop = $this->shop;
  229. $shopName = $shop->shopName;
  230. $sjName = $shop->merchantName;
  231. $senderName = $shopName == '首店' ? $sjName : $sjName . ' ' . $shopName;
  232. $senderMobile = !empty($shop->telephone) ? $shop->telephone : $shop->mobile;
  233. $senderProvince = $shop->province;
  234. $senderCity = $shop->city;
  235. $senderAddress = $shop->address;
  236. if (empty($senderAddress)) {
  237. util::fail('你的门店地址还没有设置');
  238. }
  239. $receiverName = $custom->name;
  240. $receiverMobile = $custom->mobile;
  241. $receiverProvince = $custom->province;
  242. $receiverCity = $custom->city;
  243. $receiverAddress = $custom->address;
  244. $receiverFloor = $custom->floor;
  245. $goodsName = '鲜花花材';
  246. $customRemark = '鲜花花材,编号:' . $order->sendNum;
  247. $goodsCount = ceil($order->itemNum);;
  248. $shopImgUrl = imgUtil::groupImg('logo4.png') . "?x-oss-process=image/resize,m_fill,h_80,w_80";
  249. $staff = $this->shopAdmin;
  250. $staffId = $staff->id;
  251. $staffName = $staff->name ?? '';
  252. $params = [
  253. 'bizId' => $bizId,// 快递公司客户编码或月结账号
  254. //'openId' => $openId,
  255. 'senderName' => $senderName,
  256. 'senderMobile' => $senderMobile,
  257. 'senderProvince' => $senderProvince,
  258. 'senderCity' => $senderCity,
  259. 'senderAddress' => $senderAddress,
  260. 'receiverName' => $receiverName,
  261. 'receiverMobile' => $receiverMobile,
  262. 'receiverProvince' => $receiverProvince,
  263. 'receiverCity' => $receiverCity,
  264. 'receiverAddress' => $receiverAddress,
  265. 'receiverFloor' => $receiverFloor,
  266. 'goodsCount' => $goodsCount,
  267. 'goodsName' => $goodsName,
  268. 'customRemark' => $customRemark,
  269. 'weight' => $weight,
  270. 'length' => $length,
  271. 'width' => $width,
  272. 'height' => $height,
  273. 'packageNum' => $packageNum,
  274. 'deliveryId' => $deliveryId,
  275. 'serviceType' => $serviceType,
  276. 'serviceName' => $serviceName,
  277. 'orderSn' => $orderSn,
  278. 'shopImgUrl' => $shopImgUrl,
  279. 'staffId' => $staffId,
  280. 'staffName' => $staffName,
  281. 'wxAppId' => $wxAppId,
  282. ];
  283. ExpressClass::addWayBill($params, $order);
  284. util::complete('操作成功');
  285. }
  286. }