<?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 AuctionProduct extends BaseModel
{

    use ModelTrait;

    protected $pk = 'id';

    protected $name = 'auction_product';
    protected $autoWriteTimestamp = true;


    public static function list($where, $id = 0)
    {

        $model = self::alias('a')
            ->field('a.*,u.nickname, au.nickname as au_name')
            ->order('a.id DESC')
            ->leftJoin('auction au', 'a.auction_id = au.id')
            ->leftJoin('user u', 'a.uid = u.uid');

        if (!empty($id)) {
            $model->where('a.auction_id', '=',$id);
        }
        if (trim($where['auction_id']) != '') {
            $model->where('a.auction_id', '=',$where['auction_id']);
        }
        if (trim(($where['store_name'])) != ''){

            $model->where('a.id|a.name|u.nickname', 'like','%'.$where['store_name'].'%');
        }
        if ($where['page'] && $where['limit']){
            $model->page($where['page'], $where['limit']);
        }else{
            $model->page(20, 1);
        }

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

    }




}