zhangqian
2023-08-13 6e87a1f6795af50133b10fa853fd6c2d14bb698c
完善退款单
1个文件已添加
10个文件已修改
432 ■■■■ 已修改文件
api/v1/salesRefund.go 31 ●●●● 补丁 | 查看 | 原始文档 | blame | 历史
constvar/salesRefund.go 7 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
docs/docs.go 103 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
docs/swagger.json 103 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
docs/swagger.yaml 68 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
model/receipt.go 9 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
model/request/salesRefund.go 25 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
model/salesRefund.go 34 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
pkg/ecode/code.go 14 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
pkg/ecode/msg.go 2 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
service/salesRefund.go 36 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
api/v1/salesRefund.go
@@ -98,34 +98,13 @@
    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
@@ -155,7 +134,7 @@
    }
    ctx.OkWithDetailed(response.SalesRefundResponse{
        List: salesRefunds,
        List:  salesRefunds,
        Count: int(total),
    })
}
}
constvar/salesRefund.go
New file
@@ -0,0 +1,7 @@
package constvar
type RefundSourceType int //来源类型(1销售退货)
const (
    RefundSourceTypeSalesReturn RefundSourceType = 1 //销售退货
)
docs/docs.go
@@ -10028,6 +10028,18 @@
                "ReceiptSourceTypeChuKuDan"
            ]
        },
        "constvar.RefundSourceType": {
            "type": "integer",
            "enum": [
                1
            ],
            "x-enum-comments": {
                "RefundSourceTypeSalesReturn": "销售退货"
            },
            "x-enum-varnames": [
                "RefundSourceTypeSalesReturn"
            ]
        },
        "constvar.SalesDetailsKeywordType": {
            "type": "string",
            "enum": [
@@ -11282,6 +11294,9 @@
                    "description": "收款金额",
                    "type": "number"
                },
                "bankAccount": {
                    "$ref": "#/definitions/model.BankAccount"
                },
                "bankAccountId": {
                    "description": "账户id",
                    "type": "integer"
@@ -11301,9 +11316,20 @@
                    "description": "币种",
                    "type": "string"
                },
                "paymentType": {
                    "$ref": "#/definitions/model.PaymentType"
                },
                "paymentTypeId": {
                    "description": "收款方式ID",
                    "type": "integer"
                },
                "principal": {
                    "description": "负责人id",
                    "allOf": [
                        {
                            "$ref": "#/definitions/model.User"
                        }
                    ]
                },
                "principalId": {
                    "description": "负责人id",
@@ -11721,8 +11747,15 @@
        "model.SalesRefund": {
            "type": "object",
            "properties": {
                "accountId": {
                "bankAccount": {
                    "$ref": "#/definitions/model.BankAccount"
                },
                "bankAccountId": {
                    "description": "账户id",
                    "type": "integer"
                },
                "client": {
                    "$ref": "#/definitions/model.Client"
                },
                "clientId": {
                    "type": "integer"
@@ -11739,6 +11772,13 @@
                "number": {
                    "type": "string"
                },
                "paymentType": {
                    "$ref": "#/definitions/model.PaymentType"
                },
                "paymentTypeId": {
                    "description": "收款方式ID",
                    "type": "integer"
                },
                "products": {
                    "type": "array",
                    "items": {
@@ -11751,8 +11791,17 @@
                "refundDate": {
                    "type": "string"
                },
                "refundMethod": {
                    "type": "string"
                "sourceId": {
                    "description": "源单id",
                    "type": "integer"
                },
                "sourceType": {
                    "description": "来源类型(1销售明细单2服务合同3销售发票4收款计划5出库单)",
                    "allOf": [
                        {
                            "$ref": "#/definitions/constvar.RefundSourceType"
                        }
                    ]
                }
            }
        },
@@ -13187,6 +13236,9 @@
                    "description": "收款金额",
                    "type": "number"
                },
                "bankAccount": {
                    "$ref": "#/definitions/model.BankAccount"
                },
                "bankAccountId": {
                    "description": "账户id",
                    "type": "integer"
@@ -13206,9 +13258,20 @@
                    "description": "币种",
                    "type": "string"
                },
                "paymentType": {
                    "$ref": "#/definitions/model.PaymentType"
                },
                "paymentTypeId": {
                    "description": "收款方式ID",
                    "type": "integer"
                },
                "principal": {
                    "description": "负责人id",
                    "allOf": [
                        {
                            "$ref": "#/definitions/model.User"
                        }
                    ]
                },
                "principalId": {
                    "description": "负责人id",
@@ -14933,7 +14996,8 @@
        "request.SalesRefund": {
            "type": "object",
            "properties": {
                "accountId": {
                "bankAccountId": {
                    "description": "账户id",
                    "type": "integer"
                },
                "clientId": {
@@ -14948,6 +15012,10 @@
                "number": {
                    "type": "string"
                },
                "paymentTypeId": {
                    "description": "收款方式ID",
                    "type": "integer"
                },
                "products": {
                    "type": "array",
                    "items": {
@@ -14960,8 +15028,17 @@
                "refundDate": {
                    "type": "string"
                },
                "refundMethod": {
                    "type": "string"
                "sourceId": {
                    "description": "源单id",
                    "type": "integer"
                },
                "sourceType": {
                    "description": "来源类型(1销售明细单2服务合同3销售发票4收款计划5出库单)",
                    "allOf": [
                        {
                            "$ref": "#/definitions/constvar.RefundSourceType"
                        }
                    ]
                }
            }
        },
@@ -16067,6 +16144,9 @@
                    "description": "收款金额",
                    "type": "number"
                },
                "bankAccount": {
                    "$ref": "#/definitions/model.BankAccount"
                },
                "bankAccountId": {
                    "description": "账户id",
                    "type": "integer"
@@ -16086,10 +16166,21 @@
                    "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"
docs/swagger.json
@@ -10016,6 +10016,18 @@
                "ReceiptSourceTypeChuKuDan"
            ]
        },
        "constvar.RefundSourceType": {
            "type": "integer",
            "enum": [
                1
            ],
            "x-enum-comments": {
                "RefundSourceTypeSalesReturn": "销售退货"
            },
            "x-enum-varnames": [
                "RefundSourceTypeSalesReturn"
            ]
        },
        "constvar.SalesDetailsKeywordType": {
            "type": "string",
            "enum": [
@@ -11270,6 +11282,9 @@
                    "description": "收款金额",
                    "type": "number"
                },
                "bankAccount": {
                    "$ref": "#/definitions/model.BankAccount"
                },
                "bankAccountId": {
                    "description": "账户id",
                    "type": "integer"
@@ -11289,9 +11304,20 @@
                    "description": "币种",
                    "type": "string"
                },
                "paymentType": {
                    "$ref": "#/definitions/model.PaymentType"
                },
                "paymentTypeId": {
                    "description": "收款方式ID",
                    "type": "integer"
                },
                "principal": {
                    "description": "负责人id",
                    "allOf": [
                        {
                            "$ref": "#/definitions/model.User"
                        }
                    ]
                },
                "principalId": {
                    "description": "负责人id",
@@ -11709,8 +11735,15 @@
        "model.SalesRefund": {
            "type": "object",
            "properties": {
                "accountId": {
                "bankAccount": {
                    "$ref": "#/definitions/model.BankAccount"
                },
                "bankAccountId": {
                    "description": "账户id",
                    "type": "integer"
                },
                "client": {
                    "$ref": "#/definitions/model.Client"
                },
                "clientId": {
                    "type": "integer"
@@ -11727,6 +11760,13 @@
                "number": {
                    "type": "string"
                },
                "paymentType": {
                    "$ref": "#/definitions/model.PaymentType"
                },
                "paymentTypeId": {
                    "description": "收款方式ID",
                    "type": "integer"
                },
                "products": {
                    "type": "array",
                    "items": {
@@ -11739,8 +11779,17 @@
                "refundDate": {
                    "type": "string"
                },
                "refundMethod": {
                    "type": "string"
                "sourceId": {
                    "description": "源单id",
                    "type": "integer"
                },
                "sourceType": {
                    "description": "来源类型(1销售明细单2服务合同3销售发票4收款计划5出库单)",
                    "allOf": [
                        {
                            "$ref": "#/definitions/constvar.RefundSourceType"
                        }
                    ]
                }
            }
        },
@@ -13175,6 +13224,9 @@
                    "description": "收款金额",
                    "type": "number"
                },
                "bankAccount": {
                    "$ref": "#/definitions/model.BankAccount"
                },
                "bankAccountId": {
                    "description": "账户id",
                    "type": "integer"
@@ -13194,9 +13246,20 @@
                    "description": "币种",
                    "type": "string"
                },
                "paymentType": {
                    "$ref": "#/definitions/model.PaymentType"
                },
                "paymentTypeId": {
                    "description": "收款方式ID",
                    "type": "integer"
                },
                "principal": {
                    "description": "负责人id",
                    "allOf": [
                        {
                            "$ref": "#/definitions/model.User"
                        }
                    ]
                },
                "principalId": {
                    "description": "负责人id",
@@ -14921,7 +14984,8 @@
        "request.SalesRefund": {
            "type": "object",
            "properties": {
                "accountId": {
                "bankAccountId": {
                    "description": "账户id",
                    "type": "integer"
                },
                "clientId": {
@@ -14936,6 +15000,10 @@
                "number": {
                    "type": "string"
                },
                "paymentTypeId": {
                    "description": "收款方式ID",
                    "type": "integer"
                },
                "products": {
                    "type": "array",
                    "items": {
@@ -14948,8 +15016,17 @@
                "refundDate": {
                    "type": "string"
                },
                "refundMethod": {
                    "type": "string"
                "sourceId": {
                    "description": "源单id",
                    "type": "integer"
                },
                "sourceType": {
                    "description": "来源类型(1销售明细单2服务合同3销售发票4收款计划5出库单)",
                    "allOf": [
                        {
                            "$ref": "#/definitions/constvar.RefundSourceType"
                        }
                    ]
                }
            }
        },
@@ -16055,6 +16132,9 @@
                    "description": "收款金额",
                    "type": "number"
                },
                "bankAccount": {
                    "$ref": "#/definitions/model.BankAccount"
                },
                "bankAccountId": {
                    "description": "账户id",
                    "type": "integer"
@@ -16074,10 +16154,21 @@
                    "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"
docs/swagger.yaml
@@ -142,6 +142,14 @@
    - ReceiptSourceTypeInvoice
    - ReceiptSourceTypeCollectionPlan
    - ReceiptSourceTypeChuKuDan
  constvar.RefundSourceType:
    enum:
    - 1
    type: integer
    x-enum-comments:
      RefundSourceTypeSalesReturn: 销售退货
    x-enum-varnames:
    - RefundSourceTypeSalesReturn
  constvar.SalesDetailsKeywordType:
    enum:
    - 客户名称
@@ -1002,6 +1010,8 @@
      amount:
        description: 收款金额
        type: number
      bankAccount:
        $ref: '#/definitions/model.BankAccount'
      bankAccountId:
        description: 账户id
        type: integer
@@ -1016,9 +1026,15 @@
      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
@@ -1294,8 +1310,13 @@
    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:
@@ -1306,6 +1327,11 @@
        type: integer
      number:
        type: string
      paymentType:
        $ref: '#/definitions/model.PaymentType'
      paymentTypeId:
        description: 收款方式ID
        type: integer
      products:
        items:
          $ref: '#/definitions/model.Product'
@@ -1314,8 +1340,13 @@
        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:
@@ -2283,6 +2314,8 @@
      amount:
        description: 收款金额
        type: number
      bankAccount:
        $ref: '#/definitions/model.BankAccount'
      bankAccountId:
        description: 账户id
        type: integer
@@ -2297,9 +2330,15 @@
      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
@@ -3482,7 +3521,8 @@
    type: object
  request.SalesRefund:
    properties:
      accountId:
      bankAccountId:
        description: 账户id
        type: integer
      clientId:
        type: integer
@@ -3492,6 +3532,9 @@
        type: integer
      number:
        type: string
      paymentTypeId:
        description: 收款方式ID
        type: integer
      products:
        items:
          $ref: '#/definitions/model.Product'
@@ -3500,8 +3543,13 @@
        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:
@@ -4245,6 +4293,8 @@
      amount:
        description: 收款金额
        type: number
      bankAccount:
        $ref: '#/definitions/model.BankAccount'
      bankAccountId:
        description: 账户id
        type: integer
@@ -4259,9 +4309,15 @@
      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
model/receipt.go
@@ -17,13 +17,16 @@
        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:"-"`
    }
model/request/salesRefund.go
@@ -1,21 +1,26 @@
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 {
model/salesRefund.go
@@ -1,35 +1,39 @@
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
    }
)
@@ -114,4 +118,4 @@
func (slf *SalesRefundSearch) SetOrder(order string) *SalesRefundSearch {
    slf.OrderBy = order
    return slf
}
}
pkg/ecode/code.go
@@ -214,12 +214,14 @@
    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 // 合同不存在
pkg/ecode/msg.go
@@ -23,6 +23,8 @@
    SContractProductPriceLowerThanInvoiceAmountErr:             "产品总价低于已开票金额",
    SContractProductPriceLowerThanReceivedAmountErr:            "产品总价低于已收金额",
    SContractInvoiceProductPriceGreaterThanReceivableAmountErr: "开票总额高于应收金额",
    SalesRefundProductNotExist:                                 "退货产品不存在",
    SalesRefundProductPriceOrAmountErr:                         "退货产品价格或数量错误",
}
func GetMsg(errCode int) (errMsg string) {
service/salesRefund.go
@@ -8,11 +8,36 @@
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
}
@@ -36,6 +61,15 @@
        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