ExpressController.php 5.1 KB

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