Skip to content

Commit

Permalink
format
Browse files Browse the repository at this point in the history
  • Loading branch information
shirne committed Jul 13, 2024
1 parent 7bc7f98 commit a11d0ef
Show file tree
Hide file tree
Showing 175 changed files with 12,292 additions and 11,284 deletions.
176 changes: 94 additions & 82 deletions src/application/admin/common.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,152 +3,164 @@
use think\Db;
use think\facade\Request;

define('SESSKEY_ADMIN_ID','adminId');
define('SESSKEY_ADMIN_NAME','adminname');
define('SESSKEY_ADMIN_LAST_TIME','adminLTime');
define('SESSKEY_ADMIN_AUTO_LOGIN','adminlogin');
define('SESSKEY_ADMIN_ID', 'adminId');
define('SESSKEY_ADMIN_NAME', 'adminname');
define('SESSKEY_ADMIN_LAST_TIME', 'adminLTime');
define('SESSKEY_ADMIN_AUTO_LOGIN', 'adminlogin');

function getProductPresets($model=[]){
function getProductPresets($model = [])
{
return [
'0'=>[
'type'=>isset($model['type'])?$model['type']:1,
'is_discount'=>isset($model['is_discount'])?$model['is_discount']:1,
'is_commission'=>isset($model['is_commission'])?$model['is_commission']:1,
'0' => [
'type' => isset($model['type']) ? $model['type'] : 1,
'is_discount' => isset($model['is_discount']) ? $model['is_discount'] : 1,
'is_commission' => isset($model['is_commission']) ? $model['is_commission'] : 1,
],
];
}

function showLevel($level,$isshort=false){
if(!empty($level) && $level['level_id']>0){
return '<span class="badge badge-'.$level['style'].'">'.($isshort?$level['short_name']:$level['level_name']).'</span>';
function showLevel($level, $isshort = false)
{
if (!empty($level) && $level['level_id'] > 0) {
return '<span class="badge badge-' . $level['style'] . '">' . ($isshort ? $level['short_name'] : $level['level_name']) . '</span>';
}
return '';
}

function showAgent($agent,$isshort=false){
if(!empty($agent) && $agent['level_id']>0){
return '<span class="badge badge-'.$agent['style'].'">'.($isshort?$agent['short_name']:$agent['name']).'</span>';
function showAgent($agent, $isshort = false)
{
if (!empty($agent) && $agent['level_id'] > 0) {
return '<span class="badge badge-' . $agent['style'] . '">' . ($isshort ? $agent['short_name'] : $agent['name']) . '</span>';
}
return '';
}

function setLogin($user, $logintype = 1){
$time=time();
session(SESSKEY_ADMIN_ID,$user['id']);
session(SESSKEY_ADMIN_LAST_TIME,$time);
session(SESSKEY_ADMIN_NAME,empty($user['realname'])?$user['username']:$user['realname']);
Db::name('Manager')->where('id',$user['id'])->update(array(
'login_ip'=>Request::ip(),
'logintime'=>$time
function setLogin($user, $logintype = 1)
{
$time = time();
session(SESSKEY_ADMIN_ID, $user['id']);
session(SESSKEY_ADMIN_LAST_TIME, $time);
session(SESSKEY_ADMIN_NAME, empty($user['realname']) ? $user['username'] : $user['realname']);
Db::name('Manager')->where('id', $user['id'])->update(array(
'login_ip' => Request::ip(),
'logintime' => $time
));
if($logintype == 1){
user_log($user['id'],'login',1,'登录成功' ,'manager');
}else{
user_log($user['id'],'login',1,'自动登录成功' ,'manager');
if ($logintype == 1) {
user_log($user['id'], 'login', 1, '登录成功', 'manager');
} else {
user_log($user['id'], 'login', 1, '自动登录成功', 'manager');
}
}

function clearLogin($log=true){
$id=session(SESSKEY_ADMIN_ID);
if($log && !empty($id)) {
function clearLogin($log = true)
{
$id = session(SESSKEY_ADMIN_ID);
if ($log && !empty($id)) {
user_log($id, 'logout', 1, '退出登录');
}

session(SESSKEY_ADMIN_ID,null);
session(SESSKEY_ADMIN_NAME,null);
session(SESSKEY_ADMIN_LAST_TIME,null);
cookie(SESSKEY_ADMIN_AUTO_LOGIN,null);
session(SESSKEY_ADMIN_ID, null);
session(SESSKEY_ADMIN_NAME, null);
session(SESSKEY_ADMIN_LAST_TIME, null);
cookie(SESSKEY_ADMIN_AUTO_LOGIN, null);
}

function getMenus(){
$menus=cache('menus');
if(empty($menus)){
$list=Db::name('permission')->where('disable',0)->order('parent_id ASC,sort_id ASC,id ASC')->select();
$menus=array();
foreach ($list as $item){
$menus[$item['parent_id']][]=$item;
function getMenus()
{
$menus = cache('menus');
if (empty($menus)) {
$list = Db::name('permission')->where('disable', 0)->order('parent_id ASC,sort_id ASC,id ASC')->select();
$menus = array();
foreach ($list as $item) {
$menus[$item['parent_id']][] = $item;
}

cache('menus',$menus,1800);
cache('menus', $menus, 1800);
}
return $menus;
}

function check_password($password){
if(in_array($password,['123456','654321','admin','abc123','123abc','12345678','123456789'])){
session('password_error',1);
}elseif(preg_match('/^([0-9])\\1*$/',$password)){
session('password_error',2);
}elseif(preg_match('/^[0-9]*$/',$password)){
session('password_error',3);
}elseif(preg_match('/^([a-zA-Z])\\1*$/',$password)){
session('password_error',4);
}else{
session('password_error',null);
function check_password($password)
{
if (in_array($password, ['123456', '654321', 'admin', 'abc123', '123abc', '12345678', '123456789'])) {
session('password_error', 1);
} elseif (preg_match('/^([0-9])\\1*$/', $password)) {
session('password_error', 2);
} elseif (preg_match('/^[0-9]*$/', $password)) {
session('password_error', 3);
} elseif (preg_match('/^([a-zA-Z])\\1*$/', $password)) {
session('password_error', 4);
} else {
session('password_error', null);
}
}

function delete_image($images){
if(is_array($images)){
foreach ($images as $image){
function delete_image($images)
{
if (is_array($images)) {
foreach ($images as $image) {
delete_image($image);
}
}else{
$images = str_replace('\\','/',$images);
} else {
$images = str_replace('\\', '/', $images);

if(strpos($images,'../') !== false)return;
if(!empty($images) && strpos($images,'/uploads/')===0){
@unlink('.'.$images);
if (strpos($images, '../') !== false) return;

if (!empty($images) && strpos($images, '/uploads/') === 0) {
@unlink('.' . $images);
}
}
}

function list_empty($col=5){
return '<tr><td colspan="'.$col.'" class="text-center text-muted">暂时没有记录</td></tr>';
function list_empty($col = 5)
{
return '<tr><td colspan="' . $col . '" class="text-center text-muted">暂时没有记录</td></tr>';
}

function ignore_array($val){
if(is_array($val))return '';
function ignore_array($val)
{
if (is_array($val)) return '';
return strval($val);
}

function wechat_is_official($type){
if(in_array($type,['wechat','subscribe','service'])){
function wechat_is_official($type)
{
if (in_array($type, ['wechat', 'subscribe', 'service'])) {
return true;
}
return false;
}


function save_setting( $data, $group=''){
$settings=getSettings(true,false,false);
$group = empty($group)?[]:explode(',',$group);
foreach ($data as $k=>$v){
if(substr($k,0,2)=='v-'){
$key=substr($k,2);
if(isset($settings[$key])) {
if(!empty($group) && !in_array($settings[$key]['group'],$group)){
function save_setting($data, $group = '')
{
$settings = getSettings(true, false, false);
$group = empty($group) ? [] : explode(',', $group);
foreach ($data as $k => $v) {
if (substr($k, 0, 2) == 'v-') {
$key = substr($k, 2);
if (isset($settings[$key])) {
if (!empty($group) && !in_array($settings[$key]['group'], $group)) {
continue;
}
if (is_array($v)) {
if(in_array($settings[$key]['type'],['json','array'])){
if($settings[$key]['type'] == 'array'){
if (in_array($settings[$key]['type'], ['json', 'array'])) {
if ($settings[$key]['type'] == 'array') {
$v = array_values($v);
}
$v = json_encode($v,JSON_UNESCAPED_UNICODE);
}else {
$v = json_encode($v, JSON_UNESCAPED_UNICODE);
} else {
$v = serialize($v);
}
}

if ($settings[$key]['value'] != $v) {
Db::name('setting')->where('key', $key)->update(array('value' => $v));
}
}
}
}
cache('setting',null);
cache('setting', null);
return true;
}
//end file
16 changes: 8 additions & 8 deletions src/application/admin/validate/PermissionValidate.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,14 +12,14 @@
*/
class PermissionValidate extends BaseUniqueValidate
{
protected $rule=array(
'name'=>'require',
'key'=>'require|unique:permission,%id%'
protected $rule = array(
'name' => 'require',
'key' => 'require|unique:permission,%id%'
);

protected $message=array(
'name.require'=>'请填写菜单名称',
'key.require'=>'请填写菜单键名',
'key.unique'=>'键名已存在'
protected $message = array(
'name.require' => '请填写菜单名称',
'key.require' => '请填写菜单键名',
'key.unique' => '键名已存在'
);
}
}
59 changes: 30 additions & 29 deletions src/application/admin/view/article/index/imageupdate.tpl
Original file line number Diff line number Diff line change
Expand Up @@ -7,42 +7,43 @@
<div id="page-wrapper">
<div class="page-header">{$id>0?'编辑':'添加'}图片</div>
<div class="page-content">
<form method="post" class="page-form" action="" enctype="multipart/form-data">
<div class="form-group">
<label for="title">名称</label>
<input type="text" name="title" class="form-control" value="{$model.title}" placeholder="名称">
</div>
<div class="form-group">
<label for="text">说明</label>
<input type="text" name="description" class="form-control" value="{$model.description}" placeholder="图片说明">
</div>
<div class="form-row">
<div class="col form-group">
<label for="image">图片</label>
<div class="input-group">
<div class="custom-file">
<input type="file" class="custom-file-input" name="upload_image"/>
<label class="custom-file-label" for="upload_image">选择文件</label>
<form method="post" class="page-form" action="" enctype="multipart/form-data">
<div class="form-group">
<label for="title">名称</label>
<input type="text" name="title" class="form-control" value="{$model.title}" placeholder="名称">
</div>
<div class="form-group">
<label for="text">说明</label>
<input type="text" name="description" class="form-control" value="{$model.description}"
placeholder="图片说明">
</div>
<div class="form-row">
<div class="col form-group">
<label for="image">图片</label>
<div class="input-group">
<div class="custom-file">
<input type="file" class="custom-file-input" name="upload_image" />
<label class="custom-file-label" for="upload_image">选择文件</label>
</div>
</div>
</div>
{if $model['image']}
{if $model['image']}
<figure class="figure">
<img src="{$model.image}" class="figure-img img-fluid rounded" alt="image">
<figcaption class="figure-caption text-center">{$model.image}</figcaption>
</figure>
<input type="hidden" name="delete_image" value="{$model.image}"/>
{/if}
<input type="hidden" name="delete_image" value="{$model.image}" />
{/if}
</div>
<div class="col form-group">
<label for="image">排序</label>
<input type="text" name="sort" class="form-control" value="{$model.sort}" />
</div>
</div>
<div class="col form-group">
<label for="image">排序</label>
<input type="text" name="sort" class="form-control" value="{$model.sort}" />
<div class="form-group submit-btn">
<input type="hidden" name="article_id" value="{$model.article_id}">
<button type="submit" class="btn btn-primary">{$id>0?'编辑':'添加'}</button>
</div>
</div>
<div class="form-group submit-btn">
<input type="hidden" name="article_id" value="{$model.article_id}">
<button type="submit" class="btn btn-primary">{$id>0?'编辑':'添加'}</button>
</div>
</form>
</form>
</div>
</div>
{/block}
Loading

0 comments on commit a11d0ef

Please sign in to comment.