MasterWorkerLists.php 2.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384
  1. <?php
  2. namespace app\workerapi\lists;
  3. use app\common\enum\worker\WorkerAccountLogEnum;
  4. use app\common\lists\ListsExtendInterface;
  5. use app\common\model\master_worker\MasterWorker;
  6. use app\common\model\master_worker\MasterWorkerAccountLog;
  7. use app\common\model\master_worker\MasterWorkerTeam;
  8. use app\common\lists\ListsSearchInterface;
  9. use app\common\model\works\ServiceWork;
  10. use app\workerapi\logic\MasterWorkerTeamLogic;
  11. /**
  12. * ServiceWork列表
  13. * Class ServiceWorkLists
  14. * @package app\workerapi\listsworks
  15. */
  16. class MasterWorkerLists extends BaseWorkerDataLists implements ListsSearchInterface,ListsExtendInterface
  17. {
  18. public function setSearch(): array
  19. {
  20. return [];
  21. }
  22. public function queryWhere(){
  23. $where = [];
  24. if($this->request->controller() == 'MasterWorkerTeam' && $this->request->action() == 'getMemberList'){
  25. $team = MasterWorkerTeam::where('master_worker_id',$this->userId)->findOrEmpty();
  26. if ($team->isEmpty()) {
  27. $where[] = ['team_id','=',-1];
  28. }else{
  29. $where[] = ['team_id','=',$team['id']];
  30. $where[] = ['team_role','=',2];
  31. }
  32. }
  33. return $where;
  34. }
  35. /**
  36. * @notes 获取列表
  37. * @return array
  38. * @throws \think\db\exception\DataNotFoundException
  39. * @throws \think\db\exception\DbException
  40. * @throws \think\db\exception\ModelNotFoundException
  41. * @author whitef
  42. * @date 2024/07/10 15:06
  43. */
  44. public function lists(): array
  45. {
  46. $list = MasterWorker::where($this->searchWhere)
  47. ->where($this->queryWhere())
  48. ->where('is_disable',0)
  49. ->field(['id','nickname','avatar','mobile','real_name','team_role'])
  50. ->limit($this->limitOffset, $this->limitLength)
  51. ->order(['id' => 'asc'])
  52. ->select()
  53. ->toArray();
  54. // 完工数 本月收益
  55. foreach ($list as &$item){
  56. $item['work_total'] = ServiceWork::where(['user_confirm_status'=>5])->where(['master_worker_id'=>$item['id']])->count();
  57. $item['income'] = MasterWorkerAccountLog::where(['worker_id'=>$item['id']])
  58. ->where(['change_object'=>WorkerAccountLogEnum::UM,'change_type'=>WorkerAccountLogEnum::UM_INC_ADMIN,'action'=>WorkerAccountLogEnum::INC])
  59. ->whereBetweenTime('create_time',date('Y-m-01 00:00:00',time()),date('Y-m-d 23:59:59',time()))
  60. ->sum('change_amount');
  61. }
  62. return $list;
  63. }
  64. /**
  65. * @notes 获取数量
  66. * @return int
  67. * @author whitef
  68. * @date 2024/07/10 15:06
  69. */
  70. public function count(): int
  71. {
  72. return MasterWorker::where($this->searchWhere)->where($this->queryWhere())->count();
  73. }
  74. public function extend(): array
  75. {
  76. return MasterWorkerTeamLogic::getDetail($this->userId);
  77. }
  78. }