This commit is contained in:
weiz 2023-10-26 10:20:14 +08:00
parent c2306073a0
commit aa49814d65
5 changed files with 99 additions and 9 deletions

View File

@ -38,7 +38,6 @@
Db::name('farmer_animal_pic')->insert([
'animal_id' => $animalId,
'pic' => $params['pic'],
'type' => 1,
'create_time' => time()
]);
}
@ -101,8 +100,8 @@
//上传动物养殖情况图片
public function addAnimalPic(): Json
{
$params = $this->request->post(['animal_id','pic','type']);
if(empty($params['animal_id']) || empty($params['pic']) || empty($params['type']) || !in_array($params['type'],[1,2])){
$params = $this->request->post(['animal_id','pic']);
if(empty($params['animal_id']) || empty($params['pic'])){
return $this->fail('参数错误');
}
//写入数据

View File

@ -0,0 +1,91 @@
<?php
namespace app\api\controller;
use think\facade\Db;
use think\response\Json;
class FishBreedController extends BaseApiController
{
public array $notNeedLogin = [
'pondInfo',
];
//获取农户池塘信息
public function pondInfo(): Json
{
//获取参数
$params = $this->request->get(['user_id','pond_id']);
if(empty($params['user_id']) || empty($params['pond_id'])){
return $this->fail('参数错误');
}
//获取数据
$url = env('project.worker_domain').'/api/information/farmerPondInfo';
$curl_result = curl_post($url,[],$params);
if($curl_result['code'] == 0){
return $this->fail($curl_result['msg']);
}
//获取种植信息
$pond_fish = Db::name('farmer_fish_breed')->where([
['user_id','=',$params['user_id']],
['pond_id','=',$params['pond_id']],
])->order('id desc')->findOrEmpty();
if(!empty($pond_fish)){
$curl_result['data']['is_fished'] = true;
$curl_result['data']['fish_id'] = $pond_fish['id'];
$curl_result['data']['source_code'] = $pond_fish['source_code'];
$curl_result['data']['kind'] = $pond_fish['kind'];
$curl_result['data']['breed'] = $pond_fish['breed'];
$curl_result['data']['number'] = $pond_fish['number'];
$curl_result['data']['buy_info'] = $pond_fish['buy_info'];
//获取图片
$fish_pic = Db::name('farmer_fish_pic')->field('pic,create_time')->where('fish_id',$pond_fish['id'])->order('id desc')->findOrEmpty();
$curl_result['data']['pic'] = !empty($fish_pic) ? $fish_pic['pic'] : '';
$curl_result['data']['create_time'] = !empty($fish_pic) ? date('Y-m-d H:i:s',$fish_pic['create_time']) : '';
}else{
$curl_result['data']['is_fished'] = false;
}
//返回数据
return $this->success('请求成功',$curl_result['data']);
}
//添加养殖信息
public function addFish(): Json
{
//获取参数
$params = $this->request->post(['user_id','pond_id','kind','breed','number','buy_info','pic']);
if(empty($params['user_id']) || empty($params['pond_id']) || empty($params['kind']) || empty($params['breed']) || empty($params['number']) || empty($params['buy_info'])){
return $this->fail('参数错误');
}
//判断当前土地是否种植作物
$hasRes = Db::name('farmer_land_crop')->where([
['user_id','=',$params['user_id']],
['land_id','=',$params['land_id']],
])->order('id desc')->findOrEmpty();
if(!empty($hasRes) && empty($hasRes['ripe_time']) && empty($hasRes['crop_yield'])){
return $this->fail('该土地已种植');
}
//添加数据
Db::transaction(function () use($params) {
$landCropId = Db::name('farmer_land_crop')->insertGetId([
'user_id' => $params['user_id'],
'land_id' => $params['land_id'],
'source_code' => 'NO'.time(),
'crop_name' => $params['crop_name'],
'crop_variety' => $params['crop_variety'],
'crop_brand' => $params['crop_brand'],
'seed_time' => time(),
'crop_buy_time' => strtotime($params['crop_buy_time'])
]);
if(!empty($params['pic'])){
Db::name('farmer_land_crop_pic')->insert([
'crop_id' => $landCropId,
'pic' => $params['pic'],
'create_time' => time()
]);
}
});
//返回信息
return $this->success('添加成功');
}
}

View File

@ -88,7 +88,6 @@
if(!empty($params['pic'])){
Db::name('farmer_land_crop_pic')->insert([
'crop_id' => $landCropId,
'type' => 1,
'pic' => $params['pic'],
'create_time' => time()
]);
@ -102,8 +101,8 @@
public function addLandCropPic(): Json
{
//获取参数
$params = $this->request->post(['crop_id','pic','type']);
if(empty($params['crop_id']) || empty($params['pic']) || empty($params['type']) || !in_array($params['type'],[1,2,3])){
$params = $this->request->post(['crop_id','pic']);
if(empty($params['crop_id']) || empty($params['pic'])){
return $this->fail('参数错误');
}
//写入数据

View File

@ -38,7 +38,6 @@
Db::name('farmer_poultry_pic')->insert([
'poultry_id' => $animalId,
'pic' => $params['pic'],
'type' => 1,
'create_time' => time()
]);
}
@ -101,8 +100,8 @@
//上传家禽养殖情况图片
public function addPoultryPic(): Json
{
$params = $this->request->post(['poultry_id','pic','type']);
if(empty($params['poultry_id']) || empty($params['pic']) || empty($params['type']) || !in_array($params['type'],[1,2])){
$params = $this->request->post(['poultry_id','pic']);
if(empty($params['poultry_id']) || empty($params['pic'])){
return $this->fail('参数错误');
}
//写入数据

View File

@ -126,6 +126,7 @@ class UserController extends BaseApiController
$item['action_name'] = $val['name'];
}
}
$item['create_time'] = date('Y-m-d H:i:s');
return $item;
});
}
@ -140,6 +141,7 @@ class UserController extends BaseApiController
$item['action_name'] = $val['name'];
}
}
$item['create_time'] = date('Y-m-d H:i:s');
return $item;
});
}