SetPage.class.php 17 KB

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