Exemple #1
0
 public function actionIndex()
 {
     $logTable = 'wheel_log';
     $table = 'wheel_awards';
     $remainCount = $prize = 0;
     $code = Yii::app()->request->getParam('code');
     list($openId, $wheelId, $type) = explode('|', Globals::authcode($code, 'DECODE'));
     $wheel = WheelModel::model()->findByPk($wheelId);
     //活动是否开始
     if ($wheel->startTime > date('Y-m-d H:i:s')) {
         $prize = 1;
     } elseif ($wheel->endTime < date('Y-m-d H:i:s')) {
         $prize = 1;
     } elseif ($wheel->status == 0) {
         $prize = 1;
     }
     $totalCount = $wheel->times;
     //次数限制
     if ($totalCount == -1) {
         //本活动只能参与一次
         $count = WheelLogModel::model($logTable)->count('openId=:openId and wheelId=:wheelId', array(':openId' => $openId, ':wheelId' => $wheelId));
         $totalCount = 1;
         if ($count > 0) {
             $hasCount = $count;
         }
     }
     if ($totalCount > 0) {
         $start = strtotime(date('Y-m-d')) - 1;
         $end = strtotime(date('Y-m-d', strtotime('1 days'))) - 1;
         $count = WheelLogModel::model($logTable)->count('openId=:openId and wheelId=:wheelId and datetime>:start and datetime<:end', array(':openId' => $openId, ':wheelId' => $wheelId, ':start' => $start, ':end' => $end));
         $hasCount = $count;
     }
     $this->renderPartial('active', array('wheel' => $wheel, 'prize' => $prize, 'hasCount' => $hasCount, 'encryption' => $code, 'totalCount' => $totalCount));
 }
Exemple #2
0
 /**
  * Returns the static model of the specified AR class.
  * @param string $className active record class name.
  * @return GiftCodeModel the static model class
  */
 public static function model($table_name)
 {
     self::$tableName = $table_name;
     return parent::model(__CLASS__);
 }
Exemple #3
0
 private function _getWheel($responseId, $openId, $type)
 {
     $disable = 1;
     $logTable = 'wheel_log';
     Yii::import('application.modules.wheel.models.WheelModel');
     Yii::import('application.modules.wheel.models.WheelLogModel');
     $wheel = WheelModel::model()->findByPk($responseId);
     if (!$type) {
         $keywords = KeywordsModel::model()->find('type=:type and responseId=:responseId', array(':type' => Globals::TYPE_WHEEL, ':responseId' => $responseId));
         $content = '参与' . $wheel->title . '请回复:正版(混版)' . $keywords->name;
         $responseObj = new WeChatTextResponse($content);
         return $responseObj;
     }
     //查看刮卡次数
     $totalCount = $wheel->times;
     if ($totalCount == -1) {
         //本活动只能参与一次
         $count = WheelLogModel::model($logTable)->count('openId=:openId and wheelId=:wheelId', array(':openId' => $openId, ':wheelId' => $wheel->id));
         if ($count > 0) {
             $disable = 0;
         }
     }
     if ($totalCount > 0) {
         $start = strtotime(date('Y-m-d')) - 1;
         $end = strtotime(date('Y-m-d', strtotime('1 days'))) - 1;
         $count = WheelLogModel::model($logTable)->count('openId=:openId and wheelId=:wheelId and datetime>:start and datetime<:end', array(':openId' => $openId, ':wheelId' => $wheel->id, ':start' => $start, ':end' => $end));
         if ($count >= $totalCount) {
             $disable = 0;
         }
     }
     if ($disable == 0) {
         $content = $totalCount == -1 ? '你本次活动的参与次数已完' : '今天的转盘次数已完,明天再来吧';
         $responseObj = new WeChatTextResponse($content);
         return $responseObj;
     }
     if ($wheel->startTime > date('Y-m-d H:i:s')) {
         $content = $wheel->unstartMsg ? $wheel->unstartMsg : "抱歉,还未开始呢";
     } elseif ($wheel->endTime < date('Y-m-d H:i:s')) {
         $content = $wheel->endMsg ? $wheel->endMsg : "抱歉,你来晚了";
     } elseif ($wheel->status == 0) {
         $content = $wheel->pauseMsg ? $wheel->pauseMsg : "抱歉,活动暂时停止";
     } else {
         $string = $openId . '|' . $responseId . '|' . $type;
         $code = Globals::authcode($string, 'ENCODE');
         $url = Yii::app()->params['siteUrl'] . Yii::app()->createUrl('wheel/handle', array('code' => $code));
         $responseObj = new WeChatArticleResponse();
         $responseObj->add_article($wheel->title, '', Yii::app()->params['siteUrl'] . '/wechat/' . Yii::app()->params['wheelPath'] . '/' . $wheel->wechatId . '/' . $wheel->backgroundPic, $url);
     }
     $responseObj = isset($responseObj) ? $responseObj : new WeChatTextResponse($content);
     return $responseObj;
 }