From 2405afd6f76be746a989600dde7faa624f2f797f Mon Sep 17 00:00:00 2001 From: songchuang <192749120@qq.com> Date: Fri, 17 Mar 2023 21:17:15 +0800 Subject: [PATCH] =?UTF-8?q?contract=20=E4=BF=AE=E6=94=B9=E4=BB=A3=E7=A0=81?= =?UTF-8?q?=E6=8F=90=E4=BA=A4?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- cmd/internal/dao/contract.go | 8 +++++--- cmd/internal/logic/contract.go | 8 ++++++++ cmd/model/contract.go | 4 ++-- 3 files changed, 15 insertions(+), 5 deletions(-) diff --git a/cmd/internal/dao/contract.go b/cmd/internal/dao/contract.go index a6871aa..205ba48 100644 --- a/cmd/internal/dao/contract.go +++ b/cmd/internal/dao/contract.go @@ -40,6 +40,7 @@ func GetMgmtContractByArtistUid(artistUid string, contractType int32) (err error } func CreateArtistContract(tx *gorm.DB, contract *model.Contract) (err error) { + fmt.Println("第一处1111222") if err = tx.Create(contract).Error; err != nil { zap.L().Error("create contract err", zap.Error(err)) err = errors.New(m.CREATE_ERROR) @@ -191,6 +192,7 @@ func GetContractInfo(contractUid string) (contractInfo model.Contract, err error } func UpdateContract(tx *gorm.DB, req *contract.SignContractRequest) (err error) { + fmt.Println("第一处1111") if err = tx.Model(&model.Contract{}).Where("uid = ?", req.ContractUid).Updates(model.Contract{ViewUrl: req.ViewPdfUrl, DownloadUrl: req.DownloadUrl, ContractId: req.ContractNo, TransactionId: req.TransactionId, State: 1}).Error; err != nil { zap.L().Error("update contract info err", zap.Error(err)) err = errors.New(m.UPDATE_FAILED) @@ -208,16 +210,16 @@ func UpdateContractTx(tx *gorm.DB, contractUid, transactionId string) (err error return } -func FinishContract(tx *gorm.DB, id string) (contracts *contract.Contracts, err error) { +func FinishContract(tx *gorm.DB, transactionId string) (contracts *contract.Contracts, err error) { var modelContract model.Contract - if err = tx.Where("transaction_id = ?", id).First(&modelContract).Error; err != nil { + if err = tx.Where("transaction_id = ?", transactionId).First(&modelContract).Error; err != nil { zap.L().Error("get contract info err", zap.Error(err)) err = errors.New(m.ERROR_SELECT) return } - if err = db.DB.Model(&modelContract).Update("state", 3).Error; err != nil { + if err = db.DB.Model(&modelContract).Update("state", 2).Error; err != nil { zap.L().Error("update user contract failed", zap.Error(err)) err = errors.New(m.UPDATE_FAILED) return diff --git a/cmd/internal/logic/contract.go b/cmd/internal/logic/contract.go index 84f3c21..7634c7c 100644 --- a/cmd/internal/logic/contract.go +++ b/cmd/internal/logic/contract.go @@ -57,6 +57,7 @@ func (a *Contract) CreateContract(req *contract.CreateContractRequest) (rep *con //查看画家合同是否已经存在,不存在继续 if err = dao.GetMgmtContractByArtistUid(req.ArtistUid, req.Type); err == gorm.ErrRecordNotFound { + fmt.Println("第一处111") var uid uuid.UUID if uid, err = uuid.NewV4(); err != nil { err = errors.New(m.ERROR_UID) @@ -77,6 +78,7 @@ func (a *Contract) CreateContract(req *contract.CreateContractRequest) (rep *con return } } else { + fmt.Println("第一处112") return } @@ -206,9 +208,15 @@ func (a *Contract) ContractList(req *contract.ContractListRequest) (rep *contrac func (a *Contract) SignContract(req *contract.SignContractRequest) (rep *contract.SignContractRespond, err error) { rep = &contract.SignContractRespond{} + fmt.Println("SignContractReq", req) tx := db.DB.Begin() //更新合同状态并获取合同信息 err = dao.UpdateContract(tx, req) + if err != nil { + tx.Rollback() + } + + tx.Commit() return } diff --git a/cmd/model/contract.go b/cmd/model/contract.go index b9cac6e..3cfd999 100644 --- a/cmd/model/contract.go +++ b/cmd/model/contract.go @@ -8,8 +8,8 @@ type Contract struct { Uid string `gorm:"column:uid;type:varchar(100);comment:合同表的唯一表示;NOT NULL" json:"uid"` ArtistUid string `gorm:"column:artist_uid;type:varchar(100);comment:画家uid;NOT NULL" json:"artist_uid"` ArtworkUid string `gorm:"column:artwork_uid;type:varchar(1000);comment:画作uid" json:"artwork_uid"` - ContractId string `gorm:"column:contract_id;type:varchar(100);comment:合同id" json:"contract_id"` - TransactionId string `gorm:"column:transaction_id;type:varchar(100);comment:交易id" json:"transaction_id"` + ContractId string `gorm:"column:contract_id;type:varchar(300);comment:合同id" json:"contract_id"` + TransactionId string `gorm:"column:transaction_id;type:varchar(300);comment:交易id" json:"transaction_id"` Type int32 `gorm:"column:type;type:int(1);comment:合同类型;NOT NULL" json:"type"` ViewUrl string `gorm:"column:view_url;type:varchar(500);comment:在线查看合同链接" json:"view_url"` DownloadUrl string `gorm:"column:download_url;type:varchar(500);comment:合同下载链接" json:"download_url"`