12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994199519961997199819992000200120022003200420052006200720082009201020112012201320142015201620172018201920202021202220232024202520262027202820292030203120322033203420352036203720382039204020412042204320442045204620472048204920502051205220532054205520562057205820592060206120622063206420652066206720682069207020712072207320742075207620772078207920802081208220832084208520862087208820892090209120922093209420952096209720982099210021012102210321042105210621072108210921102111211221132114211521162117211821192120212121222123212421252126212721282129213021312132213321342135213621372138213921402141214221432144214521462147214821492150215121522153215421552156215721582159216021612162216321642165216621672168216921702171217221732174217521762177217821792180218121822183218421852186218721882189219021912192219321942195219621972198219922002201220222032204220522062207220822092210221122122213221422152216221722182219222022212222222322242225222622272228222922302231223222332234223522362237223822392240224122422243224422452246224722482249225022512252225322542255225622572258225922602261226222632264226522662267226822692270227122722273227422752276227722782279228022812282228322842285228622872288228922902291229222932294229522962297229822992300230123022303230423052306230723082309231023112312231323142315231623172318231923202321232223232324232523262327232823292330233123322333233423352336233723382339234023412342234323442345234623472348234923502351235223532354235523562357235823592360236123622363236423652366236723682369237023712372237323742375237623772378237923802381238223832384238523862387238823892390239123922393 |
- package roadshow
- import (
- "encoding/json"
- "fmt"
- "github.com/rdlucklib/rdluck_tools/paging"
- "hongze/hongze_mobile_admin/controllers"
- "hongze/hongze_mobile_admin/models"
- "hongze/hongze_mobile_admin/models/cygx"
- "hongze/hongze_mobile_admin/models/roadshow"
- "hongze/hongze_mobile_admin/models/tables/admin"
- "hongze/hongze_mobile_admin/models/tables/company_product"
- "hongze/hongze_mobile_admin/models/tables/english_company"
- "hongze/hongze_mobile_admin/models/tables/system"
- "hongze/hongze_mobile_admin/services"
- "hongze/hongze_mobile_admin/services/rs"
- "hongze/hongze_mobile_admin/utils"
- "strconv"
- "strings"
- "time"
- )
- // 日历
- type CalendarController struct {
- controllers.BaseAuth
- }
- // @Title 新增路演活动接口
- // @Description 新增路演活动接口
- // @Param request body rs.AddActivityReq true "type json string"
- // @Success Ret=200 保存成功
- // @router /add [post]
- func (this *CalendarController) Add() {
- sysUser := this.AdminWx
- if sysUser == nil {
- this.FailWithMessage("请登录", "请登录,SysUser Is Empty")
- return
- }
- deleteCache := true
- cacheKey := "CACHE_RS_ACTIVITY_WX_ADD_" + strconv.Itoa(sysUser.AdminId)
- defer func() {
- if deleteCache {
- utils.Rc.Delete(cacheKey)
- }
- }()
- if !utils.Rc.SetNX(cacheKey, 1, 5*time.Second) {
- deleteCache = false
- this.FailWithMessage("系统处理中,请稍后重试!", "系统处理中,请稍后重试!"+sysUser.RealName+";data:"+string(this.Ctx.Input.RequestBody))
- return
- }
- var req roadshow.AddActivityReq
- err := json.Unmarshal(this.Ctx.Input.RequestBody, &req)
- if err != nil {
- this.FailWithMessage("参数解析异常", "参数解析失败,Err:"+err.Error())
- return
- }
- if len(req.ResearcherList) <= 0 {
- this.FailWithMessage("请选择研究员!", "请选择研究员!")
- return
- }
- researcherMap := make(map[int]string)
- var checkIsAdd []string
- sysUserList, err := cygx.GetAskEmailList()
- if err != nil {
- this.FailWithMessage("获取失败!", "获取失败,GetAskEmailList Err:"+err.Error())
- return
- }
- raiAskadminMap := make(map[int]bool, 0)
- for _, v := range sysUserList {
- raiAskadminMap[v.AdminId] = true
- }
- sysUserFwang, e := admin.GetSysUserByAdminName("fwang") // 手动拼接王芳到权益的策略行业下 start
- if e != nil {
- if e.Error() == utils.ErrNoRow() {
- this.FailWithMessage("用户不存在, 请检查!", "用户不存在, 请检查!")
- return
- }
- this.FailWithMessage("用户不存在, 请检查!", "fwang 用户名获取用户失败!Err: "+e.Error())
- return
- }
- raiAskadminMap[sysUserFwang.AdminId] = true // 手动拼接王芳到权益的策略行业下 end
- //var tipMsg string
- for _, v := range req.ResearcherList {
- if v.ResearcherId <= 0 {
- this.FailWithMessage("请选择研究员!", "请选择研究员!")
- return
- }
- if v.ResearcherName == "" {
- this.FailWithMessage("请选择研究员!", "请选择研究员!")
- return
- }
- if v.StartDate == "" {
- this.FailWithMessage("请选择开始日期!", "请选择开始日期!")
- return
- }
- if v.EndDate == "" {
- this.FailWithMessage("请选择结束日期!", "请选择结束日期!")
- return
- }
- if v.StartTime == "" {
- this.FailWithMessage("请选择开始时间!", "请选择开始时间!")
- return
- }
- if v.EndTime == "" {
- this.FailWithMessage("请选择结束时间!", "请选择结束时间!")
- return
- }
- if v.StartWeek == "" {
- this.FailWithMessage("请选择周!", "请选择周!")
- return
- }
- if v.EndWeek == "" {
- this.FailWithMessage("请选择周!", "请选择周!")
- return
- }
- if req.ActivityType == "沙龙" && !raiAskadminMap[v.ResearcherId] {
- this.FailWithMessage("ficc研究员暂不支持添加沙龙", "ficc研究员暂不支持添加沙龙")
- return
- }
- startDateTime := v.StartDate + " " + v.StartTime
- endDateTime := v.EndDate + " " + v.EndTime
- startP, _ := time.ParseInLocation(utils.FormatDateTime, startDateTime, time.Local)
- endP, _ := time.ParseInLocation(utils.FormatDateTime, endDateTime, time.Local)
- if startP.Before(time.Now()) || startP.Equal(time.Now()) {
- this.FailWithMessage("活动开始时间不能小于当前时间!", "活动开始时间不能小于当前时间!")
- return
- }
- if endP.Before(time.Now()) || endP.Equal(time.Now()) {
- this.FailWithMessage("活动结束时间不能小于当前时间!", "活动结束时间不能小于当前时间!")
- return
- }
- if startP.After(endP) || startP.Equal(endP) {
- this.FailWithMessage("活动开始时间应小于结束时间!", "活动开始时间应小于结束时间!")
- return
- }
- if realName, ok := researcherMap[v.ResearcherId]; ok {
- this.FailWithMessage("研究员:"+realName+" 被重复选择", "研究员:"+realName+" 被重复选择")
- return
- }
- researcherMap[v.ResearcherId] = v.ResearcherName
- //同步上海数据
- researcherInfo, err := admin.GetAdminWxById(v.ResearcherId)
- if err != nil {
- this.FailWithMessage("研究员异常", "获取研究员异常,Err:"+err.Error())
- return
- }
- _ = rs.SyncCalendarFromShanghai(researcherInfo.Mobile, v.StartDate, v.EndDate)
- //校验事项时间冲突
- {
- matterCount, err := rs.CheckMatters(startDateTime, endDateTime, v.ResearcherId, 0)
- if err != nil {
- this.FailWithMessage("时间冲突检测失败!", "时间冲突检测失败-CheckMattersCount!Err:"+err.Error())
- return
- }
- if matterCount > 0 {
- checkIsAdd = append(checkIsAdd, v.ResearcherName)
- }
- }
- //校验活动时间冲突
- {
- calendarCount, err := rs.CheckCalendar(startDateTime, endDateTime, "1,2", v.ResearcherId, 0)
- if err != nil {
- this.FailWithMessage("时间冲突检测失败!", "时间冲突检测失败-CheckCalendar!Err:"+err.Error())
- return
- }
- if calendarCount > 0 {
- checkIsAdd = append(checkIsAdd, v.ResearcherName)
- }
- }
- }
- if len(checkIsAdd) > 0 {
- this.FailWithMessage(strings.Join(checkIsAdd, ",")+" 时间已被占用!", "时间冲突检测失败-CheckMattersCount!")
- return
- }
- //如果是权益客户,添加销售跟共享销售的信息
- var productItemRai *company_product.CompanyProduct
- roleTypeCode := sysUser.RoleTypeCode
- //如果是权益销售、权益销售组长、权益管理员 添加的路演信息,做销售与共享销售信息关联查看
- if req.CompanyId > 0 && req.ActivityType == "路演" && (roleTypeCode == utils.ROLE_TYPE_CODE_RAI_SELLER ||
- roleTypeCode == utils.ROLE_TYPE_CODE_RAI_GROUP || roleTypeCode == utils.ROLE_TYPE_CODE_RAI_ADMIN) {
- productItemRai, err = company_product.GetCompanyProductByCompanyIdAndProductId(req.CompanyId, utils.COMPANY_PRODUCT_RAI_ID)
- if err != nil && err.Error() != utils.ErrNoRow() {
- this.FailWithMessage("客户信息有误!", "获取客户信息失败!Err:"+err.Error())
- return
- }
- }
- rsCalendar := new(roadshow.RsCalendar)
- rsCalendar.SysUserId = sysUser.AdminId
- rsCalendar.SysUserRealName = sysUser.RealName
- rsCalendar.ActivityType = req.ActivityType
- rsCalendar.RoadshowType = req.RoadshowType
- rsCalendar.RoadshowPlatform = req.RoadshowPlatform
- rsCalendar.CompanyId = req.CompanyId
- rsCalendar.CompanyName = req.CompanyName
- rsCalendar.Province = req.Province
- rsCalendar.ProvinceCode = req.ProvinceCode
- rsCalendar.City = req.City
- rsCalendar.CityCode = req.CityCode
- rsCalendar.District = req.District
- rsCalendar.Theme = req.Theme
- rsCalendar.CooperationName = req.CooperationName
- rsCalendar.CreateTime = time.Now()
- rsCalendar.ModifyTime = time.Now()
- rsCalendar.ActivityCategory = req.ActivityCategory
- rsCalendar.Source = 0
- rsCalendar.EnglishCompany = req.EnglishCompany
- rsCalendar.Title = getTitle(req.ActivityType, req.RoadshowType, req.ActivityCategory, req.RoadshowPlatform, req.Province, req.City)
- if productItemRai != nil {
- rsCalendar.SellerId = productItemRai.SellerId
- rsCalendar.ShareSellerId = productItemRai.ShareSellerId
- }
- rsCalendarId, err := roadshow.AddRsCalendar(rsCalendar)
- if err != nil {
- this.FailWithMessage("保存失败", "保存日历活动信息失败!Err:"+err.Error())
- return
- }
- //if researcherId != 99 {
- for k, v := range req.ResearcherList {
- researcher := new(roadshow.RsCalendarResearcher)
- researcher.RsCalendarId = int(rsCalendarId)
- researcher.ResearcherId = v.ResearcherId
- researcher.ResearcherName = v.ResearcherName
- researcher.StartDate = v.StartDate
- researcher.EndDate = v.EndDate
- researcher.StartTime = v.StartTime
- researcher.EndTime = v.EndTime
- researcher.StartWeek = v.StartWeek
- researcher.EndWeek = v.EndWeek
- researcher.CreateTime = time.Now()
- researcher.ModifyTime = time.Now()
- researcher.ResearcherSort = k + 1
- if req.ActivityType == "路演" || req.ActivityType == "公开会议" {
- researcher.Status = 1
- } else {
- researcher.Status = 2
- }
- //CRM15.5 权益研究员直接通过
- if raiAskadminMap[v.ResearcherId] {
- researcher.Status = 2
- }
- rsCalendarResearcherId, err := roadshow.AddRsCalendarResearcher(researcher)
- if err != nil {
- this.FailWithMessage("保存失败", "保存日历活动-研究员信息失败!Err:"+err.Error())
- return
- }
- rsCalendar.RsCalendarId = int(rsCalendarId)
- researcher.RsCalendarResearcherId = int(rsCalendarResearcherId)
- go rs.CalendarToSH(*rsCalendar, *researcher)
- //模板消息通知
- {
- go func(researcherId, tmpRsCalendarId, tmpRsCalendarResearcherId int) {
- var wxAppPath string
- sysAdmin, _ := admin.GetAdminWxById(researcherId)
- if sysAdmin != nil {
- if req.ActivityType == "路演" || req.ActivityType == "公开会议" {
- wxAppPath = "pages-approve/activity/detail?RsCalendarId=" + strconv.Itoa(tmpRsCalendarId) + "&RsCalendarResearcherId=" + strconv.Itoa(tmpRsCalendarResearcherId)
- first := "您收到一个新的【" + req.ActivityType + "】申请,请及时处理"
- keyword1 := sysUser.RealName
- keyword2 := "--"
- //keyword3 := time.Now().Format(utils.FormatDateTime)
- startDateSub := v.StartDate[5:]
- startDateSub = strings.Replace(startDateSub, "-", ".", -1)
- keyword3 := startDateSub + "(" + v.StartWeek + ")" + " " + v.StartTime[:5] + "~" + v.EndTime[:5]
- var keyword4 string
- if req.ActivityType == "路演" {
- keyword4 = req.CompanyName + "(" + req.RoadshowType + req.ActivityType + ")"
- } else {
- keyword4 = req.Theme + "(" + req.RoadshowType + req.ActivityType + ")"
- }
- remark := "请尽快完成审批"
- //wxAppPath := "pages-approve/activity/detail?RsCalendarId=" + strconv.Itoa(int(rsCalendarId)) + "&RsCalendarResearcherId=" + strconv.Itoa(int(rsCalendarResearcherId))
- if sysAdmin.OpenId != "" {
- go services.SendWxMsgWithRoadshowPending(first, keyword1, keyword2, keyword3, keyword4, remark, wxAppPath, sysAdmin.Mobile)
- }
- } else {
- wxAppPath = ""
- first := sysUser.RealName + "为你添加了一场【" + req.ActivityType + "】"
- startDate := researcher.StartDate[5:]
- startDate = strings.Replace(startDate, "-", ".", -1)
- keyword1 := startDate + "(" + researcher.StartWeek + ")" + " " + researcher.StartTime[:5] + "-" + researcher.EndTime[:5]
- keyword2 := sysUser.RealName + "为你添加了【" + req.ActivityType + "】"
- if sysAdmin.OpenId != "" {
- go services.SendWxMsgWithRoadshowDeleteNotice(first, keyword1, keyword2, "", wxAppPath, sysAdmin.Mobile)
- }
- }
- }
- }(v.ResearcherId, int(rsCalendarId), int(rsCalendarResearcherId))
- }
- }
- this.OkDetailed(nil, "保存成功")
- }
- // CalendarList
- // @Title 我的日历列表
- // @Description 我的日历列表接口
- // @Param PageSize query int true "每页数据条数"
- // @Param CurrentIndex query int true "当前页页码,从1开始"
- // @Param Status query int true "1:待接受,2:包含,已接受,已拒绝,已删除,已撤回,已结束"
- // @Success 200 {object} rs.CalendarListResp
- // @router /calendar/list [get]
- func (this *CalendarController) CalendarList() {
- adminItem := this.AdminWx
- status, _ := this.GetInt("Status")
- pageSize, _ := this.GetInt("PageSize")
- currentIndex, _ := this.GetInt("CurrentIndex")
- var total int
- page := paging.GetPaging(currentIndex, pageSize, total)
- var startSize int
- if pageSize <= 0 {
- pageSize = utils.PageSize10
- }
- if currentIndex <= 0 {
- currentIndex = 1
- }
- startSize = paging.StartIndex(currentIndex, pageSize)
- var condition string
- var pars []interface{}
- roleTypeCode := adminItem.RoleTypeCode
- //销售
- //if roleTypeCode == utils.ROLE_TYPE_CODE_FICC_SELLER ||
- // roleTypeCode == utils.ROLE_TYPE_CODE_RAI_SELLER ||
- // roleTypeCode == utils.ROLE_TYPE_CODE_FICC_GROUP ||
- // roleTypeCode == utils.ROLE_TYPE_CODE_RAI_GROUP ||
- // roleTypeCode == utils.ROLE_TYPE_CODE_RAI_ADMIN {
- // condition += ` AND a.sys_user_id=?`
- // pars = append(pars, adminItem.AdminId)
- //}
- if roleTypeCode == utils.ROLE_TYPE_CODE_FICC_SELLER ||
- //roleTypeCode == utils.ROLE_TYPE_CODE_RAI_SELLER ||
- roleTypeCode == utils.ROLE_TYPE_CODE_FICC_GROUP ||
- //roleTypeCode == utils.ROLE_TYPE_CODE_RAI_GROUP ||
- roleTypeCode == utils.ROLE_TYPE_CODE_FICC_TEAM ||
- roleTypeCode == utils.ROLE_TYPE_CODE_RAI_ADMIN {
- condition += ` AND a.sys_user_id=?`
- pars = append(pars, adminItem.AdminId)
- //condition += ` AND a.activity_type IN('路演','公开会议') `
- }
- //权益销售
- if roleTypeCode == utils.ROLE_TYPE_CODE_RAI_SELLER ||
- roleTypeCode == utils.ROLE_TYPE_CODE_RAI_GROUP {
- //if calendarType == 2 {
- condition += ` AND ( a.sys_user_id=? OR a.seller_id=? OR a.share_seller_id=? ) `
- pars = append(pars, adminItem.AdminId, adminItem.AdminId, adminItem.AdminId)
- //}
- }
- if roleTypeCode == utils.ROLE_TYPE_CODE_FICC_RESEARCHR ||
- roleTypeCode == utils.ROLE_TYPE_CODE_RESEARCHR ||
- roleTypeCode == utils.ROLE_TYPE_CODE_RAI_RESEARCHR ||
- roleTypeCode == utils.ROLE_TYPE_CODE_FICC_DEPARTMENT ||
- roleTypeCode == utils.ROLE_TYPE_CODE_RAI_DEPARTMENT ||
- roleTypeCode == utils.ROLE_TYPE_CODE_FICC_ADMIN {
- condition += ` AND b.researcher_id=?`
- pars = append(pars, adminItem.AdminId)
- }
- if roleTypeCode == utils.ROLE_TYPE_CODE_ADMIN {
- condition += ` AND a.sys_user_id=?`
- pars = append(pars, adminItem.AdminId)
- }
- condition += ` AND a.activity_type IN('路演','公开会议','沙龙') `
- if status == 1 {
- condition += ` AND b.status=?`
- pars = append(pars, 1)
- } else {
- condition += ` AND b.status IN(2,3,4,5,6)`
- }
- resp := new(roadshow.CalendarListResp)
- total, err := roadshow.GetCalendarListCount(condition, pars)
- if err != nil && err.Error() != utils.ErrNoRow() {
- this.FailWithMessage("获取信息失败!", "获取数据总数失败,GetCalendarListCount,Err:"+err.Error())
- return
- }
- page = paging.GetPaging(currentIndex, pageSize, total)
- dataList, err := roadshow.GetCalendarList(condition, pars, status, startSize, pageSize)
- if err != nil {
- this.FailWithMessage("获取信息失败!", "获取数据失败,GetCalendarList,Err:"+err.Error())
- return
- }
- // 英文客户的国家以及点击量
- englishIds := make([]int, 0)
- for i := range dataList {
- if dataList[i].EnglishCompany == 1 {
- englishIds = append(englishIds, dataList[i].CompanyId)
- }
- }
- englishMap := make(map[int]*english_company.EnglishCompany)
- if len(englishIds) > 0 {
- englishCond := ` AND company_id IN (` + utils.GetOrmInReplace(len(englishIds)) + `)`
- englishPars := make([]interface{}, 0)
- englishPars = append(englishPars, englishIds)
- englishList, e := english_company.GetEnglishCompanyList(englishCond, englishPars, "")
- if e != nil {
- this.FailWithMessage("获取英文客户失败!", "获取英文客户失败, Err:"+err.Error())
- return
- }
- for i := range englishList {
- englishMap[englishList[i].CompanyId] = englishList[i]
- }
- }
- for i := range dataList {
- if dataList[i].EnglishCompany == 1 {
- en := englishMap[dataList[i].CompanyId]
- if en != nil {
- dataList[i].EnglishCountry = en.Country
- dataList[i].EnglishViewTotal = en.ViewTotal
- }
- }
- }
- resp.Paging = page
- resp.List = dataList
- this.OkDetailed(resp, "获取成功")
- }
- // CalendarList
- // @Title 内部会议和报告电话会日历列表
- // @Description 内部会议和报告电话会日历列表
- // @Param PageSize query int true "每页数据条数"
- // @Param CurrentIndex query int true "当前页页码,从1开始"
- // @Param CalendarType query int true "1:内部会议,2:报告电话会"
- // @Success 200 {object} rs.CalendarListResp
- // @router /calendar/type/list [get]
- func (this *CalendarController) CalendarTypeList() {
- adminItem := this.AdminWx
- pageSize, _ := this.GetInt("PageSize")
- currentIndex, _ := this.GetInt("CurrentIndex")
- calendarType, _ := this.GetInt("CalendarType")
- var total int
- page := paging.GetPaging(currentIndex, pageSize, total)
- var startSize int
- if pageSize <= 0 {
- pageSize = utils.PageSize10
- }
- if currentIndex <= 0 {
- currentIndex = 1
- }
- startSize = paging.StartIndex(currentIndex, pageSize)
- var condition string
- var pars []interface{}
- if calendarType == 1 {
- condition += ` AND a.activity_type='内部会议' `
- condition += ` AND a.sys_user_id=?`
- pars = append(pars, adminItem.AdminId)
- }
- if calendarType == 2 {
- condition += ` AND a.activity_type='报告电话会' `
- }
- resp := new(roadshow.CalendarListResp)
- total, err := roadshow.GetCalendarTypeListCount(condition, pars)
- if err != nil && err.Error() != utils.ErrNoRow() {
- this.FailWithMessage("获取信息失败!", "获取数据总数失败,GetCalendarTypeListCount,Err:"+err.Error())
- return
- }
- page = paging.GetPaging(currentIndex, pageSize, total)
- dataList, err := roadshow.GetCalendarTypeList(condition, pars, startSize, pageSize)
- if err != nil {
- this.FailWithMessage("获取信息失败!", "获取数据失败,GetCalendarTypeList,Err:"+err.Error())
- return
- }
- resp.Paging = page
- resp.List = dataList
- this.OkDetailed(resp, "获取成功")
- }
- // Accept
- // @Description 接受路演活动接口
- // @Param request body rs.AcceptReq true "type json string"
- // @Success Ret=200 保存成功
- // @router /accept [post]
- func (this *CalendarController) Accept() {
- //adminItem:=this.AdminWx
- var req roadshow.AcceptReq
- err := json.Unmarshal(this.Ctx.Input.RequestBody, &req)
- if err != nil {
- this.FailWithMessage("参数解析失败!", "参数解析失败,Err:"+err.Error())
- return
- }
- if req.RsCalendarId <= 0 || req.RsCalendarResearcherId <= 0 {
- this.FailWithMessage("参数错误!", "RsCalendarId 或 RsCalendarResearcherId 小于等于0:")
- return
- }
- rsCalendar, err := roadshow.GetRsCalendarById(req.RsCalendarId)
- if err != nil {
- this.FailWithMessage("获取数据失败!", "GetRsCalendarById Err:"+err.Error())
- return
- }
- rsCalendarResearcher, err := roadshow.GetRsCalendarResearcherById(req.RsCalendarResearcherId)
- if err != nil {
- this.FailWithMessage("获取数据失败!", "GetRsCalendarResearcherById Err:"+err.Error())
- return
- }
- if rsCalendarResearcher.Status == 2 {
- this.FailWithMessage("已接受,不可重复操作!", "")
- return
- } else if rsCalendarResearcher.Status == 3 {
- this.FailWithMessage("已拒绝,不可进行接受操作!", "")
- return
- } else if rsCalendarResearcher.Status == 4 {
- this.FailWithMessage("已删除,不可进行接受操作!", "")
- return
- } else if rsCalendarResearcher.Status == 5 {
- this.FailWithMessage("已撤回,不可进行接受操作!", "")
- return
- }
- whereParams := make(map[string]interface{})
- updateParams := make(map[string]interface{})
- whereParams["rs_calendar_researcher_id"] = req.RsCalendarResearcherId
- whereParams["rs_calendar_id"] = req.RsCalendarId
- updateParams["status"] = 2
- updateParams["modify_time"] = time.Now()
- updateParams["approve_time"] = time.Now()
- err = roadshow.UpdateCalendarResearcher(whereParams, updateParams)
- if err != nil {
- this.FailWithMessage("获取数据失败!", "UpdateCalendarResearcher Err:"+err.Error())
- return
- }
- //模板消息通知
- {
- if rsCalendar != nil {
- sysAdmin, _ := admin.GetAdminById(rsCalendar.SysUserId)
- first := "【" + this.AdminWx.RealName + "】接受了你的【" + rsCalendar.ActivityType + "】申请"
- var keyword1, keyword2, keyword3, keyword4, keyword5 string
- keyword1 = rsCalendar.CompanyName + "(" + rsCalendar.RoadshowType + rsCalendar.ActivityType + ")"
- keyword2 = rsCalendar.ActivityType
- keyword4 = `【` + this.AdminWx.RealName + `】已接受`
- remark := ""
- if sysAdmin.Mobile != "" {
- go services.SendWxMsgWithRoadshowDetailResult(first, keyword1, keyword2, keyword3, keyword4, keyword5, remark, sysAdmin.Mobile, "", "")
- }
- }
- }
- this.OkDetailed(nil, "保存成功")
- }
- // @Title 拒绝路演活动接口
- // @Description 拒绝路演活动接口
- // @Param request body rs.RefuseReq true "type json string"
- // @Success Ret=200 保存成功
- // @router /refuse [post]
- func (this *CalendarController) Refuse() {
- //adminItem:=this.AdminWx
- var req roadshow.RefuseReq
- err := json.Unmarshal(this.Ctx.Input.RequestBody, &req)
- if err != nil {
- this.FailWithMessage("参数解析失败!", "参数解析失败,Err:"+err.Error())
- return
- }
- if req.RsCalendarId <= 0 || req.RsCalendarResearcherId <= 0 {
- this.FailWithMessage("参数错误!", "参数错误!RsCalendarId:"+strconv.Itoa(req.RsCalendarId)+";RsCalendarResearcherId:"+strconv.Itoa(req.RsCalendarResearcherId))
- return
- }
- rsCalendar, err := roadshow.GetRsCalendarById(req.RsCalendarId)
- if err != nil {
- this.FailWithMessage("获取数据失败!", "GetRsCalendarById,Err:"+err.Error())
- return
- }
- rsCalendarResearcher, err := roadshow.GetRsCalendarResearcherById(req.RsCalendarResearcherId)
- if err != nil {
- this.FailWithMessage("获取数据失败!", "GetRsCalendarResearcherById,Err:"+err.Error())
- return
- }
- if rsCalendarResearcher.Status == 2 {
- this.FailWithMessage("已接受,不可进行拒绝操作!", "")
- return
- } else if rsCalendarResearcher.Status == 3 {
- this.FailWithMessage("已拒绝,不可进行重复操作!", "")
- return
- } else if rsCalendarResearcher.Status == 4 {
- this.FailWithMessage("已删除,不可进行拒绝操作!", "")
- return
- } else if rsCalendarResearcher.Status == 5 {
- this.FailWithMessage("已撤回,不可进行拒绝操作!", "")
- return
- }
- whereParams := make(map[string]interface{})
- updateParams := make(map[string]interface{})
- whereParams["rs_calendar_researcher_id"] = req.RsCalendarResearcherId
- whereParams["rs_calendar_id"] = req.RsCalendarId
- updateParams["status"] = 3
- updateParams["refuse_reason"] = req.RefuseReason
- updateParams["refuse_time"] = time.Now()
- updateParams["modify_time"] = time.Now()
- err = roadshow.UpdateCalendarResearcher(whereParams, updateParams)
- if err != nil {
- this.FailWithMessage("保存失败", "保存失败!UpdateCalendarResearcher:"+err.Error())
- return
- }
- // 拒绝后需要删除上海的日程
- go rs.DeleteSHCalendar(req.RsCalendarResearcherId)
- //模板消息通知
- {
- if rsCalendar != nil {
- sysAdmin, _ := admin.GetAdminById(rsCalendar.SysUserId)
- first := "【" + this.AdminWx.RealName + "】拒绝了你的【" + rsCalendar.ActivityType + "】申请"
- var keyword1, keyword2, keyword3, keyword4, keyword5 string
- keyword1 = rsCalendar.CompanyName + "(" + rsCalendar.RoadshowType + rsCalendar.ActivityType + ")"
- keyword2 = rsCalendar.ActivityType
- keyword4 = `【` + this.AdminWx.RealName + `】已拒绝`
- keyword5 = req.RefuseReason
- remark := req.RefuseReason
- if sysAdmin.Mobile != "" {
- go services.SendWxMsgWithRoadshowDetailResult(first, keyword1, keyword2, keyword3, keyword4, keyword5, remark, sysAdmin.Mobile, "", "")
- }
- }
- }
- this.OkDetailed(nil, "保存成功")
- }
- // @Title 日历详情
- // @Description 日历详情接口
- // @Param RsCalendarId query int true "路演活动id"
- // @Param RsCalendarResearcherId query int true "活动研究员id"
- // @Success 200 {object} rs.CalendarDetailResp
- // @router /calendar/detail [get]
- func (this *CalendarController) CalendarDetail() {
- //adminItem:=this.AdminWx
- //roleTypeCode := adminItem.RoleTypeCode
- sysUser := this.AdminWx
- if sysUser == nil {
- this.FailWithMessage("请登录", "请登录,SysUser Is Empty")
- return
- }
- rsCalendarId, _ := this.GetInt("RsCalendarId")
- rsCalendarResearcherId, _ := this.GetInt("RsCalendarResearcherId")
- if rsCalendarId <= 0 || rsCalendarResearcherId <= 0 {
- this.FailWithMessage("参数错误", "rsCalendarId 或 rsCalendarResearcherId")
- return
- }
- calendarItem, err := roadshow.GetRsCalendarById(rsCalendarId)
- if err != nil {
- this.FailWithMessage("获取数据失败", "获取数据失败!GetRsCalendarById:"+err.Error())
- return
- }
- rsCalendarResearcherItem, err := roadshow.GetRsCalendarResearcherById(rsCalendarResearcherId)
- if err != nil {
- this.FailWithMessage("获取数据失败", "获取数据失败!GetRsCalendarResearcherById:"+err.Error())
- return
- }
- companyDetailView := new(roadshow.CompanyDetailView)
- productId := services.GetProductId(sysUser.RoleTypeCode)
- if productId == 0 {
- productId = 1
- }
- if calendarItem != nil && calendarItem.CompanyId > 0 {
- // 中文客户
- if calendarItem.EnglishCompany == 0 {
- companyId := calendarItem.CompanyId
- companyProductItem, err := models.GetCompanyProductByCompanyIdAndProductId(companyId, productId)
- if err != nil {
- this.FailWithMessage("获取数据失败", "获取数据失败!GetCompanyProductByCompanyIdAndProductId:"+err.Error())
- return
- }
- permissionList, err := models.GetCompanyProductReportPermissionList(companyId, productId)
- if err != nil {
- this.FailWithMessage("搜索客户权限失败", "搜索客户权限失败!GetCompanyProductReportPermissionList:"+err.Error())
- return
- }
- var permissionArr []string
- for _, v := range permissionList {
- permissionArr = append(permissionArr, v.PermissionName)
- }
- readNum := companyProductItem.ViewTotal
- companyDetailView.CompanyId = companyProductItem.CompanyId
- companyDetailView.CompanyName = companyProductItem.CompanyName
- companyDetailView.Status = companyProductItem.Status
- companyDetailView.IndustryId = companyProductItem.IndustryId
- companyDetailView.IndustryName = companyProductItem.IndustryName
- companyDetailView.PermissionName = strings.Join(permissionArr, "/")
- companyDetailView.ReportReadTotal = readNum //ficc报告-累计阅读次数
- }
- // 英文客户
- if calendarItem.EnglishCompany == 1 {
- enItem, e := english_company.GetEnglishCompanyById(calendarItem.CompanyId)
- if e != nil {
- this.FailWithMessage("搜索客户失败!", "获取英文客户详情失败, GetEnglishCompanyById Err: "+e.Error())
- return
- }
- companyDetailView.CompanyId = enItem.CompanyId
- companyDetailView.CompanyName = enItem.CompanyName
- companyDetailView.Status = "正常"
- companyDetailView.EnglishCompany = 1
- companyDetailView.EnglishCountry = enItem.Country
- companyDetailView.EnglishViewTotal = enItem.ViewTotal
- }
- }
- resp := new(roadshow.CalendarDetailResp)
- resp.RsCalendarItem = calendarItem
- resp.RsCalendarResearcherItem = rsCalendarResearcherItem
- resp.CompanyDetail = companyDetailView
- this.OkDetailed(resp, "获取成功")
- }
- // @Title 事项列表
- // @Description 事项列表接口
- // @Param PageSize query int true "每页数据条数"
- // @Param CurrentIndex query int true "当前页页码,从1开始"
- // @Success 200 {object} rs.MattersListResp
- // @router /matters/list [get]
- func (this *CalendarController) MattersList() {
- sysUser := this.AdminWx
- if sysUser == nil {
- this.FailWithMessage("请登录", "请登录,SysUser Is Empty")
- return
- }
- pageSize, _ := this.GetInt("PageSize")
- currentIndex, _ := this.GetInt("CurrentIndex")
- var total int
- page := paging.GetPaging(currentIndex, pageSize, total)
- var startSize int
- if pageSize <= 0 {
- pageSize = utils.PageSize10
- }
- if currentIndex <= 0 {
- currentIndex = 1
- }
- startSize = paging.StartIndex(currentIndex, pageSize)
- var condition string
- var pars []interface{}
- condition += ` AND a.sys_user_id=?`
- pars = append(pars, sysUser.AdminId)
- resp := new(roadshow.MattersListResp)
- total, err := roadshow.GetMattersListCount(condition, pars)
- if err != nil && err.Error() != utils.ErrNoRow() {
- this.FailWithMessage("获取事项信息失败", "获取事项信息失败,GetMattersListCount,Err:"+err.Error())
- return
- }
- page = paging.GetPaging(currentIndex, pageSize, total)
- dataList, err := roadshow.GetMattersList(condition, pars, startSize, pageSize)
- if err != nil {
- this.FailWithMessage("获取事项信息失败", "获取事项信息失败,GetMattersList,Err:"+err.Error())
- return
- }
- // 按钮权限,超过14天无按钮
- now := time.Now().Local()
- for _, v := range dataList {
- // 结束日期14天后无编辑删除按钮权限
- t := fmt.Sprintf("%s %s", v.EndDate, v.EndTime)
- ed, e := time.ParseInLocation(utils.FormatDateTime, t, time.Local)
- if e != nil {
- this.FailWithMessage("事项结束日期有误", "事项结束日期有误, Err:"+err.Error())
- return
- }
- ed = ed.AddDate(0, 0, 14)
- if ed.Before(now) {
- v.ButtonAuth.EditDisabled = true
- v.ButtonAuth.RemoveDisabled = true
- }
- }
- resp.Paging = page
- resp.List = dataList
- this.OkDetailed(resp, "获取成功")
- }
- // @Title 新增事项接口
- // @Description 新增事项接口
- // @Param request body rs.AddMattersReq true "type json string"
- // @Success Ret=200 保存成功
- // @router /matters/add [post]
- func (this *CalendarController) MattersAdd() {
- sysUser := this.AdminWx
- if sysUser == nil {
- this.FailWithMessage("请登录", "请登录,SysUser Is Empty")
- return
- }
- deleteCache := true
- cacheKey := "CACHE_RS_MATTERS_ADD_" + strconv.Itoa(sysUser.AdminId)
- defer func() {
- if deleteCache {
- utils.Rc.Delete(cacheKey)
- }
- }()
- if !utils.Rc.SetNX(cacheKey, 1, 30*time.Second) {
- deleteCache = false
- this.FailWithMessage("系统处理中,请稍后重试!", "系统处理中,请稍后重试!"+sysUser.RealName+";data:"+string(this.Ctx.Input.RequestBody))
- return
- }
- var req roadshow.AddMattersReq
- err := json.Unmarshal(this.Ctx.Input.RequestBody, &req)
- if err != nil {
- this.FailWithMessage("参数解析异常", "参数解析失败,Err:"+err.Error())
- return
- }
- if req.StartDate == "" {
- this.FailWithMessage("请选择开始日期!", "请选择开始日期!")
- return
- }
- if req.EndDate == "" {
- this.FailWithMessage("请选择结束日期!", "请选择结束日期!")
- return
- }
- if req.StartTime == "" {
- this.FailWithMessage("请选择开始时间!", "请选择开始时间!")
- return
- }
- if req.EndTime == "" {
- this.FailWithMessage("请选择结束时间!", "请选择结束时间!")
- return
- }
- if req.StartWeek == "" {
- this.FailWithMessage("请选择周!", "请选择周!")
- return
- }
- if req.EndWeek == "" {
- this.FailWithMessage("请选择周!", "请选择周!")
- return
- }
- if req.MatterContent == "" {
- this.FailWithMessage("请选择研究员!", "请选择研究员!")
- return
- }
- // 是否为销售
- sales := isSellerRole(sysUser.RoleTypeCode)
- startDateTime := req.StartDate + " " + req.StartTime
- endDateTime := req.EndDate + " " + req.EndTime
- //校验事项时间冲突
- {
- matterCount, err := rs.CheckMatters(startDateTime, endDateTime, sysUser.AdminId, 0)
- if err != nil {
- this.FailWithMessage("时间冲突检测失败!", "时间冲突检测失败-CheckMattersCount!Err:"+err.Error())
- return
- }
- if matterCount > 0 {
- this.FailWithMessage("当前时间已被占用!", "时间冲突检测失败-CheckMattersCount!")
- return
- }
- }
- if !sales {
- //校验活动时间冲突--待接受
- {
- calendarCount, err := rs.CheckCalendar(startDateTime, endDateTime, "1", sysUser.AdminId, 0)
- if err != nil {
- this.FailWithMessage("时间冲突检测失败!", "时间冲突检测失败-CheckCalendarResearcherCount!Err:"+err.Error())
- return
- }
- if calendarCount > 0 {
- this.FailWithMessage("当前时间与待处理的申请有冲突,请与相关销售沟通!", "时间冲突检测失败-CheckCalendarResearcherCount!")
- return
- }
- }
- //校验活动时间冲突--已接受
- {
- calendarCount, err := rs.CheckCalendar(startDateTime, endDateTime, "2", sysUser.AdminId, 0)
- if err != nil {
- this.FailWithMessage("时间冲突检测失败!", "时间冲突检测失败-CheckCalendarResearcherCount!Err:"+err.Error())
- return
- }
- if calendarCount > 0 {
- this.FailWithMessage("当前时间已被占用!", "时间冲突检测失败-CheckCalendarResearcherCount!")
- return
- }
- }
- }
- startP, _ := time.ParseInLocation(utils.FormatDateTime, startDateTime, time.Local)
- endP, _ := time.ParseInLocation(utils.FormatDateTime, endDateTime, time.Local)
- if startP.Before(time.Now()) || startP.Equal(time.Now()) {
- this.FailWithMessage("事项开始时间不能小于当前时间!", "事项开始时间不能小于当前时间!")
- return
- }
- if endP.Before(time.Now()) || endP.Equal(time.Now()) {
- this.FailWithMessage("事项结束时间不能小于当前时间!", "事项结束时间不能小于当前时间!")
- return
- }
- if startP.After(endP) || startP.Equal(endP) {
- this.FailWithMessage("事项开始时间应小于结束时间!", "事项开始时间应小于结束时间!")
- return
- }
- item := new(roadshow.RsMatters)
- item.SysUserId = sysUser.AdminId
- item.SysUserRealName = sysUser.RealName
- item.StartDate = req.StartDate
- item.EndDate = req.EndDate
- item.StartTime = req.StartTime
- item.EndTime = req.EndTime
- item.StartWeek = req.StartWeek
- item.EndWeek = req.EndWeek
- item.MatterContent = req.MatterContent
- item.Status = 1
- item.CreateTime = time.Now()
- item.ModifyTime = time.Now()
- if sales {
- item.IsSeller = 1
- }
- id, err := roadshow.AddRsMatters(item)
- if err != nil {
- this.FailWithMessage("保存失败!", "保存失败,AddRsMatters Err:"+err.Error())
- return
- }
- item.RsMattersId = int(id)
- // 销售的事项不同步上海
- if !sales {
- go rs.MatterToSH(*item)
- }
- this.OkDetailed(nil, "保存成功")
- }
- // @Title 修改事项接口
- // @Description 修改事项接口
- // @Param request body rs.UpdateMattersReq true "type json string"
- // @Success Ret=200 保存成功
- // @router /matters/update [post]
- func (this *CalendarController) MattersUpdate() {
- sysUser := this.AdminWx
- if sysUser == nil {
- this.FailWithMessage("请登录", "请登录,SysUser Is Empty")
- return
- }
- deleteCache := true
- cacheKey := "CACHE_RS_MATTERS_UPDATE_" + strconv.Itoa(sysUser.AdminId)
- defer func() {
- if deleteCache {
- utils.Rc.Delete(cacheKey)
- }
- }()
- if !utils.Rc.SetNX(cacheKey, 1, 30*time.Second) {
- deleteCache = false
- this.FailWithMessage("系统处理中,请稍后重试!", "系统处理中,请稍后重试!")
- return
- }
- var req roadshow.UpdateMattersReq
- err := json.Unmarshal(this.Ctx.Input.RequestBody, &req)
- if err != nil {
- this.FailWithMessage("参数解析失败!", "参数解析失败,Err:"+err.Error())
- return
- }
- updateParams := make(map[string]interface{})
- if req.RsMattersId <= 0 {
- this.FailWithMessage("参数错误!", "参数错误")
- return
- }
- if req.StartDate == "" {
- this.FailWithMessage("请选择开始日期!", "请选择开始日期")
- return
- } else {
- updateParams["start_date"] = req.StartDate
- }
- if req.EndDate == "" {
- this.FailWithMessage("请选择结束日期!", "请选择结束日期")
- return
- } else {
- updateParams["end_date"] = req.EndDate
- }
- if req.StartTime == "" {
- this.FailWithMessage("请选择开始时间!", "请选择开始时间")
- return
- } else {
- updateParams["start_time"] = req.StartTime
- }
- if req.EndTime == "" {
- this.FailWithMessage("请选择结束时间!", "请选择结束时间")
- return
- } else {
- updateParams["end_time"] = req.EndTime
- }
- if req.StartWeek == "" {
- this.FailWithMessage("请选择周!", "请选择周")
- return
- } else {
- updateParams["start_week"] = req.StartWeek
- }
- if req.EndWeek == "" {
- this.FailWithMessage("请选择周!", "请选择周")
- return
- } else {
- updateParams["end_week"] = req.EndWeek
- }
- if req.MatterContent == "" {
- this.FailWithMessage("请选择研究员!", "请选择研究员")
- return
- } else {
- updateParams["matter_content"] = req.MatterContent
- }
- req.EditReason = strings.TrimSpace(req.EditReason)
- if req.EditReason == "" {
- this.FailWithMessage("请填写修改原因!", "请填写修改原因")
- return
- }
- updateParams["edit_reason"] = req.EditReason
- startDateTime := req.StartDate + " " + req.StartTime
- endDateTime := req.EndDate + " " + req.EndTime
- startP, _ := time.ParseInLocation(utils.FormatDateTime, startDateTime, time.Local)
- endP, _ := time.ParseInLocation(utils.FormatDateTime, endDateTime, time.Local)
- if startP.Before(time.Now()) || startP.Equal(time.Now()) {
- this.FailWithMessage("事项开始时间不能小于当前时间!", "事项开始时间不能小于当前时间!")
- return
- }
- if endP.Before(time.Now()) || endP.Equal(time.Now()) {
- this.FailWithMessage("事项结束时间不能小于当前时间!", "事项结束时间不能小于当前时间!")
- return
- }
- if startP.After(endP) || startP.Equal(endP) {
- this.FailWithMessage("事项开始时间应小于结束时间!", "事项开始时间应小于结束时间!")
- return
- }
- // 结束后14天不可再编辑
- endP = endP.AddDate(0, 0, 14)
- if endP.Before(time.Now().Local()) {
- this.FailWithMessage("事项结束14天后不可再编辑!", "事项结束14天后不可再编辑!")
- return
- }
- matterItem, err := roadshow.GetMattersById(req.RsMattersId)
- if err != nil {
- this.FailWithMessage("保存失败!", "保存失败,GetMattersById,Err:"+err.Error())
- return
- }
- // 是否为销售
- sales := isSellerRole(sysUser.RoleTypeCode)
- //校验事项时间冲突
- {
- if matterItem != nil && (matterItem.StartDate != req.StartDate ||
- matterItem.StartTime != req.StartTime ||
- matterItem.EndDate != req.EndDate ||
- matterItem.EndTime != req.EndTime) {
- matterCount, err := rs.CheckMatters(startDateTime, endDateTime, sysUser.AdminId, matterItem.RsMattersId)
- if err != nil {
- this.FailWithMessage("时间冲突检测失败!", "时间冲突检测失败-CheckMattersCount!Err:"+err.Error())
- return
- }
- if matterCount > 0 {
- this.FailWithMessage("时间冲突,已存在时间段内的事项!", "时间冲突检测失败-CheckMattersCount!")
- return
- }
- }
- }
- if !sales {
- //校验活动时间冲突--待接受
- {
- calendarCount, err := rs.CheckCalendar(startDateTime, endDateTime, "1", sysUser.AdminId, 0)
- if err != nil {
- this.FailWithMessage("时间冲突检测失败!", "时间冲突检测失败-CheckCalendarResearcherCount!Err:"+err.Error())
- return
- }
- if calendarCount > 0 {
- this.FailWithMessage("当前时间与待处理的申请有冲突,请与相关销售沟通!", "时间冲突检测失败-CheckCalendarResearcherCount!")
- return
- }
- }
- //校验活动时间冲突--待接受
- {
- calendarCount, err := rs.CheckCalendar(startDateTime, endDateTime, "2", sysUser.AdminId, 0)
- if err != nil {
- this.FailWithMessage("时间冲突检测失败!", "时间冲突检测失败-CheckCalendarResearcherCount!Err:"+err.Error())
- return
- }
- if calendarCount > 0 {
- this.FailWithMessage("时间冲突,已存在时间段内的活动!", "时间冲突检测失败-CheckCalendarResearcherCount!")
- return
- }
- }
- }
- whereParams := make(map[string]interface{})
- whereParams["rs_matters_id"] = req.RsMattersId
- updateParams["modify_time"] = time.Now()
- err = roadshow.UpdateRsMatters(whereParams, updateParams)
- if err != nil {
- this.FailWithMessage("保存失败!", "保存失败!UpdateRsMatters:"+err.Error())
- return
- }
- // 销售不做上海那边的处理
- if !sales {
- go rs.UpdateSHCalendarByMatter(req)
- }
- this.OkDetailed(nil, "保存成功")
- }
- // @Title 删除事项接口
- // @Description 删除事项接口
- // @Param request body rs.DeleteMattersReq true "type json string"
- // @Success Ret=200 保存成功
- // @router /matters/delete [post]
- func (this *CalendarController) MattersDelete() {
- sysUser := this.AdminWx
- if sysUser == nil {
- this.FailWithMessage("请登录", "请登录,SysUser Is Empty")
- return
- }
- var req roadshow.DeleteMattersReq
- err := json.Unmarshal(this.Ctx.Input.RequestBody, &req)
- if err != nil {
- this.FailWithMessage("参数解析失败", "参数解析失败,Err:"+err.Error())
- return
- }
- if req.RsMattersId <= 0 {
- this.FailWithMessage("参数错误", "参数错误")
- return
- }
- matters, e := roadshow.GetMattersById(req.RsMattersId)
- if e != nil {
- if e.Error() == utils.ErrNoRow() {
- this.FailWithMessage("事项已被删除, 请刷新页面", "事项已被删除, 请刷新页面")
- return
- }
- this.FailWithMessage("操作失败", "获取事项失败, Err: "+e.Error())
- return
- }
- // 事项结束14天后不可再删除
- t := fmt.Sprintf("%s %s", matters.EndDate, matters.EndTime)
- ed, _ := time.ParseInLocation(utils.FormatDateTime, t, time.Local)
- ed = ed.AddDate(0, 0, 14)
- if ed.Before(time.Now().Local()) {
- this.FailWithMessage("事项结束14天后不可再删除", "事项结束14天后不可再删除")
- return
- }
- err = roadshow.DeleteRsMatters(req.RsMattersId)
- if err != nil {
- this.FailWithMessage("保存失败", "保存失败!DeleteRsMatters:"+err.Error())
- return
- }
- // 是否为销售
- sales := isSellerRole(sysUser.RoleTypeCode)
- // 删除上海的路演活动, 销售不同步
- if !sales {
- go rs.DeleteSHMatter(req.RsMattersId)
- }
- this.OkDetailed(nil, "删除成功")
- }
- func getTitle(activityType, roadshowType, activityCategory, roadshowPlatform, province, city string) string {
- var title string
- switch activityType {
- case "内部会议":
- title = "内部会议"
- case "公开会议", "路演", "沙龙":
- if roadshowType == "线上" {
- title = roadshowType + activityType + roadshowPlatform
- } else {
- title = roadshowType + activityType + province + city
- }
- case "报告电话会":
- title = activityCategory + "电话会"
- }
- return title
- }
- // @Title 编辑路演活动接口
- // @Description编辑路演活动接口
- // @Param request body rs.EditActivityReq true "type json string"
- // @Success Ret=200 保存成功
- // @router /edit [post]
- func (this *CalendarController) Edit() {
- sysUser := this.AdminWx
- if sysUser == nil {
- this.FailWithMessage("请登录", "请登录,SysUser Is Empty")
- return
- }
- deleteCache := true
- cacheKey := "CACHE_RS_ACTIVITY_EDIT_" + strconv.Itoa(sysUser.AdminId)
- defer func() {
- if deleteCache {
- utils.Rc.Delete(cacheKey)
- }
- }()
- if !utils.Rc.SetNX(cacheKey, 1, 3*time.Second) {
- deleteCache = false
- this.FailWithMessage("系统处理中,请稍后重试!", "系统处理中,请稍后重试!"+sysUser.RealName+";data:"+string(this.Ctx.Input.RequestBody))
- return
- }
- var req roadshow.EditActivityReq
- err := json.Unmarshal(this.Ctx.Input.RequestBody, &req)
- if err != nil {
- this.FailWithMessage("参数解析异常", "参数解析失败,Err:"+err.Error())
- return
- }
- if req.RsCalendarId <= 0 {
- this.FailWithMessage("参数错误", "RsCalendarId<=0")
- return
- }
- if req.RsCalendarResearcherId <= 0 {
- this.FailWithMessage("参数错误", "RsCalendarResearcherId<=0")
- return
- }
- if req.ActivityType == "" {
- this.FailWithMessage("请选择活动类型", "请选择活动类型")
- return
- }
- if len(req.ResearcherList) <= 0 {
- this.FailWithMessage("请选择研究员!", "请选择研究员!")
- return
- }
- researcherMap := make(map[int]string)
- var checkIsAdd []string
- for _, v := range req.ResearcherList {
- if v.ResearcherId <= 0 {
- this.FailWithMessage("请选择研究员!", "请选择研究员!")
- return
- }
- if v.ResearcherName == "" {
- this.FailWithMessage("请选择研究员!", "请选择研究员!")
- return
- }
- if v.StartDate == "" {
- this.FailWithMessage("请选择开始日期!", "请选择开始日期!")
- return
- }
- if v.EndDate == "" {
- this.FailWithMessage("请选择结束日期!", "请选择结束日期!")
- return
- }
- if v.StartTime == "" {
- this.FailWithMessage("请选择开始时间!", "请选择开始时间!")
- return
- }
- if v.EndTime == "" {
- this.FailWithMessage("请选择结束时间!", "请选择结束时间!")
- return
- }
- if v.StartWeek == "" {
- this.FailWithMessage("请选择周!", "请选择周!")
- return
- }
- if v.EndWeek == "" {
- this.FailWithMessage("请选择周!", "请选择周!")
- return
- }
- if realName, ok := researcherMap[v.ResearcherId]; ok {
- this.FailWithMessage("研究员:"+realName+" 被重复选择", "研究员:"+realName+" 被重复选择")
- return
- }
- researcherMap[v.ResearcherId] = v.ResearcherName
- startDateTime := v.StartDate + " " + v.StartTime
- endDateTime := v.EndDate + " " + v.EndTime
- startP, _ := time.ParseInLocation(utils.FormatDateTime, startDateTime, time.Local)
- endP, _ := time.ParseInLocation(utils.FormatDateTime, endDateTime, time.Local)
- if startP.Before(time.Now()) || startP.Equal(time.Now()) {
- this.FailWithMessage("活动开始时间不能小于当前时间!", "活动开始时间不能小于当前时间!")
- return
- }
- if endP.Before(time.Now()) || endP.Equal(time.Now()) {
- this.FailWithMessage("活动结束时间不能小于当前时间!", "活动结束时间不能小于当前时间!")
- return
- }
- if startP.After(endP) || startP.Equal(endP) {
- this.FailWithMessage("活动开始时间应小于结束时间!", "活动开始时间应小于结束时间!")
- return
- }
- /*
- 时间冲突时,提示:xxx时间已被占用
- 当有任意一个研究员时间有冲突时,所有申请订单都不发送。
- */
- rsCalendarResearcherItem, err := roadshow.GetRsCalendarResearcherByRsCalendarIdAndResearcherId(req.RsCalendarId, v.ResearcherId)
- var isAdd bool
- if err != nil {
- if err.Error() == utils.ErrNoRow() {
- isAdd = true
- } else {
- this.FailWithMessage("获取数据失败!", "获取数据失败!GetRsCalendarResearcherByRsCalendarIdAndResearcherId:"+err.Error())
- return
- }
- }
- var rsCalendarResearcherId int
- if rsCalendarResearcherItem == nil {
- isAdd = true
- } else {
- rsCalendarResearcherId = rsCalendarResearcherItem.RsCalendarResearcherId
- }
- //同步上海数据
- researcherInfo, err := admin.GetAdminById(v.ResearcherId)
- if err != nil {
- this.FailWithMessage("研究员异常!", "研究员异常,Err:"+err.Error())
- return
- }
- _ = rs.SyncCalendarFromShanghai(researcherInfo.Mobile, v.StartDate, v.EndDate)
- //校验事项时间冲突
- {
- if isAdd || (rsCalendarResearcherItem != nil && (rsCalendarResearcherItem.StartDate != v.StartDate ||
- rsCalendarResearcherItem.StartTime != v.StartTime ||
- rsCalendarResearcherItem.EndDate != v.EndDate ||
- rsCalendarResearcherItem.EndTime != v.EndTime)) {
- matterCount, err := rs.CheckMatters(startDateTime, endDateTime, v.ResearcherId, 0)
- if err != nil {
- this.FailWithMessage("时间冲突检测失败!", "时间冲突检测失败-CheckMattersCount!Err:"+err.Error())
- return
- }
- if matterCount > 0 {
- checkIsAdd = append(checkIsAdd, v.ResearcherName)
- }
- }
- }
- calendarCount, err := rs.CheckCalendar(startDateTime, endDateTime, "1,2", v.ResearcherId, rsCalendarResearcherId)
- if err != nil {
- this.FailWithMessage("时间冲突检测失败!", "时间冲突检测失败-CheckCalendarResearcherCount!Err:"+err.Error())
- return
- }
- if calendarCount > 0 {
- checkIsAdd = append(checkIsAdd, v.ResearcherName)
- }
- }
- if len(checkIsAdd) > 0 {
- this.FailWithMessage(strings.Join(checkIsAdd, ",")+"时间已被占用!", "时间冲突检测失败-CheckMattersCount!")
- return
- }
- rsCalendarItem, err := roadshow.GetRsCalendarById(req.RsCalendarId)
- if err != nil {
- this.FailWithMessage("获取数据失败!", "获取数据失败!GetRsCalendarById:"+err.Error())
- return
- }
- if rsCalendarItem == nil {
- this.FailWithMessage("保存失败!", "获取数据失败!GetRsCalendarById:"+err.Error())
- return
- }
- calendarWhereParams := make(map[string]interface{})
- calendarUpdateParams := make(map[string]interface{})
- calendarWhereParams["rs_calendar_id"] = req.RsCalendarId
- if req.ActivityType != "" {
- calendarUpdateParams["activity_type"] = req.ActivityType
- }
- if req.RoadshowType != "" {
- calendarUpdateParams["roadshow_type"] = req.RoadshowType
- }
- if req.RoadshowPlatform != "" {
- calendarUpdateParams["roadshow_platform"] = req.RoadshowPlatform
- }
- if req.CompanyId > 0 {
- calendarUpdateParams["company_id"] = req.CompanyId
- }
- if req.CompanyName != "" {
- calendarUpdateParams["company_name"] = req.CompanyName
- }
- if req.ActivityCategory != "" {
- calendarUpdateParams["activity_category"] = req.ActivityCategory
- }
- if req.Theme != "" {
- calendarUpdateParams["theme"] = req.Theme
- }
- if req.CooperationName != "" {
- calendarUpdateParams["cooperation_name"] = req.CooperationName
- }
- if req.Province != "" {
- calendarUpdateParams["province"] = req.Province
- }
- if req.City != "" {
- calendarUpdateParams["city"] = req.City
- }
- if req.District != "" {
- calendarUpdateParams["district"] = req.District
- }
- calendarUpdateParams["english_company"] = req.EnglishCompany
- calendarUpdateParams["modify_time"] = time.Now()
- calendarUpdateParams["title"] = getTitle(req.ActivityType, req.RoadshowType, req.ActivityCategory, req.RoadshowPlatform, req.Province, req.City)
- err = roadshow.UpdateRsCalendar(calendarWhereParams, calendarUpdateParams)
- if err != nil {
- this.FailWithMessage("保存失败!", "保存失败!UpdateRsCalendar:"+err.Error())
- return
- }
- existList, err := roadshow.GetRsCalendarResearcherByCalendarId(req.RsCalendarId)
- if err != nil {
- this.FailWithMessage("保存失败!", "保存失败!GetRsCalendarResearcherByCalendarId:"+err.Error())
- return
- }
- existResearcherMap := make(map[int]string)
- for _, ev := range existList {
- existResearcherMap[ev.ResearcherId] = ev.ResearcherName
- }
- sysUserList, err := cygx.GetAskEmailList()
- if err != nil {
- this.FailWithMessage("获取失败!", "获取失败,GetAskEmailList Err:"+err.Error())
- return
- }
- raiAskadminMap := make(map[int]bool, 0)
- for _, v := range sysUserList {
- raiAskadminMap[v.AdminId] = true
- }
- if rsCalendarItem.ActivityType == "路演" || rsCalendarItem.ActivityType == "公开会议" {
- // 更新研究员信息
- //go roadshowService.UpdateSHCalendar(req.RsCalendarId, req.RsCalendarResearcherId, req.ActivityType, req.RoadshowType, req.ActivityCategory, req.RoadshowPlatform, req.Province, req.City, req.ResearcherList)
- for k, v := range req.ResearcherList {
- rsCalendarResearcherItem, err := roadshow.GetRsCalendarResearcherById(req.RsCalendarResearcherId)
- if err != nil {
- this.FailWithMessage("获取数据失败!", "获取数据失败!GetRsCalendarResearcherById:"+err.Error())
- return
- }
- calendarResearcherWhereParams := make(map[string]interface{})
- calendarResearcherUpdateParams := make(map[string]interface{})
- calendarResearcherWhereParams["rs_calendar_researcher_id"] = req.RsCalendarResearcherId
- calendarResearcherUpdateParams["researcher_id"] = v.ResearcherId
- calendarResearcherUpdateParams["researcher_name"] = v.ResearcherName
- if rsCalendarResearcherItem.Status == 3 || rsCalendarResearcherItem.Status == 5 {
- calendarResearcherUpdateParams["status"] = 1
- }
- //CRM15.5 权益研究员直接通过
- if raiAskadminMap[v.ResearcherId] {
- calendarResearcherUpdateParams["status"] = 2
- rsCalendarResearcherItem.Status = 2
- }
- calendarResearcherUpdateParams["start_date"] = v.StartDate
- calendarResearcherUpdateParams["end_date"] = v.EndDate
- calendarResearcherUpdateParams["start_time"] = v.StartTime
- calendarResearcherUpdateParams["end_time"] = v.EndTime
- calendarResearcherUpdateParams["start_week"] = v.StartWeek
- calendarResearcherUpdateParams["end_week"] = v.EndWeek
- calendarResearcherUpdateParams["refuse_reason"] = ""
- calendarResearcherUpdateParams["refuse_time"] = nil
- calendarResearcherUpdateParams["delete_reason"] = ""
- calendarResearcherUpdateParams["approve_time"] = nil
- calendarResearcherUpdateParams["researcher_sort"] = k + 1
- calendarResearcherUpdateParams["modify_time"] = time.Now()
- calendarResearcherUpdateParams["create_time"] = time.Now()
- err = roadshow.UpdateCalendarResearcher(calendarResearcherWhereParams, calendarResearcherUpdateParams)
- if err != nil {
- this.FailWithMessage("保存失败!", "保存失败!UpdateCalendarResearcher:"+err.Error())
- return
- }
- //上海新增(因为在驳回的时候,就把上海该时间段的日程给删除了,所以修改的时候,需要重新调用新增接口)
- calendar := roadshow.RsCalendar{
- RsCalendarId: req.RsCalendarId,
- SysUserId: sysUser.AdminId,
- Title: getTitle(req.ActivityType, req.RoadshowType, req.ActivityCategory, req.RoadshowPlatform, req.Province, req.City),
- }
- researcher := *rsCalendarResearcherItem
- researcher.StartDate = v.StartDate
- researcher.EndDate = v.EndDate
- researcher.StartTime = v.StartTime
- researcher.EndTime = v.EndTime
- researcher.StartWeek = v.StartWeek
- researcher.EndWeek = v.EndWeek
- go rs.CalendarToSH(calendar, researcher)
- if req.EditType == 2 {
- //模板消息通知
- go func(researcherId, tmpRsCalendarId, tmpRsCalendarResearcherId int) {
- sysAdmin, _ := admin.GetAdminById(researcherId)
- if sysAdmin != nil && req.ActivityType != "内部会议" && req.ActivityType != "报告电话会" {
- first := "您收到一个新的【" + req.ActivityType + "】申请,请及时处理"
- keyword1 := sysUser.RealName
- keyword2 := "--"
- //keyword3 := time.Now().Format(utils.FormatDateTime)
- startDateSub := v.StartDate[5:]
- startDateSub = strings.Replace(startDateSub, "-", ".", -1)
- keyword3 := startDateSub + "(" + v.StartWeek + ")" + " " + v.StartTime[:5] + "~" + v.EndTime[:5]
- var keyword4 string
- if req.ActivityType == "路演" {
- keyword4 = req.CompanyName + "(" + req.RoadshowType + req.ActivityType + ")"
- } else {
- keyword4 = req.Theme + "(" + req.RoadshowType + req.ActivityType + ")"
- }
- remark := "请尽快完成审批"
- wxAppPath := "pages-approve/activity/detail?RsCalendarId=" + strconv.Itoa(req.RsCalendarId) + "&RsCalendarResearcherId=" + strconv.Itoa(tmpRsCalendarResearcherId)
- if sysAdmin.OpenId != "" {
- services.SendWxMsgWithRoadshowPending(first, keyword1, keyword2, keyword3, keyword4, remark, wxAppPath, sysAdmin.Mobile)
- }
- }
- }(v.ResearcherId, req.RsCalendarId, rsCalendarResearcherItem.RsCalendarResearcherId)
- }
- }
- } else {
- //先获取到所有的研究员日历表id
- researchers, err := roadshow.GetRsCalendarResearcherByCalendarId(req.RsCalendarId)
- if err != nil {
- utils.FileLog.Info("GetRsCalendarResearcherByCalendarId err: ", err)
- fmt.Println(err)
- this.FailWithMessage("保存失败!", "获取数据失败,GetRsCalendarResearcherByCalendarId:"+err.Error())
- return
- }
- //先删后增
- err = roadshow.DeleteRsCalendarResearcher(req.RsCalendarId)
- if err != nil {
- this.FailWithMessage("保存失败!", "保存失败!DeleteRsCalendarResearcher:"+err.Error())
- return
- }
- //删除上海
- for _, researcher := range researchers {
- rs.DeleteSHCalendar(researcher.RsCalendarResearcherId)
- }
- for k, v := range req.ResearcherList {
- researcher := new(roadshow.RsCalendarResearcher)
- researcher.RsCalendarId = req.RsCalendarId
- researcher.ResearcherId = v.ResearcherId
- researcher.ResearcherName = v.ResearcherName
- researcher.StartDate = v.StartDate
- researcher.EndDate = v.EndDate
- researcher.StartTime = v.StartTime
- researcher.EndTime = v.EndTime
- researcher.StartWeek = v.StartWeek
- researcher.EndWeek = v.EndWeek
- researcher.CreateTime = time.Now()
- researcher.ModifyTime = time.Now()
- researcher.ResearcherSort = k + 1
- if req.ActivityType == "路演" || req.ActivityType == "公开会议" {
- researcher.Status = 1
- } else {
- researcher.Status = 2
- }
- //CRM15.5 权益研究员直接通过
- if raiAskadminMap[v.ResearcherId] {
- researcher.Status = 2
- }
- rsCalendarResearcherId, err := roadshow.AddRsCalendarResearcher(researcher)
- if err != nil {
- this.FailWithMessage("保存失败!", "保存日历活动-研究员信息失败!Err:"+err.Error())
- return
- }
- //上海新增
- calendar := roadshow.RsCalendar{
- RsCalendarId: req.RsCalendarId,
- SysUserId: sysUser.AdminId,
- Title: getTitle(req.ActivityType, req.RoadshowType, req.ActivityCategory, req.RoadshowPlatform, req.Province, req.City),
- }
- researcher.RsCalendarResearcherId = int(rsCalendarResearcherId)
- go rs.CalendarToSH(calendar, *researcher)
- go func(researcherId, tmpRsCalendarId, tmpRsCalendarResearcherId int) {
- sysAdmin, _ := admin.GetAdminById(researcherId)
- if sysAdmin != nil && req.ActivityType != "内部会议" && req.ActivityType != "报告电话会" {
- first := "您收到一个新的【" + req.ActivityType + "】申请,请及时处理"
- keyword1 := sysUser.RealName
- keyword2 := "--"
- keyword3 := time.Now().Format(utils.FormatDateTime)
- startDateSub := v.StartDate[5:]
- startDateSub = strings.Replace(startDateSub, "-", ".", -1)
- //keyword3 := startDateSub + "(" + v.StartWeek + ")" + " " + v.StartTime[:5] + "~" + v.EndTime[:5]
- var keyword4 string
- if req.ActivityType == "路演" {
- keyword4 = req.CompanyName + "(" + req.RoadshowType + req.ActivityType + ")"
- } else {
- keyword4 = req.Theme + "(" + req.RoadshowType + req.ActivityType + ")"
- }
- remark := "请尽快完成审批"
- wxAppPath := "pages-approve/activity/detail?RsCalendarId=" + strconv.Itoa(tmpRsCalendarId) + "&RsCalendarResearcherId=" + strconv.Itoa(tmpRsCalendarResearcherId)
- if sysAdmin.OpenId != "" {
- services.SendWxMsgWithRoadshowPending(first, keyword1, keyword2, keyword3, keyword4, remark, wxAppPath, sysAdmin.Mobile)
- }
- }
- }(v.ResearcherId, req.RsCalendarId, int(rsCalendarResearcherId))
- }
- }
- this.OkDetailed(nil, "保存成功")
- }
- // ResearcherList
- // @Title 研究员列表
- // @Description 研究员列表接口
- // @Success 200 {object} rs.ResearcherGroup
- // @router /researcher/list [get]
- func (this *CalendarController) ResearcherList() {
- sysUser := this.AdminWx
- if sysUser == nil {
- this.FailWithMessage("请登录", "请登录,SysUser Is Empty")
- return
- }
- group, err := roadshow.GetResearcherGroup()
- if err != nil {
- this.FailWithMessage("获取信息失败!", "获取分组信息失败!Err:"+err.Error())
- return
- }
- researcherList, err := roadshow.GetResearcher()
- groupMap := make(map[int][]*roadshow.ResearcherGroup)
- for _, v := range researcherList {
- item := &roadshow.ResearcherGroup{
- GroupId: v.GroupId,
- GroupName: v.GroupName,
- AdminId: v.AdminId,
- RealName: v.RealName,
- RoleTypeCode: v.RoleTypeCode,
- }
- if findItems, ok := groupMap[v.GroupId]; ok {
- findItems = append(findItems, item)
- groupMap[v.GroupId] = findItems
- } else {
- findItems = append(findItems, item)
- groupMap[v.GroupId] = findItems
- }
- //}
- }
- for _, v := range group {
- v.ResearcherList = groupMap[v.GroupId]
- }
- ficcGroup := new(roadshow.ResearcherGroup)
- ficcGroup.GroupId = 999
- ficcGroup.GroupName = "ficc"
- ficcGroup.ResearcherList = group
- sysUserList, err := system.GetAdminList()
- if err != nil {
- this.FailWithMessage("获取失败!", "获取失败,获取admin列表失败 Err:"+err.Error())
- return
- }
- adminMap := make(map[int]*system.AdminItem, 0)
- for _, v := range sysUserList {
- adminMap[v.AdminId] = v
- }
- askUserList, err := cygx.GetAskEmailList()
- if err != nil {
- this.FailWithMessage("获取失败!", "获取失败,GetAskEmailList Err:"+err.Error())
- return
- }
- mapPermissionUser := make(map[string][]*roadshow.ResearcherGroup)
- listPermission, err := cygx.GetChartPermissionAll()
- if err != nil {
- this.FailWithMessage("获取失败!", "获取失败,获取品种信息失败 Err:"+err.Error())
- return
- }
- mapPermissionId := make(map[string]int)
- for _, v := range listPermission {
- mapPermissionId[v.PermissionName] = v.ChartPermissionId
- }
- sysUserFwang, e := admin.GetSysUserByAdminName("fwang") // 手动拼接王芳到权益的策略行业下 start
- if e != nil {
- if e.Error() == utils.ErrNoRow() {
- this.FailWithMessage("用户不存在, 请检查!", "用户不存在, 请检查!")
- return
- }
- this.FailWithMessage("用户不存在, 请检查!", "fwang 用户名获取用户失败!Err: "+e.Error())
- return
- }
- itemFwang := new(roadshow.ResearcherGroup)
- itemFwang.AdminId = sysUserFwang.AdminId
- itemFwang.GroupId = sysUserFwang.GroupId
- itemFwang.GroupName = sysUserFwang.GroupName
- itemFwang.RealName = sysUserFwang.RealName
- itemFwang.RoleTypeCode = sysUserFwang.RoleTypeCode
- mapPermissionUser["策略"] = append(mapPermissionUser["策略"], itemFwang) // 手动拼接王芳到权益的策略行业下 end
- for _, v := range askUserList {
- if admin, ok := adminMap[v.AdminId]; ok {
- item := &roadshow.ResearcherGroup{
- AdminId: v.AdminId,
- RealName: v.Name,
- GroupId: admin.GroupId,
- GroupName: admin.GroupName,
- RoleTypeCode: admin.RoleTypeCode,
- }
- mapPermissionUser[v.ChartPermissionName] = append(mapPermissionUser[v.ChartPermissionName], item)
- }
- }
- raiList := make([]*roadshow.ResearcherGroup, 0)
- for k, v := range mapPermissionUser {
- respItem := new(roadshow.ResearcherGroup)
- respItem.GroupName = k + "组"
- respItem.GroupId = mapPermissionId[k]
- respItem.ResearcherList = v
- raiList = append(raiList, respItem)
- }
- raiGroup := new(roadshow.ResearcherGroup)
- raiGroup.GroupId = 888
- raiGroup.GroupName = "权益"
- raiGroup.ResearcherList = raiList
- var resp []*roadshow.ResearcherGroup
- resp = append(resp, ficcGroup, raiGroup)
- this.OkDetailed(resp, "获取成功")
- }
- // @Title 撤回路演活动接口
- // @Description 撤回路演活动接口
- // @Param request body rs.AcceptReq true "type json string"
- // @Success Ret=200 保存成功
- // @router /back [post]
- func (this *CalendarController) Back() {
- sysUser := this.AdminWx
- if sysUser == nil {
- this.FailWithMessage("请登录", "请登录,SysUser Is Empty")
- return
- }
- var req roadshow.AcceptReq
- err := json.Unmarshal(this.Ctx.Input.RequestBody, &req)
- if err != nil {
- this.FailWithMessage("参数解析异常", "参数解析失败,Err:"+err.Error())
- return
- }
- if req.RsCalendarId <= 0 || req.RsCalendarResearcherId <= 0 {
- this.FailWithMessage("参数错误", "参数错误!RsCalendarId:"+strconv.Itoa(req.RsCalendarId)+";RsCalendarResearcherId:"+strconv.Itoa(req.RsCalendarResearcherId))
- return
- }
- _, err = roadshow.GetRsCalendarById(req.RsCalendarId)
- if err != nil {
- this.FailWithMessage("获取数据失败", "获取数据失败!GetRsCalendarById:"+err.Error())
- return
- }
- rsCalendarResearcher, err := roadshow.GetRsCalendarResearcherById(req.RsCalendarResearcherId)
- if err != nil {
- this.FailWithMessage("获取数据失败", "获取数据失败!GetRsCalendarResearcherById:"+err.Error())
- return
- }
- if rsCalendarResearcher.Status == 2 {
- this.FailWithMessage("已接受,不可进行撤回操作!", "已接受,不可进行撤回操作!")
- return
- } else if rsCalendarResearcher.Status == 3 {
- this.FailWithMessage("已拒绝,不可进行撤回操作!", "已拒绝,不可进行撤回操作!")
- return
- } else if rsCalendarResearcher.Status == 4 {
- this.FailWithMessage("已删除,不可进行撤回操作!", "已删除,不可进行撤回操作!")
- return
- } else if rsCalendarResearcher.Status == 5 {
- this.FailWithMessage("已撤回,不可进行重复操作!", "已撤回,不可进行重复操作!")
- return
- }
- whereParams := make(map[string]interface{})
- updateParams := make(map[string]interface{})
- whereParams["rs_calendar_researcher_id"] = req.RsCalendarResearcherId
- whereParams["rs_calendar_id"] = req.RsCalendarId
- updateParams["status"] = 5
- updateParams["modify_time"] = time.Now()
- err = roadshow.UpdateCalendarResearcher(whereParams, updateParams)
- //撤回后,需要删除该日程
- go rs.DeleteSHCalendar(req.RsCalendarResearcherId)
- if err != nil {
- this.FailWithMessage("保存失败", "保存失败!UpdateCalendarResearcher:"+err.Error())
- return
- }
- this.OkDetailed(nil, "撤回成功")
- }
- // @Title 删除路演活动接口
- // @Description 删除路演活动接口
- // @Param request body rs.DeleteReq true "type json string"
- // @Success Ret=200 保存成功
- // @router /delete [post]
- func (this *CalendarController) Delete() {
- sysUser := this.AdminWx
- if sysUser == nil {
- this.FailWithMessage("请登录", "请登录,SysUser Is Empty")
- return
- }
- var req roadshow.DeleteReq
- err := json.Unmarshal(this.Ctx.Input.RequestBody, &req)
- if err != nil {
- this.FailWithMessage("参数解析异常!", "参数解析失败,Err:"+err.Error())
- return
- }
- if req.RsCalendarId <= 0 || req.RsCalendarResearcherId <= 0 {
- this.FailWithMessage("参数错误!", "参数错误!RsCalendarId:"+strconv.Itoa(req.RsCalendarId)+";RsCalendarResearcherId:"+strconv.Itoa(req.RsCalendarResearcherId))
- return
- }
- rsCalendarItem, err := roadshow.GetRsCalendarById(req.RsCalendarId)
- if err != nil {
- this.FailWithMessage("获取数据失败!", "获取数据失败!GetRsCalendarById:"+err.Error())
- return
- }
- rsCalendarResearcherItemList, err := roadshow.GetRsCalendarResearcherListById(req.RsCalendarId)
- if err != nil {
- this.FailWithMessage("获取数据失败!", "获取数据失败!GetRsCalendarResearcherById:"+err.Error())
- return
- }
- if rsCalendarItem.ActivityType == "报告电话会" || rsCalendarItem.ActivityType == "内部会议" {
- err = roadshow.DeleteCalendar(req.RsCalendarId, req.RsCalendarResearcherId)
- if err != nil {
- this.FailWithMessage("删除失败!", "删除失败!DeleteCalendar:"+err.Error())
- return
- }
- } else {
- //只获取一条路演数据
- rsCalendarResearcherItemList, err = roadshow.GetRsCalendarResearcherListByCalendarResearcherId(req.RsCalendarResearcherId)
- if err != nil {
- this.FailWithMessage("获取数据失败!", "获取数据失败!GetRsCalendarResearcherById:"+err.Error())
- return
- }
- if req.DeleteReason == "" {
- this.FailWithMessage("删除失败,请输入删除理由!", "删除失败!请输入删除理由")
- return
- }
- whereParams := make(map[string]interface{})
- updateParams := make(map[string]interface{})
- whereParams["rs_calendar_researcher_id"] = req.RsCalendarResearcherId
- whereParams["rs_calendar_id"] = req.RsCalendarId
- updateParams["status"] = 4
- updateParams["delete_reason"] = req.DeleteReason
- updateParams["modify_time"] = time.Now()
- updateParams["delete_time"] = time.Now()
- err = roadshow.UpdateCalendarResearcher(whereParams, updateParams)
- if err != nil {
- this.FailWithMessage("删除失败!", "删除失败!UpdateCalendarResearcher:"+err.Error())
- return
- }
- }
- //`status` int(11) DEFAULT '0' COMMENT '1:待接受,2:已接受,3:已拒绝,4:已删除,5:已撤回,6:已结束',
- for _, rsCalendarResearcherItem := range rsCalendarResearcherItemList {
- //待接受、已接受的情况,需要同步删除上海那边的日程
- if rsCalendarResearcherItem.Status == 1 || rsCalendarResearcherItem.Status == 2 {
- go rs.DeleteSHCalendar(rsCalendarResearcherItem.RsCalendarResearcherId)
- }
- ////模板消息通知
- //{
- // go func() {
- // if rsCalendarItem != nil && rsCalendarResearcherItem != nil {
- // sysAdmin, _ := admin.GetAdminById(rsCalendarResearcherItem.ResearcherId)
- // if sysAdmin != nil && sysAdmin.Mobile != "" {
- // first := "【" + sysUser.RealName + "】删除了你的【路演】安排"
- // var keyword1 string
- // if rsCalendarItem.ActivityType == "路演" {
- // keyword1 = rsCalendarItem.CompanyName + "," + rsCalendarItem.RoadshowType + rsCalendarItem.ActivityType
- // } else {
- // keyword1 = rsCalendarItem.Theme + "," + rsCalendarItem.RoadshowType + rsCalendarItem.ActivityType
- // }
- // keyword2 := "已删除"
- // remark := req.DeleteReason
- // var wxAppPath string
- // if rsCalendarItem.ActivityType == "路演" || rsCalendarItem.ActivityType == "公开会议" {
- // wxAppPath = "pages-approve/activity/detail?RsCalendarId=" + strconv.Itoa(rsCalendarItem.RsCalendarId) + "&RsCalendarResearcherId=" + strconv.Itoa(rsCalendarResearcherItem.RsCalendarResearcherId)
- // }
- // go services.SendWxMsgWithRoadshowDeleteNotice(first, keyword1, keyword2, remark, wxAppPath, sysAdmin.Mobile)
- // }
- // }
- // }()
- //}
- //模板消息通知
- {
- if rsCalendarItem != nil && rsCalendarResearcherItem != nil {
- go func(tmpRsCalendarItem roadshow.RsCalendar, tmpRsCalendarResearcherItem roadshow.RsCalendarResearcher) {
- sysAdmin, _ := admin.GetAdminById(tmpRsCalendarResearcherItem.ResearcherId)
- var first string
- var wxAppPath string
- if tmpRsCalendarItem.ActivityType == "路演" || tmpRsCalendarItem.ActivityType == "公开会议" {
- wxAppPath = "pages-approve/activity/detail?RsCalendarId=" + strconv.Itoa(tmpRsCalendarItem.RsCalendarId) + "&RsCalendarResearcherId=" + strconv.Itoa(tmpRsCalendarResearcherItem.RsCalendarResearcherId)
- }
- first = "【" + sysUser.RealName + "】删除了你的【" + tmpRsCalendarItem.ActivityType + "】安排"
- keyword2 := "【" + sysUser.RealName + "】已删除(" + req.DeleteReason + ")"
- var keyword1 string
- if tmpRsCalendarItem.ActivityType == "路演" {
- keyword1 = tmpRsCalendarItem.CompanyName + "," + tmpRsCalendarItem.RoadshowType + tmpRsCalendarItem.ActivityType
- } else if tmpRsCalendarItem.ActivityType == "公开会议" {
- keyword1 = tmpRsCalendarItem.Theme + "," + tmpRsCalendarItem.RoadshowType + tmpRsCalendarItem.ActivityType
- } else {
- startDate := tmpRsCalendarResearcherItem.StartDate[5:]
- startDate = strings.Replace(startDate, "-", ".", -1)
- keyword1 = "会议时间:" + startDate + "(" + tmpRsCalendarResearcherItem.StartWeek + ")" + " " + tmpRsCalendarResearcherItem.StartTime[:5] + "-" + tmpRsCalendarResearcherItem.EndTime[:5]
- keyword2 = "【" + sysUser.RealName + "】已删除" + "【" + tmpRsCalendarItem.ActivityType + ")"
- }
- //keyword2 := "已删除"
- remark := req.DeleteReason
- if sysAdmin.OpenId != "" {
- go services.SendWxMsgWithRoadshowDeleteNotice(first, keyword1, keyword2, remark, wxAppPath, sysAdmin.Mobile)
- }
- }(*rsCalendarItem, *rsCalendarResearcherItem)
- }
- }
- }
- this.OkDetailed(nil, "删除成功")
- }
- // ResearcherList
- // @Title 获取报告电话会类型
- // @Description 获取报告电话会类型接口
- // @Success 200 {object} rs.ResearcherGroup
- // @router /activity/type/list [get]
- func (this *CalendarController) ActivityTypeList() {
- sysUser := this.AdminWx
- if sysUser == nil {
- this.FailWithMessage("请登录", "请登录,SysUser Is Empty")
- return
- }
- // 获取所有的分类
- list, err := rs.GetAllActivityType()
- if err != nil {
- this.FailWithMessage("获取活动类型列表失败", "获取活动类型列表失败,Err:"+err.Error())
- return
- }
- this.OkDetailed(list, "获取成功")
- }
- // @Title 路演-研究员日历详情
- // @Description 路演-研究员日历详情接口
- // @Param StartDate query string true "开始日期"
- // @Param EndDate query string true "结束日期日期"
- // @Param ResearcherId query int true "研究员id"
- // @Success 200 {object} roadshow.CalendarDetailResp
- // @router /researcher/calendar/detail [get]
- func (this *CalendarController) ResearcherCalendarDetail() {
- sysUser := this.AdminWx
- if sysUser == nil {
- this.FailWithMessage("请登录", "请登录,SysUser Is Empty")
- return
- }
- startDate := this.GetString("StartDate")
- endDate := this.GetString("EndDate")
- researcherId, _ := this.GetInt("ResearcherId")
- if startDate == "" || endDate == "" {
- this.FailWithMessage("参数错误!", "参数错误 StartDate"+startDate+" EndDate:"+endDate)
- return
- }
- var condition string
- var pars []interface{}
- if researcherId <= 0 {
- calendarList := make([]*roadshow.CalendarListView, 0)
- matterList := make([]*roadshow.RsMatters, 0)
- resp := new(roadshow.CalendarPanelDetailResp)
- resp.CalendarList = calendarList
- resp.RsMattersList = matterList
- this.OkDetailed(resp, "删除成功")
- return
- } else {
- condition += ` AND b.researcher_id =? `
- pars = append(pars, researcherId)
- }
- //同步上海数据
- researcherInfo, err := admin.GetAdminById(researcherId)
- if err != nil {
- this.FailWithMessage("研究员异常!", "研究员异常"+err.Error())
- return
- }
- //go rs.SyncCalendarFromShanghai(researcherInfo.Mobile, startDate, endDate)
- go rs.InsertSyncCalendarFromShanghaiLPush(researcherInfo.Mobile, startDate, endDate)
- //condition += ` AND b.start_date>=?`
- //pars = append(pars, startDate)
- //condition += ` AND b.end_date<=?`
- //pars = append(pars, endDate)
- //解决研究员休假,产生跨周的数据查询不到的bug,
- condition += ` AND ( b.start_date >= ? AND b.end_date <= ?
- OR ( b.start_date >= ? AND b.start_date <= ? )
- OR ( b.start_date <= ? AND b.end_date >= ? )
- OR ( b.end_date >= ? AND b.end_date <= ? ) ) `
- pars = append(pars, startDate, endDate, startDate, endDate, startDate, endDate, startDate, endDate)
- condition += ` AND b.status IN(2) `
- //pars = append(pars, 2)
- calendarList, err := roadshow.GetCalendarDetailList(condition, pars)
- if err != nil {
- this.FailWithMessage("获取数据失败!", "获取数据失败,GetCalendarDetailList Err:"+err.Error())
- return
- }
- matterList, err := roadshow.GetRsMattersList(startDate, endDate, researcherId)
- if err != nil {
- this.FailWithMessage("获取数据失败!", "获取数据失败,GetRsMattersList Err:"+err.Error())
- return
- }
- if calendarList == nil {
- calendarList = make([]*roadshow.CalendarListView, 0)
- } else {
- var sysUserIds []int //建会人ID
- var companyIds []int //公司ID
- for _, v := range calendarList { //上海同步过来信息展示逻辑替换 需求池 953
- if v.Source == 1 && v.CompanyName == "" {
- v.CompanyName = v.Title
- }
- if v.SysUserId > 0 {
- sysUserIds = append(sysUserIds, v.SysUserId)
- }
- if v.CompanyId > 1 {
- companyIds = append(companyIds, v.CompanyId)
- }
- }
- //如果是权益销售建的会,客户状态替换成权益那边的
- mapSellRai := make(map[int]bool) // 是否是权益销售
- mapStatus := make(map[int]string) //权益客户对应的状态
- if len(sysUserIds) > 0 && len(companyIds) > 0 {
- //判断哪些人是权益销售
- adminList, err := admin.GetAdminListByIdListWithoutEnable(sysUserIds)
- if err != nil {
- this.FailWithMessage("获取数据失败!", "获取数据失败,GetAdminListByIdListWithoutEnable Err:"+err.Error())
- return
- }
- for _, v := range adminList {
- if v.RoleTypeCode == utils.ROLE_TYPE_CODE_RAI_SELLER || v.RoleTypeCode == utils.ROLE_TYPE_CODE_RAI_GROUP {
- mapSellRai[v.AdminId] = true
- }
- }
- conditionProduct := ` AND company_id IN (` + utils.GetOrmInReplace(len(companyIds)) + `) AND product_id = 2 `
- parsProduct := make([]interface{}, 0)
- parsProduct = append(parsProduct, companyIds)
- productList, err := company_product.GetCompanyProductList(conditionProduct, parsProduct)
- if err != nil {
- this.FailWithMessage("获取数据失败!", "获取数据失败,GetCompanyProductList Err:"+err.Error())
- return
- }
- for _, v := range productList {
- mapStatus[v.CompanyId] = v.Status
- }
- }
- for _, v := range calendarList {
- if mapSellRai[v.SysUserId] && mapStatus[v.CompanyId] != "" {
- v.CompanyStatus = mapStatus[v.CompanyId]
- }
- }
- }
- if matterList == nil {
- matterList = make([]*roadshow.RsMatters, 0)
- }
- resp := new(roadshow.CalendarPanelDetailResp)
- resp.CalendarList = calendarList
- resp.RsMattersList = matterList
- this.OkDetailed(resp, "删除成功")
- }
- // @Title 路演-我的日历详情
- // @Description 路演-我的日历详情接口
- // @Param StartDate query string true "开始日期"
- // @Param EndDate query string true "结束日期日期"
- // @Success 200 {object} roadshow.CalendarDetailResp
- // @router /my/calendar/detail [get]
- func (this *CalendarController) MyCalendarDetail() {
- sysUser := this.AdminWx
- if sysUser == nil {
- this.FailWithMessage("请登录", "请登录,SysUser Is Empty")
- return
- }
- startDate := this.GetString("StartDate")
- endDate := this.GetString("EndDate")
- if startDate == "" || endDate == "" {
- this.FailWithMessage("参数错误!", "参数错误 StartDate:"+startDate+" EndDate:"+endDate)
- return
- }
- var condition string
- var pars []interface{}
- roleTypeCode := sysUser.RoleTypeCode
- //权益销售
- if roleTypeCode == utils.ROLE_TYPE_CODE_RAI_SELLER ||
- roleTypeCode == utils.ROLE_TYPE_CODE_RAI_GROUP {
- //if calendarType == 2 {
- condition += ` AND ( a.sys_user_id=? OR a.seller_id=? OR a.share_seller_id=? ) `
- pars = append(pars, sysUser.AdminId, sysUser.AdminId, sysUser.AdminId)
- //}
- } else {
- //销售
- if roleTypeCode == utils.ROLE_TYPE_CODE_FICC_SELLER ||
- roleTypeCode == utils.ROLE_TYPE_CODE_RAI_SELLER ||
- roleTypeCode == utils.ROLE_TYPE_CODE_FICC_GROUP ||
- roleTypeCode == utils.ROLE_TYPE_CODE_RAI_GROUP ||
- roleTypeCode == utils.ROLE_TYPE_CODE_RAI_ADMIN { // 王芳也作为销售身份处理 {
- condition += ` AND a.sys_user_id=?`
- pars = append(pars, sysUser.AdminId)
- condition += ` AND a.activity_type IN('路演','公开会议','沙龙') `
- }
- }
- //研究员
- if roleTypeCode == utils.ROLE_TYPE_CODE_FICC_RESEARCHR ||
- roleTypeCode == utils.ROLE_TYPE_CODE_RESEARCHR ||
- roleTypeCode == utils.ROLE_TYPE_CODE_RAI_RESEARCHR ||
- roleTypeCode == utils.ROLE_TYPE_CODE_FICC_ADMIN {
- condition += ` AND b.researcher_id=?`
- pars = append(pars, sysUser.AdminId)
- //同步上海数据
- researcherInfo, err := admin.GetAdminById(sysUser.AdminId)
- if err != nil {
- this.FailWithMessage("研究员异常!", "研究员异常"+err.Error())
- return
- }
- //go rs.SyncCalendarFromShanghai(researcherInfo.Mobile, startDate, endDate)
- go rs.InsertSyncCalendarFromShanghaiLPush(researcherInfo.Mobile, startDate, endDate)
- }
- //中级/普通/admin 管理员
- if roleTypeCode == utils.ROLE_TYPE_CODE_ADMIN {
- condition += ` AND a.sys_user_id=?`
- pars = append(pars, sysUser.AdminId)
- }
- //condition += ` AND b.start_date>=?`
- //pars = append(pars, startDate)
- //condition += ` AND b.end_date<=?`
- //pars = append(pars, endDate)
- //解决研究员休假,产生跨周的数据查询不到的bug,
- condition += ` AND ( b.start_date >= ? AND b.end_date <= ?
- OR ( b.start_date >= ? AND b.start_date <= ? )
- OR ( b.start_date <= ? AND b.end_date >= ? )
- OR ( b.end_date >= ? AND b.end_date <= ? ) ) `
- pars = append(pars, startDate, endDate, startDate, endDate, startDate, endDate, startDate, endDate)
- condition += ` AND b.status IN(2) `
- //pars = append(pars, 2)
- calendarList, err := roadshow.GetCalendarDetailList(condition, pars)
- if err != nil {
- this.FailWithMessage("获取数据失败!", "获取数据失败,GetCalendarDetailList Err:"+err.Error())
- return
- }
- if calendarList == nil {
- calendarList = make([]*roadshow.CalendarListView, 0)
- } else {
- var sysUserIds []int //建会人ID
- var companyIds []int //公司ID
- for _, v := range calendarList { //上海同步过来信息展示逻辑替换 需求池 953
- if v.Source == 1 && v.CompanyName == "" {
- v.CompanyName = v.Title
- }
- if v.SysUserId > 0 {
- sysUserIds = append(sysUserIds, v.SysUserId)
- }
- if v.CompanyId > 1 {
- companyIds = append(companyIds, v.CompanyId)
- }
- }
- //如果是权益销售建的会,客户状态替换成权益那边的
- mapSellRai := make(map[int]bool) // 是否是权益销售
- mapStatus := make(map[int]string) //权益客户对应的状态
- if len(sysUserIds) > 0 && len(companyIds) > 0 {
- //判断哪些人是权益销售
- adminList, err := admin.GetAdminListByIdListWithoutEnable(sysUserIds)
- if err != nil {
- this.FailWithMessage("获取数据失败!", "获取数据失败,GetAdminListByIdListWithoutEnable Err:"+err.Error())
- return
- }
- for _, v := range adminList {
- if v.RoleTypeCode == utils.ROLE_TYPE_CODE_RAI_SELLER || v.RoleTypeCode == utils.ROLE_TYPE_CODE_RAI_GROUP {
- mapSellRai[v.AdminId] = true
- }
- }
- conditionProduct := ` AND company_id IN (` + utils.GetOrmInReplace(len(companyIds)) + `) AND product_id = 2 `
- parsProduct := make([]interface{}, 0)
- parsProduct = append(parsProduct, companyIds)
- productList, err := company_product.GetCompanyProductList(conditionProduct, parsProduct)
- if err != nil {
- this.FailWithMessage("获取数据失败!", "获取数据失败,GetCompanyProductList Err:"+err.Error())
- return
- }
- for _, v := range productList {
- mapStatus[v.CompanyId] = v.Status
- }
- }
- for _, v := range calendarList {
- if mapSellRai[v.SysUserId] && mapStatus[v.CompanyId] != "" {
- v.CompanyStatus = mapStatus[v.CompanyId]
- }
- }
- }
- matterList, err := roadshow.GetRsMattersList(startDate, endDate, sysUser.AdminId)
- if err != nil {
- this.FailWithMessage("获取数据失败!", "获取数据失败,GetRsMattersList Err:"+err.Error())
- return
- }
- resp := new(roadshow.CalendarPanelDetailResp)
- resp.CalendarList = calendarList
- resp.RsMattersList = matterList
- this.OkDetailed(resp, "删除成功")
- }
- // SellerCalendarDetail
- // @Title 路演-销售日历详情
- // @Description 路演-销售日历详情
- // @Param StartDate query string true "开始日期"
- // @Param EndDate query string true "结束日期日期"
- // @Param SellerId query int true "销售ID"
- // @Success 200 {object} roadshow.CalendarDetailResp
- // @router /seller/calendar/detail [get]
- func (this *CalendarController) SellerCalendarDetail() {
- sysUser := this.AdminWx
- if sysUser == nil {
- this.FailWithMessage("请登录", "请登录,SysUser Is Empty")
- return
- }
- startDate := this.GetString("StartDate")
- endDate := this.GetString("EndDate")
- sellerId, _ := this.GetInt("SellerId")
- if startDate == "" || endDate == "" {
- this.FailWithMessage("参数错误!", "参数错误 StartDate"+startDate+" EndDate:"+endDate)
- return
- }
- if sellerId <= 0 {
- calendarList := make([]*roadshow.CalendarListView, 0)
- matterList := make([]*roadshow.RsMatters, 0)
- resp := new(roadshow.CalendarPanelDetailResp)
- resp.CalendarList = calendarList
- resp.RsMattersList = matterList
- this.OkDetailed(resp, "删除成功")
- return
- }
- // 路演
- condition := ` AND a.sys_user_id = ? AND b.start_date >= ? AND b.end_date <= ? AND b.status = 2`
- pars := make([]interface{}, 0)
- pars = append(pars, sellerId, startDate, endDate)
- calendarList, err := roadshow.GetCalendarDetailList(condition, pars)
- if err != nil {
- this.FailWithMessage("获取数据失败", "获取数据失败, GetCalendarDetailList Err:"+err.Error())
- return
- }
- if calendarList == nil {
- calendarList = make([]*roadshow.CalendarListView, 0)
- }
- // 事项
- matterList, err := roadshow.GetRsMattersList(startDate, endDate, sellerId)
- if err != nil {
- this.FailWithMessage("获取数据失败", "获取数据失败, GetRsMattersList Err:"+err.Error())
- return
- }
- if matterList == nil {
- matterList = make([]*roadshow.RsMatters, 0)
- }
- resp := new(roadshow.CalendarPanelDetailResp)
- resp.CalendarList = calendarList
- resp.RsMattersList = matterList
- this.OkDetailed(resp, "删除成功")
- }
- // isSellerRole 是否为销售角色
- func isSellerRole(roleType string) (ok bool) {
- sellerArr := []string{
- utils.ROLE_TYPE_CODE_FICC_SELLER, utils.ROLE_TYPE_CODE_FICC_GROUP, utils.ROLE_TYPE_CODE_FICC_TEAM,
- utils.ROLE_TYPE_CODE_RAI_SELLER, utils.ROLE_TYPE_CODE_RAI_GROUP,
- }
- if utils.InArrayByStr(sellerArr, roleType) {
- ok = true
- }
- return
- }
|