| 1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677 |
- <?php
- namespace app\workerapi\lists;
- use app\common\model\master_worker_register\MasterWorkerRegister;
- use app\common\lists\ListsSearchInterface;
- use app\common\model\works\ServiceWork;
- use app\workerapi\logic\SaleLogic;
- use think\facade\Db;
- /**
- * MasterWorkerRegister列表
- * Class MasterWorkerRegisterLists
- * @package app\workerapi\lists
- */
- class MasterWorkerRegisterLists extends BaseWorkerDataLists implements ListsSearchInterface
- {
- /**
- * @notes 设置搜索条件
- * @return \string[][]
- * @author likeadmin
- * @date 2025/02/25 09:29
- */
- public function setSearch(): array
- {
- $sale_id = SaleLogic::getSaleIdByToken($this->params['sale_token']??'00000');
- $this->params['sale_id'] = $sale_id;
- return [
- '=' => ['maintain_exp_type', 'other_exp_type', 'city', 'vehicle_type', 'status','is_credential','sale_id'],
- '%like%' => ['name', 'mobile'],
- ];
- }
- /**
- * @notes 获取列表
- * @return array
- * @throws \think\db\exception\DataNotFoundException
- * @throws \think\db\exception\DbException
- * @throws \think\db\exception\ModelNotFoundException
- * @author likeadmin
- * @date 2025/02/25 09:29
- */
- public function lists(): array
- {
- $list = MasterWorkerRegister::where($this->searchWhere)
- ->field(['*'])
- ->limit($this->limitOffset, $this->limitLength)
- ->order(['id' => 'desc'])
- ->select()
- ->toArray();
- $workCount = array_column(ServiceWork::where('master_worker_id','>',0)
- ->whereIn('master_worker_id', array_filter(array_column($list, 'worker_id'), function($value) { return $value != 0; })??[-1])
- ->field(['master_worker_id',Db::raw('COUNT(id) as work_total')])
- ->group('master_worker_id')
- ->select()->toArray(),'work_total','master_worker_id');
- foreach ($list as &$item) {
- $item['work_total'] = $workCount[$item['worker_id']]??0;
- }
- return $list;
- }
- /**
- * @notes 获取数量
- * @return int
- * @author likeadmin
- * @date 2025/02/25 09:29
- */
- public function count(): int
- {
- return MasterWorkerRegister::where($this->searchWhere)->count();
- }
- }
|