UserController.php 2.5 KB
<?php
// +----------------------------------------------------------------------
// | bronet [ 以客户为中心 以奋斗者为本 ]
// +----------------------------------------------------------------------
// | Copyright (c) 2013-2017 http://www.bronet.cn All rights reserved.
// +----------------------------------------------------------------------
// | Licensed ( http://www.apache.org/licenses/LICENSE-2.0 )
// +----------------------------------------------------------------------
namespace app\user\controller;

use cmf\controller\WeChatBaseController;
use EasyWeChat\Foundation\Application;
use think\Db;

class UserController extends WeChatBaseController
{
    public function _initialize()
    {
        parent::_initialize();
        $this->checkWeChatUserLogin();
    }


    //个人首页
    public function userIndex(){
        $re=Db::name('users')->where(['open_id'=>session('wechat_user')['id']])->find();
        if (!$re['mobile']){
            $this->redirect(url('user/register/register2'));
        }
        $last = Db::name('users_score_log')->where(['users_id' => $re['id'], 'action' => '签到'])->max('create_time');
        if (date('Ymd', time()) > date('Ymd', $last)) {
            $is_qiandao=0;
        }else{
            $is_qiandao=1;
        }
        $data=Db::name('users')->where('id',$re['id'])->find();
        $this->assign('list',$data);
        $this->assign('qiandao',$is_qiandao);
        return $this->fetch(':person_center');
    }
    public function scoreRecord(){
        $re=$this->checkUser();
        $score=Db::name('users')->where('id',$re['id'])->find()['score'];
        $data=Db::name('users_score_log')->where('users_id',$re['id'])->order('create_time','desc')->select();
        $this->assign('score',$score);
        $this->assign('list',$data);
        return $this->fetch(':score_record');
    }
    //每日签到功能
    public  function  qiandao(){
        $re=$this->checkUser();
        $last = Db::name('users_score_log')->where(['users_id'=>$re['id'], 'action' => '签到'])->max('create_time');
        $score=Db::name('config')->where('id',1)->find()['qiandao'];
        if (date('Ymd', time()) > date('Ymd',$last)) {
            $data['score'] = $score;
            $data['users_id'] = $re['id'];
            $data['create_time'] = time();
            $data['action'] = '签到';
            Db::name('users_score_log')->insert($data);
            Db::name('users')->where('id',$re['id'])->setInc('score',$score);
            return 1;
        } else {
            return 0;
        }
    }

}