catchSearch() ->order('sort', 'asc') ->paginate(); } /** * 获取字典值 * @param String type_code 字典类型code * @param String code 字典值 code */ public function getValueByCode($type_code, $code) { if (!isset($type_code) || !isset($code)) { return false; } // 有缓存,使用缓存 if (Cache::has("dict_data_{$type_code}_{$code}")) { return Cache::get("dict_data_{$type_code}_{$code}"); } // 查出字典类型id // $type_id = Db::table("sys_dict_type")->where('code', $type_code)->value('id'); $type_id = (new SysDictType)->getTypeIdByCode($type_code); return $this->where('type_id', $type_id) ->where('code', $code) ->cache("dict_data_{$type_code}_{$code}", 60) //缓存 ->value('value'); } //根据类型中的唯一编码获取所有类型 public function getTypesByCode($type_code) { //获取类型id // $type_id = Db::table("sys_dict_type")->where('code',$type_code)->value('id'); $type_id = (new SysDictType)->getTypeIdByCode($type_code); // 获取该类型下的所有字典 $type_data = $this->where('type_id', $type_id)->order('sort', 'asc')->column('type_id,value,code,remark,sort'); $options = []; foreach ($type_data as $key => $value) { $option = array( 'value' => $value['code'], 'text' => $value['value'], 'remark' => $value['remark'] ); array_push($options, $option); } return $options; } //根据类型中的唯一编码获取所有类型 public function getTypesByCodeWithRemark($type_code, $remark) { //获取类型id // $type_id = Db::table("sys_dict_type")->where('code',$type_code)->value('id'); $type_id = (new SysDictType)->getTypeIdByCode($type_code); // 获取该类型下的所有字典 $type_data = $this->where('type_id', $type_id)->whereIn('remark', $remark)->order('sort', 'asc')->column('type_id,value,code,remark,sort'); $options = []; foreach ($type_data as $key => $value) { $option = array( 'value' => (int)$value['code'], 'text' => $value['value'], 'remark' => $value['remark'] ); array_push($options, $option); } return $options; } /** * 获取字典备注 * @param String type_code 字典类型code * @param String code 字典值 code */ public function getRemarkByCode($type_code, $value) { if (!isset($type_code) || !isset($value)) { return false; } $type_id = Db::table("sys_dict_type")->where('code', $type_code)->value('id'); return $this->where('type_id', $type_id) ->where('code', $value) ->cache(true, 60) ->value('remark'); } /** * 词汇查询 * * @time 2020年06月17日 * @param $query * @param $value * @param $data * @return mixed */ public function searchTypeIdAttr($query, $value, $data) { return $query->where('type_id', $value); } public function searchValueAttr($query, $value, $data) { return $query->whereLike('value', $value); } public function searchCodeAttr($query, $value, $data) { return $query->whereLike('code', $value); } }