micro-bundle/internal/model/bundle_order_records.go

170 lines
12 KiB
Go

package model
import (
"database/sql/driver"
"encoding/json"
"errors"
"gorm.io/gorm"
)
// BundleOrderRecords struct
type BundleOrderRecords struct {
gorm.Model
UUID string `json:"uuid" gorm:"column:uuid;type:varchar(1024);comment:UUID"`
OrderNo string `json:"orderNo" gorm:"column:order_no;type:varchar(1024);comment:交易编号"`
BundleUUID string `json:"bundleUUID" gorm:"column:bundle_uuid;type:varchar(1024);comment:套餐UUID"`
BundleName string `json:"bundleName" gorm:"column:bundle_name;type:varchar(2048);comment:套餐名"`
CustomerID string `json:"customerID" gorm:"column:customer_id;type:varchar(1024);comment:客户ID"`
CustomerNum string `json:"customerNum" gorm:"column:customer_num;type:varchar(1024);comment:客户编号"`
CustomerName string `json:"customerName" gorm:"column:customer_name;type:varchar(1024);comment:客户名"`
Amount float32 `json:"amount" gorm:"column:amount;type:decimal(12,2);comment:套餐金额"`
AmountType int64 `json:"amountType" gorm:"column:amount_type;type:int;comment:金额类型"`
ValueAddBundleUUID string `json:"valueAddBundleUUID" gorm:"column:value_add_bundle_uuid;type:varchar(1024);comment:增值套餐记录UUID"`
ValueAddBundleAmount float32 `json:"valueAddBundleAmount" gorm:"column:value_add_bundle_amount;type:decimal(12,2);comment:增值套餐金额"`
ValueAddOriginalPrice float32 `json:"valueAddOriginalPrice" gorm:"column:value_add_original_price;type:decimal(12,2);comment:原单价"`
ValueAddDiscountPrice float32 `json:"valueAddDiscountPrice" gorm:"column:value_add_discount_price;type:decimal(12,2);comment:优惠单价"`
ValueAddSavedAmount float32 `json:"valueAddSavedAmount" gorm:"column:value_add_saved_amount;type:decimal(12,2);comment:节省金额"`
TotalAmount float32 `json:"totalAmount" gorm:"column:total_amount;type:decimal(12,2);comment:总金额"`
Num int32 `json:"num" gorm:"column:num;type:int;comment:视频数量"`
SignContract string `json:"signContract" gorm:"column:sign_contract;type:varchar(1024);comment:签约合同"`
Signature string `json:"signature" gorm:"column:signature;type:text;comment:签字"`
SignedTime string `json:"signedTime" gorm:"column:signed_time;type:varchar(1024);comment:签约时间(北京时间)"`
PayType int64 `json:"payType" gorm:"column:pay_type;type:int;comment:支付类型"`
PayTime string `json:"payTime" gorm:"column:pay_time;type:varchar(1024);comment:支付时间(北京时间)"`
CheckoutSessionId string `json:"checkoutSessionId" gorm:"column:checkout_session_id;type:varchar(1024);default:null;comment:checkoutSessionId"`
CheckoutSessionUrl string `json:"checkoutSessionUrl" gorm:"column:checkout_session_url;type:varchar(1024);default:null;comment:checkoutSessionUrl"`
Status int64 `json:"status" gorm:"column:status;type:int;comment:状态 1:已签未支付 2:已签已支付"`
ContractNo string `json:"contractNo" gorm:"column:contract_no;type:varchar(1024);comment:合同编号"`
BundleCommonUid string `json:"bundleCommonUid" gorm:"column:bundle_common_uid;type:text;comment:套餐公共ID"`
AddBundleCommonUid string `json:"addBundleCommonUid" gorm:"column:add_bundle_common_uid;type:text;comment:附加套餐公共ID"`
FinancialConfirmation int32 `json:"financialConfirmation" gorm:"column:financial_confirmation;type:int;comment:财务确认 1:未确认 2:已确认"`
ExpirationTime string `json:"expirationTime" gorm:"column:expiration_time;comment:套餐过期时间"`
BundleCommonJson json.RawMessage `json:"bundle_common_json" gorm:"column:bundle_common_json;type:json;serializer:json;comment:套餐信息"`
Language string `gorm:"column:language;comment:语言" json:"language"`
BundleOrderValueAdd []BundleOrderValueAdd `gorm:"foreignKey:OrderUUID;references:UUID" json:"bundleOrderValueAdd"`
ReSignature int `json:"reSignature" gorm:"column:re_signature;default:2;type:int;comment:是否重新签 1:是 2:否"`
PlatformIds PlatformIDs `gorm:"column:platform_ids;type:json;NOT NULL;comment:发布平台ID集合 TIKTOK= 1, YOUTUBE = 2, INS = 3 , DM = 4, BL = 5;" json:"platformIDs"`
InviterID uint64 `gorm:"column:inviter_id;type:bigint;comment:邀请人ID" json:"inviterID"`
PurchaseType uint64 `gorm:"column:purchase_type;type:bigint;comment:购买类型 1:新购 2:续费" json:"purchaseType"`
RenewalOrderUUID string `gorm:"column:renewal_order_uuid;type:varchar(1024);comment:续费订单UUID" json:"renewalOrderUUID"`
OrderMode int32 `gorm:"column:order_mode;type:int;default:1;comment:订单模式 1:普通 2:先用后付;index:idx_customer_order_mode,priority:2" json:"orderMode"`
DueTime string `gorm:"column:due_time;type:varchar(64);comment:先用后付到期应付时间" json:"dueTime"`
PayLaterStatus int32 `gorm:"column:pay_later_status;type:int;default:0;comment:先用后付状态 0:无 1:待付款 2:已付款 3:逾期未付;index:idx_paylater_status" json:"payLaterStatus"`
ContractTplType int32 `gorm:"column:contract_tpl_type;type:int;default:0;comment:合同模板类型 1:套餐普通 2:套餐先用后付 3:增值先用后付" json:"contractTplType"`
OrderType int32 `gorm:"column:order_type;type:int;default:1;comment:订单类型 1:套餐订单 2:增值服务订单" json:"orderType"`
}
type BundleOrderValueAdd struct {
gorm.Model
UUID string `json:"uuid" gorm:"column:uuid;type:varchar(1024);comment:UUID"`
OrderNo string `json:"orderNo" gorm:"column:order_no;type:varchar(1024);comment:交易编号"`
OrderUUID string `json:"orderUUID" gorm:"column:order_uuid;type:varchar(1024);comment:套餐UUID"`
CustomerID string `json:"customerID" gorm:"column:customer_id;type:varchar(1024);comment:客户ID"`
CustomerNum string `json:"customerNum" gorm:"column:customer_num;type:varchar(1024);comment:客户编号"`
CustomerName string `json:"customerName" gorm:"column:customer_name;type:varchar(1024);comment:客户名"`
ServiceType int32 `json:"serviceType" gorm:"column:service_type;type:int;comment:服务类型 1:视频 2:图文 3:数据报表 4:账号数 5:可用时长"`
CurrencyType int64 `json:"currencyType" gorm:"column:currency_type;type:int;comment:货币类型"`
Amount float64 `json:"amount" gorm:"column:amount;type:decimal(12,2);comment:金额"`
Num int32 `json:"num" gorm:"column:num;type:int;comment:数量"`
Unit string `json:"unit" gorm:"column:unit;type:varchar(1024);comment:单位 1个 2条 3天 4月 5年"`
ValueAddUUID string `json:"valueAddUUID" gorm:"column:value_add_uuid;type:varchar(1024);comment:增值服务UUID"`
Source int `json:"source" gorm:"column:source;comment:增加方式 1套餐 2单独购买 3拓展"`
Remark string `json:"remark" gorm:"column:remark;comment:备注"`
PaymentStatus int `json:"paymentStatus" gorm:"column:payment_status;comment:支付状态 1未支付 2已支付"`
PaymentTime string `gorm:"column:payment_time;comment:支付时间" json:"paymentTime"`
SignContract string `json:"signContract" gorm:"column:sign_contract;type:varchar(1024);comment:签约合同"`
Signature string `json:"signature" gorm:"column:signature;type:text;comment:签字"`
SignedTime string `json:"signedTime" gorm:"column:signed_time;type:varchar(1024);comment:签约时间(北京时间)"`
Snapshot string `gorm:"column:snapshot;comment:快照" json:"snapshot"` //订单快照
CheckoutSessionId string `json:"checkoutSessionId" gorm:"column:checkout_session_id;type:varchar(1024);default:null;comment:checkoutSessionId"`
CheckoutSessionUrl string `json:"checkoutSessionUrl" gorm:"column:checkout_session_url;type:varchar(1024);default:null;comment:checkoutSessionUrl"`
HandlingFee string `gorm:"column:handling_fee;comment:手续费" json:"handlingFee"`
EquityType int32 `gorm:"column:equity_type;comment:权益类型 1:套餐权益 2:附加权益" json:"equityType"`
QuotaType int32 `json:"quotaType" gorm:"column:quota_type;type:int;default:1;comment:额度类型 1:不限额度 2:每月限额度"`
QuotaValue int32 `json:"quotaValue" gorm:"column:quota_value;type:int;comment:额度值"`
IsExpired bool `json:"isExpired" gorm:"column:is_expired;default:false;comment:是否过期作废 false:不作废 true:作废"`
//OrderMode int32 `json:"orderMode" gorm:"column:order_mode;type:int;default:2;comment:订单模式 1:普通 2:先用后付(增值默认2);index:idx_valueadd_order_mode"`
//DueTime string `json:"dueTime" gorm:"column:due_time;type:varchar(64);comment:先用后付到期应付时间"`
//PayLaterStatus int32 `json:"payLaterStatus" gorm:"column:pay_later_status;type:int;default:0;comment:先用后付状态 0:无 1:待付款 2:已付款 3:逾期未付;index:idx_valueadd_paylater_status"`
//ContractTplType int32 `json:"contractTplType" gorm:"column:contract_tpl_type;type:int;default:0;comment:合同模板类型 3:增值先用后付"`
}
type PlatformIDs []uint32
// 实现 Scanner 接口
func (p *PlatformIDs) Scan(value interface{}) error {
if value == nil {
*p = []uint32{}
return nil
}
bytes, ok := value.([]byte)
if !ok {
return errors.New("type assertion to []byte failed")
}
return json.Unmarshal(bytes, p)
}
// 实现 Valuer 接口
func (p PlatformIDs) Value() (driver.Value, error) {
if len(p) == 0 {
return "[]", nil
}
return json.Marshal(p)
}
// 财务确认状态
const (
ConfirmationNotConfirmed = 1
ConfirmationConfirmed = 2
)
// 订单模式
const (
OrderModeNormal int32 = 1 // 普通订单
OrderModePayLater int32 = 2 // 先用后付订单
)
// 套餐订单 Status
const (
BundleStatusSignedUnpaid int64 = 1 // 已签未支付
BundleStatusPaid int64 = 2 // 已签已支付
BundleStatusOverdue int64 = 3 // 先用后付到期未付
BundleStatusCompleted int64 = 4 // 已完成(已支付且已过期)
)
// 先用后付状态
const (
PayLaterStatusNone int32 = 0
PayLaterStatusPending int32 = 1 // 待付款
PayLaterStatusPaid int32 = 2 // 已付款
PayLaterStatusOverdue int32 = 3 // 逾期未付
)
// 合同模板类型
const (
ContractTplBundleNormal int32 = 1 // 套餐-普通
ContractTplBundlePayLater int32 = 2 // 套餐-先用后付
ContractTplValueAddPayLater int32 = 3 // 增值-先用后付
)
// 下单校验业务类型
const (
OrderKindBundle int32 = 1
OrderKindValueAdd int32 = 2
)
// 下单校验错误码
const (
OrderGateReasonPayLaterBundleOverdue = "PAYLATER_BUNDLE_OVERDUE"
OrderGateReasonPayLaterBundlePending = "PAYLATER_BUNDLE_PENDING"
OrderGateReasonBundleActiveExists = "BUNDLE_ACTIVE_EXISTS"
OrderGateReasonValueAddLocked = "VALUE_ADD_OVERDUE_LOCKED"
)
// 订单类型
const (
OrderTypeBundle int32 = 1 // 套餐订单
OrderTypeValueAdd int32 = 2 // 增值服务订单
)