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; if(!empty($startDate) && !empty($endDate)) { $query->where('create_time', '>=', strtotime($startDate)) ->where('create_time', '<', strtotime($endDate) + 86400); } return $query->where('status', '=', RefundStatus::COMPLETED)->count(); } /** * 退款总金额 */ public function getRefundTotalMoney($startDate = null, $endDate = null): float { $query = $this->refundModel; if(!empty($startDate) && !empty($endDate)) { $query->where('create_time', '>=', strtotime($startDate)) ->where('create_time', '<', strtotime($endDate) + 86400); } // 总销售额 return $query->where('status', '=', RefundStatus::COMPLETED)->sum('refund_money'); } }