Index.php 12.0 KB
<?php

namespace app\api\controller;

use app\common\controller\Api;
use think\Validate;
/**
 * 首页接口
 */
class Index extends Api
{
    protected $noNeedLogin = ['*'];
    protected $noNeedRight = ['*'];
    protected $uid = '';
    protected $flag = '';
    public function _initialize()
    {
        parent::_initialize();
        $this->uid = $this->auth->getUserId();
        $this->flag = config('verify.flag');
    }

    /**
     * @ApiTitle    (首页)
     * @ApiSummary  (首页)
     * @ApiMethod   (GET)
     * @ApiRoute    (/api/index/index)
     *
     * @ApiReturn({
        "code": 1,
        "msg": "成功",
        "time": "1574935164",
        "data": {
            "res_banner": [//轮播图
                {
                    "id": 1,//轮播图id
                    "image": ""//图片路径
                    "url": ""//跳转链接
                },
                {
                    "id": 2,
                    "image": "http://jinglong.springchunjia.cn/uploads/20191127/79e122b17786dbf0365a1018e27872d7.png"
                },
            ],
            "res_advert": {//活动广告位(没有则不显示)
                "id": 1,//id
                "image": "http://jinglong.springchunjia.cn/uploads/20191127/febfea9a34c918cb2f100f669ede2547.png"//图片路径
                "url": ""//跳转链接
            },
            "res_design": [//设计师作品
                {
                    "id": 7,//商品id
                    "name": "MONENT 动感系列",//商品名称
                    "introduce": "轻波款,为客厅缀上霞光淡雾",//商品简介
                    "sale_price": 2299,//商品价格
                    "image": "http://jinglong.springchunjia.cn/uploads/20191127/05d216e117e11bd3de352c155b42eaaa.mp4?vframe/jpg/offset/2"//图片路径
                },
                {
                    "id": 1,
                    "name": "MONENT 动感系列",
                    "introduce": "轻波款,为客厅缀上霞光淡雾",
                    "sale_price": 2599,
                    "image": "http://jinglong.springchunjia.cn/uploads/20191127/05d216e117e11bd3de352c155b42eaaa.mp4?vframe/jpg/offset/2"
                },
            ],
            "res_u_list": [//用户晒单
                {
                    "id": 2,//晒单id
                    "images": [//图片路径(取第一个即可)
                        "http://jinglong.springchunjia.cn/uploads/20191127/febfea9a34c918cb2f100f669ede2547.png",
                        "http://jinglong.springchunjia.cn/uploads/20191127/042a3256122af7b10e26efb5e7649904.png"
                    ],
                    "title": "超越百年历史的葡萄牙餐具",//晒单标题
                    "nickname": "桃花岛岛主",//用户昵称
                    "address": "上海"//用户归属地
                }
            ],
            "res_b_type": [//大牌专区
                {
                    "id": 1,//品牌id
                    "image": "http://jinglong.springchunjia.cn/uploads/20191127/d36d8475bc3bdb999dff26d019c608ed.png",//图片路径
                    "name": "HEDRMAR1",//品牌名称
                    "address": "葡萄牙1",//品牌归属地
                    "introduce": "超百年历史的葡萄牙餐具"//品牌简介
                },
                {
                    "id": 2,
                    "image": "http://jinglong.springchunjia.cn/uploads/20191127/c53f07984e6d64d00e9bf1c9fb6ebf72.png",
                    "name": "HEDRMAR2",
                    "address": "葡萄牙2",
                    "introduce": "超百年历史的葡萄牙餐具"
                },
            ]
        }
        })
     */
    public function index(){
        if($this->request->isGet()){
            $arr = [];
            //轮播图
            $res_banner = Common::selectWhereData('banner',['status'=>'normal'],'id,image,url');
            foreach ($res_banner as &$b_value){
                $b_value['image'] = $this->auth->absolutionUrlOne($b_value['image']);
            }
            $arr['res_banner'] = $res_banner;

            //首页广告位
            $res_advert = Common::findWhereData('advert',['type'=>0],'id,image,url');
            if($res_advert){
                $res_advert['image'] = $this->auth->absolutionUrlOne($res_advert['image']);
            }
            $arr['res_advert'] = $res_advert;

            //设计师作品
            $res_design = Common::selectSoftWhereLimitData('goods',['is_design'=>$this->flag[1]],'id,name,introduce,sale_price1 sale_price,file,image','sort desc');
            foreach ($res_design as &$d_value){
                //获取视频帧
                $d_value['image'] = [$this->auth->absolutionUrlOne($d_value['image'])];
                $sale_price = Common::salePrice($d_value['sale_price']);
                if($sale_price){
                    $d_value['sale_price'] = $sale_price[0];
                }else{
                    $d_value['sale_price'] = '';
                }
                unset($d_value['file']);
            }
            $arr['res_design'] = $res_design;

            //用户晒单
            $res_u_list = Common::selectSoftWhereLimitData('ulist',['status'=>'normal'],'id,images,title,nickname,address','id desc');
            foreach ($res_u_list as &$u_value){
                $u_value['images'] = $this->auth->absolutionUrl($u_value['images']);
            }
            $arr['res_u_list'] = $res_u_list;

            //大牌专区
            $brand_limit = config('verify.brand_limit');
            $res_b_type = Common::selectSoftLimitData('btype','id,image,name,address,introduce',$brand_limit);
            foreach ($res_b_type as &$t_value){
                $t_value['image'] = $this->auth->absolutionUrlOne($t_value['image']);
            }
            $arr['res_b_type'] = $res_b_type;

            $this->success('成功',$arr);
        }else{
            $this->error('请求方式错误');
        }
    }

    /**
     * @ApiTitle    (弹窗广告位)
     * @ApiSummary  (弹窗广告位)
     * @ApiMethod   (GET)
     * @ApiRoute    (/api/index/popupAdvert)
     *
     * @ApiReturn({
        "code": 1,
        "msg": "成功",
        "time": "1574989615",
        "data": {//没有则不显示
            "id": 2,//弹窗广告位id
            "image": "http://jinglong.springchunjia.cn/uploads/20191127/0b20812d4f80307dd1025db71d690395.png"//图片路径
            "url": ""//跳转链接
        }
    })
     */
    public function popupAdvert(){
        if($this->request->isGet()){
            $res = Common::findWhereData('advert',['type'=>1],'id,image,url');
            if($res){
                $res['image'] = $this->auth->absolutionUrlOne($res['image']);
            }
            $this->success('成功',$res);
        }else{
            $this->error('请求方式错误');
        }
    }

    /**
     * @ApiTitle    (推荐商品列表)
     * @ApiSummary  (推荐商品列表)
     * @ApiMethod   (GET)
     * @ApiRoute    (/api/index/recommendGoodsList)
     *
     * @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 recommendGoodsList(){
        if($this->request->isGet()){
            $page = $this->request->get('page');
            $rule = config('verify.page');
            $validate = new Validate($rule['rule'],$rule['msg']);
            if (!$validate->check(['page'=>$page])) {
                $this->error($validate->getError());
            }

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

    /**
     * @ApiTitle    (晒单详情)
     * @ApiSummary  (晒单详情)
     * @ApiMethod   (GET)
     * @ApiRoute    (/api/index/uListDetail)
     *
     * @ApiParams   (name="u_list_id", type="inter", required=true, description="晒单id")
     *
     * @ApiReturn({
        "code": 1,
        "msg": "成功",
        "time": "1575010422",
        "data": {
            "id": 2,//晒单id
            "g_id": 6,//商品id
            "images": [//图片路径
                "http://jinglong.springchunjia.cn/uploads/20191127/febfea9a34c918cb2f100f669ede2547.png",
                "http://jinglong.springchunjia.cn/uploads/20191127/042a3256122af7b10e26efb5e7649904.png"
            ],
            "files": [//视频路径
                "http://feifangu.qiniu.brotop.cn/uploads/20191217/05d216e117e11bd3de352c155b42eaaa.mp4",
                "http://feifangu.qiniu.brotop.cn/uploads/20191217/05d216e117e11bd3de352c155b42eaaa.mp4"
            ],
            "title": "超越百年历史的葡萄牙餐具",//晒单标题
            "nickname": "桃花岛岛主",//用户昵称
            "address": "上海"//用户归属地
            "image": "http://jinglong.springchunjia.cn/uploads/20191128/0869f5de4808a04e7a3bceccff0c1132.png",//头像路径
            "detail": ,//详情(富文本)
            "goods": {//商品
                "image": "http://jinglong.springchunjia.cn/uploads/20191128/8a677f5a0418059bf1b974c50026af13.png",//图片
                "name": "MONENT 动感系列",//商品名称
                "introduce": "轻波款,为客厅缀上霞光淡雾"//商品简介
            }
        }
    })
     */
    public function uListDetail(){
        if($this->request->isGet()){
            $u_list_id = $this->request->get('u_list_id');
            $rule = config('verify.u_list_detail');
            $validate = new Validate($rule['rule'],$rule['msg']);
            if (!$validate->check(['u_list_id'=>$u_list_id])) {
                $this->error($validate->getError());
            }

            $res = Common::findSoftWhereData('ulist',['id'=>$u_list_id],'createtime,updatetime,deletetime',true);
            if($res){
                $res['image'] = $this->auth->absolutionUrlOne($res['image']);
                $res['images'] = $this->auth->absolutionUrl($res['images']);
                if(!empty($res['files'])){
                    $res['files'] = $this->auth->absolutionUrl($res['files']);
                }else{
                    $res['files'] = [];
                }

                $res_goods = Common::findSoftWhereData('goods',['id'=>$res['g_id']],'image,name,introduce');
                $res['goods'] = '';
                if($res_goods){
                    $res_goods['image'] = $this->auth->absolutionUrlOne($res_goods['image']);
                    $res['goods'] = $res_goods;
                }
            }
            $this->success('成功',$res);
        }else{
            $this->error('请求方式错误');
        }
    }

}