Controller.class.php 9.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340
  1. <?php
  2. namespace Cas\Controller\Admin;
  3. use KIF\Core\Config;
  4. use Cas\Dao\LotteryEvents;
  5. use KIF\Core\Request;
  6. use Cas\Dao\PlatformBulletin;
  7. use Cas\Dao\Platform;
  8. use KIF\Core\Model;
  9. use Cas\Module\Lottery;
  10. use Cas\Module\Count;
  11. use Cas\Dao\LotteryDeliveryChannels;
  12. /**
  13. *  后台管理控制器
  14. *
  15. * @author lihuanchun
  16. */
  17. class Controller extends \KIF\Core\PermissionController {
  18. /**
  19. * 初始化
  20. */
  21. public function __construct() {
  22. }
  23. /**
  24. * 动态获取后台页面所需数据
  25. * 以避免所有页面控制器重复代码
  26. */
  27. public function getPagePublicData($events_id=null) {
  28. $adminPublicArray = array ();
  29. $adminPublicArray ['rapidEntranceUrl'] = $this->getRapidEntrance (); // 头部导航"新建"数据
  30. if($events_id){
  31. $adminPublicArray ['EventsDefaultCode'] = $this->getEventsDefaultCode($events_id);//获取活动默认勾选列表后 "二维码"
  32. $adminPublicArray ['listDisplayDesc'] = LotteryEvents::getListDisplay(); // 活动列表中显示状态
  33. }
  34. return $adminPublicArray;
  35. }
  36. /**
  37. * 头部导航"新建"数据
  38. */
  39. public function getRapidEntrance() {
  40. $url = Request::schemeDomain () . '/?c=Admin_Activity_SetBasics&a=PageCreate&type=';
  41. $fastCreateActivityUrlData = array (
  42. '抽奖' => $url . LotteryEvents::TYPE_EVENTS_TURNTABLE . '&bigType=Event',
  43. '邀请函' => $url . LotteryEvents::TYPE_EVENTS_INVITATION . '&bigType=Event',
  44. '优惠券' => $url . LotteryEvents::TYPE_EVENTS_CODE . '&bigType=Event',
  45. '试用' => $url . LotteryEvents::TYPE_EVENTS_TRY . '&bigType=Event',
  46. '问卷调查' => $url . LotteryEvents::TYPE_EVENTS_SURVEY . '&bigType=Event',
  47. '投票' => $url . LotteryEvents::TYPE_EVENTS_VOTE . '&bigType=Event',
  48. '切屏专题' => $url . LotteryEvents::TYPE_EVENTS_CUT_SCREEN . '&bigType=H5',
  49. '文章' => $url . LotteryEvents::TYPE_EVENTS_ARTICLE . '&bigType=Article',
  50. '其他' => $url . LotteryEvents::TYPE_EVENTS_OTHER . '&bigType=Event',
  51. );
  52. return $fastCreateActivityUrlData;
  53. }
  54. /**
  55. * 创建时的导航
  56. *
  57. * @param string $type
  58. * @param string $bigType
  59. */
  60. public function getCreatePageNav($type, $bigType) {
  61. $hostUrl = Request::schemeDomain ();
  62. $config = array (
  63. 'Basics' => array (
  64. 'show' => true,
  65. 'url' => $hostUrl . "/?c=Admin_Activity_SetBasics&a=PageCreate&type={$type}&bigType={$bigType}",
  66. 'name' => '基础设置',
  67. 'onClick' => true
  68. ),
  69. 'Interactive' => array (
  70. 'name' => '互动设置'
  71. ),
  72. 'Page' => array (
  73. 'name' => '页面制作'
  74. ),
  75. 'DeliveryChannels' => array (
  76. 'name' => '投放渠道'
  77. ),
  78. 'Log' => array (
  79. 'name' => '数据统计'
  80. ),
  81. 'UserLog' => array (
  82. 'name' => '互动数据'
  83. )
  84. );
  85. if (in_array($type, array(4))) {
  86. $config['FeedBack'] = array (
  87. 'name' => '用户反馈'
  88. );
  89. }
  90. return $config;
  91. }
  92. /**
  93. * 修改时导航页面配置
  94. *
  95. * @param int $event_id
  96. * @param int $type
  97. * @param string $this_nav_type
  98. * // 当前修改操作在哪个选项卡下 字符串
  99. * @param int $display
  100. */
  101. public function getUpPageNav($event_id, $this_nav_type) {
  102. $hostUrl = Request::schemeDomain ();
  103. $navArr = array (
  104. 'Basics' => array (
  105. 'show' => true,
  106. 'url' => $hostUrl . "/?c=Admin_Activity_SetBasics&a=PageShow&events_id={$event_id}",
  107. 'name' => '基础设置'
  108. ),
  109. 'Interactive' => array (
  110. 'show' => true,
  111. 'url' => $hostUrl . "/?c=Admin_Activity_SetInteractive&a=PageShow&events_id={$event_id}",
  112. 'name' => '互动设置'
  113. ),
  114. 'Page' => array (
  115. 'show' => true,
  116. 'url' => $hostUrl . "/?c=Admin_Activity_SetPage&a=PageShow&events_id={$event_id}",
  117. 'name' => '页面制作'
  118. ),
  119. 'DeliveryChannels' => array (
  120. 'show' => true,
  121. 'url' => $hostUrl . "/?c=Admin_Activity_DeliveryChannels&a=PageList&events_id={$event_id}",
  122. 'name' => '投放渠道'
  123. ),
  124. 'Log' => array (
  125. 'show' => true,
  126. 'url' => $hostUrl . "/?c=Admin_Activity_Log&a=PageList&events_id={$event_id}",
  127. 'name' => '数据统计'
  128. ),
  129. 'UserLog' => array (
  130. 'show' => true,
  131. 'url' => $hostUrl . "/?c=Admin_Activity_UserParticipateLog&a=PageList&events_id={$event_id}&action=all",
  132. 'name' => '互动数据'
  133. )
  134. );
  135. $objDLotteryEvents = new LotteryEvents ();
  136. $eventData = $objDLotteryEvents->get ( $event_id );
  137. $type = $eventData ['type'];
  138. if (in_array($type, array(4))) {
  139. $navArr['FeedBack'] = array (
  140. 'show' => true,
  141. 'url' => $hostUrl . "/?c=Admin_Activity_FeedBack&a=PageList&events_id={$event_id}",
  142. 'name' => '用户反馈'
  143. );
  144. }
  145. foreach ( $navArr as $key => $data ) {
  146. if ($key == $this_nav_type) {
  147. $navArr [$key] ['onClick'] = true;
  148. }
  149. }
  150. // 当前活动状态 是否设置完
  151. if ($eventData ['display'] != LotteryEvents::EVENT_DISPLAY_UNFINISHED) {
  152. # 切屏专题 & 文章 特殊处理
  153. $arr = array (
  154. LotteryEvents::TYPE_EVENTS_ARTICLE,
  155. // LotteryEvents::TYPE_EVENTS_CODE,
  156. // LotteryEvents::TYPE_EVENTS_CUT_SCREEN,
  157. );
  158. if (in_array ( $type, $arr )) {
  159. $navArr ['Interactive'] ['show'] = false;
  160. }
  161. # 其他专题
  162. $arr = array (
  163. LotteryEvents::TYPE_EVENTS_OTHER,
  164. );
  165. if (in_array ( $type, $arr )) {
  166. $navArr ['Interactive'] ['show'] = false;
  167. $navArr['Page']['show'] = false;
  168. }
  169. return $navArr;
  170. }
  171. // 获取当前页面 设置到第几个选项卡了 前面&当前 选项卡都显示
  172. $show = true;
  173. foreach ( $navArr as $key => $data ) {
  174. $navArr [$key] ['show'] = $show;
  175. if ($eventData ['setPageType'] == $key) {
  176. $show = false;
  177. }
  178. }
  179. // 当修改操作到了 最后三个操作 后续都 选项卡都显示
  180. $showNavArr = array (
  181. 'DeliveryChannels',
  182. 'Log',
  183. 'UserLog'
  184. );
  185. if (in_array ( $this_nav_type, $showNavArr )) {
  186. foreach ( $showNavArr as $data ) {
  187. $navArr [$data] ['show'] = true;
  188. }
  189. }
  190. // 更具当前活动类型
  191. // 永远不显示互动设置的类型 文章 ,专题
  192. $arr = array (
  193. LotteryEvents::TYPE_EVENTS_CUT_SCREEN,
  194. LotteryEvents::TYPE_EVENTS_ARTICLE
  195. );
  196. if (in_array ( $type, $arr )) {
  197. $navArr ['Interactive'] ['show'] = false;
  198. }
  199. // 其余活动
  200. $arr = array (
  201. LotteryEvents::TYPE_EVENTS_TURNTABLE,
  202. LotteryEvents::TYPE_EVENTS_SCRATCH,
  203. LotteryEvents::TYPE_EVENTS_LETTERS,
  204. LotteryEvents::TYPE_EVENTS_TRY,
  205. LotteryEvents::TYPE_EVENTS_SURVEY,
  206. LotteryEvents::TYPE_EVENTS_VOTE,
  207. LotteryEvents::TYPE_EVENTS_INVITATION,
  208. LotteryEvents::TYPE_EVENTS_CODE,
  209. LotteryEvents::TYPE_EVENTS_CUT_SCREEN,
  210. );
  211. if (in_array ( $type, $arr )) {
  212. $navArr ['Interactive'] ['show'] = true;
  213. $navArr ['Page'] ['show'] = true;
  214. }
  215. # 切屏专题 & 文章 特殊处理
  216. $arr = array (
  217. LotteryEvents::TYPE_EVENTS_ARTICLE,
  218. LotteryEvents::TYPE_EVENTS_CODE,
  219. );
  220. if (in_array ( $type, $arr )) {
  221. $navArr ['Interactive'] ['show'] = false;
  222. }
  223. # 其他专题
  224. $arr = array (
  225. LotteryEvents::TYPE_EVENTS_OTHER,
  226. );
  227. if (in_array ( $type, $arr )) {
  228. $navArr ['Interactive'] ['show'] = false;
  229. $navArr['Page']['show'] = false;
  230. }
  231. return $navArr;
  232. }
  233. /**
  234. * 获取活动默认勾选列表后 "二维码"
  235. */
  236. public function getEventsDefaultCode($events_id){
  237. $objDLotteryEvents = new LotteryEvents ();
  238. $objLottery = new Lottery();
  239. $objDPlatform = new Platform();
  240. $objDLotteryDeliveryChannels = new LotteryDeliveryChannels();
  241. $thisPlatFormUrlData = array();
  242. $eventsData = $objDLotteryEvents -> get($events_id);
  243. $platform_ids = $eventsData['platform_ids'];
  244. $allPlatformData = $objDPlatform -> getsAll();
  245. foreach($allPlatformData as $id=> $platform){
  246. if($platform_ids&$id){
  247. $thisPlatFormUrlData[$id] = array();
  248. $thisPlatFormUrlData[$id]['name'] = $platform['name'];
  249. $url = $objLottery->getEventsUrl($eventsData['type'],$eventsData['create_time'],$platform['url']);
  250. $thisPlatFormUrlData[$id]['url'] = $url;
  251. $thisPlatFormUrlData[$id]['pv'] = $objDLotteryDeliveryChannels->getDefaultEventOnePV(Request::schemeDomain(),$events_id,$id);
  252. $thisPlatFormUrlData[$id]['img'] = $this->getImgCodePath($thisPlatFormUrlData[$id]['url']);
  253. }
  254. }
  255. //$thisPlatFormUrlData = array_pop($thisPlatFormUrlData);
  256. return $thisPlatFormUrlData;
  257. }
  258. /**
  259. * 设置当前修改完成,到哪个页面
  260. * $event_id 活动ID
  261. * $this_nav_type 当前页面的名称 见数组 $navArr Basics,Interactive ,Page
  262. */
  263. public function setNowUpPage($event_id, $this_nav_type) {
  264. $info ['setPageType'] = $this_nav_type;
  265. $objDLotteryEvents = new LotteryEvents ();
  266. $objDLotteryEvents->modify ( $info, array (
  267. 'id' => $event_id
  268. ) );
  269. return $event_id;
  270. }
  271. /**
  272. * 返回已创建Url二维码图片
  273. * return imgUrl
  274. */
  275. public function getImgCodePath($url) {
  276. $App_Path = Config::getInstance ()->get ( 'App_Path' );
  277. $uploadConfig = Config::getInstance ()->get ( 'upload' );
  278. $IMG_UPLOAD_URL = $uploadConfig ['url'] . DS . 'qrcode';
  279. $filename = md5 ( $url ) . '.png';
  280. $imgUrl = $IMG_UPLOAD_URL . DS . $filename;
  281. return $imgUrl;
  282. }
  283. /**
  284. * 创建URl 二维码 图片
  285. */
  286. public function createImgCodeUrl($url) {
  287. $App_Path = Config::getInstance ()->get ( 'App_Path' );
  288. include_once $App_Path . DS . 'include/phpqrcode/phpqrcode.php';
  289. $uploadConfig = Config::getInstance ()->get ( 'upload' );
  290. $IMG_UPLOAD_PATH = $uploadConfig ['path'] . DS . 'qrcode';
  291. $IMG_UPLOAD_URL = $uploadConfig ['url'] . DS . 'qrcode';
  292. if (! file_exists ( $IMG_UPLOAD_PATH )) {
  293. if (! mkdir ( $IMG_UPLOAD_PATH, 0775, true )) {
  294. self::fail_exit ( '创建二维码失败,原因:图片目录不存在' );
  295. }
  296. }
  297. $imgname = md5 ( $url );
  298. $filename = $imgname . '.png';
  299. \QRcode::png ( $url, $IMG_UPLOAD_PATH . DS . $filename, 3, 6 );
  300. $imgUrl = $IMG_UPLOAD_URL . DS . $filename;
  301. return $imgUrl;
  302. }
  303. }