|
@@ -77,68 +77,68 @@ func (this *baskPackStruct) defaultConsume() (r map[string]interface{}, m string
|
|
|
|
|
|
//附件下载消费 fui:免费赠送已使用次数;pui:付费权限已使用次数
|
|
|
func (this *baskPackStruct) fileConsume() (r map[string]interface{}, m string) {
|
|
|
- //查询当月附件下载历史记录-如是已下载过的附件不再扣除次数
|
|
|
- this.Month = jy.GetMonth(time.Now().Month().String())
|
|
|
- this.Year = time.Now().Year()
|
|
|
- _, retList, _ := this.perPackRechargeApi()
|
|
|
_fileName := this.Remarks["fileName"].(string)
|
|
|
_id := this.Remarks["id"].(string)
|
|
|
- _downUrl := ""
|
|
|
- _size := ""
|
|
|
- isExists := false
|
|
|
- for _, item := range retList {
|
|
|
- itemData := qutil.ObjToMap(item)
|
|
|
- if itemData == nil || len(*itemData) == 0 {
|
|
|
- continue
|
|
|
- }
|
|
|
- remarks_str := qutil.ObjToString((*itemData)["remarks"])
|
|
|
- if remarks_str == "" {
|
|
|
- continue
|
|
|
- }
|
|
|
- remarks := make(map[string]interface{})
|
|
|
- err := json.Unmarshal([]byte(remarks_str), remarks)
|
|
|
- if err != nil {
|
|
|
- fmt.Printf("Unmarshal err")
|
|
|
- continue
|
|
|
- }
|
|
|
- if remarks["fileName"] == _fileName && remarks["id"] == _id {
|
|
|
- // _downUrl = remarks["downUrl"]
|
|
|
- // _size = remarks["size"]
|
|
|
- r = remarks
|
|
|
- isExists = true
|
|
|
- break
|
|
|
- }
|
|
|
- }
|
|
|
- //当月未有消费记录
|
|
|
- if !isExists {
|
|
|
- isCanConsume_f := false
|
|
|
- isCanConsume_p := false
|
|
|
- //免费赠送已使用次数
|
|
|
- mon := fmt.Sprintf(jy.VipFileUploadNumKey, this.UserId, fmt.Sprint(time.Now().Month()))
|
|
|
- fui := redis.GetInt(jy.PowerCacheDb, mon)
|
|
|
- if fui < config.BidfileConfig.File_number {
|
|
|
- isCanConsume_f = true
|
|
|
- } else if payCount := this.accountPack(); payCount > 0 { //付费未使用次数
|
|
|
- isCanConsume_p = true
|
|
|
- }
|
|
|
- if isCanConsume_f || isCanConsume_p {
|
|
|
- // 调用rpc 获取附件信息
|
|
|
- req := util.JyFileRequest{qutil.DecodeArticleId2ByCheck(_id)[0]}
|
|
|
- rep, err := util.Attachment(&req)
|
|
|
+ // _downUrl := ""
|
|
|
+ // _size := ""
|
|
|
+ BaseMsg := jy.GetBigVipUserBaseMsg(this.UserId, util.Mysql, util.MQFW)
|
|
|
+ if BaseMsg.Status > 0 && BaseMsg.PowerMap[3] {
|
|
|
+ r = fileAttachRpc(_fileName, _id)
|
|
|
+ go func(this *baskPackStruct, r map[string]interface{}) {
|
|
|
+ data := make(map[string]interface{})
|
|
|
+ data["p_type"] = "大会员用户附件下载"
|
|
|
+ data["p_userid"] = this.UserId
|
|
|
+ data["p_infoId"] = this.Remarks["id"].(string)
|
|
|
+ data["s_platform"] = this.Platform
|
|
|
+ data["p_create_time"] = time.Now().Unix()
|
|
|
+ data["p_rep"] = r
|
|
|
+ //存库记录
|
|
|
+ if util.MQFW.Save("filehistroy", data) == "" {
|
|
|
+ log.Println("大会员附件下载-历史记录异常:" + this.UserId)
|
|
|
+ }
|
|
|
+ }(this, r)
|
|
|
+ } else if BaseMsg.VipStatus > 0 {
|
|
|
+ //查询当月附件下载历史记录-如是已下载过的附件不再扣除次数
|
|
|
+ this.Month = jy.GetMonth(time.Now().Month().String())
|
|
|
+ this.Year = time.Now().Year()
|
|
|
+ _, retList, _ := this.perPackRechargeApi()
|
|
|
+ isExists := false
|
|
|
+ for _, item := range retList {
|
|
|
+ itemData := qutil.ObjToMap(item)
|
|
|
+ if itemData == nil || len(*itemData) == 0 {
|
|
|
+ continue
|
|
|
+ }
|
|
|
+ remarks_str := qutil.ObjToString((*itemData)["remarks"])
|
|
|
+ if remarks_str == "" {
|
|
|
+ continue
|
|
|
+ }
|
|
|
+ remarks := make(map[string]interface{})
|
|
|
+ err := json.Unmarshal([]byte(remarks_str), remarks)
|
|
|
if err != nil {
|
|
|
- m = "attachment rpc调用失败"
|
|
|
- } else {
|
|
|
- if rep.Rep != nil && len(rep.Rep) > 0 {
|
|
|
- //获取当前附件下载地址
|
|
|
- for _, v := range rep.Rep {
|
|
|
- if qutil.ObjToString(v["filename"]) == _fileName {
|
|
|
- _downUrl = qutil.ObjToString(v["downUrl"])
|
|
|
- _size = qutil.ObjToString(v["size"])
|
|
|
- }
|
|
|
- }
|
|
|
- //api 消费记录
|
|
|
- this.Remarks["downUrl"] = _downUrl
|
|
|
- this.Remarks["size"] = _size
|
|
|
+ fmt.Printf("Unmarshal err")
|
|
|
+ continue
|
|
|
+ }
|
|
|
+ if remarks["fileName"] == _fileName && remarks["id"] == _id {
|
|
|
+ r = remarks
|
|
|
+ isExists = true
|
|
|
+ break
|
|
|
+ }
|
|
|
+ }
|
|
|
+ //当月未有消费记录
|
|
|
+ if !isExists {
|
|
|
+ isCanConsume_f := false
|
|
|
+ isCanConsume_p := false
|
|
|
+ //免费赠送已使用次数
|
|
|
+ mon := fmt.Sprintf(jy.VipFileUploadNumKey, this.UserId, fmt.Sprint(time.Now().Month()))
|
|
|
+ fui := redis.GetInt(jy.PowerCacheDb, mon)
|
|
|
+ if fui < config.BidfileConfig.File_number {
|
|
|
+ isCanConsume_f = true
|
|
|
+ } else if payCount := this.accountPack(); payCount > 0 { //付费未使用次数
|
|
|
+ isCanConsume_p = true
|
|
|
+ }
|
|
|
+ if isCanConsume_f || isCanConsume_p {
|
|
|
+ r = fileAttachRpc(_fileName, _id)
|
|
|
+ if len(r) > 0 {
|
|
|
rb, rm := this.consumePackApi()
|
|
|
if !rb {
|
|
|
m = fmt.Sprintf("消费异常:%s", rm)
|
|
@@ -153,6 +153,44 @@ func (this *baskPackStruct) fileConsume() (r map[string]interface{}, m string) {
|
|
|
}
|
|
|
}
|
|
|
}
|
|
|
+ } else {
|
|
|
+ m = "获取附件异常"
|
|
|
+ }
|
|
|
+ } else {
|
|
|
+ m = "该用户下载权限当前月已用完"
|
|
|
+ }
|
|
|
+ }
|
|
|
+ } else {
|
|
|
+ //判断免费用户是否有留资下载权限
|
|
|
+ if _, _, freeFileNum := jy.FreeExperience(this.UserId); freeFileNum == 1 {
|
|
|
+ //免费用户下载后取消下载权限
|
|
|
+ redis.PutKV(fmt.Sprintf(jy.PowerCacheFileKey, this.UserId), -1)
|
|
|
+ } else {
|
|
|
+ m = "该用户没有下载权限"
|
|
|
+ }
|
|
|
+ }
|
|
|
+ return
|
|
|
+}
|
|
|
+
|
|
|
+//
|
|
|
+func fileAttachRpc(fileName, id string) (r map[string]interface{}) {
|
|
|
+ r = make(map[string]interface{})
|
|
|
+ // 调用rpc 获取附件信息
|
|
|
+ req := util.JyFileRequest{qutil.DecodeArticleId2ByCheck(id)[0]}
|
|
|
+ rep, err := util.Attachment(&req)
|
|
|
+ if err != nil {
|
|
|
+ log.Println("attachment rpc调用失败")
|
|
|
+ } else {
|
|
|
+ if rep.Rep != nil && len(rep.Rep) > 0 {
|
|
|
+ //获取当前附件下载地址
|
|
|
+ for _, v := range rep.Rep {
|
|
|
+ if qutil.ObjToString(v["filename"]) == fileName {
|
|
|
+ r = map[string]interface{}{
|
|
|
+ "downurl": qutil.ObjToString(v["downUrl"]),
|
|
|
+ "filename": qutil.ObjToString(v["filename"]),
|
|
|
+ "size": qutil.ObjToString(v["size"]),
|
|
|
+ }
|
|
|
+ break
|
|
|
}
|
|
|
}
|
|
|
}
|