ShopProc.php 23 KB

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