Config.php 5.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126
  1. <?php
  2. /**
  3. * Niushop商城系统 - 团队十年电商经验汇集巨献!
  4. * =========================================================
  5. * Copy right 2019-2029 杭州牛之云科技有限公司, 保留所有权利。
  6. * ----------------------------------------------
  7. * 官方网址: https://www.niushop.com
  8. * =========================================================
  9. */
  10. namespace addon\birthdaygift\api\controller;
  11. use app\api\controller\BaseApi;
  12. use addon\birthdaygift\model\BirthdayGift;
  13. use app\model\member\Member;
  14. /**
  15. * 会员生日奖励
  16. */
  17. class Config extends BaseApi
  18. {
  19. /**
  20. * 计算信息
  21. */
  22. public function config()
  23. {
  24. $token = $this->checkToken();
  25. if ($token[ 'code' ] < 0) return $this->response($token);
  26. //获取生日有礼信息
  27. $gift_model = new BirthdayGift();
  28. $info = $gift_model->getAward($this->site_id);
  29. $flag = false;
  30. if (!empty($info[ 'data' ])) {
  31. //获取会员信息
  32. $member_model = new Member();
  33. if (empty($info[ 'data' ][ 'level_id' ])) {//所有会员
  34. $member_info = $member_model->getMemberInfo([ [ 'member_id', '=', $this->member_id ], [ 'site_id', '=', $this->site_id ] ], 'member_id,nickname,member_level,member_level_name,birthday,reg_time');
  35. $member_info = $member_info[ 'data' ];
  36. } else {
  37. $member_info = $member_model->getMemberInfo([ [ 'member_id', '=', $this->member_id ], [ 'site_id', '=', $this->site_id ], [ 'member_level', 'in', $info[ 'data' ][ 'level_id' ] ] ], 'member_id,nickname,member_level,member_level_name,birthday,reg_time');
  38. $member_info = $member_info[ 'data' ];
  39. }
  40. if (!empty($member_info)) {
  41. // 判断今年有没有领取过
  42. $start_year = date_to_time(date('Y-01-01 00:00:00'));
  43. $end_year = $start_year + 31535999;
  44. $record_condition[] = [ 'member_id', '=', $this->member_id ];
  45. $record_condition[] = [ 'receive_time', '>', $start_year ];
  46. $record_condition[] = [ 'receive_time', '<', $end_year ];
  47. $recode = $gift_model->getRecordList($record_condition);
  48. if (empty($recode[ 'data' ])) {
  49. $today = date('Y-m-d', time());
  50. //以上条件都满足 判断奖励时间 (1生日当天 2生日当周 3生日当月)
  51. if ($info[ 'data' ][ 'activity_time_type' ] == 1) {
  52. $birthday = date('m-d', $member_info[ 'birthday' ]);
  53. if (date('m-d') == $birthday) {
  54. $flag = true;
  55. }
  56. } else if ($info[ 'data' ][ 'activity_time_type' ] == 2) {
  57. // 把会员的生日转换为当前的年份
  58. $birth_month_and_day = date('m-d', $member_info[ 'birthday' ]);
  59. $now_birthday = date('Y', time());
  60. $now_birthday_year_month_day = $now_birthday . '-' . $birth_month_and_day;
  61. $member_birthday_time = date_to_time($now_birthday_year_month_day);
  62. $end_time = date_to_time("$today sunday");
  63. $end_time_date = date('Y-m-d', $end_time);
  64. $begin_time = date_to_time("$end_time_date -6 days");
  65. if ($begin_time <= $member_birthday_time && $member_birthday_time <= $end_time) {
  66. $flag = true;
  67. }
  68. } else if ($info[ 'data' ][ 'activity_time_type' ] == 3) {
  69. $birthday = date('m', $member_info[ 'birthday' ]);
  70. if (date('m') == $birthday) {
  71. $flag = true;
  72. }
  73. }
  74. $info[ 'data' ][ 'nickname' ] = $member_info[ 'nickname' ];
  75. }
  76. }
  77. }
  78. $info[ 'data' ][ 'flag' ] = $flag;
  79. if (!empty($info[ 'data' ][ 'coupon_list' ])) {
  80. foreach ($info[ 'data' ][ 'coupon_list' ] as $kk => $vv) {
  81. $coupon_flag = false;
  82. if ($vv[ 'status' ] == 1) {
  83. if ($vv[ 'count' ] == -1 || $vv[ 'count' ] - $vv[ 'lead_count' ] > 0) $coupon_flag = true;
  84. }
  85. $info[ 'data' ][ 'coupon_list' ][ $kk ][ 'coupon_flag' ] = $coupon_flag;
  86. }
  87. } else {
  88. $info[ 'data' ][ 'coupon_list' ] = [];
  89. }
  90. return $this->response($info);
  91. }
  92. /**
  93. * 领取生日奖励
  94. */
  95. public function receive()
  96. {
  97. $token = $this->checkToken();
  98. if ($token[ 'code' ] < 0) return $this->response($token);
  99. $activity_id = $this->params[ 'id' ];
  100. if (empty($activity_id)) {
  101. return $this->response($this->error('', 'REQUEST_ID'));
  102. }
  103. $gift_model = new BirthdayGift();
  104. $res = $gift_model->receive($this->member_id, $activity_id, $this->site_id);
  105. return $this->response($res);
  106. }
  107. /**
  108. * 查询领取记录
  109. */
  110. public function getRecord()
  111. {
  112. $token = $this->checkToken();
  113. $gift_model = new BirthdayGift();
  114. $res = $gift_model->verificationRecord($this->member_id);
  115. return $this->response($res);
  116. }
  117. }