ExpressController.php 9.2 KB

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