ShopProc.php 25 KB

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