From a9f6facd04a7cd5bbf39fa2a3f0aa087d4655531 Mon Sep 17 00:00:00 2001 From: yaooo <272523191@qq.com> Date: Thu, 30 Nov 2023 10:05:04 +0800 Subject: [PATCH] =?UTF-8?q?=E6=9B=B4=E6=96=B0=E7=94=A8=E6=88=B7=E4=BF=A1?= =?UTF-8?q?=E6=81=AF?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- admin/src/views/device/edit.vue | 45 ----------------- admin/src/views/land/edit.vue | 8 +--- admin/src/views/land_plant/edit.vue | 46 ------------------ admin/src/views/land_plant_action/edit.vue | 46 ------------------ admin/src/views/product/edit.vue | 48 +------------------ app/adminapi/lists/land/LandLists.php | 6 ++- app/adminapi/logic/device/DeviceLogic.php | 6 ++- app/adminapi/logic/land/LandLogic.php | 6 +++ .../logic/land/LandPlantActionLogic.php | 6 ++- app/adminapi/logic/land/LandPlantLogic.php | 7 +-- app/adminapi/logic/land/ProductLogic.php | 6 ++- .../validate/land/ProductValidate.php | 6 +-- 12 files changed, 32 insertions(+), 204 deletions(-) diff --git a/admin/src/views/device/edit.vue b/admin/src/views/device/edit.vue index add3e7c6..4d5cc1f3 100644 --- a/admin/src/views/device/edit.vue +++ b/admin/src/views/device/edit.vue @@ -9,24 +9,6 @@ @close="handleClose" > - - - - - { // 表单数据 const formData = reactive({ id: '', - user_id: '', product_id: '', code: '', name: '', @@ -150,11 +131,6 @@ const formData = reactive({ // 表单验证 const formRules = reactive({ - user_id: [{ - required: true, - message: '请输入用户ID', - trigger: ['blur'] - }], product_id: [{ required: true, message: '请输入产品id', @@ -208,29 +184,8 @@ interface ListItem { label: string } const productOptions = ref([]) -const userOptions = ref([]) const loading = ref(false) -const queryUser = async (query: string) => { - if (query) { - loading.value = true - const userList = await getUserList({ - keyword: query - }) - loading.value = false - if (userList.count > 0) { - userOptions.value = userList.lists.map((user: any) => { - return { value: `${user.id}`, label: `ID: ${user.id} / 账户: ${user.account}` } - }) - } else { - userOptions.value = [] - } - loading.value = false - } else { - userOptions.value = [] - } -} - const queryProduct = async (query: string) => { if (query) { loading.value = true diff --git a/admin/src/views/land/edit.vue b/admin/src/views/land/edit.vue index 5246023c..deb12a9e 100644 --- a/admin/src/views/land/edit.vue +++ b/admin/src/views/land/edit.vue @@ -9,7 +9,7 @@ @close="handleClose" > - + { const formData = reactive({ id: '', user_id: '', + root: 0, title: '', total_area: '', residual_area: '', @@ -142,11 +143,6 @@ const formData = reactive({ // 表单验证 const formRules = reactive({ - user_id: [{ - required: true, - message: '请输入用户ID', - trigger: ['blur'] - }], title: [{ required: true, message: '请输入土地名称', diff --git a/admin/src/views/land_plant/edit.vue b/admin/src/views/land_plant/edit.vue index 03ef3b27..1b775428 100644 --- a/admin/src/views/land_plant/edit.vue +++ b/admin/src/views/land_plant/edit.vue @@ -9,25 +9,6 @@ @close="handleClose" > - - - - - - { // 表单数据 const formData = reactive({ id: '', - user_id: '', land_id: '', kind: '', breed: '', @@ -132,11 +112,6 @@ const formData = reactive({ // 表单验证 const formRules = reactive({ - user_id: [{ - required: true, - message: '请输入用户ID', - trigger: ['blur'] - }], land_id: [{ required: true, message: '请输入土地id', @@ -198,29 +173,8 @@ interface ListItem { label: string } const landOptions = ref([]) -const userOptions = ref([]) const loading = ref(false) -const queryUser = async (query: string) => { - if (query) { - loading.value = true - const userList = await getUserList({ - keyword: query - }) - loading.value = false - if (userList.count > 0) { - userOptions.value = userList.lists.map((user: any) => { - return { value: `${user.id}`, label: `ID: ${user.id} / 账户: ${user.account}` } - }) - } else { - userOptions.value = [] - } - loading.value = false - } else { - userOptions.value = [] - } -} - const queryLand = async (query: string) => { if (query) { loading.value = true diff --git a/admin/src/views/land_plant_action/edit.vue b/admin/src/views/land_plant_action/edit.vue index d4a69119..5c000bd3 100644 --- a/admin/src/views/land_plant_action/edit.vue +++ b/admin/src/views/land_plant_action/edit.vue @@ -9,25 +9,6 @@ @close="handleClose" > - - - - - - { // 表单数据 const formData = reactive({ id: '', - user_id: '', plant_id: '', type: '', type_text: '', @@ -103,11 +83,6 @@ const formData = reactive({ // 表单验证 const formRules = reactive({ - user_id: [{ - required: true, - message: '请输入用户ID', - trigger: ['blur'] - }], plant_id: [{ required: true, message: '请输入种植ID', @@ -145,29 +120,8 @@ interface ListItem { label: string } const landPlantOptions = ref([]) -const userOptions = ref([]) const loading = ref(false) -const queryUser = async (query: string) => { - if (query) { - loading.value = true - const userList = await getUserList({ - keyword: query - }) - loading.value = false - if (userList.count > 0) { - userOptions.value = userList.lists.map((user: any) => { - return { value: `${user.id}`, label: `ID: ${user.id} / 账户: ${user.account}` } - }) - } else { - userOptions.value = [] - } - loading.value = false - } else { - userOptions.value = [] - } -} - const queryLandPlant = async (query: string) => { if (query) { loading.value = true diff --git a/admin/src/views/product/edit.vue b/admin/src/views/product/edit.vue index fa353fa5..40d24d3b 100644 --- a/admin/src/views/product/edit.vue +++ b/admin/src/views/product/edit.vue @@ -9,25 +9,6 @@ @close="handleClose" > - - - - - - { // 表单数据 const formData = reactive({ id: '', - user_id: '', land_id: '', code: '', name: '', @@ -103,11 +83,6 @@ const formData = reactive({ // 表单验证 const formRules = reactive({ - user_id: [{ - required: true, - message: '请输入用户id', - trigger: ['blur'] - }], land_id: [{ required: true, message: '请输入土地id', @@ -155,30 +130,9 @@ interface ListItem { value: string label: string } -const userOptions = ref([]) -const loading = ref(false) - -const queryUser = async (query: string) => { - if (query) { - loading.value = true - const userList = await getUserList({ - keyword: query - }) - loading.value = false - if (userList.count > 0) { - userOptions.value = userList.lists.map((user: any) => { - return { value: `${user.id}`, label: `ID: ${user.id} / 账户: ${user.account}` } - }) - } else { - userOptions.value = [] - } - loading.value = false - } else { - userOptions.value = [] - } -} const landOptions = ref([]) +const loading = ref(false) const queryLand = async (query: string) => { if (query) { diff --git a/app/adminapi/lists/land/LandLists.php b/app/adminapi/lists/land/LandLists.php index 147f3718..68815a09 100644 --- a/app/adminapi/lists/land/LandLists.php +++ b/app/adminapi/lists/land/LandLists.php @@ -68,11 +68,15 @@ class LandLists extends BaseAdminDataLists implements ListsSearchInterface */ public function lists(): array { + return Land::where($this->searchWhere)->where($this->userSearch())->with('user') ->field(['id', 'user_id', 'title', 'total_area', 'residual_area', 'province_code', 'province_name', 'city_code', 'city_name', 'county_code', 'county_name', 'town_code', 'town_name', 'village_code', 'village_name', 'group_code', 'group_name', 'longitude', 'latitude', 'master_name', 'master_phone', 'pic']) ->limit($this->limitOffset, $this->limitLength) ->order(['id' => 'desc']) - ->select() + ->select()->each(function($item, $key){ + $item['root'] = $this->adminInfo['root'] ?? 0; + return $item; + }) ->toArray(); } diff --git a/app/adminapi/logic/device/DeviceLogic.php b/app/adminapi/logic/device/DeviceLogic.php index 09a4bdd8..be754da4 100644 --- a/app/adminapi/logic/device/DeviceLogic.php +++ b/app/adminapi/logic/device/DeviceLogic.php @@ -43,10 +43,11 @@ class DeviceLogic extends BaseLogic } else { $params['monitor_item'] = trim($params['monitor_item']); } + $userId = Db::name('product')->where('id', $params['product_id'])->value('user_id'); Db::startTrans(); try { $device = Device::create([ - 'user_id' => $params['user_id'], + 'user_id' => $userId, 'code' => $params['code'], 'name' => $params['name'], 'type' => $params['type'], @@ -87,10 +88,11 @@ class DeviceLogic extends BaseLogic } else { $params['monitor_item'] = trim($params['monitor_item']); } + $userId = Db::name('product')->where('id', $params['product_id'])->value('user_id'); Db::startTrans(); try { $device = Device::where('id', $params['id'])->update([ - 'user_id' => $params['user_id'], + 'user_id' => $userId, 'code' => $params['code'], 'name' => $params['name'], 'type' => $params['type'], diff --git a/app/adminapi/logic/land/LandLogic.php b/app/adminapi/logic/land/LandLogic.php index e9a60b4d..c4fd3dd1 100644 --- a/app/adminapi/logic/land/LandLogic.php +++ b/app/adminapi/logic/land/LandLogic.php @@ -38,6 +38,9 @@ class LandLogic extends BaseLogic */ public static function add(array $params): bool { + if ((request()->adminInfo)['root'] != 1) { + $params['user_id'] = (request()->adminInfo)['user_id']; + } Db::startTrans(); try { Land::create([ @@ -83,6 +86,9 @@ class LandLogic extends BaseLogic */ public static function edit(array $params): bool { + if ((request()->adminInfo)['root'] != 1) { + $params['user_id'] = (request()->adminInfo)['user_id']; + } Db::startTrans(); try { Land::where('id', $params['id'])->update([ diff --git a/app/adminapi/logic/land/LandPlantActionLogic.php b/app/adminapi/logic/land/LandPlantActionLogic.php index 298136da..588ea419 100644 --- a/app/adminapi/logic/land/LandPlantActionLogic.php +++ b/app/adminapi/logic/land/LandPlantActionLogic.php @@ -38,10 +38,11 @@ class LandPlantActionLogic extends BaseLogic */ public static function add(array $params): bool { + $userId = Db::name('land_plant')->where('id', $params['plant_id'])->value('user_id'); Db::startTrans(); try { LandPlantAction::create([ - 'user_id' => $params['user_id'], + 'user_id' => $userId, 'plant_id' => $params['plant_id'], 'type' => $params['type'], 'type_text' => $params['type_text'], @@ -67,10 +68,11 @@ class LandPlantActionLogic extends BaseLogic */ public static function edit(array $params): bool { + $userId = Db::name('land_plant')->where('id', $params['plant_id'])->value('user_id'); Db::startTrans(); try { LandPlantAction::where('id', $params['id'])->update([ - 'user_id' => $params['user_id'], + 'user_id' => $userId, 'plant_id' => $params['plant_id'], 'type' => $params['type'], 'type_text' => $params['type_text'], diff --git a/app/adminapi/logic/land/LandPlantLogic.php b/app/adminapi/logic/land/LandPlantLogic.php index 9a7debcd..65d6f706 100644 --- a/app/adminapi/logic/land/LandPlantLogic.php +++ b/app/adminapi/logic/land/LandPlantLogic.php @@ -28,7 +28,6 @@ use think\facade\Db; class LandPlantLogic extends BaseLogic { - /** * @notes 添加 * @param array $params @@ -38,10 +37,11 @@ class LandPlantLogic extends BaseLogic */ public static function add(array $params): bool { + $userId = Db::name('land')->where('id', $params['land_id'])->value('user_id'); Db::startTrans(); try { LandPlant::create([ - 'user_id' => $params['user_id'], + 'user_id' => $userId, 'land_id' => $params['land_id'], 'kind' => $params['kind'], 'breed' => $params['breed'], @@ -73,10 +73,11 @@ class LandPlantLogic extends BaseLogic */ public static function edit(array $params): bool { + $userId = Db::name('land')->where('id', $params['land_id'])->value('user_id'); Db::startTrans(); try { LandPlant::where('id', $params['id'])->update([ - 'user_id' => $params['user_id'], + 'user_id' => $userId, 'land_id' => $params['land_id'], 'kind' => $params['kind'], 'breed' => $params['breed'], diff --git a/app/adminapi/logic/land/ProductLogic.php b/app/adminapi/logic/land/ProductLogic.php index c2de4658..a5363a78 100644 --- a/app/adminapi/logic/land/ProductLogic.php +++ b/app/adminapi/logic/land/ProductLogic.php @@ -38,10 +38,11 @@ class ProductLogic extends BaseLogic */ public static function add(array $params): bool { + $userId = Db::name('land')->where('id', $params['land_id'])->value('user_id'); Db::startTrans(); try { $product = Product::create([ - 'user_id' => $params['user_id'], + 'user_id' => $userId, 'code' => $params['code'], 'name' => $params['name'], 'status' => $params['status'], @@ -71,10 +72,11 @@ class ProductLogic extends BaseLogic */ public static function edit(array $params): bool { + $userId = Db::name('land')->where('id', $params['land_id'])->value('user_id'); Db::startTrans(); try { Product::where('id', $params['id'])->update([ - 'user_id' => $params['user_id'], + 'user_id' => $userId, 'code' => $params['code'], 'name' => $params['name'], 'status' => $params['status'], diff --git a/app/adminapi/validate/land/ProductValidate.php b/app/adminapi/validate/land/ProductValidate.php index 9a98f7ea..2515f411 100644 --- a/app/adminapi/validate/land/ProductValidate.php +++ b/app/adminapi/validate/land/ProductValidate.php @@ -32,7 +32,6 @@ class ProductValidate extends BaseValidate */ protected $rule = [ 'id' => 'require', - 'user_id' => 'require', 'code' => 'require', 'name' => 'require', 'status' => 'require', @@ -45,7 +44,6 @@ class ProductValidate extends BaseValidate */ protected $field = [ 'id' => 'id', - 'user_id' => '用户id', 'code' => '产品编号', 'name' => '产品名称', 'status' => '产品状态', @@ -60,7 +58,7 @@ class ProductValidate extends BaseValidate */ public function sceneAdd() { - return $this->only(['user_id','code','name','status']); + return $this->only(['code','name','status']); } @@ -72,7 +70,7 @@ class ProductValidate extends BaseValidate */ public function sceneEdit() { - return $this->only(['id','user_id','code','name','status']); + return $this->only(['id','code','name','status']); }