瀏覽代碼

工单结算

liugc 1 年之前
父節點
當前提交
ee5cbfaba2

+ 9 - 0
app/adminapi/controller/works/ServiceWorkController.php

@@ -126,4 +126,13 @@ class ServiceWorkController extends BaseAdminController
         }
         return $this->fail(ServiceWorkLogic::getError());
     }
+    public function settlementMaster()
+    {
+        $params = (new ServiceWorkValidate())->post()->goCheck('detail');
+        $result = ServiceWorkLogic::settlement($params);
+        if (true === $result) {
+            return $this->success('操作成功!', [], 1, 1);
+        }
+        return $this->fail(ServiceWorkLogic::getError());
+    }
 }

+ 2 - 2
app/adminapi/lists/works/ServiceWorkLists.php

@@ -40,7 +40,7 @@ class ServiceWorkLists extends BaseAdminDataLists implements ListsSearchInterfac
     public function setSearch(): array
     {
         return [
-            '=' => ['id','work_sn', 'real_name', 'mobile', 'address', 'title', 'category_type', 'base_service_fee', 'service_fee', 'work_status', 'service_status',  'finished_images', 'master_worker_id', 'work_amount','work_type'],
+            '=' => ['id','work_sn', 'real_name', 'mobile', 'address', 'title', 'category_type', 'base_service_fee', 'service_fee', 'work_status','work_pay_status', 'service_status',  'finished_images', 'master_worker_id', 'work_amount','work_type'],
 
         ];
     }
@@ -110,7 +110,7 @@ class ServiceWorkLists extends BaseAdminDataLists implements ListsSearchInterfac
         ])
             ->where($this->searchWhere)
             ->where($this->queryWhere())
-            ->field(['id', 'work_sn', 'real_name', 'mobile', 'address', 'title', 'category_type', 'goods_category_ids', 'goods_category_id', 'base_service_fee', 'service_fee', 'work_status', 'service_status', 'dispatch_time', 'receive_time', 'appointment_time', 'finished_images', 'finished_time', 'master_worker_id', 'work_amount', 'work_type', 'create_time', 'update_time'])
+            ->field(['id', 'work_sn', 'real_name', 'mobile', 'address', 'title', 'category_type', 'goods_category_ids', 'goods_category_id', 'base_service_fee', 'service_fee', 'work_status','work_pay_status', 'service_status', 'dispatch_time', 'receive_time', 'appointment_time', 'finished_images', 'finished_time', 'master_worker_id', 'work_amount', 'work_type', 'create_time', 'update_time'])
             ->limit($this->limitOffset, $this->limitLength)
             ->order(['id' => 'desc'])
             ->select()

+ 38 - 0
app/adminapi/logic/works/ServiceWorkLogic.php

@@ -15,9 +15,12 @@
 namespace app\adminapi\logic\works;
 
 
+use app\api\logic\PerformanceLogic;
 use app\common\model\dict\DictData;
 use app\common\model\master_worker\MasterWorker;
 use app\common\model\master_worker\MasterWorkerAccountLog;
+use app\common\model\performance\PerformanceRules;
+use app\common\model\recharge\OrderGoods;
 use app\common\model\recharge\RechargeOrder;
 use app\common\model\spare_part\SparePart;
 use app\common\model\works\ServiceWork;
@@ -500,4 +503,39 @@ class ServiceWorkLogic extends BaseLogic
             return false;
         }
     }
+
+    /**
+     * @notes 师傅结算操作
+     * @param array $params
+     * @return bool
+     * @author likeadmin
+     * @date 2024/09/19 10:48
+     */
+    public static function settlement(array $params): bool
+    {
+        Db::startTrans();
+        try {
+            $serviceWorkInfo = ServiceWork::find($params['id']);
+            if((int)$serviceWorkInfo['work_pay_status'] !== 3){
+                throw new \Exception('该工单非待结算状态');
+            }
+            //获取工单对应的商品id
+            $order_sns = \app\common\model\orders\RechargeOrder::where('work_id',$serviceWorkInfo->id)->column('sn');
+            $goods_id = OrderGoods::whereIn('sn',$order_sns)->value('goods_id');
+            $rule = PerformanceRules::whereFindInSet('goods_id',$goods_id)->findOrEmpty();
+            if($rule->isEmpty()){
+                throw new \Exception('请配置商品业绩规则');
+            }
+            PerformanceLogic::calculatePerformance($serviceWorkInfo);
+            Db::commit();
+            return true;
+        } catch (\Exception $e) {
+            Db::rollback();
+            self::setError($e->getMessage());
+            return false;
+        }
+    }
+
+
+
 }

+ 1 - 1
app/common/logic/EffectiveLogic.php

@@ -25,7 +25,7 @@ class EffectiveLogic extends BaseLogic
                 'effective_unit' => $effective->effectiveRule->effective_unit,
                 'effective_num' => $effective->effectiveRule->effective_num,
                 'remark' => $effective->effectiveRule->remark,
-                'end_effective_time' =>  date("Y-m-d H:i:s",EffectiveRules::formatEndEffectiveTime(time() ,$effective->effectiveRule->effective_num,$effective->effectiveRule->effective_unit)),
+                'end_effective_time' =>  EffectiveRules::formatEndEffectiveTime(time() ,$effective->effectiveRule->effective_num,$effective->effectiveRule->effective_unit),
             ]);
         }