ExpressController.php 6.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188
  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. $params = [
  39. 'deliveryId' => $deliveryId,
  40. 'bizId' => $bizId,
  41. ];
  42. ExpressClass::cancel($params, $order);
  43. }
  44. //新建运单 ssh
  45. public function actionCreateWayBill()
  46. {
  47. $post = Yii::$app->request->post();
  48. $id = $post['id'] ?? 0;
  49. $weight = $post['weight'] ?? 0;
  50. if (empty($weight) || $weight <= 0) {
  51. util::fail('请填写重量');
  52. }
  53. $length = $post['length'] ? trim($post['length']) : 0;
  54. if (!is_numeric($length) || $length <= 0) {
  55. util::fail('请填写长度');
  56. }
  57. $width = $post['width'] ? trim($post['width']) : 0;
  58. if (!is_numeric($width) || $width <= 0) {
  59. util::fail('请填写宽度');
  60. }
  61. $height = $post['height'] ? trim($post['height']) : 0;
  62. if (!is_numeric($height) || $height <= 0) {
  63. util::fail('请填写高度');
  64. }
  65. $packageNum = $post['packageNum'] ? trim($post['packageNum']) : 0;
  66. if (!is_numeric($packageNum) || $packageNum <= 0) {
  67. util::fail('请填写包裹数量');
  68. }
  69. $order = OrderClass::getById($id, true);
  70. if (empty($order)) {
  71. util::fail('没有找到订单');
  72. }
  73. if ($order->mainId != $this->mainId) {
  74. util::fail('不是你的订单');
  75. }
  76. if ($order->status == 2) {
  77. if ($order->fhWlStatus == 1) {
  78. util::fail('已发货');
  79. }
  80. } else {
  81. util::fail('无需发货');
  82. }
  83. $orderSn = $order->orderSn ?? '';
  84. $customId = $order->customId ?? 0;
  85. $custom = CustomClass::getById($customId, true);
  86. if (empty($custom)) {
  87. util::fail('没有找到客户');
  88. }
  89. //要先去后台绑定,这里填写才有用,mainId对应月结账号
  90. $bizIdMap = [
  91. //长春花路鲜花,
  92. '36707' => '4212960899',
  93. //龙岩花掌柜
  94. '50' => '5925274162',
  95. ];
  96. $mainId = $this->mainId;
  97. if (getenv('YII_ENV') == 'production') {
  98. $bizId = $bizIdMap[$mainId] ?? 0;
  99. if (empty($bizId)) {
  100. util::fail('没有找到月结账号');
  101. }
  102. //暂时只支持顺丰
  103. $deliveryId = 'SF';
  104. $serviceType = 0;
  105. $serviceName = '标准快递';
  106. } else {
  107. $deliveryId = 'TEST';
  108. $bizId = 'test_biz_id';
  109. $serviceType = 1;
  110. $serviceName = 'test_service_name';
  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. ];
  169. ExpressClass::addWayBill($params, $order);
  170. util::complete('操作成功');
  171. }
  172. }