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 ServiceFollowupApi struct{} // Add // // @Tags ServiceFollowup // @Summary 添加服务跟进 // @Produce application/json // @Param object body request.AddServiceFollowup true "查询参数" // @Success 200 {object} contextx.Response{} // @Router /api/serviceFollowup/add [post] func (s *ServiceFollowupApi) Add(c *gin.Context) { var params request.AddServiceFollowup ctx, ok := contextx.NewContext(c, ¶ms) if !ok { return } if params.MemberId == 0 { userInfo := utils.GetUserInfo(c) if userInfo.UserType == constvar.UserTypeSub { params.MemberId = userInfo.CrmUserId } } errCode, serviceFollowup := checkServiceFollowupParams(params.ServiceFollowup) if errCode != ecode.OK { ctx.Fail(errCode) return } count, err := model.NewServiceFollowupSearch().SetNumber(serviceFollowup.Number).Count() if err != nil { ctx.FailWithMsg(ecode.UnknownErr, "编码验证失败") return } if count > 0 { ctx.FailWithMsg(ecode.UnknownErr, "编码已存在") return } errCode = serviceFollowupService.AddServiceFollowup(&serviceFollowup) if errCode != ecode.OK { ctx.Fail(errCode) return } ctx.Ok() } // Delete // // @Tags ServiceFollowup // @Summary 删除服务跟进 // @Produce application/json // @Param object body request.DeleteServiceFollowup true "查询参数" // @Success 200 {object} contextx.Response{} // @Router /api/serviceFollowup/delete [delete] func (s *ServiceFollowupApi) Delete(c *gin.Context) { var params request.DeleteServiceFollowup ctx, ok := contextx.NewContext(c, ¶ms) if !ok { return } errCode := serviceFollowupService.DeleteServiceFollowup(params.Ids) if errCode != ecode.OK { ctx.Fail(errCode) return } ctx.Ok() } // Update // // @Tags ServiceFollowup // @Summary 更新服务跟进 // @Produce application/json // @Param object body request.UpdateServiceFollowup true "查询参数" // @Success 200 {object} contextx.Response{} // @Router /api/serviceFollowup/update [put] func (s *ServiceFollowupApi) Update(c *gin.Context) { var params request.UpdateServiceFollowup ctx, ok := contextx.NewContext(c, ¶ms) if !ok { return } errCode, serviceFollowup := checkServiceFollowupParams(params.ServiceFollowup) if errCode != ecode.OK { ctx.Fail(errCode) return } serviceFollowup.Id = params.Id errCode = serviceFollowupService.UpdateServiceFollowup(&serviceFollowup) if errCode != ecode.OK { ctx.Fail(errCode) return } ctx.Ok() } // checkServiceFollowupParams func checkServiceFollowupParams(serviceFollowup request.ServiceFollowup) (errCode int, serviceFollowupModel model.ServiceFollowup) { //if serviceFollowup.Number == "" { // return ecode.InvalidParams, serviceFollowupModel //} // //if serviceFollowup.MemberId == 0 { // return ecode.InvalidParams, serviceFollowupModel //} serviceFollowupModel = model.ServiceFollowup{ ClientId: serviceFollowup.ClientId, Number: serviceFollowup.Number, ContactId: serviceFollowup.ContactId, ServiceOrderId: serviceFollowup.ServiceOrderId, MemberId: serviceFollowup.MemberId, PlanId: serviceFollowup.PlanId, SatisfactionId: serviceFollowup.Satisfaction, TimelyRateId: serviceFollowup.TimelyRate, SolveRateId: serviceFollowup.SolveRate, IsVisitId: serviceFollowup.IsVisit, OldMemberId: serviceFollowup.OldMemberId, Remark: serviceFollowup.Remark, File: serviceFollowup.File, CodeStandID: serviceFollowup.CodeStandID, } return ecode.OK, serviceFollowupModel } // List // // @Tags ServiceFollowup // @Summary 回访单管理列表 // @Produce application/json // @Param object body request.GetServiceFollowupList true "参数" // // @Success 200 {object} contextx.Response{data=response.ServiceFollowupResponse} // // @Router /api/serviceFollowup/list [post] func (con *ServiceFollowupApi) List(c *gin.Context) { var params request.GetServiceFollowupList ctx, ok := contextx.NewContext(c, ¶ms) if !ok { return } var memberIds []int userInfo := utils.GetUserInfo(c) if userInfo.UserType == constvar.UserTypeSub { memberIds = userInfo.SubUserIds } serviceFollowups, total, errCode := serviceFollowupService.GetServiceFollowupList(params.Page, params.PageSize, params.KeywordType, params.Keyword, params.ServiceOrderId, memberIds) if errCode != ecode.OK { ctx.Fail(errCode) return } ctx.OkWithDetailed(response.ServiceFollowupResponse{ List: serviceFollowups, Count: int(total), }) }