FacilityModel.php 2.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384
  1. <?php
  2. namespace app\common\model;
  3. use think\Model;
  4. /**
  5. * 手环设备表
  6. *
  7. * @author wj
  8. * @date 2023-08-14
  9. */
  10. class FacilityModel extends Model
  11. {
  12. protected $table = "t_facility";
  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. /**
  42. * 根据id删除信息
  43. *
  44. * @param [type] $id
  45. * @return void
  46. * @author wj
  47. * @date 2023-08-14
  48. */
  49. public function deleteinfobyid($id)
  50. {
  51. $where = ['id' => $id];
  52. $row = $this->where($where)->delete();
  53. return empty($row) ? false : $row;
  54. }
  55. public function updateinfo($where, $updateData)
  56. {
  57. $row = $this->where($where)->update($updateData);
  58. return empty($row) ? false : $row;
  59. }
  60. private function formatData($data)
  61. {
  62. $useData = [];
  63. $fields = $this->getTableFields();
  64. foreach ($data as $key => $value) {
  65. if (in_array($key, $fields)) {
  66. $useData[$key] = $value;
  67. }
  68. }
  69. return $useData;
  70. }
  71. public function getInfo($where, $field = "*", $row = true)
  72. {
  73. $info = $this->field($field)->where($where);
  74. if ($row) {
  75. $info = $info->find();
  76. } else {
  77. $info = $info->select();
  78. }
  79. return empty($info) ? false : $info;
  80. }
  81. }