*/ 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->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['sdk_version'] = ['in',$game_ids]; unset($_REQUEST['sdk_version']); } } $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){ $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($data){ $data['novice'] = str_replace(array("\r\n", "\r", "\n"), ",", $_POST['novice']); $data['server_name']=get_server_name($data['server_id']); $data['novice_num'] = count(explode(',',$data['novice'])); $Model->add($data); $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){ $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($data){ $data['novice'] = str_replace(array("\r\n", "\r", "\n"), ",", $_POST['novice']); $data['novice_num'] = count(explode(',',$data['novice'])); $Model->save($data); $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.'失败'); } } }