2023-01-18 09:03:15 +00:00
|
|
|
|
package logic
|
|
|
|
|
|
|
|
|
|
import (
|
2023-03-03 08:18:00 +00:00
|
|
|
|
"context"
|
|
|
|
|
"errors"
|
|
|
|
|
|
2023-02-06 01:33:09 +00:00
|
|
|
|
"github.com/fonchain/fonchain-artistinfo/cmd/internal/dao"
|
2023-03-03 08:18:00 +00:00
|
|
|
|
"github.com/fonchain/fonchain-artistinfo/cmd/model"
|
|
|
|
|
"github.com/fonchain/fonchain-artistinfo/pb/artist"
|
2023-02-06 01:33:09 +00:00
|
|
|
|
"github.com/fonchain/fonchain-artistinfo/pb/contract"
|
2023-03-03 08:18:00 +00:00
|
|
|
|
db "github.com/fonchain/fonchain-artistinfo/pkg/db"
|
|
|
|
|
"github.com/fonchain/fonchain-artistinfo/pkg/m"
|
|
|
|
|
"github.com/fonchain/fonchain-artistinfo/pkg/service"
|
|
|
|
|
uuid "github.com/satori/go.uuid"
|
|
|
|
|
"go.uber.org/zap"
|
|
|
|
|
"gorm.io/gorm"
|
2023-01-18 09:03:15 +00:00
|
|
|
|
)
|
|
|
|
|
|
|
|
|
|
type IContract interface {
|
2023-03-03 08:18:00 +00:00
|
|
|
|
CreateContract(req *contract.CreateContractRequest) (rep *contract.CreateContractRespond, err error)
|
2023-01-18 09:03:15 +00:00
|
|
|
|
FinishContract(req *contract.FinishContractRequest) (rep *contract.FinishContractRespond, err error)
|
|
|
|
|
ContractList(req *contract.ContractListRequest) (rep *contract.ContractListRespond, err error)
|
|
|
|
|
ContractTxList(req *contract.ContractTxListRequest) (rep *contract.ContractTxListRespond, err error)
|
|
|
|
|
UpdateContract(req *contract.UpdateContractRequest) (rep *contract.UpdateContractRespond, err error)
|
|
|
|
|
UpdateContractTx(req *contract.UpdateContractTxRequest) (rep *contract.UpdateContractTxRespond, err error)
|
|
|
|
|
GetContract(req *contract.GetContractRequest) (rep *contract.ContractData, err error)
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
func NewContract() IContract {
|
|
|
|
|
return &Contract{}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
type Contract struct {
|
|
|
|
|
}
|
|
|
|
|
|
2023-03-03 08:18:00 +00:00
|
|
|
|
func (a *Contract) CreateContract(req *contract.CreateContractRequest) (rep *contract.CreateContractRespond, err error) {
|
|
|
|
|
rep = &contract.CreateContractRespond{}
|
|
|
|
|
//查看画家是否存在
|
|
|
|
|
if _, err := service.GrpcArtistImpl.ArtistInfo(context.Background(), &artist.ArtistInfoRequest{Uid: req.ArtistUid}); err != nil {
|
|
|
|
|
zap.L().Error("update airDrop err", zap.Error(err))
|
|
|
|
|
return rep, errors.New(m.ERROR_UPDATE + err.Error())
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
//遇到错误数据库回滚
|
|
|
|
|
tx := db.DB.Begin()
|
|
|
|
|
|
|
|
|
|
switch req.Type {
|
|
|
|
|
//1 画家合同(不涉及画家的画作)
|
|
|
|
|
case 1:
|
|
|
|
|
|
|
|
|
|
//查看画家合同是否已经存在,不存在继续
|
|
|
|
|
if err = dao.GetMgmtContractByArtistUid(req.ArtistUid, req.Type); err == gorm.ErrRecordNotFound {
|
|
|
|
|
var uid uuid.UUID
|
|
|
|
|
if uid, err = uuid.NewV4(); err != nil {
|
|
|
|
|
err = errors.New(m.ERROR_UID)
|
|
|
|
|
return
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
//创建画家合同
|
|
|
|
|
contract := &model.Contract{
|
|
|
|
|
Uid: uid.String(),
|
|
|
|
|
ArtistUid: req.ArtistUid,
|
|
|
|
|
Type: 1,
|
|
|
|
|
State: 1,
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if err = dao.CreateArtistContract(tx, contract); err != nil {
|
|
|
|
|
return
|
|
|
|
|
}
|
|
|
|
|
} else {
|
|
|
|
|
return
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
case 2:
|
|
|
|
|
for _, v := range req.ArtworkUid {
|
|
|
|
|
//查看画作合同是否已经存在,不存在继续,类型2、6
|
|
|
|
|
if err = dao.GetMgmtContractByArtworkUid(v, 2); err == gorm.ErrRecordNotFound {
|
|
|
|
|
if err = dao.GetMgmtContractByArtworkUid(v, 6); err == gorm.ErrRecordNotFound {
|
|
|
|
|
|
|
|
|
|
//创建画家画作合同,类型2
|
|
|
|
|
if err = dao.CreateArtworkContract(tx, v, req.ArtistUid, 2); err != nil {
|
|
|
|
|
tx.Rollback()
|
|
|
|
|
return
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
//创建画家画作合同,类型6
|
|
|
|
|
if err = dao.CreateArtworkContract(tx, v, req.ArtistUid, 6); err != nil {
|
|
|
|
|
tx.Rollback()
|
|
|
|
|
return
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
} else {
|
|
|
|
|
return
|
|
|
|
|
}
|
|
|
|
|
} else {
|
|
|
|
|
return
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
case 3:
|
|
|
|
|
|
|
|
|
|
case 5:
|
|
|
|
|
|
|
|
|
|
default:
|
|
|
|
|
err = errors.New("type值出错!")
|
|
|
|
|
return
|
2023-01-18 09:03:15 +00:00
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
2023-03-03 08:18:00 +00:00
|
|
|
|
tx.Commit()
|
2023-01-18 09:03:15 +00:00
|
|
|
|
return
|
|
|
|
|
}
|
|
|
|
|
|
2023-03-03 08:18:00 +00:00
|
|
|
|
// func (a *Contract) FinishContract(req *contract.FinishContractRequest) (rep *contract.FinishContractRespond, err error) {
|
|
|
|
|
// rep = &contract.FinishContractRespond{}
|
2023-01-18 09:03:15 +00:00
|
|
|
|
|
2023-03-03 08:18:00 +00:00
|
|
|
|
// tx := db.DB.Begin()
|
|
|
|
|
// //更新合同状态并获取合同信息
|
|
|
|
|
// contract, err := dao.FinishContract(tx, req.TransactionId)
|
|
|
|
|
// if err != nil {
|
|
|
|
|
// tx.Rollback()
|
|
|
|
|
// return nil, err
|
|
|
|
|
// }
|
2023-01-18 09:03:15 +00:00
|
|
|
|
|
2023-03-03 08:18:00 +00:00
|
|
|
|
// //查看画作是否已经状态改变,没有则改变 无用
|
|
|
|
|
// if err = dao.UpdateArtworkState(tx, contract.ID); err != nil {
|
|
|
|
|
// tx.Rollback()
|
|
|
|
|
// return
|
|
|
|
|
// }
|
2023-01-18 09:03:15 +00:00
|
|
|
|
|
2023-03-03 08:18:00 +00:00
|
|
|
|
// var tmp struct {
|
|
|
|
|
// Uid int32 `json:"uid"`
|
|
|
|
|
// }
|
|
|
|
|
// tmp.Uid = contract.BatchId
|
|
|
|
|
// tmpByte, _ := json.Marshal(&tmp)
|
2023-01-18 09:03:15 +00:00
|
|
|
|
|
2023-03-03 08:18:00 +00:00
|
|
|
|
// if contract.Type == 4 {
|
|
|
|
|
// _, err = util.Post("https://ms.fontree.cn/mgmt/artworktx/updatebatchtype", string(tmpByte))
|
|
|
|
|
// if err != nil {
|
|
|
|
|
// zap.L().Error("post request err", zap.Error(err))
|
|
|
|
|
// return
|
|
|
|
|
// }
|
|
|
|
|
// }
|
2023-01-18 09:03:15 +00:00
|
|
|
|
|
2023-03-03 08:18:00 +00:00
|
|
|
|
// if contract.Type == 7 {
|
|
|
|
|
// _, err = util.Post("https://ms.fontree.cn/mgmt/artworktx/updatebatchtypecopy", string(tmpByte))
|
|
|
|
|
// if err != nil {
|
|
|
|
|
// zap.L().Error("post request err", zap.Error(err))
|
|
|
|
|
// return
|
|
|
|
|
// }
|
|
|
|
|
// }
|
2023-01-18 09:03:15 +00:00
|
|
|
|
|
2023-03-03 08:18:00 +00:00
|
|
|
|
// tx.Commit()
|
|
|
|
|
// return
|
|
|
|
|
// }
|
2023-01-18 09:03:15 +00:00
|
|
|
|
|
2023-03-03 08:18:00 +00:00
|
|
|
|
// func (a *Contract) ContractList(req *contract.ContractListRequest) (rep *contract.ContractListRespond, err error) {
|
2023-01-18 09:03:15 +00:00
|
|
|
|
|
2023-03-03 08:18:00 +00:00
|
|
|
|
// rep, err = dao.ContractList(req)
|
2023-01-18 09:03:15 +00:00
|
|
|
|
|
2023-03-03 08:18:00 +00:00
|
|
|
|
// return
|
|
|
|
|
// }
|
2023-01-18 09:03:15 +00:00
|
|
|
|
|
2023-03-03 08:18:00 +00:00
|
|
|
|
// func (a *Contract) GetContract(req *contract.GetContractRequest) (rep *contract.ContractData, err error) {
|
2023-01-18 09:03:15 +00:00
|
|
|
|
|
2023-03-03 08:18:00 +00:00
|
|
|
|
// rep, err = dao.GetContract(int32(req.Id))
|
|
|
|
|
|
|
|
|
|
// return
|
|
|
|
|
// }
|
|
|
|
|
// func (a *Contract) ContractTxList(req *contract.ContractTxListRequest) (rep *contract.ContractTxListRespond, err error) {
|
|
|
|
|
|
|
|
|
|
// rep, err = dao.ContractTxList(req)
|
|
|
|
|
|
|
|
|
|
// return
|
|
|
|
|
// }
|
|
|
|
|
|
|
|
|
|
// func (a *Contract) UpdateContract(req *contract.UpdateContractRequest) (rep *contract.UpdateContractRespond, err error) {
|
|
|
|
|
// rep = &contract.UpdateContractRespond{}
|
|
|
|
|
// err = dao.UpdateContract(req)
|
|
|
|
|
|
|
|
|
|
// return
|
|
|
|
|
// }
|
|
|
|
|
|
|
|
|
|
// func (a *Contract) UpdateContractTx(req *contract.UpdateContractTxRequest) (rep *contract.UpdateContractTxRespond, err error) {
|
|
|
|
|
// rep = &contract.UpdateContractTxRespond{}
|
|
|
|
|
// err = dao.UpdateContractTx(req.TransactionId, int32(req.ID))
|
|
|
|
|
|
|
|
|
|
// return
|
|
|
|
|
// }
|