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.
186 lines
5.8 KiB
186 lines
5.8 KiB
<?php
|
|
declare (strict_types = 1);
|
|
|
|
namespace app\controller;
|
|
|
|
use app\BaseController;
|
|
use app\middleware\CheckAdmin;
|
|
use think\exception\ValidateException;
|
|
use think\facade\Cache;
|
|
use think\facade\Db;
|
|
use think\facade\Filesystem;
|
|
use think\facade\Request;
|
|
use app\model\AdminUser as AdminModel;
|
|
|
|
class AdminUser extends BaseController
|
|
{
|
|
|
|
protected $middleware = [CheckAdmin::class];
|
|
|
|
protected $relationType = [1 => '用户', 2 => '代理'];
|
|
|
|
/**
|
|
* 新增管理
|
|
* @return array
|
|
*/
|
|
public function addUser()
|
|
{
|
|
$param = Request::param();
|
|
|
|
try {
|
|
|
|
validate(\app\validate\Passport::class)->scene('adminLogin')->check($param);
|
|
|
|
$User = new AdminModel();
|
|
|
|
$result = $User::createAdmin($param['account_number'],$param['password']);
|
|
|
|
if (!$result) throw new ValidateException('管理已存在');
|
|
|
|
return $this->renderSuccess('添加成功');
|
|
} catch (ValidateException $validateException) {
|
|
return $this->renderError($validateException->getMessage());
|
|
} catch (\Exception $e) {
|
|
return $this->renderError('操作失败');
|
|
}
|
|
}
|
|
|
|
/**
|
|
* 管理员信息
|
|
* @return array
|
|
* @throws \think\db\exception\DataNotFoundException
|
|
* @throws \think\db\exception\DbException
|
|
* @throws \think\db\exception\ModelNotFoundException
|
|
*/
|
|
public function userInfo()
|
|
{
|
|
|
|
$adminData = $this->request->userInfo;
|
|
|
|
$data = AdminModel::field('id,avatar')->where('id',$adminData['id'])->find();
|
|
$data['avatar'] = get_image_url($data['avatar']);
|
|
return $this->renderSuccess('数据返回成功',['data' => $data]);
|
|
}
|
|
|
|
/**
|
|
* 上分记录
|
|
* @return array
|
|
* @throws \think\db\exception\DbException
|
|
*/
|
|
public function upScoresList()
|
|
{
|
|
$adminData = $this->request->userInfo;
|
|
|
|
$data = Request::param();
|
|
|
|
$limit = $data['limit'] ?: 10;
|
|
|
|
$list = Db::name('admin_up_scores_records')
|
|
->where('admin_id',$adminData['id'])
|
|
->field('relation_id,relation_type,balance,residue_amount,create_time')
|
|
->order('id' ,'desc')
|
|
->paginate($limit);
|
|
|
|
$listArr = $list->items();
|
|
|
|
foreach ($listArr as &$item) {
|
|
$item['relation_type'] = $this->relationType[$item['relation_type']];
|
|
give_symbol($item['balance']);
|
|
$item['create_time'] = date("m月d日 H:i",strtotime($item['create_time']));
|
|
}
|
|
|
|
return $this->renderSuccess('数据获取成功',[
|
|
'list' => $listArr,
|
|
'total' => $list->total()
|
|
]);
|
|
}
|
|
|
|
/**
|
|
* 下分记录
|
|
* @return array
|
|
* @throws \think\db\exception\DbException
|
|
*/
|
|
public function downScoresList()
|
|
{
|
|
$adminData = $this->request->userInfo;
|
|
|
|
$data = Request::param();
|
|
|
|
$limit = $data['limit'] ?: 10;
|
|
|
|
$list = Db::name('admin_down_scores_records')
|
|
->where('admin_id',$adminData['id'])
|
|
->field('relation_id,relation_type,withdrawal_amount,withdrawal_balance,create_time')
|
|
->order('id' ,'desc')
|
|
->paginate($limit);
|
|
|
|
$listArr = $list->items();
|
|
|
|
foreach ($listArr as &$item) {
|
|
$item['relation_type'] = $this->relationType[$item['relation_type']];
|
|
give_symbol($item['withdrawal_amount'],'-');
|
|
$item['create_time'] = date("m月d日 H:i",strtotime($item['create_time']));
|
|
}
|
|
|
|
return $this->renderSuccess('数据获取成功',[
|
|
'list' => $listArr,
|
|
'total' => $list->total()
|
|
]);
|
|
}
|
|
|
|
/**
|
|
* 清除所有缓存数据
|
|
* @return array
|
|
* @throws \League\Flysystem\FilesystemException
|
|
* @throws \Psr\SimpleCache\InvalidArgumentException
|
|
*/
|
|
public function clean()
|
|
{
|
|
# 获取所有表名
|
|
$tables = Db::query('SHOW TABLES');
|
|
$tablesNameArr = [];
|
|
$tableNames = 'Tables_in_' . env('database.database', 'guaguale');
|
|
foreach ($tables as $table) {
|
|
if(isset($table[$tableNames]) && !empty($table[$tableNames])) {
|
|
$tablesNameArr[] = $table[$tableNames];
|
|
}
|
|
}
|
|
|
|
# 备份数据表数据
|
|
#if (!$result['status']) return $this->renderError('清除失败');
|
|
|
|
# 清空
|
|
foreach ($tablesNameArr as $tableName) {
|
|
Db::query("TRUNCATE TABLE {$tableName}");
|
|
}
|
|
|
|
// 清空缓存
|
|
$login_user_data = Cache::store('redis')->get('login_user_data');
|
|
if ($login_user_data) Cache::store('redis')->delete('login_admin_user_data');
|
|
$login_agent_user_data = Cache::store('redis')->get('login_agent_user_data');
|
|
if ($login_agent_user_data) Cache::store('redis')->delete('login_agent_user_data');
|
|
$login_admin_user_data = Cache::store('redis')->get('login_admin_user_data');
|
|
if ($login_admin_user_data) Cache::store('redis')->delete('login_admin_user_data');
|
|
$login_admin_user_data = Cache::store('redis')->get('user_recharge_set');
|
|
if ($login_admin_user_data) Cache::store('redis')->delete('user_recharge_set');
|
|
$login_admin_user_data = Cache::store('redis')->get('agent_recharge_set');
|
|
if ($login_admin_user_data) Cache::store('redis')->delete('agent_recharge_set');
|
|
|
|
// 删除所有图片文件
|
|
// $dirPath = public_path('storage');
|
|
// Filesystem::deleteDirectory($dirPath);
|
|
|
|
return $this->renderSuccess('已清除成功');
|
|
}
|
|
|
|
|
|
/**
|
|
* 退出登陆
|
|
*/
|
|
public function LogOut()
|
|
{
|
|
$login_admin_user_data = Cache::store('redis')->get('login_admin_user_data');
|
|
if ($login_admin_user_data) Cache::store('redis')->delete('login_admin_user_data');
|
|
return $this->renderSuccess('退出登陆成功');
|
|
}
|
|
}
|
|
|