Sysusermodel.php 2.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182
  1. <?php
  2. /**
  3. * 系统用户
  4. */
  5. namespace app\common\model;
  6. use think\Model;
  7. class Sysusermodel extends Model
  8. {
  9. protected $table = 'sys_user';
  10. public function insertData($data)
  11. {
  12. $field = $this->getTableFields();
  13. $insertData = [];
  14. foreach ($field as $key => $value) {
  15. if (in_array($value, array_keys($data))) {
  16. $insertData[$value] = $data[$value];
  17. }
  18. }
  19. unset($insertData['id']);
  20. $data = $insertData;
  21. $id = $this->insertGetId($data);
  22. return empty($id) ? false : $id;
  23. }
  24. public function getInfo($where, $field = "*", $row = true)
  25. {
  26. $info = $this->field($field)->where($where);
  27. if ($row) {
  28. $info = $info->find();
  29. } else {
  30. $info = $info->select();
  31. }
  32. return empty($info) ? false : $info;
  33. }
  34. public function updateinfo($where, $updateData)
  35. {
  36. $row = $this->where($where)->update($updateData);
  37. return empty($row) ? false : $row;
  38. }
  39. public function deleteinfo($where)
  40. {
  41. $row = $this->where($where)->delete();
  42. return empty($row) ? false : $row;
  43. }
  44. public function getList($where = [], $field = "*", $page = 1, $size = 10, $order = "id desc", $group = "", $row = false)
  45. {
  46. $sqlObj = $this->where($where);
  47. if ("count" != $field) {
  48. $sqlObj = $sqlObj->field($field)->order($order)->group($group)->page($page, $size);
  49. if ($row) {
  50. $data = $sqlObj->find();
  51. } else {
  52. $data = $sqlObj->select();
  53. }
  54. } else {
  55. $data = $sqlObj->count();
  56. }
  57. return $data;
  58. }
  59. /**
  60. * 根据token获取用户信息
  61. *
  62. * @param [type] $token
  63. * @return void
  64. * @author wj
  65. * @date 2023-09-02
  66. */
  67. public function getinfobytoken($token)
  68. {
  69. $where = ['token' => $token];
  70. $field = $this->getTableFields();
  71. unset($field['password']);
  72. $info = $this->field($field)->where($where)->find();
  73. return empty($info) ? false : $info;
  74. }
  75. }