Create & Init Project...
This commit is contained in:
22
app/interface/main/ugcpay/BUILD
Normal file
22
app/interface/main/ugcpay/BUILD
Normal file
@ -0,0 +1,22 @@
|
||||
filegroup(
|
||||
name = "package-srcs",
|
||||
srcs = glob(["**"]),
|
||||
tags = ["automanaged"],
|
||||
visibility = ["//visibility:private"],
|
||||
)
|
||||
|
||||
filegroup(
|
||||
name = "all-srcs",
|
||||
srcs = [
|
||||
":package-srcs",
|
||||
"//app/interface/main/ugcpay/api/http:all-srcs",
|
||||
"//app/interface/main/ugcpay/cmd:all-srcs",
|
||||
"//app/interface/main/ugcpay/conf:all-srcs",
|
||||
"//app/interface/main/ugcpay/dao:all-srcs",
|
||||
"//app/interface/main/ugcpay/model:all-srcs",
|
||||
"//app/interface/main/ugcpay/server/http:all-srcs",
|
||||
"//app/interface/main/ugcpay/service:all-srcs",
|
||||
],
|
||||
tags = ["automanaged"],
|
||||
visibility = ["//visibility:public"],
|
||||
)
|
4
app/interface/main/ugcpay/CHANGELOG.md
Normal file
4
app/interface/main/ugcpay/CHANGELOG.md
Normal file
@ -0,0 +1,4 @@
|
||||
# v1.0.0
|
||||
1. 服务基建
|
||||
2. trade HTTP API
|
||||
3. income HTTP API
|
8
app/interface/main/ugcpay/CONTRIBUTORS.md
Normal file
8
app/interface/main/ugcpay/CONTRIBUTORS.md
Normal file
@ -0,0 +1,8 @@
|
||||
# Owner
|
||||
zhaogangtao
|
||||
|
||||
# Author
|
||||
muyang
|
||||
|
||||
# Reviewer
|
||||
zhaogangtao
|
14
app/interface/main/ugcpay/OWNERS
Normal file
14
app/interface/main/ugcpay/OWNERS
Normal file
@ -0,0 +1,14 @@
|
||||
# See the OWNERS docs at https://go.k8s.io/owners
|
||||
|
||||
approvers:
|
||||
- muyang
|
||||
- zhaogangtao
|
||||
labels:
|
||||
- interface
|
||||
- interface/main/ugcpay
|
||||
- main
|
||||
options:
|
||||
no_parent_owners: true
|
||||
reviewers:
|
||||
- muyang
|
||||
- zhaogangtao
|
13
app/interface/main/ugcpay/README.md
Normal file
13
app/interface/main/ugcpay/README.md
Normal file
@ -0,0 +1,13 @@
|
||||
# ugcpay-interface
|
||||
|
||||
# 项目简介
|
||||
1. ugc 内容付费网关
|
||||
|
||||
# 编译环境
|
||||
golang >= 1.9
|
||||
|
||||
# 依赖包
|
||||
go-common
|
||||
|
||||
# 编译执行
|
||||
go run ./cmd/main.go -conf test.toml
|
31
app/interface/main/ugcpay/api/http/BUILD
Normal file
31
app/interface/main/ugcpay/api/http/BUILD
Normal file
@ -0,0 +1,31 @@
|
||||
package(default_visibility = ["//visibility:public"])
|
||||
|
||||
load(
|
||||
"@io_bazel_rules_go//go:def.bzl",
|
||||
"go_library",
|
||||
)
|
||||
|
||||
go_library(
|
||||
name = "go_default_library",
|
||||
srcs = [
|
||||
"income.go",
|
||||
"model.go",
|
||||
],
|
||||
importpath = "go-common/app/interface/main/ugcpay/api/http",
|
||||
tags = ["automanaged"],
|
||||
visibility = ["//visibility:public"],
|
||||
)
|
||||
|
||||
filegroup(
|
||||
name = "package-srcs",
|
||||
srcs = glob(["**"]),
|
||||
tags = ["automanaged"],
|
||||
visibility = ["//visibility:private"],
|
||||
)
|
||||
|
||||
filegroup(
|
||||
name = "all-srcs",
|
||||
srcs = [":package-srcs"],
|
||||
tags = ["automanaged"],
|
||||
visibility = ["//visibility:public"],
|
||||
)
|
1
app/interface/main/ugcpay/api/http/api.md
Normal file
1
app/interface/main/ugcpay/api/http/api.md
Normal file
@ -0,0 +1 @@
|
||||
# HTTP API文档
|
42
app/interface/main/ugcpay/api/http/income.go
Normal file
42
app/interface/main/ugcpay/api/http/income.go
Normal file
@ -0,0 +1,42 @@
|
||||
package http
|
||||
|
||||
// RespIncomeAssetOverview .
|
||||
type RespIncomeAssetOverview struct {
|
||||
Total int64 `json:"total"`
|
||||
TotalBuyTimes int64 `json:"total_buy_times"`
|
||||
MonthNew int64 `json:"month_new"`
|
||||
DayNew int64 `json:"day_new"`
|
||||
}
|
||||
|
||||
// ArgIncomeAssetList .
|
||||
type ArgIncomeAssetList struct {
|
||||
Ver string `form:"ver"`
|
||||
PS int64 `form:"ps"`
|
||||
PN int64 `form:"pn"`
|
||||
}
|
||||
|
||||
// RespIncomeAssetList .
|
||||
type RespIncomeAssetList struct {
|
||||
List []*RespIncomeAsset `json:"list"`
|
||||
Page RespPage `json:"page"`
|
||||
}
|
||||
|
||||
// RespIncomeAsset .
|
||||
type RespIncomeAsset struct {
|
||||
OID int64 `json:"oid"`
|
||||
OType string `json:"otype"`
|
||||
Title string `json:"title"`
|
||||
Currency string `json:"currency"`
|
||||
Price int64 `json:"price"`
|
||||
TotalBuyTimes int64 `json:"total_buy_times"`
|
||||
NewBuyTimes int64 `json:"new_buy_times"`
|
||||
TotalErrTimes int64 `json:"total_err_times"`
|
||||
NewErrTimes int64 `json:"new_err_times"`
|
||||
}
|
||||
|
||||
// RespPage .
|
||||
type RespPage struct {
|
||||
Num int64 `json:"num"`
|
||||
Size int64 `json:"size"`
|
||||
Total int64 `json:"total"`
|
||||
}
|
34
app/interface/main/ugcpay/api/http/model.go
Normal file
34
app/interface/main/ugcpay/api/http/model.go
Normal file
@ -0,0 +1,34 @@
|
||||
package http
|
||||
|
||||
// ArgTradeOrder .
|
||||
type ArgTradeOrder struct {
|
||||
OrderID string `form:"order_id" validate:"required"`
|
||||
}
|
||||
|
||||
// RespTradeOrder .
|
||||
type RespTradeOrder struct {
|
||||
OrderID string `json:"order_id"`
|
||||
MID int64 `json:"mid"`
|
||||
Biz string `json:"biz"`
|
||||
Platform string `json:"platform"`
|
||||
OID int64 `json:"oid"`
|
||||
OType string `json:"otype"`
|
||||
Fee int64 `json:"fee"`
|
||||
Currency string `json:"currency"`
|
||||
PayID string `json:"pay_id"`
|
||||
State string `json:"state"`
|
||||
Reason string `json:"reason"`
|
||||
}
|
||||
|
||||
// ArgTradeCreate .
|
||||
type ArgTradeCreate struct {
|
||||
OID int64 `form:"oid" validate:"required"`
|
||||
OType string `form:"otype" validate:"required"`
|
||||
Currency string `form:"currency" validate:"required"`
|
||||
}
|
||||
|
||||
// RespTradeCreate .
|
||||
type RespTradeCreate struct {
|
||||
OrderID string `json:"order_id"`
|
||||
PayData string `json:"pay_data"`
|
||||
}
|
43
app/interface/main/ugcpay/cmd/BUILD
Normal file
43
app/interface/main/ugcpay/cmd/BUILD
Normal file
@ -0,0 +1,43 @@
|
||||
package(default_visibility = ["//visibility:public"])
|
||||
|
||||
load(
|
||||
"@io_bazel_rules_go//go:def.bzl",
|
||||
"go_binary",
|
||||
"go_library",
|
||||
)
|
||||
|
||||
go_binary(
|
||||
name = "cmd",
|
||||
embed = [":go_default_library"],
|
||||
tags = ["automanaged"],
|
||||
)
|
||||
|
||||
go_library(
|
||||
name = "go_default_library",
|
||||
srcs = ["main.go"],
|
||||
data = ["test.toml"],
|
||||
importpath = "go-common/app/interface/main/ugcpay/cmd",
|
||||
tags = ["automanaged"],
|
||||
visibility = ["//visibility:public"],
|
||||
deps = [
|
||||
"//app/interface/main/ugcpay/conf:go_default_library",
|
||||
"//app/interface/main/ugcpay/server/http:go_default_library",
|
||||
"//app/interface/main/ugcpay/service:go_default_library",
|
||||
"//library/ecode/tip:go_default_library",
|
||||
"//library/log: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"],
|
||||
)
|
44
app/interface/main/ugcpay/cmd/main.go
Normal file
44
app/interface/main/ugcpay/cmd/main.go
Normal file
@ -0,0 +1,44 @@
|
||||
package main
|
||||
|
||||
import (
|
||||
"flag"
|
||||
"os"
|
||||
"os/signal"
|
||||
"syscall"
|
||||
"time"
|
||||
|
||||
"go-common/app/interface/main/ugcpay/conf"
|
||||
"go-common/app/interface/main/ugcpay/server/http"
|
||||
"go-common/app/interface/main/ugcpay/service"
|
||||
ecode "go-common/library/ecode/tip"
|
||||
"go-common/library/log"
|
||||
)
|
||||
|
||||
func main() {
|
||||
flag.Parse()
|
||||
if err := conf.Init(); err != nil {
|
||||
panic(err)
|
||||
}
|
||||
log.Init(conf.Conf.Log)
|
||||
defer log.Close()
|
||||
log.Info("ugcpay-interface start")
|
||||
ecode.Init(conf.Conf.Ecode)
|
||||
svc := service.New(conf.Conf)
|
||||
http.Init(conf.Conf, svc)
|
||||
c := make(chan os.Signal, 1)
|
||||
signal.Notify(c, syscall.SIGHUP, syscall.SIGQUIT, syscall.SIGTERM, syscall.SIGINT)
|
||||
for {
|
||||
s := <-c
|
||||
log.Info("get a signal %s", s.String())
|
||||
switch s {
|
||||
case syscall.SIGQUIT, syscall.SIGTERM, syscall.SIGINT:
|
||||
svc.Close()
|
||||
log.Info("ugcpay-interface exit")
|
||||
time.Sleep(time.Second)
|
||||
return
|
||||
case syscall.SIGHUP:
|
||||
default:
|
||||
return
|
||||
}
|
||||
}
|
||||
}
|
17
app/interface/main/ugcpay/cmd/test.toml
Normal file
17
app/interface/main/ugcpay/cmd/test.toml
Normal file
@ -0,0 +1,17 @@
|
||||
[antispam]
|
||||
on=true
|
||||
second=2
|
||||
n=1
|
||||
hour=12
|
||||
m=100
|
||||
[antispam.redis]
|
||||
name = "ugcpay-interface"
|
||||
proto = "tcp"
|
||||
addr = "172.16.33.54:6379"
|
||||
idle = 100
|
||||
active = 100
|
||||
dialTimeout = "500ms"
|
||||
readTimeout = "1s"
|
||||
writeTimeout = "1s"
|
||||
idleTimeout = "80s"
|
||||
expire = "10m"
|
37
app/interface/main/ugcpay/conf/BUILD
Normal file
37
app/interface/main/ugcpay/conf/BUILD
Normal file
@ -0,0 +1,37 @@
|
||||
package(default_visibility = ["//visibility:public"])
|
||||
|
||||
load(
|
||||
"@io_bazel_rules_go//go:def.bzl",
|
||||
"go_library",
|
||||
)
|
||||
|
||||
go_library(
|
||||
name = "go_default_library",
|
||||
srcs = ["conf.go"],
|
||||
importpath = "go-common/app/interface/main/ugcpay/conf",
|
||||
tags = ["automanaged"],
|
||||
visibility = ["//visibility:public"],
|
||||
deps = [
|
||||
"//library/conf:go_default_library",
|
||||
"//library/ecode/tip:go_default_library",
|
||||
"//library/log:go_default_library",
|
||||
"//library/net/http/blademaster:go_default_library",
|
||||
"//library/net/http/blademaster/middleware/antispam:go_default_library",
|
||||
"//library/net/http/blademaster/middleware/auth:go_default_library",
|
||||
"//vendor/github.com/BurntSushi/toml: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"],
|
||||
)
|
82
app/interface/main/ugcpay/conf/conf.go
Normal file
82
app/interface/main/ugcpay/conf/conf.go
Normal file
@ -0,0 +1,82 @@
|
||||
package conf
|
||||
|
||||
import (
|
||||
"errors"
|
||||
"flag"
|
||||
|
||||
"go-common/library/conf"
|
||||
ecode "go-common/library/ecode/tip"
|
||||
"go-common/library/log"
|
||||
bm "go-common/library/net/http/blademaster"
|
||||
"go-common/library/net/http/blademaster/middleware/antispam"
|
||||
"go-common/library/net/http/blademaster/middleware/auth"
|
||||
|
||||
"github.com/BurntSushi/toml"
|
||||
)
|
||||
|
||||
var (
|
||||
confPath string
|
||||
client *conf.Client
|
||||
// Conf config
|
||||
Conf = &Config{}
|
||||
)
|
||||
|
||||
// Config .
|
||||
type Config struct {
|
||||
Log *log.Config
|
||||
BM *bm.ServerConfig
|
||||
Auth *auth.Config
|
||||
Ecode *ecode.Config
|
||||
Antispam *antispam.Config
|
||||
}
|
||||
|
||||
func init() {
|
||||
flag.StringVar(&confPath, "conf", "", "default config path")
|
||||
}
|
||||
|
||||
// Init init conf
|
||||
func Init() error {
|
||||
if confPath != "" {
|
||||
return local()
|
||||
}
|
||||
return remote()
|
||||
}
|
||||
|
||||
func local() (err error) {
|
||||
_, err = toml.DecodeFile(confPath, &Conf)
|
||||
return
|
||||
}
|
||||
|
||||
func remote() (err error) {
|
||||
if client, err = conf.New(); err != nil {
|
||||
return
|
||||
}
|
||||
if err = load(); err != nil {
|
||||
return
|
||||
}
|
||||
go func() {
|
||||
for range client.Event() {
|
||||
log.Info("config reload")
|
||||
if load() != nil {
|
||||
log.Error("config reload error (%v)", err)
|
||||
}
|
||||
}
|
||||
}()
|
||||
return
|
||||
}
|
||||
|
||||
func load() (err error) {
|
||||
var (
|
||||
s string
|
||||
ok bool
|
||||
tmpConf *Config
|
||||
)
|
||||
if s, ok = client.Toml2(); !ok {
|
||||
return errors.New("load config center error")
|
||||
}
|
||||
if _, err = toml.Decode(s, &tmpConf); err != nil {
|
||||
return errors.New("could not decode config")
|
||||
}
|
||||
*Conf = *tmpConf
|
||||
return
|
||||
}
|
52
app/interface/main/ugcpay/dao/BUILD
Normal file
52
app/interface/main/ugcpay/dao/BUILD
Normal file
@ -0,0 +1,52 @@
|
||||
package(default_visibility = ["//visibility:public"])
|
||||
|
||||
load(
|
||||
"@io_bazel_rules_go//go:def.bzl",
|
||||
"go_library",
|
||||
"go_test",
|
||||
)
|
||||
|
||||
go_library(
|
||||
name = "go_default_library",
|
||||
srcs = [
|
||||
"dao.go",
|
||||
"grpc.go",
|
||||
],
|
||||
importpath = "go-common/app/interface/main/ugcpay/dao",
|
||||
tags = ["automanaged"],
|
||||
visibility = ["//visibility:public"],
|
||||
deps = [
|
||||
"//app/interface/main/ugcpay/conf:go_default_library",
|
||||
"//app/interface/main/ugcpay/model:go_default_library",
|
||||
"//app/service/main/archive/api:go_default_library",
|
||||
"//app/service/main/ugcpay/api/grpc/v1: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"],
|
||||
)
|
||||
|
||||
go_test(
|
||||
name = "go_default_test",
|
||||
srcs = [
|
||||
"dao_test.go",
|
||||
"grpc_test.go",
|
||||
],
|
||||
embed = [":go_default_library"],
|
||||
tags = ["automanaged"],
|
||||
deps = [
|
||||
"//app/interface/main/ugcpay/conf:go_default_library",
|
||||
"//vendor/github.com/smartystreets/goconvey/convey:go_default_library",
|
||||
],
|
||||
)
|
40
app/interface/main/ugcpay/dao/dao.go
Normal file
40
app/interface/main/ugcpay/dao/dao.go
Normal file
@ -0,0 +1,40 @@
|
||||
package dao
|
||||
|
||||
import (
|
||||
"context"
|
||||
|
||||
"go-common/app/interface/main/ugcpay/conf"
|
||||
archive "go-common/app/service/main/archive/api"
|
||||
ugcpay "go-common/app/service/main/ugcpay/api/grpc/v1"
|
||||
)
|
||||
|
||||
// Dao dao
|
||||
type Dao struct {
|
||||
c *conf.Config
|
||||
ugcpayAPI ugcpay.UGCPayClient
|
||||
archiveAPI archive.ArchiveClient
|
||||
}
|
||||
|
||||
// New init mysql db
|
||||
func New(c *conf.Config) (dao *Dao) {
|
||||
dao = &Dao{
|
||||
c: c,
|
||||
}
|
||||
var err error
|
||||
if dao.ugcpayAPI, err = ugcpay.NewClient(nil); err != nil {
|
||||
panic(err)
|
||||
}
|
||||
if dao.archiveAPI, err = archive.NewClient(nil); err != nil {
|
||||
panic(err)
|
||||
}
|
||||
return
|
||||
}
|
||||
|
||||
// Close close the resource.
|
||||
func (d *Dao) Close() {
|
||||
}
|
||||
|
||||
// Ping dao ping
|
||||
func (d *Dao) Ping(c context.Context) error {
|
||||
return nil
|
||||
}
|
38
app/interface/main/ugcpay/dao/dao_test.go
Normal file
38
app/interface/main/ugcpay/dao/dao_test.go
Normal file
@ -0,0 +1,38 @@
|
||||
package dao
|
||||
|
||||
import (
|
||||
"context"
|
||||
"flag"
|
||||
"go-common/app/interface/main/ugcpay/conf"
|
||||
"os"
|
||||
"testing"
|
||||
)
|
||||
|
||||
var (
|
||||
d *Dao
|
||||
)
|
||||
|
||||
func TestMain(m *testing.M) {
|
||||
if os.Getenv("DEPLOY_ENV") != "" {
|
||||
flag.Set("app_id", "main.account.ugcpay-interface")
|
||||
flag.Set("conf_token", "e6b959f71772ec8207eb80b8a86137cc")
|
||||
flag.Set("tree_id", "63917")
|
||||
flag.Set("conf_version", "docker-1")
|
||||
flag.Set("deploy_env", "uat")
|
||||
flag.Set("conf_host", "config.bilibili.co")
|
||||
flag.Set("conf_path", "/tmp")
|
||||
flag.Set("region", "sh")
|
||||
flag.Set("zone", "sh001")
|
||||
} else {
|
||||
flag.Set("conf", "../cmd/test.toml")
|
||||
}
|
||||
flag.Parse()
|
||||
if err := conf.Init(); err != nil {
|
||||
panic(err)
|
||||
}
|
||||
d = New(conf.Conf)
|
||||
d.Ping(context.Background())
|
||||
i := m.Run()
|
||||
d.Close()
|
||||
os.Exit(i)
|
||||
}
|
176
app/interface/main/ugcpay/dao/grpc.go
Normal file
176
app/interface/main/ugcpay/dao/grpc.go
Normal file
@ -0,0 +1,176 @@
|
||||
package dao
|
||||
|
||||
import (
|
||||
"context"
|
||||
|
||||
archive "go-common/app/service/main/archive/api"
|
||||
ugcpay "go-common/app/service/main/ugcpay/api/grpc/v1"
|
||||
|
||||
"go-common/app/interface/main/ugcpay/model"
|
||||
)
|
||||
|
||||
// TradeCreate create trade order for mid
|
||||
func (d *Dao) TradeCreate(ctx context.Context, platform string, mid int64, oid int64, otype string, currency string) (orderID string, payData string, err error) {
|
||||
var (
|
||||
req = &ugcpay.TradeCreateReq{
|
||||
Platform: platform,
|
||||
Mid: mid,
|
||||
Oid: oid,
|
||||
Otype: otype,
|
||||
Currency: currency,
|
||||
}
|
||||
reply *ugcpay.TradeCreateResp
|
||||
)
|
||||
if reply, err = d.ugcpayAPI.TradeCreate(ctx, req); err != nil {
|
||||
return
|
||||
}
|
||||
orderID = reply.OrderId
|
||||
payData = reply.PayData
|
||||
return
|
||||
}
|
||||
|
||||
// TradeQuery query trade order by orderID
|
||||
func (d *Dao) TradeQuery(ctx context.Context, orderID string) (order *model.TradeOrder, err error) {
|
||||
var (
|
||||
req = &ugcpay.TradeOrderReq{
|
||||
Id: orderID,
|
||||
}
|
||||
reply *ugcpay.TradeOrderResp
|
||||
)
|
||||
if reply, err = d.ugcpayAPI.TradeQuery(ctx, req); err != nil {
|
||||
return
|
||||
}
|
||||
order = &model.TradeOrder{
|
||||
OrderID: reply.OrderId,
|
||||
MID: reply.Mid,
|
||||
Biz: reply.Biz,
|
||||
Platform: reply.Platform,
|
||||
OID: reply.Oid,
|
||||
OType: reply.Otype,
|
||||
Fee: reply.Fee,
|
||||
Currency: reply.Currency,
|
||||
PayID: reply.PayId,
|
||||
State: reply.State,
|
||||
Reason: reply.Reason,
|
||||
}
|
||||
return
|
||||
}
|
||||
|
||||
// TradeConfirm confirm trade order by orderID
|
||||
func (d *Dao) TradeConfirm(ctx context.Context, orderID string) (order *model.TradeOrder, err error) {
|
||||
var (
|
||||
req = &ugcpay.TradeOrderReq{
|
||||
Id: orderID,
|
||||
}
|
||||
reply *ugcpay.TradeOrderResp
|
||||
)
|
||||
if reply, err = d.ugcpayAPI.TradeConfirm(ctx, req); err != nil {
|
||||
return
|
||||
}
|
||||
order = &model.TradeOrder{
|
||||
OrderID: reply.OrderId,
|
||||
MID: reply.Mid,
|
||||
Biz: reply.Biz,
|
||||
Platform: reply.Platform,
|
||||
OID: reply.Oid,
|
||||
OType: reply.Otype,
|
||||
Fee: reply.Fee,
|
||||
Currency: reply.Currency,
|
||||
PayID: reply.PayId,
|
||||
State: reply.State,
|
||||
Reason: reply.Reason,
|
||||
}
|
||||
return
|
||||
}
|
||||
|
||||
// TradeCancel cancel trade order by orderID
|
||||
func (d *Dao) TradeCancel(ctx context.Context, orderID string) (err error) {
|
||||
var (
|
||||
req = &ugcpay.TradeOrderReq{
|
||||
Id: orderID,
|
||||
}
|
||||
)
|
||||
if _, err = d.ugcpayAPI.TradeCancel(ctx, req); err != nil {
|
||||
return
|
||||
}
|
||||
return
|
||||
}
|
||||
|
||||
// Income
|
||||
|
||||
// IncomeAssetOverview .
|
||||
func (d *Dao) IncomeAssetOverview(ctx context.Context, mid int64) (inc *model.IncomeAssetOverview, err error) {
|
||||
var (
|
||||
req = &ugcpay.IncomeUserAssetOverviewReq{
|
||||
Mid: mid,
|
||||
}
|
||||
reply *ugcpay.IncomeUserAssetOverviewResp
|
||||
)
|
||||
if reply, err = d.ugcpayAPI.IncomeUserAssetOverview(ctx, req); err != nil {
|
||||
return
|
||||
}
|
||||
inc = &model.IncomeAssetOverview{
|
||||
Total: reply.Total,
|
||||
TotalBuyTimes: reply.TotalBuyTimes,
|
||||
MonthNew: reply.MonthNew,
|
||||
DayNew: reply.DayNew,
|
||||
}
|
||||
return
|
||||
}
|
||||
|
||||
// IncomeUserAssetList .
|
||||
func (d *Dao) IncomeUserAssetList(ctx context.Context, mid int64, ver int64, ps, pn int64) (inc *model.IncomeAssetMonthly, err error) {
|
||||
var (
|
||||
req = &ugcpay.IncomeUserAssetListReq{
|
||||
Mid: mid,
|
||||
Ver: ver,
|
||||
Ps: ps,
|
||||
Pn: pn,
|
||||
}
|
||||
reply *ugcpay.IncomeUserAssetListResp
|
||||
)
|
||||
if reply, err = d.ugcpayAPI.IncomeUserAssetList(ctx, req); err != nil {
|
||||
return
|
||||
}
|
||||
inc = &model.IncomeAssetMonthly{
|
||||
List: make([]*model.IncomeAssetMonthlyByContent, 0),
|
||||
Page: &model.Page{
|
||||
Num: reply.Page.Num,
|
||||
Size: reply.Page.Size_,
|
||||
Total: reply.Page.Total,
|
||||
},
|
||||
}
|
||||
for _, c := range reply.List {
|
||||
inc.List = append(inc.List, &model.IncomeAssetMonthlyByContent{
|
||||
OID: c.Oid,
|
||||
OType: c.Otype,
|
||||
Currency: c.Currency,
|
||||
Price: c.Price,
|
||||
TotalBuyTimes: c.TotalBuyTimes,
|
||||
NewBuyTimes: c.NewBuyTimes,
|
||||
TotalErrTimes: c.TotalErrTimes,
|
||||
NewErrTimes: c.NewErrTimes,
|
||||
})
|
||||
}
|
||||
return
|
||||
}
|
||||
|
||||
// archive
|
||||
|
||||
// ArchiveTitles 通过 aid list 获取稿件标题
|
||||
func (d *Dao) ArchiveTitles(ctx context.Context, aids []int64) (arcTitles map[int64]string, err error) {
|
||||
var (
|
||||
req = &archive.ArcsRequest{
|
||||
Aids: aids,
|
||||
}
|
||||
reply *archive.ArcsReply
|
||||
)
|
||||
if reply, err = d.archiveAPI.Arcs(ctx, req); err != nil {
|
||||
return
|
||||
}
|
||||
arcTitles = make(map[int64]string)
|
||||
for aid, a := range reply.Arcs {
|
||||
arcTitles[aid] = a.Title
|
||||
}
|
||||
return
|
||||
}
|
127
app/interface/main/ugcpay/dao/grpc_test.go
Normal file
127
app/interface/main/ugcpay/dao/grpc_test.go
Normal file
@ -0,0 +1,127 @@
|
||||
package dao
|
||||
|
||||
import (
|
||||
"context"
|
||||
"testing"
|
||||
|
||||
"github.com/smartystreets/goconvey/convey"
|
||||
)
|
||||
|
||||
func TestDaoTradeCreate(t *testing.T) {
|
||||
convey.Convey("TradeCreate", t, func(ctx convey.C) {
|
||||
var (
|
||||
c = context.Background()
|
||||
platform = "ios"
|
||||
mid = int64(46333)
|
||||
oid = int64(10110745)
|
||||
otype = "archive"
|
||||
currency = "bp"
|
||||
)
|
||||
ctx.Convey("When everything goes positive", func(ctx convey.C) {
|
||||
orderID, payData, err := d.TradeCreate(c, platform, mid, oid, otype, currency)
|
||||
ctx.Convey("Then err should be nil.orderID,payData should not be nil.", func(ctx convey.C) {
|
||||
ctx.So(err, convey.ShouldBeNil)
|
||||
ctx.So(payData, convey.ShouldNotBeNil)
|
||||
ctx.So(orderID, convey.ShouldNotBeNil)
|
||||
})
|
||||
})
|
||||
})
|
||||
}
|
||||
|
||||
func TestDaoTradeQuery(t *testing.T) {
|
||||
convey.Convey("TradeQuery", t, func(ctx convey.C) {
|
||||
var (
|
||||
c = context.Background()
|
||||
orderID = "32172647181109193324"
|
||||
)
|
||||
ctx.Convey("When everything goes positive", func(ctx convey.C) {
|
||||
order, err := d.TradeQuery(c, orderID)
|
||||
ctx.Convey("Then err should be nil.order should not be nil.", func(ctx convey.C) {
|
||||
ctx.So(err, convey.ShouldBeNil)
|
||||
ctx.So(order, convey.ShouldNotBeNil)
|
||||
})
|
||||
})
|
||||
})
|
||||
}
|
||||
|
||||
func TestDaoTradeConfirm(t *testing.T) {
|
||||
convey.Convey("TradeConfirm", t, func(ctx convey.C) {
|
||||
var (
|
||||
c = context.Background()
|
||||
orderID = "32172647181109193324"
|
||||
)
|
||||
ctx.Convey("When everything goes positive", func(ctx convey.C) {
|
||||
order, err := d.TradeConfirm(c, orderID)
|
||||
ctx.Convey("Then err should be nil.order should not be nil.", func(ctx convey.C) {
|
||||
ctx.So(err, convey.ShouldBeNil)
|
||||
ctx.So(order, convey.ShouldNotBeNil)
|
||||
})
|
||||
})
|
||||
})
|
||||
}
|
||||
|
||||
func TestDaoTradeCancel(t *testing.T) {
|
||||
convey.Convey("TradeCancel", t, func(ctx convey.C) {
|
||||
var (
|
||||
c = context.Background()
|
||||
orderID = "32172647181109193324"
|
||||
)
|
||||
ctx.Convey("When everything goes positive", func(ctx convey.C) {
|
||||
err := d.TradeCancel(c, orderID)
|
||||
ctx.Convey("Then err should be nil.", func(ctx convey.C) {
|
||||
ctx.So(err, convey.ShouldBeNil)
|
||||
})
|
||||
})
|
||||
})
|
||||
}
|
||||
|
||||
func TestDaoIncomeAssetOverview(t *testing.T) {
|
||||
convey.Convey("IncomeAssetOverview", t, func(ctx convey.C) {
|
||||
var (
|
||||
c = context.Background()
|
||||
mid = int64(46333)
|
||||
)
|
||||
ctx.Convey("When everything goes positive", func(ctx convey.C) {
|
||||
inc, err := d.IncomeAssetOverview(c, mid)
|
||||
ctx.Convey("Then err should be nil.inc should not be nil.", func(ctx convey.C) {
|
||||
ctx.So(err, convey.ShouldBeNil)
|
||||
ctx.So(inc, convey.ShouldNotBeNil)
|
||||
})
|
||||
})
|
||||
})
|
||||
}
|
||||
|
||||
func TestDaoIncomeUserAssetList(t *testing.T) {
|
||||
convey.Convey("IncomeUserAssetList", t, func(ctx convey.C) {
|
||||
var (
|
||||
c = context.Background()
|
||||
mid = int64(46333)
|
||||
ver = int64(201811)
|
||||
ps = int64(10)
|
||||
pn = int64(1)
|
||||
)
|
||||
ctx.Convey("When everything goes positive", func(ctx convey.C) {
|
||||
inc, err := d.IncomeUserAssetList(c, mid, ver, ps, pn)
|
||||
ctx.Convey("Then err should be nil.inc should not be nil.", func(ctx convey.C) {
|
||||
ctx.So(err, convey.ShouldBeNil)
|
||||
ctx.So(inc, convey.ShouldNotBeNil)
|
||||
})
|
||||
})
|
||||
})
|
||||
}
|
||||
|
||||
func TestDaoArchiveTitles(t *testing.T) {
|
||||
convey.Convey("ArchiveTitles", t, func(ctx convey.C) {
|
||||
var (
|
||||
c = context.Background()
|
||||
aids = []int64{10110745}
|
||||
)
|
||||
ctx.Convey("When everything goes positive", func(ctx convey.C) {
|
||||
arcTitles, err := d.ArchiveTitles(c, aids)
|
||||
ctx.Convey("Then err should be nil.arcTitles should not be nil.", func(ctx convey.C) {
|
||||
ctx.So(err, convey.ShouldBeNil)
|
||||
ctx.So(arcTitles, convey.ShouldNotBeNil)
|
||||
})
|
||||
})
|
||||
})
|
||||
}
|
28
app/interface/main/ugcpay/model/BUILD
Normal file
28
app/interface/main/ugcpay/model/BUILD
Normal file
@ -0,0 +1,28 @@
|
||||
package(default_visibility = ["//visibility:public"])
|
||||
|
||||
load(
|
||||
"@io_bazel_rules_go//go:def.bzl",
|
||||
"go_library",
|
||||
)
|
||||
|
||||
go_library(
|
||||
name = "go_default_library",
|
||||
srcs = ["model.go"],
|
||||
importpath = "go-common/app/interface/main/ugcpay/model",
|
||||
tags = ["automanaged"],
|
||||
visibility = ["//visibility:public"],
|
||||
)
|
||||
|
||||
filegroup(
|
||||
name = "package-srcs",
|
||||
srcs = glob(["**"]),
|
||||
tags = ["automanaged"],
|
||||
visibility = ["//visibility:private"],
|
||||
)
|
||||
|
||||
filegroup(
|
||||
name = "all-srcs",
|
||||
srcs = [":package-srcs"],
|
||||
tags = ["automanaged"],
|
||||
visibility = ["//visibility:public"],
|
||||
)
|
50
app/interface/main/ugcpay/model/model.go
Normal file
50
app/interface/main/ugcpay/model/model.go
Normal file
@ -0,0 +1,50 @@
|
||||
package model
|
||||
|
||||
// TradeOrder .
|
||||
type TradeOrder struct {
|
||||
OrderID string `json:"order_id"`
|
||||
MID int64 `json:"mid"`
|
||||
Biz string `json:"biz"`
|
||||
Platform string `json:"platform"`
|
||||
OID int64 `json:"oid"`
|
||||
OType string `json:"otype"`
|
||||
Fee int64 `json:"fee"`
|
||||
Currency string `json:"currency"`
|
||||
PayID string `json:"pay_id"`
|
||||
State string `json:"state"`
|
||||
Reason string `json:"reason"`
|
||||
}
|
||||
|
||||
// IncomeAssetOverview .
|
||||
type IncomeAssetOverview struct {
|
||||
Total int64
|
||||
TotalBuyTimes int64
|
||||
MonthNew int64
|
||||
DayNew int64
|
||||
}
|
||||
|
||||
// IncomeAssetMonthly .
|
||||
type IncomeAssetMonthly struct {
|
||||
List []*IncomeAssetMonthlyByContent
|
||||
Page *Page
|
||||
}
|
||||
|
||||
// IncomeAssetMonthlyByContent .
|
||||
type IncomeAssetMonthlyByContent struct {
|
||||
OID int64
|
||||
OType string
|
||||
Currency string
|
||||
Title string
|
||||
Price int64
|
||||
TotalBuyTimes int64
|
||||
NewBuyTimes int64
|
||||
TotalErrTimes int64
|
||||
NewErrTimes int64
|
||||
}
|
||||
|
||||
// Page .
|
||||
type Page struct {
|
||||
Num int64
|
||||
Size int64
|
||||
Total int64
|
||||
}
|
43
app/interface/main/ugcpay/server/http/BUILD
Normal file
43
app/interface/main/ugcpay/server/http/BUILD
Normal file
@ -0,0 +1,43 @@
|
||||
package(default_visibility = ["//visibility:public"])
|
||||
|
||||
load(
|
||||
"@io_bazel_rules_go//go:def.bzl",
|
||||
"go_library",
|
||||
)
|
||||
|
||||
go_library(
|
||||
name = "go_default_library",
|
||||
srcs = [
|
||||
"http.go",
|
||||
"income.go",
|
||||
"trade.go",
|
||||
],
|
||||
importpath = "go-common/app/interface/main/ugcpay/server/http",
|
||||
tags = ["automanaged"],
|
||||
visibility = ["//visibility:public"],
|
||||
deps = [
|
||||
"//app/interface/main/ugcpay/api/http:go_default_library",
|
||||
"//app/interface/main/ugcpay/conf:go_default_library",
|
||||
"//app/interface/main/ugcpay/model:go_default_library",
|
||||
"//app/interface/main/ugcpay/service:go_default_library",
|
||||
"//library/ecode:go_default_library",
|
||||
"//library/log:go_default_library",
|
||||
"//library/net/http/blademaster:go_default_library",
|
||||
"//library/net/http/blademaster/middleware/antispam:go_default_library",
|
||||
"//library/net/http/blademaster/middleware/auth: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"],
|
||||
)
|
54
app/interface/main/ugcpay/server/http/http.go
Normal file
54
app/interface/main/ugcpay/server/http/http.go
Normal file
@ -0,0 +1,54 @@
|
||||
package http
|
||||
|
||||
import (
|
||||
"go-common/app/interface/main/ugcpay/conf"
|
||||
"go-common/app/interface/main/ugcpay/service"
|
||||
"go-common/library/log"
|
||||
bm "go-common/library/net/http/blademaster"
|
||||
"go-common/library/net/http/blademaster/middleware/antispam"
|
||||
"go-common/library/net/http/blademaster/middleware/auth"
|
||||
)
|
||||
|
||||
var (
|
||||
srv *service.Service
|
||||
authM *auth.Auth
|
||||
antispamM *antispam.Antispam
|
||||
)
|
||||
|
||||
// Init init
|
||||
func Init(c *conf.Config, s *service.Service) {
|
||||
srv = s
|
||||
authM = auth.New(c.Auth)
|
||||
antispamM = antispam.New(c.Antispam)
|
||||
engine := bm.DefaultServer(c.BM)
|
||||
route(engine)
|
||||
if err := engine.Start(); err != nil {
|
||||
log.Error("bm Start error(%+v)", err)
|
||||
panic(err)
|
||||
}
|
||||
}
|
||||
|
||||
func route(e *bm.Engine) {
|
||||
e.Ping(ping)
|
||||
web := e.Group("/x/ugcpay", authM.UserWeb)
|
||||
{
|
||||
web.GET("/trade", tradeQuery)
|
||||
web.POST("/trade/confirm", antispamM.Handler(), tradeConfirm)
|
||||
web.POST("/trade/create", antispamM.Handler(), tradeCreate)
|
||||
web.POST("/trade/cancel", tradeCancel)
|
||||
web.GET("/income/asset/overview", antispamM.Handler(), incomeAssetOverview)
|
||||
web.GET("/income/asset/monthly", antispamM.Handler(), incomeAssetMonthly)
|
||||
}
|
||||
app := e.Group("/x/ugcpay/v1", authM.UserMobile)
|
||||
{
|
||||
app.GET("/trade", tradeQuery)
|
||||
app.POST("/trade/confirm", antispamM.Handler(), tradeConfirm)
|
||||
app.POST("/trade/create", antispamM.Handler(), tradeCreate)
|
||||
app.POST("/trade/cancel", tradeCancel)
|
||||
app.GET("/income/asset/overview", antispamM.Handler(), incomeAssetOverview)
|
||||
app.GET("/income/asset/monthly", antispamM.Handler(), incomeAssetMonthly)
|
||||
}
|
||||
}
|
||||
|
||||
func ping(c *bm.Context) {
|
||||
}
|
84
app/interface/main/ugcpay/server/http/income.go
Normal file
84
app/interface/main/ugcpay/server/http/income.go
Normal file
@ -0,0 +1,84 @@
|
||||
package http
|
||||
|
||||
import (
|
||||
"strconv"
|
||||
|
||||
api "go-common/app/interface/main/ugcpay/api/http"
|
||||
"go-common/app/interface/main/ugcpay/model"
|
||||
"go-common/library/ecode"
|
||||
bm "go-common/library/net/http/blademaster"
|
||||
)
|
||||
|
||||
func incomeAssetOverview(ctx *bm.Context) {
|
||||
var (
|
||||
err error
|
||||
resp *api.RespIncomeAssetOverview
|
||||
inc *model.IncomeAssetOverview
|
||||
mid, _ = ctx.Get("mid")
|
||||
)
|
||||
if inc, err = srv.IncomeAssetOverview(ctx, mid.(int64)); err != nil {
|
||||
ctx.JSON(nil, err)
|
||||
return
|
||||
}
|
||||
resp = &api.RespIncomeAssetOverview{
|
||||
Total: inc.Total,
|
||||
TotalBuyTimes: inc.TotalBuyTimes,
|
||||
MonthNew: inc.MonthNew,
|
||||
DayNew: inc.DayNew,
|
||||
}
|
||||
ctx.JSON(resp, err)
|
||||
}
|
||||
|
||||
func incomeAssetMonthly(ctx *bm.Context) {
|
||||
var (
|
||||
err error
|
||||
arg = &api.ArgIncomeAssetList{}
|
||||
resp = &api.RespIncomeAssetList{List: make([]*api.RespIncomeAsset, 0)}
|
||||
inc *model.IncomeAssetMonthly
|
||||
page *model.Page
|
||||
ver int64
|
||||
mid, _ = ctx.Get("mid")
|
||||
)
|
||||
if err = ctx.Bind(arg); err != nil {
|
||||
return
|
||||
}
|
||||
if arg.PS == 0 {
|
||||
arg.PS = 20
|
||||
}
|
||||
if arg.PN == 0 {
|
||||
arg.PN = 1
|
||||
}
|
||||
if arg.Ver != "" {
|
||||
if ver, err = strconv.ParseInt(arg.Ver, 10, 64); err != nil {
|
||||
ctx.JSON(nil, ecode.RequestErr)
|
||||
return
|
||||
}
|
||||
} else {
|
||||
// ver=0 代表总计
|
||||
ver = 0
|
||||
}
|
||||
|
||||
if inc, page, err = srv.IncomeAssetList(ctx, mid.(int64), ver, arg.PS, arg.PN); err != nil {
|
||||
ctx.JSON(nil, err)
|
||||
return
|
||||
}
|
||||
resp.Page = api.RespPage{
|
||||
Num: page.Num,
|
||||
Size: page.Size,
|
||||
Total: page.Total,
|
||||
}
|
||||
for _, i := range inc.List {
|
||||
resp.List = append(resp.List, &api.RespIncomeAsset{
|
||||
OID: i.OID,
|
||||
OType: i.OType,
|
||||
Title: i.Title,
|
||||
Currency: i.Currency,
|
||||
Price: i.Price,
|
||||
TotalBuyTimes: i.TotalBuyTimes,
|
||||
NewBuyTimes: i.NewBuyTimes,
|
||||
TotalErrTimes: i.TotalErrTimes,
|
||||
NewErrTimes: i.NewErrTimes,
|
||||
})
|
||||
}
|
||||
ctx.JSON(resp, err)
|
||||
}
|
96
app/interface/main/ugcpay/server/http/trade.go
Normal file
96
app/interface/main/ugcpay/server/http/trade.go
Normal file
@ -0,0 +1,96 @@
|
||||
package http
|
||||
|
||||
import (
|
||||
api "go-common/app/interface/main/ugcpay/api/http"
|
||||
"go-common/app/interface/main/ugcpay/model"
|
||||
bm "go-common/library/net/http/blademaster"
|
||||
)
|
||||
|
||||
func tradeCreate(ctx *bm.Context) {
|
||||
var (
|
||||
err error
|
||||
arg = &api.ArgTradeCreate{}
|
||||
resp = &api.RespTradeCreate{}
|
||||
mid, _ = ctx.Get("mid")
|
||||
platform = ctx.Request.FormValue("platform")
|
||||
)
|
||||
if err = ctx.Bind(arg); err != nil {
|
||||
return
|
||||
}
|
||||
if resp.OrderID, resp.PayData, err = srv.TradeCreate(ctx, mid.(int64), platform, arg.OID, arg.OType, arg.Currency); err != nil {
|
||||
ctx.JSON(nil, err)
|
||||
return
|
||||
}
|
||||
ctx.JSON(resp, err)
|
||||
}
|
||||
|
||||
func tradeQuery(ctx *bm.Context) {
|
||||
var (
|
||||
err error
|
||||
arg = &api.ArgTradeOrder{}
|
||||
resp *api.RespTradeOrder
|
||||
order *model.TradeOrder
|
||||
)
|
||||
if err = ctx.Bind(arg); err != nil {
|
||||
return
|
||||
}
|
||||
if order, err = srv.TradeQuery(ctx, arg.OrderID); err != nil {
|
||||
ctx.JSON(nil, err)
|
||||
return
|
||||
}
|
||||
resp = &api.RespTradeOrder{
|
||||
OrderID: order.OrderID,
|
||||
MID: order.MID,
|
||||
Biz: order.Biz,
|
||||
Platform: order.Platform,
|
||||
OID: order.OID,
|
||||
OType: order.OType,
|
||||
Fee: order.Fee,
|
||||
Currency: order.Currency,
|
||||
PayID: order.PayID,
|
||||
State: order.State,
|
||||
Reason: order.Reason,
|
||||
}
|
||||
ctx.JSON(resp, err)
|
||||
}
|
||||
|
||||
func tradeConfirm(ctx *bm.Context) {
|
||||
var (
|
||||
err error
|
||||
arg = &api.ArgTradeOrder{}
|
||||
resp *api.RespTradeOrder
|
||||
order *model.TradeOrder
|
||||
)
|
||||
if err = ctx.Bind(arg); err != nil {
|
||||
return
|
||||
}
|
||||
if order, err = srv.TradeConfirm(ctx, arg.OrderID); err != nil {
|
||||
ctx.JSON(nil, err)
|
||||
return
|
||||
}
|
||||
resp = &api.RespTradeOrder{
|
||||
OrderID: order.OrderID,
|
||||
MID: order.MID,
|
||||
Biz: order.Biz,
|
||||
Platform: order.Platform,
|
||||
OID: order.OID,
|
||||
OType: order.OType,
|
||||
Fee: order.Fee,
|
||||
Currency: order.Currency,
|
||||
PayID: order.PayID,
|
||||
State: order.State,
|
||||
Reason: order.Reason,
|
||||
}
|
||||
ctx.JSON(resp, err)
|
||||
}
|
||||
|
||||
func tradeCancel(ctx *bm.Context) {
|
||||
var (
|
||||
err error
|
||||
arg = &api.ArgTradeOrder{}
|
||||
)
|
||||
if err = ctx.Bind(arg); err != nil {
|
||||
return
|
||||
}
|
||||
ctx.JSON(nil, srv.TradeCancel(ctx, arg.OrderID))
|
||||
}
|
38
app/interface/main/ugcpay/service/BUILD
Normal file
38
app/interface/main/ugcpay/service/BUILD
Normal file
@ -0,0 +1,38 @@
|
||||
package(default_visibility = ["//visibility:public"])
|
||||
|
||||
load(
|
||||
"@io_bazel_rules_go//go:def.bzl",
|
||||
"go_library",
|
||||
)
|
||||
|
||||
go_library(
|
||||
name = "go_default_library",
|
||||
srcs = [
|
||||
"income.go",
|
||||
"service.go",
|
||||
"trade.go",
|
||||
],
|
||||
importpath = "go-common/app/interface/main/ugcpay/service",
|
||||
tags = ["automanaged"],
|
||||
visibility = ["//visibility:public"],
|
||||
deps = [
|
||||
"//app/interface/main/ugcpay/conf:go_default_library",
|
||||
"//app/interface/main/ugcpay/dao:go_default_library",
|
||||
"//app/interface/main/ugcpay/model:go_default_library",
|
||||
"//library/log: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"],
|
||||
)
|
44
app/interface/main/ugcpay/service/income.go
Normal file
44
app/interface/main/ugcpay/service/income.go
Normal file
@ -0,0 +1,44 @@
|
||||
package service
|
||||
|
||||
import (
|
||||
"context"
|
||||
|
||||
"go-common/app/interface/main/ugcpay/model"
|
||||
"go-common/library/log"
|
||||
)
|
||||
|
||||
// IncomeAssetOverview 获得收入总览数据
|
||||
func (s *Service) IncomeAssetOverview(ctx context.Context, mid int64) (inc *model.IncomeAssetOverview, err error) {
|
||||
inc, err = s.dao.IncomeAssetOverview(ctx, mid)
|
||||
return
|
||||
}
|
||||
|
||||
// IncomeAssetList 获得稿件维度的收入数据
|
||||
func (s *Service) IncomeAssetList(ctx context.Context, mid int64, ver int64, ps, pn int64) (inc *model.IncomeAssetMonthly, page *model.Page, err error) {
|
||||
if inc, err = s.dao.IncomeUserAssetList(ctx, mid, ver, ps, pn); err != nil {
|
||||
return
|
||||
}
|
||||
|
||||
// 获得稿件标题信息
|
||||
var (
|
||||
aids = make([]int64, 0)
|
||||
titleMap = make(map[int64]string)
|
||||
)
|
||||
for _, l := range inc.List {
|
||||
aids = append(aids, l.OID)
|
||||
}
|
||||
if titleMap, err = s.dao.ArchiveTitles(ctx, aids); err != nil {
|
||||
log.Error("s.dao.ArchiveTitles aids: %+v, err: %+v", aids, err)
|
||||
err = nil
|
||||
}
|
||||
for _, l := range inc.List {
|
||||
l.Title = titleMap[l.OID]
|
||||
}
|
||||
|
||||
page = &model.Page{
|
||||
Size: inc.Page.Size,
|
||||
Num: inc.Page.Num,
|
||||
Total: inc.Page.Total,
|
||||
}
|
||||
return
|
||||
}
|
33
app/interface/main/ugcpay/service/service.go
Normal file
33
app/interface/main/ugcpay/service/service.go
Normal file
@ -0,0 +1,33 @@
|
||||
package service
|
||||
|
||||
import (
|
||||
"context"
|
||||
|
||||
"go-common/app/interface/main/ugcpay/conf"
|
||||
"go-common/app/interface/main/ugcpay/dao"
|
||||
)
|
||||
|
||||
// Service struct
|
||||
type Service struct {
|
||||
c *conf.Config
|
||||
dao *dao.Dao
|
||||
}
|
||||
|
||||
// New init
|
||||
func New(c *conf.Config) (s *Service) {
|
||||
s = &Service{
|
||||
c: c,
|
||||
dao: dao.New(c),
|
||||
}
|
||||
return s
|
||||
}
|
||||
|
||||
// Ping Service
|
||||
func (s *Service) Ping(c context.Context) (err error) {
|
||||
return s.dao.Ping(c)
|
||||
}
|
||||
|
||||
// Close Service
|
||||
func (s *Service) Close() {
|
||||
s.dao.Close()
|
||||
}
|
34
app/interface/main/ugcpay/service/trade.go
Normal file
34
app/interface/main/ugcpay/service/trade.go
Normal file
@ -0,0 +1,34 @@
|
||||
package service
|
||||
|
||||
import (
|
||||
"context"
|
||||
|
||||
"go-common/app/interface/main/ugcpay/model"
|
||||
)
|
||||
|
||||
// TradeCreate 订单创建
|
||||
func (s *Service) TradeCreate(ctx context.Context, mid int64, platform string, oid int64, otype string, currency string) (orderID string, payData string, err error) {
|
||||
if platform == "" {
|
||||
platform = "web"
|
||||
}
|
||||
orderID, payData, err = s.dao.TradeCreate(ctx, platform, mid, oid, otype, currency)
|
||||
return
|
||||
}
|
||||
|
||||
// TradeQuery 订单查询
|
||||
func (s *Service) TradeQuery(ctx context.Context, orderID string) (order *model.TradeOrder, err error) {
|
||||
order, err = s.dao.TradeQuery(ctx, orderID)
|
||||
return
|
||||
}
|
||||
|
||||
// TradeConfirm 订单二次确认
|
||||
func (s *Service) TradeConfirm(ctx context.Context, orderID string) (order *model.TradeOrder, err error) {
|
||||
order, err = s.dao.TradeConfirm(ctx, orderID)
|
||||
return
|
||||
}
|
||||
|
||||
// TradeCancel 订单取消
|
||||
func (s *Service) TradeCancel(ctx context.Context, orderID string) (err error) {
|
||||
err = s.dao.TradeCancel(ctx, orderID)
|
||||
return
|
||||
}
|
Reference in New Issue
Block a user