123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217 |
- <?php
- namespace Cas\Controller;
- use Cas\Module\LotteryEventsLimitations;
- use Cas\Module\LotteryEventsTypeLetters;
- use Cas\Dao\LotteryEvents;
- use KIF\Dao\SqlHelper;
- use Cas\Module\Lottery;
- use Cas\Dao\LotteryUserExpress;
- use KIF\Core\Request;
- use KIF\Verify;
- use Cas\Dao\UserInfo;
- use Cas\Module\Count;
- use Cas\Dao\Platform;
- /**
- * 收集字母
- * lihuanchun
- */
- class EventsLetters extends EventsController {
-
-
- /**
- * 页面:默认页面
- */
- public function doDefault() {
- //$events_id = Request::g('events_id');
- $events_id = $this->getEventsCreateTimeToId();
- if (!Verify::unsignedInt($events_id)) {
- self::fail_exit('无效id');
- }
-
-
- # 获取用户信息
- $objUserData = new UserInfo();
- $uid = $this->getRunTimeUid();
- $userData = $objUserData -> get($uid);
- $this->setOutput('userData', $userData);
-
- # 获取当前活动的信息 & 字母 & 奖项
- $objMLotteryEventsTypeLetters = new LotteryEventsTypeLetters($uid,$events_id);
- $lettersData = $objMLotteryEventsTypeLetters -> getEventsData();
-
- # 获取登录地址
- $url = Request::g('url');
- $plat_form_id = $this->getPlatFormId();
- $objMLottery = new Lottery();
- $thisUrl = $objMLottery -> getEventsUrl($lettersData['type'],$lettersData['create_time'],$url);
- $loginUrl = $this -> getLoginUrl($thisUrl);
- $this->setOutput('loginUrl', $loginUrl);
- # 判断是否需要登录
- $ckLogin = $this->ckLogin();
- $this->setOutput('ckLogin', $ckLogin);
-
-
-
-
- # 获取用户当前收集的字母列表
- $userLettersData = $objMLotteryEventsTypeLetters -> getUserLetters();
- foreach($lettersData['letters'] as $key => $data ){
- if(isset($userLettersData['ABC_data'][$key])){
- $lettersData['letters'][$key]['thisUser'] = true;
- }
- }
-
- # 检查当前活动是否需要登录
- $authorize = $lettersData['events']['authorize'];
- if ($authorize && $loginUrl) {
- if($ckLogin==true){
- self::redirect($loginUrl);
- }
- }
-
- $objMLotteryEventsLimitations = new LotteryEventsLimitations();
-
- # 活动状态
- $TIME = time();
- $eventsStatus = false;
-
- if($TIME < $lettersData['events']['begin_time'] ){
- $eventsStatus = 'STATUS_NOT_START';
-
- } elseif ($TIME > $lettersData['events']['end_time']){
- $eventsStatus = 'STATUS_HAS_END';
-
- } elseif ($lettersData['events']['display'] == \Cas\Dao\LotteryEvents::EVENT_DISPLAY_HIDE) {
- //$eventsStatus = 'STATUS_HIDE'; //先注释了。此隐藏 之印象列表
-
- }elseif (!$objMLotteryEventsLimitations->ckEventRestrictions($uid,Request::ip(), $events_id)) {
- $eventsStatus = 'STATUS_HAS_RESTRTICTIONS';
-
- }elseif (count($userLettersData['ABC_data'])==count($lettersData['letters'])) {
- $eventsStatus = 'STATUS_HAS_COMPLETE';
- }
-
- # 获取其他开始的活动
- $objDLottery = new Lottery();
- $condition = array(
- 'display' => LotteryEvents::EVENT_DISPLAY_SHOW,
- 'id' => SqlHelper::addCompareOperator('!=', $events_id),
- 'begin_time' => SqlHelper::addCompareOperator('<', $TIME),
- 'end_time' => SqlHelper::addCompareOperator('>', $TIME)
- );
- $otherEventsData = $objDLottery -> getLotteryEventsList($condition, 3, 'id desc');
-
- # 获取用户最新收货地址
- $objDLotteryUserExpress = new LotteryUserExpress();
- $userExpress = $objDLotteryUserExpress -> getUserExpress($uid);
-
-
- # 页面ABC Json 增加出现位置
- $i = 1;
- foreach ($lettersData['letters'] as $key =>$data){
- $data['occurrence'] = $i;
- $lettersData['letters'][$key] = $data;
- $i++;
- }
- $ABCJsonData = json_encode($lettersData['letters']);
-
- # 记录PV UV日志 访问
- $objCount = new Count();
- $objCount->setPassLog( $events_id,$plat_form_id);
-
-
- # 页面数据
- $this->tpl = 'events_letters';
- $this->setOutput('display', $lettersData['events']['list_display']);
- $this->setOutput('title', $lettersData['events']['weixinShare']['title'] ? $lettersData['events']['weixinShare']['title'] : $lettersData['events']['events_name']);
- $this->setOutput('ABCJsonData', $ABCJsonData);
- $this->setOutput('eventsStatus', $eventsStatus);
- $this->setOutput('lettersData', $lettersData);
- $this->setOutput('userLettersData', $userLettersData);
- $this->setOutput('otherEventsData', $otherEventsData);
- $this->setOutput('userExpress', $userExpress);
- $this->setOutput('weixinShare', $lettersData['events']['weixinShare']);
- }
-
- /**
- * 事件:ajax 收集动作
- */
- public function doSweepstakes() {
-
- # 获取转盘信息
- $events_id = Request::g('events_id');
- if (!Verify::unsignedInt($events_id)) {
- self::fail_exit('无效id');
- }
- $uid = $this->getRunTimeUid();
-
- # 获取数据
- $objLotteryEventsTypeLetters = new LotteryEventsTypeLetters($uid,$events_id);
- $lettersData = $objLotteryEventsTypeLetters -> getEventsData();
-
- # 检查当前活动是否需要登录 & 获取登录地址
- $plat_form_id = $this->getPlatFormId();
- $objPlatForm = new Platform();
- $form = $objPlatForm -> get($plat_form_id);
- //$thisUrl = Request::schemeDomain().'/EventsLetters/T'.$plat_form_id.'/E'.$events_id;
- $thisUrl = Request::schemeDomain().'/'.$form['url'].'/EventsLetters/'.$lettersData['events']['create_time'];
- $loginUrl = $this -> getLoginUrl($thisUrl);
- $authorize = $lettersData['events']['authorize'];
- if ($authorize && $loginUrl) {
- $ckLogin = $this->ckLogin();
- if($ckLogin==true){
- self::ajax_fail_exit(array('url' =>$loginUrl));
- }
- }
-
-
-
- # 前端渲染的字母
- $user_letters = array();
- $userLettersData = $objLotteryEventsTypeLetters -> getUserLetters();
- if($userLettersData){
- $user_letters = $userLettersData['ABC_data'];
- }
-
-
- # 开始抽字母 & 奖项
- $tmpLotteryData = $objLotteryEventsTypeLetters ->sweepstakes();
- if(!$tmpLotteryData -> isSuccess()){
- # 失败:返回页面所需要的成功数据
- $data = $tmpLotteryData->getData();
- if(is_array($data)){
- $data['user_letters'] = $user_letters;
- }
- self::ajax_fail_exit($data);
- }
-
-
- # 成功:返回页面所需要的成功数据
- $data = $tmpLotteryData->getData();
-
- if(isset($data['lotteryData'])){
- $prize_id = $data['lotteryData']['prize_id'];
- $thisPrizeData = array();
- $thisPrizeData['prize_name'] = $data['lotteryData']['run_time_data']['prize'][$prize_id]['prize_name'];
- $thisPrizeData['id'] = $prize_id;
- $thisPrizeData['lottery_data_id'] = $data['lotteryData']['id'];
- $thisPrizeData['express'] = $data['lotteryData']['run_time_data']['prize'][$prize_id]['express'];
- $thisPrizeData['img_url'] = $data['lotteryData']['run_time_data']['prize'][$prize_id]['img_url'];
- $thisPrizeData['express'] = $data['lotteryData']['run_time_data']['prize'][$prize_id]['express'];
- $thisPrizeData['type'] = $data['lotteryData']['run_time_data']['prize'][$prize_id]['type'];
- $thisPrizeData['virtual_data'] = isset($data['lotteryData']['virtual_data'])?$data['lotteryData']['virtual_data']:'';
- $data['lotteryData'] = $thisPrizeData;
- }
- $user_letters[$data['lottery_id']] = $data['lottery_id'];
- $data['user_letters'] = $user_letters;
- self::ajax_success_exit($data);
- }
-
-
- public function display() {
- return $this->render();
- }
- }
|