objLottery = new Lottery (); $this->operatorData = $this->getUser (); # 能在当前页面显示的活动 $this->showActivityTypeArr = array( LotteryEvents::TYPE_EVENTS_TURNTABLE, LotteryEvents::TYPE_EVENTS_SCRATCH, LotteryEvents::TYPE_EVENTS_LETTERS, LotteryEvents::TYPE_EVENTS_TRY, LotteryEvents::TYPE_EVENTS_VOTE, LotteryEvents::TYPE_EVENTS_INVITATION, LotteryEvents::TYPE_EVENTS_CODE, LotteryEvents::TYPE_EVENTS_OTHER, LotteryEvents::TYPE_EVENTS_CUT_SCREEN, LotteryEvents::TYPE_EVENTS_ARTICLE ); $events_id = isset($_REQUEST['events_id'])?$_REQUEST['events_id'] : null; if($events_id){ $this->setNowUpPage($events_id, 'Page'); } } /** * 默认 */ public function doDefault() {} /** * 页面: 显示&修改 * 地址:http://cas.lishuy.com/?c=Admin_Activity_SetPage&a=PageShow&events_id=nnn * 参数: events_id 活动ID */ public function doPageShow() { $events_id = Request::g ( 'events_id' ); $events_Data = $this->objLottery->getOneLotteryEventsAndPrize ( $events_id ); // 载入修改页面需要用到的配置 $eventsTopData = LotteryEvents::getTopData (); // // [活动] $eventsBuyButton = LotteryEvents::getBuyButton (); // // [活动] $eventsShareButton = LotteryEvents::getShareButton (); // // [活动] 是否显示分享按钮 $eventsDeliveryType = LotteryEvents::getDeliveryType (); // // [活动] 发货状态 $eventsAuthorize = LotteryEvents::getAuthorize (); // [活动] 授权 $eventsDisplayStatus = LotteryEvents::getDisplay (); // [活动] 是否显示 $eventsTwoDimensionalCodeType = LotteryEvents::getTwoDimensionalCodeType (); // [领券活动] 是否是二维码输出 类型 $eventsTypeData = LotteryEvents::getType (); // [活动] 类型 $eventsBigTypeConfig = LotteryEvents::getBigTypeConfig (); // [活动] 大类 $eventsFormRegular = $this->formRegular (); // [活动] 表单 $prizeDisplay = LotteryPrize::getDisplay (); // [奖项] 显示状态 $prizeExpress = LotteryPrize::getExpress (); // [奖项] 是否需要快递 $prizeType = LotteryPrize::getType (); // [奖项] 类型 $this->setOutput ( 'eventsTopData', $eventsTopData ); $this->setOutput ( 'eventsBuyButton', $eventsBuyButton ); $this->setOutput ( 'eventsShareButton', $eventsShareButton ); $this->setOutput ( 'eventsDeliveryType', $eventsDeliveryType ); $this->setOutput ( 'eventsAuthorize', $eventsAuthorize ); $this->setOutput ( 'eventsDisplayStatus', $eventsDisplayStatus ); $this->setOutput ( 'eventsTwoDimensionalCodeType', $eventsTwoDimensionalCodeType ); $this->setOutput ( 'eventsTypeData', $eventsTypeData ); $this->setOutput ( 'eventsBigTypeConfig', $eventsBigTypeConfig ); $this->setOutput ( 'eventsFormRegular', $eventsFormRegular ); $this->setOutput ( 'prizeDisplay', $prizeDisplay ); $this->setOutput ( 'prizeExpress', $prizeExpress ); $this->setOutput ( 'prizeType', $prizeType ); $this->setOutput('events_Data', $events_Data); $this->setOutput('eventData', $events_Data['events']); $this->setOutput('typeData', $eventsTypeData); $this->setOutput('displayDesc', LotteryEvents::getDisplay()); $pageDatas = $disData = array(); if(isset($events_Data['events']['pageData'])){ foreach ($events_Data['events']['pageData'] as $tmpKey => $tmpItem) { $pageDatas[] = json_encode($tmpItem); $disData[$tmpKey] = $tmpItem; } } $this->setOutput('pageDatas', $pageDatas); $this->setOutput('pageData_json', $disData ? json_encode($disData) : '{}'); $this->setOutput('count_num_page', count($disData)); if ($events_Data['events']['pageData']) { $pageData = $this->getPageData($events_Data['events']['pageData'], 2.9); } $this->setOutput('pageData', $pageData); $navConfig = $this->getUpPageNav($events_id, 'Page'); switch (LotteryEvents::getBigType($events_Data['events']['type'])) { case 'H5': $this->tpl = 'admin/activity/setPage_h5'; break; case 'Event': $this->tpl = 'admin/activity/setPage_event'; break; case 'Article': $this->tpl = 'admin/activity/setPage_article'; break; default: $this->tpl = 'admin/activity/setPage_event'; } $title = '页面制作'; $this->setOutput('title', $title); $this->setOutput('menu_active', array('name' => 'mypublish', 'item' => '')); //激活菜单 $this->addNavMenu('活动列表'); $this->addNavMenu($title); $this->setOutput ( 'navConfig', $navConfig );// 导航 显示 URL 配置 $this->setOutput('pagePublicData', $this->getPagePublicData($events_id)); // 后台管理相关数据 } /** * 活动页面常规设置 * 事件:修改常规页面 * 地址:http://cas.lishuy.com/?c=Admin_Activity_SetPage&a=ReqUpRoutine * 参数:见方法内 */ public function doReqUpRoutine(){ $events_id = Request::p ( 'events_id' ); $events_Data = $this->objLottery->getOneLotteryEventsAndPrize ( $events_id ); // 正文介绍内容 events_tips // 活动规则 events_rules // 活动规则提示语 operationt_tips $info = array(); $info['events_tips'] = Request::p('events_tips', null); $info['events_hd_tips'] = Request::p('events_hd_tips', null); //互动提示语 $info['share_button'] = Request::p('share_button', null); //是否显示分享按钮 $info['top_data'] = Request::p('top_data', null); $info['share_button_tips'] = Request::p('share_button_tips', null); $info['buy_button'] = Request::p('buy_button', null); $info['buy_button_tips'] = Request::p('buy_button_tips', null); $info['buy_button_link'] = Request::p('buy_button_link', null); $info['buy_button_app'] = Request::p('buy_button_app', null); $info['is_column_tag_1'] = Request::p('is_column_tag_1', null); $info['column_tag_1'] = Request::p('column_tag_1', null); $info['is_column_tag_2'] = Request::p('is_column_tag_2', null); $info['column_tag_2'] = Request::p('column_tag_2', null); $info['is_column_tag_3'] = Request::p('is_column_tag_3', null); $info['column_tag_3'] = Request::p('column_tag_3', null); $info['events_rules'] = Request::p('events_rules', null); $info['operationt_tips'] = Request::p('operationt_tips', null); $info['display'] = LotteryEvents::EVENT_DISPLAY_SHOW; $this->objLottery->upLotteryEvents ( $info, array ('id' => $events_id) ); $this->ajax_success_exit(); } /** * 修改或创建切屏专题 * 事件:http://cas.lishuy.com/?c=Admin_Activity_SetPage&a=ReqUpCutScreen */ public function doReqUpCutScreen(){ $events_id = Request::p ( 'events_id' ); $pageData = Request::p('p', null); foreach ($pageData as $key => $tmpData) { $pageData[$key] = json_decode($tmpData, true); } $events_Data = $this->objLottery->getOneLotteryEventsAndPrize ( $events_id ); $info = array(); $info['pageData'] = $pageData; // ............................. // ............................. if($events_Data['events']['display'] == LotteryEvents::EVENT_DISPLAY_UNFINISHED){ $info['display'] = LotteryEvents::EVENT_DISPLAY_HIDE; } $events_id = $this->objLottery->upLotteryEvents ( $info, array ('id' => $events_id) ); if (!$events_id) { $this->ajax_fail_exit('操作失败'); } $this->ajax_success_exit(); } /** * 生成预览页面的二维码 */ public function doReqUpPreview() { $pageData = Request::p('p', null); $events_id = Request::p('events_id'); foreach ($pageData as $key => $tmpData) { $pageData[$key] = json_decode($tmpData, true); } $info = array( 'events_id' => $events_id, 'pageData' => $pageData, ); $memkey = 'preview_cutscreen_'.time(); $objMemcached = new \KIF\Cache\Memcached(); $tmpResult = $objMemcached->add($memkey, $info, time() + 5*60*60); $preview_url = Request::schemeDomain() . '/?c=CutScreenPreview&key='.$memkey; $qr_url = $this->createImgCodeUrl($preview_url); $this->ajax_success_exit($qr_url); } /** * 活动页文章页面 * 事件:修改 文章页面内容 * 地址:http://cas.lishuy.com/?c=Admin_Activity_SetPage&a=ReqUpArticle * 参数:见方法内 */ public function doReqUpArticle(){ $events_id = Request::p ( 'events_id' ); $events_Data = $this->objLottery->getOneLotteryEventsAndPrize ( $events_id ); /* 文章标题 article_title 作者 article_author 浏览量基数 article_pass_base_num 赞基数 article_praise 原文链接 article_original_url 正文 article_text */ $info = array(); $info['article_title'] = Request::p('article_title'); $info['article_author'] = Request::p('article_author'); $info['article_pass_base_num'] = Request::p('article_pass_base_num'); $info['article_praise'] = Request::p('article_praise'); $info['article_original_url'] = Request::p('article_original_url'); $info['article_text'] = Request::p('article_text', null); if($events_Data['events']['display'] == LotteryEvents::EVENT_DISPLAY_UNFINISHED){ $info['display'] = LotteryEvents::EVENT_DISPLAY_HIDE; } $events_id = $this->objLottery->upLotteryEvents ( $info, array ('id' => $events_id) ); // TODO 跳转页面自定义 返回 信息自定义 if (!$events_id) { $this->ajax_fail_exit('操作失败'); } $this->ajax_success_exit(); } /** * 方法:图片上传 */ public function loadImg($image_name = 'image') { $uploadConfig = Config::getInstance ()->get ( 'upload' ); // 定义允许上传的文件扩展名 $ext_arr = array ( 'image' => array ( 'gif', 'jpg', 'jpeg', 'png', 'bmp' ) ); if (! is_array ( $_FILES [$image_name] ['name'] )) { foreach ( $_FILES [$image_name] as $key => $data ) { unset ( $_FILES [$image_name] [$key] ); $_FILES [$image_name] [$key] [] = $data; } } $file_url = array (); foreach ( $_FILES [$image_name] ['name'] as $key => $oneData ) { // 文件保存目录路径 $save_path = $uploadConfig ['path'] . '/'; $save_path = realpath ( $save_path ) . '/'; // PHP上传失败 if ($_FILES [$image_name] ['error'] [$key] != 0) { switch ($_FILES [$image_name] ['error'] [$key]) { case '1' : $error = '超过php.ini允许的大小。'; break; case '2' : $error = '超过表单允许的大小。'; break; case '3' : $error = '图片只有部分被上传。'; break; case '4' : $error = '请选择图片。'; break; case '6' : $error = '找不到临时目录。'; break; case '7' : $error = '写文件到硬盘出错。'; break; case '8' : $error = 'File upload stopped by extension。'; break; case '999' : default : $error = '未知错误。'; } return $error; } // 有上传文件时 if (empty ( $_FILES ) === false) { // 原文件名 $file_name = $_FILES [$image_name] ['name'] [$key]; // 服务器上临时文件名 $tmp_name = $_FILES [$image_name] ['tmp_name'] [$key]; // 文件大小 $file_size = $_FILES [$image_name] ['size'] [$key]; // 检查文件名 if (! $file_name) { return "请选择文件。"; } // 检查目录 if (@is_dir ( $save_path ) === false) { return "上传目录不存在。"; } // 检查目录写权限 if (@is_writable ( $save_path ) === false) { return "上传目录没有写权限。"; } // 检查是否已上传 if (@is_uploaded_file ( $tmp_name ) === false) { return "上传失败。"; } // 检查目录名 $dir_name = 'image'; if (empty ( $ext_arr [$dir_name] )) { return "目录名不正确。"; } // 获得文件扩展名 $temp_arr = explode ( ".", $file_name ); $file_ext = array_pop ( $temp_arr ); $file_ext = trim ( $file_ext ); $file_ext = strtolower ( $file_ext ); // 检查扩展名 if (in_array ( $file_ext, $ext_arr [$dir_name] ) === false) { return "上传文件扩展名是不允许的扩展名。\n只允许" . implode ( ",", $ext_arr [$dir_name] ) . "格式。"; } // 创建文件夹 $ymd = date ( "Ymd" ); $ymd = date ( "Y" ) . '/' . date ( 'md' ); // 文件保存目录URL $save_url = $uploadConfig ['url'] . '/'; $new_file_name = ''; $save_path .= $dir_name . "/" . $ymd . "/"; $save_url .= $dir_name . "/" . $ymd . "/"; if (! file_exists ( $save_path )) { if (! mkdir ( $save_path, 0775, true )) { return "创建目录失败:{$save_path}"; } } // 新文件名 $new_file_name = date ( "His" ) . '_' . rand ( 10000, 99999 ) . '.' . $file_ext; // 移动文件 $file_path = $save_path . $new_file_name; // 原图上传 if (move_uploaded_file ( $tmp_name, $file_path ) === false) { return "上传文件失败。"; } error_reporting ( E_ALL ); // 压缩65质量原图 $this_basename = basename ( $file_path ); $this_dirname = dirname ( $file_path ); $z_file_path = $this_dirname . '/' . 'z.' . $this_basename; Image::transformFormat ( $file_path, $z_file_path, 'JPG' ); @chmod ( $file_path, 0777 ); $file_url [$key] = $save_url . 'z.' . $new_file_name; } } return array ( 'error' => 0, 'url' => $file_url ); } /** * 表单验证规则 * * @return multitype:multitype:string */ public function formRegular() { return array ( 1 => array ( 'desc' => '手机验证', 'regular' => '/^(1[0-9][0-9]|15[0-9]|18[02-9]|14[57])[0-9]{8}$/' ), 2 => array ( 'desc' => '邮箱验证', 'regular' => '/^[\w\-\.]+@[\w\-\.]+(\.\w+)+$/' ) ); } /** * 获取单页面预览html */ public function doGetPreviewPage() { $singlePageData = json_decode(Request::p('pageData', null), true); if (isset($singlePageData['bgimage_isShow']) && $singlePageData['bgimage_isShow'] == false) { unset($singlePageData['bgimage_url']); unset($singlePageData['bgimage_isShow']); } foreach ($singlePageData['layers'] as $key => $tmpLayer) { if (isset($tmpLayer['isShow']) && $tmpLayer['isShow'] == false) { unset($singlePageData['layers'][$key]); } } $singlePageData = $this->getPageData(array($singlePageData), 2.9); $this->tpl = 'admin/activity/preview_single_page'; $this->setOutput('pageData', $singlePageData); $html = $this->render(true); $this->ajax_success_exit($html); } /** * * @param number $shrink 图片缩小倍数 */ public function getPageData(array $pageData, $shrink = 2) { foreach ($pageData as $tmpkey => $tmpData) { $pageData[$tmpkey]['json'] = json_encode($tmpData); // 上层图片、按钮图片 宽高压缩一半。 foreach ($tmpData['layers'] as $key => $tmpLayer) { $new_layer = $pageData[$tmpkey]['layers'][$key]; if ($new_layer['url']) { $new_layer['width'] = $tmpLayer['width'] / $shrink; $new_layer['height'] = $tmpLayer['height'] / $shrink; } if ($new_layer['video_url']) { $new_layer['width'] = $new_layer['video_width'] = $tmpLayer['video_width'] / ($shrink - 2); $new_layer['height'] = $new_layer['video_height'] = $tmpLayer['video_height'] / ($shrink - 2); } $style = ''; switch ($tmpLayer['position']) { case 'center': $margin_left = $new_layer['width'] / 2; $margin_top = $new_layer['height'] / 2; $style = "left:50%;top:50%;margin-left:-{$margin_left}px;margin-top:-{$margin_top}px;"; break; case 'up'; $margin_left = $new_layer['width'] / 2; $style = "left:50%;top:0%;margin-left:-{$margin_left}px;"; break; case 'down': $margin_left = $new_layer['width'] / 2; $style = "left:50%;bottom:6%;margin-left:-{$margin_left}px;"; break; case 'leftup': $style = "left:0%;top:0%;"; break; case 'leftdown': $style = "left:0%;bottom:0%;"; break; case 'rightup': $style = "right:0%;top:0%;"; break; case 'rightdown': $style = "right:0%;bottom:0%;"; break; } $new_layer['style'] = $style; $pageData[$tmpkey]['layers'][$key] = $new_layer; } } return $pageData; } public function display() { return $this->render (); } }