ShopProc.php 22 KB

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