SetPage.class.php 15 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508
  1. <?php
  2. namespace Cas\Controller\Admin\Activity;
  3. use Cas\Module\Lottery;
  4. use Cas\Dao\PlatformBulletin;
  5. use KIF\Core\Request;
  6. use Cas\Dao\LotteryEvents;
  7. use Cas\Controller\Admin\Controller;
  8. use Cas\Dao\Platform;
  9. use KIF\Core\Config;
  10. use Cas\Dao\LotteryPrize;
  11. /**
  12. * ["活动相关" - "页面设置" ]
  13. * 页面: 显示&修改 doPageShow
  14. * 选择不同模板
  15. * 活动页面常规设置
  16. *  显示&修改   doPageShow
  17. * 事件:修改常规    doReqUpRoutine
  18. * 事件:修改或创建切屏专题 doReqUpCutScreen
  19. * 事件:文章设置 doReqUpArticle
  20. *
  21. */
  22. class SetPage extends Controller {
  23. private $objLottery; // 活动后端
  24. private $operatorData;
  25. private $showActivityTypeArr;
  26. /**
  27. *  初始化
  28. */
  29. public function __construct() {
  30. header ( "Content-Type: text/html; charset=utf-8" );
  31. $this->objLottery = new Lottery ();
  32. $this->operatorData = $this->getUser ();
  33. # 能在当前页面显示的活动
  34. $this->showActivityTypeArr = array(
  35. LotteryEvents::TYPE_EVENTS_TURNTABLE,
  36. LotteryEvents::TYPE_EVENTS_SCRATCH,
  37. LotteryEvents::TYPE_EVENTS_LETTERS,
  38. LotteryEvents::TYPE_EVENTS_TRY,
  39. LotteryEvents::TYPE_EVENTS_VOTE,
  40. LotteryEvents::TYPE_EVENTS_INVITATION,
  41. LotteryEvents::TYPE_EVENTS_CODE,
  42. LotteryEvents::TYPE_EVENTS_OTHER,
  43. LotteryEvents::TYPE_EVENTS_CUT_SCREEN,
  44. LotteryEvents::TYPE_EVENTS_ARTICLE
  45. );
  46. $events_id = isset($_REQUEST['events_id'])?$_REQUEST['events_id'] : null;
  47. if($events_id){
  48. $this->setNowUpPage($events_id, 'Page');
  49. }
  50. }
  51. /**
  52. * 默认
  53. */
  54. public function doDefault() {}
  55. /**
  56. * 页面: 显示&修改
  57. * 地址:http://cas.lishuy.com/?c=Admin_Activity_SetPage&a=PageShow&events_id=nnn
  58. * 参数: events_id 活动ID
  59. */
  60. public function doPageShow() {
  61. $events_id = Request::g ( 'events_id' );
  62. $events_Data = $this->objLottery->getOneLotteryEventsAndPrize ( $events_id );
  63. // 载入修改页面需要用到的配置
  64. $eventsDeliveryType = LotteryEvents::getDeliveryType (); // // [活动] 发货状态
  65. $eventsAuthorize = LotteryEvents::getAuthorize (); // [活动] 授权
  66. $eventsDisplayStatus = LotteryEvents::getDisplay (); // [活动] 是否显示
  67. $eventsTwoDimensionalCodeType = LotteryEvents::getTwoDimensionalCodeType (); // [领券活动] 是否是二维码输出 类型
  68. $eventsTypeData = LotteryEvents::getType (); // [活动] 类型
  69. $eventsBigTypeConfig = LotteryEvents::getBigTypeConfig (); // [活动] 大类
  70. $eventsFormRegular = $this->formRegular (); // [活动] 表单
  71. $prizeDisplay = LotteryPrize::getDisplay (); // [奖项] 显示状态
  72. $prizeExpress = LotteryPrize::getExpress (); // [奖项] 是否需要快递
  73. $prizeType = LotteryPrize::getType (); // [奖项] 类型
  74. $this->setOutput ( 'eventsDeliveryType', $eventsDeliveryType );
  75. $this->setOutput ( 'eventsAuthorize', $eventsAuthorize );
  76. $this->setOutput ( 'eventsDisplayStatus', $eventsDisplayStatus );
  77. $this->setOutput ( 'eventsTwoDimensionalCodeType', $eventsTwoDimensionalCodeType );
  78. $this->setOutput ( 'eventsTypeData', $eventsTypeData );
  79. $this->setOutput ( 'eventsBigTypeConfig', $eventsBigTypeConfig );
  80. $this->setOutput ( 'eventsFormRegular', $eventsFormRegular );
  81. $this->setOutput ( 'prizeDisplay', $prizeDisplay );
  82. $this->setOutput ( 'prizeExpress', $prizeExpress );
  83. $this->setOutput ( 'prizeType', $prizeType );
  84. $this->setOutput('events_Data', $events_Data);
  85. $this->setOutput('eventData', $events_Data['events']);
  86. $this->setOutput('typeData', $eventsTypeData);
  87. $this->setOutput('displayDesc', LotteryEvents::getDisplay());
  88. $pageDatas = $disData = array();
  89. if(isset($events_Data['events']['pageData'])){
  90. foreach ($events_Data['events']['pageData'] as $tmpKey => $tmpItem) {
  91. $pageDatas[] = json_encode($tmpItem);
  92. $disData[$tmpKey] = $tmpItem;
  93. }
  94. }
  95. $this->setOutput('pageDatas', $pageDatas);
  96. $this->setOutput('pageData_json', $disData ? json_encode($disData) : '{}');
  97. $this->setOutput('count_num_page', count($disData));
  98. if ($events_Data['events']['pageData']) {
  99. $pageData = $this->getPageData($events_Data['events']['pageData'], 2.9);
  100. }
  101. $this->setOutput('pageData', $pageData);
  102. $navConfig = $this->getUpPageNav($events_id, 'Page');
  103. switch (LotteryEvents::getBigType($events_Data['events']['type'])) {
  104. case 'H5':
  105. $this->tpl = 'admin/activity/setPage_h5';
  106. break;
  107. case 'Event':
  108. $this->tpl = 'admin/activity/setPage_event';
  109. break;
  110. case 'Article':
  111. $this->tpl = 'admin/activity/setPage_article';
  112. break;
  113. default:
  114. $this->tpl = 'admin/activity/setPage_event';
  115. }
  116. $title = '页面制作';
  117. $this->setOutput('title', $title);
  118. $this->setOutput('menu_active', array('name' => 'mypublish', 'item' => '')); //激活菜单
  119. $this->addNavMenu('活动列表');
  120. $this->addNavMenu($title);
  121. $this->setOutput ( 'navConfig', $navConfig );// 导航 显示 URL 配置
  122. $this->setOutput('pagePublicData', $this->getPagePublicData($events_id)); // 后台管理相关数据
  123. }
  124. /**
  125. * 活动页面常规设置
  126. * 事件:修改常规页面
  127. * 地址:http://cas.lishuy.com/?c=Admin_Activity_SetPage&a=ReqUpRoutine
  128. * 参数:见方法内
  129. */
  130. public function doReqUpRoutine(){
  131. $events_id = Request::p ( 'events_id' );
  132. $events_Data = $this->objLottery->getOneLotteryEventsAndPrize ( $events_id );
  133. // 正文介绍内容 events_tips
  134. // 活动规则 events_rules
  135. // 活动规则提示语 operationt_tips
  136. $info = array();
  137. $info['events_tips'] = Request::p('events_tips', null);
  138. $info['events_hd_tips'] = Request::p('events_hd_tips', null); //互动提示语
  139. $info['events_rules'] = Request::p('events_rules', null);
  140. $info['operationt_tips'] = Request::p('operationt_tips', null);
  141. $info['display'] = LotteryEvents::EVENT_DISPLAY_SHOW;
  142. $this->objLottery->upLotteryEvents ( $info, array ('id' => $events_id) );
  143. $this->ajax_success_exit();
  144. }
  145. /**
  146. * 修改或创建切屏专题
  147. * 事件:http://cas.lishuy.com/?c=Admin_Activity_SetPage&a=ReqUpCutScreen
  148. */
  149. public function doReqUpCutScreen(){
  150. $events_id = Request::p ( 'events_id' );
  151. $pageData = Request::p('p', null);
  152. foreach ($pageData as $key => $tmpData) {
  153. $pageData[$key] = json_decode($tmpData, true);
  154. }
  155. $events_Data = $this->objLottery->getOneLotteryEventsAndPrize ( $events_id );
  156. $info = array();
  157. $info['pageData'] = $pageData;
  158. // .............................
  159. // .............................
  160. if($events_Data['events']['display'] == LotteryEvents::EVENT_DISPLAY_UNFINISHED){
  161. $info['display'] = LotteryEvents::EVENT_DISPLAY_HIDE;
  162. }
  163. $events_id = $this->objLottery->upLotteryEvents ( $info, array ('id' => $events_id) );
  164. if (!$events_id) {
  165. $this->ajax_fail_exit('操作失败');
  166. }
  167. $this->ajax_success_exit();
  168. }
  169. /**
  170. * 生成预览页面的二维码
  171. */
  172. public function doReqUpPreview() {
  173. $pageData = Request::p('p', null);
  174. $events_id = Request::p('events_id');
  175. foreach ($pageData as $key => $tmpData) {
  176. $pageData[$key] = json_decode($tmpData, true);
  177. }
  178. $info = array(
  179. 'events_id' => $events_id,
  180. 'pageData' => $pageData,
  181. );
  182. $memkey = 'preview_cutscreen_'.time();
  183. $objMemcached = new \KIF\Cache\Memcached();
  184. $tmpResult = $objMemcached->add($memkey, $info, time() + 5*60*60);
  185. $preview_url = Request::schemeDomain() . '/?c=CutScreenPreview&key='.$memkey;
  186. $qr_url = $this->createImgCodeUrl($preview_url);
  187. $this->ajax_success_exit($qr_url);
  188. }
  189. /**
  190. * 活动页文章页面
  191. * 事件:修改 文章页面内容
  192. * 地址:http://cas.lishuy.com/?c=Admin_Activity_SetPage&a=ReqUpArticle
  193. * 参数:见方法内
  194. */
  195. public function doReqUpArticle(){
  196. $events_id = Request::p ( 'events_id' );
  197. $events_Data = $this->objLottery->getOneLotteryEventsAndPrize ( $events_id );
  198. /*
  199. 文章标题 article_title
  200. 作者 article_author
  201. 浏览量基数 article_pass_base_num
  202. 赞基数 article_praise
  203. 原文链接 article_original_url
  204. 正文 article_text
  205. */
  206. $info = array();
  207. $info['article_title'] = Request::p('article_title');
  208. $info['article_author'] = Request::p('article_author');
  209. $info['article_pass_base_num'] = Request::p('article_pass_base_num');
  210. $info['article_praise'] = Request::p('article_praise');
  211. $info['article_original_url'] = Request::p('article_original_url');
  212. $info['article_text'] = Request::p('article_text', null);
  213. if($events_Data['events']['display'] == LotteryEvents::EVENT_DISPLAY_UNFINISHED){
  214. $info['display'] = LotteryEvents::EVENT_DISPLAY_HIDE;
  215. }
  216. $events_id = $this->objLottery->upLotteryEvents ( $info, array ('id' => $events_id) );
  217. // TODO 跳转页面自定义 返回 信息自定义
  218. if (!$events_id) {
  219. $this->ajax_fail_exit('操作失败');
  220. }
  221. $this->ajax_success_exit();
  222. }
  223. /**
  224. * 方法:图片上传
  225. */
  226. public function loadImg($image_name = 'image') {
  227. $uploadConfig = Config::getInstance ()->get ( 'upload' );
  228. // 定义允许上传的文件扩展名
  229. $ext_arr = array (
  230. 'image' => array (
  231. 'gif',
  232. 'jpg',
  233. 'jpeg',
  234. 'png',
  235. 'bmp'
  236. )
  237. );
  238. if (! is_array ( $_FILES [$image_name] ['name'] )) {
  239. foreach ( $_FILES [$image_name] as $key => $data ) {
  240. unset ( $_FILES [$image_name] [$key] );
  241. $_FILES [$image_name] [$key] [] = $data;
  242. }
  243. }
  244. $file_url = array ();
  245. foreach ( $_FILES [$image_name] ['name'] as $key => $oneData ) {
  246. // 文件保存目录路径
  247. $save_path = $uploadConfig ['path'] . '/';
  248. $save_path = realpath ( $save_path ) . '/';
  249. // PHP上传失败
  250. if ($_FILES [$image_name] ['error'] [$key] != 0) {
  251. switch ($_FILES [$image_name] ['error'] [$key]) {
  252. case '1' :
  253. $error = '超过php.ini允许的大小。';
  254. break;
  255. case '2' :
  256. $error = '超过表单允许的大小。';
  257. break;
  258. case '3' :
  259. $error = '图片只有部分被上传。';
  260. break;
  261. case '4' :
  262. $error = '请选择图片。';
  263. break;
  264. case '6' :
  265. $error = '找不到临时目录。';
  266. break;
  267. case '7' :
  268. $error = '写文件到硬盘出错。';
  269. break;
  270. case '8' :
  271. $error = 'File upload stopped by extension。';
  272. break;
  273. case '999' :
  274. default :
  275. $error = '未知错误。';
  276. }
  277. return $error;
  278. }
  279. // 有上传文件时
  280. if (empty ( $_FILES ) === false) {
  281. // 原文件名
  282. $file_name = $_FILES [$image_name] ['name'] [$key];
  283. // 服务器上临时文件名
  284. $tmp_name = $_FILES [$image_name] ['tmp_name'] [$key];
  285. // 文件大小
  286. $file_size = $_FILES [$image_name] ['size'] [$key];
  287. // 检查文件名
  288. if (! $file_name) {
  289. return "请选择文件。";
  290. }
  291. // 检查目录
  292. if (@is_dir ( $save_path ) === false) {
  293. return "上传目录不存在。";
  294. }
  295. // 检查目录写权限
  296. if (@is_writable ( $save_path ) === false) {
  297. return "上传目录没有写权限。";
  298. }
  299. // 检查是否已上传
  300. if (@is_uploaded_file ( $tmp_name ) === false) {
  301. return "上传失败。";
  302. }
  303. // 检查目录名
  304. $dir_name = 'image';
  305. if (empty ( $ext_arr [$dir_name] )) {
  306. return "目录名不正确。";
  307. }
  308. // 获得文件扩展名
  309. $temp_arr = explode ( ".", $file_name );
  310. $file_ext = array_pop ( $temp_arr );
  311. $file_ext = trim ( $file_ext );
  312. $file_ext = strtolower ( $file_ext );
  313. // 检查扩展名
  314. if (in_array ( $file_ext, $ext_arr [$dir_name] ) === false) {
  315. return "上传文件扩展名是不允许的扩展名。\n只允许" . implode ( ",", $ext_arr [$dir_name] ) . "格式。";
  316. }
  317. // 创建文件夹
  318. $ymd = date ( "Ymd" );
  319. $ymd = date ( "Y" ) . '/' . date ( 'md' );
  320. // 文件保存目录URL
  321. $save_url = $uploadConfig ['url'] . '/';
  322. $new_file_name = '';
  323. $save_path .= $dir_name . "/" . $ymd . "/";
  324. $save_url .= $dir_name . "/" . $ymd . "/";
  325. if (! file_exists ( $save_path )) {
  326. if (! mkdir ( $save_path, 0775, true )) {
  327. return "创建目录失败:{$save_path}";
  328. }
  329. }
  330. // 新文件名
  331. $new_file_name = date ( "His" ) . '_' . rand ( 10000, 99999 ) . '.' . $file_ext;
  332. // 移动文件
  333. $file_path = $save_path . $new_file_name;
  334. // 原图上传
  335. if (move_uploaded_file ( $tmp_name, $file_path ) === false) {
  336. return "上传文件失败。";
  337. }
  338. error_reporting ( E_ALL );
  339. // 压缩65质量原图
  340. $this_basename = basename ( $file_path );
  341. $this_dirname = dirname ( $file_path );
  342. $z_file_path = $this_dirname . '/' . 'z.' . $this_basename;
  343. Image::transformFormat ( $file_path, $z_file_path, 'JPG' );
  344. @chmod ( $file_path, 0777 );
  345. $file_url [$key] = $save_url . 'z.' . $new_file_name;
  346. }
  347. }
  348. return array (
  349. 'error' => 0,
  350. 'url' => $file_url
  351. );
  352. }
  353. /**
  354. * 表单验证规则
  355. *
  356. * @return multitype:multitype:string
  357. */
  358. public function formRegular() {
  359. return array (
  360. 1 => array (
  361. 'desc' => '手机验证',
  362. 'regular' => '/^(1[0-9][0-9]|15[0-9]|18[02-9]|14[57])[0-9]{8}$/'
  363. ),
  364. 2 => array (
  365. 'desc' => '邮箱验证',
  366. 'regular' => '/^[\w\-\.]+@[\w\-\.]+(\.\w+)+$/'
  367. )
  368. );
  369. }
  370. /**
  371. * 获取单页面预览html
  372. */
  373. public function doGetPreviewPage() {
  374. $singlePageData = json_decode(Request::p('pageData', null), true);
  375. if (isset($singlePageData['bgimage_isShow']) && $singlePageData['bgimage_isShow'] == false) {
  376. unset($singlePageData['bgimage_url']);
  377. unset($singlePageData['bgimage_isShow']);
  378. }
  379. foreach ($singlePageData['layers'] as $key => $tmpLayer) {
  380. if (isset($tmpLayer['isShow']) && $tmpLayer['isShow'] == false) {
  381. unset($singlePageData['layers'][$key]);
  382. }
  383. }
  384. $singlePageData = $this->getPageData(array($singlePageData), 2.9);
  385. $this->tpl = 'admin/activity/preview_single_page';
  386. $this->setOutput('pageData', $singlePageData);
  387. $html = $this->render(true);
  388. $this->ajax_success_exit($html);
  389. }
  390. /**
  391. *
  392. * @param number $shrink 图片缩小倍数
  393. */
  394. public function getPageData(array $pageData, $shrink = 2) {
  395. foreach ($pageData as $tmpkey => $tmpData) {
  396. $pageData[$tmpkey]['json'] = json_encode($tmpData);
  397. // 上层图片、按钮图片 宽高压缩一半。
  398. foreach ($tmpData['layers'] as $key => $tmpLayer) {
  399. $new_layer = $pageData[$tmpkey]['layers'][$key];
  400. if ($new_layer['url']) {
  401. $new_layer['width'] = $tmpLayer['width'] / $shrink;
  402. $new_layer['height'] = $tmpLayer['height'] / $shrink;
  403. }
  404. if ($new_layer['video_url']) {
  405. $new_layer['width'] = $new_layer['video_width'] = $tmpLayer['video_width'] / ($shrink - 2);
  406. $new_layer['height'] = $new_layer['video_height'] = $tmpLayer['video_height'] / ($shrink - 2);
  407. }
  408. $style = '';
  409. switch ($tmpLayer['position']) {
  410. case 'center':
  411. $margin_left = $new_layer['width'] / 2;
  412. $margin_top = $new_layer['height'] / 2;
  413. $style = "left:50%;top:50%;margin-left:-{$margin_left}px;margin-top:-{$margin_top}px;";
  414. break;
  415. case 'up';
  416. $margin_left = $new_layer['width'] / 2;
  417. $style = "left:50%;top:0%;margin-left:-{$margin_left}px;";
  418. break;
  419. case 'down':
  420. $margin_left = $new_layer['width'] / 2;
  421. $style = "left:50%;bottom:6%;margin-left:-{$margin_left}px;";
  422. break;
  423. case 'leftup':
  424. $style = "left:0%;top:0%;";
  425. break;
  426. case 'leftdown':
  427. $style = "left:0%;bottom:0%;";
  428. break;
  429. case 'rightup':
  430. $style = "right:0%;top:0%;";
  431. break;
  432. case 'rightdown':
  433. $style = "right:0%;bottom:0%;";
  434. break;
  435. }
  436. $new_layer['style'] = $style;
  437. $pageData[$tmpkey]['layers'][$key] = $new_layer;
  438. }
  439. }
  440. return $pageData;
  441. }
  442. public function display() {
  443. return $this->render ();
  444. }
  445. }