|
@@ -2,7 +2,6 @@ package entity
|
|
|
|
|
|
import (
|
|
import (
|
|
"config"
|
|
"config"
|
|
- "encoding/json"
|
|
|
|
"fmt"
|
|
"fmt"
|
|
"log"
|
|
"log"
|
|
qutil "qfw/util"
|
|
qutil "qfw/util"
|
|
@@ -12,79 +11,23 @@ import (
|
|
"util"
|
|
"util"
|
|
)
|
|
)
|
|
|
|
|
|
-//剑鱼数据流量包 消费记录
|
|
|
|
-type baskPackStruct struct {
|
|
|
|
- UserId string //用户身份
|
|
|
|
- Month int //查询月份
|
|
|
|
- Year int //查询年份
|
|
|
|
- PageSize int //每页多少条
|
|
|
|
- PageNo int //当前页
|
|
|
|
- ProductName string //产品名称
|
|
|
|
- State int // 0 查消耗记录 1 查充值记录
|
|
|
|
- Platform string //平台:PC;APP;WX
|
|
|
|
- Remarks map[string]interface{} //备注信息
|
|
|
|
-}
|
|
|
|
-
|
|
|
|
-var JyBaskPack baskPackStruct
|
|
|
|
-
|
|
|
|
-//new
|
|
|
|
-func GetNewJyBaskPack(userId, productName, platform string, month, year, pageSize, pageNo, state int, remarks map[string]interface{}) *baskPackStruct {
|
|
|
|
- if pageSize == 0 {
|
|
|
|
- pageSize = 10
|
|
|
|
- }
|
|
|
|
- if pageNo == 0 {
|
|
|
|
- pageNo = 1
|
|
|
|
- }
|
|
|
|
- if platform == "" {
|
|
|
|
- platform = "PC"
|
|
|
|
- }
|
|
|
|
- return &baskPackStruct{
|
|
|
|
- UserId: userId,
|
|
|
|
- Month: month,
|
|
|
|
- Year: year,
|
|
|
|
- PageSize: pageSize,
|
|
|
|
- PageNo: pageNo,
|
|
|
|
- ProductName: productName,
|
|
|
|
- State: state,
|
|
|
|
- Platform: platform,
|
|
|
|
- Remarks: remarks,
|
|
|
|
- }
|
|
|
|
-}
|
|
|
|
-
|
|
|
|
-//消费
|
|
|
|
-func (this *baskPackStruct) ConsumePack() (r map[string]interface{}, m string) {
|
|
|
|
- switch this.ProductName {
|
|
|
|
- case "附件下载包":
|
|
|
|
- r, m = this.fileConsume()
|
|
|
|
- default:
|
|
|
|
- r, m = this.defaultConsume()
|
|
|
|
- }
|
|
|
|
- return
|
|
|
|
-}
|
|
|
|
-
|
|
|
|
// 默认消费
|
|
// 默认消费
|
|
-func (this *baskPackStruct) defaultConsume() (r map[string]interface{}, m string) {
|
|
|
|
- rb, rm := this.consumePackApi()
|
|
|
|
- if !rb {
|
|
|
|
- m = fmt.Sprintf("消费异常:%s", rm)
|
|
|
|
- }
|
|
|
|
- r = map[string]interface{}{
|
|
|
|
- "success": rb,
|
|
|
|
- "msg": rm,
|
|
|
|
|
|
+func (this *UseBalanceStruct) defaultConsume() (r map[string]interface{}, m string) {
|
|
|
|
+ r, rerr := this.UseBalance()
|
|
|
|
+ if rerr != nil {
|
|
|
|
+ m = fmt.Sprintf("消费异常:%s", rerr.Error())
|
|
}
|
|
}
|
|
return
|
|
return
|
|
}
|
|
}
|
|
|
|
|
|
//附件下载消费 fui:免费赠送已使用次数;pui:付费权限已使用次数
|
|
//附件下载消费 fui:免费赠送已使用次数;pui:付费权限已使用次数
|
|
-func (this *baskPackStruct) fileConsume() (r map[string]interface{}, m string) {
|
|
|
|
|
|
+func (this *UseBalanceStruct) fileConsume() (r map[string]interface{}, m string) {
|
|
_fileName := this.Remarks["fileName"].(string)
|
|
_fileName := this.Remarks["fileName"].(string)
|
|
_id := this.Remarks["id"].(string)
|
|
_id := this.Remarks["id"].(string)
|
|
- // _downUrl := ""
|
|
|
|
- // _size := ""
|
|
|
|
BaseMsg := jy.GetBigVipUserBaseMsg(this.UserId, util.Mysql, util.MQFW)
|
|
BaseMsg := jy.GetBigVipUserBaseMsg(this.UserId, util.Mysql, util.MQFW)
|
|
if BaseMsg.Status > 0 && BaseMsg.PowerMap[3] {
|
|
if BaseMsg.Status > 0 && BaseMsg.PowerMap[3] {
|
|
r = fileAttachRpc(_fileName, _id)
|
|
r = fileAttachRpc(_fileName, _id)
|
|
- go func(this *baskPackStruct, 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
|
|
@@ -98,31 +41,13 @@ func (this *baskPackStruct) fileConsume() (r map[string]interface{}, m string) {
|
|
}
|
|
}
|
|
}(this, r)
|
|
}(this, r)
|
|
} else if BaseMsg.VipStatus > 0 {
|
|
} else if BaseMsg.VipStatus > 0 {
|
|
- //查询当月附件下载历史记录-如是已下载过的附件不再扣除次数
|
|
|
|
- this.Month = jy.GetMonth(time.Now().Month().String())
|
|
|
|
- this.Year = time.Now().Year()
|
|
|
|
- _, retList, _ := this.perPackRechargeApi()
|
|
|
|
isExists := false
|
|
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 {
|
|
|
|
- r = remarks
|
|
|
|
- isExists = true
|
|
|
|
- break
|
|
|
|
- }
|
|
|
|
|
|
+ //查询当月附件下载历史记录-如是已下载过的附件不再扣除次数
|
|
|
|
+ if this.FindJyConsumePackRecord() && this.Remarks["downUrl"] != nil {
|
|
|
|
+ delete(this.Remarks, "id")
|
|
|
|
+ delete(this.Remarks, "title")
|
|
|
|
+ r = this.Remarks
|
|
|
|
+ isExists = true
|
|
}
|
|
}
|
|
//当月未有消费记录
|
|
//当月未有消费记录
|
|
if !isExists {
|
|
if !isExists {
|
|
@@ -138,21 +63,23 @@ func (this *baskPackStruct) fileConsume() (r map[string]interface{}, m string) {
|
|
}
|
|
}
|
|
if isCanConsume_f || isCanConsume_p {
|
|
if isCanConsume_f || isCanConsume_p {
|
|
r = fileAttachRpc(_fileName, _id)
|
|
r = fileAttachRpc(_fileName, _id)
|
|
- if len(r) > 0 {
|
|
|
|
- rb, rm := this.consumePackApi()
|
|
|
|
- if !rb {
|
|
|
|
- m = fmt.Sprintf("消费异常:%s", rm)
|
|
|
|
- } else {
|
|
|
|
- r = this.Remarks
|
|
|
|
- if isCanConsume_f {
|
|
|
|
- //下载后自增一次 免费权限默认存储31d
|
|
|
|
- if fui == 0 {
|
|
|
|
- redis.Put(jy.PowerCacheDb, mon, 1, 60*60*24*31)
|
|
|
|
- } else {
|
|
|
|
- redis.Incr(jy.PowerCacheDb, mon)
|
|
|
|
- }
|
|
|
|
|
|
+ if r["downurl"] != nil {
|
|
|
|
+ this.Remarks["downUrl"] = r["downurl"]
|
|
|
|
+ this.Remarks["size"] = r["size"]
|
|
|
|
+ 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 if isCanConsume_f { //下载后自增一次 免费权限默认存储31d
|
|
|
|
+ if fui == 0 {
|
|
|
|
+ redis.Put(jy.PowerCacheDb, mon, 1, 60*60*24*31)
|
|
|
|
+ } else {
|
|
|
|
+ redis.Incr(jy.PowerCacheDb, mon)
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
+ go this.saveJyConsumePackList(qutil.If(isCanConsume_p, true, false).(bool))
|
|
} else {
|
|
} else {
|
|
m = "获取附件异常"
|
|
m = "获取附件异常"
|
|
}
|
|
}
|
|
@@ -172,11 +99,53 @@ func (this *baskPackStruct) fileConsume() (r map[string]interface{}, m string) {
|
|
return
|
|
return
|
|
}
|
|
}
|
|
|
|
|
|
-//
|
|
|
|
|
|
+var jyCC = "jy_consumepack"
|
|
|
|
+
|
|
|
|
+//查询jy 消费日志记录
|
|
|
|
+func (this *UseBalanceStruct) FindJyConsumePackRecord() bool {
|
|
|
|
+ query := map[string]interface{}{
|
|
|
|
+ "s_id": this.Remarks["id"],
|
|
|
|
+ "s_userId": this.UserId,
|
|
|
|
+ "s_product": this.Name,
|
|
|
|
+ "s_month": time.Now().Format("2006-01"),
|
|
|
|
+ }
|
|
|
|
+ res, ok := util.MQFW.FindOne(jyCC, query)
|
|
|
|
+ if ok && res != nil {
|
|
|
|
+ if (*res)["s_downUrl"] != nil {
|
|
|
|
+ this.Remarks["downUrl"] = (*res)["s_downUrl"]
|
|
|
|
+ this.Remarks["size"] = (*res)["s_fileSize"]
|
|
|
|
+ }
|
|
|
|
+ } else {
|
|
|
|
+ log.Println("查询附件下载日志异常:", this.UserId)
|
|
|
|
+ }
|
|
|
|
+ return ok
|
|
|
|
+}
|
|
|
|
+
|
|
|
|
+//保存日志
|
|
|
|
+func (this *UseBalanceStruct) saveJyConsumePackList(b bool) {
|
|
|
|
+ saveMap := map[string]interface{}{
|
|
|
|
+ "s_id": this.Remarks["id"],
|
|
|
|
+ "s_userId": this.UserId,
|
|
|
|
+ "s_product": this.Name,
|
|
|
|
+ "l_date": time.Now().Unix(),
|
|
|
|
+ "s_month": time.Now().Format("2006-01"),
|
|
|
|
+ "s_fileName": this.Remarks["fileName"],
|
|
|
|
+ "s_downUrl": this.Remarks["downUrl"],
|
|
|
|
+ "s_fileSize": this.Remarks["size"],
|
|
|
|
+ "s_title": this.Remarks["title"],
|
|
|
|
+ "b_isPay": b,
|
|
|
|
+ "s_platform": this.Platform,
|
|
|
|
+ }
|
|
|
|
+ if util.MQFW.Save(jyCC, saveMap) == "" {
|
|
|
|
+ log.Println("保存附件下载日志异常:", this.UserId)
|
|
|
|
+ }
|
|
|
|
+}
|
|
|
|
+
|
|
|
|
+//调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 获取附件信息
|
|
- req := util.JyFileRequest{qutil.DecodeArticleId2ByCheck(id)[0]}
|
|
|
|
|
|
+ req := util.JyFileRequest{id}
|
|
rep, err := util.Attachment(&req)
|
|
rep, err := util.Attachment(&req)
|
|
if err != nil {
|
|
if err != nil {
|
|
log.Println("attachment rpc调用失败")
|
|
log.Println("attachment rpc调用失败")
|
|
@@ -186,7 +155,7 @@ func fileAttachRpc(fileName, id string) (r map[string]interface{}) {
|
|
for _, v := range rep.Rep {
|
|
for _, v := range rep.Rep {
|
|
if qutil.ObjToString(v["filename"]) == fileName {
|
|
if qutil.ObjToString(v["filename"]) == fileName {
|
|
r = map[string]interface{}{
|
|
r = map[string]interface{}{
|
|
- "downurl": qutil.ObjToString(v["downUrl"]),
|
|
|
|
|
|
+ "downurl": qutil.ObjToString(v["downurl"]),
|
|
"filename": qutil.ObjToString(v["filename"]),
|
|
"filename": qutil.ObjToString(v["filename"]),
|
|
"size": qutil.ObjToString(v["size"]),
|
|
"size": qutil.ObjToString(v["size"]),
|
|
}
|
|
}
|
|
@@ -198,45 +167,76 @@ func fileAttachRpc(fileName, id string) (r map[string]interface{}) {
|
|
return
|
|
return
|
|
}
|
|
}
|
|
|
|
|
|
-//记录
|
|
|
|
-func (this *baskPackStruct) GetBaseRecordList() (list []map[string]interface{}, total int, err error) {
|
|
|
|
- retTotal, retList, _ := this.perPackRechargeApi()
|
|
|
|
- log.Println(retTotal, retList)
|
|
|
|
- switch this.ProductName {
|
|
|
|
|
|
+//消费
|
|
|
|
+func JyConsumePack(userId, product, platform string, remarks map[string]interface{}) (r map[string]interface{}, m string) {
|
|
|
|
+ CStruct := InitUseBalance(userId, product, product, "", "", nil, remarks, 1, platform)
|
|
|
|
+ switch product {
|
|
case "附件下载包":
|
|
case "附件下载包":
|
|
- list = this.FileUploadData(retList)
|
|
|
|
|
|
+ r, m = CStruct.fileConsume()
|
|
default:
|
|
default:
|
|
- list = this.DefaultData(retList)
|
|
|
|
|
|
+ r, m = CStruct.defaultConsume()
|
|
}
|
|
}
|
|
return
|
|
return
|
|
}
|
|
}
|
|
|
|
|
|
|
|
+//流水
|
|
|
|
+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)
|
|
|
|
+ switch productName {
|
|
|
|
+ case "附件下载包":
|
|
|
|
+ list, total = RStruct.FindJyConsumePackAllRecord()
|
|
|
|
+ default:
|
|
|
|
+ list, total = RStruct.DefaultData()
|
|
|
|
+ }
|
|
|
|
+ return list, total, nil
|
|
|
|
+}
|
|
|
|
+
|
|
//数据处理-附件下载包
|
|
//数据处理-附件下载包
|
|
-func (this *baskPackStruct) FileUploadData(retList []interface{}) []map[string]interface{} {
|
|
|
|
|
|
+func (this *FindRecordStruct) FindJyConsumePackAllRecord() ([]map[string]interface{}, int) {
|
|
var articleAddMap = map[string]string{
|
|
var articleAddMap = map[string]string{
|
|
"PC": "/article/content/%s",
|
|
"PC": "/article/content/%s",
|
|
"WX": "/article/content/%s",
|
|
"WX": "/article/content/%s",
|
|
"APP": "/jyapp/article/content/%s",
|
|
"APP": "/jyapp/article/content/%s",
|
|
}
|
|
}
|
|
- returnMapArr := make([]map[string]interface{}, 0, len(retList))
|
|
|
|
- for _, item := range retList {
|
|
|
|
- itemData := qutil.ObjToMap(item)
|
|
|
|
- if itemData == nil || len(*itemData) == 0 {
|
|
|
|
- continue
|
|
|
|
- }
|
|
|
|
- jyid := qutil.ObjToString((*itemData)["jyid"])
|
|
|
|
- parsMap := map[string]interface{}{
|
|
|
|
- "resourceType": (*itemData)["resourceType"],
|
|
|
|
- "number": (*itemData)["number"],
|
|
|
|
- "articleUrl": fmt.Sprintf(articleAddMap[this.Platform], qutil.EncodeArticleId2ByCheck(jyid)),
|
|
|
|
|
|
+ query := map[string]interface{}{
|
|
|
|
+ "s_userId": this.UserId,
|
|
|
|
+ "s_product": this.Name,
|
|
|
|
+ "s_month": this.QueryTime,
|
|
|
|
+ }
|
|
|
|
+ total := util.MQFW.Count(jyCC, query)
|
|
|
|
+ list, ok := util.MQFW.Find(jyCC, query, `{"l_date":-1}`, `{"s_id":1,"s_fileName":1,"s_downUrl":1,"l_date":1,"s_title":1}`, false, (this.Page-1)*this.PageSize, this.PageSize)
|
|
|
|
+ if ok && list != nil {
|
|
|
|
+ if len(*list) >= 1 {
|
|
|
|
+ for _, item := range *list {
|
|
|
|
+ itemData := qutil.ObjToMap(item)
|
|
|
|
+ if itemData == nil || len(*itemData) == 0 {
|
|
|
|
+ continue
|
|
|
|
+ }
|
|
|
|
+ l_date := (*itemData)["l_date"]
|
|
|
|
+ (*itemData)["l_date"] = qutil.FormatDateWithObj(&l_date, "2006/01/02")
|
|
|
|
+ (*itemData)["articleUrl"] = fmt.Sprintf(articleAddMap[this.Platform], qutil.EncodeArticleId2ByCheck((*itemData)["s_id"].(string)))
|
|
|
|
+ delete((*itemData), "_id")
|
|
|
|
+ delete((*itemData), "s_id")
|
|
|
|
+ }
|
|
|
|
+ } else {
|
|
|
|
+ log.Println("暂无附件下载记录:", this.UserId)
|
|
}
|
|
}
|
|
- returnMapArr = append(returnMapArr, parsMap)
|
|
|
|
|
|
+ } else {
|
|
|
|
+ log.Println("查询附件下载记录异常:", this.UserId)
|
|
}
|
|
}
|
|
- return returnMapArr
|
|
|
|
|
|
+
|
|
|
|
+ return *list, total
|
|
}
|
|
}
|
|
|
|
|
|
//数据处理-default
|
|
//数据处理-default
|
|
-func (this *baskPackStruct) DefaultData(retList []interface{}) []map[string]interface{} {
|
|
|
|
-
|
|
|
|
- return qutil.ObjArrToMapArr(retList)
|
|
|
|
|
|
+func (this *FindRecordStruct) DefaultData() ([]map[string]interface{}, int) {
|
|
|
|
+ returnList, total, err := this.FindBalance()
|
|
|
|
+ if err != nil {
|
|
|
|
+ log.Println("默认资源包流水异常:", err)
|
|
|
|
+ return nil, 0
|
|
|
|
+ }
|
|
|
|
+ if total == 0 {
|
|
|
|
+ log.Println(fmt.Sprintf("暂无%s资源包流水", this.Name))
|
|
|
|
+ }
|
|
|
|
+ return qutil.ObjArrToMapArr(returnList), total
|
|
}
|
|
}
|