$params['farm_id'], 'animal_name' => $params['animal_name'], 'fence_house_name' => $params['fence_house_name'], 'animal_type' => $params['animal_type'], 'fence_house_type' => $params['fence_house_type'], 'capacity' => $params['capacity'], 'master' => $params['master'], 'status' => $params['status'], 'qr_code' => $params['qr_code'], 'image' => $params['image'], ]); 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:15 */ public static function edit(array $params): bool { Db::startTrans(); try { FenceHouse::where('id', $params['id'])->update([ 'farm_id' => $params['farm_id'], 'animal_name' => $params['animal_name'], 'fence_house_name' => $params['fence_house_name'], 'animal_type' => $params['animal_type'], 'fence_house_type' => $params['fence_house_type'], 'capacity' => $params['capacity'], 'master' => $params['master'], 'status' => $params['status'], 'qr_code' => $params['qr_code'], 'image' => $params['image'], ]); 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:15 */ public static function delete(array $params): bool { return FenceHouse::destroy($params['id']); } /** * @notes 获取详情 * @param $params * @return array * @author likeadmin * @date 2024/01/10 15:15 */ public static function detail($params): array { return FenceHouse::findOrEmpty($params['id'])->toArray(); } public static function datas($params) { $queryWhere = []; if (!empty($params['keyword'])) { $queryWhere[] = ['fence_house_name', 'like', '%' . $params['keyword'] . '%']; } if (!empty($params['user_id'])) { $farmIds = Farm::where('user_id', $params['user_id'])->column('id'); $queryWhere[] = ['farm_id', 'in', $farmIds]; } $lists = FenceHouse::where($queryWhere)->order(['id' => 'desc'])->select()->toArray(); foreach ($lists as &$item) { $item['fencehouseinfo'] = 'ID:' . $item['id'] . ' / 名称:' . $item['fence_house_name']; } return $lists; } }