ExpressController.php 8.0 KB

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