ShopProc.php 27 KB

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