private function _getScratch($responseId, $openId, $type) { $disable = 1; $logTable = 'scratch_log'; Yii::import('application.modules.scratch.models.ScratchModel'); Yii::import('application.modules.scratch.models.ScratchLogModel'); $scratch = ScratchModel::model()->findByPk($responseId); if (!$type) { $keywords = KeywordsModel::model()->find('type=:type and responseId=:responseId', array(':type' => Globals::TYPE_SCRATCH, ':responseId' => $responseId)); $content = '参与' . $scratch->title . '请回复:正版(混版)' . $keywords->name; $responseObj = new WeChatTextResponse($content); return $responseObj; } //查看刮卡次数 $totalCount = $scratch->times; if ($totalCount == -1) { //本活动只能参与一次 $count = ScratchLogModel::model($logTable)->count('openId=:openId and scratchId=:scratchId', array(':openId' => $openId, ':scratchId' => $scratch->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 = ScratchLogModel::model($logTable)->count('openId=:openId and scratchId=:scratchId and datetime>:start and datetime<:end', array(':openId' => $openId, ':scratchId' => $scratch->id, ':start' => $start, ':end' => $end)); if ($count >= $totalCount) { $disable = 0; } } if ($disable == 0) { $content = $totalCount == -1 ? '你本次活动的参与次数已完' : '今天的刮奖次数已完,明天再来吧'; $responseObj = new WeChatTextResponse($content); return $responseObj; } if ($scratch->startTime > date('Y-m-d H:i:s')) { $content = $scratch->unstartMsg ? $scratch->unstartMsg : "抱歉,还未开始呢"; } elseif ($scratch->endTime < date('Y-m-d H:i:s')) { $content = $scratch->endMsg ? $scratch->endMsg : "抱歉,你来晚了"; } elseif ($scratch->status == 0) { $content = $scratch->pauseMsg ? $scratch->pauseMsg : "抱歉,活动暂时停止"; } else { $string = $openId . '|' . $responseId . '|' . $type; $code = Globals::authcode($string, 'ENCODE'); $url = Yii::app()->params['siteUrl'] . Yii::app()->createUrl('scratch/handle', array('code' => $code)); $responseObj = new WeChatArticleResponse(); $responseObj->add_article($scratch->title, '', Yii::app()->params['siteUrl'] . '/wechat/' . Yii::app()->params['scratchPath'] . '/' . $scratch->wechatId . '/' . $scratch->backgroundPic, $url); } $responseObj = isset($responseObj) ? $responseObj : new WeChatTextResponse($content); return $responseObj; }
/** * 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__); }
public function actionConfirm() { //status 更新为1,表明用户已经参 $logTable = 'scratch_log'; $status = false; $encryption = $_POST['encryption']; $table = 'scratch_awards'; list($openid, $grade, $scratchId) = explode('|', Globals::authcode($encryption, 'DECODE')); $code = ScratchAwardsModel::model($table)->find('grade=:grade and scratchId=:scratchId and openId=:openId', array(':grade' => $grade, ':scratchId' => $scratchId, ':openId' => $openid)); if ($code) { $code->status = $grade == 0 ? 2 : 1; $code->save(); $status = true; } $log = new ScratchLogModel($logTable); $log->datetime = time(); $log->openId = $openid; $log->scratchId = $scratchId; $log->save(); echo json_encode(array('status' => $status)); }