|
@@ -6,13 +6,17 @@ import (
|
|
|
"encoding/json"
|
|
|
"entity"
|
|
|
"fmt"
|
|
|
+ "io/ioutil"
|
|
|
"log"
|
|
|
"math"
|
|
|
+ "net/http"
|
|
|
"pay"
|
|
|
qutil "qfw/util"
|
|
|
"qfw/util/dataexport"
|
|
|
"qfw/util/jy"
|
|
|
"qfw/util/redis"
|
|
|
+ "strconv"
|
|
|
+ "strings"
|
|
|
"time"
|
|
|
"util"
|
|
|
|
|
@@ -36,6 +40,50 @@ type DataExportPack struct {
|
|
|
// PackGoodsList 数据包规格及价格列表
|
|
|
func (this *DataExportPack) PackGoodsList() {
|
|
|
packList, _ := entity.JyDataExportPack.GetPackPriceList()
|
|
|
+ userId, _ := this.GetSession("userId").(string)
|
|
|
+ if userId != "" {
|
|
|
+ getUrl := fmt.Sprintf("%s?useProduct=%s&appId=%s&useProductType=%v&userId=%s", config.CouponConfig.Giveinfo, config.CouponConfig.Products["数据流量包"], config.CouponConfig.AppId, 0, userId)
|
|
|
+ log.Println(getUrl)
|
|
|
+ res, err := http.Get(getUrl)
|
|
|
+ if err != nil {
|
|
|
+ log.Println(err.Error())
|
|
|
+ }
|
|
|
+ defer res.Body.Close()
|
|
|
+ bs, _ := ioutil.ReadAll(res.Body)
|
|
|
+ log.Println("res:", string(bs))
|
|
|
+ resMap := map[string]interface{}{}
|
|
|
+ err = json.Unmarshal([]byte(bs), &resMap)
|
|
|
+ if err != nil {
|
|
|
+ log.Println("json.unmarshal err", resMap)
|
|
|
+ } else {
|
|
|
+ proDuctM := map[string]string{} //产品码对应关系
|
|
|
+ for k, v := range config.CouponConfig.Products {
|
|
|
+ proDuctM[v] = k
|
|
|
+ }
|
|
|
+ pl, _ := packList.(map[string]interface{})
|
|
|
+ marr := []map[string]interface{}{}
|
|
|
+ if qutil.IntAll(resMap["Code"]) == 1 {
|
|
|
+ for _, vv := range config.ExConf.Packs_showList {
|
|
|
+ m := map[string]interface{}{
|
|
|
+ "packNum": vv.PackNum,
|
|
|
+ "normal_discount": vv.Normal_discount,
|
|
|
+ "senior_discount": vv.Senior_discount,
|
|
|
+ }
|
|
|
+ if resMap["Data"] != nil {
|
|
|
+ for _, v := range qutil.ObjArrToMapArr(resMap["Data"].([]interface{})) {
|
|
|
+ product := strconv.Itoa(qutil.IntAll(v["ProductCode"]))
|
|
|
+ if strings.Contains(proDuctM[product], strconv.Itoa(vv.PackNum)) {
|
|
|
+ m[fmt.Sprintf("%v_num", strings.Split(proDuctM[product], "_")[0])] = v["Time"]
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ marr = append(marr, m)
|
|
|
+ }
|
|
|
+ pl["packs_showList"] = marr
|
|
|
+ packList = pl
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
this.ServeJson(packList)
|
|
|
}
|
|
|
|
|
@@ -46,11 +94,10 @@ func (this *DataExportPack) PackGoodsList() {
|
|
|
func (this *DataExportPack) CreateOrder() {
|
|
|
userId, _ := this.GetSession("userId").(string)
|
|
|
rData, errMsg := func() (interface{}, error) {
|
|
|
- packId := this.GetString("packId") //
|
|
|
+ packId := this.GetString("packId") //
|
|
|
// 获取用户分销口令
|
|
|
disWordStr := ""
|
|
|
// 查询用户携带的分销口令
|
|
|
- log.Println(userId,"userId")
|
|
|
userfilter, ok := util.MQFW.FindById("user", userId, "")
|
|
|
if ok && userfilter != nil {
|
|
|
startTime := qutil.Int64All((*userfilter)["startTime"])
|
|
@@ -62,10 +109,11 @@ func (this *DataExportPack) CreateOrder() {
|
|
|
}
|
|
|
}
|
|
|
}
|
|
|
- log.Printf("user====",userfilter)
|
|
|
|
|
|
//根据id查询流量包价格
|
|
|
packDetail, err := entity.JyDataExportPack.GetPackDetailById(packId)
|
|
|
+ packDetail.GiveCycle = 0
|
|
|
+ packDetail.DisCountId = 0
|
|
|
if err != nil {
|
|
|
return nil, err
|
|
|
}
|
|
@@ -73,9 +121,15 @@ func (this *DataExportPack) CreateOrder() {
|
|
|
orderMoney, discountPrice := packDetail.Price, 0 //订单金额,卡券折扣金额
|
|
|
var userLotteryId string //用户卡券id
|
|
|
var discount float64
|
|
|
+ useProduct, _ := this.GetInteger("useProduct")
|
|
|
+ discountId, _ := this.GetInteger("discountId") //赠品相关
|
|
|
if lotteryId := this.GetString("lotteryId"); lotteryId != "" {
|
|
|
+ products := config.CouponConfig.Products["数据流量包"]
|
|
|
+ if useProduct > 0 {
|
|
|
+ products = strconv.Itoa(useProduct)
|
|
|
+ }
|
|
|
var fullPrice, reducePrice int
|
|
|
- fullPrice, reducePrice, discount, userLotteryId = util.GetCouponInfo(userId, lotteryId, config.CouponConfig.Products["数据流量包"])
|
|
|
+ fullPrice, reducePrice, discount, userLotteryId = util.GetCouponInfo(userId, lotteryId, products)
|
|
|
if discount == 100 {
|
|
|
if fullPrice <= orderMoney {
|
|
|
orderMoney = orderMoney - reducePrice
|
|
@@ -89,6 +143,18 @@ func (this *DataExportPack) CreateOrder() {
|
|
|
}
|
|
|
log.Printf("用户%s 购买数据流量包 使用卡券:%s 折扣金额:%d", userId, userLotteryId, discountPrice)
|
|
|
}
|
|
|
+ //赠品相关
|
|
|
+ useProduct, _ = strconv.Atoi(config.CouponConfig.Products[packId])
|
|
|
+ giveArr := GiveInfo(userId, useProduct, 0, 0) //获取满赠时长
|
|
|
+ if giveArr != nil && len(giveArr) > 0 {
|
|
|
+ packDetail.GiveCycle = qutil.IntAll(giveArr[0]["Time"])
|
|
|
+ packDetail.DisCountId = qutil.IntAll(giveArr[0]["DiscountId"])
|
|
|
+ discountId = qutil.IntAll(giveArr[0]["DiscountId"])
|
|
|
+ if strings.Contains(qutil.ObjToString(giveArr[0]["ActivityName"]), config.Config.ActivityName) {
|
|
|
+ packDetail.Badge = "202111" //双十一角标展示
|
|
|
+ }
|
|
|
+ }
|
|
|
+ //
|
|
|
orderCode := pay.GetOrderCode()
|
|
|
nickname, _ := this.GetSession("s_nickname").(string)
|
|
|
openId, _ := this.GetSession("s_m_openid").(string)
|
|
@@ -97,6 +163,7 @@ func (this *DataExportPack) CreateOrder() {
|
|
|
if err != nil {
|
|
|
return nil, fmt.Errorf("数据异常")
|
|
|
}
|
|
|
+ log.Println("---?>", string(filter))
|
|
|
orderid := util.Mysql.Insert("dataexport_order", map[string]interface{}{
|
|
|
"order_money": orderMoney,
|
|
|
"order_status": 0,
|
|
@@ -118,13 +185,18 @@ func (this *DataExportPack) CreateOrder() {
|
|
|
return nil, fmt.Errorf("创建订单异常")
|
|
|
}
|
|
|
//绑定核销卡券
|
|
|
- if userLotteryId != "" && this.GetString("lotteryId") != "" {
|
|
|
- go func(userId, userLotteryId, orderCode string) {
|
|
|
+ if (userLotteryId != "" && this.GetString("lotteryId") != "") || (discountId > 0) {
|
|
|
+ go func(userId, userLotteryId, orderCode, discountIdStr string) {
|
|
|
phone, nickname := util.GetMyPhoneAndName(userId)
|
|
|
- if !util.UpdateCouponState(userId, userLotteryId, nickname, phone, orderCode, "数据流量包", "", 3, 0) {
|
|
|
+ if !util.UpdateCouponState(userId, userLotteryId, nickname, phone, orderCode, "数据流量包", discountIdStr, 3, 0) {
|
|
|
log.Println(fmt.Sprintf("单号%s-绑定失败-卡卷%s", orderCode, userLotteryId))
|
|
|
}
|
|
|
- }(userId, userLotteryId, orderCode)
|
|
|
+ if discountId > 0 {
|
|
|
+ if ulid := util.FindUserLotteryId(userId, orderid, discountId); ulid != 0 {
|
|
|
+ userLotteryId = strconv.Itoa(ulid)
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }(userId, userLotteryId, orderCode, strconv.Itoa(discountId))
|
|
|
}
|
|
|
return map[string]interface{}{
|
|
|
"orderCode": orderCode,
|
|
@@ -395,3 +467,35 @@ func (this *DataExportPack) SendExportMail() {
|
|
|
}
|
|
|
this.ServeJson(NewResult(rData, errMsg))
|
|
|
}
|
|
|
+
|
|
|
+/*
|
|
|
+ useProduct :产品类型
|
|
|
+ useProductType:商品类型 0普通的 1线上课程
|
|
|
+ discountId:活动赠品对应标识
|
|
|
+return:
|
|
|
+ timeNum:赠送数量
|
|
|
+ 查看赠品
|
|
|
+*/
|
|
|
+func GiveInfo(userid string, useProduct, useProductType, discountId int) []map[string]interface{} {
|
|
|
+ getUrl := fmt.Sprintf("%s?useProduct=%s&appId=%s&useProductType=%v&userId=%s", config.CouponConfig.Giveinfo, strconv.Itoa(useProduct), config.CouponConfig.AppId, useProductType, userid)
|
|
|
+ log.Println(getUrl)
|
|
|
+ res, err := http.Get(getUrl)
|
|
|
+ if err != nil {
|
|
|
+ log.Println(err.Error())
|
|
|
+ }
|
|
|
+ defer res.Body.Close()
|
|
|
+ bs, _ := ioutil.ReadAll(res.Body)
|
|
|
+ log.Println("res:", string(bs))
|
|
|
+ resMap := map[string]interface{}{}
|
|
|
+ err = json.Unmarshal([]byte(bs), &resMap)
|
|
|
+ if err != nil {
|
|
|
+ log.Println("json.unmarshal err", resMap)
|
|
|
+ } else {
|
|
|
+ if qutil.IntAll(resMap["Code"]) == 1 {
|
|
|
+ if data, _ := resMap["Data"].([]interface{}); len(data) > 0 && data != nil {
|
|
|
+ return qutil.ObjArrToMapArr(data)
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ return nil
|
|
|
+}
|