ExpressController.php 4.5 KB

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