ExpressController.php 4.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139
  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. $orderSn = $order->orderSn ?? '';
  45. $customId = $order->customId ?? 0;
  46. $custom = CustomClass::getById($customId, true);
  47. if (empty($custom)) {
  48. util::fail('没有找到客户');
  49. }
  50. //要先去后台绑定,这里填写才有用,mainId对应月结账号
  51. $bizIdMap = [
  52. //长春花路鲜花,
  53. '36707' => '4212960899',
  54. //龙岩花掌柜
  55. '50' => '5925274162',
  56. ];
  57. $mainId = $this->mainId;
  58. if (getenv('YII_ENV') == 'production') {
  59. $bizId = $bizIdMap[$mainId] ?? 0;
  60. if (empty($bizId)) {
  61. util::fail('没有找到月结账号');
  62. }
  63. //暂时只支持顺丰
  64. $deliveryId = 'SF';
  65. $serviceType = 0;
  66. $serviceName = '标准快递';
  67. } else {
  68. $deliveryId = 'TEST';
  69. $bizId = 'test_biz_id';
  70. $serviceType = 1;
  71. $serviceName = 'test_service_name';
  72. }
  73. $admin = $this->admin;
  74. $openId = $admin->ghsMiniOpenId ?? '';
  75. if (empty($openId)) {
  76. util::fail('请用小程序发单');
  77. }
  78. $shop = $this->shop;
  79. $shopName = $shop->shopName;
  80. $sjName = $shop->merchantName;
  81. $senderName = $shopName == '首店' ? $sjName : $sjName . ' ' . $shopName;
  82. $senderMobile = !empty($shop->telephone) ? $shop->telephone : $shop->mobile;
  83. $senderProvince = $shop->province;
  84. $senderCity = $shop->city;
  85. $senderAddress = $shop->address;
  86. if (empty($senderAddress)) {
  87. util::fail('你的门店地址还没有设置');
  88. }
  89. $receiverName = $custom->name;
  90. $receiverMobile = $custom->mobile;
  91. $receiverProvince = $custom->province;
  92. $receiverCity = $custom->city;
  93. $receiverAddress = $custom->address;
  94. $goodsName = '鲜花花材';
  95. $customRemark = '鲜花花材,编号:' . $order->sendNum;
  96. $goodsCount = ceil($order->itemNum);;
  97. $shopImgUrl = imgUtil::groupImg('logo4.png') . "?x-oss-process=image/resize,m_fill,h_80,w_80";
  98. $params = [
  99. 'bizId' => $bizId,// 快递公司客户编码或月结账号
  100. 'openId' => $openId,
  101. 'senderName' => $senderName,
  102. 'senderMobile' => $senderMobile,
  103. 'senderProvince' => $senderProvince,
  104. 'senderCity' => $senderCity,
  105. 'senderAddress' => $senderAddress,
  106. 'receiverName' => $receiverName,
  107. 'receiverMobile' => $receiverMobile,
  108. 'receiverProvince' => $receiverProvince,
  109. 'receiverCity' => $receiverCity,
  110. 'receiverAddress' => $receiverAddress,
  111. 'goodsCount' => $goodsCount,
  112. 'goodsName' => $goodsName,
  113. 'customRemark' => $customRemark,
  114. 'weight' => $weight,
  115. 'length' => $length,
  116. 'width' => $width,
  117. 'height' => $height,
  118. 'packageNum' => $packageNum,
  119. 'deliveryId' => $deliveryId,
  120. 'serviceType' => $serviceType,
  121. 'serviceName' => $serviceName,
  122. 'orderSn' => $orderSn,
  123. 'shopImgUrl' => $shopImgUrl,
  124. ];
  125. ExpressClass::addWayBill($params);
  126. }
  127. }