ShopProc.php 21 KB

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