ShopProc.php 23 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648
  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. if(ctx()->privateState->firstRecharge_receiveTag == 0){
  372. ctx()->privateState->firstRechargeUI_OpenTip = 1;
  373. }
  374. if(ctx()->privateState->firstRecharge_receiveTag < 1){
  375. ctx()->privateState->firstRecharge_receiveTag = 1;
  376. }
  377. TaskProc::OnRecharge();
  378. }
  379. /**
  380. * 金币商城
  381. * @param type $type
  382. * @param type $typeId
  383. * @param type $buyNum
  384. */
  385. public static function BuyShop_Gold($type, $typeId, $buyNum) {
  386. $mo = GameConfig::shop_gold_getItem($typeId);
  387. my_Assert($mo != null, ErrCode::err_const_no);
  388. $tempNum = 0;
  389. foreach (ctx()->privateState->goldShopReceived as $key) {
  390. if ($key == $typeId) {
  391. $tempNum += 1;
  392. }
  393. }
  394. if ($tempNum >= $mo->freeNum) {
  395. $ts = 0;
  396. switch ($typeId) {
  397. case 1:
  398. $ts = ctx()->privateState->goldShop_CoolDownTs_1;
  399. break;
  400. case 2:
  401. $ts = ctx()->privateState->goldShop_CoolDownTs_2;
  402. break;
  403. case 3:
  404. $ts = ctx()->privateState->goldShop_CoolDownTs_3;
  405. break;
  406. }
  407. //收费买
  408. if ($typeId == 1 && ctx()->privateState->goldShop_GuangGaoNum < $mo->guanggaoNum) {
  409. ctx()->privateState->goldShop_GuangGaoNum += 1;
  410. } else {
  411. my_Assert(ctx()->baseInfo->cash >= $mo->price, ErrCode::notenough_cash_msg);
  412. ctx()->baseInfo->Consume_Cash($mo->price);
  413. }
  414. if ($ts == 0) {
  415. switch ($typeId) {
  416. case 1:
  417. ctx()->privateState->goldShop_CoolDownTs_1 = now();
  418. break;
  419. case 2:
  420. ctx()->privateState->goldShop_CoolDownTs_2 = now();
  421. break;
  422. case 3:
  423. ctx()->privateState->goldShop_CoolDownTs_3 = now();
  424. break;
  425. }
  426. //$user->privateState->goldShopReceived[] = $typeId;
  427. } else {
  428. my_Assert(now() - $ts >= $mo->downTs, ErrCode::user_shop_DownTsLimit);
  429. switch ($typeId) {
  430. case 1:
  431. ctx()->privateState->goldShop_CoolDownTs_1 = now();
  432. break;
  433. case 2:
  434. ctx()->privateState->goldShop_CoolDownTs_2 = now();
  435. break;
  436. case 3:
  437. ctx()->privateState->goldShop_CoolDownTs_3 = now();
  438. break;
  439. }
  440. }
  441. if ($typeId == 1 && ctx()->privateState->goldShop_GuangGaoNum == $mo->guanggaoNum) {
  442. ctx()->privateState->goldShop_GuangGaoNum += 1;
  443. ctx()->privateState->goldShop_CoolDownTs_1 = 0;
  444. }
  445. }
  446. TaskProc::OnBuyGold();
  447. ctx()->privateState->goldShopReceived[] = $typeId;
  448. StoreProc::AddMultiItemInStore($mo->reward);
  449. }
  450. public static function BuyShop_MonthCard($type, $typeId, $buyNum) {
  451. $mo = GameConfig::shop_monthcard_getItem($typeId);
  452. my_Assert($mo != null, ErrCode::err_const_no);
  453. //$user->privateState->monthCardShop_Received[] = $typeId;
  454. if ($typeId == 1) {
  455. my_Assert(ctx()->privateState->monthCardShop_ts == 0, ErrCode::err_const_no);
  456. ctx()->privateState->monthCardShop_ts = now();
  457. StoreProc::AddMultiItemInStore($mo->buy_reward);
  458. EmailProc::SendMonthCardRewardMail(req()->zoneid, req()->uid, $mo->daily_reward);
  459. } else {
  460. my_Assert(ctx()->privateState->honourCardShop_ts == 0, ErrCode::err_const_no);
  461. ctx()->privateState->honourCardShop_ts = now();
  462. }
  463. }
  464. /**
  465. * 商城每日重置
  466. */
  467. public static function ShopDailyClear() {
  468. ctx()->privateState->dailyShopReceived = array();
  469. ctx()->privateState->goldShopReceived = array();
  470. $num = count(ctx()->privateState->goldShopReceived);
  471. $arr = ctx()->privateState->goldShopReceived;
  472. for ($i = 0; $i < $num; $i++) {
  473. if ($arr[$i] == 1) {
  474. StlUtil::arrayRemoveAt($arr, $i);
  475. }
  476. }
  477. ctx()->privateState->goldShop_CoolDownTs_1 = 0;
  478. ctx()->privateState->goldShop_GuangGaoNum = 0;
  479. ctx()->privateState->junbeiShopNumRecord = new \stdClass();
  480. ctx()->privateState->dailyShop_GuangGaoNum = 0;
  481. ctx()->privateState->dailyShop_GuangGaoTs = 0;
  482. ctx()->privateState->guanggaoGetTiliNum = 0;
  483. ctx()->privateState->buyTiliNum = 0;
  484. ctx()->privateState->lastFreeGetTs_ShopBoxBright = 0;
  485. ctx()->privateState->lastFreeGetTs_ShopBoxCommon = 0;
  486. self::ShopMonthClear();
  487. }
  488. /**
  489. * 月卡按照时间记录的一个月后清理
  490. */
  491. public static function ShopMonthClear() {
  492. $monthTs = 30 * 24 * 60 * 60;
  493. if (ctx()->privateState->monthCardShop_ts > 0) {
  494. if (now() - ctx()->privateState->monthCardShop_ts >= $monthTs) {
  495. ctx()->privateState->monthCardShop_ts = 0;
  496. } else {
  497. $mo = GameConfig::shop_monthcard_getItem(1);
  498. EmailProc::SendMonthCardRewardMail(req()->zoneid, req()->uid, $mo->daily_reward);
  499. }
  500. }
  501. if (ctx()->privateState->honourCardShop_ts > 0 && now() - ctx()->privateState->honourCardShop_ts >= $monthTs) {
  502. ctx()->privateState->honourCardShop_ts = 0;
  503. }
  504. }
  505. /**
  506. * 每日商城随机6个道具
  507. * @return type
  508. */
  509. public static function DailyShopItemRand() {
  510. $dataDic = new \stdClass();
  511. $dic = GameConfig::shop_daily();
  512. if ($dic == null) {
  513. return;
  514. }
  515. foreach ($dic as $typeId => $mo) {
  516. $type = $mo->type;
  517. if (StlUtil::dictHasProperty($dataDic, $type)) {
  518. $list = $dataDic->$type;
  519. $list[] = $typeId;
  520. $dataDic->$type = $list;
  521. } else {
  522. $list = array();
  523. $list[] = $typeId;
  524. $dataDic->$type = $list;
  525. }
  526. }
  527. $result = array();
  528. $arrType = array(1, 2, 3, 2, 4, 3);
  529. foreach ($arrType as $k) {
  530. if (StlUtil::dictHasProperty($dataDic, $k) && count($dataDic->$k) > 0) {
  531. $arr2 = $dataDic->$k;
  532. if ($k == 1) {
  533. $result[] = $arr2[0];
  534. continue;
  535. }
  536. $allNum = 0;
  537. foreach ($arr2 as $giftTypeId) {
  538. $allNum += GameConfig::shop_daily_getItem($giftTypeId)->per;
  539. }
  540. $randNum = rand(1, $allNum);
  541. $start = 0;
  542. $end = 0;
  543. $index = 0;
  544. foreach ($arr2 as $itemId) {
  545. $per = GameConfig::shop_daily_getItem($itemId)->per;
  546. $end += $per;
  547. if ($randNum >= $start && $randNum < $end) {
  548. $result[] = $itemId;
  549. break;
  550. }
  551. $start = $end;
  552. $index += 1;
  553. }
  554. unset($arr2[$index]);
  555. $dataDic->$k = array_values($arr2);
  556. }
  557. }
  558. ctx()->privateState->dailyShopRandItems = $result;
  559. UserProc::updateUserInfo();
  560. }
  561. }