ShopProc.php 22 KB

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