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 |   45 ++++++++++++++++++++++++++++++++++-----------
 1 files changed, 34 insertions(+), 11 deletions(-)

diff --git a/api/v1/contract.go b/api/v1/contract.go
index 2d36e1b..8041742 100644
--- a/api/v1/contract.go
+++ b/api/v1/contract.go
@@ -9,6 +9,7 @@
 	"aps_crm/pkg/ecode"
 	"aps_crm/utils"
 	"github.com/gin-gonic/gin"
+	"strconv"
 )
 
 type ContractApi struct{}
@@ -34,10 +35,25 @@
 		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, &params.CodeRule)
+		m := map[string]interface{}{
+			"number": autoCode,
+		}
+		_ = model.NewContractSearch().SetId(contract.Id).UpdateByMap(m)
 	}
 
 	ctx.Ok()
@@ -52,13 +68,18 @@
 //	@Success	200	{object}	contextx.Response{}
 //	@Router		/api/contract/delete [delete]
 func (s *ContractApi) Delete(c *gin.Context) {
-	var params request.DeleteContract
-	ctx, ok := contextx.NewContext(c, &params)
-	if !ok {
+	id := c.Param("id")
+	ctx, _ := contextx.NewContext(c, nil)
+	if id == "" {
+		ctx.Fail(ecode.ParamsErr)
 		return
 	}
-
-	errCode := contractService.DeleteContract(params.Ids)
+	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
@@ -109,12 +130,14 @@
 	//}
 
 	contractModel = model.Contract{
-		ClientId:    contract.ClientId,
-		MemberId:    contract.MemberId,
-		Number:      contract.Number,
-		QuotationId: contract.QuotationId,
-		StatusId:    contract.StatusId,
-		File:        contract.File,
+		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

--
Gitblit v1.8.0