1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586 |
- <?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'];
- }
- }
|