MasterWorkerRegisterLists.php 2.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677
  1. <?php
  2. namespace app\workerapi\lists;
  3. use app\common\model\master_worker_register\MasterWorkerRegister;
  4. use app\common\lists\ListsSearchInterface;
  5. use app\common\model\works\ServiceWork;
  6. use app\workerapi\logic\SaleLogic;
  7. use think\facade\Db;
  8. /**
  9. * MasterWorkerRegister列表
  10. * Class MasterWorkerRegisterLists
  11. * @package app\workerapi\lists
  12. */
  13. class MasterWorkerRegisterLists extends BaseWorkerDataLists implements ListsSearchInterface
  14. {
  15. /**
  16. * @notes 设置搜索条件
  17. * @return \string[][]
  18. * @author likeadmin
  19. * @date 2025/02/25 09:29
  20. */
  21. public function setSearch(): array
  22. {
  23. $sale_id = SaleLogic::getSaleIdByToken($this->params['sale_token']??'00000');
  24. $this->params['sale_id'] = $sale_id;
  25. return [
  26. '=' => ['maintain_exp_type', 'other_exp_type', 'city', 'vehicle_type', 'status','is_credential','sale_id'],
  27. '%like%' => ['name', 'mobile'],
  28. ];
  29. }
  30. /**
  31. * @notes 获取列表
  32. * @return array
  33. * @throws \think\db\exception\DataNotFoundException
  34. * @throws \think\db\exception\DbException
  35. * @throws \think\db\exception\ModelNotFoundException
  36. * @author likeadmin
  37. * @date 2025/02/25 09:29
  38. */
  39. public function lists(): array
  40. {
  41. $list = MasterWorkerRegister::where($this->searchWhere)
  42. ->field(['*'])
  43. ->limit($this->limitOffset, $this->limitLength)
  44. ->order(['id' => 'desc'])
  45. ->select()
  46. ->toArray();
  47. $workCount = array_column(ServiceWork::where('master_worker_id','>',0)
  48. ->whereIn('master_worker_id', array_filter(array_column($list, 'worker_id'), function($value) { return $value != 0; })??[-1])
  49. ->field(['master_worker_id',Db::raw('COUNT(id) as work_total')])
  50. ->group('master_worker_id')
  51. ->select()->toArray(),'work_total','master_worker_id');
  52. foreach ($list as &$item) {
  53. $item['work_total'] = $workCount[$item['worker_id']]??0;
  54. }
  55. return $list;
  56. }
  57. /**
  58. * @notes 获取数量
  59. * @return int
  60. * @author likeadmin
  61. * @date 2025/02/25 09:29
  62. */
  63. public function count(): int
  64. {
  65. return MasterWorkerRegister::where($this->searchWhere)->count();
  66. }
  67. }