Is_Login(); // 权限校验 $this->Is_Power(); //要执行的表 } /** * 活动列表 * @author Devil */ public function Index() { $List = M('activity_v2')->order('id desc')->select(); $this->assign('List', $List); $this->display('Index'); } /** * [SaveInfo 文章添加/编辑页面] * @author Devil * @blog http://gong.gg/ * @version 0.0.1 * @datetime 2016-12-14T21:37:02+0800 */ public function SaveInfo() { // 文章信息 // $this->display('test');die; if (empty($_REQUEST['id'])) { var_dump('从创建活动栏目中新建活动');die; } else { $data = M('activity_v2')->find(I('id')); $data['collect_list'] = json_decode($data['collect_list'],TRUE); $data['prize_list'] = json_decode($data['prize_list'],TRUE); $data['prize_rule'] = json_decode($data['prize_rule'],TRUE); // var_dump($data); if (empty($data)) { $data['id'] = I('id'); } } // 是否启用 $this->assign('common_is_enable_list', L('common_is_enable_list')); $this->assign('data', $data); $this->display($data['view']); } /** * [Save 文章添加/编辑] * @author Devil * @blog http://gong.gg/ * @version 0.0.1 * @datetime 2016-12-14T21:37:02+0800 */ public function Save() { $post = I('post.'); // var_dump($post);die; if (!IS_AjAX) { $this->error(L('common_unauthorized_access')); } $collect_length = count($post['collect_id']); if($collect_length){ for ($i=0;$i<=$collect_length-1;$i++){ $collects[] = [ 'collect_id'=>$post['collect_id'][$i], 'collect_name'=>$post['collect_name'][$i], 'collect_num'=>$post['collect_num'][$i], 'collect_probability'=>$post['collect_probability'][$i], 'collect_img'=>$post['collect_img'][$i], 'collect_status'=>$post['collect_status'][$i] ? :0, ]; } $collect_json = json_encode($collects,JSON_UNESCAPED_UNICODE|JSON_UNESCAPED_SLASHES); } $collect_json = $collect_json ? $collect_json : ''; $prize_length = count($post['prize_id']); if($prize_length){ for ($i=0;$i<=$prize_length-1;$i++){ $prizes[] = [ 'prize_id'=>$post['prize_id'][$i], 'prize_name'=>$post['prize_name'][$i], 'prize_num'=>$post['prize_num'][$i], 'prize_level'=>$post['prize_level'][$i], 'prize_img'=>$post['prize_img'][$i], 'prize_status'=>$post['prize_status'][$i] ? :0, 'prize_object'=>$post['prize_object'][$i] ]; } $prize_json = json_encode($prizes,JSON_UNESCAPED_UNICODE|JSON_UNESCAPED_SLASHES); } $prize_json = $prize_json ? $prize_json : ''; //中奖规则序列化 $rule_length = count($post['rule_id']); if($rule_length){ for ($i=0;$i<=$rule_length-1;$i++){ // var_dump($prize_name); $prize_id = explode('#', $post['rule_prize_name'][$i])[0]; $rules[] = [ 'rule_id'=>trim($post['rule_id'][$i]), 'rule_prize_id'=>trim($prize_id), 'rule_prize_name'=>trim($post['rule_prize_name'][$i]), 'rule_num'=>trim($post['rule_num'][$i]), 'rule_probability'=>trim($post['rule_probability'][$i]), 'rule_role'=>trim($post['rule_role'][$i]), 'rule_date'=>trim($post['rule_date'][$i]), 'rule_hour'=>trim($post['rule_hour'][$i]), 'rule_cycle'=>trim($post['rule_cycle'][$i]), 'rule_status'=>trim($post['rule_status'][$i]) ? : 0 ]; } $rule_json = json_encode($rules,JSON_UNESCAPED_UNICODE|JSON_UNESCAPED_SLASHES); } $rule_json = $rule_json ? $rule_json : ''; $data['activity_name'] = trim(I('activity_name')); $data['logic'] = trim(I('logic')); $data['is_enable'] = trim(I('is_enable')); $data['start_at'] = trim(I('start_at')); $data['end_at'] = trim(I('end_at')); $data['introduce'] = trim(I('introduce')); $data['is_test'] = trim(I('is_test')); $data['vip_chance'] = trim(I('vip_chance')); $data['novip_chance'] = trim(I('novip_chance')); $data['collect_list'] = $collect_json; $data['prize_list'] = $prize_json; $data['prize_rule'] = $rule_json; $data['view'] = trim(I('view')); $data['prize_log_table'] = trim(I('prize_log_table')); $data['checkvip_style'] = trim(I('checkvip_style')); // 添加 // var_dump($data);die; if ($id = I('id')) { $data['id'] = $id; $data['updated_at'] = date('Y-m-d H:i:s'); if (M('activity_v2')->save($data)) { $this->ajaxReturn('更新成功'); } else { $this->ajaxReturn('更新失败',400); } } else { $data['created_at'] = date('Y-m-d H:i:s'); $data['updated_at'] = date('Y-m-d H:i:s'); if ($bool=M('activity_v2')->add($data)) { $this->ajaxReturn('新增成功'); } else { echo M()->getLastSql(); $this->ajaxReturn('新增失败',400); } } } /** * [Delete 删除] * @author Devil * @blog http://gong.gg/ * @version 0.0.1 * @datetime 2016-12-15T11:03:30+0800 */ public function Delete() { // 是否ajax请求 if (!IS_AJAX) { $this->error(L('common_unauthorized_access')); } // 删除数据 if (I('id')) { // 更新 if (M('activity_v2')->delete(I('id'))) { $this->ajaxReturn(L('common_operation_delete_success')); } else { $this->ajaxReturn(L('common_operation_delete_error'), -100); } } else { $this->ajaxReturn(L('common_param_error'), -1); } } public function uploadFile($path, $name, $type) { $error = FileUploadError($name); if ($error !== true) { $this->ajaxReturn($error, -1); } if (!is_dir($path)) { mkdir(ROOT_PATH . $path, 0777, true); } $filename = \time() . '.'.$type; $home_site_logo = $path . $filename; if (move_uploaded_file($_FILES[$name]['tmp_name'], ROOT_PATH . $home_site_logo)) { return $_SERVER['SERVER_NAME'] . '/' . $home_site_logo; } } public function Uploader() { if($load_config = file_get_contents('UploadImageDir.config')){ $arr = json_decode($load_config,true); $path = $arr['prize'] ? : C('uploaderPrizeImg'); }else{ $path = C('uploaderPrizeImg'); } $uploader = D('Uploader'); if(I('get.model') == 'one'){ $uploader->Uploader($path); die; } $info = $uploader->Uploader($path); if ($info['state'] == 'SUCCESS') { $this->ajaxReturn($info['state'], 200); } else { $this->ajaxReturn($info['state'], 400); } } public function headCount() { if(empty(I('get.'))){ $this->display('export'); die; } $start_date = date('Y-m-d',strtotime(I('start_date'))); $end_date = date('Y-m-d 23:59:59',strtotime(I('end_date'))); // 文章信息 //vv $where['created_at'] = ['between',[$start_date,$end_date]]; $vv_data = M('prize_log_v2')->field('date(created_at) as date,count(*) as vv')->where($where)->group('date')->select(); $vvs= array_column($vv_data, 'vv','date'); //pv $where = []; $where['created_at'] = ['between',[$start_date,$end_date]]; $pv_data = M('iptv_user_login_log')->field('date(created_at) as date,count(*) as pv')->where($where)->group('date')->select(); // var_dump($pv_data);die; $pvs = array_column($pv_data, 'pv','date'); //uv $uv_data = M('iptv_user_login_log')->field('date(created_at) as date,count(distinct(uid)) as uv')->where($where)->group('date')->select(); $uvs = array_column($uv_data, 'uv','date'); $dates = getBetweenDates($start_date,$end_date); foreach ($dates['int'] as $date) { $date = date('Y-m-d',strtotime($date)); $return_data[] = ['date'=>$date,'pv'=>$pvs[$date] ?:0,'uv'=>$uvs[$date]?:0,'vv'=>$vvs[$date]]; } $title = array( 'date' => array('col' => 'A', 'name' => 'date'), 'pv' => array('col' => 'B', 'name' => 'pv'), 'uv' => array('col' => 'C', 'name' => 'uv'), 'vv' => array('col' => 'D', 'name' => 'vv'), ); // Excel驱动导出数据 $excel = new \My\Excel(array('filename' => '芒果电信运营数据', 'title' => $title, 'data' => $return_data, 'msg' => L('common_not_data_tips'))); $excel->Export(); } }