123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081 |
- <?php
- namespace app\user\model;
- use think\Model;
- use think\Db;
- use think\Validate;
- use think\Request;
- /**
- * 角色管理
- * @author Superbee
- *
- */
- class Role extends Model{
-
- protected $updateTime = 'update_time'; // 每次更新时间
- protected $autoWriteTimestamp = 'datetime'; // 开启自动写入时间戳字段
-
- public function initialize() {
- parent::initialize();
- }
-
- /**
- * 获取数据信息
- * @param int $page 页码
- * @param array $where 查询条件
- */
- public function getInfo($page, $where = array()){
- return $this->db()
- ->where($where)
- ->page($page, config('paginate.list_rows'))
- ->select();
- }
-
- /**
- * 获取分页信息
- * @param array $where 查询条件
- */
- public function getPage($where = array()){
- $query = getPaginatiorQuery();
- $total = $this->db()->where($where)->count();
- // 查询条件
- $config = ['query'=>$query];
- $paginate = $this->db()->where($where)->paginate(config('paginate.list_rows'), $total, $config);
-
- return $paginate->render();
- }
-
- /**
- * 根据id找到角色
- * @param int $id
- */
- public function getRoleById($id){
- return $this->db()->where(['id'=>$id])->find();
- }
-
- /**
- * 获取所有角色
- * @return array
- */
- public function getAllRole(){
- return $this->db()->where(['status'=>1])->select();
- }
-
- /**
- * 添加和更新的方法
- */
- public function addAndSave(){
- $data = request()->post();
- return $this->allowField(true)->isUpdate($data['id']?true:false)->save($data);
- }
-
- public function remove(){
- $request = Request::instance();
-
- if($request->isPost()) $this->data = $request->post();
- if($request->isGet()) $this->data = $request->get();
-
- return $this->delete();
- }
- }
|