xxxrrrdddd преди 3 години
родител
ревизия
531fd568de
променени са 6 файла, в които са добавени 1182 реда и са изтрити 162 реда
  1. 105 11
      application/api/controller/UserOrder.php
  2. 94 7
      application/common/model/UserOrder.php
  3. 4 4
      application/common/model/UserOrderLog.php
  4. 2 0
      application/extra/site.php
  5. 975 140
      public/api.html
  6. 2 0
      public/index.php

+ 105 - 11
application/api/controller/UserOrder.php

@@ -176,13 +176,7 @@ class UserOrder extends UserApi
         if($order['coupon_id']){
             UserCoupon::where('id',$order['coupon_id'])->save(['is_used'=>1]);
         }
-        if($order['pay_type']==1){
-            $params='';
-            $user->money(bcsub(0,$order['real_amount'],2),$user['id'],"订单[{$order['no']}]付款");
-            \app\common\model\UserOrder::payed(['id'=>$order['id']]);
-        }else {
-            $params = Payment::pay($user, $order['real_amount'], UserOrder::class, 'payed', ['id' => $order['id']]);
-        }
+        $params=$order->pay();
         Db::commit();
         $this->success('',$params);
     }
@@ -212,7 +206,7 @@ class UserOrder extends UserApi
                     $query->where('status', UO::STATUS_WAIT_PAY);
                     break;
                 case 2:
-                    $query->whereBetween('status',[UO::STATUS_WAIT_GET,UO::STATUS_WAIT_SENDING]);
+                    $query->whereBetween('status',[UO::STATUS_WAIT_GET,UO::STATUS_GIVED]);
                     break;
                 case 3:
                     $query->whereBetween('status',UO::STATUS_COMPLETE);
@@ -276,6 +270,7 @@ class UserOrder extends UserApi
     /**
      * 托运详情
      * @ApiParams (name=id,decription=订单ID)
+     * @ApiReturnParams (name=addr,description="取宠地址")
      * @ApiReturnParams (name=created_at,description="时间")
      * @ApiReturnParams (name=status,description="状态")
      * @ApiReturnParams (name=txt,description="描述")
@@ -288,11 +283,110 @@ class UserOrder extends UserApi
         ]);
         $user=$this->auth->getUser();
         $order=$user->orders()->findOrFail($data['id']);
-        $log=$order->log()->select();
 
-        $res['addr']=$order['to_addr']['address'];
-        $res['log']=$log;
+        $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();
+    }
 }

+ 94 - 7
application/common/model/UserOrder.php

@@ -3,9 +3,17 @@
 namespace app\common\model;
 
 use think\Model;
+use traits\model\SoftDelete;
 
+/**
+ *@property array send_detail 运送详情
+ *@property float cal_refund 退款手续费
+ *@property float refund_money 退款金额
+ */
 class UserOrder extends Model
 {
+    use SoftDelete;
+    protected $deleteTime='deleted_at';
     protected $type=[
         'get_time'=>'array',
         'has_cage'=>'boolean',
@@ -23,19 +31,23 @@ class UserOrder extends Model
     const STATUS_WAIT_PAY=0;
     const STATUS_WAIT_GET=1;
     const STATUS_WAIT_GETTING=10;
-    const STATUS_WAIT_SENDING=15;
-    const STATUS_WAIT_GIVING=17;
-    const STATUS_COMPLETE=20;
-    const STATUS_SET=30;
-    const STATUS_CANCEL=40;
+    const STATUS_SENDING=20;
+    const STATUS_GIVING=30;
+    const STATUS_GIVED=40;
+    const STATUS_COMPLETE=50;
+    const STATUS_SET=60;
+    const STATUS_REFUND=70;
+    const STATUS_CANCEL=80;
     public static $statusList=[
         self::STATUS_WAIT_PAY=>'待支付',
         self::STATUS_WAIT_GET=>'待接单',
         self::STATUS_WAIT_GETTING=>'已接单,取宠中',
-        self::STATUS_WAIT_SENDING=>'已取宠,运输中',
-        self::STATUS_WAIT_GIVING=>'送宠中',
+        self::STATUS_SENDING=>'已取宠,运输中',
+        self::STATUS_GIVING=>'送宠中',
+        self::STATUS_GIVED=>'送宠完成,待用户确认',
         self::STATUS_COMPLETE=>'已完成,待结算',
         self::STATUS_SET=>'已结算',
+        self::STATUS_REFUND=>'退款中',
         self::STATUS_CANCEL=>'已取消',
     ];
 
@@ -72,6 +84,81 @@ class UserOrder extends Model
     public function getImagesAttr($v){
         return array_filter(json_decode($v));
     }
+    public function cancel(){
+        if($this['status']!==self::STATUS_WAIT_PAY){
+            throw_user('状态有误');
+        }
+        $this['status']=self::STATUS_CANCEL;
+        $this['cancel_at']=time();
+        $this->save();
+        if($this['coupon_id']){
+            UserCoupon::where('id',$this['coupon_id'])->save(['is_used'=>0]);
+        }
+    }
+    public function pay(){
+        if($this['status']!=self::STATUS_WAIT_PAY){
+            throw_user('状态有误');
+        }
+        if($this['pay_type']==1){
+            $params='';
+            $this->user->money(bcsub(0,$this['real_amount'],2),$this['user_id'],"订单[{$this['no']}]付款");
+            self::payed(['id'=>$this['id']]);
+        }else {
+            $params = Payment::pay($this->user, $this['real_amount'], self::class, 'payed', ['id' => $this['id']]);
+        }
+        return $params;
+    }
+    public function complete(){
+        if($this['status']!=self::STATUS_GIVED){
+            throw_user('非已送达状态无法确认完成');
+        }
+        $this['status']=self::STATUS_COMPLETE;
+        if(!$this->save()){
+            throw_user('保存状态失败');
+        }
+    }
+    public function refund($reason,$images){
+        if(!in_array($this['status'],[self::STATUS_WAIT_GET,self::STATUS_WAIT_GETTING,self::STATUS_SENDING])){
+            throw_user('当前无法申请退款');
+        }
+        $this['refund_reason']=$reason;
+        $this['refund_amount']=$this->refund_money;
+        $this['refund_images']=$images;
+        $this['status']=self::STATUS_REFUND;
+        $this['refund_status']=self::REFUND_STATUS_DEFAULT;
+        if(!$this->save()){
+            throw_user('保存失败');
+        }
+    }
+    public function getCalRefundAttr($v,$data){
+        if($this['freight']==self::FREIGHT_AIR){
+            $fee=bcdiv(config('site.order_refund_air'),100,4);
+        }else{
+            $fee=bcdiv(config('site.order_refund_land'),100,4);
+        }
+        $amount=bcmul($this['real_amount'],$fee);
+        return $amount;
+    }
+    public function getRefundMoneyAttr($v,$data){
+        return bcsub($this['real_amount'],$this->cal_refund);
+    }
+    public function getSendDetailAttr(){
+        $log=$this->log()->select();
+        $res['addr']=$this['to_addr']['address'];
+        $res['log']=$log;
+        return $res;
+    }
+    public function remove(){
+        if(!in_array($this['status'],[self::STATUS_CANCEL])){
+            throw_user('非已取消订单无法删除');
+        }
+        $this->delete();
+    }
+
+
+
+
+
 
 
 

+ 4 - 4
application/common/model/UserOrderLog.php

@@ -8,15 +8,15 @@ class UserOrderLog extends Model
 {
     public static $status=[
         UserOrder::STATUS_WAIT_GETTING=>'已接单正在取宠',
-        UserOrder::STATUS_WAIT_SENDING=>'已取宠正在运输',
-        UserOrder::STATUS_WAIT_GIVING=>'宠物已启程,请关注收宠',
+        UserOrder::STATUS_SENDING=>'已取宠正在运输',
+        UserOrder::STATUS_GIVING=>'宠物已启程,请关注收宠',
         UserOrder::STATUS_COMPLETE=>'订单已完成',
         0=>'状态更新',
     ];
     public static $txt=[
         UserOrder::STATUS_WAIT_GETTING=>'请您保持电话畅通方便与您联系',
-        UserOrder::STATUS_WAIT_SENDING=>'正在快马加鞭运输中请您耐心等待',
-        UserOrder::STATUS_WAIT_GIVING=>'感谢您的支持正在努力送宠中',
+        UserOrder::STATUS_SENDING=>'正在快马加鞭运输中请您耐心等待',
+        UserOrder::STATUS_GIVING=>'感谢您的支持正在努力送宠中',
         UserOrder::STATUS_COMPLETE=>'订单已完成服务永不止哦~~~',
         0=>'',
     ];

+ 2 - 0
application/extra/site.php

@@ -47,4 +47,6 @@ return array (
   'sender_appserret' => '22',
   'mch_id' => 'asda',
   'mch_secret' => 'nbasssjjjjsssssssssssswwwwwwwwww',
+  'order_refund_land' => '20',
+  'order_refund_air' => '30',
 );

Файловите разлики са ограничени, защото са твърде много
+ 975 - 140
public/api.html


+ 2 - 0
public/index.php

@@ -19,5 +19,7 @@ if (!is_file(APP_PATH . 'admin/command/Install/install.lock')) {
     exit;
 }
 
+bcscale(2);
+
 // 加载框架引导文件
 require __DIR__ . '/../thinkphp/start.php';

Някои файлове не бяха показани, защото твърде много файлове са промени