manghe/app/common/model/Advert.php
2025-03-31 06:17:21 +00:00

56 lines
1.5 KiB
PHP
Executable File

<?php
namespace app\common\model;
use app\common\model\Base;
use think\Model;
class Advert extends Base
{
// 设置当前模型对应的完整数据表名称
protected $table = 'advert';
/**
* 定义与 AdvertType 模型的多对一关联
*/
public function advertType()
{
// 第一个参数是关联的模型名
// 第二个参数是外键 (Advert 表中的字段,默认为 advert_type_id)
// 第三个参数是关联表的主键 (AdvertType 表中的字段,默认为 id)
// 假设 Advert 表中存储类型 ID 的字段仍然是 'type'
return $this->belongsTo(AdvertType::class, 'type', 'id');
}
/**
* 获取列表
*/
public static function getList($where = [], $field = '*', $order = '', $pageSize = "15")
{
$list = self::where($where)
->field($field)
->order($order)
->paginate(['list_rows' => $pageSize, 'query' => request()->param()]);
$page = $list->render();
$data['list'] = $list->toArray()['data'];
$data['count'] = $list->total();
$data['last_page'] = $list->toArray()['last_page'];
$data['page'] = $page;
return $data;
}
/**
* 获取列表 不分页
*/
public static function getAllList($where = [], $field = '*', $order = '', $limit = '0')
{
$data = self::where($where)
->field($field)
->order($order)
->limit($limit)
->select();
return $data;
}
}