ShopProc.php 23 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653
  1. <?php
  2. /*
  3. * To change this license header, choose License Headers in Project Properties.
  4. * To change this template file, choose Tools | Templates
  5. * and open the template in the editor.
  6. */
  7. namespace loyalsoft;
  8. /**
  9. * Description of ShopProc
  10. *
  11. * @author c'y'zhao
  12. */
  13. class ShopProc {
  14. /**
  15. * 逻辑分发
  16. * 所有的Proc中必须有这样一个方法
  17. * @param Req $req
  18. */
  19. public static function procMain($req) {
  20. switch ($req->cmd) {
  21. case CmdCode::cmd_shop_BuyGift: # 6501 商城购买东西
  22. return ShopProc::ShopBuyGift();
  23. case CmdCode::cmd_shop_BuyTili: # 6502 买体力
  24. return ShopProc::BuyTili();
  25. default:
  26. Err(ErrCode::cmd_err);
  27. }
  28. }
  29. public static function BuyTili() {
  30. list($type) = req()->paras;
  31. $addTili = 0;
  32. if ($type == 1) {//广告
  33. $maxNum = glc()->GuanggaoGetTili_DailyMaxNum;
  34. my_Assert(ctx()->privateState->guanggaoGetTiliNum < $maxNum, ErrCode::user_shop_GuanggaoGetTiliNumLimit);
  35. my_Assert(now() - ctx()->privateState->guanggaoGetTili_ts > 300, ErrCode::user_shop_DownTsLimit);
  36. $addTili = glc()->GuanggaoGetTili;
  37. ctx()->baseInfo->Add_tili(glc()->GuanggaoGetTili);
  38. ctx()->privateState->guanggaoGetTiliNum += 1;
  39. ctx()->privateState->guanggaoGetTili_ts = now();
  40. } else {
  41. $maxNum = glc()->BuyTili_DailyMaxNum;
  42. my_Assert(ctx()->privateState->buyTiliNum < $maxNum, ErrCode::user_shop_buyTiliNumLimit);
  43. $arr = explode(',', glc()->BuyTiliCost);
  44. my_Assert(ctx()->baseInfo->cash >= $arr[0], ErrCode::user_shop_NotRepeatBuy);
  45. ctx()->baseInfo->Consume_Cash($arr[0]);
  46. $addTili = $arr[1];
  47. ctx()->baseInfo->Add_tili($arr[1]);
  48. ctx()->privateState->buyTiliNum += 1;
  49. }
  50. TaskProc::OnBuyTiliOrLookGuanggao();
  51. UserProc::updateUserInfo();
  52. return Resp::ok(array(
  53. "privateState" => ctx()->privateState,
  54. "baseInfo" => ctx()->baseInfo,
  55. "tili" => $addTili,
  56. "task" => ctx()->task,
  57. ));
  58. }
  59. /**
  60. * 商城购买东西
  61. * @return type
  62. */
  63. public static function ShopBuyGift() {
  64. list($type, $typeId, $buyNum) = req()->paras;
  65. $user = ctx();
  66. //$resultArr = array();
  67. switch ($type) {
  68. case EnumShopGift::GateGift_Shop://章节礼包
  69. $gateGift = self::BuyShop_GateGift($type, $typeId, $buyNum);
  70. break;
  71. case EnumShopGift::Daily_Shop://每日商店
  72. self::BuyShop_Daily($type, $typeId, $buyNum);
  73. break;
  74. case EnumShopGift::GemBox_Shop ://宝石宝箱---->2024.8.14 改为可能抽出宝石或是道具
  75. self::BuyShop_GemBox($type, $typeId, $buyNum);
  76. break;
  77. case EnumShopGift::BujiBox_Shop://补给箱
  78. $equip = self::BuyShop_BujiBox($type, $typeId, $buyNum);
  79. break;
  80. case EnumShopGift::Cash_Shop://商城-钻石
  81. self::BuyShop_Cash($type, $typeId, $buyNum);
  82. break;
  83. case EnumShopGift::Gold_Shop://商城-金币--可以多次购买
  84. self::BuyShop_Gold($type, $typeId, $buyNum);
  85. break;
  86. case EnumShopGift::MonthCard_Shop:
  87. self::BuyShop_MonthCard($type, $typeId, $buyNum);
  88. break;
  89. default:
  90. break;
  91. }
  92. // if (ctx()->baseInfo->charge_amt > 0 && ctx()->baseInfo->fRechargePriceReceived == 0) {
  93. // StoreProc::AddMultiItemInStore(GameConfig::globalsettings()->FirstRechargePrice);
  94. // ctx()->baseInfo->fRechargePriceReceived = 1;
  95. // }
  96. ctx($user);
  97. UserProc::updateUserInfo();
  98. return Resp::ok(array(
  99. //'gemBox' => $resultArr,
  100. //'gateGift' => $gateGift,
  101. 'cash' => $user->baseInfo->cash,
  102. 'gold' => $user->baseInfo->gold,
  103. 'privateState' => $user->privateState,
  104. 'store' => $user->store,
  105. 'task' => ctx()->task,
  106. 'heros' => ctx()->heros,
  107. 'reward' => StoreProc::$reward,
  108. 'reward_Gem' => StoreProc::$reward_Gem,
  109. ));
  110. }
  111. /*
  112. * 商城章节礼包购买
  113. */
  114. public static function BuyShop_GateGift($type, $typeId, $buyNum) {
  115. $gateGift = array();
  116. my_Assert(!in_array($typeId, ctx()->privateState->gateGiftReceived), ErrCode::user_shop_NotRepeatBuy);
  117. $mo = GameConfig::shop_gategift_getItem($typeId);
  118. my_Assert($mo != null, ErrCode::err_const_no);
  119. $price = explode(';', $mo->reward);
  120. foreach ($price as $value) {
  121. $item = explode(',', $value);
  122. if (GameConfig::item_getItem($item[0])->itemType == EnumItemType::tuzhiBox) {
  123. $dic = GameConfig::item();
  124. $list = array();
  125. foreach ($dic as $id => $val) {
  126. if ($val->itemType == EnumItemType::tuzhi) {
  127. $list[] = $val->typeId;
  128. }
  129. }
  130. $randNum = rand(0, count($list) - 1);
  131. $tuzhiId = $list[$randNum];
  132. $gateGift[] = $tuzhiId . ',1';
  133. } else {
  134. $gateGift[] = $value;
  135. }
  136. }
  137. foreach ($gateGift as $str) {
  138. StoreProc::AddMultiItemInStore($str);
  139. }
  140. ctx()->privateState->gateGiftReceived[] = $typeId;
  141. ctx()->baseInfo->charge_amt += $mo->curPrice;
  142. return $gateGift;
  143. }
  144. /**
  145. * 每日商店
  146. * @param type $type
  147. * @param type $typeId
  148. * @param type $buyNum
  149. */
  150. public static function BuyShop_Daily($type, $typeId, $buyNum) {
  151. $mo = GameConfig::shop_daily_getItem($typeId);
  152. my_Assert($mo != null, ErrCode::err_const_no);
  153. my_Assert(in_array($typeId, ctx()->privateState->dailyShopRandItems), ErrCode::err_const_no);
  154. if ($mo->type == 1) {
  155. $getNum = 0;
  156. foreach (ctx()->privateState->dailyShopReceived as $id) {
  157. if ($id == $typeId) {
  158. $getNum += 1;
  159. }
  160. }
  161. if ($getNum >= $mo->freeNum) {
  162. my_Assert(ctx()->privateState->dailyShop_GuangGaoNum < $mo->num, ErrCode::user_shop_GuanggaoFreeNumLimit);
  163. if (ctx()->privateState->dailyShop_GuangGaoNum >= 1) {
  164. my_Assert(now() - ctx()->privateState->dailyShop_GuangGaoTs >= $mo->downTs, ErrCode::user_shop_DownTsLimit);
  165. }
  166. ctx()->privateState->dailyShop_GuangGaoNum += 1;
  167. ctx()->privateState->dailyShop_GuangGaoTs = now();
  168. }
  169. } else {
  170. my_Assert(!in_array($typeId, ctx()->privateState->dailyShopReceived), ErrCode::user_shop_NotRepeatBuy);
  171. switch ($mo->costType) {
  172. case EnumShopCost::Gold:
  173. my_Assert(ctx()->baseInfo->gold >= $mo->costNum, ErrCode::notenough_gold_msg);
  174. ctx()->baseInfo->Consume_Gold($mo->costNum);
  175. break;
  176. case EnumShopCost::Cash:
  177. my_Assert(ctx()->baseInfo->cash >= $mo->costNum, ErrCode::notenough_cash_msg);
  178. ctx()->baseInfo->Consume_Cash($mo->costNum);
  179. break;
  180. default:
  181. break;
  182. }
  183. TaskProc::OnBuyNumDailyShop();
  184. }
  185. StoreProc::AddMultiItemInStore($mo->reward);
  186. ctx()->privateState->dailyShopReceived[] = $typeId;
  187. TaskProc::OnBuyNumDailyShop_state();
  188. }
  189. /**
  190. * 宝石宝箱---->2024.8.14 改为可能抽出宝石或是道具
  191. */
  192. public static function BuyShop_GemBox($type, $typeId, $buyNum) {
  193. $mo = GameConfig::shop_box_getItem($typeId);
  194. my_Assert($mo != null, ErrCode::err_const_no);
  195. if ($buyNum == 1) {
  196. $yaoshiArr = explode(',', $mo->cost_one_yaoshi);
  197. $itemId = $yaoshiArr[0];
  198. if (StlUtil::dictHasProperty(ctx()->store->items, $itemId) && ctx()->store->items->$itemId >= $yaoshiArr[1]) {
  199. ctx()->store->removeItem($itemId, $yaoshiArr[1]);
  200. } else {
  201. $cost = $mo->cost_one;
  202. my_Assert(ctx()->baseInfo->cash >= $cost, ErrCode::notenough_cash_msg);
  203. ctx()->baseInfo->Consume_Cash($cost);
  204. }
  205. } elseif ($buyNum == 10) {
  206. $yaoshiArr = explode(',', $mo->cost_ten_yaoshi);
  207. $itemId = $yaoshiArr[0];
  208. if (StlUtil::dictHasProperty(ctx()->store->items, $itemId) && ctx()->store->items->$itemId >= $yaoshiArr[1]) {
  209. ctx()->store->removeItem($itemId, $yaoshiArr[1]);
  210. } else {
  211. $cost = $mo->cost_ten;
  212. my_Assert(ctx()->baseInfo->cash >= $cost, ErrCode::notenough_cash_msg);
  213. ctx()->baseInfo->Consume_Cash($cost);
  214. }
  215. }
  216. if ($mo->type == 1) {
  217. if ($buyNum == 0) {
  218. $buyNum = 1;
  219. my_Assert(now() - ctx()->privateState->lastFreeGetTs_ShopBoxCommon >= $mo->freeDownTs * 24 * 60 * 60, ErrCode::user_shop_FreeNumLimit);
  220. ctx()->privateState->lastFreeGetTs_ShopBoxCommon = now();
  221. }
  222. } else if ($mo->type == 2) {
  223. if ($buyNum == 0) {
  224. $buyNum = 1;
  225. my_Assert(now() - ctx()->privateState->lastFreeGetTs_ShopBoxBright >= $mo->freeDownTs * 24 * 60 * 60, ErrCode::user_shop_FreeNumLimit);
  226. ctx()->privateState->lastFreeGetTs_ShopBoxBright = now();
  227. }
  228. }
  229. $arr = array();
  230. $arr[] = 1;
  231. $arr[] = 10;
  232. if (!in_array($buyNum, $arr)) {
  233. $buyNum = 1;
  234. }
  235. TaskProc::OnOpenNumBrightBox($typeId, $buyNum);
  236. TaskProc::OnOpenNumAnyBox($buyNum);
  237. FightProc::funUnlock_Gem();
  238. $perList = explode(';', $mo->percent);
  239. $allNum = 0;
  240. foreach ($perList as $key => $value) {
  241. $str = explode(',', $value);
  242. $allNum += $str[1];
  243. }
  244. $allNum *= 10;
  245. for ($i = 0; $i < $buyNum; $i++) {
  246. mt_srand((double) microtime() * 1000000);
  247. $buyCount = 0;
  248. if ($mo->type == 1) {
  249. ctx()->privateState->buyNum_ShopBoxCommon += 1;
  250. $buyCount = ctx()->privateState->buyNum_ShopBoxCommon;
  251. } else {
  252. ctx()->privateState->buyNum_ShopBoxBright += 1;
  253. $buyCount = ctx()->privateState->buyNum_ShopBoxBright;
  254. }
  255. $bichu1 = explode(',', $mo->bichu1);
  256. $qual = 0; //改成道具盒子了 但是这个变量不动了
  257. if ($buyCount % $bichu1[0] == 0) {
  258. $qual = $bichu1[1];
  259. }
  260. if ($mo->bichu2 != null) {
  261. $bichu2 = explode(',', $mo->bichu2);
  262. if ($buyCount % $bichu2[0] == 0) {
  263. $qual = $bichu2[1];
  264. }
  265. }
  266. if ($qual == 0) {
  267. $start = 0;
  268. $end = 0;
  269. $randNum = mt_rand(1, $allNum);
  270. foreach ($perList as $k => $val) {
  271. $str = explode(',', $val);
  272. $end += $str[1] * 10;
  273. if ($randNum > $start && $randNum <= $end) {
  274. $qual = $str[0];
  275. break;
  276. }
  277. $start = $end;
  278. }
  279. }
  280. if ($qual > 0) {
  281. StoreProc::AddMultiItemInStore($qual . ",1", Enum_StoreSourceType::ShopBox);
  282. }
  283. }
  284. TaskProc::OnOpenNumBrightBox_state($typeId, $buyNum);
  285. }
  286. /**
  287. * 补给箱
  288. * @param type $type
  289. * @param type $typeId
  290. * @param type $buyNum
  291. */
  292. public static function BuyShop_BujiBox($type, $typeId, $buyNum) {
  293. $equip = array();
  294. $mo = GameConfig::shop_supply_getItem($typeId);
  295. my_Assert($mo != null, ErrCode::err_const_no);
  296. $list = explode(',', $mo->cost);
  297. my_Assert(StlUtil::dictHasProperty(ctx()->store->items, $list[0]), ErrCode::notenough_item);
  298. ctx()->store->removeItem($list[0], $list[1]);
  299. ctx()->baseInfo->Add_Gold($mo->gold);
  300. if (!StlUtil::dictHasProperty(ctx()->privateState->junbeiShopNumRecord, $typeId)) {
  301. ctx()->privateState->junbeiShopNumRecord->$typeId = 0;
  302. }
  303. $num = ctx()->privateState->junbeiShopNumRecord->$typeId += 1;
  304. if (!StlUtil::dictHasProperty(ctx()->privateState->supplyBichuDic, $typeId)) {
  305. ctx()->privateState->supplyBichuDic->$typeId = 0;
  306. }
  307. ctx()->privateState->supplyBichuDic->$typeId += 1;
  308. my_Assert($num <= $mo->limitNum, ErrCode::user_shop_LimitNum);
  309. $plist = explode(';', $mo->percent);
  310. $randNum = rand(0, 10000);
  311. $start = 0;
  312. $end = 0;
  313. $qual = null;
  314. foreach ($plist as $item) {
  315. $arr = explode(',', $item);
  316. $per = $arr[2] * 100;
  317. $end += $per;
  318. if ($randNum >= $start && $randNum < $end) {
  319. $qual = $arr[0] . ',' . $arr[1]; //品阶,稀有度
  320. break;
  321. }
  322. $start = $end;
  323. }
  324. //必出
  325. $bichu = explode(',', $mo->bichu);
  326. $qArr = explode(',', $qual);
  327. if ($qArr[0] == $bichu[1] && $qArr[1] == $bichu[2]) {//得到必出,重置数量记录
  328. ctx()->privateState->supplyBichuDic->$typeId = 0;
  329. $qual = $bichu[1] . ',' . $bichu[2];
  330. } else {
  331. if (ctx()->privateState->supplyBichuDic->$typeId == $bichu[0]) {
  332. $qual = $bichu[1] . ',' . $bichu[2];
  333. ctx()->privateState->supplyBichuDic->$typeId = 0;
  334. }
  335. }
  336. if ($qual != null) {
  337. $str = explode(',', $qual);
  338. $equipList = array();
  339. $dic = GameConfig::equip();
  340. foreach ($dic as $tid => $item) {
  341. if ($item->qual == $str[0] && $item->rarity == $str[1]) {
  342. $equipList[] = $item->typeId;
  343. }
  344. }
  345. $rNum = rand(0, count($equipList) - 1);
  346. $equipId = $equipList[$rNum];
  347. StoreProc::PutEquipInStore($equipId, 1);
  348. $equip[] = $equipId;
  349. }
  350. return $equip;
  351. }
  352. /**
  353. * 钻石商城
  354. * @param type $type
  355. * @param type $typeId
  356. * @param type $buyNum
  357. */
  358. public static function BuyShop_Cash($type, $typeId, $buyNum) {
  359. $mo = GameConfig::shop_cash_getItem($typeId);
  360. my_Assert($mo != null, ErrCode::err_const_no);
  361. $tag = false;
  362. if (in_array($typeId, ctx()->privateState->cashShopReceived)) {
  363. $tag = true;
  364. }
  365. $reward = $mo->reward;
  366. $pList = explode(',', $reward);
  367. $addYuanbao = $pList[1];
  368. if (!$tag) {
  369. $reward = $mo->reward . ';' . $mo->reward;
  370. $addYuanbao *= 2;
  371. }
  372. StoreProc::AddMultiItemInStore($reward);
  373. ctx()->baseInfo->accumulateYuanBao += $addYuanbao;
  374. ctx()->baseInfo->charge_amt += $mo->price;
  375. ctx()->privateState->cashShopReceived[] = $typeId;
  376. if (ctx()->privateState->firstRecharge_receiveTag == 0) {
  377. ctx()->privateState->firstRechargeUI_OpenTip = 1;
  378. }
  379. if (ctx()->privateState->firstRecharge_receiveTag < 1) {
  380. ctx()->privateState->firstRecharge_receiveTag = 1;
  381. }
  382. TaskProc::OnRecharge();
  383. return $reward;
  384. }
  385. /**
  386. * 金币商城
  387. * @param type $type
  388. * @param type $typeId
  389. * @param type $buyNum
  390. */
  391. public static function BuyShop_Gold($type, $typeId, $buyNum) {
  392. $mo = GameConfig::shop_gold_getItem($typeId);
  393. my_Assert($mo != null, ErrCode::err_const_no);
  394. $tempNum = 0;
  395. foreach (ctx()->privateState->goldShopReceived as $key) {
  396. if ($key == $typeId) {
  397. $tempNum += 1;
  398. }
  399. }
  400. if ($tempNum >= $mo->freeNum) {
  401. $ts = 0;
  402. switch ($typeId) {
  403. case 1:
  404. $ts = ctx()->privateState->goldShop_CoolDownTs_1;
  405. break;
  406. case 2:
  407. $ts = ctx()->privateState->goldShop_CoolDownTs_2;
  408. break;
  409. case 3:
  410. $ts = ctx()->privateState->goldShop_CoolDownTs_3;
  411. break;
  412. }
  413. //收费买
  414. if ($typeId == 1 && ctx()->privateState->goldShop_GuangGaoNum < $mo->guanggaoNum) {
  415. ctx()->privateState->goldShop_GuangGaoNum += 1;
  416. } else {
  417. my_Assert(ctx()->baseInfo->cash >= $mo->price, ErrCode::notenough_cash_msg);
  418. ctx()->baseInfo->Consume_Cash($mo->price);
  419. }
  420. if ($ts == 0) {
  421. switch ($typeId) {
  422. case 1:
  423. ctx()->privateState->goldShop_CoolDownTs_1 = now();
  424. break;
  425. case 2:
  426. ctx()->privateState->goldShop_CoolDownTs_2 = now();
  427. break;
  428. case 3:
  429. ctx()->privateState->goldShop_CoolDownTs_3 = now();
  430. break;
  431. }
  432. //$user->privateState->goldShopReceived[] = $typeId;
  433. } else {
  434. my_Assert(now() - $ts >= $mo->downTs, ErrCode::user_shop_DownTsLimit);
  435. switch ($typeId) {
  436. case 1:
  437. ctx()->privateState->goldShop_CoolDownTs_1 = now();
  438. break;
  439. case 2:
  440. ctx()->privateState->goldShop_CoolDownTs_2 = now();
  441. break;
  442. case 3:
  443. ctx()->privateState->goldShop_CoolDownTs_3 = now();
  444. break;
  445. }
  446. }
  447. if ($typeId == 1 && ctx()->privateState->goldShop_GuangGaoNum == $mo->guanggaoNum) {
  448. ctx()->privateState->goldShop_GuangGaoNum += 1;
  449. ctx()->privateState->goldShop_CoolDownTs_1 = 0;
  450. }
  451. }
  452. TaskProc::OnBuyGold();
  453. ctx()->privateState->goldShopReceived[] = $typeId;
  454. StoreProc::AddMultiItemInStore($mo->reward);
  455. }
  456. public static function BuyShop_MonthCard($type, $typeId, $buyNum) {
  457. $mo = GameConfig::shop_monthcard_getItem($typeId);
  458. my_Assert($mo != null, ErrCode::err_const_no);
  459. //$user->privateState->monthCardShop_Received[] = $typeId;
  460. if ($typeId == 1) {
  461. my_Assert(ctx()->privateState->monthCardShop_ts == 0, ErrCode::err_const_no);
  462. ctx()->privateState->monthCardShop_ts = now();
  463. StoreProc::AddMultiItemInStore($mo->buy_reward);
  464. EmailProc::SendMonthCardRewardMail(req()->zoneid, req()->uid, $mo->daily_reward);
  465. } else {
  466. my_Assert(ctx()->privateState->honourCardShop_ts == 0, ErrCode::err_const_no);
  467. ctx()->privateState->honourCardShop_ts = now();
  468. }
  469. }
  470. /**
  471. * 商城每日重置
  472. */
  473. public static function ShopDailyClear() {
  474. ctx()->privateState->dailyShopReceived = array();
  475. ctx()->privateState->goldShopReceived = array();
  476. $num = count(ctx()->privateState->goldShopReceived);
  477. $arr = ctx()->privateState->goldShopReceived;
  478. for ($i = 0; $i < $num; $i++) {
  479. if ($arr[$i] == 1) {
  480. StlUtil::arrayRemoveAt($arr, $i);
  481. }
  482. }
  483. ctx()->privateState->goldShop_CoolDownTs_1 = 0;
  484. ctx()->privateState->goldShop_GuangGaoNum = 0;
  485. ctx()->privateState->junbeiShopNumRecord = new \stdClass();
  486. ctx()->privateState->dailyShop_GuangGaoNum = 0;
  487. ctx()->privateState->dailyShop_GuangGaoTs = 0;
  488. ctx()->privateState->guanggaoGetTiliNum = 0;
  489. ctx()->privateState->buyTiliNum = 0;
  490. ctx()->privateState->lastFreeGetTs_ShopBoxBright = 0;
  491. ctx()->privateState->lastFreeGetTs_ShopBoxCommon = 0;
  492. self::ShopMonthClear();
  493. }
  494. /**
  495. * 月卡按照时间记录的一个月后清理
  496. */
  497. public static function ShopMonthClear() {
  498. $monthTs = 30 * 24 * 60 * 60;
  499. if (ctx()->privateState->monthCardShop_ts > 0) {
  500. if (now() - ctx()->privateState->monthCardShop_ts >= $monthTs) {
  501. ctx()->privateState->monthCardShop_ts = 0;
  502. } else {
  503. $mo = GameConfig::shop_monthcard_getItem(1);
  504. EmailProc::SendMonthCardRewardMail(req()->zoneid, req()->uid, $mo->daily_reward);
  505. }
  506. }
  507. if (ctx()->privateState->honourCardShop_ts > 0 && now() - ctx()->privateState->honourCardShop_ts >= $monthTs) {
  508. ctx()->privateState->honourCardShop_ts = 0;
  509. }
  510. }
  511. /**
  512. * 每日商城随机6个道具
  513. * @return type
  514. */
  515. public static function DailyShopItemRand() {
  516. $dataDic = new \stdClass();
  517. $dic = GameConfig::shop_daily();
  518. if ($dic == null) {
  519. return;
  520. }
  521. foreach ($dic as $typeId => $mo) {
  522. $type = $mo->type;
  523. if (StlUtil::dictHasProperty($dataDic, $type)) {
  524. $list = $dataDic->$type;
  525. $list[] = $typeId;
  526. $dataDic->$type = $list;
  527. } else {
  528. $list = array();
  529. $list[] = $typeId;
  530. $dataDic->$type = $list;
  531. }
  532. }
  533. $result = array();
  534. $arrType = array(1, 2, 3, 2, 4, 3);
  535. foreach ($arrType as $k) {
  536. if (StlUtil::dictHasProperty($dataDic, $k) && count($dataDic->$k) > 0) {
  537. $arr2 = $dataDic->$k;
  538. if ($k == 1) {
  539. $result[] = $arr2[0];
  540. continue;
  541. }
  542. $allNum = 0;
  543. foreach ($arr2 as $giftTypeId) {
  544. $allNum += GameConfig::shop_daily_getItem($giftTypeId)->per;
  545. }
  546. $randNum = rand(1, $allNum);
  547. $start = 0;
  548. $end = 0;
  549. $index = 0;
  550. foreach ($arr2 as $itemId) {
  551. $per = GameConfig::shop_daily_getItem($itemId)->per;
  552. $end += $per;
  553. if ($randNum >= $start && $randNum < $end) {
  554. $result[] = $itemId;
  555. break;
  556. }
  557. $start = $end;
  558. $index += 1;
  559. }
  560. unset($arr2[$index]);
  561. $dataDic->$k = array_values($arr2);
  562. }
  563. }
  564. ctx()->privateState->dailyShopRandItems = $result;
  565. UserProc::updateUserInfo();
  566. }
  567. }