123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157 |
- package controllers
- import (
- "encoding/json"
- "hongze/hongze_cygxzs/models"
- "hongze/hongze_cygxzs/utils"
- "time"
- )
- type UserController struct {
- BaseAuthController
- }
- type UserCommonController struct {
- BaseCommonController
- }
- // @Title 获取用户的选择详情
- // @Description 获取用户的选择详情接口
- // @Success 200 {object} models.CygxXzsChooseSendResp
- // @router /choose/detail [get]
- func (this *UserController) ChooseDetail() {
- br := new(models.BaseResponse).Init()
- defer func() {
- this.Data["json"] = br
- this.ServeJSON()
- }()
- user := this.User
- if user == nil {
- br.Msg = "请登录"
- br.ErrMsg = "请登录,用户信息为空"
- br.Ret = 408
- return
- }
- mobile := user.Mobile
- mapIndustrial := make(map[int][]*models.IndustrialManagementRep)
- mapFllow := make(map[int]int)
- fllowList, err := models.GetCygxIndustryFllowList(mobile)
- if err != nil && err.Error() != utils.ErrNoRow() {
- br.Msg = "获取信息失败"
- br.ErrMsg = "获取客户信息失败,Err:" + err.Error()
- return
- }
- for _, v := range fllowList {
- mapFllow[v.IndustrialManagementId] = v.IndustrialManagementId
- }
- industrialList, err := models.GetindustrialManagement()
- if err != nil {
- br.Msg = "获取信息失败"
- br.ErrMsg = "获取产业信息失败,Err:" + err.Error()
- return
- }
- for _, v := range industrialList {
- if mapFllow[v.IndustrialManagementId] > 0 {
- v.IsFllow = true
- }
- mapIndustrial[v.ChartPermissionId] = append(mapIndustrial[v.ChartPermissionId], v)
- }
- permissionList, err := models.GetChartPermissionAll("")
- if err != nil {
- br.Msg = "获取信息失败"
- br.ErrMsg = "获取产业信息失败,Err:" + err.Error()
- return
- }
- for k, v := range permissionList {
- permissionList[k].List = mapIndustrial[v.ChartPermissionId]
- }
- count, err := models.GetXzsChooseSendCountByMobile(mobile)
- if err != nil {
- br.Msg = "获取信息失败"
- br.ErrMsg = "GetXzsChooseSendCountByMobile,Err:" + err.Error()
- return
- }
- resp := new(models.CygxXzsChooseSendResp)
- if count == 0 {
- resp.IsObjective = 1
- resp.IsSubjective = 1
- }
- resp.List = permissionList
- br.Ret = 200
- br.Success = true
- br.Msg = "获取成功"
- br.Data = resp
- }
- // @Title 提交用户的选择详情
- // @Description 提交用户的选择详情接口
- // @Param request body models.ActivityIdRep true "type json string"
- // @Success 200 {object} models.CygxXzsChooseSendResp
- // @router /choose/submit [post]
- func (this *UserController) ChooseSubmit() {
- br := new(models.BaseResponse).Init()
- defer func() {
- this.Data["json"] = br
- this.ServeJSON()
- }()
- user := this.User
- if user == nil {
- br.Msg = "请登录"
- br.ErrMsg = "请登录,用户信息为空"
- br.Ret = 408
- return
- }
- var req models.SubmitChooseSendResp
- err := json.Unmarshal(this.Ctx.Input.RequestBody, &req)
- if err != nil {
- br.Msg = "参数解析异常!"
- br.ErrMsg = "参数解析失败,Err:" + err.Error()
- return
- }
- mobile := user.Mobile
- item := new(models.CygxXzsChooseSend)
- item.UserId = user.UserId
- item.Mobile = user.Mobile
- item.Email = user.Email
- item.CompanyId = user.CompanyId
- item.CompanyName = user.CompanyName
- item.RealName = user.RealName
- item.CreateTime = time.Now()
- item.ModifyTime = time.Now()
- item.IsRefuse = req.IsRefuse
- item.IsSubjective = req.IsSubjective
- item.IsObjective = req.IsObjective
- count, err := models.GetXzsChooseSendCountByMobile(mobile)
- if err != nil {
- br.Msg = "获取信息失败"
- br.ErrMsg = "GetXzsChooseSendCountByMobile,Err:" + err.Error()
- return
- }
- if count == 0 {
- err = models.AddCygxXzsChooseSend(item)
- } else {
- updateParams := make(map[string]interface{})
- updateParams["UserId"] = item.UserId
- updateParams["Mobile"] = item.Mobile
- updateParams["Email"] = item.Email
- updateParams["CompanyId"] = item.CompanyId
- updateParams["CompanyName"] = item.CompanyName
- updateParams["RealName"] = item.RealName
- updateParams["ModifyTime"] = time.Now()
- updateParams["IsRefuse"] = item.IsRefuse
- updateParams["IsSubjective"] = item.IsSubjective
- updateParams["IsObjective"] = item.IsObjective
- whereParam := map[string]interface{}{"mobile": item.Mobile}
- err = models.UpdateByExpr(models.CygxXzsChooseSend{}, whereParam, updateParams)
- }
- if err != nil {
- br.Msg = "保存失败!"
- br.ErrMsg = "保存失败!,Err:" + err.Error()
- return
- }
- br.Ret = 200
- br.Success = true
- br.Msg = "保存成功"
- }
|