ActiveController.php
4.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
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
<?php
// +----------------------------------------------------------------------
// | bronet [ 以客户为中心 以奋斗者为本 ]
// +----------------------------------------------------------------------
// | Copyright (c) 2013-2017 http://www.bronet.cn All rights reserved.
// +----------------------------------------------------------------------
// | Licensed ( http://www.apache.org/licenses/LICENSE-2.0 )
// +----------------------------------------------------------------------
namespace app\portal\controller;
use app\portal\service\LikeService;
use cmf\controller\HomeBaseController;
use cmf\controller\WeChatBaseController;
use EasyWeChat\Foundation\Application;
use think\Db;
class ActiveController extends WeChatBaseController
{
public function _initialize()
{
parent::_initialize();
$this->checkWeChatUserLogin();
}
//活动首页
public function active(){
$banner=Db::name('active')->where('is_top',1)->field('thumbnail,id')->select();
$this->assign('banner',$banner);
$data=Db::name('active')->where(['status'=>1,'category_id'=>1])->select();
$this->assign('list',$data);
return $this->fetch();
}
//活动首页ajax
public function activeAjax(){
$where['status']=1;
$status=$this->request->param('status');
$where['category_id']=$status;
$data=Db::name('active')->where($where)->select()->toArray();
foreach ($data as $k => $v) {
$data[$k]['url']=url('portal/active/activeDetail',array('id'=>$data[$k]['id']));
$data[$k]['image'] = cmf_get_image_preview_url($data[$k]['thumbnail']);
$data[$k]['active_time'] = date('Y-m-d',$data[$k]['active_time']);
$data[$k]['end_time'] = date('Y-m-d',$data[$k]['end_time']);
};
return $data;
}
//活动详情
public function activeDetail()
{
$re=Db::name('users')->where(['open_id'=>session('wechat_user')['id']])->find();
if (!$re['mobile']){
$like=0;
}
$id=$this->request->param('id');
$data=Db::name('active')
->where('id',$id)
->find();
$data['more']=json_decode($data['more'],true);
$data['content']=cmf_replace_content_file_url(htmlspecialchars_decode($data['content']));
if (!isset($like)) {
$like = Db::name('like')->where(['cid' => $id, 'users_id' => $re['id'], 'status' => 2])->find();
if ($like) {
$like = 1;
} else {
$like = 0;
}
}
$comment=Db::name('comment')
->alias('c')
->join('users u','c.users_id=u.id')
->join('brand b','c.cid=b.id')
->where(['b.id'=>$id,'c.status'=>2])
->field('c.*,u.*')
->select();
$this->assign('comment',$comment);
$this->assign('like',$like);
$this->assign('list',$data);
return $this->fetch('active_detail');
}
public function comment(){
$id=$this->request->param('id');
$re=Db::name('users')->where(['open_id'=>session('wechat_user')['id']])->find();
if (!$re['mobile']){
return 2;
}
else {
return url('portal/active/comment2',array('id'=>$id));
}
}
public function comment2(){
$id=$this->request->param('id');
$this->assign('id', $id);
return $this->fetch();
}
public function commentPost(){
$re=Db::name('users')->where(['open_id'=>session('wechat_user')['id']])->find();
if (!$re['mobile']){
return 3;
}
$param=$this->request->param();
$param['create_time']=time();
$param['status']=2;
$param['users_id']=$re['id'];
$result=Db::name('comment')->where(['users_id'=>$param['users_id'],'status'=>2,'cid'=>$param['cid']])->find();
if ($result){
return 2;
}
$re1=Db::name('comment')->insert($param);
$re2=Db::name('active')->where('id',$param['cid'])->setInc('comment',1);
if ($re1 && $re2) {
$url = url('portal/active/activeDetail', array('id' => $param['cid']));
return $url;
}else{
return 0;
}
}
//点赞ajax接口
public function like(){
$re=Db::name('users')->where(['open_id'=>session('wechat_user')['id']])->find();
if (!$re['mobile']){
return 3;
}
$param=$this->request->param();
$like=new LikeService();
return $like->like($param['id'],2,$re['id']);
}
}