Devicelistmodel.php 2.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586
  1. <?php
  2. namespace app\common\model;
  3. use think\Model;
  4. /**
  5. * 设备列表
  6. *
  7. * @author wj
  8. * @date 2023-09-28
  9. */
  10. class Devicelistmodel extends Model
  11. {
  12. protected $table = "t_device_list";
  13. public function insertData($data)
  14. {
  15. $data = $this->formatData($data);
  16. if (empty($data)) {
  17. return false;
  18. }
  19. $id = $this->insertGetId($data);
  20. return $id ? $id : false;
  21. }
  22. public function getList($where = [], $field = "*", $page = 1, $size = 10, $order = "id desc", $group = "", $row = false)
  23. {
  24. $sqlObj = $this->where($where);
  25. if ("count" != $field) {
  26. if (empty($size)) {
  27. $sqlObj = $sqlObj->field($field)->order($order)->group($group);
  28. } else {
  29. $sqlObj = $sqlObj->field($field)->order($order)->group($group)->page($page, $size);
  30. }
  31. if ($row) {
  32. $data = $sqlObj->find();
  33. } else {
  34. $data = $sqlObj->select();
  35. }
  36. } else {
  37. $data = $sqlObj->count();
  38. }
  39. return $data;
  40. }
  41. public function updateinfo($where, $updateData)
  42. {
  43. $updateData = $this->formatData($updateData);
  44. $row = $this->where($where)->update($updateData);
  45. return empty($row) ? false : $row;
  46. }
  47. private function formatData($data)
  48. {
  49. $useData = [];
  50. $fields = $this->getTableFields();
  51. foreach ($data as $key => $value) {
  52. if (in_array($key, $fields)) {
  53. $useData[$key] = $value;
  54. }
  55. }
  56. return $useData;
  57. }
  58. public function getInfo($where, $field = "*", $row = true)
  59. {
  60. $info = $this->field($field)->where($where);
  61. if ($row) {
  62. $info = $info->find();
  63. } else {
  64. $info = $info->select();
  65. }
  66. return empty($info) ? false : $info;
  67. }
  68. /**
  69. * 根据设备号获取用户uid
  70. *
  71. * @return void
  72. * @author wj
  73. * @date 2023-09-28
  74. */
  75. public function getuidbydeviceid($device_id)
  76. {
  77. $field = ['userid'];
  78. $where = ['device_id' => $device_id];
  79. $info = $this->field($field)->where($where)->find();
  80. return empty($info) ? false : $info['userid'];
  81. }
  82. }