ExpressController.php 3.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112
  1. <?php
  2. /**
  3. * User: admin
  4. * Date Time: 2021/2/21 19:55
  5. */
  6. namespace ghs\controllers;
  7. use bizGhs\custom\classes\CustomClass;
  8. use bizGhs\custom\services\CustomService;
  9. use bizGhs\express\services\MiniExpressService;
  10. use bizGhs\merchant\services\ShopService;
  11. use bizGhs\product\services\ProductService;
  12. use common\components\util;
  13. use Yii;
  14. class ExpressController extends BaseController
  15. {
  16. //获取即时配送快递列表
  17. public function actionList()
  18. {
  19. $data = MiniExpressService::getAllImmeDelivery("id,deliveryId,deliveryName", ['status' => 1]);
  20. util::success($data);
  21. }
  22. //配送费预估
  23. public function actionPreAddOrder()
  24. {
  25. // util::success(['fee' => 16.5]);
  26. $post = Yii::$app->request->post();
  27. $expressId = $post['expressId'] ?? 0;
  28. $ghsItemInfo = $post['itemInfo'] ?? '';
  29. if (empty($ghsItemInfo)) {
  30. util::fail('请选择花材');
  31. }
  32. $ghsItemInfo = json_decode($ghsItemInfo, true); // [{productId:0,itemPrice:1,bigNum:1,smallNum:0}]
  33. //计算总价格,总重量
  34. $cargoInfo = ProductService::groupCargo($ghsItemInfo);
  35. $shop_order_id = time();
  36. $shop_no = ""; //与快递签约时的门店ID(应该是固定的)
  37. $openid = isset($this->admin) && !empty($this->admin) ? $this->admin->miniOpenId : '';
  38. if (empty($openId)) {
  39. util::fail('没有找到openId');
  40. }
  41. //客户id
  42. $customId = $post['customId'] ?? 0;
  43. //获取客户name
  44. $customInfo = CustomService::getCustomInfo($customId);
  45. CustomClass::valid($customInfo, $this->shopId);
  46. //当前门店的地址信息
  47. $shopInfo = ShopService::getById($this->shopId);
  48. $sender = [
  49. 'name' => $shopInfo['shopName'],
  50. 'city' => $shopInfo['city'] ?? '',
  51. 'address' => $shopInfo['address'] ?? '',
  52. 'address_detail' => $shopInfo['floor'] ?? '',
  53. 'phone' => $shopInfo['telephone'] ?? '',
  54. 'lng' => (float)$shopInfo['long'] ?? '',
  55. 'lat' => (float)$shopInfo['lat'] ?? '',
  56. 'coordinate_type' => 0,
  57. ];
  58. $receiver = [
  59. 'name' => $customInfo['name'],
  60. 'city' => $post['city'] ?? '',
  61. 'address' => $post['address'] ?? '',
  62. 'address_detail' => $post['floor'] ?? '',
  63. //'phone'=>$customInfo['mobile']??'199121223333',
  64. 'phone' => '18030142050',
  65. 'lng' => (float)$post['long'] ?? '118.134343',
  66. 'lat' => (float)$post['lat'] ?? '24.491566',
  67. 'coordinate_type' => 0,
  68. ];
  69. $cargo = [
  70. 'goods_value' => $cargoInfo['totalPrice'], //总价格 元
  71. 'goods_weight' => $cargoInfo['totalWeight'], //总重量 kg
  72. 'cargo_first_class' => '鲜花',
  73. 'cargo_second_class' => '鲜花',
  74. ];
  75. $orderInfo = [
  76. 'is_direct_delivery' => 0,//闪送只能为1,只能直拿直送
  77. ];
  78. $shop = [
  79. 'wxa_path' => '/shop',
  80. 'img_url' => 'http://www.baidu.com/test.png',
  81. 'goods_name' => '鲜花',
  82. 'goods_count' => count($ghsItemInfo),
  83. ];
  84. $res = MiniExpressService::preAddOrder($expressId, $shop_no, $shop_order_id, $openid, $sender, $receiver, $cargo, $orderInfo, $shop);
  85. util::success(['fee' => $res['fee']]);
  86. }
  87. //根据订单号发货
  88. public function actionAddOrder()
  89. {
  90. $post = Yii::$app->request->post();
  91. $expressId = $post['expressId'] ?? 0;// 快递ID
  92. $orderSn = $post['orderSn'] ?? '';
  93. }
  94. }