91 lines
3.2 KiB
PHP
91 lines
3.2 KiB
PHP
|
<?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('添加成功');
|
||
|
}
|
||
|
}
|