Explorar el Código

判断是否已下单时间过了两小时,并且师傅暂未上门,距离预约时间两小时以上-用户直接退款

whitefang hace 1 año
padre
commit
b823266c33
Se han modificado 2 ficheros con 37 adiciones y 1 borrados
  1. 36 0
      app/api/logic/ServiceOrderLogic.php
  2. 1 1
      app/common/command/QueryRefund.php

+ 36 - 0
app/api/logic/ServiceOrderLogic.php

@@ -5,9 +5,12 @@ namespace app\api\logic;
 use app\adminapi\service\DistributeLeafletsService;
 use app\common\enum\GoodsEnum;
 use app\common\enum\PayEnum;
+use app\common\enum\RefundEnum;
 use app\common\enum\WorkEnum;
+use app\common\enum\YesNoEnum;
 use app\common\logic\BaseLogic;
 use app\common\logic\PaymentLogic;
+use app\common\logic\RefundLogic;
 use app\common\model\coupon\UserCoupon;
 use app\common\model\dict\DictData;
 use app\common\model\goods\Goods;
@@ -822,6 +825,39 @@ class ServiceOrderLogic extends BaseLogic
             }
             $work->refund_approval = 1;
             $work->save();
+
+            //判断是否已下单时间过了两小时,并且师傅暂未上门,距离预约时间两小时以上
+            if(($order['pay_time']+7200)>time() and $work['work_status']<4 and ($work['appointment_time']-7200)>time()){
+                //生成退款订单
+                \app\common\model\recharge\RechargeOrder::update([
+                    'id' => $order['id'],
+                    'refund_status' => YesNoEnum::YES,
+                ]);
+
+                // 生成退款记录
+                $recordSn = generate_sn(RefundRecord::class, 'sn');
+                $record = RefundRecord::create([
+                    'sn' => $recordSn,
+                    'user_id' => $order['user_id'],
+                    'order_id' => $order['id'],
+                    'order_sn' => $order['sn'],
+                    'order_type' => RefundEnum::ORDER_TYPE_ORDER,
+                    'order_amount' => $order['order_amount'],
+                    'refund_amount' => $order['order_amount'],
+                    'refund_type' => RefundEnum::TYPE_ADMIN,
+                    'transaction_id' => $order['transaction_id'] ?? '',
+                    'refund_way' => RefundEnum::getRefundWayByPayWay($order['pay_way']),
+                ]);
+
+                //更新工单状态
+                ServiceWork::update([
+                    'id'=>$order['work_id'],
+                    'service_status'=>5
+                ]);
+
+                // 退款
+                RefundLogic::refund($order, $record['id'], $order['order_amount'], 1);
+            }
             Db::commit();
         }
         catch (\Exception $e) {

+ 1 - 1
app/common/command/QueryRefund.php

@@ -195,7 +195,6 @@ class QueryRefund extends Command
         //更新工单退款状态以及处理工程师金额和物业金额
         $order = RechargeOrder::where('id',$order_id)->findOrEmpty();
         $work = ServiceWork::where('id',$order->work_id)->findOrEmpty();
-        Log::write($work->toArray());
         if(!$work->isEmpty()){
             if(($work->work_pay_status == '1' || $work->work_pay_status == '2') and $work->service_status != '5' and $work->work_status != '9'){
                 //工程师余额变动
@@ -222,6 +221,7 @@ class QueryRefund extends Command
                     ]);
                 }
             }
+            $work->refund_approval = 2;
             $work->service_status = 5;
             $work->work_status = 9;
             $work->save();