|
@@ -40,35 +40,44 @@ class ActiveProc {
|
|
|
$codePlatStr = "";
|
|
|
$packageID = 0;
|
|
|
|
|
|
- $active = GameConfig::activity_getItem($activeId); # 活动数据
|
|
|
- my_Assert(null != $active, ErrCode::active_const_no_err);
|
|
|
- my_Assert($active->startts <= now() && $active->endts >= now(), ErrCode::active_time); # 校验开放时间
|
|
|
- my_Assert(preg_match("/^[a-kmnp-z2-9]{10}$/", $codestring), ErrCode::active_activecode_format); # 基础格式校验(10个特定字符)
|
|
|
- $activeCode = CipheredBase32::Decode($codestring); # 解码
|
|
|
- $codePlatStr = GameConstants::GetPlatStringByActivteCode($activeCode); # platstr
|
|
|
- my_Assert(GameConstants::AllPlatStr == $codePlatStr # # 忽略全平台礼包
|
|
|
- || req()->getPlatStr() == $codePlatStr, # # 平台字符串必须相符
|
|
|
- ErrCode::active_activecode_plat); # # 平台错误
|
|
|
-
|
|
|
- my_Assert(is_int($activeCode->number) # # 编号为int值
|
|
|
- && $activeCode->number >= 1 && $activeCode->number <= 50000, # # 检查 兑换码的编号范围0~50000
|
|
|
- ErrCode::active_activecode_format);
|
|
|
-
|
|
|
- $packageID = $activeCode->package; # 礼包id
|
|
|
- $packageInfo = GameConfig::token_gift_getItem($packageID); # 礼包常量数据
|
|
|
- my_Assert(null != $packageInfo, ErrCode::err_const_no); # 防御
|
|
|
- my_Assert($packageInfo->expirets >= now() && $packageInfo->startTs <= now(),
|
|
|
- ErrCode::active_activecode_outtime); # 激活码已经失效,或者礼包尚未开启
|
|
|
-
|
|
|
- $privateState = new Info_PrivateState(ctx()->privateState); # 快速访问
|
|
|
- my_Assert(!in_array($packageID, $privateState->usedTokens), ErrCode::active_hasgetted); # 已经领取过该礼包了
|
|
|
- //my_Assert(!self::checkActiveCodeIsUsed($activeCode), ErrCode::active_activecode_used); # 检查 该激活码是否别人已经使用过了
|
|
|
- $err = StoreProc::AddMultiItemInStore($packageInfo->reward); # 发放礼包
|
|
|
- my_Assert(ErrCode::ok == $err, $err); # 防御发放礼包过程出错
|
|
|
-
|
|
|
- //$ok = self::setActiveCodeUserRecord($activeCode, req()->uid); # 插入数据库
|
|
|
- //my_Assert($ok, ErrCode::err_db); # 数据库操作失败- 重试
|
|
|
-
|
|
|
+ if (self::PublicTokenCodeCheck($codestring)) {
|
|
|
+ $packageInfo = GameConfig::token_PublicGift_getItem($codestring);
|
|
|
+ my_Assert($packageInfo->expirets >= now() && $packageInfo->startTs <= now(),
|
|
|
+ ErrCode::active_activecode_outtime);
|
|
|
+ my_Assert(!in_array($codestring, ctx()->privateState->usedTokens), ErrCode::active_hasgetted); # 已经领取过该礼包了
|
|
|
+ $packageID = $codestring;
|
|
|
+ $err = StoreProc::AddMultiItemInStore($packageInfo->reward); # 发放礼包
|
|
|
+ my_Assert(ErrCode::ok == $err, $err);
|
|
|
+ } else {
|
|
|
+ $active = GameConfig::activity_getItem($activeId); # 活动数据
|
|
|
+ my_Assert(null != $active, ErrCode::active_const_no_err);
|
|
|
+ my_Assert($active->startts <= now() && $active->endts >= now(), ErrCode::active_time); # 校验开放时间
|
|
|
+ my_Assert(preg_match("/^[a-kmnp-z2-9]{10}$/", $codestring), ErrCode::active_activecode_format); # 基础格式校验(10个特定字符)
|
|
|
+ $activeCode = CipheredBase32::Decode($codestring); # 解码
|
|
|
+ $codePlatStr = GameConstants::GetPlatStringByActivteCode($activeCode); # platstr
|
|
|
+ my_Assert(GameConstants::AllPlatStr == $codePlatStr # # 忽略全平台礼包
|
|
|
+ || req()->getPlatStr() == $codePlatStr, # # 平台字符串必须相符
|
|
|
+ ErrCode::active_activecode_plat); # # 平台错误
|
|
|
+
|
|
|
+ my_Assert(is_int($activeCode->number) # # 编号为int值
|
|
|
+ && $activeCode->number >= 1 && $activeCode->number <= 50000, # # 检查 兑换码的编号范围0~50000
|
|
|
+ ErrCode::active_activecode_format);
|
|
|
+
|
|
|
+ $packageID = $activeCode->package; # 礼包id
|
|
|
+ $packageInfo = GameConfig::token_gift_getItem($packageID); # 礼包常量数据
|
|
|
+ my_Assert(null != $packageInfo, ErrCode::err_const_no); # 防御
|
|
|
+ my_Assert($packageInfo->expirets >= now() && $packageInfo->startTs <= now(),
|
|
|
+ ErrCode::active_activecode_outtime); # 激活码已经失效,或者礼包尚未开启
|
|
|
+
|
|
|
+ $privateState = new Info_PrivateState(ctx()->privateState); # 快速访问
|
|
|
+ my_Assert(!in_array($packageID, $privateState->usedTokens), ErrCode::active_hasgetted); # 已经领取过该礼包了
|
|
|
+ my_Assert(!self::checkActiveCodeIsUsed($activeCode), ErrCode::active_activecode_used); # 检查 该激活码是否别人已经使用过了
|
|
|
+ $err = StoreProc::AddMultiItemInStore($packageInfo->reward); # 发放礼包
|
|
|
+ my_Assert(ErrCode::ok == $err, $err); # 防御发放礼包过程出错
|
|
|
+ $ok = self::setActiveCodeUserRecord($activeCode, req()->uid); # 插入数据库
|
|
|
+ my_Assert($ok, ErrCode::err_db); # 数据库操作失败- 重试
|
|
|
+ }
|
|
|
+
|
|
|
ctx()->privateState->usedTokens[] = $packageID;
|
|
|
|
|
|
UserProc::updateUserInfo(); # 回存玩家数据
|
|
@@ -80,10 +89,49 @@ class ActiveProc {
|
|
|
'cash' => ctx()->base()->cash,
|
|
|
'tili' => ctx()->base()->tili,
|
|
|
'store' => ctx()->store,
|
|
|
- 'hero' => ctx()->heros,
|
|
|
+ 'hero' => ctx()->heros,
|
|
|
);
|
|
|
return Resp::ok($ret); # 返回成功信息
|
|
|
}
|
|
|
+
|
|
|
+ public static function PublicTokenCodeCheck($codestring) {
|
|
|
+ $dic = GameConfig::token_PublicGift();
|
|
|
+ if (StlUtil::dictHasProperty($dic, $codestring)) {
|
|
|
+ return true;
|
|
|
+ }
|
|
|
+ return false;
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 检查兑换码是否已经使用过了
|
|
|
+ * @param ActiveCode $activeCode
|
|
|
+ * @return boolean true : 已经用过了, false : 激活码尚未使用过.
|
|
|
+ */
|
|
|
+ static function checkActiveCodeIsUsed($activeCode) {
|
|
|
+ $sql = sprintf("`plat`='%d' and `package`='%d' and `number`='%d'", # # where 子句
|
|
|
+ $activeCode->plat, $activeCode->package, $activeCode->number);
|
|
|
+ $rows = daoInst()
|
|
|
+ ->select()
|
|
|
+ ->from(self::tab_toke_gift) # 表名
|
|
|
+ ->where($sql)
|
|
|
+ ->count();
|
|
|
+ return $rows > 0;
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 将兑换码添加到使用记录中
|
|
|
+ * @param ActiveCode $actvieCode
|
|
|
+ * @param string $uid
|
|
|
+ * @return boolean true: 操作成功, false: 操作失败
|
|
|
+ */
|
|
|
+ static function setActiveCodeUserRecord($actvieCode, $uid) {
|
|
|
+ $actvieCode->uid = $uid; # 添加uid
|
|
|
+ $ret = daoInst()
|
|
|
+ ->insert(self::tab_toke_gift) # 表名
|
|
|
+ ->data($actvieCode)
|
|
|
+ ->exec();
|
|
|
+ return $ret > 0;
|
|
|
+ }
|
|
|
|
|
|
/**
|
|
|
* 7日签到 数据更新
|