fixed
This commit is contained in:
parent
af9cfe7ae8
commit
eda6481f7c
|
@ -8,12 +8,37 @@
|
|||
class AnimalBreedController extends BaseApiController
|
||||
{
|
||||
public array $notNeedLogin = [
|
||||
'addAnimal','animalInfo','animalList','animalSell','animalStatus','animalChangeList',
|
||||
'addAnimal','animalInfo','animalList','animalSell','animalStatus','animalChangeList','animalSearchByCode',
|
||||
'addAnimalPic','animalPicList',
|
||||
'addAnimalRecord','delAnimalRecord','ediAnimalRecord','animalRecordInfo','animalRecordList',
|
||||
'animalEnvData'
|
||||
];
|
||||
|
||||
//获取状态文本
|
||||
private function getStatusText($status): string
|
||||
{
|
||||
//养殖动物状态 1-健康 2-怀孕中 3-生病隔离中 4-可出栏 5-已出栏
|
||||
$str = '';
|
||||
switch ($status) {
|
||||
case 1:
|
||||
$str = '健康';
|
||||
break;
|
||||
case 2:
|
||||
$str = '怀孕中';
|
||||
break;
|
||||
case 3:
|
||||
$str = '生病隔离中';
|
||||
break;
|
||||
case 4:
|
||||
$str = '可出栏';
|
||||
break;
|
||||
case 5:
|
||||
$str = '已出栏';
|
||||
break;
|
||||
}
|
||||
return $str;
|
||||
}
|
||||
|
||||
//添加饲养动物
|
||||
public function addAnimal(): Json
|
||||
{
|
||||
|
@ -86,6 +111,17 @@
|
|||
return $this->success('请求成功',$data);
|
||||
}
|
||||
|
||||
//通过编码查询动物
|
||||
public function animalSearchByCode(): Json
|
||||
{
|
||||
$params = $this->request->get(['code']);
|
||||
if(empty($params['code'])){
|
||||
return $this->fail('参数错误');
|
||||
}
|
||||
$data = Db::name('farmer_animal_breed')->where('animal_code',$params['code'])->findOrEmpty();
|
||||
return $this->success('请求成功',$data);
|
||||
}
|
||||
|
||||
//标记动物为出栏状态
|
||||
public function animalSell(): Json
|
||||
{
|
||||
|
@ -100,11 +136,11 @@
|
|||
//更新动物状态
|
||||
public function animalStatus(): Json
|
||||
{
|
||||
$params = $this->request->post(['animal_id','status','weight','pic']);
|
||||
$params = $this->request->post(['animal_id','status','weight']);
|
||||
if(empty($params['animal_id'])){
|
||||
return $this->fail('参数错误');
|
||||
}
|
||||
if(empty($params['status']) && empty($params['weight']) && empty($params['pic'])){
|
||||
if(empty($params['status']) && empty($params['weight'])){
|
||||
return $this->fail('没有可更改的项');
|
||||
}
|
||||
//获取元数据
|
||||
|
@ -117,23 +153,25 @@
|
|||
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 = [];
|
||||
$textData = [];
|
||||
if(!empty($params['status'])){
|
||||
$updateData['animal_status'] = $params['status'];
|
||||
$textData['状态变更']['原状态'] = $this->getStatusText($data['animal_status']);
|
||||
$textData['状态变更']['新状态'] = $this->getStatusText($params['status']);
|
||||
}
|
||||
if(!empty($params['weight'])){
|
||||
$updateData['animal_weight'] = $params['weight'];
|
||||
$textData['体重变更']['原体重'] = $data['animal_weight'];
|
||||
$textData['体重变更']['新体重'] = $params['weight'];
|
||||
}
|
||||
//设置数据
|
||||
$saveData = [
|
||||
'animal_id' => $params['animal_id'],
|
||||
'action_name' => '生长状态变更',
|
||||
'action_content' => json_encode($textData),
|
||||
'create_time' => time()
|
||||
];
|
||||
Db::transaction(function () use($params,$saveData,$updateData) {
|
||||
Db::name('farmer_animal_status')->insert($saveData);
|
||||
if(!empty($updateData)) {
|
||||
|
|
|
@ -8,12 +8,37 @@
|
|||
class PoultryBreedController extends BaseApiController
|
||||
{
|
||||
public array $notNeedLogin = [
|
||||
'addPoultry','poultryInfo','poultryList','poultrySell','poultryStatus','poultryChangeList',
|
||||
'addPoultry','poultryInfo','poultryList','poultrySell','poultryStatus','poultryChangeList','poultrySearchByCode',
|
||||
'addPoultryPic','poultryPicList',
|
||||
'addPoultryRecord','delPoultryRecord','ediPoultryRecord','poultryRecordInfo','poultryRecordList',
|
||||
'poultryEnvData'
|
||||
];
|
||||
|
||||
//获取状态文本
|
||||
private function getStatusText($status): string
|
||||
{
|
||||
//状态 1-健康 2-产蛋期 3-生病隔离 4-可出栏 5-已出栏
|
||||
$str = '';
|
||||
switch ($status) {
|
||||
case 1:
|
||||
$str = '健康';
|
||||
break;
|
||||
case 2:
|
||||
$str = '产蛋期';
|
||||
break;
|
||||
case 3:
|
||||
$str = '生病隔离中';
|
||||
break;
|
||||
case 4:
|
||||
$str = '可出栏';
|
||||
break;
|
||||
case 5:
|
||||
$str = '已出栏';
|
||||
break;
|
||||
}
|
||||
return $str;
|
||||
}
|
||||
|
||||
//添加饲养家禽
|
||||
public function addPoultry(): Json
|
||||
{
|
||||
|
@ -86,6 +111,17 @@
|
|||
return $this->success('请求成功',$data);
|
||||
}
|
||||
|
||||
//通过编码查询动物
|
||||
public function poultrySearchByCode(): Json
|
||||
{
|
||||
$params = $this->request->get(['code']);
|
||||
if(empty($params['code'])){
|
||||
return $this->fail('参数错误');
|
||||
}
|
||||
$data = Db::name('farmer_poultry_breed')->where('code',$params['code'])->findOrEmpty();
|
||||
return $this->success('请求成功',$data);
|
||||
}
|
||||
|
||||
//更新饲养家禽状态
|
||||
public function poultrySell(): Json
|
||||
{
|
||||
|
@ -100,11 +136,11 @@
|
|||
//更新动物状态
|
||||
public function poultryStatus(): Json
|
||||
{
|
||||
$params = $this->request->post(['poultry_id','status','weight','pic']);
|
||||
$params = $this->request->post(['poultry_id','status','weight']);
|
||||
if(empty($params['poultry_id'])){
|
||||
return $this->fail('参数错误');
|
||||
}
|
||||
if(empty($params['status']) && empty($params['weight']) && empty($params['pic'])){
|
||||
if(empty($params['status']) && empty($params['weight'])){
|
||||
return $this->fail('没有可更改的项');
|
||||
}
|
||||
//获取元数据
|
||||
|
@ -117,27 +153,29 @@
|
|||
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 = [];
|
||||
$textData = [];
|
||||
if(!empty($params['status'])){
|
||||
$updateData['status'] = $params['status'];
|
||||
$textData['状态变更']['原状态'] = $this->getStatusText($data['status']);
|
||||
$textData['状态变更']['新状态'] = $this->getStatusText($params['status']);
|
||||
}
|
||||
if(!empty($params['weight'])){
|
||||
$updateData['weight'] = $params['weight'];
|
||||
$textData['体重变更']['原体重'] = $data['weight'];
|
||||
$textData['体重变更']['新体重'] = $params['weight'];
|
||||
}
|
||||
//设置数据
|
||||
$saveData = [
|
||||
'poultry_id' => $params['poultry_id'],
|
||||
'action_name' => '生长状态变更',
|
||||
'action_content' => json_encode($textData),
|
||||
'create_time' => time()
|
||||
];
|
||||
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);
|
||||
Db::name('farmer_poultry_breed')->where('id', $params['animal_id'])->update($updateData);
|
||||
}
|
||||
});
|
||||
return $this->success('更新成功');
|
||||
|
|
Loading…
Reference in New Issue