ExpressController.php 6.5 KB

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