<?php

namespace app\models\auction;

use app\models\store\StoreProduct;
use crmeb\services\SystemConfigService;
use think\facade\Db;
use crmeb\traits\ModelTrait;
use crmeb\basic\BaseModel;

/**
 * TODO 场馆model
 * Class Article
 * @package app\models\article
 */
class Auction extends BaseModel
{
    /**
     * 数据表主键
     * @var string
     */
    protected $pk = 'id';

    /**
     * 模型名称
     * @var string
     */
    protected $name = 'auction';

    use ModelTrait;


    public function list($data, $uid)
    {
        $model = self::where([['delete_time', '=', 0], ['status' ,'=', '1'], ['auction_gu_id', '=', $data['auction_gu_id']]]);
        $model->page($data['page'], $data['limit']);
        $model->order('id DESC, sort DESC');
        $id = [];
        $booking = AuctionBooking::where([['uid', '=', $uid], ['create_time', '>', strtotime(date('Y-m-d'), time())]])->field('auction_id')->select();
        foreach ($booking as $v) {
            $id[] = $v['auction_id'];
        }
        if ($data['advance']){
            $model->where('id', 'in', $id);
        }
        $list = $model->select();
        $list = count($list) ? $list->toArray() : [];
        if ($list){
            foreach ($list as  $k =>$v)
            {
                if (in_array($v['id'], $id)){
                    $list[$k]['sta'] = 2; // 进入
                    $list[$k]['str'] = '进入';
                }else{
                    $list[$k]['sta'] = 1; // 预约
                    $list[$k]['str'] = '预约';
                }
            }
        }
        return $list;
    }

}
