ActiveProc.php 2.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566
  1. <?php
  2. /*
  3. * To change this license header, choose License Headers in Project Properties.
  4. * To change this template file, choose Tools | Templates
  5. * and open the template in the editor.
  6. */
  7. namespace loyalsoft;
  8. /**
  9. * Description of ActiveProc
  10. *
  11. * @author c'y'zhao
  12. */
  13. class ActiveProc {
  14. /**
  15. * 逻辑分发
  16. * 所有的Proc中必须有这样一个方法
  17. * @param Req $req
  18. */
  19. public static function procMain($req) {
  20. switch ($req->cmd) {
  21. case CmdCode::active_day7_drawreward: # 6101 签到
  22. return ActiveProc::Day7_DrawReward();
  23. default:
  24. Err(ErrCode::cmd_err);
  25. }
  26. }
  27. /**
  28. * 7日签到 数据更新
  29. */
  30. public static function DailyResetDay7Task() {
  31. if(count(ctx()->privateState->LoginDays) >= 7){
  32. ctx()->privateState->LoginDays = array();
  33. }
  34. $index = count(ctx()->privateState->LoginDays)+1;
  35. ctx()->privateState->LoginDays[] = $index;
  36. }
  37. /**
  38. * 7日签到
  39. * @return type
  40. */
  41. public static function Day7_DrawReward() {
  42. list($day) = req()->paras; # 参数: 领取第x天的奖励
  43. $user = ctx();
  44. my_Assert(in_array($day,$user->privateState->LoginDays), ErrCode::active_day7_expired);
  45. my_Assert(!in_array($day, $user->privateState->day7_drawed), ErrCode::active_hasgetted);
  46. $day_rwd = GameConfig::activity_day7_getItem($day); # 查询奖励数据
  47. my_Assert(null != $day_rwd, ErrCode::err_const_no); # 防御找不到配置
  48. StoreProc::AddMultiItemInStore($day_rwd->reward); # 发放奖励
  49. $user->privateState->day7_drawed[] = $day; # 添加领取记录
  50. ctx($user);
  51. UserProc::updateUserInfo(); # 回存
  52. return Resp::ok(array(
  53. 'gold' => $user->baseInfo->gold,
  54. 'cash' => $user->baseInfo->cash,
  55. 'tili' => $user->baseInfo->tili,
  56. 'store' => $user->store,
  57. ));
  58. }
  59. }