ActiveProc.php 3.6 KB

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