Просмотр исходного кода

add - 保修卡:后台、接口

liugc 1 год назад
Родитель
Сommit
3a6cf14659

+ 111 - 0
app/adminapi/controller/effective/OrderEffectiveLogController.php

@@ -0,0 +1,111 @@
+<?php
+// +----------------------------------------------------------------------
+// | likeadmin快速开发前后端分离管理后台(PHP版)
+// +----------------------------------------------------------------------
+// | 欢迎阅读学习系统程序代码,建议反馈是我们前进的动力
+// | 开源版本可自由商用,可去除界面版权logo
+// | gitee下载:https://gitee.com/likeshop_gitee/likeadmin
+// | github下载:https://github.com/likeshop-github/likeadmin
+// | 访问官网:https://www.likeadmin.cn
+// | likeadmin团队 版权所有 拥有最终解释权
+// +----------------------------------------------------------------------
+// | author: likeadminTeam
+// +----------------------------------------------------------------------
+
+
+namespace app\adminapi\controller\effective;
+
+
+use app\adminapi\controller\BaseAdminController;
+use app\adminapi\lists\effective\OrderEffectiveLogLists;
+use app\adminapi\logic\effective\OrderEffectiveLogLogic;
+use app\adminapi\validate\effective\OrderEffectiveLogValidate;
+
+
+/**
+ * OrderEffectiveLog控制器
+ * Class OrderEffectiveLogController
+ * @package app\adminapi\controller
+ */
+class OrderEffectiveLogController extends BaseAdminController
+{
+
+
+    /**
+     * @notes 获取列表
+     * @return \think\response\Json
+     * @author likeadmin
+     * @date 2025/01/17 11:10
+     */
+    public function lists()
+    {
+        return $this->dataLists(new OrderEffectiveLogLists());
+    }
+
+
+    /**
+     * @notes 添加
+     * @return \think\response\Json
+     * @author likeadmin
+     * @date 2025/01/17 11:10
+     */
+    public function add()
+    {
+        $params = (new OrderEffectiveLogValidate())->post()->goCheck('add');
+        $result = OrderEffectiveLogLogic::add($params);
+        if (true === $result) {
+            return $this->success('添加成功', [], 1, 1);
+        }
+        return $this->fail(OrderEffectiveLogLogic::getError());
+    }
+
+
+    /**
+     * @notes 编辑
+     * @return \think\response\Json
+     * @author likeadmin
+     * @date 2025/01/17 11:10
+     */
+    public function edit()
+    {
+        $params = (new OrderEffectiveLogValidate())->post()->goCheck('detail',[
+            'adminId' => $this->adminId,
+            'adminInfo' => $this->adminInfo
+        ]);
+        $result = OrderEffectiveLogLogic::edit($params);
+        if (true === $result) {
+            return $this->success('编辑成功', [], 1, 1);
+        }
+        return $this->fail(OrderEffectiveLogLogic::getError());
+    }
+
+
+    /**
+     * @notes 删除
+     * @return \think\response\Json
+     * @author likeadmin
+     * @date 2025/01/17 11:10
+     */
+    public function delete()
+    {
+        $params = (new OrderEffectiveLogValidate())->post()->goCheck('delete');
+        OrderEffectiveLogLogic::delete($params);
+        return $this->success('删除成功', [], 1, 1);
+    }
+
+
+    /**
+     * @notes 获取详情
+     * @return \think\response\Json
+     * @author likeadmin
+     * @date 2025/01/17 11:10
+     */
+    public function detail()
+    {
+        $params = (new OrderEffectiveLogValidate())->goCheck('detail');
+        $result = OrderEffectiveLogLogic::detail($params);
+        return $this->data($result);
+    }
+
+
+}

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

@@ -122,19 +122,6 @@ class ServiceWorkController extends BaseAdminController
         $params = (new ServiceWorkValidate())->post()->goCheck('allocateWorker');
         $result = ServiceWorkLogic::allocateWorker($params,$this->adminInfo);
         if (true === $result) {
-            // 工程师派单通知【给工程师的通知】【公众号通知,不发短信】
-            $workDetail = ServiceWorkLogic::detail($params);
-            $res = event('Notice',  [
-                'scene_id' => 113,
-                'params' => [
-                    'user_id' => $params['master_worker_id'],
-                    'order_id' => $params['id'],
-                    'thing9' => $workDetail['title'],
-                    'time7' => $workDetail['appointment_time'],
-                    'thing8' => (iconv_strlen($workDetail['address'])>15)?(mb_substr($workDetail['address'],0,15,'UTF-8').'...'):$workDetail['address'],
-                    'phone_number6' => asteriskString($workDetail['mobile']),
-                ]
-            ]);
             return $this->success('分配工程师成功', [], 1, 1);
         }
         return $this->fail(ServiceWorkLogic::getError());

+ 78 - 0
app/adminapi/lists/effective/OrderEffectiveLogLists.php

@@ -0,0 +1,78 @@
+<?php
+// +----------------------------------------------------------------------
+// | likeadmin快速开发前后端分离管理后台(PHP版)
+// +----------------------------------------------------------------------
+// | 欢迎阅读学习系统程序代码,建议反馈是我们前进的动力
+// | 开源版本可自由商用,可去除界面版权logo
+// | gitee下载:https://gitee.com/likeshop_gitee/likeadmin
+// | github下载:https://github.com/likeshop-github/likeadmin
+// | 访问官网:https://www.likeadmin.cn
+// | likeadmin团队 版权所有 拥有最终解释权
+// +----------------------------------------------------------------------
+// | author: likeadminTeam
+// +----------------------------------------------------------------------
+
+namespace app\adminapi\lists\effective;
+
+
+use app\adminapi\lists\BaseAdminDataLists;
+use app\common\model\effective\OrderEffectiveLog;
+use app\common\lists\ListsSearchInterface;
+
+
+/**
+ * OrderEffectiveLog列表
+ * Class OrderEffectiveLogLists
+ * @package app\adminapi\lists
+ */
+class OrderEffectiveLogLists extends BaseAdminDataLists implements ListsSearchInterface
+{
+
+
+    /**
+     * @notes 设置搜索条件
+     * @return \string[][]
+     * @author likeadmin
+     * @date 2025/01/17 11:10
+     */
+    public function setSearch(): array
+    {
+        return [
+            '=' => ['effective_id', 'sn', 'user_id', 'work_id', 'goods_id', 'effective_unit', 'effective_num', 'remark', 'end_effective_time'],
+
+        ];
+    }
+
+
+    /**
+     * @notes 获取列表
+     * @return array
+     * @throws \think\db\exception\DataNotFoundException
+     * @throws \think\db\exception\DbException
+     * @throws \think\db\exception\ModelNotFoundException
+     * @author likeadmin
+     * @date 2025/01/17 11:10
+     */
+    public function lists(): array
+    {
+        return OrderEffectiveLog::where($this->searchWhere)
+            ->field(['*'])
+            ->limit($this->limitOffset, $this->limitLength)
+            ->order(['id' => 'desc'])
+            ->select()
+            ->toArray();
+    }
+
+
+    /**
+     * @notes 获取数量
+     * @return int
+     * @author likeadmin
+     * @date 2025/01/17 11:10
+     */
+    public function count(): int
+    {
+        return OrderEffectiveLog::where($this->searchWhere)->count();
+    }
+
+}

+ 288 - 0
app/adminapi/logic/effective/OrderEffectiveLogLogic.php

@@ -0,0 +1,288 @@
+<?php
+// +----------------------------------------------------------------------
+// | likeadmin快速开发前后端分离管理后台(PHP版)
+// +----------------------------------------------------------------------
+// | 欢迎阅读学习系统程序代码,建议反馈是我们前进的动力
+// | 开源版本可自由商用,可去除界面版权logo
+// | gitee下载:https://gitee.com/likeshop_gitee/likeadmin
+// | github下载:https://github.com/likeshop-github/likeadmin
+// | 访问官网:https://www.likeadmin.cn
+// | likeadmin团队 版权所有 拥有最终解释权
+// +----------------------------------------------------------------------
+// | author: likeadminTeam
+// +----------------------------------------------------------------------
+
+namespace app\adminapi\logic\effective;
+
+
+use app\adminapi\logic\works\ServiceWorkLogic;
+use app\common\enum\GoodsEnum;
+use app\common\enum\PayEnum;
+use app\common\enum\WorkEnum;
+use app\common\enum\worker\WorkerAccountLogEnum;
+use app\common\model\effective\OrderEffectiveLog;
+use app\common\logic\BaseLogic;
+use app\common\model\goods\Goods;
+use app\common\model\master_worker\MasterWorkerAccountLog;
+use app\common\model\master_worker\MasterWorkerRetentionMoneyLog;
+use app\common\model\orders\RechargeOrder;
+use app\common\model\recharge\OrderGoods;
+use app\common\model\works\ServiceWork;
+use think\facade\Db;
+
+
+/**
+ * OrderEffectiveLog逻辑
+ * Class OrderEffectiveLogLogic
+ * @package app\adminapi\logic
+ */
+class OrderEffectiveLogLogic extends BaseLogic
+{
+
+
+    /**
+     * @notes 添加
+     * @param array $params
+     * @return bool
+     * @author likeadmin
+     * @date 2025/01/17 11:10
+     */
+    public static function add(array $params): bool
+    {
+        Db::startTrans();
+        try {
+            OrderEffectiveLog::create([
+                'effective_id' => $params['effective_id'],
+                'sn' => $params['sn'],
+                'user_id' => $params['user_id'],
+                'work_id' => $params['work_id'],
+                'goods_id' => $params['goods_id'],
+                'effective_unit' => $params['effective_unit'],
+                'effective_num' => $params['effective_num'],
+                'remark' => $params['remark'],
+                'end_effective_time' => $params['end_effective_time'],
+            ]);
+
+            Db::commit();
+            return true;
+        } catch (\Exception $e) {
+            Db::rollback();
+            self::setError($e->getMessage());
+            return false;
+        }
+    }
+
+
+    /**
+     * @notes 编辑
+     * @param array $params
+     * @return bool
+     * @author likeadmin
+     * @date 2025/01/17 11:10
+     */
+    public static function edit(array $params): bool
+    {
+        if($params['operation_type'] == 1){
+            //无需保修 - 恢复状态
+            OrderEffectiveLog::where('id', $params['id'])->update([
+                'effective_status' => 0,
+                'effective_time' => 0,
+            ]);
+            return true;
+        }
+
+        // 用户已提交 - 客服处理下单
+        if($params['edit_status'] == 1){
+            self::effectiveServiceWork($params);
+        }
+        // 保修中 - 客服处理新增定金 ,尾款可由工程师完成 =0 || >0 均可
+        if($params['edit_status'] == 2){
+            // 惩罚金额
+            OrderEffectiveLog::where('id', $params['id'])->update([
+                'penalty_amount' => $params['penalty_amount']
+            ]);
+        }
+        return true;
+    }
+
+
+    /**
+     * @notes 删除
+     * @param array $params
+     * @return bool
+     * @author likeadmin
+     * @date 2025/01/17 11:10
+     */
+    public static function delete(array $params): bool
+    {
+        return OrderEffectiveLog::destroy($params['id']);
+    }
+
+
+    /**
+     * @notes 获取详情
+     * @param $params
+     * @return array
+     * @author likeadmin
+     * @date 2025/01/17 11:10
+     */
+    public static function detail($params): array
+    {
+        return OrderEffectiveLog::findOrEmpty($params['id'])->toArray();
+    }
+    /**
+     * @notes 计算工单所得的 提成+质保金
+     */
+    public static function commissionAndAssuranceDeposit($serviceWork)
+    {
+        $change_amount = MasterWorkerAccountLog::where([
+            'change_object'=>WorkerAccountLogEnum::UM,'change_type'=>WorkerAccountLogEnum::UM_INC_ADMIN,
+            'action'=>WorkerAccountLogEnum::INC,'worker_id'=>$serviceWork['master_worker_id'],
+            'work_sn'=>$serviceWork['work_sn']])->value('change_amount');
+        $retentionAmount = MasterWorkerRetentionMoneyLog::where(['action'=>WorkerAccountLogEnum::INC,'source'=>2,'worker_id'=>$serviceWork['master_worker_id'],'work_id'=>$serviceWork['id']])->value('amount');
+        return $change_amount + $retentionAmount;
+    }
+
+
+    /**
+     * @notes 用户已提交 - 客服处理下单
+     */
+    public static function effectiveServiceWork($params)
+    {
+        Db::startTrans();
+        try {
+            /*{ name: '无需保修', value: 1 },
+            { name: '原工程师修复', value: 2 },
+            { name: '新工程师修复', value: 3 }*/
+            $effectiveLog = OrderEffectiveLog::where('id', $params['id'])->find();
+
+            /*$effectiveLog['user_id']
+            $effectiveLog['work_id']
+            $effectiveLog['goods_id']*/
+            // 原工单信息 $effectiveLog['work_id']
+            $serviceWork = ServiceWork::find($effectiveLog['work_id'])->toArray();
+
+            if($params['operation_type'] == 2){
+                //原工程师修复
+                OrderEffectiveLog::where('id', $params['id'])->update([
+                    'effective_status' => 2
+                ]);
+                // 原工程师为0
+                $service_fee = 0;
+                $master_worker_id = $serviceWork['master_worker_id'];
+
+            }else if($params['operation_type'] == 3){
+                //新工程师修复
+                OrderEffectiveLog::where('id', $params['id'])->update([
+                    'effective_status' => 2
+                ]);
+                // 计算原工程师的原工单的提成+质保金
+                //$service_fee = self::commissionAndAssuranceDeposit($serviceWork);
+                $service_fee = 0;
+                if($serviceWork['master_worker_id'] == $params['master_worker_id']){
+                    throw new \Exception('请选择新的工程师');
+                }
+                $master_worker_id = $params['master_worker_id'];
+            }else{
+                throw new \Exception('操作类型错误');
+            }
+
+            //生成服务工单
+            $work_data = [
+                'work_sn' => generate_sn(ServiceWork::class, 'work_sn'),
+                'real_name' => $serviceWork['real_name'],
+                'mobile' => $serviceWork['mobile'],
+                'address' => $serviceWork['address'],
+
+                'province' => $serviceWork['province']??0,
+                'city' => $serviceWork['city']??0,
+                'area_name' => $serviceWork['area_name']??'',
+
+                'title' => $serviceWork['title']??'',
+                'category_type' => $serviceWork['category_type'],
+                'goods_category_ids' => $serviceWork['goods_category_ids'],
+                'goods_category_id' => $serviceWork['goods_category_id'],
+
+                'user_id'=>$serviceWork['user_id'],
+                'lon'=>$serviceWork['lon'],
+                'lat'=>$serviceWork['lat'],
+                'property_activity_id'=>0,
+                'user_equity_id'=>0,
+
+                'work_pay_status'=>WorkEnum::IS_PAY_STATUS,
+                'appointment_time' => $params['appointment_time']?strtotime($params['appointment_time']):0,
+                'order_effective_id'=>$params['id'],
+                'base_service_fee' => 0,
+                'service_fee' => 0,
+                'work_total'=>0,
+                'work_amount'=>0,
+            ];
+
+            $service_work = ServiceWork::create($work_data);
+
+            //生成支付订单
+            $data = [
+                'work_id'=> $service_work['id'],
+                'sn' => generate_sn(RechargeOrder::class, 'sn'),
+                'order_type'=>0,//服务订单
+                'order_terminal' => 1,
+                'payment_type'=>1,
+                'user_id' => $serviceWork['user_id'],
+                'pay_way' => 2,
+                'pay_status' => PayEnum::ISPAID,
+                'pay_time' => time(),
+                'paid_amount' => 0,
+                'coupon_id'=>0,
+                'coupon_price'=>0,
+                'order_total' => 0,
+                'order_amount' => 0,
+            ];
+            $order = RechargeOrder::create($data);
+
+            //生成订单服务详情
+            $goods = Goods::findOrEmpty($effectiveLog['goods_id']);
+            OrderGoods::create([
+                'sn' => $order['sn'],
+                'goods_id' => $effectiveLog['goods_id'],
+                'category_type' => $goods['category_type'],
+                'goods_category_ids' => $goods['goods_category_ids'],
+                'goods_category_id' => $goods['goods_category_id'],
+                'goods_name' => $goods['goods_name'],
+                'goods_image' => $goods['goods_image'],
+                'goods_video' => $goods['goods_video'],
+                'goods_number' => $goods['goods_number'],
+                'good_unit' => $goods['good_unit'],
+                'goods_size' => $goods['goods_size'],
+                'goods_type' => $goods['goods_type'],
+                'goods_brand' => $goods['goods_brand'],
+                'install_guide' => $goods['install_guide'],
+                'goods_payment_type'=>$goods['goods_payment_type'],
+                'base_service_fee' => $goods['base_service_fee'],
+                'service_total' => $goods['service_total'],
+                'service_fee' => $goods['service_fee'],
+                'service_image' => $goods['service_image'],
+                'warranty_period'=>$goods['warranty_period'],
+                'fee_schedule' => $goods['fee_schedule'],
+                'goods_status' => $goods['goods_status'],
+            ]);
+
+            Db::commit();
+
+            //派单
+            if(isset($service_work['id']) && !empty($service_work['id'])) ServiceWorkLogic::allocateWorker(['id'=>$service_work['id'],'master_worker_id'=>$master_worker_id],$params['adminInfo']);
+
+            return true;
+        } catch (\Exception $e) {
+            Db::rollback();
+
+            dd($e->getMessage());
+            self::setError($e->getMessage());
+            return false;
+        }
+    }
+
+
+
+
+
+}

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

@@ -364,6 +364,19 @@ class ServiceWorkLogic extends BaseLogic
             ];
             ServiceWorkerAllocateWorkerLogic::add($work_log);
             Db::commit();
+            // 工程师派单通知【给工程师的通知】【公众号通知,不发短信】
+            $workDetail = ServiceWorkLogic::detail($params);
+            $res = event('Notice',  [
+                'scene_id' => 113,
+                'params' => [
+                    'user_id' => $params['master_worker_id'],
+                    'order_id' => $params['id'],
+                    'thing9' => $workDetail['title'],
+                    'time7' => $workDetail['appointment_time'],
+                    'thing8' => (iconv_strlen($workDetail['address'])>15)?(mb_substr($workDetail['address'],0,15,'UTF-8').'...'):$workDetail['address'],
+                    'phone_number6' => asteriskString($workDetail['mobile']),
+                ]
+            ]);
             return true;
         }catch(\Exception $e){
             Db::rollback();

+ 110 - 0
app/adminapi/validate/effective/OrderEffectiveLogValidate.php

@@ -0,0 +1,110 @@
+<?php
+// +----------------------------------------------------------------------
+// | likeadmin快速开发前后端分离管理后台(PHP版)
+// +----------------------------------------------------------------------
+// | 欢迎阅读学习系统程序代码,建议反馈是我们前进的动力
+// | 开源版本可自由商用,可去除界面版权logo
+// | gitee下载:https://gitee.com/likeshop_gitee/likeadmin
+// | github下载:https://github.com/likeshop-github/likeadmin
+// | 访问官网:https://www.likeadmin.cn
+// | likeadmin团队 版权所有 拥有最终解释权
+// +----------------------------------------------------------------------
+// | author: likeadminTeam
+// +----------------------------------------------------------------------
+
+namespace app\adminapi\validate\effective;
+
+
+use app\common\validate\BaseValidate;
+
+
+/**
+ * OrderEffectiveLog验证器
+ * Class OrderEffectiveLogValidate
+ * @package app\adminapi\validate
+ */
+class OrderEffectiveLogValidate extends BaseValidate
+{
+
+     /**
+      * 设置校验规则
+      * @var string[]
+      */
+    protected $rule = [
+        'id' => 'require',
+        'effective_id' => 'require',
+        'sn' => 'require',
+        'user_id' => 'require',
+        'work_id' => 'require',
+        'goods_id' => 'require',
+        'effective_num' => 'require',
+        'end_effective_time' => 'require',
+
+    ];
+
+
+    /**
+     * 参数描述
+     * @var string[]
+     */
+    protected $field = [
+        'id' => 'id',
+        'effective_id' => '保修卡ID',
+        'sn' => '订单编号',
+        'user_id' => '用户ID',
+        'work_id' => '工单ID',
+        'goods_id' => '商品ID',
+        'effective_num' => '值',
+        'end_effective_time' => '保修截至时间',
+
+    ];
+
+
+    /**
+     * @notes 添加场景
+     * @return OrderEffectiveLogValidate
+     * @author likeadmin
+     * @date 2025/01/17 11:10
+     */
+    public function sceneAdd()
+    {
+        return $this->only(['effective_id','sn','user_id','work_id','goods_id','effective_num','end_effective_time']);
+    }
+
+
+    /**
+     * @notes 编辑场景
+     * @return OrderEffectiveLogValidate
+     * @author likeadmin
+     * @date 2025/01/17 11:10
+     */
+    public function sceneEdit()
+    {
+        return $this->only(['id','effective_id','sn','user_id','work_id','goods_id','effective_num','end_effective_time']);
+    }
+
+
+    /**
+     * @notes 删除场景
+     * @return OrderEffectiveLogValidate
+     * @author likeadmin
+     * @date 2025/01/17 11:10
+     */
+    public function sceneDelete()
+    {
+        return $this->only(['id']);
+    }
+
+
+    /**
+     * @notes 详情场景
+     * @return OrderEffectiveLogValidate
+     * @author likeadmin
+     * @date 2025/01/17 11:10
+     */
+    public function sceneDetail()
+    {
+        return $this->only(['id']);
+    }
+
+}

+ 25 - 0
app/api/controller/OrderEffectiveController.php

@@ -3,11 +3,36 @@
 namespace app\api\controller;
 
 use app\api\lists\OrderEffectiveLogLists;
+use app\api\logic\OrderEffectiveLogLogic;
+use app\api\validate\OrderEffectiveLogValidate;
 
 class OrderEffectiveController extends BaseApiController
 {
+    public array $notNeedLogin = ['submitEffective'];
     public function lists()
     {
         return $this->dataLists(new OrderEffectiveLogLists());
     }
+
+
+    /**
+     * 提交保修申请
+     * @return \think\response\Json
+     */
+    public function submitEffective()
+    {
+        $params = (new OrderEffectiveLogValidate())->post()->goCheck('applyFor', [
+            'user_id' => $this->userId,
+            'user_info' => $this->userInfo
+        ]);
+        $result = OrderEffectiveLogLogic::submitEffective($params);
+        if (false === $result) {
+            return $this->fail(OrderEffectiveLogLogic::getError());
+        }
+        return $this->success('提交成功', [], 1, 1);
+    }
+
+
+
+
 }

+ 2 - 2
app/api/lists/OrderEffectiveLogLists.php

@@ -22,9 +22,9 @@ class OrderEffectiveLogLists  extends BaseApiDataLists
            $query->with(['goodsCategory'=>function ($query1) {
                $query1->field(['name','picture']);
            }]);
-       }])->where($this->queryWhere())
+       },'serviceWork'])->where($this->queryWhere())
            ->limit($this->limitOffset, $this->limitLength)
-           ->field(['id','goods_id','sn','effective_unit','effective_num','remark','end_effective_time'])
+           ->field(['*'])
            ->append(['effective_unit_text'])
            ->order('create_time desc')
            ->select()

+ 62 - 0
app/api/logic/OrderEffectiveLogLogic.php

@@ -0,0 +1,62 @@
+<?php
+// +----------------------------------------------------------------------
+// | likeadmin快速开发前后端分离管理后台(PHP版)
+// +----------------------------------------------------------------------
+// | 欢迎阅读学习系统程序代码,建议反馈是我们前进的动力
+// | 开源版本可自由商用,可去除界面版权logo
+// | gitee下载:https://gitee.com/likeshop_gitee/likeadmin
+// | github下载:https://github.com/likeshop-github/likeadmin
+// | 访问官网:https://www.likeadmin.cn
+// | likeadmin团队 版权所有 拥有最终解释权
+// +----------------------------------------------------------------------
+// | author: likeadminTeam
+// +----------------------------------------------------------------------
+
+namespace app\api\logic;
+
+
+use app\common\model\effective\OrderEffectiveLog;
+use app\common\logic\BaseLogic;
+use think\facade\Db;
+
+
+/**
+ * OrderEffectiveLog逻辑
+ * Class OrderEffectiveLogLogic
+ * @package app\api\logic
+ */
+class OrderEffectiveLogLogic extends BaseLogic
+{
+
+    /**
+     * @notes 提交保修工单申请
+     */
+    public static function submitEffective(array $params): bool
+    {
+        //Db::startTrans();
+        try {
+            $info = OrderEffectiveLog::find($params['id']);
+            if($info['end_effective_time'] < time()){
+                throw new \Exception('该保修卡已过期');
+            }
+            if($info['effective_status'] > 0){
+                throw new \Exception('该保修卡已提交过');
+            }
+
+            OrderEffectiveLog::where('id', $params['id'])->update([
+                'effective_images' => json_encode($params['effective_images']),
+                'remark' => $params['remark'] ?? '',
+                'effective_status' => 1,
+                'effective_time' => time()
+            ]);
+
+            //Db::commit();
+            return true;
+        } catch (\Exception $e) {
+            //Db::rollback();
+            self::setError($e->getMessage());
+            return false;
+        }
+    }
+
+}

+ 35 - 0
app/api/logic/PerformanceLogic.php

@@ -7,6 +7,7 @@ use app\common\logic\BaseLogic;
 use app\common\logic\EffectiveLogic;
 use app\common\logic\WorkAddMoneyLogic;
 use app\common\logic\WorkerAccountLogLogic;
+use app\common\model\effective\OrderEffectiveLog;
 use app\common\model\master_commission\MasterWorkerCommissionConfig;
 use app\common\model\master_commission\MasterWorkerCommissionRatio;
 use app\common\model\master_worker\MasterWorker;
@@ -14,6 +15,8 @@ use app\common\model\orders\RechargeOrder;
 use app\common\model\performance\PerformanceRules;
 use app\common\model\recharge\OrderGoods;
 use app\common\logic\RetentionMoneyLogic;
+use app\common\model\works\ServiceWork;
+use app\common\model\works\ServiceWorkLog;
 use think\facade\Db;
 use think\facade\Log;
 
@@ -187,4 +190,36 @@ class PerformanceLogic extends BaseLogic
         EffectiveLogic::receiveEffective($work);
     }
 
+    /**
+     * @notes 保修单结算
+     * @param $work
+     * @return false|void
+     */
+    public static function effectivePerformance($work)
+    {
+        if(empty($work->order_effective_id)){
+            return false;
+        }
+        Log::info('effectivePerformance:'.json_encode($work->toArray()));
+        // 判断该工单是否为新工程师 - 保修前工单的工程师是谁
+        $orderEffectiveLog = OrderEffectiveLog::where('id',$work->order_effective_id)->findOrEmpty();
+        // 前工单
+        $serviceWork = ServiceWork::where('id',$orderEffectiveLog->work_id)->findOrEmpty();
+        if($serviceWork->master_worker_id != $work->master_worker_id){
+            // 扣掉 原工单工程师的提成+质保金 + 惩罚金额 to 新工程师余额
+            $income_fee = \app\adminapi\logic\effective\OrderEffectiveLogLogic::commissionAndAssuranceDeposit($serviceWork);
+            $new_amount = $income_fee + $orderEffectiveLog->penalty_amount;
+
+            $remark = '工单号:'.$work->work_sn.',扣除金额:'.$new_amount.',扣除原因:保修工单新工程师收益';
+            RetentionMoneyLogic::refundRetention([
+                'remark'=>$remark,
+                'work_id'=>$work->id,
+                'worker_id'=>$serviceWork->master_worker_id,
+                'amount'=>$new_amount
+            ],false);
+
+            $remark = '保修单结算-工单号:'.$work->work_sn.',收益金额:'.$new_amount.',原因:保修工单新工程师收益';
+            WorkerAccountLogLogic::addAccountLog($work,$new_amount,WorkerAccountLogEnum::UM_INC_ADMIN,WorkerAccountLogEnum::INC,$remark);
+        }
+    }
 }

+ 116 - 0
app/api/validate/OrderEffectiveLogValidate.php

@@ -0,0 +1,116 @@
+<?php
+// +----------------------------------------------------------------------
+// | likeadmin快速开发前后端分离管理后台(PHP版)
+// +----------------------------------------------------------------------
+// | 欢迎阅读学习系统程序代码,建议反馈是我们前进的动力
+// | 开源版本可自由商用,可去除界面版权logo
+// | gitee下载:https://gitee.com/likeshop_gitee/likeadmin
+// | github下载:https://github.com/likeshop-github/likeadmin
+// | 访问官网:https://www.likeadmin.cn
+// | likeadmin团队 版权所有 拥有最终解释权
+// +----------------------------------------------------------------------
+// | author: likeadminTeam
+// +----------------------------------------------------------------------
+
+namespace app\api\validate;
+
+
+use app\common\validate\BaseValidate;
+
+
+/**
+ * OrderEffectiveLog验证器
+ * Class OrderEffectiveLogValidate
+ * @package app\api\validate
+ */
+class OrderEffectiveLogValidate extends BaseValidate
+{
+
+     /**
+      * 设置校验规则
+      * @var string[]
+      */
+    protected $rule = [
+        'id' => 'require',
+        'effective_id' => 'require',
+        'sn' => 'require',
+        'user_id' => 'require',
+        'work_id' => 'require',
+        'goods_id' => 'require',
+        'effective_num' => 'require',
+        'end_effective_time' => 'require',
+        'effective_images' => 'require'
+    ];
+
+
+    /**
+     * 参数描述
+     * @var string[]
+     */
+    protected $field = [
+        'id' => 'id',
+        'effective_id' => '保修卡ID',
+        'sn' => '订单编号',
+        'user_id' => '用户ID',
+        'work_id' => '工单ID',
+        'goods_id' => '商品ID',
+        'effective_num' => '值',
+        'end_effective_time' => '保修截至时间',
+        'effective_images' => '保修图片/视频',
+
+    ];
+
+
+    /**
+     * @notes 添加场景
+     * @return OrderEffectiveLogValidate
+     * @author likeadmin
+     * @date 2025/01/17 11:10
+     */
+    public function sceneAdd()
+    {
+        return $this->only(['effective_id','sn','user_id','work_id','goods_id','effective_num','end_effective_time']);
+    }
+
+
+    /**
+     * @notes 编辑场景
+     * @return OrderEffectiveLogValidate
+     * @author likeadmin
+     * @date 2025/01/17 11:10
+     */
+    public function sceneEdit()
+    {
+        return $this->only(['id','effective_id','sn','user_id','work_id','goods_id','effective_num','end_effective_time']);
+    }
+
+
+    /**
+     * @notes 删除场景
+     * @return OrderEffectiveLogValidate
+     * @author likeadmin
+     * @date 2025/01/17 11:10
+     */
+    public function sceneDelete()
+    {
+        return $this->only(['id']);
+    }
+
+
+    /**
+     * @notes 详情场景
+     * @return OrderEffectiveLogValidate
+     * @author likeadmin
+     * @date 2025/01/17 11:10
+     */
+    public function sceneDetail()
+    {
+        return $this->only(['id']);
+    }
+
+    public function sceneApplyFor()
+    {
+        return $this->only(['id','effective_images']);
+    }
+
+}

+ 35 - 0
app/common/model/effective/OrderEffectiveLog.php

@@ -0,0 +1,35 @@
+<?php
+// +----------------------------------------------------------------------
+// | likeadmin快速开发前后端分离管理后台(PHP版)
+// +----------------------------------------------------------------------
+// | 欢迎阅读学习系统程序代码,建议反馈是我们前进的动力
+// | 开源版本可自由商用,可去除界面版权logo
+// | gitee下载:https://gitee.com/likeshop_gitee/likeadmin
+// | github下载:https://github.com/likeshop-github/likeadmin
+// | 访问官网:https://www.likeadmin.cn
+// | likeadmin团队 版权所有 拥有最终解释权
+// +----------------------------------------------------------------------
+// | author: likeadminTeam
+// +----------------------------------------------------------------------
+
+namespace app\common\model\effective;
+
+
+use app\common\model\BaseModel;
+
+
+
+/**
+ * OrderEffectiveLog模型
+ * Class OrderEffectiveLog
+ * @package app\common\model
+ */
+class OrderEffectiveLog extends BaseModel
+{
+    
+    protected $name = 'order_effective_log';
+    protected $type = [
+        'effective_images' => 'array',
+    ];
+    
+}

+ 5 - 1
app/common/model/orders/OrderEffectiveLog.php

@@ -2,6 +2,7 @@
 namespace app\common\model\orders;
 use app\common\model\BaseModel;
 use app\common\model\goods\Goods;
+use app\common\model\works\ServiceWork;
 
 /**
  * @author 林海涛
@@ -15,7 +16,10 @@ class OrderEffectiveLog extends BaseModel
     {
         return $this->hasOne(Goods::class, 'id', 'goods_id');
     }
-
+    public function serviceWork()
+    {
+        return $this->hasOne(ServiceWork::class, 'order_effective_id', 'id');
+    }
 
     public function getEndEffectiveTimeAttr($value,$data)
     {

+ 2 - 0
app/common/model/works/ServiceWork.php

@@ -41,6 +41,8 @@ class ServiceWork extends BaseModel
     public static function onAfterUpdate($model)
     {
         if($model->user_confirm_status == 5 and $model->work_status == 7 and $model->work_pay_status==1){
+            // 保修工单完结,进行结算
+            PerformanceLogic::effectivePerformance($model);
             //工单已完结,进行结算,结算完成后设置work_pay_status为2,已结算
             $ratio = 0;
             $commissionConfig = MasterWorkerCommissionConfig::where('master_worker_id',$model->master_worker_id)->where('voucher_status',2)->findOrEmpty();