后台
This commit is contained in:
242
app/czg/controller/SysController.php
Normal file
242
app/czg/controller/SysController.php
Normal file
@@ -0,0 +1,242 @@
|
||||
<?php
|
||||
|
||||
namespace app\czg\controller;
|
||||
|
||||
use app\api\model\Msg;
|
||||
use app\common\controller\Backend;
|
||||
use app\common\facade\Token;
|
||||
use app\common\library\DatabaseRoute;
|
||||
use think\facade\Db;
|
||||
use think\Http;
|
||||
|
||||
class SysController extends Backend
|
||||
{
|
||||
protected array $noNeedLogin = ['*'];
|
||||
public function login()
|
||||
{
|
||||
$data = $this->request->post();
|
||||
if(empty($data['username']) || empty($data['password']) || empty($data['uuid']) || empty($data['captcha']) || empty($data['adminType'])){
|
||||
$this->n_error('参数不完整');
|
||||
}
|
||||
$uuid = $data['uuid'];
|
||||
$connect = Db::connect(get_slave_connect_name());
|
||||
$captcha = $connect->name('sys_captcha')->where(['uuid' => $uuid, 'code' => $data['captcha']])->find();
|
||||
if(!$captcha) {
|
||||
$this->n_error('验证码错误', [], 500);
|
||||
}
|
||||
$ext_time = strtotime($captcha['expire_time']);
|
||||
if(time() > $ext_time) {
|
||||
$this->n_error('验证码已经过期', [], 500);
|
||||
}
|
||||
$res = $this->auth->login($data['username'], $data['password']);
|
||||
if (isset($res) && $res === true) {
|
||||
$user = $this->auth->getAdmin();
|
||||
if($data['adminType'] == 1 && $user['is_channel'] != null && $user['is_channel'] == 1) {
|
||||
$this->n_error('代理账号请登录代理端', [], 500);
|
||||
}
|
||||
if($data['adminType'] == 2 && $user['is_channel'] == null) {
|
||||
$this->n_error('管理员请登录管理端', [], 500);
|
||||
}
|
||||
$this->n_success([
|
||||
'token' => $this->auth->getToken()
|
||||
]);
|
||||
} else {
|
||||
$msg = $this->auth->getError();
|
||||
$msg = $msg ?: __('Check in failed, please try again or contact the website administrator~');
|
||||
$this->n_error($msg);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 管理员注销
|
||||
* @return void
|
||||
*/
|
||||
public function logout(): void
|
||||
{
|
||||
if ($this->request->isPost()) {
|
||||
$refreshToken = $this->request->post('refreshToken', '');
|
||||
if ($refreshToken) Token::delete((string)$refreshToken);
|
||||
$this->auth->logout();
|
||||
$this->success();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* 邀请好友奖励分页
|
||||
* @return void
|
||||
*/
|
||||
public function invitefriendaward()
|
||||
{
|
||||
$params = $this->request->get();
|
||||
$subQuery = DatabaseRoute::getAllDbData('user_money_details', function ($query) use ($params) {
|
||||
return $query->field('user_id, SUM(money) as awardAmount, SUM(IF(title = "签到奖励", 1, 0)) as signInNum')
|
||||
->where('classify', 6)->group('user_id');
|
||||
})->buildSql();
|
||||
|
||||
$result = DatabaseRoute::paginateAllDb('tb_user', function ($query) use ($subQuery , $params) {
|
||||
$query->alias('t1')
|
||||
->field([
|
||||
't1.user_id as userId',
|
||||
't1.user_name as userName',
|
||||
't1.phone',
|
||||
't1.avatar',
|
||||
'IFNULL(t2.signInNum, 0) as signInNum',
|
||||
'IFNULL(t2.awardAmount, 0) as awardAmount'
|
||||
])
|
||||
->leftJoin("{$subQuery} t2", 't1.user_id = t2.user_id');
|
||||
if(!empty($params['keywords'])) {
|
||||
$query->where('t1.user_name', $params['keywords'])->whereOr('t1.phone', $params['keywords']);
|
||||
}
|
||||
$query->order('t2.signInNum', 'desc');
|
||||
$query->order('t1.user_id', 'asc');
|
||||
return $query;
|
||||
}, (int)$params['page'], (int)$params['limit']);
|
||||
$this->n_success(['data' => $result]);
|
||||
}
|
||||
/**
|
||||
* 奖励详情
|
||||
* @return void
|
||||
*/
|
||||
public function invitefrienddetail()
|
||||
{
|
||||
$params = $this->request->get();
|
||||
$userId = $params['userId'];
|
||||
$result = DatabaseRoute::paginateAllDb('user_money_details', function ($query) use ($params, $userId) {
|
||||
$query->alias('t1')
|
||||
->field([
|
||||
't1.by_user_id AS userId',
|
||||
't1.money AS amount',
|
||||
't2.phone AS userPhone',
|
||||
't1.create_time AS createTime'
|
||||
])
|
||||
->leftJoin('tb_user t2', 't1.by_user_id = t2.user_id')
|
||||
->where('t1.user_id', $userId)
|
||||
->where('t1.classify', 6)
|
||||
->whereNotNull('t1.by_user_id')
|
||||
->whereNotNull('t2.user_id')
|
||||
->order('t1.create_time', 'desc')
|
||||
->order('t1.by_user_id', 'asc');
|
||||
return $query;
|
||||
}, (int)$params['page'], (int)$params['limit'], 'createTime');
|
||||
$this->successWithData($result);
|
||||
}
|
||||
|
||||
/**
|
||||
* 邀请好友奖励-签到人数分页
|
||||
* @return void
|
||||
*/
|
||||
public function signindetailpage()
|
||||
{
|
||||
$params = $this->request->get();
|
||||
$userId = $params['userId'];
|
||||
// 先获取总数
|
||||
$count = DatabaseRoute::getAllDbData('user_money_details', function ($query) use($userId) {
|
||||
return $query->alias('t')
|
||||
->field('t.by_user_id')
|
||||
->where('t.user_id', $userId)
|
||||
->where('t.classify', 6)
|
||||
->where('t.title', '签到奖励')
|
||||
->group('t.by_user_id');
|
||||
})->count();
|
||||
$v_db_name = config('database.connections.' . get_slave_connect_name() . '.database');
|
||||
$result = DatabaseRoute::paginateAllDbBySqlAutoCount(function () use($userId, $v_db_name) {
|
||||
return "select
|
||||
t1.by_user_id as userId,
|
||||
t1.createTime,
|
||||
t2.user_name as userName,
|
||||
t2.phone,
|
||||
t3.cert_name as realName,
|
||||
t3.cert_no as idCardNo,
|
||||
t3.bank_name as bankName,
|
||||
t3.account_no as bankCardNo,
|
||||
t3.mobile,
|
||||
t3.province,
|
||||
t3.city,
|
||||
t3.bank_branch as bankBranch
|
||||
from (
|
||||
SELECT
|
||||
t.by_user_id,
|
||||
MIN( t.create_time ) as createTime
|
||||
FROM
|
||||
" . $v_db_name . ".v_user_money_details t
|
||||
WHERE 1=1
|
||||
AND t.user_id = ".$userId."
|
||||
AND t.classify = 6
|
||||
AND t.title = '签到奖励'
|
||||
GROUP BY t.by_user_id
|
||||
) t1
|
||||
LEFT JOIN " . $v_db_name . ".v_tb_user t2 on t1.by_user_id = t2.user_id
|
||||
LEFT JOIN " . $v_db_name . ".v_user_info t3 on t1.by_user_id = t3.user_id
|
||||
order by t1.createTime desc,t1.by_user_id asc";
|
||||
}, $params['page'], $params['limit'], null, $count);
|
||||
$this->successWithData($result);
|
||||
}
|
||||
|
||||
/**
|
||||
* 抽奖次数查询-分页
|
||||
* @return void
|
||||
*/
|
||||
public function lotterypage()
|
||||
{
|
||||
$params = $this->request->get();
|
||||
$keywords = $params['keywords'];
|
||||
$v_db_name = config('database.connections.' . get_slave_connect_name() . '.database');
|
||||
$result = DatabaseRoute::paginateAllDb('tb_user', function ($query) use($keywords, $v_db_name) {
|
||||
return $query->alias('t1')
|
||||
->field([
|
||||
't1.user_id as userId',
|
||||
't1.avatar',
|
||||
't1.user_name as userName',
|
||||
't1.phone',
|
||||
// 今日解锁订单数
|
||||
'(SELECT COUNT(1) FROM '. $v_db_name .'.v_orders WHERE STATUS = 1 AND pay_way = 9 AND user_id = t1.user_id AND pay_time >= DATE_FORMAT(CURDATE(), "%Y-%m-%d 00:00:00") AND pay_time <= DATE_FORMAT(CURDATE(), "%Y-%m-%d 23:59:59")) as todayUnlocked',
|
||||
// 今日抽奖次数
|
||||
'(SELECT COUNT(1) FROM '. $v_db_name .'.v_disc_spinning_record WHERE user_id = t1.user_id AND DATE_FORMAT(create_time, "%Y-%m-%d") = CURDATE()) as todayDrawCount'
|
||||
])
|
||||
->where(function ($query) use ($keywords) {
|
||||
$query->where('t1.user_name', $keywords)
|
||||
->whereOr('t1.phone', $keywords);
|
||||
})
|
||||
->order('todayUnlocked', 'desc')
|
||||
->order('t1.user_id', 'asc');
|
||||
}, $params['page'], $params['limit']);
|
||||
|
||||
$this->n_success(['data' => $result]);
|
||||
}
|
||||
|
||||
/**
|
||||
* 抽奖详情-分页
|
||||
* @return void
|
||||
*/
|
||||
public function lotterydetailpage()
|
||||
{
|
||||
$params = $this->request->get();
|
||||
$userId = $params['userId'];
|
||||
// 先获取总数
|
||||
$count = Db::connect(get_slave_connect_name())->query("select
|
||||
count(*) count
|
||||
from v_disc_spinning_record t1
|
||||
where t1.user_id = ".$userId);
|
||||
$count = $count[0]['count'];
|
||||
$v_db_name = config('database.connections.' . get_slave_connect_name() . '.database');
|
||||
$result = DatabaseRoute::paginateAllDbBySqlAutoCount(function () use($userId, $v_db_name) {
|
||||
return "select
|
||||
t1.id,
|
||||
t1.name,
|
||||
t1.number,
|
||||
t1.create_time
|
||||
from ". $v_db_name .".v_disc_spinning_record t1
|
||||
where t1.user_id = " . $userId . "
|
||||
order by t1.id desc";
|
||||
}, $params['page'], $params['limit'], null, $count);
|
||||
$this->successWithData($result);
|
||||
}
|
||||
|
||||
// 发送验证码
|
||||
public function sendMsg()
|
||||
{
|
||||
$get = $this->request->get();
|
||||
return $this->ApiDataReturn(Msg::sendMsg($get['phone'], $get['event']));
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user