|
@@ -4,6 +4,7 @@ import (
|
|
|
"app.yhyue.com/moapp/jybase/go-xweb/httpsession"
|
|
|
"encoding/json"
|
|
|
"fmt"
|
|
|
+ "github.com/gogf/gf/v2/util/gconv"
|
|
|
"jy/src/jfw/modules/subscribepay/src/config"
|
|
|
"jy/src/jfw/modules/subscribepay/src/util"
|
|
|
"log"
|
|
@@ -13,7 +14,6 @@ import (
|
|
|
. "app.yhyue.com/moapp/jybase/date"
|
|
|
"app.yhyue.com/moapp/jybase/encrypt"
|
|
|
. "app.yhyue.com/moapp/jybase/mongodb"
|
|
|
- "app.yhyue.com/moapp/jybase/redis"
|
|
|
"app.yhyue.com/moapp/jypkg/common/src/qfw/util/jy"
|
|
|
)
|
|
|
|
|
@@ -33,6 +33,26 @@ func (this *UseBalanceStruct) fileConsume() (r map[string]interface{}, m string,
|
|
|
log.Println("附件下载包。。。。。")
|
|
|
BaseMsg := jy.GetBigVipUserBaseMsg(this.Session, *config.Middleground)
|
|
|
log.Println("---:", this.Remarks)
|
|
|
+ //获取余额数量
|
|
|
+ dbs := &FindBalanceStruct{
|
|
|
+ AccountId: this.UserId,
|
|
|
+ ResourceType: "附件下载包",
|
|
|
+ VipState: BaseMsg.VipStatus,
|
|
|
+ }
|
|
|
+ data, err := dbs.FindBalance()
|
|
|
+ if data == nil || err != nil {
|
|
|
+ c = -1
|
|
|
+ m = "余额不足"
|
|
|
+ return
|
|
|
+ }
|
|
|
+ number := 0
|
|
|
+ if data != nil {
|
|
|
+ dataArr := gconv.SliceAny(data["data"])
|
|
|
+ if len(dataArr) > 0 {
|
|
|
+ dataMap := gconv.MapStrStr(dataArr[0])
|
|
|
+ number = gconv.Int(dataMap["number"])
|
|
|
+ }
|
|
|
+ }
|
|
|
if BaseMsg.Status > 0 && BaseMsg.PowerMap[3] {
|
|
|
if this.Remarks["infoType"] != nil && this.Remarks["infoType"].(string) == "S" {
|
|
|
r = SupplyInfoFile(_fileName, _id)
|
|
@@ -72,17 +92,8 @@ func (this *UseBalanceStruct) fileConsume() (r map[string]interface{}, m string,
|
|
|
// log.Println(this.Remarks, "++++++", this.AccountId, id, "-------------", isExists)
|
|
|
//当月未有消费记录
|
|
|
if !isExists {
|
|
|
- isCanConsume_f := false
|
|
|
- isCanConsume_p := false
|
|
|
//免费赠送已使用次数
|
|
|
- mon_free := fmt.Sprintf(jy.VipFileUploadNumKey, this.UserId, fmt.Sprint(time.Now().Month()))
|
|
|
- fui := redis.GetInt(jy.PowerCacheDb, mon_free)
|
|
|
- if fui < config.BidfileConfig.File_number {
|
|
|
- isCanConsume_f = true
|
|
|
- } else if payCount := this.accountPack(); payCount > 0 { //付费未使用次数
|
|
|
- isCanConsume_p = true
|
|
|
- }
|
|
|
- if isCanConsume_f || isCanConsume_p {
|
|
|
+ if number > 0 {
|
|
|
if this.Remarks["infoType"] != nil && this.Remarks["infoType"].(string) == "S" {
|
|
|
r = SupplyInfoFile(_fileName, _id)
|
|
|
} else {
|
|
@@ -92,24 +103,10 @@ func (this *UseBalanceStruct) fileConsume() (r map[string]interface{}, m string,
|
|
|
this.Remarks["downUrl"] = r["downUrl"]
|
|
|
this.Remarks["size"] = r["size"]
|
|
|
if this.saveJyConsumePackList() {
|
|
|
- if isCanConsume_p {
|
|
|
- //中台消费记录
|
|
|
- rb, err := this.UseBalance()
|
|
|
- if err != nil || (rb != nil && qutil.IntAll(rb["code"]) == 0) {
|
|
|
- m = fmt.Sprintf("消费记录保存异常:%s", qutil.ObjToString(rb["message"]))
|
|
|
- } else {
|
|
|
- //更新redis 购买附件下载包数量
|
|
|
- mon_pay := fmt.Sprintf(jy.FilePackNumKey, this.UserId, fmt.Sprint(time.Now().Month()))
|
|
|
- if redis.GetInt(jy.PowerCacheDb, mon_pay) <= 0 || redis.Decrby(jy.PowerCacheDb, mon_pay, 1) < 0 {
|
|
|
- log.Println(fmt.Sprintf("附件下载包 消费异常:%s,附件名称:%s", this.UserId, this.Remarks["fileName"].(string)))
|
|
|
- }
|
|
|
- }
|
|
|
- } else if isCanConsume_f { //下载后自增一次 免费权限默认存储31d
|
|
|
- if fui == 0 {
|
|
|
- redis.Put(jy.PowerCacheDb, mon_free, 1, 60*60*24*31)
|
|
|
- } else {
|
|
|
- redis.Incr(jy.PowerCacheDb, mon_free)
|
|
|
- }
|
|
|
+ //中台消费记录
|
|
|
+ rb, err := this.UseBalance()
|
|
|
+ if err != nil || (rb != nil && qutil.IntAll(rb["code"]) == 0) {
|
|
|
+ m = fmt.Sprintf("消费记录保存异常:%s", qutil.ObjToString(rb["message"]))
|
|
|
}
|
|
|
}
|
|
|
} else {
|
|
@@ -122,17 +119,28 @@ func (this *UseBalanceStruct) fileConsume() (r map[string]interface{}, m string,
|
|
|
}
|
|
|
} else {
|
|
|
//判断免费用户是否有留资下载权限
|
|
|
- if _, _, freeFileNum := jy.FreeExperience(this.UserId); freeFileNum == 1 {
|
|
|
+ if number > 0 {
|
|
|
if this.Remarks["infoType"] != nil && this.Remarks["infoType"].(string) == "S" {
|
|
|
r = SupplyInfoFile(_fileName, _id)
|
|
|
} else {
|
|
|
r = fileAttachRpc(_fileName, _id)
|
|
|
}
|
|
|
- //免费用户下载后取消下载权限
|
|
|
- redis.PutKV(fmt.Sprintf(jy.PowerCacheFileKey, this.UserId), -1)
|
|
|
+ if r["downUrl"] != nil {
|
|
|
+ this.Remarks["downUrl"] = r["downUrl"]
|
|
|
+ this.Remarks["size"] = r["size"]
|
|
|
+ if this.saveJyConsumePackList() {
|
|
|
+ //中台消费记录
|
|
|
+ rb, err := this.UseBalance()
|
|
|
+ if err != nil || (rb != nil && qutil.IntAll(rb["code"]) == 0) {
|
|
|
+ m = fmt.Sprintf("消费记录保存异常:%s", qutil.ObjToString(rb["message"]))
|
|
|
+ }
|
|
|
+ }
|
|
|
+ } else {
|
|
|
+ m = "获取附件异常"
|
|
|
+ }
|
|
|
} else {
|
|
|
c = -1
|
|
|
- m = "该用户没有下载权限"
|
|
|
+ m = "该用户下载权限当前月已用完"
|
|
|
}
|
|
|
}
|
|
|
return
|