| | |
| | | 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"
|
| | | "time"
|
| | | )
|
| | |
|
| | | type FollowRecordApi struct{}
|
| | |
|
| | | // Add
|
| | | //
|
| | | // @Tags FollowRecord
|
| | | // @Summary 添加跟进记录
|
| | | // @Produce application/json
|
| | | // @Param object body request.AddFollowRecord true "查询参数"
|
| | | // @Success 200 {object} contextx.Response{}
|
| | | // @Router /api/followRecord/add [post]
|
| | | func (fr *FollowRecordApi) Add(c *gin.Context) {
|
| | | var params request.AddFollowRecord
|
| | | ctx, ok := contextx.NewContext(c, ¶ms)
|
| | | if !ok {
|
| | | return
|
| | | }
|
| | |
|
| | | errCode, followRecord := checkFollowRecordParams(params.FollowRecord)
|
| | | if errCode != ecode.OK {
|
| | | ctx.Fail(errCode)
|
| | | return
|
| | | }
|
| | |
|
| | | errCode = followRecordService.AddFollowRecord(followRecord)
|
| | | if errCode != ecode.OK {
|
| | | ctx.Fail(errCode)
|
| | | return
|
| | | }
|
| | |
|
| | | ctx.Ok()
|
| | | }
|
| | |
|
| | | // Delete
|
| | | //
|
| | | // @Tags FollowRecord
|
| | | // @Summary 删除跟进记录
|
| | | // @Produce application/json
|
| | | // @Param object body request.DeleteFollowRecord true "查询参数"
|
| | | // @Success 200 {object} contextx.Response{}
|
| | | // @Router /api/followRecord/delete [delete]
|
| | | func (fr *FollowRecordApi) Delete(c *gin.Context) {
|
| | | var params request.DeleteFollowRecord
|
| | | ctx, ok := contextx.NewContext(c, ¶ms)
|
| | | if !ok {
|
| | | return
|
| | | }
|
| | |
|
| | | errCode := followRecordService.DeleteFollowRecord(params.Ids)
|
| | | if errCode != ecode.OK {
|
| | | ctx.Fail(errCode)
|
| | | return
|
| | | }
|
| | |
|
| | | ctx.Ok()
|
| | | }
|
| | |
|
| | | // Update
|
| | | //
|
| | | // @Tags FollowRecord
|
| | | // @Summary 更新跟进记录
|
| | | // @Produce application/json
|
| | | // @Param object body request.UpdateFollowRecord true "查询参数"
|
| | | // @Success 200 {object} contextx.Response{}
|
| | | // @Router /api/followRecord/update [put]
|
| | | func (fr *FollowRecordApi) Update(c *gin.Context) {
|
| | | var params request.UpdateFollowRecord
|
| | | ctx, ok := contextx.NewContext(c, ¶ms)
|
| | | if !ok {
|
| | | return
|
| | | }
|
| | |
|
| | | errCode, followRecord := checkFollowRecordParams(params.FollowRecord)
|
| | | if errCode != ecode.OK {
|
| | | ctx.Fail(errCode)
|
| | | return
|
| | | }
|
| | |
|
| | | followRecord.Id = params.Id
|
| | | errCode = followRecordService.UpdateFollowRecord(followRecord)
|
| | | if errCode != ecode.OK {
|
| | | ctx.Fail(errCode)
|
| | | return
|
| | | }
|
| | |
|
| | | ctx.Ok()
|
| | | }
|
| | |
|
| | | // checkFollowRecordParams
|
| | | // 检查跟进记录参数
|
| | | func checkFollowRecordParams(followRecord request.FollowRecord) (int, *model.FollowRecord) {
|
| | | var followRecordModel model.FollowRecord
|
| | |
|
| | | //if followRecord.ClientId != 0 {
|
| | | // // check client exist
|
| | | // if service.CheckClientExist(followRecord.ClientId) != ecode.OK {
|
| | | // return ecode.ClientNotExist, &followRecordModel
|
| | | // }
|
| | | //}
|
| | | //
|
| | | //if followRecord.ContactId != 0 {
|
| | | // // check contact exist
|
| | | // if service.CheckContactExist(followRecord.ContactId) != ecode.OK {
|
| | | // return ecode.ContactNotExist, &followRecordModel
|
| | | // }
|
| | | //}
|
| | | //
|
| | | //if followRecord.SalesLeadsId != 0 {
|
| | | // // check sales leads exist
|
| | | // if service.CheckSalesLeadsExist(followRecord.SalesLeadsId) != ecode.OK {
|
| | | // return ecode.SalesLeadsNotExist, &followRecordModel
|
| | | // }
|
| | | //}
|
| | | //
|
| | | //// check member id
|
| | | //if followRecord.MemberId == 0 {
|
| | | // // todo check member exist
|
| | | // return ecode.InvalidParams, &followRecordModel
|
| | | //}
|
| | | //
|
| | | //// check number
|
| | | //if followRecord.Number == "" {
|
| | | // return ecode.InvalidParams, &followRecordModel
|
| | | //}
|
| | | //
|
| | | //// check follow content
|
| | | //if followRecord.Content == "" {
|
| | | // return ecode.InvalidParams, &followRecordModel
|
| | | //}
|
| | |
|
| | | // check follow time
|
| | | t, err := checkTimeFormat(followRecord.FollowTime)
|
| | | if err != nil {
|
| | | return ecode.InvalidParams, &followRecordModel
|
| | | }
|
| | |
|
| | | followRecordModel.FollowTime = t
|
| | |
|
| | | t, err = checkTimeFormat(followRecord.NextFollowTime)
|
| | | if err != nil {
|
| | | return ecode.InvalidParams, &followRecordModel
|
| | | }
|
| | | followRecordModel.NextFollowTime = t
|
| | |
|
| | | followRecordModel.ClientId = followRecord.ClientId
|
| | | followRecordModel.Content = followRecord.Content
|
| | | followRecordModel.MemberId = followRecord.MemberId
|
| | | followRecordModel.Number = followRecord.Number
|
| | | followRecordModel.ClientStatusId = followRecord.ClientStatusId
|
| | | followRecordModel.ContactId = followRecord.ContactId
|
| | | followRecordModel.Topic = followRecord.Topic
|
| | | followRecordModel.SalesLeadsId = followRecord.SalesLeadsId
|
| | | followRecordModel.SaleChanceId = followRecord.SaleChanceId
|
| | | followRecordModel.ContactInformationId = followRecord.ContactInformationId
|
| | | followRecordModel.Purpose = followRecord.Purpose
|
| | | followRecordModel.Content = followRecord.Content
|
| | | followRecordModel.Record = followRecord.Record
|
| | |
|
| | | return ecode.OK, &followRecordModel
|
| | | }
|
| | |
|
| | | // checkTimeFormat
|
| | | // 检查时间格式
|
| | | func checkTimeFormat(t string) (time.Time, error) {
|
| | | if t == "" {
|
| | | t = "1900-01-01T00:00:00+08:00"
|
| | | }
|
| | |
|
| | | location, err := time.LoadLocation("Asia/Shanghai")
|
| | | if err != nil {
|
| | | return time.Time{}, err
|
| | | }
|
| | |
|
| | | tt, err := time.Parse("2006-01-02T15:04:05.000Z", t)
|
| | | if err == nil {
|
| | | return tt.In(location), nil
|
| | | }
|
| | |
|
| | | tt, err = time.Parse("2006-01-02T15:04:05-07:00", t)
|
| | | if err == nil {
|
| | | return tt.In(location), nil
|
| | | }
|
| | |
|
| | | return time.Time{}, err
|
| | | }
|
| | |
|
| | | // List
|
| | | //
|
| | | // @Tags FollowRecord
|
| | | // @Summary 回访记录列表
|
| | | // @Produce application/json
|
| | | // @Param object body request.GetFollowRecordList true "参数"
|
| | | // @Success 200 {object} contextx.Response{data=response.FollowRecordResponse}
|
| | | // @Router /api/followRecord/list [post]
|
| | | func (fr *FollowRecordApi) List(c *gin.Context) {
|
| | | var params request.GetFollowRecordList
|
| | | ctx, ok := contextx.NewContext(c, ¶ms)
|
| | | if !ok {
|
| | | return
|
| | | }
|
| | |
|
| | | followRecords, total, errCode := followRecordService.GetFollowRecordList(params.Page, params.PageSize, params.Keyword)
|
| | | if errCode != ecode.OK {
|
| | | ctx.Fail(errCode)
|
| | | return
|
| | | }
|
| | |
|
| | | ctx.OkWithDetailed(response.FollowRecordResponse{
|
| | | List: followRecords,
|
| | | Count: int(total),
|
| | | })
|
| | | }
|
| | | 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" |
| | | "time" |
| | | ) |
| | | |
| | | type FollowRecordApi struct{} |
| | | |
| | | // Add |
| | | // |
| | | // @Tags FollowRecord |
| | | // @Summary 添加跟进记录 |
| | | // @Produce application/json |
| | | // @Param object body request.AddFollowRecord true "查询参数" |
| | | // @Success 200 {object} contextx.Response{} |
| | | // @Router /api/followRecord/add [post] |
| | | func (fr *FollowRecordApi) Add(c *gin.Context) { |
| | | var params request.AddFollowRecord |
| | | ctx, ok := contextx.NewContext(c, ¶ms) |
| | | if !ok { |
| | | return |
| | | } |
| | | |
| | | errCode, followRecord := checkFollowRecordParams(params.FollowRecord) |
| | | if errCode != ecode.OK { |
| | | ctx.Fail(errCode) |
| | | return |
| | | } |
| | | |
| | | errCode = followRecordService.AddFollowRecord(followRecord) |
| | | if errCode != ecode.OK { |
| | | ctx.Fail(errCode) |
| | | return |
| | | } |
| | | |
| | | ctx.Ok() |
| | | } |
| | | |
| | | // Delete |
| | | // |
| | | // @Tags FollowRecord |
| | | // @Summary 删除跟进记录 |
| | | // @Produce application/json |
| | | // @Param object body request.DeleteFollowRecord true "查询参数" |
| | | // @Success 200 {object} contextx.Response{} |
| | | // @Router /api/followRecord/delete [delete] |
| | | func (fr *FollowRecordApi) Delete(c *gin.Context) { |
| | | var params request.DeleteFollowRecord |
| | | ctx, ok := contextx.NewContext(c, ¶ms) |
| | | if !ok { |
| | | return |
| | | } |
| | | |
| | | errCode := followRecordService.DeleteFollowRecord(params.Ids) |
| | | if errCode != ecode.OK { |
| | | ctx.Fail(errCode) |
| | | return |
| | | } |
| | | |
| | | ctx.Ok() |
| | | } |
| | | |
| | | // Update |
| | | // |
| | | // @Tags FollowRecord |
| | | // @Summary 更新跟进记录 |
| | | // @Produce application/json |
| | | // @Param object body request.UpdateFollowRecord true "查询参数" |
| | | // @Success 200 {object} contextx.Response{} |
| | | // @Router /api/followRecord/update [put] |
| | | func (fr *FollowRecordApi) Update(c *gin.Context) { |
| | | var params request.UpdateFollowRecord |
| | | ctx, ok := contextx.NewContext(c, ¶ms) |
| | | if !ok { |
| | | return |
| | | } |
| | | |
| | | errCode, followRecord := checkFollowRecordParams(params.FollowRecord) |
| | | if errCode != ecode.OK { |
| | | ctx.Fail(errCode) |
| | | return |
| | | } |
| | | |
| | | followRecord.Id = params.Id |
| | | errCode = followRecordService.UpdateFollowRecord(followRecord) |
| | | if errCode != ecode.OK { |
| | | ctx.Fail(errCode) |
| | | return |
| | | } |
| | | |
| | | ctx.Ok() |
| | | } |
| | | |
| | | // checkFollowRecordParams |
| | | // 检查跟进记录参数 |
| | | func checkFollowRecordParams(followRecord request.FollowRecord) (int, *model.FollowRecord) { |
| | | var followRecordModel model.FollowRecord |
| | | |
| | | //if followRecord.ClientId != 0 { |
| | | // // check client exist |
| | | // if service.CheckClientExist(followRecord.ClientId) != ecode.OK { |
| | | // return ecode.ClientNotExist, &followRecordModel |
| | | // } |
| | | //} |
| | | // |
| | | //if followRecord.ContactId != 0 { |
| | | // // check contact exist |
| | | // if service.CheckContactExist(followRecord.ContactId) != ecode.OK { |
| | | // return ecode.ContactNotExist, &followRecordModel |
| | | // } |
| | | //} |
| | | // |
| | | //if followRecord.SalesLeadsId != 0 { |
| | | // // check sales leads exist |
| | | // if service.CheckSalesLeadsExist(followRecord.SalesLeadsId) != ecode.OK { |
| | | // return ecode.SalesLeadsNotExist, &followRecordModel |
| | | // } |
| | | //} |
| | | // |
| | | //// check member id |
| | | //if followRecord.MemberId == 0 { |
| | | // // todo check member exist |
| | | // return ecode.InvalidParams, &followRecordModel |
| | | //} |
| | | // |
| | | //// check number |
| | | //if followRecord.Number == "" { |
| | | // return ecode.InvalidParams, &followRecordModel |
| | | //} |
| | | // |
| | | //// check follow content |
| | | //if followRecord.Content == "" { |
| | | // return ecode.InvalidParams, &followRecordModel |
| | | //} |
| | | |
| | | // check follow time |
| | | t, err := checkTimeFormat(followRecord.FollowTime) |
| | | if err != nil { |
| | | return ecode.InvalidParams, &followRecordModel |
| | | } |
| | | |
| | | followRecordModel.FollowTime = t |
| | | |
| | | t, err = checkTimeFormat(followRecord.NextFollowTime) |
| | | if err != nil { |
| | | return ecode.InvalidParams, &followRecordModel |
| | | } |
| | | followRecordModel.NextFollowTime = t |
| | | |
| | | followRecordModel.ClientId = followRecord.ClientId |
| | | followRecordModel.Content = followRecord.Content |
| | | followRecordModel.MemberId = followRecord.MemberId |
| | | followRecordModel.Number = followRecord.Number |
| | | followRecordModel.ClientStatusId = followRecord.ClientStatusId |
| | | followRecordModel.ContactId = followRecord.ContactId |
| | | followRecordModel.Topic = followRecord.Topic |
| | | followRecordModel.SalesLeadsId = followRecord.SalesLeadsId |
| | | followRecordModel.SaleChanceId = followRecord.SaleChanceId |
| | | followRecordModel.ContactInformationId = followRecord.ContactInformationId |
| | | followRecordModel.Purpose = followRecord.Purpose |
| | | followRecordModel.Content = followRecord.Content |
| | | followRecordModel.Record = followRecord.Record |
| | | |
| | | return ecode.OK, &followRecordModel |
| | | } |
| | | |
| | | // checkTimeFormat |
| | | // 检查时间格式 |
| | | func checkTimeFormat(t string) (time.Time, error) { |
| | | if t == "" { |
| | | t = "1900-01-01T00:00:00+08:00" |
| | | } |
| | | |
| | | location, err := time.LoadLocation("Asia/Shanghai") |
| | | if err != nil { |
| | | return time.Time{}, err |
| | | } |
| | | |
| | | tt, err := time.Parse("2006-01-02T15:04:05.000Z", t) |
| | | if err == nil { |
| | | return tt.In(location), nil |
| | | } |
| | | |
| | | tt, err = time.Parse("2006-01-02T15:04:05-07:00", t) |
| | | if err == nil { |
| | | return tt.In(location), nil |
| | | } |
| | | |
| | | return time.Time{}, err |
| | | } |
| | | |
| | | // List |
| | | // |
| | | // @Tags FollowRecord |
| | | // @Summary 回访记录列表 |
| | | // @Produce application/json |
| | | // @Param object body request.GetFollowRecordList true "参数" |
| | | // @Success 200 {object} contextx.Response{data=response.FollowRecordResponse} |
| | | // @Router /api/followRecord/list [post] |
| | | func (fr *FollowRecordApi) List(c *gin.Context) { |
| | | var params request.GetFollowRecordList |
| | | ctx, ok := contextx.NewContext(c, ¶ms) |
| | | if !ok { |
| | | return |
| | | } |
| | | |
| | | followRecords, total, errCode := followRecordService.GetFollowRecordList(params.Page, params.PageSize, params.SearchMap) |
| | | if errCode != ecode.OK { |
| | | ctx.Fail(errCode) |
| | | return |
| | | } |
| | | |
| | | ctx.OkWithDetailed(response.FollowRecordResponse{ |
| | | List: followRecords, |
| | | Count: int(total), |
| | | }) |
| | | } |