Memberpoints.php 9.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186
  1. <?php
  2. namespace app\api\controller;
  3. use think\facade\Lang;
  4. /**
  5. * ============================================================================
  6. * DSMall多用户商城
  7. * ============================================================================
  8. * 版权所有 2014-2028 长沙德尚网络科技有限公司,并保留所有权利。
  9. * 网站地址: http://www.csdeshang.com
  10. * ----------------------------------------------------------------------------
  11. * 这不是一个自由软件!您只能在不用于商业目的的前提下对程序代码进行修改和使用 .
  12. * 不允许对程序代码以任何形式任何目的的再发布。
  13. * ============================================================================
  14. * 积分记录控制器
  15. */
  16. class Memberpoints extends MobileMember {
  17. public function initialize() {
  18. parent::initialize(); // TODO: Change the autogenerated stub
  19. Lang::load(base_path() . 'home/lang/' . config('lang.default_lang') . '/memberpoints.lang.php');
  20. }
  21. /**
  22. * @api {POST} api/Memberpoints/pointslog 签到列表
  23. * @apiVersion 1.0.0
  24. * @apiGroup MemberPoints
  25. *
  26. * @apiHeader {String} X-DS-KEY 用户授权token
  27. *
  28. * @apiParam {Int} page 页码
  29. * @apiParam {Int} per_page 每页数量
  30. *
  31. * @apiSuccess {String} code 返回码,10000为成功
  32. * @apiSuccess {String} message 返回消息
  33. * @apiSuccess {Object} result 返回数据
  34. * @apiSuccess {Object[]} result.log_list 积分记录列表
  35. * @apiSuccess {String} result.log_list.addtimetext 添加时间描述
  36. * @apiSuccess {Int} result.log_list.pl_addtime 添加时间
  37. * @apiSuccess {Int} result.log_list.pl_adminid 管理员ID
  38. * @apiSuccess {String} result.log_list.pl_adminname 管理员名称
  39. * @apiSuccess {String} result.log_list.pl_desc 积分记录描述
  40. * @apiSuccess {Int} result.log_list.pl_id 积分记录ID
  41. * @apiSuccess {Int} result.log_list.pl_memberid 用户ID
  42. * @apiSuccess {String} result.log_list.pl_membername 用户名称
  43. * @apiSuccess {Int} result.log_list.pl_points 积分
  44. * @apiSuccess {String} result.log_list.pl_stage 积分操作阶段
  45. * @apiSuccess {String} result.log_list.stagetext 积分操作阶段描述
  46. * @apiSuccess {Int} result.page_total 总页数
  47. * @apiSuccess {Boolean} result.hasmore 是否有更多 true是false否
  48. */
  49. public function pointslog() {
  50. $condition = $list_log = array();
  51. $condition[] = array('pl_memberid','=',$this->member_info['member_id']);
  52. //分页
  53. $points_model = model('points');
  54. $list_log = $points_model->getPointslogList($condition, $this->pagesize, '*', '');
  55. if (!empty($list_log)) {
  56. foreach ($list_log as $key => $value) {
  57. $list_log[$key]['stagetext'] = lang('points_stage_'.$value['pl_stage']);
  58. $list_log[$key]['addtimetext'] = date('Y-m-d H:i:s', $value['pl_addtime']);
  59. }
  60. }
  61. $result = array_merge(array('log_list' => $list_log), mobile_page($points_model->page_info));
  62. ds_json_encode(10000, '', $result);
  63. }
  64. /**
  65. * @api {POST} api/Memberpoints/points_signin 签到页面
  66. * @apiVersion 1.0.0
  67. * @apiGroup MemberPoints
  68. *
  69. * @apiHeader {String} X-DS-KEY 用户授权token
  70. *
  71. * @apiParam {String} search_day 查询日期(YYYY-MM-DD)
  72. *
  73. * @apiSuccess {String} code 返回码,10000为成功
  74. * @apiSuccess {String} message 返回消息
  75. * @apiSuccess {Object} result 返回数据
  76. * @apiSuccess {Object[]} result.day_list 日历列表
  77. * @apiSuccess {Int} result.day_list.state 签到状态 (0未签到1已签到)
  78. * @apiSuccess {Int} result.day_list.num 日期数字
  79. * @apiSuccess {Int} result.day_list.week 星期
  80. * @apiSuccess {String} result.day_list.day 日期
  81. * @apiSuccess {Int} result.time 搜索时间(unix时间戳)
  82. * @apiSuccess {Boolean} result.if_signin 是否已签到
  83. */
  84. public function points_signin() {
  85. $search_day = input('param.search_day');
  86. $today = date("Y-m-d");
  87. $today_time = strtotime($today);
  88. if (!$search_day) {
  89. $search_day = $today;
  90. }
  91. $search_time = strtotime($search_day);
  92. if (!$search_time) {
  93. ds_json_encode(10001, lang('param_error'));
  94. }
  95. //这个月的第一天
  96. $start_day = date('Y-m-01', $search_time);
  97. //这个月的最后一天
  98. $end_time = strtotime("$start_day +1 month -1 day") + 86399;
  99. $start_time = strtotime($start_day);
  100. //从签到记录中已签到的日期
  101. $points_model = model('points');
  102. $condition_arr = array();
  103. $condition_arr[] = array('pl_memberid', '=', $this->member_info['member_id']);
  104. $condition_arr[] = array('pl_addtime', 'between', [$start_time, $end_time]);
  105. $condition_arr[] = array('pl_stage', '=', 'signin');
  106. $signin_list = $points_model->getPointslogList($condition_arr);
  107. $day_list = array();
  108. for ($i = 1; $i <= intval(date('d', $end_time)); $i++) {
  109. $time = $start_time + ($i - 1) * 86400;
  110. $day = date('Y-m-d', $time);
  111. $day_list[] = array('state' => 0, 'num' => $i, 'week' => intval(date("w", $time)), 'day' => $day);
  112. }
  113. foreach ($signin_list as $item) {
  114. $day = intval(date('d', $item['pl_addtime']));
  115. $day_list[$day - 1]['state'] = 1;
  116. }
  117. $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])));
  118. ds_json_encode(10000, '', array('day_list' => $day_list, 'time' => $search_time, 'if_signin' => $if_signin ? true : false));
  119. }
  120. /**
  121. * @api {POST} api/Memberpoints/signin_add 签到
  122. * @apiVersion 1.0.0
  123. * @apiGroup MemberPoints
  124. *
  125. * @apiHeader {String} X-DS-KEY 用户授权token
  126. *
  127. * @apiParam {String} search_day 查询日期(YYYY-MM-DD)
  128. *
  129. * @apiSuccess {String} code 返回码,10000为成功
  130. * @apiSuccess {String} message 返回消息
  131. * @apiSuccess {Object} result 返回数据
  132. * @apiSuccess {Object} result.member_signin_info 用户签到信息
  133. * @apiSuccess {Int} result.member_signin_info.member_signin_time 签到时间 (Unix时间戳)
  134. * @apiSuccess {Int} result.member_signin_info.member_signin_days_cycle 签到连续次数(每过一个周期清零)
  135. * @apiSuccess {Int} result.member_signin_info.member_signin_days_total 签到总次数
  136. * @apiSuccess {Int} result.member_signin_info.member_signin_days_series 签到连续次数
  137. */
  138. public function signin_add() {
  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. }