Parcourir la source

合并自动派单,工程师面试

dongxiaoqin il y a 1 an
Parent
commit
e084e4ac5b

+ 4 - 2
app/common/command/AutomaticDispatch.php

@@ -23,8 +23,8 @@ class AutomaticDispatch extends Command
     //工程师综合评分占比
     protected $comprehensiveRate = 0.55;
 
-    //默认服务时长 300 分钟
-    protected $defaultServiceTime = 300; 
+    //默认服务时长 180 分钟
+    protected $defaultServiceTime = 180; 
 
     protected function configure()
     {
@@ -53,6 +53,7 @@ class AutomaticDispatch extends Command
             // 获取当前时间的前五分钟时间戳
             $fiveMinutesAgo = time() - 120; // 300 秒 = 2 分钟
             $list = ServiceWork::where('work_status',0)
+                        ->where('service_status',0)
                         ->where(function ($query) use ($fiveMinutesAgo) {
                             $query->where('exec_time', 0)->whereOr('exec_time', '<', $fiveMinutesAgo);
                         })
@@ -185,6 +186,7 @@ class AutomaticDispatch extends Command
                 ['master_worker_id','=',$worker['id']],
                 ['work_status','>=',1],
                 ['work_status','<=',5],
+                ['service_status','<',4]
             ])
             ->where(function ($query) use ($appointment_time,$estimated_finish_time) {
                 $query->where('appointment_time', 'between',[$appointment_time, $estimated_finish_time])

+ 8 - 0
app/common/model/master_worker/MasterWorkerInterview.php

@@ -0,0 +1,8 @@
+<?php
+namespace app\common\model\master_worker;
+use app\common\model\BaseModel;
+
+class MasterWorkerInterview extends BaseModel
+{
+    protected $name = 'master_worker_interview';
+}

+ 8 - 0
app/common/model/master_worker/MasterWorkerQuestion.php

@@ -0,0 +1,8 @@
+<?php
+namespace app\common\model\master_worker;
+use app\common\model\BaseModel;
+
+class MasterWorkerQuestion extends BaseModel
+{
+    protected $name = 'master_worker_question';
+}

+ 249 - 0
app/workerapi/controller/InterviewController.php

@@ -0,0 +1,249 @@
+<?php
+
+namespace app\workerapi\controller;
+
+use think\Request;
+use think\facade\Db;
+use app\workerapi\logic\MasterWorkerLogic;
+use app\workerapi\logic\MasterWorkerRegisterLogic;
+use app\common\model\master_worker\MasterWorkerQuestion;
+use app\common\model\master_worker\MasterWorkerInterview;
+use app\common\model\master_worker_register\MasterWorkerRegister;
+
+class InterviewController extends BaseApiController
+{
+    public array $notNeedLogin = ['lists'];
+    private array $list = [
+        [
+            'id' => 1,
+            'title' => '请问您目前的工作状态是全职工作还是自由工作?',
+            'options' => [
+                '全职工作',
+                '自由工作'
+            ],
+            'type' => 1,
+        ],
+        [
+            'id' => 2,
+            'title' => '请问您是否有独立上门给客户提供家电维修/清洗/安装的经验?',
+            'options' => [
+                '有',
+                '没有'
+            ],
+            'type' => 1,
+        ],
+        [
+            'id' => 3,
+            'title' => '请问您有没有在其他同类型平台的工作经验?',
+            'options' => [
+                '有',
+                '没有'
+            ],
+            'type' => 1,
+        ],
+        [
+            'id' => 4,
+            'title' => '请简要说明平台名称、工作时间年限、所服务的类目',
+            'type' => 3,
+        ],
+        [
+            'id' => 5,
+            'title' => '请选择您具备的经验?',
+            'options' => [
+                '家电清洗',
+                '家电维修',
+                '不具备以上经验'
+            ],
+            'type' => 1,
+        ]
+    ];
+
+    private array $list2 = [
+        
+        [
+            'id' => 6,
+            'title' => '请选择您会的项目?最多选5个,最后会根据您所选的项目进行答题。',
+            'options' => [
+                '天井机','风管机','家用中央空调','空调','油烟机','洗衣机','热水器','燃气灶','冰箱'
+            ],
+            'type' => 2,
+        ],
+        [
+            'id' => 7,
+            'title' => '请选择您会的项目?最多选5个,最后会根据您所选的项目进行答题。',
+            'options' => [
+                '空调加氟',
+                '空调维修',
+                '冰箱','制冷设备','油烟机','洗衣机','甩干机','燃气热水器','电热水器','燃气灶','干洗机',
+            ],
+            'type' => 2,
+        ]
+    ];
+
+    private array $list3 = [
+        [
+            'id' => 9,
+            'title' => '请选择您持有的证书?',
+            'options' => [
+                '低压电工作业',
+                '高压电工作业',
+                '高处作业',
+                '制冷与空调作业',
+                '焊接与热切割作业',
+                '无',
+            ],
+            'type' => 1,
+        ],
+        [
+            'id' => 10,
+            'title' => '请简单描述您具备的其他技能?',
+            'type' => 3,
+        ]
+    ];
+    public function lists(Request $request)
+    {
+        // 获取单个 POST 参数
+        $worker_register_id = $request->post('worker_register_id');
+        $step = $request->post('step');
+        // 获取所有 POST 参数
+        $data = $request->post('data');
+        if ( !in_array($step, [1,2,3,4,5])) {
+            return $this->fail('参数错误');
+        }
+        if ($step > 1 && (empty($data) || !is_array($data))) {
+            return $this->fail('答案不可为空');
+        }
+
+        $worker_register_id = MasterWorkerRegister::where('id',$worker_register_id)->value('id');
+        if (!$worker_register_id) {
+            return $this->fail('ID有误');
+        }
+        $info = MasterWorkerInterview::where("worker_register_id", $worker_register_id)->findOrEmpty();
+        if ($info->isEmpty()) {
+            $info = new MasterWorkerInterview();
+            $info->worker_register_id = $worker_register_id;
+        } else if ($info->status > 0) {
+            return $this->fail('您已提交过面试题,请勿重复提交');
+        }
+
+        $msg = '操作成功';
+        $has_next = 1;
+        $is_success = 0;
+        $result = [];
+        $list = $this->list;
+        $list2 = $this->list2;
+        $list3 = $this->list3;
+        $tmplist = array_column($list, null, 'id');
+        if ($step == 1 ) {
+            $result = $list;
+        } elseif ($step == 2) {
+            foreach($data as $item) {
+                if (empty($item['id']) || ($item['id'] != 4 && empty($item['options']))) {
+                    return $this->fail('参数错误');
+                }
+                if ($item['id'] == 5) {
+                    $options = $item['options'];
+                }
+            }
+            if (empty($options)) {
+                return $this->fail('请选择您具备的经验');
+            }
+            $key = array_search($options, $tmplist[5]['options']);
+            if ($key === false || !isset($list2[$key])) {
+                $has_next = 0;
+                $info->status = 2;
+                $msg = '很抱歉,您的测试未通过,感谢您的关注!';
+            } else {
+                //根据上一步的选项判断
+                $result[] = $list2[$key]; 
+            }
+            
+            switch($key) {
+                case 0 :
+                    $info->type = 1;
+                    break;
+                case 1 : 
+                    $info->type = 2;
+                    break;
+                default : 
+                    $info->type = 0;
+            }
+            $info->content = json_encode([ 1 => $data]);
+            $info->save();
+            
+        } elseif ($step == 3) {
+            $data = current($data);
+            $id = empty($data['id']) ? 0 : $data['id'];            
+            if ($id == 6 || $id == 7) {
+                $question = MasterWorkerLogic::getQuestion(['type' => $info->type, 'category' => $data['options']]);
+                foreach($question['list'] as $key => $item) {   
+                    $temp = [
+                        "id" => $item['id'],
+                        "title" => $item['title'],
+                        "options" => explode(",",$item['options']),
+                        "type" => strpos($item['title'], '多选题') !== false ? 2 : 1,
+                    ];
+                    $result[] = $temp;
+                }
+            } else {
+                return $this->fail('参数有误');
+            }
+            $content = json_decode($info->content, true);
+            $content[2] = $data;
+            $info->content = json_encode($content);
+            $info->save();
+        } elseif (($step == 4 && $info->type == 3) || $step == 5) {
+            try{
+                Db::startTrans();
+
+                MasterWorkerRegisterLogic::createMasterWorker(['worker_register_id' => $worker_register_id,'is_rinse' => $info->type]);
+
+                $content = json_decode($info->content, true);
+                $content[$step - 1] = $data;
+                $info->content = json_encode($content);
+                $info->status = 1;
+                $info->save();
+                $has_next = 0;
+                $is_success = 1;
+                $msg = '恭喜您成功入驻众盾闪修平台!';
+                
+                Db::commit();
+            } catch (\Exception $e) {
+                Db::rollback();
+                return $this->fail($e->getMessage());
+            }
+        } else {
+            //校验
+            $data = array_column($data, null, 'id');
+            $ids = array_keys($data);
+            $answers = MasterWorkerQuestion::where('type',$info->type)->whereIn('id',$ids)->column('answer','id');
+            if (count($ids) != count($answers)) {
+                return $this->fail('题目参数有误');
+            }
+            $rights = 0;
+            foreach($data as &$item) {
+                $answer = $answers[$item['id']];
+                $item['options'] = preg_replace('/[^a-zA-Z]/', '', $item['options']);
+                if ($answer == '对' || $answer == '错') {
+                    $item['options'] = $item['options'] == 'A' ? '对' : '错';
+                }
+                if ($item['options'] == $answer) {
+                    $rights ++;
+                }
+            }
+            if ($rights / count($data) >= 0.8) {
+                $result = $list3; 
+            } else {
+                $has_next = 0;
+                $info->status = 2;
+                $msg = '很抱歉,您的测试未通过,感谢您的关注!';
+            }
+            $content = json_decode($info->content, true);
+            $content[$step - 1] = $data;
+            $info->content = json_encode($content);
+            $info->save();
+        }
+        return $this->success($msg, ['has_next' => $has_next,'is_success' => $is_success, 'list' => $result], 1, 1);
+    }
+
+}

+ 31 - 1
app/workerapi/controller/MasterWorkerController.php

@@ -13,7 +13,7 @@ use app\workerapi\validate\MasterWokerValidate;
 
 class MasterWorkerController extends BaseApiController
 {
-    public array $notNeedLogin = ['customerPhone'];
+    public array $notNeedLogin = ['customerPhone','interview','getQuestion','getInterview','getRegInfo'];
 
     /**
      * @notes 修改密码
@@ -146,4 +146,34 @@ class MasterWorkerController extends BaseApiController
         }
         return $this->success('操作成功', $result, 1, 1);
     }
+    public function interview()
+    {
+        $params = (new MasterWokerValidate())->post()->goCheck('interview');
+        $result = MasterWorkerLogic::setInterview($params);
+        if (false === $result) {
+            return $this->fail(MasterWorkerLogic::getError());
+        }
+        return $this->success('操作成功', $result, 1, 1);
+    }
+    public function getInterview()
+    {
+        $params = (new MasterWokerValidate())->get()->goCheck('getInterview');
+        $result = MasterWorkerLogic::getInterview($params);
+        return $this->data($result);
+    }
+    public function getQuestion()
+    {
+        $params = (new MasterWokerValidate())->post()->goCheck('question');
+        $result = MasterWorkerLogic::getQuestion($params);
+        return json(['code' => 1, 'data' => $result['list'],'text'=> $result['text'], 'msg' => 'success']);
+    }
+
+    
+    public function getRegInfo()
+    {
+        $params = (new MasterWokerValidate())->post()->goCheck('getRegInfo');
+        $result = MasterWorkerLogic::getRegInfo($params);
+        echo $result;
+        die;
+    }
 }

+ 155 - 2
app/workerapi/logic/MasterWorkerLogic.php

@@ -1,5 +1,6 @@
 <?php
 namespace app\workerapi\logic;
+
 use app\adminapi\logic\training\TrainingBlockConfigLogic;
 use app\common\enum\worker\WorkerAccountLogEnum;
 use app\common\enum\YesNoEnum;
@@ -10,6 +11,8 @@ use app\common\model\master_worker\MasterWorkerAccountLog;
 use app\common\model\master_worker\MasterWorkerAgree;
 use app\common\model\master_worker\MasterWorkerInfo;
 use app\common\model\master_worker_register\MasterWorkerRegister;
+use app\common\model\master_worker\MasterWorkerQuestion;
+use app\common\model\master_worker\MasterWorkerInterview;
 use app\common\model\training\TrainingWorkerTask;
 use app\common\model\works\ServiceWork;
 use app\common\service\FileService;
@@ -17,6 +20,8 @@ use app\workerapi\service\MasterWokerTaskRequiredService;
 use think\Exception;
 use think\facade\Config;
 use think\facade\Log;
+use think\facade\Db;
+
 
 /**
  * @author 林海涛
@@ -236,7 +241,6 @@ class MasterWorkerLogic extends  BaseLogic
         }
     }
 
-
     public static function taskRequired($userId,$identity_source): bool
     {
 
@@ -271,6 +275,155 @@ class MasterWorkerLogic extends  BaseLogic
         return true;
     }
 
+    /**
+     * 查询机器人面试结果
+     */
+    public static function getInterview(array $params)
+    {
+        if (empty($params['worker_id'])) {
+            return false;
+        }
+        $info = MasterWorkerInterview::where('worker_id',$params['worker_id'])
+                    ->field('id,worker_id,type,status,nickname,create_time')
+                    ->select()
+                    ->toArray();
+        return $info;
+    }
+    /**
+     * 机器人面试结果
+     */
+    public static function setInterview(array $params)
+    {
+        try {
+            
+            if (empty($params['worker_id']) || empty($params['answer']) || empty($params['answer1']) || empty($params['answer2']) ) {
+                return false;
+            }
+            if (!empty($params['answer7'])) {
+                //维修
+                $type = 1;
+            } else if (!empty($params['answer6'])) {
+                //清洗
+                $type = 2;
+            } else if (!empty($params['answer5'])) {
+                //安装
+                $type = 3;
+                $params['status'] = 1;
+            } else {
+                $type = 0;
+                $params['status'] = 0;
+            }
+
+            //校验一下工程师注册ID是否有效
+            $worker_register_id = $params['worker_id'];
+            $worker_register_id = MasterWorkerRegister::where('id',$worker_register_id)->value('id');
+            if (!$worker_register_id) {
+                return false;
+            }
+
+            $info = MasterWorkerInterview::where('worker_id',$params['worker_id'])->value("id");
+            if ($info) {
+                return false;
+            }
+            $params['nickname'] = isset($params['nickname']) ?? '';
+            $insertData = [
+                'sys_uuid' => $params['sys_uuid'],
+                'worker_id' => $params['worker_id'],
+                'nickname' => $params['nickname'],
+                'type' => $type,
+                'status' => $params['status'],
+            ];
+            unset($params['sys_uuid']);
+            unset($params['worker_id']);
+            unset($params['nickname']);
+            unset($params['status']);
+            $insertData['content'] = json_encode($params);
+
+            Db::startTrans();
+
+            MasterWorkerInterview::create($insertData);
+            MasterWorkerRegisterLogic::createMasterWorker(['worker_register_id' => $worker_register_id]);
+
+            Db::commit();
+            return [];
+        } catch (\Exception $e) {
+            Db::rollback();
+            self::$error = $e->getMessage();
+            self::$returnCode = $e->getCode();
+            return false;
+        }
+    }
+
+    /**
+     * 查询工程师面试题库
+     */
+    public static function getQuestion(array $params)
+    {
+        if ($params['type'] == 1 || $params['type'] == 2) {
+
+            $category = trim($params['category']);
+            $category = str_replace(',', ',', $category);
+            $category = explode(',', $category);
+            $category = array_slice($category, 0, 5);
+            $list = MasterWorkerQuestion::where('type',$params['type'])
+                        ->whereIn('category', $category)
+                        ->where('type',$params['type'])
+                        ->limit(100)
+                        ->select()
+                        ->toArray();
+            // 按 category 分组
+            $grouped = [];
+            foreach ($list as $item) {
+                $category = $item['category'];
+                if (!isset($grouped[$category])) {
+                    $grouped[$category] = [];
+                }
+                $grouped[$category][] = $item;
+            }
 
+            // 从每组中随机取 5 个元素
+            $result = [];
+            foreach ($grouped as $category => $items) {
+                $randomItems = [];
+                $count = count($items);
+                if ($count <= 5) {
+                    $randomItems = $items;
+                } else {
+                    $keys = array_rand($items, 5);
+                    foreach ($keys as $key) {
+                        $randomItems[] = $items[$key];
+                    }
+                }
+                $result = array_merge($result,$randomItems);
+            }
+            $text = '';
+            $i = 0;
+            foreach($result as $item) {
+                $i++;
+                $text .= $i.'.'.$item['title']."\r\n"."  ". str_replace(",","\r\n",$item['options'])."\r\n\r\n";
+            }
+            return [
+                'list' => array_values($result),
+                'text' => $text
+            ];
+        } 
+        return false;
+    }
+    public static function getRegInfo(array $params)
+    {
+        if (empty($params['user'])){
+            return 0;
+        }
+        $user = trim($params['user']);
+        $pattern = '/(\d{11})/';
+        if (preg_match($pattern, $user, $matches)) {
+            // 提取手机号
+            $mobile = $matches[1];
+        } 
 
-}
+        $specialChars = array('.', ',', '。', ',', $mobile);
+        $name = str_replace($specialChars,"",$user);
+        return (int)MasterWorkerRegister::where('name',$name)->where('mobile',$mobile)->value('id');
+    }
+    
+}

+ 18 - 0
app/workerapi/validate/MasterWokerValidate.php

@@ -68,4 +68,22 @@ class MasterWokerValidate  extends BaseValidate
     {
         return $this->only(['field', 'value']);
     }
+
+    public function sceneInterview()
+    {
+        return $this->only(['sys_uuid', 'worker_id','nickname','status','start_answer','answer','answer1','answer2','answer3','answer4','answer5','answer6','answer7','answer8','answer9','answer10','question_answer']);
+    }
+
+    public function sceneQuestion()
+    {
+        return $this->only(['category']);
+    }
+    public function sceneGetInterview()
+    {
+        return $this->only(['worker_id']);
+    }
+    public function sceneGetRegInfo()
+    {
+        return $this->only(['user']);
+    }
 }