Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

管理画面トップ 売上状況が9時間ずれる問題修正 #4465

Merged
merged 5 commits into from
Aug 21, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
70 changes: 35 additions & 35 deletions src/Eccube/Controller/Admin/AdminController.php
Original file line number Diff line number Diff line change
Expand Up @@ -445,32 +445,31 @@ protected function getOrderEachStatus(array $excludes)
}

/**
* @param $dateTime
* @param \DateTime $dateTime
*
* @return array|mixed
*
* @throws \Doctrine\ORM\NonUniqueResultException
*/
protected function getSalesByDay($dateTime)
{
// concat... for pgsql
// http://stackoverflow.com/questions/1091924/substr-does-not-work-with-datatype-timestamp-in-postgres-8-3
$dql = 'SELECT
SUBSTRING(CONCAT(o.order_date, \'\'), 1, 10) AS order_day,
SUM(o.payment_total) AS order_amount,
COUNT(o) AS order_count
FROM
Eccube\Entity\Order o
WHERE
o.OrderStatus NOT IN (:excludes)
AND SUBSTRING(CONCAT(o.order_date, \'\'), 1, 10) = SUBSTRING(:targetDate, 1, 10)
GROUP BY
order_day';
$dateTimeStart = clone $dateTime;
$dateTimeStart->setTime(0, 0, 0, 0);

$dateTimeEnd = clone $dateTimeStart;
$dateTimeEnd->modify('+1 days');

$q = $this->entityManager
->createQuery($dql)
$qb = $this->orderRepository
->createQueryBuilder('o')
->select('
SUM(o.payment_total) AS order_amount,
COUNT(o) AS order_count')
->setParameter(':excludes', $this->excludes)
->setParameter(':targetDate', $dateTime);
->setParameter(':targetDateStart', $dateTimeStart)
->setParameter(':targetDateEnd', $dateTimeEnd)
->andWhere(':targetDateStart <= o.order_date and o.order_date < :targetDateEnd')
->andWhere('o.OrderStatus NOT IN (:excludes)');
$q = $qb->getQuery();

$result = [];
try {
Expand All @@ -483,32 +482,33 @@ protected function getSalesByDay($dateTime)
}

/**
* @param $dateTime
* @param \DateTime $dateTime
*
* @return array|mixed
*
* @throws \Doctrine\ORM\NonUniqueResultException
*/
protected function getSalesByMonth($dateTime)
{
// concat... for pgsql
// http://stackoverflow.com/questions/1091924/substr-does-not-work-with-datatype-timestamp-in-postgres-8-3
$dql = 'SELECT
SUBSTRING(CONCAT(o.order_date, \'\'), 1, 7) AS order_month,
SUM(o.payment_total) AS order_amount,
COUNT(o) AS order_count
FROM
Eccube\Entity\Order o
WHERE
o.OrderStatus NOT IN (:excludes)
AND SUBSTRING(CONCAT(o.order_date, \'\'), 1, 7) = SUBSTRING(:targetDate, 1, 7)
GROUP BY
order_month';

$q = $this->entityManager
->createQuery($dql)
$dateTimeStart = clone $dateTime;
$dateTimeStart->setTime(0, 0, 0, 0);
$dateTimeStart->modify('first day of this month');

$dateTimeEnd = clone $dateTime;
$dateTimeEnd->setTime(0, 0, 0, 0);
$dateTimeEnd->modify('first day of 1 month');

$qb = $this->orderRepository
->createQueryBuilder('o')
->select('
SUM(o.payment_total) AS order_amount,
COUNT(o) AS order_count')
->setParameter(':excludes', $this->excludes)
->setParameter(':targetDate', $dateTime);
->setParameter(':targetDateStart', $dateTimeStart)
->setParameter(':targetDateEnd', $dateTimeEnd)
->andWhere(':targetDateStart <= o.order_date and o.order_date < :targetDateEnd')
->andWhere('o.OrderStatus NOT IN (:excludes)');
$q = $qb->getQuery();

$result = [];
try {
Expand Down
76 changes: 27 additions & 49 deletions tests/Eccube/Tests/Web/Admin/IndexControllerTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -51,11 +51,16 @@ public function testRoutingAdminChangePassword()

/**
* @see https://github.com/EC-CUBE/ec-cube/issues/1143
*
* @param int $hour
*
* @dataProvider indexWithSalesProvider
*/
public function testIndexWithSales()
public function testIndexWithSales($hour)
{
$Customer = $this->createCustomer();
$Today = new \DateTime();
$Today->setTime($hour, 0);
$Yesterday = new \DateTime('-1 days');

$OrderNew = $this->orderStatusRepository->find(OrderStatus::NEW);
Expand Down Expand Up @@ -90,15 +95,14 @@ public function testIndexWithSales()
}
}

$this->client->request(
$crawler = $this->client->request(
'GET',
$this->generateUrl('admin_homepage')
);

$this->assertTrue($this->client->getResponse()->isSuccessful());

// TODO: Need to improve functionality sale today and this month, etc
/* preg_match('/^¥([0-9,]+) \/ ([0-9]+)/u', trim($crawler->filter('.today_sale')->text()), $match);
preg_match('/^¥([0-9,]+) \/ ([0-9]+)/u', trim($crawler->filter('#chart-statistics > div.card-body > div.row:nth-child(1) > div:nth-child(2) > div')->text()), $match);
$this->expected = $todaysSales;
$this->actual = str_replace(',', '', $match[1]);
$this->verify('本日の売上');
Expand All @@ -107,57 +111,31 @@ public function testIndexWithSales()
$this->actual = str_replace(',', '', $match[2]);
$this->verify('本日の売上件数');

preg_match('/^¥([0-9,]+) \/ ([0-9]+)/u', trim($crawler->filter('.yesterday_sale')->text()), $match);
preg_match('/^¥([0-9,]+) \/ ([0-9]+)/u', trim($crawler->filter('#chart-statistics > div.card-body > div.row:nth-child(1) > div:nth-child(3) > div')->text()), $match);
$this->expected = $yesterdaysSales;
$this->actual = str_replace(',', '', $match[1]);
$this->verify('昨日の売上');

$this->expected = 3;
$this->actual = str_replace(',', '', $match[2]);
$this->verify('昨日の売上件数');*/

/*
// 当月の受注を取得する
$firstDate = clone $Today;
$firstDate->setDate($Today->format('Y'), $Today->format('m'), 1);
$firstDate->setTime(0, 0 ,0);
$endDate = clone $firstDate;
$endDate->setDate($Today->format('Y'), $Today->format('m'), $Today->format('t'));
$endDate->setTime(23, 59, 59);

$qb = $this->orderRepository->createQueryBuilder('o');
$qb->andWhere($qb->expr()->notIn('o.OrderStatus',
array(
$OrderPending->getId(),
$OrderProcessing->getId(),
$OrderCancel->getId()
)))
->andWhere('o.order_date BETWEEN :firstDate AND :endDate')
->setParameters(
array(
'firstDate' => $firstDate,
'endDate' => $endDate
)
);
$MonthlyOrders = $qb->getQuery()->getResult();

preg_match('/^¥([0-9,]+) \/ ([0-9]+)/u', trim($crawler->filter('.monthly_sale')->text()), $match);
$this->expected = array_reduce( // MonthlyOrders の payment_total をすべて足す
array_map(
function ($Order) {
return $Order->getPaymentTotal();
}, $MonthlyOrders
),
function ($carry, $item) {
return $carry += $item;
}
);
$this->actual = str_replace(',', '', $match[1]);
$this->verify('今月の売上');

$this->expected = count($MonthlyOrders);
$this->actual = str_replace(',', '', $match[2]);
$this->verify('今月の売上件数');*/
$this->verify('昨日の売上件数');

preg_match('/^¥([0-9,]+) \/ ([0-9]+)/u', trim($crawler->filter('#chart-statistics > div.card-body > div.row:nth-child(1) > div:nth-child(1) > div')->text()), $match);
$this->expected = $todaysSales + $yesterdaysSales;
$this->actual = str_replace(',', '', $match[1]);
$this->verify('今月の売上');

$this->expected = 6;
$this->actual = str_replace(',', '', $match[2]);
$this->verify('今月の売上件数');
}

public function indexWithSalesProvider()
{
return [
[8],
[10],
];
}

public function testChangePasswordWithPost()
Expand Down