CacheService.php 2.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899
  1. <?php
  2. namespace App\Services;
  3. use App\Helpers\Utils;
  4. use App\Services\CallApiService;
  5. use Exception;
  6. use Illuminate\Support\Facades\Storage;
  7. class CacheService
  8. {
  9. private $callApiService;
  10. public function __construct(CallApiService $callApiService)
  11. {
  12. $this->callApiService = $callApiService;
  13. }
  14. public function putMainMenu()
  15. {
  16. $data = $this->callApiService->callApi([
  17. 'url' => 'igroup-page',
  18. 'data' => [
  19. 'PageVars' => [
  20. 'Limit' => 9999999,
  21. 'Offset' => 0
  22. ]
  23. ],
  24. ]);
  25. if ($data['Page']) {
  26. $mainMenuList = Utils::formatIgroupMenuList($data['Page'], 'IgroupCode');
  27. $fullFileUrl = "dabory-footage/basic/igroup.json";
  28. Storage::put($fullFileUrl, json_encode($mainMenuList));
  29. }
  30. }
  31. public function putEtcBrand()
  32. {
  33. $data = $this->callApiService->callApi([
  34. 'url' => 'etc-page',
  35. 'data' => [
  36. 'Query' => "status = '0' and select_name = 'brand'",
  37. 'PageVars' => [
  38. 'Limit' => 100000,
  39. ]
  40. ]
  41. ]);
  42. if ($data['Page']) {
  43. $fullFileUrl = "dabory-footage/basic/etc/brand.json";
  44. Storage::put($fullFileUrl, json_encode($data));
  45. }
  46. }
  47. public function putSetup()
  48. {
  49. $data = $this->callApiService->callApi([
  50. 'url' => 'setup-page',
  51. 'data' => [
  52. 'PageVars' => [
  53. 'Limit' => 9999999,
  54. 'Offset' => 0
  55. ]
  56. ],
  57. ]);
  58. if ($data['Page']) {
  59. foreach ($data['Page'] as $setup) {
  60. $setupCode = $setup['SetupCode'];
  61. $brandCode = $setup['BrandCode'] ? '-'.$setup['BrandCode'] : $setup['BrandCode'];
  62. $fullFileUrl = "dabory-footage/basic/setup/$setupCode$brandCode.json";
  63. Storage::put($fullFileUrl, json_encode($setup));
  64. }
  65. }
  66. }
  67. public function get($fullFileUrl)
  68. {
  69. if (Storage::disk()->exists($fullFileUrl)) {
  70. return json_decode(Storage::get($fullFileUrl), true);
  71. }
  72. return null;
  73. }
  74. public function getSetup($setupCode, $brandCode = null)
  75. {
  76. $brandCode = $brandCode ? '-'.$brandCode : $brandCode;
  77. $fullFileUrl = "dabory-footage/basic/setup/$setupCode$brandCode.json";
  78. if (Storage::disk()->exists($fullFileUrl)) {
  79. $setup = json_decode(Storage::get($fullFileUrl), true);
  80. return json_decode($setup['SetupJson'], true);
  81. }
  82. return null;
  83. }
  84. }