SetPage.class.php 17 KB

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