$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'], 'master_phone' => $params['master_phone'], 'status' => 1, '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: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'], 'master_phone' => $params['master_phone'], 'status' => $params['status'], '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: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 { $data = FenceHouse::findOrEmpty($params['id'])->toArray(); $product = Product::where('fence_house_id', $params['id'])->findOrEmpty()->toArray(); $deviceIds = ProductDevice::where('product_id', $product['id'])->column('device_id'); $device = Device::whereIn('id', $deviceIds)->where('type', 2)->findOrEmpty(); $data['video_url'] = $device['video_url']; $data['device_id'] = $device['id']; return $data; } 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; } }