Memberpoints.php 8.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185
  1. <?php
  2. namespace app\api\controller;
  3. use think\facade\Lang;
  4. /**
  5. * ============================================================================
  6. *
  7. * ============================================================================
  8. * 版权所有 2014-2028 浙江惠利玛产业互联网有限公司,并保留所有权利。
  9. * 网站地址: https://www.valimart.net/
  10. * ----------------------------------------------------------------------------
  11. *
  12. * ============================================================================
  13. * 积分记录控制器
  14. */
  15. class Memberpoints extends MobileMember {
  16. public function initialize() {
  17. parent::initialize(); // TODO: Change the autogenerated stub
  18. Lang::load(base_path() . 'home/lang/' . config('lang.default_lang') . '/memberpoints.lang.php');
  19. }
  20. /**
  21. * @api {POST} api/Memberpoints/pointslog 签到列表
  22. * @apiVersion 1.0.0
  23. * @apiGroup MemberPoints
  24. *
  25. * @apiHeader {String} X-DS-KEY 用户授权token
  26. *
  27. * @apiParam {Int} page 页码
  28. * @apiParam {Int} per_page 每页数量
  29. *
  30. * @apiSuccess {String} code 返回码,10000为成功
  31. * @apiSuccess {String} message 返回消息
  32. * @apiSuccess {Object} result 返回数据
  33. * @apiSuccess {Object[]} result.log_list 积分记录列表
  34. * @apiSuccess {String} result.log_list.addtimetext 添加时间描述
  35. * @apiSuccess {Int} result.log_list.pl_addtime 添加时间
  36. * @apiSuccess {Int} result.log_list.pl_adminid 管理员ID
  37. * @apiSuccess {String} result.log_list.pl_adminname 管理员名称
  38. * @apiSuccess {String} result.log_list.pl_desc 积分记录描述
  39. * @apiSuccess {Int} result.log_list.pl_id 积分记录ID
  40. * @apiSuccess {Int} result.log_list.pl_memberid 用户ID
  41. * @apiSuccess {String} result.log_list.pl_membername 用户名称
  42. * @apiSuccess {Int} result.log_list.pl_points 积分
  43. * @apiSuccess {String} result.log_list.pl_stage 积分操作阶段
  44. * @apiSuccess {String} result.log_list.stagetext 积分操作阶段描述
  45. * @apiSuccess {Int} result.page_total 总页数
  46. * @apiSuccess {Boolean} result.hasmore 是否有更多 true是false否
  47. */
  48. public function pointslog() {
  49. $condition = $list_log = array();
  50. $condition[] = array('pl_memberid','=',$this->member_info['member_id']);
  51. //分页
  52. $points_model = model('points');
  53. $list_log = $points_model->getPointslogList($condition, $this->pagesize, '*', '');
  54. if (!empty($list_log)) {
  55. foreach ($list_log as $key => $value) {
  56. $list_log[$key]['stagetext'] = lang('points_stage_'.$value['pl_stage']);
  57. $list_log[$key]['addtimetext'] = date('Y-m-d H:i:s', $value['pl_addtime']);
  58. }
  59. }
  60. $result = array_merge(array('log_list' => $list_log), mobile_page($points_model->page_info));
  61. ds_json_encode(10000, '', $result);
  62. }
  63. /**
  64. * @api {POST} api/Memberpoints/points_signin 签到页面
  65. * @apiVersion 1.0.0
  66. * @apiGroup MemberPoints
  67. *
  68. * @apiHeader {String} X-DS-KEY 用户授权token
  69. *
  70. * @apiParam {String} search_day 查询日期(YYYY-MM-DD)
  71. *
  72. * @apiSuccess {String} code 返回码,10000为成功
  73. * @apiSuccess {String} message 返回消息
  74. * @apiSuccess {Object} result 返回数据
  75. * @apiSuccess {Object[]} result.day_list 日历列表
  76. * @apiSuccess {Int} result.day_list.state 签到状态 (0未签到1已签到)
  77. * @apiSuccess {Int} result.day_list.num 日期数字
  78. * @apiSuccess {Int} result.day_list.week 星期
  79. * @apiSuccess {String} result.day_list.day 日期
  80. * @apiSuccess {Int} result.time 搜索时间(unix时间戳)
  81. * @apiSuccess {Boolean} result.if_signin 是否已签到
  82. */
  83. public function points_signin() {
  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. if (!intval(config('ds_config.points_signin_isuse'))) {
  139. ds_json_encode(10001, lang('签到已关闭'));
  140. }
  141. $today = date("Y-m-d");
  142. $today_time = strtotime($today);
  143. $points_model = model('points');
  144. $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])));
  145. if ($if_signin) {
  146. ds_json_encode(10001, lang('signin_repeat'));
  147. }
  148. $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])));
  149. $points_signin = intval(config('ds_config.points_signin')); //签到对得积分数
  150. $points_signin_cycle = intval(config('ds_config.points_signin_cycle'));
  151. $points_signin_reward = intval(config('ds_config.points_signin_reward'));
  152. $edit_member = array(
  153. 'member_signin_time' => TIMESTAMP,
  154. 'member_signin_days_cycle' => (($if_signin_series ? $this->member_info['member_signin_days_cycle'] : 0) + 1) % $points_signin_cycle,
  155. 'member_signin_days_total' => $this->member_info['member_signin_days_total'] + 1,
  156. 'member_signin_days_series' => ($if_signin_series ? $this->member_info['member_signin_days_series'] : 0) + 1,
  157. );
  158. if ($points_signin_cycle && $points_signin_reward) {
  159. if ($edit_member['member_signin_days_cycle'] == 0) {
  160. $points_signin += $points_signin_reward;
  161. }
  162. }
  163. $insertarr['pl_memberid'] = $this->member_info['member_id'];
  164. $insertarr['pl_membername'] = $this->member_info['member_name'];
  165. $insertarr['pl_points'] = $points_signin;
  166. $return = $points_model->savePointslog('signin', $insertarr);
  167. if ($return) {
  168. model('member')->editMember(array('member_id' => $this->member_info['member_id']), $edit_member,$this->member_info['member_id']);
  169. }
  170. ds_json_encode(10000, lang('signin_success') . $points_signin, array('member_signin_info' => $edit_member));
  171. }
  172. }