CaiWuXiTong/app/Console/Commands/DownloadModule.php
15061959991 1adf627c0d feat: 财务系统二次开发 - 营销账户账单功能
- 基础环境:Docker 部署配置,源码挂载实时同步
- 修复:super_admin 权限补全、登录重定向循环
- 开发:店铺营销账户账单 - 抖音账户(15字段汇总账单)
- 开发:店铺营销账户账单 - 淘系支付宝账户(8字段流水账单)
- 开发:店铺营销账户账单 - 拼多多账户(7字段流水账单)
- 业务页面导航集成:config/business_navigation.php + Business\Pages 控制器
- 各平台独立表结构和视图,互不影响
2026-07-21 18:43:52 +08:00

131 lines
2.7 KiB
PHP

<?php
namespace App\Console\Commands;
use App\Jobs\Install\CopyFiles;
use App\Jobs\Install\DownloadFile;
use App\Jobs\Install\UnzipFile;
use App\Traits\Jobs;
use App\Utilities\Versions;
use Illuminate\Console\Command;
class DownloadModule extends Command
{
use Jobs;
const CMD_SUCCESS = 0;
const CMD_ERROR = 1;
public $alias;
public $company;
/**
* The name and signature of the console command.
*
* @var string
*/
protected $signature = 'module:download {alias} {company}';
/**
* The console command description.
*
* @var string
*/
protected $description = 'Download the specified module.';
/**
* Execute the console command.
*
* @return mixed
*/
public function handle()
{
set_time_limit(3600); // 1 hour
$this->alias = $this->argument('alias');
$this->company = $this->argument('company');
company($this->company)->makeCurrent();
if (!$path = $this->download()) {
return self::CMD_ERROR;
}
if (!$this->unzip($path)) {
return self::CMD_ERROR;
}
if (!$this->copyFiles($path)) {
return self::CMD_ERROR;
}
$this->info("Module [{$this->alias}] downloaded!");
return self::CMD_SUCCESS;
}
public function download()
{
$this->info('Downloading module...');
try {
$path = $this->dispatch(new DownloadFile($this->alias, $this->getVersion()));
} catch (\Exception $e) {
$this->error($e->getMessage());
return false;
}
return $path;
}
public function unzip($path)
{
$this->info('Unzipping module...');
try {
$this->dispatch(new UnzipFile($this->alias, $path));
} catch (\Exception $e) {
$this->error($e->getMessage());
return false;
}
return true;
}
public function copyFiles($path)
{
$this->info('Copying module files...');
try {
$this->dispatch(new CopyFiles($this->alias, $path));
event(new \App\Events\Module\Copied($this->alias, $this->company));
} catch (\Exception $e) {
$this->error($e->getMessage());
return false;
}
return true;
}
protected function getVersion()
{
$version = Versions::latest($this->alias);
if (empty($version)) {
$current = '1.0.0';
$url = 'apps/' . $this->alias . '/version/' . $current . '/' . version('short');
$version = Versions::getLatestVersion($url, $current);
}
return $version?->latest;
}
}