Compare commits

...

9 Commits

Author SHA1 Message Date
yaooo 57ad0556a2 Merge branch 'dev' of https://gitea.lihaink.cn/weiz/suyuan into yaooo 2023-11-28 13:51:25 +08:00
yaooo 45ee96a193 更新关联删除 2023-11-28 13:51:06 +08:00
weiz d51397ef95 Merge pull request '新增视频监控接口' (#24) from zhangwei into dev
Reviewed-on: #24
2023-11-28 11:28:28 +08:00
weiz 4770d6bef7 新增视频监控接口 2023-11-28 11:27:34 +08:00
weiz 73182f382c Merge pull request 'update' (#23) from zhangwei into dev
Reviewed-on: #23
2023-11-28 10:32:53 +08:00
weiz 5788063a9b update 2023-11-28 10:32:22 +08:00
weiz 3ee3060b9f Merge pull request '新增溯源结果查询接口' (#22) from zhangwei into dev
Reviewed-on: #22
2023-11-28 09:56:22 +08:00
weiz cd0dd00d6d 新增溯源结果查询接口 2023-11-28 09:54:57 +08:00
weiz 84a941a1fc fixed 2023-11-28 09:23:40 +08:00
3 changed files with 73 additions and 10 deletions

View File

@ -16,6 +16,7 @@ namespace app\adminapi\validate\land;
use app\common\validate\BaseValidate; use app\common\validate\BaseValidate;
use think\facade\Db;
/** /**
@ -118,7 +119,7 @@ class LandValidate extends BaseValidate
*/ */
public function sceneDelete() public function sceneDelete()
{ {
return $this->only(['id']); return $this->only(['id'])->append('id', 'require|checkLand');;
} }
@ -133,4 +134,13 @@ class LandValidate extends BaseValidate
return $this->only(['id']); return $this->only(['id']);
} }
public function checkLand($value, $rule, $data)
{
$landProduct = Db::name('land_product')->where('land_id', $value)->findOrEmpty();
if (!empty($landProduct)) {
return '存在关联产品,无法删除';
}
return true;
}
} }

View File

@ -2,11 +2,12 @@
namespace app\api\controller; namespace app\api\controller;
use app\common\enum\notice\NoticeEnum; use app\common\enum\notice\NoticeEnum;
use app\common\model\action\Action;
use app\common\model\device\Device;
use app\common\model\land\Land; use app\common\model\land\Land;
use app\common\model\land\LandProduct; use app\common\model\land\LandProduct;
use app\common\model\monitor\AirMonitor;
use app\common\model\monitor\MonitorData; use app\common\model\monitor\MonitorData;
use app\common\model\monitor\SoilMonitor; use app\common\model\plant\Plant;
use app\common\model\product\ProductDevice; use app\common\model\product\ProductDevice;
use think\facade\Log; use think\facade\Log;
use think\response\Json; use think\response\Json;
@ -22,6 +23,7 @@ class IndexController extends BaseApiController
public array $notNeedLogin = ['code','suYuan']; public array $notNeedLogin = ['code','suYuan'];
//溯源首页
public function index(): Json public function index(): Json
{ {
$params = $this->request->get(['land_id']); $params = $this->request->get(['land_id']);
@ -70,6 +72,31 @@ class IndexController extends BaseApiController
return $this->success('请求成功',$data); return $this->success('请求成功',$data);
} }
//视频监控
public function video() {
$params = $this->request->get(['land_id']);
if(empty($params['land_id'])){
return $this->fail('参数错误');
}
//获取土地绑定的产品
$landProduct = LandProduct::where('land_id',$params['land_id'])->findOrEmpty();
if($landProduct->isEmpty()){
return $this->fail('当前土地未绑定设备产品');
}
//获取监控设备
$productDevice = ProductDevice::where('product_id',$landProduct['product_id'])->where('device_type',3)->findOrEmpty();
if($productDevice->isEmpty()){
return $this->fail('当前土地未绑定监控设备');
}
//获取设备编号
$device = Device::where('id',$productDevice['device_id'])->findOrEmpty();
if($device->isEmpty()){
return $this->fail('监控设备信息错误');
}
//获取监控数据
//todo
}
// 获取短信验证码 // 获取短信验证码
public function code(): Json public function code(): Json
{ {
@ -102,9 +129,34 @@ class IndexController extends BaseApiController
} }
} }
public function suYuan() { public function suYuan(): Json
{
$params = $this->request->get(['plant_id']);
if(empty($params['plant_id'])){
return $this->fail('参数错误');
}
$plantInfo = Plant::where('id',$params['plant_id'])->findOrEmpty();
if($plantInfo->isEmpty()){
return $this->fail('种植信息错误');
}
if($plantInfo['status'] != 2){
return $this->fail('种植信息状态错误');
}
$landInfo = Land::where('id',$plantInfo['land_id'])->findOrEmpty();
if($landInfo->isEmpty()){
return $this->fail('土地信息错误');
}
$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['plant_id'])->select()->each(function($item){
$item['detail'] = json_decode($item['detail'],true);
return $item;
})->toArray();
$plantInfo['actions'] = $action;
return $this->success('请求成功',$plantInfo->toArray());
} }
} }

View File

@ -129,13 +129,14 @@
public function product(): Json public function product(): Json
{ {
$data = Product::field('id as product_id,code,name')->where('status',1)->select()->toArray(); $data = Product::field('id as product_id,code,name')->where('status',1)->select()->toArray();
$result = [];
foreach ($data as $k=>$v) { foreach ($data as $k=>$v) {
$productDevice = ProductDevice::where('product_id',$v['product_id'])->select()->toArray(); $productDevice = ProductDevice::where('product_id',$v['product_id'])->select()->toArray();
if(empty($productDevice)){ if(!empty($productDevice)){
unset($data[$k]); $result[] = $v;
} }
} }
return $this->success('请求成功',$data); return $this->success('请求成功',$result);
} }
//绑定产品 //绑定产品