Nobase.php 3.09 KB
<?php
/**
 * Created by PhpStorm.
 * User: wxd1061
 * Date: 2018-07-21
 * Time: 17:35
 */

namespace app\mobile\controller;
use app\home\logic\UsersLogic;
use think\Controller;
use think\Cookie;
use Think\Db;
use think\Page;

class Nobase extends Controller
{
    /**
     * 秒杀活动列表
     */
    public function ajax_team_list()
    {
        $stype = I('type/d', 1);
        $now_time = time();  //当前时间
        $where = " and f.is_end=0";
        /*---当开始时间大于当前时间,就是活动已经开始---*/
        if ($stype == 1) {
            $where = " and f.start_time<" . $now_time;
            $fname = "/team/ajax_team_list_1";
        } else {
            $where = " and f.start_time>=" . $now_time;
            $fname = "/team/ajax_team_list_2";
        }

        //秒杀商品
        $id = getMobileStoId();
        if (is_int($now_time / 7200)) {      //双整点时间,如:10:00, 12:00
            $start_time = $now_time;
        } else {
            $start_time = floor($now_time / 7200) * 7200; //取得前一个双整点时间
        }
        $end_time = $start_time + 7200;   //结束时间

        $tt=time();
        /*--and f.goods_num>f.buy_num--*/
        $count = M('goods')
            ->alias('g')
            ->join('teamlist f', 'g.goods_id = f.goods_id', 'inner')
            ->where("  g.store_id=" . $id . " and g.is_on_sale=1   and f.show_time<" . $now_time . " and f.end_time>" . $now_time . $where)
            ->where("g.on_time<".$tt." and (g.down_time>".$tt." or g.down_time=0 ) and g.is_mainshow=1")
            ->where('f.is_show=1 and f.is_end=0')
            ->count();

        //dump("  g.store_id=".$id." and g.is_on_sale=1  and f.goods_num>f.buy_num and f.show_time<".$now_time." and end_time>".$now_time);exit;
        $pagesize = 10;//C('PAGESIZE');  //每页显示数
        $Page = new Page($count, $pagesize); // 实例化分页类 传入总记录数和每页显示的记录数

        $show = $Page->show();  // 分页显示输出
        $this->assign('page', $show);    // 赋值分页输出
        //mlog($Page->firstRow.','.$Page->listRows,"seckill");
        /*and f.goods_num>f.buy_num*/
        $list = M('goods')
            ->alias('g')
            ->join('teamlist f', 'g.goods_id = f.goods_id', 'inner')
            ->where(" g.store_id=" . $id . " and g.is_on_sale=1   and f.show_time<" . $now_time . " and f.end_time>" . $now_time . $where)
            ->where("g.on_time<".$tt." and (g.down_time>".$tt." or g.down_time=0 )")
            ->where('f.is_show=1 and f.is_end=0')
            ->order('f.ordid')
            ->limit($Page->firstRow . ',' . $Page->listRows)
            ->select();

        foreach ($list as $item) {
            $item['cur_num'] = $item['goods_num'] - $item['buy_num'];
            $list1[] = $item;
        }

        $this->assign('list', $list1);
        $p = I("p/d", 1);

        if ($count <= $p * 10) {
            $this->assign('mshow', 0);
        } else {
            $this->assign('mshow', 1);
        }
        upload_ylp_log('秒杀活动列表');
        return $this->fetch($fname, getMobileStoId());
    }


}