feat: 产品相关接口
This commit is contained in:
31
app/common/model/BaseModel.php
Normal file
31
app/common/model/BaseModel.php
Normal file
@@ -0,0 +1,31 @@
|
||||
<?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);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user