Преглед изворни кода

wip:卡券相关代码提交

wangkaiyue пре 3 година
родитељ
комит
1482fd4f26
3 измењених фајлова са 122 додато и 19 уклоњено
  1. 5 8
      etc/config.yaml
  2. 76 9
      handler/activity/lotteryService.go
  3. 41 2
      services/activity/bidderPlan/services.go

+ 5 - 8
etc/config.yaml

@@ -21,7 +21,7 @@ nsq:
 #数据库配置
 databases:
   # redis配置
-  redis: main=123.56.53.97:1713,session=123.56.53.97:1713
+  redis: main=127.0.0.1:6379,session=192.168.3.206:1712
   # nsq操作日志库
   mogLog:
     address: 192.168.3.206:27090
@@ -74,8 +74,8 @@ jyactivity: # 临时活动
   name: 剑鱼超级会员节
   code: membershipDay
   dateRange: #活动时间
-    t1: 2022-07-25 00:00:00 #预热活动
-    t2: 2022-07-25 00:00:00 #活动开始
+    t1: 2022-05-25 00:00:00 #预热活动
+    t2: 2022-06-25 00:00:00 #活动开始
     ed: 2022-08-07 00:00:00 #活动结束
   missions: #任务列表
     buysubvip: #购买超级订阅
@@ -98,15 +98,12 @@ jyactivity: # 临时活动
       svip: 7 #赠送超级订阅限制
       limit: 500 #每日数量限制
 
-#优惠券领取及查询接口
-lotteryUrl: http://192.168.3.206:8090
-
 #优惠券Rpc查询接口
-lotteryRpcUrl: 192.168.3.206:8090
+lotteryUrl: http://192.168.3.206:8090
 
 productCode:
   subscription: 101
   subscriptionWeek: 1011
   subscriptionMonth: 1012
   subscriptionQuarter: 1013
-  subscriptionYear: 1014
+  subscriptionYear: 1014

+ 76 - 9
handler/activity/lotteryService.go

@@ -2,6 +2,7 @@ package activity
 
 import (
 	"app.yhyue.com/moapp/message/config"
+	"app.yhyue.com/moapp/message/db"
 	"encoding/json"
 	"fmt"
 	"github.com/gogf/gf/v2/os/gcfg"
@@ -11,16 +12,84 @@ import (
 	"net/http"
 	url2 "net/url"
 	"strconv"
+	"time"
 )
 
-//ActivityLottery 获取活动下的奖券 receivingLocation 奖券形式0落地页 1付款页 999全部 3 我的奖券 productCode 活动code
-func ActivityLottery(userId, receivingLocation string) (map[string]interface{}, error) {
+type LotteryReq struct {
+	Code int             `json:"Code"`
+	Msg  string          `json:"Message"`
+	Data []LotteryDetail `json:"Data"`
+}
+
+type LotteryDetail struct {
+	Full         int    `json:"Full"`         //满
+	Reduce       int    `json:"Reduce"`       //减
+	IsReceive    bool   `json:"IsReceive"`    //是否领取 true可领取 false 不能领取
+	IsUser       bool   `json:"IsUser"`       //是否使用 true已用 false 未使用
+	LotteryName  string `json:"LotteryName"`  //卡券名字
+	LotteryIdStr string `json:"LotteryIdStr"` //卡券加密id
+}
+
+func (BP *JyActivity) GetActivityLotteryList(userId string) ([]LotteryDetail, error) {
+	if _, inActivity := BP.InActivity(); !inActivity {
+		return nil, fmt.Errorf("不在活动时间内")
+	}
+	req, err := activityLotteryRequest(userId, "0")
+	if err != nil {
+		return nil, err
+	}
+	if req.Code != 1 {
+		return nil, fmt.Errorf("获取优惠券异常" + req.Msg)
+	}
+	if len(req.Data) == 0 {
+		return nil, fmt.Errorf("优惠券列表空")
+	}
+	return req.Data, err
+}
+
+//GetLottery 领取卡券
+func (BP *JyActivity) GetLottery(userId, userName, lotteryIds string) error {
+	if _, inActivity := BP.InActivity(); !inActivity {
+		return fmt.Errorf("不在活动时间内")
+	}
+	lotteryRep := config.LotteryReceiveReq{
+		UserName:     userName,
+		UserId:       userId,
+		LotteryIdArr: lotteryIds,
+	}
+	code, msg := getLotteryReceive(lotteryRep)
+	if code != 1 {
+		return fmt.Errorf("领取优惠券异常%s", msg)
+	}
+
+	//存入奖励列表
+	var awardList []map[string]interface{}
+	nowStamp := time.Now().Unix()
+	list, _ := activityLotteryRequest(userId, "0")
+	for _, v := range list.Data {
+		awardList = append(awardList, map[string]interface{}{
+			"activity_code": BP.ActivityCode,
+			"detail":        v.LotteryName,
+			"userid":        userId,
+			"award":         "lottery-fullReduce", //满减券
+			"num":           v.Reduce,
+			"getway":        "福利一",
+			"date":          nowStamp,
+		})
+	}
+	if len(awardList) > 0 {
+		db.Mgo.SaveBulk("activity_award", awardList...)
+	}
+	return nil
+}
+
+//activityLottery 获取活动下的奖券 receivingLocation 奖券形式0落地页 1付款页 999全部 3 我的奖券 productCode 活动code
+func activityLotteryRequest(userId, receivingLocation string) (*LotteryReq, error) {
 	//url := config.PushConfig.ActivityUrl + "/activityLottery?userId=" + userId + "&appId=" + appId + "&activityId=" + activityId + "&receivingLocation=" + receivingLocation + "&productCode=" + productCode
 	appId := gcfg.Instance().MustGet(gctx.New(), "appid").String()
 	productCode := gcfg.Instance().MustGet(gctx.New(), "productCode.subscriptionMonth").String()
 	url := gcfg.Instance().MustGet(gctx.New(), "lotteryUrl").String() + "/activityLottery?userId=" + userId + "&appId=" + appId + "&receivingLocation=" + receivingLocation + "&productCode=" + productCode
 
-	log.Println(url)
 	request, err := http.NewRequest("GET", url, nil)
 	if err != nil {
 		return nil, err
@@ -31,17 +100,15 @@ func ActivityLottery(userId, receivingLocation string) (map[string]interface{},
 		return nil, err1
 	}
 	defer resp.Body.Close()
-	var info map[string]interface{}
+	var info LotteryReq
 	result, _ := ioutil.ReadAll(resp.Body)
 	err = json.Unmarshal(result, &info)
-	fmt.Println("==============json str 转map=======================", info)
-	return info, err
+	return &info, err
 }
 
-//LotteryReceive 奖卷领取 LotteryIdArr 奖券id 支持多个逗号拼接
-func LotteryReceive(lotteryRep config.LotteryReceiveReq) (int, string) {
+//getLotteryReceive 奖卷领取 LotteryIdArr 奖券id 支持多个逗号拼接
+func getLotteryReceive(lotteryRep config.LotteryReceiveReq) (int, string) {
 	appId := gcfg.Instance().MustGet(gctx.New(), "appid").String()
-
 	userNameStr := url2.PathEscape(lotteryRep.UserName)
 	url := gcfg.Instance().MustGet(gctx.New(), "lotteryUrl").String() + "/lotteryReceive?userName=" + userNameStr + "&userId=" + lotteryRep.UserId + "&appId=" + appId + "&lotteryIdArr=" + lotteryRep.LotteryIdArr
 	log.Println(url)

+ 41 - 2
services/activity/bidderPlan/services.go

@@ -22,6 +22,9 @@ type Activity struct {
 	//预热-每日福利
 	getDailyBoonDetail xweb.Mapper `xweb:"/membershipDay/getDailyBoonDetail"` //查询每日福利余额
 	getDailyBoonSVip   xweb.Mapper `xweb:"/membershipDay/getDailyBoonSVip"`   //获取限量vip
+	//活动领券
+	lotteryList xweb.Mapper `xweb:"/membershipDay/lotteryList"` //活动券列表
+	getLottery  xweb.Mapper `xweb:"/membershipDay/getLottery"`  //领取优惠券
 }
 
 // Period 活动周期
@@ -151,8 +154,7 @@ func (act *Activity) GetDailyBoonSVip() {
 		if !activity.MembershipDay.FastClickCheck(userId) {
 			return false, fmt.Errorf("操作频繁")
 		}
-		err := activity.MembershipDay.GetDailyBoonSVip(userId)
-		if err != nil {
+		if err := activity.MembershipDay.GetDailyBoonSVip(userId); err != nil {
 			return false, err
 		}
 		return true, nil
@@ -162,3 +164,40 @@ func (act *Activity) GetDailyBoonSVip() {
 	}
 	act.ServeJson(NewResult(rData, errMsg))
 }
+
+// LotteryList 活动券列表
+func (act *Activity) LotteryList() {
+	userId := gconv.String(act.GetSession("userId"))
+	rData, errMsg := func() ([]activity.LotteryDetail, error) {
+		return activity.MembershipDay.GetActivityLotteryList(userId)
+	}()
+	if errMsg != nil {
+		log.Printf("Activity BidderPlan LotteryDetail  %s error:%s\n", userId, errMsg.Error())
+	}
+	act.ServeJson(NewResult(rData, errMsg))
+}
+
+// GetLottery 领取活动券
+func (act *Activity) GetLottery() {
+	userId := gconv.String(act.GetSession("userId"))
+	rData, errMsg := func() (bool, error) {
+		name := gconv.String(act.Session().Get("s_nickname"))
+		reqParam := map[string]interface{}{}
+		if err := json.Unmarshal(act.Body(), &reqParam); err != nil || len(reqParam) == 0 {
+			return false, fmt.Errorf("请求参数异常")
+		}
+		lotteryIds := gconv.String(reqParam["lotteryIds"])
+		if lotteryIds == "" {
+			return false, fmt.Errorf("无选择卡券")
+		}
+		err := activity.MembershipDay.GetLottery(userId, name, lotteryIds)
+		if err != nil {
+			return false, err
+		}
+		return true, nil
+	}()
+	if errMsg != nil {
+		log.Printf("Activity BidderPlan GetLottery  %s error:%s\n", userId, errMsg.Error())
+	}
+	act.ServeJson(NewResult(rData, errMsg))
+}