ShopProc.php 6.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160
  1. <?php
  2. namespace loyalsoft;
  3. /**
  4. * Description of ShopProc
  5. * 商城
  6. * @author gwang
  7. * @version 1.0.0 Created. 2020.8.19 -gwang
  8. */
  9. class ShopProc {
  10. /**
  11. * 逻辑分发
  12. * 所有的Proc中必须有这样一个方法
  13. * @param Req $req
  14. */
  15. public static function procMain($req) {
  16. switch ($req->cmd) {
  17. case CmdCode::shop_limit_maininfo:
  18. return self::GetLimitMainInfo($req);
  19. case CmdCode::shop_limit_buy:
  20. return self::BuyLimitPackage($req);
  21. case CmdCode::shop_monthlyVIP_Info:
  22. return self::GetMonthlyVipInfo($req);
  23. case CmdCode::shop_monthlyVIP_Buy:
  24. return self::BuyMonthlyVip($req);
  25. default:
  26. Err(ErrCode::cmd_err);
  27. }
  28. }
  29. public static function GetMonthlyVipInfo($req) {
  30. return Resp::ok(array(
  31. "shopdata" => $req->userInfo->game->shopdata
  32. ));
  33. }
  34. public static function BuyMonthlyVip($req) {
  35. $packageId = $req->paras[0]; # 参数; 礼包id
  36. $shopdata = new Info_UserShop($req->userInfo->game->shopdata);
  37. $packageCfg = GameConfig::shop_monthVIP_getItem($packageId);
  38. my_Assert(null != $packageCfg, ErrCode::err_const_no);
  39. if ($packageCfg->subType == 4) {
  40. my_Assert($shopdata->monthlyVIP1_ts + $packageCfg->ExpireTs * 3600 * 24 < now(), ErrCode::shop_monthlyvip_buyed);
  41. } elseif ($packageCfg->subType == 5) {
  42. my_Assert($shopdata->monthlyVIP2_ts + $packageCfg->ExpireTs * 3600 * 24 < now(), ErrCode::shop_monthlyvip_buyed);
  43. }
  44. $err = StoreProc::AddMultiItemInStore($req, $packageCfg->pri_reward); # 发放一次性奖励
  45. my_Assert(ErrCode::ok == $err, $err);
  46. if ($packageCfg->subType == 4) {
  47. $shopdata->monthlyVIP1_ts = 3600 * 24 * (tsDay() + 1) - 1;
  48. } elseif ($packageCfg->subType == 5) {
  49. $shopdata->monthlyVIP2_ts = 3600 * 24 * (tsDay() + 1) - 1;
  50. }
  51. $req->userInfo->game->shopdata = $shopdata; # 回写数据
  52. UserProc::updateUserInfo();
  53. return Resp::ok(array(
  54. "reward" => $packageCfg->pri_reward,
  55. "shopdata" => $shopdata,
  56. 'gold' => $req->userInfo->game->baseInfo->gold,
  57. 'cash' => $req->userInfo->game->baseInfo->cash,
  58. 'tili' => $req->userInfo->game->baseInfo->tili,
  59. 'store' => $req->userInfo->game->store,
  60. 'hero' => $req->userInfo->game->heros
  61. ));
  62. }
  63. /**
  64. * 【7101】限购礼包主界面
  65. * @param Req $req
  66. */
  67. public static function GetLimitMainInfo($req) {
  68. return Resp::ok(array(
  69. "shopdata" => $req->userInfo->game->shopdata
  70. ));
  71. }
  72. /**
  73. * 【7102】 购买限购礼包
  74. * @param Req $req
  75. */
  76. public static function BuyLimitPackage($req) {
  77. $packageId = $req->paras[0]; # 参数; 礼包id
  78. $shopdata = new Info_UserShop($req->userInfo->game->shopdata);
  79. $packageCfg = GameConfig::shop_limit_getItem($packageId);
  80. my_Assert(null != $packageCfg, ErrCode::err_const_no);
  81. $arr = array();
  82. switch ((int) $packageCfg->subType) {
  83. case 1:
  84. $shopdata->purchasedDailyLimitPackages[] = $packageId;
  85. $arr = $shopdata->purchasedDailyLimitPackages;
  86. break;
  87. case 2:
  88. $shopdata->purchasedWeeklyLimitPackages[] = $packageId;
  89. $arr = $shopdata->purchasedWeeklyLimitPackages;
  90. break;
  91. case 3:
  92. $shopdata->purchasedMonthlyLimitPackages[] = $packageId;
  93. $arr = $shopdata->purchasedMonthlyLimitPackages;
  94. break;
  95. default:
  96. Err(ErrCode::err_innerfault);
  97. }
  98. $hasN = count(array_filter($arr, function($val)use($packageId) {
  99. return $val == $packageId;
  100. }));
  101. my_Assert($hasN <= $packageCfg->limit_num, ErrCode::shop_limit_max);
  102. $itemid = explode(',', $packageCfg->reward)[0]; # 奖励礼包Id
  103. $itemMO = GameConfig::item_package_getItem($itemid);
  104. my_Assert(null != $itemMO, ErrCode::err_const_no);
  105. $err = StoreProc::AddMultiItemInStore($req, $itemMO->contents); # 发放奖励
  106. my_Assert(ErrCode::ok == $err, $err);
  107. $req->userInfo->game->shopdata = $shopdata; # 回写数据
  108. UserProc::updateUserInfo();
  109. return Resp::ok(array(
  110. "reward" => $itemMO->contents,
  111. "shopdata" => $shopdata,
  112. 'gold' => $req->userInfo->game->baseInfo->gold,
  113. 'cash' => $req->userInfo->game->baseInfo->cash,
  114. 'tili' => $req->userInfo->game->baseInfo->tili,
  115. 'store' => $req->userInfo->game->store,
  116. 'hero' => $req->userInfo->game->heros
  117. ));
  118. }
  119. /**
  120. * 每日检查
  121. * @param req $req
  122. */
  123. static function DailyCheck($req) {
  124. CLog::info("shop-每日检查-清除每日/周限量礼包购买记录");
  125. $zoneid = $req->zoneid;
  126. $uid = $req->uid;
  127. $shopdata = new Info_UserShop($req->userInfo->game->shopdata);
  128. $shopdata->purchasedDailyLimitPackages = array(); # 每天重置
  129. if (date("N") == 1) { # 周一重置
  130. $shopdata->purchasedWeeklyLimitPackages = array();
  131. }
  132. if (date("d") == 1) { # 1号重置
  133. $shopdata->purchasedMonthlyLimitPackages = array();
  134. }
  135. if ($shopdata->monthlyVIP1_ts + 30 * 24 * 3600 > now()) {
  136. $id = 901001;
  137. $card1 = GameConfig::shop_monthVIP_getItem($id);
  138. my_Assert(null != $card1, ErrCode::err_const_no);
  139. EmailProc::SendMonthlyVIPDailyReward($zoneid, $uid, $card1->name, $card1->daily_reward);
  140. }
  141. if ($shopdata->monthlyVIP2_ts + 30 * 24 * 3600 > now()) {
  142. $id = 901002;
  143. $card2 = GameConfig::shop_monthVIP_getItem($id);
  144. my_Assert(null != $card2, ErrCode::err_const_no);
  145. EmailProc::SendMonthlyVIPDailyReward($zoneid, $uid, $card2->name, $card2->daily_reward);
  146. }
  147. }
  148. }