Files
shopxo/app/admin/controller/Admin.php

306 lines
7.4 KiB
PHP
Raw Normal View History

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\admin\controller;
use app\service\ApiService;
use app\service\AdminService;
2021-07-06 23:57:03 +08:00
use app\service\SystemBaseService;
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 Admin extends Common
{
/**
* 构造方法
* @author Devil
* @blog http://gong.gg/
* @version 1.0.0
* @date 2021-03-03
* @desc description
*/
2018-12-28 18:58:37 +08:00
public function __construct()
{
// 调用父类前置方法
parent::__construct();
2022-08-02 17:23:10 +08:00
// 需要校验权限
if(in_array($this->action_name, ['index', 'detail', 'delete']))
{
// 登录校验
$this->IsLogin();
// 权限校验
$this->IsPower();
}
2018-12-28 18:58:37 +08:00
}
/**
2022-08-02 17:23:10 +08:00
* 列表
* @author Devil
* @blog http://gong.gg/
* @version 1.0.0
* @date 2021-03-03
* @desc description
2018-12-28 18:58:37 +08:00
*/
public function Index()
{
2021-07-18 23:42:10 +08:00
return MyView();
2018-12-28 18:58:37 +08:00
}
/**
* 详情
* @author Devil
* @blog http://gong.gg/
* @version 1.0.0
* @date 2021-03-03
* @desc description
*/
public function Detail()
{
2021-07-18 23:42:10 +08:00
return MyView();
}
2018-12-28 18:58:37 +08:00
/**
* 管理员添加/编辑页面
* @author Devil
* @blog http://gong.gg/
* @version 1.0.0
* @date 2021-03-03
* @desc description
2018-12-28 18:58:37 +08:00
*/
public function SaveInfo()
{
// 登录校验
2019-02-12 11:46:46 +08:00
$this->IsLogin();
2018-12-28 18:58:37 +08:00
// 参数
2020-06-11 18:48:31 +08:00
$params = $this->data_request;
2018-12-28 18:58:37 +08:00
// 不是操作自己的情况下
if(!isset($params['id']) || $params['id'] != $this->admin['id'])
{
// 权限校验
2019-02-12 11:46:46 +08:00
$this->IsPower();
2018-12-28 18:58:37 +08:00
}
2022-08-02 17:23:10 +08:00
// 数据
$data = $this->data_detail;
2018-12-28 18:58:37 +08:00
if(!empty($params['id']))
{
2022-08-02 17:23:10 +08:00
if(empty($data))
2018-12-28 18:58:37 +08:00
{
return $this->error('管理员信息不存在', MyUrl('admin/index/index'));
}
}
// 模板数据
$assign = [
'id' => isset($params['id']) ? $params['id'] : 0,
'common_gender_list' => MyConst('common_gender_list'),
'common_admin_status_list' => MyConst('common_admin_status_list'),
];
2018-12-28 18:58:37 +08:00
// 角色
$role_params = [
2022-08-02 17:23:10 +08:00
'where' => [
['is_enable', '=', 1],
],
2018-12-28 18:58:37 +08:00
'field' => 'id,name',
];
$role = AdminService::RoleList($role_params);
$assign['role_list'] = $role['data'];
2019-08-01 09:55:14 +08:00
// 管理员编辑页面钩子
$hook_name = 'plugins_view_admin_admin_save';
$assign[$hook_name.'_data'] = MyEventTrigger($hook_name,
2019-08-01 09:55:14 +08:00
[
'hook_name' => $hook_name,
2019-08-15 18:56:05 +08:00
'is_backend' => true,
2019-08-01 10:02:34 +08:00
'admin_id' => isset($params['id']) ? $params['id'] : 0,
2019-08-01 09:55:14 +08:00
'data' => &$data,
'params' => &$params,
]);
2019-08-01 09:55:14 +08:00
// 数据
2020-12-09 11:54:55 +08:00
unset($params['id']);
$assign['data'] = $data;
$assign['params'] = $params;
// 数据赋值
MyViewAssign($assign);
2021-07-18 23:42:10 +08:00
return MyView();
2018-12-28 18:58:37 +08:00
}
/**
* 管理员添加/编辑
* @author Devil
* @blog http://gong.gg/
* @version 1.0.0
* @date 2021-03-03
* @desc description
2018-12-28 18:58:37 +08:00
*/
public function Save()
{
2019-02-28 16:56:27 +08:00
// 登录校验
$this->IsLogin();
// 参数
2020-06-11 18:48:31 +08:00
$params = $this->data_post;
2019-02-28 16:56:27 +08:00
// 不是操作自己的情况下
if(!isset($params['id']) || $params['id'] != $this->admin['id'])
{
// 权限校验
$this->IsPower();
}
// 开始操作
2018-12-28 18:58:37 +08:00
$params['admin'] = $this->admin;
return ApiService::ApiDataReturn(AdminService::AdminSave($params));
2018-12-28 18:58:37 +08:00
}
/**
* 管理员删除
* @author Devil
* @blog http://gong.gg/
* @version 1.0.0
* @date 2021-03-03
* @desc description
*/
2018-12-28 18:58:37 +08:00
public function Delete()
{
2020-06-11 18:48:31 +08:00
$params = $this->data_post;
2018-12-28 18:58:37 +08:00
$params['admin'] = $this->admin;
return ApiService::ApiDataReturn(AdminService::AdminDelete($params));
2018-12-28 18:58:37 +08:00
}
/**
* 登录页面
* @author Devil
* @blog http://gong.gg/
* @version 1.0.0
* @date 2021-03-03
* @desc description
2018-12-28 18:58:37 +08:00
*/
public function LoginInfo()
{
// 是否已登录
2022-05-16 16:35:50 +08:00
if(!empty($this->admin))
2018-12-28 18:58:37 +08:00
{
2021-07-18 23:42:10 +08:00
return MyRedirect(MyUrl('admin/index/index'));
2018-12-28 18:58:37 +08:00
}
// 模板数据
$assign = [
// 登录方式
'admin_login_type' => MyC('admin_login_type', [], true),
];
2020-09-28 22:47:21 +08:00
// 背景图片
2021-07-06 23:57:03 +08:00
$host = SystemBaseService::AttachmentHost();
2020-09-28 22:47:21 +08:00
$bg_images_list = [
$host.'/static/admin/default/images/login/1.jpg',
$host.'/static/admin/default/images/login/2.jpg',
$host.'/static/admin/default/images/login/3.jpg',
$host.'/static/admin/default/images/login/4.jpg',
$host.'/static/admin/default/images/login/5.jpg',
$host.'/static/admin/default/images/login/6.jpg',
$host.'/static/admin/default/images/login/7.jpg',
$host.'/static/admin/default/images/login/8.jpg',
$host.'/static/admin/default/images/login/9.jpg',
$host.'/static/admin/default/images/login/10.jpg',
$host.'/static/admin/default/images/login/11.jpg',
$host.'/static/admin/default/images/login/12.jpg',
$host.'/static/admin/default/images/login/13.jpg',
$host.'/static/admin/default/images/login/14.jpg',
$host.'/static/admin/default/images/login/15.jpg',
];
$assign['bg_images_list'] = $bg_images_list;
2020-09-28 22:47:21 +08:00
2019-08-01 10:02:34 +08:00
// 管理员登录页面钩子
$hook_name = 'plugins_view_admin_login_info';
$assign[$hook_name.'_data'] = MyEventTrigger($hook_name,
2019-08-01 10:02:34 +08:00
[
'hook_name' => $hook_name,
2019-08-15 18:56:05 +08:00
'is_backend' => true,
]);
2019-08-01 10:02:34 +08:00
// 数据赋值
MyViewAssign($assign);
2021-07-18 23:42:10 +08:00
return MyView();
2018-12-28 18:58:37 +08:00
}
/**
* 管理员登录
* @author Devil
* @blog http://gong.gg/
* @version 1.0.0
* @date 2021-03-03
* @desc description
*/
2018-12-28 18:58:37 +08:00
public function Login()
{
2020-06-11 18:48:31 +08:00
$params = $this->data_post;
return ApiService::ApiDataReturn(AdminService::Login($params));
2018-12-28 18:58:37 +08:00
}
/**
* 验证码显示
* @author Devil
* @blog http://gong.gg/
* @version 1.0.0
* @date 2021-03-03
* @desc description
*/
public function AdminVerifyEntry()
{
$params = [
'width' => 100,
2021-04-28 14:33:03 +08:00
'height' => 28,
'key_prefix' => 'admin_login',
];
$verify = new \base\Verify($params);
$verify->Entry();
}
/**
* 登录验证码发送
* @author Devil
* @blog http://gong.gg/
* @version 1.0.0
* @date 2021-03-03
* @desc description
*/
public function LoginVerifySend()
{
return ApiService::ApiDataReturn(AdminService::LoginVerifySend($this->data_post));
}
2018-12-28 18:58:37 +08:00
/**
* 退出
* @author Devil
* @blog http://gong.gg/
* @version 1.0.0
* @date 2021-03-03
* @desc description
*/
2018-12-28 18:58:37 +08:00
public function Logout()
{
AdminService::LoginLogout();
2021-07-18 23:42:10 +08:00
return MyRedirect(MyUrl('admin/admin/logininfo'));
2018-12-28 18:58:37 +08:00
}
}
?>