ShopProc.php 9.6 KB

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