| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384 |
- <?php
- namespace App\Module\Shop\AdminControllers\Tools;
- use App\Module\Game\DCache\ShopItemsJsonConfig;
- use Dcat\Admin\Grid\Tools\AbstractTool;
- use Illuminate\Http\Request;
- use Illuminate\Support\Facades\Log;
- /**
- * 同步商店商品JSON配置表工具
- */
- class SyncShopItemsJsonTool extends AbstractTool
- {
- /**
- * 按钮样式
- *
- * @var string
- */
- protected $style = 'btn btn-success waves-effect';
- /**
- * 按钮标题
- *
- * @return string
- */
- public function title()
- {
- return '同步商品JSON';
- }
- /**
- * 确认提示
- *
- * @return string
- */
- public function confirm()
- {
- return '确定要立即同步商店商品JSON数据吗?';
- }
- /**
- * 处理请求
- *
- * @param Request $request
- * @return \Dcat\Admin\Actions\Response
- */
- public function handle(Request $request)
- {
- try {
- // 强制刷新商店商品JSON配置
- $result = ShopItemsJsonConfig::getData([], true);
-
- if ($result) {
- Log::info('商店商品JSON配置表同步成功', [
- 'operator' => admin_user()->name ?? 'unknown',
- 'time' => now()->toDateTimeString()
- ]);
-
- return $this->response()
- ->success('商店商品JSON配置表同步成功!')
- ->refresh();
- } else {
- Log::error('商店商品JSON配置表同步失败', [
- 'operator' => admin_user()->name ?? 'unknown',
- 'time' => now()->toDateTimeString()
- ]);
-
- return $this->response()
- ->error('商店商品JSON配置表同步失败,请检查日志!');
- }
- } catch (\Exception $e) {
- Log::error('商店商品JSON配置表同步异常', [
- 'error' => $e->getMessage(),
- 'trace' => $e->getTraceAsString(),
- 'operator' => admin_user()->name ?? 'unknown',
- 'time' => now()->toDateTimeString()
- ]);
-
- return $this->response()
- ->error('商店商品JSON配置表同步异常:' . $e->getMessage());
- }
- }
- }
|