| | |
| | | package v1 |
| | | |
| | | import ( |
| | | "aps_crm/constvar" |
| | | "aps_crm/model" |
| | | "aps_crm/model/request" |
| | | "aps_crm/model/response" |
| | | "aps_crm/pkg/contextx" |
| | | "aps_crm/pkg/ecode" |
| | | "aps_crm/utils" |
| | | "github.com/gin-gonic/gin" |
| | | "strconv" |
| | | "strings" |
| | | ) |
| | | |
| | | type SalesRefundApi struct{} |
| | | |
| | | // Add |
| | | // |
| | | // @Tags SalesRefund |
| | | // @Tags 销售退款单 |
| | | // @Summary 添加销售退款 |
| | | // @Produce application/json |
| | | // @Param object body request.AddSalesRefundRequest true "查询参数" |
| | |
| | | return |
| | | } |
| | | |
| | | count, err := model.NewSalesRefundSearch().SetNumber(salesRefund.Number).Count() |
| | | if err != nil { |
| | | ctx.FailWithMsg(ecode.UnknownErr, "编码验证失败") |
| | | return |
| | | } |
| | | if count > 0 { |
| | | ctx.FailWithMsg(ecode.UnknownErr, "编码已存在") |
| | | return |
| | | } |
| | | |
| | | if salesRefund.MemberId == 0 { |
| | | userInfo := utils.GetUserInfo(c) |
| | | if userInfo.UserType == constvar.UserTypeSub { |
| | | salesRefund.MemberId = userInfo.CrmUserId |
| | | } |
| | | } |
| | | |
| | | errCode = salesRefundService.AddSalesRefund(&salesRefund) |
| | | if errCode != ecode.OK { |
| | | ctx.Fail(errCode) |
| | |
| | | |
| | | // Delete |
| | | // |
| | | // @Tags SalesRefund |
| | | // @Tags 销售退款单 |
| | | // @Summary 删除销售退款 |
| | | // @Produce application/json |
| | | // @Param id path int true "查询参数" |
| | |
| | | ctx.Ok() |
| | | } |
| | | |
| | | // BatchDelete |
| | | // @Tags 销售退款单 |
| | | // @Summary 批量删除销售退款单 |
| | | // @Produce application/json |
| | | // @Param object body request.CommonIds true "参数" |
| | | // @Success 200 {object} contextx.Response{} |
| | | // @Router /api/salesRefund/delete [delete] |
| | | func (s *SalesRefundApi) BatchDelete(c *gin.Context) { |
| | | var params request.CommonIds |
| | | ctx, ok := contextx.NewContext(c, ¶ms) |
| | | if !ok { |
| | | return |
| | | } |
| | | |
| | | failIds, _ := salesRefundService.BatchDeleteSalesRefund(params.Ids) |
| | | if len(failIds) == 0 { |
| | | ctx.Ok() |
| | | return |
| | | } |
| | | salesReturns, code := salesRefundService.GetSalesRefundListByIds(failIds) |
| | | if code != ecode.OK { |
| | | ctx.Ok() |
| | | return |
| | | } |
| | | var numbers []string |
| | | for _, salesReturn := range salesReturns { |
| | | numbers = append(numbers, salesReturn.Number) |
| | | } |
| | | ctx.FailWithMsg(ecode.DBErr, strings.Join(numbers, ",")+"删除失败") |
| | | } |
| | | |
| | | // Update |
| | | // |
| | | // @Tags SalesRefund |
| | | // @Tags 销售退款单 |
| | | // @Summary 更新销售退款 |
| | | // @Produce application/json |
| | | // @Param object body request.UpdateSalesRefundRequest true "查询参数" |
| | |
| | | salesRefundRes.IsInvoice = salesRefund.IsInvoice |
| | | salesRefundRes.Reason = salesRefund.Reason |
| | | salesRefundRes.Products = salesRefund.Products |
| | | salesRefundRes.SourceType = salesRefund.SourceType |
| | | salesRefundRes.SalesReturnId = salesRefund.SourceId |
| | | salesRefundRes.CodeStandID = salesRefund.CodeStandID |
| | | |
| | | return ecode.OK, salesRefundRes |
| | | } |
| | | |
| | | // List |
| | | // |
| | | // @Tags SalesRefund |
| | | // @Tags 销售退款单 |
| | | // @Summary 销售退款单列表 |
| | | // @Produce application/json |
| | | // @Param object body request.GetSalesRefundList true "参数" |
| | |
| | | return |
| | | } |
| | | |
| | | salesRefunds, total, errCode := salesRefundService.GetSalesRefundList(params.Page, params.PageSize, params.KeywordType, params.Keyword) |
| | | var memberIds []int |
| | | userInfo := utils.GetUserInfo(c) |
| | | if userInfo.UserType == constvar.UserTypeSub { |
| | | memberIds = userInfo.SubUserIds |
| | | } |
| | | |
| | | salesRefunds, total, errCode := salesRefundService.GetSalesRefundList(params.Page, params.PageSize, params.KeywordType, params.Keyword, params.SourceId, memberIds) |
| | | if errCode != ecode.OK { |
| | | ctx.Fail(errCode) |
| | | return |