123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123 |
- <?php
- namespace app\api\controller;
- use app\common\controller\UserApi;
- use app\service\Pet;
- use app\service\UserOrderService;
- use app\UserException;
- use app\validate\UserOrderValidate;
- use think\Exception;
- /**
- * 用户端订单接口
- */
- class UserOrder extends UserApi
- {
- protected $noNeedLogin = ['category','spec','protect'];
- protected $noNeedRight = '*';
- /**
- * 常用地址
- * @ApiReturnParams (name=id,description=id)
- * @ApiReturnParams (name=name,description=姓名)
- * @ApiReturnParams (name=mobile,description=手机号)
- * @ApiReturnParams (name=address,description=地址)
- * @ApiReturnParams (name=city,description=城市)
- */
- public function address(){
- $user=$this->auth->getUser();
- $this->success('',$user->address()->order('id','desc')->select());
- }
- /**
- * 宠物类别
- * @ApiReturnParams (name=id,description=id)
- * @ApiReturnParams (name=name,description=名称)
- */
- public function category(Pet $pet){
- $this->success('',$pet::category());
- }
- /**
- * 宠物规格
- * @ApiReturnParams (name=id,description=id)
- * @ApiReturnParams (name=name,description=名称)
- * @ApiReturnParams (name=weight,description=重量范围)
- */
- public function spec(Pet $pet){
- $this->success('',$pet::spec());
- }
- /**
- * 宠物保
- * @ApiReturnParams (name=id,description=id)
- * @ApiReturnParams (name=name,description=名称)
- * @ApiReturnParams (name=max,description=最高保多少)
- * @ApiReturnParams (name=price,description=价格)
- */
- public function protect(Pet $pet){
- $this->success('',$pet::protect());
- }
- /**
- * 预下单
- * @ApiMethod (POST)
- * @param array from_addr 必须,取宠地址信息
- * @param string from_addr[longitude] 必须,取宠地址经度
- * @param string from_addr[latitude] 必须,取宠地址纬度
- * @param string from_addr[name] 必须,取宠人
- * @param string from_addr[mobile] 必须,取宠手机号
- * @param string from_addr[city] 必须,取宠城市
- * @param string from_addr[address] 必须,取宠详细地址
- * @param array to_addr 必须,收宠地址信息
- * @param string to_addr[longitude] 必须,收宠地址经度
- * @param string to_addr[latitude] 必须,收宠地址纬度
- * @param string to_addr[name] 必须,收宠人
- * @param string to_addr[mobile] 必须,收宠手机号
- * @param string to_addr[city] 必须,收宠城市
- * @param string to_addr[address] 必须,收宠详细地址
- * @param string pick_up 0无1上门接2上门送4上门接送
- * @param string agree_time 取宠时间
- * @param string pet_category 宠物分类ID
- * @param string num 宠物数量
- * @param string weight 宠物重量
- * @param string spec 宠物规格
- * @param string piece 宠物件数
- * @param string has_cage 有无宠具0无1有
- * @param string remark 备注信息
- * @param string images 照片
- * @param string protect_id 安心保ID
- * @param string coupon_id 优惠券ID
- * @param string freight fast快车air空运special专车
- *
- * @ApiReturnParams (name=total_amount,type=string,description=总价)
- * @ApiReturnParams (name=coupon_amount,type=string,description=优惠券优惠金额)
- * @ApiReturnParams (name=real_amount,type=string,description=实付总价)
- * @ApiReturnParams (name=freights[0][price],type=string,description=实际价格)
- * @ApiReturnParams (name=freights[0][total_price],type=string,description=总价)
- * @ApiReturnParams (name=freights[0][type],type=string,description=类型:fast快车air空运special专车)
- * @ApiReturnParams (name=freights[0][coupon][0][amount],type=string,description=优惠券优惠额度)
- * @ApiReturnParams (name=freights[0][coupon][0][end_time],type=string,description=优惠券过期时间)
- * @ApiReturnParams (name=freights[0][coupon][0][id],type=string,description=优惠券id)
- * @ApiReturnParams (name=freights[0][coupon][0][is_used],type=string,description=优惠券实付已使用)
- * @ApiReturnParams (name=freights[0][coupon][0][max],type=string,description=优惠券满多少可以减)
- * @ApiReturnParams (name=freights[0][coupon][0][selected],type=string,description=实付是选中的优惠券)
- * @ApiReturnParams (name=freights[0][coupon][0][start_time],type=string,description=优惠券开始时间)
- * @ApiReturnParams (name=freights[0][coupon][0][type],type=string,description="优惠券类型,1代金券2满减券3折扣券4新用户下单券")
- * @ApiReturnParams (name=freights[0][coupon][0][type_desc],type=string,description=优惠券类型)
- */
- public function prepare(UserOrderService $userOrder){
- $data=input();
- $this->validate($data,UserOrderValidate::class);
- $user=$this->auth->getUser();
- if(!empty($data['freight'])){
- $this->validate($data,UserOrderValidate::$freight);
- }
- try {
- $data=$userOrder->setUser($user)
- ->import($data)
- ->setCoupon($data['coupon_id']??null)
- ->prepare();
- $this->success('',$data);
- }catch (UserException $e){
- $this->error($e->getMessage());
- }
- }
- }
|