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 |   59 ++++++++++++++++++++++++++++++++++++++---------------------
 1 files changed, 38 insertions(+), 21 deletions(-)

diff --git a/api/v1/contract.go b/api/v1/contract.go
index 6e432b3..5cfdd31 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,18 +35,27 @@
 		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)
 		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()
@@ -60,13 +70,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
@@ -117,13 +132,15 @@
 	//}
 
 	contractModel = model.Contract{
-		ClientId:    contract.ClientId,
-		MemberId:    contract.MemberId,
-		Number:      contract.Number,
-		QuotationId: contract.QuotationId,
-		StatusId:    contract.StatusId,
-		File:        contract.File,
-		CodeStandID: contract.CodeStandID,
+		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
@@ -149,7 +166,7 @@
 		if params.SearchMap == nil {
 			params.SearchMap = make(map[string]interface{}, 0)
 		}
-		params.SearchMap["member_id"] = userInfo.CrmUserId
+		params.SearchMap["member_ids"] = userInfo.SubUserIds
 	}
 
 	contracts, total, errCode := contractService.GetContractList(params.Page, params.PageSize, params.SearchMap)

--
Gitblit v1.8.0