ExpressController.php 3.8 KB

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