You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
124 lines
4.2 KiB
124 lines
4.2 KiB
<?php
|
|
|
|
namespace App\Controller\v3;
|
|
|
|
use App\Constants\v3\ErrorCode;
|
|
use App\Controller\BaseController;
|
|
use App\Exception\ErrorCodeException;
|
|
use App\Request\v3\OrderOnlineDetailRequest;
|
|
use App\Request\v3\OrderOnlineRequest;
|
|
use App\Service\CouponServiceInterface;
|
|
use App\Service\v3\Interfaces\ShopCartServiceInterface;
|
|
use Hyperf\Di\Annotation\Inject;
|
|
use App\Service\v3\Interfaces\OrderOnlineServiceInterface;
|
|
use App\Service\v3\Interfaces\UserBindTelServiceInterface;
|
|
use App\Service\v3\Interfaces\AppointmentTimeServiceInterface;
|
|
use Psr\Http\Message\ResponseInterface;
|
|
use App\Model\v3\UserAddress;
|
|
|
|
class OrderOnlineController extends BaseController
|
|
{
|
|
/**
|
|
* @Inject
|
|
* @var UserBindTelServiceInterface
|
|
*/
|
|
protected $userBindTelService;
|
|
/**
|
|
* @Inject
|
|
* @var CouponServiceInterface
|
|
*/
|
|
protected $couponService;
|
|
/**
|
|
* @Inject
|
|
* @var AppointmentTimeServiceInterface
|
|
*/
|
|
protected $appointmentTimeService;
|
|
|
|
/**
|
|
* @Inject
|
|
* @var OrderOnlineServiceInterface
|
|
*/
|
|
protected $orderOnlineService;
|
|
|
|
/**
|
|
* @Inject
|
|
* @var ShopCartServiceInterface
|
|
*/
|
|
protected $shopCartService;
|
|
|
|
/*
|
|
* 如果没有绑手机号去绑定页面
|
|
* 收货地址接口
|
|
* 返回预约送达时间
|
|
* 商品数据接口
|
|
* 红包独立接口
|
|
* 配送费独立接口 可根据距离动态计算费用
|
|
* 增值服务接口
|
|
* */
|
|
public function review()
|
|
{
|
|
$params = $this->request->all();
|
|
//判断用户有没有绑定手机
|
|
// $telExists = $this->userBindTelService->check($params['user_id']);
|
|
// if(!$telExists){
|
|
// throw new ErrorCodeException(ErrorCode::NOT_BIND_TEL_ERROR);
|
|
// }
|
|
//获取用户收货地址
|
|
$res['address'] = UserAddress::query()->find(15);
|
|
//返回预约送达时间 数组
|
|
$res['appointment_time'] = $this->appointmentTimeService->do();
|
|
//
|
|
$res['store_list'] = $this->shopCartService->do();
|
|
//获取用户优惠券
|
|
$res['coupon'] = $this->couponService->getUserAvailableCoupons('',$params['user_id'],'',2,'','');
|
|
//获取配送费
|
|
$res['distribution_price'] = '5.0';
|
|
//增值服务接口
|
|
$res['value_added_service'] = [
|
|
'select' => 1,
|
|
'price' => 3.50
|
|
];
|
|
return $this->success($res);
|
|
}
|
|
|
|
/**
|
|
* 订单详情
|
|
* 1、主订单信息,用户配送信息(地址、姓名、电话、配送时间、配送类型)、基础信息(订单ID、订单编号、下单时间、订单金额、付款时间、支付方式、红包优惠、服务站电话、增值服务费)
|
|
* 2、子订单以及订单商品,按商户分组,有商户信息(ID、商户名、商户logo),商品信息(id、名字、封面、规格、tag、原价、售价、库存、总销、月销、是否失效、失效原因)
|
|
* @param OrderOnlineDetailRequest $request
|
|
* @return ResponseInterface
|
|
*/
|
|
public function detailByUser(OrderOnlineDetailRequest $request)
|
|
{
|
|
$params = $request->validated();
|
|
return $this->success(['detail' => $this->orderOnlineService->detailByUser($params['order_id'], $params['user_id'])]);
|
|
}
|
|
|
|
/**
|
|
* 下单并进行支付,返回支付参数
|
|
* 1、用户传参,用户地址ID,用于获取用户地址经纬度来计算配送费
|
|
* 2、用户传参,购物车IDs,去获取购物车里的商品详情
|
|
* 3、预约送达时间
|
|
* 4、优惠券IDs
|
|
* 5、订单总金额,用于校验比对
|
|
* 6、下单成功,请求支付
|
|
* @param OrderOnlineRequest $request
|
|
* @return ResponseInterface
|
|
*/
|
|
public function add(OrderOnlineRequest $request){
|
|
|
|
// 下单
|
|
$params = $request->validated();
|
|
$data = $this->orderOnlineService->do(
|
|
$params['market_id'],
|
|
$params['user_id'],
|
|
$params['user_address_id'],
|
|
explode(',', $params['cart_ids']),
|
|
$params['total_money'],
|
|
$params['delivery_time_note'],
|
|
explode(',', $params['coupon_ids'])
|
|
);
|
|
|
|
return $this->success(['data' => $data]);
|
|
}
|
|
}
|