blog/app/model/User.php

49 lines
1.4 KiB
PHP
Raw Permalink Normal View History

2024-06-08 15:54:41 +08:00
<?php
namespace app\model;
use think\Model;
class User extends Model
{
protected $table = 'eb_user';
protected $primaryKey = 'id';
public $timestamps = false;
/**
* User: 高军
* Date: 2024/5/8
* QQ: 2926804347
* @param string $userName
* @return array
* @throws \think\db\exception\DataNotFoundException
* @throws \think\db\exception\DbException
* @throws \think\db\exception\ModelNotFoundException
* Notes:
*/
public function getInfoByUserName(string $userName):array
{
$info = $this->where('delete_time', 0)->where('user_name', $userName)->find();
if ($info) return show(true, '获取成功', $info->toArray());
return show(false, '暂无查询到的数据');
}
/**
* User: 高军
* Date: 2024/5/8
* QQ: 2926804347
* @param array $param
* @return array
* @throws \think\db\exception\DataNotFoundException
* @throws \think\db\exception\DbException
* @throws \think\db\exception\ModelNotFoundException
* Notes:
*/
public function getList(array $param):array
{
$offset = ($param['page'] - 1) * $param['pageSize'];
$data = $this->limit($offset, $param['pageSize'])->select()->toArray();
$count = $this->count();
if ($data) return show(true, '获取成功', ['rows' => $data, 'total' => $count]);
return show(false, '暂无数据');
}
}