TP5 商城分类接口

一、首先创建表 分别为: 分类表(es_store_goods_cate) 、商品表(es_store_goods)。
如下图所示:
TP5 商城分类接口_第1张图片
TP5 商城分类接口_第2张图片
代码如下:

 	/**
     * 商品顶级分类列表
     * @return array|string
     */
    public $table = 'store_goodsCate';
     
    public  function Shoptype($pid=0)
    {
        $this->title = '商品分类';
        $db = Db::name($this->table)
                ->where(['pid' => $pid])
                ->order('sort asc,id asc')
                ->select();
         $json = json_encode($db );
         return $json;
    }
    
     /**
     * 子类查询信息
     * @return array|string
     */
    public function Shopsubclass()
    {
        $id = 10;
        $db = Db::name('store_goodsCate')
                ->where(['pid' => $id])
                ->order('sort asc,id asc')
                ->select();
        $json = json_encode($db );
        return $json;
    }
     /**
     * 商品信息
     * @return array|string
     */
    public function Shoplist()
    {
        $id = 9;
        $db = Db::name('store_goods')
                ->where('status',1)
                ->where("cate_id",$id)
                ->order('sort asc,id asc')
                ->select();
        $json = json_encode($db );
        return $json;
    }
    

你可能感兴趣的:(TP5)