From b45b8ce8051e2ad9c80aafa42d1a5892f6a36bce Mon Sep 17 00:00:00 2001 From: zhangqian <zhangqian@123.com> Date: 星期二, 17 十月 2023 15:27:44 +0800 Subject: [PATCH] 初始化一些表shuju --- api/v1/contract.go | 178 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 files changed, 178 insertions(+), 0 deletions(-) diff --git a/api/v1/contract.go b/api/v1/contract.go index b7b1f99..8041742 100644 --- a/api/v1/contract.go +++ b/api/v1/contract.go @@ -1 +1,179 @@ 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" +) + +type ContractApi struct{} + +// Add +// +// @Tags Contract +// @Summary 娣诲姞鍚堝悓 +// @Produce application/json +// @Param object body request.AddContract true "鏌ヨ鍙傛暟" +// @Success 200 {object} contextx.Response{} +// @Router /api/contract/add [post] +func (s *ContractApi) Add(c *gin.Context) { + var params request.AddContract + ctx, ok := contextx.NewContext(c, ¶ms) + if !ok { + return + } + + errCode, contract := checkContractParams(params.Contract) + if errCode != ecode.OK { + ctx.Fail(errCode) + 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) + return + } + + if params.CodeRule.Method == 1 { + autoCode := model.GetAutoCode(contract.Id, ¶ms.CodeRule) + m := map[string]interface{}{ + "number": autoCode, + } + _ = model.NewContractSearch().SetId(contract.Id).UpdateByMap(m) + } + + ctx.Ok() +} + +// Delete +// +// @Tags Contract +// @Summary 鍒犻櫎鍚堝悓 +// @Produce application/json +// @Param object body request.DeleteContract true "鏌ヨ鍙傛暟" +// @Success 200 {object} contextx.Response{} +// @Router /api/contract/delete [delete] +func (s *ContractApi) Delete(c *gin.Context) { + id := c.Param("id") + ctx, _ := contextx.NewContext(c, nil) + if id == "" { + ctx.Fail(ecode.ParamsErr) + return + } + 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 + } + + ctx.Ok() +} + +// Update +// +// @Tags Contract +// @Summary 鏇存柊鍚堝悓 +// @Produce application/json +// @Param object body request.UpdateContract true "鏌ヨ鍙傛暟" +// @Success 200 {object} contextx.Response{} +// @Router /api/contract/update [put] +func (s *ContractApi) Update(c *gin.Context) { + var params request.UpdateContract + ctx, ok := contextx.NewContext(c, ¶ms) + if !ok { + return + } + + errCode, contract := checkContractParams(params.Contract) + if errCode != ecode.OK { + ctx.Fail(errCode) + return + } + + contract.Id = params.Id + + errCode = contractService.UpdateContract(&contract) + if errCode != ecode.OK { + ctx.Fail(errCode) + return + } + + 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, + } + + return ecode.OK, contractModel +} + +// List +// +// @Tags Contract +// @Summary 閿�鍞悎鍚屽垪琛� +// @Produce application/json +// @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 + } + + userInfo := utils.GetUserInfo(c) + if userInfo.UserType == constvar.UserTypeSub { + if params.SearchMap == nil { + params.SearchMap = make(map[string]interface{}, 0) + } + params.SearchMap["member_id"] = userInfo.CrmUserId + } + + contracts, total, errCode := contractService.GetContractList(params.Page, params.PageSize, params.SearchMap) + if errCode != ecode.OK { + ctx.Fail(errCode) + return + } + + ctx.OkWithDetailed(response.ContractResponse{ + List: contracts, + Count: int(total), + }) +} -- Gitblit v1.8.0