Lottery.class.php 49 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470
  1. <?php
  2. namespace Cas\Controller\Admin;
  3. use Cas\Dao\LotteryData;
  4. use Cas\Module\LotteryDrawLetters;
  5. use Cas\Dao\LotteryEventsCodeData;
  6. use Cas\Dao\LotteryEventsInvitation;
  7. use KIF\Core\Request;
  8. use KIF\Page\Page;
  9. use KIF\Verify;
  10. use Cas\Dao\LotteryEvents as LotteryEvents;
  11. use KIF\Core\Config;
  12. use KIF\Image;
  13. use Cas\Dao\LotteryPrize;
  14. use KIF\Cache\Memcached;
  15. use KIF\Dao\SqlHelper;
  16. use Cas\Module\LotteryDraw;
  17. use Cas\Module\LotteryLog;
  18. use Cas\Dao\LotteryEventsTry;
  19. use Cas\Dao\LotteryEventsLetters;
  20. use Cas\Dao\LotteryEventsUserLetters;
  21. use Cas\Dao\LotteryEventsVote;
  22. use KIF\String\Filter;
  23. use Cas\Dao\LotteryEventsForms;
  24. use Cas\Module\WeixinUser;
  25. use KIF\Data\Convert;
  26. /**
  27. *
  28. *
  29. * 抽奖控制器
  30. *
  31. * @author lihuanchun
  32. */
  33. class Lottery extends Controller {
  34. private $objLottery;
  35. public function __construct() {
  36. header ( "Content-Type: text/html; charset=utf-8" );
  37. $this->objLottery = new \Cas\Module\Lottery ();
  38. }
  39. /**
  40. * 操作 ajax:测试抽奖页面
  41. */
  42. public function doTestWantToDraw() {
  43. $uid = Request::p ( 'uid' );
  44. $events_id = Request::p ( 'events_id' );
  45. $lotteryDataId = $this->objLottery->tmpWantToDraw ( $events_id, $uid );
  46. if (! $lotteryDataId) {
  47. $this->ajax_fail_exit ( '未中奖' );
  48. } else {
  49. $data = $this->objLottery->getOneLotteryData ( $lotteryDataId );
  50. $this->ajax_success_exit ( "中奖啦\n" );
  51. }
  52. }
  53. /**
  54. * ajax: 添加 活动【领码】
  55. */
  56. public function doAddEventCode() {
  57. $events_id = Request::p ( 'events_id' );
  58. $code_data = Request::p ( 'code_data' );
  59. $code_data = explode ( "\n", $code_data );
  60. foreach ( $code_data as $key => $data ) {
  61. if ($data) {
  62. $code_data [$data] = $data;
  63. }
  64. }
  65. if (count ( $code_data ) > 200) {
  66. $this->ajax_fail_exit ( '一次上传不允许超过200条记录' );
  67. }
  68. $objDLotteryEventsCodeData = new LotteryEventsCodeData ();
  69. foreach ( $code_data as $key => $data ) {
  70. $info = array (
  71. 'events_id' => $events_id,
  72. 'data' => $data
  73. );
  74. $objDLotteryEventsCodeData->add ( $info );
  75. }
  76. $this->ajax_success_exit ( "上传成功" );
  77. }
  78. /**
  79. * 页面:活动【领码】页面
  80. */
  81. public function doEventCodePage() {
  82. $events_id = Request::varGetInt ( 'events_id' );
  83. $eventsData = $this->objLottery->getOneLotteryEvents ( $events_id );
  84. $page = Request::varGetInt ( 'page', 1 );
  85. $size = 20;
  86. $offset = ($page - 1) * $size;
  87. $limit = "{$offset},{$size}";
  88. $condition = array (
  89. 'events_id' => $events_id
  90. );
  91. $objDLotteryEventsCodeData = new LotteryEventsCodeData ();
  92. $codeIds = $objDLotteryEventsCodeData->findIdsBy ( $condition, $limit, 'id desc' );
  93. $codeData = $objDLotteryEventsCodeData->gets ( $codeIds );
  94. $total_num = $objDLotteryEventsCodeData->totals ( $condition );
  95. $url_tpl = Request::schemeDomain () . "?c=admin_lottery&a=EventCodePage&events_id={$events_id}";
  96. $url_tpl .= "&page={page}";
  97. // 分页
  98. $objPage = new Page ( $total_num, $url_tpl, $page, $size );
  99. $page_html = $objPage->html ();
  100. $this->tpl = 'admin/lottery/event_code_data_list';
  101. $title = '抵用券信息';
  102. $this->setOutput ( 'title', $title );
  103. $this->setOutput ( 'page_html', $page_html );
  104. $this->addNavMenu ( '活动管理' );
  105. $this->addNavMenu ( $title, Request::url (), '_self' );
  106. $this->setOutput ( 'codeData', $codeData );
  107. $this->setOutput ( 'eventsData', $eventsData );
  108. $this->setOutput ( 'showAddCode', Request::g ( 'showAddCode' ) );
  109. }
  110. /**
  111. * 页面: 邀请函申请列表【活动】
  112. */
  113. public function doEventInvitationPage() {
  114. $objDLotteryEventsInvitation = new LotteryEventsInvitation ();
  115. $events_id = Request::varGetInt ( 'events_id' );
  116. $page = Request::varGetInt ( 'page', 1 );
  117. $size = 20;
  118. $offset = ($page - 1) * $size;
  119. $limit = "{$offset},{$size}";
  120. $condition = array (
  121. 'events_id' => $events_id
  122. );
  123. $applyIds = $objDLotteryEventsInvitation->findIdsBy ( $condition, $limit, 'id desc' );
  124. $applyData = $objDLotteryEventsInvitation->gets ( $applyIds );
  125. $total_num = $objDLotteryEventsInvitation->totals ( $condition );
  126. $url_tpl = Request::schemeDomain () . "?c=admin_lottery&a=EventInvitationPage&events_id={$events_id}";
  127. $url_tpl .= "&page={page}";
  128. // 分页
  129. $objPage = new Page ( $total_num, $url_tpl, $page, $size );
  130. $page_html = $objPage->html ();
  131. $this->tpl = 'admin/lottery/event_invitation_list';
  132. $title = '邀请函表单信息';
  133. $this->setOutput ( 'title', $title );
  134. $this->setOutput ( 'page_html', $page_html );
  135. $this->addNavMenu ( '活动管理' );
  136. $this->addNavMenu ( $title, Request::url (), '_self' );
  137. $this->setOutput ( 'applyData', $applyData );
  138. }
  139. /**
  140. * 页面: 表单数据
  141. */
  142. public function doEventFormDataPage() {
  143. $events_id = Request::varGetInt ( 'events_id' );
  144. if (! Verify::unsignedInt ( $events_id )) {
  145. self::fail_exit_bs ( '无效events_id' );
  146. }
  147. $page = Request::varGetInt ( 'page', 1 );
  148. $size = 20;
  149. $offset = ($page - 1) * $size;
  150. $limit = "{$offset},{$size}";
  151. $condition = array (
  152. 'events_id' => $events_id
  153. );
  154. $objLotteryEventsForms = new LotteryEventsForms ();
  155. $ids = $objLotteryEventsForms->findIdsBy ( $condition, $limit, 'id desc' );
  156. $formData = $objLotteryEventsForms->gets ( $ids );
  157. $objLotteryEvents = new LotteryEvents ();
  158. $event = $objLotteryEvents->get ( $events_id );
  159. // 表单类型数据
  160. $formType = array ();
  161. foreach ( $event ['forms'] as $tmpForms ) {
  162. $formType [] = $tmpForms ['name'];
  163. }
  164. // 分页
  165. $total_num = $objLotteryEventsForms->totals ( $condition );
  166. $url_tpl = Request::schemeDomain () . "?c=admin_lottery&a=EventFormDataPage&events_id={$events_id}";
  167. $url_tpl .= "&page={page}";
  168. $objPage = new Page ( $total_num, $url_tpl, $page, $size );
  169. $page_html = $objPage->html ();
  170. $this->tpl = 'admin/lottery/event_form_data';
  171. $title = "活动\"{$event['events_name']}\"表单数据";
  172. $this->setOutput ( 'title', $title );
  173. $this->setOutput ( 'page_html', $page_html );
  174. $this->addNavMenu ( '活动管理' );
  175. $this->addNavMenu ( $title, Request::url (), '_self' );
  176. $this->setOutput ( 'formData', $formData );
  177. $this->setOutput ( 'formType', $formType );
  178. }
  179. /**
  180. * 页面: 活动日志产看列表
  181. */
  182. public function doEventLogPage() {
  183. $objMLotteryLog = new LotteryLog ();
  184. $lotteryLogType = $objMLotteryLog->getType ();
  185. $events_id = Request::varGetInt ( 'events_id' );
  186. $page = Request::varGetInt ( 'page', 1 );
  187. $size = 20;
  188. $offset = ($page - 1) * $size;
  189. $limit = "{$offset},{$size}";
  190. $condition = array (
  191. 'events_id' => $events_id
  192. );
  193. $logData = $objMLotteryLog->findData ( $condition, $limit, 'id desc' );
  194. $total_num = $objMLotteryLog->getLogNum ( $condition );
  195. $url_tpl = Request::schemeDomain () . "?c=admin_lottery&a=EventLogPage&events_id={$events_id}";
  196. $url_tpl .= "&page={page}";
  197. // 分页
  198. $objPage = new Page ( $total_num, $url_tpl, $page, $size );
  199. $page_html = $objPage->html ();
  200. $this->tpl = 'admin/lottery/event_log_list';
  201. $title = '活动日志';
  202. $this->setOutput ( 'title', $title );
  203. $this->setOutput ( 'page_html', $page_html );
  204. $this->addNavMenu ( '活动管理' );
  205. $this->addNavMenu ( $title, Request::url (), '_self' );
  206. $this->setOutput ( 'logData', $logData );
  207. $this->setOutput ( 'lotteryLogType', $lotteryLogType );
  208. }
  209. /**
  210. * 页面:创建活动页
  211. */
  212. public function doAddEventPage() {
  213. $objDLotteryEvents = new LotteryEvents ();
  214. $eventsType = $objDLotteryEvents->getType ();
  215. $this->tpl = 'admin/lottery/add_event';
  216. $title = '创建活动';
  217. $this->setOutput ( 'title', $title );
  218. $this->addNavMenu ( '活动管理' );
  219. $this->addNavMenu ( $title, Request::url (), '_self' );
  220. $this->setOutput ( 'eventsType', $eventsType );
  221. }
  222. /**
  223. * 事件:创建活动
  224. */
  225. public function doAddEvent() {
  226. $events_name = Request::p ( 'events_name' );
  227. $begin_time = Request::p ( 'begin_unix_time' );
  228. $end_time = Request::p ( 'end_unix_time' );
  229. $type = Request::varPostInt ( 'type' );
  230. $events_rules = $_POST ['events_rules'];
  231. $events_tips = $_POST ['events_tips'];
  232. $img_url = '';
  233. $tmpImgData = $this->loadImg ();
  234. if (is_array ( $tmpImgData )) {
  235. $img_url = $tmpImgData ['url'] [0];
  236. }
  237. $info = array (
  238. 'events_name' => $events_name,
  239. 'begin_time' => $begin_time,
  240. 'end_time' => $end_time,
  241. 'end_time_receive_prizes' => $end_time,
  242. 'type' => $type,
  243. 'img_url' => $img_url,
  244. 'authorize' => LotteryEvents::EVENT_AUTHORIZE_FALSE,
  245. 'events_rules' => $events_rules,
  246. 'events_tips' => $events_tips,
  247. 'delivery' => LotteryEvents::DELIVERY_FALSE,
  248. 'participation_user_num' => 0,
  249. 'participation_ip_num' => 0,
  250. 'winning_user_num' => 0,
  251. 'participation_user_all_num' => 0
  252. );
  253. $events_id = $this->objLottery->addLotteryEvents ( $info );
  254. if (! $events_id) {
  255. exit ( '创建活动失败' );
  256. }
  257. header ( "Location: " . Request::schemeDomain () . "/?c=admin_Lottery&a=EventPage&events_id={$events_id}" );
  258. }
  259. /**
  260. * 事件:修改活动
  261. */
  262. public function doUpEvent() {
  263. $events_id = Request::p ( 'events_id' );
  264. $events_name = Request::p ( 'events_name' );
  265. $display = Request::p ( 'display' );
  266. $authorize = Request::p ( 'authorize' );
  267. $list_display = Request::p ( 'list_display' ); // 是否在列表中出现
  268. $img_url = Request::p ( 'old_img_url' );
  269. $begin_time = Request::p ( 'begin_unix_time' );
  270. $end_time = Request::p ( 'end_unix_time' );
  271. $end_time_receive_prizes = Request::p ( 'end_unix_time_receive_prizes' );
  272. $type = Request::p ( 'type' );
  273. $delivery = Request::p ( 'delivery' );
  274. $events_rules = $_POST ['events_rules'];
  275. $operationt_tips = $_POST ['operationt_tips'];
  276. $events_tips = $_POST ['events_tips'];
  277. $participation_user_num = Request::p ( 'participation_user_num' );
  278. $participation_ip_num = Request::p ( 'participation_ip_num' );
  279. $winning_user_num = Request::p ( 'winning_user_num' );
  280. $participation_user_all_num = Request::p ( 'participation_user_all_num' );
  281. $tmpImgData = $this->loadImg ();
  282. if (is_array ( $tmpImgData )) {
  283. $img_url = $tmpImgData ['url'] [0];
  284. }
  285. $weixinShare_title = Request::p ( 'weixinShare_title' );
  286. $weixinShare_content = Request::p ( 'weixinShare_content' );
  287. $weixinShare_imgUrl = Request::p ( 'weixinShare_imgUrl' );
  288. $tmpImgData = $this->loadImg ( 'weixinShareImg' );
  289. if (is_array ( $tmpImgData )) {
  290. $weixinShare_imgUrl = $tmpImgData ['url'] [0];
  291. }
  292. $weixinShare_notAllow = Request::p ( 'weixinShare_notAllow' );
  293. $info = array (
  294. 'events_name' => $events_name,
  295. 'begin_time' => $begin_time,
  296. 'end_time' => $end_time,
  297. 'end_time_receive_prizes' => $end_time_receive_prizes,
  298. 'img_url' => $img_url,
  299. 'display' => $display,
  300. 'authorize' => $authorize,
  301. 'list_display' => $list_display,
  302. 'operationt_tips' => $operationt_tips,
  303. 'events_rules' => $events_rules,
  304. 'events_tips' => $events_tips,
  305. 'delivery' => $delivery,
  306. 'participation_user_num' => $participation_user_num,
  307. 'participation_ip_num' => $participation_ip_num,
  308. 'winning_user_num' => $winning_user_num,
  309. 'participation_user_all_num' => $participation_user_all_num,
  310. 'weixinShare' => array (
  311. 'title' => $weixinShare_title,
  312. 'content' => $weixinShare_content,
  313. 'imgUrl' => $weixinShare_imgUrl,
  314. 'notAllow' => $weixinShare_notAllow
  315. )
  316. );
  317. if ($type == LotteryEvents::TYPE_EVENTS_INVITATION) {
  318. // <邀请函> 白名单列表
  319. $invitation_white_list = Request::p ( 'invitation_white_list' );
  320. if ($invitation_white_list) {
  321. $invitation_white_list = explode ( "@", $invitation_white_list );
  322. $tmpData = array ();
  323. foreach ( $invitation_white_list as $key => $data ) {
  324. $tmpData [$data] = $data;
  325. }
  326. $info ['invitation_white_list'] = $tmpData;
  327. } else {
  328. $info ['invitation_white_list'] = '';
  329. }
  330. }
  331. // 其他
  332. if ($type == LotteryEvents::TYPE_EVENTS_OTHER) {
  333. $info ['other_url'] = Request::p ( 'other_url' );
  334. }
  335. if ($type == LotteryEvents::TYPE_EVENTS_INVITATION) {
  336. $info ['participation_user_max_num'] = Request::p ( 'participation_user_max_num' );
  337. }
  338. // 领券操作
  339. if ($type == LotteryEvents::TYPE_EVENTS_CODE) {
  340. $info ['two_dimensional_code'] = Request::p ( 'two_dimensional_code' );
  341. $info ['code_name'] = Request::p ( 'code_name' );
  342. $info ['code_img_url'] = Request::p ( 'code_old_img_url' );
  343. $tmpImgData = $this->loadImg ( 'code_image' );
  344. if (is_array ( $tmpImgData )) {
  345. $info ['code_img_url'] = $tmpImgData ['url'] [0];
  346. }
  347. }
  348. $formRegular = $this->formRegular ();
  349. if (isset ( $_POST ['f'] )) {
  350. $forms = Filter::arrayfilter ( $_POST ['f'] );
  351. foreach ( $forms as $tmpKey => $tmpForm ) {
  352. if (! $tmpForm ['name']) {
  353. unset ( $forms [$tmpKey] );
  354. }
  355. $regularid = $tmpForm ['rule'] ['regularid'];
  356. if (! empty ( $regularid ) && in_array ( $regularid, array_keys ( $formRegular ) )) {
  357. $forms [$tmpKey] ['rule'] ['regular'] = $formRegular [$regularid] ['regular'];
  358. } else {
  359. unset ( $forms [$tmpKey] ['rule'] ['regular'] );
  360. }
  361. if ($tmpForm ['options']) {
  362. $forms [$tmpKey] ['options'] = Filter::arrayfilter ( explode ( "\n", $tmpForm ['options'] ) );
  363. }
  364. }
  365. $info ['forms'] = $forms;
  366. }
  367. $this->objLottery->upLotteryEvents ( $info, array (
  368. 'id' => $events_id
  369. ) );
  370. header ( "Location: " . Request::schemeDomain () . "/?c=admin_Lottery&a=EventPage&events_id={$events_id}" );
  371. }
  372. /**
  373. * 页面:修改活动页
  374. */
  375. public function doUpEventPage() {
  376. $events_id = Request::g ( 'events_id' );
  377. $events_Data = $this->objLottery->getOneLotteryEvents ( $events_id );
  378. $this->objLottery->getOneLotteryEventsAndPrize($events_id);
  379. $objDLotteryEvents = new LotteryEvents ();
  380. $eventsType = $objDLotteryEvents->getType ();
  381. $deliveryType = $objDLotteryEvents->getDeliveryType ();
  382. $eventsAuthorize = $objDLotteryEvents->getAuthorize ();
  383. $eventsDisplayStatus = $objDLotteryEvents->getDisplay ();
  384. $eventsTwoDimensionalCodeType = $objDLotteryEvents->getTwoDimensionalCodeType ();
  385. $this->tpl = 'admin/lottery/up_event';
  386. $title = '修改活动';
  387. $this->setOutput ( 'title', $title );
  388. $this->addNavMenu ( '活动管理' );
  389. $this->addNavMenu ( $title, Request::url (), '_self' );
  390. $this->setOutput ( 'eventsType', $eventsType );
  391. $this->setOutput ( 'deliveryType', $deliveryType );
  392. $this->setOutput ( 'eventsAuthorize', $eventsAuthorize );
  393. $this->setOutput ( 'eventsDisplayStatus', $eventsDisplayStatus );
  394. $this->setOutput ( 'events_Data', $events_Data );
  395. $this->setOutput ( 'eventsTwoDimensionalCodeType', $eventsTwoDimensionalCodeType );
  396. $this->setOutput ( 'formRegular', $this->formRegular () );
  397. }
  398. /**
  399. * 页面:活动列表页
  400. */
  401. public function doEventListPage() {
  402. $objDLotteryEvents = new LotteryEvents ();
  403. $eventsType = $objDLotteryEvents->getType ();
  404. $eventsDisplayStatus = $objDLotteryEvents->getDisplay ();
  405. $objDLotteryPrize = new LotteryPrize ();
  406. $prizeType = $objDLotteryPrize->getType ();
  407. $prizeDisplayStatus = $objDLotteryPrize->getDisplay ();
  408. // 取数据
  409. $page = Request::varGetInt ( 'page', 1 );
  410. $size = 20;
  411. $offset = ($page - 1) * $size;
  412. $limit = "{$offset},{$size}";
  413. $condition = array ();
  414. $allLotteryEventsIds = $objDLotteryEvents->findIdsBy ( $condition, $limit, 'id desc' );
  415. $eventsData = $objDLotteryEvents->gets ( $allLotteryEventsIds );
  416. $total_num = $this->objLottery->getLotteryEventsListNum ( $condition );
  417. $url_tpl = Request::schemeDomain () . "?c=admin_lottery&a=EventListPage";
  418. $url_tpl .= "&page={page}";
  419. // 分页
  420. $objPage = new Page ( $total_num, $url_tpl, $page, $size );
  421. $page_html = $objPage->html ();
  422. $this->tpl = 'admin/lottery/event_list';
  423. $title = '活动列表';
  424. $this->setOutput ( 'title', $title );
  425. $this->setOutput ( 'page_html', $page_html );
  426. $this->addNavMenu ( '活动管理' );
  427. $this->addNavMenu ( $title, Request::url (), '_self' );
  428. $this->setOutput ( 'allEventsData', $eventsData );
  429. $this->setOutput ( 'eventsType', $eventsType );
  430. $this->setOutput ( 'eventsDisplay', $eventsDisplayStatus );
  431. $this->setOutput ( 'prizeType', $prizeType );
  432. $this->setOutput ( 'prizeDisplayStatus', $prizeDisplayStatus );
  433. }
  434. /**
  435. * 页面:活动详情页
  436. */
  437. public function doEventPage() {
  438. $events_id = Request::g ( 'events_id' );
  439. $eventsAndPrize_Data = $this->objLottery->getOneLotteryEventsAndPrize ( $events_id );
  440. $objDLotteryEvents = new LotteryEvents ();
  441. $eventsType = $objDLotteryEvents->getType ();
  442. $eventsDisplayStatus = $objDLotteryEvents->getDisplay ();
  443. $eventsVoteType = $objDLotteryEvents->getVoteType ();
  444. $eventsAuthorizeStatus = $objDLotteryEvents->getAuthorize ();
  445. $eventsTwoDimensionalCodeType = $objDLotteryEvents->getTwoDimensionalCodeType ();
  446. $deliveryType = $objDLotteryEvents->getDeliveryType ();
  447. $objDLotteryPrize = new LotteryPrize ();
  448. $prizeType = $objDLotteryPrize->getType ();
  449. $prizeDisplayStatus = $objDLotteryPrize->getDisplay ();
  450. $objMemcached = new Memcached ();
  451. // 收集字母
  452. $lettersData = null;
  453. if ($eventsAndPrize_Data ['events'] ['type'] == \Cas\Dao\LotteryEvents::TYPE_EVENTS_LETTERS) {
  454. $objDLotteryEventsLetters = new LotteryEventsLetters ();
  455. $lettersData = $objDLotteryEventsLetters->getEventData ( $events_id );
  456. }
  457. // 投票
  458. $voteData = null;
  459. if ($eventsAndPrize_Data ['events'] ['type'] == \Cas\Dao\LotteryEvents::TYPE_EVENTS_VOTE) {
  460. $objDLotteryEventsVote = new LotteryEventsVote ();
  461. $voteData = $objDLotteryEventsVote->getThisEventData ( $events_id );
  462. }
  463. // 领码
  464. if ($eventsAndPrize_Data ['events'] ['type'] == \Cas\Dao\LotteryEvents::TYPE_EVENTS_CODE) {
  465. $voteData = null;
  466. $objEventsCodeData = new LotteryEventsCodeData ();
  467. $useCodeDataNum = $objEventsCodeData->getEventsUseCodeDataNum ( $events_id );
  468. $codeDataNum = $objEventsCodeData->getEventsCodeDataNum ( $events_id );
  469. $this->setOutput ( 'codeDataNum', $codeDataNum );
  470. $this->setOutput ( 'useCodeDataNum', $useCodeDataNum );
  471. }
  472. $objMLotteryDraw = new LotteryDraw ( null, $events_id );
  473. foreach ( $eventsAndPrize_Data ['prize'] as $key => $prize ) {
  474. $lottery_prize_draw_next_time_key = $objMLotteryDraw->getCacheKeyOfNextWinTime ( $key );
  475. $eventsAndPrize_Data ['prize'] [$key] ['nextTime'] = $objMemcached->get ( $lottery_prize_draw_next_time_key );
  476. }
  477. // 页面URL
  478. $thisurl = $this->objLottery->getEventsUrl ( $eventsAndPrize_Data ['events'] ['type'],$eventsAndPrize_Data ['create_time']);
  479. $this->setOutput ( 'thisurl', $thisurl );
  480. // APP载入URL
  481. $thisAppUrl = Request::schemeDomain () . '/redirect/?url=' . urlencode ( $thisurl ) . '&uf=';
  482. $this->setOutput ( 'thisAppUrl', $thisAppUrl );
  483. $this->tpl = 'admin/lottery/event';
  484. $title = '活动详情';
  485. $this->setOutput ( 'title', $title );
  486. $this->addNavMenu ( '活动管理' );
  487. $this->addNavMenu ( $title, Request::url (), '_self' );
  488. $this->setOutput ( 'eventsType', $eventsType );
  489. $this->setOutput ( 'eventsAuthorizeStatus', $eventsAuthorizeStatus );
  490. $this->setOutput ( 'eventsDisplayStatus', $eventsDisplayStatus );
  491. $this->setOutput ( 'eventsVoteType', $eventsVoteType );
  492. $this->setOutput ( 'prizeType', $prizeType );
  493. $this->setOutput ( 'prizeDisplayStatus', $prizeDisplayStatus );
  494. $this->setOutput ( 'eventsAndPrize_Data', $eventsAndPrize_Data );
  495. $this->setOutput ( 'deliveryType', $deliveryType );
  496. $this->setOutput ( 'lettersData', $lettersData );
  497. $this->setOutput ( 'voteData', $voteData );
  498. $this->setOutput ( 'eventsTwoDimensionalCodeType', $eventsTwoDimensionalCodeType );
  499. }
  500. /**
  501. * 页面:投票详情列表
  502. */
  503. public function doEventVotePage() {
  504. $events_id = Request::g ( 'events_id' );
  505. $objDLotteryEvents = new LotteryEvents ();
  506. $eventsData = $objDLotteryEvents->get ( $events_id );
  507. $eventsVoteType = $objDLotteryEvents->getVoteType ();
  508. $objDLotteryEventsVote = new LotteryEventsVote ();
  509. $voteData = $objDLotteryEventsVote->getThisEventData ( $events_id );
  510. $this->tpl = 'admin/lottery/event_vote_list';
  511. $title = '投票详情';
  512. $this->setOutput ( 'title', $title );
  513. $this->addNavMenu ( '活动管理' );
  514. $this->addNavMenu ( $title, Request::url (), '_self' );
  515. $this->setOutput ( 'eventsData', $eventsData );
  516. $this->setOutput ( 'eventsVoteType', $eventsVoteType );
  517. $this->setOutput ( 'voteData', $voteData );
  518. }
  519. /**
  520. * 页面: 修改投票页
  521. */
  522. public function doUpEventVotePage() {
  523. $vote_id = Request::g ( 'vote_id' );
  524. $objDLotteryEventsVote = new LotteryEventsVote ();
  525. $voteOneData = $objDLotteryEventsVote->get ( $vote_id );
  526. $this->tpl = 'admin/lottery/up_event_vote';
  527. $title = '修改投票';
  528. $this->setOutput ( 'title', $title );
  529. $this->addNavMenu ( '活动管理' );
  530. $this->setOutput ( 'voteOneData', $voteOneData );
  531. }
  532. /**
  533. * 事件: 修改投票信息
  534. */
  535. public function doUpEventVote() {
  536. $vote_id = Request::p ( 'vote_id' );
  537. $add_num = Request::p ( 'add_num' );
  538. $title = Request::p ( 'title' );
  539. $img_url = Request::p ( 'old_img_url' );
  540. $events_id = Request::p ( 'events_id' );
  541. $objDLotteryEventsVote = new LotteryEventsVote ();
  542. $tmpImgData = $this->loadImg ();
  543. if (is_array ( $tmpImgData )) {
  544. $img_url = $tmpImgData ['url'] [0];
  545. }
  546. $info = array (
  547. 'add_num' => $add_num,
  548. 'title' => $title,
  549. 'img_url' => $img_url
  550. );
  551. $objDLotteryEventsVote->modify ( $info, array (
  552. 'id' => $vote_id
  553. ) );
  554. header ( "Location: " . Request::schemeDomain () . "/?c=admin_Lottery&a=EventVotePage&events_id={$events_id}" );
  555. }
  556. public function doAddEventVote() {
  557. if (Request::isPost ()) {
  558. $title = Request::p ( 'title' );
  559. $events_id = Request::p ( 'events_id' );
  560. $img_url = '';
  561. $tmpImgData = $this->loadImg ();
  562. if (is_array ( $tmpImgData )) {
  563. $img_url = $tmpImgData ['url'] [0];
  564. }
  565. $add_num = Request::p ( 'add_num' );
  566. $info = array (
  567. 'title' => $title,
  568. 'img_url' => $img_url,
  569. 'add_num' => $add_num,
  570. 'events_id' => $events_id
  571. );
  572. $objDLotteryEventsVote = new LotteryEventsVote ();
  573. $id = $objDLotteryEventsVote->add ( $info );
  574. if (! $id) {
  575. self::ajax_fail_exit ( '数据库操作失败' );
  576. }
  577. $this->redirect ( Request::schemeDomain () . "/?c=admin_Lottery&a=UpEventVotePage&vote_id={$id}" );
  578. } else {
  579. $events_id = Request::g ( 'events_id' );
  580. $this->tpl = 'admin/lottery/add_event_vote';
  581. $title = '修改投票';
  582. $this->setOutput ( 'title', $title );
  583. $this->addNavMenu ( '活动管理' );
  584. $this->addNavMenu ( '添加投票项', Request::url (), '_self' );
  585. $this->setOutput ( 'events_id', $events_id );
  586. }
  587. }
  588. /**
  589. * 事件:ajax 创建投票活动
  590. */
  591. public function doCreateVote() {
  592. $events_id = Request::p ( 'events_id' );
  593. $vote_num = Request::p ( 'vote_num' );
  594. $vote_type = Request::p ( 'vote_type' );
  595. $vote_title = Request::p ( 'vote_title' );
  596. $objDLotteryEvents = new LotteryEvents ();
  597. $info = array (
  598. 'vote_type' => $vote_type,
  599. 'vote_title' => $vote_title
  600. );
  601. $objDLotteryEvents->modify ( $info, array (
  602. 'id' => $events_id
  603. ) );
  604. $objDLotteryEventsVote = new LotteryEventsVote ();
  605. for($i = 1; $i <= $vote_num; $i ++) {
  606. $info = array (
  607. 'events_id' => $events_id,
  608. 'title' => 'null',
  609. 'img_url' => 'null'
  610. );
  611. $objDLotteryEventsVote->add ( $info );
  612. }
  613. $this->ajax_success_exit ( '创建成功' );
  614. }
  615. /**
  616. * 事件:ajax 创建收集字母
  617. */
  618. public function doCreateLetters() {
  619. $events_id = Request::p ( 'events_id' );
  620. $lettersText = Request::p ( 'lettersText' );
  621. $data = explode ( '@', $lettersText );
  622. $objDLotteryEvents = new LotteryEvents ();
  623. $info = array (
  624. 'ABC_data' => $data
  625. );
  626. $objDLotteryEvents->modify ( $info, array (
  627. 'id' => $events_id
  628. ) );
  629. $objDLotteryEventsLetters = new LotteryEventsLetters ();
  630. $objMLotteryDrawLetters = new LotteryDrawLetters ( null, $events_id );
  631. foreach ( $data as $key => $data ) {
  632. $info = array (
  633. 'ABC_name' => $data,
  634. 'events_id' => $events_id
  635. );
  636. $id = $objDLotteryEventsLetters->add ( $info );
  637. $objMLotteryDrawLetters->clear_draw_next_time ( $id );
  638. }
  639. $this->ajax_success_exit ( '创建成功' );
  640. }
  641. /**
  642. * 页面:添加奖项页面
  643. */
  644. public function doAddPrizePage() {
  645. $events_id = Request::g ( 'events_id' );
  646. $events_Data = $this->objLottery->getOneLotteryEvents ( $events_id );
  647. $objDLotteryEvents = new LotteryEvents ();
  648. $eventsType = $objDLotteryEvents->getType ();
  649. $eventsDisplayStatus = $objDLotteryEvents->getDisplay ();
  650. $objDLotteryPrize = new LotteryPrize ();
  651. $prizeType = $objDLotteryPrize->getType ();
  652. $prizeDisplayStatus = $objDLotteryPrize->getDisplay ();
  653. $prizeExpress = $objDLotteryPrize->getExpress ();
  654. $this->tpl = 'admin/lottery/add_prize';
  655. $title = '添加奖项';
  656. $this->setOutput ( 'title', $title );
  657. $this->addNavMenu ( '活动管理' );
  658. $this->addNavMenu ( $title, Request::url (), '_self' );
  659. $this->setOutput ( 'events_id', $events_id );
  660. $this->setOutput ( 'eventsType', $eventsType );
  661. $this->setOutput ( 'prizeExpress', $prizeExpress );
  662. $this->setOutput ( 'eventsDisplayStatus', $eventsDisplayStatus );
  663. $this->setOutput ( 'prizeType', $prizeType );
  664. $this->setOutput ( 'prizeDisplayStatus', $prizeDisplayStatus );
  665. $this->setOutput ( 'events_Data', $events_Data );
  666. }
  667. /**
  668. * 事件:添加奖项
  669. */
  670. public function doAddPrize() {
  671. $events_id = Request::p ( 'events_id' );
  672. $prize_name = Request::p ( 'prize_name' );
  673. $begin_hour = Request::p ( 'begin_hour' );
  674. $end_hour = Request::p ( 'end_hour' );
  675. $type = Request::p ( 'type' );
  676. $prize_num = Request::p ( 'prize_num' );
  677. $virtual_data_str = Request::p ( 'virtual_data' );
  678. $white_list_str = Request::p ( 'white_list' );
  679. $hundred_percent_list_str = Request::p ( 'hundred_percent_list' );
  680. $black_list_str = Request::p ( 'black_list' );
  681. $express = Request::p ( 'express' );
  682. $img_url = '';
  683. $tmpImgData = $this->loadImg ();
  684. if (is_array ( $tmpImgData )) {
  685. $img_url = $tmpImgData ['url'] [0];
  686. }
  687. $virtual_data = array ();
  688. $tmp_virtual_data = explode ( "\n", $virtual_data_str );
  689. foreach ( $tmp_virtual_data as $data ) {
  690. if (! empty ( $data )) {
  691. $virtual_data [$data] = $data;
  692. }
  693. }
  694. if ($type == LotteryPrize::TYPE_ENTITY) {
  695. $prize_num = count ( $virtual_data );
  696. }
  697. $white_list = array ();
  698. $tmp_white_list = explode ( "\n", $white_list_str );
  699. foreach ( $tmp_white_list as $data ) {
  700. if (! empty ( $data )) {
  701. $white_list [$data] = $data;
  702. }
  703. }
  704. $hundred_percent_list = array ();
  705. $tmp_hundred_percent_list = explode ( "\n", $hundred_percent_list_str );
  706. foreach ( $tmp_hundred_percent_list as $data ) {
  707. if (! empty ( $data )) {
  708. $hundred_percent_list [$data] = $data;
  709. }
  710. }
  711. $black_list = array ();
  712. $tmp_black_list = explode ( "\n", $black_list_str );
  713. foreach ( $tmp_black_list as $data ) {
  714. if (! empty ( $data )) {
  715. $black_list [$data] = $data;
  716. }
  717. }
  718. $info = array (
  719. 'events_id' => $events_id,
  720. 'prize_name' => $prize_name,
  721. 'prize_num' => $prize_num,
  722. 'type' => $type,
  723. 'white_list' => $white_list,
  724. 'hundred_percent_list' => $hundred_percent_list,
  725. 'black_list' => $black_list,
  726. 'begin_hour' => $begin_hour,
  727. 'end_hour' => $end_hour,
  728. 'img_url' => $img_url,
  729. 'virtual_data' => $virtual_data,
  730. 'express' => $express
  731. );
  732. $this->objLottery->addLotteryPrize ( $info );
  733. header ( "Location: " . Request::schemeDomain () . "/?c=admin_Lottery&a=EventPage&events_id={$events_id}" );
  734. }
  735. /**
  736. * 事件:增加奖项数量[虚拟,实物]
  737. */
  738. public function doAddPrizeNum() {
  739. $virtual_data_str = Request::p ( 'virtual_data' );
  740. $prize_id = Request::p ( 'prize_id' );
  741. $num = Request::p ( 'prize_num' );
  742. $events_id = Request::p ( 'events_id' );
  743. $virtual_data = array ();
  744. $tmp_virtual_data = explode ( "\n", $virtual_data_str );
  745. foreach ( $tmp_virtual_data as $data ) {
  746. if (! empty ( $data )) {
  747. $virtual_data [$data] = $data;
  748. }
  749. }
  750. $this->objLottery->addLotteryPrizeNum ( $prize_id, $num, $virtual_data );
  751. header ( "Location: " . Request::schemeDomain () . "/?c=admin_Lottery&a=EventPage&events_id={$events_id}" );
  752. }
  753. /**
  754. * 事件ajax:减少奖项数量[实物]
  755. */
  756. public function doMinusPrizeNum() {
  757. $prize_id = Request::p ( 'pirze_id' );
  758. $num = Request::p ( 'num' );
  759. $this->objLottery->addLotteryPrizeNum ( $prize_id, - $num );
  760. $this->ajax_success_exit ( '操作成功' );
  761. }
  762. /**
  763. * 事件:修改奖项
  764. */
  765. public function doUpPrize() {
  766. $prize_id = Request::p ( 'prize_id' );
  767. $events_id = Request::p ( 'events_id' );
  768. $prize_name = Request::p ( 'prize_name' );
  769. $begin_hour = Request::p ( 'begin_hour' );
  770. $end_hour = Request::p ( 'end_hour' );
  771. $white_list_str = Request::p ( 'white_list' );
  772. $hundred_percent_list_str = Request::p ( 'hundred_percent_list' );
  773. $black_list_str = Request::p ( 'black_list' );
  774. $display = Request::p ( 'display' );
  775. $express = Request::p ( 'express' );
  776. $img_url = Request::p ( 'old_img_url' );
  777. $tmpImgData = $this->loadImg ();
  778. if (is_array ( $tmpImgData )) {
  779. $img_url = $tmpImgData ['url'] [0];
  780. }
  781. $white_list = array ();
  782. $tmp_white_list = explode ( "\n", $white_list_str );
  783. foreach ( $tmp_white_list as $data ) {
  784. if (! empty ( $data )) {
  785. $white_list [$data] = $data;
  786. }
  787. }
  788. $hundred_percent_list = array ();
  789. $tmp_hundred_percent_list = explode ( "\n", $hundred_percent_list_str );
  790. foreach ( $tmp_hundred_percent_list as $data ) {
  791. if (! empty ( $data )) {
  792. $hundred_percent_list [$data] = $data;
  793. }
  794. }
  795. $black_list = array ();
  796. $tmp_black_list = explode ( "\n", $black_list_str );
  797. foreach ( $tmp_black_list as $data ) {
  798. if (! empty ( $data )) {
  799. $black_list [$data] = $data;
  800. }
  801. }
  802. $info = array (
  803. 'events_id' => $events_id,
  804. 'prize_name' => $prize_name,
  805. 'white_list' => $white_list,
  806. 'hundred_percent_list' => $hundred_percent_list,
  807. 'black_list' => $black_list,
  808. 'begin_hour' => $begin_hour,
  809. 'end_hour' => $end_hour,
  810. 'img_url' => $img_url,
  811. 'display' => $display,
  812. 'express' => $express
  813. );
  814. $this->objLottery->UpLotteryPrize ( $info, array (
  815. 'id' => $prize_id
  816. ) );
  817. header ( "Location: " . Request::schemeDomain () . "/?c=admin_Lottery&a=EventPage&events_id={$events_id}" );
  818. }
  819. /**
  820. * 页面:修改奖项页
  821. */
  822. public function doUpPrizePage() {
  823. $prize_id = Request::g ( 'prize_id' );
  824. $prize_data = $this->objLottery->getOneLotteryPrize ( $prize_id );
  825. $prize_data ['black_list'] = join ( "\n", $prize_data ['black_list'] );
  826. $prize_data ['hundred_percent_list'] = join ( "\n", $prize_data ['hundred_percent_list'] );
  827. $prize_data ['white_list'] = join ( "\n", $prize_data ['white_list'] );
  828. $event_data = $this->objLottery->getOneLotteryEvents ( $prize_data ['events_id'] );
  829. $objDLotteryEvents = new LotteryEvents ();
  830. $eventsType = $objDLotteryEvents->getType ();
  831. $eventsDisplayStatus = $objDLotteryEvents->getDisplay ();
  832. $objDLotteryPrize = new LotteryPrize ();
  833. $prizeType = $objDLotteryPrize->getType ();
  834. $prizeExpress = $objDLotteryPrize->getExpress ();
  835. $prizeDisplayStatus = $objDLotteryPrize->getDisplay ();
  836. $this->tpl = 'admin/lottery/up_prize';
  837. $title = '修改奖项';
  838. $this->setOutput ( 'title', $title );
  839. $this->addNavMenu ( '活动管理' );
  840. $this->addNavMenu ( $title, Request::url (), '_self' );
  841. $this->setOutput ( 'eventsType', $eventsType );
  842. $this->setOutput ( 'eventsDisplayStatus', $eventsDisplayStatus );
  843. $this->setOutput ( 'prizeType', $prizeType );
  844. $this->setOutput ( 'prizeExpress', $prizeExpress );
  845. $this->setOutput ( 'prizeDisplayStatus', $prizeDisplayStatus );
  846. $this->setOutput ( 'prize_data', $prize_data );
  847. $this->setOutput ( 'event_data', $event_data );
  848. }
  849. /**
  850. * 页面:获奖数据列表页
  851. */
  852. public function doLotteryDataListPage() {
  853. $events_id = Request::g ( 'events_id' );
  854. $scratch_receive = Request::g ( 'scratch_receive' );
  855. $eventsAndPrizeData = $this->objLottery->getOneLotteryEventsAndPrize ( $events_id );
  856. if ($eventsAndPrizeData ['events'] ['type'] == LotteryEvents::TYPE_EVENTS_SCRATCH) {
  857. }
  858. // 取数据
  859. $page = Request::varGetInt ( 'page', 1 );
  860. $size = 20;
  861. $offset = ($page - 1) * $size;
  862. $limit = "{$offset},{$size}";
  863. $condition = array (
  864. 'events_id' => $events_id
  865. );
  866. // 刮刮卡 跳将特殊处理
  867. $pieze_notreceive_num = array ();
  868. if ($eventsAndPrizeData ['events'] ['type'] == LotteryEvents::TYPE_EVENTS_SCRATCH) {
  869. $condition ['scratch_receive'] = LotteryData::EVENT_SCRATCH_RECEIVE_TRUE;
  870. foreach ( $eventsAndPrizeData ['prize'] as $prize ) {
  871. $for_condition = array (
  872. 'events_id' => $events_id,
  873. 'prize_id' => $prize ['id'],
  874. 'scratch_receive' => LotteryData::EVENT_SCRATCH_RECEIVE_FALSE
  875. );
  876. $pieze_notreceive_num [$prize ['id']] = $this->objLottery->getLotteryDataListNum ( $for_condition );
  877. }
  878. }
  879. // 筛选条件
  880. $prize_id = Request::g ( 'prize_id' );
  881. if ($prize_id) {
  882. $condition ['prize_id'] = $prize_id;
  883. }
  884. if ($scratch_receive == 'false') {
  885. $condition ['scratch_receive'] = LotteryData::EVENT_SCRATCH_RECEIVE_FALSE;
  886. }
  887. $total_num = $this->objLottery->getLotteryDataListNum ( $condition );
  888. $url_tpl = Request::schemeDomain () . "?c=admin_Lottery&a=LotteryDataListPage&events_id={$events_id}";
  889. if ($prize_id) {
  890. $url_tpl .= "&prize_id={$prize_id}";
  891. }
  892. $url_tpl .= "&page={page}";
  893. // 分页
  894. $objPage = new Page ( $total_num, $url_tpl, $page, $size );
  895. $page_html = $objPage->html ();
  896. $order = 'id desc';
  897. $lotteryData = $this->objLottery->getLotteryDataList ( $condition, $limit, $order );
  898. $objDLotteryPrize = new LotteryPrize ();
  899. $prizeType = $objDLotteryPrize->getType ();
  900. $prizeDisplayStatus = $objDLotteryPrize->getDisplay ();
  901. $this->tpl = 'admin/lottery/lottery_data_list';
  902. $title = '获奖数据列表';
  903. $this->setOutput ( 'title', $title );
  904. $this->addNavMenu ( '活动管理' );
  905. $this->addNavMenu ( $title, Request::url (), '_self' );
  906. $this->setOutput ( 'page_html', $page_html );
  907. $this->setOutput ( 'eventsAndPrizeData', $eventsAndPrizeData );
  908. $this->setOutput ( 'pieze_notreceive_num', $pieze_notreceive_num );
  909. $this->setOutput ( 'prizeType', $prizeType );
  910. $this->setOutput ( 'lotteryData', $lotteryData );
  911. }
  912. /**
  913. * 页面: 收集字母 数据
  914. */
  915. public function doLettersDataPage() {
  916. $events_id = Request::varGetInt ( 'events_id' );
  917. $objDLotteryEventsLetters = new LotteryEventsLetters ();
  918. $lettersData = $objDLotteryEventsLetters->getEventData ( $events_id );
  919. $eventsAndPrizeData = $this->objLottery->getOneLotteryEventsAndPrize ( $events_id );
  920. $objMLotteryDrawLetters = new LotteryDrawLetters ( null, $events_id );
  921. foreach ( $lettersData as $key => $data ) {
  922. $lettersData [$key] ['next_time'] = $objMLotteryDrawLetters->getNextWinTime ( $data ['id'] );
  923. }
  924. $this->tpl = 'admin/lottery/event_letters_data';
  925. $title = '字母详情';
  926. $this->setOutput ( 'title', $title );
  927. $this->addNavMenu ( '活动管理' );
  928. $this->addNavMenu ( $title, Request::url (), '_self' );
  929. $this->setOutput ( 'lettersData', $lettersData );
  930. $this->setOutput ( 'eventsAndPrizeData', $eventsAndPrizeData );
  931. }
  932. /**
  933. * 页面: 用户收集字母列表
  934. */
  935. public function doLotteryEventsUserLettersPage() {
  936. $events_id = Request::varGetInt ( 'events_id' );
  937. $objDLotteryEventsLetters = new LotteryEventsLetters ();
  938. $lettersData = $objDLotteryEventsLetters->getEventData ( $events_id );
  939. $eventsAndPrizeData = $this->objLottery->getOneLotteryEventsAndPrize ( $events_id );
  940. $objDLotteryEventsUserLetters = new LotteryEventsUserLetters ();
  941. $condition = array (
  942. 'events_id' => $events_id
  943. );
  944. // 取数据
  945. $page = Request::varGetInt ( 'page', 1 );
  946. $size = 20;
  947. $offset = ($page - 1) * $size;
  948. $limit = "{$offset},{$size}";
  949. $allLotteryEventsIds = $objDLotteryEventsUserLetters->findIdsBy ( $condition, $limit, 'id desc' );
  950. $userData = $objDLotteryEventsUserLetters->gets ( $allLotteryEventsIds );
  951. foreach ( $userData as $key => $data ) {
  952. foreach ( $lettersData as $k => $d ) {
  953. if (isset ( $userData [$key] ['ABC_data'] [$d ['id']] )) {
  954. $userData [$key] ['ABC_data'] [$d ['id']] = array (
  955. 'state' => '已收集',
  956. 'ABC_name' => $d ['ABC_name']
  957. );
  958. } else {
  959. $userData [$key] ['ABC_data'] [$d ['id']] = array (
  960. 'state' => '未收集',
  961. 'ABC_name' => $d ['ABC_name']
  962. );
  963. ;
  964. }
  965. }
  966. }
  967. $total_num = $objDLotteryEventsUserLetters->totals ( $condition );
  968. $url_tpl = Request::schemeDomain () . "?c=admin_lottery&a=LotteryEventsUserLettersPage&events_id={$events_id}";
  969. $url_tpl .= "&page={page}";
  970. // 分页
  971. $objPage = new Page ( $total_num, $url_tpl, $page, $size );
  972. $page_html = $objPage->html ();
  973. $this->tpl = 'admin/lottery/event_user_letters_list';
  974. $title = '用户收集字母列表';
  975. $this->setOutput ( 'title', $title );
  976. $this->addNavMenu ( '活动管理' );
  977. $this->addNavMenu ( $title, Request::url (), '_self' );
  978. $this->setOutput ( 'lettersData', $lettersData );
  979. $this->setOutput ( 'userData', $userData );
  980. $this->setOutput ( 'page_html', $page_html );
  981. $this->setOutput ( 'eventsAndPrizeData', $eventsAndPrizeData );
  982. }
  983. /**
  984. * 页面:修改收集字母数据
  985. */
  986. public function doUpLettersDataPage() {
  987. $letters_id = Request::varGetInt ( 'id' );
  988. $objDLotteryEventsLetters = new LotteryEventsLetters ();
  989. $letters_data = $objDLotteryEventsLetters->get ( $letters_id );
  990. $eventsAndPrizeData = $this->objLottery->getOneLotteryEventsAndPrize ( $letters_data ['events_id'] );
  991. $this->tpl = 'admin/lottery/up_letters';
  992. $title = '修改字母详情';
  993. $this->setOutput ( 'title', $title );
  994. $this->addNavMenu ( '活动管理' );
  995. $this->addNavMenu ( $title, Request::url (), '_self' );
  996. $this->setOutput ( 'letters_data', $letters_data );
  997. $this->setOutput ( 'eventsAndPrizeData', $eventsAndPrizeData );
  998. }
  999. /**
  1000. * 事件:修改收集字母数据
  1001. */
  1002. public function doUpLettersData() {
  1003. $id = Request::varPostInt ( 'letters_data_id' );
  1004. $num = Request::varPostInt ( 'num' );
  1005. $info = array (
  1006. 'num' => $num
  1007. );
  1008. $tmpImgData = $this->loadImg ();
  1009. if (is_array ( $tmpImgData )) {
  1010. if ($tmpImgData ['url'] [1]) {
  1011. $info ['img_1'] = $tmpImgData ['url'] [1];
  1012. }
  1013. if ($tmpImgData ['url'] [2]) {
  1014. $info ['img_2'] = $tmpImgData ['url'] [2];
  1015. }
  1016. }
  1017. $objDLotteryEventsLetters = new LotteryEventsLetters ();
  1018. $condition = array (
  1019. 'id' => $id
  1020. );
  1021. $objDLotteryEventsLetters->modify ( $info, $condition );
  1022. $letters_data = $objDLotteryEventsLetters->get ( $id );
  1023. $objMLotteryDrawLetters = new LotteryDrawLetters ( null, $letters_data ['events_id'] );
  1024. $objMLotteryDrawLetters->clear_draw_next_time ( $id );
  1025. header ( "Location: " . Request::schemeDomain () . "/?c=admin_Lottery&a=LettersDataPage&events_id={$letters_data['events_id']}" );
  1026. }
  1027. /**
  1028. * 页面:虚拟数据列表页
  1029. */
  1030. public function doVirtualDataListPage() {
  1031. $prize_id = Request::g ( 'prize_id' );
  1032. $lottery_data_id = Request::g ( 'lottery_data_id' );
  1033. $prizeData = $this->objLottery->getOneLotteryPrize ( $prize_id );
  1034. // 取数据
  1035. $page = Request::varGetInt ( 'page', 1 );
  1036. $size = 20;
  1037. $offset = ($page - 1) * $size;
  1038. $limit = "{$offset},{$size}";
  1039. $condition = array (
  1040. 'prize_id' => $prize_id
  1041. );
  1042. if ($lottery_data_id == 'true') {
  1043. $condition ['lottery_data_id'] = SqlHelper::addCompareOperator ( '!=', 0 );
  1044. }
  1045. if ($lottery_data_id == 'false') {
  1046. $condition ['lottery_data_id'] = 0;
  1047. }
  1048. $order = 'id desc';
  1049. $prizeVirtualData = $this->objLottery->getLotteryPrizeVirtualDataList ( $condition, $limit, $order );
  1050. $page_html = '';
  1051. $total_num = $this->objLottery->getLotteryPrizeVirtualDataListNum ( $condition );
  1052. $url_tpl = Request::schemeDomain () . "?c=admin_Lottery&a=VirtualDataListPage&prize_id={$prize_id}";
  1053. if ($lottery_data_id) {
  1054. $url_tpl .= "&lottery_data_id={$lottery_data_id}";
  1055. }
  1056. $url_tpl .= "&page={page}";
  1057. // 分页
  1058. $objPage = new Page ( $total_num, $url_tpl, $page, $size );
  1059. $page_html = $objPage->html ();
  1060. // 通过data_id 获取用户中奖信息
  1061. $dataIds = array ();
  1062. foreach ( $prizeVirtualData as $key => $data ) {
  1063. if ($data ['lottery_data_id']) {
  1064. $dataIds [$data ['lottery_data_id']] = $data ['lottery_data_id'];
  1065. }
  1066. }
  1067. $lotteryData = $this->objLottery->getLotteryDatas ( $dataIds );
  1068. $title = '虚拟数据列表';
  1069. $this->setOutput ( 'title', $title );
  1070. $this->addNavMenu ( '活动管理' );
  1071. $this->addNavMenu ( $title, Request::url (), '_self' );
  1072. $this->setOutput ( 'prizeVirtualData', $prizeVirtualData );
  1073. $this->setOutput ( 'page_html', $page_html );
  1074. $this->setOutput ( 'prizeData', $prizeData );
  1075. $this->setOutput ( 'lotteryData', $lotteryData );
  1076. $this->tpl = 'admin/lottery/prize_virtual_list';
  1077. }
  1078. /**
  1079. * 事件ajax: 删除一条虚拟数据
  1080. */
  1081. public function doDelPrizeVirtual() {
  1082. $prize_id = Request::p ( 'prize_id' );
  1083. $prize_virtua_id = Request::p ( 'prize_virtua_id' );
  1084. $prizeData = $this->objLottery->delLotteryPrizeVirtual ( $prize_virtua_id );
  1085. $this->ajax_success_exit ( '删除成功' );
  1086. }
  1087. /**
  1088. * 页面:获取用户参与活动日志
  1089. */
  1090. public function doShowUserParticipateLogPage() {
  1091. $events_id = Request::varGetInt ( 'events_id' );
  1092. $groupByUid = Request::g ( 'groupByUid' );
  1093. $objMLotteryLog = new LotteryLog ( null, $events_id );
  1094. $eventData = $this->objLottery->getOneLotteryEvents ( $events_id );
  1095. $this->setOutput ( 'eventData', $eventData );
  1096. $page = Request::varGetInt ( 'page', 1 );
  1097. $size = 20;
  1098. $offset = ($page - 1) * $size;
  1099. $limit = "{$offset},{$size}";
  1100. $order = ' id desc';
  1101. if ($groupByUid) {
  1102. $logData = $objMLotteryLog->findUserParticipateDataGroupByUid ( $limit, $order );
  1103. } else {
  1104. $condition = array (
  1105. 'events_id' => $events_id
  1106. );
  1107. $logData = $objMLotteryLog->findUserParticipateData ( $condition, $limit, $order );
  1108. }
  1109. $uids = array ();
  1110. foreach ( $logData as $key => $data ) {
  1111. $uids [$data ['uid']] = $data ['uid'];
  1112. }
  1113. $objMWeixinUser = new WeixinUser ();
  1114. $userData = $objMWeixinUser->gets ( $uids );
  1115. $total_user_num = $objMLotteryLog->getUserParticipateLogNumGroupByUid ();
  1116. if ($groupByUid) {
  1117. $total_num = $total_user_num;
  1118. } else {
  1119. $total_num = $objMLotteryLog->getUserParticipateLogNum ( $condition );
  1120. }
  1121. $url_tpl = Request::schemeDomain () . "?c=admin_lottery&a=ShowUserParticipateLogPage&events_id={$events_id}";
  1122. $url_tpl .= "&page={page}";
  1123. // 分页
  1124. $objPage = new Page ( $total_num, $url_tpl, $page, $size );
  1125. $page_html = $objPage->html ();
  1126. $this->tpl = 'admin/lottery/event_user_participate_log_list';
  1127. $title = '查看用户参与活动日志';
  1128. $this->setOutput ( 'title', $title );
  1129. $this->setOutput ( 'page_html', $page_html );
  1130. $this->addNavMenu ( '活动管理' );
  1131. $this->addNavMenu ( $title, Request::url (), '_self' );
  1132. $this->setOutput ( 'logData', $logData );
  1133. $this->setOutput ( 'userData', $userData );
  1134. $this->setOutput ( 'groupByUid', $groupByUid );
  1135. $this->setOutput ( 'total_user_num', $total_user_num );
  1136. }
  1137. /**
  1138. * 导出:获取用户参与活动日志
  1139. * ?c=admin_lottery&a=ShowUserParticipateLogExportData&events_id=x
  1140. * ?c=admin_lottery&a=ShowUserParticipateLogExportData&groupByUid=true&events_id=x
  1141. */
  1142. public function doShowUserParticipateLogExportData() {
  1143. $events_id = Request::varGetInt ( 'events_id' );
  1144. $groupByUid = Request::g ( 'groupByUid' );
  1145. $datalist = array ();
  1146. $objMLotteryLog = new LotteryLog ( null, $events_id );
  1147. $allData = array ();
  1148. if ($groupByUid) {
  1149. $allData = $objMLotteryLog->findUserParticipateDataGroupByUid ();
  1150. } else {
  1151. $condition = array (
  1152. 'events_id' => $events_id
  1153. );
  1154. $allData = $objMLotteryLog->findUserParticipateData ( $condition );
  1155. }
  1156. $uids = array ();
  1157. foreach ( $allData as $key => $data ) {
  1158. $uids [$data ['uid']] = $data ['uid'];
  1159. }
  1160. $objMWeixinUser = new WeixinUser ();
  1161. $userData = $objMWeixinUser->gets ( $uids );
  1162. $filename = '' . date ( 'YmdHis' ) . '.csv';
  1163. header ( "Content-Type: application/vnd.ms-excel; charset=GBK" );
  1164. header ( "Pragma: public" );
  1165. header ( "Expires: 0" );
  1166. header ( "Cache-Control: must-revalidate, post-check=0, pre-check=0" );
  1167. header ( "Content-Type: application/force-download" );
  1168. header ( "Content-Type: application/octet-stream" );
  1169. header ( "Content-Type: application/download" );
  1170. header ( 'Content-Disposition: attachment; filename=' . $filename );
  1171. header ( "Content-Transfer-Encoding: binary " );
  1172. $titleTag = '用户ID,昵称,时间,其他' . "\n";
  1173. foreach ( $allData as $data ) {
  1174. if (isset ( $data ['other'] )) {
  1175. $otherStr = '';
  1176. foreach ( $data ['other'] as $k => $d ) {
  1177. $otherStr = $otherStr . $k . $d;
  1178. }
  1179. $titleTag .= $data ['uid'] . ',' . $userData [$data ['uid']] ['nickname'] . ',' . date ( 'Y-m-d H:i:s', $data ['create_time'] ) . ',' . $otherStr . "\n";
  1180. } else {
  1181. $titleTag .= $data ['uid'] . ',' . $userData [$data ['uid']] ['nickname'] . ',' . date ( 'Y-m-d H:i:s', $data ['create_time'] ) . ',空' . "\n";
  1182. }
  1183. }
  1184. $titleTag = Convert::u82gb ( $titleTag );
  1185. exit ( $titleTag );
  1186. }
  1187. public function display() {
  1188. return $this->render ();
  1189. }
  1190. /**
  1191. * 图片上传
  1192. */
  1193. public function loadImg($image_name = 'image') {
  1194. $uploadConfig = Config::getInstance ()->get ( 'upload' );
  1195. // 定义允许上传的文件扩展名
  1196. $ext_arr = array (
  1197. 'image' => array (
  1198. 'gif',
  1199. 'jpg',
  1200. 'jpeg',
  1201. 'png',
  1202. 'bmp'
  1203. )
  1204. );
  1205. if (! is_array ( $_FILES [$image_name] ['name'] )) {
  1206. foreach ( $_FILES [$image_name] as $key => $data ) {
  1207. unset ( $_FILES [$image_name] [$key] );
  1208. $_FILES [$image_name] [$key] [] = $data;
  1209. }
  1210. }
  1211. $file_url = array ();
  1212. foreach ( $_FILES [$image_name] ['name'] as $key => $oneData ) {
  1213. // 文件保存目录路径
  1214. $save_path = $uploadConfig ['path'] . '/';
  1215. $save_path = realpath ( $save_path ) . '/';
  1216. // PHP上传失败
  1217. if ($_FILES [$image_name] ['error'] [$key] != 0) {
  1218. switch ($_FILES [$image_name] ['error'] [$key]) {
  1219. case '1' :
  1220. $error = '超过php.ini允许的大小。';
  1221. break;
  1222. case '2' :
  1223. $error = '超过表单允许的大小。';
  1224. break;
  1225. case '3' :
  1226. $error = '图片只有部分被上传。';
  1227. break;
  1228. case '4' :
  1229. $error = '请选择图片。';
  1230. break;
  1231. case '6' :
  1232. $error = '找不到临时目录。';
  1233. break;
  1234. case '7' :
  1235. $error = '写文件到硬盘出错。';
  1236. break;
  1237. case '8' :
  1238. $error = 'File upload stopped by extension。';
  1239. break;
  1240. case '999' :
  1241. default :
  1242. $error = '未知错误。';
  1243. }
  1244. return $error;
  1245. }
  1246. // 有上传文件时
  1247. if (empty ( $_FILES ) === false) {
  1248. // 原文件名
  1249. $file_name = $_FILES [$image_name] ['name'] [$key];
  1250. // 服务器上临时文件名
  1251. $tmp_name = $_FILES [$image_name] ['tmp_name'] [$key];
  1252. // 文件大小
  1253. $file_size = $_FILES [$image_name] ['size'] [$key];
  1254. // 检查文件名
  1255. if (! $file_name) {
  1256. return "请选择文件。";
  1257. }
  1258. // 检查目录
  1259. if (@is_dir ( $save_path ) === false) {
  1260. return "上传目录不存在。";
  1261. }
  1262. // 检查目录写权限
  1263. if (@is_writable ( $save_path ) === false) {
  1264. return "上传目录没有写权限。";
  1265. }
  1266. // 检查是否已上传
  1267. if (@is_uploaded_file ( $tmp_name ) === false) {
  1268. return "上传失败。";
  1269. }
  1270. // 检查目录名
  1271. $dir_name = 'image';
  1272. if (empty ( $ext_arr [$dir_name] )) {
  1273. return "目录名不正确。";
  1274. }
  1275. // 获得文件扩展名
  1276. $temp_arr = explode ( ".", $file_name );
  1277. $file_ext = array_pop ( $temp_arr );
  1278. $file_ext = trim ( $file_ext );
  1279. $file_ext = strtolower ( $file_ext );
  1280. // 检查扩展名
  1281. if (in_array ( $file_ext, $ext_arr [$dir_name] ) === false) {
  1282. return "上传文件扩展名是不允许的扩展名。\n只允许" . implode ( ",", $ext_arr [$dir_name] ) . "格式。";
  1283. }
  1284. // 创建文件夹
  1285. $ymd = date ( "Ymd" );
  1286. $ymd = date ( "Y" ) . '/' . date ( 'md' );
  1287. // 文件保存目录URL
  1288. $save_url = $uploadConfig ['url'] . '/';
  1289. $new_file_name = '';
  1290. $save_path .= $dir_name . "/" . $ymd . "/";
  1291. $save_url .= $dir_name . "/" . $ymd . "/";
  1292. if (! file_exists ( $save_path )) {
  1293. if (! mkdir ( $save_path, 0775, true )) {
  1294. return "创建目录失败:{$save_path}";
  1295. }
  1296. }
  1297. // 新文件名
  1298. $new_file_name = date ( "His" ) . '_' . rand ( 10000, 99999 ) . '.' . $file_ext;
  1299. // 移动文件
  1300. $file_path = $save_path . $new_file_name;
  1301. // 原图上传
  1302. if (move_uploaded_file ( $tmp_name, $file_path ) === false) {
  1303. return "上传文件失败。";
  1304. }
  1305. error_reporting ( E_ALL );
  1306. // 压缩65质量原图
  1307. $this_basename = basename ( $file_path );
  1308. $this_dirname = dirname ( $file_path );
  1309. $z_file_path = $this_dirname . '/' . 'z.' . $this_basename;
  1310. Image::transformFormat ( $file_path, $z_file_path, 'JPG' );
  1311. /*
  1312. * $img = imagecreatefromjpeg ( $z_file_path );
  1313. * // 获取拍摄角度 旋转图片
  1314. * $exifData = exif_read_data ( $file_path );
  1315. * if (isset ( $exifData ['Orientation'] ) && $exifData ['Orientation'] == 6) {
  1316. * $new = imagerotate ( $img, - 90, 0 );
  1317. * imagejpeg ( $new, $z_file_path, 65 );
  1318. * imagedestroy ( $new );
  1319. * } else {
  1320. * imagejpeg ( $img, $z_file_path, 65 );
  1321. * imagedestroy ( $img );
  1322. * }
  1323. */
  1324. @chmod ( $file_path, 0777 );
  1325. $file_url [$key] = $save_url . 'z.' . $new_file_name;
  1326. }
  1327. }
  1328. return array (
  1329. 'error' => 0,
  1330. 'url' => $file_url
  1331. );
  1332. }
  1333. /**
  1334. * 表单验证规则
  1335. *
  1336. * @return multitype:multitype:string
  1337. */
  1338. public function formRegular() {
  1339. return array (
  1340. 1 => array (
  1341. 'desc' => '手机验证',
  1342. 'regular' => '/^(1[0-9][0-9]|15[0-9]|18[02-9]|14[57])[0-9]{8}$/'
  1343. ),
  1344. 2 => array (
  1345. 'desc' => '邮箱验证',
  1346. 'regular' => '/^[\w\-\.]+@[\w\-\.]+(\.\w+)+$/'
  1347. )
  1348. );
  1349. }
  1350. }