From d4bf53dd19a45ef09a367babcf7a2ac04ae1d08f Mon Sep 17 00:00:00 2001 From: liujiandao <274878379@qq.com> Date: 星期二, 17 十月 2023 14:31:31 +0800 Subject: [PATCH] bug修改 --- api/v1/salesReturn.go | 74 +++++++++++++++++++++++-------------- 1 files changed, 46 insertions(+), 28 deletions(-) diff --git a/api/v1/salesReturn.go b/api/v1/salesReturn.go index caa7150..bf1fdbd 100644 --- a/api/v1/salesReturn.go +++ b/api/v1/salesReturn.go @@ -1,13 +1,17 @@ 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/pkg/structx" + "aps_crm/utils" "github.com/gin-gonic/gin" "strconv" + "strings" ) type SalesReturnApi struct{} @@ -33,10 +37,25 @@ return } + if salesReturn.MemberId == 0 { + userInfo := utils.GetUserInfo(c) + if userInfo.UserType == constvar.UserTypeSub { + salesReturn.MemberId = userInfo.CrmUserId + } + } + errCode = salesReturnService.AddSalesReturn(&salesReturn) if errCode != ecode.OK { ctx.Fail(errCode) return + } + + if params.SalesReturn.CodeRule.Method == 1 { + autoCode := model.GetAutoCode(salesReturn.Id, ¶ms.SalesReturn.CodeRule) + m := map[string]interface{}{ + "number": autoCode, + } + _ = model.NewSalesReturnSearch().SetId(salesReturn.Id).UpdateByMap(m) } ctx.Ok() @@ -79,14 +98,21 @@ if !ok { return } - - errCode := salesReturnService.BatchDeleteSalesReturn(params.Ids) - if errCode != ecode.OK { - ctx.Fail(errCode) + failIds, _ := salesReturnService.BatchDeleteSalesReturn(params.Ids) + if len(failIds) == 0 { + ctx.Ok() return } - - ctx.Ok() + salesReturns, code := salesReturnService.GetSalesReturnListByIds(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 @@ -123,26 +149,10 @@ } func checkSalesReturnParams(salesReturn request.SalesReturn) (errCode int, s model.SalesReturn) { - //if salesReturn.Number == "" { - // return ecode.InvalidParams, s - //} - // - //if salesReturn.Repository == "" { - // return ecode.InvalidParams, s - //} - // - //if salesReturn.MemberId == 0 { - // return ecode.InvalidParams, s - //} - - s.ClientId = salesReturn.ClientId - s.ReturnDate = salesReturn.ReturnDate - s.Number = salesReturn.Number - s.Repository = salesReturn.Repository - s.MemberId = salesReturn.MemberId - s.SalesReturnStatusId = salesReturn.SalesReturnStatusId - s.Reason = salesReturn.Reason - s.Products = salesReturn.Products + err := structx.AssignTo(salesReturn, &s) + if err != nil { + return ecode.ParamsErr, s + } return ecode.OK, s } @@ -152,7 +162,9 @@ // @Tags 閿�鍞��璐у崟 // @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) { @@ -162,7 +174,13 @@ return } - salesReturns, total, errCode := salesReturnService.GetSalesReturnList(params.Page, params.PageSize, params.Keyword) + var memberIds []int + userInfo := utils.GetUserInfo(c) + if userInfo.UserType == constvar.UserTypeSub { + memberIds = []int{userInfo.CrmUserId} + } + + salesReturns, total, errCode := salesReturnService.GetSalesReturnList(params, memberIds) if errCode != ecode.OK { ctx.Fail(errCode) return -- Gitblit v1.8.0