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

1 year ago
<?php
namespace app\api\service\statistics;
1 year ago
use app\api\model\OrderRefund;
1 year ago
use app\common\enum\order\refund\RefundStatus;
1 year ago
use app\common\service\BaseService;
class RefundData extends BaseService
{
1 year 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
1 year ago
{
return [
1 year ago
'refundCount' => $this->getRefundCount($startDate, $endDate),
'refundTotalMoney' => $this->getRefundTotalMoney($startDate, $endDate)
1 year ago
];
}
1 year ago
/**
* 退款总数
*/
public function getRefundCount($startDate = null, $endDate = null): int
{
$query = $this->refundModel;
1 year ago
$filter = [];
if (!is_null($startDate) && !is_null($endDate)) {
$filter[] = ['create_time', '>=', strtotime($startDate)];
$filter[] = ['create_time', '<', strtotime($endDate) + 86400];
1 year ago
}
1 year ago
return $query->where($filter)->where('status', '=', RefundStatus::COMPLETED)->count();
1 year ago
}
/**
* 退款总金额
*/
public function getRefundTotalMoney($startDate = null, $endDate = null): float {
$query = $this->refundModel;
1 year ago
$filter = [];
if (!is_null($startDate) && !is_null($endDate)) {
$filter[] = ['create_time', '>=', strtotime($startDate)];
$filter[] = ['create_time', '<', strtotime($endDate) + 86400];
1 year ago
}
// 总销售额
1 year ago
return $query->where($filter)->where('status', '=', RefundStatus::COMPLETED)->sum('refund_money');
1 year ago
}
1 year ago
}