初始化代码

This commit is contained in:
2025-08-11 10:22:05 +08:00
commit ebd8d85201
4206 changed files with 753018 additions and 0 deletions

View File

@@ -0,0 +1,77 @@
<?php
namespace app\anchor\controller;
use think\Controller;
use think\captcha\Captcha;
use think\DB;
class Apip extends Controller
{
public function initialize()
{
header('Access-Control-Allow-Origin: *');
add_operation(3, 0); //用户行为日志
}
public function login()
{
$captcha = input('captcha');
$username = input('username');
$password = input('password');
if (empty($captcha)) {
return ajaxReturn(201, '验证码不能为空');
}
// if (!captcha_check($captcha)) {
// // 验证失败
// return ajaxReturn(201, '验证码错误');
// }
if (empty($username)) {
return ajaxReturn(201, '用户名不能为空');
}
if (empty($password)) {
return ajaxReturn(201, '密码不能为空');
}
$map = [];
$map[] = ['user_name', '=', $username];
$map[] = ['password', '=', md5($password)];
$info = db::name('user')->where($map)->find();
if (empty($info)) {
return ajaxReturn(201, '用户名不存在');
} else {
if (md5($password) != $info['password']) {
return ajaxReturn(201, '密码错误');
}
if ($info['is_anchor'] != 2) {
return ajaxReturn(201, '普通用户无法登录');
}
$login_token = generateRandom(32);
$login_token = $info['login_token']; //防止用户APP掉线 此处不更新登录token
$data = [];
$data['uid'] = $info['uid'];
$data['login_token'] = $login_token;
$data['update_time'] = time();
$reslut = db::name('user')->update($data);
if (!$reslut) {
return ajaxReturn(201, '登录失败', '');
} else {
return ajaxReturn(200, '登录成功', $login_token);
}
}
}
public function verify()
{
$config = [
'codeSet' => '0123456789',
// 验证码字体大小
'fontSize' => 30,
// 验证码位数
'length' => 4,
// 关闭验证码杂点
'useNoise' => false,
];
$captcha = new Captcha($config);
return $captcha->entry();
}
}

View File

@@ -0,0 +1,51 @@
<?php
namespace app\anchor\controller;
use think\Controller;
use think\Request;
use think\DB;
class Capital extends Common
{
//获取房间流水 列表
public function room_money_log()
{
$rid = -1;
$room_info = Db::name("room")->where(array("room_owner_uid" => $this->uid))->find();
if (!empty($room_info)) {
$rid = $room_info['rid'];
}
$room_number = 0;
$room_name = '';
$time1 = input('time1', '');
$time2 = input('time2', 0);
$order = input('order', 'a.sid');
$sort = input('sort', 'desc');
$page = input('page', 1);
$limit = input('limit', 20);
$reslut = model('admin/Capital')->room_money_log($rid, $room_number, $room_name, $time1, $time2, $order, $sort, $page, $limit);
$data = [];
$data['code'] = 0;
$data['msg'] = '获取成功';
$data['count'] = $reslut['data']['count'];
$data['data'] = $reslut['data']['list'];
$data['totalRow'] = $reslut['data']['totalRow'];
return json($data);
}
//获取资金改变类型
public function get_change_type()
{
$data = model('admin/UserMoneyLog')->ChangeTypeLable();
return ajaxReturn(200, '', $data);
}
//获取资金类型
public function get_money_type()
{
$data = model('admin/UserMoneyLog')->MoneyTypeLable();
return ajaxReturn(200, '', $data);
}
}

View File

@@ -0,0 +1,37 @@
<?php
namespace app\anchor\controller;
use think\Controller;
use think\Request;
use think\Db;
class Common extends Controller
{
public $uid;
public function initialize()
{
header('Access-Control-Allow-Origin: *');
// ajaxReturn(301, '系统维护');
$login_token = input('login_token', 0);
$reslut = model('User')->check_login_token($login_token);
if ($reslut['code'] == 201) {
return ajaxReturn(301, $reslut['msg'], $reslut['data']);
} else {
$this->uid = $reslut['data'];
}
add_operation(3, $this->uid); //用户行为日志
}
public function check_login_status()
{
$user_name = Db::name("user")->where(array("uid" => $this->uid))->value("user_name");
$data['data'] = $user_name;
ajaxReturn(1, '登录成功', $data);
}
public function get_menu_list()
{
$data = model('SystemMenu')->getSystemInit($this->uid);
return json($data);
}
}

View File

@@ -0,0 +1,10 @@
<?php
namespace app\anchor\model;
use think\Model;
class Capital extends Model
{
//
}

View File

@@ -0,0 +1,63 @@
<?php
namespace app\anchor\model;
use think\Db;
use think\Model;
class SystemMenu extends Model
{
// 获取初始化数据
public function getSystemInit($aid = 0)
{
$homeInfo = [
'title' => '首页',
'href' => '',
];
$logoInfo = [
'title' => '系统 管理',
'image' => 'images/logo.png',
];
$menuInfo = $this->getMenuList($aid);
$systemInit = [
'homeInfo' => $homeInfo,
'logoInfo' => $logoInfo,
'menuInfo' => $menuInfo,
];
return $systemInit;
}
// 获取菜单列表
private function getMenuList($aid)
{
$menuList = Db::name('system_menu_anchor')
->field('id,pid,title,icon,href,target')
->where('status', 1)
->where('type', 'in', [1, 2])
->order('sort', 'desc')
->select();
$menuList = $this->buildMenuChild(0, $menuList);
return $menuList;
}
//递归获取子菜单
private function buildMenuChild($pid, $menuList)
{
$treeList = [];
foreach ($menuList as &$v) {
if ($pid == $v['pid']) {
$node = $v;
$child = $this->buildMenuChild($v['id'], $menuList);
if (!empty($child)) {
$node['child'] = $child;
}
// todo 后续此处加上用户的权限判断
$treeList[] = $node;
}
}
return $treeList;
}
}

View File

@@ -0,0 +1,24 @@
<?php
namespace app\anchor\model;
use think\Model;
use think\DB;
class User extends Model
{
public function check_login_token($login_token)
{
if (empty($login_token)) {
return ['code' => 201, 'msg' => '登录失效', 'data' => ''];
}
$map = [];
$map[] = ['login_token', '=', $login_token];
$user_info = db::name('user')->where($map)->find();
if (empty($user_info)) {
return ['code' => 201, 'msg' => '登录失效', 'data' => ''];
} else {
return ['code' => 200, 'msg' => '登录成功', 'data' => $user_info['uid']];
}
}
}