From fbb3b8c3eb3b48772dc1123561e68741d05dfffa Mon Sep 17 00:00:00 2001
From: zhangqian <zhangqian@123.com>
Date: 星期三, 30 八月 2023 13:31:35 +0800
Subject: [PATCH] 统一记录编号

---
 model/model.go   |    8 ++++++++
 model/receipt.go |   13 +++++++++++--
 2 files changed, 19 insertions(+), 2 deletions(-)

diff --git a/model/model.go b/model/model.go
index d8f51a2..c6d1ca8 100644
--- a/model/model.go
+++ b/model/model.go
@@ -1,6 +1,7 @@
 package model
 
 import (
+	"fmt"
 	"gorm.io/gorm"
 	"time"
 )
@@ -30,6 +31,7 @@
 	CreateTime  string `json:"createTime"  gorm:"-"`
 	UpdateTime  string `json:"updateTime"  gorm:"-"`
 	CreatorName string `json:"creatorName" gorm:"-"`
+	Number      string `json:"number"`
 }
 
 func (slf *CrmModel) AfterFind(tx *gorm.DB) (err error) {
@@ -38,3 +40,9 @@
 	slf.UpdateTime = slf.UpdatedAt.Format("2006-01-02 15:04")
 	return nil
 }
+
+func (slf *CrmModel) SetNumber(prefix string) {
+	if slf.Number == "" {
+		slf.Number = fmt.Sprintf("%v%v", prefix, slf.ID)
+	}
+}
diff --git a/model/receipt.go b/model/receipt.go
index 50945d3..5c335a9 100644
--- a/model/receipt.go
+++ b/model/receipt.go
@@ -28,7 +28,7 @@
 		BankAccount   BankAccount                `gorm:"foreignKey:BankAccountId" json:"bankAccount"`
 		Remark        string                     `gorm:"column:remark;type:varchar(255);not null;default '';comment:澶囨敞" json:"remark"` // 澶囨敞
 		FileId        int                        `gorm:"column:file_id;type:int;not null;default 0;comment:闄勪欢id" json:"fileId"`        // 闄勪欢id
-		gorm.Model    `json:"-"`
+		CrmModel
 	}
 
 	// ReceiptSearch 鏀舵鍗曟悳绱㈡潯浠�
@@ -43,10 +43,19 @@
 	}
 )
 
-func (Receipt) TableName() string {
+func (slf *Receipt) TableName() string {
 	return "receipt"
 }
 
+func (slf *Receipt) AfterFind(db *gorm.DB) (err error) {
+	err = slf.CrmModel.AfterFind(db)
+	if slf.CrmModel.ID == 0 {
+		slf.CrmModel.ID = uint(slf.Id)
+	}
+	slf.CrmModel.SetNumber(constvar.NumberPrefixOfReceipt)
+	return nil
+}
+
 func NewReceiptSearch() *ReceiptSearch {
 	return &ReceiptSearch{
 		Orm: mysqlx.GetDB(),

--
Gitblit v1.8.0