From c54325c428b994efc5f75d1cb7740e9cce63d320 Mon Sep 17 00:00:00 2001
From: yaooo <272523191@qq.com>
Date: Thu, 30 Nov 2023 14:58:46 +0800
Subject: [PATCH] =?UTF-8?q?=E6=9B=B4=E6=96=B0=E7=BB=91=E5=AE=9A=E7=8A=B6?=
=?UTF-8?q?=E6=80=81=E5=8F=8A=E6=95=B0=E6=8D=AE=E5=A4=84=E7=90=86?=
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
---
admin/src/views/device/edit.vue | 52 +++++---------
admin/src/views/device/index.vue | 19 +-----
admin/src/views/product/edit.vue | 67 +++++++------------
app/adminapi/logic/device/DeviceLogic.php | 48 +++++++------
app/adminapi/logic/land/ProductLogic.php | 8 ++-
.../validate/land/ProductValidate.php | 6 +-
6 files changed, 78 insertions(+), 122 deletions(-)
diff --git a/admin/src/views/device/edit.vue b/admin/src/views/device/edit.vue
index 4d5cc1f3..98d0329d 100644
--- a/admin/src/views/device/edit.vue
+++ b/admin/src/views/device/edit.vue
@@ -9,7 +9,20 @@
@close="handleClose"
>
-
+
+
+
+
+
+
+
+
+
-
+
-
-
-
-
-
-
-
-
@@ -75,16 +75,6 @@
:value="parseInt(item.value)"
/>
-
-
-
-
-
@@ -125,17 +115,10 @@ const formData = reactive({
monitor_item: '',
status: '',
is_online: '',
- is_bind: '',
})
-
// 表单验证
const formRules = reactive({
- product_id: [{
- required: true,
- message: '请输入产品id',
- trigger: ['blur']
- }],
code: [{
required: true,
message: '请输入设备编码',
@@ -161,11 +144,6 @@ const formRules = reactive({
message: '请选择是否在线',
trigger: ['blur']
}],
- is_bind: [{
- required: true,
- message: '请选择是否绑定土地',
- trigger: ['blur']
- }],
})
diff --git a/admin/src/views/device/index.vue b/admin/src/views/device/index.vue
index e8819089..afcc4eee 100644
--- a/admin/src/views/device/index.vue
+++ b/admin/src/views/device/index.vue
@@ -58,17 +58,6 @@
:value="item.value"
/>
-
-
-
-
-
-
查询
@@ -128,11 +117,6 @@
-
-
-
-
-
@@ -229,8 +213,7 @@ const queryParams = reactive({
name: '',
type: '',
status: '',
- is_online: '',
- is_bind: ''
+ is_online: ''
})
// 选中数据
diff --git a/admin/src/views/product/edit.vue b/admin/src/views/product/edit.vue
index e80d272a..92c144e3 100644
--- a/admin/src/views/product/edit.vue
+++ b/admin/src/views/product/edit.vue
@@ -8,41 +8,31 @@
@confirm="handleSubmit"
@close="handleClose"
>
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
+
+
+
+
+
+
+
+
+
+
+
+
@@ -92,12 +82,7 @@ const formRules = reactive({
required: true,
message: '请输入产品名称',
trigger: ['blur']
- }],
- status: [{
- required: true,
- message: '请选择产品状态',
- trigger: ['blur']
- }],
+ }]
})
diff --git a/app/adminapi/logic/device/DeviceLogic.php b/app/adminapi/logic/device/DeviceLogic.php
index be754da4..4d7d39c4 100644
--- a/app/adminapi/logic/device/DeviceLogic.php
+++ b/app/adminapi/logic/device/DeviceLogic.php
@@ -43,7 +43,10 @@ class DeviceLogic extends BaseLogic
} else {
$params['monitor_item'] = trim($params['monitor_item']);
}
- $userId = Db::name('product')->where('id', $params['product_id'])->value('user_id');
+ $userId = (request()->adminInfo)['user_id'];
+ if (!empty($params['product_id'])) {
+ $userId = Db::name('product')->where('id', $params['product_id'])->value('user_id');
+ }
Db::startTrans();
try {
$device = Device::create([
@@ -54,16 +57,17 @@ class DeviceLogic extends BaseLogic
'monitor_item' => $params['monitor_item'],
'video_url' => $params['video_url'],
'status' => $params['status'],
- 'is_online' => $params['is_online'],
- 'is_bind' => $params['is_bind'],
- ]);
- Db::name('product_device')->insert([
- 'product_id' => $params['product_id'],
- 'device_id' => $device['id'],
- 'device_type' => $params['type'],
- 'create_time' => time(),
- 'update_time' => time()
+ 'is_online' => $params['is_online']
]);
+ if (!empty($params['product_id'])) {
+ Db::name('product_device')->insert([
+ 'product_id' => $params['product_id'],
+ 'device_id' => $device['id'],
+ 'device_type' => $params['type'],
+ 'create_time' => time(),
+ 'update_time' => time()
+ ]);
+ }
Db::commit();
return true;
} catch (\Exception $e) {
@@ -88,7 +92,10 @@ class DeviceLogic extends BaseLogic
} else {
$params['monitor_item'] = trim($params['monitor_item']);
}
- $userId = Db::name('product')->where('id', $params['product_id'])->value('user_id');
+ $userId = (request()->adminInfo)['user_id'];
+ if (!empty($params['product_id'])) {
+ $userId = Db::name('product')->where('id', $params['product_id'])->value('user_id');
+ }
Db::startTrans();
try {
$device = Device::where('id', $params['id'])->update([
@@ -99,17 +106,18 @@ class DeviceLogic extends BaseLogic
'monitor_item' => $params['monitor_item'],
'video_url' => $params['video_url'],
'status' => $params['status'],
- 'is_online' => $params['is_online'],
- 'is_bind' => $params['is_bind'],
+ 'is_online' => $params['is_online']
]);
Db::name('product_device')->where('device_id', $params['id'])->delete();
- Db::name('product_device')->insert([
- 'product_id' => $params['product_id'],
- 'device_id' => $params['id'],
- 'device_type' => $params['type'],
- 'create_time' => time(),
- 'update_time' => time()
- ]);
+ if (!empty($params['product_id'])) {
+ Db::name('product_device')->insert([
+ 'product_id' => $params['product_id'],
+ 'device_id' => $params['id'],
+ 'device_type' => $params['type'],
+ 'create_time' => time(),
+ 'update_time' => time()
+ ]);
+ }
Db::commit();
return true;
} catch (\Exception $e) {
diff --git a/app/adminapi/logic/land/ProductLogic.php b/app/adminapi/logic/land/ProductLogic.php
index 04604eea..bec1ea07 100644
--- a/app/adminapi/logic/land/ProductLogic.php
+++ b/app/adminapi/logic/land/ProductLogic.php
@@ -39,8 +39,10 @@ class ProductLogic extends BaseLogic
public static function add(array $params): bool
{
$userId = (request()->adminInfo)['user_id'];
+ $status = 1;
if (!empty($params['land_id'])) {
$userId = Db::name('land')->where('id', $params['land_id'])->value('user_id');
+ $status = 2;
}
Db::startTrans();
try {
@@ -48,7 +50,7 @@ class ProductLogic extends BaseLogic
'user_id' => $userId,
'code' => $params['code'],
'name' => $params['name'],
- 'status' => $params['status'],
+ 'status' => $status,
]);
if (!empty($params['land_id'])) {
Db::name('land_product')->insert([
@@ -78,8 +80,10 @@ class ProductLogic extends BaseLogic
public static function edit(array $params): bool
{
$userId = (request()->adminInfo)['user_id'];
+ $status = 1;
if (!empty($params['land_id'])) {
$userId = Db::name('land')->where('id', $params['land_id'])->value('user_id');
+ $status = 2;
}
Db::startTrans();
try {
@@ -87,7 +91,7 @@ class ProductLogic extends BaseLogic
'user_id' => $userId,
'code' => $params['code'],
'name' => $params['name'],
- 'status' => $params['status'],
+ 'status' => $status,
]);
Db::name('land_product')->where('product_id', $params['id'])->delete();
if (!empty($params['land_id'])) {
diff --git a/app/adminapi/validate/land/ProductValidate.php b/app/adminapi/validate/land/ProductValidate.php
index 4cda010b..be4d1f22 100644
--- a/app/adminapi/validate/land/ProductValidate.php
+++ b/app/adminapi/validate/land/ProductValidate.php
@@ -35,7 +35,6 @@ class ProductValidate extends BaseValidate
'device_id' => 'require',
'code' => 'require',
'name' => 'require',
- 'status' => 'require',
];
/**
@@ -46,7 +45,6 @@ class ProductValidate extends BaseValidate
'id' => 'id',
'code' => '产品编号',
'name' => '产品名称',
- 'status' => '产品状态',
];
@@ -58,7 +56,7 @@ class ProductValidate extends BaseValidate
*/
public function sceneAdd()
{
- return $this->only(['code','name','status']);
+ return $this->only(['code','name']);
}
@@ -70,7 +68,7 @@ class ProductValidate extends BaseValidate
*/
public function sceneEdit()
{
- return $this->only(['id','code','name','status']);
+ return $this->only(['id','code','name']);
}