ExpressController.php 3.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899
  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();
  20. util::success($data);
  21. }
  22. //配送费预估
  23. public function actionPreAddOrder()
  24. {
  25. $post = Yii::$app->request->post();
  26. $expressId = $post['expressId']??0;
  27. $ghsItemInfo = $post['itemInfo']??'';
  28. if(empty($ghsItemInfo)){
  29. util::fail('请选择花材');
  30. }
  31. $ghsItemInfo = json_decode($ghsItemInfo,true); // [{productId:0,itemPrice:1,bigNum:1,smallNum:0}]
  32. //计算总价格,总重量
  33. $cargoInfo = ProductService::groupCargo($ghsItemInfo);
  34. $shop_order_id = time();
  35. $shop_no = ""; //与快递签约时的门店ID(应该是固定的)
  36. $openid = $this->admin['miniOpenId'];
  37. //客户id
  38. $customId = $post['customId']??0;
  39. //获取客户name
  40. $customInfo = CustomService::getCustomInfo($customId);
  41. CustomClass::valid($customInfo, $this->sjId);
  42. //当前门店的地址信息
  43. $shopInfo = ShopService::getById($this->shopId);
  44. $sender =[
  45. 'name'=>$shopInfo['shopName'],
  46. 'city'=>$shopInfo['city']??'',
  47. 'address'=>$shopInfo['address']??'',
  48. 'address_detail'=>$shopInfo['floor']??'',
  49. 'phone'=>$shopInfo['telephone']??'',
  50. 'lng'=>(float)$shopInfo['long']??'',
  51. 'lat'=>(float)$shopInfo['lat']??'',
  52. 'coordinate_type'=>0,
  53. ];
  54. $receiver = [
  55. 'name'=>$customInfo['name'],
  56. 'city'=>$post['receiveCity']??'',
  57. 'address'=>$post['receiveAddress']??'',
  58. 'address_detail'=>$post['receiveFloor']??'',
  59. //'phone'=>$customInfo['mobile']??'199121223333',
  60. 'phone'=>'18030142050',
  61. 'lng'=>(float)$post['receiveLong']??'118.134343',
  62. 'lat'=>(float)$post['receiveLat']??'24.491566',
  63. 'coordinate_type'=>0,
  64. ];
  65. $cargo = [
  66. 'goods_value'=>$cargoInfo['totalPrice'], //总价格 元
  67. 'goods_weight'=>$cargoInfo['totalWeight'], //总重量 kg
  68. 'cargo_first_class'=>'鲜花',
  69. 'cargo_second_class'=>'鲜花',
  70. ];
  71. $orderInfo = [
  72. 'is_direct_delivery'=>1,//设置应该为1,只能直拿直送
  73. ];
  74. $shop = [
  75. 'wxa_path'=>'/shop',
  76. 'img_url'=>'http://www.baidu.com/test.png',
  77. 'goods_name'=>'鲜花',
  78. 'goods_count'=>count($ghsItemInfo),
  79. ];
  80. $res = MiniExpressService::preAddOrder($expressId,$shop_no,$shop_order_id,$openid,$sender,$receiver,$cargo,$orderInfo,$shop);
  81. util::success(['fee'=>$res['fee']]);
  82. }
  83. //
  84. }