['prescription_name'], '=' => ['is_public', 'creator_id'] ]; } /** * @notes 获取列表 */ public function lists(): array { $field = [ 'id', 'prescription_name', 'herbs', 'is_public', 'creator_id', 'creator_name', 'create_time', 'update_time' ]; $lists = PrescriptionLibrary::where($this->searchWhere) ->where(function ($query) { // 只显示自己创建的或公开的处方 $query->where('creator_id', $this->adminId) ->whereOr('is_public', 1); }) ->field($field) ->limit($this->limitOffset, $this->limitLength) ->order('id', 'desc') ->select() ->toArray(); // 解析药材JSON foreach ($lists as &$item) { if (!empty($item['herbs'])) { $item['herbs'] = json_decode($item['herbs'], true); } else { $item['herbs'] = []; } } return $lists; } /** * @notes 获取数量 */ public function count(): int { return PrescriptionLibrary::where($this->searchWhere) ->where(function ($query) { // 只统计自己创建的或公开的处方 $query->where('creator_id', $this->adminId) ->whereOr('is_public', 1); }) ->count(); } }