|
|
@@ -0,0 +1,1691 @@
|
|
|
+<?php
|
|
|
+namespace app\controller;
|
|
|
+
|
|
|
+
|
|
|
+use app\AdminBaseController;
|
|
|
+use think\facade\Db;
|
|
|
+use phpu\facade\ThinkCaptcha;
|
|
|
+use Ramsey\Uuid\Uuid;
|
|
|
+
|
|
|
+
|
|
|
+//后台控制器
|
|
|
+class Admin extends AdminBaseController
|
|
|
+{
|
|
|
+ protected $noNeedLogin = ['login', 'logout', 'getAdminCaptchaImage'];
|
|
|
+
|
|
|
+ //获取管理员登录验证码图片
|
|
|
+ public function getAdminCaptchaImage()
|
|
|
+ {
|
|
|
+ return ThinkCaptcha::printImg('admin');
|
|
|
+ }
|
|
|
+
|
|
|
+ //登录
|
|
|
+ public function login()
|
|
|
+ {
|
|
|
+ $username = $this->request->post('username');
|
|
|
+ $password = $this->request->post('password');
|
|
|
+ //$captcha = $this->request->post('captcha');
|
|
|
+ if (empty($username) || empty($password)) {
|
|
|
+ $this->fail(500, '参数校验错误');
|
|
|
+ }
|
|
|
+ //if (!ThinkCaptcha::check($captcha, 'admin', 2)) {
|
|
|
+ // $this->fail(501, '验证码错误');
|
|
|
+ //}
|
|
|
+ $admin = Db::table('tb_admin')
|
|
|
+ ->where(['username' => $username])
|
|
|
+ ->where(['password' => md5($password)])
|
|
|
+ ->find();
|
|
|
+ if (!$admin) {
|
|
|
+ $this->fail(502, '管理员用户名或密码错误');
|
|
|
+ }
|
|
|
+ //写登录日志
|
|
|
+ Db::table('tb_admin_login_log')
|
|
|
+ ->insert([
|
|
|
+ 'user_id' => $admin['id'],
|
|
|
+ 'ip' => $this->request->ip(),
|
|
|
+ 'user_agent' => $this->request->header('user-agent'),
|
|
|
+ 'created_at' => time(),
|
|
|
+ ]);
|
|
|
+ //写登录Token
|
|
|
+ $token = Uuid::uuid4()->toString();
|
|
|
+ Db::table('tb_admin_token')
|
|
|
+ ->insert([
|
|
|
+ 'user_id' => $admin['id'],
|
|
|
+ 'token' => $token,
|
|
|
+ 'expired_at' => time() + 24 * 60 * 60,
|
|
|
+ ]);
|
|
|
+ $this->success('success', [
|
|
|
+ 'token' => $token,
|
|
|
+ ]);
|
|
|
+ }
|
|
|
+
|
|
|
+ //退出登录
|
|
|
+ public function logout()
|
|
|
+ {
|
|
|
+ $token = $this->request->post('token');
|
|
|
+ if (empty($token)) {
|
|
|
+ $this->fail(500, 'token参数校验错误');
|
|
|
+ }
|
|
|
+ Db::table('tb_admin_token')
|
|
|
+ ->where(['token' => $token])
|
|
|
+ ->delete();
|
|
|
+ $this->success('success', null);
|
|
|
+ }
|
|
|
+
|
|
|
+ //修改密码,修改后前端需要跳到登录页重新登录
|
|
|
+ public function changePwd()
|
|
|
+ {
|
|
|
+ $oldPassword = $this->request->post('oldPassword');
|
|
|
+ $newPassword = $this->request->post('newPassword');
|
|
|
+ if (empty($oldPassword) || empty($newPassword)) {
|
|
|
+ $this->fail(500, '参数校验错误');
|
|
|
+ }
|
|
|
+ $user = $this->getUser();
|
|
|
+ $data = Db::table('tb_user')
|
|
|
+ ->where(['id' => $user->user_id])
|
|
|
+ ->find();
|
|
|
+ if ($data['password'] != md5($oldPassword)) {
|
|
|
+ $this->fail(501, '当前密码错误');
|
|
|
+ }
|
|
|
+ Db::table('tb_user')
|
|
|
+ ->where(['id' => $user->user_id])
|
|
|
+ ->update([
|
|
|
+ 'password' => md5($newPassword),
|
|
|
+ ]);
|
|
|
+ //释放token
|
|
|
+ Db::table('tb_user_token')
|
|
|
+ ->where(['token' => $user->token])
|
|
|
+ ->delete();
|
|
|
+ $this->success('success', null);
|
|
|
+ }
|
|
|
+
|
|
|
+ //获取控制台数据
|
|
|
+ public function getConsoleData()
|
|
|
+ {
|
|
|
+ $userCount = Db::table('tb_user')->count();
|
|
|
+ $todayUserCount = Db::table('tb_user')
|
|
|
+ ->where('created_at', '>', strtotime(date('Y-m-d') . ' 00:00:00'))
|
|
|
+ ->count();
|
|
|
+ $totalWebsitePay = Db::table('tb_user_order')
|
|
|
+ ->where(['state' => 1])
|
|
|
+ ->sum('balance');
|
|
|
+ $todayWebsitePay = Db::table('tb_user_order')
|
|
|
+ ->where(['state' => 1])
|
|
|
+ ->where('created_at', '>', strtotime(date('Y-m-d') . ' 00:00:00'))
|
|
|
+ ->sum('balance');
|
|
|
+ $totalTaobaoPay = Db::table('tb_user_game')
|
|
|
+ ->where(['channel' => 2])
|
|
|
+ ->sum('price');
|
|
|
+ $todayTaobaoPay = Db::table('tb_user_game')
|
|
|
+ ->where(['channel' => 2])
|
|
|
+ ->where('created_at', '>', strtotime(date('Y-m-d') . ' 00:00:00'))
|
|
|
+ ->sum('price');
|
|
|
+ $totalPddPay = Db::table('tb_user_game')
|
|
|
+ ->where(['channel' => 3])
|
|
|
+ ->sum('price');
|
|
|
+ $todayPddPay = Db::table('tb_user_game')
|
|
|
+ ->where(['channel' => 3])
|
|
|
+ ->where('created_at', '>', strtotime(date('Y-m-d') . ' 00:00:00'))
|
|
|
+ ->sum('price');
|
|
|
+ $this->success('success', [
|
|
|
+ //用户数据
|
|
|
+ 'userData' => [
|
|
|
+ 'totalUserCount' => $userCount, //总会员数
|
|
|
+ 'todayUserCount' => $todayUserCount, //今日新增会员数
|
|
|
+ ],
|
|
|
+ //网站消费数据
|
|
|
+ 'websitePayData' => [
|
|
|
+ 'totalPay' => number_format(floatval($totalWebsitePay), 2), //网站总直充
|
|
|
+ 'todayPay' => number_format(floatval($todayWebsitePay), 2), //今日网站直充
|
|
|
+ ],
|
|
|
+ //淘宝平台消费数据
|
|
|
+ 'taobaoPayData' => [
|
|
|
+ 'totalPay' => number_format(floatval($totalTaobaoPay), 2), //淘宝平台总消费
|
|
|
+ 'todayPay' => number_format(floatval($todayTaobaoPay), 2), //淘宝平台今日消费
|
|
|
+ ],
|
|
|
+ //拼多多平台消费数据
|
|
|
+ 'pddPayData' => [
|
|
|
+ 'totalPay' => number_format(floatval($totalPddPay), 2), //拼多多平台总消费
|
|
|
+ 'todayPay' => number_format(floatval($todayPddPay), 2), //拼多多平台今日消费
|
|
|
+ ],
|
|
|
+ ]);
|
|
|
+ }
|
|
|
+
|
|
|
+ //获取用户数据
|
|
|
+ public function getUserList()
|
|
|
+ {
|
|
|
+ // 获取分页参数,确保有默认值
|
|
|
+ $pageSize = $this->request->post('pageSize', 10); // 每页显示的数据数量
|
|
|
+ $pageNum = $this->request->post('pageNum', 1); // 当前页码
|
|
|
+
|
|
|
+ // 参数校验
|
|
|
+ if (!is_numeric($pageSize) || !is_numeric($pageNum)) {
|
|
|
+ $this->fail(500, '分页参数校验错误');
|
|
|
+ }
|
|
|
+
|
|
|
+ // 转换为整数
|
|
|
+ $pageSize = intval($pageSize);
|
|
|
+ $pageNum = intval($pageNum);
|
|
|
+
|
|
|
+ // 确保最小值
|
|
|
+ $pageSize = max(1, $pageSize);
|
|
|
+ $pageNum = max(1, $pageNum);
|
|
|
+
|
|
|
+ // 获取搜索参数
|
|
|
+ $keyword = $this->request->post('keyword', '');
|
|
|
+ $startDate = $this->request->post('startDate', '');
|
|
|
+ $endDate = $this->request->post('endDate', '');
|
|
|
+
|
|
|
+ // 构建查询
|
|
|
+ $query = Db::table('tb_user')
|
|
|
+ ->field('id,username,created_at,last_login,login_count,last_login_ip,avatar,balance,email,state');
|
|
|
+
|
|
|
+ // 添加搜索条件
|
|
|
+ if (!empty($keyword)) {
|
|
|
+ $query->where(function($q) use ($keyword) {
|
|
|
+ $q->where('username', 'like', "%{$keyword}%")
|
|
|
+ ->whereOr('id', '=', $keyword)
|
|
|
+ ->whereOr('email', 'like', "%{$keyword}%");
|
|
|
+ });
|
|
|
+ }
|
|
|
+
|
|
|
+ // 添加日期范围条件
|
|
|
+ if (!empty($startDate)) {
|
|
|
+ $query->where('created_at', '>=', $startDate . ' 00:00:00');
|
|
|
+ }
|
|
|
+ if (!empty($endDate)) {
|
|
|
+ $query->where('created_at', '<=', $endDate . ' 23:59:59');
|
|
|
+ }
|
|
|
+
|
|
|
+ // 排序
|
|
|
+ $query->order('created_at', 'DESC');
|
|
|
+
|
|
|
+ // 分页查询
|
|
|
+ $paginator = $query->paginate([
|
|
|
+ 'list_rows' => $pageSize,
|
|
|
+ 'page' => $pageNum,
|
|
|
+ 'path' => '' // 保持URL简洁
|
|
|
+ ]);
|
|
|
+
|
|
|
+ // 处理头像数据
|
|
|
+ $users = $paginator->getCollection()->each(function($user) {
|
|
|
+ if (str_starts_with($user['avatar'], 'system://')) {
|
|
|
+ $data = explode('//', $user['avatar']);
|
|
|
+ $avatarId = intval($data[1]);
|
|
|
+ $avatar = Db::table('tb_system_avatar')
|
|
|
+ ->where(['id' => $avatarId])
|
|
|
+ ->find();
|
|
|
+ $user['avatar'] = $avatar['image_url'] ?? '';
|
|
|
+ }
|
|
|
+ return $user;
|
|
|
+ });
|
|
|
+
|
|
|
+ // 返回分页数据
|
|
|
+ $this->success('success', [
|
|
|
+ 'data' => $users,
|
|
|
+ 'total' => $paginator->total(),
|
|
|
+ 'current_page' => $paginator->currentPage(),
|
|
|
+ 'per_page' => $paginator->listRows(),
|
|
|
+ 'last_page' => $paginator->lastPage(),
|
|
|
+ ]);
|
|
|
+ }
|
|
|
+
|
|
|
+ //用户封号或解封
|
|
|
+ public function banUser()
|
|
|
+ {
|
|
|
+ $userId = $this->request->post('userId'); //用户ID
|
|
|
+ $state = $this->request->post('state'); //状态 1:设置为封号 0:设置为解封
|
|
|
+ if (!is_numeric($userId) || !is_numeric($state)) {
|
|
|
+ $this->fail(500, '参数校验错误');
|
|
|
+ }
|
|
|
+ $user = Db::table('tb_user')
|
|
|
+ ->where(['id' => $userId])
|
|
|
+ ->find();
|
|
|
+ if (!$user) {
|
|
|
+ $this->fail(501, 'userId不存在');
|
|
|
+ }
|
|
|
+ if (intval($state) == 0) {
|
|
|
+ $state = 1;
|
|
|
+ } else {
|
|
|
+ $state = 2;
|
|
|
+ }
|
|
|
+ Db::table('tb_user')
|
|
|
+ ->where(['id' => $userId])
|
|
|
+ ->update(['state' => $state]);
|
|
|
+ $this->success('success', null);
|
|
|
+ }
|
|
|
+
|
|
|
+ //新增游戏分类
|
|
|
+ public function addGameCategory()
|
|
|
+ {
|
|
|
+ $name = $this->request->post('name');
|
|
|
+ $imageUrl = $this->request->post('imageUrl');
|
|
|
+ $description = $this->request->post('description');
|
|
|
+ $priority = $this->request->post('priority');
|
|
|
+ if (empty($name) || empty($imageUrl) || empty($description) || !is_numeric($priority)) {
|
|
|
+ $this->fail(500, '参数校验错误');
|
|
|
+ }
|
|
|
+ Db::table('tb_game_category')
|
|
|
+ ->insert([
|
|
|
+ 'name' => $name,
|
|
|
+ 'image_url' => $imageUrl,
|
|
|
+ 'description' => $description,
|
|
|
+ 'priority' => $priority,
|
|
|
+ 'created_at' => time(),
|
|
|
+ 'updated_at' => time(),
|
|
|
+ ]);
|
|
|
+ $this->success('success', null);
|
|
|
+ }
|
|
|
+
|
|
|
+ //获取游戏分类,无需分类
|
|
|
+ public function getGameCategory()
|
|
|
+ {
|
|
|
+ $data = Db::table('tb_game_category')
|
|
|
+ ->order('priority DESC')
|
|
|
+ ->select();
|
|
|
+ $this->success('success', $data);
|
|
|
+ }
|
|
|
+
|
|
|
+ //编辑游戏分类
|
|
|
+ public function editGameCategory()
|
|
|
+ {
|
|
|
+ $categoryId = $this->request->post('categoryId');
|
|
|
+ $name = $this->request->post('name');
|
|
|
+ $imageUrl = $this->request->post('imageUrl');
|
|
|
+ $description = $this->request->post('description');
|
|
|
+ $priority = $this->request->post('priority');
|
|
|
+ if (empty($name) || empty($imageUrl) || empty($description) || !is_numeric($priority) || !is_numeric($categoryId)) {
|
|
|
+ $this->fail(500, '参数校验错误');
|
|
|
+ }
|
|
|
+ Db::table('tb_game_category')
|
|
|
+ ->where(['id' => $categoryId])
|
|
|
+ ->update([
|
|
|
+ 'name' => $name,
|
|
|
+ 'image_url' => $imageUrl,
|
|
|
+ 'description' => $description,
|
|
|
+ 'priority' => $priority,
|
|
|
+ 'updated_at' => time(),
|
|
|
+ ]);
|
|
|
+ $this->success('success', null);
|
|
|
+ }
|
|
|
+
|
|
|
+ //删除游戏分类
|
|
|
+ public function removeGameCategory()
|
|
|
+ {
|
|
|
+ $categoryId = $this->request->post('categoryId');
|
|
|
+ if (!is_numeric($categoryId)) {
|
|
|
+ $this->fail(500, 'categoryId参数校验错误');
|
|
|
+ }
|
|
|
+ $data = Db::table('tb_game_category')
|
|
|
+ ->where(['id' => $categoryId])
|
|
|
+ ->find();
|
|
|
+ if (!$data) {
|
|
|
+ $this->fail(501, 'categoryId不存在');
|
|
|
+ }
|
|
|
+ Db::table('tb_game_category')
|
|
|
+ ->where(['id' => $categoryId])
|
|
|
+ ->delete();
|
|
|
+ $this->success('success', null);
|
|
|
+ }
|
|
|
+
|
|
|
+ public function getGameList()
|
|
|
+ {
|
|
|
+ $categoryId = $this->request->post('categoryId'); // 游戏分类ID
|
|
|
+ $pageNum = $this->request->post('pageNum'); // 当前页码
|
|
|
+ $pageSize = $this->request->post('pageSize'); // 每页数量
|
|
|
+
|
|
|
+ if (!is_numeric($categoryId) || !is_numeric($pageNum) || !is_numeric($pageSize)) {
|
|
|
+ $this->fail(500, '参数校验错误');
|
|
|
+ }
|
|
|
+
|
|
|
+ $query = Db::table('tb_game')->where(['category' => $categoryId]);
|
|
|
+
|
|
|
+ // 获取总数
|
|
|
+ $total = $query->count();
|
|
|
+
|
|
|
+ // 获取分页数据
|
|
|
+ $list = $query->page(intval($pageNum), intval($pageSize))->select();
|
|
|
+
|
|
|
+ $this->success('success', [
|
|
|
+ 'list' => $list,
|
|
|
+ 'total' => $total,
|
|
|
+ 'pageNum' => intval($pageNum),
|
|
|
+ 'pageSize' => intval($pageSize)
|
|
|
+ ]);
|
|
|
+ }
|
|
|
+
|
|
|
+ //新增游戏
|
|
|
+ public function addGame()
|
|
|
+ {
|
|
|
+ $categoryId = $this->request->post('categoryId'); //游戏分类ID
|
|
|
+ $title = $this->request->post('title'); //标题
|
|
|
+ $imageUrl = $this->request->post('imageUrl'); //图片URL
|
|
|
+ $price = $this->request->post('price'); //价格
|
|
|
+ $description = $this->request->post('description'); //描述
|
|
|
+ $priority = $this->request->post('priority'); //优先级,越小越靠前
|
|
|
+ $browse = $this->request->post('browse'); //浏览次数,营销需要,添加的时候可以自定义
|
|
|
+ $buyCount = $this->request->post('buyCount'); //购买次数,营销需要,添加的时候可以自定义
|
|
|
+ $downloadUrl = $this->request->post('downloadUrl'); //下载链接
|
|
|
+ $extractedCode = $this->request->post('extractedCode'); //提取码
|
|
|
+ $gameVersion = $this->request->post('gameVersion'); //游戏版本
|
|
|
+ $language = $this->request->post('language'); //游戏语言
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+ if (!is_numeric($categoryId) || empty($title) || empty($imageUrl) || !is_float($price) || empty($description) || !is_numeric($priority) || !is_numeric($browse) || !is_numeric($buyCount) || empty($downloadUrl) || empty($extractedCode) || empty($gameVersion) || empty($language)) {
|
|
|
+ $this->fail(500, '参数校验错误');
|
|
|
+ }
|
|
|
+ //判断游戏分类ID是否存在
|
|
|
+ $category = Db::table('tb_game_category')
|
|
|
+ ->where(['id' => $categoryId])
|
|
|
+ ->find();
|
|
|
+ if (!$category) {
|
|
|
+ $this->fail(501, '游戏分类ID不存在');
|
|
|
+ }
|
|
|
+ Db::table('tb_game')
|
|
|
+ ->insert([
|
|
|
+ 'category' => $categoryId,
|
|
|
+ 'title' => $title,
|
|
|
+ 'image_url' => $imageUrl,
|
|
|
+ 'price' => $price,
|
|
|
+ 'description' => $description,
|
|
|
+ 'priority' => $priority,
|
|
|
+ 'browse' => $browse,
|
|
|
+ 'buy_count' => $buyCount,
|
|
|
+ 'game_version' => $gameVersion,
|
|
|
+ 'language' => $language,
|
|
|
+ 'created_at' => time(),
|
|
|
+ 'updated_at' => time(),
|
|
|
+ 'download_url' => $downloadUrl,
|
|
|
+ 'extracted_code' => $extractedCode,
|
|
|
+ ]);
|
|
|
+ $this->success('success', null);
|
|
|
+ }
|
|
|
+
|
|
|
+ //编辑游戏信息
|
|
|
+ public function editGame()
|
|
|
+ {
|
|
|
+ $gameId = $this->request->post('gameId'); //游戏ID
|
|
|
+ $categoryId = $this->request->post('categoryId'); //游戏分类ID
|
|
|
+ $title = $this->request->post('title'); //标题
|
|
|
+ $imageUrl = $this->request->post('imageUrl'); //图片URL
|
|
|
+ $price = $this->request->post('price'); //价格
|
|
|
+ $description = $this->request->post('description'); //描述
|
|
|
+ $priority = $this->request->post('priority'); //优先级,越小越靠前
|
|
|
+ $browse = $this->request->post('browse'); //浏览次数, 营销需要,修改的时候可以自定义
|
|
|
+ $buyCount = $this->request->post('buyCount'); //购买次数,营销需要,修改的时候可以自定义
|
|
|
+ $downloadUrl = $this->request->post('downloadUrl'); //下载链接
|
|
|
+ $extractedCode = $this->request->post('extractedCode'); //提取码
|
|
|
+ $language = $this->request->post('language'); //游戏语言
|
|
|
+ $gameVersion = $this->request->post('gameVersion'); //游戏版本
|
|
|
+
|
|
|
+
|
|
|
+ if (!is_numeric($categoryId) || empty($title) || empty($imageUrl) || !is_float($price) || empty($description) || !is_numeric($priority) || !is_numeric($browse) || !is_numeric($buyCount) || !is_numeric($gameId) || empty($downloadUrl) || empty($extractedCode) || empty($language) || empty($gameVersion)) {
|
|
|
+ $this->fail(500, '参数校验错误');
|
|
|
+ }
|
|
|
+ //判断游戏分类ID是否存在
|
|
|
+ $category = Db::table('tb_game_category')
|
|
|
+ ->where(['id' => $categoryId])
|
|
|
+ ->find();
|
|
|
+ if (!$category) {
|
|
|
+ $this->fail(501, '游戏分类ID不存在');
|
|
|
+ }
|
|
|
+ $game = Db::table('tb_game')
|
|
|
+ ->where(['id' => $gameId])
|
|
|
+ ->find();
|
|
|
+ if (!$game) {
|
|
|
+ $this->fail(502, '游戏ID不存在');
|
|
|
+ }
|
|
|
+ Db::table('tb_game')
|
|
|
+ ->where(['id' => $gameId])
|
|
|
+ ->update([
|
|
|
+ 'category' => $categoryId,
|
|
|
+ 'title' => $title,
|
|
|
+ 'image_url' => $imageUrl,
|
|
|
+ 'price' => $price,
|
|
|
+ 'description' => $description,
|
|
|
+ 'priority' => $priority,
|
|
|
+ 'browse' => $browse,
|
|
|
+ 'buy_count' => $buyCount,
|
|
|
+ 'updated_at' => time(),
|
|
|
+ 'download_url' => $downloadUrl,
|
|
|
+ 'extracted_code' => $extractedCode,
|
|
|
+ 'language' => $language,
|
|
|
+ 'game_version' => $gameVersion
|
|
|
+ ]);
|
|
|
+ $this->success('success', null);
|
|
|
+ }
|
|
|
+
|
|
|
+ //删除游戏
|
|
|
+ public function removeGame()
|
|
|
+ {
|
|
|
+ $gameId = $this->request->post('gameId'); //游戏ID
|
|
|
+ if (!is_numeric($gameId)) {
|
|
|
+ $this->fail(500, '参数校验错误');
|
|
|
+ }
|
|
|
+ $game = Db::table('tb_game')
|
|
|
+ ->where(['id' => $gameId])
|
|
|
+ ->find();
|
|
|
+ if (!$game) {
|
|
|
+ $this->fail(502, '游戏ID不存在');
|
|
|
+ }
|
|
|
+ Db::table('tb_game')
|
|
|
+ ->where(['id' => $gameId])
|
|
|
+ ->delete();
|
|
|
+ $this->success('success', null);
|
|
|
+ }
|
|
|
+
|
|
|
+ //获取单个游戏信息
|
|
|
+ public function getGame()
|
|
|
+ {
|
|
|
+ $gameId = $this->request->post('gameId'); //游戏ID
|
|
|
+ $game = Db::table('tb_game')
|
|
|
+ ->where(['id' => $gameId])
|
|
|
+ ->find();
|
|
|
+ if (!$game) {
|
|
|
+ $this->fail(502, '游戏ID不存在');
|
|
|
+ }
|
|
|
+ $this->success('success', $game);
|
|
|
+ }
|
|
|
+
|
|
|
+ //获取所有的CDKEY
|
|
|
+ public function getCdKeyList()
|
|
|
+ {
|
|
|
+ // 获取分页参数
|
|
|
+ $pageNum = $this->request->post('pageNum', 10);
|
|
|
+ if (!is_numeric($pageNum)) {
|
|
|
+ $this->fail(500, 'pageNum参数校验错误');
|
|
|
+ }
|
|
|
+
|
|
|
+ // 获取搜索参数
|
|
|
+ $user_id = $this->request->post('user_id', '');
|
|
|
+ $createTimeRange = $this->request->post('createTimeRange', []);
|
|
|
+
|
|
|
+ // 构建查询条件
|
|
|
+ $query = Db::table('tb_cdkey');
|
|
|
+
|
|
|
+ // 用户ID搜索
|
|
|
+ if (!empty($user_id)) {
|
|
|
+ $query->where('user_id', $user_id);
|
|
|
+ }
|
|
|
+
|
|
|
+ // 创建时间范围搜索(时间戳直接比较)
|
|
|
+ if (!empty($createTimeRange) && count($createTimeRange) == 2) {
|
|
|
+ $startTime = $createTimeRange[0];
|
|
|
+ $endTime = $createTimeRange[1];
|
|
|
+ $query->whereBetween('created_at', [$startTime, $endTime]);
|
|
|
+ }
|
|
|
+
|
|
|
+ // 执行分页查询
|
|
|
+ $data = $query->order('created_at DESC')
|
|
|
+ ->paginate(intval($pageNum));
|
|
|
+
|
|
|
+ $this->success('success', $data);
|
|
|
+ }
|
|
|
+ //批量创建CDKEY
|
|
|
+ public function addCdKeyBatch()
|
|
|
+ {
|
|
|
+ $num = $this->request->post('num'); //生成CDKEY的数量
|
|
|
+ $days = $this->request->post('days'); //有效期天数
|
|
|
+ $gameId = $this->request->post('gameId'); //CDKEY关联的购买游戏ID
|
|
|
+ $channel = $this->request->post('channel'); //CDKEY销售渠道:1:淘宝 2:拼多多
|
|
|
+ if (!is_numeric($num) || !is_numeric($days) || !is_numeric($gameId) || !is_numeric($channel)) {
|
|
|
+ $this->fail(500, '参数校验错误');
|
|
|
+ }
|
|
|
+ $game = Db::table('tb_game')
|
|
|
+ ->where(['id' => $gameId])
|
|
|
+ ->find();
|
|
|
+ if (!$game) {
|
|
|
+ $this->fail(501, '游戏ID不存在');
|
|
|
+ }
|
|
|
+ $batchData = [];
|
|
|
+ for ($i = 0; $i < $num; $i++) {
|
|
|
+ $prefix = '';
|
|
|
+ if ($channel == 1) {
|
|
|
+ $prefix = 'tb';
|
|
|
+ } elseif ($channel == 2) {
|
|
|
+ $prefix = 'pdd';
|
|
|
+ }
|
|
|
+ $cdKey = $prefix . '-' . Uuid::uuid4()->toString();
|
|
|
+ $data = [
|
|
|
+ 'cdkey' => $cdKey,
|
|
|
+ 'game_id' => $gameId,
|
|
|
+ 'expired_at' => time() + 60 * 60 * 24 * intval($days),
|
|
|
+ 'state' => 0, //未使用状态
|
|
|
+ 'created_at' => time(),
|
|
|
+ ];
|
|
|
+ Db::table('tb_cdkey')
|
|
|
+ ->insert($data);
|
|
|
+ $batchData[] = $data;
|
|
|
+ }
|
|
|
+ $this->success('success', $batchData);
|
|
|
+ }
|
|
|
+
|
|
|
+ //删除CDKEY
|
|
|
+ public function removeCdKey()
|
|
|
+ {
|
|
|
+ $cdKey = $this->request->post('cdKey'); //CDKEY
|
|
|
+ if (empty($cdKey)) {
|
|
|
+ $this->fail(500, 'cdKey参数校验错误');
|
|
|
+ }
|
|
|
+ $data = Db::table('tb_cdkey')
|
|
|
+ ->where(['cdkey' => $cdKey])
|
|
|
+ ->find();
|
|
|
+ if (!$data) {
|
|
|
+ $this->fail(501, 'cdKey不存在');
|
|
|
+ }
|
|
|
+ Db::table('tb_cdkey')
|
|
|
+ ->where(['cdkey' => $cdKey])
|
|
|
+ ->delete();
|
|
|
+ $this->success('success', null);
|
|
|
+ }
|
|
|
+
|
|
|
+ //获取充值订单列表
|
|
|
+public function getOrderList()
|
|
|
+{
|
|
|
+ $pageSize = $this->request->post('pageSize', 10); // 每页数量
|
|
|
+ $pageNum = $this->request->post('pageNum', 1); // 当前页码
|
|
|
+
|
|
|
+ // 参数校验
|
|
|
+ if (!is_numeric($pageSize) || !is_numeric($pageNum)) {
|
|
|
+ $this->fail(500, '参数校验错误');
|
|
|
+ }
|
|
|
+
|
|
|
+ // 搜索条件
|
|
|
+ $startDate = $this->request->post('startDate', '');
|
|
|
+ $endDate = $this->request->post('endDate', '');
|
|
|
+
|
|
|
+ $query = Db::table('tb_user_order')->order('created_at DESC');
|
|
|
+
|
|
|
+ // 添加日期范围 - 修复时间查询
|
|
|
+ if (!empty($startDate)) {
|
|
|
+ // 将日期转换为时间戳格式进行比较
|
|
|
+ $startTimestamp = strtotime($startDate);
|
|
|
+ $query->where('created_at', '>=', $startTimestamp);
|
|
|
+ }
|
|
|
+ if (!empty($endDate)) {
|
|
|
+ // 结束日期需要包含一整天,所以加上86399秒(23:59:59)
|
|
|
+ $endTimestamp = strtotime($endDate) + 86399;
|
|
|
+ $query->where('created_at', '<=', $endTimestamp);
|
|
|
+ }
|
|
|
+
|
|
|
+ $data = $query->paginate([
|
|
|
+ 'list_rows' => $pageSize,
|
|
|
+ 'page' => $pageNum
|
|
|
+ ]);
|
|
|
+
|
|
|
+ $this->success('success', $data);
|
|
|
+}
|
|
|
+
|
|
|
+ //上传图片
|
|
|
+ public function uploadImage()
|
|
|
+ {
|
|
|
+ $file = $this->request->file('file');
|
|
|
+ if (empty($file)) {
|
|
|
+ $this->fail(500, '上传的图片文件不能为空');
|
|
|
+ }
|
|
|
+ // 使用验证器验证上传的文件
|
|
|
+ validate(['file' => [
|
|
|
+ // 限制文件大小(单位b),这里限制为2M
|
|
|
+ 'fileSize' => 200 * 1024 * 1024,
|
|
|
+ // 限制文件后缀,多个后缀以英文逗号分割
|
|
|
+ 'fileExt' => 'jpg,jpeg,png',
|
|
|
+ ]])->check(['file' => $file]);
|
|
|
+ $saveName = \think\facade\Filesystem::disk('public')->putFile('upload', $file);
|
|
|
+ $this->success('success', [
|
|
|
+ 'filePath' => $this->request->scheme() . '://' . $this->request->host() . '/storage/' . $saveName,
|
|
|
+ ]);
|
|
|
+ }
|
|
|
+
|
|
|
+public function uploadFile()
|
|
|
+{
|
|
|
+ $file = $this->request->file('file');
|
|
|
+ if (empty($file)) {
|
|
|
+ $this->fail(500, '上传的文件不能为空');
|
|
|
+ }
|
|
|
+
|
|
|
+ // 使用验证器验证上传的文件
|
|
|
+ validate(['file' => [
|
|
|
+ // 限制文件大小(单位b),这里限制为50M
|
|
|
+ 'fileSize' => 50 * 1024 * 1024,
|
|
|
+ // 限制文件后缀,多个后缀以英文逗号分割,支持压缩包、文档和图片
|
|
|
+ 'fileExt' => 'zip,rar,7z,doc,docx,xls,xlsx,ppt,pptx,pdf,txt,jpg,jpeg,png,gif,bmp',
|
|
|
+ ]])->check(['file' => $file]);
|
|
|
+
|
|
|
+ $saveName = \think\facade\Filesystem::disk('public')->putFile('upload', $file);
|
|
|
+ $filePath = $this->request->scheme() . '://' . $this->request->host() . '/storage/' . $saveName;
|
|
|
+ $fileSize = $file->getSize(); // 获取文件大小
|
|
|
+
|
|
|
+ $this->success('success', [
|
|
|
+ 'filePath' => $filePath,
|
|
|
+ 'fileSize' => $fileSize,
|
|
|
+ ]);
|
|
|
+}
|
|
|
+
|
|
|
+ //后台手动给用户上下余额
|
|
|
+ //amount为正整数给用户加余额,如果为负数则给用户减余额
|
|
|
+ public function addUserBalance()
|
|
|
+ {
|
|
|
+ $userId = $this->request->post('userId');
|
|
|
+ $amount = $this->request->post('amount');
|
|
|
+ if (!is_numeric($amount) || !is_numeric($userId)) {
|
|
|
+ $this->fail(500, '参数校验错误');
|
|
|
+ }
|
|
|
+ $user = Db::table('tb_user')
|
|
|
+ ->where(['id' => $userId])
|
|
|
+ ->find();
|
|
|
+ if (!$user) {
|
|
|
+ $this->fail(501, '找不到userId的用户');
|
|
|
+ }
|
|
|
+ Db::table('tb_user')
|
|
|
+ ->where(['id' => $userId])
|
|
|
+ ->update([
|
|
|
+ 'balance' => $amount > 0 ? $user['balance'] + $amount : $user['balance'] + $amount,
|
|
|
+ ]);
|
|
|
+ //写记录
|
|
|
+ Db::table('tb_user_balance_record')
|
|
|
+ ->insert([
|
|
|
+ 'user_id' => $userId,
|
|
|
+ 'amount' => $amount,
|
|
|
+ 'created_at' => time(),
|
|
|
+ ]);
|
|
|
+ $this->success('success', null);
|
|
|
+ }
|
|
|
+
|
|
|
+ //获取用户购买游戏的记录
|
|
|
+ public function getUserGames()
|
|
|
+ {
|
|
|
+ $userId = $this->request->post('userId');
|
|
|
+ if (!is_numeric($userId)) {
|
|
|
+ $this->fail(500, 'userId参数校验错误');
|
|
|
+ }
|
|
|
+ $user = Db::table('tb_user')
|
|
|
+ ->where(['id' => $userId])
|
|
|
+ ->find();
|
|
|
+ if (!$user) {
|
|
|
+ $this->fail(501, 'userId不存在');
|
|
|
+ }
|
|
|
+ $data = Db::table('tb_user_game')
|
|
|
+ ->where(['user_id' => $userId])
|
|
|
+ ->select();
|
|
|
+ $this->success('success', $data);
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+ //获取管理员手动变动用户余额记录
|
|
|
+ public function getUserBalanceRecord()
|
|
|
+ {
|
|
|
+ $userId = $this->request->post('userId');
|
|
|
+ $pageNum = $this->request->post('pageNum', 1);
|
|
|
+ $pageSize = $this->request->post('pageSize', 10);
|
|
|
+
|
|
|
+ if (!is_numeric($userId)) {
|
|
|
+ $this->fail(500, 'userId参数校验错误');
|
|
|
+ }
|
|
|
+
|
|
|
+ $user = Db::table('tb_user')
|
|
|
+ ->where(['id' => $userId])
|
|
|
+ ->find();
|
|
|
+ if (!$user) {
|
|
|
+ $this->fail(501, 'userId不存在');
|
|
|
+ }
|
|
|
+
|
|
|
+ $query = Db::table('tb_user_balance_record')
|
|
|
+ ->where(['user_id' => $userId]);
|
|
|
+
|
|
|
+ $total = $query->count();
|
|
|
+ $data = $query->order('created_at', 'desc')
|
|
|
+ ->limit(($pageNum - 1) * $pageSize, $pageSize)
|
|
|
+ ->select();
|
|
|
+
|
|
|
+ $this->success('success', [
|
|
|
+ 'data' => $data,
|
|
|
+ 'total' => $total
|
|
|
+ ]);
|
|
|
+ }
|
|
|
+
|
|
|
+ //获取VIP用户列表
|
|
|
+ public function getVipUserList()
|
|
|
+ {
|
|
|
+
|
|
|
+ $page = input('page', 1);
|
|
|
+ $pageSize = input('pageSize', 10);
|
|
|
+
|
|
|
+
|
|
|
+ $userId = input('user_id', '');
|
|
|
+ $type = input('type', '');
|
|
|
+ $createdAtStart = input('created_at_start', '');
|
|
|
+ $createdAtEnd = input('created_at_end', '');
|
|
|
+ $expiredAtStart = input('expired_at_start', '');
|
|
|
+ $expiredAtEnd = input('expired_at_end', '');
|
|
|
+ $search = input('search', '');
|
|
|
+
|
|
|
+ $query = Db::table('tb_user_vip');
|
|
|
+
|
|
|
+
|
|
|
+ if (!empty($userId)) {
|
|
|
+ $query->where('user_id', $userId);
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+ if (!empty($type)) {
|
|
|
+ $query->where('type', $type);
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+ if (!empty($createdAtStart) && !empty($createdAtEnd)) {
|
|
|
+ $query->where('created_at', '>=', $createdAtStart)
|
|
|
+ ->where('created_at', '<=', $createdAtEnd);
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+ if (!empty($expiredAtStart) && !empty($expiredAtEnd)) {
|
|
|
+ $query->where('expired_at', '>=', $expiredAtStart)
|
|
|
+ ->where('expired_at', '<=', $expiredAtEnd);
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+ if (!empty($search)) {
|
|
|
+ $query->where(function($q) use ($search) {
|
|
|
+ $q->where('user_id', 'like', "%{$search}%");
|
|
|
+
|
|
|
+ });
|
|
|
+ }
|
|
|
+
|
|
|
+ // 获取总数
|
|
|
+ $total = $query->count();
|
|
|
+
|
|
|
+ // 获取分页数据
|
|
|
+ $data = $query->order('created_at DESC')
|
|
|
+ ->limit(($page - 1) * $pageSize, $pageSize)
|
|
|
+ ->select();
|
|
|
+
|
|
|
+ // 返回结果
|
|
|
+ return $this->success('success', [
|
|
|
+ 'data' => $data,
|
|
|
+ 'total' => $total,
|
|
|
+ 'page' => $page,
|
|
|
+ 'pageSize' => $pageSize
|
|
|
+ ]);
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+ public function getCustomerList()
|
|
|
+ {
|
|
|
+
|
|
|
+ $data = Db::table('tb_kefu')
|
|
|
+ ->select();
|
|
|
+ $this->success('success', $data);
|
|
|
+ }
|
|
|
+
|
|
|
+ public function addCustomerList()
|
|
|
+ {
|
|
|
+ $name = $this->request->post('name');
|
|
|
+ $jumpUrl = $this->request->post('jumpUrl');
|
|
|
+ $type = $this->request->post('type');
|
|
|
+
|
|
|
+ if (!is_numeric($type) || empty($name) || empty($jumpUrl)) {
|
|
|
+ $this->fail(500, '参数校验错误');
|
|
|
+ }
|
|
|
+
|
|
|
+ Db::table('tb_kefu')
|
|
|
+ ->insert([
|
|
|
+ 'name' => $name,
|
|
|
+ 'jump_url' => $jumpUrl,
|
|
|
+ 'type' => $type,
|
|
|
+ 'created_at' => time(),
|
|
|
+ 'updated_at' => time(),
|
|
|
+ ]);
|
|
|
+ $this->success('success', null);
|
|
|
+ }
|
|
|
+
|
|
|
+ public function editCustomerList()
|
|
|
+ {
|
|
|
+ $name = $this->request->post('name');
|
|
|
+ $jumpUrl = $this->request->post('jumpUrl');
|
|
|
+ $type = $this->request->post('type');
|
|
|
+ $id = $this->request->post('id');
|
|
|
+
|
|
|
+ if (!is_numeric($type) || empty($name) || empty($jumpUrl)) {
|
|
|
+ $this->fail(500, '参数校验错误');
|
|
|
+ }
|
|
|
+
|
|
|
+ $game = Db::table('tb_kefu')
|
|
|
+ ->where(['id' => $id])
|
|
|
+ ->find();
|
|
|
+ if (!$game) {
|
|
|
+ $this->fail(502, '数据不存在');
|
|
|
+ }
|
|
|
+ Db::table('tb_kefu')
|
|
|
+ ->where(['id' => $id])
|
|
|
+ ->update([
|
|
|
+ 'name' => $name,
|
|
|
+ 'jump_url' => $jumpUrl,
|
|
|
+ 'type' => $type,
|
|
|
+ 'created_at' => time(),
|
|
|
+ 'updated_at' => time(),
|
|
|
+
|
|
|
+ ]);
|
|
|
+ $this->success('success', null);
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+ public function deleteCustomerList()
|
|
|
+ {
|
|
|
+ $id = $this->request->post('id'); //CDKEY
|
|
|
+ if (empty($id)) {
|
|
|
+ $this->fail(500, '参数校验错误');
|
|
|
+ }
|
|
|
+ $data = Db::table('tb_kefu')
|
|
|
+ ->where(['id' => $id])
|
|
|
+ ->find();
|
|
|
+ if (!$data) {
|
|
|
+ $this->fail(501, '数据不存在');
|
|
|
+ }
|
|
|
+ Db::table('tb_kefu')
|
|
|
+ ->where(['id' => $id])
|
|
|
+ ->delete();
|
|
|
+ $this->success('success', null);
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+ //获取用户访问网站记录,用于统计用户行为
|
|
|
+ public function getVisitRecord()
|
|
|
+ {
|
|
|
+ // 获取分页参数,确保有默认值
|
|
|
+ $pageSize = $this->request->post('pageSize', 10); // 每页显示的数据数量
|
|
|
+ $pageNum = $this->request->post('pageNum', 1); // 当前页码
|
|
|
+
|
|
|
+ // 获取日期筛选参数
|
|
|
+ $startDate = $this->request->post('startDate', '');
|
|
|
+ $endDate = $this->request->post('endDate', '');
|
|
|
+
|
|
|
+ // 构建查询
|
|
|
+ $query = Db::table('tb_website_visit');
|
|
|
+
|
|
|
+ // 添加日期筛选条件
|
|
|
+ if (!empty($startDate)) {
|
|
|
+ $startTimestamp = strtotime($startDate . ' 00:00:00');
|
|
|
+ $query->where('created_at', '>=', $startTimestamp);
|
|
|
+ }
|
|
|
+
|
|
|
+ if (!empty($endDate)) {
|
|
|
+ $endTimestamp = strtotime($endDate . ' 23:59:59');
|
|
|
+ $query->where('created_at', '<=', $endTimestamp);
|
|
|
+ }
|
|
|
+
|
|
|
+ // 获取总数和数据
|
|
|
+ $total = $query->count();
|
|
|
+ $data = $query
|
|
|
+ ->order('created_at DESC')
|
|
|
+ ->page(intval($pageNum), intval($pageSize))
|
|
|
+ ->select();
|
|
|
+
|
|
|
+ $this->success('success', [
|
|
|
+ 'data' => $data, // 当前页数据
|
|
|
+ 'total' => $total, // 总记录数
|
|
|
+ ]);
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+ //获取日均,总PV,日均,总IP访问数据
|
|
|
+ public function visitData()
|
|
|
+ {
|
|
|
+ $totalPV = Db::table('tb_website_visit')->count();
|
|
|
+ $todayPV = Db::table('tb_website_visit')
|
|
|
+ ->where('created_at', '>', strtotime(date('Y-m-d') . ' 00:00:00'))
|
|
|
+ ->count();
|
|
|
+ $totalIP = Db::table('tb_website_visit')
|
|
|
+ ->distinct(true)
|
|
|
+ ->count('ip_address');
|
|
|
+ $todayIP = Db::table('tb_website_visit')
|
|
|
+ ->where('created_at', '>', strtotime(date('Y-m-d') . ' 00:00:00'))
|
|
|
+ ->distinct(true)
|
|
|
+ ->count('ip_address');
|
|
|
+ $this->success('success', [
|
|
|
+ 'totalPV' => $totalPV, //总PV
|
|
|
+ 'todayPV' => $todayPV, //今日PV
|
|
|
+ 'todayIP' => $todayIP, //今日IP
|
|
|
+ 'totalIP' => $totalIP, //总IP
|
|
|
+ ]);
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+ //获取用户组
|
|
|
+ public function getUserGroup()
|
|
|
+ {
|
|
|
+ $name = $this->request->post('name', '');
|
|
|
+ $level = $this->request->post('level', '');
|
|
|
+ $startDate = $this->request->post('start_date', '');
|
|
|
+ $endDate = $this->request->post('end_date', '');
|
|
|
+
|
|
|
+ $query = Db::table('tb_user_group');
|
|
|
+
|
|
|
+ // 按名称搜索
|
|
|
+ if (!empty($name)) {
|
|
|
+ $query->where('name', 'like', '%' . $name . '%');
|
|
|
+ }
|
|
|
+
|
|
|
+ // 按等级搜索
|
|
|
+ if (!empty($level) && is_numeric($level)) {
|
|
|
+ $query->where('level', $level);
|
|
|
+ }
|
|
|
+
|
|
|
+ // 按时间范围搜索
|
|
|
+ if (!empty($startDate)) {
|
|
|
+ $startTimestamp = strtotime($startDate);
|
|
|
+ $query->where('created_at', '>=', $startTimestamp);
|
|
|
+ }
|
|
|
+
|
|
|
+ if (!empty($endDate)) {
|
|
|
+ $endTimestamp = strtotime($endDate . ' 23:59:59');
|
|
|
+ $query->where('created_at', '<=', $endTimestamp);
|
|
|
+ }
|
|
|
+
|
|
|
+ $data = $query->order('created_at DESC')->select();
|
|
|
+ $this->success('success', $data);
|
|
|
+ }
|
|
|
+ //添加用户组
|
|
|
+ public function addUserGroup()
|
|
|
+ {
|
|
|
+ $name = $this->request->post('name'); //用户组名称
|
|
|
+ $level = $this->request->post('level'); //等级
|
|
|
+ $exp = $this->request->post('exp'); //所需经验值
|
|
|
+ if (empty($name) || !is_numeric($level) || !is_numeric($exp)) {
|
|
|
+ $this->fail(500, '参数校验错误');
|
|
|
+ }
|
|
|
+ Db::table('tb_user_group')
|
|
|
+ ->insert([
|
|
|
+ 'name' => $name,
|
|
|
+ 'level' => $level,
|
|
|
+ 'exp' => $exp,
|
|
|
+ 'created_at' => time(),
|
|
|
+ 'updated_at' => time(),
|
|
|
+ ]);
|
|
|
+ $this->success('success', null);
|
|
|
+ }
|
|
|
+
|
|
|
+ //编辑用户组
|
|
|
+ public function editUserGroup()
|
|
|
+ {
|
|
|
+ $id = $this->request->post('id'); //用户组ID
|
|
|
+ $name = $this->request->post('name'); //用户组名称
|
|
|
+ $level = $this->request->post('level'); //等级
|
|
|
+ $exp = $this->request->post('exp'); //所需经验值
|
|
|
+ if (empty($name) || !is_numeric($id) || !is_numeric($level) || !is_numeric($exp)) {
|
|
|
+ $this->fail(500, '参数校验错误');
|
|
|
+ }
|
|
|
+ $userGroup = Db::table('tb_user_group')
|
|
|
+ ->where(['id' => $id])
|
|
|
+ ->find();
|
|
|
+ if (!$userGroup) {
|
|
|
+ $this->fail(501, '找不到用户组ID');
|
|
|
+ }
|
|
|
+ Db::table('tb_user_group')
|
|
|
+ ->where(['id' => $id])
|
|
|
+ ->update([
|
|
|
+ 'name' => $name,
|
|
|
+ 'level' => $level,
|
|
|
+ 'exp' => $exp,
|
|
|
+ 'updated_at' => time(),
|
|
|
+ ]);
|
|
|
+ $this->success('success', null);
|
|
|
+ }
|
|
|
+
|
|
|
+ //删除用户组
|
|
|
+ public function removeUserGroup()
|
|
|
+ {
|
|
|
+ $id = $this->request->post('id'); //用户组ID
|
|
|
+ if (!is_numeric($id)) {
|
|
|
+ $this->fail(500, '参数校验错误');
|
|
|
+ }
|
|
|
+ $userGroup = Db::table('tb_user_group')
|
|
|
+ ->where(['id' => $id])
|
|
|
+ ->find();
|
|
|
+ if (!$userGroup) {
|
|
|
+ $this->fail(501, '找不到用户组ID');
|
|
|
+ }
|
|
|
+ Db::table('tb_user_group')
|
|
|
+ ->where(['id' => $id])
|
|
|
+ ->delete();
|
|
|
+ $this->success('success', null);
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+ // 获取用户消息,支持分页和时间筛选
|
|
|
+ public function getUserMessage()
|
|
|
+ {
|
|
|
+ $page = $this->request->post('page', 1);
|
|
|
+ $limit = $this->request->post('limit', 10);
|
|
|
+ $startDate = $this->request->post('start_date', '');
|
|
|
+ $endDate = $this->request->post('end_date', '');
|
|
|
+
|
|
|
+ $query = Db::table('tb_message');
|
|
|
+
|
|
|
+ // 按时间范围搜索
|
|
|
+ if (!empty($startDate)) {
|
|
|
+ $startTimestamp = strtotime($startDate);
|
|
|
+ $query->where('created_at', '>=', $startTimestamp);
|
|
|
+ }
|
|
|
+
|
|
|
+ if (!empty($endDate)) {
|
|
|
+ $endTimestamp = strtotime($endDate . ' 23:59:59');
|
|
|
+ $query->where('created_at', '<=', $endTimestamp);
|
|
|
+ }
|
|
|
+
|
|
|
+ // 获取总数
|
|
|
+ $total = $query->count();
|
|
|
+
|
|
|
+ // 分页查询
|
|
|
+ $data = $query->order('created_at DESC')
|
|
|
+ ->limit(($page - 1) * $limit, $limit)
|
|
|
+ ->select();
|
|
|
+
|
|
|
+ $this->success('success', [
|
|
|
+ 'data' => $data,
|
|
|
+ 'total' => $total,
|
|
|
+ 'page' => $page,
|
|
|
+ 'limit' => $limit
|
|
|
+ ]);
|
|
|
+ }
|
|
|
+
|
|
|
+ //获取所有论坛版块列表
|
|
|
+public function getForumCategoryList()
|
|
|
+{
|
|
|
+ $categoryId = $this->request->post('categoryId');
|
|
|
+ $page = $this->request->post('page', 1);
|
|
|
+ $limit = $this->request->post('limit', 10);
|
|
|
+
|
|
|
+ // 构建查询条件
|
|
|
+ $query = Db::table('tb_forum_category');
|
|
|
+
|
|
|
+ if (!empty($categoryId)) {
|
|
|
+ $query->where('category_id', $categoryId);
|
|
|
+ }
|
|
|
+
|
|
|
+ // 获取总数
|
|
|
+ $total = $query->count();
|
|
|
+
|
|
|
+ // 获取分页数据
|
|
|
+ $data = $query->order('created_at DESC')
|
|
|
+ ->page($page, $limit)
|
|
|
+ ->select();
|
|
|
+
|
|
|
+ $this->success('success', [
|
|
|
+ 'list' => $data,
|
|
|
+ 'total' => $total,
|
|
|
+ 'page' => $page,
|
|
|
+ 'limit' => $limit
|
|
|
+ ]);
|
|
|
+}
|
|
|
+
|
|
|
+
|
|
|
+ public function getForumThreadCategory()
|
|
|
+ {
|
|
|
+ $categoryid = $this->request->post('forumId');
|
|
|
+ $data = Db::table('tb_forum_thread_category')->where('category_id',$categoryid)
|
|
|
+ ->order('created_at DESC')
|
|
|
+ ->select();
|
|
|
+ $this->success('success', $data);
|
|
|
+ }
|
|
|
+
|
|
|
+public function saveThreadCategories()
|
|
|
+{
|
|
|
+ // 获取前端传来的板块ID和分类数据
|
|
|
+ $forumId = $this->request->post('forumId');
|
|
|
+ $categories = $this->request->post('categories');
|
|
|
+
|
|
|
+ // 开启数据库事务
|
|
|
+ Db::startTrans();
|
|
|
+ try {
|
|
|
+ // 获取当前板块的所有帖子分类
|
|
|
+ $existingCategories = Db::table('tb_forum_thread_category')
|
|
|
+ ->where('category_id', $forumId)
|
|
|
+ ->select()
|
|
|
+ ->toArray();
|
|
|
+
|
|
|
+ // 将现有分类的 ID 存入数组,方便后续对比
|
|
|
+ $existingCategoryIds = array_column($existingCategories, 'id');
|
|
|
+
|
|
|
+ // 收集新分类的ID(包括已有的和新增的)
|
|
|
+ $newCategoryIds = [];
|
|
|
+
|
|
|
+ // 遍历前端传来的分类数据
|
|
|
+ foreach ($categories as $category) {
|
|
|
+ if (isset($category['id']) && !empty($category['id'])) {
|
|
|
+ // 如果有 ID,表示是已存在的分类,需要更新
|
|
|
+ $newCategoryIds[] = $category['id'];
|
|
|
+
|
|
|
+ // 检查是否需要更新
|
|
|
+ $existingCategory = array_filter($existingCategories, function($item) use ($category) {
|
|
|
+ return $item['id'] == $category['id'];
|
|
|
+ });
|
|
|
+
|
|
|
+ if (!empty($existingCategory)) {
|
|
|
+ $existingCategory = array_values($existingCategory);
|
|
|
+ if ($existingCategory[0]['title'] != $category['title']) {
|
|
|
+ // 更新分类
|
|
|
+ Db::table('tb_forum_thread_category')
|
|
|
+ ->where('id', $category['id'])
|
|
|
+ ->update(['title' => $category['title'], 'updated_at' => time()]);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ } else {
|
|
|
+ // 如果没有 ID,表示是新增的分类
|
|
|
+ // 插入新的分类
|
|
|
+ $newId = Db::table('tb_forum_thread_category')
|
|
|
+ ->insertGetId([
|
|
|
+ 'category_id' => $forumId,
|
|
|
+ 'title' => $category['title'],
|
|
|
+ 'created_at' => time(),
|
|
|
+ 'updated_at' => time()
|
|
|
+ ]);
|
|
|
+
|
|
|
+ // 将新插入的ID加入到数组中
|
|
|
+ $newCategoryIds[] = $newId;
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ // 删除被移除的分类
|
|
|
+ if (!empty($newCategoryIds)) {
|
|
|
+ $deletedCategoryIds = array_diff($existingCategoryIds, $newCategoryIds);
|
|
|
+ if (!empty($deletedCategoryIds)) {
|
|
|
+ Db::table('tb_forum_thread_category')
|
|
|
+ ->where('id', 'in', $deletedCategoryIds)
|
|
|
+ ->delete();
|
|
|
+ }
|
|
|
+ } else {
|
|
|
+ // 如果没有新分类,删除所有现有分类
|
|
|
+ if (!empty($existingCategoryIds)) {
|
|
|
+ Db::table('tb_forum_thread_category')
|
|
|
+ ->where('id', 'in', $existingCategoryIds)
|
|
|
+ ->delete();
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ // 提交事务
|
|
|
+ Db::commit();
|
|
|
+ return json(['code' => 200, 'msg' => '保存成功']);
|
|
|
+ } catch (\Exception $e) {
|
|
|
+ // 回滚事务
|
|
|
+ Db::rollback();
|
|
|
+ return json(['code' => 500, 'msg' => '保存失败:' . $e->getMessage()]);
|
|
|
+ }
|
|
|
+}
|
|
|
+
|
|
|
+ //添加论坛版块
|
|
|
+ public function addForumCategory()
|
|
|
+ {
|
|
|
+ $name = $this->request->post('name'); //版块名称
|
|
|
+ $description = $this->request->post('description'); //版块描述
|
|
|
+ $imageUrl = $this->request->post('imageUrl'); //版块图片URL,需要用uploadImage接口先上传拿到URL
|
|
|
+ $adminId = $this->request->post('adminId'); //版主用户ID
|
|
|
+ $priority = $this->request->post('priority'); //优先级
|
|
|
+ $categoryId = $this->request->post('categoryId'); //分类ID
|
|
|
+
|
|
|
+ if (empty($name) || empty($description) || empty($imageUrl) || !is_numeric($adminId) || !is_numeric($priority) || !is_numeric($categoryId)) {
|
|
|
+ $this->fail(500, '参数校验错误');
|
|
|
+ }
|
|
|
+
|
|
|
+ Db::table('tb_forum_category')
|
|
|
+ ->insert([
|
|
|
+ 'name' => $name,
|
|
|
+ 'description' => $description,
|
|
|
+ 'image_url' => $imageUrl,
|
|
|
+ 'admin_id' => $adminId,
|
|
|
+ 'priority' => $priority,
|
|
|
+ 'category_id' => $categoryId, // 这里是分类ID
|
|
|
+ 'created_at' => time(),
|
|
|
+ 'updated_at' => time(),
|
|
|
+ ]);
|
|
|
+ $this->success('success', null);
|
|
|
+ }
|
|
|
+
|
|
|
+ //编辑论坛版块
|
|
|
+ public function editForumCategory()
|
|
|
+ {
|
|
|
+ $id = $this->request->post('id'); //版块ID(主键)
|
|
|
+ $name = $this->request->post('name'); //版块名称
|
|
|
+ $description = $this->request->post('description'); //版块描述
|
|
|
+ $imageUrl = $this->request->post('imageUrl'); //版块图片URL
|
|
|
+ $adminId = $this->request->post('adminId'); //版主用户ID
|
|
|
+ $priority = $this->request->post('priority'); //优先级
|
|
|
+ $categoryId = $this->request->post('categoryId'); //分类ID
|
|
|
+
|
|
|
+ if (!is_numeric($id) || empty($name) || empty($description) || empty($imageUrl) || !is_numeric($adminId) || !is_numeric($priority) || !is_numeric($categoryId)) {
|
|
|
+ $this->fail(500, '参数校验错误');
|
|
|
+ }
|
|
|
+
|
|
|
+ Db::table('tb_forum_category')
|
|
|
+ ->where(['id' => $id]) // 使用版块ID作为主键
|
|
|
+ ->update([
|
|
|
+ 'name' => $name,
|
|
|
+ 'description' => $description,
|
|
|
+ 'image_url' => $imageUrl,
|
|
|
+ 'admin_id' => $adminId,
|
|
|
+ 'priority' => $priority,
|
|
|
+ 'category_id' => $categoryId, // 这里是分类ID
|
|
|
+ 'updated_at' => time(),
|
|
|
+ ]);
|
|
|
+ $this->success('success', null);
|
|
|
+ }
|
|
|
+
|
|
|
+ //移除版块
|
|
|
+ public function removeForumCategory()
|
|
|
+ {
|
|
|
+ $categoryId = $this->request->post('id'); //版块ID
|
|
|
+ if (!is_numeric($categoryId)) {
|
|
|
+ $this->fail(500, 'categoryId参数校验错误');
|
|
|
+ }
|
|
|
+ $forumCategory = Db::table('tb_forum_category')
|
|
|
+ ->where(['id' => $categoryId])
|
|
|
+ ->find();
|
|
|
+ if (!$forumCategory) {
|
|
|
+ $this->fail(501, '找不到categoryId对应的版块');
|
|
|
+ }
|
|
|
+ Db::table('tb_forum_category')
|
|
|
+ ->where(['id' => $categoryId])
|
|
|
+ ->delete();
|
|
|
+ $this->success('success', null);
|
|
|
+ }
|
|
|
+
|
|
|
+ //获取单个对应ID论坛版块信息
|
|
|
+ public function getForumCategory()
|
|
|
+ {
|
|
|
+ $categoryId = $this->request->post('categoryId'); //版块ID
|
|
|
+ if (!is_numeric($categoryId)) {
|
|
|
+ $this->fail(500, 'categoryId参数校验错误');
|
|
|
+ }
|
|
|
+ $forumCategory = Db::table('tb_forum_category')
|
|
|
+ ->where(['id' => $categoryId])
|
|
|
+ ->find();
|
|
|
+ if (!$forumCategory) {
|
|
|
+ $this->fail(501, '找不到categoryId对应的版块');
|
|
|
+ }
|
|
|
+ $this->success('success', $forumCategory);
|
|
|
+ }
|
|
|
+
|
|
|
+ // 获取所有辅助列表
|
|
|
+ public function getFuzhuList()
|
|
|
+ {
|
|
|
+ $page = $this->request->post('page'); // 页数
|
|
|
+ $list = $this->request->post('list'); // 每页记录数
|
|
|
+ $key = $this->request->post('key'); // 搜索关键字
|
|
|
+ if(!is_numeric($page)|| !is_numeric($list)) {
|
|
|
+ $this->fail(500, '参数校验错误!');
|
|
|
+ }
|
|
|
+ $query = Db::table('tb_fuzhu');
|
|
|
+ if ($key) {
|
|
|
+ $query->whereLike('title', '%'.$key.'%');
|
|
|
+ }
|
|
|
+ $data = $query->paginate([
|
|
|
+ 'page' => $page,
|
|
|
+ 'list_rows' => $list
|
|
|
+ ]);
|
|
|
+ $this->success('success', $data);
|
|
|
+ }
|
|
|
+
|
|
|
+ // 新增辅助
|
|
|
+ public function addFuzhu()
|
|
|
+ {
|
|
|
+ $title = $this->request->post('title'); // 辅助名称
|
|
|
+ $image_url = $this->request->post('image_url'); // 图片Url地址
|
|
|
+ $version = $this->request->post('version'); // 辅助版本
|
|
|
+ $file_size = $this->request->post('file_size'); // 辅助文件大小(字节)
|
|
|
+ $language = $this->request->post('language'); // 辅助语言
|
|
|
+ $game = $this->request->post('game'); // 游戏名称
|
|
|
+ $type = $this->request->post('type'); // 授权类型 0:免费辅助 1:收费辅助
|
|
|
+ $priority = $this->request->post('priority'); // 排序优先级,越小越靠前原则
|
|
|
+ $rate = $this->request->post('rate'); // 评分星星数,最多5分
|
|
|
+ $description = $this->request->post('description'); // 辅助详细描述
|
|
|
+ $download_url = $this->request->post('download_url'); // 下载地址URL
|
|
|
+ // if (!$title || !$image_url || !$version || !$file_size || $language || $game || $type || $priority || $rate || $description || $download_url) {
|
|
|
+ // $this->fail(500, '请检查传参!');
|
|
|
+ // }
|
|
|
+
|
|
|
+ // if ( !$language || !$game || !$priority || !$rate || !$description || !$download_url) {
|
|
|
+ // $this->fail(5001, '请检查传参!');
|
|
|
+ // }
|
|
|
+
|
|
|
+ if (!$title || !$image_url || !$version || !$file_size || !$language || !$game || !$priority || !$rate || !$description || !$download_url) {
|
|
|
+ $this->fail(500, '请检查传参!');
|
|
|
+ }
|
|
|
+ // 校验通过 插入数据库
|
|
|
+ Db::table('tb_fuzhu')->insert([
|
|
|
+ 'title' => $title,
|
|
|
+ 'image_url' => $image_url,
|
|
|
+ 'version' => $version,
|
|
|
+ 'file_size' => $file_size,
|
|
|
+ 'language' => $language,
|
|
|
+ 'game' => $game,
|
|
|
+ 'type' => $type,
|
|
|
+ 'priority' => $priority,
|
|
|
+ 'rate' => $rate,
|
|
|
+ 'description' => $description,
|
|
|
+ 'download_url' => $download_url,
|
|
|
+ 'created_at' => time(),
|
|
|
+ 'updated_at' => time(),
|
|
|
+ ]);
|
|
|
+ $this->success('success', null);
|
|
|
+ }
|
|
|
+
|
|
|
+ // 修改辅助
|
|
|
+ public function updateFuzhu()
|
|
|
+ {
|
|
|
+ $id = $this->request->post('id'); // 辅助ID
|
|
|
+ $title = $this->request->post('title'); // 辅助名称
|
|
|
+ $image_url = $this->request->post('image_url'); // 图片Url地址
|
|
|
+ $version = $this->request->post('version'); // 辅助版本
|
|
|
+ $file_size = $this->request->post('file_size'); // 辅助文件大小(字节)
|
|
|
+ $language = $this->request->post('language'); // 辅助语言
|
|
|
+ $game = $this->request->post('game'); // 游戏名称
|
|
|
+ $type = $this->request->post('type'); // 授权类型 0:免费辅助 1:收费辅助
|
|
|
+ $priority = $this->request->post('priority'); // 排序优先级,越小越靠前原则
|
|
|
+ $rate = $this->request->post('rate'); // 评分星星数,最多5分
|
|
|
+ $description = $this->request->post('description'); // 辅助详细描述
|
|
|
+ $download_url = $this->request->post('download_url'); // 下载地址URL
|
|
|
+ if (!$id || !$title || !$image_url || !$version || !$file_size || !$language || !$game || !$priority || !$rate || !$description || !$download_url) {
|
|
|
+ $this->fail(500, '请检查传参!');
|
|
|
+ }
|
|
|
+ // 校验通过 插入数据库
|
|
|
+ Db::table('tb_fuzhu')
|
|
|
+ ->where('id', $id)
|
|
|
+ ->update([
|
|
|
+ 'title' => $title,
|
|
|
+ 'image_url' => $image_url,
|
|
|
+ 'version' => $version,
|
|
|
+ 'file_size' => $file_size,
|
|
|
+ 'language' => $language,
|
|
|
+ 'game' => $game,
|
|
|
+ 'type' => $type,
|
|
|
+ 'priority' => $priority,
|
|
|
+ 'rate' => $rate,
|
|
|
+ 'description' => $description,
|
|
|
+ 'download_url' => $download_url,
|
|
|
+ 'created_at' => time(),
|
|
|
+ 'updated_at' => time(),
|
|
|
+ ]);
|
|
|
+ $this->success('success', null);
|
|
|
+ }
|
|
|
+
|
|
|
+ // 删除辅助
|
|
|
+ public function deleteFuzhu()
|
|
|
+ {
|
|
|
+ $id = $this->request->post('id'); // 辅助ID
|
|
|
+ if (!$id) {
|
|
|
+ $this->fail(500, '缺少参数id!');
|
|
|
+ }
|
|
|
+ $deleted = Db::table('tb_fuzhu')->where('id', $id)->delete();
|
|
|
+ if ($deleted) {
|
|
|
+ $this->success('删除成功', null);
|
|
|
+ } else {
|
|
|
+ $this->fail(500, '删除失败,未找到对应记录');
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ //获取辅助下载记录,需要支持分页
|
|
|
+ public function getFuzhuDownload()
|
|
|
+ {
|
|
|
+ $page = $this->request->post('page'); // 当前页数
|
|
|
+ $list = $this->request->post('list'); // 每页记录数
|
|
|
+ $fuzhuId = $this->request->post('fuzhuId'); //辅助ID
|
|
|
+ if (!is_numeric($fuzhuId)) {
|
|
|
+ $this->fail(500, 'fuzhuId参数校验错误');
|
|
|
+ }
|
|
|
+ $data = Db::table('tb_fuzhu_download')
|
|
|
+ ->alias('tfd')
|
|
|
+ ->where(['tfd.fuzhu_id' => $fuzhuId])
|
|
|
+ ->order('tfd.created_at DESC')
|
|
|
+ ->join('tb_user tu', 'tfd.user_id = tu.id', 'LEFT')
|
|
|
+ ->field('tfd.*, tu.username, tu.avatar')
|
|
|
+ ->paginate([
|
|
|
+ 'page' => $page,
|
|
|
+ 'list_rows' => $list
|
|
|
+ ]);
|
|
|
+ // 处理头像数据
|
|
|
+ $items = $data->getCollection()->toArray();
|
|
|
+ if ($items) {
|
|
|
+ foreach($items as &$item) {
|
|
|
+ if (!empty($item['avatar'])) {
|
|
|
+ $avatarParts = explode('//', $item['avatar']);
|
|
|
+ if (count($avatarParts) > 1) {
|
|
|
+ $avatarId = intval($avatarParts[1]);
|
|
|
+ $avatar = Db::table('tb_system_avatar')
|
|
|
+ ->where(['id' => $avatarId])
|
|
|
+ ->find();
|
|
|
+ $item['avatar'] = $avatar['image_url'] ?? '';
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ // 将处理后的数据重新设置到分页对象中
|
|
|
+ $data->setCollection(collect($items));
|
|
|
+ }
|
|
|
+ $this->success('success', $data);
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 获取全局配置
|
|
|
+ */
|
|
|
+ public function getGlobalConfig()
|
|
|
+ {
|
|
|
+ $page = $this->request->post('page',1); // 当前页数
|
|
|
+ $list = $this->request->post('list',10); // 每页记录数
|
|
|
+ $key = $this->request->post('key'); // 搜索关键词 不传则不搜索
|
|
|
+ if (!is_numeric($page) ||!is_numeric($list)) {
|
|
|
+ $this->fail(500, '参数错误!');
|
|
|
+ }
|
|
|
+ $query = Db::table('tb_global_config');
|
|
|
+ if($key){
|
|
|
+ $query->whereLike('key', '%' . $key . '%');
|
|
|
+ }
|
|
|
+ $data = $query->paginate([
|
|
|
+ 'page' => $page,
|
|
|
+ 'list_rows' => $list
|
|
|
+ ]);
|
|
|
+ $this->success('success', $data);
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 新增全局配置
|
|
|
+ */
|
|
|
+ public function addGlobalConfig()
|
|
|
+ {
|
|
|
+ $key = $this->request->post('key'); // 配置名称
|
|
|
+ $value = $this->request->post('value'); // 配置值
|
|
|
+ $description = $this->request->post('description'); // 配置说明
|
|
|
+ if(!$key || !$value) {
|
|
|
+ $this->fail(500, '参数校验错误!');
|
|
|
+ }
|
|
|
+ Db::table('tb_global_config')
|
|
|
+ ->insert([
|
|
|
+ 'key' => $key,
|
|
|
+ 'value' => $value,
|
|
|
+ 'description' => $description,
|
|
|
+ 'create_at' => time()
|
|
|
+ ]);
|
|
|
+ $this->success('success', null);
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 修改全局配置
|
|
|
+ */
|
|
|
+ public function updateGlobalConfig()
|
|
|
+ {
|
|
|
+ $id = $this->request->post('id'); // 主键ID
|
|
|
+ $key = $this->request->post('key'); // 配置名称
|
|
|
+ $value = $this->request->post('value'); // 配置值
|
|
|
+ $description = $this->request->post('description'); // 配置说明
|
|
|
+
|
|
|
+ if(!is_numeric($id)|| !$key || !$value) {
|
|
|
+ $this->fail(500, '参数校验错误!');
|
|
|
+ }
|
|
|
+ Db::table('tb_global_config')
|
|
|
+ ->where('id', $id)
|
|
|
+ ->update([
|
|
|
+ 'key' => $key,
|
|
|
+ 'value' => $value,
|
|
|
+ 'description' => $description,
|
|
|
+ 'update_at' => time()
|
|
|
+ ]);
|
|
|
+ $this->success('success', null);
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 删除全局配置
|
|
|
+ */
|
|
|
+ public function deleteGlobalConfig()
|
|
|
+ {
|
|
|
+ $id = $this->request->post('id'); // 主键ID
|
|
|
+ if(!is_numeric($id)) {
|
|
|
+ $this->fail(500, '参数校验错误!');
|
|
|
+ }
|
|
|
+ Db::table('tb_global_config')
|
|
|
+ ->where('id', $id)
|
|
|
+ ->delete();
|
|
|
+ $this->success('success', null);
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+ public function getFeedBack()
|
|
|
+ {
|
|
|
+ $page = $this->request->post('page',1); // 当前页数
|
|
|
+ $list = $this->request->post('list',10); // 每页记录数
|
|
|
+ $key = $this->request->post('key'); // 搜索关键词 不传则不搜索
|
|
|
+ if (!is_numeric($page) ||!is_numeric($list)) {
|
|
|
+ $this->fail(500, '参数错误!');
|
|
|
+ }
|
|
|
+ $query = Db::table('tb_feedback');
|
|
|
+ if($key){
|
|
|
+ $query->whereLike('key', '%' . $key . '%');
|
|
|
+ }
|
|
|
+ $data = $query->paginate([
|
|
|
+ 'page' => $page,
|
|
|
+ 'list_rows' => $list
|
|
|
+ ]);
|
|
|
+ $this->success('success', $data);
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+ public function getUserBug()
|
|
|
+ {
|
|
|
+ $page = $this->request->post('page',1); // 当前页数
|
|
|
+ $list = $this->request->post('list',10); // 每页记录数
|
|
|
+ $key = $this->request->post('key'); // 搜索关键词 不传则不搜索
|
|
|
+ if (!is_numeric($page) ||!is_numeric($list)) {
|
|
|
+ $this->fail(500, '参数错误!');
|
|
|
+ }
|
|
|
+ $query = Db::table('tb_user_bug');
|
|
|
+ if($key){
|
|
|
+ $query->whereLike('key', '%' . $key . '%');
|
|
|
+ }
|
|
|
+ $data = $query->paginate([
|
|
|
+ 'page' => $page,
|
|
|
+ 'list_rows' => $list
|
|
|
+ ]);
|
|
|
+ $this->success('success', $data);
|
|
|
+ }
|
|
|
+
|
|
|
+ public function getThreadList()
|
|
|
+ {
|
|
|
+ $page = $this->request->post('page', 1); // 当前页数
|
|
|
+ $list = $this->request->post('limit', 10); // 每页记录数
|
|
|
+ $key = $this->request->post('key'); // 搜索关键词
|
|
|
+ $category_id = $this->request->post('category_id'); // 板块ID
|
|
|
+ $user_id = $this->request->post('user_id'); // 用户ID
|
|
|
+ $start_date = $this->request->post('start_date'); // 开始日期
|
|
|
+ $end_date = $this->request->post('end_date'); // 结束日期
|
|
|
+
|
|
|
+ if (!is_numeric($page) || !is_numeric($list)) {
|
|
|
+ $this->fail(500, '参数错误!');
|
|
|
+ }
|
|
|
+
|
|
|
+ $query = Db::table('tb_thread')
|
|
|
+ ->alias('t')
|
|
|
+ ->leftJoin('tb_forum_category fc', 't.category_id = fc.id')
|
|
|
+ ->field('t.*, fc.name as category_name');
|
|
|
+
|
|
|
+ if ($key) {
|
|
|
+ $query->whereLike('t.title', '%' . $key . '%')
|
|
|
+ ->whereOrLike('t.content', '%' . $key . '%');
|
|
|
+ }
|
|
|
+
|
|
|
+ if ($category_id) {
|
|
|
+ $query->where('t.category_id', $category_id);
|
|
|
+ }
|
|
|
+
|
|
|
+ if ($user_id) {
|
|
|
+ $query->where('t.user_id', $user_id);
|
|
|
+ }
|
|
|
+
|
|
|
+ if ($start_date && $end_date) {
|
|
|
+ $query->whereBetween('t.created_at', [strtotime($start_date), strtotime($end_date) + 86399]);
|
|
|
+ }
|
|
|
+
|
|
|
+ $data = $query->paginate([
|
|
|
+ 'page' => $page,
|
|
|
+ 'list_rows' => $list
|
|
|
+ ]);
|
|
|
+
|
|
|
+ $this->success('success', $data);
|
|
|
+ }
|
|
|
+
|
|
|
+ public function deleteThreadList()
|
|
|
+ {
|
|
|
+ $id = $this->request->post('id'); // 主键ID
|
|
|
+ if(!is_numeric($id)) {
|
|
|
+ $this->fail(500, '参数校验错误!');
|
|
|
+ }
|
|
|
+
|
|
|
+ $result = Db::table('tb_thread')
|
|
|
+ ->where('id', $id)
|
|
|
+ ->delete();
|
|
|
+
|
|
|
+ if ($result) {
|
|
|
+ $this->success('删除成功', null);
|
|
|
+ } else {
|
|
|
+ $this->fail(500, '删除失败');
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ public function getForumCategories()
|
|
|
+ {
|
|
|
+ $categories = Db::table('tb_forum_category')
|
|
|
+ ->field('id, name')
|
|
|
+ ->select()
|
|
|
+ ->toArray();
|
|
|
+
|
|
|
+ $this->success('success', $categories);
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+ // public function getOrderList()
|
|
|
+ // {
|
|
|
+ // $page = $this->request->post('page',1); // 当前页数
|
|
|
+ // $list = $this->request->post('list',10); // 每页记录数
|
|
|
+ // $key = $this->request->post('key'); // 搜索关键词 不传则不搜索
|
|
|
+ // if (!is_numeric($page) ||!is_numeric($list)) {
|
|
|
+ // $this->fail(500, '参数错误!');
|
|
|
+ // }
|
|
|
+ // $query = Db::table('tb_user_order');
|
|
|
+ // if($key){
|
|
|
+ // $query->whereLike('key', '%' . $key . '%');
|
|
|
+ // }
|
|
|
+ // $data = $query->paginate([
|
|
|
+ // 'page' => $page,
|
|
|
+ // 'list_rows' => $list
|
|
|
+ // ]);
|
|
|
+ // $this->success('success', $data);
|
|
|
+ // }
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+}
|