ShopgoodsController.php 4.1 KB
<?php
/**
 * Created by PhpStorm.
 * User: Administrator
 * Date: 2019/11/12
 * Time: 17:17
 */

namespace api\index\controller;


use api\index\model\ShoptypeModel;
use api\index\model\ShopgoodsModel;
use api\index\model\ShoppicModel;
use cmf\controller\RestBaseController;

/**
 * @title 积分商城首页
 * @description
 */
class ShopgoodsController extends RestBaseController
{

    /**
     * @title 商品类型
     * @description
     * @author GuoSheng
     * @url /index/Shopgoods/index
     * @method GET
     *
     * @return id:ID
     * @return type_name:类型名称
     *
     */
    public function index()
    {
        $where['delete_time'] = ['eq',0];
        $shopTypeModel = new ShoptypeModel();
        $data = $shopTypeModel->selectData($where);
        $this->success('SUCCESS',$data);
    }

    /**
     * @title 商品列表
     * @description
     * @author GuoSheng
     * @url /index/Shopgoods/goods
     * @method GET
     *
     * @param name:shoptype_id type:int require:0 other: desc:商品类型ID
     *
     * @return id:商品ID
     * @return shoptype_id:所属类型ID
     * @return goods_name:商品名称
     * @return price:所需积分
     *
     */
    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);
            $this->success('SUCCESS',$data);
        }else{
            $shopGoodsModel = new ShopgoodsModel();
            $where['delete_time'] = ['eq',0];
            $where['shoptype_id'] = ['eq',$shoptype_id];
            $data = $shopGoodsModel->selectData($where);
            $this->success('SUCCESS',$data);
        }
    }

    /**
     * @title 商城首页轮播图
     * @description
     * @author GuoSheng
     * @url /index/Shopgoods/photo
     * @method GET
     *
     * @return id:ID
     * @return thumbnail:图片
     * @return url:链接地址
     *
     */
    public function photo(){
        $where['delete_time'] = ['eq',0];
        $shopPicModel = new ShoppicModel();
        $data = $shopPicModel->selectData($where);
        $this->success('SUCCESS',$data);
    }

    /**
     * @title 商品搜索页
     * @description
     * @author GuoSheng
     * @url /index/Shopgoods/search
     * @method GET
     *
     * @param name:keyword type:string require:1 other: desc:商品关键字
     *
     * @return id:商品ID
     * @return shoptype_id:所属类型ID
     * @return goods_name:商品名称
     * @return price:所需积分
     *
     */
    public function search(){
        $keyword = $this->request->param('keyword');
        if(empty($keyword)){
            $this -> error(['code'=>40005,'msg'=>'缺少必要参数']);
        }
        $where['goods_name'] = ['like',"%$keyword%"];
        $shopGoodsModel = new ShopgoodsModel();
        $data = $shopGoodsModel->selectData($where);
        $this->success('SUCCESS',$data);
    }

    /**
     * @title 商品详情页
     * @description
     * @author GuoSheng
     * @url /index/Shopgoods/goodsDetail
     * @method GET
     *
     * @header name:XX-Token require:1 default: desc:token
     *
     * @param name:id type:int require:0 other: desc:商品ID
     *
     * @return id:商品ID
     * @return shoptype_id:所属类型ID
     * @return goods_name:商品名称
     * @return price:所需积分
     * @return thumbnail:商品缩略图
     * @return images:商品轮播图
     * @return freight:运费
     * @return content:详情
     *
     *
     */
    public function goodsDetail(){
        $user_id = $this->getUserId();
        $goods_id = $this->request->param('id',0,'intval');
        if(empty($goods_id)){
            $this -> error(['code'=>40005,'msg'=>'缺少必要参数']);
        }
        $where['id'] = ['eq',$goods_id];
        $shopGoodsModel = new ShopgoodsModel();
        $data = $shopGoodsModel->findData($where);
        $data['create_time'] = date('Y-m-d H:i:s',$data['create_time']);
        $data['update_time'] = date('Y-m-d H:i:s',$data['update_time']);
        $this->success('SUCCESS',$data);
    }
}