ExpressController.php 10.0 KB

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