ShopgoodsController.php 2.7 KB
<?php
/**
 * Created by PhpStorm.
 * User: Administrator
 * Date: 2019/11/9
 * Time: 14:19
 */

namespace app\index\controller;


use app\index\model\ShopgoodsModel;
use app\index\model\ShoppicModel;
use app\index\model\ShoptypeModel;
use cmf\controller\HomeBaseController;
use cmf\controller\WeChatBaseController;
use think\Db;

class ShopgoodsController extends WeChatBaseController
{
    function _initialize()
    {
        parent::_initialize();
        $this->checkWeChatUserLogin();
    }

    //商品分类列表
    public function index()
    {
        $where['delete_time'] = ['eq',0];
        $shopTypeModel = new ShoptypeModel();
        $data = $shopTypeModel->selectData($where)->toArray();
        return $data;
    }

    //商品类表
    public function goods(){
        $shoptype_id = $this->request->param('shoptype_id');
        if(empty($shoptype_id)){
            $shopGoodsModel = new ShopgoodsModel();
            $where['delete_time'] = ['eq',0];
            $data['goods'] = $shopGoodsModel->selectData($where)->toArray();
            $data['type'] = $this->index();
            $data['photo'] = $this->photo();
            $this->assign('data',$data);
            return $this->fetch();
        }else{
            $shopGoodsModel = new ShopgoodsModel();
            $where['delete_time'] = ['eq',0];
            $where['shoptype_id'] = ['eq',$shoptype_id];
            $data['goods'] = $shopGoodsModel->selectData($where)->toArray();
            $data['type'] = $this->index();
            $data['photo'] = $this->photo();
            $this->assign('data',$data);
            return $this->fetch();
        }
    }

    //商城轮播图
    public function photo(){
        $where['delete_time'] = ['eq',0];
        $shopPicModel = new ShoppicModel();
        $data = $shopPicModel->selectData($where)->toArray();
        return $data;
    }

    //商城搜索页
    public function search(){
        $keyword = $this->request->param('keyword');
        if(empty($keyword)){
            $this->error('请输入要搜索的内容');
        }
        $where['goods_name'] = ['like',"%$keyword%"];
        $shopGoodsModel = new ShopgoodsModel();
        $data = $shopGoodsModel->selectData($where)->toArray();
        $this->assign('data',$data);
        return $this->fetch();
    }

    //商品详情页
    public function goodsDetail(){
        $goods_id = $this->request->param('id',0,'intval');
        if(empty($goods_id)){
            $this->error('404');
        }
        $where['id'] = ['eq',$goods_id];
        $shopGoodsModel = new ShopgoodsModel();
        $data = $shopGoodsModel->findData($where)->toArray();
        $this->assign('data',$data);
        return $this->fetch();
    }
}