新增溯源码管理模块相关接口
This commit is contained in:
parent
18b1d9474c
commit
474affde25
|
@ -41,7 +41,7 @@
|
||||||
}
|
}
|
||||||
Db::name($this->actionDetailTableName)->insertAll($detail);
|
Db::name($this->actionDetailTableName)->insertAll($detail);
|
||||||
});
|
});
|
||||||
return $this->success('添加成功');
|
return $this->success('添加成功',[],1,1);
|
||||||
}
|
}
|
||||||
|
|
||||||
//删除用户操作
|
//删除用户操作
|
||||||
|
@ -59,7 +59,7 @@
|
||||||
//在删除操作信息
|
//在删除操作信息
|
||||||
Db::name($this->actionTableName)->where('id',$params['action_id'])->delete();
|
Db::name($this->actionTableName)->where('id',$params['action_id'])->delete();
|
||||||
});
|
});
|
||||||
return $this->success('删除成功');
|
return $this->success('删除成功',[],1,1);
|
||||||
}
|
}
|
||||||
|
|
||||||
//删除相关信息
|
//删除相关信息
|
||||||
|
@ -73,7 +73,7 @@
|
||||||
//删除数据
|
//删除数据
|
||||||
$delRes = Db::name($this->actionDetailTableName)->where('id',$params['action_detail_id'])->delete();
|
$delRes = Db::name($this->actionDetailTableName)->where('id',$params['action_detail_id'])->delete();
|
||||||
//返回数据
|
//返回数据
|
||||||
return $delRes ? $this->success('删除成功') : $this->fail('删除失败');
|
return $delRes ? $this->success('删除成功',[],1,1) : $this->fail('删除失败',[],1,1);
|
||||||
}
|
}
|
||||||
|
|
||||||
//操作列表
|
//操作列表
|
||||||
|
|
|
@ -25,7 +25,7 @@
|
||||||
//添加数据
|
//添加数据
|
||||||
$addRes = Db::name($this->actionTypeTableName)->insert(['name'=>$params['name']]);
|
$addRes = Db::name($this->actionTypeTableName)->insert(['name'=>$params['name']]);
|
||||||
//返回数据
|
//返回数据
|
||||||
return $addRes ? $this->success('添加成功') : $this->fail('添加失败');
|
return $addRes ? $this->success('添加成功',[],1,1) : $this->fail('添加失败',[],1,1);
|
||||||
}
|
}
|
||||||
|
|
||||||
//修改操作类型
|
//修改操作类型
|
||||||
|
@ -45,7 +45,7 @@
|
||||||
//更新数据
|
//更新数据
|
||||||
$ediRes = Db::name($this->actionTypeTableName)->where('id',$params['id'])->update(['name'=>$params['name']]);
|
$ediRes = Db::name($this->actionTypeTableName)->where('id',$params['id'])->update(['name'=>$params['name']]);
|
||||||
//返回数据
|
//返回数据
|
||||||
return $ediRes ? $this->success('修改成功') : $this->fail('修改失败');
|
return $ediRes ? $this->success('修改成功',[],1,1) : $this->fail('修改失败',[],1,1);
|
||||||
}
|
}
|
||||||
|
|
||||||
//操作记录列表
|
//操作记录列表
|
||||||
|
|
|
@ -118,11 +118,191 @@
|
||||||
return $this->success('请求成功',$result);
|
return $this->success('请求成功',$result);
|
||||||
}
|
}
|
||||||
|
|
||||||
public function detail() {
|
public function detail(): Json
|
||||||
|
{
|
||||||
//type=>1-种植户 2-家禽养殖户 3-家畜养殖户 4-水产养殖户
|
//type=>1-种植户 2-家禽养殖户 3-家畜养殖户 4-水产养殖户
|
||||||
$params = $this->request->get(['id','type']);
|
$params = $this->request->get(['id','type']);
|
||||||
if(empty($params['id']) || empty($params['type']) || !in_array($params['type'],[1,2,3,4])){
|
if(empty($params['id']) || empty($params['type']) || !in_array($params['type'],[1,2,3,4])){
|
||||||
return $this->fail('参数错误');
|
return $this->fail('参数错误');
|
||||||
}
|
}
|
||||||
|
//获取数据
|
||||||
|
switch ($params['type']) {
|
||||||
|
case 1:
|
||||||
|
$data = Db::name('farmer_land_crop')->field('id,user_id,land_id,source_code as code,crop_variety as kind,crop_brand as breed,ripe_time,seed_time as create_time')->where('id',$params['id'])->findOrEmpty();
|
||||||
|
if(!empty($data)){
|
||||||
|
$data['status'] = !empty($data['ripe_time']) ? '已成熟' : '生长中';
|
||||||
|
$data['create_time'] = date('Y-m-d H:i:s',$data['create_time']);
|
||||||
|
unset($data['ripe_time']);
|
||||||
|
//获取生长记录
|
||||||
|
$data['action_lists'] = Db::name('farmer_land_crop_record')->field('action_id,action_content,create_time')
|
||||||
|
->where('crop_id',$data['id'])->order('create_time desc')->limit(10)->select()->each(function($item){
|
||||||
|
$action = Db::name('farmer_action')->where('id',$item['action_id'])->findOrEmpty();
|
||||||
|
if(!empty($action)){
|
||||||
|
$item['action_name'] = $action['name'];
|
||||||
|
}
|
||||||
|
$item['create_time'] = date('Y-m-d H:i:s',$item['create_time']);
|
||||||
|
return $item;
|
||||||
|
})->toArray();
|
||||||
|
//获取监管记录
|
||||||
|
$data['check_list'] = Db::name('farmer_land_check')->field('check_status,pic,create_time')
|
||||||
|
->where('land_id',$data['land_id'])->order('create_time desc')->limit(10)->select()->each(function($item){
|
||||||
|
//1-正常 2-未及时更新生产状况 3-生产状况与实际不符
|
||||||
|
$item['status'] = $item['check_status'] == 1 ? '正常' : ($item['check_status'] == 2 ? '未及时更新生产状况' : '生产状况与实际不符');
|
||||||
|
$item['create_time'] = date('Y-m-d H:i:s',$item['create_time']);
|
||||||
|
unset($item['check_status']);
|
||||||
|
return $item;
|
||||||
|
})->toArray();
|
||||||
|
unset($data['land_id']);
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
case 2:
|
||||||
|
$data = Db::name('farmer_poultry_breed')->field('id,user_id,code,kind,breed,status,create_time')->where('id',$params['id'])->findOrEmpty();
|
||||||
|
if(!empty($data)){
|
||||||
|
switch ($data['status']) {
|
||||||
|
case 1:
|
||||||
|
$data['status'] = '健康';
|
||||||
|
break;
|
||||||
|
case 2:
|
||||||
|
$data['status'] = '产蛋期';
|
||||||
|
break;
|
||||||
|
case 3:
|
||||||
|
$data['status'] = '生病隔离';
|
||||||
|
break;
|
||||||
|
case 4:
|
||||||
|
$data['status'] = '可出栏';
|
||||||
|
break;
|
||||||
|
case 5:
|
||||||
|
$data['status'] = '已出栏';
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
$data['create_time'] = date('Y-m-d H:i:s',$data['create_time']);
|
||||||
|
//获取生长记录
|
||||||
|
$data['action_lists'] = Db::name('farmer_poultry_record')->field('action_id,action_content,create_time')
|
||||||
|
->where('user_id',$data['user_id'])->order('create_time desc')->limit(10)->select()->each(function($item){
|
||||||
|
$action = Db::name('farmer_action')->where('id',$item['action_id'])->findOrEmpty();
|
||||||
|
if(!empty($action)){
|
||||||
|
$item['action_name'] = $action['name'];
|
||||||
|
}
|
||||||
|
$item['create_time'] = date('Y-m-d H:i:s',$item['create_time']);
|
||||||
|
return $item;
|
||||||
|
})->toArray();
|
||||||
|
//获取监管记录
|
||||||
|
$data['check_list'] = Db::name('farmer_poultry_check')->field('check_status,pic,create_time')
|
||||||
|
->where('user_id',$data['user_id'])->order('create_time desc')->limit(10)->select()->each(function($item){
|
||||||
|
//1-正常 2-未及时更新生产状况 3-生产状况与实际不符
|
||||||
|
$item['status'] = $item['check_status'] == 1 ? '正常' : ($item['check_status'] == 2 ? '未及时更新生产状况' : '生产状况与实际不符');
|
||||||
|
$item['create_time'] = date('Y-m-d H:i:s',$item['create_time']);
|
||||||
|
unset($item['check_status']);
|
||||||
|
return $item;
|
||||||
|
})->toArray();
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
case 3:
|
||||||
|
$data = Db::name('farmer_animal_breed')->field('id,user_id,animal_code as code,animal_kind as kind,animal_breed as breed,animal_status as status,create_time')->where('id',$params['id'])->findOrEmpty();
|
||||||
|
if(!empty($data)){
|
||||||
|
switch ($data['status']) {
|
||||||
|
case 1:
|
||||||
|
$data['status'] = '健康';
|
||||||
|
break;
|
||||||
|
case 2:
|
||||||
|
$data['status'] = '怀孕中';
|
||||||
|
break;
|
||||||
|
case 3:
|
||||||
|
$data['status'] = '生病隔离';
|
||||||
|
break;
|
||||||
|
case 4:
|
||||||
|
$data['status'] = '可出栏';
|
||||||
|
break;
|
||||||
|
case 5:
|
||||||
|
$data['status'] = '已出栏';
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
$data['create_time'] = date('Y-m-d H:i:s',$data['create_time']);
|
||||||
|
//获取生长记录
|
||||||
|
$data['action_lists'] = Db::name('farmer_animal_record')->field('action_id,action_content,create_time')
|
||||||
|
->where('user_id',$data['user_id'])->order('create_time desc')->limit(10)->select()->each(function($item){
|
||||||
|
$action = Db::name('farmer_action')->where('id',$item['action_id'])->findOrEmpty();
|
||||||
|
if(!empty($action)){
|
||||||
|
$item['action_name'] = $action['name'];
|
||||||
|
}
|
||||||
|
$item['create_time'] = date('Y-m-d H:i:s',$item['create_time']);
|
||||||
|
return $item;
|
||||||
|
})->toArray();
|
||||||
|
//获取监管记录
|
||||||
|
$data['check_list'] = Db::name('farmer_animal_check')->field('check_status,pic,create_time')
|
||||||
|
->where('user_id',$data['user_id'])->order('create_time desc')->limit(10)->select()->each(function($item){
|
||||||
|
//1-正常 2-未及时更新生产状况 3-生产状况与实际不符
|
||||||
|
$item['status'] = $item['check_status'] == 1 ? '正常' : ($item['check_status'] == 2 ? '未及时更新生产状况' : '生产状况与实际不符');
|
||||||
|
$item['create_time'] = date('Y-m-d H:i:s',$item['create_time']);
|
||||||
|
unset($item['check_status']);
|
||||||
|
return $item;
|
||||||
|
})->toArray();
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
case 4:
|
||||||
|
$data = Db::name('farmer_pond_breed')->field('id,user_id,pond_id,source_code as code,kind,breed,create_time')->where('id',$params['id'])->findOrEmpty();
|
||||||
|
if(!empty($data)){
|
||||||
|
$data['status'] = '生长中';
|
||||||
|
$data['create_time'] = date('Y-m-d H:i:s',$data['create_time']);
|
||||||
|
//获取生长记录
|
||||||
|
$data['action_lists'] = Db::name('farmer_pond_record')->field('action_id,action_content,create_time')
|
||||||
|
->where('pond_id',$data['pond_id'])->order('create_time desc')->limit(10)->select()->each(function($item){
|
||||||
|
$action = Db::name('farmer_action')->where('id',$item['action_id'])->findOrEmpty();
|
||||||
|
if(!empty($action)){
|
||||||
|
$item['action_name'] = $action['name'];
|
||||||
|
}
|
||||||
|
$item['create_time'] = date('Y-m-d H:i:s',$item['create_time']);
|
||||||
|
return $item;
|
||||||
|
})->toArray();
|
||||||
|
//获取监管记录
|
||||||
|
$data['check_list'] = Db::name('farmer_pond_check')->field('check_status,pic,create_time')
|
||||||
|
->where('pond_id',$data['pond_id'])->order('create_time desc')->limit(10)->select()->each(function($item){
|
||||||
|
//1-正常 2-未及时更新生产状况 3-生产状况与实际不符
|
||||||
|
$item['status'] = $item['check_status'] == 1 ? '正常' : ($item['check_status'] == 2 ? '未及时更新生产状况' : '生产状况与实际不符');
|
||||||
|
$item['create_time'] = date('Y-m-d H:i:s',$item['create_time']);
|
||||||
|
unset($item['check_status']);
|
||||||
|
return $item;
|
||||||
|
})->toArray();
|
||||||
|
unset($data['pond_id']);
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
default:
|
||||||
|
$data = [];
|
||||||
|
}
|
||||||
|
if(!empty($data)){
|
||||||
|
$url = env('project.worker_domain').'/api/information/farmerInfo';
|
||||||
|
$farmer = curl_post($url,[],['user_id'=>$data['user_id']]);
|
||||||
|
if(!empty($farmer) && $farmer['code'] == 1){
|
||||||
|
$data['address'] = $farmer['data']['area_name'].$farmer['data']['street_name'].$farmer['data']['village_name'].$farmer['data']['brigade_name'].$farmer['data']['address'];
|
||||||
|
$data['captain_name'] = $farmer['data']['captain_name'];
|
||||||
|
$data['group_name'] = $farmer['data']['group_name'];
|
||||||
|
$data['farmer_name'] = $farmer['data']['name'];
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return $this->success('请求成功',$data);
|
||||||
|
}
|
||||||
|
|
||||||
|
public function landEnv(): Json
|
||||||
|
{
|
||||||
|
$params = $this->request->get(['user_id','start_time','end_time']);
|
||||||
|
if(empty($params['user_id']) || empty($params['start_time']) || empty($params['end_time'])){
|
||||||
|
return $this->fail('参数错误');
|
||||||
|
}
|
||||||
|
//获取数据
|
||||||
|
$data = Db::name('farmer_land_env_data')->where('user_id',$params['user_id'])->whereBetweenTime('create_time', $params['start_time'], $params['end_time'])->order('id asc')->select()->each(function($item){
|
||||||
|
$item['create_time'] = date('m-d',$item['create_time']);
|
||||||
|
return $item;
|
||||||
|
})->toArray();
|
||||||
|
if(empty($data)){
|
||||||
|
return $this->fail('暂无数据');
|
||||||
|
}
|
||||||
|
$result = [
|
||||||
|
['soil_temp' => '土地温度','categories' => array_column($data,'create_time'),'series'=>['name'=>'目标值','data'=>array_column($data,'soil_temp')],'max'=>max(array_column($data,'soil_temp'))],
|
||||||
|
['soil_mois' => '土地湿度','categories' => array_column($data,'create_time'),'series'=>['name'=>'目标值','data'=>array_column($data,'soil_mois')],'max'=>max(array_column($data,'soil_mois'))],
|
||||||
|
['p_content' => '土壤磷含量','categories' => array_column($data,'create_time'),'series'=>['name'=>'目标值','data'=>array_column($data,'p_content')],'max'=>max(array_column($data,'p_content'))],
|
||||||
|
['n_content' => '土壤氮含量','categories' => array_column($data,'create_time'),'series'=>['name'=>'目标值','data'=>array_column($data,'n_content')],'max'=>max(array_column($data,'n_content'))],
|
||||||
|
['k_content' => '土壤钾含量','categories' => array_column($data,'create_time'),'series'=>['name'=>'目标值','data'=>array_column($data,'k_content')],'max'=>max(array_column($data,'k_content'))],
|
||||||
|
];
|
||||||
|
return $this->success('请求成功',$result);
|
||||||
}
|
}
|
||||||
}
|
}
|
|
@ -0,0 +1,10 @@
|
||||||
|
<?php
|
||||||
|
|
||||||
|
namespace app\adminapi\controller\device;
|
||||||
|
|
||||||
|
use app\adminapi\controller\BaseAdminController;
|
||||||
|
|
||||||
|
class DeviceController extends BaseAdminController
|
||||||
|
{
|
||||||
|
|
||||||
|
}
|
Loading…
Reference in New Issue