toArray(); $total = 0; $ing = 0; $success = 0; $error = 0; foreach ($records as $record) { $total += $record['order_amount']; switch ($record['refund_status']) { case RefundEnum::REFUND_ING: $ing += $record['order_amount']; break; case RefundEnum::REFUND_SUCCESS: $success += $record['order_amount']; break; case RefundEnum::REFUND_ERROR: $error += $record['order_amount']; break; } } return [ 'total' => round($total, 2), 'ing' => round($ing, 2), 'success' => round($success, 2), 'error' => round($error, 2), ]; } /** * @notes 退款日志 * @param $recordId * @return array * @throws \think\db\exception\DataNotFoundException * @throws \think\db\exception\DbException * @throws \think\db\exception\ModelNotFoundException * @author 段誉 * @date 2023/3/3 14:25 */ public static function refundLog($recordId) { return (new RefundLog()) ->order(['id' => 'desc']) ->where('record_id', $recordId) ->hidden(['refund_msg']) ->append(['handler', 'refund_status_text']) ->select() ->toArray(); } }