2020-11-25 01:07:06 +00:00
|
|
|
<?php
|
|
|
|
namespace app\model;
|
|
|
|
|
|
|
|
use think\Model;
|
|
|
|
|
|
|
|
class Base extends Model
|
|
|
|
{
|
|
|
|
protected $autoWriteTimestamp = false;
|
|
|
|
//根据Id列表获取列表
|
2020-12-03 08:06:33 +00:00
|
|
|
public static function getListByIds($ids, $order = [])
|
2020-11-25 01:07:06 +00:00
|
|
|
{
|
|
|
|
if(count($ids) == 0 || empty($ids)) {
|
|
|
|
return [];
|
|
|
|
}
|
2020-12-03 08:06:33 +00:00
|
|
|
if(empty($order)) {
|
|
|
|
$order = ['id'=>'asc'];
|
|
|
|
}
|
|
|
|
return self::where('id', 'in', $ids)
|
|
|
|
->order($order)
|
|
|
|
->select()
|
|
|
|
->toArray();
|
2020-11-25 01:07:06 +00:00
|
|
|
}
|
|
|
|
//根据ID获取单条数据
|
|
|
|
public static function getById($id)
|
|
|
|
{
|
|
|
|
if($id <= 0){
|
|
|
|
return [];
|
|
|
|
}
|
|
|
|
return self::where('id', $id)->findOrEmpty()->toArray();
|
|
|
|
}
|
|
|
|
|
|
|
|
//根据ID更新数据
|
|
|
|
public static function updateById($id, $data)
|
|
|
|
{
|
|
|
|
return self::where('id', $id)->update($data);
|
|
|
|
}
|
|
|
|
|
|
|
|
//根据where条件和排序获取记录
|
|
|
|
public static function getListByWhereAndOrder($where, $order, $limit = 1)
|
|
|
|
{
|
|
|
|
return self::where($where)
|
|
|
|
->order($order)
|
|
|
|
->limit($limit)
|
|
|
|
->select()
|
|
|
|
->toArray();
|
|
|
|
}
|
|
|
|
}
|