ShopProc.php 8.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201
  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. */
  14. public static function procMain() {
  15. switch (req()->cmd) {
  16. case CmdCode::shop_limit_maininfo:
  17. return self::GetLimitMainInfo();
  18. case CmdCode::shop_limit_buy:
  19. return self::BuyLimitPackage();
  20. case CmdCode::shop_monthlyVIP_Info:
  21. return self::GetMonthlyVipInfo();
  22. case CmdCode::shop_monthlyVIP_Buy:
  23. return self::BuyMonthlyVip();
  24. case CmdCode::shop_getDaliySpecial:
  25. return self::GetDaliySpecial();
  26. default:
  27. Err(ErrCode::cmd_err);
  28. }
  29. }
  30. //
  31. public static function GetDaliySpecial() {
  32. return Resp::ok(array(
  33. "shopdata" => req()->userInfo->game->shopdata
  34. ));
  35. }
  36. /*
  37. * 重置每日特惠信息
  38. */
  39. static function resetDaliySpecialPackages() {
  40. if(req()->userInfo->game->shopdata->daliySpecialClear_ts == 0){
  41. req()->userInfo->game->shopdata->daliySpecialClear_ts = now();
  42. }
  43. $curDay = TimeUtil::tsDay();
  44. $lastDay = TimeUtil::tsDay(req()->userInfo->game->shopdata->daliySpecialClear_ts);
  45. if($curDay-$lastDay ==1 && TimeUtil::tsHour(req()->userInfo->game->shopdata->daliySpecialClear_ts) < 5 && TimeUtil::tsHour(now()) > 5){
  46. req()->userInfo->game->shopdata->daliySpecialClear_ts = now();
  47. req()->userInfo->game->shopdata->daliySpecialPackages = array();
  48. } else if($curDay-$lastDay >1){
  49. req()->userInfo->game->shopdata->daliySpecialClear_ts = now();
  50. req()->userInfo->game->shopdata->daliySpecialPackages = array();
  51. }
  52. if(TimeUtil::tsDay(req()->userInfo->game->shopdata->daliySpecialClear_ts) == TimeUtil::tsDay() #
  53. && TimeUtil::tsHour(req()->userInfo->game->shopdata->daliySpecialClear_ts) < 5 && TimeUtil::tsHour(now()) > 5){
  54. req()->userInfo->game->shopdata->daliySpecialClear_ts = now();
  55. req()->userInfo->game->shopdata->daliySpecialPackages = array();
  56. }
  57. }
  58. /**
  59. * 获取月卡信息
  60. * @return type
  61. */
  62. public static function GetMonthlyVipInfo() {
  63. return Resp::ok(array(
  64. "shopdata" => req()->userInfo->game->shopdata
  65. ));
  66. }
  67. /**
  68. * 购买月卡
  69. * @return type
  70. */
  71. public static function BuyMonthlyVip() {
  72. $packageId = req()->paras[0]; # 参数; 礼包id
  73. $shopdata = new Info_UserShop(req()->userInfo->game->shopdata);
  74. $packageCfg = GameConfig::shop_monthVIP_getItem($packageId);
  75. my_Assert(null != $packageCfg, ErrCode::err_const_no);
  76. if ($packageCfg->subType == 4) {
  77. my_Assert($shopdata->monthlyVIP1_ts + $packageCfg->ExpireTs * 3600 * 24 < now(), ErrCode::shop_monthlyvip_buyed);
  78. } elseif ($packageCfg->subType == 5) {
  79. my_Assert($shopdata->monthlyVIP2_ts + $packageCfg->ExpireTs * 3600 * 24 < now(), ErrCode::shop_monthlyvip_buyed);
  80. }
  81. $err = StoreProc::AddMultiItemInStore($packageCfg->pri_reward); # 发放一次性奖励
  82. my_Assert(ErrCode::ok == $err, $err);
  83. if ($packageCfg->subType == 4) {
  84. $shopdata->monthlyVIP1_ts = 3600 * 24 * (tsDay() + 1) - 1;
  85. } elseif ($packageCfg->subType == 5) {
  86. $shopdata->monthlyVIP2_ts = 3600 * 24 * (tsDay() + 1) - 1;
  87. }
  88. EmailProc::SendMonthlyVIPDailyReward(req()->zoneid, req()->uid, $packageCfg->name, $packageCfg->daily_reward);
  89. req()->userInfo->game->shopdata = $shopdata; # 回写数据
  90. UserProc::updateUserInfo();
  91. $user = req()->userInfo->game;
  92. return Resp::ok(array(
  93. "reward" => $packageCfg->pri_reward,
  94. "shopdata" => $shopdata,
  95. 'gold' => $user->baseInfo->gold,
  96. 'cash' => $user->baseInfo->cash,
  97. 'tili' => $user->baseInfo->tili,
  98. 'store' => $user->store,
  99. 'hero' => $user->heros
  100. ));
  101. }
  102. /**
  103. * 【7101】限购礼包主界面
  104. */
  105. public static function GetLimitMainInfo() {
  106. return Resp::ok(array(
  107. "shopdata" => req()->userInfo->game->shopdata
  108. ));
  109. }
  110. /**
  111. * 【7102】 购买限购礼包
  112. */
  113. public static function BuyLimitPackage() {
  114. $packageId = req()->paras[0]; # 参数; 礼包id
  115. $shopdata = new Info_UserShop(req()->userInfo->game->shopdata);
  116. $packageCfg = GameConfig::shop_limit_getItem($packageId);
  117. my_Assert(null != $packageCfg, ErrCode::err_const_no);
  118. $arr = array();
  119. switch ((int) $packageCfg->subType) {
  120. case 1:
  121. $shopdata->purchasedDailyLimitPackages[] = $packageId;
  122. $arr = $shopdata->purchasedDailyLimitPackages;
  123. break;
  124. case 2:
  125. $shopdata->purchasedWeeklyLimitPackages[] = $packageId;
  126. $arr = $shopdata->purchasedWeeklyLimitPackages;
  127. break;
  128. case 3:
  129. $shopdata->purchasedMonthlyLimitPackages[] = $packageId;
  130. $arr = $shopdata->purchasedMonthlyLimitPackages;
  131. break;
  132. default:
  133. Err(ErrCode::err_innerfault);
  134. }
  135. $hasN = count(array_filter($arr, function ($val)use ($packageId) {
  136. return $val == $packageId;
  137. }));
  138. my_Assert($hasN <= $packageCfg->limit_num, ErrCode::shop_limit_max);
  139. $itemid = explode(',', $packageCfg->reward)[0]; # 奖励礼包Id
  140. $itemMO = GameConfig::item_package_getItem($itemid);
  141. my_Assert(null != $itemMO, ErrCode::err_const_no);
  142. $err = StoreProc::AddMultiItemInStore($itemMO->contents); # 发放奖励
  143. my_Assert(ErrCode::ok == $err, $err);
  144. req()->userInfo->game->shopdata = $shopdata; # 回写数据
  145. UserProc::updateUserInfo();
  146. $user = req()->userInfo->game;
  147. return Resp::ok(array(
  148. "reward" => $itemMO->contents,
  149. "shopdata" => $shopdata,
  150. 'gold' => $user->baseInfo->gold,
  151. 'cash' => $user->baseInfo->cash,
  152. 'tili' => $user->baseInfo->tili,
  153. 'store' => $user->store,
  154. 'hero' => $user->heros
  155. ));
  156. }
  157. /**
  158. * 每日检查
  159. */
  160. static function DailyCheck() {
  161. CLog::info("shop-每日检查-清除每日/周限量礼包购买记录");
  162. $zoneid = req()->zoneid;
  163. $uid = req()->uid;
  164. $shopdata = new Info_UserShop(req()->userInfo->game->shopdata);
  165. $shopdata->purchasedDailyLimitPackages = array(); # 每天重置
  166. if (date("N") == 1) { # 周一重置
  167. $shopdata->purchasedWeeklyLimitPackages = array();
  168. }
  169. if (date("d") == 1) { # 1号重置
  170. $shopdata->purchasedMonthlyLimitPackages = array();
  171. }
  172. if ($shopdata->monthlyVIP1_ts + 30 * 24 * 3600 > now()) {
  173. $id = 901001;
  174. $card1 = GameConfig::shop_monthVIP_getItem($id);
  175. my_Assert(null != $card1, ErrCode::err_const_no);
  176. EmailProc::SendMonthlyVIPDailyReward($zoneid, $uid, $card1->name, $card1->daily_reward);
  177. }
  178. if ($shopdata->monthlyVIP2_ts + 30 * 24 * 3600 > now()) {
  179. $id = 901002;
  180. $card2 = GameConfig::shop_monthVIP_getItem($id);
  181. my_Assert(null != $card2, ErrCode::err_const_no);
  182. EmailProc::SendMonthlyVIPDailyReward($zoneid, $uid, $card2->name, $card2->daily_reward);
  183. }
  184. }
  185. }