Create & Init Project...

This commit is contained in:
2019-04-22 18:49:16 +08:00
commit fc4fa37393
25440 changed files with 4054998 additions and 0 deletions

View File

@@ -0,0 +1,44 @@
package(default_visibility = ["//visibility:public"])
load(
"@io_bazel_rules_go//go:def.bzl",
"go_library",
)
go_library(
name = "go_default_library",
srcs = [
"change_history.go",
"contract.go",
"enum.go",
"main_vip.go",
"pay_order.go",
"price_config.go",
"qr.go",
"token.go",
"user_info.go",
"yst.go",
],
importpath = "go-common/app/service/main/tv/internal/model",
tags = ["automanaged"],
visibility = ["//visibility:public"],
deps = [
"//app/service/main/account/api:go_default_library",
"//library/log:go_default_library",
"//library/time:go_default_library",
],
)
filegroup(
name = "package-srcs",
srcs = glob(["**"]),
tags = ["automanaged"],
visibility = ["//visibility:private"],
)
filegroup(
name = "all-srcs",
srcs = [":package-srcs"],
tags = ["automanaged"],
visibility = ["//visibility:public"],
)

View File

@@ -0,0 +1,47 @@
package model
import (
"strconv"
"time"
"go-common/library/log"
xtime "go-common/library/time"
)
// UserChangeHistory 会员变动流水.
type UserChangeHistory struct {
ID int32 `json:"id"` // vip开通历史
Mid int64 `json:"mid"` // 用户mid
ChangeType int8 `json:"change_type"` // 变更类型(1:充值开通 2:系统发放 3:活动赠送 4:重复领取扣除)
ChangeTime xtime.Time `json:"change_time"` // 变更时间
OrderNo string `json:"order_no"` // 关联订单号
Days int32 `json:"days"` // 开通天数
OperatorId string `json:"operator_id"` // 操作人id
Remark string `json:"remark"` // 备注
Ctime xtime.Time `json:"ctime"` // 创建时间
Mtime xtime.Time `json:"mtime"` // 修改时间
}
func (uc *UserChangeHistory) orderType2ChangeType(orderType int8) int8 {
var ct int8
switch orderType {
case PayOrderTypeNormal:
ct = UserChangeTypeRecharge
case PayOrderTypeSub:
ct = UserChangeTypeSystem
default:
log.Error("uc.CopyFromPayOrder() err(UnknownOrderType) orderType(%d)", orderType)
ct = UserChangeTypeRecharge
}
return ct
}
// CopyFromPayOrder copies fields from pay order.
func (uc *UserChangeHistory) CopyFromPayOrder(po *PayOrder) {
uc.Mid = po.Mid
uc.OrderNo = po.OrderNo
uc.Days = int32(po.BuyMonths) * 31
uc.OperatorId = strconv.Itoa(int(po.Mid))
uc.ChangeTime = xtime.Time(time.Now().Unix())
uc.ChangeType = uc.orderType2ChangeType(po.OrderType)
}

View File

@@ -0,0 +1,14 @@
package model
import xtime "go-common/library/time"
// UserContract represents user contract record.
type UserContract struct {
ID int32
Mid int64
ContractId string
OrderNo string
IsDeleted int8
Ctime xtime.Time
Mtime xtime.Time
}

View File

@@ -0,0 +1,67 @@
package model
// enums.
const (
PlatformAndriod = 1
PlatformWechatMp = 2
PlatformSystem = 3
SuitTypeAll = 0
SuitTypeMvip = 10
SubTypeOther = 0
SubTypeContract = 1
PayOrderTypeNormal = 0
PayOrderTypeSub = 1
PayOrderStatusPending = 0
PayOrderStatusPaying = 1
PayOrderStatusSuccess = 2
PayOrderStatusFail = 3
PaymentTypeAliPay = "alipay"
PaymentTypeWechat = "wechat"
UserChangeTypeRecharge = 1
UserChangeTypeSystem = 2
UserChangeTypeGift = 3
UserChangeTypeDup = 4
UserChangeTypeRenewVIp = 5
UserChangeTypeSignContract = 6
UserChangeTypeCancelContract = 7
VipTypeVip = 1
VipTypeAnnualVip = 2
VipPayTypeNormal = 0
VipPayTypeSub = 1
PayChannelAli = "alipay"
PayChannelWechat = "wechat"
VipStatusActive = 1
VipStatusExpired = 0
YstPayWayQr = "1"
YstPayTypeAliPay = "1"
YstPayTypeWechat = "2"
YstPayStatusPaied = "1"
YstPayStatusPending = "0"
YstTradeStateSuccess = "SUCCESS"
YstTradeStateRefund = "REFUND"
YstTradeStateNotPay = "NOTPAY"
YstTradeStateClosed = "CLOSED"
YstTradeStateAccept = "ACCEPT"
YstTradeStatePayFail = "PAY_FAIL"
YstResultSuccess = "0"
YstResultFail = "998"
YstResultSysErr = "999"
YST_CONTRACT_TYPE_SIGN = "ADD"
YST_CONTRSCT_TYPE_CANCEL = "DELETE"
)

View File

@@ -0,0 +1,33 @@
package model
import (
"math"
"time"
)
// MainVip represents bilibili vip info.
type MainVip struct {
Mid int64 `json:"mid"`
VipType int8 `json:"vip_type"` // 大会员类型 0.非大会员 1.月度大会员 2.年度会员
PayType int8 `json:"pay_type"`
VipStatus int8 `json:"vip_status"` //大会员状态: 0.过期 1.未过期 2.冻结 3.封禁
VipDueDate int64 `json:"vip_due_date"`
}
// IsVip returns true if user is vip.
func (mv *MainVip) IsVip() bool {
return mv.VipType != 0 && (mv.VipStatus == 1 || mv.VipStatus == 3)
}
// Months returns vip months.
func (mv *MainVip) Months() int32 {
if !mv.IsVip() {
return 0
}
nowInMs := time.Now().UnixNano() / int64(time.Millisecond)
span := mv.VipDueDate - nowInMs
if span <= 0 {
return 0
}
return int32(math.Floor(float64(span) / 1000 / 60 / 60 / 24 / 31))
}

View File

@@ -0,0 +1,50 @@
package model
import (
xtime "go-common/library/time"
)
// PayOrder represents pay order.
type PayOrder struct {
ID int32 `json:"id"` // 订单表自增ID
OrderNo string `json:"order_no"` // 订单号
Platform int8 `json:"platform"` // 设备平台,1:tv安卓 2:公众号
OrderType int8 `json:"order_type"` // 订单类型0-普通订单 1-自动续费订单
Mid int64 `json:"mid"` // 下单支付的用户mid
BuyMonths int8 `json:"buy_months"` // 购买vip时长
ProductId string `json:"product_id"` // 产品id
Money int32 `json:"money"` // vip单价单位分
Quantity int32 `json:"quantity"` // 购买数量
RefundAmount int32 `json:"refund_amount"` // 退款金额,单位分
Status int8 `json:"status"` // 订单状态1.消费中 2.消费成功 3.消费失败
ThirdTradeNo string `json:"third_trade_no"` // 第三方订单号yst订单号
PaymentMoney int32 `json:"payment_money"` // 真正支付金额,单位分
PaymentType string `json:"payment_type"` // 支付方式alipay,wechat
PaymentTime xtime.Time `json:"payment_time"` // 支付时间
Ver int32 `json:"ver"` // 版本号,用于乐观锁
AppChannel string `json:"app_channel"` // 应用渠道
Token string
Ctime xtime.Time `json:"ctime"` // 创建时间
Mtime xtime.Time `json:"mtime"` // 修改时间
}
// CopyFromPayParam copies fiels from pay param.
func (p *PayOrder) CopyFromPayParam(pp *PayParam) {
p.OrderNo = pp.OrderNo
p.Quantity = pp.BuyNum
p.AppChannel = pp.AppChannel
}
// CopyFromPanel copies field from panel.
func (p *PayOrder) CopyFromPanel(panel *PanelPriceConfig) {
if panel.SubType == 0 {
p.OrderType = 0
}
if panel.SubType == 1 {
p.OrderType = 1
}
p.ProductId = panel.ProductId
p.Money = panel.Price
p.BuyMonths = int8(panel.Month * p.Quantity)
p.PaymentMoney = panel.Price * p.Quantity
}

View File

@@ -0,0 +1,73 @@
package model
import (
xtime "go-common/library/time"
)
// PriceConfig represents price config of tv vip.
type PriceConfig struct {
ID int32 `json:"id"` // 主键id
Pid int32 `json:"pid"` // 父id为空表示为原价信息
Platform int8 `json:"platform"` // 类型: 1:tv安卓 2:公众号
ProductName string `json:"product_name"` // 产品展示名
ProductId string `json:"product_id"` // 产品id
SuitType int8 `json:"suit_type"` // 适用人群: 0.所有用户 1.旧客 2.新客 3.续期旧客 4.续期新客 5.套餐旧客 6.套餐新客 10.主站vip专项
Month int32 `json:"month"` // 月份单位
SubType int8 `json:"sub_type"` // 订阅类型0.其他1.连续包月
Price int32 `json:"price"` // 价格pid为0表示原价,单位:分
Selected int8 `json:"selected"` // 选中状态: 0.未选中1.选中
Remark string `json:"remark"` // 促销tip
Status int8 `json:"status"` // 状态0:有效,1:失效
Superscript string `json:"superscript"` // 角标
Operator string `json:"operator"` // 操作者
OperId int64 `json:"oper_id"` // 操作者id
Stime xtime.Time `json:"stime"` // 折扣开始时间
Etime xtime.Time `json:"etime"` // 折扣结束时间
Ctime xtime.Time `json:"ctime"` // 创建时间
Mtime xtime.Time `json:"mtime"` // 最后修改时间
}
// PanelPriceConfig represents panel config of tv vip.
type PanelPriceConfig struct {
PriceConfig
MaxNum int32 // 允许最大购买数量,-1 表示不限制
OriginPrice int32 // 原价
}
// CopyFromPriceConfig copies fields from price config.
func (pi *PanelPriceConfig) CopyFromPriceConfig(pc *PriceConfig) {
pi.ID = pc.ID
pi.Pid = pc.Pid
pi.Platform = pc.Platform
pi.ProductName = pc.ProductName
pi.ProductId = pc.ProductId
pi.SuitType = pc.SuitType
pi.Month = pc.Month
pi.SubType = pc.SubType
pi.Price = pc.Price
pi.Selected = pc.Selected
pi.Remark = pc.Remark
pi.Status = pc.Status
pi.Superscript = pc.Superscript
pi.Operator = pc.Operator
pi.OperId = pc.OperId
pi.Stime = pc.Stime
pi.Etime = pc.Etime
pi.Ctime = pc.Ctime
pi.Mtime = pc.Mtime
pi.MaxNum = 1
}
// IsContracted returns true if panel is contracted package.
func (pi *PanelPriceConfig) IsContracted() bool {
return pi.SubType == SubTypeContract
}
// PidOrId returns panel parent id or panel id.
func (pi *PanelPriceConfig) PidOrId() int32 {
if pi.Pid != 0 {
return pi.Pid
}
return pi.ID
}

View File

@@ -0,0 +1,44 @@
package model
import (
"crypto/md5"
"fmt"
"io"
"strconv"
"time"
xtime "go-common/library/time"
)
// QR represents pay qr info.
type QR struct {
ExpireAt xtime.Time
URL string
Token string
}
// PayParam represents pay params.
type PayParam struct {
Mid int64
Pid int32
BuyNum int32
Guid string
AppChannel string
Status int8
OrderNo string
ExpireAt xtime.Time
}
// MD5 calculates md5 of pay params.
func (p *PayParam) MD5() string {
m := md5.New()
io.WriteString(m, strconv.Itoa(int(p.Mid)))
io.WriteString(m, strconv.Itoa(int(p.Pid)))
io.WriteString(m, strconv.Itoa(int(p.ExpireAt)))
return fmt.Sprintf("%x", string(m.Sum(nil)))
}
// IsExpired return true if pay param is expired.
func (p *PayParam) IsExpired() bool {
return int64(p.ExpireAt) < time.Now().Unix()
}

View File

@@ -0,0 +1,16 @@
package model
// TokenInfo represents pay token.
type TokenInfo struct {
Token string
OrderNo string
Status int8
Mid int64
}
// CopyFromPayParam copies fields from pay param.
func (t *TokenInfo) CopyFromPayParam(pp *PayParam) {
t.Mid = pp.Mid
t.Status = pp.Status
t.OrderNo = pp.OrderNo
}

View File

@@ -0,0 +1,69 @@
package model
import (
"time"
xtime "go-common/library/time"
)
// UserInfo represents user info.
type UserInfo struct {
ID int32 `json:"id"` // 用户信息表
Mid int64 `json:"mid"` // 用户mid
Ver int32 `json:"ver"` // 版本控制
VipType int8 `json:"vip_type"` // tv-vip类型:1.vip 2.年费vip
PayType int8 `json:"pay_type"` // tv-vip购买类型:0.正常购买 1.连续包月
PayChannelId string `json:"pay_channel_id"` // 自动续费渠道:wechat,alipay
Status int8 `json:"status"` // tv-vip状态:0:过期 1:未过期
OverdueTime xtime.Time `json:"overdue_time"` // tv-vip过期时间
RecentPayTime xtime.Time `json:"recent_pay_time"` // tv-vip最近开通时间
Ctime xtime.Time `json:"ctime"` // 创建时间
Mtime xtime.Time `json:"mtime"` // 修改时间
}
// IsEmpty returns true if user id equals -1.
func (ui *UserInfo) IsEmpty() bool {
return ui.ID == -1
}
// IsExpired returns true if user is expired vip.
func (ui *UserInfo) IsExpired() bool {
return ui.OverdueTime < xtime.Time(time.Now().Unix())
}
// MarkExpired sets user status to expired status.
func (ui *UserInfo) MarkExpired() {
ui.Status = 0
}
// IsVip returns true if user is vip.
func (ui *UserInfo) IsVip() bool {
if ui.IsEmpty() {
return false
}
if ui.IsExpired() {
return false
}
return ui.Status == 1
}
// IsContracted returns true if user buys contracted package.
func (ui *UserInfo) IsContracted() bool {
return ui.PayType == 1
}
// CopyFromPayOrder copies fileds from pay order.
func (ui *UserInfo) CopyFromPayOrder(po *PayOrder) {
ui.VipType = VipTypeVip
ui.PayChannelId = po.PaymentType
ui.RecentPayTime = xtime.Time(time.Now().Unix())
}
// CopyFromPanel copies field from panel.
func (ui *UserInfo) CopyFromPanel(p *PanelPriceConfig) {
if p.SubType == SubTypeContract {
ui.PayType = VipPayTypeSub
return
}
ui.PayType = VipPayTypeNormal
}

View File

@@ -0,0 +1,167 @@
package model
import (
"strconv"
"go-common/app/service/main/account/api"
)
// YstCreateOrderReq represents request of yst order creation.
type YstCreateOrderReq struct {
SeqNo string `json:"seqno" url:"seqno"`
Source string `json:"source" url:"source"`
ProductId string `json:"product_id" url:"product_id"`
Price int32 `json:"price" url:"price"`
Total int32 `json:"total" url:"total"`
BuyNum int32 `json:"buy_num" url:"buy_num"`
VideoType string `json:"video_type" url:"video_type"`
PayType string `json:"pay_type" url:"pay_type"`
PayWay string `json:"pay_way" url:"pay_way"`
UserLogin string `json:"user_login" url:"user_login"`
UserId string `json:"user_id" url:"user_id"`
GUID string `json:"guid" url:"guid"`
ClientIp string `json:"client_ip" url:"client_ip"`
Sign string `json:"sign" url:"sign,omitempty"`
LoginName string `json:"login_name" url:"login_name"`
}
// CopyFromPayOrder copies fields from pay order.
func (y *YstCreateOrderReq) CopyFromPayOrder(po *PayOrder) {
y.SeqNo = po.OrderNo
y.Source = "snm_bilibili"
y.ProductId = po.ProductId
y.Price = po.Money
y.Total = po.PaymentMoney
y.BuyNum = po.Quantity
if po.OrderType == 0 {
y.VideoType = "fvod"
}
if po.OrderType == 1 {
y.VideoType = "svod"
}
if po.PaymentType == PaymentTypeAliPay {
y.PayType = YstPayTypeAliPay
}
if po.PaymentType == PaymentTypeWechat {
y.PayType = YstPayTypeWechat
}
y.PayWay = YstPayWayQr
}
// CopyFromAccount copies fields from account info.
func (y *YstCreateOrderReq) CopyFromAccount(account *api.Info) {
y.LoginName = account.Name
y.UserId = strconv.Itoa(int(account.Mid))
}
// YstCreateOrderReply represents response of yst order creation.
type YstCreateOrderReply struct {
SeqNo string `json:"seqno" url:"seqno"`
TraceNo string `json:"traceno" url:"traceno"`
PayWary string `json:"pay_wary" url:"pay_wary"`
CodeUrl string `json:"code_url" url:"code_url"`
ContractCode string `json:"contract_code" url:"contract_code"`
Price int32 `json:"price" url:"price"`
VideoType string `json:"video_type" url:"video_type"`
PayParam string `json:"pay_param" url:"pay_param"`
ResultCode string `json:"result_code" url:"result_code"`
ResultMsg string `json:"result_msg" url:"result_msg"`
Sign string `json:"sign"`
}
// YstPayCallbackReq represents request of pay callback.
type YstPayCallbackReq struct {
SeqNo string `json:"seqno" url:"seqno"`
TraceNo string `json:"traceno" url:"traceno"`
TradeState string `json:"trade_state" url:"trade_state"`
ContractId string `json:"contract_id" url:"contract_id,omitempty"`
Sign string `json:"sign" url:"sign"`
}
// YstPayCallbackReply represents response of pay callback.
type YstPayCallbackReply struct {
TraceNo string
Result string
Msg string
}
// PayInfo represents short pay details.
type PayInfo struct {
OrderNo string
PaymentType string
CodeUrl string
PaymentMoney int32
}
// CopyFromPayOrder copies fields from pay order.
func (p *PayInfo) CopyFromPayOrder(po *PayOrder) {
p.OrderNo = po.OrderNo
p.PaymentType = po.PaymentType
p.PaymentMoney = po.PaymentMoney
}
// YstRenewOrderReq.
type YstRenewOrderReq struct {
SeqNo string `json:"seqno" url:"seqno"`
Source string `json:"source" url:"source"`
ProductId string `json:"product_id" url:"product_id"`
Price int32 `json:"price" url:"price"`
BuyNum int32 `json:"buy_num" url:"buy_num"`
Total int32 `json:"total" url:"total"`
VideoType string `json:"video_type" url:"video_type"`
PayType string `json:"pay_type" url:"pay_type"`
UserId string `json:"user_id" url:"user_id"`
ContractId string `json:"contract_id" url:"contract_id"`
Sandbox string `json:"sandbox" url:"sandbox"`
ClientIp string `json:"client_ip" url:"client_ip"`
Sign string `json:"sign"`
}
// YstRenewOrderReply.
type YstRenewOrderReply struct {
SeqNo string `json:"seqno" url:"seqno"`
TraceNo string `json:"traceno" url:"traceno"`
Price int32 `json:"price" url:"price"`
VideoType string `json:"video_type" url:"video_type"`
ResultCode string `json:"result_code" url:"result_code"`
ResultMsg string `json:"result_msg" url:"result_msg"`
Sign string `json:"sign" `
}
// YstOrderState.
type YstOrderStateReq struct {
SeqNo string `json:"seqno" url:"seqno"`
TraceNo string `json:"traceno" url:"traceno"`
Sign string `json:"sign" url:"sign"`
}
// YstOrderStateReply.
type YstOrderStateReply struct {
SeqNo string `json:"seqno" `
TraceNo string `json:"traceno" `
PayStatus string `json:"pay_status"`
Result string `json:"result"`
Msg string `json:"msg"`
}
// YstUserInfoReq.
type YstUserInfoReq struct {
Mid int32 `json:"mid" url:"mid"`
Sign string `json:"sign" url:"sign,omitempty"`
}
// WxContractCallbackReq.
type WxContractCallbackReq struct {
ContractId string `json:"contract_id" url:"contract_id"`
ContractCode string `json:"contract_code" url:"contract_code"`
ChangeType string `json:"change_type" url:"contract_id"`
ContractTerminationMode string `json:"contract_termination_mode" url:"contract_termination_mode,omitempty"`
Sign string `json:"sign" url:"sign"`
}
// WxContractCallbackReply.
type WxContractCallbackReply struct {
ContractId string `json:"contract_id"`
Result string `json:"result"`
Msg string `json:"msg"`
}