Goods.php 2.2 KB
<?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();
    }
}