ExpressController.php 2.9 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495
  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 = 1; //与快递签约时的门店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'=>$shopInfo['long']??'',
  51. 'lat'=>$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']??'',
  60. 'lng'=>$post['receiveLong']??'',
  61. 'lat'=>$post['receiveLat']??'',
  62. 'coordinate_type'=>0,
  63. ];
  64. $cargo = [
  65. 'goods_value'=>$cargoInfo['totalPrice'], //总价格 元
  66. 'goods_weight'=>$cargoInfo['totalWeight'], //总重量 kg
  67. 'cargo_first_class'=>'鲜花',
  68. 'cargo_second_class'=>'鲜花',
  69. ];
  70. $orderInfo = [];
  71. $shop = [
  72. 'wxa_path'=>'/shop',
  73. 'img_url'=>'http://www.baidu.com/test.png',
  74. 'goods_name'=>'鲜花',
  75. 'goods_count'=>count($ghsItemInfo),
  76. ];
  77. $res = MiniExpressService::preAddOrder($expressId,$shop_no,$shop_order_id,$openid,$sender,$receiver,$cargo,$orderInfo,$shop);
  78. util::success(['fee'=>$res['fee']]);
  79. }
  80. //
  81. }