123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392 |
- <?php
- namespace app\api\controller;
- use app\common\controller\UserApi;
- use app\common\model\Payment;
- use app\common\model\UserCoupon;
- use app\service\Pet;
- use app\service\UserOrderService;
- use app\UserException;
- use app\validate\UserOrderValidate;
- use think\Db;
- use think\Exception;
- use app\common\model\UserOrder as UO;
- /**
- * 用户端订单接口
- */
- 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());
- }
- }
- /**
- * 提交订单
- * @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专车
- * @param string pay_type 1余额2微信
- *
- * @ApiReturnParams (name=total_amount,type=string,description=总价)
- */
- public function submit(UserOrderService $userOrder){
- $data=input();
- $this->validate($data,UserOrderValidate::class);
- $user=$this->auth->getUser();
- $this->validate($data,UserOrderValidate::$freight);
- $this->validate($data,[
- 'pay_type'=>['require','in:1,2'],
- ]);
- Db::startTrans();
- $data=$userOrder->setUser($user)
- ->import($data)
- ->setCoupon($data['coupon_id']??null)
- ->prepare();
- $data['user_id']=$user['id'];
- $order=new \app\common\model\UserOrder();
- $order->allowField(true)->save($data);
- if($order['coupon_id']){
- UserCoupon::where('id',$order['coupon_id'])->save(['is_used'=>1]);
- }
- $params=$order->pay();
- Db::commit();
- $this->success('',$params);
- }
- /**
- * 订单列表
- * @ApiParams(name=status,required=false,description="1待支付2进行中3已完成4已取消")
- * @ApiParams(name=page,required=false,description="页码,默认1")
- * @ApiParams(name=limit,required=false,description="每页数量,默认10")
- * @ApiReturnParams(name=id,type=string,description=订单id)
- * @ApiReturnParams(name=from_addr[name],type=string,description=取件人)
- * @ApiReturnParams(name=from_addr[mobile],type=string,description=取件人手机号)
- * @ApiReturnParams(name=from_addr[address],type=string,description=取件人地址)
- * @ApiReturnParams(name=to_addr[name],type=string,description=送件人)
- * @ApiReturnParams(name=to_addr[mobile],type=string,description=送件人手机号)
- * @ApiReturnParams(name=to_addr[address],type=string,description=送件人地址)
- * @ApiReturnParams(name=pet_category,type=string,description=宠物类别)
- * @ApiReturnParams(name=spec,type=string,description=规格)
- * @ApiReturnParams(name=real_amount,type=string,description=金额)
- */
- public function list(){
- $data=input();
- $user=$this->auth->getUser();
- $query=$user->orders()->order('id','desc');
- if(!is_null($data['status'])){
- switch ($data['status']) {
- case 1:
- $query->where('status', UO::STATUS_WAIT_PAY);
- break;
- case 2:
- $query->whereBetween('status',[UO::STATUS_WAIT_GET,UO::STATUS_GIVED]);
- break;
- case 3:
- $query->whereBetween('status',UO::STATUS_COMPLETE);
- break;
- case 4:
- $query->whereBetween('status',UO::STATUS_CANCEL);
- break;
- }
- }
- $orders=$query->paginate($data['limit']?:10);
- $this->success('',$orders);
- }
- /**
- * 订单详情
- * @ApiParams (name=id,decription=订单ID)
- * @ApiReturnParams(name=id,type=string,description=订单id)
- * @ApiReturnParams(name=from_addr[name],type=string,description=取件人)
- * @ApiReturnParams(name=from_addr[mobile],type=string,description=取件人手机号)
- * @ApiReturnParams(name=from_addr[address],type=string,description=取件人地址)
- * @ApiReturnParams(name=to_addr[name],type=string,description=送件人)
- * @ApiReturnParams(name=to_addr[mobile],type=string,description=送件人手机号)
- * @ApiReturnParams(name=to_addr[address],type=string,description=送件人地址)
- * @ApiReturnParams(name=pet_category,type=string,description=宠物类别)
- * @ApiReturnParams(name=spec,type=string,description=规格)
- * @ApiReturnParams(name=real_amount,type=string,description=金额)
- * @ApiReturnParams(name=num,type=string,description=宠物数量)
- * @ApiReturnParams(name=pick_up,type=string,description=0不接不送1接宠2送宠4接送宠)
- * @ApiReturnParams(name=has_cage,type=string,description=有无宠具)
- * @ApiReturnParams(name=weight,type=string,description=重量)
- * @ApiReturnParams(name=piece,type=string,description=件数)
- * @ApiReturnParams(name=remark,type=string,description=备注)
- * @ApiReturnParams(name=images,type=string,description=照片)
- * @ApiReturnParams(name=coupon_amount,type=string,description=优惠金额)
- * @ApiReturnParams(name=no,type=string,description=订单编号)
- * @ApiReturnParams(name=created_at,type=string,description=下单时间)
- * @ApiReturnParams(name=pay_type,type=string,description=支付方式1余额2微信)
- * @ApiReturnParams(name=protect_amount,type=string,description=安心保金额)
- * @ApiReturnParams(name=protect_max,type=string,description=安心保保多少)
- * @ApiReturnParams (name=status,description="0待支付1待接单10取宠中15运输中20已完成30已结算40已取消")
- * @ApiReturnParams (name=cancel_at,description="用户取消时间")
- * @ApiReturnParams (name=refund_at,description="退款时间")
- * @ApiReturnParams (name=agree_date,description="取宠时间日期")
- * @ApiReturnParams (name=agree_time,description="取宠具体时间")
- * @ApiReturnParams (name=freight,description="fast快车air空运special专车")
- * @ApiReturnParams (name=refund_status,description="-1未申请0审核中1审核通过2驳回")
- * @ApiReturnParams (name=refund_amount,description="退款金额")
- * @ApiReturnParams (name=refund_images,description="退款图片")
- * @ApiReturnParams (name=refund_reason,description="退款原因")
- * @ApiReturnParams (name=refund_at,description="退款时间")
- */
- public function detail(){
- $data=input();
- $this->validate($data,[
- 'id'=>['require','integer','gt:0'],
- ]);
- $user=$this->auth->getUser();
- $order=$user->orders()->findOrFail($data['id']);
- return $order;
- }
- /**
- * 托运详情
- * @ApiParams (name=id,decription=订单ID)
- * @ApiReturnParams (name=addr,description="取宠地址")
- * @ApiReturnParams (name=created_at,description="时间")
- * @ApiReturnParams (name=status,description="状态")
- * @ApiReturnParams (name=txt,description="描述")
- * @ApiReturnParams (name=media,description="视频")
- */
- public function send_detail(){
- $data=input();
- $this->validate($data,[
- 'id'=>['require']
- ]);
- $user=$this->auth->getUser();
- $order=$user->orders()->findOrFail($data['id']);
- $this->success('',$order->send_detail);
- }
- /**
- * 取消订单
- * @ApiParams (name=id,decription=订单ID)
- */
- public function cancel(){
- $data=input();
- $this->validate($data,[
- 'id'=>['require']
- ]);
- $user=$this->auth->getUser();
- Db::startTrans();
- $order=$user->orders()->lock(true)->findOrFail($data['id']);
- $order->cancel();
- Db::commit();
- $this->success();
- }
- /**
- * 继续支付
- * @ApiParams (name=id,decription=订单ID)
- */
- public function pay(){
- $data=input();
- $this->validate($data,[
- 'id'=>['require']
- ]);
- $user=$this->auth->getUser();
- Db::startTrans();
- $order=$user->orders()->lock(true)->findOrFail($data['id']);
- $params=$order->pay();
- Db::commit();
- $this->success('',$params);
- }
- /**
- * 确认完成
- * @ApiParams (name=id,decription=订单ID)
- */
- public function complete(){
- $data=input();
- $this->validate($data,[
- 'id'=>['require']
- ]);
- $user=$this->auth->getUser();
- Db::startTrans();
- $order=$user->orders()->lock(true)->findOrFail($data['id']);
- $params=$order->complete();
- Db::commit();
- $this->success('',$params);
- }
- /**
- * 获取申请退款信息
- * @ApiParams (name=id,decription=订单ID)
- */
- public function refund_info(){
- $data=input();
- $this->validate($data,[
- 'id'=>['require'],
- ]);
- $user=$this->auth->getUser();
- $order=$user->orders()->findOrFail($data['id']);
- $res=[];
- $res['fee']=[
- 'land'=>config('site.order_refund_land'),
- 'air'=>config('site.order_refund_air'),
- ];
- $res['refund_amount']=$order->refund_money;
- $this->success('',$res);
- }
- /**
- * 申请退款
- * @ApiParams (name=id,description=订单ID)
- * @ApiParams (name=reason,description=原因必须)
- * @ApiParams (name=images,description=图片可选)
- */
- public function refund(){
- $data=input();
- $this->validate($data,[
- 'id'=>['require'],
- 'reason'=>['require','max:200'],
- 'images'=>['array'],
- ]);
- $user=$this->auth->getUser();
- Db::startTrans();
- $order=$user->orders()->lock(true)->findOrFail($data['id']);
- $order->refund($data['reason'],$data['images']);
- Db::commit();
- $this->success();
- }
- /**
- * 删除订单
- * @ApiParams (name=id,decription=订单ID)
- */
- public function delete(){
- $data=input();
- $this->validate($data,[
- 'id'=>['require'],
- ]);
- $user=$this->auth->getUser();
- $order=$user->orders()->findOrFail($data['id']);
- $order->remove();
- $this->success();
- }
- }
|