Memberpoints.php 8.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188
  1. <?php
  2. namespace app\api\controller;
  3. use think\facade\Lang;
  4. /**
  5. *
  6. *
  7. * ----------------------------------------------------------------------------
  8. *
  9. * 积分记录控制器
  10. */
  11. class Memberpoints extends MobileMember
  12. {
  13. public function initialize()
  14. {
  15. parent::initialize(); // TODO: Change the autogenerated stub
  16. Lang::load(base_path() . 'home/lang/' . config('lang.default_lang') . '/memberpoints.lang.php');
  17. }
  18. /**
  19. * @api {POST} api/Memberpoints/pointslog 签到列表
  20. * @apiVersion 1.0.0
  21. * @apiGroup MemberPoints
  22. *
  23. * @apiHeader {String} X-DS-KEY 用户授权token
  24. *
  25. * @apiParam {Int} page 页码
  26. * @apiParam {Int} per_page 每页数量
  27. *
  28. * @apiSuccess {String} code 返回码,10000为成功
  29. * @apiSuccess {String} message 返回消息
  30. * @apiSuccess {Object} result 返回数据
  31. * @apiSuccess {Object[]} result.log_list 积分记录列表
  32. * @apiSuccess {String} result.log_list.addtimetext 添加时间描述
  33. * @apiSuccess {Int} result.log_list.pl_addtime 添加时间
  34. * @apiSuccess {Int} result.log_list.pl_adminid 管理员ID
  35. * @apiSuccess {String} result.log_list.pl_adminname 管理员名称
  36. * @apiSuccess {String} result.log_list.pl_desc 积分记录描述
  37. * @apiSuccess {Int} result.log_list.pl_id 积分记录ID
  38. * @apiSuccess {Int} result.log_list.pl_memberid 用户ID
  39. * @apiSuccess {String} result.log_list.pl_membername 用户名称
  40. * @apiSuccess {Int} result.log_list.pl_points 积分
  41. * @apiSuccess {String} result.log_list.pl_stage 积分操作阶段
  42. * @apiSuccess {String} result.log_list.stagetext 积分操作阶段描述
  43. * @apiSuccess {Int} result.page_total 总页数
  44. * @apiSuccess {Boolean} result.hasmore 是否有更多 true是false否
  45. */
  46. public function pointslog()
  47. {
  48. $condition = $list_log = array();
  49. $condition[] = array('pl_memberid', '=', $this->member_info['member_id']);
  50. //分页
  51. $points_model = model('points');
  52. $list_log = $points_model->getPointslogList($condition, $this->pagesize, '*', '');
  53. if (!empty($list_log)) {
  54. foreach ($list_log as $key => $value) {
  55. $list_log[$key]['stagetext'] = lang('points_stage_' . $value['pl_stage']);
  56. $list_log[$key]['addtimetext'] = date('Y-m-d H:i:s', $value['pl_addtime']);
  57. }
  58. }
  59. $result = array_merge(array('log_list' => $list_log), mobile_page($points_model->page_info));
  60. ds_json_encode(10000, '', $result);
  61. }
  62. /**
  63. * @api {POST} api/Memberpoints/points_signin 签到页面
  64. * @apiVersion 1.0.0
  65. * @apiGroup MemberPoints
  66. *
  67. * @apiHeader {String} X-DS-KEY 用户授权token
  68. *
  69. * @apiParam {String} search_day 查询日期(YYYY-MM-DD)
  70. *
  71. * @apiSuccess {String} code 返回码,10000为成功
  72. * @apiSuccess {String} message 返回消息
  73. * @apiSuccess {Object} result 返回数据
  74. * @apiSuccess {Object[]} result.day_list 日历列表
  75. * @apiSuccess {Int} result.day_list.state 签到状态 (0未签到1已签到)
  76. * @apiSuccess {Int} result.day_list.num 日期数字
  77. * @apiSuccess {Int} result.day_list.week 星期
  78. * @apiSuccess {String} result.day_list.day 日期
  79. * @apiSuccess {Int} result.time 搜索时间(unix时间戳)
  80. * @apiSuccess {Boolean} result.if_signin 是否已签到
  81. */
  82. public function points_signin()
  83. {
  84. $search_day = input('param.search_day');
  85. $today = date("Y-m-d");
  86. $today_time = strtotime($today);
  87. if (!$search_day) {
  88. $search_day = $today;
  89. }
  90. $search_time = strtotime($search_day);
  91. if (!$search_time) {
  92. ds_json_encode(10001, lang('param_error'));
  93. }
  94. //这个月的第一天
  95. $start_day = date('Y-m-01', $search_time);
  96. //这个月的最后一天
  97. $end_time = strtotime("$start_day +1 month -1 day") + 86399;
  98. $start_time = strtotime($start_day);
  99. //从签到记录中已签到的日期
  100. $points_model = model('points');
  101. $condition_arr = array();
  102. $condition_arr[] = array('pl_memberid', '=', $this->member_info['member_id']);
  103. $condition_arr[] = array('pl_addtime', 'between', [$start_time, $end_time]);
  104. $condition_arr[] = array('pl_stage', '=', 'signin');
  105. $signin_list = $points_model->getPointslogList($condition_arr);
  106. $day_list = array();
  107. for ($i = 1; $i <= intval(date('d', $end_time)); $i++) {
  108. $time = $start_time + ($i - 1) * 86400;
  109. $day = date('Y-m-d', $time);
  110. $day_list[] = array('state' => 0, 'num' => $i, 'week' => intval(date("w", $time)), 'day' => $day);
  111. }
  112. foreach ($signin_list as $item) {
  113. $day = intval(date('d', $item['pl_addtime']));
  114. $day_list[$day - 1]['state'] = 1;
  115. }
  116. $if_signin = $points_model->getPointsInfo(array(array('pl_memberid', '=', $this->member_info['member_id']), array('pl_stage', '=', 'signin'), array('pl_addtime', 'between', [$today_time, $today_time + 86399])));
  117. ds_json_encode(10000, '', array('day_list' => $day_list, 'time' => $search_time, 'if_signin' => $if_signin ? true : false));
  118. }
  119. /**
  120. * @api {POST} api/Memberpoints/signin_add 签到
  121. * @apiVersion 1.0.0
  122. * @apiGroup MemberPoints
  123. *
  124. * @apiHeader {String} X-DS-KEY 用户授权token
  125. *
  126. * @apiParam {String} search_day 查询日期(YYYY-MM-DD)
  127. *
  128. * @apiSuccess {String} code 返回码,10000为成功
  129. * @apiSuccess {String} message 返回消息
  130. * @apiSuccess {Object} result 返回数据
  131. * @apiSuccess {Object} result.member_signin_info 用户签到信息
  132. * @apiSuccess {Int} result.member_signin_info.member_signin_time 签到时间 (Unix时间戳)
  133. * @apiSuccess {Int} result.member_signin_info.member_signin_days_cycle 签到连续次数(每过一个周期清零)
  134. * @apiSuccess {Int} result.member_signin_info.member_signin_days_total 签到总次数
  135. * @apiSuccess {Int} result.member_signin_info.member_signin_days_series 签到连续次数
  136. */
  137. public function signin_add()
  138. {
  139. if (!intval(config('ds_config.points_signin_isuse'))) {
  140. ds_json_encode(10001, lang('签到已关闭'));
  141. }
  142. $today = date("Y-m-d");
  143. $today_time = strtotime($today);
  144. $points_model = model('points');
  145. $if_signin = $points_model->getPointsInfo(array(array('pl_memberid', '=', $this->member_info['member_id']), array('pl_stage', '=', 'signin'), array('pl_addtime', 'between', [$today_time, $today_time + 86399])));
  146. if ($if_signin) {
  147. ds_json_encode(10001, lang('signin_repeat'));
  148. }
  149. $if_signin_series = $points_model->getPointsInfo(array(array('pl_memberid', '=', $this->member_info['member_id']), array('pl_stage', '=', 'signin'), array('pl_addtime', 'between', [$today_time - 86400, $today_time - 1])));
  150. $points_signin = intval(config('ds_config.points_signin')); //签到对得积分数
  151. $points_signin_cycle = intval(config('ds_config.points_signin_cycle'));
  152. $points_signin_reward = intval(config('ds_config.points_signin_reward'));
  153. $edit_member = array(
  154. 'member_signin_time' => TIMESTAMP,
  155. 'member_signin_days_cycle' => (($if_signin_series ? $this->member_info['member_signin_days_cycle'] : 0) + 1) % $points_signin_cycle,
  156. 'member_signin_days_total' => $this->member_info['member_signin_days_total'] + 1,
  157. 'member_signin_days_series' => ($if_signin_series ? $this->member_info['member_signin_days_series'] : 0) + 1,
  158. );
  159. if ($points_signin_cycle && $points_signin_reward) {
  160. if ($edit_member['member_signin_days_cycle'] == 0) {
  161. $points_signin += $points_signin_reward;
  162. }
  163. }
  164. $insertarr['pl_memberid'] = $this->member_info['member_id'];
  165. $insertarr['pl_membername'] = $this->member_info['member_name'];
  166. $insertarr['pl_points'] = $points_signin;
  167. $return = $points_model->savePointslog('signin', $insertarr);
  168. if ($return) {
  169. model('member')->editMember(array('member_id' => $this->member_info['member_id']), $edit_member, $this->member_info['member_id']);
  170. }
  171. ds_json_encode(10000, lang('signin_success') . $points_signin, array('member_signin_info' => $edit_member));
  172. }
  173. }