123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265 |
- <?php
- namespace App\Http\Controllers;
- use App\Services\CallApiService;
- use Carbon\Carbon;
- class DashboardController extends Controller
- {
- public function __construct(CallApiService $callApiService)
- {
- $this->callApiService = $callApiService;
- }
- public function index() {
- // dd($this->getMenu());
- // dump(session('user'));
- // dump(session('GateToken'));
- // $erpThemes = preg_replace('/\s+/', '', explode(',', env('ERP_THEMES')));
- //
- // if ($erpThemes[0]) {
- // return view("erp.{$erpThemes[0]}.resources.views.dashboard");
- // }
- $view = null;
- $sortMenu = session('user.SortMenu');
- if (empty($sortMenu['C7'])) {
- $view = 'pages.generic_dash';
- // return view('pages.shop_dash');
- }
- $component = explode('::', $sortMenu['C7']);
- if (count($component) === 1) {
- $view = 'pages.' . $sortMenu['C7'];
- // return view('pages.' . $sortMenu['C7']);
- }
- if ($view) {
- if ($view === 'pages.shop_dash') {
- $howManyWorkingDays = $this->callApiService->callApi([
- 'url' => 'how-many-working-days',
- 'data' => [
- 'ReturnField' => 'StartDate',
- 'EndDate' => Carbon::now()->format('Ymd'),
- 'WorkingDays' => 7,
- ]
- ]);
- // $howManyWorkingDays['StartDate'] = '20240721';
- // $howManyWorkingDays['EndDate'] = '20240728';
- $noticeFilter = request('notice_filter', 'all');
- $reviewFilter = request('review_filter', 'all');
- $inquiryFilter = request('inquiry_filter', 'all');
- $noticeSimpleFilter = '';
- if ($noticeFilter !== 'all') {
- $noticeSimpleFilter = "mx.status = '$noticeFilter'";
- }
- $inquirySimpleFilter = '';
- if ($inquiryFilter !== 'all') {
- $inquirySimpleFilter = "mx.status = '$inquiryFilter'";
- }
- $reviewSimpleFilter = '';
- if ($reviewFilter === 'up') {
- $reviewSimpleFilter = 'mx.rating_score >= 4';
- } else if ($reviewFilter === 'down') {
- $reviewSimpleFilter = 'mx.rating_score < 4';
- }
- $listType1Book = $this->callApiService->callApi([
- 'url' => 'list-type1-book',
- 'data' => [
- 'Book' => [
- [
- 'QueryVars' => [
- 'QueryName' => 'dashboard/generic_dash/1-left-top',
- 'SimpleFilter' => '',
- ],
- 'ListType1Vars' => [
- 'OrderBy' => 'mx.created_on desc'
- ],
- ],
- [
- 'QueryVars' => [
- 'QueryName' => 'dashboard/generic_dash/2-left-top',
- 'SimpleFilter' => '',
- ],
- 'ListType1Vars' => [
- 'IsDownloadList' => true,
- 'OrderBy' => 'mx.created_on desc'
- ],
- 'PageVars' => [
- 'Limit' => 1,
- ]
- ],
- [
- 'QueryVars' => [
- 'QueryName' => 'dashboard/generic_dash/3-left-top',
- 'SimpleFilter' => '',
- ],
- 'ListType1Vars' => [
- 'OrderBy' => 'mx.created_on desc'
- ],
- ],
- [
- 'QueryVars' => [
- 'QueryName' => 'dashboard/generic_dash/order-new',
- 'SimpleFilter' => '',
- ],
- 'ListType1Vars' => [
- 'OrderBy' => 'mx.created_on desc'
- ],
- ],
- [
- 'QueryVars' => [
- 'QueryName' => 'dashboard/generic_dash/order-delayed',
- 'SimpleFilter' => '',
- ],
- 'ListType1Vars' => [
- 'IsDownloadList' => true,
- 'OrderBy' => 'mx.created_on desc'
- ],
- 'PageVars' => [
- 'Limit' => 1,
- ]
- ],
- [
- 'QueryVars' => [
- 'QueryName' => 'dashboard/generic_dash/order-cancelled',
- 'SimpleFilter' => '',
- ],
- ],
- [
- 'QueryVars' => [
- 'QueryName' => 'dashboard/generic_dash/post-item-inquiry',
- 'SimpleFilter' => $inquirySimpleFilter,
- // 'TestMode' => 'query'
- ],
- 'ListType1Vars' => [
- 'OrderBy' => 'mx.created_on desc'
- ],
- 'PageVars' => [
- 'Limit' => 6,
- ]
- ],
- [
- 'QueryVars' => [
- 'QueryName' => 'dashboard/generic_dash/item-count',
- 'SimpleFilter' => '',
- ],
- ],
- [
- 'QueryVars' => [
- 'QueryName' => 'dashboard/generic_dash/post-notice',
- 'SimpleFilter' => $noticeSimpleFilter,
- ],
- 'ListType1Vars' => [
- 'OrderBy' => 'mx.created_on desc'
- ],
- 'PageVars' => [
- 'Limit' => 4,
- ]
- ],
- [
- 'QueryVars' => [
- 'QueryName' => 'dashboard/generic_dash/post-item-review',
- 'SimpleFilter' => $reviewSimpleFilter,
- ],
- 'ListType1Vars' => [
- 'OrderBy' => 'mx.created_on desc'
- ],
- 'PageVars' => [
- 'Limit' => 4,
- ]
- ],
- [
- 'QueryVars' => [
- 'QueryName' => 'dashboard/generic_dash/sales-statistics',
- 'SimpleFilter' => '',
- ],
- 'ListType1Vars' => [
- 'FilterDate' => 'sorder_date',
- 'StartDate' => $howManyWorkingDays['StartDate'],
- 'EndDate' => $howManyWorkingDays['EndDate'],
- ],
- ],
- [
- 'QueryVars' => [
- 'QueryName' => 'dashboard/generic_dash/sales-statistics-graph',
- 'SimpleFilter' => '',
- ],
- 'ListType1Vars' => [
- 'IsDownloadList' => true,
- 'FilterDate' => 'sorder_date',
- 'StartDate' => $howManyWorkingDays['StartDate'],
- 'EndDate' => $howManyWorkingDays['EndDate'],
- ],
- 'PageVars' => [
- 'Limit' => 100,
- ]
- ],
- ]
- ]
- ]);
- // dump($listType1Book);
- if ($this->callApiService->verifyApiError($listType1Book)) {
- return redirect()->to('/user-logout');
- }
- $salesStatisticsGraph = collect($listType1Book['Book'][11]['Page'])->map(function ($data) {
- return [
- 'type' => 'val1',
- 'date' => Carbon::createFromFormat('Y-m-d', $data['C1'])->format('Y/m/d'),
- '매출 금액' => $data['C2'],
- '매출 건수' => $data['C3'],
- '고객 수' => $data['C4'],
- ];
- });
- // Generate the complete range of dates
- $startDate = Carbon::parse($howManyWorkingDays['StartDate']);
- $endDate = Carbon::parse($howManyWorkingDays['EndDate']);
- $dateRange = collect();
- $currentDate = $startDate->copy();
- while ($currentDate <= $endDate) {
- $dateRange->push($currentDate->format('Y/m/d'));
- $currentDate->addDay();
- }
- // Fill in missing dates with empty values
- $salesStatisticsGraph = $dateRange->map(function ($date) use ($salesStatisticsGraph) {
- $existingEntry = $salesStatisticsGraph->firstWhere('date', $date);
- if ($existingEntry) {
- return $existingEntry;
- } else {
- return [
- 'type' => 'val1',
- 'date' => $date,
- '매출 금액' => 0,
- '매출 건수' => 0,
- '고객 수' => 0,
- ];
- }
- })->toArray();
- return view($view, compact('listType1Book', 'salesStatisticsGraph'))
- ->with('codeTitle', [ "status('post-item-inquiry')", "status('post-notice')" ]);
- }
- return view($view);
- }
- return redirect()->route("themes.$component[0].dashboard");
- }
- }
|