update system module

This commit is contained in:
unknown 2023-09-19 09:18:45 +08:00
parent ce3a570a25
commit 17a8c02415
5 changed files with 38 additions and 38 deletions

View File

@ -12,26 +12,26 @@ class SystemLists extends BaseAdminDataLists implements ListsSearchInterface
public function setSearch(): array public function setSearch(): array
{ {
return [ return [
'=' => ['system_status'], '=' => ['status'],
'%like%' => ['system_name'], '%like%' => ['name'],
]; ];
} }
// 获取列表 // 获取列表
public function lists(): array public function lists(): array
{ {
$field = "id,system_name,system_appid,system_appkey,system_url,create_time,system_status"; $field = "id,name,app_id,app_key,url,status,create_time";
return System::field($field)->where($this->searchWhere)->where('system_status','<>',2) return System::field($field)->where($this->searchWhere)->where('status','<>',2)
->limit($this->limitOffset, $this->limitLength) ->limit($this->limitOffset, $this->limitLength)
->order('id desc') ->order('id desc')
->select()->each(function($item){ ->select()->each(function($item){
$item['system_status_text'] = $item->system_status_text; $item['status_text'] = $item->status_text;
})->toArray(); })->toArray();
} }
// 获取数量 // 获取数量
public function count(): int public function count(): int
{ {
return System::field('id')->where($this->searchWhere)->where('system_status','<>',2)->count(); return System::field('id')->where($this->searchWhere)->where('status','<>',2)->count();
} }
} }

View File

@ -12,11 +12,11 @@ class SystemLogic extends BaseLogic
{ {
try{ try{
System::create([ System::create([
'system_name' => $params['system_name'], 'name' => $params['name'],
'system_url' => $params['system_url'], 'url' => $params['url'],
'system_appid' => create_appid(), 'app_id' => create_app_id(),
'system_appkey' => create_appkey(), 'app_key' => create_app_key(),
'system_status' => 0, 'status' => 0,
]); ]);
return true; return true;
}catch (\Exception $e) { }catch (\Exception $e) {
@ -31,7 +31,7 @@ class SystemLogic extends BaseLogic
try { try {
System::update([ System::update([
'id' => $params['id'], 'id' => $params['id'],
'system_status' => 2, 'status' => 2,
'update_time' => time() 'update_time' => time()
]); ]);
return true; return true;
@ -47,9 +47,9 @@ class SystemLogic extends BaseLogic
try { try {
System::update([ System::update([
'id' => $params['id'], 'id' => $params['id'],
'system_name' => $params['system_name'], 'name' => $params['name'],
'system_url' => $params['system_url'], 'url' => $params['url'],
'system_status' => $params['system_status'], 'status' => $params['status'],
'update_time' => time() 'update_time' => time()
]); ]);
return true; return true;
@ -62,8 +62,8 @@ class SystemLogic extends BaseLogic
// 查看 // 查看
public static function detail($params) : array public static function detail($params) : array
{ {
$data = System::field('id,system_name,system_appid,system_appkey,system_url,system_status,system_type,create_time')->findOrEmpty($params['id']); $data = System::field('id,name,app_id,app_key,url,status,create_time')->findOrEmpty($params['id']);
$data['system_status_text'] = $data->system_status_text; $data['status_text'] = $data->status_text;
return $data->toArray(); return $data->toArray();
} }
} }

View File

@ -31,28 +31,28 @@ function create_token(string $extra = '') : string
return md5($salt . $extra . time() . $encryptSalt); return md5($salt . $extra . time() . $encryptSalt);
} }
function create_appid() function create_app_id()
{ {
$appid = 'AD'.time(); $appid = 'AD'.time();
//判断appid是否存在 //判断appid是否存在
$system = \app\common\model\systems\System::field('id')->where('system_appid',$appid)->findOrEmpty(); $system = \app\common\model\systems\System::field('id')->where('app_id',$appid)->findOrEmpty();
if($system->isEmpty()){ if($system->isEmpty()){
return $appid; return $appid;
}else{ }else{
create_appid(); create_app_id();
} }
} }
function create_appkey() function create_app_key()
{ {
$salt = md5('dc@lh@app_key'.uniqid().microtime()); $salt = md5('dc@lh@app_key'.uniqid().microtime());
$appkey = 'AK'.strtoupper(md5($salt.time().$salt)); $appkey = 'AK'.strtoupper(md5($salt.time().$salt));
//判断appkey是否存在 //判断appkey是否存在
$system = \app\common\model\systems\System::field('id')->where('system_appkey',$appkey)->findOrEmpty(); $system = \app\common\model\systems\System::field('id')->where('app_key',$appkey)->findOrEmpty();
if($system->isEmpty()){ if($system->isEmpty()){
return $appkey; return $appkey;
}else{ }else{
create_appkey(); create_app_key();
} }
} }

View File

@ -8,9 +8,9 @@ class System extends BaseModel
{ {
protected $name = 'system'; protected $name = 'system';
public function getSystemStatusTextAttr($value,$data): string public function getStatusTextAttr($value,$data): string
{ {
$system_status = [0=>'正常',1=>'禁用',2=>'删除']; $status = [0=>'正常',1=>'禁用',2=>'删除'];
return $system_status[$data['system_status']]; return $status[$data['status']];
} }
} }

View File

@ -13,30 +13,30 @@ class SystemValidate extends BaseValidate
protected $rule = [ protected $rule = [
'id' => 'require', 'id' => 'require',
'system_name' => 'require|unique:system', 'name' => 'require|unique:system',
'system_url' => 'require|uri|unique:system', 'url' => 'require|uri|unique:system',
'system_status' => 'require|in:0,1', 'status' => 'require|in:0,1',
]; ];
protected $message = [ protected $message = [
'id.require' => '请选择系统', 'id.require' => '请选择系统',
'system_name.require' => '请填写系统名称', 'name.require' => '请填写系统名称',
'system_name' => '系统名称已被使用', 'name' => '系统名称已被使用',
'system_url.require' => '请填写系统网址', 'url.require' => '请填写系统网址',
'system_url.uri' => '系统网址填写错误', 'url.uri' => '系统网址填写错误',
'system_url.unique' => '系统网址已被使用', 'url.unique' => '系统网址已被使用',
'system_status.require' => '请选择系统状态', 'status.require' => '请选择系统状态',
'system_status.in' => '系统状态值错误', 'status.in' => '系统状态值错误',
]; ];
public function sceneAdd(): SystemValidate public function sceneAdd(): SystemValidate
{ {
return $this->only(['system_name','system_url']); return $this->only(['name','url']);
} }
public function sceneEdit(): SystemValidate public function sceneEdit(): SystemValidate
{ {
return $this->only(['id','system_name','system_url','system_status']); return $this->only(['id','_name','url','status']);
} }
public function sceneDetail(): SystemValidate public function sceneDetail(): SystemValidate