You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
yanzong/app/api/service/statistics/RefundData.php

54 lines
1.7 KiB

10 months ago
<?php
namespace app\api\service\statistics;
10 months ago
use app\api\model\OrderRefund;
10 months ago
use app\common\enum\order\refund\RefundStatus;
10 months ago
use app\common\service\BaseService;
class RefundData extends BaseService
{
10 months ago
protected OrderRefund $refundModel;
public function initialize()
{
parent::initialize(); // TODO: Change the autogenerated stub
$this->refundModel = new OrderRefund();
}
public function getRefundData($startDate = null, $endDate = null): array
10 months ago
{
return [
10 months ago
'refundCount' => $this->getRefundCount($startDate, $endDate),
'refundTotalMoney' => $this->getRefundTotalMoney($startDate, $endDate)
10 months ago
];
}
10 months ago
/**
* 退款总数
*/
public function getRefundCount($startDate = null, $endDate = null): int
{
$query = $this->refundModel;
10 months ago
$filter = [];
if (!is_null($startDate) && !is_null($endDate)) {
$filter[] = ['create_time', '>=', strtotime($startDate)];
$filter[] = ['create_time', '<', strtotime($endDate) + 86400];
10 months ago
}
10 months ago
return $query->where($filter)->where('status', '=', RefundStatus::COMPLETED)->count();
10 months ago
}
/**
* 退款总金额
*/
public function getRefundTotalMoney($startDate = null, $endDate = null): float {
$query = $this->refundModel;
10 months ago
$filter = [];
if (!is_null($startDate) && !is_null($endDate)) {
$filter[] = ['create_time', '>=', strtotime($startDate)];
$filter[] = ['create_time', '<', strtotime($endDate) + 86400];
10 months ago
}
// 总销售额
10 months ago
return $query->where($filter)->where('status', '=', RefundStatus::COMPLETED)->sum('refund_money');
10 months ago
}
10 months ago
}