ActiveProc.php 5.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113
  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($type,$typeId) = req()->paras; # 参数: 领取第x天的奖励
  34. $user = ctx();
  35. if($type == Enum_TaskType::Day7_Sign){
  36. my_Assert($user->privateState->day7_accumulate >= $typeId, ErrCode::active_day7_expired);
  37. my_Assert(!in_array($typeId, $user->privateState->day7_accumulateDrawed), ErrCode::active_hasgetted);
  38. $day_rwd = GameConfig::active_day7_accumulate_getItem($typeId); # 查询奖励数据
  39. my_Assert(null != $day_rwd, ErrCode::err_const_no); # 防御找不到配置
  40. StoreProc::AddMultiItemInStore($day_rwd->reward); # 发放奖励
  41. $user->privateState->day7_accumulateDrawed[] = $typeId;
  42. } elseif (Enum_TaskType::DailyTask) {
  43. my_Assert($user->task->dailyTaskAccumulate >= $typeId, ErrCode::active_day7_expired);
  44. my_Assert(!in_array($typeId, $user->task->dailyTaskAccumulateDrawed), ErrCode::active_hasgetted);
  45. $day_rwd = GameConfig::task_accumulate_daily_getItem($typeId); # 查询奖励数据
  46. my_Assert(null != $day_rwd, ErrCode::err_const_no); # 防御找不到配置
  47. StoreProc::AddMultiItemInStore($day_rwd->reward); # 发放奖励
  48. $user->task->dailyTaskAccumulateDrawed[] = $typeId;
  49. } elseif (Enum_TaskType::WeekTask) {
  50. my_Assert($user->task->weekTaskAccumulate >= $typeId, ErrCode::active_day7_expired);
  51. my_Assert(!in_array($typeId, $user->task->weekTaskAccumulateDrawed), ErrCode::active_hasgetted);
  52. $day_rwd = GameConfig::task_accumulate_week_getItem($typeId); # 查询奖励数据
  53. my_Assert(null != $day_rwd, ErrCode::err_const_no); # 防御找不到配置
  54. StoreProc::AddMultiItemInStore($day_rwd->reward); # 发放奖励
  55. $user->task->weekTaskAccumulateDrawed[] = $typeId;
  56. }
  57. ctx($user);
  58. UserProc::updateUserInfo(); # 回存
  59. return Resp::ok(array(
  60. 'gold' => $user->baseInfo->gold,
  61. 'cash' => $user->baseInfo->cash,
  62. 'tili' => $user->baseInfo->tili,
  63. 'store' => $user->store,
  64. ));
  65. }
  66. /**
  67. * 7日签到 数据更新
  68. */
  69. public static function DailyResetDay7Task() {
  70. if(count(ctx()->privateState->LoginDays) >= 7){
  71. ctx()->privateState->LoginDays = array();
  72. ctx()->privateState->day7_drawed = array();
  73. }
  74. $index = count(ctx()->privateState->LoginDays)+1;
  75. ctx()->privateState->LoginDays[] = $index;
  76. ctx()->privateState->day7_accumulate += 1;
  77. }
  78. /**
  79. * 7日签到
  80. * @return type
  81. */
  82. public static function Day7_DrawReward() {
  83. list($day) = req()->paras; # 参数: 领取第x天的奖励
  84. $user = ctx();
  85. my_Assert(in_array($day,$user->privateState->LoginDays), ErrCode::active_day7_expired);
  86. my_Assert(!in_array($day, $user->privateState->day7_drawed), ErrCode::active_hasgetted);
  87. $day_rwd = GameConfig::activity_day7_getItem($day); # 查询奖励数据
  88. my_Assert(null != $day_rwd, ErrCode::err_const_no); # 防御找不到配置
  89. StoreProc::AddMultiItemInStore($day_rwd->reward); # 发放奖励
  90. $user->privateState->day7_drawed[] = $day; # 添加领取记录
  91. ctx($user);
  92. UserProc::updateUserInfo(); # 回存
  93. return Resp::ok(array(
  94. 'gold' => $user->baseInfo->gold,
  95. 'cash' => $user->baseInfo->cash,
  96. 'tili' => $user->baseInfo->tili,
  97. 'store' => $user->store,
  98. ));
  99. }
  100. }