Browse Source

wip: 营销平台新增rpc

zhangxinlei1996 2 năm trước cách đây
mục cha
commit
5026b6e720
2 tập tin đã thay đổi với 95 bổ sung0 xóa
  1. 90 0
      middleground/activity.go
  2. 5 0
      middleground/middleground.go

+ 90 - 0
middleground/activity.go

@@ -0,0 +1,90 @@
+package middleground
+
+import (
+	"context"
+	"log"
+
+	activityC "app.yhyue.com/moapp/jyMarketing/rpc/activity"
+	"github.com/zeromicro/go-zero/core/discov"
+	"github.com/zeromicro/go-zero/zrpc"
+)
+
+//活动
+type activity struct {
+	hosts  []string
+	key    string
+	client zrpc.Client
+}
+
+func newActivity(hosts []string, key string) *activity {
+	r := &activity{
+		hosts: hosts,
+		key:   key,
+	}
+	r.client = r.NewClient()
+	return r
+}
+
+func (a *activity) NewClient() zrpc.Client {
+	if a.client != nil && a.client.Conn() != nil {
+		return a.client
+	}
+	client, err := zrpc.NewClient(zrpc.RpcClientConf{
+		Etcd: discov.EtcdConf{
+			Hosts: a.hosts,
+			Key:   a.key,
+		},
+	})
+	if err != nil {
+		log.Println(err)
+		return nil
+	}
+	a.client = client
+	return client
+}
+
+// 获取赠品
+func (a *activity) GiveInfo(useProductType int64, useProduct, userId, appId string) *activityC.ActivitygiftResp {
+	client := a.NewClient()
+	if client == nil {
+		return nil
+	}
+	resp, err := activityC.NewActivity(client).GiveInfo(context.Background(), &activityC.Request{
+		UseProduct:     useProduct,
+		AppId:          appId,
+		UseProductType: useProductType,
+		UserId:         userId,
+	})
+	if err != nil {
+		log.Println(err)
+		return nil
+	}
+	return resp
+}
+
+//用户下所有的奖券(自带领取功能)
+/*
+useProductType     商品类型0普通的1线上课程
+receivingLocation  落地页位置0落地页1支付页面
+productCode        产品代码
+userId             用户标识
+appId              身份标识
+*/
+func (a *activity) UserAllLottery(useProductType, receivingLocation int64, productCode, userId, appId string) *activityC.AllLotteryResp {
+	client := a.NewClient()
+	if client == nil {
+		return nil
+	}
+	resp, err := activityC.NewActivity(client).UserAllLottery(context.Background(), &activityC.AllLotteryReq{
+		UseProductType:    useProductType,    //商品类型0普通的1线上课程
+		ReceivingLocation: receivingLocation, //落地页位置0落地页1支付页面
+		AppId:             appId,
+		UserId:            userId,
+		ProductCode:       productCode, //产品代码
+	})
+	if err != nil {
+		log.Println(err)
+		return nil
+	}
+	return resp
+}

+ 5 - 0
middleground/middleground.go

@@ -6,6 +6,7 @@ type Middleground struct {
 	ResourceCenter       *resourceCenter
 	PowerCheckCenter     *powerCheckCenter
 	EntManageApplication *entManageApplication
+	ActivityCenter       *activity
 }
 
 func NewMiddleground(hosts []string) *Middleground {
@@ -29,6 +30,10 @@ func (m *Middleground) RegEntManageApplication(key string) *Middleground {
 	m.EntManageApplication = newEntManageApplication(m.hosts, key)
 	return m
 }
+func (m *Middleground) RegActivity(key string) *Middleground {
+	m.ActivityCenter = newActivity(m.hosts, key)
+	return m
+}
 func main() {
 	//userId: 63d498bb6ae0e1ea2170e03d -baseUserId: 366251 -accountId: 13485 -entId: 15419 -positionType: 0 -baseUserId: 366251 -accountId: 13485 -entId: 15419 -positionType: 0 -positionId: 932
 	NewMiddleground([]string{"192.168.3.206:2379"}).RegPowerCheckCenter("powercheck.rpc")