wang jun 1 year ago
parent
commit
e1f009ff0c
1 changed files with 86 additions and 0 deletions
  1. 86 0
      application/common/model/Devicelistmodel.php

+ 86 - 0
application/common/model/Devicelistmodel.php

@@ -0,0 +1,86 @@
+<?php
+namespace app\common\model;
+
+use think\Model;
+
+/**
+ * 设备列表
+ *
+ * @author wj
+ * @date 2023-09-28
+ */
+class Devicelistmodel extends Model
+{
+    protected $table = "t_device_list";
+
+    public function insertData($data)
+    {
+        $data = $this->formatData($data);
+        if (empty($data)) {
+            return false;
+        }
+        $id = $this->insertGetId($data);
+        return $id ? $id : false;
+    }
+    public function getList($where = [], $field = "*", $page = 1, $size = 10, $order = "id desc", $group = "", $row = false)
+    {
+        $sqlObj = $this->where($where);
+        if ("count" != $field) {
+            if (empty($size)) {
+                $sqlObj = $sqlObj->field($field)->order($order)->group($group);
+            } else {
+                $sqlObj = $sqlObj->field($field)->order($order)->group($group)->page($page, $size);
+            }
+            if ($row) {
+                $data = $sqlObj->find();
+            } else {
+                $data = $sqlObj->select();
+            }
+        } else {
+            $data = $sqlObj->count();
+        }
+        return $data;
+    }
+
+    public function updateinfo($where, $updateData)
+    {
+        $updateData = $this->formatData($updateData);
+        $row = $this->where($where)->update($updateData);
+        return empty($row) ? false : $row;
+    }
+    private function formatData($data)
+    {
+        $useData = [];
+        $fields = $this->getTableFields();
+        foreach ($data as $key => $value) {
+            if (in_array($key, $fields)) {
+                $useData[$key] = $value;
+            }
+        }
+        return $useData;
+    }
+    public function getInfo($where, $field = "*", $row = true)
+    {
+        $info = $this->field($field)->where($where);
+        if ($row) {
+            $info = $info->find();
+        } else {
+            $info = $info->select();
+        }
+        return empty($info) ? false : $info;
+    }
+    /**
+     * 根据设备号获取用户uid
+     *
+     * @return void
+     * @author wj
+     * @date 2023-09-28
+     */
+    public function getuidbydeviceid($device_id)
+    {
+        $field = ['userid'];
+        $where = ['device_id' => $device_id];
+        $info = $this->field($field)->where($where)->find();
+        return empty($info) ? false : $info['userid'];
+    }
+}