You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
127 lines
3.8 KiB
127 lines
3.8 KiB
<?php
|
|
|
|
// +----------------------------------------------------------------------
|
|
// | ThinkAdmin
|
|
// +----------------------------------------------------------------------
|
|
// | 版权所有 2014~2019 广州楚才信息科技有限公司 [ http://www.cuci.cc ]
|
|
// +----------------------------------------------------------------------
|
|
// | 官方网站: http://demo.thinkadmin.top
|
|
// +----------------------------------------------------------------------
|
|
// | 开源协议 ( https://mit-license.org )
|
|
// +----------------------------------------------------------------------
|
|
// | gitee 代码仓库:https://gitee.com/zoujingli/ThinkAdmin
|
|
// | github 代码仓库:https://github.com/zoujingli/ThinkAdmin
|
|
// +----------------------------------------------------------------------
|
|
|
|
namespace app\index\controller;
|
|
|
|
use think\App;
|
|
use think\Db;
|
|
|
|
/**
|
|
* 子账号管理
|
|
* Class Index
|
|
* @package app\index\controller
|
|
*/
|
|
class Subaccount extends Base
|
|
{
|
|
private $table = 'CloudSubaccount';
|
|
|
|
public function __construct(App $app = null)
|
|
{
|
|
parent::__construct($app);
|
|
parent::auth();
|
|
}
|
|
|
|
/**
|
|
* 获取子账号列表
|
|
*/
|
|
public function index()
|
|
{
|
|
$_where = 'user_id = ' . USER_ID;
|
|
$count = Db::name($this->table)->where($_where)->count();
|
|
$page = $this->request->param('page', 1);
|
|
$pagesize = $this->request->param('pagesize', 10);
|
|
$pages = ceil($count / $pagesize); //总页数
|
|
$_result = Db::name($this->table)->where($_where)->page($page, $pagesize)->order('id', "DESC")->select();
|
|
$_data['list'] = $_result;
|
|
$_data['pages'] = $pages;
|
|
self::formatData($_data['list']);
|
|
return send_http_status(200, $_data);
|
|
}
|
|
|
|
/**
|
|
* 子账号详情
|
|
*/
|
|
public function view($id = '')
|
|
{
|
|
if (!$id) {
|
|
return;
|
|
}
|
|
//获取房源详情
|
|
$_data = Db::name($this->table)->where('user_id', USER_ID)->find($id);
|
|
return send_http_status(200, $_data);
|
|
}
|
|
|
|
/**
|
|
* 添加子账号
|
|
*/
|
|
public function add()
|
|
{
|
|
$_data = $this->request->post();
|
|
$_data['create_time'] = $_data['update_time'] = time();
|
|
$_data['password'] = sha1($_data['password']);
|
|
$_data['user_id'] = USER_ID;
|
|
$_data = array_filter($_data);
|
|
//先查询账号是否存在
|
|
$_user = Db::name($this->table)->where('username', $_data['username'])->find();
|
|
if ($_user) {
|
|
return send_http_status(51010);
|
|
}
|
|
//查询已有账号的数量
|
|
$count = Db::name($this->table)->where('user_id', USER_ID)->where('status', 1)->count();
|
|
$_config = config('vip_level');
|
|
if ($count > $_config[MEMBER['vip_level']]['subaccount_count']) {
|
|
return send_http_status(51011);
|
|
}
|
|
$affected = Db::name($this->table)->strict(false)->insert($_data);
|
|
if (!$affected) {
|
|
return send_http_status(51002);
|
|
}
|
|
return send_http_status(200);
|
|
}
|
|
|
|
/**
|
|
* 修改子账号
|
|
*/
|
|
public function edit()
|
|
{
|
|
$_data = $this->request->post();
|
|
$_data['update_time'] = time();
|
|
$_data['user_id'] = USER_ID;
|
|
if ($_data['password'] == '***123***') {
|
|
unset($_data['password']);
|
|
}else{
|
|
$_data['password'] = sha1($_data['password']);
|
|
}
|
|
$affected = Db::name($this->table)->strict(false)->update($_data);
|
|
if (!$affected) {
|
|
return send_http_status(51002);
|
|
}
|
|
return send_http_status(200);
|
|
}
|
|
|
|
|
|
static private function formatData(&$data)
|
|
{
|
|
if (!$data) {
|
|
return;
|
|
}
|
|
array_walk($data, function (&$v, &$k) {
|
|
!empty($v['create_time']) ? $v['create_time'] = date('Y-m-d', $v['create_time']) : $v['create_time'] = '';
|
|
});
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|