ExpressController.php 9.3 KB

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