123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188 |
- <?php
- namespace app\api\controller;
- use think\facade\Lang;
- class Memberpoints extends MobileMember
- {
- public function initialize()
- {
- parent::initialize();
- Lang::load(base_path() . 'home/lang/' . config('lang.default_lang') . '/memberpoints.lang.php');
- }
-
- public function pointslog()
- {
- $condition = $list_log = array();
- $condition[] = array('pl_memberid', '=', $this->member_info['member_id']);
-
- $points_model = model('points');
- $list_log = $points_model->getPointslogList($condition, $this->pagesize, '*', '');
- if (!empty($list_log)) {
- foreach ($list_log as $key => $value) {
- $list_log[$key]['stagetext'] = lang('points_stage_' . $value['pl_stage']);
- $list_log[$key]['addtimetext'] = date('Y-m-d H:i:s', $value['pl_addtime']);
- }
- }
- $result = array_merge(array('log_list' => $list_log), mobile_page($points_model->page_info));
- ds_json_encode(10000, '', $result);
- }
-
- public function points_signin()
- {
- $search_day = input('param.search_day');
- $today = date("Y-m-d");
- $today_time = strtotime($today);
- if (!$search_day) {
- $search_day = $today;
- }
- $search_time = strtotime($search_day);
- if (!$search_time) {
- ds_json_encode(10001, lang('param_error'));
- }
-
- $start_day = date('Y-m-01', $search_time);
-
- $end_time = strtotime("$start_day +1 month -1 day") + 86399;
- $start_time = strtotime($start_day);
-
- $points_model = model('points');
- $condition_arr = array();
- $condition_arr[] = array('pl_memberid', '=', $this->member_info['member_id']);
- $condition_arr[] = array('pl_addtime', 'between', [$start_time, $end_time]);
- $condition_arr[] = array('pl_stage', '=', 'signin');
- $signin_list = $points_model->getPointslogList($condition_arr);
- $day_list = array();
- for ($i = 1; $i <= intval(date('d', $end_time)); $i++) {
- $time = $start_time + ($i - 1) * 86400;
- $day = date('Y-m-d', $time);
- $day_list[] = array('state' => 0, 'num' => $i, 'week' => intval(date("w", $time)), 'day' => $day);
- }
- foreach ($signin_list as $item) {
- $day = intval(date('d', $item['pl_addtime']));
- $day_list[$day - 1]['state'] = 1;
- }
- $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])));
- ds_json_encode(10000, '', array('day_list' => $day_list, 'time' => $search_time, 'if_signin' => $if_signin ? true : false));
- }
-
- public function signin_add()
- {
- if (!intval(config('ds_config.points_signin_isuse'))) {
- ds_json_encode(10001, lang('签到已关闭'));
- }
- $today = date("Y-m-d");
- $today_time = strtotime($today);
- $points_model = model('points');
- $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])));
- if ($if_signin) {
- ds_json_encode(10001, lang('signin_repeat'));
- }
- $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])));
- $points_signin = intval(config('ds_config.points_signin'));
- $points_signin_cycle = intval(config('ds_config.points_signin_cycle'));
- $points_signin_reward = intval(config('ds_config.points_signin_reward'));
- $edit_member = array(
- 'member_signin_time' => TIMESTAMP,
- 'member_signin_days_cycle' => (($if_signin_series ? $this->member_info['member_signin_days_cycle'] : 0) + 1) % $points_signin_cycle,
- 'member_signin_days_total' => $this->member_info['member_signin_days_total'] + 1,
- 'member_signin_days_series' => ($if_signin_series ? $this->member_info['member_signin_days_series'] : 0) + 1,
- );
- if ($points_signin_cycle && $points_signin_reward) {
- if ($edit_member['member_signin_days_cycle'] == 0) {
- $points_signin += $points_signin_reward;
- }
- }
- $insertarr['pl_memberid'] = $this->member_info['member_id'];
- $insertarr['pl_membername'] = $this->member_info['member_name'];
- $insertarr['pl_points'] = $points_signin;
- $return = $points_model->savePointslog('signin', $insertarr);
- if ($return) {
- model('member')->editMember(array('member_id' => $this->member_info['member_id']), $edit_member, $this->member_info['member_id']);
- }
- ds_json_encode(10000, lang('signin_success') . $points_signin, array('member_signin_info' => $edit_member));
- }
- }
|