lizhen_gitee 11 ماه پیش
والد
کامیت
4e5504de0a
3فایلهای تغییر یافته به همراه74 افزوده شده و 1 حذف شده
  1. 72 0
      application/api/controller/Wenzhen.php
  2. 1 1
      application/api/controller/doctor/Wenzhen.php
  3. 1 0
      application/extra/site.php

+ 72 - 0
application/api/controller/Wenzhen.php

@@ -452,4 +452,76 @@ class Wenzhen extends Api
 
         $this->success();
     }
+
+    //用户发起退珍
+    public function tuizhen(){
+        $apilimit = $this->apiLimit();
+        if(!$apilimit){
+            $this->error('操作频繁');
+        }
+
+        //订单详情
+        $order_id = input('order_id',0);
+        $wenzhen_order = Db::name('wenzhen_order')->where('user_id',$this->auth->id)->where('id',$order_id)->find();
+        if(empty($wenzhen_order)){
+            $this->error('不存在的订单');
+        }
+
+        //仅限视频订单
+        if($wenzhen_order['ordertype'] == 1){
+            $this->error('图文问诊不能退诊');
+        }
+
+        //状态限制
+        if(!in_array($wenzhen_order['status'],[10,20])){
+            $this->error('当前订单不能退诊');
+        }
+
+        //超过支付时间一小时不能退
+        if( time() - $wenzhen_order['pay_time'] > 3600){
+            $this->error('支付超过一小时,不能退诊');
+        }
+
+        //修改订单
+        $nowtime = time();
+        $update = [
+            'status'        => 13,
+            'cancel_time'   => $nowtime,
+            'cancel_reason' => '用户付款后退诊',
+            'finish_time'   => $nowtime,
+        ];
+        Db::startTrans();
+
+        //余额支付的直接退款
+        if($wenzhen_order['pay_type'] == 'wallet'){
+
+            //用户加钱
+            $logtype = $wenzhen_order['ordertype'] == 1 ? 13 : 14;
+
+            $wenzhen_refund_bili = config('site.payorder_userrefund_bili') ?: 70;
+            $refund_price = bcdiv(bcmul($wenzhen_order['total_fee'],$wenzhen_refund_bili,2),100,2);
+
+            $rs_wallet = model('wallet')->lockChangeAccountRemain($wenzhen_order['user_id'],'money',$refund_price,$logtype,$remark='用户问诊退珍','wenzhen_order',$order_id);
+            if($rs_wallet['status'] === false){
+                Db::rollback();
+                $this->error($rs_wallet['msg']);
+            }
+
+            //订单退款参数
+            $update['refund_price']  = $refund_price;
+            $update['refund_status'] = 3;
+        }else{
+            //订单退款参数
+            $update['refund_status'] = 1; //异步退款
+        }
+
+        $update_rs = Db::name('wenzhen_order')->where('id',$order_id)->where('status',$wenzhen_order['status'])->update($update);
+        if(!$update_rs){
+            Db::rollback();
+            $this->error('退诊失败');
+        }
+
+        Db::commit();
+        $this->success(1,'退珍成功');
+    }
 }

+ 1 - 1
application/api/controller/doctor/Wenzhen.php

@@ -177,7 +177,7 @@ class Wenzhen extends Apic
 
             //用户加钱
             $logtype = $wenzhen_order['ordertype'] == 1 ? 13 : 14;
-            $rs_wallet = model('wallet')->lockChangeAccountRemain($wenzhen_order['user_id'],'money',$wenzhen_order['total_fee'],$logtype,$remark='问诊退珍','wenzhen_order',$order_id);
+            $rs_wallet = model('wallet')->lockChangeAccountRemain($wenzhen_order['user_id'],'money',$wenzhen_order['total_fee'],$logtype,$remark='医生问诊退珍','wenzhen_order',$order_id);
             if($rs_wallet['status'] === false){
                 Db::rollback();
                 $this->error($rs_wallet['msg']);

+ 1 - 0
application/extra/site.php

@@ -96,4 +96,5 @@ return array (
   'accept_textorder_autofinish_minute' => '2880',
   'index_jiuyipeizhen' => '/uploads/20240428/85e048031609eb5fcb29d0b901a5c82c.png',
   'index_hulipeihu' => '/uploads/20240428/85e048031609eb5fcb29d0b901a5c82c.png',
+  'payorder_userrefund_bili' => '70',
 );