ShopProc.php 27 KB

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