Goods.php
4.9 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
135
136
137
138
139
140
<?php
/**
* Created by PhpStorm.
* User: Administrator
* Date: 2019/10/23
* Time: 11:47
*/
namespace app\home\controller;
use app\common\controller\WechatBase;
use app\home\model\Question;
use app\home\model\User;
use EasyWeChat\Foundation\Application;
use think\Db;
class Goods extends WechatBase
{
protected $user_id;
function _initialize()
{
parent::_initialize();
//判断是否授权
$user_id = get_current_user_id();
if(empty($user_id)){
$goods_id = $this->request->param('goods_id',0,'intval');
$target_url = rawurlencode(url('',array('goods_id'=>$goods_id),false,true));
$this->redirect('user/authorization_view',array('target_url'=>$target_url));
}
$this->user_id = $user_id;
}
public function detail(){
$domain_name = $this->request->domain();//域名
$goods_id = $this->request->param('goods_id',0,'intval');
if(empty($goods_id)){
$this->error('404');
}
$where['id'] = ['eq',$goods_id];
$goodsModel = new \app\home\model\Goods();
$data = $goodsModel->findData($where);
if(!empty($data['video'])){
$data['video'] = $domain_name.$data['video'];
}
if(!empty($data['voice'])){
$voice = explode(',',$data['voice']);
foreach($voice as $key => $v){
$voice[$key] = $domain_name.$v;
}
$data['voice'] = $voice;
}
if(empty($data)){
$this->error('404');
}
if($data['status'] == 1){
$this->error('广告审核中');
}
if($data['status'] == 3){
$this->error('广告审核未通过');
}
if($data['admin_deletetime'] != 0){
$this->error('已下架');
}
if($data['user_deletetime'] != 0){
$this->error('已下架');
}
if($data['admin_is_up'] != 1){
$this->error('已下架');
}
if($data['user_is_up'] != 1){
$this->error('已下架');
}
//判断是否收藏
$collect = Db::name('collect')->where(['user_id'=>$this->user_id,'goods_id'=>$goods_id])->find();
if(!empty($collect)){
$is_collect = 1;
}else{
$is_collect = 0;
}
$data['is_collect'] = $is_collect;
$userModel = new User();
$user = $userModel->findData(['id'=>$this->user_id]);
if(empty($user)){
$this->error('查无此人');
}
//判断用户是否答过题
$is_answer = Db::name('user_question_answer')->where(['goods_id'=>$goods_id,'user_id'=>$this->user_id])->find();
if(empty($is_answer)){
$data['is_answer'] = 0;//未答过
$is_correct = 0;
}else{
$data['is_answer'] = 1;//答过题
//判断是否全部正确
$correct = Db::name('user_question_answer')->where(['goods_id'=>$goods_id,'user_id'=>$this->user_id,'is_correct'=>0])->find();
if(empty($correct)){
$is_correct = 1;//全部正确
}else{
$is_correct = 0;//未全部正确
}
}
$data['is_correct'] = $is_correct;
//数据回显
$question = json_decode($data['question'],true);
foreach($question as $key => $q){
$user_question_answer = Db::name('user_question_answer')->where(['user_id'=>$this->user_id,'goods_id'=>$goods_id,'question_key'=>$key])->find();
$question[$key]['answer'] = $user_question_answer;
}
//判断是否处于重新答题倒计时状态
$question_error = Db::name('user_question_answer')->where(['user_id'=>$this->user_id,'goods_id'=>$goods_id])->find();
$time = !empty($question_error['resettime']) ? $question_error['resettime']-time() : 0;
$data['time'] = $time;
$data['question'] = $question;
//判断用户是否完成答题条件
if(empty($user['mobile']) || empty($user['name']) || empty($user['card'])){
$user['is_satisfy'] = 0;//不满足
}else{
$user['is_satisfy'] = 1;//满足
}
$this->assign('user',$user);
$this->assign('data',$data);
$options = [
'app_id' => config('wechat.app_id'),
'secret' => config('wechat.secret'),
];
$app = new Application($options);
$js = $app->js;
$jssdk = $js->config(['getLocation'], $debug = false, $beta = false, $json = true);
$this->assign('jssdk',$jssdk);
if($data['type'] == 1){
return $this->fetch('video_detail');
}else if($data['type'] == 2){
return $this->fetch('audio_detail');
}else if($data['type'] == 3){
return $this->fetch('content_detail');
}else{
$this->error('未知类型');
}
}
}