Index.php
4.6 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
<?php
/**
* Created by PhpStorm.
* User: Administrator
* Date: 2019/10/18
* Time: 11:03
*/
namespace app\home\controller;
use app\common\controller\WechatBase;
use app\home\model\Goods;
use app\home\model\Slide;
use think\Db;
class Index extends WechatBase
{
public function index(){
$domain_name = $this->request->domain();//域名
//幻灯片
$slideModel = new Slide();
$slide = $slideModel->selectData([]);
$slide = collection($slide)->toArray();
foreach($slide as $key => $s){
$s[$key]['image'] = $domain_name.$s['image'];
}
//广告信息
$user_id = get_current_user_id();
$goods_ids = [];
if(!empty($user_id)){
//获取用户答对了哪些广告(拿过广告的积分就不要展示在列表里了)
$user_exp_log = Db::name('user_exp_log')->where(['user_id'=>$user_id,'type'=>4])->select();
foreach($user_exp_log as $key => $value){
$goods_ids[] = $value['goods_id'];
}
}
$goodsModel = new Goods();
$data = $goodsModel->selectPageData(['id'=>['not in',$goods_ids]],1,5);
foreach($data as $key => $vo){
if(!empty($vo['video'])){
$data[$key]['video'] = $domain_name.$vo['video'];
}
$voice = explode(',',$vo['voice']);
if(!empty($voice)){
foreach($voice as $key2 => $vo2){
$voice[$key2] = $domain_name.$vo2;
}
$data[$key]['voice'] = $voice;
}
$data[$key]['start_time'] = date('Y-m-d',$vo['start_time']);
$data[$key]['end_time'] = date('Y-m-d',$vo['end_time']);
$images = explode(',',$vo['images']);
if(!empty($images)){
foreach($images as $key3 => $vo3){
$images[$key3] = $domain_name.$vo3;
}
$data[$key]['images'] = $images;
}
}
$this->assign('slide',$slide);
$this->assign('data',$data);
$this->assign('title','广告商城');
return $this->fetch();
}
/**
* 加载更多
*/
public function more(){
$domain_name = $this->request->domain();//域名
$user_id = $this->request->param('user_id',0,'intval');
$page = $this->request->param('page',1,'intval');
$pageNum = $this->request->param('pageNum',5,'intval');
$goods_ids = [];
if(!empty($user_id)){
//获取用户答对了哪些广告(拿过广告的积分就不要展示在列表里了)
$user_exp_log = Db::name('user_exp_log')->where(['user_id'=>$user_id,'type'=>4])->select();
foreach($user_exp_log as $key => $value){
$goods_ids[] = $value['goods_id'];
}
}
$goodsModel = new Goods();
$data = $goodsModel->selectPageData(['id'=>['not in',$goods_ids]],$page,$pageNum);
foreach($data as $key => $vo){
if(!empty($vo['video'])){
$data[$key]['video'] = $domain_name.$vo['video'];
}
$voice = explode(',',$vo['voice']);
if(!empty($voice)){
foreach($voice as $key2 => $vo2){
$voice[$key2] = $domain_name.$vo2;
}
$data[$key]['voice'] = $voice;
}
$data[$key]['start_time'] = date('Y-m-d',$vo['start_time']);
$data[$key]['end_time'] = date('Y-m-d',$vo['end_time']);
$images = explode(',',$vo['images']);
if(!empty($images)){
foreach($images as $key3 => $vo3){
$images[$key3] = $domain_name.$vo3;
}
$data[$key]['images'] = $images;
}
}
$this->success('SUCCESS','',$data);
}
public function collect(){
$type = $this->request->param('type',0,'intval');
$goods_id = $this->request->param('goods_id',0,'intval');
$user_id = $this->request->param('user_id',0,'intval');
if(empty($type) || empty($goods_id) || empty($user_id)){
$this->error('404');
}
if($type == 1){
//收藏
if(empty($collect)){
$arr['user_id'] = $user_id;
$arr['goods_id'] = $goods_id;
$arr['createtime'] = time();
Db::name('collect')->insert($arr);
}
}else if($type == 2){
//取消收藏
Db::name('collect')->where(['user_id'=>$user_id,'goods_id'=>$goods_id])->delete();
}
$this->success('SUCCESS');
}
}