You cannot select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

286 lines
10 KiB
PHP

<?php
namespace Admin\Controller;
use User\Api\UserApi as UserApi;
/**
* 后台首页控制器
* @author 麦当苗儿 <zuojiazi@vip.qq.com>
*/
class GiftbagController extends ThinkController {
const model_name = 'Giftbag';
public function lists(){
$extend = array('key'=>'gift_name');
if(isset($_REQUEST['timestart'])&&isset($_REQUEST['timeend'])){
$extend['create_time'] =array('BETWEEN',array(strtotime($_REQUEST['timestart']),strtotime($_REQUEST['timeend'])+24*60*60-1));
unset($_REQUEST['timestart']);unset($_REQUEST['timeend']);
}elseif(isset($_REQUEST['timestart'])){
$extend['create_time']=array('egt',strtotime($_REQUEST['timestart']));
unset($_REQUEST['timestart']);
}elseif(isset($_REQUEST['timeend'])){
$extend['create_time']=array('elt',strtotime($_REQUEST['timeend'])+24*60*60-1);
unset($_REQUEST['timeend']);
}
if(isset($_REQUEST['game_name'])){
if($_REQUEST['game_name']=='全部'){
unset($_REQUEST['game_name']);
}else{
$extend['game_name']=$_REQUEST['game_name'];
unset($_REQUEST['game_name']);
}
}
if(isset($_REQUEST['giftbag_name'])){
$extend['giftbag_name']=array('like','%'.$_REQUEST['giftbag_name'].'%');
unset($_REQUEST['giftbag_name']);
}
if(isset($_REQUEST['status'])){
if($_REQUEST['status']=='全部'){
unset($_REQUEST['status']);
}else{
$extend['status']=$_REQUEST['status'];
unset($_REQUEST['status']);
}
}
if(isset($_REQUEST['giftbag_version'])){
if($_REQUEST['giftbag_version']=='全部'){
unset($_REQUEST['giftbag_version']);
}else{
$extend['giftbag_version']=$_REQUEST['giftbag_version'];
unset($_REQUEST['giftbag_version']);
}
}
if(isset($_REQUEST['developers'])){
$extend['developers']=$_REQUEST['developers'];
unset($_REQUEST['developers']);
}
if($_GET['type'] == 1 || empty($_GET['type'])){
$extend['developers'] = array('EQ',0);
}else{
$extend['developers'] = array('NEQ',0);
$this->assign('show_status',1);
}
$extend['for_show_pic_list']='novice';
$this->checkListOrCountAuthRestMap($map,[]);
$this->m_title = '礼包列表';
$this->assign('commonset',M('Kuaijieicon')->where(['url'=>'Giftbag/lists','status'=>1])->find());
parent::order_lists2(self::model_name,$_GET["p"],['where'=>$extend,'order'=>'create_time desc']);
}
public function record(){
if(isset($_REQUEST['game_name'])){
$extend['game_name']=trim($_REQUEST['game_name']);
unset($_REQUEST['game_name']);
}
if (isset($_REQUEST['user_account'])) {
$extend['user_account']=array('like','%'.trim($_REQUEST['user_account']).'%');
unset($_REQUEST['user_account']);
}
if(isset($_REQUEST['sdk_version'])){
if($_REQUEST['sdk_version'] ==''){
unset($_REQUEST['sdk_version']);
}else{
$map['sdk_version'] = $_REQUEST['sdk_version'];
$game_ids = M('game','tab_')->field('id')->where($map)->select();
$game_ids = array_column($game_ids,'id');
$extend['game_id'] = ['in',$game_ids];
unset($_REQUEST['sdk_version']);
}
}
$this->checkListOrCountAuthRestMap($map,[]);
$this->m_title = '礼包领取记录';
$this->assign('commonset',M('Kuaijieicon')->where(['url'=>'Giftbag/record','status'=>1])->find());
parent::lists('GiftRecord',$_GET["p"],$extend);
}
public function add(){
if(IS_POST){
if ($_POST['giftbag_version'] == '3') {
$whereGift['giftbag_version'] = $_POST['giftbag_version'];
$whereGift['game_id'] = $_POST['game_id'];
$_POST['start_time'] = time();
$giftData = D('giftbag')->field('id')->where($whereGift)->find();
if ($giftData) {
$this->error('超级签礼包一个游戏只能有一个!');
}
}
$Model = D('Giftbag');
// 获取模型的字段信息
$Model = $this->checkAttr($Model,$model['id']);
if(empty($_REQUEST['game_id'])){
$this->error('请输选择游戏');
}
if($_REQUEST['end_time']!=''){
if(strtotime($_REQUEST['start_time'])>strtotime($_REQUEST['end_time'])){
$this->error('请输入正确开始结束时间');
}
}
$data = $Model->create();
if ($_POST['giftbag_version'] == '3') {
$data['start_time'] = time();
}
// var_dump($data);die();
if($data){
$data['novice'] = str_replace(array("\r\n", "\r", "\n"), ",", $_POST['novice']);
$noviceList = explode(',', $data['novice']);
$noviceList = array_filter($noviceList, function ($value) {
return $value != '';
});
$data['novice'] = implode(',', $noviceList);
$data['server_name']=get_server_name($data['server_id']);
$data['novice_num'] = count(explode(',',$data['novice']));
$Model->add($data);
addOperationLog(array(
"op_type"=>0,
"key"=>$data['game_name']."/".$data['giftbag_name'],
"url"=>U("Giftbag/lists",array("giftbag_name"=>$data['giftbag_name']))
));
$this->success('添加礼包成功!', U('lists?model='.$model['name']));
} else {
$this->error($Model->getError());
}
} else {
$this->meta_title = '新增礼包';
$this->m_title = '礼包列表';
$this->assign('commonset',M('Kuaijieicon')->where(['url'=>'Giftbag/lists','status'=>1])->find());
$this->display('add');
}
}
public function edit($id=0){
$_REQUEST['id'] || $this->error('请选择要编辑的用户!');
$model = M('Model')->getByName(self::model_name); /*通过Model名称获取Model完整信息*/
//获取模型信息
$model = M('Model')->find($model['id']);
$model || $this->error('模型不存在!');
if(IS_POST){
if ($_POST['giftbag_version'] == '3') {
$_POST['start_time'] = time();
}
$Model = D(parse_name(get_table_name($model['id']),1));
// 获取模型的字段信息
$Model = $this->checkAttr($Model,$model['id']);
if(empty($_REQUEST['game_id'])){
$this->error('请输选择游戏');
}
if($_REQUEST['end_time']!=''){
if(strtotime($_REQUEST['start_time'])>strtotime($_REQUEST['end_time'])){
$this->error('请输入正确开始结束时间');
}
}
$data = $Model->create();
if ($_POST['giftbag_version'] == '3') {
$data['start_time'] = time();
}
if($data){
$data['novice'] = str_replace(array("\r\n", "\r", "\n"), ",", $_POST['novice']);
$noviceList = explode(',', $data['novice']);
$noviceList = array_filter($noviceList, function ($value) {
return $value != '';
});
$data['novice'] = implode(',', $noviceList);
$data['novice_num'] = count(explode(',',$data['novice']));
$Model->save($data);
addOperationLog(array(
"op_type"=>1,
"key"=>$data['game_name']."/".$data['giftbag_name'],
"url"=>U("Giftbag/lists",array("giftbag_name"=>$data['giftbag_name']))
));
$this->success('保存'.$model['title'].'成功!', U('lists',array('model'=>$model['name'],'type'=>$_REQUEST['type'])));
} else {
$this->error($Model->getError());
}
} else {
$fields = get_model_attribute($model['id']);
//获取数据
$data = D(get_table_name($model['id']))->find($id);
$data || $this->error('数据不存在!');
$this->assign('model', $model);
$this->assign('fields', $fields);
$this->assign('data', $data);
$this->meta_title = '编辑礼包';
$this->m_title = '礼包列表';
$this->assign('commonset',M('Kuaijieicon')->where(['url'=>'Giftbag/lists','status'=>1])->find());
$this->display($model['template_edit']?$model['template_edit']:'');
}
}
public function del($model = null, $ids=null){
$model = M('Model')->getByName(self::model_name); /*通过Model名称获取Model完整信息*/
parent::del($model["id"],$ids);
}
public function get_ajax_area_list(){
$area = D('Server');
$map['game_id'] = I('post.game_id',1);
$list = $area->where($map)->select();
$this->ajaxReturn($list);
}
/**
* 礼包状态修改
* @author 鹿文学
*/
public function change_status($field = null,$value=null) {
$id = array_unique((array)I('ids', 0));
$id = is_array($id) ? implode(',', $id) : $id;
if (empty($id)) {
$this->error('请选择要操作的数据!');
}
$map['id'] = array('in', $id);
$giftmodel = D(self::model_name);
$gift = $giftmodel->where($map)->find();
//开发者礼包
if($gift['developers'] > 0){
if($gift['apply_status'] < 1){
$this->error('未审核的礼包不能设置礼包状态');
}
$save[$field] = $value;
$result = $giftmodel->where($map)->save($save);
}else{
$result = $giftmodel->where($map)->setField($field,$value);
}
$msg = "操作";
if($result !== false){
$this->success($msg.'成功');
}else{
$this->error($msg.'失败');
}
}
}