DashboardController.php 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265
  1. <?php
  2. namespace App\Http\Controllers;
  3. use App\Services\CallApiService;
  4. use Carbon\Carbon;
  5. class DashboardController extends Controller
  6. {
  7. public function __construct(CallApiService $callApiService)
  8. {
  9. $this->callApiService = $callApiService;
  10. }
  11. public function index() {
  12. // dd($this->getMenu());
  13. // dump(session('user'));
  14. // dump(session('GateToken'));
  15. // $erpThemes = preg_replace('/\s+/', '', explode(',', env('ERP_THEMES')));
  16. //
  17. // if ($erpThemes[0]) {
  18. // return view("erp.{$erpThemes[0]}.resources.views.dashboard");
  19. // }
  20. $view = null;
  21. $sortMenu = session('user.SortMenu');
  22. if (empty($sortMenu['C7'])) {
  23. $view = 'pages.generic_dash';
  24. // return view('pages.shop_dash');
  25. }
  26. $component = explode('::', $sortMenu['C7']);
  27. if (count($component) === 1) {
  28. $view = 'pages.' . $sortMenu['C7'];
  29. // return view('pages.' . $sortMenu['C7']);
  30. }
  31. if ($view) {
  32. if ($view === 'pages.shop_dash') {
  33. $howManyWorkingDays = $this->callApiService->callApi([
  34. 'url' => 'how-many-working-days',
  35. 'data' => [
  36. 'ReturnField' => 'StartDate',
  37. 'EndDate' => Carbon::now()->format('Ymd'),
  38. 'WorkingDays' => 7,
  39. ]
  40. ]);
  41. // $howManyWorkingDays['StartDate'] = '20240721';
  42. // $howManyWorkingDays['EndDate'] = '20240728';
  43. $noticeFilter = request('notice_filter', 'all');
  44. $reviewFilter = request('review_filter', 'all');
  45. $inquiryFilter = request('inquiry_filter', 'all');
  46. $noticeSimpleFilter = '';
  47. if ($noticeFilter !== 'all') {
  48. $noticeSimpleFilter = "mx.status = '$noticeFilter'";
  49. }
  50. $inquirySimpleFilter = '';
  51. if ($inquiryFilter !== 'all') {
  52. $inquirySimpleFilter = "mx.status = '$inquiryFilter'";
  53. }
  54. $reviewSimpleFilter = '';
  55. if ($reviewFilter === 'up') {
  56. $reviewSimpleFilter = 'mx.rating_score >= 4';
  57. } else if ($reviewFilter === 'down') {
  58. $reviewSimpleFilter = 'mx.rating_score < 4';
  59. }
  60. $listType1Book = $this->callApiService->callApi([
  61. 'url' => 'list-type1-book',
  62. 'data' => [
  63. 'Book' => [
  64. [
  65. 'QueryVars' => [
  66. 'QueryName' => 'dashboard/generic_dash/1-left-top',
  67. 'SimpleFilter' => '',
  68. ],
  69. 'ListType1Vars' => [
  70. 'OrderBy' => 'mx.created_on desc'
  71. ],
  72. ],
  73. [
  74. 'QueryVars' => [
  75. 'QueryName' => 'dashboard/generic_dash/2-left-top',
  76. 'SimpleFilter' => '',
  77. ],
  78. 'ListType1Vars' => [
  79. 'IsDownloadList' => true,
  80. 'OrderBy' => 'mx.created_on desc'
  81. ],
  82. 'PageVars' => [
  83. 'Limit' => 1,
  84. ]
  85. ],
  86. [
  87. 'QueryVars' => [
  88. 'QueryName' => 'dashboard/generic_dash/3-left-top',
  89. 'SimpleFilter' => '',
  90. ],
  91. 'ListType1Vars' => [
  92. 'OrderBy' => 'mx.created_on desc'
  93. ],
  94. ],
  95. [
  96. 'QueryVars' => [
  97. 'QueryName' => 'dashboard/generic_dash/order-new',
  98. 'SimpleFilter' => '',
  99. ],
  100. 'ListType1Vars' => [
  101. 'OrderBy' => 'mx.created_on desc'
  102. ],
  103. ],
  104. [
  105. 'QueryVars' => [
  106. 'QueryName' => 'dashboard/generic_dash/order-delayed',
  107. 'SimpleFilter' => '',
  108. ],
  109. 'ListType1Vars' => [
  110. 'IsDownloadList' => true,
  111. 'OrderBy' => 'mx.created_on desc'
  112. ],
  113. 'PageVars' => [
  114. 'Limit' => 1,
  115. ]
  116. ],
  117. [
  118. 'QueryVars' => [
  119. 'QueryName' => 'dashboard/generic_dash/order-cancelled',
  120. 'SimpleFilter' => '',
  121. ],
  122. ],
  123. [
  124. 'QueryVars' => [
  125. 'QueryName' => 'dashboard/generic_dash/post-item-inquiry',
  126. 'SimpleFilter' => $inquirySimpleFilter,
  127. // 'TestMode' => 'query'
  128. ],
  129. 'ListType1Vars' => [
  130. 'OrderBy' => 'mx.created_on desc'
  131. ],
  132. 'PageVars' => [
  133. 'Limit' => 6,
  134. ]
  135. ],
  136. [
  137. 'QueryVars' => [
  138. 'QueryName' => 'dashboard/generic_dash/item-count',
  139. 'SimpleFilter' => '',
  140. ],
  141. ],
  142. [
  143. 'QueryVars' => [
  144. 'QueryName' => 'dashboard/generic_dash/post-notice',
  145. 'SimpleFilter' => $noticeSimpleFilter,
  146. ],
  147. 'ListType1Vars' => [
  148. 'OrderBy' => 'mx.created_on desc'
  149. ],
  150. 'PageVars' => [
  151. 'Limit' => 4,
  152. ]
  153. ],
  154. [
  155. 'QueryVars' => [
  156. 'QueryName' => 'dashboard/generic_dash/post-item-review',
  157. 'SimpleFilter' => $reviewSimpleFilter,
  158. ],
  159. 'ListType1Vars' => [
  160. 'OrderBy' => 'mx.created_on desc'
  161. ],
  162. 'PageVars' => [
  163. 'Limit' => 4,
  164. ]
  165. ],
  166. [
  167. 'QueryVars' => [
  168. 'QueryName' => 'dashboard/generic_dash/sales-statistics',
  169. 'SimpleFilter' => '',
  170. ],
  171. 'ListType1Vars' => [
  172. 'FilterDate' => 'sorder_date',
  173. 'StartDate' => $howManyWorkingDays['StartDate'],
  174. 'EndDate' => $howManyWorkingDays['EndDate'],
  175. ],
  176. ],
  177. [
  178. 'QueryVars' => [
  179. 'QueryName' => 'dashboard/generic_dash/sales-statistics-graph',
  180. 'SimpleFilter' => '',
  181. ],
  182. 'ListType1Vars' => [
  183. 'IsDownloadList' => true,
  184. 'FilterDate' => 'sorder_date',
  185. 'StartDate' => $howManyWorkingDays['StartDate'],
  186. 'EndDate' => $howManyWorkingDays['EndDate'],
  187. ],
  188. 'PageVars' => [
  189. 'Limit' => 100,
  190. ]
  191. ],
  192. ]
  193. ]
  194. ]);
  195. // dump($listType1Book);
  196. if ($this->callApiService->verifyApiError($listType1Book)) {
  197. return redirect()->to('/user-logout');
  198. }
  199. $salesStatisticsGraph = collect($listType1Book['Book'][11]['Page'])->map(function ($data) {
  200. return [
  201. 'type' => 'val1',
  202. 'date' => Carbon::createFromFormat('Y-m-d', $data['C1'])->format('Y/m/d'),
  203. '매출 금액' => $data['C2'],
  204. '매출 건수' => $data['C3'],
  205. '고객 수' => $data['C4'],
  206. ];
  207. });
  208. // Generate the complete range of dates
  209. $startDate = Carbon::parse($howManyWorkingDays['StartDate']);
  210. $endDate = Carbon::parse($howManyWorkingDays['EndDate']);
  211. $dateRange = collect();
  212. $currentDate = $startDate->copy();
  213. while ($currentDate <= $endDate) {
  214. $dateRange->push($currentDate->format('Y/m/d'));
  215. $currentDate->addDay();
  216. }
  217. // Fill in missing dates with empty values
  218. $salesStatisticsGraph = $dateRange->map(function ($date) use ($salesStatisticsGraph) {
  219. $existingEntry = $salesStatisticsGraph->firstWhere('date', $date);
  220. if ($existingEntry) {
  221. return $existingEntry;
  222. } else {
  223. return [
  224. 'type' => 'val1',
  225. 'date' => $date,
  226. '매출 금액' => 0,
  227. '매출 건수' => 0,
  228. '고객 수' => 0,
  229. ];
  230. }
  231. })->toArray();
  232. return view($view, compact('listType1Book', 'salesStatisticsGraph'))
  233. ->with('codeTitle', [ "status('post-item-inquiry')", "status('post-notice')" ]);
  234. }
  235. return view($view);
  236. }
  237. return redirect()->route("themes.$component[0].dashboard");
  238. }
  239. }