ExpressController.php 9.3 KB

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