From 530fed8ec225453572d57b15c200ab062c335457 Mon Sep 17 00:00:00 2001 From: zhangqian <zhangqian@123.com> Date: 星期三, 01 十一月 2023 19:20:21 +0800 Subject: [PATCH] 公海member_id使用0 --- api/v1/contract.go | 110 +++++++++++++++++++++++++++++++++++++----------------- 1 files changed, 75 insertions(+), 35 deletions(-) diff --git a/api/v1/contract.go b/api/v1/contract.go index 9d8cc67..5cfdd31 100644 --- a/api/v1/contract.go +++ b/api/v1/contract.go @@ -1,11 +1,13 @@ 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" ) @@ -33,6 +35,23 @@ return } + count, err := model.NewContractSearch().SetNumber(params.Number).Count() + if err != nil { + ctx.FailWithMsg(ecode.UnknownErr, "缂栫爜楠岃瘉澶辫触") + return + } + if count > 0 { + ctx.FailWithMsg(ecode.UnknownErr, "缂栫爜宸插瓨鍦�") + return + } + + if contract.MemberId == 0 { + userInfo := utils.GetUserInfo(c) + if userInfo.UserType == constvar.UserTypeSub { + contract.MemberId = userInfo.CrmUserId + } + } + errCode = contractService.AddContract(&contract) if errCode != ecode.OK { ctx.Fail(errCode) @@ -47,17 +66,22 @@ // @Tags Contract // @Summary 鍒犻櫎鍚堝悓 // @Produce application/json -// @Param id path int true "鏌ヨ鍙傛暟" +// @Param object body request.DeleteContract true "鏌ヨ鍙傛暟" // @Success 200 {object} contextx.Response{} -// @Router /api/contract/delete/{id} [delete] +// @Router /api/contract/delete [delete] func (s *ContractApi) Delete(c *gin.Context) { - ctx, ok := contextx.NewContext(c, nil) - if !ok { + id := c.Param("id") + ctx, _ := contextx.NewContext(c, nil) + if id == "" { + ctx.Fail(ecode.ParamsErr) return } - - id, _ := strconv.Atoi(c.Param("id")) - errCode := contractService.DeleteContract(id) + atoi, err := strconv.Atoi(id) + if err != nil { + ctx.FailWithMsg(ecode.UnknownErr, "鏁版嵁杞崲澶辫触") + return + } + errCode := contractService.DeleteContract(atoi) if errCode != ecode.OK { ctx.Fail(errCode) return @@ -87,6 +111,8 @@ return } + contract.Id = params.Id + errCode = contractService.UpdateContract(&contract) if errCode != ecode.OK { ctx.Fail(errCode) @@ -96,47 +122,61 @@ ctx.Ok() } +func checkContractParams(contract request.Contract) (errCode int, contractModel model.Contract) { + //if contract.Number == "" { + // return ecode.InvalidParams, contractModel + //} + + //if contract.MemberId == 0 { + // return ecode.InvalidParams, contractModel + //} + + contractModel = model.Contract{ + ClientId: contract.ClientId, + MemberId: contract.MemberId, + Number: contract.Number, + QuotationId: contract.QuotationId, + StatusId: contract.StatusId, + File: contract.File, + CodeStandID: contract.CodeStandID, + ContractName: contract.ContractName, + SendTime: contract.SendTime, + } + + return ecode.OK, contractModel +} + // List // // @Tags Contract -// @Summary 鑾峰彇鍚堝悓鍒楄〃 +// @Summary 閿�鍞悎鍚屽垪琛� // @Produce application/json -// @Success 200 {object} contextx.Response{data=response.ContractResponse} -// @Router /api/contract/list [get] -func (s *ContractApi) List(c *gin.Context) { - ctx, ok := contextx.NewContext(c, nil) +// @Param object body request.GetContractList true "鍙傛暟" +// @Success 200 {object} contextx.Response{data=response.ContractResponse} +// @Router /api/contract/list [post] +func (con *ContractApi) List(c *gin.Context) { + var params request.GetContractList + ctx, ok := contextx.NewContext(c, ¶ms) if !ok { return } - contractList, errCode := contractService.GetContractList() + userInfo := utils.GetUserInfo(c) + if userInfo.UserType == constvar.UserTypeSub { + if params.SearchMap == nil { + params.SearchMap = make(map[string]interface{}, 0) + } + params.SearchMap["member_ids"] = userInfo.SubUserIds + } + + contracts, total, errCode := contractService.GetContractList(params.Page, params.PageSize, params.SearchMap) if errCode != ecode.OK { ctx.Fail(errCode) return } ctx.OkWithDetailed(response.ContractResponse{ - List: contractList, + List: contracts, + Count: int(total), }) -} - -func checkContractParams(contract request.Contract) (errCode int, contractModel model.Contract) { - if contract.Number == "" { - return ecode.InvalidParams, contractModel - } - - if contract.MemberId == 0 { - return ecode.InvalidParams, contractModel - } - - contractModel = model.Contract{ - ClientId: contract.ClientId, - MemberId: contract.MemberId, - Number: contract.Number, - QuotationId: contract.QuotationId, - StatusId: contract.StatusId, - File: contract.File, - } - - return ecode.OK, contractModel } -- Gitblit v1.8.0