diff --git a/serve/app/Http/Controllers/Api/UploadController.php b/serve/app/Http/Controllers/Api/UploadController.php index c84775e..dec310f 100644 --- a/serve/app/Http/Controllers/Api/UploadController.php +++ b/serve/app/Http/Controllers/Api/UploadController.php @@ -108,4 +108,17 @@ class UploadController extends Controller return $this->success(); } + + public function upload_file(Request $request) + { + $request->validate([ + 'file' => 'required|', + ]); + $file = $request->file('file'); + $path = $file->store(date('Y/m/d')); + + return $this->success([ + 'path' => $path, + ]); + } } diff --git a/serve/app/Http/Controllers/Api/VersionController.php b/serve/app/Http/Controllers/Api/VersionController.php index 2b8d06d..bd8c421 100644 --- a/serve/app/Http/Controllers/Api/VersionController.php +++ b/serve/app/Http/Controllers/Api/VersionController.php @@ -6,6 +6,7 @@ use App\Http\Controllers\Controller; use App\Models\Version; use Illuminate\Http\JsonResponse; use Illuminate\Http\Request; +use Illuminate\Support\Facades\Storage; use Ugly\Base\Traits\ApiResource; class VersionController extends Controller @@ -44,8 +45,13 @@ class VersionController extends Controller if (! empty($last_version) && $last_version > $version) { return $this->failed("当前版本号{$version}应大于最后一次版本编号{$last_version}"); } + $data = $request->only(array_keys($rules)); - Version::query()->create($request->only(array_keys($rules))); + if (strpos('http',$data['path']) === false) { + $data['path'] = Storage::url($data['path']); + } + + Version::query()->create($data); return $this->success(); } @@ -58,7 +64,12 @@ class VersionController extends Controller ]; $request->validate($rules); - Version::query()->where('id', $id)->update($request->only(array_keys($rules))); + $data = $request->only(array_keys($rules)); + if (strpos('http',$data['path']) === false) { + $data['path'] = Storage::url($data['path']); + } + + Version::query()->where('id', $id)->update($data); return $this->success(); } diff --git a/serve/app/Http/Controllers/UpgradeController.php b/serve/app/Http/Controllers/UpgradeController.php new file mode 100644 index 0000000..b84d260 --- /dev/null +++ b/serve/app/Http/Controllers/UpgradeController.php @@ -0,0 +1,67 @@ +json(); + if (empty($new_version['path'])) { + return $this->success(['message' => '没有要更新的版本']); + } + + $file = basename($new_version['path']); // 本地文件 + + // 下载文件到本地 + $client = new Client([ + 'timeout' => 600.0, // 设置总的请求超时时间为 60 秒 + 'connect_timeout' => 30.0, // 设置连接超时时间为 30 秒 + ]); + $response = $client->get($new_version['path']); + if ($response->getStatusCode() == 200) { + Storage::put($file, $response->getBody()); + } + $base_path = base_path(); + $base_arr = explode('/', $base_path); + $count = count($base_arr); + $server_str = $base_arr[$count - 1]; + $extractPath = str_replace("/{$server_str}", '', base_path()); // 解压目标目录 + $zipFilePath = Storage::path($file); // ZIP 文件的路径 + // 创建解压目录(如果不存在) + if (! file_exists($extractPath)) { + mkdir($extractPath, 0755, true); + } + + // 解压 ZIP 文件 + $zip = new \ZipArchive; + if ($zip->open($zipFilePath) === true) { + $zip->extractTo($extractPath); + $zip->close(); + + SystemConfig::set(['system_version' => [ + 'version_number' => $new_version['version_number'], + 'version' => $new_version['version'], + ]]); + + return $this->success(); + } + + return $this->failed(); + } +} diff --git a/serve/database/base.sql b/serve/database/base.sql index dbd9ee0..fca480f 100644 --- a/serve/database/base.sql +++ b/serve/database/base.sql @@ -318,6 +318,7 @@ INSERT INTO `migrations` (`id`, `migration`, `batch`) VALUES (14, '2024_04_15_14 INSERT INTO `migrations` (`id`, `migration`, `batch`) VALUES (15, '2024_04_15_143134_create_cards_table', 1); INSERT INTO `migrations` (`id`, `migration`, `batch`) VALUES (16, '2024_04_16_084221_create_vip_logs_table', 1); INSERT INTO `migrations` (`id`, `migration`, `batch`) VALUES (17, '2024_05_08_101122_create_material_categories_table', 1); +INSERT INTO `migrations` (`id`, `migration`, `batch`) VALUES (17, '2025_01_08_011255_create_versions_table', 1); COMMIT; -- ---------------------------- @@ -479,6 +480,8 @@ INSERT INTO `sys_configs` (`slug`, `value`, `desc`, `created_at`, `updated_at`) INSERT INTO `sys_configs` (`slug`, `value`, `desc`, `created_at`, `updated_at`) VALUES ('wechat_pay_mch_id', '', NULL, '2025-01-02 00:04:23', '2025-01-02 00:04:23'); INSERT INTO `sys_configs` (`slug`, `value`, `desc`, `created_at`, `updated_at`) VALUES ('wechat_pay_private_cert', '', NULL, '2025-01-02 00:04:23', '2025-01-02 00:04:23'); INSERT INTO `sys_configs` (`slug`, `value`, `desc`, `created_at`, `updated_at`) VALUES ('wechat_pay_secret_key', '', NULL, '2025-01-02 00:04:23', '2025-01-02 00:04:23'); +INSERT INTO `sys_configs` (`slug`, `value`, `desc`, `created_at`, `updated_at`) VALUES ('system_version', '{\"version_number\":\"1.0.1\",\"version\":1}', NULL, NULL, '2025-01-08 01:53:06'); +INSERT INTO `sys_configs` (`slug`, `value`, `desc`, `created_at`, `updated_at`) VALUES ('upgrade_domain', 'https://huoxing-test.o2.sapuai.com', NULL, NULL, '2025-01-08 01:53:06'); COMMIT; -- ---------------------------- @@ -532,6 +535,27 @@ CREATE TABLE `vip_logs` ( BEGIN; COMMIT; +-- ---------------------------- +-- Table structure for versions +-- ---------------------------- +DROP TABLE IF EXISTS `versions`; +CREATE TABLE `versions` ( + `id` bigint unsigned NOT NULL AUTO_INCREMENT, + `version_number` varchar(255) COLLATE utf8mb4_unicode_ci NOT NULL COMMENT '版本号', + `version` int NOT NULL COMMENT '版本', + `path` varchar(255) COLLATE utf8mb4_unicode_ci NOT NULL COMMENT '安装包', + `created_at` timestamp NULL DEFAULT NULL, + `updated_at` timestamp NULL DEFAULT NULL, + PRIMARY KEY (`id`) +) ENGINE=InnoDB AUTO_INCREMENT=2 DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci; + +-- ---------------------------- +-- Records of versions +-- ---------------------------- +BEGIN; +INSERT INTO `versions` (`id`, `version_number`, `version`, `path`, `created_at`, `updated_at`) VALUES (1, '1.0.1', 1, 'zip.zip', '2025-01-08 01:32:12', '2025-01-08 01:32:12'); +COMMIT; + -- ---------------------------- -- Table structure for vip_packages -- ---------------------------- @@ -552,7 +576,7 @@ CREATE TABLE `vip_packages` ( -- ---------------------------- BEGIN; INSERT INTO `vip_packages` (`id`, `name`, `price`, `level`, `config`, `created_at`, `updated_at`) VALUES (1, '体验套餐', 0, 0, '{\"pre_min\": false, \"support\": true, \"uv_limit\": 9, \"cur_index\": false, \"allow_type\": {\"CLI_QR\": false, \"KING_DOC\": false, \"WORK_WECHAT\": false, \"LANDING_MINI\": false, \"MINI_PROGRAM\": true}, \"count_limit\": 1, \"min_count_limit\": 1, \"min_disabled_check\": true}', '2024-04-11 12:49:52', '2024-09-29 08:28:55'); -INSERT INTO `vip_packages` (`id`, `name`, `price`, `level`, `config`, `created_at`, `updated_at`) VALUES (2, '初级会员', 4300, 1, '{\"pre_min\": true, \"support\": true, \"uv_limit\": 50, \"cur_index\": true, \"allow_type\": {\"CLI_QR\": true, \"KING_DOC\": true, \"WORK_WECHAT\": true, \"LANDING_MINI\": true, \"MINI_PROGRAM\": true}, \"count_limit\": 5, \"min_count_limit\": 5, \"min_disabled_check\": true}', '2024-04-17 14:27:19', '2024-09-29 08:29:32'); +INSERT INTO `vip_packages` (`id`, `name`, `price`, `level`, `config`, `created_at`, `updated_at`) VALUES (2, '初级会员', 4300, 1, '{\"pre_min\": true, \"support\": true, \"uv_limit\": 50, \"cur_index\": true, \"allow_type\": {\"QR_QQ\": true, \"CLI_QR\": true, \"KING_DOC\": true, \"WORK_WECHAT\": true, \"LANDING_MINI\": true, \"MINI_PROGRAM\": true}, \"count_limit\": 5, \"min_count_limit\": 5, \"min_disabled_check\": true}', '2024-04-17 14:27:19', '2025-01-04 02:59:09'); INSERT INTO `vip_packages` (`id`, `name`, `price`, `level`, `config`, `created_at`, `updated_at`) VALUES (3, '高级会员', 29800, 2, '{\"pre_min\": true, \"support\": true, \"uv_limit\": 100000, \"cur_index\": true, \"allow_type\": {\"CLI_QR\": true, \"KING_DOC\": true, \"WORK_WECHAT\": true, \"LANDING_MINI\": true, \"MINI_PROGRAM\": true}, \"count_limit\": 50, \"min_count_limit\": 10, \"min_disabled_check\": true}', '2024-04-22 17:40:28', '2024-09-29 08:29:49'); COMMIT; diff --git a/serve/routes/api.php b/serve/routes/api.php index 1c4dfdc..3e198c4 100644 --- a/serve/routes/api.php +++ b/serve/routes/api.php @@ -105,7 +105,7 @@ Route::middleware(ApiAuth::class.':admin')->group(function (Router $router) { $router->get('/commission-logs/{user_id}', [CommissionController::class, 'agent_logs']); // 代理商佣金记录 $router->apiResource('version', VersionController::class); - + $router->post('upload-file', [UploadController::class, 'upload_file']); }); Route::get('news_version', [VersionController::class, 'version']); -Route::get('upgrade', [UpgradeController::class, 'index']); +Route::get('upgrade_status', [UpgradeController::class, 'index']);