123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145 |
- <?php
- namespace catchAdmin\system\model;
- use catcher\base\CatchModel as Model;
- use think\facade\Db;
- use think\facade\Cache;
- use catchAdmin\system\model\SysDictType;
- class SysDictData extends Model
- {
-
- public $name = 'sys_dict_data';
-
- public $field = array(
- 'id',
-
- 'type_id',
-
- 'value',
-
- 'code',
-
- 'sort',
-
- 'remark',
-
- 'status',
-
- 'creator_id',
-
- 'created_at',
-
- 'updated_at',
-
- 'deleted_at',
- );
- public function getList()
- {
- return $this->catchSearch()
- ->order('sort', 'asc')
- ->paginate();
- }
-
- 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}");
- }
-
-
- $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)
- {
-
-
- $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)
- {
-
-
- $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;
- }
-
- 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');
- }
-
- 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);
- }
- }
|