From 5a356c6178e15b44bdfe4cf3e94c52b0d4a17668 Mon Sep 17 00:00:00 2001 From: zhangqian <zhangqian@123.com> Date: 星期二, 15 八月 2023 17:32:25 +0800 Subject: [PATCH] 完善退货单查询,fix一些bug --- model/salesReturn.go | 74 +++++++++++--- constvar/salesRefund.go | 14 ++ docs/swagger.yaml | 32 ++++++ docs/docs.go | 38 +++++++ api/v1/salesReturn.go | 6 docs/swagger.json | 38 +++++++ constvar/salesReturn.go | 13 ++ constvar/saleRefund.go | 14 -- model/request/salesReturn.go | 15 +- model/salesRefund.go | 2 service/salesRefund.go | 2 model/request/salesRefund.go | 2 service/salesReturn.go | 10 + 13 files changed, 211 insertions(+), 49 deletions(-) diff --git a/api/v1/salesReturn.go b/api/v1/salesReturn.go index e0c7990..2a55b45 100644 --- a/api/v1/salesReturn.go +++ b/api/v1/salesReturn.go @@ -129,7 +129,9 @@ // @Tags SalesReturn // @Summary 閿�鍞��璐у崟鍒楄〃 // @Produce application/json -// @Param object body request.GetSalesReturnList true "鍙傛暟" +// +// @Param object body request.GetSalesReturnList true "鍙傛暟" +// // @Success 200 {object} contextx.Response{data=response.SalesReturnResponse} // @Router /api/salesReturn/list [post] func (con *SalesReturnApi) List(c *gin.Context) { @@ -139,7 +141,7 @@ return } - salesReturns, total, errCode := salesReturnService.GetSalesReturnList(params.Page, params.PageSize, params.Keyword) + salesReturns, total, errCode := salesReturnService.GetSalesReturnList(params.Page, params.PageSize, params.KeywordType, params.Keyword) if errCode != ecode.OK { ctx.Fail(errCode) return diff --git a/constvar/saleRefund.go b/constvar/saleRefund.go index 06d3f55..c2ae672 100644 --- a/constvar/saleRefund.go +++ b/constvar/saleRefund.go @@ -1,15 +1 @@ package constvar - -type SalesRefundKeywordType string - -const ( - SalesRefundKeywordRefundNumber SalesRefundKeywordType = "閿�鍞��璐у崟缂栧彿" - SalesRefundKeywordClientName SalesRefundKeywordType = "瀹㈡埛鍚嶇О" - SalesRefundKeywordRefundDate SalesRefundKeywordType = "閫�娆炬棩鏈�" - SalesRefundKeywordAccount SalesRefundKeywordType = "璐︽埛" - SalesRefundKeywordIsInvoice SalesRefundKeywordType = "鏄惁寮�绁�" - SalesRefundKeywordPaymentType SalesRefundKeywordType = "浠樻鏂瑰紡" - SalesRefundKeywordPrincipal SalesRefundKeywordType = "閿�鍞礋璐d汉" - SalesRefundKeywordUpdateAt SalesRefundKeywordType = "淇敼鏃堕棿" - SalesRefundKeywordPriceTotal SalesRefundKeywordType = "浠风◣鍚堣" -) diff --git a/constvar/salesRefund.go b/constvar/salesRefund.go index 0f65a91..d81da04 100644 --- a/constvar/salesRefund.go +++ b/constvar/salesRefund.go @@ -5,3 +5,17 @@ const ( RefundSourceTypeSalesReturn RefundSourceType = 1 //閿�鍞��璐� ) + +type SalesRefundKeywordType string + +const ( + SalesRefundKeywordRefundNumber SalesRefundKeywordType = "閿�鍞��璐у崟缂栧彿" + SalesRefundKeywordClientName SalesRefundKeywordType = "瀹㈡埛鍚嶇О" + SalesRefundKeywordRefundDate SalesRefundKeywordType = "閫�娆炬棩鏈�" + SalesRefundKeywordAccount SalesRefundKeywordType = "璐︽埛" + SalesRefundKeywordIsInvoice SalesRefundKeywordType = "鏄惁寮�绁�" + SalesRefundKeywordPaymentType SalesRefundKeywordType = "浠樻鏂瑰紡" + SalesRefundKeywordPrincipal SalesRefundKeywordType = "閿�鍞礋璐d汉" + SalesRefundKeywordUpdateAt SalesRefundKeywordType = "淇敼鏃堕棿" + SalesRefundKeywordPriceTotal SalesRefundKeywordType = "浠风◣鍚堣" +) diff --git a/constvar/salesReturn.go b/constvar/salesReturn.go index f86185f..a2a13ca 100644 --- a/constvar/salesReturn.go +++ b/constvar/salesReturn.go @@ -5,3 +5,16 @@ const ( SalesReturnSourceTypeSaleDetails SalesReturnSourceType = 1 //閿�鍞槑缁� ) + +type SalesReturnKeywordType string + +const ( + SalesReturnKeywordReturnNumber SalesReturnKeywordType = "閿�鍞��璐у崟缂栧彿" + SalesReturnKeywordClientName SalesReturnKeywordType = "瀹㈡埛鍚嶇О" + SalesReturnKeywordReturnDate SalesReturnKeywordType = "閫�娆炬棩鏈�" + SalesReturnKeywordStatus SalesReturnKeywordType = "鐘舵��" + SalesReturnKeywordRepository SalesReturnKeywordType = "閫�鍏ヤ粨搴�" + SalesReturnKeywordAmountShouldRefund SalesReturnKeywordType = "搴旈��娆�" + SalesReturnKeywordAmountHasRefund SalesReturnKeywordType = "宸查��娆�" + SalesReturnKeywordPrincipal SalesReturnKeywordType = "閿�鍞礋璐d汉" +) diff --git a/docs/docs.go b/docs/docs.go index 8d18427..7eae24b 100644 --- a/docs/docs.go +++ b/docs/docs.go @@ -10263,6 +10263,29 @@ "SalesRefundKeywordPriceTotal" ] }, + "constvar.SalesReturnKeywordType": { + "type": "string", + "enum": [ + "閿�鍞��璐у崟缂栧彿", + "瀹㈡埛鍚嶇О", + "閫�娆炬棩鏈�", + "鐘舵��", + "閫�鍏ヤ粨搴�", + "搴旈��娆�", + "宸查��娆�", + "閿�鍞礋璐d汉" + ], + "x-enum-varnames": [ + "SalesReturnKeywordReturnNumber", + "SalesReturnKeywordClientName", + "SalesReturnKeywordReturnDate", + "SalesReturnKeywordStatus", + "SalesReturnKeywordRepository", + "SalesReturnKeywordAmountShouldRefund", + "SalesReturnKeywordAmountHasRefund", + "SalesReturnKeywordPrincipal" + ] + }, "constvar.SalesReturnSourceType": { "type": "integer", "enum": [ @@ -12066,7 +12089,7 @@ "type": "integer" }, "isInvoice": { - "type": "integer" + "type": "string" }, "member": { "$ref": "#/definitions/model.User" @@ -12123,6 +12146,14 @@ "$ref": "#/definitions/model.SalesReturnStatus" } ] + }, + "amountHasRefund": { + "description": "宸查��娆鹃噾棰�", + "type": "number" + }, + "amountShouldRefund": { + "description": "搴旈��娆鹃噾棰�", + "type": "number" }, "client": { "$ref": "#/definitions/model.Client" @@ -15041,6 +15072,9 @@ "keyword": { "type": "string" }, + "keywordType": { + "$ref": "#/definitions/constvar.SalesReturnKeywordType" + }, "page": { "description": "椤电爜", "type": "integer" @@ -15384,7 +15418,7 @@ "type": "integer" }, "isInvoice": { - "type": "integer" + "type": "string" }, "memberId": { "type": "integer" diff --git a/docs/swagger.json b/docs/swagger.json index f5753ae..b1ea281 100644 --- a/docs/swagger.json +++ b/docs/swagger.json @@ -10251,6 +10251,29 @@ "SalesRefundKeywordPriceTotal" ] }, + "constvar.SalesReturnKeywordType": { + "type": "string", + "enum": [ + "閿�鍞��璐у崟缂栧彿", + "瀹㈡埛鍚嶇О", + "閫�娆炬棩鏈�", + "鐘舵��", + "閫�鍏ヤ粨搴�", + "搴旈��娆�", + "宸查��娆�", + "閿�鍞礋璐d汉" + ], + "x-enum-varnames": [ + "SalesReturnKeywordReturnNumber", + "SalesReturnKeywordClientName", + "SalesReturnKeywordReturnDate", + "SalesReturnKeywordStatus", + "SalesReturnKeywordRepository", + "SalesReturnKeywordAmountShouldRefund", + "SalesReturnKeywordAmountHasRefund", + "SalesReturnKeywordPrincipal" + ] + }, "constvar.SalesReturnSourceType": { "type": "integer", "enum": [ @@ -12054,7 +12077,7 @@ "type": "integer" }, "isInvoice": { - "type": "integer" + "type": "string" }, "member": { "$ref": "#/definitions/model.User" @@ -12111,6 +12134,14 @@ "$ref": "#/definitions/model.SalesReturnStatus" } ] + }, + "amountHasRefund": { + "description": "宸查��娆鹃噾棰�", + "type": "number" + }, + "amountShouldRefund": { + "description": "搴旈��娆鹃噾棰�", + "type": "number" }, "client": { "$ref": "#/definitions/model.Client" @@ -15029,6 +15060,9 @@ "keyword": { "type": "string" }, + "keywordType": { + "$ref": "#/definitions/constvar.SalesReturnKeywordType" + }, "page": { "description": "椤电爜", "type": "integer" @@ -15372,7 +15406,7 @@ "type": "integer" }, "isInvoice": { - "type": "integer" + "type": "string" }, "memberId": { "type": "integer" diff --git a/docs/swagger.yaml b/docs/swagger.yaml index 24f3e2d..3f42ba4 100644 --- a/docs/swagger.yaml +++ b/docs/swagger.yaml @@ -186,6 +186,26 @@ - SalesRefundKeywordPrincipal - SalesRefundKeywordUpdateAt - SalesRefundKeywordPriceTotal + constvar.SalesReturnKeywordType: + enum: + - 閿�鍞��璐у崟缂栧彿 + - 瀹㈡埛鍚嶇О + - 閫�娆炬棩鏈� + - 鐘舵�� + - 閫�鍏ヤ粨搴� + - 搴旈��娆� + - 宸查��娆� + - 閿�鍞礋璐d汉 + type: string + x-enum-varnames: + - SalesReturnKeywordReturnNumber + - SalesReturnKeywordClientName + - SalesReturnKeywordReturnDate + - SalesReturnKeywordStatus + - SalesReturnKeywordRepository + - SalesReturnKeywordAmountShouldRefund + - SalesReturnKeywordAmountHasRefund + - SalesReturnKeywordPrincipal constvar.SalesReturnSourceType: enum: - 1 @@ -1427,7 +1447,7 @@ id: type: integer isInvoice: - type: integer + type: string member: $ref: '#/definitions/model.User' memberId: @@ -1463,6 +1483,12 @@ allOf: - $ref: '#/definitions/model.SalesReturnStatus' description: 閫�璐х姸鎬� + amountHasRefund: + description: 宸查��娆鹃噾棰� + type: number + amountShouldRefund: + description: 搴旈��娆鹃噾棰� + type: number client: $ref: '#/definitions/model.Client' clientId: @@ -3464,6 +3490,8 @@ properties: keyword: type: string + keywordType: + $ref: '#/definitions/constvar.SalesReturnKeywordType' page: description: 椤电爜 type: integer @@ -3698,7 +3726,7 @@ clientId: type: integer isInvoice: - type: integer + type: string memberId: type: integer number: diff --git a/model/request/salesRefund.go b/model/request/salesRefund.go index 5f54725..d8fd5b5 100644 --- a/model/request/salesRefund.go +++ b/model/request/salesRefund.go @@ -18,7 +18,7 @@ RefundDate string `json:"refundDate"` PaymentTypeId int `gorm:"column:payment_type_id;type:int;not null;default 0;comment:鏀舵鏂瑰紡ID" json:"paymentTypeId"` // 鏀舵鏂瑰紡ID BankAccountId int `gorm:"column:bank_account_id;type:int;not null;default 0;comment:璐︽埛id" json:"bankAccountId"` // 璐︽埛id - IsInvoice int `json:"isInvoice"` + IsInvoice string `json:"isInvoice"` Reason string `json:"reason"` Products []*model.Product `json:"products"` } diff --git a/model/request/salesReturn.go b/model/request/salesReturn.go index 8da7dbc..b451ee1 100644 --- a/model/request/salesReturn.go +++ b/model/request/salesReturn.go @@ -16,12 +16,12 @@ Number string `json:"number" gorm:"column:number;type:varchar(255);comment:閫�璐у崟鍙�"` Repository string `json:"repository" gorm:"column:repository;type:varchar(255);comment:浠撳簱"` MemberId int `json:"memberId" gorm:"column:member_id;type:int;comment:璐熻矗浜篿d"` - ReturnDate string `json:"returnDate" gorm:"column:return_date;type:datetime(3);comment:閫�璐ф棩鏈�"` //閫�璐ф棩鏈� - SalesReturnStatusId int `json:"salesReturnStatusId" gorm:"column:sales_return_status;type:int;comment:閫�璐х姸鎬�"` //閫�璐х姸鎬乮d - CreatorId int `json:"-" gorm:"column:creator_id;type:int;comment:鍒涘缓浜篿d"` //鍒涘缓浜篒D - Creator User `json:"-" gorm:"foreignKey:CreatorId"` //鍒涘缓浜轰俊鎭� - Reason string `json:"reason" gorm:"column:reason;type:varchar(255);comment:閫�璐у師鍥�"` //閫�璐у師鍥� - Products []*model.Product `json:"products" gorm:"many2many:salesReturn_product;"` //閫�璐т骇鍝� + ReturnDate string `json:"returnDate" gorm:"column:return_date;type:datetime(3);comment:閫�璐ф棩鏈�"` //閫�璐ф棩鏈� + SalesReturnStatusId int `json:"salesReturnStatusId" gorm:"column:sales_return_status_id;type:int;comment:閫�璐х姸鎬�"` //閫�璐х姸鎬乮d + CreatorId int `json:"-" gorm:"column:creator_id;type:int;comment:鍒涘缓浜篿d"` //鍒涘缓浜篒D + Creator User `json:"-" gorm:"foreignKey:CreatorId"` //鍒涘缓浜轰俊鎭� + Reason string `json:"reason" gorm:"column:reason;type:varchar(255);comment:閫�璐у師鍥�"` //閫�璐у師鍥� + Products []*model.Product `json:"products" gorm:"many2many:salesReturn_product;"` //閫�璐т骇鍝� } type UpdateSalesReturnRequest struct { @@ -31,5 +31,6 @@ type GetSalesReturnList struct { PageInfo - Keyword string `json:"keyword"` + Keyword string `json:"keyword"` + KeywordType constvar.SalesReturnKeywordType } diff --git a/model/salesRefund.go b/model/salesRefund.go index c5519c9..ef9b5ca 100644 --- a/model/salesRefund.go +++ b/model/salesRefund.go @@ -24,7 +24,7 @@ PaymentType PaymentType `gorm:"foreignKey:PaymentTypeId" json:"paymentType"` BankAccountId int `gorm:"column:bank_account_id;type:int;not null;default 0;comment:璐︽埛id" json:"bankAccountId"` // 璐︽埛id BankAccount BankAccount `gorm:"foreignKey:BankAccountId" json:"bankAccount"` - IsInvoice int `json:"isInvoice" gorm:"column:is_invoice;type:int;comment:鏄惁寮�绁�"` + IsInvoice string `json:"isInvoice" gorm:"column:is_invoice;type:varchar(255);comment:鏄惁寮�绁�"` Reason string `json:"reason" gorm:"column:reason;type:varchar(255);comment:閫�娆惧師鍥�"` Products []*Product `json:"products" gorm:"many2many:salesRefund_product;"` AmountTotal decimal.Decimal `gorm:"column:amount_total;type:decimal(12,2);comment:浠风◣鍚堣" json:"amountTotal"` // 浠风◣鍚堣 diff --git a/model/salesReturn.go b/model/salesReturn.go index 0b36fef..17aa2de 100644 --- a/model/salesReturn.go +++ b/model/salesReturn.go @@ -3,7 +3,10 @@ import ( "aps_crm/constvar" "aps_crm/pkg/mysqlx" + "fmt" + "github.com/shopspring/decimal" "gorm.io/gorm" + "gorm.io/gorm/clause" ) type ( @@ -17,24 +20,29 @@ Repository string `json:"repository" gorm:"column:repository;type:varchar(255);comment:浠撳簱"` MemberId int `json:"memberId" gorm:"column:member_id;type:int;comment:璐熻矗浜篿d"` Member User `json:"Member" gorm:"foreignKey:MemberId"` - ReturnDate string `json:"returnDate" gorm:"column:return_date;type:datetime(3);comment:閫�璐ф棩鏈�"` //閫�璐ф棩鏈� - SalesReturnStatusId int `json:"salesReturnStatusId" gorm:"column:sales_return_status;type:int;comment:閫�璐х姸鎬�"` //閫�璐х姸鎬乮d - SalesReturnStatus SalesReturnStatus `json:"SalesReturnStatus" gorm:"foreignKey:SalesReturnStatusId"` //閫�璐х姸鎬� - CreatorId int `json:"-" gorm:"column:creator_id;type:int;comment:鍒涘缓浜篿d"` //鍒涘缓浜篒D - Creator User `json:"-" gorm:"foreignKey:CreatorId"` //鍒涘缓浜轰俊鎭� - Reason string `json:"reason" gorm:"column:reason;type:varchar(255);comment:閫�璐у師鍥�"` //閫�璐у師鍥� - Products []*Product `json:"products" gorm:"many2many:salesReturn_product;"` //閫�璐т骇鍝� + ReturnDate string `json:"returnDate" gorm:"column:return_date;type:datetime(3);comment:閫�璐ф棩鏈�"` //閫�璐ф棩鏈� + SalesReturnStatusId int `json:"salesReturnStatusId" gorm:"column:sales_return_status;type:int;comment:閫�璐х姸鎬�"` //閫�璐х姸鎬乮d + SalesReturnStatus SalesReturnStatus `json:"SalesReturnStatus" gorm:"foreignKey:SalesReturnStatusId"` //閫�璐х姸鎬� + CreatorId int `json:"-" gorm:"column:creator_id;type:int;comment:鍒涘缓浜篿d"` //鍒涘缓浜篒D + Creator User `json:"-" gorm:"foreignKey:CreatorId"` //鍒涘缓浜轰俊鎭� + Reason string `json:"reason" gorm:"column:reason;type:varchar(255);comment:閫�璐у師鍥�"` //閫�璐у師鍥� + Products []*Product `json:"products" gorm:"many2many:salesReturn_product;"` //閫�璐т骇鍝� + AmountShouldRefund decimal.Decimal `gorm:"column:amount_should_refund;type:decimal(12,2);comment:搴旈��娆鹃噾棰�" json:"amountShouldRefund"` // 搴旈��娆鹃噾棰� + AmountHasRefund decimal.Decimal `gorm:"column:amount_has_refund;type:decimal(12,2);comment:宸查��娆鹃噾棰�" json:"amountHasRefund"` // 宸查��娆鹃噾棰� + CrmModel } SalesReturnSearch struct { SalesReturn - Orm *gorm.DB - Keyword string - OrderBy string - PageNum int - PageSize int + Orm *gorm.DB + KeywordType constvar.SalesReturnKeywordType + Keyword string + OrderBy string + PageNum int + PageSize int + Preload bool } ) @@ -49,11 +57,37 @@ func (slf *SalesReturnSearch) build() *gorm.DB { var db = slf.Orm.Model(&SalesReturn{}) - if slf.Keyword != "" { - db = db.Where("name LIKE ?", "%"+slf.Keyword+"%") - } if slf.Id != 0 { db = db.Where("id = ?", slf.Id) + } + + if slf.Preload { + db = db.Preload("Client"). + Preload("Member"). + Preload("SalesReturnStatus"). + Preload("Products") + } + + if slf.KeywordType != "" { + switch slf.KeywordType { + case constvar.SalesReturnKeywordReturnNumber: + db = db.Where("number like ?", fmt.Sprintf("%%%s%%", slf.Keyword)) + case constvar.SalesReturnKeywordClientName: + db = db.Joins("Client", clause.LeftJoin).Where("Client.name like ?", fmt.Sprintf("%%%s%%", slf.Keyword)) + case constvar.SalesReturnKeywordReturnDate: + db = db.Where("return_date like ?", fmt.Sprintf("%%%s%%", slf.Keyword)) + case constvar.SalesReturnKeywordStatus: + db = db.Joins("SalesReturnStatus").Where("SalesReturnStatus name like ?", fmt.Sprintf("%%%s%%", slf.Keyword)) + case constvar.SalesReturnKeywordRepository: + db = db.Where("repository like ?", fmt.Sprintf("%%%s%%", slf.Keyword)) + case constvar.SalesReturnKeywordAmountShouldRefund: + db = db.Where("amount_should_refund = ?", slf.Keyword) + case constvar.SalesReturnKeywordPrincipal: + db = db.Joins("left join user on user.id = sales_refund.member_id").Where("user.username like ?", fmt.Sprintf("%%%s%%", slf.Keyword)) + case constvar.SalesReturnKeywordAmountHasRefund: + db = db.Where("amount_has_refund = ?", slf.Keyword) + + } } return db @@ -106,6 +140,11 @@ return slf } +func (slf *SalesReturnSearch) SetKeywordType(keywordType constvar.SalesReturnKeywordType) *SalesReturnSearch { + slf.KeywordType = keywordType + return slf +} + func (slf *SalesReturnSearch) SetPage(page, size int) *SalesReturnSearch { slf.PageNum, slf.PageSize = page, size return slf @@ -115,3 +154,8 @@ slf.OrderBy = order return slf } + +func (slf *SalesReturnSearch) SetPreload(preload bool) *SalesReturnSearch { + slf.Preload = preload + return slf +} diff --git a/service/salesRefund.go b/service/salesRefund.go index 1403dac..14738b1 100644 --- a/service/salesRefund.go +++ b/service/salesRefund.go @@ -62,7 +62,7 @@ return ecode.SalesRefundNotExist } - salesReturnRecord, err := model.NewSalesReturnSearch().SetId(salesRefund.SourceId).Find() + salesReturnRecord, err := model.NewSalesReturnSearch().SetId(salesRefund.SourceId).SetPreload(true).Find() if err != nil { return ecode.SalesReturnNotExist } diff --git a/service/salesReturn.go b/service/salesReturn.go index 6a4bab0..e2b3284 100644 --- a/service/salesReturn.go +++ b/service/salesReturn.go @@ -1,6 +1,7 @@ package service import ( + "aps_crm/constvar" "aps_crm/model" "aps_crm/pkg/ecode" ) @@ -44,9 +45,14 @@ return ecode.OK } -func (SalesReturnService) GetSalesReturnList(page, pageSize int, keyword string) ([]*model.SalesReturn, int64, int) { +func (SalesReturnService) GetSalesReturnList(page, pageSize int, keywordType constvar.SalesReturnKeywordType, keyword string) ([]*model.SalesReturn, int64, int) { // get contact list - contacts, total, err := model.NewSalesReturnSearch().SetKeyword(keyword).SetPage(page, pageSize).FindAll() + contacts, total, err := model.NewSalesReturnSearch(). + SetKeywordType(keywordType). + SetKeyword(keyword). + SetPage(page, pageSize). + SetPreload(true). + FindAll() if err != nil { return nil, 0, ecode.SalesReturnListErr } -- Gitblit v1.8.0