123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899 |
- <?php
- namespace App\Services;
- use App\Helpers\Utils;
- use App\Services\CallApiService;
- use Exception;
- use Illuminate\Support\Facades\Storage;
- class CacheService
- {
- private $callApiService;
- public function __construct(CallApiService $callApiService)
- {
- $this->callApiService = $callApiService;
- }
- public function putMainMenu()
- {
- $data = $this->callApiService->callApi([
- 'url' => 'igroup-page',
- 'data' => [
- 'PageVars' => [
- 'Limit' => 9999999,
- 'Offset' => 0
- ]
- ],
- ]);
- if ($data['Page']) {
- $mainMenuList = Utils::formatIgroupMenuList($data['Page'], 'IgroupCode');
- $fullFileUrl = "dabory-footage/basic/igroup.json";
- Storage::put($fullFileUrl, json_encode($mainMenuList));
- }
- }
- public function putEtcBrand()
- {
- $data = $this->callApiService->callApi([
- 'url' => 'etc-page',
- 'data' => [
- 'Query' => "status = '0' and select_name = 'brand'",
- 'PageVars' => [
- 'Limit' => 100000,
- ]
- ]
- ]);
- if ($data['Page']) {
- $fullFileUrl = "dabory-footage/basic/etc/brand.json";
- Storage::put($fullFileUrl, json_encode($data));
- }
- }
- public function putSetup()
- {
- $data = $this->callApiService->callApi([
- 'url' => 'setup-page',
- 'data' => [
- 'PageVars' => [
- 'Limit' => 9999999,
- 'Offset' => 0
- ]
- ],
- ]);
- if ($data['Page']) {
- foreach ($data['Page'] as $setup) {
- $setupCode = $setup['SetupCode'];
- $brandCode = $setup['BrandCode'] ? '-'.$setup['BrandCode'] : $setup['BrandCode'];
- $fullFileUrl = "dabory-footage/basic/setup/$setupCode$brandCode.json";
- Storage::put($fullFileUrl, json_encode($setup));
- }
- }
- }
- public function get($fullFileUrl)
- {
- if (Storage::disk()->exists($fullFileUrl)) {
- return json_decode(Storage::get($fullFileUrl), true);
- }
- return null;
- }
- public function getSetup($setupCode, $brandCode = null)
- {
- $brandCode = $brandCode ? '-'.$brandCode : $brandCode;
- $fullFileUrl = "dabory-footage/basic/setup/$setupCode$brandCode.json";
- if (Storage::disk()->exists($fullFileUrl)) {
- $setup = json_decode(Storage::get($fullFileUrl), true);
- return json_decode($setup['SetupJson'], true);
- }
- return null;
- }
- }
|