ExpressController.php 6.3 KB

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