|
@@ -1,15 +1,10 @@
|
|
|
package userlib
|
|
|
|
|
|
import (
|
|
|
- "app.yhyue.com/moapp/jyPoints/rpc/integral"
|
|
|
- "app.yhyue.com/moapp/jyPoints/rpc/integralclient"
|
|
|
"app.yhyue.com/moapp/jy_docs/rpc/userlib/userlib"
|
|
|
"app.yhyue.com/moapp/jy_docs/services/model"
|
|
|
docRpcUtil "app.yhyue.com/moapp/jy_docs/services/util"
|
|
|
- "context"
|
|
|
"errors"
|
|
|
- "github.com/tal-tech/go-zero/core/discov"
|
|
|
- "github.com/tal-tech/go-zero/zrpc"
|
|
|
"gorm.io/gorm"
|
|
|
"log"
|
|
|
"time"
|
|
@@ -132,7 +127,7 @@ func UserDocDownload(userDoc *model.UserDoc, cost int, hosts []string, key strin
|
|
|
}
|
|
|
//先扣除积分
|
|
|
//rpc
|
|
|
- client := zrpc.MustNewClient(zrpc.RpcClientConf{
|
|
|
+ /*client := zrpc.MustNewClient(zrpc.RpcClientConf{
|
|
|
Etcd: discov.EtcdConf{
|
|
|
Hosts: hosts,
|
|
|
Key: key,
|
|
@@ -157,8 +152,8 @@ func UserDocDownload(userDoc *model.UserDoc, cost int, hosts []string, key strin
|
|
|
log.Println("扣除积分失败:", pointsErr)
|
|
|
msg = res.Message
|
|
|
return errors.New(res.Message)
|
|
|
- }
|
|
|
- //查询之前有无收藏记录 有收藏记录类型改为兑换,状态改为未删除、有收藏记录插入一条新纪录
|
|
|
+ }*/
|
|
|
+ //查询之前有无记录 有记录类型更新兑换,状态改为未删除、没有记录插入一条新纪录
|
|
|
userDocCollectionList := []model.UserDoc{}
|
|
|
err = docRpcUtil.GetJyDocsDB().Table("user_doc").Where(" userId=? and docId=? and appId=? ", userDoc.UserId, userDoc.DocId, userDoc.AppId).Find(&userDocCollectionList)
|
|
|
if err.Error != nil {
|
|
@@ -181,7 +176,7 @@ func UserDocDownload(userDoc *model.UserDoc, cost int, hosts []string, key strin
|
|
|
return err.Error
|
|
|
}
|
|
|
//用户收藏、兑换记录表添加记录
|
|
|
- err := docRpcUtil.GetJyDocsDB().Exec("insert into download_collection_record (docId,userId,sourceUserId,category,cost,date) values (?,?,?,?,?,?)", userDoc.DocId, userDoc.UserId, userDoc.DocSourceUserId, model.UserDocCategory_Download, cost, time.Now())
|
|
|
+ err := docRpcUtil.GetJyDocsDB().Exec("insert into download_collection_record (docId,userId,sourceUserId,category,cost,date,appId) values (?,?,?,?,?,?,?)", userDoc.DocId, userDoc.UserId, userDoc.DocSourceUserId, model.UserDocCategory_Download, cost, time.Now(),userDoc.AppId)
|
|
|
if err.Error != nil {
|
|
|
log.Println("兑换操作流水添加失败:", err)
|
|
|
msg = "兑换操作流水添加失败"
|
|
@@ -193,6 +188,8 @@ func UserDocDownload(userDoc *model.UserDoc, cost int, hosts []string, key strin
|
|
|
userDoc.CreateAt = time.Now()
|
|
|
userDoc.UpdateAt = time.Now()
|
|
|
userDoc.DeletedAt = time.Now()
|
|
|
+ userDoc.IsCollection=0
|
|
|
+ userDoc.IsDownload=1
|
|
|
//获取文件基本信息
|
|
|
|
|
|
//查询文档基础信息
|
|
@@ -206,7 +203,6 @@ func UserDocDownload(userDoc *model.UserDoc, cost int, hosts []string, key strin
|
|
|
return errors.New("文档不存在")
|
|
|
}
|
|
|
userDoc.DocSourceUserId = doc.UserId
|
|
|
- userDoc.DocCategory = model.UserDocCategory_Download
|
|
|
userDoc.IsDelete = int(userlib.UserDocStatus_Normal)
|
|
|
userDoc.DocName = doc.DocName
|
|
|
userDoc.DocFileType = doc.DocFileType
|
|
@@ -222,7 +218,7 @@ func UserDocDownload(userDoc *model.UserDoc, cost int, hosts []string, key strin
|
|
|
return err.Error
|
|
|
}
|
|
|
//用户收藏、兑换记录表添加记录
|
|
|
- err := docRpcUtil.GetJyDocsDB().Exec("insert into download_collection_record (docId,userId,sourceUserId,category,cost,date) values (?,?,?,?,?,?)", userDoc.DocId, userDoc.UserId, userDoc.DocSourceUserId, model.UserDocCategory_Download, cost, time.Now())
|
|
|
+ err := docRpcUtil.GetJyDocsDB().Exec("insert into download_collection_record (docId,userId,sourceUserId,category,cost,date,appId) values (?,?,?,?,?,?,?)", userDoc.DocId, userDoc.UserId, userDoc.DocSourceUserId, model.UserDocCategory_Download, cost, time.Now(),userDoc.AppId)
|
|
|
if err.Error != nil {
|
|
|
log.Println("兑换操作流水添加失败:", err)
|
|
|
msg = "兑换操作流水添加失败"
|
|
@@ -291,7 +287,7 @@ func UserDocRestore(userDocId int32,appId int64) (bool, string) {
|
|
|
log.Println(docData.UserId)
|
|
|
log.Println(docData.DocId)
|
|
|
//删除记录新增
|
|
|
- err = docRpcUtil.GetJyDocsDB().Exec("insert into del_record (docId, userId, date, operate, appId) values (?,?,?,?,?)", docData.DocId,docData.UserId, time.Now(), 1, appId).Error
|
|
|
+ err = docRpcUtil.GetJyDocsDB().Exec("insert into del_record (docId, userId, date, operate, appId) values (?,?,?,?,?)", docData.DocId,docData.UserId, time.Now(), 2, appId).Error
|
|
|
if err != nil {
|
|
|
tx.Rollback()
|
|
|
msg = "删除记录新增失败"
|
|
@@ -310,13 +306,26 @@ func UserDocPermanentDelete(userDocId int32,appId int64) (bool, string) {
|
|
|
msg := "永久删除成功"
|
|
|
err := docRpcUtil.GetJyDocsDB().Transaction(func(tx *gorm.DB) error {
|
|
|
//逻辑删除
|
|
|
- err := docRpcUtil.GetJyDocsDB().Exec("UPDATE user_doc SET isDelete = ? WHERE id = ?", model.UserDocStatus_PermanentlyDelete, userDocId).Error
|
|
|
+ err := docRpcUtil.GetJyDocsDB().Exec("UPDATE user_doc SET isDelete = ? ,isDownload=0 WHERE id = ?", model.UserDocStatus_PermanentlyDelete, userDocId).Error
|
|
|
if err != nil {
|
|
|
msg = "永久删除失败"
|
|
|
log.Println("永久删除失败:", err)
|
|
|
tx.Rollback()
|
|
|
return err
|
|
|
}
|
|
|
+ docData := model.UserDoc{}
|
|
|
+ //查询用户文档详情
|
|
|
+ docRpcUtil.GetJyDocsDB().Select("userId,docId").First(&docData, userDocId)
|
|
|
+ log.Println(docData.UserId)
|
|
|
+ log.Println(docData.DocId)
|
|
|
+ //删除记录新增
|
|
|
+ err = docRpcUtil.GetJyDocsDB().Exec("insert into del_record (docId, userId, date, operate, appId) values (?,?,?,?,?)", docData.DocId,docData.UserId, time.Now(),4, appId).Error
|
|
|
+ if err != nil {
|
|
|
+ tx.Rollback()
|
|
|
+ msg = "删除记录新增失败"
|
|
|
+ log.Println("删除记录新增失败:", err)
|
|
|
+ return err
|
|
|
+ }
|
|
|
return nil
|
|
|
})
|
|
|
if err != nil {
|