ShopProc.php 22 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640
  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. $perList = explode(';', $mo->percent);
  238. $allNum = 0;
  239. foreach ($perList as $key => $value) {
  240. $str = explode(',', $value);
  241. $allNum += $str[1];
  242. }
  243. $allNum *= 10;
  244. for ($i = 0; $i < $buyNum; $i++) {
  245. mt_srand((double) microtime() * 1000000);
  246. $buyCount = 0;
  247. if ($mo->type == 1) {
  248. ctx()->privateState->buyNum_ShopBoxCommon += 1;
  249. $buyCount = ctx()->privateState->buyNum_ShopBoxCommon;
  250. } else {
  251. ctx()->privateState->buyNum_ShopBoxBright += 1;
  252. $buyCount = ctx()->privateState->buyNum_ShopBoxBright;
  253. }
  254. $bichu1 = explode(',', $mo->bichu1);
  255. $qual = 0; //改成道具盒子了 但是这个变量不动了
  256. if ($buyCount % $bichu1[0] == 0) {
  257. $qual = $bichu1[1];
  258. }
  259. if ($mo->bichu2 != null) {
  260. $bichu2 = explode(',', $mo->bichu2);
  261. if ($buyCount % $bichu2[0] == 0) {
  262. $qual = $bichu2[1];
  263. }
  264. }
  265. if ($qual == 0) {
  266. $start = 0;
  267. $end = 0;
  268. $randNum = mt_rand(1, $allNum);
  269. foreach ($perList as $k => $val) {
  270. $str = explode(',', $val);
  271. $end += $str[1] * 10;
  272. if ($randNum > $start && $randNum <= $end) {
  273. $qual = $str[0];
  274. break;
  275. }
  276. $start = $end;
  277. }
  278. }
  279. if ($qual > 0) {
  280. StoreProc::AddMultiItemInStore($qual . ",1", Enum_StoreSourceType::ShopBox);
  281. }
  282. }
  283. TaskProc::OnOpenNumBrightBox_state($typeId, $buyNum);
  284. }
  285. /**
  286. * 补给箱
  287. * @param type $type
  288. * @param type $typeId
  289. * @param type $buyNum
  290. */
  291. public static function BuyShop_BujiBox($type, $typeId, $buyNum) {
  292. $equip = array();
  293. $mo = GameConfig::shop_supply_getItem($typeId);
  294. my_Assert($mo != null, ErrCode::err_const_no);
  295. $list = explode(',', $mo->cost);
  296. my_Assert(StlUtil::dictHasProperty(ctx()->store->items, $list[0]), ErrCode::notenough_item);
  297. ctx()->store->removeItem($list[0], $list[1]);
  298. ctx()->baseInfo->Add_Gold($mo->gold);
  299. if (!StlUtil::dictHasProperty(ctx()->privateState->junbeiShopNumRecord, $typeId)) {
  300. ctx()->privateState->junbeiShopNumRecord->$typeId = 0;
  301. }
  302. $num = ctx()->privateState->junbeiShopNumRecord->$typeId += 1;
  303. if (!StlUtil::dictHasProperty(ctx()->privateState->supplyBichuDic, $typeId)) {
  304. ctx()->privateState->supplyBichuDic->$typeId = 0;
  305. }
  306. ctx()->privateState->supplyBichuDic->$typeId += 1;
  307. my_Assert($num <= $mo->limitNum, ErrCode::user_shop_LimitNum);
  308. $plist = explode(';', $mo->percent);
  309. $randNum = rand(0, 10000);
  310. $start = 0;
  311. $end = 0;
  312. $qual = null;
  313. foreach ($plist as $item) {
  314. $arr = explode(',', $item);
  315. $per = $arr[2] * 100;
  316. $end += $per;
  317. if ($randNum >= $start && $randNum < $end) {
  318. $qual = $arr[0] . ',' . $arr[1]; //品阶,稀有度
  319. break;
  320. }
  321. $start = $end;
  322. }
  323. //必出
  324. $bichu = explode(',', $mo->bichu);
  325. $qArr = explode(',', $qual);
  326. if ($qArr[0] == $bichu[1] && $qArr[1] == $bichu[2]) {//得到必出,重置数量记录
  327. ctx()->privateState->supplyBichuDic->$typeId = 0;
  328. $qual = $bichu[1] . ',' . $bichu[2];
  329. } else {
  330. if (ctx()->privateState->supplyBichuDic->$typeId == $bichu[0]) {
  331. $qual = $bichu[1] . ',' . $bichu[2];
  332. ctx()->privateState->supplyBichuDic->$typeId = 0;
  333. }
  334. }
  335. if ($qual != null) {
  336. $str = explode(',', $qual);
  337. $equipList = array();
  338. $dic = GameConfig::equip();
  339. foreach ($dic as $tid => $item) {
  340. if ($item->qual == $str[0] && $item->rarity == $str[1]) {
  341. $equipList[] = $item->typeId;
  342. }
  343. }
  344. $rNum = rand(0, count($equipList) - 1);
  345. $equipId = $equipList[$rNum];
  346. StoreProc::PutEquipInStore($equipId, 1);
  347. $equip[] = $equipId;
  348. }
  349. return $equip;
  350. }
  351. /**
  352. * 钻石商城
  353. * @param type $type
  354. * @param type $typeId
  355. * @param type $buyNum
  356. */
  357. public static function BuyShop_Cash($type, $typeId, $buyNum) {
  358. $mo = GameConfig::shop_cash_getItem($typeId);
  359. my_Assert($mo != null, ErrCode::err_const_no);
  360. $tag = false;
  361. if (in_array($typeId, ctx()->privateState->cashShopReceived)) {
  362. $tag = true;
  363. }
  364. $reward = $mo->reward;
  365. if (!$tag) {
  366. $reward = $mo->reward . ';' . $mo->reward;
  367. }
  368. StoreProc::AddMultiItemInStore($reward);
  369. ctx()->baseInfo->charge_amt += $mo->price;
  370. ctx()->privateState->cashShopReceived[] = $typeId;
  371. TaskProc::OnRecharge();
  372. }
  373. /**
  374. * 金币商城
  375. * @param type $type
  376. * @param type $typeId
  377. * @param type $buyNum
  378. */
  379. public static function BuyShop_Gold($type, $typeId, $buyNum) {
  380. $mo = GameConfig::shop_gold_getItem($typeId);
  381. my_Assert($mo != null, ErrCode::err_const_no);
  382. $tempNum = 0;
  383. foreach (ctx()->privateState->goldShopReceived as $key) {
  384. if ($key == $typeId) {
  385. $tempNum += 1;
  386. }
  387. }
  388. if ($tempNum >= $mo->freeNum) {
  389. $ts = 0;
  390. switch ($typeId) {
  391. case 1:
  392. $ts = ctx()->privateState->goldShop_CoolDownTs_1;
  393. break;
  394. case 2:
  395. $ts = ctx()->privateState->goldShop_CoolDownTs_2;
  396. break;
  397. case 3:
  398. $ts = ctx()->privateState->goldShop_CoolDownTs_3;
  399. break;
  400. }
  401. //收费买
  402. if ($typeId == 1 && ctx()->privateState->goldShop_GuangGaoNum < $mo->guanggaoNum) {
  403. ctx()->privateState->goldShop_GuangGaoNum += 1;
  404. } else {
  405. my_Assert(ctx()->baseInfo->cash >= $mo->price, ErrCode::notenough_cash_msg);
  406. ctx()->baseInfo->Consume_Cash($mo->price);
  407. }
  408. if ($ts == 0) {
  409. switch ($typeId) {
  410. case 1:
  411. ctx()->privateState->goldShop_CoolDownTs_1 = now();
  412. break;
  413. case 2:
  414. ctx()->privateState->goldShop_CoolDownTs_2 = now();
  415. break;
  416. case 3:
  417. ctx()->privateState->goldShop_CoolDownTs_3 = now();
  418. break;
  419. }
  420. //$user->privateState->goldShopReceived[] = $typeId;
  421. } else {
  422. my_Assert(now() - $ts >= $mo->downTs, ErrCode::user_shop_DownTsLimit);
  423. switch ($typeId) {
  424. case 1:
  425. ctx()->privateState->goldShop_CoolDownTs_1 = now();
  426. break;
  427. case 2:
  428. ctx()->privateState->goldShop_CoolDownTs_2 = now();
  429. break;
  430. case 3:
  431. ctx()->privateState->goldShop_CoolDownTs_3 = now();
  432. break;
  433. }
  434. }
  435. if ($typeId == 1 && ctx()->privateState->goldShop_GuangGaoNum == $mo->guanggaoNum) {
  436. ctx()->privateState->goldShop_GuangGaoNum += 1;
  437. ctx()->privateState->goldShop_CoolDownTs_1 = 0;
  438. }
  439. }
  440. TaskProc::OnBuyGold();
  441. ctx()->privateState->goldShopReceived[] = $typeId;
  442. StoreProc::AddMultiItemInStore($mo->reward);
  443. }
  444. public static function BuyShop_MonthCard($type, $typeId, $buyNum) {
  445. $mo = GameConfig::shop_monthcard_getItem($typeId);
  446. my_Assert($mo != null, ErrCode::err_const_no);
  447. //$user->privateState->monthCardShop_Received[] = $typeId;
  448. if ($typeId == 1) {
  449. my_Assert(ctx()->privateState->monthCardShop_ts == 0, ErrCode::err_const_no);
  450. ctx()->privateState->monthCardShop_ts = now();
  451. StoreProc::AddMultiItemInStore($mo->buy_reward);
  452. EmailProc::SendMonthCardRewardMail(req()->zoneid, req()->uid, $mo->daily_reward);
  453. } else {
  454. my_Assert(ctx()->privateState->honourCardShop_ts == 0, ErrCode::err_const_no);
  455. ctx()->privateState->honourCardShop_ts = now();
  456. }
  457. }
  458. /**
  459. * 商城每日重置
  460. */
  461. public static function ShopDailyClear() {
  462. ctx()->privateState->dailyShopReceived = array();
  463. ctx()->privateState->goldShopReceived = array();
  464. $num = count(ctx()->privateState->goldShopReceived);
  465. $arr = ctx()->privateState->goldShopReceived;
  466. for ($i = 0; $i < $num; $i++) {
  467. if ($arr[$i] == 1) {
  468. StlUtil::arrayRemoveAt($arr, $i);
  469. }
  470. }
  471. ctx()->privateState->goldShop_CoolDownTs_1 = 0;
  472. ctx()->privateState->goldShop_GuangGaoNum = 0;
  473. ctx()->privateState->junbeiShopNumRecord = new \stdClass();
  474. ctx()->privateState->dailyShop_GuangGaoNum = 0;
  475. ctx()->privateState->dailyShop_GuangGaoTs = 0;
  476. ctx()->privateState->guanggaoGetTiliNum = 0;
  477. ctx()->privateState->buyTiliNum = 0;
  478. ctx()->privateState->lastFreeGetTs_ShopBoxBright = 0;
  479. ctx()->privateState->lastFreeGetTs_ShopBoxCommon = 0;
  480. self::ShopMonthClear();
  481. }
  482. /**
  483. * 月卡按照时间记录的一个月后清理
  484. */
  485. public static function ShopMonthClear() {
  486. $monthTs = 30 * 24 * 60 * 60;
  487. if (ctx()->privateState->monthCardShop_ts > 0) {
  488. if (now() - ctx()->privateState->monthCardShop_ts >= $monthTs) {
  489. ctx()->privateState->monthCardShop_ts = 0;
  490. } else {
  491. $mo = GameConfig::shop_monthcard_getItem(1);
  492. EmailProc::SendMonthCardRewardMail(req()->zoneid, req()->uid, $mo->daily_reward);
  493. }
  494. }
  495. if (ctx()->privateState->honourCardShop_ts > 0 && now() - ctx()->privateState->honourCardShop_ts >= $monthTs) {
  496. ctx()->privateState->honourCardShop_ts = 0;
  497. }
  498. }
  499. /**
  500. * 每日商城随机6个道具
  501. * @return type
  502. */
  503. public static function DailyShopItemRand() {
  504. $dataDic = new \stdClass();
  505. $dic = GameConfig::shop_daily();
  506. if ($dic == null) {
  507. return;
  508. }
  509. foreach ($dic as $typeId => $mo) {
  510. $type = $mo->type;
  511. if (StlUtil::dictHasProperty($dataDic, $type)) {
  512. $list = $dataDic->$type;
  513. $list[] = $typeId;
  514. $dataDic->$type = $list;
  515. } else {
  516. $list = array();
  517. $list[] = $typeId;
  518. $dataDic->$type = $list;
  519. }
  520. }
  521. $result = array();
  522. $arrType = array(1, 2, 3, 2, 4, 3);
  523. foreach ($arrType as $k) {
  524. if (StlUtil::dictHasProperty($dataDic, $k) && count($dataDic->$k) > 0) {
  525. $arr2 = $dataDic->$k;
  526. if ($k == 1) {
  527. $result[] = $arr2[0];
  528. continue;
  529. }
  530. $allNum = 0;
  531. foreach ($arr2 as $giftTypeId) {
  532. $allNum += GameConfig::shop_daily_getItem($giftTypeId)->per;
  533. }
  534. $randNum = rand(1, $allNum);
  535. $start = 0;
  536. $end = 0;
  537. $index = 0;
  538. foreach ($arr2 as $itemId) {
  539. $per = GameConfig::shop_daily_getItem($itemId)->per;
  540. $end += $per;
  541. if ($randNum >= $start && $randNum < $end) {
  542. $result[] = $itemId;
  543. break;
  544. }
  545. $start = $end;
  546. $index += 1;
  547. }
  548. unset($arr2[$index]);
  549. $dataDic->$k = array_values($arr2);
  550. }
  551. }
  552. ctx()->privateState->dailyShopRandItems = $result;
  553. UserProc::updateUserInfo();
  554. }
  555. }