From b8bb13639cc0dafff4c4b29131dfac33be07a1cb Mon Sep 17 00:00:00 2001
From: zhangqian <zhangqian@123.com>
Date: 星期一, 16 十月 2023 14:48:37 +0800
Subject: [PATCH] aps grpc env
---
api/v1/contract.go | 101 ++++++++++++++++++++++++++++++++------------------
1 files changed, 65 insertions(+), 36 deletions(-)
diff --git a/api/v1/contract.go b/api/v1/contract.go
index 0f69384..8e05fa5 100644
--- a/api/v1/contract.go
+++ b/api/v1/contract.go
@@ -1,13 +1,14 @@
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{}
@@ -33,10 +34,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, ¶ms.CodeRule)
+ m := map[string]interface{}{
+ "number": autoCode,
+ }
+ _ = model.NewContractSearch().SetId(contract.Id).UpdateByMap(m)
}
ctx.Ok()
@@ -47,17 +63,17 @@
// @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)
+ var params request.DeleteContract
+ ctx, ok := contextx.NewContext(c, ¶ms)
if !ok {
return
}
- id, _ := strconv.Atoi(c.Param("id"))
- errCode := contractService.DeleteContract(id)
+ errCode := contractService.DeleteContract(params.Ids)
if errCode != ecode.OK {
ctx.Fail(errCode)
return
@@ -98,30 +114,6 @@
ctx.Ok()
}
-// List
-//
-// @Tags Contract
-// @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)
- if !ok {
- return
- }
-
- contractList, errCode := contractService.GetContractList()
- if errCode != ecode.OK {
- ctx.Fail(errCode)
- return
- }
-
- ctx.OkWithDetailed(response.ContractResponse{
- List: contractList,
- })
-}
-
func checkContractParams(contract request.Contract) (errCode int, contractModel model.Contract) {
//if contract.Number == "" {
// return ecode.InvalidParams, contractModel
@@ -132,13 +124,50 @@
//}
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
}
+
+// 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