| | |
| | | ctx.Ok() |
| | | } |
| | | |
| | | |
| | | func checkSalesRefundParams(salesRefund request.SalesRefund) (errCode int, salesRefundRes model.SalesRefund) { |
| | | //if salesRefund.ClientId == 0 { |
| | | // return ecode.InvalidParams, salesRefundRes |
| | | //} |
| | | // |
| | | //if salesRefund.Number == "" { |
| | | // return ecode.InvalidParams, salesRefundRes |
| | | //} |
| | | // |
| | | //if salesRefund.MemberId == 0 { |
| | | // return ecode.InvalidParams, salesRefundRes |
| | | //} |
| | | // |
| | | //if salesRefund.RefundDate == "" { |
| | | // return ecode.InvalidParams, salesRefundRes |
| | | //} |
| | | |
| | | t, err := checkTimeFormat(salesRefund.RefundDate) |
| | | if err != nil { |
| | | return ecode.InvalidParams, salesRefundRes |
| | | } |
| | | salesRefundRes.RefundDate = t |
| | | salesRefundRes.RefundDate = salesRefund.RefundDate |
| | | salesRefundRes.ClientId = salesRefund.ClientId |
| | | salesRefundRes.Number = salesRefund.Number |
| | | salesRefundRes.MemberId = salesRefund.MemberId |
| | | salesRefundRes.RefundMethod = salesRefund.RefundMethod |
| | | salesRefundRes.AccountId = salesRefund.AccountId |
| | | salesRefundRes.PaymentTypeId = salesRefund.PaymentTypeId |
| | | salesRefundRes.BankAccountId = salesRefund.BankAccountId |
| | | salesRefundRes.IsInvoice = salesRefund.IsInvoice |
| | | salesRefundRes.Reason = salesRefund.Reason |
| | | salesRefundRes.Products = salesRefund.Products |
| | |
| | | } |
| | | |
| | | ctx.OkWithDetailed(response.SalesRefundResponse{ |
| | | List: salesRefunds, |
| | | List: salesRefunds, |
| | | Count: int(total), |
| | | }) |
| | | } |
| | | } |
New file |
| | |
| | | package constvar |
| | | |
| | | type RefundSourceType int //来源类型(1销售退货) |
| | | |
| | | const ( |
| | | RefundSourceTypeSalesReturn RefundSourceType = 1 //销售退货 |
| | | ) |
| | |
| | | "ReceiptSourceTypeChuKuDan" |
| | | ] |
| | | }, |
| | | "constvar.RefundSourceType": { |
| | | "type": "integer", |
| | | "enum": [ |
| | | 1 |
| | | ], |
| | | "x-enum-comments": { |
| | | "RefundSourceTypeSalesReturn": "销售退货" |
| | | }, |
| | | "x-enum-varnames": [ |
| | | "RefundSourceTypeSalesReturn" |
| | | ] |
| | | }, |
| | | "constvar.SalesDetailsKeywordType": { |
| | | "type": "string", |
| | | "enum": [ |
| | |
| | | "description": "收款金额", |
| | | "type": "number" |
| | | }, |
| | | "bankAccount": { |
| | | "$ref": "#/definitions/model.BankAccount" |
| | | }, |
| | | "bankAccountId": { |
| | | "description": "账户id", |
| | | "type": "integer" |
| | |
| | | "description": "币种", |
| | | "type": "string" |
| | | }, |
| | | "paymentType": { |
| | | "$ref": "#/definitions/model.PaymentType" |
| | | }, |
| | | "paymentTypeId": { |
| | | "description": "收款方式ID", |
| | | "type": "integer" |
| | | }, |
| | | "principal": { |
| | | "description": "负责人id", |
| | | "allOf": [ |
| | | { |
| | | "$ref": "#/definitions/model.User" |
| | | } |
| | | ] |
| | | }, |
| | | "principalId": { |
| | | "description": "负责人id", |
| | |
| | | "model.SalesRefund": { |
| | | "type": "object", |
| | | "properties": { |
| | | "accountId": { |
| | | "bankAccount": { |
| | | "$ref": "#/definitions/model.BankAccount" |
| | | }, |
| | | "bankAccountId": { |
| | | "description": "账户id", |
| | | "type": "integer" |
| | | }, |
| | | "client": { |
| | | "$ref": "#/definitions/model.Client" |
| | | }, |
| | | "clientId": { |
| | | "type": "integer" |
| | |
| | | "number": { |
| | | "type": "string" |
| | | }, |
| | | "paymentType": { |
| | | "$ref": "#/definitions/model.PaymentType" |
| | | }, |
| | | "paymentTypeId": { |
| | | "description": "收款方式ID", |
| | | "type": "integer" |
| | | }, |
| | | "products": { |
| | | "type": "array", |
| | | "items": { |
| | |
| | | "refundDate": { |
| | | "type": "string" |
| | | }, |
| | | "refundMethod": { |
| | | "type": "string" |
| | | "sourceId": { |
| | | "description": "源单id", |
| | | "type": "integer" |
| | | }, |
| | | "sourceType": { |
| | | "description": "来源类型(1销售明细单2服务合同3销售发票4收款计划5出库单)", |
| | | "allOf": [ |
| | | { |
| | | "$ref": "#/definitions/constvar.RefundSourceType" |
| | | } |
| | | ] |
| | | } |
| | | } |
| | | }, |
| | |
| | | "description": "收款金额", |
| | | "type": "number" |
| | | }, |
| | | "bankAccount": { |
| | | "$ref": "#/definitions/model.BankAccount" |
| | | }, |
| | | "bankAccountId": { |
| | | "description": "账户id", |
| | | "type": "integer" |
| | |
| | | "description": "币种", |
| | | "type": "string" |
| | | }, |
| | | "paymentType": { |
| | | "$ref": "#/definitions/model.PaymentType" |
| | | }, |
| | | "paymentTypeId": { |
| | | "description": "收款方式ID", |
| | | "type": "integer" |
| | | }, |
| | | "principal": { |
| | | "description": "负责人id", |
| | | "allOf": [ |
| | | { |
| | | "$ref": "#/definitions/model.User" |
| | | } |
| | | ] |
| | | }, |
| | | "principalId": { |
| | | "description": "负责人id", |
| | |
| | | "request.SalesRefund": { |
| | | "type": "object", |
| | | "properties": { |
| | | "accountId": { |
| | | "bankAccountId": { |
| | | "description": "账户id", |
| | | "type": "integer" |
| | | }, |
| | | "clientId": { |
| | |
| | | "number": { |
| | | "type": "string" |
| | | }, |
| | | "paymentTypeId": { |
| | | "description": "收款方式ID", |
| | | "type": "integer" |
| | | }, |
| | | "products": { |
| | | "type": "array", |
| | | "items": { |
| | |
| | | "refundDate": { |
| | | "type": "string" |
| | | }, |
| | | "refundMethod": { |
| | | "type": "string" |
| | | "sourceId": { |
| | | "description": "源单id", |
| | | "type": "integer" |
| | | }, |
| | | "sourceType": { |
| | | "description": "来源类型(1销售明细单2服务合同3销售发票4收款计划5出库单)", |
| | | "allOf": [ |
| | | { |
| | | "$ref": "#/definitions/constvar.RefundSourceType" |
| | | } |
| | | ] |
| | | } |
| | | } |
| | | }, |
| | |
| | | "description": "收款金额", |
| | | "type": "number" |
| | | }, |
| | | "bankAccount": { |
| | | "$ref": "#/definitions/model.BankAccount" |
| | | }, |
| | | "bankAccountId": { |
| | | "description": "账户id", |
| | | "type": "integer" |
| | |
| | | "description": "币种", |
| | | "type": "string" |
| | | }, |
| | | "paymentType": { |
| | | "$ref": "#/definitions/model.PaymentType" |
| | | }, |
| | | "paymentTypeId": { |
| | | "description": "收款方式ID", |
| | | "type": "integer" |
| | | }, |
| | | "principal": { |
| | | "description": "负责人id", |
| | | "allOf": [ |
| | | { |
| | | "$ref": "#/definitions/model.User" |
| | | } |
| | | ] |
| | | }, |
| | | "principalId": { |
| | | "description": "负责人id", |
| | | "type": "integer" |
| | |
| | | "ReceiptSourceTypeChuKuDan" |
| | | ] |
| | | }, |
| | | "constvar.RefundSourceType": { |
| | | "type": "integer", |
| | | "enum": [ |
| | | 1 |
| | | ], |
| | | "x-enum-comments": { |
| | | "RefundSourceTypeSalesReturn": "销售退货" |
| | | }, |
| | | "x-enum-varnames": [ |
| | | "RefundSourceTypeSalesReturn" |
| | | ] |
| | | }, |
| | | "constvar.SalesDetailsKeywordType": { |
| | | "type": "string", |
| | | "enum": [ |
| | |
| | | "description": "收款金额", |
| | | "type": "number" |
| | | }, |
| | | "bankAccount": { |
| | | "$ref": "#/definitions/model.BankAccount" |
| | | }, |
| | | "bankAccountId": { |
| | | "description": "账户id", |
| | | "type": "integer" |
| | |
| | | "description": "币种", |
| | | "type": "string" |
| | | }, |
| | | "paymentType": { |
| | | "$ref": "#/definitions/model.PaymentType" |
| | | }, |
| | | "paymentTypeId": { |
| | | "description": "收款方式ID", |
| | | "type": "integer" |
| | | }, |
| | | "principal": { |
| | | "description": "负责人id", |
| | | "allOf": [ |
| | | { |
| | | "$ref": "#/definitions/model.User" |
| | | } |
| | | ] |
| | | }, |
| | | "principalId": { |
| | | "description": "负责人id", |
| | |
| | | "model.SalesRefund": { |
| | | "type": "object", |
| | | "properties": { |
| | | "accountId": { |
| | | "bankAccount": { |
| | | "$ref": "#/definitions/model.BankAccount" |
| | | }, |
| | | "bankAccountId": { |
| | | "description": "账户id", |
| | | "type": "integer" |
| | | }, |
| | | "client": { |
| | | "$ref": "#/definitions/model.Client" |
| | | }, |
| | | "clientId": { |
| | | "type": "integer" |
| | |
| | | "number": { |
| | | "type": "string" |
| | | }, |
| | | "paymentType": { |
| | | "$ref": "#/definitions/model.PaymentType" |
| | | }, |
| | | "paymentTypeId": { |
| | | "description": "收款方式ID", |
| | | "type": "integer" |
| | | }, |
| | | "products": { |
| | | "type": "array", |
| | | "items": { |
| | |
| | | "refundDate": { |
| | | "type": "string" |
| | | }, |
| | | "refundMethod": { |
| | | "type": "string" |
| | | "sourceId": { |
| | | "description": "源单id", |
| | | "type": "integer" |
| | | }, |
| | | "sourceType": { |
| | | "description": "来源类型(1销售明细单2服务合同3销售发票4收款计划5出库单)", |
| | | "allOf": [ |
| | | { |
| | | "$ref": "#/definitions/constvar.RefundSourceType" |
| | | } |
| | | ] |
| | | } |
| | | } |
| | | }, |
| | |
| | | "description": "收款金额", |
| | | "type": "number" |
| | | }, |
| | | "bankAccount": { |
| | | "$ref": "#/definitions/model.BankAccount" |
| | | }, |
| | | "bankAccountId": { |
| | | "description": "账户id", |
| | | "type": "integer" |
| | |
| | | "description": "币种", |
| | | "type": "string" |
| | | }, |
| | | "paymentType": { |
| | | "$ref": "#/definitions/model.PaymentType" |
| | | }, |
| | | "paymentTypeId": { |
| | | "description": "收款方式ID", |
| | | "type": "integer" |
| | | }, |
| | | "principal": { |
| | | "description": "负责人id", |
| | | "allOf": [ |
| | | { |
| | | "$ref": "#/definitions/model.User" |
| | | } |
| | | ] |
| | | }, |
| | | "principalId": { |
| | | "description": "负责人id", |
| | |
| | | "request.SalesRefund": { |
| | | "type": "object", |
| | | "properties": { |
| | | "accountId": { |
| | | "bankAccountId": { |
| | | "description": "账户id", |
| | | "type": "integer" |
| | | }, |
| | | "clientId": { |
| | |
| | | "number": { |
| | | "type": "string" |
| | | }, |
| | | "paymentTypeId": { |
| | | "description": "收款方式ID", |
| | | "type": "integer" |
| | | }, |
| | | "products": { |
| | | "type": "array", |
| | | "items": { |
| | |
| | | "refundDate": { |
| | | "type": "string" |
| | | }, |
| | | "refundMethod": { |
| | | "type": "string" |
| | | "sourceId": { |
| | | "description": "源单id", |
| | | "type": "integer" |
| | | }, |
| | | "sourceType": { |
| | | "description": "来源类型(1销售明细单2服务合同3销售发票4收款计划5出库单)", |
| | | "allOf": [ |
| | | { |
| | | "$ref": "#/definitions/constvar.RefundSourceType" |
| | | } |
| | | ] |
| | | } |
| | | } |
| | | }, |
| | |
| | | "description": "收款金额", |
| | | "type": "number" |
| | | }, |
| | | "bankAccount": { |
| | | "$ref": "#/definitions/model.BankAccount" |
| | | }, |
| | | "bankAccountId": { |
| | | "description": "账户id", |
| | | "type": "integer" |
| | |
| | | "description": "币种", |
| | | "type": "string" |
| | | }, |
| | | "paymentType": { |
| | | "$ref": "#/definitions/model.PaymentType" |
| | | }, |
| | | "paymentTypeId": { |
| | | "description": "收款方式ID", |
| | | "type": "integer" |
| | | }, |
| | | "principal": { |
| | | "description": "负责人id", |
| | | "allOf": [ |
| | | { |
| | | "$ref": "#/definitions/model.User" |
| | | } |
| | | ] |
| | | }, |
| | | "principalId": { |
| | | "description": "负责人id", |
| | | "type": "integer" |
| | |
| | | - ReceiptSourceTypeInvoice |
| | | - ReceiptSourceTypeCollectionPlan |
| | | - ReceiptSourceTypeChuKuDan |
| | | constvar.RefundSourceType: |
| | | enum: |
| | | - 1 |
| | | type: integer |
| | | x-enum-comments: |
| | | RefundSourceTypeSalesReturn: 销售退货 |
| | | x-enum-varnames: |
| | | - RefundSourceTypeSalesReturn |
| | | constvar.SalesDetailsKeywordType: |
| | | enum: |
| | | - 客户名称 |
| | |
| | | amount: |
| | | description: 收款金额 |
| | | type: number |
| | | bankAccount: |
| | | $ref: '#/definitions/model.BankAccount' |
| | | bankAccountId: |
| | | description: 账户id |
| | | type: integer |
| | |
| | | moneyType: |
| | | description: 币种 |
| | | type: string |
| | | paymentType: |
| | | $ref: '#/definitions/model.PaymentType' |
| | | paymentTypeId: |
| | | description: 收款方式ID |
| | | type: integer |
| | | principal: |
| | | allOf: |
| | | - $ref: '#/definitions/model.User' |
| | | description: 负责人id |
| | | principalId: |
| | | description: 负责人id |
| | | type: integer |
| | |
| | | type: object |
| | | model.SalesRefund: |
| | | properties: |
| | | accountId: |
| | | bankAccount: |
| | | $ref: '#/definitions/model.BankAccount' |
| | | bankAccountId: |
| | | description: 账户id |
| | | type: integer |
| | | client: |
| | | $ref: '#/definitions/model.Client' |
| | | clientId: |
| | | type: integer |
| | | id: |
| | |
| | | type: integer |
| | | number: |
| | | type: string |
| | | paymentType: |
| | | $ref: '#/definitions/model.PaymentType' |
| | | paymentTypeId: |
| | | description: 收款方式ID |
| | | type: integer |
| | | products: |
| | | items: |
| | | $ref: '#/definitions/model.Product' |
| | |
| | | type: string |
| | | refundDate: |
| | | type: string |
| | | refundMethod: |
| | | type: string |
| | | sourceId: |
| | | description: 源单id |
| | | type: integer |
| | | sourceType: |
| | | allOf: |
| | | - $ref: '#/definitions/constvar.RefundSourceType' |
| | | description: 来源类型(1销售明细单2服务合同3销售发票4收款计划5出库单) |
| | | type: object |
| | | model.SalesReturn: |
| | | properties: |
| | |
| | | amount: |
| | | description: 收款金额 |
| | | type: number |
| | | bankAccount: |
| | | $ref: '#/definitions/model.BankAccount' |
| | | bankAccountId: |
| | | description: 账户id |
| | | type: integer |
| | |
| | | moneyType: |
| | | description: 币种 |
| | | type: string |
| | | paymentType: |
| | | $ref: '#/definitions/model.PaymentType' |
| | | paymentTypeId: |
| | | description: 收款方式ID |
| | | type: integer |
| | | principal: |
| | | allOf: |
| | | - $ref: '#/definitions/model.User' |
| | | description: 负责人id |
| | | principalId: |
| | | description: 负责人id |
| | | type: integer |
| | |
| | | type: object |
| | | request.SalesRefund: |
| | | properties: |
| | | accountId: |
| | | bankAccountId: |
| | | description: 账户id |
| | | type: integer |
| | | clientId: |
| | | type: integer |
| | |
| | | type: integer |
| | | number: |
| | | type: string |
| | | paymentTypeId: |
| | | description: 收款方式ID |
| | | type: integer |
| | | products: |
| | | items: |
| | | $ref: '#/definitions/model.Product' |
| | |
| | | type: string |
| | | refundDate: |
| | | type: string |
| | | refundMethod: |
| | | type: string |
| | | sourceId: |
| | | description: 源单id |
| | | type: integer |
| | | sourceType: |
| | | allOf: |
| | | - $ref: '#/definitions/constvar.RefundSourceType' |
| | | description: 来源类型(1销售明细单2服务合同3销售发票4收款计划5出库单) |
| | | type: object |
| | | request.SalesReturn: |
| | | properties: |
| | |
| | | amount: |
| | | description: 收款金额 |
| | | type: number |
| | | bankAccount: |
| | | $ref: '#/definitions/model.BankAccount' |
| | | bankAccountId: |
| | | description: 账户id |
| | | type: integer |
| | |
| | | moneyType: |
| | | description: 币种 |
| | | type: string |
| | | paymentType: |
| | | $ref: '#/definitions/model.PaymentType' |
| | | paymentTypeId: |
| | | description: 收款方式ID |
| | | type: integer |
| | | principal: |
| | | allOf: |
| | | - $ref: '#/definitions/model.User' |
| | | description: 负责人id |
| | | principalId: |
| | | description: 负责人id |
| | | type: integer |
| | |
| | | SourceType constvar.ReceiptSourceType `gorm:"column:source_type;type:int;not null;default 0;comment:来源类型(1销售明细单2服务合同3销售发票4收款计划5出库单)" json:"sourceType"` // 来源类型(1销售明细单2服务合同3销售发票4收款计划5出库单) |
| | | SourceId int `gorm:"column:source_id;type:int;not null;default 0;comment:源单id " json:"sourceId"` // 源单id |
| | | PrincipalId int `gorm:"column:principal_id;type:int;not null;default 0;comment:负责人id" json:"principalId"` // 负责人id |
| | | Principal User `gorm:"foreignKey:PrincipalId" json:"principal"` // 负责人id |
| | | ReceiptDate string `gorm:"column:receipt_date;type:varchar(255);not null;default '';comment:收款日期" json:"receiptDate"` // 收款日期 |
| | | MoneyType string `gorm:"column:money_type;type:varchar(255);not null;default '';comment:币种" json:"moneyType"` // 币种 |
| | | Amount decimal.Decimal `gorm:"column:amount;type:decimal(12,2);not null;default '0.00';comment:收款金额" json:"amount"` // 收款金额 |
| | | 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 |
| | | 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 |
| | | 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"` |
| | | 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:"-"` |
| | | } |
| | | |
| | |
| | | package request |
| | | |
| | | import "aps_crm/model" |
| | | import ( |
| | | "aps_crm/constvar" |
| | | "aps_crm/model" |
| | | ) |
| | | |
| | | type AddSalesRefundRequest struct { |
| | | SalesRefund SalesRefund `json:"salesRefund"` |
| | | } |
| | | |
| | | type SalesRefund struct { |
| | | ClientId int `json:"clientId"` |
| | | Number string `json:"number"` |
| | | MemberId int `json:"memberId"` |
| | | RefundDate string `json:"refundDate"` |
| | | RefundMethod string `json:"refundMethod"` |
| | | AccountId int `json:"accountId"` |
| | | IsInvoice int `json:"isInvoice"` |
| | | Reason string `json:"reason"` |
| | | Products []model.Product `json:"products"` |
| | | ClientId int `json:"clientId"` |
| | | Number string `json:"number"` |
| | | MemberId int `json:"memberId"` |
| | | SourceType constvar.RefundSourceType `gorm:"column:source_type;type:int;not null;default 0;comment:来源类型(1销售明细单2服务合同3销售发票4收款计划5出库单)" json:"sourceType"` // 来源类型(1销售明细单2服务合同3销售发票4收款计划5出库单) |
| | | SourceId int `gorm:"column:source_id;type:int;not null;default 0;comment:源单id " json:"sourceId"` // 源单id |
| | | 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"` |
| | | Reason string `json:"reason"` |
| | | Products []*model.Product `json:"products"` |
| | | } |
| | | |
| | | type UpdateSalesRefundRequest struct { |
| | |
| | | package model |
| | | |
| | | import ( |
| | | "aps_crm/constvar" |
| | | "aps_crm/pkg/mysqlx" |
| | | "gorm.io/gorm" |
| | | "time" |
| | | ) |
| | | |
| | | type ( |
| | | SalesRefund struct { |
| | | Id int `json:"id" gorm:"column:id;primary_key;AUTO_INCREMENT"` |
| | | ClientId int `json:"clientId" gorm:"column:client_id;type:int;comment:客户id"` |
| | | Number string `json:"number" gorm:"column:number;type:varchar(255);comment:退款单号"` |
| | | MemberId int `json:"memberId" gorm:"column:member_id;type:int;comment:负责人id"` |
| | | RefundDate time.Time `json:"refundDate" gorm:"column:refund_date;type:datetime;comment:退款日期"` |
| | | RefundMethod string `json:"refundMethod" gorm:"column:refund_method;type:varchar(255);comment:退款方式"` |
| | | AccountId int `json:"accountId" gorm:"column:account_id;type:int;comment:账户"` |
| | | IsInvoice int `json:"isInvoice" gorm:"column:is_invoice;type:int;comment:是否开票"` |
| | | Reason string `json:"reason" gorm:"column:reason;type:varchar(255);comment:退款原因"` |
| | | Products []Product `json:"products" gorm:"many2many:salesRefund_product;"` |
| | | gorm.Model `json:"-"` |
| | | Id int `json:"id" gorm:"column:id;primary_key;AUTO_INCREMENT"` |
| | | ClientId int `json:"clientId" gorm:"column:client_id;type:int;comment:客户id"` |
| | | Client Client `json:"client" gorm:"foreignKey:ClientId"` |
| | | Number string `json:"number" gorm:"column:number;type:varchar(255);comment:退款单号"` |
| | | SourceType constvar.RefundSourceType `gorm:"column:source_type;type:int;not null;default 0;comment:来源类型(1销售明细单2服务合同3销售发票4收款计划5出库单)" json:"sourceType"` // 来源类型(1销售明细单2服务合同3销售发票4收款计划5出库单) |
| | | SourceId int `gorm:"column:source_id;type:int;not null;default 0;comment:源单id " json:"sourceId"` // 源单id |
| | | MemberId int `json:"memberId" gorm:"column:member_id;type:int;comment:负责人id"` |
| | | RefundDate string `json:"refundDate" gorm:"column:refund_date;type:datetime;comment:退款日期"` |
| | | PaymentTypeId int `gorm:"column:payment_type_id;type:int;not null;default 0;comment:收款方式ID" json:"paymentTypeId"` // 收款方式ID |
| | | 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:是否开票"` |
| | | Reason string `json:"reason" gorm:"column:reason;type:varchar(255);comment:退款原因"` |
| | | Products []*Product `json:"products" gorm:"many2many:salesRefund_product;"` |
| | | gorm.Model `json:"-"` |
| | | } |
| | | |
| | | SalesRefundSearch struct { |
| | | SalesRefund |
| | | |
| | | Orm *gorm.DB |
| | | Orm *gorm.DB |
| | | Keyword string |
| | | OrderBy string |
| | | PageNum int |
| | | PageSize int |
| | | |
| | | } |
| | | ) |
| | | |
| | |
| | | func (slf *SalesRefundSearch) SetOrder(order string) *SalesRefundSearch { |
| | | slf.OrderBy = order |
| | | return slf |
| | | } |
| | | } |
| | |
| | | SalesReturnUpdateErr = 2900005 // 更新销售退货单失败 |
| | | SalesReturnDeleteErr = 2900006 // 删除销售退货单失败 |
| | | |
| | | SalesRefundExist = 3000001 // 销售退款单已存在 |
| | | SalesRefundNotExist = 3000002 // 销售退款单不存在 |
| | | SalesRefundListErr = 3000003 // 获取销售退款单列表失败 |
| | | SalesRefundSetErr = 3000004 // 设置销售退款单失败 |
| | | SalesRefundUpdateErr = 3000005 // 更新销售退款单失败 |
| | | SalesRefundDeleteErr = 3000006 // 删除销售退款单失败 |
| | | SalesRefundExist = 3000001 // 销售退款单已存在 |
| | | SalesRefundNotExist = 3000002 // 销售退款单不存在 |
| | | SalesRefundListErr = 3000003 // 获取销售退款单列表失败 |
| | | SalesRefundSetErr = 3000004 // 设置销售退款单失败 |
| | | SalesRefundUpdateErr = 3000005 // 更新销售退款单失败 |
| | | SalesRefundDeleteErr = 3000006 // 删除销售退款单失败 |
| | | SalesRefundProductNotExist = 3000007 // 退货产品不存在 |
| | | SalesRefundProductPriceOrAmountErr = 3000009 // 退货产品价格或数量错误 |
| | | |
| | | ContractExist = 3100001 // 合同已存在 |
| | | ContractNotExist = 3100002 // 合同不存在 |
| | |
| | | SContractProductPriceLowerThanInvoiceAmountErr: "产品总价低于已开票金额", |
| | | SContractProductPriceLowerThanReceivedAmountErr: "产品总价低于已收金额", |
| | | SContractInvoiceProductPriceGreaterThanReceivableAmountErr: "开票总额高于应收金额", |
| | | SalesRefundProductNotExist: "退货产品不存在", |
| | | SalesRefundProductPriceOrAmountErr: "退货产品价格或数量错误", |
| | | } |
| | | |
| | | func GetMsg(errCode int) (errMsg string) { |
| | |
| | | type SalesRefundService struct{} |
| | | |
| | | func (SalesRefundService) AddSalesRefund(salesRefund *model.SalesRefund) int { |
| | | err := model.NewSalesRefundSearch().Create(salesRefund) |
| | | salesReturnRecord, err := model.NewSalesReturnSearch().SetId(salesRefund.SourceId).Find() |
| | | if err != nil { |
| | | return ecode.SalesReturnNotExist |
| | | } |
| | | |
| | | if code := CheckProduct(salesReturnRecord.Products, salesRefund.Products); code != ecode.OK { |
| | | return code |
| | | } |
| | | |
| | | err = model.NewSalesRefundSearch().Create(salesRefund) |
| | | if err != nil { |
| | | return ecode.SalesRefundExist |
| | | } |
| | | |
| | | return ecode.OK |
| | | } |
| | | |
| | | func CheckProduct(returnProducts, refundProducts []*model.Product) int { |
| | | returnProductsMap := make(map[uint]*model.Product, len(returnProducts)) |
| | | for _, product := range returnProducts { |
| | | returnProductsMap[product.Id] = product |
| | | } |
| | | for _, product := range refundProducts { |
| | | if returnProductsMap[product.Id] == nil { |
| | | return ecode.SalesRefundProductNotExist |
| | | } |
| | | if returnProductsMap[product.Id].Price != product.Price || product.Amount.GreaterThan(returnProductsMap[product.Id].Amount) { |
| | | return ecode.SalesRefundProductPriceOrAmountErr |
| | | } |
| | | } |
| | | return ecode.OK |
| | | } |
| | | |
| | |
| | | return ecode.SalesRefundNotExist |
| | | } |
| | | |
| | | salesReturnRecord, err := model.NewSalesReturnSearch().SetId(salesRefund.SourceId).Find() |
| | | if err != nil { |
| | | return ecode.SalesReturnNotExist |
| | | } |
| | | |
| | | if code := CheckProduct(salesReturnRecord.Products, salesRefund.Products); code != ecode.OK { |
| | | return code |
| | | } |
| | | |
| | | err = model.NewSalesRefundSearch().SetId(salesRefund.Id).Update(salesRefund) |
| | | if err != nil { |
| | | return ecode.SalesRefundSetErr |