ExpressController.php 4.5 KB

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