Utils.php 23 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671
  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')['UserId'] ?? 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')['UserId'] ?? 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. ];
  220. self::bpaDelete($menuPage);
  221. return array_merge($menuPage, ['bpa' => base64_encode(json_encode($bpa))]);
  222. });
  223. }
  224. public static function bpaDelete(array &$array): void
  225. {
  226. foreach (['IsMymenu', 'IsList',
  227. 'IsRead', 'IsCreate', 'IsUpdate', 'IsDelete',
  228. 'ParaName'] as $item) {
  229. unset($array[$item]);
  230. }
  231. }
  232. public static function formatArrayToTree(array &$data, int $parentId = 0, string $key_ = 'UserMenuId'): array
  233. {
  234. $branch = [];
  235. foreach ($data as $key => $element) {
  236. if ($element['ParentId'] == $parentId) {
  237. $children = self::formatArrayToTree($data, $element[$key_], $key_);
  238. if ($children) {
  239. $element['children'] = $children;
  240. }
  241. $branch[] = $element;
  242. unset($data[$key]);
  243. }
  244. }
  245. return $branch;
  246. }
  247. public static function makeFrontRoute(string $name = '', string $themeDir = ''): string
  248. {
  249. $result = '';
  250. if ($name) $name = explode('/', $name);
  251. if (is_array($name) && count($name) > 1) {
  252. $controller = self::makeRouteController(array_pop($name));
  253. if (count($name))
  254. foreach ($name as $row)
  255. if ($row) $urls[] = self::makeRouteFolder($row);
  256. if (empty($themeDir)) {
  257. $basePath = '\\App\\Http\\Controllers\\Front\\';
  258. $result = $basePath . implode('\\', $urls) . '\\' . $controller . '@index';
  259. } else {
  260. $pathArray = explode('/', $themeDir);
  261. $count = count($pathArray) - 1;
  262. $themePath = ucfirst($pathArray[$count - 1]) . '\\' . $pathArray[$count];
  263. $basePath = '\\Themes\\' . $themePath . '\\app\\Http\\Controllers';
  264. $result = $basePath . '\\' . last($urls) . '\\' . $controller . '@index';
  265. }
  266. }
  267. return $result;
  268. }
  269. public static function makeRouteFolder(string $fname): string
  270. {
  271. return ucfirst(Str::camel($fname));
  272. }
  273. public static function makeRouteController(string $fname): string
  274. {
  275. return ucfirst(Str::camel($fname)) . 'Controller';
  276. }
  277. public static function getParamsFromUrl(array $paramKeys = []): array
  278. {
  279. $params = [];
  280. foreach ($paramKeys as $paramKey) {
  281. if (isset($_GET[$paramKey]) && $_GET[$paramKey]) {
  282. $params[$paramKey] = $_GET[$paramKey];
  283. }
  284. }
  285. return $params;
  286. }
  287. public static function makeLists($data, array $list = []): array
  288. {
  289. if (is_array($data)) {
  290. foreach ($data as $key => $row) {
  291. $list[$key] = $row;
  292. $list[$key]['View'] = '';
  293. }
  294. }
  295. return $list;
  296. }
  297. public static function putProMainParamCache($menuCode, $fileName, $data)
  298. {
  299. $fullFileUrl = "dabory-footage/pro/{$menuCode}-{$fileName}.json";
  300. Storage::put($fullFileUrl, $data);
  301. }
  302. public static function getProMainMenu()
  303. {
  304. $cacheName = "main-menu";
  305. $menuCacheData = Utils::getProMainParamCache('000000', $cacheName);
  306. if ($menuCacheData) {
  307. return json_decode($menuCacheData['query'], true);
  308. }
  309. $response = app(CallApiService::class)->callApi([
  310. 'url' => 'list-type1-page',
  311. 'data' => [
  312. 'QueryVars' => [
  313. 'QueryName' => 'menu-perm/main',
  314. 'IsntPagination' => true
  315. ],
  316. 'PageVars' => [
  317. 'Limit' => 10000,
  318. 'Offset' => 0
  319. ]
  320. ],
  321. ]);
  322. if (! isset($response['apiStatus'])) {
  323. $response['Page'] = Utils::parseMainApiResponse($response['Page']);
  324. Utils::putProMainParamCache('000000', $cacheName, json_encode($response));
  325. }
  326. return $response;
  327. }
  328. public static function parseMainApiResponse($data): array
  329. {
  330. return collect($data)->map(function ($menu) {
  331. return [
  332. 'MainMenuId' => $menu['Id'],
  333. 'Sort' => $menu['C1'],
  334. 'MenuCode' => $menu['C2'],
  335. 'LangType' => $menu['C3'],
  336. 'DeviceType' => $menu['C4'],
  337. 'MenuName' => $menu['C5'],
  338. 'PageUri' => $menu['C6'],
  339. 'IsLoginOnly' => $menu['C7'],
  340. 'IsLogoutOnly' => $menu['C8'],
  341. 'IsTgtBlank' => $menu['C9'],
  342. 'Icon' => $menu['C10'],
  343. 'MenuImg' => $menu['C11'],
  344. 'Status' => $menu['C12'],
  345. 'IsOffPc' => $menu['C13'],
  346. 'IsOffMobile' => $menu['C14'],
  347. 'IsOffTablet' => $menu['C15'],
  348. 'CustomVar' => $menu['C16']
  349. ];
  350. })->toArray();
  351. }
  352. public static function getProMainParamCache($menuCode, $fileName, $queryName = null)
  353. {
  354. $fullFileUrl = "dabory-footage/pro/{$menuCode}-{$fileName}.json";
  355. if (isset($queryName)) {
  356. $fullFileUrl = "dabory-footage/pro/{$menuCode}-{$fileName}-{$queryName}.json";
  357. }
  358. if (Storage::disk()->exists($fullFileUrl)) {
  359. return [
  360. 'url' => $fileName,
  361. 'query' => Storage::get($fullFileUrl)
  362. ];
  363. }
  364. return false;
  365. }
  366. public static function getSortMenu()
  367. {
  368. $userPermId = session('user')['UserPermId'] ?? null;
  369. if (empty($userPermId)) { return []; }
  370. $cacheName = "user-sort-menu";
  371. $menuCacheData = Utils::getDirectParamCache($cacheName);
  372. if ($menuCacheData) {
  373. return json_decode($menuCacheData, true);
  374. }
  375. $response = app(CallApiService::class)->callApi([
  376. 'url' => 'list-type1-page',
  377. 'data' => [
  378. 'QueryVars' => [
  379. 'QueryName' => 'menu-perm/sort',
  380. 'SimpleFilter' => "is_enabled = '1' and mgt_type = 'user'",
  381. 'IsntPagination' => true
  382. ],
  383. 'PageVars' => [
  384. 'Limit' => 9999999,
  385. 'Offset' => 0
  386. ]
  387. ],
  388. ]);
  389. if (! isset($response['apiStatus'])) {
  390. Utils::putDirectParamCache($cacheName, json_encode($response));
  391. }
  392. return $response;
  393. }
  394. public static function getMainMenu($sortType)
  395. {
  396. $userPermId = session('user')['UserPermId'] ?? null;
  397. if (empty($userPermId)) { return []; }
  398. $cacheName = "user-menu/$sortType";
  399. $menuCacheData = Utils::getDirectParamCache($cacheName);
  400. if ($menuCacheData) {
  401. return json_decode($menuCacheData, true);
  402. }
  403. $response = app(CallApiService::class)->callApi([
  404. 'url' => 'list-type1-page',
  405. 'data' => [
  406. 'QueryVars' => [
  407. 'QueryName' => 'menu-perm/user',
  408. 'SimpleFilter' => "mb.user_perm_id = $userPermId and sort_type = '$sortType'",
  409. 'IsntPagination' => true
  410. ],
  411. 'PageVars' => [
  412. 'Limit' => 10000,
  413. 'Offset' => 0
  414. ]
  415. ],
  416. ]);
  417. if (! isset($response['apiStatus'])) {
  418. $response['Page'] = Utils::parseApiResponse($response['Page']);
  419. Utils::putDirectParamCache($cacheName, json_encode($response));
  420. }
  421. return $response;
  422. }
  423. public static function parseApiResponse($data): array
  424. {
  425. return collect($data)->map(function ($menu) {
  426. return [
  427. 'UserMenuId' => $menu['Id'],
  428. 'SortType' => $menu['C1'],
  429. 'IsMymenu' => $menu['C2'],
  430. 'IsList' => $menu['C3'],
  431. 'IsRead' => $menu['C4'],
  432. 'IsCreate' => $menu['C5'],
  433. 'IsUpdate' => $menu['C6'],
  434. 'IsDelete' => $menu['C7'],
  435. 'IsNewtab' => $menu['C8'],
  436. 'MenuCode' => $menu['C9'],
  437. 'MenuName' => $menu['C10'],
  438. 'PageUri' => $menu['C11'],
  439. 'ParaName' => $menu['C12'],
  440. 'ThemeDir' => $menu['C13'],
  441. 'Icon' => $menu['C14'],
  442. 'DisableLMenu' => $menu['C15'],
  443. 'EnableRMenu' => $menu['C16'],
  444. 'MainAppId' => (int)$menu['C17'],
  445. 'GuestAppId' => (int)$menu['C18'],
  446. 'CustomVar' => $menu['C19'],
  447. ];
  448. })->toArray();
  449. }
  450. public static function get_params_from_url(array $paramKeys = []): array
  451. {
  452. $params = [];
  453. foreach ($paramKeys as $paramKey) {
  454. if (isset($_GET[$paramKey]) && $_GET[$paramKey]) {
  455. $params[$paramKey] = $_GET[$paramKey];
  456. }
  457. }
  458. return $params;
  459. }
  460. public static function get_client_ip()
  461. {
  462. $ipaddress = '';
  463. if (getenv('HTTP_CLIENT_IP'))
  464. $ipaddress = getenv('HTTP_CLIENT_IP');
  465. else if(getenv('HTTP_X_FORWARDED_FOR'))
  466. $ipaddress = getenv('HTTP_X_FORWARDED_FOR');
  467. else if(getenv('HTTP_X_FORWARDED'))
  468. $ipaddress = getenv('HTTP_X_FORWARDED');
  469. else if(getenv('HTTP_FORWARDED_FOR'))
  470. $ipaddress = getenv('HTTP_FORWARDED_FOR');
  471. else if(getenv('HTTP_FORWARDED'))
  472. $ipaddress = getenv('HTTP_FORWARDED');
  473. else if(getenv('REMOTE_ADDR'))
  474. $ipaddress = getenv('REMOTE_ADDR');
  475. else
  476. $ipaddress = 'UNKNOWN';
  477. return $ipaddress;
  478. }
  479. public static function formatIgroupMenuList($menuPages, $codeName = 'MenuCode')
  480. {
  481. $menuList = [];
  482. foreach ($menuPages as $key => $value) {
  483. $value[$codeName] = (int)$value[$codeName];
  484. if ($value[$codeName] % 1000000 == 0) {
  485. $menuList[] = $value;
  486. unset($menuPages[$key]);
  487. }
  488. }
  489. $menuPages = collect($menuPages)->sortBy($codeName);
  490. foreach ($menuPages as $key => $value) {
  491. foreach ($menuList as $k => $v) {
  492. $valArr = str_split($value[$codeName], 2);
  493. $vArr = str_split($v[$codeName], 2);
  494. if ($valArr[0] == $vArr[0] && $valArr[1] != '00' && $valArr[2] == '00' && $valArr[3] == '00') {
  495. $menuList[$k]['child'][$value[$codeName]] = $value;
  496. unset($menuPages[$key]);
  497. }
  498. }
  499. }
  500. foreach ($menuPages as $key => $value) {
  501. foreach ($menuList as $k => $v) {
  502. $valArr = str_split($value[$codeName], 2);
  503. $vArr = str_split($v[$codeName], 2);
  504. if ($valArr[0] == $vArr[0] && $valArr[1] != '00' && $valArr[2] == '00' && $valArr[3] == '00') {
  505. $menuList[$k]['child'][$value[$codeName]] = $value;
  506. unset($menuPages[$key]);
  507. }
  508. if (empty($v['child'])) { continue; }
  509. foreach ($v['child'] as $o => $l) {
  510. $lArr = str_split($l[$codeName], 2);
  511. if ($valArr[0] == $lArr[0] && $valArr[1] == $lArr[1] && $valArr[1] != '00' && $valArr[2] != '00' && $valArr[3] == '00') {
  512. $menuList[$k]['child'][$o]['child'][$value[$codeName]] = $value;
  513. unset($menuPages[$key]);
  514. }
  515. }
  516. }
  517. }
  518. foreach ($menuPages as $key => $value) {
  519. foreach ($menuList as $k => $v) {
  520. if (empty($v['child'])) { continue; }
  521. foreach ($v['child'] as $i => $j) {
  522. $valArr = str_split($value[$codeName], 2);
  523. if (empty($j['child'])) { continue; }
  524. foreach ($j['child'] as $o => $l) {
  525. $lArr = str_split($o, 2);
  526. if ($valArr[0] == $lArr[0] && $valArr[1] == $lArr[1] && $valArr[2] == $lArr[2]) {
  527. $menuList[$k]['child'][$i]['child'][$o]['child'][$value[$codeName]] = $value;
  528. }
  529. }
  530. }
  531. }
  532. }
  533. // dump($menuPages);
  534. // dd($menuList);
  535. return $menuList;
  536. }
  537. public static function formatMenuList($menuPages, $codeName = 'MenuCode')
  538. {
  539. $menuList = [];
  540. foreach ($menuPages as $key => $value) {
  541. if ($value[$codeName] % 10000 == 0) {
  542. $menuList[] = $value;
  543. unset($menuPages[$key]);
  544. }
  545. }
  546. $menuPages = collect($menuPages)->sortBy($codeName);
  547. foreach ($menuPages as $key => $value) {
  548. foreach ($menuList as $k => $v) {
  549. $valArr = str_split($value[$codeName], 2);
  550. $vArr = str_split($v[$codeName], 2);
  551. if ($valArr[0] == $vArr[0] && $valArr[1] != '00' && $valArr[2] == '00') {
  552. $menuList[$k]['child'][$value[$codeName]] = $value;
  553. unset($menuPages[$key]);
  554. }
  555. }
  556. }
  557. foreach ($menuPages as $key => $value) {
  558. foreach ($menuList as $k => $v) {
  559. if (empty($v['child'])) { continue; }
  560. foreach ($v['child'] as $i => $j) {
  561. $valArr = str_split($value[$codeName], 2);
  562. $jArr = str_split($i, 2);
  563. if ($valArr[0] == $jArr[0] && $valArr[1] == $jArr[1]) {
  564. $menuList[$k]['child'][$i]['child'][$value[$codeName]] = $value;
  565. }
  566. }
  567. }
  568. }
  569. // dump($menuPages);
  570. // dd($menuList);
  571. return $menuList;
  572. }
  573. }