ShopProc.php 9.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245
  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. case CmdCode::shop_getRechargeRebate:
  27. return self::GetRechargeRebate();
  28. default:
  29. Err(ErrCode::cmd_err);
  30. }
  31. }
  32. /*
  33. * 限购礼包触发条件检测
  34. */
  35. public function checkLimitTsRandGiftTrigger($typeId,$para) {
  36. $arr = GameConfig::shop_limitTs_Type_getItemArray($typeId);
  37. my_Assert($arr != null, ErrCode::err_const_no);
  38. $giftId = 0;
  39. $giftArr = array();
  40. foreach ($arr as $item) {
  41. if($item->para <= $para){
  42. if(!in_array($item->giftId, req()->userInfo->game->shopdata->limitTsRewardsList)){
  43. $giftId = $item->giftId;
  44. $giftArr[] = $giftId;
  45. }
  46. }
  47. }
  48. //没有触发对应的礼包条件
  49. if($giftId == 0){
  50. return;
  51. }
  52. //已经领取礼包,不能重复领取
  53. if(in_array($giftId, req()->userInfo->game->shopdata->limitTsRewardsList)){
  54. return;
  55. }
  56. //触发对应的礼包条件。则将礼包id存储在
  57. $gift = new Ins_Gift();
  58. $gift->giftId = $giftId;
  59. $gift->startTs = now();
  60. $gift->endTs = now() + GameConfig::shop_limit_getItem($giftId)->limit_ts;
  61. req()->userInfo->game->store->triggerLimitTsGift[] = $gift;
  62. }
  63. public static function GetRechargeRebate() {
  64. return Resp::ok(array(
  65. "shopdata" => req()->userInfo->game->shopdata
  66. ));
  67. }
  68. //
  69. public static function GetDaliySpecial() {
  70. return Resp::ok(array(
  71. "shopdata" => req()->userInfo->game->shopdata
  72. ));
  73. }
  74. /*
  75. * 重置每日特惠信息
  76. */
  77. static function resetDaliySpecialPackages() {
  78. if(req()->userInfo->game->shopdata->daliySpecialClear_ts == 0){
  79. req()->userInfo->game->shopdata->daliySpecialClear_ts = now();
  80. }
  81. $curDay = TimeUtil::tsDay();
  82. $lastDay = TimeUtil::tsDay(req()->userInfo->game->shopdata->daliySpecialClear_ts);
  83. if($curDay-$lastDay ==1 && TimeUtil::tsHour(req()->userInfo->game->shopdata->daliySpecialClear_ts) < 5 && TimeUtil::tsHour(now()) > 5){
  84. req()->userInfo->game->shopdata->daliySpecialClear_ts = now();
  85. req()->userInfo->game->shopdata->daliySpecialPackages = array();
  86. } else if($curDay-$lastDay >1){
  87. req()->userInfo->game->shopdata->daliySpecialClear_ts = now();
  88. req()->userInfo->game->shopdata->daliySpecialPackages = array();
  89. }
  90. if(TimeUtil::tsDay(req()->userInfo->game->shopdata->daliySpecialClear_ts) == TimeUtil::tsDay() #
  91. && TimeUtil::tsHour(req()->userInfo->game->shopdata->daliySpecialClear_ts) < 5 && TimeUtil::tsHour(now()) > 5){
  92. req()->userInfo->game->shopdata->daliySpecialClear_ts = now();
  93. req()->userInfo->game->shopdata->daliySpecialPackages = array();
  94. }
  95. }
  96. /**
  97. * 获取月卡信息
  98. * @return type
  99. */
  100. public static function GetMonthlyVipInfo() {
  101. return Resp::ok(array(
  102. "shopdata" => req()->userInfo->game->shopdata
  103. ));
  104. }
  105. /**
  106. * 购买月卡
  107. * @return type
  108. */
  109. public static function BuyMonthlyVip() {
  110. $packageId = req()->paras[0]; # 参数; 礼包id
  111. $shopdata = new Info_UserShop(req()->userInfo->game->shopdata);
  112. $packageCfg = GameConfig::shop_monthVIP_getItem($packageId);
  113. my_Assert(null != $packageCfg, ErrCode::err_const_no);
  114. if ($packageCfg->subType == 4) {
  115. my_Assert($shopdata->monthlyVIP1_ts + $packageCfg->ExpireTs * 3600 * 24 < now(), ErrCode::shop_monthlyvip_buyed);
  116. } elseif ($packageCfg->subType == 5) {
  117. my_Assert($shopdata->monthlyVIP2_ts + $packageCfg->ExpireTs * 3600 * 24 < now(), ErrCode::shop_monthlyvip_buyed);
  118. }
  119. $err = StoreProc::AddMultiItemInStore($packageCfg->pri_reward); # 发放一次性奖励
  120. my_Assert(ErrCode::ok == $err, $err);
  121. if ($packageCfg->subType == 4) {
  122. $shopdata->monthlyVIP1_ts = 3600 * 24 * (tsDay() + 1) - 1;
  123. } elseif ($packageCfg->subType == 5) {
  124. $shopdata->monthlyVIP2_ts = 3600 * 24 * (tsDay() + 1) - 1;
  125. }
  126. EmailProc::SendMonthlyVIPDailyReward(req()->zoneid, req()->uid, $packageCfg->name, $packageCfg->daily_reward);
  127. req()->userInfo->game->shopdata = $shopdata; # 回写数据
  128. UserProc::updateUserInfo();
  129. $user = req()->userInfo->game;
  130. return Resp::ok(array(
  131. "reward" => $packageCfg->pri_reward,
  132. "shopdata" => $shopdata,
  133. 'gold' => $user->baseInfo->gold,
  134. 'cash' => $user->baseInfo->cash,
  135. 'tili' => $user->baseInfo->tili,
  136. 'store' => $user->store,
  137. 'hero' => $user->heros
  138. ));
  139. }
  140. /**
  141. * 【7101】限购礼包主界面
  142. */
  143. public static function GetLimitMainInfo() {
  144. return Resp::ok(array(
  145. "shopdata" => req()->userInfo->game->shopdata
  146. ));
  147. }
  148. /**
  149. * 【7102】 购买限购礼包
  150. */
  151. public static function BuyLimitPackage() {
  152. $packageId = req()->paras[0]; # 参数; 礼包id
  153. $shopdata = new Info_UserShop(req()->userInfo->game->shopdata);
  154. $packageCfg = GameConfig::shop_limit_getItem($packageId);
  155. my_Assert(null != $packageCfg, ErrCode::err_const_no);
  156. $arr = array();
  157. switch ((int) $packageCfg->subType) {
  158. case 1:
  159. $shopdata->purchasedDailyLimitPackages[] = $packageId;
  160. $arr = $shopdata->purchasedDailyLimitPackages;
  161. break;
  162. case 2:
  163. $shopdata->purchasedWeeklyLimitPackages[] = $packageId;
  164. $arr = $shopdata->purchasedWeeklyLimitPackages;
  165. break;
  166. case 3:
  167. $shopdata->purchasedMonthlyLimitPackages[] = $packageId;
  168. $arr = $shopdata->purchasedMonthlyLimitPackages;
  169. break;
  170. default:
  171. Err(ErrCode::err_innerfault);
  172. }
  173. $hasN = count(array_filter($arr, function ($val)use ($packageId) {
  174. return $val == $packageId;
  175. }));
  176. my_Assert($hasN <= $packageCfg->limit_num, ErrCode::shop_limit_max);
  177. $itemid = explode(',', $packageCfg->reward)[0]; # 奖励礼包Id
  178. $itemMO = GameConfig::item_package_getItem($itemid);
  179. my_Assert(null != $itemMO, ErrCode::err_const_no);
  180. $err = StoreProc::AddMultiItemInStore($itemMO->contents); # 发放奖励
  181. my_Assert(ErrCode::ok == $err, $err);
  182. req()->userInfo->game->shopdata = $shopdata; # 回写数据
  183. UserProc::updateUserInfo();
  184. $user = req()->userInfo->game;
  185. return Resp::ok(array(
  186. "reward" => $itemMO->contents,
  187. "shopdata" => $shopdata,
  188. 'gold' => $user->baseInfo->gold,
  189. 'cash' => $user->baseInfo->cash,
  190. 'tili' => $user->baseInfo->tili,
  191. 'store' => $user->store,
  192. 'hero' => $user->heros
  193. ));
  194. }
  195. /**
  196. * 每日检查
  197. */
  198. static function DailyCheck() {
  199. CLog::info("shop-每日检查-清除每日/周限量礼包购买记录");
  200. $zoneid = req()->zoneid;
  201. $uid = req()->uid;
  202. $shopdata = new Info_UserShop(req()->userInfo->game->shopdata);
  203. $shopdata->purchasedDailyLimitPackages = array(); # 每天重置
  204. if (date("N") == 1) { # 周一重置
  205. $shopdata->purchasedWeeklyLimitPackages = array();
  206. }
  207. if (date("d") == 1) { # 1号重置
  208. $shopdata->purchasedMonthlyLimitPackages = array();
  209. }
  210. if ($shopdata->monthlyVIP1_ts + 30 * 24 * 3600 > now()) {
  211. $id = 901001;
  212. $card1 = GameConfig::shop_monthVIP_getItem($id);
  213. my_Assert(null != $card1, ErrCode::err_const_no);
  214. EmailProc::SendMonthlyVIPDailyReward($zoneid, $uid, $card1->name, $card1->daily_reward);
  215. }
  216. if ($shopdata->monthlyVIP2_ts + 30 * 24 * 3600 > now()) {
  217. $id = 901002;
  218. $card2 = GameConfig::shop_monthVIP_getItem($id);
  219. my_Assert(null != $card2, ErrCode::err_const_no);
  220. EmailProc::SendMonthlyVIPDailyReward($zoneid, $uid, $card2->name, $card2->daily_reward);
  221. }
  222. }
  223. }