2018-12-28 18:58:37 +08:00
|
|
|
<?php
|
|
|
|
// +----------------------------------------------------------------------
|
|
|
|
// | ShopXO 国内领先企业级B2C免费开源电商系统
|
|
|
|
// +----------------------------------------------------------------------
|
2021-03-16 10:34:52 +08:00
|
|
|
// | Copyright (c) 2011~2099 http://shopxo.net All rights reserved.
|
2018-12-28 18:58:37 +08:00
|
|
|
// +----------------------------------------------------------------------
|
2021-03-16 10:34:52 +08:00
|
|
|
// | Licensed ( https://opensource.org/licenses/mit-license.php )
|
2018-12-28 18:58:37 +08:00
|
|
|
// +----------------------------------------------------------------------
|
|
|
|
// | Author: Devil
|
|
|
|
// +----------------------------------------------------------------------
|
|
|
|
namespace app\service;
|
|
|
|
|
2021-07-18 23:42:10 +08:00
|
|
|
use think\facade\Db;
|
2022-04-21 22:08:53 +08:00
|
|
|
use app\service\SystemService;
|
2021-08-07 10:08:06 +08:00
|
|
|
use app\service\AdminPowerService;
|
2018-12-28 18:58:37 +08:00
|
|
|
|
|
|
|
/**
|
|
|
|
* 管理员服务层
|
|
|
|
* @author Devil
|
|
|
|
* @blog http://gong.gg/
|
|
|
|
* @version 0.0.1
|
|
|
|
* @datetime 2016-12-01T21:51:08+0800
|
|
|
|
*/
|
|
|
|
class AdminService
|
|
|
|
{
|
2020-11-26 18:34:41 +08:00
|
|
|
// admin登录session key
|
2021-07-29 10:17:10 +08:00
|
|
|
public static $admin_login_key = 'admin_login_info';
|
2020-11-26 18:34:41 +08:00
|
|
|
|
2018-12-28 18:58:37 +08:00
|
|
|
/**
|
|
|
|
* 角色列表
|
|
|
|
* @author Devil
|
|
|
|
* @blog http://gong.gg/
|
|
|
|
* @version 0.0.1
|
|
|
|
* @datetime 2016-12-10T22:16:29+0800
|
|
|
|
* @param [array] $params [输入参数]
|
|
|
|
*/
|
2019-01-17 00:37:20 +08:00
|
|
|
public static function RoleList($params = [])
|
2018-12-28 18:58:37 +08:00
|
|
|
{
|
|
|
|
$where = empty($params['where']) ? [] : $params['where'];
|
|
|
|
$field = empty($params['field']) ? '*' : $params['field'];
|
2021-07-18 23:42:10 +08:00
|
|
|
$data = Db::name('Role')->field($field)->where($where)->select()->toArray();
|
2023-01-19 17:44:03 +08:00
|
|
|
return DataReturn(MyLang('handle_success'), 0, $data);
|
2018-12-28 18:58:37 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* 管理员保存
|
|
|
|
* @author Devil
|
|
|
|
* @blog http://gong.gg/
|
|
|
|
* @version 0.0.1
|
|
|
|
* @datetime 2016-12-10T22:16:29+0800
|
|
|
|
* @param [array] $params [输入参数]
|
|
|
|
*/
|
2019-01-17 00:37:20 +08:00
|
|
|
public static function AdminSave($params = [])
|
2018-12-28 18:58:37 +08:00
|
|
|
{
|
|
|
|
// 请求参数
|
|
|
|
$p = [
|
|
|
|
[
|
|
|
|
'checked_type' => 'empty',
|
|
|
|
'key_name' => 'admin',
|
2023-02-06 18:30:08 +08:00
|
|
|
'error_msg' => MyLang('common_service.admin.save_admin_info_error_tips'),
|
2018-12-28 18:58:37 +08:00
|
|
|
],
|
|
|
|
[
|
|
|
|
'checked_type' => 'fun',
|
|
|
|
'key_name' => 'mobile',
|
|
|
|
'checked_data' => 'CheckMobile',
|
|
|
|
'is_checked' => 1,
|
2023-02-06 18:30:08 +08:00
|
|
|
'error_msg' => MyLang('common_service.admin.form_item_mobile_message'),
|
2018-12-28 18:58:37 +08:00
|
|
|
],
|
2021-03-04 21:50:30 +08:00
|
|
|
[
|
|
|
|
'checked_type' => 'fun',
|
|
|
|
'key_name' => 'email',
|
|
|
|
'checked_data' => 'CheckEmail',
|
|
|
|
'is_checked' => 1,
|
2023-02-06 18:30:08 +08:00
|
|
|
'error_msg' => MyLang('common_service.admin.form_item_email_message'),
|
2021-03-04 21:50:30 +08:00
|
|
|
],
|
2018-12-28 18:58:37 +08:00
|
|
|
[
|
|
|
|
'checked_type' => 'in',
|
|
|
|
'key_name' => 'gender',
|
|
|
|
'checked_data' => [0,1,2],
|
2023-02-06 18:30:08 +08:00
|
|
|
'error_msg' => MyLang('common_service.admin.save_gender_tips'),
|
2018-12-28 18:58:37 +08:00
|
|
|
],
|
2020-06-11 18:48:31 +08:00
|
|
|
[
|
|
|
|
'checked_type' => 'in',
|
|
|
|
'key_name' => 'status',
|
2023-01-19 17:44:03 +08:00
|
|
|
'checked_data' => array_column(MyLang('common_admin_status_list'), 'value'),
|
2023-02-06 18:30:08 +08:00
|
|
|
'error_msg' => MyLang('common_service.admin.save_status_tips'),
|
2020-06-11 18:48:31 +08:00
|
|
|
],
|
2021-03-04 21:50:30 +08:00
|
|
|
[
|
|
|
|
'checked_type' => 'unique',
|
|
|
|
'key_name' => 'mobile',
|
|
|
|
'checked_data' => 'Admin',
|
|
|
|
'checked_key' => 'id',
|
|
|
|
'is_checked' => 1,
|
2023-02-06 18:30:08 +08:00
|
|
|
'error_msg' => MyLang('common_service.admin.save_mobile_already_exist_tips'),
|
2021-03-04 21:50:30 +08:00
|
|
|
],
|
|
|
|
[
|
|
|
|
'checked_type' => 'unique',
|
|
|
|
'key_name' => 'email',
|
|
|
|
'checked_data' => 'Admin',
|
|
|
|
'checked_key' => 'id',
|
|
|
|
'is_checked' => 1,
|
2023-02-06 18:30:08 +08:00
|
|
|
'error_msg' => MyLang('common_service.admin.save_email_already_exist_tips'),
|
2021-03-04 21:50:30 +08:00
|
|
|
],
|
2018-12-28 18:58:37 +08:00
|
|
|
];
|
|
|
|
$ret = ParamsChecked($params, $p);
|
|
|
|
if($ret !== true)
|
|
|
|
{
|
|
|
|
return DataReturn($ret, -1);
|
|
|
|
}
|
2019-01-17 00:37:20 +08:00
|
|
|
return empty($params['id']) ? self::AdminInsert($params) : self::AdminUpdate($params);
|
2018-12-28 18:58:37 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* 管理员添加
|
|
|
|
* @author Devil
|
|
|
|
* @blog http://gong.gg/
|
|
|
|
* @version 0.0.1
|
|
|
|
* @datetime 2016-12-10T22:16:29+0800
|
|
|
|
* @param [array] $params [输入参数]
|
|
|
|
*/
|
2019-01-17 00:37:20 +08:00
|
|
|
public static function AdminInsert($params = [])
|
2018-12-28 18:58:37 +08:00
|
|
|
{
|
|
|
|
// 请求参数
|
|
|
|
$p = [
|
|
|
|
[
|
|
|
|
'checked_type' => 'empty',
|
|
|
|
'key_name' => 'username',
|
2023-02-06 18:30:08 +08:00
|
|
|
'error_msg' => MyLang('common_service.admin.form_item_username_placeholder'),
|
2018-12-28 18:58:37 +08:00
|
|
|
],
|
|
|
|
[
|
|
|
|
'checked_type' => 'fun',
|
|
|
|
'key_name' => 'username',
|
|
|
|
'checked_data' => 'CheckUserName',
|
2023-02-06 18:30:08 +08:00
|
|
|
'error_msg' => MyLang('common_service.admin.form_item_username_message'),
|
2018-12-28 18:58:37 +08:00
|
|
|
],
|
2019-04-16 15:17:30 +08:00
|
|
|
[
|
|
|
|
'checked_type' => 'unique',
|
|
|
|
'key_name' => 'username',
|
|
|
|
'checked_data' => 'Admin',
|
2020-08-24 23:39:14 +08:00
|
|
|
'checked_key' => 'id',
|
2023-02-06 18:30:08 +08:00
|
|
|
'error_msg' => MyLang('common_service.admin.save_admin_already_exist_tips'),
|
|
|
|
],
|
|
|
|
[
|
|
|
|
'checked_type' => 'empty',
|
|
|
|
'key_name' => 'login_pwd',
|
|
|
|
'error_msg' => MyLang('common_service.admin.form_item_password_placeholder'),
|
2019-04-16 15:17:30 +08:00
|
|
|
],
|
2018-12-28 18:58:37 +08:00
|
|
|
[
|
|
|
|
'checked_type' => 'fun',
|
|
|
|
'key_name' => 'login_pwd',
|
|
|
|
'checked_data' => 'CheckLoginPwd',
|
2023-02-06 18:30:08 +08:00
|
|
|
'error_msg' => MyLang('common_service.admin.form_item_password_message'),
|
2018-12-28 18:58:37 +08:00
|
|
|
],
|
|
|
|
[
|
|
|
|
'checked_type' => 'empty',
|
|
|
|
'key_name' => 'role_id',
|
2023-02-06 18:30:08 +08:00
|
|
|
'error_msg' => MyLang('common_service.admin.form_item_role_message'),
|
2018-12-28 18:58:37 +08:00
|
|
|
],
|
|
|
|
];
|
|
|
|
$ret = ParamsChecked($params, $p);
|
|
|
|
if($ret !== true)
|
|
|
|
{
|
|
|
|
return DataReturn($ret, -1);
|
|
|
|
}
|
|
|
|
|
|
|
|
// 添加账号
|
|
|
|
$salt = GetNumberCode(6);
|
|
|
|
$data = [
|
|
|
|
'username' => $params['username'],
|
|
|
|
'login_salt' => $salt,
|
|
|
|
'login_pwd' => LoginPwdEncryption($params['login_pwd'], $salt),
|
2021-03-04 21:50:30 +08:00
|
|
|
'mobile' => empty($params['mobile']) ? '' : $params['mobile'],
|
|
|
|
'email' => empty($params['email']) ? '' : $params['email'],
|
2018-12-28 18:58:37 +08:00
|
|
|
'gender' => intval($params['gender']),
|
2020-06-11 18:48:31 +08:00
|
|
|
'status' => intval($params['status']),
|
2018-12-28 18:58:37 +08:00
|
|
|
'role_id' => intval($params['role_id']),
|
|
|
|
'add_time' => time(),
|
|
|
|
];
|
|
|
|
|
|
|
|
// 添加
|
|
|
|
if(Db::name('Admin')->insert($data) > 0)
|
|
|
|
{
|
2023-02-04 16:47:48 +08:00
|
|
|
return DataReturn(MyLang('insert_success'), 0);
|
2018-12-28 18:58:37 +08:00
|
|
|
}
|
2023-02-04 16:47:48 +08:00
|
|
|
return DataReturn(MyLang('insert_fail'), -100);
|
2018-12-28 18:58:37 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* 管理员更新
|
|
|
|
* @author Devil
|
|
|
|
* @blog http://gong.gg/
|
|
|
|
* @version 0.0.1
|
|
|
|
* @datetime 2016-12-10T22:16:29+0800
|
|
|
|
* @param [array] $params [输入参数]
|
|
|
|
*/
|
2019-01-17 00:37:20 +08:00
|
|
|
public static function AdminUpdate($params = [])
|
2018-12-28 18:58:37 +08:00
|
|
|
{
|
|
|
|
// 请求参数
|
|
|
|
$p = [
|
|
|
|
[
|
|
|
|
'checked_type' => 'fun',
|
|
|
|
'key_name' => 'login_pwd',
|
|
|
|
'checked_data' => 'CheckLoginPwd',
|
|
|
|
'is_checked' => 1,
|
2023-02-06 18:30:08 +08:00
|
|
|
'error_msg' => MyLang('common_service.admin.form_item_password_message'),
|
2018-12-28 18:58:37 +08:00
|
|
|
],
|
|
|
|
];
|
|
|
|
if($params['id'] != $params['admin']['id'])
|
|
|
|
{
|
|
|
|
$p[] = [
|
|
|
|
'checked_type' => 'empty',
|
|
|
|
'key_name' => 'role_id',
|
2023-02-06 18:30:08 +08:00
|
|
|
'error_msg' => MyLang('common_service.admin.form_item_role_message'),
|
2018-12-28 18:58:37 +08:00
|
|
|
];
|
|
|
|
}
|
|
|
|
$ret = ParamsChecked($params, $p);
|
|
|
|
if($ret !== true)
|
|
|
|
{
|
|
|
|
return DataReturn($ret, -1);
|
|
|
|
}
|
|
|
|
|
2019-03-03 10:05:16 +08:00
|
|
|
// 是否非法修改超管
|
|
|
|
if($params['id'] == 1 && $params['id'] != $params['admin']['id'])
|
|
|
|
{
|
2023-02-06 18:30:08 +08:00
|
|
|
return DataReturn(MyLang('illegal_operate_tips'), -1);
|
2019-03-03 10:05:16 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
// 数据
|
2018-12-28 18:58:37 +08:00
|
|
|
$data = [
|
2021-03-04 21:50:30 +08:00
|
|
|
'mobile' => empty($params['mobile']) ? '' : $params['mobile'],
|
|
|
|
'email' => empty($params['email']) ? '' : $params['email'],
|
2018-12-28 18:58:37 +08:00
|
|
|
'gender' => intval($params['gender']),
|
2020-06-11 18:48:31 +08:00
|
|
|
'status' => intval($params['status']),
|
2018-12-28 18:58:37 +08:00
|
|
|
'upd_time' => time(),
|
|
|
|
];
|
|
|
|
|
|
|
|
// 密码
|
|
|
|
if(!empty($params['login_pwd']))
|
|
|
|
{
|
|
|
|
$data['login_salt'] = GetNumberCode(6);
|
|
|
|
$data['login_pwd'] = LoginPwdEncryption($params['login_pwd'], $data['login_salt']);
|
|
|
|
}
|
|
|
|
// 不能修改自身所属角色组
|
|
|
|
if($params['id'] != $params['admin']['id'])
|
|
|
|
{
|
|
|
|
$data['role_id'] = intval($params['role_id']);
|
|
|
|
}
|
|
|
|
|
|
|
|
// 更新
|
|
|
|
if(Db::name('Admin')->where(['id'=>intval($params['id'])])->update($data))
|
|
|
|
{
|
|
|
|
// 自己修改密码则重新登录
|
|
|
|
if(!empty($params['login_pwd']) && $params['id'] == $params['admin']['id'])
|
|
|
|
{
|
2021-07-29 10:17:10 +08:00
|
|
|
self::LoginLogout();
|
2018-12-28 18:58:37 +08:00
|
|
|
}
|
|
|
|
|
2023-01-19 17:44:03 +08:00
|
|
|
return DataReturn(MyLang('edit_success'), 0);
|
2018-12-28 18:58:37 +08:00
|
|
|
}
|
2023-01-19 17:44:03 +08:00
|
|
|
return DataReturn(MyLang('edit_fail'), -100);
|
2018-12-28 18:58:37 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* 管理员删除
|
|
|
|
* @author Devil
|
|
|
|
* @blog http://gong.gg/
|
|
|
|
* @version 0.0.1
|
|
|
|
* @datetime 2016-12-10T22:16:29+0800
|
|
|
|
* @param [array] $params [输入参数]
|
|
|
|
*/
|
2019-01-17 00:37:20 +08:00
|
|
|
public static function AdminDelete($params = [])
|
2018-12-28 18:58:37 +08:00
|
|
|
{
|
2020-06-11 18:48:31 +08:00
|
|
|
// 参数是否有误
|
|
|
|
if(empty($params['ids']))
|
2018-12-28 18:58:37 +08:00
|
|
|
{
|
2023-02-06 18:30:08 +08:00
|
|
|
return DataReturn(MyLang('data_id_error_tips'), -1);
|
2020-06-11 18:48:31 +08:00
|
|
|
}
|
|
|
|
// 是否数组
|
|
|
|
if(!is_array($params['ids']))
|
|
|
|
{
|
|
|
|
$params['ids'] = explode(',', $params['ids']);
|
|
|
|
}
|
|
|
|
|
|
|
|
// 是否包含删除超级管理员
|
|
|
|
if(in_array(1, $params['ids']))
|
|
|
|
{
|
2023-02-06 18:30:08 +08:00
|
|
|
return DataReturn(MyLang('common_service.admin.delete_super_admin_not_tips'), -1);
|
2018-12-28 18:58:37 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
// 删除操作
|
2020-06-11 18:48:31 +08:00
|
|
|
if(Db::name('Admin')->where(['id'=>$params['ids']])->delete())
|
2018-12-28 18:58:37 +08:00
|
|
|
{
|
2023-01-19 17:44:03 +08:00
|
|
|
return DataReturn(MyLang('delete_success'), 0);
|
2018-12-28 18:58:37 +08:00
|
|
|
}
|
2023-01-19 17:44:03 +08:00
|
|
|
return DataReturn(MyLang('delete_fail'), -100);
|
2018-12-28 18:58:37 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* 管理员登录
|
|
|
|
* @author Devil
|
|
|
|
* @blog http://gong.gg/
|
|
|
|
* @version 0.0.1
|
|
|
|
* @datetime 2016-12-10T22:16:29+0800
|
|
|
|
* @param [array] $params [输入参数]
|
|
|
|
*/
|
2019-01-17 00:37:20 +08:00
|
|
|
public static function Login($params = [])
|
2018-12-28 18:58:37 +08:00
|
|
|
{
|
|
|
|
// 请求参数
|
|
|
|
$p = [
|
|
|
|
[
|
2021-03-04 21:50:30 +08:00
|
|
|
'checked_type' => 'in',
|
|
|
|
'key_name' => 'type',
|
2023-01-19 17:44:03 +08:00
|
|
|
'checked_data' => array_column(MyLang('common_login_type_list'), 'value'),
|
2023-02-06 18:30:08 +08:00
|
|
|
'error_msg' => MyLang('login_type_error_tips'),
|
2018-12-28 18:58:37 +08:00
|
|
|
],
|
|
|
|
[
|
|
|
|
'checked_type' => 'empty',
|
2021-03-04 21:50:30 +08:00
|
|
|
'key_name' => 'accounts',
|
2023-02-06 18:30:08 +08:00
|
|
|
'error_msg' => MyLang('accounts_empty_tips'),
|
2018-12-28 18:58:37 +08:00
|
|
|
],
|
|
|
|
];
|
|
|
|
$ret = ParamsChecked($params, $p);
|
|
|
|
if($ret !== true)
|
|
|
|
{
|
|
|
|
return DataReturn($ret, -1);
|
|
|
|
}
|
|
|
|
|
2021-03-04 21:50:30 +08:00
|
|
|
// 是否开启用户注册
|
|
|
|
if(!in_array($params['type'], MyC('admin_login_type', [], true)))
|
|
|
|
{
|
2023-02-06 18:30:08 +08:00
|
|
|
return DataReturn(MyLang('login_close_tips'), -1);
|
2021-03-04 21:50:30 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
// 账户校验
|
|
|
|
$ac = self::LoginAccountsCheck($params);
|
|
|
|
if($ac['code'] != 0)
|
|
|
|
{
|
|
|
|
return $ac;
|
|
|
|
}
|
|
|
|
|
|
|
|
// 验证参数
|
|
|
|
$verify_params = [
|
|
|
|
'key_prefix' => 'admin_login_'.md5($params['accounts']),
|
|
|
|
'expire_time' => MyC('common_verify_expire_time'),
|
|
|
|
];
|
|
|
|
|
|
|
|
// 帐号密码登录需要校验密码
|
|
|
|
if($params['type'] == 'username')
|
|
|
|
{
|
|
|
|
// 请求参数
|
2023-02-06 18:30:08 +08:00
|
|
|
$password_message = MyLang('common_service.admin.form_item_password_message');
|
2021-03-04 21:50:30 +08:00
|
|
|
$p = [
|
|
|
|
[
|
|
|
|
'checked_type' => 'empty',
|
|
|
|
'key_name' => 'pwd',
|
2023-02-06 18:30:08 +08:00
|
|
|
'error_msg' => $password_message,
|
2021-03-04 21:50:30 +08:00
|
|
|
],
|
|
|
|
[
|
|
|
|
'checked_type' => 'fun',
|
|
|
|
'key_name' => 'pwd',
|
|
|
|
'checked_data' => 'CheckLoginPwd',
|
2023-02-06 18:30:08 +08:00
|
|
|
'error_msg' => $password_message,
|
2021-03-04 21:50:30 +08:00
|
|
|
],
|
|
|
|
];
|
|
|
|
$ret = ParamsChecked($params, $p);
|
|
|
|
if($ret !== true)
|
|
|
|
{
|
|
|
|
return DataReturn($ret, -1);
|
|
|
|
}
|
|
|
|
|
|
|
|
// 帐号密码登录是否开启图片验证码
|
|
|
|
$verify_params['key_prefix'] = 'admin_login';
|
|
|
|
$verify = self::IsImaVerify($params, $verify_params, MyC('admin_login_img_verify_state'));
|
|
|
|
if($verify['code'] != 0)
|
|
|
|
{
|
|
|
|
return $verify;
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
// 账户类型
|
|
|
|
$obj = null;
|
|
|
|
switch($params['type'])
|
|
|
|
{
|
|
|
|
// 短信
|
|
|
|
case 'sms' :
|
|
|
|
$obj = new \base\Sms($verify_params);
|
|
|
|
break;
|
|
|
|
|
|
|
|
// 邮箱
|
|
|
|
case 'email' :
|
|
|
|
$obj = new \base\Email($verify_params);
|
|
|
|
break;
|
|
|
|
|
|
|
|
// 未知的字段
|
|
|
|
default :
|
2023-02-06 18:30:08 +08:00
|
|
|
return DataReturn(MyLang('verify_type_error_tips'), -1);
|
2021-03-04 21:50:30 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
// 验证码校验
|
|
|
|
// sms, email
|
|
|
|
if(isset($obj) && is_object($obj))
|
|
|
|
{
|
|
|
|
// 是否已过期
|
|
|
|
if(!$obj->CheckExpire())
|
|
|
|
{
|
2023-02-06 18:30:08 +08:00
|
|
|
return DataReturn(MyLang('verify_code_expire_tips'), -10);
|
2021-03-04 21:50:30 +08:00
|
|
|
}
|
|
|
|
// 是否正确
|
|
|
|
if(!$obj->CheckCorrect($params['verify']))
|
|
|
|
{
|
2023-02-06 18:30:08 +08:00
|
|
|
return DataReturn(MyLang('verify_code_error_tips'), -11);
|
2021-03-04 21:50:30 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-12-28 18:58:37 +08:00
|
|
|
// 获取管理员
|
2021-03-04 21:50:30 +08:00
|
|
|
$admin = Db::name('Admin')->field('id,username,mobile,email,login_pwd,login_salt,login_total,role_id')->where([$ac['data']=>$params['accounts'], 'status'=>0])->find();
|
2018-12-28 18:58:37 +08:00
|
|
|
if(empty($admin))
|
|
|
|
{
|
2023-02-06 18:30:08 +08:00
|
|
|
return DataReturn(MyLang('account_abnormal_tips'), -2);
|
2018-12-28 18:58:37 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
// 密码校验
|
2021-03-04 21:50:30 +08:00
|
|
|
// 帐号密码登录需要校验密码
|
|
|
|
if($params['type'] == 'username')
|
2018-12-28 18:58:37 +08:00
|
|
|
{
|
2021-03-04 21:50:30 +08:00
|
|
|
$pwd = LoginPwdEncryption($params['pwd'], $admin['login_salt']);
|
|
|
|
if($pwd != $admin['login_pwd'])
|
|
|
|
{
|
2023-02-06 18:30:08 +08:00
|
|
|
return DataReturn(MyLang('password_error_tips'), -3);
|
2021-03-04 21:50:30 +08:00
|
|
|
}
|
2018-12-28 18:58:37 +08:00
|
|
|
}
|
|
|
|
|
2022-05-16 16:35:50 +08:00
|
|
|
// 种session,更新数据库
|
|
|
|
if(self::LoginSession($admin))
|
2018-12-28 18:58:37 +08:00
|
|
|
{
|
2021-03-04 21:50:30 +08:00
|
|
|
$data = [
|
2018-12-28 18:58:37 +08:00
|
|
|
'login_total' => $admin['login_total']+1,
|
|
|
|
'login_time' => time(),
|
2021-03-04 21:50:30 +08:00
|
|
|
];
|
|
|
|
if($params['type'] == 'username')
|
|
|
|
{
|
|
|
|
$login_salt = GetNumberCode(6);
|
|
|
|
$data['login_salt'] = $login_salt;
|
|
|
|
$data['login_pwd'] = LoginPwdEncryption($params['pwd'], $login_salt);
|
|
|
|
}
|
2018-12-28 18:58:37 +08:00
|
|
|
if(Db::name('Admin')->where(['id'=>$admin['id']])->update($data))
|
|
|
|
{
|
2019-07-10 18:27:00 +08:00
|
|
|
// 清空权限缓存数据
|
2022-04-21 22:08:53 +08:00
|
|
|
MyCache(SystemService::CacheKey('shopxo.cache_admin_left_menu_key').$admin['id'], null);
|
|
|
|
MyCache(SystemService::CacheKey('shopxo.cache_admin_power_key').$admin['id'], null);
|
|
|
|
MyCache(SystemService::CacheKey('shopxo.cache_admin_power_plugins_key').$admin['id'], null);
|
2018-12-28 18:58:37 +08:00
|
|
|
|
2021-08-07 10:08:06 +08:00
|
|
|
// 权限菜单初始化
|
2022-05-16 16:35:50 +08:00
|
|
|
AdminPowerService::PowerMenuInit($admin);
|
2021-08-07 10:08:06 +08:00
|
|
|
|
2023-02-04 16:47:48 +08:00
|
|
|
return DataReturn(MyLang('login_success'));
|
2018-12-28 18:58:37 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// 失败
|
2020-11-27 15:57:34 +08:00
|
|
|
self::LoginLogout();
|
2023-02-06 18:30:08 +08:00
|
|
|
return DataReturn(MyLang('login_fail_tips'), -100);
|
2018-12-28 18:58:37 +08:00
|
|
|
}
|
2020-11-26 18:34:41 +08:00
|
|
|
|
|
|
|
/**
|
|
|
|
* 登录信息
|
|
|
|
* @author Devil
|
|
|
|
* @blog http://gong.gg/
|
|
|
|
* @version 1.0.0
|
|
|
|
* @date 2020-11-26
|
|
|
|
* @desc description
|
|
|
|
*/
|
|
|
|
public static function LoginInfo()
|
|
|
|
{
|
2022-05-16 16:35:50 +08:00
|
|
|
return MyCookie(self::$admin_login_key);
|
2020-11-26 18:34:41 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2020-11-27 15:57:34 +08:00
|
|
|
* 登录种session
|
2020-11-26 18:34:41 +08:00
|
|
|
* @author Devil
|
|
|
|
* @blog http://gong.gg/
|
|
|
|
* @version 1.0.0
|
|
|
|
* @date 2020-11-26
|
|
|
|
* @desc description
|
|
|
|
* @param [array] $admin [管理员登录信息]
|
|
|
|
*/
|
2020-11-27 15:57:34 +08:00
|
|
|
public static function LoginSession($admin)
|
2020-11-26 18:34:41 +08:00
|
|
|
{
|
2021-03-04 21:50:30 +08:00
|
|
|
unset($admin['login_pwd'], $admin['login_salt']);
|
2022-05-16 16:35:50 +08:00
|
|
|
MyCookie(self::$admin_login_key, $admin);
|
|
|
|
return true;
|
2020-11-26 18:34:41 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* 登录退出
|
|
|
|
* @author Devil
|
|
|
|
* @blog http://gong.gg/
|
|
|
|
* @version 1.0.0
|
|
|
|
* @date 2020-11-26
|
|
|
|
* @desc description
|
|
|
|
*/
|
|
|
|
public static function LoginLogout()
|
|
|
|
{
|
2022-05-16 16:35:50 +08:00
|
|
|
return MyCookie(self::$admin_login_key, null);
|
2020-11-26 18:34:41 +08:00
|
|
|
}
|
2021-03-04 21:50:30 +08:00
|
|
|
|
|
|
|
/**
|
|
|
|
* 管理员登录验证码发送
|
|
|
|
* @author Devil
|
|
|
|
* @blog http://gong.gg/
|
|
|
|
* @version 1.0.0
|
|
|
|
* @date 2021-03-03
|
|
|
|
* @desc description
|
|
|
|
* @param [array] $params [输入参数]
|
|
|
|
*/
|
|
|
|
public static function LoginVerifySend($params = [])
|
|
|
|
{
|
|
|
|
// 数据验证
|
|
|
|
$p = [
|
|
|
|
[
|
|
|
|
'checked_type' => 'empty',
|
|
|
|
'key_name' => 'accounts',
|
2023-02-06 18:30:08 +08:00
|
|
|
'error_msg' => MyLang('accounts_empty_tips'),
|
2021-03-04 21:50:30 +08:00
|
|
|
],
|
|
|
|
[
|
|
|
|
'checked_type' => 'in',
|
|
|
|
'key_name' => 'type',
|
2023-01-19 17:44:03 +08:00
|
|
|
'checked_data' => array_column(MyLang('common_login_type_list'), 'value'),
|
2023-02-06 18:30:08 +08:00
|
|
|
'error_msg' => MyLang('login_type_error_tips'),
|
2021-03-04 21:50:30 +08:00
|
|
|
],
|
|
|
|
];
|
|
|
|
$ret = ParamsChecked($params, $p);
|
|
|
|
if($ret !== true)
|
|
|
|
{
|
|
|
|
return DataReturn($ret, -1);
|
|
|
|
}
|
|
|
|
|
|
|
|
// 是否开启用户注册
|
|
|
|
if(!in_array($params['type'], MyC('admin_login_type', [], true)))
|
|
|
|
{
|
2023-02-06 18:30:08 +08:00
|
|
|
return DataReturn(MyLang('login_close_tips'), -1);
|
2021-03-04 21:50:30 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
// 验证码基础参数
|
|
|
|
$verify_params = [
|
|
|
|
'key_prefix' => 'admin_login',
|
|
|
|
'expire_time' => MyC('common_verify_expire_time'),
|
|
|
|
'interval_time' => MyC('common_verify_interval_time'),
|
|
|
|
];
|
|
|
|
|
|
|
|
// 是否开启图片验证码
|
|
|
|
$verify = self::IsImaVerify($params, $verify_params, MyC('common_img_verify_state'));
|
|
|
|
if($verify['code'] != 0)
|
|
|
|
{
|
|
|
|
return $verify;
|
|
|
|
}
|
|
|
|
|
|
|
|
// 账户校验
|
|
|
|
$ac = self::LoginAccountsCheck($params);
|
|
|
|
if($ac['code'] != 0)
|
|
|
|
{
|
|
|
|
return $ac;
|
|
|
|
}
|
|
|
|
|
|
|
|
// 验证码基础参数 key
|
|
|
|
$verify_params['key_prefix'] = 'admin_login_'.md5($params['accounts']);
|
|
|
|
|
|
|
|
// 发送验证码
|
|
|
|
$code = GetNumberCode(4);
|
|
|
|
switch($params['type'])
|
|
|
|
{
|
|
|
|
// 短信
|
|
|
|
case 'sms' :
|
|
|
|
$obj = new \base\Sms($verify_params);
|
|
|
|
$status = $obj->SendCode($params['accounts'], $code, MyC('admin_sms_login_template'));
|
|
|
|
break;
|
|
|
|
|
|
|
|
// 邮箱
|
|
|
|
case 'email' :
|
|
|
|
$obj = new \base\Email($verify_params);
|
|
|
|
$email_params = [
|
|
|
|
'email' => $params['accounts'],
|
|
|
|
'content' => MyC('admin_email_login_template'),
|
2023-02-06 18:30:08 +08:00
|
|
|
'title' => MyC('home_site_name').MyLang('common_service.admin.login_verify_send_last_title'),
|
2021-03-04 21:50:30 +08:00
|
|
|
'code' => $code,
|
|
|
|
];
|
|
|
|
$status = $obj->SendHtml($email_params);
|
|
|
|
break;
|
|
|
|
|
|
|
|
// 默认
|
|
|
|
default :
|
2023-02-06 18:30:08 +08:00
|
|
|
return DataReturn(MyLang('verify_code_not_support_send_error_tips'), -2);
|
2021-03-04 21:50:30 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
// 状态
|
|
|
|
if($status)
|
|
|
|
{
|
|
|
|
// 清除验证码
|
|
|
|
if(isset($verify['data']) && is_object($verify['data']))
|
|
|
|
{
|
|
|
|
$verify['data']->Remove();
|
|
|
|
}
|
|
|
|
|
2023-01-19 17:44:03 +08:00
|
|
|
return DataReturn(MyLang('send_success'), 0);
|
2021-03-04 21:50:30 +08:00
|
|
|
}
|
2023-01-19 17:44:03 +08:00
|
|
|
return DataReturn(MyLang('send_fail').'['.$obj->error.']', -100);
|
2021-03-04 21:50:30 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* 登录账户校验
|
|
|
|
* @author Devil
|
|
|
|
* @blog http://gong.gg/
|
|
|
|
* @version 1.0.0
|
|
|
|
* @date 2021-03-03
|
|
|
|
* @desc description
|
|
|
|
* @param [array] $params [输入参数]
|
|
|
|
*/
|
|
|
|
private static function LoginAccountsCheck($params = [])
|
|
|
|
{
|
|
|
|
$field = '';
|
|
|
|
switch($params['type'])
|
|
|
|
{
|
|
|
|
// 手机
|
|
|
|
case 'sms' :
|
|
|
|
// 手机号码格式
|
|
|
|
if(!CheckMobile($params['accounts']))
|
|
|
|
{
|
2023-02-06 18:30:08 +08:00
|
|
|
return DataReturn(MyLang('mobile_format_error_tips'), -2);
|
2021-03-04 21:50:30 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
// 手机号码是否存在
|
|
|
|
if(!self::IsExistAccounts($params['accounts'], 'mobile'))
|
|
|
|
{
|
2023-02-06 18:30:08 +08:00
|
|
|
return DataReturn(MyLang('mobile_no_exist_error_tips'), -3);
|
2021-03-04 21:50:30 +08:00
|
|
|
}
|
|
|
|
$field = 'mobile';
|
|
|
|
break;
|
|
|
|
|
|
|
|
// 邮箱
|
|
|
|
case 'email' :
|
|
|
|
// 电子邮箱格式
|
|
|
|
if(!CheckEmail($params['accounts']))
|
|
|
|
{
|
2023-02-06 18:30:08 +08:00
|
|
|
return DataReturn(MyLang('email_format_error_tips'), -2);
|
2021-03-04 21:50:30 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
// 电子邮箱是否存在
|
|
|
|
if(!self::IsExistAccounts($params['accounts'], 'email'))
|
|
|
|
{
|
2023-02-06 18:30:08 +08:00
|
|
|
return DataReturn(MyLang('email_no_exist_error_tips'), -3);
|
2021-03-04 21:50:30 +08:00
|
|
|
}
|
|
|
|
$field = 'email';
|
|
|
|
break;
|
|
|
|
|
|
|
|
// 用户名
|
|
|
|
case 'username' :
|
|
|
|
// 用户名格式
|
|
|
|
if(!CheckUserName($params['accounts']))
|
|
|
|
{
|
2023-02-06 18:30:08 +08:00
|
|
|
return DataReturn(MyLang('common_service.admin.form_item_username_message'), -2);
|
2021-03-04 21:50:30 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
// 用户名是否存在
|
|
|
|
if(!self::IsExistAccounts($params['accounts'], 'username'))
|
|
|
|
{
|
2023-02-06 18:30:08 +08:00
|
|
|
return DataReturn(MyLang('accounts_error_tips'), -3);
|
2021-03-04 21:50:30 +08:00
|
|
|
}
|
|
|
|
$field = 'username';
|
|
|
|
break;
|
|
|
|
}
|
2023-01-19 17:44:03 +08:00
|
|
|
return DataReturn(MyLang('operate_success'), 0, $field);
|
2021-03-04 21:50:30 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
*
|
|
|
|
* @author Devil
|
|
|
|
* @blog http://gong.gg/
|
|
|
|
* @version 0.0.1
|
|
|
|
* @datetime 2017-03-08T10:27:14+0800
|
|
|
|
* @param [string] $accounts [账户名称]
|
|
|
|
* @param [string] $field [字段名称]
|
|
|
|
* @return [boolean] [存在true, 不存在false]
|
|
|
|
*/
|
|
|
|
|
|
|
|
/**
|
|
|
|
* 账户是否存在
|
|
|
|
* @author Devil
|
|
|
|
* @blog http://gong.gg/
|
|
|
|
* @version 1.0.0
|
|
|
|
* @date 2021-03-03
|
|
|
|
* @desc description
|
|
|
|
* @param [string] $accounts [账户名称]
|
|
|
|
* @param [string] $field [字段名称]
|
|
|
|
* @return [boolean] [存在true, 不存在false]
|
|
|
|
*/
|
|
|
|
private static function IsExistAccounts($accounts, $field = 'username')
|
|
|
|
{
|
|
|
|
$id = Db::name('Admin')->where(array($field=>$accounts))->value('id');
|
|
|
|
return !empty($id);
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* 是否开启图片验证码校验
|
|
|
|
* @author Devil
|
|
|
|
* @blog http://gong.gg/
|
|
|
|
* @version 1.0.0
|
|
|
|
* @date 2021-03-03
|
|
|
|
* @desc description
|
|
|
|
* @param [array] $params [输入参数]
|
|
|
|
* @param [array] $verify_params [配置参数]
|
|
|
|
* @param [int] $status [状态 0未开启, 1已开启]
|
|
|
|
* @return [object] [图片验证码类对象]
|
|
|
|
*/
|
|
|
|
private static function IsImaVerify($params, $verify_params, $status = 0)
|
|
|
|
{
|
|
|
|
if($status == 1)
|
|
|
|
{
|
|
|
|
if(empty($params['verify']))
|
|
|
|
{
|
2023-02-06 18:30:08 +08:00
|
|
|
return DataReturn(MyLang('verify_images_empty_tips'), -10);
|
2021-03-04 21:50:30 +08:00
|
|
|
}
|
|
|
|
$verify = new \base\Verify($verify_params);
|
|
|
|
if(!$verify->CheckExpire())
|
|
|
|
{
|
2023-02-06 18:30:08 +08:00
|
|
|
return DataReturn(MyLang('verify_code_expire_tips'), -11);
|
2021-03-04 21:50:30 +08:00
|
|
|
}
|
|
|
|
if(!$verify->CheckCorrect($params['verify']))
|
|
|
|
{
|
2023-02-06 18:30:08 +08:00
|
|
|
return DataReturn(MyLang('verify_code_error_tips'), -12);
|
2021-03-04 21:50:30 +08:00
|
|
|
}
|
2023-02-04 16:47:48 +08:00
|
|
|
return DataReturn(MyLang('check_success'), 0, $verify);
|
2021-03-04 21:50:30 +08:00
|
|
|
}
|
2023-02-04 16:47:48 +08:00
|
|
|
return DataReturn(MyLang('check_success'), 0);
|
2021-03-04 21:50:30 +08:00
|
|
|
}
|
2018-12-28 18:58:37 +08:00
|
|
|
}
|
|
|
|
?>
|