From 115bd9b51f5d8eade4658f844de37516486c60e7 Mon Sep 17 00:00:00 2001
From: liujiandao <274878379@qq.com>
Date: 星期六, 18 十一月 2023 17:25:25 +0800
Subject: [PATCH] crm获取aps项目模块信息

---
 api/v1/contact.go |  369 ++++++++++++++++++++++++++++------------------------
 1 files changed, 197 insertions(+), 172 deletions(-)

diff --git a/api/v1/contact.go b/api/v1/contact.go
index 5530eed..97068ca 100644
--- a/api/v1/contact.go
+++ b/api/v1/contact.go
@@ -1,172 +1,197 @@
-package v1
-
-import (
-	"aps_crm/model"
-	"aps_crm/model/request"
-	"aps_crm/model/response"
-	"aps_crm/pkg/contextx"
-	"aps_crm/pkg/ecode"
-	"github.com/gin-gonic/gin"
-)
-
-type ContactApi struct{}
-
-// Add
-//
-//	@Tags		Contact
-//	@Summary	娣诲姞鑱旂郴浜�
-//	@Produce	application/json
-//	@Param		object	body		request.AddContact	true	"鏌ヨ鍙傛暟"
-//	@Success	200		{object}	contextx.Response{}
-//	@Router		/api/contact/add [post]
-func (con *ContactApi) Add(c *gin.Context) {
-	var params request.AddContact
-	ctx, ok := contextx.NewContext(c, &params)
-	if !ok {
-		return
-	}
-
-	errCode, contact := checkContactParams(params.Contact)
-	if errCode != ecode.OK {
-		ctx.Fail(errCode)
-		return
-	}
-
-	errCode = contactService.AddContact(&contact)
-	if errCode != ecode.OK {
-		ctx.Fail(errCode)
-		return
-	}
-
-	ctx.Ok()
-}
-
-// Delete
-//
-//	@Tags		Contact
-//	@Summary	鍒犻櫎鑱旂郴浜�
-//	@Produce	application/json
-//	@Param		object	body		request.DeleteContact true	"鏌ヨ鍙傛暟"
-//	@Success	200	{object}	contextx.Response{}
-//	@Router		/api/contact/delete [delete]
-func (con *ContactApi) Delete(c *gin.Context) {
-	var params request.DeleteContact
-	ctx, ok := contextx.NewContext(c, &params)
-	if !ok {
-		return
-	}
-
-	errCode := contactService.DeleteContact(params.Ids)
-	if errCode != ecode.OK {
-		ctx.Fail(errCode)
-		return
-	}
-
-	ctx.Ok()
-}
-
-// Update
-//
-//	@Tags		Contact
-//	@Summary	鏇存柊鑱旂郴浜�
-//	@Produce	application/json
-//	@Param		object	body		request.UpdateContact	true	"鏌ヨ鍙傛暟"
-//	@Success	200		{object}	contextx.Response{}
-//	@Router		/api/contact/update [put]
-func (con *ContactApi) Update(c *gin.Context) {
-	var params request.UpdateContact
-	ctx, ok := contextx.NewContext(c, &params)
-	if !ok {
-		return
-	}
-
-	// check id
-	if params.Id == 0 {
-		ctx.Fail(ecode.InvalidParams)
-		return
-	}
-
-	errCode, contact := checkContactParams(params.Contact)
-	if errCode != ecode.OK {
-		ctx.Fail(errCode)
-		return
-	}
-
-	contact.Id = params.Id
-
-	errCode = contactService.UpdateContact(&contact)
-	if errCode != ecode.OK {
-		ctx.Fail(errCode)
-		return
-	}
-
-	ctx.Ok()
-}
-
-func checkContactParams(params request.Contact) (int, model.Contact) {
-	var contact model.Contact
-	// name not empty
-	//if params.Name == "" {
-	//	return ecode.InvalidParams, contact
-	//}
-	contact.Name = params.Name
-
-	contact.Phone = params.Phone
-	contact.Email = params.Email
-
-	// check member id not -1
-	//if params.MemberId == 0 {
-	//	return ecode.InvalidParams, contact
-	//}
-	contact.MemberId = params.MemberId
-
-	contact.ProvinceId = params.ProvinceId
-	contact.CityId = params.CityId
-	contact.CountryId = params.CountryId
-	contact.RegionId = params.RegionId
-	contact.Position = params.Position
-	contact.ClientId = params.ClientId
-	contact.Desc = params.Desc
-
-	// check number not empty
-	//if params.Number == "" {
-	//	return ecode.InvalidParams, contact
-	//}
-	contact.Number = params.Number
-
-	t, err := checkTimeFormat(params.Birthday)
-	if err != nil {
-		return ecode.InvalidParams, contact
-	}
-	contact.Birthday = t
-	contact.Wechat = params.Wechat
-	contact.IsFirst = params.IsFirst
-	return ecode.OK, contact
-}
-
-// List
-//
-//	@Tags		Contact
-//	@Summary	鑱旂郴浜哄垪琛�
-//	@Produce	application/json
-//	@Param		object	body		request.GetContactList	true	"鍙傛暟"
-//	@Success	200		{object}	contextx.Response{data=response.ContactResponse}
-//	@Router		/api/contact/list [post]
-func (con *ContactApi) List(c *gin.Context) {
-	var params request.GetContactList
-	ctx, ok := contextx.NewContext(c, &params)
-	if !ok {
-		return
-	}
-
-	contacts, total, errCode := contactService.GetContactList(params.Page, params.PageSize, params.Keyword)
-	if errCode != ecode.OK {
-		ctx.Fail(errCode)
-		return
-	}
-
-	ctx.OkWithDetailed(response.ContactResponse{
-		List:  contacts,
-		Count: int(total),
-	})
-}
+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"
+)
+
+type ContactApi struct{}
+
+// Add
+//
+//	@Tags		Contact
+//	@Summary	娣诲姞鑱旂郴浜�
+//	@Produce	application/json
+//	@Param		object	body		request.AddContact	true	"鏌ヨ鍙傛暟"
+//	@Success	200		{object}	contextx.Response{}
+//	@Router		/api/contact/add [post]
+func (con *ContactApi) Add(c *gin.Context) {
+	var params request.AddContact
+	ctx, ok := contextx.NewContext(c, &params)
+	if !ok {
+		return
+	}
+
+	errCode, contact := checkContactParams(params.Contact)
+	if errCode != ecode.OK {
+		ctx.Fail(errCode)
+		return
+	}
+
+	if params.MemberId == 0 {
+		userInfo := utils.GetUserInfo(c)
+		if userInfo.UserType == constvar.UserTypeSub {
+			params.MemberId = userInfo.CrmUserId
+		}
+	}
+
+	errCode = contactService.AddContact(&contact)
+	if errCode != ecode.OK {
+		ctx.Fail(errCode)
+		return
+	}
+	//if params.CodeRule.Method == 1 {
+	//	autoCode := model.GetAutoCode(contact.Id, &params.CodeRule)
+	//	m := map[string]interface{}{
+	//		"number": autoCode,
+	//	}
+	//	_ = model.NewContactSearch(nil).SetId(contact.Id).UpdateByMap(m)
+	//}
+
+	ctx.Ok()
+}
+
+// Delete
+//
+//	@Tags		Contact
+//	@Summary	鍒犻櫎鑱旂郴浜�
+//	@Produce	application/json
+//	@Param		object	body		request.DeleteContact true	"鏌ヨ鍙傛暟"
+//	@Success	200	{object}	contextx.Response{}
+//	@Router		/api/contact/delete [delete]
+func (con *ContactApi) Delete(c *gin.Context) {
+	var params request.DeleteContact
+	ctx, ok := contextx.NewContext(c, &params)
+	if !ok {
+		return
+	}
+
+	errCode := contactService.DeleteContact(params.Ids)
+	if errCode != ecode.OK {
+		ctx.Fail(errCode)
+		return
+	}
+
+	ctx.Ok()
+}
+
+// Update
+//
+//	@Tags		Contact
+//	@Summary	鏇存柊鑱旂郴浜�
+//	@Produce	application/json
+//	@Param		object	body		request.UpdateContact	true	"鏌ヨ鍙傛暟"
+//	@Success	200		{object}	contextx.Response{}
+//	@Router		/api/contact/update [put]
+func (con *ContactApi) Update(c *gin.Context) {
+	var params request.UpdateContact
+	ctx, ok := contextx.NewContext(c, &params)
+	if !ok {
+		return
+	}
+
+	// check id
+	if params.Id == 0 {
+		ctx.Fail(ecode.InvalidParams)
+		return
+	}
+
+	errCode, contact := checkContactParams(params.Contact)
+	if errCode != ecode.OK {
+		ctx.Fail(errCode)
+		return
+	}
+
+	contact.Id = params.Id
+
+	errCode = contactService.UpdateContact(&contact)
+	if errCode != ecode.OK {
+		ctx.Fail(errCode)
+		return
+	}
+
+	ctx.Ok()
+}
+
+func checkContactParams(params request.Contact) (int, model.Contact) {
+	var contact model.Contact
+	// name not empty
+	//if params.Name == "" {
+	//	return ecode.InvalidParams, contact
+	//}
+	contact.Name = params.Name
+
+	contact.Phone = params.Phone
+	contact.Email = params.Email
+
+	// check member id not -1
+	//if params.MemberId == 0 {
+	//	return ecode.InvalidParams, contact
+	//}
+	contact.MemberId = params.MemberId
+
+	contact.ProvinceId = params.ProvinceId
+	contact.CityId = params.CityId
+	contact.CountryId = params.CountryId
+	contact.RegionId = params.RegionId
+	contact.Position = params.Position
+	contact.ClientId = params.ClientId
+	contact.Desc = params.Desc
+
+	// check number not empty
+	//if params.Number == "" {
+	//	return ecode.InvalidParams, contact
+	//}
+	contact.Number = params.Number
+
+	t, err := checkTimeFormat(params.Birthday)
+	if err != nil {
+		return ecode.InvalidParams, contact
+	}
+	contact.Birthday = t
+	contact.Wechat = params.Wechat
+	contact.IsFirst = params.IsFirst
+	//contact.CodeStandID = params.CodeStandID
+	return ecode.OK, contact
+}
+
+// List
+//
+//	@Tags		Contact
+//	@Summary	鑱旂郴浜哄垪琛�
+//	@Produce	application/json
+//	@Param		object	body		request.GetContactList	true	"鍙傛暟"
+//	@Success	200		{object}	contextx.Response{data=response.ContactResponse}
+//	@Router		/api/contact/list [post]
+func (con *ContactApi) List(c *gin.Context) {
+	var params request.GetContactList
+	ctx, ok := contextx.NewContext(c, &params)
+	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_ids"] = userInfo.SubUserIds
+	}
+
+	contacts, total, errCode := contactService.GetContactList(params.Page, params.PageSize, params.SearchMap, params.ClientId)
+	if errCode != ecode.OK {
+		ctx.Fail(errCode)
+		return
+	}
+
+	ctx.OkWithDetailed(response.ContactResponse{
+		List:  contacts,
+		Count: int(total),
+	})
+}

--
Gitblit v1.8.0