liugc 10 месяцев назад
Родитель
Сommit
193ffaff39

+ 34 - 2
app/adminapi/logic/spare_part/SparePartLogic.php

@@ -18,6 +18,8 @@ namespace app\adminapi\logic\spare_part;
 use app\adminapi\logic\works\ServiceWorkLogic;
 use app\common\model\spare_part\SparePart;
 use app\common\logic\BaseLogic;
+use app\common\model\works\ServiceWork;
+use app\common\model\works\ServiceWorkSpare;
 use app\common\model\works\ServiceWorkSpareAudit;
 use think\facade\Db;
 
@@ -120,10 +122,13 @@ class SparePartLogic extends BaseLogic
     public static function examineSpare()
     {
         $tm = time() - 3 * 86400;
-        $spareAudits = ServiceWorkSpareAudit::where("create_time",'<', $tm)->where('status', 2)->select()->toArray();
+        $spareAudits = ServiceWorkSpare::where("create_time",'<', $tm)->whereIn('status', [0,2])->select()->toArray();
         foreach ($spareAudits as $spareAudit) {
             try {
-                ServiceWorkLogic::settlementSpare(['id' => $spareAudit['service_work_id'],  'status' => 3]);
+                ServiceWorkSpare::where('id', $spareAudit['id'])->update([
+                    'status' => 3
+                ]);
+                self::isExamineOk($spareAudit['service_work_id']);
             } catch (\Exception $e) {
                 self::setError($e->getMessage());
             }
@@ -131,4 +136,31 @@ class SparePartLogic extends BaseLogic
         return true;
     }
 
+
+    /**
+     * 是否都审核完成
+     * @return bool
+     * @author liugc <466014217@qq.com>
+     * @date 2025/5/27 15:10
+     */
+    public static function isExamineOk($service_work_id)
+    {
+        $tm = time() - 3 * 86400;
+        $count = ServiceWorkSpare::where("create_time",'<', $tm)->where("service_work_id",$service_work_id)->whereIn('status', [0,2])->count();
+        $serviceWorkInfo = ServiceWork::find($service_work_id);
+        if((int)$serviceWorkInfo['work_pay_status'] !== 3){
+            throw new \Exception('该工单非待结算状态');
+        }
+        // 是否所有配件审核完成
+        if($count == 0){
+            $serviceWorkInfo->user_confirm_status = 5;
+            $serviceWorkInfo->work_status = 7;
+            $serviceWorkInfo->work_pay_status = 1;
+            $serviceWorkInfo->save();
+        }
+        return true;
+    }
+
+
+
 }

+ 12 - 14
app/adminapi/logic/works/ServiceWorkLogic.php

@@ -14,6 +14,7 @@
 
 namespace app\adminapi\logic\works;
 
+use app\adminapi\logic\spare_part\SparePartLogic;
 use app\adminapi\logic\user\UserLogic;
 use app\api\logic\ServiceOrderLogic;
 use app\api\logic\UserCouponLogic;
@@ -889,25 +890,22 @@ class ServiceWorkLogic extends BaseLogic
     {
         Db::startTrans();
         try {
-            $serviceWorkInfo = ServiceWork::find($params['id']);
-            if((int)$serviceWorkInfo['work_pay_status'] !== 3){
-                throw new \Exception('该工单非待结算状态');
-            }
-            $spareAudit = ServiceWorkSpareAudit::where('service_work_id',$serviceWorkInfo->id)->findOrEmpty();
-            if($spareAudit->isEmpty()){
+
+            $spare = ServiceWorkSpare::where('id',$params['id'])->findOrEmpty();
+            if($spare->isEmpty()){
                 throw new \Exception('无配件审核');
             }else{
-                if(in_array($spareAudit->status,[0,2]) && in_array($params['status'],[1,3])){
-                    $serviceWorkInfo->user_confirm_status = 5;
-                    $serviceWorkInfo->work_status = 7;
-                    $serviceWorkInfo->work_pay_status = 1;
-                    $serviceWorkInfo->save();
+                $serviceWorkInfo = ServiceWork::find($spare->service_work_id);
+                if((int)$serviceWorkInfo['work_pay_status'] !== 3){
+                    throw new \Exception('该工单非待结算状态');
                 }
-                $spareAudit->status = $params['status']??0;
-                $spareAudit->remark = $params['remark']??'';
-                $spareAudit->save();
+                $spare->status = $params['status']??0;
+                $spare->remark = $params['remark']??'';
+                $spare->save();
             }
             Db::commit();
+            // 是否所有配件审核完成
+            SparePartLogic::isExamineOk($spare->service_work_id);
             return true;
         } catch (\Exception $e) {
             Db::rollback();

+ 32 - 2
app/api/logic/PerformanceLogic.php

@@ -20,6 +20,7 @@ use app\common\model\recharge\OrderGoods;
 use app\common\logic\RetentionMoneyLogic;
 use app\common\model\works\ServiceWork;
 use app\common\model\works\ServiceWorkLog;
+use app\common\model\works\ServiceWorkSpare;
 use think\facade\Db;
 use think\facade\Log;
 
@@ -133,7 +134,21 @@ class PerformanceLogic extends BaseLogic
             $settlement_amount += (float)$work->add_work_amount;
 
             //工程师可提现金额,汇总 配件总金额
-            $settlement_amount += (float)$work->spare_total;
+            $offering_price = ServiceWorkSpare::where("service_work_id", $work->id)->where('status', 1)->sum('offering_price')??0;
+            $freezeMoney = $work->spare_total - $offering_price;
+            if($freezeMoney > 0){
+                // work_id
+                $retentionMoneyLog = MasterWorkerRetentionMoneyLog::create([
+                    'sn' => generate_sn(MasterWorkerRetentionMoneyLog::class,'sn'),
+                    'worker_id' => $work->master_worker_id,
+                    'action' => WorkerAccountLogEnum::DEC,
+                    'amount' => (float)$freezeMoney,
+                    'work_id' => $work->id,
+                    'remark' => '配件费超时审核冻结',
+                ])->getData();
+                Log::info('配件费超时审核冻结:'.$work->master_worker_id.',工单Id:'.$work->id);
+            }
+            $settlement_amount += (float)$offering_price;
 
             Log::info('工单'.$work->id.',总服务费:'.$worker_price.'可提现金额:'.$settlement_amount.',加单金额:'.$work->add_work_amount.',缴纳质保金:'.$work->earnest_money.',系统回收金额:'.$work->system_amount.',门店总金额(包含工程师):'.$work->tenant_all_amount . ',门店实际金额:'.$work->tenant_amount);
 
@@ -219,7 +234,22 @@ class PerformanceLogic extends BaseLogic
             //工程师可提现金额,汇总了加单金额
             $settlement_amount += (float)$work->add_work_amount;
             //工程师可提现金额,汇总 配件总金额
-            $settlement_amount += (float)$work->spare_total;
+            $offering_price = ServiceWorkSpare::where("service_work_id", $work->id)->where('status', 1)->sum('offering_price')??0;
+            $freezeMoney = $work->spare_total - $offering_price;
+            if($freezeMoney > 0){
+                // work_id
+                $retentionMoneyLog = MasterWorkerRetentionMoneyLog::create([
+                    'sn' => generate_sn(MasterWorkerRetentionMoneyLog::class,'sn'),
+                    'worker_id' => $work->master_worker_id,
+                    'action' => WorkerAccountLogEnum::DEC,
+                    'amount' => (float)$freezeMoney,
+                    'work_id' => $work->id,
+                    'remark' => '配件费超时审核冻结',
+                ])->getData();
+                Log::info('配件费超时审核冻结:'.$work->master_worker_id.',工单Id:'.$work->id);
+            }
+            $settlement_amount += (float)$offering_price;
+
             Log::info('calculatePerformanceCommission:工单'.$work->id.',总服务费:'.$work->worker_price.'可提现金额:'.$settlement_amount.',加单金额:'.$work->add_work_amount.',缴纳质保金:'.$work->earnest_money.',系统回收金额:'.$work->system_amount.',门店总金额(包含工程师):'.$work->tenant_all_amount . ',门店实际金额:'.$work->tenant_amount);
 
             WorkerAccountLogLogic::addAccountLog($work,$settlement_amount,WorkerAccountLogEnum::UM_INC_ADMIN,WorkerAccountLogEnum::INC);

+ 9 - 8
app/common/model/works/ServiceWork.php

@@ -58,18 +58,19 @@ class ServiceWork extends BaseModel
         $is_settlement = false;
         if($model->user_confirm_status == 5 and $model->work_status == 7 and $model->work_pay_status==1) {
             $isOneselfSpare = ServiceWorkSpare::where("service_work_id", $model->id)->where('spare_part_id', 0)->count('id');
-            $isAudit = ServiceWorkSpareAudit::where("service_work_id", $model->id)->findOrEmpty();
-            if ($isOneselfSpare > 0 && $isAudit->isEmpty()) {
+            if ($isOneselfSpare) {
+                $count = ServiceWorkSpare::where("service_work_id",$model->id)->whereIn('status', [0,2])->count();
                 // 结算待审
-                ServiceWorkSpareAudit::create(['service_work_id' => $model->id]);
-                $model->work_pay_status = 3;
-                $model->save();
+                if($count>0){
+                    $model->work_pay_status = 3;
+                    $model->save();
+                }else{
+                    // 通过审核且未结算 - 结算
+                    $model->settlement_amount == 0 && $model->earnest_money == 0 && $model->system_amount == 0 && $is_settlement = true;
+                }
             }elseif ($isOneselfSpare == 0){
                 // 直接结算
                 $is_settlement = true;
-            }else{
-                // 通过审核且未结算 - 结算
-                in_array($isAudit->status,[1,3]) && $model->settlement_amount == 0 && $model->earnest_money == 0 && $model->system_amount == 0 && $is_settlement = true;
             }
         }
         if($is_settlement){