first commit
This commit is contained in:
64
application/model/AbstractBaseModel.php
Normal file
64
application/model/AbstractBaseModel.php
Normal file
@@ -0,0 +1,64 @@
|
||||
<?php
|
||||
/**
|
||||
* Created by PhpStorm.
|
||||
* User: Administrator
|
||||
* Date: 2018/11/12 0012
|
||||
* Time: 上午 11:05
|
||||
*/
|
||||
namespace app\model;
|
||||
|
||||
use think\Model;
|
||||
|
||||
abstract class AbstractBaseModel extends Model
|
||||
{
|
||||
const LIMIT = 20;
|
||||
|
||||
/**
|
||||
* Store Data
|
||||
*
|
||||
* @time at 2018年11月12日
|
||||
* @param array $data
|
||||
* @return bool
|
||||
*/
|
||||
public function store(array $data)
|
||||
{
|
||||
return $this->save($data) ? $this->id : false;
|
||||
}
|
||||
|
||||
/**
|
||||
* Find By ID
|
||||
*
|
||||
* @time at 2018年11月12日
|
||||
* @param int $id
|
||||
* @return array|false|\PDOStatement|string|\think\Model
|
||||
*/
|
||||
public function findBy(int $id)
|
||||
{
|
||||
return $this->where('id', $id)->find();
|
||||
}
|
||||
|
||||
/**
|
||||
* Update By ID && Data
|
||||
*
|
||||
* @time at 2018年11月12日
|
||||
* @param int $id
|
||||
* @param array $data
|
||||
* @return bool
|
||||
*/
|
||||
public function updateBy(int $id, array $data)
|
||||
{
|
||||
return $this->save($data, ['id' => $id]);
|
||||
}
|
||||
|
||||
/**
|
||||
* Delete By ID
|
||||
*
|
||||
* @time at 2018年11月12日
|
||||
* @param int $id
|
||||
* @return bool|null
|
||||
*/
|
||||
public function deleteBy(int $id)
|
||||
{
|
||||
return $this->where('id', $id)->delete();
|
||||
}
|
||||
}
|
37
application/model/UserModel.php
Normal file
37
application/model/UserModel.php
Normal file
@@ -0,0 +1,37 @@
|
||||
<?php
|
||||
|
||||
namespace app\model;
|
||||
|
||||
use think\permissions\traits\hasRoles;
|
||||
|
||||
class UserModel extends AbstractBaseModel
|
||||
{
|
||||
use hasRoles;
|
||||
|
||||
protected $name = 'users';
|
||||
|
||||
/**
|
||||
* Users List
|
||||
*
|
||||
* @time at 2018年11月14日
|
||||
* @param $params
|
||||
* @return \think\Paginator
|
||||
*/
|
||||
public function getList($params, $limit = self::LIMIT)
|
||||
{
|
||||
if (!count($params)) {
|
||||
return $this->paginate($limit);
|
||||
}
|
||||
|
||||
|
||||
if (isset($params['name'])) {
|
||||
$user = $this->whereLike('name', '%'.$params['name'].'%');
|
||||
}
|
||||
if (isset($params['email'])) {
|
||||
$user = $this->whereLike('email', '%'.$params['email'].'%');
|
||||
}
|
||||
|
||||
return $user->paginate($limit, false, ['query' => request()->param()]);
|
||||
}
|
||||
|
||||
}
|
Reference in New Issue
Block a user