审查视图

application/api/controller/Activity.php 2.8 KB
李忠强 authored
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16
<?php


namespace app\api\controller;


use app\common\controller\Api;
use think\Config;
use think\Db;

/**
 * 首页活动
 */
class Activity extends Api
{
    protected $noNeedRight = ['*'];
李忠强 authored
17
//    protected $noNeedLogin = ['*'];
李忠强 authored
18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40


    /**
     * @ApiTitle    (活动商品列表)
     * @ApiMethod   (POST)
     * @ApiHeaders  (name=token, type=string, required=true, description="请求的Token")
     * @ApiParams   (name="id", type="integer", required=true, description="活动ID")
     * @ApiParams   (name="page", type="integer", required=true, description="页数")
     * @ApiReturn   ({
    'code':'1',
    'msg':'返回成功'
    'data':
        "list": {
        "total": 4, 总条数
        "per_page": 10,每页数量
        "current_page": 1,当前页
        "last_page": 1,最后一页
        "data": [
        {
        "goods_id": 21,
        "goods_name": "小米Mix3",
        "price": "100.00",
        "line_price": "1000.00",划线价
何书鹏 authored
41 42
        "image_text": "图片路径",
        "stock_num": 68, 商品总库存
李忠强 authored
43 44 45 46 47 48 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
        }
        ]
        },
        "timeslot": "秒杀时间段"
        {
            "time": "16:41",
            "status": "not" not 未开始 will即将开始 begin 抢购中 over 已结束
        },
        {
            "time": "17:24",
            "status": "not"
        },
        "image": "广告图"
    })
     */
    public function listGoods()
    {
        $id = $this->request->post('id');
        $page = $this->request->post('page',1);
        if (!is_numeric($page) || !is_numeric($id)) $this->error('参数不合法');
        $model = new \app\api\model\Goods();

        $list = $model
            ->where('is_delete','0')
            ->where('goods_status','10')
            ->where('activity_id',$id)
            ->field('goods_id,goods_name,image')
            ->paginate(10,false,['page'=>$page])
            ->each(function ($item,$key){
                $goods_spec = Db::name('litestore_goods_spec')
                    ->where('goods_id',$item['goods_id'])
                    ->find();
李忠强 authored
75 76 77 78
                $item['cart_number'] = Db::name('cart')
                    ->where('user_id',$this->auth->id)
                    ->where('goods_id',$item['goods_id'])
                    ->sum('number');
李忠强 authored
79 80
                $item['price'] = $goods_spec['goods_price'];
                $item['line_price'] = $goods_spec['line_price'];
何书鹏 authored
81 82
                // 总库存
                $item->append(['stock_num']);
李忠强 authored
83 84
            });
        $timeslot = $this->timeplot();
李忠强 authored
85 86 87 88 89 90
        foreach ($timeslot as $key => $value){
            if ($value['int'] > time()){
                $next_time = $value['int'];
                break;
            }
        }
李忠强 authored
91
        $image = cdnurl(Config::get('site.activity_image'),true);
李忠强 authored
92
        $this->success('活动商品列表',['list'=>$list,'timeslot'=>$timeslot,'image'=>$image,'next_time'=>$next_time]);
李忠强 authored
93 94
    }
}