113 lines
4.1 KiB
PHP
113 lines
4.1 KiB
PHP
<?php
|
|
|
|
namespace app\admin\controller;
|
|
|
|
use think\Db;
|
|
use think\Request;
|
|
|
|
class Tip extends Common{
|
|
public function index(){
|
|
// 接收分页的条件
|
|
$get = Request::instance()->get();
|
|
$query = http_build_query($get);
|
|
$this->assign('get',$get);
|
|
$this->assign('query',$query);
|
|
|
|
//接收搜索的条件信息
|
|
$username = Request::instance()->get('username');
|
|
$export = Request::instance()->get('export');
|
|
// 拼装搜索条件
|
|
$where = array();
|
|
if(!empty($username)) $where['username'] = $username;
|
|
if($export == 1){
|
|
$tip_list = Db::name('tip')->where($where)->order('id desc')->select();
|
|
}else{
|
|
//获取所有代理信息
|
|
$tip_list = Db::name('tip')->where($where)->order('id desc')->paginate(15,false,array('query'=>$get));
|
|
}
|
|
foreach ($tip_list as $k => $v) {
|
|
$v['create_time'] = date("Y-m-d H:i",$v['create_time']);
|
|
$tip_list[$k] = $v;
|
|
}
|
|
//导出excel列表
|
|
if($export == 1){
|
|
if($tip_list){
|
|
//重新组合
|
|
$excelData = array();
|
|
foreach($tip_list AS $k => $v){
|
|
$excelData[$k][0] = $v['user_id'];
|
|
$excelData[$k][1] = $v['username'];
|
|
$excelData[$k][2] = $v['table_id'];
|
|
$excelData[$k][3] = $v['table_name'];
|
|
$excelData[$k][4] = $v['create_time'];
|
|
$excelData[$k][5] = $v['money'];
|
|
}
|
|
$title = array('用户ID','用户账号','桌子ID','桌子名称','打赏时间','打赏金额');
|
|
$this->exportExcelCore($excelData, '打赏列表', $title);
|
|
exit('已导出支持列表,请不要重复刷新该页面!');
|
|
}else{
|
|
exit('没有可以导出的列表!');
|
|
}
|
|
}
|
|
// 渲染参数和模板
|
|
$this->assign('tip_list',$tip_list);
|
|
return $this->fetch();
|
|
}
|
|
|
|
public function optimum(){
|
|
$optimum_list = Db::name('optimum')->order('win_money desc')->select();
|
|
$this->assign('optimum_list',$optimum_list);
|
|
return $this->fetch();
|
|
}
|
|
public function do_add_optimum(){
|
|
// 接收提交过来的数据
|
|
$username = Request::instance()->post('username');
|
|
$win_money = Request::instance()->post('win_money');
|
|
if( !isset($username) && empty($username) ){
|
|
die(json_encode(['code'=>0,'msg'=>'账户名不能为空!']));
|
|
}
|
|
if( !isset($win_money) && empty($win_money) ){
|
|
die(json_encode(['code'=>0,'msg'=>'赢钱金额不能为空!']));
|
|
}
|
|
// 拼装数据
|
|
$data = array();
|
|
$data['username'] = $username;
|
|
$data['win_money'] = $win_money;
|
|
$insert_id = Db::name('optimum')->insertGetId($data);
|
|
if($insert_id){
|
|
die(json_encode(['code'=>1,'msg'=>'添加成功!']));
|
|
}else{
|
|
die(json_encode(['code'=>0,'msg'=>'添加失败!']));
|
|
}
|
|
}
|
|
public function do_edit_optimum(){
|
|
if(Request::instance()->post()){
|
|
|
|
// 接收提交过来的数据
|
|
$id = Request::instance()->post('edit_id');
|
|
$username = Request::instance()->post('username');
|
|
$win_money = Request::instance()->post('win_money');
|
|
// 数据验证
|
|
if( !isset($username) && empty($username) ){
|
|
die(json_encode(['code'=>0,'msg'=>'用户账户不能为空!']));
|
|
}
|
|
if( !isset($win_money) && empty($win_money) ){
|
|
die(json_encode(['code'=>0,'msg'=>'赢钱金额不能为空!']));
|
|
}
|
|
|
|
// 拼装数据
|
|
$data = array();
|
|
$data['username'] = $username;
|
|
$data['win_money'] = $win_money;
|
|
|
|
$insert_id = Db::name('optimum')->where('id',$id)->update($data);
|
|
if($insert_id){
|
|
die(json_encode(['code'=>1,'msg'=>'修改成功!']));
|
|
}else{
|
|
die(json_encode(['code'=>0,'msg'=>'修改失败!']));
|
|
}
|
|
}else{
|
|
die(json_encode(['code'=>0,'msg'=>'操作错误!']));
|
|
}
|
|
}
|
|
} |