<?php
declare (strict_types = 1);

namespace app\common\model;

use think\Model;

/**
 * @mixin \think\Model
 */
class BaseModel extends Model
{
    /**
     * 根据主键查询
     */
    public function scopeBypk($query, $pk)
    {
        $query->where((new static)->pk, '=', $pk);
    }

    /**
     * 根据多主键查询
     */
    public function scopeBypks($query, $pks)
    {
        if (!is_array($pks) && (is_string($pks) && false === strpos($pks, ','))) {
            throw new \Exception('pks参数为级数或逗号分隔字符串');
        }
        $query->where((new static)->pk, 'in', $pks);
    }
}
