<?php

namespace app\admin\model;

use think\Model;

class Order extends Model
{
    protected $pk = 'order_id';

    public function user()
    {
        return $this->belongsTo('User', 'user_id', 'user_id');
    }

    public function product()
    {
        return $this->belongsTo('Product', 'product_id', 'product_id');
    }

    public function getOrdList($condition, $fileds = '*', $limit = 10)
    {
        if (empty($condition)) {
            $result = $this
                ->field($fileds)
                ->order('order_id', 'desc')
                ->paginate($limit);
        } else {
            $result = $this
                ->where($condition)
                ->order('order_id', 'desc')
                ->paginate($limit);
        }
        return $result;
    }
    public function countOrder($condition)
    {
        $result = $this
            ->where($condition)
            ->count();
        return $result;
    }

}
