count(); if ($repeat > 0) { self::setError('耳号已使用'); return false; } Db::startTrans(); try { AnimalInfo::create([ 'fence_house_id' => $params['fence_house_id'], 'sn' => $params['sn'], 'animal_type' => $params['animal_type'], 'brand' => $params['brand'], 'physi_stage' => $params['physi_stage'], 'gender' => $params['gender'], 'blood_purity' => $params['blood_purity'], 'animal_source' => $params['animal_source'], 'current_estimation' => $params['current_estimation'], 'algebra' => $params['algebra'], 'birth' => $params['birth'], 'entry_date' => $params['entry_date'], 'birth_estimation' => $params['birth_estimation'], 'health_condition' => $params['health_condition'], 'pic' => $params['pic'], ]); Db::commit(); return true; } catch (\Exception $e) { Db::rollback(); self::setError($e->getMessage()); return false; } } /** * @notes 编辑 * @param array $params * @return bool * @author likeadmin * @date 2024/01/10 15:53 */ public static function edit(array $params): bool { Db::startTrans(); try { AnimalInfo::where('id', $params['id'])->update([ 'fence_house_id' => $params['fence_house_id'], 'sn' => $params['sn'], 'animal_type' => $params['animal_type'], 'brand' => $params['brand'], 'physi_stage' => $params['physi_stage'], 'gender' => $params['gender'], 'blood_purity' => $params['blood_purity'], 'animal_source' => $params['animal_source'], 'current_estimation' => $params['current_estimation'], 'algebra' => $params['algebra'], 'birth' => $params['birth'], 'entry_date' => $params['entry_date'], 'birth_estimation' => $params['birth_estimation'], 'health_condition' => $params['health_condition'], 'pic' => $params['pic'], ]); Db::commit(); return true; } catch (\Exception $e) { Db::rollback(); self::setError($e->getMessage()); return false; } } /** * @notes 删除 * @param array $params * @return bool * @author likeadmin * @date 2024/01/10 15:53 */ public static function delete(array $params): bool { return AnimalInfo::destroy($params['id']); } /** * @notes 获取详情 * @param $params * @return array * @author likeadmin * @date 2024/01/10 15:53 */ public static function detail($params): array { if (isset($params['sn'])) { return AnimalInfo::with(['fenceHouseAttr'])->where('sn', $params['sn'])->toArray(); } return AnimalInfo::with(['fenceHouseAttr'])->findOrEmpty($params['id'])->toArray(); } }