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

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

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

+ 4 - 6
app/workerapi/controller/MasterWorkerTeamController.php

@@ -4,6 +4,7 @@ namespace app\workerapi\controller;
 
 use app\common\logic\MasterWorkerExamineLogic;
 use app\common\model\dict\DictData;
+use app\workerapi\lists\MasterWorkerLists;
 use app\workerapi\lists\ServiceWorkLists;
 use app\workerapi\lists\TeamServiceWorkLists;
 use app\workerapi\logic\LoginLogic;
@@ -25,8 +26,7 @@ class MasterWorkerTeamController extends BaseApiController
      */
     public function getTeamInfo()
     {
-        $params = (new MasterWokerTeamValidate())->get()->goCheck('info');
-        $result = MasterWorkerTeamLogic::getDetail($params['id'],$this->userId);
+        $result = MasterWorkerTeamLogic::getDetail($this->userId);
         return $this->data($result);
     }
 
@@ -36,9 +36,7 @@ class MasterWorkerTeamController extends BaseApiController
      */
     public function getMemberList()
     {
-        $params = (new MasterWokerTeamValidate())->get()->goCheck('info');
-        $result = MasterWorkerTeamLogic::getMemberList($params['id'],$this->userId);
-        return $this->data($result);
+        return $this->dataLists(new MasterWorkerLists());
     }
 
     /**
@@ -73,7 +71,7 @@ class MasterWorkerTeamController extends BaseApiController
         return $this->success('', [], 1, 1);
     }
     /**
-     * 团队工单状态统计查询
+     * 团队工单状态统计
      * @return \think\response\Json
      */
     public function getTeamWorkCount()

+ 84 - 0
app/workerapi/lists/MasterWorkerLists.php

@@ -0,0 +1,84 @@
+<?php
+namespace app\workerapi\lists;
+
+use app\common\enum\worker\WorkerAccountLogEnum;
+use app\common\lists\ListsExtendInterface;
+use app\common\model\master_worker\MasterWorker;
+use app\common\model\master_worker\MasterWorkerAccountLog;
+use app\common\model\master_worker\MasterWorkerTeam;
+use app\common\lists\ListsSearchInterface;
+use app\common\model\works\ServiceWork;
+use app\workerapi\logic\MasterWorkerTeamLogic;
+
+
+/**
+ * ServiceWork列表
+ * Class ServiceWorkLists
+ * @package app\workerapi\listsworks
+ */
+class MasterWorkerLists extends BaseWorkerDataLists implements ListsSearchInterface,ListsExtendInterface
+{
+    public function setSearch(): array
+    {
+        return [];
+    }
+
+    public function queryWhere(){
+        $where = [];
+        if($this->request->controller() == 'MasterWorkerTeam' && $this->request->action() == 'getMemberList'){
+            $team = MasterWorkerTeam::where('master_worker_id',$this->userId)->findOrEmpty();
+            if ($team->isEmpty()) {
+                $where[] = ['team_id','=',-1];
+            }else{
+                $where[] = ['team_id','=',$team['id']];
+                $where[] = ['team_role','=',2];
+            }
+        }
+        return $where;
+    }
+
+    /**
+     * @notes 获取列表
+     * @return array
+     * @throws \think\db\exception\DataNotFoundException
+     * @throws \think\db\exception\DbException
+     * @throws \think\db\exception\ModelNotFoundException
+     * @author whitef
+     * @date 2024/07/10 15:06
+     */
+    public function lists(): array
+    {
+        $list = MasterWorker::where($this->searchWhere)
+            ->where($this->queryWhere())
+            ->where('is_disable',0)
+            ->field(['id','nickname','avatar','mobile','real_name','team_role'])
+            ->limit($this->limitOffset, $this->limitLength)
+            ->order(['id' => 'asc'])
+            ->select()
+            ->toArray();
+        // 完工数 本月收益
+        foreach ($list as &$item){
+            $item['work_total'] = ServiceWork::where(['user_confirm_status'=>5])->where(['master_worker_id'=>$item['id']])->count();
+            $item['income'] = MasterWorkerAccountLog::where(['worker_id'=>$item['id']])
+                ->where(['change_object'=>WorkerAccountLogEnum::UM,'change_type'=>WorkerAccountLogEnum::UM_INC_ADMIN,'action'=>WorkerAccountLogEnum::INC])
+                ->whereBetweenTime('create_time',date('Y-m-01 00:00:00',time()),date('Y-m-d 23:59:59',time()))
+                ->sum('change_amount');
+        }
+        return $list;
+    }
+    /**
+     * @notes 获取数量
+     * @return int
+     * @author whitef
+     * @date 2024/07/10 15:06
+     */
+    public function count(): int
+    {
+        return MasterWorker::where($this->searchWhere)->where($this->queryWhere())->count();
+    }
+    public function extend(): array
+    {
+        return MasterWorkerTeamLogic::getDetail($this->userId);
+    }
+
+}

+ 12 - 2
app/workerapi/lists/ServiceWorkLists.php

@@ -1,6 +1,8 @@
 <?php
 namespace app\workerapi\lists;
 
+use app\common\lists\ListsExtendInterface;
+use app\common\model\master_worker\MasterWorker;
 use app\common\model\works\ServiceWork;
 use app\common\lists\ListsSearchInterface;
 use DateTime;
@@ -10,10 +12,13 @@ use DateTime;
  * Class ServiceWorkLists
  * @package app\workerapi\listsworks
  */
-class ServiceWorkLists extends BaseWorkerDataLists
+class ServiceWorkLists extends BaseWorkerDataLists implements ListsSearchInterface,ListsExtendInterface
 {
     protected $count = 0;
-
+    public function setSearch(): array
+    {
+        return [];
+    }
     /**
      * @notes 获取列表
      * @return array
@@ -96,5 +101,10 @@ class ServiceWorkLists extends BaseWorkerDataLists
     {
         return $this->count;
     }
+    public function extend(): array
+    {
+        $team = MasterWorker::where('id', $this->userId)->find();
+        return ['team_id'=>$team['team_id'],'team_role'=>$team['team_role']];
+    }
 
 }

+ 5 - 7
app/workerapi/lists/TeamServiceWorkLists.php

@@ -23,7 +23,7 @@ class TeamServiceWorkLists extends BaseWorkerDataLists
         // 待领单、待联系、待上门、已上门、服务中、待结算、已完结、已评价、已取消
         // 1=待领单,2=待联系,3=待上门,4=已上门,5=服务中,6=待结算,7=已完结,8=已评价,9=已退
         if(isset($this->params['work_status']) && !empty($this->params['work_status'])){
-            $where[] = ['work_status', '=', $this->params['work_status']];
+            $where['work_status'] = ['=', $this->params['work_status']];
         }
         if(isset($this->params['create_time']) && !empty($this->params['create_time'])){
             $where[] = ['create_time', 'between', [strtotime($this->params['create_time']), strtotime($this->params['create_time'])+86400-1]];
@@ -37,21 +37,19 @@ class TeamServiceWorkLists extends BaseWorkerDataLists
             switch ($this->params['team_work_type']){
                 case 1: // 挂起订单
                     $where['master_worker_id'] = $this->userInfo['user_id'];
-                    $where[] = ['work_status','=',1];
+                    $where['work_status'] = ['=',1];
                     break;
                 case 2: // 超时未领单
-                    $where[] = ['work_status','=',1];
+                    $where['work_status'] = ['=',1];
                     break;
                 case 3: // 异常预约
-                    $where[] = ['work_status','=',2];
+                    $where['work_status'] = ['=',2];
                     break;
                 case 4: // 超时未服务
-                    $where[] = ['work_status','=',3];
+                    $where['work_status'] = ['=',3];
                     break;
             }
         }
-        //
-        //dd($where);
         return $where;
     }
     /**

+ 13 - 17
app/workerapi/logic/MasterWorkerTeamLogic.php

@@ -12,6 +12,7 @@ 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\MasterWorkerLists;
 use app\workerapi\lists\ServiceWorkLists;
 use think\Exception;
 use think\facade\Config;
@@ -23,15 +24,16 @@ use think\facade\Db;
  */
 class MasterWorkerTeamLogic extends  BaseLogic
 {
-    public static function getDetail(int $teamId,int $masterWorkerId)
+    public static function getDetail(int $masterWorkerId)
     {
         try {
-            $team = MasterWorkerTeam::where('id',$teamId)->where('master_worker_id',$masterWorkerId)->findOrEmpty();
+            $team = MasterWorkerTeam::where('master_worker_id',$masterWorkerId)->findOrEmpty();
             if ($team->isEmpty()) {
                 throw new \Exception('团队不存在');
             }
-
-            return $team->toArray();
+            $team = $team->toArray();
+            $team['count_num'] = MasterWorker::where('team_id',$team['id'])->where('team_role',2)->count();
+            return $team;
         } catch (\Exception $e) {
             self::setError($e->getMessage());
             return [];
@@ -64,14 +66,14 @@ class MasterWorkerTeamLogic extends  BaseLogic
     }
 
 
-    public static function getMemberList(int $teamId,int $masterWorkerId)
+    public static function getMemberList(int $masterWorkerId)
     {
         try {
-            $team = MasterWorkerTeam::where('id',$teamId)->where('master_worker_id',$masterWorkerId)->findOrEmpty();
+            $team = MasterWorkerTeam::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();
+            return MasterWorker::where('team_id',$team['id'])->where('team_role',2)->field(['id','nickname','avatar','mobile','real_name','team_role'])->select()->toArray();
         } catch (\Exception $e) {
             self::setError($e->getMessage());
             return [];
@@ -132,23 +134,17 @@ class MasterWorkerTeamLogic extends  BaseLogic
      * @return array
      */
     public static function MemberWorkStatistics($userInfo){
-        return ServiceWork::whereIn('master_worker_id',
+        $lists = 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){
-
+            ->select()->toArray();
 
+        dd(array_column($lists,'count_num','work_status'));
+        return [];
     }
 
 
-
-
-
 }