ShopProc.php 27 KB

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