|
@@ -6,6 +6,7 @@ import (
|
|
|
"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"
|
|
@@ -39,8 +40,9 @@ func UserDocCollect(userDoc *model.UserDoc, cost int) bool {
|
|
|
}
|
|
|
|
|
|
//转存操作
|
|
|
-func UserDocDownload(userDoc *model.UserDoc, cost int,hosts []string,key string) bool {
|
|
|
+func UserDocDownload(userDoc *model.UserDoc, cost int,hosts []string,key string) (bool,string) {
|
|
|
log.Println("UserDocCollect exec ......")
|
|
|
+ msg:="转存成功"
|
|
|
err := docRpcUtil.GetJyDocsDB().Transaction(func(tx *gorm.DB) error {
|
|
|
//用户文库表添加记录
|
|
|
//获取文档有关信息
|
|
@@ -48,11 +50,13 @@ func UserDocDownload(userDoc *model.UserDoc, cost int,hosts []string,key string)
|
|
|
userDocDownloadList := []model.UserDoc{}
|
|
|
err := docRpcUtil.GetJyDocsDB().Table("user_doc").Where(" userId=? and docId=? and docCategory=? and (isDelete=? or isDelete=?)", userDoc.UserId, userDoc.DocId, model.UserDocCategory_Download, model.UserDocStatus_Normal, model.UserDocStatus_LogicDelete).Find(&userDocDownloadList)
|
|
|
if err.Error != nil {
|
|
|
+ log.Println("查询转存记录失败:",err)
|
|
|
+ msg="查询转存记录失败"
|
|
|
return err.Error
|
|
|
}
|
|
|
if len(userDocDownloadList) > 0 {
|
|
|
- return nil
|
|
|
- }
|
|
|
+ msg="之前已经下载不能再次下载"
|
|
|
+ return errors.New("之前已经下载不能再次下载")}
|
|
|
//先扣除积分
|
|
|
//rpc
|
|
|
client := zrpc.MustNewClient(zrpc.RpcClientConf{
|
|
@@ -71,30 +75,43 @@ func UserDocDownload(userDoc *model.UserDoc, cost int,hosts []string,key string)
|
|
|
res, pointsErr := integralLib.IntegralConsume(context.Background(), req)
|
|
|
log.Println("err ", pointsErr)
|
|
|
log.Println("req ", res)
|
|
|
- if (pointsErr != nil || res.Code == 0) {
|
|
|
+ if (pointsErr != nil ) {
|
|
|
+ log.Println("扣除积分失败:",pointsErr)
|
|
|
+ msg="扣除积分失败"
|
|
|
return pointsErr
|
|
|
}
|
|
|
-
|
|
|
+ if (res.Code == 0) {
|
|
|
+ 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 docCategory=? and (isDelete=? or isDelete=?)", userDoc.UserId, userDoc.DocId, model.UserDocCategory_Collect, model.UserDocStatus_Normal, model.UserDocStatus_LogicDelete).Find(&userDocCollectionList)
|
|
|
if err.Error != nil {
|
|
|
+ log.Println("收藏记录查询:",err)
|
|
|
+ msg="收藏记录查询"
|
|
|
return err.Error
|
|
|
}
|
|
|
if len(userDocCollectionList) > 0 {
|
|
|
//修改收藏为下载
|
|
|
if err := tx.Exec("update user_doc set docCategory=? , isDelete=? ,update_at=? where id =?", model.UserDocCategory_Download, model.UserDocStatus_Normal, time.Now(), userDocCollectionList[0].ID).Error; err != nil {
|
|
|
+ log.Println("收藏记录更改为转存记录失败:",err)
|
|
|
+ msg="收藏记录更改为转存记录失败"
|
|
|
+ tx.Rollback()
|
|
|
return err
|
|
|
}
|
|
|
if err.Error != nil {
|
|
|
- log.Println("userDocCollect error:", err)
|
|
|
+ log.Println("转存操作流水添加失败:", err)
|
|
|
+ msg="收藏记录更改为转存记录失败"
|
|
|
tx.Rollback()
|
|
|
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())
|
|
|
if err.Error != nil {
|
|
|
- log.Println("userDocCollect record insert error:", err)
|
|
|
+ log.Println("转存操作流水添加失败:", err)
|
|
|
+ msg="转存操作流水添加失败"
|
|
|
tx.Rollback()
|
|
|
return err.Error
|
|
|
}
|
|
@@ -103,16 +120,20 @@ func UserDocDownload(userDoc *model.UserDoc, cost int,hosts []string,key string)
|
|
|
userDoc.CreateAt = time.Now()
|
|
|
userDoc.UpdateAt = time.Now()
|
|
|
userDoc.DeletedAt = time.Now()
|
|
|
+ //获取文件基本信息
|
|
|
+
|
|
|
err = docRpcUtil.GetJyDocsDB().Create(userDoc)
|
|
|
if err.Error != nil {
|
|
|
- log.Println("userDocCollect error:", err)
|
|
|
+ log.Println("转存操作添加失败:", err)
|
|
|
+ msg="转存操作添加失败"
|
|
|
tx.Rollback()
|
|
|
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())
|
|
|
if err.Error != nil {
|
|
|
- log.Println("userDocCollect record insert error:", err)
|
|
|
+ log.Println("转存操作流水添加失败:", err)
|
|
|
+ msg="转存操作流水添加失败"
|
|
|
tx.Rollback()
|
|
|
return err.Error
|
|
|
}
|
|
@@ -120,9 +141,9 @@ func UserDocDownload(userDoc *model.UserDoc, cost int,hosts []string,key string)
|
|
|
return nil
|
|
|
})
|
|
|
if err != nil {
|
|
|
- return false
|
|
|
+ return false,msg
|
|
|
}
|
|
|
- return true
|
|
|
+ return true,msg
|
|
|
}
|
|
|
func UserDocDelete(docId string) bool {
|
|
|
err := docRpcUtil.GetJyDocsDB().Transaction(func(tx *gorm.DB) error {
|