|
@@ -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
|
|
|
+}
|