From 4e3353eacde35d52c7ae7ec53753abf0e0503a8c Mon Sep 17 00:00:00 2001 From: yaooo <272523191@qq.com> Date: Fri, 1 Dec 2023 11:36:01 +0800 Subject: [PATCH] =?UTF-8?q?=E6=9B=B4=E6=96=B0=E5=90=8E=E5=8F=B0=E7=AE=A1?= =?UTF-8?q?=E7=90=86=E7=B3=BB=E7=BB=9F=E7=BB=86=E8=8A=82?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../controller/land/LandPlantController.php | 16 ++++++++ app/adminapi/logic/land/LandPlantLogic.php | 39 ++++++++++++++++++- .../validate/land/LandPlantValidate.php | 11 ++++++ 3 files changed, 65 insertions(+), 1 deletion(-) diff --git a/app/adminapi/controller/land/LandPlantController.php b/app/adminapi/controller/land/LandPlantController.php index 4be38ba0..c5a98db2 100644 --- a/app/adminapi/controller/land/LandPlantController.php +++ b/app/adminapi/controller/land/LandPlantController.php @@ -104,5 +104,21 @@ class LandPlantController extends BaseAdminController return $this->data($result); } + /** + * @notes + * @return \think\response\Json + * @author likeadmin + * @date 2023/11/23 11:32 + */ + public function suyuan() + { + $params = (new LandPlantValidate())->goCheck('suyuan'); + $result = LandPlantLogic::suyuan($params); + if (false === $result) { + return $this->fail(LandPlantLogic::getError()); + } + return $this->data($result); + } + } \ No newline at end of file diff --git a/app/adminapi/logic/land/LandPlantLogic.php b/app/adminapi/logic/land/LandPlantLogic.php index 65d6f706..ed54f981 100644 --- a/app/adminapi/logic/land/LandPlantLogic.php +++ b/app/adminapi/logic/land/LandPlantLogic.php @@ -15,8 +15,11 @@ namespace app\adminapi\logic\land; -use app\common\model\land\LandPlant; use app\common\logic\BaseLogic; +use app\common\model\land\LandPlant; +use app\common\model\action\Action; +use app\common\model\land\Land; +use app\common\model\plant\Plant; use think\facade\Db; @@ -125,4 +128,38 @@ class LandPlantLogic extends BaseLogic { return LandPlant::findOrEmpty($params['id'])->toArray(); } + + public static function suyuan($params): array|bool + { + if(empty($params['id'])){ + self::setError('参数错误'); + return false; + } + $plantInfo = Plant::where('id',$params['id'])->findOrEmpty(); + if($plantInfo->isEmpty()){ + self::setError('种植信息错误'); + return false; + } + if($plantInfo['status'] != 2){ + self::setError('种植信息状态错误'); + return false; + } + $landInfo = Land::where('id',$plantInfo['land_id'])->findOrEmpty(); + if($landInfo->isEmpty()){ + self::setError('土地信息错误'); + return false; + } + $plantInfo['pic'] = json_decode($plantInfo['pic'],true); + $plantInfo['plant_date'] = date('Y-m-d',$plantInfo['plant_date']); + $plantInfo['land_name'] = $landInfo['title']; + $plantInfo['land_area'] = $landInfo['total_area']; + $plantInfo['land_address'] = $landInfo['province_name'].$landInfo['city_name'].$landInfo['county_name'].$landInfo['town_name'].$landInfo['village_name'].$landInfo['group_name']; + //获取操作 + $action = Action::field('type,type_text,detail,create_time')->where('plant_id',$params['id'])->select()->each(function($item){ + $item['detail'] = json_decode($item['detail'],true); + return $item; + })->toArray(); + $plantInfo['actions'] = $action; + return $plantInfo->toArray(); + } } \ No newline at end of file diff --git a/app/adminapi/validate/land/LandPlantValidate.php b/app/adminapi/validate/land/LandPlantValidate.php index e57710fc..eaf18b1b 100644 --- a/app/adminapi/validate/land/LandPlantValidate.php +++ b/app/adminapi/validate/land/LandPlantValidate.php @@ -109,4 +109,15 @@ class LandPlantValidate extends BaseValidate return $this->only(['id']); } + /** + * @notes 溯源场景 + * @return LandPlantValidate + * @author likeadmin + * @date 2023/11/23 11:32 + */ + public function sceneSuyuan() + { + return $this->only(['id']); + } + } \ No newline at end of file