SetPage.class.php 16 KB

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