|
@@ -4,6 +4,7 @@ import (
|
|
"app.yhyue.com/moapp/jybase/go-xweb/httpsession"
|
|
"app.yhyue.com/moapp/jybase/go-xweb/httpsession"
|
|
"encoding/json"
|
|
"encoding/json"
|
|
"fmt"
|
|
"fmt"
|
|
|
|
+ "github.com/gogf/gf/v2/util/gconv"
|
|
"jy/src/jfw/modules/subscribepay/src/config"
|
|
"jy/src/jfw/modules/subscribepay/src/config"
|
|
"jy/src/jfw/modules/subscribepay/src/util"
|
|
"jy/src/jfw/modules/subscribepay/src/util"
|
|
"log"
|
|
"log"
|
|
@@ -13,7 +14,6 @@ import (
|
|
. "app.yhyue.com/moapp/jybase/date"
|
|
. "app.yhyue.com/moapp/jybase/date"
|
|
"app.yhyue.com/moapp/jybase/encrypt"
|
|
"app.yhyue.com/moapp/jybase/encrypt"
|
|
. "app.yhyue.com/moapp/jybase/mongodb"
|
|
. "app.yhyue.com/moapp/jybase/mongodb"
|
|
- "app.yhyue.com/moapp/jybase/redis"
|
|
|
|
"app.yhyue.com/moapp/jypkg/common/src/qfw/util/jy"
|
|
"app.yhyue.com/moapp/jypkg/common/src/qfw/util/jy"
|
|
)
|
|
)
|
|
|
|
|
|
@@ -26,20 +26,56 @@ func (this *UseBalanceStruct) defaultConsume() (r map[string]interface{}, m stri
|
|
return
|
|
return
|
|
}
|
|
}
|
|
|
|
|
|
-//附件下载消费 fui:免费赠送已使用次数;pui:付费权限已使用次数
|
|
|
|
|
|
+// 附件下载消费 fui:免费赠送已使用次数;pui:付费权限已使用次数
|
|
func (this *UseBalanceStruct) fileConsume() (r map[string]interface{}, m string, c int) {
|
|
func (this *UseBalanceStruct) fileConsume() (r map[string]interface{}, m string, c int) {
|
|
_fileName := this.Remarks["fileName"].(string)
|
|
_fileName := this.Remarks["fileName"].(string)
|
|
_id := this.Remarks["id"].(string)
|
|
_id := this.Remarks["id"].(string)
|
|
log.Println("附件下载包。。。。。")
|
|
log.Println("附件下载包。。。。。")
|
|
BaseMsg := jy.GetBigVipUserBaseMsg(this.Session, *config.Middleground)
|
|
BaseMsg := jy.GetBigVipUserBaseMsg(this.Session, *config.Middleground)
|
|
log.Println("---:", this.Remarks)
|
|
log.Println("---:", this.Remarks)
|
|
|
|
+ //获取余额数量
|
|
|
|
+ dbs := &FindBalanceStruct{
|
|
|
|
+ AccountId: this.UserId,
|
|
|
|
+ ResourceType: "附件下载包",
|
|
|
|
+ VipState: BaseMsg.VipStatus,
|
|
|
|
+ }
|
|
|
|
+ this.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"])
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+ isExists := false
|
|
|
|
+ id := this.FindJyConsumePackRecord()
|
|
|
|
+ if id != "" && this.Remarks["downUrl"] != nil {
|
|
|
|
+ if util.MQFW.UpdateById(jyCC, id, map[string]interface{}{
|
|
|
|
+ "$set": map[string]interface{}{
|
|
|
|
+ "l_updateDate": time.Now().Unix(),
|
|
|
|
+ },
|
|
|
|
+ }) {
|
|
|
|
+ delete(this.Remarks, "id")
|
|
|
|
+ delete(this.Remarks, "title")
|
|
|
|
+ r = this.Remarks
|
|
|
|
+ r["isExists"] = true
|
|
|
|
+ isExists = true
|
|
|
|
+ }
|
|
|
|
+ }
|
|
if BaseMsg.Status > 0 && BaseMsg.PowerMap[3] {
|
|
if BaseMsg.Status > 0 && BaseMsg.PowerMap[3] {
|
|
if this.Remarks["infoType"] != nil && this.Remarks["infoType"].(string) == "S" {
|
|
if this.Remarks["infoType"] != nil && this.Remarks["infoType"].(string) == "S" {
|
|
r = SupplyInfoFile(_fileName, _id)
|
|
r = SupplyInfoFile(_fileName, _id)
|
|
} else {
|
|
} else {
|
|
r = fileAttachRpc(_fileName, _id)
|
|
r = fileAttachRpc(_fileName, _id)
|
|
}
|
|
}
|
|
- go func(this *UseBalanceStruct, r map[string]interface{}) {
|
|
|
|
|
|
+ /*go func(this *UseBalanceStruct, r map[string]interface{}) {
|
|
data := make(map[string]interface{})
|
|
data := make(map[string]interface{})
|
|
data["p_type"] = "大会员用户附件下载"
|
|
data["p_type"] = "大会员用户附件下载"
|
|
data["p_userid"] = this.UserId
|
|
data["p_userid"] = this.UserId
|
|
@@ -51,38 +87,21 @@ func (this *UseBalanceStruct) fileConsume() (r map[string]interface{}, m string,
|
|
if util.MQFW.Save("filehistroy", data) == "" {
|
|
if util.MQFW.Save("filehistroy", data) == "" {
|
|
log.Println("大会员附件下载-历史记录异常:" + this.UserId)
|
|
log.Println("大会员附件下载-历史记录异常:" + this.UserId)
|
|
}
|
|
}
|
|
- }(this, r)
|
|
|
|
- } else if BaseMsg.VipStatus > 0 {
|
|
|
|
- isExists := false
|
|
|
|
- //查询当月附件下载历史记录-如是已下载过的附件不再扣除次数
|
|
|
|
- id := this.FindJyConsumePackRecord()
|
|
|
|
- if id != "" && this.Remarks["downUrl"] != nil {
|
|
|
|
- if util.MQFW.UpdateById(jyCC, id, map[string]interface{}{
|
|
|
|
- "$set": map[string]interface{}{
|
|
|
|
- "l_updateDate": time.Now().Unix(),
|
|
|
|
- },
|
|
|
|
- }) {
|
|
|
|
- delete(this.Remarks, "id")
|
|
|
|
- delete(this.Remarks, "title")
|
|
|
|
- r = this.Remarks
|
|
|
|
- r["isExists"] = true
|
|
|
|
- isExists = true
|
|
|
|
- }
|
|
|
|
|
|
+ }(this, r)*/
|
|
|
|
+ if r["downUrl"] != nil {
|
|
|
|
+ this.Remarks["downUrl"] = r["downUrl"]
|
|
|
|
+ this.Remarks["size"] = r["size"]
|
|
}
|
|
}
|
|
|
|
+ if !isExists {
|
|
|
|
+ this.saveJyConsumePackList()
|
|
|
|
+ }
|
|
|
|
+ } else {
|
|
|
|
+ //查询当月附件下载历史记录-如是已下载过的附件不再扣除次数
|
|
// log.Println(this.Remarks, "++++++", this.AccountId, id, "-------------", isExists)
|
|
// log.Println(this.Remarks, "++++++", this.AccountId, id, "-------------", isExists)
|
|
//当月未有消费记录
|
|
//当月未有消费记录
|
|
if !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" {
|
|
if this.Remarks["infoType"] != nil && this.Remarks["infoType"].(string) == "S" {
|
|
r = SupplyInfoFile(_fileName, _id)
|
|
r = SupplyInfoFile(_fileName, _id)
|
|
} else {
|
|
} else {
|
|
@@ -92,24 +111,10 @@ func (this *UseBalanceStruct) fileConsume() (r map[string]interface{}, m string,
|
|
this.Remarks["downUrl"] = r["downUrl"]
|
|
this.Remarks["downUrl"] = r["downUrl"]
|
|
this.Remarks["size"] = r["size"]
|
|
this.Remarks["size"] = r["size"]
|
|
if this.saveJyConsumePackList() {
|
|
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 {
|
|
} else {
|
|
@@ -117,22 +122,8 @@ func (this *UseBalanceStruct) fileConsume() (r map[string]interface{}, m string,
|
|
}
|
|
}
|
|
} else {
|
|
} else {
|
|
c = -1
|
|
c = -1
|
|
- m = "该用户下载权限当前月已用完"
|
|
|
|
- }
|
|
|
|
- }
|
|
|
|
- } else {
|
|
|
|
- //判断免费用户是否有留资下载权限
|
|
|
|
- if _, _, freeFileNum := jy.FreeExperience(this.UserId); freeFileNum == 1 {
|
|
|
|
- if this.Remarks["infoType"] != nil && this.Remarks["infoType"].(string) == "S" {
|
|
|
|
- r = SupplyInfoFile(_fileName, _id)
|
|
|
|
- } else {
|
|
|
|
- r = fileAttachRpc(_fileName, _id)
|
|
|
|
|
|
+ m = "该用户下载权限已用完"
|
|
}
|
|
}
|
|
- //免费用户下载后取消下载权限
|
|
|
|
- redis.PutKV(fmt.Sprintf(jy.PowerCacheFileKey, this.UserId), -1)
|
|
|
|
- } else {
|
|
|
|
- c = -1
|
|
|
|
- m = "该用户没有下载权限"
|
|
|
|
}
|
|
}
|
|
}
|
|
}
|
|
return
|
|
return
|
|
@@ -140,7 +131,7 @@ func (this *UseBalanceStruct) fileConsume() (r map[string]interface{}, m string,
|
|
|
|
|
|
var jyCC = "jy_consumepack"
|
|
var jyCC = "jy_consumepack"
|
|
|
|
|
|
-//查询jy 消费日志记录
|
|
|
|
|
|
+// 查询jy 消费日志记录
|
|
func (this *UseBalanceStruct) FindJyConsumePackRecord() string {
|
|
func (this *UseBalanceStruct) FindJyConsumePackRecord() string {
|
|
query := map[string]interface{}{
|
|
query := map[string]interface{}{
|
|
"s_id": this.Remarks["id"].(string),
|
|
"s_id": this.Remarks["id"].(string),
|
|
@@ -161,7 +152,7 @@ func (this *UseBalanceStruct) FindJyConsumePackRecord() string {
|
|
return BsonIdToSId((*res)["_id"])
|
|
return BsonIdToSId((*res)["_id"])
|
|
}
|
|
}
|
|
|
|
|
|
-//保存日志
|
|
|
|
|
|
+// 保存日志
|
|
func (this *UseBalanceStruct) saveJyConsumePackList() (b bool) {
|
|
func (this *UseBalanceStruct) saveJyConsumePackList() (b bool) {
|
|
saveMap := map[string]interface{}{
|
|
saveMap := map[string]interface{}{
|
|
"s_id": this.Remarks["id"],
|
|
"s_id": this.Remarks["id"],
|
|
@@ -184,7 +175,7 @@ func (this *UseBalanceStruct) saveJyConsumePackList() (b bool) {
|
|
return
|
|
return
|
|
}
|
|
}
|
|
|
|
|
|
-//调rpc 获取附件信息
|
|
|
|
|
|
+// 调rpc 获取附件信息
|
|
func fileAttachRpc(fileName, id string) (r map[string]interface{}) {
|
|
func fileAttachRpc(fileName, id string) (r map[string]interface{}) {
|
|
r = make(map[string]interface{})
|
|
r = make(map[string]interface{})
|
|
// 调用rpc 获取附件信息
|
|
// 调用rpc 获取附件信息
|
|
@@ -210,7 +201,7 @@ func fileAttachRpc(fileName, id string) (r map[string]interface{}) {
|
|
return
|
|
return
|
|
}
|
|
}
|
|
|
|
|
|
-//供应信息附件
|
|
|
|
|
|
+// 供应信息附件
|
|
func SupplyInfoFile(fileName, msgId string) (r map[string]interface{}) {
|
|
func SupplyInfoFile(fileName, msgId string) (r map[string]interface{}) {
|
|
//查数据
|
|
//查数据
|
|
data := util.InfoMysql.FindOne("supply_info", map[string]interface{}{"id": msgId}, "", "")
|
|
data := util.InfoMysql.FindOne("supply_info", map[string]interface{}{"id": msgId}, "", "")
|
|
@@ -236,7 +227,14 @@ func SupplyInfoFile(fileName, msgId string) (r map[string]interface{}) {
|
|
return
|
|
return
|
|
}
|
|
}
|
|
|
|
|
|
-//消费
|
|
|
|
|
|
+// 兑换作废
|
|
|
|
+func JyexchangeCance(userId, product, platform, queryTime string, pageSize, pageNum int) (list []map[string]interface{}, total int, err error) {
|
|
|
|
+ RStruct := InitFindRecord(userId, product, queryTime, platform, pageSize, pageNum, 2)
|
|
|
|
+ list, total = RStruct.DefaultData()
|
|
|
|
+ return list, total, nil
|
|
|
|
+}
|
|
|
|
+
|
|
|
|
+// 消费
|
|
func JyConsumePack(userId, product, platform string, remarks map[string]interface{}, session *httpsession.Session) (r map[string]interface{}, m string, c int) {
|
|
func JyConsumePack(userId, product, platform string, remarks map[string]interface{}, session *httpsession.Session) (r map[string]interface{}, m string, c int) {
|
|
CStruct := InitUseBalance(userId, product, product, "", "", nil, remarks, 1, platform, session)
|
|
CStruct := InitUseBalance(userId, product, product, "", "", nil, remarks, 1, platform, session)
|
|
switch product {
|
|
switch product {
|
|
@@ -248,7 +246,7 @@ func JyConsumePack(userId, product, platform string, remarks map[string]interfac
|
|
return
|
|
return
|
|
}
|
|
}
|
|
|
|
|
|
-//流水
|
|
|
|
|
|
+// 流水
|
|
func JyFindRecordPack(userId, productName, queryTime, platform string, pageSize, pageNum int) (list []map[string]interface{}, total int, err error) {
|
|
func JyFindRecordPack(userId, productName, queryTime, platform string, pageSize, pageNum int) (list []map[string]interface{}, total int, err error) {
|
|
RStruct := InitFindRecord(userId, productName, queryTime, platform, pageSize, pageNum, 0)
|
|
RStruct := InitFindRecord(userId, productName, queryTime, platform, pageSize, pageNum, 0)
|
|
switch productName {
|
|
switch productName {
|
|
@@ -260,7 +258,7 @@ func JyFindRecordPack(userId, productName, queryTime, platform string, pageSize,
|
|
return list, total, nil
|
|
return list, total, nil
|
|
}
|
|
}
|
|
|
|
|
|
-//数据处理-附件下载包
|
|
|
|
|
|
+// 数据处理-附件下载包
|
|
func (this *FindRecordStruct) FindJyConsumePackAllRecord() ([]map[string]interface{}, int) {
|
|
func (this *FindRecordStruct) FindJyConsumePackAllRecord() ([]map[string]interface{}, int) {
|
|
var articleAddMap = map[string]string{
|
|
var articleAddMap = map[string]string{
|
|
"PC": "/article/content/%s.html",
|
|
"PC": "/article/content/%s.html",
|
|
@@ -301,7 +299,7 @@ func (this *FindRecordStruct) FindJyConsumePackAllRecord() ([]map[string]interfa
|
|
return *list, total
|
|
return *list, total
|
|
}
|
|
}
|
|
|
|
|
|
-//数据处理-default
|
|
|
|
|
|
+// 数据处理-default
|
|
func (this *FindRecordStruct) DefaultData() ([]map[string]interface{}, int) {
|
|
func (this *FindRecordStruct) DefaultData() ([]map[string]interface{}, int) {
|
|
returnList, total, err := this.FindRecord()
|
|
returnList, total, err := this.FindRecord()
|
|
if err != nil {
|
|
if err != nil {
|