This commit is contained in:
weiz 2023-10-27 16:08:19 +08:00
parent 50fc7c1d15
commit af9cfe7ae8
2 changed files with 6 additions and 6 deletions

View File

@ -17,15 +17,15 @@
//添加饲养动物 //添加饲养动物
public function addAnimal(): Json public function addAnimal(): Json
{ {
$params = $this->request->post(['user_id','kind','breed','gender','age','status','weight','pic']); $params = $this->request->post(['user_id','code','kind','breed','gender','age','status','weight','pic']);
if(empty($params['user_id']) || empty($params['kind']) || empty($params['breed']) || empty($params['gender']) || !in_array($params['gender'],[1,2]) || empty($params['age']) || empty($params['status']) || !in_array($params['status'],[1,2,3,4]) || empty($params['weight'])){ if(empty($params['user_id']) || empty($params['code']) || empty($params['kind']) || empty($params['breed']) || empty($params['gender']) || !in_array($params['gender'],[1,2]) || empty($params['age']) || empty($params['status']) || !in_array($params['status'],[1,2,3,4]) || empty($params['weight'])){
return $this->fail('参数错误'); return $this->fail('参数错误');
} }
//写入数据 //写入数据
Db::transaction(function () use($params) { Db::transaction(function () use($params) {
$animalId = Db::name('farmer_animal_breed')->insertGetId([ $animalId = Db::name('farmer_animal_breed')->insertGetId([
'user_id' => $params['user_id'], 'user_id' => $params['user_id'],
'animal_code' => '', 'animal_code' => $params['code'],
'animal_kind' => $params['kind'], 'animal_kind' => $params['kind'],
'animal_breed' => $params['breed'], 'animal_breed' => $params['breed'],
'animal_gender' => $params['gender'], 'animal_gender' => $params['gender'],

View File

@ -17,15 +17,15 @@
//添加饲养家禽 //添加饲养家禽
public function addPoultry(): Json public function addPoultry(): Json
{ {
$params = $this->request->post(['user_id','kind','breed','gender','age','status','weight','pic']); $params = $this->request->post(['user_id','code','kind','breed','gender','age','status','weight','pic']);
if(empty($params['user_id']) || empty($params['kind']) || empty($params['breed']) || empty($params['gender']) || !in_array($params['gender'],[1,2]) || empty($params['age']) || empty($params['status']) || !in_array($params['status'],[1,2,3,4]) || empty($params['weight'])){ if(empty($params['user_id']) || empty($params['code']) || empty($params['kind']) || empty($params['breed']) || empty($params['gender']) || !in_array($params['gender'],[1,2]) || empty($params['age']) || empty($params['status']) || !in_array($params['status'],[1,2,3,4]) || empty($params['weight'])){
return $this->fail('参数错误'); return $this->fail('参数错误');
} }
//写入数据 //写入数据
Db::transaction(function () use($params) { Db::transaction(function () use($params) {
$animalId = Db::name('farmer_poultry_breed')->insertGetId([ $animalId = Db::name('farmer_poultry_breed')->insertGetId([
'user_id' => $params['user_id'], 'user_id' => $params['user_id'],
'code' => '', 'code' => $params['code'],
'kind' => $params['kind'], 'kind' => $params['kind'],
'breed' => $params['breed'], 'breed' => $params['breed'],
'gender' => $params['gender'], 'gender' => $params['gender'],