后台
This commit is contained in:
163
app/czg/user/controller/GroupController.php
Normal file
163
app/czg/user/controller/GroupController.php
Normal file
@@ -0,0 +1,163 @@
|
||||
<?php
|
||||
|
||||
namespace app\czg\user\controller;
|
||||
|
||||
use Throwable;
|
||||
use app\admin\model\UserRule;
|
||||
use app\admin\model\UserGroup;
|
||||
use app\common\controller\Backend;
|
||||
|
||||
class GroupController extends Backend
|
||||
{
|
||||
/**
|
||||
* @var object
|
||||
* @phpstan-var UserGroup
|
||||
*/
|
||||
protected object $model;
|
||||
|
||||
// 排除字段
|
||||
protected string|array $preExcludeFields = ['update_time', 'create_time'];
|
||||
|
||||
protected string|array $quickSearchField = 'name';
|
||||
|
||||
public function initialize(): void
|
||||
{
|
||||
// parent::initialize();
|
||||
$this->model = new UserGroup();
|
||||
}
|
||||
|
||||
/**
|
||||
* 添加
|
||||
* @throws Throwable
|
||||
*/
|
||||
public function add(): void
|
||||
{
|
||||
if ($this->request->isPost()) {
|
||||
$data = $this->request->post();
|
||||
if (!$data) {
|
||||
$this->error(__('Parameter %s can not be empty', ['']));
|
||||
}
|
||||
|
||||
$data = $this->excludeFields($data);
|
||||
$data = $this->handleRules($data);
|
||||
|
||||
$result = false;
|
||||
$this->model->startTrans();
|
||||
try {
|
||||
// 模型验证
|
||||
if ($this->modelValidate) {
|
||||
$validate = str_replace("\\model\\", "\\validate\\", get_class($this->model));
|
||||
if (class_exists($validate)) {
|
||||
$validate = new $validate();
|
||||
$validate->scene('add')->check($data);
|
||||
}
|
||||
}
|
||||
$result = $this->model->save($data);
|
||||
$this->model->commit();
|
||||
} catch (Throwable $e) {
|
||||
$this->model->rollback();
|
||||
$this->error($e->getMessage());
|
||||
}
|
||||
if ($result !== false) {
|
||||
$this->success(__('Added successfully'));
|
||||
} else {
|
||||
$this->error(__('No rows were added'));
|
||||
}
|
||||
}
|
||||
|
||||
$this->error(__('Parameter error'));
|
||||
}
|
||||
|
||||
/**
|
||||
* 编辑
|
||||
* @throws Throwable
|
||||
*/
|
||||
public function edit(): void
|
||||
{
|
||||
$pk = $this->model->getPk();
|
||||
$id = $this->request->param($pk);
|
||||
$row = $this->model->find($id);
|
||||
if (!$row) {
|
||||
$this->error(__('Record not found'));
|
||||
}
|
||||
|
||||
if ($this->request->isPost()) {
|
||||
$data = $this->request->post();
|
||||
if (!$data) {
|
||||
$this->error(__('Parameter %s can not be empty', ['']));
|
||||
}
|
||||
|
||||
$data = $this->excludeFields($data);
|
||||
$data = $this->handleRules($data);
|
||||
|
||||
$result = false;
|
||||
$this->model->startTrans();
|
||||
try {
|
||||
// 模型验证
|
||||
if ($this->modelValidate) {
|
||||
$validate = str_replace("\\model\\", "\\validate\\", get_class($this->model));
|
||||
if (class_exists($validate)) {
|
||||
$validate = new $validate();
|
||||
$validate->scene('edit')->check($data);
|
||||
}
|
||||
}
|
||||
$result = $row->save($data);
|
||||
$this->model->commit();
|
||||
} catch (Throwable $e) {
|
||||
$this->model->rollback();
|
||||
$this->error($e->getMessage());
|
||||
}
|
||||
if ($result !== false) {
|
||||
$this->success(__('Update successful'));
|
||||
} else {
|
||||
$this->error(__('No rows updated'));
|
||||
}
|
||||
}
|
||||
|
||||
// 读取所有pid,全部从节点数组移除,父级选择状态由子级决定
|
||||
$pidArr = UserRule::field('pid')
|
||||
->distinct(true)
|
||||
->where('id', 'in', $row->rules)
|
||||
->select()
|
||||
->toArray();
|
||||
$rules = $row->rules ? explode(',', $row->rules) : [];
|
||||
foreach ($pidArr as $item) {
|
||||
$ruKey = array_search($item['pid'], $rules);
|
||||
if ($ruKey !== false) {
|
||||
unset($rules[$ruKey]);
|
||||
}
|
||||
}
|
||||
$row->rules = array_values($rules);
|
||||
$this->success('', [
|
||||
'row' => $row
|
||||
]);
|
||||
}
|
||||
|
||||
/**
|
||||
* 权限规则入库前处理
|
||||
* @param array $data 接受到的数据
|
||||
* @return array
|
||||
* @throws Throwable
|
||||
*/
|
||||
private function handleRules(array &$data): array
|
||||
{
|
||||
if (is_array($data['rules']) && $data['rules']) {
|
||||
$rules = UserRule::select();
|
||||
$super = true;
|
||||
foreach ($rules as $rule) {
|
||||
if (!in_array($rule['id'], $data['rules'])) {
|
||||
$super = false;
|
||||
}
|
||||
}
|
||||
|
||||
if ($super) {
|
||||
$data['rules'] = '*';
|
||||
} else {
|
||||
$data['rules'] = implode(',', $data['rules']);
|
||||
}
|
||||
} else {
|
||||
unset($data['rules']);
|
||||
}
|
||||
return $data;
|
||||
}
|
||||
}
|
||||
50
app/czg/user/controller/MoneyLogController.php
Normal file
50
app/czg/user/controller/MoneyLogController.php
Normal file
@@ -0,0 +1,50 @@
|
||||
<?php
|
||||
|
||||
namespace app\czg\user\controller;
|
||||
|
||||
use Throwable;
|
||||
use app\admin\model\User;
|
||||
use app\admin\model\UserMoneyLog;
|
||||
use app\common\controller\Backend;
|
||||
|
||||
class MoneyLogController extends Backend
|
||||
{
|
||||
/**
|
||||
* @var object
|
||||
* @phpstan-var UserMoneyLog
|
||||
*/
|
||||
protected object $model;
|
||||
|
||||
protected array $withJoinTable = ['user'];
|
||||
|
||||
// 排除字段
|
||||
protected string|array $preExcludeFields = ['create_time'];
|
||||
|
||||
protected string|array $quickSearchField = ['user.username', 'user.nickname'];
|
||||
|
||||
public function initialize(): void
|
||||
{
|
||||
// parent::initialize();
|
||||
$this->model = new UserMoneyLog();
|
||||
}
|
||||
|
||||
/**
|
||||
* 添加
|
||||
* @param int $userId
|
||||
* @throws Throwable
|
||||
*/
|
||||
public function add(int $userId = 0): void
|
||||
{
|
||||
if ($this->request->isPost()) {
|
||||
parent::add();
|
||||
}
|
||||
|
||||
$user = User::where('id', $userId)->find();
|
||||
if (!$user) {
|
||||
$this->error(__("The user can't find it"));
|
||||
}
|
||||
$this->success('', [
|
||||
'user' => $user
|
||||
]);
|
||||
}
|
||||
}
|
||||
260
app/czg/user/controller/RuleController.php
Normal file
260
app/czg/user/controller/RuleController.php
Normal file
@@ -0,0 +1,260 @@
|
||||
<?php
|
||||
|
||||
namespace app\czg\user\controller;
|
||||
|
||||
use ba\Tree;
|
||||
use Throwable;
|
||||
use app\admin\model\UserRule;
|
||||
use app\admin\model\UserGroup;
|
||||
use app\common\controller\Backend;
|
||||
|
||||
class RuleController extends Backend
|
||||
{
|
||||
/**
|
||||
* @var object
|
||||
* @phpstan-var UserRule
|
||||
*/
|
||||
protected object $model;
|
||||
|
||||
/**
|
||||
* @var Tree
|
||||
*/
|
||||
protected Tree $tree;
|
||||
|
||||
protected string|array $preExcludeFields = ['create_time', 'update_time'];
|
||||
|
||||
protected string|array $defaultSortField = ['weigh' => 'desc'];
|
||||
|
||||
protected string|array $quickSearchField = 'title';
|
||||
|
||||
/**
|
||||
* 远程select初始化传值
|
||||
* @var array
|
||||
*/
|
||||
protected array $initValue;
|
||||
|
||||
/**
|
||||
* 是否组装Tree
|
||||
* @var bool
|
||||
*/
|
||||
protected bool $assembleTree;
|
||||
|
||||
/**
|
||||
* 搜索关键词
|
||||
* @var string
|
||||
*/
|
||||
protected string $keyword;
|
||||
|
||||
public function initialize(): void
|
||||
{
|
||||
// parent::initialize();
|
||||
|
||||
// 防止 URL 中的特殊符号被默认的 filter 函数转义
|
||||
$this->request->filter('clean_xss');
|
||||
|
||||
$this->model = new UserRule();
|
||||
$this->tree = Tree::instance();
|
||||
$isTree = $this->request->param('isTree', true);
|
||||
$this->initValue = $this->request->get("initValue/a", []);
|
||||
$this->initValue = array_filter($this->initValue);
|
||||
$this->keyword = $this->request->request('quickSearch', '');
|
||||
$this->assembleTree = $isTree && !$this->initValue; // 有初始化值时不组装树状(初始化出来的值更好看)
|
||||
}
|
||||
|
||||
public function index(): void
|
||||
{
|
||||
if ($this->request->param('select')) {
|
||||
$this->select();
|
||||
}
|
||||
|
||||
$this->success('', [
|
||||
'list' => $this->getRules(),
|
||||
'remark' => get_route_remark(),
|
||||
]);
|
||||
}
|
||||
|
||||
/**
|
||||
* 添加
|
||||
*/
|
||||
public function add(): void
|
||||
{
|
||||
if ($this->request->isPost()) {
|
||||
$data = $this->request->post();
|
||||
if (!$data) {
|
||||
$this->error(__('Parameter %s can not be empty', ['']));
|
||||
}
|
||||
|
||||
$data = $this->excludeFields($data);
|
||||
if ($this->dataLimit && $this->dataLimitFieldAutoFill) {
|
||||
$data[$this->dataLimitField] = $this->auth->id;
|
||||
}
|
||||
|
||||
$result = false;
|
||||
$this->model->startTrans();
|
||||
try {
|
||||
// 模型验证
|
||||
if ($this->modelValidate) {
|
||||
$validate = str_replace("\\model\\", "\\validate\\", get_class($this->model));
|
||||
if (class_exists($validate)) {
|
||||
$validate = new $validate();
|
||||
if ($this->modelSceneValidate) $validate->scene('add');
|
||||
$validate->check($data);
|
||||
}
|
||||
}
|
||||
$result = $this->model->save($data);
|
||||
|
||||
if (!empty($data['pid'])) {
|
||||
$groups = UserGroup::where('rules', '<>', '*')->select();
|
||||
foreach ($groups as $group) {
|
||||
$rules = explode(',', $group->rules);
|
||||
if (in_array($data['pid'], $rules) && !in_array($this->model->id, $rules)) {
|
||||
$rules[] = $this->model->id;
|
||||
$group->rules = implode(',', $rules);
|
||||
$group->save();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
$this->model->commit();
|
||||
} catch (Throwable $e) {
|
||||
$this->model->rollback();
|
||||
$this->error($e->getMessage());
|
||||
}
|
||||
if ($result !== false) {
|
||||
$this->success(__('Added successfully'));
|
||||
} else {
|
||||
$this->error(__('No rows were added'));
|
||||
}
|
||||
}
|
||||
|
||||
$this->error(__('Parameter error'));
|
||||
}
|
||||
|
||||
/**
|
||||
* 编辑
|
||||
* @throws Throwable
|
||||
*/
|
||||
public function edit(): void
|
||||
{
|
||||
$id = $this->request->param($this->model->getPk());
|
||||
$row = $this->model->find($id);
|
||||
if (!$row) {
|
||||
$this->error(__('Record not found'));
|
||||
}
|
||||
|
||||
$dataLimitAdminIds = $this->getDataLimitAdminIds();
|
||||
if ($dataLimitAdminIds && !in_array($row[$this->dataLimitField], $dataLimitAdminIds)) {
|
||||
$this->error(__('You have no permission'));
|
||||
}
|
||||
|
||||
if ($this->request->isPost()) {
|
||||
$data = $this->request->post();
|
||||
if (!$data) {
|
||||
$this->error(__('Parameter %s can not be empty', ['']));
|
||||
}
|
||||
|
||||
$data = $this->excludeFields($data);
|
||||
$result = false;
|
||||
$this->model->startTrans();
|
||||
try {
|
||||
// 模型验证
|
||||
if ($this->modelValidate) {
|
||||
$validate = str_replace("\\model\\", "\\validate\\", get_class($this->model));
|
||||
if (class_exists($validate)) {
|
||||
$validate = new $validate();
|
||||
if ($this->modelSceneValidate) $validate->scene('edit');
|
||||
$validate->check($data);
|
||||
}
|
||||
}
|
||||
if (isset($data['pid']) && $data['pid'] > 0) {
|
||||
// 满足意图并消除副作用
|
||||
$parent = $this->model->where('id', $data['pid'])->find();
|
||||
if ($parent['pid'] == $row['id']) {
|
||||
$parent->pid = 0;
|
||||
$parent->save();
|
||||
}
|
||||
}
|
||||
$result = $row->save($data);
|
||||
$this->model->commit();
|
||||
} catch (Throwable $e) {
|
||||
$this->model->rollback();
|
||||
$this->error($e->getMessage());
|
||||
}
|
||||
if ($result !== false) {
|
||||
$this->success(__('Update successful'));
|
||||
} else {
|
||||
$this->error(__('No rows updated'));
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
$this->success('', [
|
||||
'row' => $row
|
||||
]);
|
||||
}
|
||||
|
||||
/**
|
||||
* 删除
|
||||
* @throws Throwable
|
||||
*/
|
||||
public function del(): void
|
||||
{
|
||||
$ids = $this->request->param('ids/a', []);
|
||||
|
||||
// 子级元素检查
|
||||
$subData = $this->model->where('pid', 'in', $ids)->column('pid', 'id');
|
||||
foreach ($subData as $key => $subDatum) {
|
||||
if (!in_array($key, $ids)) {
|
||||
$this->error(__('Please delete the child element first, or use batch deletion'));
|
||||
}
|
||||
}
|
||||
|
||||
parent::del();
|
||||
}
|
||||
|
||||
/**
|
||||
* 远程下拉
|
||||
* @throws Throwable
|
||||
*/
|
||||
public function select(): void
|
||||
{
|
||||
$data = $this->getRules([['status', '=', 1]]);
|
||||
|
||||
if ($this->assembleTree) {
|
||||
$data = $this->tree->assembleTree($this->tree->getTreeArray($data, 'title'));
|
||||
}
|
||||
$this->success('', [
|
||||
'options' => $data
|
||||
]);
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取菜单规则
|
||||
* @throws Throwable
|
||||
*/
|
||||
private function getRules(array $where = []): array
|
||||
{
|
||||
$pk = $this->model->getPk();
|
||||
$initKey = $this->request->get("initKey/s", $pk);
|
||||
|
||||
if ($this->keyword) {
|
||||
$keyword = explode(' ', $this->keyword);
|
||||
foreach ($keyword as $item) {
|
||||
$where[] = [$this->quickSearchField, 'like', '%' . $item . '%'];
|
||||
}
|
||||
}
|
||||
|
||||
if ($this->initValue) {
|
||||
$where[] = [$initKey, 'in', $this->initValue];
|
||||
}
|
||||
|
||||
$data = $this->model
|
||||
->where($where)
|
||||
->order($this->queryOrderBuilder())
|
||||
->select()
|
||||
->toArray();
|
||||
|
||||
return $this->assembleTree ? $this->tree->assembleChild($data) : $data;
|
||||
}
|
||||
|
||||
}
|
||||
50
app/czg/user/controller/ScoreLogController.php
Normal file
50
app/czg/user/controller/ScoreLogController.php
Normal file
@@ -0,0 +1,50 @@
|
||||
<?php
|
||||
|
||||
namespace app\czg\user\controller;
|
||||
|
||||
use Throwable;
|
||||
use app\admin\model\User;
|
||||
use app\admin\model\UserScoreLog;
|
||||
use app\common\controller\Backend;
|
||||
|
||||
class ScoreLogController extends Backend
|
||||
{
|
||||
/**
|
||||
* @var object
|
||||
* @phpstan-var UserScoreLog
|
||||
*/
|
||||
protected object $model;
|
||||
|
||||
protected array $withJoinTable = ['user'];
|
||||
|
||||
// 排除字段
|
||||
protected string|array $preExcludeFields = ['create_time'];
|
||||
|
||||
protected string|array $quickSearchField = ['user.username', 'user.nickname'];
|
||||
|
||||
public function initialize(): void
|
||||
{
|
||||
// parent::initialize();
|
||||
$this->model = new UserScoreLog();
|
||||
}
|
||||
|
||||
/**
|
||||
* 添加
|
||||
* @param int $userId
|
||||
* @throws Throwable
|
||||
*/
|
||||
public function add(int $userId = 0): void
|
||||
{
|
||||
if ($this->request->isPost()) {
|
||||
parent::add();
|
||||
}
|
||||
|
||||
$user = User::where('id', $userId)->find();
|
||||
if (!$user) {
|
||||
$this->error(__("The user can't find it"));
|
||||
}
|
||||
$this->success('', [
|
||||
'user' => $user
|
||||
]);
|
||||
}
|
||||
}
|
||||
541
app/czg/user/controller/UserController.php
Normal file
541
app/czg/user/controller/UserController.php
Normal file
@@ -0,0 +1,541 @@
|
||||
<?php
|
||||
|
||||
namespace app\czg\user\controller;
|
||||
|
||||
use app\api\model\TbUser;
|
||||
use app\common\library\DatabaseRoute;
|
||||
use think\facade\Db;
|
||||
use Throwable;
|
||||
use app\common\controller\Backend;
|
||||
use app\admin\model\User as UserModel;
|
||||
|
||||
class UserController extends Backend
|
||||
{
|
||||
/**
|
||||
* @var object
|
||||
* @phpstan-var UserModel
|
||||
*/
|
||||
protected object $model;
|
||||
|
||||
protected array $withJoinTable = ['userGroup'];
|
||||
|
||||
// 排除字段
|
||||
protected string|array $preExcludeFields = ['last_login_time', 'login_failure', 'password', 'salt'];
|
||||
|
||||
protected string|array $quickSearchField = ['username', 'nickname', 'id'];
|
||||
|
||||
protected array $noNeedPermission = [
|
||||
'courseMessage',
|
||||
'userMessage',
|
||||
'selectUserOnLineCount',
|
||||
'homeMessage',
|
||||
'selectUserCountStatisticsByTime',
|
||||
'selectUserList',
|
||||
'updateUserStatusByUserId',
|
||||
'inviteAmount',
|
||||
'selectUserByInvitationCode',
|
||||
'getuserinfo',
|
||||
'deleteUserByUserId',
|
||||
];
|
||||
protected array $noNeedLogin = ['userListExcel'];
|
||||
public function initialize(): void
|
||||
{
|
||||
// $this->model = new UserModel();
|
||||
}
|
||||
|
||||
/**
|
||||
* 查看
|
||||
* @throws Throwable
|
||||
*/
|
||||
public function index(): void
|
||||
{
|
||||
if ($this->request->param('select')) {
|
||||
$this->select();
|
||||
}
|
||||
|
||||
list($where, $alias, $limit, $order) = $this->queryBuilder();
|
||||
$res = $this->model
|
||||
->withoutField('password,salt')
|
||||
->withJoin($this->withJoinTable, $this->withJoinType)
|
||||
->alias($alias)
|
||||
->where($where)
|
||||
->order($order)
|
||||
->paginate($limit);
|
||||
|
||||
$this->success('', [
|
||||
'list' => $res->items(),
|
||||
'total' => $res->total(),
|
||||
'remark' => get_route_remark(),
|
||||
]);
|
||||
}
|
||||
|
||||
/**
|
||||
* 添加
|
||||
* @throws Throwable
|
||||
*/
|
||||
public function add(): void
|
||||
{
|
||||
if ($this->request->isPost()) {
|
||||
$data = $this->request->post();
|
||||
if (!$data) {
|
||||
$this->error(__('Parameter %s can not be empty', ['']));
|
||||
}
|
||||
|
||||
$result = false;
|
||||
$passwd = $data['password']; // 密码将被排除不直接入库
|
||||
$data = $this->excludeFields($data);
|
||||
|
||||
$this->model->startTrans();
|
||||
try {
|
||||
// 模型验证
|
||||
if ($this->modelValidate) {
|
||||
$validate = str_replace("\\model\\", "\\validate\\", get_class($this->model));
|
||||
if (class_exists($validate)) {
|
||||
$validate = new $validate();
|
||||
if ($this->modelSceneValidate) $validate->scene('add');
|
||||
$validate->check($data);
|
||||
}
|
||||
}
|
||||
$result = $this->model->save($data);
|
||||
$this->model->commit();
|
||||
|
||||
if (!empty($passwd)) {
|
||||
$this->model->resetPassword($this->model->id, $passwd);
|
||||
}
|
||||
} catch (Throwable $e) {
|
||||
$this->model->rollback();
|
||||
$this->error($e->getMessage());
|
||||
}
|
||||
if ($result !== false) {
|
||||
$this->success(__('Added successfully'));
|
||||
} else {
|
||||
$this->error(__('No rows were added'));
|
||||
}
|
||||
}
|
||||
|
||||
$this->error(__('Parameter error'));
|
||||
}
|
||||
|
||||
/**
|
||||
* 编辑
|
||||
* @throws Throwable
|
||||
*/
|
||||
public function edit(): void
|
||||
{
|
||||
$pk = $this->model->getPk();
|
||||
$id = $this->request->param($pk);
|
||||
$row = $this->model->find($id);
|
||||
if (!$row) {
|
||||
$this->error(__('Record not found'));
|
||||
}
|
||||
|
||||
if ($this->request->isPost()) {
|
||||
$password = $this->request->post('password', '');
|
||||
if ($password) {
|
||||
$this->model->resetPassword($id, $password);
|
||||
}
|
||||
parent::edit();
|
||||
}
|
||||
|
||||
unset($row->salt);
|
||||
$row->password = '';
|
||||
$this->success('', [
|
||||
'row' => $row
|
||||
]);
|
||||
}
|
||||
|
||||
/**
|
||||
* 重写select
|
||||
* @throws Throwable
|
||||
*/
|
||||
public function select(): void
|
||||
{
|
||||
list($where, $alias, $limit, $order) = $this->queryBuilder();
|
||||
$res = $this->model
|
||||
->withoutField('password,salt')
|
||||
->withJoin($this->withJoinTable, $this->withJoinType)
|
||||
->alias($alias)
|
||||
->where($where)
|
||||
->order($order)
|
||||
->paginate($limit);
|
||||
|
||||
foreach ($res as $re) {
|
||||
$re->nickname_text = $re->username . '(ID:' . $re->id . ')';
|
||||
}
|
||||
|
||||
$this->success('', [
|
||||
'list' => $res->items(),
|
||||
'total' => $res->total(),
|
||||
'remark' => get_route_remark(),
|
||||
]);
|
||||
}
|
||||
|
||||
// 短剧分析
|
||||
public function courseMessage()
|
||||
{
|
||||
$get = $this->request->get();
|
||||
$admin = $this->auth->getAdmin();
|
||||
$pageUtils = \app\admin\model\User::queryCourseOrder($get['page'], $get['limit'], $get['type'], completeStartTime($get['date']), $admin['user_id']);
|
||||
$this->n_success(['data' => $pageUtils]);
|
||||
}
|
||||
|
||||
// 用户分析
|
||||
public function userMessage()
|
||||
{
|
||||
$get = $this->request->get();
|
||||
$admin = $this->auth->getAdmin();
|
||||
// 补全开始时间(调用之前实现的函数)
|
||||
$date = completeStartTime($get['date']); // 假设已实现该函数
|
||||
$qdCode = $admin['qd_code'];
|
||||
$sumUserCount = \app\admin\model\User::queryUserCount($get['type'], $date, null, $qdCode);
|
||||
$h5Count = \app\admin\model\User::queryUserCount($get['type'], $date, "h5", $qdCode);
|
||||
$appCount = \app\admin\model\User::queryUserCount($get['type'], $date, "app", $qdCode);
|
||||
$wxCount = \app\admin\model\User::queryUserCount($get['type'], $date, "小程序", $qdCode);
|
||||
$dyCount = \app\admin\model\User::queryUserCount($get['type'], $date, "抖音", $qdCode);
|
||||
$giveMemberCount = \app\admin\model\User::userMessage($date, $get['type'], $qdCode, 1);
|
||||
$moneyMemberCount = \app\admin\model\User::userMessage($date, $get['type'], $qdCode, 2);
|
||||
$memberCount = \app\admin\model\User::userMessage($date, $get['type'], $qdCode, null);
|
||||
$userCount = $sumUserCount - $memberCount;
|
||||
$this->n_success(['data' => [
|
||||
'sumUserCount' => $sumUserCount,
|
||||
'h5Count' => $h5Count,
|
||||
'appCount' => $appCount,
|
||||
'wxCount' => $wxCount,
|
||||
'dyCount' => $dyCount,
|
||||
'memberCount' => $memberCount,
|
||||
'giveMemberCount' => $giveMemberCount,
|
||||
'moneyMemberCount' => $moneyMemberCount,
|
||||
'userCount' => $userCount,
|
||||
]]);
|
||||
}
|
||||
|
||||
// 当前在线人数统计
|
||||
public function selectUserOnLineCount()
|
||||
{
|
||||
$admin = $this->auth->getAdmin();
|
||||
$qdCode = $admin['qd_code'];
|
||||
$selectUserOnLineCount = DatabaseRoute::getAllDbData('tb_user', function($query)use($qdCode) {
|
||||
if($query) {
|
||||
$query->where(['qd_code' => $qdCode]);
|
||||
}
|
||||
return $query->where('on_line_time', '>=', Db::raw('DATE_SUB(NOW(), INTERVAL 10 MINUTE)'));
|
||||
})->count();
|
||||
$this->n_success(['data' => $selectUserOnLineCount]);
|
||||
}
|
||||
|
||||
// 用户统计
|
||||
public function homeMessage()
|
||||
{
|
||||
$admin = $this->auth->getAdmin();
|
||||
$qdCode = $admin['qd_code'];
|
||||
$data = [];
|
||||
$data['totalUsers'] = \app\admin\model\User::queryUserCount(0, null, null, $qdCode);
|
||||
$data['newToday'] = \app\admin\model\User::queryUserCount(1, null, null, $qdCode);
|
||||
$data['newMonth'] = \app\admin\model\User::queryUserCount(2, null, null, $qdCode);
|
||||
$data['newYear'] = \app\admin\model\User::queryUserCount(3, null, null, $qdCode);
|
||||
$data['totalRevenue'] = \app\admin\model\User::queryPayMoney(0, $qdCode);
|
||||
$data['todayRevenue'] = \app\admin\model\User::queryPayMoney(1, $qdCode);
|
||||
$data['monthRevenue'] = \app\admin\model\User::queryPayMoney(2, $qdCode);
|
||||
$data['yearRevenue'] = \app\admin\model\User::queryPayMoney(3, $qdCode);
|
||||
$map = \app\admin\model\User::queryPayAndExtractInfo();
|
||||
$data['todayPayAmount'] = isset($map['payAmount'])
|
||||
? round((float)$map['payAmount'], 2, PHP_ROUND_HALF_UP)
|
||||
: 0.00;
|
||||
$data['todayPayCount'] = isset($map['payCount'])
|
||||
? (int)$map['payCount']
|
||||
: 0;
|
||||
$data['todayExtractAmount'] = isset($map['extractAmount'])
|
||||
? round((float)$map['extractAmount'], 2, PHP_ROUND_HALF_UP)
|
||||
: 0.00;
|
||||
|
||||
$data['todayExtractCount'] = isset($map['extractCount'])
|
||||
? (int)$map['extractCount']
|
||||
: 0;
|
||||
$this->n_success(['data' => $data]);
|
||||
}
|
||||
|
||||
// 用户增长折线图
|
||||
public function selectUserCountStatisticsByTime()
|
||||
{
|
||||
$get = $this->request->get();
|
||||
$startTime = $get['startTime'];
|
||||
$endTime = $get['endTime'];
|
||||
|
||||
// 初始化结果数组
|
||||
$userCountList = [];
|
||||
$dateList = [];
|
||||
|
||||
// 日期处理
|
||||
$currentDate = strtotime($startTime);
|
||||
$endDate = strtotime($endTime);
|
||||
|
||||
// 循环遍历日期范围
|
||||
while ($currentDate <= $endDate) {
|
||||
$date = date('Y-m-d', $currentDate);
|
||||
|
||||
// 查询当日用户注册数量
|
||||
$userCount = \app\admin\model\User::queryUserCount(1, $date, null, null);
|
||||
|
||||
// 记录数据
|
||||
$userCountList[] = $userCount;
|
||||
$dateList[] = $date;
|
||||
|
||||
// 日期加1天
|
||||
$currentDate = strtotime('+1 day', $currentDate);
|
||||
}
|
||||
|
||||
// 构建结果数据
|
||||
$result = [
|
||||
'userCountList' => $userCountList,
|
||||
'year' => $dateList // 注:原Java代码中使用year变量,但实际存储的是日期列表
|
||||
];
|
||||
|
||||
$this->n_success(['data' => $result]);
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
// 查询所有用户列表
|
||||
public function selectUserList()
|
||||
{
|
||||
$params = $this->request->get();
|
||||
$vipType = $params['vipType'] ?? null;
|
||||
$member = $params['member'] ?? null;
|
||||
$status = $params['status'] ?? null;
|
||||
$page = $params['page'] ?? null;
|
||||
$limit = $params['limit'] ?? null;
|
||||
$phone = $params['phone'] ?? null;
|
||||
$sysUserName = $params['sysUserName'] ?? null;
|
||||
$userName = $params['userName'] ?? null;
|
||||
$sex = $params['sex'] ?? null;
|
||||
$platform = $params['platform'] ?? null;
|
||||
$sysPhone = $params['sysPhone'] ?? null;
|
||||
$inviterCode = $params['inviterCode'] ?? null;
|
||||
$invitationCode = $params['invitationCode'] ?? null;
|
||||
$qdCode = $params['qdCode'] ?? null;
|
||||
$startTime = $params['startTime'] ?? null;
|
||||
$endTime = $params['endTime'] ?? null;
|
||||
$delegate = $params['delegate'] ?? null;
|
||||
$this->n_success(['data' => \app\admin\model\User::selectUserPage(
|
||||
$page, $limit, $phone, $sex, $platform, $sysPhone, $status, $member,
|
||||
$inviterCode, $userName, $invitationCode, $startTime, $endTime, $qdCode, $sysUserName, $vipType, $delegate
|
||||
)]);
|
||||
}
|
||||
|
||||
// 修改用户状态
|
||||
public function updateUserStatusByUserId()
|
||||
{
|
||||
$get = $this->request->get();
|
||||
if(empty($get['userId'])) {
|
||||
$this->error('userId 不能为空');
|
||||
}
|
||||
if(empty($get['status']) && $get['status'] == null) {
|
||||
$this->error('status 不能为空');
|
||||
}
|
||||
$status = $get['status'];
|
||||
$userId = $get['userId'];
|
||||
$db = Db::connect(DatabaseRoute::getConnection('tb_user', ['user_id' => $userId], true));
|
||||
// 查询用户是否存在
|
||||
$user = $db->name('tb_user')->where(['user_id' => $userId])->find();
|
||||
if (is_null($user)) {
|
||||
$this->error('用户不存在');
|
||||
}
|
||||
|
||||
// 根据状态执行不同操作
|
||||
switch ($status) {
|
||||
case 1:
|
||||
// 状态1:设置状态为1,并调用upUserBlack方法(拉黑)
|
||||
\app\admin\model\User::upUserBlack($user, 1, $db);
|
||||
break;
|
||||
case 2:
|
||||
// 状态2:直接更新状态为2
|
||||
$db->name('tb_user')->where('user_id', $userId)
|
||||
->update(['status' => 2]);
|
||||
break;
|
||||
case 0:
|
||||
// 状态0:调用upUserBlack方法(解封)
|
||||
\app\admin\model\User::upUserBlack($user, 0, $db);
|
||||
break;
|
||||
default:
|
||||
// 无效状态
|
||||
$this->error('状态不正确');
|
||||
}
|
||||
$this->success();
|
||||
}
|
||||
|
||||
|
||||
// 更新用户邀请奖励金额
|
||||
public function inviteAmount()
|
||||
{
|
||||
$userInviteDTO = $this->request->post();
|
||||
// 验证用户ID不能为空
|
||||
if (empty($userInviteDTO['userId'])) {
|
||||
$this->error('用户id不能为空');
|
||||
}
|
||||
|
||||
// 验证邀请奖励金额必须大于0
|
||||
$inviteAmount = $userInviteDTO['inviteAmount'] ?? null;
|
||||
if (is_null($inviteAmount) || bccomp($inviteAmount, 0) <= 0) {
|
||||
$this->error('邀请奖励金额必须大于0');
|
||||
}
|
||||
|
||||
$db = Db::connect(DatabaseRoute::getConnection('tb_user', ['user_id' => $userInviteDTO['userId']], true))->name('tb_user');
|
||||
// 查询用户是否存在
|
||||
$userEntity = $db->where(['user_id' => $userInviteDTO['userId']])->find($userInviteDTO['userId']);
|
||||
if (is_null($userEntity)) {
|
||||
$this->error('用户不存在');
|
||||
}
|
||||
// 更新用户邀请奖励金额
|
||||
$db->where(['user_id' => $userInviteDTO['userId']])->update(['invite_amount' => $inviteAmount]);
|
||||
$this->success();
|
||||
}
|
||||
|
||||
|
||||
public function updatePwd()
|
||||
{
|
||||
$get = $this->request->get();
|
||||
if(empty($get['userId']) || empty($get['pwd'])) {
|
||||
$this->error('参数不完整');
|
||||
}
|
||||
$userId = $get['userId'];
|
||||
$pwd = $get['pwd'];
|
||||
$db = Db::connect(DatabaseRoute::getConnection('sys_user', ['user_id' => $userId]));
|
||||
$user = $db->name('sys_user')->where(['user_id' => $userId])->find();
|
||||
if(!$user) {
|
||||
$this->error('用户不存在');
|
||||
}
|
||||
$db = Db::connect(DatabaseRoute::getConnection('sys_user', ['user_id' => $userId], true));
|
||||
$user = $db->name('sys_user')->where(['user_id' => $userId])->update(['password' => shiro_simple_hash_hex_salt('sha256', $pwd, $user['salt'])]);
|
||||
if($user) {
|
||||
$this->success();
|
||||
}
|
||||
$this->error();
|
||||
}
|
||||
|
||||
public function deleteUserByUserId()
|
||||
{
|
||||
$post = $this->request->post();
|
||||
if(empty($post['userId'])) {
|
||||
$this->error('userId 不能为空');
|
||||
}
|
||||
$userId = $post['userId'];
|
||||
$db = Db::connect(DatabaseRoute::getConnection('tb_user', ['user_id' => $userId], true));
|
||||
$user = $db->name('tb_user')->where(['user_id' => $userId])->delete();
|
||||
if($user) {
|
||||
$this->success();
|
||||
}
|
||||
$this->error('操作失败');
|
||||
}
|
||||
|
||||
|
||||
public function getuserinfo()
|
||||
{
|
||||
$userId = $this->request->get('userId');
|
||||
if(empty($userId)) {
|
||||
$this->error('userId 不能为空');
|
||||
}
|
||||
|
||||
$db = Db::connect(DatabaseRoute::getConnection('tb_user', ['user_id' => $userId]));
|
||||
$user = $db->name('tb_user')->where(['user_id' => $userId])->find();
|
||||
if(!$user) {
|
||||
$this->error('用户不存在');
|
||||
}
|
||||
|
||||
$inviteMoney = \app\admin\model\User::selectInviteMoneyByUserId($userId, $db);
|
||||
if(empty($inviteMoney)) {
|
||||
$inviteMoney = [
|
||||
'user_id' => $userId,
|
||||
'money_sum' => 0.00,
|
||||
'money' => 0.00,
|
||||
'cash_out' => 0.00,
|
||||
];
|
||||
Db::connect(DatabaseRoute::getConnection('invite_money', ['user_id' => $userId], true), true)->name('invite_money')->insert($inviteMoney);
|
||||
}
|
||||
$money = $inviteMoney['money'];
|
||||
|
||||
// 获取当前日期(格式:YYYY-MM-DD HH:mm:ss)
|
||||
$date = date('Y-m-d H:i:s');
|
||||
|
||||
// 查询本月充值(复用之前的instantselectSumPay方法)
|
||||
$consume = \app\admin\model\User::instantselectSumPay(date('Y-m'), $userId, $db);
|
||||
|
||||
// 查询本月提现(假设monthIncome方法已实现)
|
||||
$income = \app\admin\model\User::monthIncome(date('Y-m'), $userId, $db);
|
||||
|
||||
// 查询邀请人数(复用之前的countUsersByInviterCode方法)
|
||||
$count = \app\admin\model\User::queryInviterCount($user['invitation_code']);
|
||||
|
||||
// 查询VIP信息
|
||||
$userVip = \app\admin\model\User::selectUserVipByUserId($userId);
|
||||
if ($userVip) {
|
||||
$user['member'] = $userVip['is_vip'];
|
||||
$user['end_time'] = $userVip['end_time'];
|
||||
$user['vip_type'] = $userVip['vip_type'];
|
||||
}
|
||||
|
||||
// 组装结果数据
|
||||
$resultData = [
|
||||
'userEntity' => $user,
|
||||
'money' => $money,
|
||||
'consume' => $consume,
|
||||
'income' => $income,
|
||||
'count' => $count
|
||||
];
|
||||
$this->n_success(['data' => $resultData]);
|
||||
|
||||
}
|
||||
|
||||
public function userListExcel()
|
||||
{
|
||||
$get = $this->request->get();
|
||||
$startTime = $get['startTime'] ?? null;
|
||||
$endTime = $get['endTime'] ?? null;
|
||||
$this->n_success(\app\admin\model\User::userListExcel($startTime, $endTime));
|
||||
}
|
||||
|
||||
|
||||
|
||||
// 获取用户详细信息
|
||||
public function selectUserByInvitationCode()
|
||||
{
|
||||
$get = $this->request->get();
|
||||
if(empty($get['invitationCode'])) {
|
||||
$this->error('参数不完整');
|
||||
}
|
||||
$invitationCode = $get['invitationCode'];
|
||||
$userEntity = TbUser::GetByusername($invitationCode, 'invitation_code');
|
||||
if(empty($userEntity)) {
|
||||
$this->error('用户信息不存在');
|
||||
}
|
||||
$userId = $userEntity['user_id'];
|
||||
|
||||
$db = Db::connect(DatabaseRoute::getConnection('invite_money', ['user_id' => $userId]));
|
||||
// 查询用户钱包
|
||||
$inviteMoney = \app\admin\model\User::selectInviteMoneyByUserId($userId, $db);
|
||||
$money = $inviteMoney['money'];
|
||||
// 获取当前时间(格式:Y-m-d H:i:s)
|
||||
$currentDate = date('Y-m-d H:i:s');
|
||||
// 查询本月充值总额
|
||||
$consume = \app\admin\model\User::instantselectSumPay($currentDate, $userId, $db);
|
||||
$income = \app\admin\model\User::monthIncome($currentDate, $userId, $db);
|
||||
//查询邀请人数
|
||||
$count = \app\admin\model\User::queryInviterCount($userEntity['invitation_code']);
|
||||
$userVip = \app\admin\model\User::selectUserVipByUserId($userId);
|
||||
if ($userVip) {
|
||||
$userEntity['member'] = $userVip['is_vip'];
|
||||
$userEntity['end_time'] = $userVip['end_time'];
|
||||
$userEntity['vip_type'] = $userVip['vip_type'];
|
||||
}
|
||||
$data = [
|
||||
'userEntity' => $userEntity,
|
||||
'money' => $money,
|
||||
'consume' => $consume,
|
||||
'income' => $income,
|
||||
'count' => $count
|
||||
];
|
||||
$this->n_success(['data' => $data]);
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user