refundModel = new OrderRefund(); } public function getRefundData($startDate = null, $endDate = null): array { return [ 'refundCount' => $this->getRefundCount($startDate, $endDate), 'refundTotalMoney' => $this->getRefundTotalMoney($startDate, $endDate) ]; } /** * 退款总数 */ public function getRefundCount($startDate = null, $endDate = null): int { $query = $this->refundModel; $filter = []; if (!is_null($startDate) && !is_null($endDate)) { $filter[] = ['create_time', '>=', strtotime($startDate)]; $filter[] = ['create_time', '<', strtotime($endDate) + 86400]; } return $query->where($filter)->where('status', '=', RefundStatus::COMPLETED)->count(); } /** * 退款总金额 */ public function getRefundTotalMoney($startDate = null, $endDate = null): float { $query = $this->refundModel; $filter = []; if (!is_null($startDate) && !is_null($endDate)) { $filter[] = ['create_time', '>=', strtotime($startDate)]; $filter[] = ['create_time', '<', strtotime($endDate) + 86400]; } // 总销售额 return $query->where($filter)->where('status', '=', RefundStatus::COMPLETED)->sum('refund_money'); } }