ShopProc.php 24 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676
  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. $mo = GameConfig::shop_supply_getItem($typeId);
  316. my_Assert($mo != null, ErrCode::err_const_no);
  317. $list = explode(',', $mo->cost);
  318. my_Assert(StlUtil::dictHasProperty(ctx()->store->items, $list[0]), ErrCode::notenough_item);
  319. ctx()->store->removeItem($list[0], $list[1]);
  320. ctx()->baseInfo->Add_Gold($mo->gold);
  321. if (!StlUtil::dictHasProperty(ctx()->privateState->junbeiShopNumRecord, $typeId)) {
  322. ctx()->privateState->junbeiShopNumRecord->$typeId = 0;
  323. }
  324. $num = ctx()->privateState->junbeiShopNumRecord->$typeId += 1;
  325. if (!StlUtil::dictHasProperty(ctx()->privateState->supplyBichuDic, $typeId)) {
  326. ctx()->privateState->supplyBichuDic->$typeId = 0;
  327. }
  328. ctx()->privateState->supplyBichuDic->$typeId += 1;
  329. my_Assert($num <= $mo->limitNum, ErrCode::user_shop_LimitNum);
  330. $plist = explode(';', $mo->percent);
  331. $randNum = rand(0, 10000);
  332. $start = 0;
  333. $end = 0;
  334. $qual = null;
  335. foreach ($plist as $item) {
  336. $arr = explode(',', $item);
  337. $per = $arr[2] * 100;
  338. $end += $per;
  339. if ($randNum >= $start && $randNum < $end) {
  340. $qual = $arr[0] . ',' . $arr[1]; //品阶,稀有度
  341. break;
  342. }
  343. $start = $end;
  344. }
  345. //必出
  346. $bichu = explode(',', $mo->bichu);
  347. $qArr = explode(',', $qual);
  348. if ($qArr[0] == $bichu[1] && $qArr[1] == $bichu[2]) {//得到必出,重置数量记录
  349. ctx()->privateState->supplyBichuDic->$typeId = 0;
  350. $qual = $bichu[1] . ',' . $bichu[2];
  351. } else {
  352. if (ctx()->privateState->supplyBichuDic->$typeId == $bichu[0]) {
  353. $qual = $bichu[1] . ',' . $bichu[2];
  354. ctx()->privateState->supplyBichuDic->$typeId = 0;
  355. }
  356. }
  357. if ($qual != null) {
  358. $str = explode(',', $qual);
  359. $equipList = array();
  360. $dic = GameConfig::equip();
  361. foreach ($dic as $tid => $item) {
  362. if ($item->qual == $str[0] && $item->rarity == $str[1]) {
  363. $equipList[] = $item->typeId;
  364. }
  365. }
  366. $rNum = rand(0, count($equipList) - 1);
  367. $equipId = $equipList[$rNum];
  368. StoreProc::PutEquipInStore($equipId, 1);
  369. $equip[] = $equipId;
  370. }
  371. return $equip;
  372. }
  373. /**
  374. * 钻石商城
  375. * @param type $type
  376. * @param type $typeId
  377. * @param type $buyNum
  378. */
  379. public static function BuyShop_Cash($type, $typeId, $buyNum) {
  380. $mo = GameConfig::shop_cash_getItem($typeId);
  381. my_Assert($mo != null, ErrCode::err_const_no);
  382. $tag = false;
  383. if (in_array($typeId, ctx()->privateState->cashShopReceived)) {
  384. $tag = true;
  385. }
  386. $reward = $mo->reward;
  387. $pList = explode(',', $reward);
  388. $addYuanbao = $pList[1];
  389. if (!$tag) {
  390. $reward = $mo->reward . ';' . $mo->reward;
  391. $addYuanbao *= 2;
  392. }
  393. StoreProc::AddMultiItemInStore($reward);
  394. ctx()->baseInfo->accumulateYuanBao += $addYuanbao;
  395. ctx()->baseInfo->charge_amt += $mo->price;
  396. ctx()->privateState->cashShopReceived[] = $typeId;
  397. if (ctx()->privateState->firstRecharge_receiveTag == 0) {
  398. ctx()->privateState->firstRechargeUI_OpenTip = 1;
  399. }
  400. if (ctx()->privateState->firstRecharge_receiveTag < 1) {
  401. ctx()->privateState->firstRecharge_receiveTag = 1;
  402. }
  403. TaskProc::OnRecharge();
  404. return $reward;
  405. }
  406. /**
  407. * 金币商城
  408. * @param type $type
  409. * @param type $typeId
  410. * @param type $buyNum
  411. */
  412. public static function BuyShop_Gold($type, $typeId, $buyNum) {
  413. $mo = GameConfig::shop_gold_getItem($typeId);
  414. my_Assert($mo != null, ErrCode::err_const_no);
  415. $tempNum = 0;
  416. foreach (ctx()->privateState->goldShopReceived as $key) {
  417. if ($key == $typeId) {
  418. $tempNum += 1;
  419. }
  420. }
  421. if ($tempNum >= $mo->freeNum) {
  422. $ts = 0;
  423. switch ($typeId) {
  424. case 1:
  425. $ts = ctx()->privateState->goldShop_CoolDownTs_1;
  426. break;
  427. case 2:
  428. $ts = ctx()->privateState->goldShop_CoolDownTs_2;
  429. break;
  430. case 3:
  431. $ts = ctx()->privateState->goldShop_CoolDownTs_3;
  432. break;
  433. }
  434. //收费买
  435. if ($typeId == 1 && ctx()->privateState->goldShop_GuangGaoNum < $mo->guanggaoNum) {
  436. ctx()->privateState->goldShop_GuangGaoNum += 1;
  437. } else {
  438. my_Assert(ctx()->baseInfo->cash >= $mo->price, ErrCode::notenough_cash_msg);
  439. ctx()->baseInfo->Consume_Cash($mo->price);
  440. }
  441. if ($ts == 0) {
  442. switch ($typeId) {
  443. case 1:
  444. ctx()->privateState->goldShop_CoolDownTs_1 = now();
  445. break;
  446. case 2:
  447. ctx()->privateState->goldShop_CoolDownTs_2 = now();
  448. break;
  449. case 3:
  450. ctx()->privateState->goldShop_CoolDownTs_3 = now();
  451. break;
  452. }
  453. //$user->privateState->goldShopReceived[] = $typeId;
  454. } else {
  455. my_Assert(now() - $ts >= $mo->downTs, ErrCode::user_shop_DownTsLimit);
  456. switch ($typeId) {
  457. case 1:
  458. ctx()->privateState->goldShop_CoolDownTs_1 = now();
  459. break;
  460. case 2:
  461. ctx()->privateState->goldShop_CoolDownTs_2 = now();
  462. break;
  463. case 3:
  464. ctx()->privateState->goldShop_CoolDownTs_3 = now();
  465. break;
  466. }
  467. }
  468. if ($typeId == 1 && ctx()->privateState->goldShop_GuangGaoNum == $mo->guanggaoNum) {
  469. ctx()->privateState->goldShop_GuangGaoNum += 1;
  470. ctx()->privateState->goldShop_CoolDownTs_1 = 0;
  471. }
  472. }
  473. ctx()->privateState->goldShopReceived[] = $typeId;
  474. TaskProc::OnBuyGold();
  475. StoreProc::AddMultiItemInStore($mo->reward);
  476. }
  477. public static function BuyShop_MonthCard($type, $typeId, $buyNum) {
  478. $mo = GameConfig::shop_monthcard_getItem($typeId);
  479. my_Assert($mo != null, ErrCode::err_const_no);
  480. //$user->privateState->monthCardShop_Received[] = $typeId;
  481. if ($typeId == 1) {
  482. my_Assert(ctx()->privateState->monthCardShop_ts == 0, ErrCode::err_const_no);
  483. ctx()->privateState->monthCardShop_ts = now();
  484. StoreProc::AddMultiItemInStore($mo->buy_reward);
  485. EmailProc::SendMonthCardRewardMail(req()->zoneid, req()->uid, $mo->daily_reward);
  486. } else {
  487. my_Assert(ctx()->privateState->honourCardShop_ts == 0, ErrCode::err_const_no);
  488. ctx()->privateState->honourCardShop_ts = now();
  489. }
  490. }
  491. /**
  492. * 商城每日重置
  493. */
  494. public static function ShopDailyClear() {
  495. ctx()->privateState->dailyShopReceived = array();
  496. ctx()->privateState->goldShopReceived = array();
  497. $num = count(ctx()->privateState->goldShopReceived);
  498. $arr = ctx()->privateState->goldShopReceived;
  499. for ($i = 0; $i < $num; $i++) {
  500. if ($arr[$i] == 1) {
  501. StlUtil::arrayRemoveAt($arr, $i);
  502. }
  503. }
  504. ctx()->privateState->goldShop_CoolDownTs_1 = 0;
  505. ctx()->privateState->goldShop_GuangGaoNum = 0;
  506. ctx()->privateState->junbeiShopNumRecord = new \stdClass();
  507. ctx()->privateState->dailyShop_GuangGaoNum = 0;
  508. ctx()->privateState->dailyShop_GuangGaoTs = 0;
  509. ctx()->privateState->guanggaoGetTiliNum = 0;
  510. ctx()->privateState->buyTiliNum = 0;
  511. ctx()->privateState->lastFreeGetTs_ShopBoxBright = 0;
  512. ctx()->privateState->lastFreeGetTs_ShopBoxCommon = 0;
  513. self::ShopMonthClear();
  514. }
  515. /**
  516. * 月卡按照时间记录的一个月后清理
  517. */
  518. public static function ShopMonthClear() {
  519. $monthTs = 30 * 24 * 60 * 60;
  520. if (ctx()->privateState->monthCardShop_ts > 0) {
  521. if (now() - ctx()->privateState->monthCardShop_ts >= $monthTs) {
  522. ctx()->privateState->monthCardShop_ts = 0;
  523. } else {
  524. $mo = GameConfig::shop_monthcard_getItem(1);
  525. EmailProc::SendMonthCardRewardMail(req()->zoneid, req()->uid, $mo->daily_reward);
  526. }
  527. }
  528. if (ctx()->privateState->honourCardShop_ts > 0 && now() - ctx()->privateState->honourCardShop_ts >= $monthTs) {
  529. ctx()->privateState->honourCardShop_ts = 0;
  530. }
  531. }
  532. /**
  533. * 每日商城随机6个道具
  534. * @return type
  535. */
  536. public static function DailyShopItemRand() {
  537. $dataDic = new \stdClass();
  538. $dic = GameConfig::shop_daily();
  539. if ($dic == null) {
  540. return;
  541. }
  542. foreach ($dic as $typeId => $mo) {
  543. $type = $mo->type;
  544. if (StlUtil::dictHasProperty($dataDic, $type)) {
  545. $list = $dataDic->$type;
  546. $list[] = $typeId;
  547. $dataDic->$type = $list;
  548. } else {
  549. $list = array();
  550. $list[] = $typeId;
  551. $dataDic->$type = $list;
  552. }
  553. }
  554. $result = array();
  555. $arrType = array(1, 2, 3, 2, 4, 3);
  556. foreach ($arrType as $k) {
  557. if (StlUtil::dictHasProperty($dataDic, $k) && count($dataDic->$k) > 0) {
  558. $arr2 = $dataDic->$k;
  559. if ($k == 1) {
  560. $result[] = $arr2[0];
  561. continue;
  562. }
  563. $allNum = 0;
  564. foreach ($arr2 as $giftTypeId) {
  565. $allNum += GameConfig::shop_daily_getItem($giftTypeId)->per;
  566. }
  567. $randNum = rand(1, $allNum);
  568. $start = 0;
  569. $end = 0;
  570. $index = 0;
  571. foreach ($arr2 as $itemId) {
  572. $per = GameConfig::shop_daily_getItem($itemId)->per;
  573. $end += $per;
  574. if ($randNum >= $start && $randNum < $end) {
  575. $result[] = $itemId;
  576. break;
  577. }
  578. $start = $end;
  579. $index += 1;
  580. }
  581. unset($arr2[$index]);
  582. $dataDic->$k = array_values($arr2);
  583. }
  584. }
  585. ctx()->privateState->dailyShopRandItems = $result;
  586. UserProc::updateUserInfo();
  587. }
  588. }