MasterWorkerLists.php 3.0 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889
  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. '%like%' => ['real_name'],
  22. ];
  23. }
  24. public function queryWhere(){
  25. $where = [];
  26. if($this->request->controller() == 'MasterWorkerTeam' && $this->request->action() == 'getMemberList'){
  27. $team = MasterWorkerTeam::where('master_worker_id',$this->userId)->findOrEmpty();
  28. if ($team->isEmpty()) {
  29. $where[] = ['team_id','=',-1];
  30. }else{
  31. $where[] = ['team_id','=',$team['id']];
  32. $where[] = ['team_role','=',2];
  33. $where[] = ['work_status','=',0];
  34. $where[] = ['audit_state','=',1];
  35. $where[] = ['accept_order_status','=',1];
  36. }
  37. }
  38. return $where;
  39. }
  40. /**
  41. * @notes 获取列表
  42. * @return array
  43. * @throws \think\db\exception\DataNotFoundException
  44. * @throws \think\db\exception\DbException
  45. * @throws \think\db\exception\ModelNotFoundException
  46. * @author whitef
  47. * @date 2024/07/10 15:06
  48. */
  49. public function lists(): array
  50. {
  51. $list = MasterWorker::where($this->searchWhere)
  52. ->where($this->queryWhere())
  53. ->where('is_disable',0)
  54. ->field(['id','nickname','avatar','mobile','real_name','team_role'])
  55. ->limit($this->limitOffset, $this->limitLength)
  56. ->order(['id' => 'asc'])
  57. ->select()
  58. ->toArray();
  59. // 完工数 本月收益
  60. foreach ($list as &$item){
  61. $item['work_total'] = ServiceWork::where(['user_confirm_status'=>5])->where(['master_worker_id'=>$item['id']])->count();
  62. $item['income'] = MasterWorkerAccountLog::where(['worker_id'=>$item['id']])
  63. ->where(['change_object'=>WorkerAccountLogEnum::UM,'change_type'=>WorkerAccountLogEnum::UM_INC_ADMIN,'action'=>WorkerAccountLogEnum::INC])
  64. ->whereBetweenTime('create_time',date('Y-m-01 00:00:00',time()),date('Y-m-d 23:59:59',time()))
  65. ->sum('change_amount');
  66. }
  67. return $list;
  68. }
  69. /**
  70. * @notes 获取数量
  71. * @return int
  72. * @author whitef
  73. * @date 2024/07/10 15:06
  74. */
  75. public function count(): int
  76. {
  77. return MasterWorker::where($this->searchWhere)->where($this->queryWhere())->count();
  78. }
  79. public function extend(): array
  80. {
  81. return MasterWorkerTeamLogic::getDetail($this->userId);
  82. }
  83. }