Brand.php 7.1 KB
<?php

namespace app\api\controller;

use app\common\controller\Api;
use think\Validate;
/**
 * 品牌接口
 */
class Brand extends Api
{
    protected $noNeedLogin = ['*'];
    protected $noNeedRight = ['*'];
    protected $uid = '';
    public function _initialize()
    {
        parent::_initialize();
        $this->uid = $this->auth->getUserId();
    }

    /**
     * @ApiTitle    (品牌分类)
     * @ApiSummary  (品牌分类)
     * @ApiMethod   (GET)
     * @ApiRoute    (/api/brand/brandType)
     *
     * @ApiReturn({
        "code": 1,
        "msg": "成功",
        "time": "1574939519",
        "data": {
            "data": [
                {
                    "id": 1,//品牌分类id
                    "image": "http://jinglong.springchunjia.cn/uploads/20191127/d36d8475bc3bdb999dff26d019c608ed.png",//图片路径
                    "name": "HEDRMAR1",//品牌名称
                    "address": "葡萄牙1"//品牌产地
                },
                {
                    "id": 2,
                    "image": "http://jinglong.springchunjia.cn/uploads/20191127/c53f07984e6d64d00e9bf1c9fb6ebf72.png",
                    "name": "HEDRMAR2",
                    "address": "葡萄牙2"
                }
            ],
            "images": [//右侧轮播图
                {
                    "id": 5,
                    "image": "/uploads/20191127/d36d8475bc3bdb999dff26d019c608ed.png",//图片
                    "url": "/pages/index/brandDetail/brandDetail?id=1"//路径
                },
                {
                    "id": 4,
                    "image": "/uploads/20191207/7a9772ee5e3947c8ad0e8bff2069e1ac.jpg",
                    "url": ""
                },
            ]
        }
    })
     */
    public function brandType(){
        if($this->request->isGet()){
            $arr = [];
            $res = Common::selectSoftData('btype','id,image,name,address','sort desc,id desc');
            foreach ($res as &$value){
                $value['image'] = $this->auth->absolutionUrlOne($value['image']);
            }
            $arr['data'] = $res;
            //品牌专区轮播图
            $res1 = Common::selectData('btbanner','id,image,url','sort desc,id desc');
            foreach ($res1 as &$value1){
                $value1['image'] = $this->auth->absolutionUrlOne($value1['image']);
            }
            $arr['images'] = $res1;
            $this->success('成功',$arr);
        }else{
            $this->error('请求方式错误');
        }
    }

    /**
     * @ApiTitle    (品牌详情)
     * @ApiSummary  (品牌详情)
     * @ApiMethod   (GET)
     * @ApiRoute    (/api/brand/brandDetail)
     *
     * @ApiParams   (name="b_id", type="inter", required=true, description="品牌分类id")
     *
     * @ApiReturn({
        "code": 1,
        "msg": "成功",
        "time": "1575007401",
        "data": {
            "id": 1,//品牌id
            "image": "http://jinglong.springchunjia.cn/uploads/20191127/d36d8475bc3bdb999dff26d019c608ed.png",//品牌图片路径
            "name": "HEDRMAR1",//品牌名称
            "address": "葡萄牙1",//品牌所属地
            "introduce": "超百年历史的葡萄牙餐具",//品牌简介
            "brand_explain": "",//品牌详情(富文本)
            "tag": [//品牌标签
                "日式简约",
                "隐秘乡奢",
                "家庭情侣"
            ],
            "file": "http://jinglong.springchunjia.cn/uploads/20191127/05d216e117e11bd3de352c155b42eaaa.mp4",//视频路径
            "image_long": "http://jinglong.springchunjia.cn/uploads/20191127/bf35ec1b42a6d1c95355ce22fa633a43.jpg"//长图路径
        }
    })
     */
    public function brandDetail(){
        if($this->request->isGet()){
            $b_id = $this->request->get('b_id');
            $rule = config('verify.brand_detail');
            $validate = new Validate($rule['rule'],$rule['msg']);
            if (!$validate->check(['b_id'=>$b_id])) {
                $this->error($validate->getError());
            }

            $res = Common::findSoftWhereData('btype',['id'=>$b_id],'createtime,updatetime,deletetime',true);
            if($res){
                $res['image'] = $this->auth->absolutionUrlOne($res['image']);
                $res['file_cover'] = $this->auth->absolutionUrlOneFrame($res['file'],1);
                $res['file'] = $this->auth->absolutionUrlOne($res['file']);
                $res['image_long'] = $this->auth->absolutionUrlOne($res['image_long']);
                $res['tag'] = explode('|',$res['tag']);
            }
            $this->success('成功',$res);
        }else{
            $this->error('请求方式错误');
        }
    }

    /**
     * @ApiTitle    (品牌商品列表)
     * @ApiSummary  (品牌商品列表)
     * @ApiMethod   (GET)
     * @ApiRoute    (/api/brand/brandGoodsList)
     *
     * @ApiParams   (name="b_id", type="inter", required=true, description="品牌id")
     * @ApiParams   (name="page", type="inter", required=true, description="分页页码")
     *
     * @ApiReturn({
        "code": 1,
        "msg": "成功",
        "time": "1574941706",
        "data": {
            "data": [
                {
                    "id": 7,//商品id
                    "image": "http://jinglong.springchunjia.cn/uploads/20191128/8a677f5a0418059bf1b974c50026af13.png",//图片路径
                    "name": "MONENT 动感系列",//商品名称
                    "tag": [//商品标签
                        "日式简约",
                        "隐秘乡奢",
                        "家庭情侣"
                    ],
                    "style": [//商品规格
                        "主餐匙,茶匙各1件",
                        "古堡灰"
                    ],
                    "sale_price": 2299//销售价格
                    "expense_price": //运费(0:显示包运费标签)
                    is_new_tag": 0//新人价格标签(0:不显示,1:显示)
                },
                {
                    "id": 4,
                    "image": "http://jinglong.springchunjia.cn/uploads/20191128/93971e55b83d1a09c1831f8197514305.png",
                    "name": "MONENT 动感系列",
                        "tag": [
                        "AB级",
                        "ABX级",
                        "ABN级"
                    ],
                    "sale_price": 2599
                },
            ],
            "total_page": 1
        }
    })
     */
    public function brandGoodsList(){
        if($this->request->isGet()){
            $b_id = $this->request->get('b_id');
            $page = $this->request->get('page');
            $rule = config('verify.brand_goods');
            $validate = new Validate($rule['rule'],$rule['msg']);
            if (!$validate->check(['b_id'=>$b_id,'page'=>$page])) {
                $this->error($validate->getError());
            }

            $where = ['type'=>1,'t_id'=>$b_id];
            $arr = Common::goodsList($where,$page,$this->uid);
            $this->success('成功',$arr);
        }else{
            $this->error('请求方式错误');
        }
    }

}