123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646 |
- package controllers
- import (
- "encoding/json"
- "github.com/rdlucklib/rdluck_tools/paging"
- "hongze/hongze_cygx/models"
- "hongze/hongze_cygx/services"
- "hongze/hongze_cygx/utils"
- "strconv"
- "strings"
- "time"
- )
- type ActivitySpecialCoAntroller struct {
- BaseAuthController
- }
- func (this *ActivitySpecialCoAntroller) SpecialList() {
- 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"
- return
- }
- pageSize, _ := this.GetInt("PageSize")
- currentIndex, _ := this.GetInt("CurrentIndex")
- if pageSize <= 0 {
- pageSize = utils.PageSize20
- }
- if currentIndex <= 0 {
- currentIndex = 1
- }
- list, total, errList := services.GetActivitySpecialList(user, currentIndex, pageSize, "")
- if errList != nil {
- br.Msg = "获取失败"
- br.ErrMsg = "获取失败,Err:" + errList.Error()
- return
- }
- page := paging.GetPaging(currentIndex, pageSize, total)
- resp := new(models.GetCygxActivitySpecialDetailListResp)
- count, err := models.GetCygxUserFollowSpecial(user.UserId)
- if err != nil {
- br.Msg = "获取数据失败!"
- br.ErrMsg = "获取客户详情失败,Err:" + err.Error()
- return
- }
- if count == 1 && user.UserId > 0 {
- resp.IsFollow = true
- }
- if user.Mobile != "" {
- resp.IsBindingMobile = true
- }
- resp.List = list
- resp.Paging = page
- br.Ret = 200
- br.Success = true
- br.Msg = "获取成功"
- br.Data = resp
- }
- func (this *ActivitySpecialCoAntroller) SpecialDetail() {
- 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
- }
- uid := user.UserId
- activityId, _ := this.GetInt("ActivityId")
- if activityId < 1 {
- br.Msg = "请输入活动ID"
- return
- }
- resp := new(models.CygxActivitySpecialResp)
- hasPermission := 0
- activityInfo, err := models.GetCygxActivitySpecialDetailById(uid, activityId)
- if err != nil && err.Error() != utils.ErrNoRow() {
- br.Msg = "获取信息失败"
- br.ErrMsg = "判断是否已申请过试用失败,Err:" + err.Error()
- return
- }
- if activityInfo == nil {
- br.Msg = "活动不存在"
- br.ErrMsg = "活动ID错误,Err:" + "activityId:" + strconv.Itoa(activityId)
- return
- }
- applyCount, err := models.GetApplyRecordCount(uid)
- if err != nil && err.Error() != utils.ErrNoRow() {
- br.Msg = "获取信息失败"
- br.ErrMsg = "判断是否已申请过试用失败,Err:" + err.Error()
- return
- }
-
- sellerItem, err := models.GetSellerByCompanyIdCheckFicc(user.CompanyId, 1)
- if err != nil && err.Error() != utils.ErrNoRow() {
- br.Msg = "获取信息失败"
- br.ErrMsg = "获取销售信息失败,Err:" + err.Error()
- return
- }
- if user.CompanyId <= 1 {
-
- } else {
- companyPermission, err := models.GetCompanyPermission(user.CompanyId)
- if err != nil {
- br.Msg = "获取信息失败"
- br.ErrMsg = "获取客户详情失败,Err:" + err.Error()
- return
- }
- if companyPermission == "" {
- if applyCount > 0 {
- hasPermission = 4
- } else {
- if sellerItem != nil {
- hasPermission = 5
- } else {
-
- sellerItemQy, err := models.GetSellerByCompanyIdCheckFicc(user.CompanyId, 2)
- if err != nil && err.Error() != utils.ErrNoRow() {
- br.Msg = "获取信息失败"
- br.ErrMsg = "获取销售信息失败,Err:" + err.Error()
- return
- }
- if sellerItemQy != nil {
- hasPermission = 2
- resp.SellerMobile = sellerItemQy.Mobile
- resp.SellerName = sellerItemQy.RealName
- } else {
- hasPermission = 3
- }
- }
- }
- resp.HasPermission = hasPermission
- resp.OperationMode = "Apply"
- resp.PopupMsg = "您暂无权限参加此活动,若想参加可以申请开通对应的试用权限"
- br.Ret = 200
- br.Success = true
- br.Msg = "获取成功"
- br.Data = resp
- 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) + "CompanyId:" + strconv.Itoa(user.CompanyId)
- return
- }
- }
- userType, permissionStr, err := services.GetUserType(user.CompanyId)
- if err != nil {
- br.Msg = "获取信息失败"
- br.ErrMsg = "获取客户信息失败,Err:" + err.Error()
- return
- }
- itemAct := new(models.ActivityDetail)
- itemAct.CustomerTypeIds = activityInfo.CustomerTypeIds
- noPower, err := services.GetShareNoPowe(itemAct, permissionStr, userType, user)
- if err != nil {
- br.Msg = "获取信息失败"
- br.ErrMsg = "获取客户信息失败,Err:" + err.Error()
- return
- }
-
- companyProduct, err := models.GetCompanyProductDetail(user.CompanyId, 2)
- if err != nil && err.Error() != utils.ErrNoRow() {
- br.Msg = "获取信息失败"
- br.ErrMsg = "获取客户信息失败,Err:" + err.Error()
- return
- }
- if companyProduct != nil {
- if companyProduct.Scale != "" {
- if strings.Count(activityInfo.Scale, companyProduct.Scale) > 0 {
- noPower = false
- }
- }
- }
- if noPower {
- br.Msg = "您暂无查看该活动权限"
- br.ErrMsg = "被分享客户不可见,获取信息失败"
- br.IsSendEmail = false
- return
- }
- if userType == 1 && strings.Contains(activityInfo.ChartPermissionName, "研选") {
- br.Msg = "您暂无查看该活动权限"
- br.ErrMsg = "被分享客户不可见,永续客户无法查看研选行业"
- return
- }
-
- if user.CompanyId > 1 {
- permissionStr, err := models.GetCompanyPermissionByUser(user.CompanyId)
- if err != nil {
- br.Msg = "获取信息失败"
- br.ErrMsg = "获取客户权限信息失败,Err:" + err.Error()
- return
- }
- companyItem, err := models.GetCompanyDetailById(user.CompanyId)
-
- if err != nil {
- if err.Error() == utils.ErrNoRow() {
- if applyCount > 0 {
- hasPermission = 4
- } else {
- if sellerItem != nil {
- hasPermission = 5
- } else {
-
- sellerItemQy, err := models.GetSellerByCompanyIdCheckFicc(user.CompanyId, 2)
- if err != nil && err.Error() != utils.ErrNoRow() {
- br.Msg = "获取信息失败"
- br.ErrMsg = "获取销售信息失败,Err:" + err.Error()
- return
- }
- if sellerItemQy != nil {
- hasPermission = 2
- resp.SellerMobile = sellerItemQy.Mobile
- resp.SellerName = sellerItemQy.RealName
- } else {
- hasPermission = 3
- }
- }
- }
- resp.HasPermission = hasPermission
- resp.OperationMode = "Apply"
- resp.PopupMsg = "您暂无权限参加此活动,若想参加可以申请开通对应的试用权限"
- br.Ret = 200
- br.Success = true
- br.Msg = "获取成功"
- br.Data = resp
- return
- } else {
- br.Msg = "获取信息失败"
- br.ErrMsg = "获取客户公司信息失败,Err:" + err.Error()
- return
- }
- }
- var havePower bool
- if strings.Contains(permissionStr, activityInfo.ActivityTypeName) {
- havePower = true
- }
- if havePower {
- hasPermission = 1
- resp.HaqveJurisdiction = true
- } else {
- if permissionStr == "专家" {
- resp.PopupMsg = "您暂无权限参加此活动,若想参加可以申请开通对应的试用权限"
- resp.MsgType = "Type"
- } else {
- resp.PopupMsg = "您暂无权限参加此活动,若想参加可以申请开通对应的试用权限"
- resp.MsgType = "Industry"
- }
- if companyItem.ProductId == 2 {
- resp.SellerMobile = companyItem.Mobile
- resp.SellerName = companyItem.SellerName
- resp.OperationMode = "Call"
- hasPermission = 2
- } else {
- hasPermission = 5
- }
- }
- } else {
- if applyCount > 0 {
- hasPermission = 4
- } else {
- if sellerItem != nil {
- hasPermission = 5
- } else {
- hasPermission = 3
- }
- }
- resp.OperationMode = "Apply"
- resp.PopupMsg = "您暂无权限参加此活动,若想参加可以申请开通对应的试用权限"
- }
- if hasPermission == 1 {
- count, err := models.GetCygxUserFollowSpecial(user.UserId)
- if err != nil {
- br.Msg = "获取数据失败!"
- br.ErrMsg = "获取客户详情失败,Err:" + err.Error()
- return
- }
- if count == 1 {
- resp.IsFollow = true
- }
- activityInfo, err := services.HandleActivitySpecialShow(activityInfo, user)
- if err != nil {
- br.Msg = "获取数据失败!"
- br.ErrMsg = "HandleActivitySpecialShow,Err:" + err.Error()
- return
- }
- activityInfo.ActivityTypeName = "专项调研"
- resp.Detail = activityInfo
- }
- resp.HasPermission = hasPermission
- br.Ret = 200
- br.Success = true
- br.Msg = "获取成功"
- br.Data = resp
- }
- func (this *ActivitySpecialCoAntroller) SpecialTripAdd() {
- 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
- }
- uid := user.UserId
- var req models.ActivityIdRep
- resp := new(models.SignupSpecialStatus)
- err := json.Unmarshal(this.Ctx.Input.RequestBody, &req)
- if err != nil {
- br.Msg = "参数解析异常!"
- br.ErrMsg = "参数解析失败,Err:" + err.Error()
- return
- }
- activityId := req.ActivityId
- hasPermission := 0
-
- applyCount, err := models.GetApplyRecordCount(uid)
- if err != nil && err.Error() != utils.ErrNoRow() {
- br.Msg = "获取信息失败"
- br.ErrMsg = "判断是否已申请过试用失败,Err:" + err.Error()
- return
- }
-
- sellerItem, err := models.GetSellerByCompanyIdCheckFicc(user.CompanyId, 1)
- if err != nil && err.Error() != utils.ErrNoRow() {
- br.Msg = "申请失败"
- br.ErrMsg = "获取销售信息失败,Err:" + err.Error()
- return
- }
- activityInfo, errInfo := models.GetCygxActivitySpecialDetail(activityId)
- if activityInfo == nil {
- br.Msg = "操作失败"
- br.ErrMsg = "活动ID错误,不存在activityId:" + strconv.Itoa(activityId)
- return
- }
- if errInfo != nil {
- br.Msg = "操作失败"
- br.ErrMsg = "操作失败,Err:" + errInfo.Error()
- return
- }
-
-
- if user.CompanyId > 1 {
- companyPermission, err := models.GetCompanyPermission(user.CompanyId)
- if err != nil {
- br.Msg = "获取信息失败"
- br.ErrMsg = "获取客户详情失败,Err:" + err.Error()
- return
- }
- if companyPermission == "" {
- if applyCount > 0 {
- hasPermission = 4
- } else {
- if sellerItem != nil {
- hasPermission = 5
- } else {
-
- sellerItemQy, err := models.GetSellerByCompanyIdCheckFicc(user.CompanyId, 2)
- if err != nil && err.Error() != utils.ErrNoRow() {
- br.Msg = "获取信息失败"
- br.ErrMsg = "获取销售信息失败,Err:" + err.Error()
- return
- }
- if sellerItemQy != nil {
- hasPermission = 2
- resp.SellerMobile = sellerItemQy.Mobile
- resp.SellerName = sellerItemQy.RealName
- } else {
- hasPermission = 3
- }
- }
- }
- resp.HasPermission = hasPermission
- resp.ActivityId = activityId
- resp.PopupMsg = "您暂无权限参加此活动,若想参加可以申请开通对应的试用权限"
- br.Ret = 200
- br.Success = true
- br.Msg = "获取成功"
- br.Data = resp
- 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) + "CompanyId:" + strconv.Itoa(user.CompanyId)
- return
- }
- }
- var userType int
- var permissionStr string
- userType, permissionStr, err = services.GetUserType(user.CompanyId)
- if err != nil {
- br.Msg = "获取信息失败!"
- br.ErrMsg = "获取失败,Err:" + err.Error()
- return
- }
- if userType == 1 && strings.Contains(activityInfo.ChartPermissionName, "研选") {
- br.Msg = "您暂无查看该活动权限"
- br.ErrMsg = "被分享客户不可见,永续客户无法查看研选行业"
- return
- }
- if user.CompanyId > 1 {
- companyItem, err := models.GetCompanyDetailById(user.CompanyId)
-
- if err != nil {
- if err.Error() == utils.ErrNoRow() {
- if applyCount > 0 {
- hasPermission = 4
- } else {
- if sellerItem != nil {
- hasPermission = 5
- } else {
- hasPermission = 3
- }
- }
- resp.ActivityId = activityId
- resp.HasPermission = hasPermission
- resp.PopupMsg = "您暂无权限参加此活动,若想参加可以申请开通对应的试用权限"
- br.Ret = 200
- br.Success = true
- br.Msg = "获取成功"
- br.Data = resp
- return
- } else {
- br.Msg = "获取信息失败"
- br.ErrMsg = "获取客户公司信息失败,Err:" + err.Error()
- return
- }
- }
-
- var havePower bool
- if strings.Contains(permissionStr, activityInfo.ActivityTypeName) {
- havePower = true
- }
- if havePower {
- hasPermission = 1
- } else {
- if companyItem.ProductId == 2 {
- hasPermission = 2
- resp.SellerMobile = companyItem.Mobile
- resp.SellerName = companyItem.SellerName
- if permissionStr == "专家" {
- resp.PopupMsg = "您暂无权限参加【" + activityInfo.ActivityTypeName + "】类型活动,若想参加请联系对口销售--" + companyItem.SellerName + ":" + companyItem.Mobile
- } else {
- resp.PopupMsg = "您暂无权限参加【" + activityInfo.ChartPermissionName + "】行业活动,若想参加请联系对口销售--" + companyItem.SellerName + ":" + companyItem.Mobile
- }
- } else {
- hasPermission = 5
- }
- }
- } else {
- if applyCount > 0 {
- hasPermission = 4
- } else {
- if sellerItem != nil {
- hasPermission = 5
- } else {
- hasPermission = 3
- }
- }
- resp.PopupMsg = "您暂无权限参加此活动,若想参加可以申请开通对应的试用权限"
- }
- resp.HasPermission = hasPermission
- resp.ActivityId = activityId
- if hasPermission == 1 {
- signupStatus, popupMsg, popupMsg2, err := services.SpecialTripPopupMsg(activityInfo, user)
- if err != nil {
- br.Msg = "获取信息失败"
- br.ErrMsg = "SpecialTripPopupMsg,Err:" + err.Error()
- return
- }
- total, err := models.GetUserActivitySpecialTripCount(user.UserId, activityId)
- if err != nil {
- br.Msg = "获取信息失败"
- br.ErrMsg = "获取日程数量信息失败,Err:" + err.Error()
- return
- }
- resp.PopupMsg = popupMsg
- resp.PopupMsg2 = popupMsg2
- resp.SignupStatus = signupStatus
-
- if total == 0 {
-
- sellerItem, err := models.GetSellerByCompanyIdCheckFicc(user.CompanyId, 2)
- if err != nil {
- br.Msg = "操作失败"
- br.ErrMsg = "获取销售信息失败,Err:" + err.Error()
- return
- }
- item := new(models.CygxActivitySpecialTrip)
- item.UserId = uid
- item.RealName = user.RealName
- item.ActivityId = activityId
- item.CreateTime = time.Now()
- item.Mobile = user.Mobile
- item.Email = user.Email
- item.CompanyId = user.CompanyId
- item.CompanyName = user.CompanyName
- if sellerItem != nil {
- item.SellerName = sellerItem.RealName
- }
- err = models.AddCygxActivitySpecialTrip(item)
- if err != nil {
- br.Msg = "操作失败"
- br.ErrMsg = "操作失败,Err:" + err.Error()
- return
- }
-
- resp.Status = 1
- resp.SignupStatus = 1
- resp.PopupMsg = "感谢参与,本次报名会扣除一次贵司在弘则的调研点数。"
- resp.PopupMsg2 = "由于每场活动人数有限,如果不能参加请提前48小时取消,未及时取消导致影响其他客户报名将会维持扣点。"
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
- }
- }
- br.Ret = 200
- br.Success = true
- br.Msg = "操作成功"
- br.Data = resp
- }
- func (this *ActivitySpecialCoAntroller) Tripcancel() {
- 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
- }
- uid := user.UserId
- var req models.ActivityIdRep
- err := json.Unmarshal(this.Ctx.Input.RequestBody, &req)
- if err != nil {
- br.Msg = "参数解析异常!"
- br.ErrMsg = "参数解析失败,Err:" + err.Error()
- return
- }
- activityId := req.ActivityId
- activityInfo, errInfo := models.GetCygxActivitySpecialDetailById(uid, activityId)
- if activityInfo == nil {
- br.Msg = "操作失败"
- br.ErrMsg = "活动ID错误,不存在activityId:" + strconv.Itoa(activityId)
- return
- }
- if errInfo != nil {
- br.Msg = "操作失败"
- br.ErrMsg = "操作失败,Err:" + errInfo.Error()
- return
- }
- err = models.CancelActivitySpecialTrip(uid, activityInfo)
- if err != nil {
- br.Msg = "操作失败"
- br.ErrMsg = "CancelActivitySpecialTrip,Err:" + err.Error()
- return
- }
- br.Ret = 200
- br.Success = true
- br.Msg = "会议提醒已取消"
- }
|