| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112 |
- <?php
- namespace App\Module\Fund\AdminControllers\Tools;
- use App\Module\Game\DCache\FundCurrencyJsonConfig;
- use Dcat\Admin\Grid\Tools\AbstractTool;
- use Illuminate\Http\Request;
- use Illuminate\Support\Facades\Log;
- /**
- * 货币配置表刷新工具
- *
- * 用于在后台管理界面中刷新货币配置表数据
- */
- class RefreshFundCurrencyJsonTool extends AbstractTool
- {
- /**
- * 是否显示按钮
- *
- * @var bool
- */
- protected $shouldDisplay;
- /**
- * 按钮样式
- *
- * @var string
- */
- protected $style = 'btn btn-danger waves-effect';
- /**
- * 构造函数
- *
- * @param bool $shouldDisplay 是否显示按钮
- */
- public function __construct(bool $shouldDisplay = true)
- {
- $this->shouldDisplay = $shouldDisplay;
- }
- /**
- * 按钮标题
- *
- * @return string
- */
- public function title()
- {
- return '立即刷新';
- }
- /**
- * 确认提示
- *
- * @return string
- */
- public function confirm()
- {
- return '确定要立即刷新货币配置JSON数据吗?';
- }
- /**
- * 处理请求
- *
- * @param Request $request
- * @return mixed
- */
- public function handle(Request $request)
- {
- try {
- // 调用命令生成JSON
- $process = new \Symfony\Component\Process\Process(['php', 'artisan', 'fund:generate-currency-json']);
- $process->setWorkingDirectory(base_path());
- $process->run();
- if (!$process->isSuccessful()) {
- return $this->response()->error('刷新失败: ' . $process->getErrorOutput());
- }
- // 强制刷新缓存
- FundCurrencyJsonConfig::getData([], true);
- return $this->response()->success('刷新成功')->refresh();
- } catch (\Exception $e) {
- Log::error('Refresh fund currency JSON exception: '.$e->getMessage());
- return $this->response()->error('刷新失败:'.$e->getMessage());
- }
- }
- /**
- * 渲染按钮
- *
- * @return string
- */
- public function render()
- {
- if (!$this->shouldDisplay) {
- return '';
- }
- return parent::render();
- }
- /**
- * 判断是否应该显示按钮
- *
- * @return bool
- */
- public static function shouldDisplay(): bool
- {
- return true;
- }
- }
|