ExpressController.php 9.1 KB

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