MasterWorkerLists.php 3.4 KB

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