cmd) { case CmdCode::shop_limit_maininfo: return self::GetLimitMainInfo($req); case CmdCode::shop_limit_buy: return self::BuyLimitPackage($req); case CmdCode::shop_monthlyVIP_Info: return self::GetMonthlyVipInfo($req); case CmdCode::shop_monthlyVIP_Buy: return self::BuyMonthlyVip($req); default: Err(ErrCode::cmd_err); } } public static function GetMonthlyVipInfo($req) { return Resp::ok(array( "shopdata" => $req->userInfo->game->shopdata )); } public static function BuyMonthlyVip($req) { $packageId = $req->paras[0]; # 参数; 礼包id $shopdata = new Info_UserShop($req->userInfo->game->shopdata); $packageCfg = GameConfig::shop_monthVIP_getItem($packageId); my_Assert(null != $packageCfg, ErrCode::err_const_no); if ($packageCfg->subType == 4) { my_Assert($shopdata->monthlyVIP1_ts + $packageCfg->ExpireTs * 3600 * 24 < now(), ErrCode::shop_monthlyvip_buyed); } elseif ($packageCfg->subType == 5) { my_Assert($shopdata->monthlyVIP2_ts + $packageCfg->ExpireTs * 3600 * 24 < now(), ErrCode::shop_monthlyvip_buyed); } $err = StoreProc::AddMultiItemInStore($req, $packageCfg->pri_reward); # 发放一次性奖励 my_Assert(ErrCode::ok == $err, $err); if ($packageCfg->subType == 4) { $shopdata->monthlyVIP1_ts = 3600 * 24 * (tsDay() + 1) - 1; } elseif ($packageCfg->subType == 5) { $shopdata->monthlyVIP2_ts = 3600 * 24 * (tsDay() + 1) - 1; } $req->userInfo->game->shopdata = $shopdata; # 回写数据 UserProc::updateUserInfo(); return Resp::ok(array( "reward" => $packageCfg->pri_reward, "shopdata" => $shopdata, 'gold' => $req->userInfo->game->baseInfo->gold, 'cash' => $req->userInfo->game->baseInfo->cash, 'tili' => $req->userInfo->game->baseInfo->tili, 'store' => $req->userInfo->game->store, 'hero' => $req->userInfo->game->heros )); } /** * 【7101】限购礼包主界面 * @param Req $req */ public static function GetLimitMainInfo($req) { return Resp::ok(array( "shopdata" => $req->userInfo->game->shopdata )); } /** * 【7102】 购买限购礼包 * @param Req $req */ public static function BuyLimitPackage($req) { $packageId = $req->paras[0]; # 参数; 礼包id $shopdata = new Info_UserShop($req->userInfo->game->shopdata); $packageCfg = GameConfig::shop_limit_getItem($packageId); my_Assert(null != $packageCfg, ErrCode::err_const_no); $arr = array(); switch ((int) $packageCfg->subType) { case 1: $shopdata->purchasedDailyLimitPackages[] = $packageId; $arr = $shopdata->purchasedDailyLimitPackages; break; case 2: $shopdata->purchasedWeeklyLimitPackages[] = $packageId; $arr = $shopdata->purchasedWeeklyLimitPackages; break; case 3: $shopdata->purchasedMonthlyLimitPackages[] = $packageId; $arr = $shopdata->purchasedMonthlyLimitPackages; break; default: Err(ErrCode::err_innerfault); } $hasN = count(array_filter($arr, function($val)use($packageId) { return $val == $packageId; })); my_Assert($hasN <= $packageCfg->limit_num, ErrCode::shop_limit_max); $itemid = explode(',', $packageCfg->reward)[0]; # 奖励礼包Id $itemMO = GameConfig::item_package_getItem($itemid); my_Assert(null != $itemMO, ErrCode::err_const_no); $err = StoreProc::AddMultiItemInStore($req, $itemMO->contents); # 发放奖励 my_Assert(ErrCode::ok == $err, $err); $req->userInfo->game->shopdata = $shopdata; # 回写数据 UserProc::updateUserInfo(); return Resp::ok(array( "reward" => $itemMO->contents, "shopdata" => $shopdata, 'gold' => $req->userInfo->game->baseInfo->gold, 'cash' => $req->userInfo->game->baseInfo->cash, 'tili' => $req->userInfo->game->baseInfo->tili, 'store' => $req->userInfo->game->store, 'hero' => $req->userInfo->game->heros )); } /** * 每日检查 * @param req $req */ static function DailyCheck($req) { CLog::info("shop-每日检查-清除每日/周限量礼包购买记录"); $zoneid = $req->zoneid; $uid = $req->uid; $shopdata = new Info_UserShop($req->userInfo->game->shopdata); $shopdata->purchasedDailyLimitPackages = array(); # 每天重置 if (date("N") == 1) { # 周一重置 $shopdata->purchasedWeeklyLimitPackages = array(); } if (date("d") == 1) { # 1号重置 $shopdata->purchasedMonthlyLimitPackages = array(); } if ($shopdata->monthlyVIP1_ts + 30 * 24 * 3600 > now()) { $id = 901001; $card1 = GameConfig::shop_monthVIP_getItem($id); my_Assert(null != $card1, ErrCode::err_const_no); EmailProc::SendMonthlyVIPDailyReward($zoneid, $uid, $card1->name, $card1->daily_reward); } if ($shopdata->monthlyVIP2_ts + 30 * 24 * 3600 > now()) { $id = 901002; $card2 = GameConfig::shop_monthVIP_getItem($id); my_Assert(null != $card2, ErrCode::err_const_no); EmailProc::SendMonthlyVIPDailyReward($zoneid, $uid, $card2->name, $card2->daily_reward); } } }