ExpressController.php 9.9 KB

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