ShopProc.php 23 KB

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