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,72 @@
package(default_visibility = ["//visibility:public"])
load(
"@io_bazel_rules_go//go:def.bzl",
"go_library",
"go_test",
)
go_library(
name = "go_default_library",
srcs = [
"invite.go",
"pendant.go",
"pendant_new.go",
"service.go",
],
importpath = "go-common/app/interface/main/account/service/usersuit",
tags = ["automanaged"],
visibility = ["//visibility:public"],
deps = [
"//app/interface/main/account/conf:go_default_library",
"//app/interface/main/account/dao/usersuit:go_default_library",
"//app/interface/main/account/dao/vip:go_default_library",
"//app/interface/main/account/model:go_default_library",
"//app/service/main/account/model:go_default_library",
"//app/service/main/account/rpc/client:go_default_library",
"//app/service/main/coin/api/gorpc:go_default_library",
"//app/service/main/coin/model:go_default_library",
"//app/service/main/member/api/gorpc:go_default_library",
"//app/service/main/member/model:go_default_library",
"//app/service/main/usersuit/model:go_default_library",
"//app/service/main/usersuit/rpc/client:go_default_library",
"//library/ecode:go_default_library",
"//library/log:go_default_library",
"//library/net/metadata:go_default_library",
"//library/sync/errgroup: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 = [
"invite_test.go",
"pendant_test.go",
"service_test.go",
],
embed = [":go_default_library"],
rundir = ".",
tags = ["automanaged"],
deps = [
"//app/interface/main/account/conf:go_default_library",
"//app/service/main/usersuit/model:go_default_library",
"//app/service/main/usersuit/rpc/client:go_default_library",
"//library/ecode:go_default_library",
"//vendor/github.com/bouk/monkey:go_default_library",
"//vendor/github.com/smartystreets/goconvey/convey:go_default_library",
],
)

View File

@@ -0,0 +1,134 @@
package usersuit
import (
"context"
"sync"
"time"
"go-common/app/interface/main/account/model"
accmdl "go-common/app/service/main/account/model"
usmdl "go-common/app/service/main/usersuit/model"
"go-common/library/log"
"go-common/library/net/metadata"
"go-common/library/sync/errgroup"
)
const (
_batch = 20
_fetchInfoTimeout = time.Second * 10
)
var (
_emptyRichInvites = make([]*model.RichInvite, 0)
_emptyInfoMap = make(map[int64]*accmdl.Info)
)
// Buy buy invite code.
func (s *Service) Buy(c context.Context, mid int64, num int64) (res []*model.RichInvite, err error) {
var invs []*usmdl.Invite
ip := metadata.String(c, metadata.RemoteIP)
arg := &usmdl.ArgBuy{Mid: mid, Num: num, IP: ip}
if invs, err = s.usRPC.Buy(c, arg); err != nil {
log.Error("service.userserviceRPC.Buy(%v) error(%v)", arg, err)
return
}
res = make([]*model.RichInvite, 0)
for _, inv := range invs {
res = append(res, model.NewRichInvite(inv, nil))
}
return
}
// Apply apply invite code.
func (s *Service) Apply(c context.Context, mid int64, code string, cookie string) (err error) {
ip := metadata.String(c, metadata.RemoteIP)
arg := &usmdl.ArgApply{Mid: mid, Code: code, Cookie: cookie, IP: ip}
if err = s.usRPC.Apply(c, arg); err != nil {
log.Error("service.userserviceRPC.Apply(%v) error(%v)", arg, err)
}
return
}
// Stat get user's invite code stat.
func (s *Service) Stat(c context.Context, mid int64) (res *model.RichInviteStat, err error) {
var st *usmdl.InviteStat
ip := metadata.String(c, metadata.RemoteIP)
arg := &usmdl.ArgStat{Mid: mid, IP: ip}
if st, err = s.usRPC.Stat(c, arg); err != nil {
log.Error("service.userserviceRPC.Stat(%v) error(%v)", arg, err)
return
}
res = &model.RichInviteStat{
Mid: st.Mid,
CurrentLimit: st.CurrentLimit,
CurrentBought: st.CurrentBought,
TotalBought: st.TotalBought,
TotalUsed: st.TotalUsed,
InviteCodes: s.fillInviteeInfo(c, st.InviteCodes, ip),
}
return
}
func (s *Service) fillInviteeInfo(c context.Context, invs []*usmdl.Invite, ip string) []*model.RichInvite {
if len(invs) == 0 {
return _emptyRichInvites
}
imidm := make(map[int64]int)
for _, inv := range invs {
if inv.Status == usmdl.StatusUsed {
imidm[inv.Imid] = 1
}
}
infom := _emptyInfoMap
if len(imidm) > 0 {
imids := make([]int64, 0, len(imidm))
for imid := range imidm {
imids = append(imids, imid)
}
var err1 error
if infom, err1 = s.fetchInfos(c, imids, ip, _fetchInfoTimeout); err1 != nil {
log.Error("service.fetchInfos(%v, %s, %v) error(%v)", imids, ip, _fetchInfoTimeout, err1)
}
}
rinvs := make([]*model.RichInvite, 0)
for _, inv := range invs {
rinvs = append(rinvs, model.NewRichInvite(inv, infom[inv.Imid]))
}
return rinvs
}
func (s *Service) fetchInfos(c context.Context, mids []int64, ip string, timeout time.Duration) (res map[int64]*accmdl.Info, err error) {
if len(mids) == 0 {
res = _emptyInfoMap
return
}
batches := len(mids)/_batch + 1
tc, cancel := context.WithTimeout(c, timeout)
defer cancel()
eg, errCtx := errgroup.WithContext(tc)
bms := make([]map[int64]*accmdl.Info, batches)
mu := sync.Mutex{}
for i := 0; i < batches; i++ {
idx := i
end := (idx + 1) * _batch
if idx == batches-1 {
end = len(mids)
}
ids := mids[idx*_batch : end]
eg.Go(func() error {
m, err1 := s.accRPC.Infos3(errCtx, &accmdl.ArgMids{Mids: ids})
mu.Lock()
bms[idx] = m
mu.Unlock()
return err1
})
}
err = eg.Wait()
res = make(map[int64]*accmdl.Info)
for _, bm := range bms {
for mid, info := range bm {
res[mid] = info
}
}
return
}

View File

@@ -0,0 +1,27 @@
package usersuit
import (
"context"
"testing"
"time"
"go-common/library/ecode"
. "github.com/smartystreets/goconvey/convey"
)
func TestService_FetchMultiInfo(t *testing.T) {
time.Sleep(time.Second * 2)
Convey("Fetch multi info", t, func() {
mids := []int64{88888970}
Convey("when not timeout", func() {
res, err := s.fetchInfos(context.Background(), mids, "127.0.0.1", time.Second)
So(err, ShouldBeNil)
So(len(res), ShouldEqual, len(mids))
})
Convey("when timeout", func() {
_, err := s.fetchInfos(context.Background(), mids, "127.0.0.1", time.Millisecond)
So(err, ShouldEqual, ecode.Deadline.Error())
})
})
}

View File

@@ -0,0 +1,274 @@
package usersuit
import (
"context"
"math"
"go-common/app/interface/main/account/model"
cmdl "go-common/app/service/main/coin/model"
memmdl "go-common/app/service/main/member/model"
usmdl "go-common/app/service/main/usersuit/model"
"go-common/library/ecode"
"go-common/library/log"
"go-common/library/net/metadata"
)
// Equip user pendant equip.
func (s *Service) Equip(c context.Context, mid, pid int64, status int8, source int64) (err error) {
return s.usRPC.Equip(c, &usmdl.ArgEquip{Mid: mid, Pid: pid, Status: status, Source: source})
}
// Equipment get pendant current equipment
func (s *Service) Equipment(c context.Context, mid int64) (equipPHP *model.EquipPHP, err error) {
var equip *usmdl.PendantEquip
ip := metadata.String(c, metadata.RemoteIP)
if equip, err = s.usRPC.Equipment(c, &usmdl.ArgEquipment{Mid: mid, IP: ip}); err != nil {
log.Error("s.usRPC.Equipment(%d) error(%v)", mid, err)
return
}
var coin float64
if coin, err = s.coinRPC.UserCoins(c, &cmdl.ArgCoinInfo{Mid: mid}); err != nil {
log.Error("s.coinRPC.UserCoins(%d) error(%v)", mid, err)
return
}
var base *memmdl.BaseInfo
if base, err = s.memRPC.Base(c, &memmdl.ArgMemberMid{Mid: mid, RemoteIP: ip}); err != nil {
log.Error("s.memRPC.Base(%d) error(%v)", mid, err)
return
}
equipPHP = &model.EquipPHP{
Coins: coin,
FaceURL: base.Face,
}
if equip == nil || equip.Pendant == nil {
log.Info("s.Equipment(%d) usequip(%+v) or usequip.Pendant(%+v) is nil", equip, equip.Pendant)
return
}
equipPHP.Pid = equip.Pid
equipPHP.Image = model.FormatImgURL(mid, equip.Pendant.Image)
equipPHP.ImageModel = model.FormatImgURL(mid, equip.Pendant.ImageModel)
return
}
// Pendant return pendant info.
func (s *Service) Pendant(c context.Context, pid int64) (pendantPHP *model.PendantPHP, err error) {
var pendant *usmdl.Pendant
ip := metadata.String(c, metadata.RemoteIP)
if pendant, err = s.dao.Pendant(c, pid, ip); err != nil {
log.Error("s.dao.Group(%d) error(%v)", pid, err)
return
}
pendantPHP = &model.PendantPHP{}
pendantPHP.Name = pendant.Name
pendantPHP.Pid = pendant.ID
pendantPHP.Image = model.FormatImgURL(pid, pendant.Image)
pendantPHP.ImageModel = model.FormatImgURL(pid, pendant.ImageModel)
return
}
// Group return pendant group info.
func (s *Service) Group(c context.Context, mid int64) (groupPHP []*model.GroupPHP, err error) {
var groups []*usmdl.PendantGroupInfo
ip := metadata.String(c, metadata.RemoteIP)
if groups, err = s.dao.Group(c, ip); err != nil {
log.Error("s.dao.Group(%d) error(%v)", mid, err)
return
}
for _, g := range groups {
if g.ID == 30 || g.ID == 31 {
continue
}
for _, p := range g.SubPendant {
p.BCoin = p.BCoin / 100
p.Image = model.FormatImgURL(mid, p.Image)
p.ImageModel = model.FormatImgURL(mid, p.ImageModel)
}
gh := &model.GroupPHP{}
gh.Name = g.Name
gh.Count = g.Number
gh.Pendant = g.SubPendant
groupPHP = append(groupPHP, gh)
}
return
}
// GroupEntry return vip pendant.
func (s *Service) GroupEntry(c context.Context, mid int64) (entryPHP []*model.GroupEntryPHP, err error) {
var group *usmdl.PendantGroupInfo
ip := metadata.String(c, metadata.RemoteIP)
if group, err = s.dao.GroupEntry(c, ip); err != nil {
log.Error("s.dao.GroupEntry(%d) error(%v)", mid, ip)
return
}
if group == nil {
log.Info("s.dao.GroupEntry(%d) result value is nil", mid)
return
}
for _, p := range group.SubPendant {
entry := &model.GroupEntryPHP{}
entry.Pid = p.ID
entry.Name = p.Name
entry.Money = p.Point
entry.Image = model.FormatImgURL(mid, p.Image)
entry.ImageModel = model.FormatImgURL(mid, p.ImageModel)
entryPHP = append(entryPHP, entry)
}
return
}
// GroupVIP return vip pendant.
func (s *Service) GroupVIP(c context.Context, mid int64) (vipPHP []*model.GroupVipPHP, err error) {
var group *usmdl.PendantGroupInfo
ip := metadata.String(c, metadata.RemoteIP)
if group, err = s.dao.GroupVip(c, ip); err != nil {
log.Error("s.dao.GroupVip(%d) error(%v)", mid, ip)
return
}
if group == nil {
log.Info("s.dao.GroupEntry(%d) result value is nil", mid)
return
}
for _, p := range group.SubPendant {
vip := &model.GroupVipPHP{}
vip.Pid = p.ID
vip.Name = p.Name
vip.Money = 0
vip.MoneyType = 3
vip.Expire = 2678400
vip.Image = model.FormatImgURL(mid, p.Image)
vip.ImageModel = model.FormatImgURL(mid, p.ImageModel)
vipPHP = append(vipPHP, vip)
}
return
}
// VipGet pc vip install pendant.
func (s *Service) VipGet(c context.Context, mid, pid int64, activated int8) (err error) {
err = s.Equip(c, mid, pid, int8(activated), usmdl.EquipFromVIP)
return
}
// CheckOrder check order by oid.
func (s *Service) CheckOrder(c context.Context, mid int64, orderID string) (err error) {
var hs []*usmdl.PendantOrderInfo
ip := metadata.String(c, metadata.RemoteIP)
if hs, _, err = s.dao.OrderHistory(c, mid, 1, 0, orderID, ip); err != nil {
log.Error("s.dao.OrderHistory(%d) error(%v)", mid, err)
return
}
if len(hs) == 0 {
err = ecode.PendantOrderNotFound
log.Info("s.dao.OrderHistory(%d) orderID(%d) error(%v)", mid, orderID, err)
return
}
if hs[0].Stauts != 1 {
err = ecode.PendantOrderNotFound
log.Info("s.dao.OrderHistory(%d) orderID(%d) order not complete", mid, orderID, err)
return
}
return
}
// Order pay pandent by coin/bcoin/point.
func (s *Service) Order(c context.Context, mid, pid, timeLength int64, moneyType int8) (res interface{}, err error) {
var payInfo *usmdl.PayInfo
ip := metadata.String(c, metadata.RemoteIP)
if payInfo, err = s.dao.Order(c, mid, pid, timeLength, moneyType, ip); err != nil {
log.Error("s.dao.Order(%d) error(%v)", mid, err)
return
}
if payInfo != nil {
payInfo.PayURL = "https://pay.bilibili.com" + payInfo.PayURL
res = payInfo
return
}
if moneyType == 2 {
log.Info("s.dao.Order(%d) pid(%d) buy type with point", mid, pid)
s.Equip(c, mid, pid, 2, usmdl.EquipFromPackage)
}
var pkgs []*usmdl.PendantPackage
if pkgs, err = s.dao.Packages(c, mid, ip); err != nil {
log.Error("s.dao.Packages(%d) error(%v)", mid, err)
return
}
var pendant *usmdl.PendantPackage
for _, pkg := range pkgs {
if pkg.Pid == pid {
pendant = pkg
}
}
if pendant != nil {
res = &struct {
Msg string `json:"msg"`
Expire int64 `json:"expire"`
}{
Msg: "您已成功购买" + pendant.Pendant.Name,
Expire: pendant.Expires,
}
}
return
}
// My get my pandent
func (s *Service) My(c context.Context, mid int64) (my []*model.MyPHP, err error) {
var equip *usmdl.PendantEquip
ip := metadata.String(c, metadata.RemoteIP)
if equip, err = s.usRPC.Equipment(c, &usmdl.ArgEquipment{Mid: mid, IP: ip}); err != nil {
log.Error("s.usRPC.Equipment(%d) error(%v)", mid, err)
return
}
var pkgs []*usmdl.PendantPackage
if pkgs, err = s.dao.Packages(c, mid, ip); err != nil {
log.Error("s.dao.Packages(%d) error(%v)", mid, err)
return
}
for _, pkg := range pkgs {
m := &model.MyPHP{}
m.Pid = pkg.Pid
m.Name = pkg.Pendant.Name
m.MoneyType = int8(pkg.Type)
m.Image = model.FormatImgURL(mid, pkg.Pendant.Image)
m.ImageModel = model.FormatImgURL(mid, pkg.Pendant.ImageModel)
m.Expire = pkg.Expires
m.IsOnline = 1
if equip != nil && equip.Pid == pkg.Pid {
m.IsActivated = 1
}
my = append(my, m)
}
return
}
// MyHistory get my pandent buy history.
func (s *Service) MyHistory(c context.Context, mid, page int64) (res map[string]interface{}, err error) {
var (
hs []*usmdl.PendantOrderInfo
myhs []*model.MyHistoryPHP
count map[string]int64
ip = metadata.String(c, metadata.RemoteIP)
)
if hs, count, err = s.dao.OrderHistory(c, mid, page, 0, "", ip); err != nil {
log.Error("s.dao.OrderHistory(%d) error(%v)", mid, err)
return
}
if len(hs) == 0 {
log.Info("s.dao.OrderHistory(%d) result len eq(0)", mid)
return
}
for _, h := range hs {
my := &model.MyHistoryPHP{}
my.Pid = h.Pid
my.Image = model.FormatImgURL(mid, h.Image)
my.Name = h.Name
my.BuyTime = h.BuyTime
my.PayID = h.PayID
my.Cost = h.Cost
my.TimeLength = h.TimeLength
myhs = append(myhs, my)
}
res = make(map[string]interface{})
count["page_count"] = int64(math.Ceil(float64(count["result_count"]) / float64(count["page_size"])))
res["page"] = count
res["result"] = myhs
return
}

View File

@@ -0,0 +1,12 @@
package usersuit
import (
"context"
usmdl "go-common/app/service/main/usersuit/model"
)
// PointFlag .
func (s *Service) PointFlag(c context.Context, arg *usmdl.ArgMID) (res *usmdl.PointFlag, err error) {
return s.usRPC.PointFlag(c, arg)
}

View File

@@ -0,0 +1,208 @@
package usersuit
import (
"context"
"fmt"
"reflect"
"testing"
usmdl "go-common/app/service/main/usersuit/model"
usrpc "go-common/app/service/main/usersuit/rpc/client"
"github.com/bouk/monkey"
. "github.com/smartystreets/goconvey/convey"
)
func TestService_Equip(t *testing.T) {
// 1背包里只要存在挂件且来源是背包不论挂件是否为大会员的都能佩戴 2背包里不存在挂件但来源是大会员挂件也可以佩戴反之报错用例如下
Convey("Equip interface", t, func() {
var (
c = context.Background()
)
// 穿戴一个非vip挂件但是挂件来源是vip报错
Convey(" wear vip pendant", t, func() {
var ArgEquip = &usmdl.ArgEquip{
Mid: 111001965,
Pid: 98,
Status: 2, //1 卸载 2 佩戴
Source: 2, // 0 未知 1背包 2 vip
}
guard := monkey.PatchInstanceMethod(reflect.TypeOf(s.usRPC), "Equip", func(_ *usrpc.Service2, _ context.Context, _ *usmdl.ArgEquip) error {
return fmt.Errorf("wear not vip pendant,but source is EquipFromVip")
})
defer guard.Unpatch()
err := s.usRPC.Equip(c, ArgEquip)
Convey("the pendant is not vip pendant,then err should not be nil", t, func() {
So(err, ShouldNotBeNil)
})
})
// 穿戴一个vip挂件但是挂件来源是背包(前提:背包里存在该挂件),正确
Convey(" wear vip pendant", t, func() {
var ArgEquip = &usmdl.ArgEquip{
Mid: 111001965,
Pid: 102,
Status: 2, //1 卸载 2 佩戴
Source: 1, // 0 未知 1背包 2 vip
}
guard := monkey.PatchInstanceMethod(reflect.TypeOf(s.usRPC), "Equip", func(_ *usrpc.Service2, _ context.Context, _ *usmdl.ArgEquip) error {
return nil
})
defer guard.Unpatch()
err := s.usRPC.Equip(c, ArgEquip)
Convey("wear vip pendant and this pendant exist in package, then err should be nil", t, func() {
So(err, ShouldBeNil)
})
})
// 穿戴挂件与来源一致 vip挂件
Convey(" wear vip pendant", t, func() {
var ArgEquip = &usmdl.ArgEquip{
Mid: 111001965,
Pid: 103,
Status: 2, //1 卸载 2 佩戴
Source: 2, // 0 未知 1背包 2 vip
}
guard := monkey.PatchInstanceMethod(reflect.TypeOf(s.usRPC), "Equip", func(_ *usrpc.Service2, _ context.Context, _ *usmdl.ArgEquip) error {
return nil
})
defer guard.Unpatch()
err := s.usRPC.Equip(c, ArgEquip)
Convey("the pendant is vip pendant and source is EquipFromVip,then err should be nil", t, func() {
So(err, ShouldBeNil)
})
})
// 穿戴挂件与来源一致 :背包挂件(背包存在该挂件)
Convey(" wear vip pendant", t, func() {
var ArgEquip = &usmdl.ArgEquip{
Mid: 111001965,
Pid: 98,
Status: 2, //1 卸载 2 佩戴
Source: 1, // 0 未知 1背包 2 vip
}
guard := monkey.PatchInstanceMethod(reflect.TypeOf(s.usRPC), "Equip", func(_ *usrpc.Service2, _ context.Context, _ *usmdl.ArgEquip) error {
return nil
})
defer guard.Unpatch()
err := s.usRPC.Equip(c, ArgEquip)
Convey("wear a pkg pendant and package exist the pendant and source is EquipFromPackage, then err should be nil", t, func() {
So(err, ShouldBeNil)
})
})
// 穿戴一个背包里不存在的挂件但是挂件来源是背包非vip挂件,报错
Convey(" wear vip pendant", t, func() {
var ArgEquip = &usmdl.ArgEquip{
Mid: 111001965,
Pid: 99,
Status: 2, //1 卸载 2 佩戴
Source: 1, // 0 未知 1背包 2 vip
}
guard := monkey.PatchInstanceMethod(reflect.TypeOf(s.usRPC), "Equip", func(_ *usrpc.Service2, _ context.Context, _ *usmdl.ArgEquip) error {
return fmt.Errorf("pendant is not exist, err_code: 64101")
})
defer guard.Unpatch()
err := s.usRPC.Equip(c, ArgEquip)
Convey("wear a pendant which is not exist in package and source is EquipFromPackage, then err should not be nil", t, func() {
So(err, ShouldNotBeNil)
})
})
// 卸下挂件(挂件存在),不会受到 source 的影响
Convey(" take off pkg pendant", t, func() {
var ArgEquip = &usmdl.ArgEquip{
Mid: 111001965, Pid: 98, Status: 1, Source: 2,
}
guard := monkey.PatchInstanceMethod(reflect.TypeOf(s.usRPC), "Equip", func(_ *usrpc.Service2, _ context.Context, _ *usmdl.ArgEquip) error {
return nil
})
defer guard.Unpatch()
err := s.usRPC.Equip(c, ArgEquip)
Convey("take off pendant is not be affected by source, then err should not be nil", t, func() {
So(err, ShouldBeNil)
})
})
Convey(" take off vip pendant", t, func() {
var ArgEquip = &usmdl.ArgEquip{
Mid: 111001965, Pid: 102, Status: 1, Source: 2,
}
guard := monkey.PatchInstanceMethod(reflect.TypeOf(s.usRPC), "Equip", func(_ *usrpc.Service2, _ context.Context, _ *usmdl.ArgEquip) error {
return nil
})
defer guard.Unpatch()
err := s.usRPC.Equip(c, ArgEquip)
Convey("take off pendant is not be affected by source, then err should not be nil", t, func() {
So(err, ShouldBeNil)
})
})
})
}
//func TestService_Equip(t *testing.T) {
// Convey("Equip interface", t, func() {
// So(s.Equip(context.Background(), 1, 1, 2, 1), ShouldBeNil)
// })
//}
func TestService_Equipment(t *testing.T) {
Convey("Equipment interface", t, func() {
equip, err := s.Equipment(context.Background(), 1)
So(err, ShouldBeNil)
So(equip, ShouldNotBeEmpty)
})
}
func TestService_Pendant(t *testing.T) {
Convey("Pendant interface", t, func() {
pendant, err := s.Pendant(context.Background(), 1)
So(err, ShouldBeNil)
So(pendant, ShouldNotBeEmpty)
})
}
func TestService_GroupEntry(t *testing.T) {
Convey("GroupEntry interface", t, func() {
groups, err := s.GroupEntry(context.Background(), 1)
So(err, ShouldBeNil)
So(groups, ShouldNotBeEmpty)
})
}
func TestService_GroupVIP(t *testing.T) {
Convey("GroupVIP interface", t, func() {
vips, err := s.GroupVIP(context.Background(), 1)
So(err, ShouldBeNil)
So(vips, ShouldNotBeEmpty)
})
}
func TestService_VipGet(t *testing.T) {
Convey("VipGet interface", t, func() {
So(s.VipGet(context.Background(), 1, 1, 2), ShouldBeNil)
})
}
func TestService_CheckOrder(t *testing.T) {
Convey("CheckOrder interface", t, func() {
So(s.CheckOrder(context.Background(), 1, "lalala"), ShouldBeNil)
})
}
func TestService_My(t *testing.T) {
Convey("My interface", t, func() {
my, err := s.My(context.Background(), 1)
So(err, ShouldBeNil)
So(my, ShouldNotBeEmpty)
})
}
func TestService_MyHistory(t *testing.T) {
Convey("MyHistory interface", t, func() {
res, err := s.MyHistory(context.Background(), 1, 1)
So(err, ShouldBeNil)
So(res, ShouldNotBeEmpty)
})
}

View File

@@ -0,0 +1,46 @@
package usersuit
import (
"context"
"go-common/app/interface/main/account/conf"
"go-common/app/interface/main/account/dao/usersuit"
"go-common/app/interface/main/account/dao/vip"
accrpc "go-common/app/service/main/account/rpc/client"
coinrpc "go-common/app/service/main/coin/api/gorpc"
memrpc "go-common/app/service/main/member/api/gorpc"
usrpc "go-common/app/service/main/usersuit/rpc/client"
)
// Service struct.
type Service struct {
c *conf.Config
dao *usersuit.Dao
vipDao *vip.Dao
usRPC *usrpc.Service2
accRPC *accrpc.Service3
coinRPC *coinrpc.Service
memRPC *memrpc.Service
}
// New a pendant service
func New(c *conf.Config) (s *Service) {
s = &Service{
c: c,
dao: usersuit.New(c),
vipDao: vip.New(c),
usRPC: usrpc.New(c.RPCClient2.Usersuit),
memRPC: memrpc.New(c.RPCClient2.Member),
accRPC: accrpc.New3(c.RPCClient2.Account),
coinRPC: coinrpc.New(c.RPCClient2.Coin),
}
return
}
// Ping check server ok.
func (s *Service) Ping(c context.Context) (err error) {
return
}
// Close dao.
func (s *Service) Close() {}

View File

@@ -0,0 +1,19 @@
package usersuit
import (
"flag"
"go-common/app/interface/main/account/conf"
)
var (
s *Service
)
func init() {
flag.Set("conf", "../../cmd/account-interface-example.toml")
if err := conf.Init(); err != nil {
panic(err)
}
s = New(conf.Conf)
}