审查视图

application/api/controller/Index.php 12.1 KB
jinglong authored
1 2 3 4 5
<?php

namespace app\api\controller;

use app\common\controller\Api;
6
use think\Validate;
jinglong authored
7 8 9 10 11 12 13
/**
 * 首页接口
 */
class Index extends Api
{
    protected $noNeedLogin = ['*'];
    protected $noNeedRight = ['*'];
14
    protected $uid = '';
15
    protected $flag = '';
16 17 18 19
    public function _initialize()
    {
        parent::_initialize();
        $this->uid = $this->auth->getUserId();
20
        $this->flag = config('verify.flag');
21
    }
jinglong authored
22 23

    /**
24 25 26 27
     * @ApiTitle    (首页)
     * @ApiSummary  (首页)
     * @ApiMethod   (GET)
     * @ApiRoute    (/api/index/index)
jinglong authored
28
     *
29 30 31 32 33 34 35 36 37
     * @ApiReturn({
        "code": 1,
        "msg": "成功",
        "time": "1574935164",
        "data": {
            "res_banner": [//轮播图
                {
                    "id": 1,//轮播图id
                    "image": ""//图片路径
jinglong authored
38
                    "url": ""//跳转链接
39 40 41 42 43 44 45 46 47
                },
                {
                    "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"//图片路径
jinglong authored
48
                "url": ""//跳转链接
49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95
            },
            "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": "超百年历史的葡萄牙餐具"
                },
            ]
        }
        })
jinglong authored
96
     */
97 98 99 100
    public function index(){
        if($this->request->isGet()){
            $arr = [];
            //轮播图
jinglong authored
101
            $res_banner = Common::selectWhereData('banner',['status'=>'normal'],'id,image,url','sort desc,id desc');
102 103 104 105 106 107
            foreach ($res_banner as &$b_value){
                $b_value['image'] = $this->auth->absolutionUrlOne($b_value['image']);
            }
            $arr['res_banner'] = $res_banner;

            //首页广告位
jinglong authored
108
            $res_advert = Common::findWhereData('advert',['type'=>0,'status'=>'normal'],'id,image,url');
109 110 111 112 113 114
            if($res_advert){
                $res_advert['image'] = $this->auth->absolutionUrlOne($res_advert['image']);
            }
            $arr['res_advert'] = $res_advert;

            //设计师作品
115
            $res_design = Common::selectSoftWhereLimitData('goods',['is_design'=>$this->flag[1]],'id,name,introduce,sale_price1 sale_price,file,image','sort desc');
116 117
            foreach ($res_design as &$d_value){
                //获取视频帧
118
                $d_value['image'] = [$this->auth->absolutionUrlOne($d_value['image'])];
jinglong authored
119 120 121 122 123 124
                $sale_price = Common::salePrice($d_value['sale_price']);
                if($sale_price){
                    $d_value['sale_price'] = $sale_price[0];
                }else{
                    $d_value['sale_price'] = '';
                }
125 126 127 128 129
                unset($d_value['file']);
            }
            $arr['res_design'] = $res_design;

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

            //大牌专区
jinglong authored
137 138
            $brand_limit = config('verify.brand_limit');
            $res_b_type = Common::selectSoftLimitData('btype','id,image,name,address,introduce',$brand_limit);
139 140 141 142 143 144 145 146 147 148 149 150
            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('请求方式错误');
        }
    }

    /**
jinglong authored
151 152
     * @ApiTitle    (弹窗广告位)
     * @ApiSummary  (弹窗广告位)
153
     * @ApiMethod   (GET)
jinglong authored
154
     * @ApiRoute    (/api/index/popupAdvert)
155 156 157 158
     *
     * @ApiReturn({
        "code": 1,
        "msg": "成功",
jinglong authored
159 160 161 162
        "time": "1574989615",
        "data": {//没有则不显示
            "id": 2,//弹窗广告位id
            "image": "http://jinglong.springchunjia.cn/uploads/20191127/0b20812d4f80307dd1025db71d690395.png"//图片路径
jinglong authored
163
            "url": ""//跳转链接
164
        }
jinglong authored
165
    })
166
     */
jinglong authored
167
    public function popupAdvert(){
168
        if($this->request->isGet()){
jinglong authored
169
            $res = Common::findWhereData('advert',['type'=>1,'status'=>'normal'],'id,image,url');
jinglong authored
170 171
            if($res){
                $res['image'] = $this->auth->absolutionUrlOne($res['image']);
172
            }
jinglong authored
173
            $this->success('成功',$res);
174 175 176 177 178 179
        }else{
            $this->error('请求方式错误');
        }
    }

    /**
jinglong authored
180 181
     * @ApiTitle    (推荐商品列表)
     * @ApiSummary  (推荐商品列表)
182
     * @ApiMethod   (GET)
jinglong authored
183
     * @ApiRoute    (/api/index/recommendGoodsList)
184 185 186 187 188 189 190 191 192 193 194 195
     *
     * @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",//图片路径
196
                    "name": "MONENT 动感系列",//商品名称(含有标记红色标签)
197 198 199 200 201
                    "tag": [//商品标签
                        "日式简约",
                        "隐秘乡奢",
                        "家庭情侣"
                    ],
jinglong authored
202 203 204 205
                    "style": [//商品规格
                        "主餐匙,茶匙各1件",
                        "古堡灰"
                    ],
206 207
                    "sale_price": 2299//销售价格
                    "expense_price": //运费(0:显示包运费标签)
208
                    "is_new_tag": 0//新人价格标签(0:不显示,1:显示)
209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225
                },
                {
                    "id": 4,
                    "image": "http://jinglong.springchunjia.cn/uploads/20191128/93971e55b83d1a09c1831f8197514305.png",
                    "name": "MONENT 动感系列",
                    "tag": [
                        "AB级",
                        "ABX级",
                        "ABN级"
                    ],
                    "sale_price": 2599
                },
            ],
            "total_page": 1
        }
    })
     */
jinglong authored
226
    public function recommendGoodsList(){
227 228 229 230 231 232 233 234
        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());
            }
235 236
            $where = ['is_recommend'=>$this->flag[1]];
            $arr = Common::goodsList($where,$page,$this->uid);
237 238 239 240
            $this->success('成功',$arr);
        }else{
            $this->error('请求方式错误');
        }
jinglong authored
241
    }
jinglong authored
242
jinglong authored
243 244 245 246 247 248 249 250 251 252 253 254 255 256 257
    /**
     * @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
258
            "images": [//图片路径
jinglong authored
259 260 261
                "http://jinglong.springchunjia.cn/uploads/20191127/febfea9a34c918cb2f100f669ede2547.png",
                "http://jinglong.springchunjia.cn/uploads/20191127/042a3256122af7b10e26efb5e7649904.png"
            ],
jinglong authored
262 263 264 265
            "files": [//视频路径
                "http://feifangu.qiniu.brotop.cn/uploads/20191217/05d216e117e11bd3de352c155b42eaaa.mp4",
                "http://feifangu.qiniu.brotop.cn/uploads/20191217/05d216e117e11bd3de352c155b42eaaa.mp4"
            ],
jinglong authored
266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290
            "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']);
jinglong authored
291
                $res['images'] = $this->auth->absolutionUrl($res['images']);
jinglong authored
292 293 294 295 296 297
                if(!empty($res['files'])){
                    $res['files'] = $this->auth->absolutionUrl($res['files']);
                }else{
                    $res['files'] = [];
                }
jinglong authored
298 299 300 301 302 303 304 305 306 307 308 309 310
                $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('请求方式错误');
        }
    }
jinglong authored
311
}