ActiveProc.php 3.7 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495
  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. case CmdCode::active_day7_accumulateDrawreward: # 6102 7日累充
  24. return ActiveProc::Day7__accumulateDrawreward();
  25. default:
  26. Err(ErrCode::cmd_err);
  27. }
  28. }
  29. /**
  30. * 7日累充领奖
  31. */
  32. public static function Day7__accumulateDrawreward() {
  33. list($typeId) = req()->paras; # 参数: 领取第x天的奖励
  34. $user = ctx();
  35. my_Assert($user->privateState->day7_accumulate >= $typeId, ErrCode::active_day7_expired);
  36. my_Assert(!in_array($typeId, $user->privateState->day7_accumulateDrawed), ErrCode::active_hasgetted);
  37. $day_rwd = GameConfig::active_day7_accumulate_getItem($typeId); # 查询奖励数据
  38. my_Assert(null != $day_rwd, ErrCode::err_const_no); # 防御找不到配置
  39. StoreProc::AddMultiItemInStore($day_rwd->reward); # 发放奖励
  40. $user->privateState->day7_accumulateDrawed[] = $typeId;
  41. ctx($user);
  42. UserProc::updateUserInfo(); # 回存
  43. return Resp::ok(array(
  44. 'gold' => $user->baseInfo->gold,
  45. 'cash' => $user->baseInfo->cash,
  46. 'tili' => $user->baseInfo->tili,
  47. 'store' => $user->store,
  48. ));
  49. }
  50. /**
  51. * 7日签到 数据更新
  52. */
  53. public static function DailyResetDay7Task() {
  54. if(count(ctx()->privateState->LoginDays) >= 7){
  55. ctx()->privateState->LoginDays = array();
  56. ctx()->privateState->day7_drawed = array();
  57. }
  58. $index = count(ctx()->privateState->LoginDays)+1;
  59. ctx()->privateState->LoginDays[] = $index;
  60. ctx()->privateState->day7_accumulate += 1;
  61. }
  62. /**
  63. * 7日签到
  64. * @return type
  65. */
  66. public static function Day7_DrawReward() {
  67. list($day) = req()->paras; # 参数: 领取第x天的奖励
  68. $user = ctx();
  69. my_Assert(in_array($day,$user->privateState->LoginDays), ErrCode::active_day7_expired);
  70. my_Assert(!in_array($day, $user->privateState->day7_drawed), ErrCode::active_hasgetted);
  71. $day_rwd = GameConfig::activity_day7_getItem($day); # 查询奖励数据
  72. my_Assert(null != $day_rwd, ErrCode::err_const_no); # 防御找不到配置
  73. StoreProc::AddMultiItemInStore($day_rwd->reward); # 发放奖励
  74. $user->privateState->day7_drawed[] = $day; # 添加领取记录
  75. ctx($user);
  76. UserProc::updateUserInfo(); # 回存
  77. return Resp::ok(array(
  78. 'gold' => $user->baseInfo->gold,
  79. 'cash' => $user->baseInfo->cash,
  80. 'tili' => $user->baseInfo->tili,
  81. 'store' => $user->store,
  82. ));
  83. }
  84. }