zhangqian
2023-11-01 530fed8ec225453572d57b15c200ab062c335457
api/v1/followRecord.go
@@ -1,11 +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"
   "errors"
   "github.com/gin-gonic/gin"
   "time"
)
@@ -31,6 +34,23 @@
   if errCode != ecode.OK {
      ctx.Fail(errCode)
      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)
@@ -166,31 +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 == "" {
      return nil, nil
   }
   location, err := time.LoadLocation("Asia/Shanghai")
   if err != nil {
      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 {
      ret := tt.In(location)
      return &ret, nil
      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 {
      ret := tt.In(location)
      return &ret, nil
      tmp := model.CustomTime(ret)
      return &tmp, nil
   }
   return nil, 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
@@ -208,6 +241,14 @@
      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
   }
   followRecords, total, errCode := followRecordService.GetFollowRecordList(params.Page, params.PageSize, params.SearchMap)
   if errCode != ecode.OK {
      ctx.Fail(errCode)