SyncShopItemsJsonTool.php 2.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384
  1. <?php
  2. namespace App\Module\Shop\AdminControllers\Tools;
  3. use App\Module\Game\DCache\ShopItemsJsonConfig;
  4. use Dcat\Admin\Grid\Tools\AbstractTool;
  5. use Illuminate\Http\Request;
  6. use Illuminate\Support\Facades\Log;
  7. /**
  8. * 同步商店商品JSON配置表工具
  9. */
  10. class SyncShopItemsJsonTool extends AbstractTool
  11. {
  12. /**
  13. * 按钮样式
  14. *
  15. * @var string
  16. */
  17. protected $style = 'btn btn-success waves-effect';
  18. /**
  19. * 按钮标题
  20. *
  21. * @return string
  22. */
  23. public function title()
  24. {
  25. return '同步商品JSON';
  26. }
  27. /**
  28. * 确认提示
  29. *
  30. * @return string
  31. */
  32. public function confirm()
  33. {
  34. return '确定要立即同步商店商品JSON数据吗?';
  35. }
  36. /**
  37. * 处理请求
  38. *
  39. * @param Request $request
  40. * @return \Dcat\Admin\Actions\Response
  41. */
  42. public function handle(Request $request)
  43. {
  44. try {
  45. // 强制刷新商店商品JSON配置
  46. $result = ShopItemsJsonConfig::getData([], true);
  47. if ($result) {
  48. Log::info('商店商品JSON配置表同步成功', [
  49. 'operator' => admin_user()->name ?? 'unknown',
  50. 'time' => now()->toDateTimeString()
  51. ]);
  52. return $this->response()
  53. ->success('商店商品JSON配置表同步成功!')
  54. ->refresh();
  55. } else {
  56. Log::error('商店商品JSON配置表同步失败', [
  57. 'operator' => admin_user()->name ?? 'unknown',
  58. 'time' => now()->toDateTimeString()
  59. ]);
  60. return $this->response()
  61. ->error('商店商品JSON配置表同步失败,请检查日志!');
  62. }
  63. } catch (\Exception $e) {
  64. Log::error('商店商品JSON配置表同步异常', [
  65. 'error' => $e->getMessage(),
  66. 'trace' => $e->getTraceAsString(),
  67. 'operator' => admin_user()->name ?? 'unknown',
  68. 'time' => now()->toDateTimeString()
  69. ]);
  70. return $this->response()
  71. ->error('商店商品JSON配置表同步异常:' . $e->getMessage());
  72. }
  73. }
  74. }