|
@@ -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)
|