/** * 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($tableName = false, $className = __CLASS__) { self::$tableName = $tableName; return parent::model(__CLASS__); }
public function actionActive() { $result = -1; $prize = 1; $msg = '活动已结束'; $sinDate = 0; $table = 'active_awards'; $logTable = 'active_log'; $encryption = Yii::app()->request->getParam('encryption'); list($openId, $activeId, $type) = explode('|', Globals::authcode($encryption, 'DECODE')); $active = ActiveModel::model()->findByPk($activeId); //活动是否开始 if ($active->startTime > date('Y-m-d H:i:s')) { $prize = 1; } elseif ($active->endTime < date('Y-m-d H:i:s')) { $prize = 1; } elseif ($active->status == 0) { $prize = 1; } $prize = $active->status == 0 ? 0 : $prize; if ($prize == 1) { //检查今天是否已经签到 $startTime = strtotime(date('Y-m-d')); $endTime = strtotime(date('Y-m-d', strtotime('+1 days'))) - 1; $logExit = ActiveLogModel::model($logTable)->find('activeId=:activeId and openId=:openId and datetime>=' . $startTime . ' and datetime<=' . $endTime, array(':activeId' => $activeId, ':openId' => $openId)); if ($logExit) { $result = 1; //签到过了 $msg = '你今天已经签过到了'; } else { $count = ActiveLogModel::model($logTable)->count('activeId=:activeId and openId=:openId', array(':activeId' => $activeId, ':openId' => $openId)); $count = $count + 1; $awardsArray = unserialize($active->awards); if (isset($awardsArray[$count])) { //获取礼包码 $code = ActiveAwardsModel::model($table)->find('activeId=:activeId and grade=:grade and type=:type and openId is null', array(':activeId' => $activeId, ':grade' => $count, ':type' => $type)); if ($code) { $code->status = 2; $code->awardsInfo = $awardsArray[$count]['name']; $code->openId = $openId; $code->datetime = time(); $code->save(); $result = 2; // $msg = '恭喜你,获得' . $awardsArray[$count]['name'] . ',礼包码为:'.$code->code; $msg = '恭喜签到' . $count . '次,活动礼包激活码:' . $code->code; } else { $result = -3; $msg = '抱歉,礼包码发完了,请联系客服'; } } else { $result = 3; $msg = '恭喜你,签到成功'; } $sinDate = date('md'); //log $log = new ActiveLogModel($logTable); $log->datetime = time(); $log->openId = $openId; $log->activeId = $activeId; $log->save(); } } echo json_encode(array('success' => $result, 'msg' => $msg, 'sinDate' => $sinDate)); }