From 2030ec81f18f4ec9ea1800f13046acafff6d50f7 Mon Sep 17 00:00:00 2001
From: yinbentan <yinbentan@live.com>
Date: 星期四, 26 九月 2024 00:48:59 +0800
Subject: [PATCH] 添加grpc方法:客户信息维护

---
 api/v1/followRecord.go |   70 +++++++++++++++++++++++++++--------
 1 files changed, 54 insertions(+), 16 deletions(-)

diff --git a/api/v1/followRecord.go b/api/v1/followRecord.go
index e6c2f4c..666ea35 100644
--- a/api/v1/followRecord.go
+++ b/api/v1/followRecord.go
@@ -1,13 +1,15 @@
 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"
+	"errors"
 	"github.com/gin-gonic/gin"
-	"strconv"
 	"time"
 )
 
@@ -34,6 +36,23 @@
 		return
 	}
 
+	count, err := model.NewFollowRecordSearch().SetNumber(followRecord.Number).Count()
+	if err != nil {
+		ctx.FailWithMsg(ecode.UnknownErr, "缂栫爜楠岃瘉澶辫触")
+		return
+	}
+	if count > 0 {
+		ctx.FailWithMsg(ecode.UnknownErr, "缂栫爜宸插瓨鍦�")
+		return
+	}
+
+	if followRecord.MemberId == 0 {
+		userInfo := utils.GetUserInfo(c)
+		if userInfo.UserType == constvar.UserTypeSub {
+			followRecord.MemberId = userInfo.CrmUserId
+		}
+	}
+
 	errCode = followRecordService.AddFollowRecord(followRecord)
 	if errCode != ecode.OK {
 		ctx.Fail(errCode)
@@ -48,17 +67,17 @@
 //	@Tags		FollowRecord
 //	@Summary	鍒犻櫎璺熻繘璁板綍
 //	@Produce	application/json
-//	@Param		id	path		string	true	"璺熻繘璁板綍id"
+//	@Param		object	body		request.DeleteFollowRecord true	"鏌ヨ鍙傛暟"
 //	@Success	200	{object}	contextx.Response{}
-//	@Router		/api/followRecord/delete/{id} [delete]
+//	@Router		/api/followRecord/delete [delete]
 func (fr *FollowRecordApi) Delete(c *gin.Context) {
-	ctx, ok := contextx.NewContext(c, nil)
+	var params request.DeleteFollowRecord
+	ctx, ok := contextx.NewContext(c, &params)
 	if !ok {
 		return
 	}
 
-	id, _ := strconv.Atoi(c.Param("id"))
-	errCode := followRecordService.DeleteFollowRecord(id)
+	errCode := followRecordService.DeleteFollowRecord(params.Ids)
 	if errCode != ecode.OK {
 		ctx.Fail(errCode)
 		return
@@ -167,33 +186,44 @@
 	followRecordModel.Purpose = followRecord.Purpose
 	followRecordModel.Content = followRecord.Content
 	followRecordModel.Record = followRecord.Record
+	followRecordModel.CodeStandID = followRecord.CodeStandID
 
 	return ecode.OK, &followRecordModel
 }
 
 // checkTimeFormat
 // 妫�鏌ユ椂闂存牸寮�
-func checkTimeFormat(t string) (time.Time, error) {
+func checkTimeFormat(t string) (*model.CustomTime, error) {
 	if t == "" {
-		t = "1900-01-01T00:00:00+08:00"
+		return nil, nil
 	}
 
 	location, err := time.LoadLocation("Asia/Shanghai")
 	if err != nil {
-		return time.Time{}, err
+		return nil, err
 	}
 
-	tt, err := time.Parse("2006-01-02T15:04:05.000Z", t)
+	tt, err := time.Parse("2006-01-02", t)
 	if err == nil {
-		return tt.In(location), nil
+		ret := tt.In(location)
+		tmp := model.CustomTime(ret)
+		return &tmp, nil
 	}
 
-	tt, err = time.Parse("2006-01-02T15:04:05-07:00", t)
+	tt, err = time.Parse("2006-01-02 15:04:05", t)
 	if err == nil {
-		return tt.In(location), nil
+		ret := tt.In(location)
+		tmp := model.CustomTime(ret)
+		return &tmp, nil
 	}
 
-	return time.Time{}, err
+	//tt, err = time.Parse("2006-01-02T15:04:05-07:00", t)
+	//if err == nil {
+	//	ret := tt.In(location)
+	//	return &ret, nil
+	//}
+
+	return nil, errors.New("invalid time format")
 }
 
 // List
@@ -211,7 +241,15 @@
 		return
 	}
 
-	followRecords, total, errCode := followRecordService.GetFollowRecordList(params.Page, params.PageSize, params.Keyword)
+	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
+	}
+
+	followRecords, total, errCode := followRecordService.GetFollowRecordList(params.Page, params.PageSize, params.SearchMap)
 	if errCode != ecode.OK {
 		ctx.Fail(errCode)
 		return
@@ -221,4 +259,4 @@
 		List:  followRecords,
 		Count: int(total),
 	})
-}
\ No newline at end of file
+}

--
Gitblit v1.8.0