12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182 |
- package controllers
- import (
- "encoding/json"
- "hongze/hongze_clpt/models"
- "strconv"
- "strings"
- "time"
- )
- //优化建议
- type AdviceController struct {
- BaseAuthController
- }
- // @Title 新增优化建议
- // @Description 新增优化建议接口
- // @Param request body models.AddCygxAdviceReq true "type json string"
- // @Success Ret=200 新增成功
- // @router /add [post]
- func (this *AdviceController) ApplyApprove() {
- br := new(models.BaseResponse).Init()
- defer func() {
- this.Data["json"] = br
- this.ServeJSON()
- }()
- user := this.User
- if user == nil {
- br.Msg = "请登录"
- br.ErrMsg = "请登录,SysUser Is Empty"
- br.Ret = 408
- return
- }
- var req models.AddCygxAdviceReq
- err := json.Unmarshal(this.Ctx.Input.RequestBody, &req)
- if err != nil {
- br.Msg = "参数解析异常!"
- br.ErrMsg = "参数解析失败,Err:" + err.Error()
- return
- }
- if req.Advice == "" {
- br.Msg = "建议内容不可为空"
- return
- }
- companyDetail, err := models.GetCompanyDetailById(user.CompanyId)
- if err != nil {
- br.Msg = "新增优化建议失败!"
- br.ErrMsg = "获取客户详情失败,Err:" + err.Error()
- return
- }
- if companyDetail == nil {
- br.Msg = "新增优化建议失败!"
- br.ErrMsg = "客户不存在,uid:" + strconv.Itoa(user.UserId)
- return
- }
- var adviceImgUrl string
- for _, s := range req.AdviceImgUrl {
- adviceImgUrl += "#"+s
- }
- adviceImgUrl = strings.TrimLeft(adviceImgUrl, "#")
- item := new(models.CygxAdvice)
- item.UserId = user.UserId
- item.UserRealName = user.RealName
- item.CompanyId = user.CompanyId
- item.CompanyName = companyDetail.CompanyName
- item.SalesRealName = companyDetail.SellerName
- item.Advice = req.Advice
- item.AdviceImgUrl = adviceImgUrl
- item.CreateTime = time.Now()
- item.Mobile = user.Mobile
- item.Email = user.Email
- _, err = models.AddCygxAdvice(item)
- if err != nil {
- br.Msg = "新增优化建议失败"
- br.ErrMsg = "新增优化建议失败,Err:" + err.Error()
- return
- }
- br.Ret = 200
- br.Success = true
- br.Msg = "新增成功"
- }
|