Goods.php
2.2 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
<?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 think\Db;
class Goods extends WechatBase
{
protected $user_id;
function _initialize()
{
parent::_initialize();
//判断是否授权
$user_id = get_current_user_id();
if(empty($user_id)){
dump(url('','',false,true));
echo $this->request->controller();
echo $this->request->module();
echo $this->request->action();
exit();
$this->redirect('user/authorization_view');
}
$this->user_id = $user_id;
}
public function detail(){
$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)){
$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('查无此人');
}
$this->assign('data',$data);
return $this->fetch();
}
}