135 lines
6.3 KiB
Go
135 lines
6.3 KiB
Go
package dto
|
||
|
||
import (
|
||
"fmt"
|
||
"github.com/wechatpay-apiv3/wechatpay-go/services/payments/app"
|
||
"github.com/wechatpay-apiv3/wechatpay-go/services/payments/jsapi"
|
||
"hepa-calc-api/api/model"
|
||
)
|
||
|
||
// OrderSingleDto 订单-单项
|
||
type OrderSingleDto struct {
|
||
OrderId string `json:"order_id"` // 主键id
|
||
UserId string `json:"user_id"` // 用户id
|
||
QuestionId string `json:"question_id"` // 问题id
|
||
OrderStatus int `json:"order_status"` // 订单状态(1:待支付 2:已完成 3:已取消)
|
||
IsDelete int `json:"is_delete"` // 用户删除状态(0:否 1:是)
|
||
PayChannel int `json:"pay_channel"` // 支付渠道(1:h5支付 2:app支付 3:会员支付)
|
||
PayStatus int `json:"pay_status"` // 支付状态(1:未支付 2:已支付 3:支付中 4:支付失败 5:支付超时 6:支付关闭 7:已撤销 8:转入退款)
|
||
PayTime *model.LocalTime `json:"pay_time"` // 支付时间
|
||
RefundStatus int `json:"refund_status"` // 订单退款状态(0:无退款 1:申请退款 2:退款中 3:退款成功 4:拒绝退款 5:退款关闭 6:退款异常 7:部分退款)
|
||
OrderNo string `json:"order_no"` // 系统订单编号
|
||
EscrowTradeNo string `json:"escrow_trade_no"` // 第三方支付流水号
|
||
AmountTotal float64 `json:"amount_total"` // 订单金额
|
||
CouponAmountTotal float64 `json:"coupon_amount_total"` // 优惠卷总金额
|
||
PaymentAmountTotal float64 `json:"payment_amount_total"` // 实际付款金额
|
||
CancelStatus int `json:"cancel_status"` // 取消状态(0:否 1:是)
|
||
CancelTime *model.LocalTime `json:"cancel_time"` // 订单取消时间
|
||
CancelRemarks string `json:"cancel_remarks"` // 取消订单备注
|
||
ValidDate *model.LocalTime `json:"valid_date"` // 到期时间
|
||
OrderRemarks string `json:"order_remarks"` // 订单备注
|
||
CreatedAt model.LocalTime `json:"created_at"` // 创建时间
|
||
UpdatedAt model.LocalTime `json:"updated_at"` // 更新时间
|
||
Question *QuestionDto `json:"question"` // 问题
|
||
}
|
||
|
||
// OrderSinglePayDto 单项订单支付数据
|
||
type OrderSinglePayDto struct {
|
||
OrderId string `json:"order_id"` // 主键id
|
||
QuestionId string `json:"question_id"` // 问题id
|
||
OrderNo string `json:"order_no"` // 系统订单编号
|
||
AmountTotal float64 `json:"amount_total"` // 订单金额
|
||
CouponAmountTotal float64 `json:"coupon_amount_total"` // 优惠卷总金额
|
||
PaymentAmountTotal float64 `json:"payment_amount_total"` // 实际付款金额
|
||
CreatedAt model.LocalTime `json:"created_at"` // 创建时间
|
||
PrepayJsapi *jsapi.PrepayWithRequestPaymentResponse `json:"prepay_jsapi"` // 预支付交易数据-jsapi
|
||
PrepayApp *app.PrepayWithRequestPaymentResponse `json:"prepay_app"` // 预支付交易数据-app
|
||
}
|
||
|
||
// OrderSinglePayStatusDto 单项订单支付状态
|
||
type OrderSinglePayStatusDto struct {
|
||
PayStatus int `json:"pay_status"` // 支付状态(1:未支付 2:已支付 3:支付中 4:支付失败 5:支付超时 6:支付关闭 7:已撤销 8:转入退款)
|
||
PaymentAmountTotal float64 `json:"payment_amount_total"` // 实际付款金额
|
||
ValidDate *model.LocalTime `json:"valid_date"` // 到期时间
|
||
}
|
||
|
||
// AddOrderSingleDto 创建单项订单
|
||
type AddOrderSingleDto struct {
|
||
OrderId string `json:"order_id"` // 主键id
|
||
OrderNo string `json:"order_no"` // 系统订单编号
|
||
}
|
||
|
||
// GetOrderSingleListDto 列表
|
||
func GetOrderSingleListDto(m []*model.OrderSingle) []*OrderSingleDto {
|
||
// 处理返回值
|
||
responses := make([]*OrderSingleDto, len(m))
|
||
|
||
if len(m) > 0 {
|
||
for i, v := range m {
|
||
response := &OrderSingleDto{
|
||
OrderId: fmt.Sprintf("%d", v.OrderId),
|
||
UserId: fmt.Sprintf("%d", v.UserId),
|
||
QuestionId: fmt.Sprintf("%d", v.QuestionId),
|
||
OrderStatus: v.OrderStatus,
|
||
IsDelete: v.IsDelete,
|
||
PayChannel: v.PayChannel,
|
||
PayStatus: v.PayStatus,
|
||
PayTime: v.PayTime,
|
||
RefundStatus: v.RefundStatus,
|
||
OrderNo: v.OrderNo,
|
||
EscrowTradeNo: v.EscrowTradeNo,
|
||
AmountTotal: v.AmountTotal,
|
||
CouponAmountTotal: v.CouponAmountTotal,
|
||
PaymentAmountTotal: v.PaymentAmountTotal,
|
||
CancelStatus: v.CancelStatus,
|
||
CancelTime: v.CancelTime,
|
||
CancelRemarks: v.CancelRemarks,
|
||
ValidDate: v.ValidDate,
|
||
OrderRemarks: v.OrderRemarks,
|
||
CreatedAt: v.CreatedAt,
|
||
UpdatedAt: v.UpdatedAt,
|
||
}
|
||
|
||
// 加载问题数据
|
||
if v.Question != nil {
|
||
response = response.LoadQuestion(v.Question)
|
||
}
|
||
|
||
// 将转换后的结构体添加到新切片中
|
||
responses[i] = response
|
||
}
|
||
}
|
||
|
||
return responses
|
||
}
|
||
|
||
// GetOrderSinglePayDto 获取单项订单支付数据
|
||
func GetOrderSinglePayDto(m *model.OrderSingle) *OrderSinglePayDto {
|
||
return &OrderSinglePayDto{
|
||
OrderId: fmt.Sprintf("%d", m.OrderId),
|
||
QuestionId: fmt.Sprintf("%d", m.QuestionId),
|
||
OrderNo: m.OrderNo,
|
||
AmountTotal: m.AmountTotal,
|
||
CouponAmountTotal: m.CouponAmountTotal,
|
||
PaymentAmountTotal: m.PaymentAmountTotal,
|
||
CreatedAt: m.CreatedAt,
|
||
}
|
||
}
|
||
|
||
// GetOrderSinglePayStatus 获取单项订单支付状态
|
||
func GetOrderSinglePayStatus(m *model.OrderSingle) *OrderSinglePayStatusDto {
|
||
return &OrderSinglePayStatusDto{
|
||
PayStatus: m.PayStatus,
|
||
PaymentAmountTotal: m.PaymentAmountTotal,
|
||
ValidDate: m.ValidDate,
|
||
}
|
||
}
|
||
|
||
// LoadQuestion 加载题目数据
|
||
func (r *OrderSingleDto) LoadQuestion(m *model.Question) *OrderSingleDto {
|
||
if m != nil {
|
||
r.Question = GetQuestionDto(m)
|
||
}
|
||
return r
|
||
}
|