Przeglądaj źródła

add - 团队管理、前端API

liugc 1 rok temu
rodzic
commit
c68973a5d6

+ 108 - 0
app/adminapi/controller/master_worker/MasterWorkerTeamController.php

@@ -0,0 +1,108 @@
+<?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\master_worker;
+
+
+use app\adminapi\controller\BaseAdminController;
+use app\adminapi\lists\master_worker\MasterWorkerTeamLists;
+use app\adminapi\logic\master_worker\MasterWorkerTeamLogic;
+use app\adminapi\validate\master_worker\MasterWorkerTeamValidate;
+
+
+/**
+ * MasterWorkerTeam控制器
+ * Class MasterWorkerTeamController
+ * @package app\adminapi\controller
+ */
+class MasterWorkerTeamController extends BaseAdminController
+{
+
+
+    /**
+     * @notes 获取列表
+     * @return \think\response\Json
+     * @author likeadmin
+     * @date 2024/11/20 17:42
+     */
+    public function lists()
+    {
+        return $this->dataLists(new MasterWorkerTeamLists());
+    }
+
+
+    /**
+     * @notes 添加
+     * @return \think\response\Json
+     * @author likeadmin
+     * @date 2024/11/20 17:42
+     */
+    public function add()
+    {
+        $params = (new MasterWorkerTeamValidate())->post()->goCheck('add');
+        $result = MasterWorkerTeamLogic::add($params);
+        if (true === $result) {
+            return $this->success('添加成功', [], 1, 1);
+        }
+        return $this->fail(MasterWorkerTeamLogic::getError());
+    }
+
+
+    /**
+     * @notes 编辑
+     * @return \think\response\Json
+     * @author likeadmin
+     * @date 2024/11/20 17:42
+     */
+    public function edit()
+    {
+        $params = (new MasterWorkerTeamValidate())->post()->goCheck('edit');
+        $result = MasterWorkerTeamLogic::edit($params);
+        if (true === $result) {
+            return $this->success('编辑成功', [], 1, 1);
+        }
+        return $this->fail(MasterWorkerTeamLogic::getError());
+    }
+
+
+    /**
+     * @notes 删除
+     * @return \think\response\Json
+     * @author likeadmin
+     * @date 2024/11/20 17:42
+     */
+    public function delete()
+    {
+        $params = (new MasterWorkerTeamValidate())->post()->goCheck('delete');
+        MasterWorkerTeamLogic::delete($params);
+        return $this->success('删除成功', [], 1, 1);
+    }
+
+
+    /**
+     * @notes 获取详情
+     * @return \think\response\Json
+     * @author likeadmin
+     * @date 2024/11/20 17:42
+     */
+    public function detail()
+    {
+        $params = (new MasterWorkerTeamValidate())->goCheck('detail');
+        $result = MasterWorkerTeamLogic::detail($params);
+        return $this->data($result);
+    }
+
+
+}

+ 4 - 0
app/adminapi/lists/master_worker/MasterWorkerLists.php

@@ -19,6 +19,7 @@ use app\adminapi\lists\BaseAdminDataLists;
 use app\adminapi\service\DistributeLeafletsService;
 use app\common\model\master_worker\MasterWorker;
 use app\common\lists\ListsSearchInterface;
+use app\common\model\master_worker\MasterWorkerTeam;
 use app\common\model\works\ServiceWork;
 use think\db\Query;
 use think\facade\Db;
@@ -52,6 +53,7 @@ class MasterWorkerLists extends BaseAdminDataLists implements ListsSearchInterfa
 
     public function queryWhere(){
         $where = [];
+        $where[] = ['mw.team_role','in',[0,1]];
         if(isset($this->params['time_period']) && !empty($this->params['time_period'])){
             $sqls = [];
             foreach ($this->params['time_period'] as $item) {
@@ -129,8 +131,10 @@ class MasterWorkerLists extends BaseAdminDataLists implements ListsSearchInterfa
             ->field(['master_worker_id',Db::raw('COUNT(id) as work_total')])
             ->group('master_worker_id')
             ->select()->toArray(),'work_total','master_worker_id');
+        $teams = MasterWorkerTeam::whereIn('master_worker_id', array_column($list, 'id'))->column('team_name','master_worker_id');
         foreach ($list as &$item) {
             $item['work_total'] = $workCount[$item['id']]??0;
+            $item['team_name'] = $teams[$item['id']]??'';
         }
         return $list;
     }

+ 79 - 0
app/adminapi/lists/master_worker/MasterWorkerTeamLists.php

@@ -0,0 +1,79 @@
+<?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\master_worker;
+
+
+use app\adminapi\lists\BaseAdminDataLists;
+use app\common\model\master_worker\MasterWorkerTeam;
+use app\common\lists\ListsSearchInterface;
+
+
+/**
+ * MasterWorkerTeam列表
+ * Class MasterWorkerTeamLists
+ * @package app\adminapi\lists
+ */
+class MasterWorkerTeamLists extends BaseAdminDataLists implements ListsSearchInterface
+{
+
+
+    /**
+     * @notes 设置搜索条件
+     * @return \string[][]
+     * @author likeadmin
+     * @date 2024/11/20 17:42
+     */
+    public function setSearch(): array
+    {
+        return [
+            '=' => ['team_name', 'master_worker_id'],
+
+        ];
+    }
+
+
+    /**
+     * @notes 获取列表
+     * @return array
+     * @throws \think\db\exception\DataNotFoundException
+     * @throws \think\db\exception\DbException
+     * @throws \think\db\exception\ModelNotFoundException
+     * @author likeadmin
+     * @date 2024/11/20 17:42
+     */
+    public function lists(): array
+    {
+        return MasterWorkerTeam::with(['masterWorker'])->where($this->searchWhere)
+            ->field(['id', 'team_name', 'master_worker_id'])
+            ->append(['master_worker_name'])
+            ->limit($this->limitOffset, $this->limitLength)
+            ->order(['id' => 'desc'])
+            ->select()
+            ->toArray();
+    }
+
+
+    /**
+     * @notes 获取数量
+     * @return int
+     * @author likeadmin
+     * @date 2024/11/20 17:42
+     */
+    public function count(): int
+    {
+        return MasterWorkerTeam::where($this->searchWhere)->count();
+    }
+
+}

+ 141 - 0
app/adminapi/logic/master_worker/MasterWorkerTeamLogic.php

@@ -0,0 +1,141 @@
+<?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\master_worker;
+
+
+use app\common\model\master_worker\MasterWorker;
+use app\common\model\master_worker\MasterWorkerTeam;
+use app\common\logic\BaseLogic;
+use think\facade\Db;
+
+
+/**
+ * MasterWorkerTeam逻辑
+ * Class MasterWorkerTeamLogic
+ * @package app\adminapi\logic
+ */
+class MasterWorkerTeamLogic extends BaseLogic
+{
+
+
+    /**
+     * @notes 添加
+     * @param array $params
+     * @return bool
+     * @author likeadmin
+     * @date 2024/11/20 17:42
+     */
+    public static function add(array $params): bool
+    {
+        Db::startTrans();
+        try {
+            $masterWorker = \app\common\model\master_worker\MasterWorker::where('id', $params['master_worker_id'])->find();
+            if($masterWorker['team_id']){
+                throw new \Exception('该师傅已加入团队,请先退出团队');
+            }
+            $masterWorkerTeam = MasterWorkerTeam::create([
+                'team_name' => $params['team_name'],
+                'master_worker_id' => $params['master_worker_id'],
+            ]);
+            MasterWorker::where('id', $params['master_worker_id'])->update(
+                [
+                    'team_id' => $masterWorkerTeam->id,
+                    'team_role' => 1,
+                ]
+            );
+            Db::commit();
+            return true;
+        } catch (\Exception $e) {
+            Db::rollback();
+            self::setError($e->getMessage());
+            return false;
+        }
+    }
+
+
+    /**
+     * @notes 编辑
+     * @param array $params
+     * @return bool
+     * @author likeadmin
+     * @date 2024/11/20 17:42
+     */
+    public static function edit(array $params): bool
+    {
+        Db::startTrans();
+        try {
+            $masterWorker = \app\common\model\master_worker\MasterWorker::where('id', $params['master_worker_id'])->find();
+            if($masterWorker['team_id']){
+                throw new \Exception('该师傅已加入团队,请先退出团队');
+            }
+            $masterWorkerTeam = MasterWorkerTeam::where('id', $params['id'])->find();
+            \app\common\model\master_worker\MasterWorker::where('id', $masterWorkerTeam['master_worker_id'])->update(
+                [
+                    'team_id' => 0,
+                    'team_role' => 0,
+                ]
+            );
+            MasterWorkerTeam::where('id', $params['id'])->update([
+                'team_name' => $params['team_name'],
+                'master_worker_id' => $params['master_worker_id'],
+            ]);
+            \app\common\model\master_worker\MasterWorker::where('id', $params['master_worker_id'])->update(
+                [
+                    'team_id' => $params['id'],
+                    'team_role' => 1,
+                ]
+            );
+            Db::commit();
+            return true;
+        } catch (\Exception $e) {
+            Db::rollback();
+            self::setError($e->getMessage());
+            return false;
+        }
+    }
+
+
+    /**
+     * @notes 删除
+     * @param array $params
+     * @return bool
+     * @author likeadmin
+     * @date 2024/11/20 17:42
+     */
+    public static function delete(array $params): bool
+    {
+        $masterWorkerTeam = MasterWorkerTeam::where('id', $params['id'])->find();
+        \app\common\model\master_worker\MasterWorker::where('id', $masterWorkerTeam['master_worker_id'])->update(
+            [
+                'team_id' => 0,
+                'team_role' => 0,
+            ]
+        );
+        return MasterWorkerTeam::destroy($params['id']);
+    }
+
+
+    /**
+     * @notes 获取详情
+     * @param $params
+     * @return array
+     * @author likeadmin
+     * @date 2024/11/20 17:42
+     */
+    public static function detail($params): array
+    {
+        return MasterWorkerTeam::with('masterWorker')->findOrEmpty($params['id'])->toArray();
+    }
+}

+ 100 - 0
app/adminapi/validate/master_worker/MasterWorkerTeamValidate.php

@@ -0,0 +1,100 @@
+<?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\master_worker;
+
+
+use app\common\validate\BaseValidate;
+
+
+/**
+ * MasterWorkerTeam验证器
+ * Class MasterWorkerTeamValidate
+ * @package app\adminapi\validate
+ */
+class MasterWorkerTeamValidate extends BaseValidate
+{
+
+     /**
+      * 设置校验规则
+      * @var string[]
+      */
+    protected $rule = [
+        'id' => 'require',
+        'team_name' => 'require',
+        'master_worker_id' => 'require',
+
+    ];
+
+
+    /**
+     * 参数描述
+     * @var string[]
+     */
+    protected $field = [
+        'id' => 'id',
+        'team_name' => '团队名称',
+        'master_worker_id' => '负责工程师ID',
+
+    ];
+
+
+    /**
+     * @notes 添加场景
+     * @return MasterWorkerTeamValidate
+     * @author likeadmin
+     * @date 2024/11/20 17:42
+     */
+    public function sceneAdd()
+    {
+        return $this->only(['team_name','master_worker_id']);
+    }
+
+
+    /**
+     * @notes 编辑场景
+     * @return MasterWorkerTeamValidate
+     * @author likeadmin
+     * @date 2024/11/20 17:42
+     */
+    public function sceneEdit()
+    {
+        return $this->only(['id','team_name','master_worker_id']);
+    }
+
+
+    /**
+     * @notes 删除场景
+     * @return MasterWorkerTeamValidate
+     * @author likeadmin
+     * @date 2024/11/20 17:42
+     */
+    public function sceneDelete()
+    {
+        return $this->only(['id']);
+    }
+
+
+    /**
+     * @notes 详情场景
+     * @return MasterWorkerTeamValidate
+     * @author likeadmin
+     * @date 2024/11/20 17:42
+     */
+    public function sceneDetail()
+    {
+        return $this->only(['id']);
+    }
+
+}

+ 2 - 0
app/common/cache/MasterWokerTokenCache.php

@@ -83,6 +83,8 @@ class MasterWokerTokenCache extends BaseCache
             'sn' => $user->sn,
             'mobile' => $user->mobile,
             'avatar' => $user->avatar,
+            'team_id' => $user->team_id,
+            'team_role' => $user->team_role,
             'terminal' => $userSession->terminal,
             'expire_time' => $userSession->expire_time,
         ];

+ 41 - 0
app/common/model/master_worker/MasterWorkerTeam.php

@@ -0,0 +1,41 @@
+<?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\master_worker;
+
+
+use app\common\model\BaseModel;
+
+
+
+/**
+ * MasterWorkerTeam模型
+ * Class MasterWorkerTeam
+ * @package app\common\model
+ */
+class MasterWorkerTeam extends BaseModel
+{
+    
+    protected $name = 'master_worker_team';
+
+    public function masterWorker()
+    {
+        return $this->hasOne(MasterWorker::class, 'id', 'master_worker_id');
+    }
+    public function getMasterWorkerNameAttr($value,$data):string{
+        return MasterWorker::where('id',$data['master_worker_id'])->value('real_name') ?? '';
+    }
+
+
+}

+ 1 - 1
app/common/model/works/ServiceWork.php

@@ -70,7 +70,7 @@ class ServiceWork extends BaseModel
     public function getWorkStatusTextAttr($value,$data)
     {
          $status = [0=>'待派单',1=>'待领单',2=>'待联系',3=>'待上门',4=>'已上门',5=>'服务中',6=>'待结算',7=>'已完结',8=>'已评价',9=>'已退费'];
-        return $data['service_status']===4?'已取消':$status[$data['work_status']];
+        return (isset($data['service_status']) && $data['service_status']===4)?'已取消':$status[$data['work_status']];
     }
 
     public function getUserConfirmStatusTextAttr($value,$data)

+ 93 - 0
app/workerapi/controller/MasterWorkerTeamController.php

@@ -0,0 +1,93 @@
+<?php
+
+namespace app\workerapi\controller;
+
+use app\common\logic\MasterWorkerExamineLogic;
+use app\common\model\dict\DictData;
+use app\workerapi\lists\ServiceWorkLists;
+use app\workerapi\logic\LoginLogic;
+use app\workerapi\logic\MasterWorkerInfoLogic;
+use app\workerapi\logic\MasterWorkerLogic;
+use app\workerapi\logic\MasterWorkerTeamLogic;
+use app\workerapi\validate\BankAccountValidate;
+use app\workerapi\validate\MasterWokerInfoValidate;
+use app\workerapi\validate\MasterWokerTeamValidate;
+use app\workerapi\validate\MasterWokerValidate;
+
+class MasterWorkerTeamController extends BaseApiController
+{
+    public array $notNeedLogin = [''];
+
+    /**
+     * 获取团队信息
+     * @return \think\response\Json
+     */
+    public function getTeamInfo()
+    {
+        $params = (new MasterWokerTeamValidate())->get()->goCheck('info');
+        $result = MasterWorkerTeamLogic::getDetail($params['id'],$this->userId);
+        return $this->data($result);
+    }
+
+    /**
+     * 团队成员列表展示和分配
+     * @return \think\response\Json
+     */
+    public function getMemberList()
+    {
+        $params = (new MasterWokerTeamValidate())->get()->goCheck('info');
+        $result = MasterWorkerTeamLogic::getMemberList($params['id'],$this->userId);
+        return $this->data($result);
+    }
+
+    /**
+     * 添加团队成员
+     * @return \think\response\Json
+     */
+    public function addTeamMember()
+    {
+        $params = (new MasterWokerTeamValidate())->post()->goCheck('add');
+        /*$res = LoginLogic::confirmMobile($params);
+        if(!$res){
+            return $this->fail(LoginLogic::getError());
+        }*/
+        $result = MasterWorkerTeamLogic::addTeamMember($params,$this->userId);
+        if($result === false){
+            return $this->fail(MasterWorkerTeamLogic::getError());
+        }
+        return $this->success('', [], 1, 1);
+    }
+
+    /**
+     * 分配工单给团队成员
+     * @return \think\response\Json
+     */
+    public function allocation()
+    {
+        $params = (new MasterWokerTeamValidate())->post()->goCheck('allocation');
+        $result = MasterWorkerTeamLogic::allocation($params,$this->userInfo);
+        if($result === false){
+            return $this->fail(MasterWorkerTeamLogic::getError());
+        }
+        return $this->success('', [], 1, 1);
+    }
+    /**
+     * 团队工单状态统计查询
+     * @return \think\response\Json
+     */
+    public function getTeamWorkCount()
+    {
+        $result = MasterWorkerTeamLogic::MemberWorkStatistics($this->userInfo);
+        return $this->data($result);
+    }
+
+    /**
+     * 团队工单查询
+     * @return \think\response\Json
+     */
+    public function getTeamWorkLists()
+    {
+        return $this->dataLists(MasterWorkerTeamLogic::MemberWorkLists($this->userInfo));
+    }
+
+}

+ 2 - 0
app/workerapi/logic/LoginLogic.php

@@ -165,6 +165,8 @@ class LoginLogic extends BaseLogic
                 'sn' => $userInfo['sn'],
                 'mobile' => $userInfo['mobile'],
                 'avatar' => $avatar,
+                'team_id' => $userInfo['team_id'],
+                'team_role' => $userInfo['team_role'],
                 'token' => $userInfo['token'],
                 'is_id_card'=>!empty($is_id_card)?1:0,
                 'is_bank'=>!empty($is_bank)?1:0,

+ 154 - 0
app/workerapi/logic/MasterWorkerTeamLogic.php

@@ -0,0 +1,154 @@
+<?php
+namespace app\workerapi\logic;
+use app\adminapi\logic\master_worker_register\MasterWorkerRegisterLogic;
+use app\common\enum\worker\WorkerAccountLogEnum;
+use app\common\enum\YesNoEnum;
+use app\common\logic\BaseLogic;
+use app\common\model\bank_account\BankAccount;
+use app\common\model\master_worker\MasterWorker;
+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\MasterWorkerTeam;
+use app\common\model\works\ServiceWork;
+use app\common\service\FileService;
+use app\workerapi\lists\ServiceWorkLists;
+use think\Exception;
+use think\facade\Config;
+use think\facade\Db;
+
+/**
+ * @author 林海涛
+ * @date 2024/7/10 下午1:45
+ */
+class MasterWorkerTeamLogic extends  BaseLogic
+{
+    public static function getDetail(int $teamId,int $masterWorkerId)
+    {
+        try {
+            $team = MasterWorkerTeam::where('id',$teamId)->where('master_worker_id',$masterWorkerId)->findOrEmpty();
+            if ($team->isEmpty()) {
+                throw new \Exception('团队不存在');
+            }
+
+            return $team->toArray();
+        } catch (\Exception $e) {
+            self::setError($e->getMessage());
+            return [];
+        }
+    }
+
+    public static function addTeamMember(array $params,int $masterWorkerId)
+    {
+        try {
+            $team = MasterWorkerTeam::where('master_worker_id',$masterWorkerId)->findOrEmpty();
+            if ($team->isEmpty()) {
+                throw new \Exception('团队不存在');
+            }
+            $masterWorker =  \app\common\model\master_worker\MasterWorker::where('mobile',$params['mobile'])->findOrEmpty();
+            if (!$masterWorker->isEmpty()) {
+                throw new \Exception('该手机号已占用');
+            }
+            // 新增工程师
+            $mwId = MasterWorkerRegisterLogic::createMasterWorker([
+                'mobile' => $params['mobile'],
+                'lon' => isset($params['lon'])?$params['lon']:0,
+                'lat' => isset($params['lat'])?$params['lat']:0,
+            ]);
+            MasterWorker::where('id',$mwId)->update(['team_id'=>$team->id,'team_role'=>2]);
+            return true;
+        } catch (\Exception $e) {
+            self::setError($e->getMessage());
+            return false;
+        }
+    }
+
+
+    public static function getMemberList(int $teamId,int $masterWorkerId)
+    {
+        try {
+            $team = MasterWorkerTeam::where('id',$teamId)->where('master_worker_id',$masterWorkerId)->findOrEmpty();
+            if ($team->isEmpty()) {
+                throw new \Exception('团队不存在');
+            }
+            return MasterWorker::where('team_id',$teamId)->where('team_role',2)->field(['id','nickname','avatar','mobile','real_name','team_role'])->select()->toArray();
+        } catch (\Exception $e) {
+            self::setError($e->getMessage());
+            return [];
+        }
+    }
+
+
+    /**
+     * 分配给团队成员
+     * @param int $teamId
+     * @param int $masterWorkerId
+     * @return array
+     */
+    public static function allocation($params,$userInfo){
+        Db::startTrans();
+        try {
+            $work = ServiceWork::findOrEmpty($params['work_id']);
+            if($work->isEmpty()){
+                throw new Exception('工单不存在');
+            }
+            if($work->work_status != 1 ){
+                throw new \Exception('工单已被领取,不可分配');
+            }
+            if($work->master_worker_id == $params['master_worker_id']){
+                throw new \Exception('分配的工程师相同');
+            }
+            $worker = MasterWorker::where(['id'=>$params['master_worker_id'],'team_id' =>$userInfo['team_id'],'team_role' =>2,'is_disable' =>0])->findOrEmpty();
+            if($worker->isEmpty()){
+                throw new \Exception('成员工程师不存在或被禁用');
+            }
+            if($worker->master_worker_id){
+                MasterWorker::setWorktotal('dec',$worker->master_worker_id);
+            }
+            $work->master_worker_id = $params['master_worker_id'];
+            $work->work_status = 1;
+            $work->dispatch_time = time();
+            MasterWorker::setWorktotal('inc',$params['master_worker_id']);
+            $work->save();
+            $work_log = [
+                'work_id'=>$work->id,
+                'master_worker_id'=>$work->master_worker_id,
+                'opera_log'=>'团队负责人['.$userInfo['user_id'].']'.$userInfo['real_name'].'于'.date('Y-m-d H:i:s',time()).'分配了工程师成员'.'编号['.$worker->worker_number.']'.$worker->real_name
+            ];
+            ServiceWorkerAllocateWorkerLogic::add($work_log);
+            Db::commit();
+            return true;
+        }catch(\Exception $e){
+            Db::rollback();
+            self::setError($e->getMessage());
+            return false;
+        }
+    }
+
+    /**
+     * 团队成员工单统计
+     * @param int $teamId
+     * @param int $masterWorkerId
+     * @return array
+     */
+    public static function MemberWorkStatistics($userInfo){
+        return ServiceWork::whereIn('master_worker_id',
+                MasterWorker::where('team_id', $userInfo['team_id'])->where('team_role', 2)->column('id')
+            )->group('work_status')
+            ->field('work_status, COUNT(id) as count_num')
+            ->append(['work_status_text'])
+            ->order('work_status asc')
+            ->select()
+            ->toArray();
+    }
+
+    public static function MemberWorkLists($userInfo){
+
+
+    }
+
+
+
+
+
+}

+ 43 - 0
app/workerapi/validate/MasterWokerTeamValidate.php

@@ -0,0 +1,43 @@
+<?php
+namespace app\workerapi\validate;
+use app\common\enum\notice\NoticeEnum;
+use app\common\service\sms\SmsDriver;
+use app\common\validate\BaseValidate;
+
+class MasterWokerTeamValidate  extends BaseValidate
+{
+    protected $rule = [
+        'id' => 'require',
+        'name' => 'require',
+        'age' => 'require',
+        'mobile' => 'require',
+        'lon' => 'require',
+        'lat' => 'require',
+        'address' => 'require',
+        'work_id' => 'require',
+        'master_worker_id' => 'require',
+    ];
+
+
+    protected $message = [
+        'id.require' => '请输入团队Id',
+        'name.require' => '姓名不能为空',
+        'age.require' => '年龄不能为空',
+        'mobile.require' => '手机号不能为空',
+        'lon.require' => '经纬度不能为空',
+        'lat.require' => '经纬度不能为空',
+        'address.require' => '地址不能为空',
+        'work_id.require' => '工单Id不能为空',
+        'master_worker_id.require' => '成员Id不能为空',
+    ];
+
+    public function sceneInfo(){
+        return $this->only(['id']);
+    }
+    public function sceneAdd(){
+        return $this->only(['mobile']);
+    }
+    public function sceneAllocation(){
+        return $this->only(['work_id','master_worker_id']);
+    }
+}