You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
108 lines
2.6 KiB
108 lines
2.6 KiB
<?php
|
|
declare (strict_types=1);
|
|
|
|
namespace app\api\model;
|
|
|
|
use think\Model;
|
|
|
|
|
|
/**
|
|
* @mixin think\Model
|
|
*/
|
|
class Dictionary extends Common
|
|
{
|
|
|
|
protected $table = 'system_dictionary'; //如cloud_开头不需要
|
|
|
|
/**
|
|
* 字典列表数据模型
|
|
* @return array|\think\Collection
|
|
* @throws \think\db\exception\DataNotFoundException
|
|
* @throws \think\db\exception\DbException
|
|
* @throws \think\db\exception\ModelNotFoundException
|
|
*/
|
|
public function index()
|
|
{
|
|
//自定义处理逻辑
|
|
$dict_name = $this->request->param('dict_name', '');
|
|
$_op = $this->whereLike('dict_name', "{$dict_name}%");
|
|
|
|
$dict_value = $this->request->param('dict_value', '');
|
|
$_op = $this->whereLike('dict_value', "{dict_value}%");
|
|
|
|
//自定义处理逻辑
|
|
$dict_type_id = $this->request->param('dict_type_id', '');
|
|
$_op = $this->where('dict_type_id', $dict_type_id);
|
|
|
|
//通用逻辑
|
|
return parent::parentLists($_op);
|
|
}
|
|
|
|
public function chekName($name)
|
|
{
|
|
//自定义处理逻辑
|
|
$dict_type_id = $this->request->param('dict_type_id', '');
|
|
$id = $this->request->param('id', '');
|
|
$codition = [
|
|
'dict_value' => $name,
|
|
'dict_type_id' => $dict_type_id,
|
|
|
|
];
|
|
|
|
if($id >0){
|
|
$count = $this->where($codition)->where('id','<>',$id)->count();
|
|
}else{
|
|
$count = $this->where($codition)->count();
|
|
}
|
|
|
|
return $count;
|
|
}
|
|
|
|
|
|
/**
|
|
* 读取后
|
|
* @param Model $model
|
|
* @return bool|void
|
|
*/
|
|
public static function onAfterRead(Model $model)
|
|
{
|
|
//读取数据前格式化数据
|
|
if (in_array(request()->action(), ['edit', 'delete', 'status'])) {
|
|
return true;
|
|
}
|
|
//业务逻辑
|
|
}
|
|
|
|
/**
|
|
* 新增或修改前
|
|
* @param Model $model
|
|
* @return mixed|void
|
|
*/
|
|
public static function onBeforeWrite(Model $model)
|
|
{
|
|
parent::onBeforeWrite($model);
|
|
|
|
//写入数据前格式化数据
|
|
if (!in_array(request()->action(), ['add', 'edit'])) {
|
|
return true;
|
|
}
|
|
//业务逻辑
|
|
// code...
|
|
}
|
|
|
|
public static function onAfterDelete(Model $model)
|
|
{
|
|
parent::onAfterDelete($model); // TODO: Change the autogenerated stub
|
|
$dic = new DictionaryType();
|
|
$dic->exportDictToConfig();
|
|
}
|
|
|
|
public static function onAfterWrite(Model $model)
|
|
{
|
|
parent::onAfterWrite($model); // TODO: Change the autogenerated stub
|
|
$dic = new DictionaryType();
|
|
$dic->exportDictToConfig();
|
|
}
|
|
|
|
|
|
}
|
|
|