['order_type', 'status'], 'like' => ['order_no'], ]; } /** * @notes 权限过滤 - 普通员工只能看自己创建的订单 * @param array $where * @return void */ private function filterByPermission(array &$where): void { // 检查是否是超管(root字段为1) if (!empty($this->adminInfo['root']) && $this->adminInfo['root'] == 1) { // 超管不过滤,可以看所有订单 return; } // 主管角色ID列表(可根据实际调整) $supervisorRoles = [0, 3]; // 检查当前用户是否是主管 $roleIds = \app\common\model\auth\AdminRole::where('admin_id', $this->adminId)->column('role_id'); // 如果不是主管,只能看自己创建的订单 $isSupervisor = count(array_intersect($roleIds, $supervisorRoles)) > 0; if (!$isSupervisor) { $where[] = ['creator_id', '=', $this->adminId]; } } /** * @notes 获取列表 * @return array * @throws \think\db\exception\DataNotFoundException * @throws \think\db\exception\DbException * @throws \think\db\exception\ModelNotFoundException */ public function lists(): array { $where = $this->searchWhere; // 权限控制:普通员工只能看自己创建的订单 $this->filterByPermission($where); // 处理患者关联状态:pending=待关联, associated=已关联 $patientAssociation = $this->params['patient_association'] ?? ''; if ($patientAssociation === 'pending') { $where[] = ['patient_id', 'null', '']; } elseif ($patientAssociation === 'associated') { $where[] = ['patient_id', 'not null', '']; } // 处理患者关键词搜索(从诊单表搜索) if (!empty($this->params['patient_keyword'])) { $where[] = ['patient_id', 'in', function ($query) { $query->table('zyt_tcm_diagnosis') ->whereNull('delete_time') ->where('patient_name|patient_phone', 'like', '%' . $this->params['patient_keyword'] . '%') ->field('id'); }]; } // 处理创建时间范围 if (!empty($this->params['create_time_start'])) { $where[] = ['create_time', '>=', $this->params['create_time_start'] . ' 00:00:00']; } if (!empty($this->params['create_time_end'])) { $where[] = ['create_time', '<=', $this->params['create_time_end'] . ' 23:59:59']; } return Order::where($where) ->with(['patient', 'creator']) ->order(['create_time' => 'desc']) ->limit($this->limitOffset, $this->pageSize) ->select() ->toArray(); } /** * @notes 获取数量 * @return int */ public function count(): int { $where = $this->searchWhere; // 权限控制:普通员工只能看自己创建的订单 $this->filterByPermission($where); // 处理患者关联状态 $patientAssociation = $this->params['patient_association'] ?? ''; if ($patientAssociation === 'pending') { $where[] = ['patient_id', 'null', '']; } elseif ($patientAssociation === 'associated') { $where[] = ['patient_id', 'not null', '']; } // 处理患者关键词搜索(从诊单表搜索) if (!empty($this->params['patient_keyword'])) { $where[] = ['patient_id', 'in', function ($query) { $query->table('zyt_tcm_diagnosis') ->whereNull('delete_time') ->where('patient_name|patient_phone', 'like', '%' . $this->params['patient_keyword'] . '%') ->field('id'); }]; } // 处理创建时间范围 if (!empty($this->params['create_time_start'])) { $where[] = ['create_time', '>=', $this->params['create_time_start'] . ' 00:00:00']; } if (!empty($this->params['create_time_end'])) { $where[] = ['create_time', '<=', $this->params['create_time_end'] . ' 23:59:59']; } return Order::where($where)->count(); } }