ActiveProc.php 2.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970
  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. ctx()->privateState->day7_drawed = array();
  34. }
  35. $index = count(ctx()->privateState->LoginDays)+1;
  36. ctx()->privateState->LoginDays[] = $index;
  37. ctx()->privateState->day7_accumulate += 1;
  38. }
  39. /**
  40. * 7日签到
  41. * @return type
  42. */
  43. public static function Day7_DrawReward() {
  44. list($day) = req()->paras; # 参数: 领取第x天的奖励
  45. $user = ctx();
  46. my_Assert(in_array($day,$user->privateState->LoginDays), ErrCode::active_day7_expired);
  47. my_Assert(!in_array($day, $user->privateState->day7_drawed), ErrCode::active_hasgetted);
  48. $day_rwd = GameConfig::activity_day7_getItem($day); # 查询奖励数据
  49. my_Assert(null != $day_rwd, ErrCode::err_const_no); # 防御找不到配置
  50. StoreProc::AddMultiItemInStore($day_rwd->reward); # 发放奖励
  51. $user->privateState->day7_drawed[] = $day; # 添加领取记录
  52. ctx($user);
  53. UserProc::updateUserInfo(); # 回存
  54. return Resp::ok(array(
  55. 'gold' => $user->baseInfo->gold,
  56. 'cash' => $user->baseInfo->cash,
  57. 'tili' => $user->baseInfo->tili,
  58. 'store' => $user->store,
  59. ));
  60. }
  61. }