ShopProc.php 6.5 KB

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