Utils.php 23 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679
  1. <?php
  2. namespace App\Helpers;
  3. use Illuminate\Support\Str;
  4. use App\Services\CallApiService;
  5. use Illuminate\Support\Collection;
  6. use App\Exceptions\ParameterException;
  7. use Illuminate\Support\Facades\Storage;
  8. use App\Http\Controllers\Api\ApiController;
  9. class Utils
  10. {
  11. public static function getSeoHtml($brandCode = 'common')
  12. {
  13. $response = app(CallApiService::class)->callApi([
  14. 'url' => 'setup-get',
  15. 'data' => [
  16. 'SetupCode' => 'seo-html',
  17. 'BrandCode' => $brandCode
  18. ],
  19. ]);
  20. if (isset($response['PageHtml'])) {
  21. return $response['PageHtml'];
  22. }
  23. }
  24. public static function getSetupParamCache($setupCode)
  25. {
  26. $fullFileUrl = "dabory-footage/setup-page";
  27. if (Storage::disk()->exists($fullFileUrl)) {
  28. $setup = json_decode(Storage::get($fullFileUrl), true);
  29. $findSetup = collect($setup['Page'])->filter(function ($setup) use ($setupCode) {
  30. return $setup['SetupCode'] === $setupCode;
  31. })->first();
  32. return json_decode($findSetup['SetupJson'], true);
  33. }
  34. }
  35. public static function putDirectParamCache($cacheName, $data)
  36. {
  37. $userId = session('user')['UserPermId'] ?? null;
  38. $fullFileUrl = "dabory-footage/users/{$userId}/{$cacheName}.json";
  39. Storage::put($fullFileUrl, $data);
  40. }
  41. public static function getDirectParamCache($cacheName)
  42. {
  43. $userId = session('user')['UserPermId'] ?? null;
  44. $fullFileUrl = "dabory-footage/users/{$userId}/{$cacheName}.json";
  45. if (Storage::disk()->exists($fullFileUrl)) {
  46. return Storage::get($fullFileUrl);
  47. }
  48. return false;
  49. }
  50. public static function getParamCache($menuCode, $fileName, $queryName = null)
  51. {
  52. $userId = session('user')['UserId'] ?? null;
  53. $fullFileUrl = "dabory-footage/users/{$userId}/{$menuCode}-{$fileName}.json";
  54. if (isset($queryName)) {
  55. $fullFileUrl = "dabory-footage/users/{$userId}/{$menuCode}-{$fileName}-{$queryName}.json";
  56. }
  57. if (Storage::disk()->exists($fullFileUrl)) {
  58. return [
  59. 'url' => $fileName,
  60. 'query' => Storage::get($fullFileUrl)
  61. ];
  62. }
  63. return false;
  64. }
  65. public static function getSlipFormInitCache($queryName)
  66. {
  67. $fullFileUrl = "dabory-footage/basic/slip-form-init/{$queryName}.json";
  68. if (Storage::disk()->exists($fullFileUrl)) {
  69. return json_decode(Storage::get($fullFileUrl), true);
  70. }
  71. $response = app(CallApiService::class)->callApi([
  72. 'url' => 'slip-form-init',
  73. 'data' => [
  74. 'QueryVars' => [
  75. 'QueryName' => $queryName
  76. ]
  77. ],
  78. ]);
  79. Storage::put($fullFileUrl, json_encode($response));
  80. return $response;
  81. }
  82. public static function kebabCase($value) {
  83. if (ctype_lower($value)) return $value;
  84. $value = preg_replace('/[\s]+/u', '', ucwords(str_replace('_','-',$value)));
  85. $value = preg_replace('/[\s]+/u', '', ucwords(str_replace('.','-',$value)));
  86. return mb_strtolower(preg_replace('/(.)(?=[A-Z])/u', '$1-', $value), 'UTF-8');
  87. }
  88. public static function snakeCase($value) {
  89. if (ctype_lower($value)) return $value;
  90. $value = preg_replace('/[\s]+/u', '', ucwords(str_replace('-','_',$value)));
  91. $value = preg_replace('/[\s]+/u', '', ucwords(str_replace('.','_',$value)));
  92. return mb_strtolower(preg_replace('/(.)(?=[A-Z])/u', '$1_', $value), 'UTF-8');
  93. }
  94. public static function putParamCache($menuCode, $fileName, $data)
  95. {
  96. $userId = session('user')['UserId'] ?? null;
  97. $fullFileUrl = "dabory-footage/users/{$userId}/{$menuCode}-{$fileName}.json";
  98. if (isset(json_decode($data, true)['QueryVars'])) {
  99. $queryName = json_decode($data, true)['QueryVars']['QueryName'];
  100. $fullFileUrl = "dabory-footage/users/{$userId}/{$menuCode}-{$fileName}-{$queryName}.json";
  101. }
  102. Storage::put($fullFileUrl, $data);
  103. }
  104. public static function getParamUrl(string $settingFileName = '', $extension = '.json')
  105. {
  106. $countryCode = session('user')['CountryCode'] ?? config('constants.countries')[0];
  107. $setPath = "para-local/dabory/erp/{$countryCode}{$settingFileName}{$extension}";
  108. if (file_exists(public_path($setPath))) {
  109. return $setPath;
  110. } else {
  111. $setPath = "para/dabory/erp/{$countryCode}{$settingFileName}{$extension}";
  112. if (file_exists(public_path($setPath))) {
  113. return $setPath;
  114. }
  115. }
  116. return -1;
  117. }
  118. public static function getThemeParamUrl(string $settingFileName = '', $extension = '.json', $themeDir = '')
  119. {
  120. $countryCode = session('user')['CountryCode'] ?? config('constants.countries')[0];
  121. // 이제 안씀
  122. $customTheme = env('ERP_PARA_CUSTOM_THEME');
  123. $localPath = "themes/erp/{$customTheme}/para_custom/{$countryCode}{$settingFileName}{$extension}";
  124. if (file_exists(public_path($localPath))) {
  125. return $localPath;
  126. } else {
  127. $setPath = "themes/{$themeDir}/para/{$countryCode}{$settingFileName}{$extension}";
  128. if (file_exists(public_path($setPath))) {
  129. return $setPath;
  130. }
  131. }
  132. return -1;
  133. }
  134. public static function getParamFile(string $settingFileName = '', $extension = '.json', $popupOptions = false, $mode = 'erp')
  135. {
  136. $countryCode = session('user')['CountryCode'] ?? config('constants.countries')[0];
  137. if ($mode !== 'erp') {
  138. $countryCode = session('member')['CountryCode'] ?? config('constants.countries')[0];
  139. }
  140. $setPath = "para/{$mode}/{$countryCode}{$settingFileName}{$extension}";
  141. if (file_exists(daboryPath($setPath))) {
  142. $paramsFilePath = file_get_contents(daboryPath($setPath));
  143. } else {
  144. $daboryPath = daboryPath($setPath);
  145. if ($popupOptions) {
  146. switch ($popupOptions['OptionsType']) {
  147. case 'SelectPopupOptions':
  148. $msg = '(' . $popupOptions['OptionsType'] . ') ' . $daboryPath . ' 경로를 확인하세요.';
  149. break;
  150. case 'HeadSelectOptions':
  151. case 'HeadSelectPopupOptions':
  152. case 'BodySelectOptions':
  153. $msg = "Parameter File Not Fount in {$popupOptions['Value']} ({$popupOptions['Caption']}) : {$daboryPath}";
  154. break;
  155. }
  156. } else {
  157. $msg = 'Parameter File Not Fount (Main) : ' . $daboryPath;
  158. }
  159. throw new ParameterException($msg);
  160. }
  161. if ($extension == '.json') {
  162. return json_decode($paramsFilePath, true );
  163. }
  164. return $paramsFilePath;
  165. }
  166. public static function getThemeParamFile(string $settingFileName = '', $extension = '.json', $themeDir = '', $popupOptions = false)
  167. {
  168. $countryCode = session('user')['CountryCode'] ?? config('constants.countries')[0];
  169. $setPath = "themes/{$themeDir}/para/{$countryCode}{$settingFileName}{$extension}";
  170. if (file_exists(daboryPath($setPath))) {
  171. $paramsFilePath = file_get_contents(daboryPath($setPath));
  172. } else {
  173. // dd($popupOptions);
  174. if ($popupOptions) {
  175. $msg = '(' . $popupOptions['OptionsType'] . ') ' . daboryPath($setPath) . ' 경로를 확인하세요.';
  176. } else {
  177. $msg = daboryPath($setPath) . ' 경로에 Parameter 형식에 맞춰서 넣어주세요.';
  178. }
  179. // dump($popupOptions);
  180. // dd($msg);
  181. throw new ParameterException($msg);
  182. }
  183. if ($extension == '.json') {
  184. return json_decode($paramsFilePath, true );
  185. }
  186. return $paramsFilePath;
  187. }
  188. public static function bpaDecoding($bpa)
  189. {
  190. $bpa = json_decode(base64_decode($bpa), true);
  191. if ($bpa) {
  192. session()->put('user.MenuPermission', $bpa['permission']);
  193. }
  194. return $bpa;
  195. }
  196. public static function bpaEncoding(array $menuPages): Collection
  197. {
  198. return collect($menuPages)->map(function ($menuPage) {
  199. $bpa = [
  200. 'menu_name' => $menuPage['MenuName'],
  201. 'menu_code' => $menuPage['MenuCode'],
  202. 'disable_l_menu' => $menuPage['DisableLMenu'] ?? '',
  203. 'enable_r_menu' => $menuPage['EnableRMenu'] ?? '',
  204. 'permission' => [
  205. 'is_mymenu' => $menuPage['IsMymenu'],
  206. 'is_list' => $menuPage['IsList'],
  207. 'is_read' => $menuPage['IsRead'],
  208. 'is_create' => $menuPage['IsCreate'],
  209. 'is_update' => $menuPage['IsUpdate'],
  210. 'is_delete' => $menuPage['IsDelete'],
  211. 'is_newtab' => $menuPage['IsNewtab'] ?? '',
  212. ],
  213. 'page_uri' => $menuPage['PageUri'],
  214. 'para_name' => $menuPage['ParaName'],
  215. 'theme_dir' => $menuPage['ThemeDir'] ?? '',
  216. 'main_app_id' => $menuPage['MainAppId'],
  217. 'guest_app_id' => $menuPage['GuestAppId'],
  218. 'custom_var' => $menuPage['CustomVar'],
  219. 'tabbed_menu_hash' => $menuPage['TabbedMenuHash'],
  220. ];
  221. self::bpaDelete($menuPage);
  222. return array_merge($menuPage, ['bpa' => base64_encode(json_encode($bpa))]);
  223. });
  224. }
  225. public static function bpaDelete(array &$array): void
  226. {
  227. foreach (['IsMymenu', 'IsList',
  228. 'IsRead', 'IsCreate', 'IsUpdate', 'IsDelete',
  229. 'ParaName'] as $item) {
  230. unset($array[$item]);
  231. }
  232. }
  233. public static function formatArrayToTree(array &$data, int $parentId = 0, string $key_ = 'UserMenuId'): array
  234. {
  235. $branch = [];
  236. foreach ($data as $key => $element) {
  237. if ($element['ParentId'] == $parentId) {
  238. $children = self::formatArrayToTree($data, $element[$key_], $key_);
  239. if ($children) {
  240. $element['children'] = $children;
  241. }
  242. $branch[] = $element;
  243. unset($data[$key]);
  244. }
  245. }
  246. return $branch;
  247. }
  248. public static function makeFrontRoute(string $name = '', string $themeDir = ''): string
  249. {
  250. $result = '';
  251. if ($name) $name = explode('/', $name);
  252. if (is_array($name) && count($name) > 1) {
  253. $controller = self::makeRouteController(array_pop($name));
  254. if (count($name))
  255. foreach ($name as $row)
  256. if ($row) $urls[] = self::makeRouteFolder($row);
  257. if (empty($themeDir)) {
  258. $basePath = '\\App\\Http\\Controllers\\Front\\';
  259. $result = $basePath . implode('\\', $urls) . '\\' . $controller . '@index';
  260. } else {
  261. $pathArray = explode('/', $themeDir);
  262. $count = count($pathArray) - 1;
  263. $themePath = ucfirst($pathArray[$count - 1]) . '\\' . $pathArray[$count];
  264. $basePath = '\\Themes\\' . $themePath . '\\app\\Http\\Controllers';
  265. $result = $basePath . '\\' . last($urls) . '\\' . $controller . '@index';
  266. }
  267. }
  268. return $result;
  269. }
  270. public static function makeRouteFolder(string $fname): string
  271. {
  272. return ucfirst(Str::camel($fname));
  273. }
  274. public static function makeRouteController(string $fname): string
  275. {
  276. return ucfirst(Str::camel($fname)) . 'Controller';
  277. }
  278. public static function getParamsFromUrl(array $paramKeys = []): array
  279. {
  280. $params = [];
  281. foreach ($paramKeys as $paramKey) {
  282. if (isset($_GET[$paramKey]) && $_GET[$paramKey]) {
  283. $params[$paramKey] = $_GET[$paramKey];
  284. }
  285. }
  286. return $params;
  287. }
  288. public static function makeLists($data, array $list = []): array
  289. {
  290. if (is_array($data)) {
  291. foreach ($data as $key => $row) {
  292. $list[$key] = $row;
  293. $list[$key]['View'] = '';
  294. }
  295. }
  296. return $list;
  297. }
  298. public static function putProMainParamCache($menuCode, $fileName, $data)
  299. {
  300. $fullFileUrl = "dabory-footage/pro/{$menuCode}-{$fileName}.json";
  301. Storage::put($fullFileUrl, $data);
  302. }
  303. public static function getProMainMenu()
  304. {
  305. $cacheName = "main-menu";
  306. $menuCacheData = Utils::getProMainParamCache('000000', $cacheName);
  307. if ($menuCacheData) {
  308. return json_decode($menuCacheData['query'], true);
  309. }
  310. $response = app(CallApiService::class)->callApi([
  311. 'url' => 'list-type1-page',
  312. 'data' => [
  313. 'QueryVars' => [
  314. 'QueryName' => 'menu-perm/main',
  315. 'IsntPagination' => true
  316. ],
  317. 'PageVars' => [
  318. 'Limit' => 10000,
  319. 'Offset' => 0
  320. ]
  321. ],
  322. ]);
  323. if (! isset($response['apiStatus'])) {
  324. $response['Page'] = Utils::parseMainApiResponse($response['Page']);
  325. Utils::putProMainParamCache('000000', $cacheName, json_encode($response));
  326. }
  327. return $response;
  328. }
  329. public static function parseMainApiResponse($data): array
  330. {
  331. return collect($data)->map(function ($menu) {
  332. return [
  333. 'MainMenuId' => $menu['Id'],
  334. 'Sort' => $menu['C1'],
  335. 'MenuCode' => $menu['C2'],
  336. 'LangType' => $menu['C3'],
  337. 'DeviceType' => $menu['C4'],
  338. 'MenuName' => $menu['C5'],
  339. 'PageUri' => $menu['C6'],
  340. 'IsLoginOnly' => $menu['C7'],
  341. 'IsLogoutOnly' => $menu['C8'],
  342. 'IsTgtBlank' => $menu['C9'],
  343. 'Icon' => $menu['C10'],
  344. 'MenuImg' => $menu['C11'],
  345. 'Status' => $menu['C12'],
  346. 'IsOffPc' => $menu['C13'],
  347. 'IsOffMobile' => $menu['C14'],
  348. 'IsOffTablet' => $menu['C15'],
  349. 'CustomVar' => $menu['C16'],
  350. 'TabbedMenuHash' => $menu['C17']
  351. ];
  352. })->toArray();
  353. }
  354. public static function getProMainParamCache($menuCode, $fileName, $queryName = null)
  355. {
  356. $fullFileUrl = "dabory-footage/pro/{$menuCode}-{$fileName}.json";
  357. if (isset($queryName)) {
  358. $fullFileUrl = "dabory-footage/pro/{$menuCode}-{$fileName}-{$queryName}.json";
  359. }
  360. if (Storage::disk()->exists($fullFileUrl)) {
  361. return [
  362. 'url' => $fileName,
  363. 'query' => Storage::get($fullFileUrl)
  364. ];
  365. }
  366. return false;
  367. }
  368. public static function getSortMenu()
  369. {
  370. $userPermId = session('user')['UserPermId'] ?? null;
  371. if (empty($userPermId)) { return []; }
  372. $cacheName = "user-sort-menu";
  373. $menuCacheData = Utils::getDirectParamCache($cacheName);
  374. if ($menuCacheData) {
  375. return json_decode($menuCacheData, true);
  376. }
  377. $response = app(CallApiService::class)->callApi([
  378. 'url' => 'list-type1-page',
  379. 'data' => [
  380. 'QueryVars' => [
  381. 'QueryName' => 'menu-perm/sort',
  382. 'SimpleFilter' => "is_enabled = '1' and mgt_type = 'user'",
  383. 'IsntPagination' => true
  384. ],
  385. 'PageVars' => [
  386. 'Limit' => 9999999,
  387. 'Offset' => 0
  388. ]
  389. ],
  390. ]);
  391. if (! isset($response['apiStatus'])) {
  392. Utils::putDirectParamCache($cacheName, json_encode($response));
  393. }
  394. return $response;
  395. }
  396. public static function getMainMenu($sortType)
  397. {
  398. $userPermId = session('user')['UserPermId'] ?? null;
  399. if (empty($userPermId)) { return []; }
  400. $cacheName = "user-menu/$sortType";
  401. $menuCacheData = Utils::getDirectParamCache($cacheName);
  402. if ($menuCacheData) {
  403. return json_decode($menuCacheData, true);
  404. }
  405. $simpleFilter = "mb.user_perm_id = $userPermId";
  406. if ($sortType !== 'all') {
  407. $simpleFilter .= " and sort_type = '$sortType'";
  408. }
  409. $response = app(CallApiService::class)->callApi([
  410. 'url' => 'list-type1-page',
  411. 'data' => [
  412. 'QueryVars' => [
  413. 'QueryName' => 'menu-perm/user',
  414. 'SimpleFilter' => $simpleFilter,
  415. 'IsntPagination' => true
  416. ],
  417. 'PageVars' => [
  418. 'Limit' => 10000,
  419. 'Offset' => 0
  420. ]
  421. ],
  422. ]);
  423. if (! isset($response['apiStatus'])) {
  424. $response['Page'] = Utils::parseApiResponse($response['Page']);
  425. Utils::putDirectParamCache($cacheName, json_encode($response));
  426. }
  427. return $response;
  428. }
  429. public static function parseApiResponse($data): array
  430. {
  431. return collect($data)->map(function ($menu) {
  432. return [
  433. 'UserMenuId' => $menu['Id'],
  434. 'SortType' => $menu['C1'],
  435. 'IsMymenu' => $menu['C2'],
  436. 'IsList' => $menu['C3'],
  437. 'IsRead' => $menu['C4'],
  438. 'IsCreate' => $menu['C5'],
  439. 'IsUpdate' => $menu['C6'],
  440. 'IsDelete' => $menu['C7'],
  441. 'IsNewtab' => $menu['C8'],
  442. 'MenuCode' => $menu['C9'],
  443. 'MenuName' => $menu['C10'],
  444. 'PageUri' => $menu['C11'],
  445. 'ParaName' => $menu['C12'],
  446. 'ThemeDir' => $menu['C13'],
  447. 'Icon' => $menu['C14'],
  448. 'DisableLMenu' => $menu['C15'],
  449. 'EnableRMenu' => $menu['C16'],
  450. 'MainAppId' => (int)$menu['C17'],
  451. 'GuestAppId' => (int)$menu['C18'],
  452. 'CustomVar' => $menu['C19'],
  453. 'TabbedMenuHash' => $menu['C20'],
  454. ];
  455. })->toArray();
  456. }
  457. public static function get_params_from_url(array $paramKeys = []): array
  458. {
  459. $params = [];
  460. foreach ($paramKeys as $paramKey) {
  461. if (isset($_GET[$paramKey]) && $_GET[$paramKey]) {
  462. $params[$paramKey] = $_GET[$paramKey];
  463. }
  464. }
  465. return $params;
  466. }
  467. public static function get_client_ip()
  468. {
  469. $ipaddress = '';
  470. if (getenv('HTTP_CLIENT_IP'))
  471. $ipaddress = getenv('HTTP_CLIENT_IP');
  472. else if(getenv('HTTP_X_FORWARDED_FOR'))
  473. $ipaddress = getenv('HTTP_X_FORWARDED_FOR');
  474. else if(getenv('HTTP_X_FORWARDED'))
  475. $ipaddress = getenv('HTTP_X_FORWARDED');
  476. else if(getenv('HTTP_FORWARDED_FOR'))
  477. $ipaddress = getenv('HTTP_FORWARDED_FOR');
  478. else if(getenv('HTTP_FORWARDED'))
  479. $ipaddress = getenv('HTTP_FORWARDED');
  480. else if(getenv('REMOTE_ADDR'))
  481. $ipaddress = getenv('REMOTE_ADDR');
  482. else
  483. $ipaddress = 'UNKNOWN';
  484. return $ipaddress;
  485. }
  486. public static function formatIgroupMenuList($menuPages, $codeName = 'MenuCode')
  487. {
  488. $menuList = [];
  489. foreach ($menuPages as $key => $value) {
  490. $value[$codeName] = (int)$value[$codeName];
  491. if ($value[$codeName] % 1000000 == 0) {
  492. $menuList[] = $value;
  493. unset($menuPages[$key]);
  494. }
  495. }
  496. $menuPages = collect($menuPages)->sortBy($codeName);
  497. foreach ($menuPages as $key => $value) {
  498. foreach ($menuList as $k => $v) {
  499. $valArr = str_split($value[$codeName], 2);
  500. $vArr = str_split($v[$codeName], 2);
  501. if ($valArr[0] == $vArr[0] && $valArr[1] != '00' && $valArr[2] == '00' && $valArr[3] == '00') {
  502. $menuList[$k]['child'][$value[$codeName]] = $value;
  503. unset($menuPages[$key]);
  504. }
  505. }
  506. }
  507. foreach ($menuPages as $key => $value) {
  508. foreach ($menuList as $k => $v) {
  509. $valArr = str_split($value[$codeName], 2);
  510. $vArr = str_split($v[$codeName], 2);
  511. if ($valArr[0] == $vArr[0] && $valArr[1] != '00' && $valArr[2] == '00' && $valArr[3] == '00') {
  512. $menuList[$k]['child'][$value[$codeName]] = $value;
  513. unset($menuPages[$key]);
  514. }
  515. if (empty($v['child'])) { continue; }
  516. foreach ($v['child'] as $o => $l) {
  517. $lArr = str_split($l[$codeName], 2);
  518. if ($valArr[0] == $lArr[0] && $valArr[1] == $lArr[1] && $valArr[1] != '00' && $valArr[2] != '00' && $valArr[3] == '00') {
  519. $menuList[$k]['child'][$o]['child'][$value[$codeName]] = $value;
  520. unset($menuPages[$key]);
  521. }
  522. }
  523. }
  524. }
  525. foreach ($menuPages as $key => $value) {
  526. foreach ($menuList as $k => $v) {
  527. if (empty($v['child'])) { continue; }
  528. foreach ($v['child'] as $i => $j) {
  529. $valArr = str_split($value[$codeName], 2);
  530. if (empty($j['child'])) { continue; }
  531. foreach ($j['child'] as $o => $l) {
  532. $lArr = str_split($o, 2);
  533. if ($valArr[0] == $lArr[0] && $valArr[1] == $lArr[1] && $valArr[2] == $lArr[2]) {
  534. $menuList[$k]['child'][$i]['child'][$o]['child'][$value[$codeName]] = $value;
  535. }
  536. }
  537. }
  538. }
  539. }
  540. // dump($menuPages);
  541. // dd($menuList);
  542. return $menuList;
  543. }
  544. public static function formatMenuList($menuPages, $codeName = 'MenuCode')
  545. {
  546. $menuList = [];
  547. foreach ($menuPages as $key => $value) {
  548. if ($value[$codeName] % 10000 == 0) {
  549. $menuList[] = $value;
  550. unset($menuPages[$key]);
  551. }
  552. }
  553. $menuPages = collect($menuPages)->sortBy($codeName);
  554. foreach ($menuPages as $key => $value) {
  555. foreach ($menuList as $k => $v) {
  556. $valArr = str_split($value[$codeName], 2);
  557. $vArr = str_split($v[$codeName], 2);
  558. if ($valArr[0] == $vArr[0] && $valArr[1] != '00' && $valArr[2] == '00') {
  559. $menuList[$k]['child'][$value[$codeName]] = $value;
  560. unset($menuPages[$key]);
  561. }
  562. }
  563. }
  564. foreach ($menuPages as $key => $value) {
  565. foreach ($menuList as $k => $v) {
  566. if (empty($v['child'])) { continue; }
  567. foreach ($v['child'] as $i => $j) {
  568. $valArr = str_split($value[$codeName], 2);
  569. $jArr = str_split($i, 2);
  570. if ($valArr[0] == $jArr[0] && $valArr[1] == $jArr[1]) {
  571. $menuList[$k]['child'][$i]['child'][$value[$codeName]] = $value;
  572. }
  573. }
  574. }
  575. }
  576. // dump($menuPages);
  577. // dd($menuList);
  578. return $menuList;
  579. }
  580. }