<?php

/**
 *
 * @author: xaboy<365615158@qq.com>
 * @day: 2017/11/02
 */

namespace app\admin\model\auction;

use crmeb\traits\ModelTrait;
use crmeb\basic\BaseModel;

/**
 * 场馆 Model
 * Class WechatNews
 * @package app\admin\model\wechat
 */
class Auction extends BaseModel
{

    use ModelTrait;

    protected $pk = 'id';

    protected $name = 'auction';



    public static function list($where)
    {
        $model = self::alias('a')
            ->field('a.*, gu.name')
            ->order('a.id DESC')
            ->leftJoin('auction_gu gu', 'a.auction_gu_id = gu.id');

        $model->where(['a.delete_time' => 0]);
        if ($where['auction'])$model->where('a.id|a.nickname' , 'like', '%'.$where['auction'],'%');
        if ($where['auction_id'])$model->where('gu.id' , $where['auction_id']);
        if ($where['page'] && $where['limit']){
            $model->page($where['page'], $where['limit']);
        }else{
            $model->page(20, 1);
        }

        $data['count'] = $model->count();
        $list = $model->select()->toArray();

        $day = strtotime(date('Y-m-d'));
        $tomorrow = strtotime(date('Y-m-d', strtotime('+1 day')));
        foreach ($list as $k => $v){
           $list[$k]['b_count'] = AuctionBooking::where([['create_time', '>=', $day], ['create_time', '<=', $tomorrow], ['auction_id', '=', $list[$k]['id']]])->count();


//           $list[$k]['u_count'] = AuctionBooking::alias('a')
//               ->leftJoin('user u', 'a.uid = u.uid')
//               ->whereOr('u.is_new', 1)
//               ->whereOr([['green_time', '>=', $day], ['green_time', '<=', $tomorrow]])
//               ->where([['date', '>=', $day], ['date', '<=', $tomorrow], ['a.auction_id', '=', $list[$k]['id']]])->count();


        }
        $data['data'] = $list;
        return $data;

    }




}