新增单个动物状态变更记录
This commit is contained in:
parent
b5b1be9578
commit
50fc7c1d15
|
@ -8,7 +8,7 @@
|
|||
class AnimalBreedController extends BaseApiController
|
||||
{
|
||||
public array $notNeedLogin = [
|
||||
'addAnimal','animalInfo','animalList','animalStatus',
|
||||
'addAnimal','animalInfo','animalList','animalSell','animalStatus','animalChangeList',
|
||||
'addAnimalPic','animalPicList',
|
||||
'addAnimalRecord','delAnimalRecord','ediAnimalRecord','animalRecordInfo','animalRecordList',
|
||||
'animalEnvData'
|
||||
|
@ -86,17 +86,81 @@
|
|||
return $this->success('请求成功',$data);
|
||||
}
|
||||
|
||||
//更新饲养动物状态
|
||||
public function animalStatus(): Json
|
||||
//标记动物为出栏状态
|
||||
public function animalSell(): Json
|
||||
{
|
||||
$params = $this->request->post(['animal_id','status']);
|
||||
if(empty($params['animal_id']) || empty($params['status']) || !in_array($params['status'],[1,2,3,4,5])){
|
||||
$params = $this->request->post(['animal_id']);
|
||||
if(empty($params['animal_id'])){
|
||||
return $this->fail('参数错误');
|
||||
}
|
||||
$result = Db::name('farmer_animal_breed')->where('id',$params['animal_id'])->update(['animal_status'=>$params['status']]);
|
||||
$result = Db::name('farmer_animal_breed')->where('id',$params['animal_id'])->update(['animal_status'=>5]);
|
||||
return $result ? $this->success('更新成功') : $this->fail('更新失败');
|
||||
}
|
||||
|
||||
//更新动物状态
|
||||
public function animalStatus(): Json
|
||||
{
|
||||
$params = $this->request->post(['animal_id','status','weight','pic']);
|
||||
if(empty($params['animal_id'])){
|
||||
return $this->fail('参数错误');
|
||||
}
|
||||
if(empty($params['status']) && empty($params['weight']) && empty($params['pic'])){
|
||||
return $this->fail('没有可更改的项');
|
||||
}
|
||||
//获取元数据
|
||||
$data = Db::name('farmer_animal_breed')->where('id',$params['animal_id'])->findOrEmpty();
|
||||
if(empty($data)){
|
||||
return $this->fail('数据错误');
|
||||
}
|
||||
if(isset($params['status']) && !empty($params['status'])){
|
||||
if(!in_array($params['status'],[1,2,3,4])){
|
||||
return $this->fail('状态之错误');
|
||||
}
|
||||
}
|
||||
//设置数据
|
||||
$saveData = [
|
||||
'animal_id' => $params['animal_id'],
|
||||
'old_status' => $data['animal_status'],
|
||||
'new_status' => !empty($params['status']) ? $params['status'] : $data['animal_status'],
|
||||
'old_weight' => $data['animal_weight'],
|
||||
'new_weight' => !empty($params['weight']) ? $params['weight'] : $data['animal_weight'],
|
||||
'pic' => $params['pic'],
|
||||
'create_time' => time()
|
||||
];
|
||||
$updateData = [];
|
||||
if(!empty($params['status'])){
|
||||
$updateData['animal_status'] = $params['status'];
|
||||
}
|
||||
if(!empty($params['weight'])){
|
||||
$updateData['animal_weight'] = $params['weight'];
|
||||
}
|
||||
Db::transaction(function () use($params,$saveData,$updateData) {
|
||||
Db::name('farmer_animal_status')->insert($saveData);
|
||||
if(!empty($updateData)) {
|
||||
Db::name('farmer_animal_breed')->where('id', $params['animal_id'])->update($updateData);
|
||||
}
|
||||
});
|
||||
return $this->success('更新成功');
|
||||
}
|
||||
|
||||
//获取状态列表
|
||||
public function animalChangeList(): Json
|
||||
{
|
||||
$params = $this->request->get(['animal_id','page_no','page_size']);
|
||||
if(empty($params['animal_id'])){
|
||||
return $this->fail('参数错误');
|
||||
}
|
||||
//设置分页条件
|
||||
$pageNo = empty($params['page_no']) || $params['page_no'] < 0 ? 1 : $params['page_no'];
|
||||
$pageSize = empty($params['page_size']) || $params['page_size'] < 0 ? 10 : $params['page_size'];
|
||||
//获取数据
|
||||
$data = Db::name('farmer_animal_status')->where('animal_id',$params['animal_id'])->page($pageNo,$pageSize)->order('create_time desc')->select()->each(function($item){
|
||||
$item['create_time'] = date('Y-m-d H:i:s',$item['create_time']);
|
||||
return $item;
|
||||
})->toArray();
|
||||
return $this->success('请求成功',$data);
|
||||
}
|
||||
|
||||
//上传动物养殖情况图片
|
||||
public function addAnimalPic(): Json
|
||||
{
|
||||
|
|
|
@ -8,7 +8,7 @@
|
|||
class PoultryBreedController extends BaseApiController
|
||||
{
|
||||
public array $notNeedLogin = [
|
||||
'addPoultry','poultryInfo','poultryList','poultryStatus',
|
||||
'addPoultry','poultryInfo','poultryList','poultrySell','poultryStatus','poultryChangeList',
|
||||
'addPoultryPic','poultryPicList',
|
||||
'addPoultryRecord','delPoultryRecord','ediPoultryRecord','poultryRecordInfo','poultryRecordList',
|
||||
'poultryEnvData'
|
||||
|
@ -87,16 +87,80 @@
|
|||
}
|
||||
|
||||
//更新饲养家禽状态
|
||||
public function poultryStatus(): Json
|
||||
public function poultrySell(): Json
|
||||
{
|
||||
$params = $this->request->post(['poultry_id','status']);
|
||||
if(empty($params['poultry_id']) || empty($params['status']) || !in_array($params['status'],[1,2,3,4,5])){
|
||||
$params = $this->request->post(['poultry_id']);
|
||||
if(empty($params['poultry_id'])){
|
||||
return $this->fail('参数错误');
|
||||
}
|
||||
$result = Db::name('farmer_poultry_breed')->where('id',$params['poultry_id'])->update(['status'=>$params['status']]);
|
||||
$result = Db::name('farmer_poultry_breed')->where('id',$params['poultry_id'])->update(['status'=>5]);
|
||||
return $result ? $this->success('更新成功') : $this->fail('更新失败');
|
||||
}
|
||||
|
||||
//更新动物状态
|
||||
public function poultryStatus(): Json
|
||||
{
|
||||
$params = $this->request->post(['poultry_id','status','weight','pic']);
|
||||
if(empty($params['poultry_id'])){
|
||||
return $this->fail('参数错误');
|
||||
}
|
||||
if(empty($params['status']) && empty($params['weight']) && empty($params['pic'])){
|
||||
return $this->fail('没有可更改的项');
|
||||
}
|
||||
//获取元数据
|
||||
$data = Db::name('farmer_poultry_breed')->where('id',$params['poultry_id'])->findOrEmpty();
|
||||
if(empty($data)){
|
||||
return $this->fail('数据错误');
|
||||
}
|
||||
if(isset($params['status']) && !empty($params['status'])){
|
||||
if(!in_array($params['status'],[1,2,3,4])){
|
||||
return $this->fail('状态之错误');
|
||||
}
|
||||
}
|
||||
//设置数据
|
||||
$saveData = [
|
||||
'poultry_id' => $params['poultry_id'],
|
||||
'old_status' => $data['status'],
|
||||
'new_status' => !empty($params['status']) ? $params['status'] : $data['status'],
|
||||
'old_weight' => $data['weight'],
|
||||
'new_weight' => !empty($params['weight']) ? $params['weight'] : $data['weight'],
|
||||
'pic' => $params['pic'],
|
||||
'create_time' => time()
|
||||
];
|
||||
$updateData = [];
|
||||
if(!empty($params['status'])){
|
||||
$updateData['status'] = $params['status'];
|
||||
}
|
||||
if(!empty($params['weight'])){
|
||||
$updateData['weight'] = $params['weight'];
|
||||
}
|
||||
Db::transaction(function () use($params,$saveData,$updateData) {
|
||||
Db::name('farmer_poultry_status')->insert($saveData);
|
||||
if(!empty($updateData)) {
|
||||
Db::name('farmer_poultry_breed')->where('id', $params['poultry_id'])->update($updateData);
|
||||
}
|
||||
});
|
||||
return $this->success('更新成功');
|
||||
}
|
||||
|
||||
//获取状态列表
|
||||
public function poultryChangeList(): Json
|
||||
{
|
||||
$params = $this->request->get(['poultry_id','page_no','page_size']);
|
||||
if(empty($params['poultry_id'])){
|
||||
return $this->fail('参数错误');
|
||||
}
|
||||
//设置分页条件
|
||||
$pageNo = empty($params['page_no']) || $params['page_no'] < 0 ? 1 : $params['page_no'];
|
||||
$pageSize = empty($params['page_size']) || $params['page_size'] < 0 ? 10 : $params['page_size'];
|
||||
//获取数据
|
||||
$data = Db::name('farmer_poultry_status')->where('poultry_id',$params['poultry_id'])->page($pageNo,$pageSize)->order('create_time desc')->select()->each(function($item){
|
||||
$item['create_time'] = date('Y-m-d H:i:s',$item['create_time']);
|
||||
return $item;
|
||||
})->toArray();
|
||||
return $this->success('请求成功',$data);
|
||||
}
|
||||
|
||||
//上传家禽养殖情况图片
|
||||
public function addPoultryPic(): Json
|
||||
{
|
||||
|
|
Loading…
Reference in New Issue