MasterWorkerLists.php 3.1 KB

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