chaoyu/app/model/Base.php

47 lines
1.1 KiB
PHP

<?php
namespace app\model;
use think\Model;
class Base extends Model
{
protected $autoWriteTimestamp = false;
//根据Id列表获取列表
public static function getListByIds($ids, $order = [])
{
if(count($ids) == 0 || empty($ids)) {
return [];
}
if(empty($order)) {
$order = ['id'=>'asc'];
}
return self::where('id', 'in', $ids)
->order($order)
->select()
->toArray();
}
//根据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();
}
}