Admin.php 1.9 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273
  1. <?php
  2. namespace app\admins\model;
  3. use think\Db;
  4. use think\Model;
  5. //封装model工具类
  6. class Admin extends Common
  7. {
  8. public function initialize()
  9. {
  10. parent::initialize();
  11. }
  12. //添加,更改==
  13. public function addUpdate($table, $data = null, $id = null)
  14. {
  15. if ($id) {
  16. return Db::name($table)->where('id', $id)->update($data);
  17. }
  18. return Db::name($table)->insertGetId($data);
  19. }
  20. //返回管理员信息
  21. public function findOne($field, $value)
  22. {
  23. return Db::name('admin')->where($field, $value)->find();
  24. }
  25. //验证指定字段
  26. public function checkUserAdmin($field, $value)
  27. {
  28. return Db::name('admin')->field('id')->where($field, $value)->find();
  29. }
  30. //管理员列表
  31. public function getAllUserAdmins()
  32. {
  33. // return Db::name('admin')->field('user_name,password')->select();
  34. return Db::name('admin')->where('status != -1')->order('id desc')->paginate(1000);
  35. }
  36. //返回注册时间===
  37. public function getRegDate($admName)
  38. {
  39. return Db::name('admin')->field('add_time')->where('account', $admName)->find();
  40. }
  41. //登陆验证==
  42. public function getLoginResult($admName, $admPass)
  43. {
  44. return Db::name('admin')->field(['id','position_name','sto_id','identity','serve','code'])->where(['account' => $admName, 'password' => $admPass, 'status' => 1,'status_del'=>1])->find();
  45. }
  46. //删除
  47. public function del($table, $data, $ids = null, $opt = null)
  48. {
  49. //删除
  50. if ($opt) {
  51. return Db::name($table)->where("id in ({$ids})")->delete();
  52. }
  53. return Db::name($table)->where("id in ({$ids})")->update($data);
  54. }
  55. //获取日志
  56. public function getLogs($data)
  57. {
  58. return Db::name('admin_log')->alias('a')->join('admin b', 'a.adm_id = b.id')
  59. ->field('a.*, b.account')->where($data)->order('a.id desc')->paginate(15);
  60. }
  61. }