From 924a7c35e84706df8516db35f6afa1d28c79baa7 Mon Sep 17 00:00:00 2001
From: yaooo <272523191@qq.com>
Date: Thu, 30 Nov 2023 12:00:50 +0800
Subject: [PATCH] =?UTF-8?q?=E6=9B=B4=E6=96=B0=E5=9C=9F=E5=9C=B0=E7=BB=91?=
=?UTF-8?q?=E5=AE=9A=E4=BA=A7=E5=93=81?=
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
---
admin/src/api/land.ts | 10 ++
admin/src/views/land/bind.vue | 147 ++++++++++++++++++
admin/src/views/land/index.vue | 28 +++-
admin/src/views/product/edit.vue | 19 +--
admin/src/views/product/index.vue | 16 +-
.../controller/land/LandController.php | 13 ++
app/adminapi/logic/land/LandLogic.php | 42 ++++-
app/adminapi/logic/land/ProductLogic.php | 38 +++--
app/adminapi/validate/land/LandValidate.php | 18 ++-
9 files changed, 285 insertions(+), 46 deletions(-)
create mode 100644 admin/src/views/land/bind.vue
diff --git a/admin/src/api/land.ts b/admin/src/api/land.ts
index b251e26c..1d2a0c1f 100644
--- a/admin/src/api/land.ts
+++ b/admin/src/api/land.ts
@@ -5,6 +5,11 @@ export function getUserList(params: any) {
return request.get({ url: '/user.user/lists', params }, { ignoreCancelToken: true })
}
+// 产品列表列表
+export function apiProductLists(params: any) {
+ return request.get({ url: '/land.product/lists', params })
+}
+
// 土地表列表
export function apiLandLists(params: any) {
console.log(params)
@@ -29,4 +34,9 @@ export function apiLandDelete(params: any) {
// 土地表详情
export function apiLandDetail(params: any) {
return request.get({ url: '/land.land/detail', params })
+}
+
+// 绑定产品
+export function apiLandBind(params: any) {
+ return request.post({ url: '/land.land/bind', params })
}
\ No newline at end of file
diff --git a/admin/src/views/land/bind.vue b/admin/src/views/land/bind.vue
new file mode 100644
index 00000000..381fdefb
--- /dev/null
+++ b/admin/src/views/land/bind.vue
@@ -0,0 +1,147 @@
+
+
+
+
+
diff --git a/admin/src/views/land/index.vue b/admin/src/views/land/index.vue
index 2682404b..62b3e9a7 100644
--- a/admin/src/views/land/index.vue
+++ b/admin/src/views/land/index.vue
@@ -49,16 +49,12 @@
账户: {{ row.user.account }}
-->
-
-
- {{ row.title }}
-
-
+
-
+
编辑
+
+ 绑定产品
+
+
@@ -148,11 +153,14 @@ import { apiLandLists, apiLandDelete } from '@/api/land'
import { timeFormat } from '@/utils/util'
import feedback from '@/utils/feedback'
import EditPopup from './edit.vue'
+import BindPopup from './bind.vue'
const { query } = useRoute()
const editRef = shallowRef>()
+const bindRef = shallowRef>()
// 是否显示编辑框
const showEdit = ref(false)
+const bindEdit = ref(false)
let user_id = query.user_id
if (typeof user_id == 'undefined') {
@@ -215,6 +223,14 @@ const handleEdit = async (data: any) => {
editRef.value?.setFormData(data)
}
+// 绑定
+const handleBind = async (data: any) => {
+ bindEdit.value = true
+ await nextTick()
+ bindRef.value?.open('bind')
+ bindRef.value?.setFormData(data)
+}
+
// 删除
const handleDelete = async (id: number | any[]) => {
await feedback.confirm('确定要删除?')
diff --git a/admin/src/views/product/edit.vue b/admin/src/views/product/edit.vue
index 40d24d3b..e80d272a 100644
--- a/admin/src/views/product/edit.vue
+++ b/admin/src/views/product/edit.vue
@@ -9,7 +9,13 @@
@close="handleClose"
>
-
+
+
+
+
+
+
+
-
-
-
-
-
-
@@ -83,11 +83,6 @@ const formData = reactive({
// 表单验证
const formRules = reactive({
- land_id: [{
- required: true,
- message: '请输入土地id',
- trigger: ['blur']
- }],
code: [{
required: true,
message: '请输入产品编号',
diff --git a/admin/src/views/product/index.vue b/admin/src/views/product/index.vue
index 25a35699..4f3b8dbe 100644
--- a/admin/src/views/product/index.vue
+++ b/admin/src/views/product/index.vue
@@ -84,9 +84,9 @@
{{ row.create_time ? timeFormat(row.create_time, 'yyyy-mm-dd hh:MM:ss') : '' }}
-
+
-
编辑
+
+ 绑定设备
+
- 查看设备
-
+ 设备信息
+
data($result);
}
+ /**
+ * @notes 绑定产品
+ * @return \think\response\Json
+ * @author likeadmin
+ * @date 2023/11/22 16:35
+ */
+ public function bind()
+ {
+ $params = (new LandValidate())->post()->goCheck('bind');
+ LandLogic::bind($params);
+ return $this->success('绑定成功', [], 1, 1);
+ }
+
}
\ No newline at end of file
diff --git a/app/adminapi/logic/land/LandLogic.php b/app/adminapi/logic/land/LandLogic.php
index c4fd3dd1..4bf480c8 100644
--- a/app/adminapi/logic/land/LandLogic.php
+++ b/app/adminapi/logic/land/LandLogic.php
@@ -38,13 +38,14 @@ class LandLogic extends BaseLogic
*/
public static function add(array $params): bool
{
- if ((request()->adminInfo)['root'] != 1) {
- $params['user_id'] = (request()->adminInfo)['user_id'];
+ $userId = (request()->adminInfo)['user_id'];
+ if (!empty($params['user_id'])) {
+ $userId = $params['user_id'];
}
Db::startTrans();
try {
Land::create([
- 'user_id' => $params['user_id'],
+ 'user_id' => $userId,
'title' => $params['title'],
'total_area' => $params['total_area'],
'residual_area' => $params['residual_area'],
@@ -86,13 +87,14 @@ class LandLogic extends BaseLogic
*/
public static function edit(array $params): bool
{
- if ((request()->adminInfo)['root'] != 1) {
- $params['user_id'] = (request()->adminInfo)['user_id'];
+ $userId = (request()->adminInfo)['user_id'];
+ if (!empty($params['user_id'])) {
+ $userId = $params['user_id'];
}
Db::startTrans();
try {
Land::where('id', $params['id'])->update([
- 'user_id' => $params['user_id'],
+ 'user_id' => $userId,
'title' => $params['title'],
'total_area' => $params['total_area'],
'residual_area' => $params['residual_area'],
@@ -149,4 +151,32 @@ class LandLogic extends BaseLogic
{
return Land::findOrEmpty($params['id'])->toArray();
}
+
+ public static function bind($params): bool
+ {
+ $userId = (request()->adminInfo)['user_id'];
+ if (!empty($params['id'])) {
+ $userId = Db::name('land')->where('id', $params['id'])->value('user_id');
+ }
+ Db::startTrans();
+ try {
+ Db::name('product')->where('id', $params['product_id'])->update([
+ 'user_id' => $userId
+ ]);
+ Db::name('land_product')->where('land_id', $params['id'])->delete();
+ Db::name('land_product')->where('product_id', $params['product_id'])->delete();
+ Db::name('land_product')->insert([
+ 'land_id' => $params['id'],
+ 'product_id' => $params['product_id'],
+ 'create_time' => time(),
+ 'update_time' => time()
+ ]);
+ Db::commit();
+ return true;
+ } catch (\Exception $e) {
+ Db::rollback();
+ self::setError($e->getMessage());
+ return false;
+ }
+ }
}
\ No newline at end of file
diff --git a/app/adminapi/logic/land/ProductLogic.php b/app/adminapi/logic/land/ProductLogic.php
index a5363a78..9b5c78df 100644
--- a/app/adminapi/logic/land/ProductLogic.php
+++ b/app/adminapi/logic/land/ProductLogic.php
@@ -38,7 +38,10 @@ class ProductLogic extends BaseLogic
*/
public static function add(array $params): bool
{
- $userId = Db::name('land')->where('id', $params['land_id'])->value('user_id');
+ $userId = (request()->adminInfo)['user_id'];
+ if (!empty($params['land_id'])) {
+ $userId = Db::name('land')->where('id', $params['land_id'])->value('user_id');
+ }
Db::startTrans();
try {
$product = Product::create([
@@ -47,12 +50,14 @@ class ProductLogic extends BaseLogic
'name' => $params['name'],
'status' => $params['status'],
]);
- Db::name('land_product')->insert([
- 'land_id' => $params['land_id'],
- 'product_id' => $product['id'],
- 'create_time' => time(),
- 'update_time' => time()
- ]);
+ if (!empty($params['land_id'])) {
+ Db::name('land_product')->insert([
+ 'land_id' => $params['land_id'],
+ 'product_id' => $product['id'],
+ 'create_time' => time(),
+ 'update_time' => time()
+ ]);
+ }
Db::commit();
return true;
} catch (\Exception $e) {
@@ -72,7 +77,10 @@ class ProductLogic extends BaseLogic
*/
public static function edit(array $params): bool
{
- $userId = Db::name('land')->where('id', $params['land_id'])->value('user_id');
+ $userId = (request()->adminInfo)['user_id'];
+ if (!empty($params['land_id'])) {
+ $userId = Db::name('land')->where('id', $params['land_id'])->value('user_id');
+ }
Db::startTrans();
try {
Product::where('id', $params['id'])->update([
@@ -82,12 +90,14 @@ class ProductLogic extends BaseLogic
'status' => $params['status'],
]);
Db::name('land_product')->where('product_id', $params['id'])->delete();
- Db::name('land_product')->insert([
- 'land_id' => $params['land_id'],
- 'product_id' => $params['id'],
- 'create_time' => time(),
- 'update_time' => time()
- ]);
+ if (!empty($params['land_id'])) {
+ Db::name('land_product')->insert([
+ 'land_id' => $params['land_id'],
+ 'product_id' => $params['id'],
+ 'create_time' => time(),
+ 'update_time' => time()
+ ]);
+ }
Db::commit();
return true;
} catch (\Exception $e) {
diff --git a/app/adminapi/validate/land/LandValidate.php b/app/adminapi/validate/land/LandValidate.php
index 40ae07f5..5232e5dc 100644
--- a/app/adminapi/validate/land/LandValidate.php
+++ b/app/adminapi/validate/land/LandValidate.php
@@ -33,7 +33,7 @@ class LandValidate extends BaseValidate
*/
protected $rule = [
'id' => 'require',
- 'user_id' => 'require',
+ 'product_id' => 'require',
'title' => 'require',
'total_area' => 'require',
'residual_area' => 'require',
@@ -62,7 +62,6 @@ class LandValidate extends BaseValidate
*/
protected $field = [
'id' => 'id',
- 'user_id' => '用户id',
'title' => '土地名称',
'total_area' => '土地面积',
'residual_area' => '剩余面积',
@@ -95,7 +94,7 @@ class LandValidate extends BaseValidate
*/
public function sceneAdd()
{
- return $this->only(['user_id','title','master_name','master_phone']);
+ return $this->only(['title','master_name','master_phone']);
}
@@ -107,7 +106,7 @@ class LandValidate extends BaseValidate
*/
public function sceneEdit()
{
- return $this->only(['id','user_id','title','master_name','master_phone']);
+ return $this->only(['id','title','master_name','master_phone']);
}
@@ -143,4 +142,15 @@ class LandValidate extends BaseValidate
return true;
}
+ /**
+ * @notes 绑定产品
+ * @return LandValidate
+ * @author likeadmin
+ * @date 2023/11/22 16:35
+ */
+ public function sceneBind()
+ {
+ return $this->only(['id', 'product_id']);
+ }
+
}
\ No newline at end of file