Role.php 1.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081
  1. <?php
  2. namespace app\user\model;
  3. use think\Model;
  4. use think\Db;
  5. use think\Validate;
  6. use think\Request;
  7. /**
  8. * 角色管理
  9. * @author Superbee
  10. *
  11. */
  12. class Role extends Model{
  13. protected $updateTime = 'update_time'; // 每次更新时间
  14. protected $autoWriteTimestamp = 'datetime'; // 开启自动写入时间戳字段
  15. public function initialize() {
  16. parent::initialize();
  17. }
  18. /**
  19. * 获取数据信息
  20. * @param int $page 页码
  21. * @param array $where 查询条件
  22. */
  23. public function getInfo($page, $where = array()){
  24. return $this->db()
  25. ->where($where)
  26. ->page($page, config('paginate.list_rows'))
  27. ->select();
  28. }
  29. /**
  30. * 获取分页信息
  31. * @param array $where 查询条件
  32. */
  33. public function getPage($where = array()){
  34. $query = getPaginatiorQuery();
  35. $total = $this->db()->where($where)->count();
  36. // 查询条件
  37. $config = ['query'=>$query];
  38. $paginate = $this->db()->where($where)->paginate(config('paginate.list_rows'), $total, $config);
  39. return $paginate->render();
  40. }
  41. /**
  42. * 根据id找到角色
  43. * @param int $id
  44. */
  45. public function getRoleById($id){
  46. return $this->db()->where(['id'=>$id])->find();
  47. }
  48. /**
  49. * 获取所有角色
  50. * @return array
  51. */
  52. public function getAllRole(){
  53. return $this->db()->where(['status'=>1])->select();
  54. }
  55. /**
  56. * 添加和更新的方法
  57. */
  58. public function addAndSave(){
  59. $data = request()->post();
  60. return $this->allowField(true)->isUpdate($data['id']?true:false)->save($data);
  61. }
  62. public function remove(){
  63. $request = Request::instance();
  64. if($request->isPost()) $this->data = $request->post();
  65. if($request->isGet()) $this->data = $request->get();
  66. return $this->delete();
  67. }
  68. }