UserController.php
2.5 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
<?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;
}
}
}