private function _getGiftReplay($responseId, $openId) { $giftInfo = GiftModel::model()->findByPk($responseId); if ($giftInfo->startTime > date('Y-m-d H:i:s')) { $content = $giftInfo->unstartMsg ? $giftInfo->unstartMsg : "抱歉,还未开始呢"; } elseif ($giftInfo->endTime < date('Y-m-d H:i:s')) { $content = $giftInfo->endMsg ? $giftInfo->endMsg : "抱歉,你来晚了"; } elseif ($giftInfo->status == 0) { $content = $giftInfo->pauseMsg ? $giftInfo->pauseMsg : "抱歉,活动暂时停止"; } else { $codeTableName = GiftModel::model()->getCodeTableName($giftInfo->wechatId); $userHasGet = GiftCodeModel::model($codeTableName)->find('giftId=:giftId and openId=:openId', array(':giftId' => $giftInfo->id, ':openId' => $openId)); if ($userHasGet) { $content = $giftInfo->RTemplate ? str_replace('{code}', $userHasGet->code, $giftInfo->RTemplate) : $userHasGet->code; } else { $codeInfo = GiftCodeModel::model($codeTableName)->find('giftId=:giftId and openId is null', array(':giftId' => $giftInfo->id)); if ($codeInfo) { //update $codeInfo->openId = $openId; $codeInfo->save(); $content = $giftInfo->template ? str_replace('{code}', $codeInfo->code, $giftInfo->template) : $codeInfo->code; } else { $content = $giftInfo->codeOverMsg ? $giftInfo->codeOverMsg : "抱歉,领完了"; } } } $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 actionCodeImport() { set_time_limit(0); $giftId = Yii::app()->request->getParam('giftId'); $file = $_FILES; if ($file && $giftId) { $tmpFile = "upload/" . $_FILES["file"]["name"]; if (file_exists($tmpFile)) { @unlink($_FILES["file"]["name"]); } else { move_uploaded_file($_FILES["file"]["tmp_name"], $tmpFile); } $handle = @fopen($tmpFile, "r"); if ($handle) { while (!feof($handle)) { $code = fgets($handle, 4096); //入库 $tableName = sprintf(GiftModel::CREATE_CODE_TABLE_NAME, $this->wechatInfo->id); $CodeModel = new GiftCodeModel($tableName); $CodeModel->giftId = $giftId; $CodeModel->code = trim($code); $CodeModel->save(); } fclose($handle); } @unlink($tmpFile); $msg = "导入成功!"; } else { $msg = '提交错误'; } echo $msg; }