update system module
This commit is contained in:
parent
ce3a570a25
commit
17a8c02415
|
@ -12,26 +12,26 @@ class SystemLists extends BaseAdminDataLists implements ListsSearchInterface
|
|||
public function setSearch(): array
|
||||
{
|
||||
return [
|
||||
'=' => ['system_status'],
|
||||
'%like%' => ['system_name'],
|
||||
'=' => ['status'],
|
||||
'%like%' => ['name'],
|
||||
];
|
||||
}
|
||||
|
||||
// 获取列表
|
||||
public function lists(): array
|
||||
{
|
||||
$field = "id,system_name,system_appid,system_appkey,system_url,create_time,system_status";
|
||||
return System::field($field)->where($this->searchWhere)->where('system_status','<>',2)
|
||||
$field = "id,name,app_id,app_key,url,status,create_time";
|
||||
return System::field($field)->where($this->searchWhere)->where('status','<>',2)
|
||||
->limit($this->limitOffset, $this->limitLength)
|
||||
->order('id desc')
|
||||
->select()->each(function($item){
|
||||
$item['system_status_text'] = $item->system_status_text;
|
||||
$item['status_text'] = $item->status_text;
|
||||
})->toArray();
|
||||
}
|
||||
|
||||
// 获取数量
|
||||
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();
|
||||
}
|
||||
}
|
|
@ -12,11 +12,11 @@ class SystemLogic extends BaseLogic
|
|||
{
|
||||
try{
|
||||
System::create([
|
||||
'system_name' => $params['system_name'],
|
||||
'system_url' => $params['system_url'],
|
||||
'system_appid' => create_appid(),
|
||||
'system_appkey' => create_appkey(),
|
||||
'system_status' => 0,
|
||||
'name' => $params['name'],
|
||||
'url' => $params['url'],
|
||||
'app_id' => create_app_id(),
|
||||
'app_key' => create_app_key(),
|
||||
'status' => 0,
|
||||
]);
|
||||
return true;
|
||||
}catch (\Exception $e) {
|
||||
|
@ -31,7 +31,7 @@ class SystemLogic extends BaseLogic
|
|||
try {
|
||||
System::update([
|
||||
'id' => $params['id'],
|
||||
'system_status' => 2,
|
||||
'status' => 2,
|
||||
'update_time' => time()
|
||||
]);
|
||||
return true;
|
||||
|
@ -47,9 +47,9 @@ class SystemLogic extends BaseLogic
|
|||
try {
|
||||
System::update([
|
||||
'id' => $params['id'],
|
||||
'system_name' => $params['system_name'],
|
||||
'system_url' => $params['system_url'],
|
||||
'system_status' => $params['system_status'],
|
||||
'name' => $params['name'],
|
||||
'url' => $params['url'],
|
||||
'status' => $params['status'],
|
||||
'update_time' => time()
|
||||
]);
|
||||
return true;
|
||||
|
@ -62,8 +62,8 @@ class SystemLogic extends BaseLogic
|
|||
// 查看
|
||||
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_status_text'] = $data->system_status_text;
|
||||
$data = System::field('id,name,app_id,app_key,url,status,create_time')->findOrEmpty($params['id']);
|
||||
$data['status_text'] = $data->status_text;
|
||||
return $data->toArray();
|
||||
}
|
||||
}
|
|
@ -31,28 +31,28 @@ function create_token(string $extra = '') : string
|
|||
return md5($salt . $extra . time() . $encryptSalt);
|
||||
}
|
||||
|
||||
function create_appid()
|
||||
function create_app_id()
|
||||
{
|
||||
$appid = 'AD'.time();
|
||||
//判断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()){
|
||||
return $appid;
|
||||
}else{
|
||||
create_appid();
|
||||
create_app_id();
|
||||
}
|
||||
}
|
||||
|
||||
function create_appkey()
|
||||
function create_app_key()
|
||||
{
|
||||
$salt = md5('dc@lh@app_key'.uniqid().microtime());
|
||||
$appkey = 'AK'.strtoupper(md5($salt.time().$salt));
|
||||
//判断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()){
|
||||
return $appkey;
|
||||
}else{
|
||||
create_appkey();
|
||||
create_app_key();
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -8,9 +8,9 @@ class System extends BaseModel
|
|||
{
|
||||
protected $name = 'system';
|
||||
|
||||
public function getSystemStatusTextAttr($value,$data): string
|
||||
public function getStatusTextAttr($value,$data): string
|
||||
{
|
||||
$system_status = [0=>'正常',1=>'禁用',2=>'删除'];
|
||||
return $system_status[$data['system_status']];
|
||||
$status = [0=>'正常',1=>'禁用',2=>'删除'];
|
||||
return $status[$data['status']];
|
||||
}
|
||||
}
|
|
@ -13,30 +13,30 @@ class SystemValidate extends BaseValidate
|
|||
|
||||
protected $rule = [
|
||||
'id' => 'require',
|
||||
'system_name' => 'require|unique:system',
|
||||
'system_url' => 'require|uri|unique:system',
|
||||
'system_status' => 'require|in:0,1',
|
||||
'name' => 'require|unique:system',
|
||||
'url' => 'require|uri|unique:system',
|
||||
'status' => 'require|in:0,1',
|
||||
];
|
||||
|
||||
protected $message = [
|
||||
'id.require' => '请选择系统',
|
||||
'system_name.require' => '请填写系统名称',
|
||||
'system_name' => '系统名称已被使用',
|
||||
'system_url.require' => '请填写系统网址',
|
||||
'system_url.uri' => '系统网址填写错误',
|
||||
'system_url.unique' => '系统网址已被使用',
|
||||
'system_status.require' => '请选择系统状态',
|
||||
'system_status.in' => '系统状态值错误',
|
||||
'name.require' => '请填写系统名称',
|
||||
'name' => '系统名称已被使用',
|
||||
'url.require' => '请填写系统网址',
|
||||
'url.uri' => '系统网址填写错误',
|
||||
'url.unique' => '系统网址已被使用',
|
||||
'status.require' => '请选择系统状态',
|
||||
'status.in' => '系统状态值错误',
|
||||
];
|
||||
|
||||
public function sceneAdd(): SystemValidate
|
||||
{
|
||||
return $this->only(['system_name','system_url']);
|
||||
return $this->only(['name','url']);
|
||||
}
|
||||
|
||||
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
|
||||
|
|
Loading…
Reference in New Issue