123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073207420752076207720782079208020812082208320842085208620872088208920902091209220932094209520962097209820992100210121022103210421052106210721082109211021112112211321142115211621172118211921202121212221232124212521262127212821292130213121322133213421352136213721382139214021412142214321442145214621472148214921502151215221532154215521562157215821592160216121622163216421652166216721682169217021712172217321742175217621772178217921802181218221832184218521862187218821892190219121922193219421952196219721982199220022012202220322042205220622072208220922102211221222132214221522162217221822192220222122222223222422252226222722282229223022312232223322342235223622372238223922402241224222432244224522462247224822492250225122522253225422552256225722582259226022612262226322642265226622672268226922702271227222732274227522762277227822792280228122822283228422852286228722882289229022912292229322942295229622972298229923002301230223032304230523062307230823092310231123122313231423152316231723182319232023212322232323242325232623272328232923302331233223332334233523362337233823392340234123422343234423452346234723482349235023512352235323542355235623572358235923602361236223632364236523662367236823692370237123722373237423752376237723782379238023812382238323842385238623872388238923902391239223932394239523962397239823992400240124022403240424052406240724082409241024112412241324142415241624172418241924202421242224232424242524262427242824292430243124322433243424352436243724382439244024412442244324442445244624472448244924502451245224532454245524562457245824592460246124622463246424652466246724682469247024712472247324742475247624772478247924802481248224832484248524862487248824892490249124922493249424952496249724982499250025012502250325042505250625072508250925102511251225132514251525162517251825192520252125222523252425252526252725282529253025312532253325342535253625372538253925402541254225432544254525462547254825492550255125522553255425552556255725582559256025612562256325642565256625672568256925702571257225732574257525762577257825792580258125822583258425852586258725882589259025912592259325942595259625972598259926002601260226032604260526062607260826092610261126122613261426152616261726182619262026212622262326242625262626272628262926302631263226332634263526362637263826392640264126422643264426452646264726482649265026512652265326542655265626572658265926602661266226632664266526662667266826692670267126722673267426752676267726782679268026812682268326842685268626872688268926902691269226932694269526962697269826992700270127022703270427052706270727082709271027112712271327142715271627172718271927202721272227232724272527262727272827292730273127322733273427352736273727382739274027412742274327442745274627472748274927502751275227532754275527562757275827592760276127622763276427652766276727682769277027712772277327742775277627772778277927802781278227832784278527862787278827892790279127922793279427952796279727982799280028012802280328042805280628072808280928102811281228132814281528162817281828192820282128222823282428252826282728282829283028312832283328342835283628372838283928402841284228432844284528462847284828492850285128522853285428552856285728582859286028612862286328642865286628672868286928702871287228732874287528762877287828792880288128822883288428852886288728882889289028912892289328942895289628972898289929002901290229032904290529062907290829092910291129122913291429152916291729182919292029212922292329242925292629272928292929302931293229332934293529362937293829392940294129422943294429452946294729482949295029512952295329542955295629572958295929602961296229632964296529662967296829692970297129722973297429752976297729782979298029812982 |
- package roadshow
- import (
- "encoding/json"
- "fmt"
- "github.com/rdlucklib/rdluck_tools/paging"
- "hongze/hz_crm_api/controllers"
- "hongze/hz_crm_api/models"
- "hongze/hz_crm_api/models/company"
- "hongze/hz_crm_api/models/cygx"
- "hongze/hz_crm_api/models/roadshow"
- "hongze/hz_crm_api/models/system"
- "hongze/hz_crm_api/services"
- roadshowService "hongze/hz_crm_api/services/roadshow"
- "hongze/hz_crm_api/utils"
- "strconv"
- "strings"
- "time"
- )
- // 日历
- type CalendarController struct {
- controllers.BaseAuthController
- }
- // @Title 新增路演活动接口
- // @Description 新增路演活动接口
- // @Param request body roadshow.AddActivityReq true "type json string"
- // @Success Ret=200 保存成功
- // @router /add [post]
- func (this *CalendarController) Add() {
- br := new(models.BaseResponse).Init()
- defer func() {
- this.Data["json"] = br
- this.ServeJSON()
- }()
- sysUser := this.SysUser
- if sysUser == nil {
- br.Msg = "请登录"
- br.ErrMsg = "请登录,SysUser Is Empty"
- br.Ret = 408
- return
- }
- deleteCache := true
- cacheKey := "CACHE_RS_ACTIVITY_ADD_" + strconv.Itoa(sysUser.AdminId)
- defer func() {
- if deleteCache {
- utils.Rc.Delete(cacheKey)
- }
- }()
- if !utils.Rc.SetNX(cacheKey, 1, 5*time.Second) {
- deleteCache = false
- br.Msg = "系统处理中,请稍后重试!"
- br.ErrMsg = "系统处理中,请稍后重试!" + sysUser.RealName + ";data:" + string(this.Ctx.Input.RequestBody)
- return
- }
- var req roadshow.AddActivityReq
- err := json.Unmarshal(this.Ctx.Input.RequestBody, &req)
- if err != nil {
- br.Msg = "参数解析异常!"
- br.ErrMsg = "参数解析失败,Err:" + err.Error()
- return
- }
- if len(req.ResearcherList) <= 0 {
- br.Msg = "请选择研究员!"
- return
- }
- researcherMap := make(map[int]string)
- var checkIsAdd []string
- //获取所有自定义的权益研究员
- sysUserList, err := cygx.GetAskEmailList()
- if err != nil {
- br.Msg = "获取失败"
- br.ErrMsg = "获取失败,GetAskEmailList Err: " + err.Error()
- return
- }
- raiAskadminMap := make(map[int]bool, 0)
- for _, v := range sysUserList {
- raiAskadminMap[v.AdminId] = true
- }
- sysUserFwang, e := system.GetSysUserByAdminName("fwang") // 手动拼接王芳到权益的策略行业下 start
- if e != nil {
- if e.Error() == utils.ErrNoRow() {
- br.Msg = "用户不存在, 请检查"
- return
- }
- br.Msg = "账号错误, 请重新输入"
- br.ErrMsg = "fwang 用户名获取用户失败, Err: " + e.Error()
- return
- }
- raiAskadminMap[sysUserFwang.AdminId] = true // 手动拼接王芳到权益的策略行业下 end
- //var tipMsg string
- for _, v := range req.ResearcherList {
- if v.ResearcherId <= 0 {
- br.Msg = "请选择研究员!"
- return
- }
- if v.ResearcherName == "" {
- br.Msg = "请选择研究员!"
- return
- }
- if v.StartDate == "" {
- br.Msg = "请选择开始日期!"
- return
- }
- if v.EndDate == "" {
- br.Msg = "请选择结束日期!"
- return
- }
- if v.StartTime == "" {
- br.Msg = "请选择开始时间!"
- return
- }
- if v.EndTime == "" {
- br.Msg = "请选择结束时间!"
- return
- }
- if v.StartWeek == "" {
- br.Msg = "请选择周!"
- return
- }
- if v.EndWeek == "" {
- br.Msg = "请选择周!"
- return
- }
- if req.ActivityType == "沙龙" && !raiAskadminMap[v.ResearcherId] {
- br.Msg = "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()) {
- br.Msg = "活动开始时间不能小于当前时间!"
- return
- }
- if endP.Before(time.Now()) || endP.Equal(time.Now()) {
- br.Msg = "活动结束时间不能小于当前时间!"
- return
- }
- if startP.After(endP) || startP.Equal(endP) {
- br.Msg = "活动开始时间应小于结束时间!"
- return
- }
- if realName, ok := researcherMap[v.ResearcherId]; ok {
- br.Msg = "研究员:" + realName + " 被重复选择"
- return
- }
- researcherMap[v.ResearcherId] = v.ResearcherName
- //同步上海数据
- researcherInfo, err := system.GetSysAdminById(v.ResearcherId)
- if err != nil {
- br.Msg = "研究员异常"
- return
- }
- _ = roadshowService.SyncCalendarFromShanghai(researcherInfo.Mobile, v.StartDate, v.EndDate)
- //校验事项时间冲突
- {
- matterCount, err := roadshowService.CheckMatters(startDateTime, endDateTime, v.ResearcherId, 0)
- if err != nil {
- br.Msg = "时间冲突检测失败!"
- br.ErrMsg = "时间冲突检测失败-CheckMattersCount!Err:" + err.Error()
- return
- }
- if matterCount > 0 {
- checkIsAdd = append(checkIsAdd, v.ResearcherName)
- }
- }
- //校验活动时间冲突
- {
- calendarCount, err := roadshowService.CheckCalendar(startDateTime, endDateTime, "1,2", v.ResearcherId, 0)
- if err != nil {
- br.Msg = "时间冲突检测失败!"
- br.ErrMsg = "时间冲突检测失败-CheckCalendar!Err:" + err.Error()
- return
- }
- if calendarCount > 0 {
- checkIsAdd = append(checkIsAdd, v.ResearcherName)
- }
- }
- }
- if len(checkIsAdd) > 0 {
- br.Msg = strings.Join(checkIsAdd, ",") + " 时间已被占用!"
- br.ErrMsg = "时间冲突检测失败-CheckMattersCount!"
- br.IsSendEmail = false
- return
- }
- //如果是权益客户,添加销售跟共享销售的信息
- var productItemRai *company.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.GetCompanyProductByCompanyIdAndProductId(req.CompanyId, utils.COMPANY_PRODUCT_RAI_ID)
- if err != nil && err.Error() != utils.ErrNoRow() {
- br.Msg = "客户信息有误"
- br.ErrMsg = "获取客户信息失败, 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 {
- br.Msg = "保存失败!"
- br.ErrMsg = "保存日历活动信息失败!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 {
- br.Msg = "保存失败!"
- br.ErrMsg = "保存日历活动-研究员信息失败!Err:" + err.Error()
- return
- }
- rsCalendar.RsCalendarId = int(rsCalendarId)
- researcher.RsCalendarResearcherId = int(rsCalendarResearcherId)
- go roadshowService.CalendarToSH(*rsCalendar, *researcher)
- //模板消息通知
- {
- go func(researcherId, tmpRsCalendarId, tmpRsCalendarResearcherId int) { // 研究员id,路演id,路演与研究员记录的id
- var wxAppPath string
- sysAdmin, _ := system.GetSysAdminById(researcherId)
- if sysAdmin != nil && sysAdmin.OpenId != "" {
- openIdObj := &system.OpenIdList{
- OpenId: sysAdmin.OpenId,
- AdminId: sysAdmin.AdminId,
- }
- openIdList := make([]*system.OpenIdList, 0)
- openIdList = append(openIdList, openIdObj)
- 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 := "--"
- startDateSub := v.StartDate[5:]
- startDateSub = strings.Replace(startDateSub, "-", ".", -1)
- //keyword3 := time.Now().Format(utils.FormatDateTime)
- 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 len(openIdList) > 0 {
- services.SendWxMsgWithRoadshowPending(first, keyword1, keyword2, keyword3, keyword4, remark, wxAppPath, openIdList)
- }
- } 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 len(openIdList) > 0 {
- services.SendWxMsgWithRoadshowDeleteNotice(first, keyword1, keyword2, "", wxAppPath, openIdList)
- }
- }
- }
- }(v.ResearcherId, int(rsCalendarId), int(rsCalendarResearcherId))
- }
- }
- //if req.ActivityType == "公开会议" {
- // go roadshowService.SetPublicMeetingUnionCode()
- //}
- br.Ret = 200
- br.Success = true
- br.Msg = "保存成功"
- br.IsAddLog = true
- }
- // @Title 编辑路演活动接口
- // @Description编辑路演活动接口
- // @Param request body roadshow.EditActivityReq true "type json string"
- // @Success Ret=200 保存成功
- // @router /edit [post]
- func (this *CalendarController) Edit() {
- br := new(models.BaseResponse).Init()
- defer func() {
- this.Data["json"] = br
- this.ServeJSON()
- }()
- sysUser := this.SysUser
- if sysUser == nil {
- br.Msg = "请登录"
- br.ErrMsg = "请登录,SysUser Is Empty"
- br.Ret = 408
- 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, 5*time.Second) {
- deleteCache = false
- br.Msg = "系统处理中,请稍后重试!"
- br.ErrMsg = "系统处理中,请稍后重试!" + sysUser.RealName + ";data:" + string(this.Ctx.Input.RequestBody)
- return
- }
- var req roadshow.EditActivityReq
- err := json.Unmarshal(this.Ctx.Input.RequestBody, &req)
- if err != nil {
- br.Msg = "参数解析异常!"
- br.ErrMsg = "参数解析失败,Err:" + err.Error()
- return
- }
- if req.RsCalendarId <= 0 {
- br.Msg = "参数错误!"
- br.ErrMsg = "RsCalendarId<=0"
- return
- }
- if req.RsCalendarResearcherId <= 0 {
- br.Msg = "参数错误!"
- br.ErrMsg = "RsCalendarResearcherId<=0"
- return
- }
- if req.ActivityType == "" {
- br.Msg = "请选择活动类型!"
- return
- }
- if len(req.ResearcherList) <= 0 {
- br.Msg = "请选择研究员!"
- return
- }
- researcherMap := make(map[int]string)
- var checkIsAdd []string
- for _, v := range req.ResearcherList {
- if v.ResearcherId <= 0 {
- br.Msg = "请选择研究员!"
- return
- }
- if v.ResearcherName == "" {
- br.Msg = "请选择研究员!"
- return
- }
- if v.StartDate == "" {
- br.Msg = "请选择开始日期!"
- return
- }
- if v.EndDate == "" {
- br.Msg = "请选择结束日期!"
- return
- }
- if v.StartTime == "" {
- br.Msg = "请选择开始时间!"
- return
- }
- if v.EndTime == "" {
- br.Msg = "请选择结束时间!"
- return
- }
- if v.StartWeek == "" {
- br.Msg = "请选择周!"
- return
- }
- if v.EndWeek == "" {
- br.Msg = "请选择周!"
- return
- }
- if realName, ok := researcherMap[v.ResearcherId]; ok {
- br.Msg = "研究员:" + 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()) {
- br.Msg = "活动开始时间不能小于当前时间!"
- return
- }
- if endP.Before(time.Now()) || endP.Equal(time.Now()) {
- br.Msg = "活动结束时间不能小于当前时间!"
- return
- }
- if startP.After(endP) || startP.Equal(endP) {
- br.Msg = "活动开始时间应小于结束时间!"
- return
- }
- /*
- 时间冲突时,提示:xxx时间已被占用
- 当有任意一个研究员时间有冲突时,所有申请订单都不发送。
- */
- rsCalendarResearcherItem, err := roadshow.GetRsCalendarResearcherByRsCalendarIdAndResearcherId(req.RsCalendarId, v.ResearcherId)
- var isAdd bool
- if err != nil {
- if err.Error() == utils.ErrNoRow() {
- isAdd = true
- } else {
- br.Msg = "获取数据失败!"
- br.ErrMsg = "获取数据失败!GetRsCalendarResearcherByRsCalendarIdAndResearcherId:" + err.Error()
- return
- }
- }
- var rsCalendarResearcherId int
- if rsCalendarResearcherItem == nil {
- isAdd = true
- } else {
- rsCalendarResearcherId = rsCalendarResearcherItem.RsCalendarResearcherId
- }
- //同步上海数据
- researcherInfo, err := system.GetSysAdminById(v.ResearcherId)
- if err != nil {
- br.Msg = "研究员异常"
- return
- }
- _ = roadshowService.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 := roadshowService.CheckMatters(startDateTime, endDateTime, v.ResearcherId, 0)
- if err != nil {
- br.Msg = "时间冲突检测失败!"
- br.ErrMsg = "时间冲突检测失败-CheckMattersCount!Err:" + err.Error()
- return
- }
- if matterCount > 0 {
- checkIsAdd = append(checkIsAdd, v.ResearcherName)
- }
- }
- }
- //校验活动时间冲突
- //{
- // if isAdd || (rsCalendarResearcherItem != nil && (rsCalendarResearcherItem.StartDate != v.StartDate ||
- // rsCalendarResearcherItem.StartTime != v.StartTime ||
- // rsCalendarResearcherItem.EndDate != v.EndDate ||
- // rsCalendarResearcherItem.EndTime != v.EndTime)) {
- //
- // calendarCount, err := roadshowService.CheckCalendar(startDateTime, endDateTime, "1,2", v.ResearcherId, rsCalendarResearcherId)
- // if err != nil {
- // br.Msg = "时间冲突检测失败!"
- // br.ErrMsg = "时间冲突检测失败-CheckCalendarResearcherCount!Err:" + err.Error()
- // return
- // }
- // if calendarCount > 0 {
- // checkIsAdd = append(checkIsAdd, v.ResearcherName)
- // }
- // }
- //}
- calendarCount, err := roadshowService.CheckCalendar(startDateTime, endDateTime, "1,2", v.ResearcherId, rsCalendarResearcherId)
- if err != nil {
- br.Msg = "时间冲突检测失败!"
- br.ErrMsg = "时间冲突检测失败-CheckCalendarResearcherCount!Err:" + err.Error()
- return
- }
- if calendarCount > 0 {
- checkIsAdd = append(checkIsAdd, v.ResearcherName)
- }
- }
- if len(checkIsAdd) > 0 {
- br.Msg = strings.Join(checkIsAdd, ",") + "时间已被占用!"
- br.ErrMsg = "时间冲突检测失败-CheckMattersCount!"
- br.IsSendEmail = false
- return
- }
- rsCalendarItem, err := roadshow.GetRsCalendarById(req.RsCalendarId)
- if err != nil {
- br.Msg = "获取数据失败!"
- br.ErrMsg = "获取数据失败!GetRsCalendarById:" + err.Error()
- return
- }
- if rsCalendarItem == nil {
- br.Msg = "保存失败!"
- br.ErrMsg = "获取数据失败!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 {
- br.Msg = "保存失败!"
- br.ErrMsg = "保存失败!UpdateRsCalendar:" + err.Error()
- return
- }
- //newResearcherMap := make(map[int]string)
- existList, err := roadshow.GetRsCalendarResearcherByCalendarId(req.RsCalendarId)
- if err != nil {
- br.Msg = "保存失败!"
- br.ErrMsg = "保存失败!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 {
- br.Msg = "获取失败"
- br.ErrMsg = "获取失败,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 {
- br.Msg = "获取数据失败!"
- br.ErrMsg = "获取数据失败!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
- rsCalendarResearcherItem.ResearcherId = v.ResearcherId
- rsCalendarResearcherItem.ResearcherName = v.ResearcherName
- if rsCalendarResearcherItem.Status == 3 || rsCalendarResearcherItem.Status == 5 {
- calendarResearcherUpdateParams["status"] = 1
- rsCalendarResearcherItem.Status = 1
- }
- //CRM15.5 权益研究员直接通过
- if raiAskadminMap[v.ResearcherId] {
- calendarResearcherUpdateParams["status"] = 2
- rsCalendarResearcherItem.Status = 2
- }
- calendarResearcherUpdateParams["start_date"] = v.StartDate
- rsCalendarResearcherItem.StartDate = v.StartDate
- calendarResearcherUpdateParams["end_date"] = v.EndDate
- rsCalendarResearcherItem.EndDate = v.EndDate
- calendarResearcherUpdateParams["start_time"] = v.StartTime
- rsCalendarResearcherItem.StartTime = v.StartTime
- calendarResearcherUpdateParams["end_time"] = v.EndTime
- rsCalendarResearcherItem.EndTime = v.EndTime
- calendarResearcherUpdateParams["start_week"] = v.StartWeek
- rsCalendarResearcherItem.StartWeek = v.StartWeek
- calendarResearcherUpdateParams["end_week"] = v.EndWeek
- rsCalendarResearcherItem.EndWeek = v.EndWeek
- calendarResearcherUpdateParams["refuse_reason"] = ""
- rsCalendarResearcherItem.RefuseReason = ""
- calendarResearcherUpdateParams["refuse_time"] = nil
- calendarResearcherUpdateParams["delete_reason"] = ""
- rsCalendarResearcherItem.DeleteReason = ""
- calendarResearcherUpdateParams["approve_time"] = nil
- calendarResearcherUpdateParams["researcher_sort"] = k + 1
- rsCalendarResearcherItem.ResearcherSort = k + 1
- calendarResearcherUpdateParams["modify_time"] = time.Now()
- rsCalendarResearcherItem.ModifyTime = time.Now()
- calendarResearcherUpdateParams["create_time"] = time.Now()
- rsCalendarResearcherItem.CreateTime = time.Now()
- err = roadshow.UpdateCalendarResearcher(calendarResearcherWhereParams, calendarResearcherUpdateParams)
- if err != nil {
- br.Msg = "保存失败!"
- br.ErrMsg = "保存失败!UpdateCalendarResearcher:" + err.Error()
- return
- }
- //上海新增(因为在驳回的时候,就把上海该时间段的日程给删除了,所以修改的时候,需要重新调用新增接口)
- calendar := roadshow.RsCalendar{
- RsCalendarId: req.RsCalendarId,
- SysUserId: this.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 roadshowService.CalendarToSH(calendar, researcher)
- if req.EditType == 2 {
- //模板消息通知
- go func(researcherId, tmpRsCalendarId, tmpRsCalendarResearcherId int) {
- sysAdmin, _ := system.GetSysAdminById(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)
- openIdObj := &system.OpenIdList{
- OpenId: sysAdmin.OpenId,
- AdminId: sysAdmin.AdminId,
- }
- openIdList := make([]*system.OpenIdList, 0)
- openIdList = append(openIdList, openIdObj)
- if sysAdmin.OpenId != "" {
- services.SendWxMsgWithRoadshowPending(first, keyword1, keyword2, keyword3, keyword4, remark, wxAppPath, openIdList)
- }
- }
- }(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)
- return
- }
- //先删后增
- err = roadshow.DeleteRsCalendarResearcher(req.RsCalendarId)
- if err != nil {
- br.Msg = "保存失败!"
- br.ErrMsg = "保存失败!DeleteRsCalendarResearcher:" + err.Error()
- return
- }
- //删除上海
- for _, researcher := range researchers {
- roadshowService.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 {
- br.Msg = "保存失败!"
- br.ErrMsg = "保存日历活动-研究员信息失败!Err:" + err.Error()
- return
- }
- //上海新增
- calendar := roadshow.RsCalendar{
- RsCalendarId: req.RsCalendarId,
- SysUserId: this.SysUser.AdminId,
- Title: getTitle(req.ActivityType, req.RoadshowType, req.ActivityCategory, req.RoadshowPlatform, req.Province, req.City),
- }
- researcher.RsCalendarResearcherId = int(rsCalendarResearcherId)
- go roadshowService.CalendarToSH(calendar, *researcher)
- go func(researcherId, tmpRsCalendarId, tmpRsCalendarResearcherId int) {
- sysAdmin, _ := system.GetSysAdminById(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)
- openIdObj := &system.OpenIdList{
- OpenId: sysAdmin.OpenId,
- AdminId: sysAdmin.AdminId,
- }
- openIdList := make([]*system.OpenIdList, 0)
- openIdList = append(openIdList, openIdObj)
- if sysAdmin.OpenId != "" {
- services.SendWxMsgWithRoadshowPending(first, keyword1, keyword2, keyword3, keyword4, remark, wxAppPath, openIdList)
- }
- }
- }(v.ResearcherId, req.RsCalendarId, int(rsCalendarResearcherId))
- }
- }
- //for k, v := range req.ResearcherList {
- // rsCalendarResearcherItem, err := roadshow.GetRsCalendarResearcherById(req.RsCalendarResearcherId)
- // var isAdd bool
- // if err != nil {
- // if err.Error() == utils.ErrNoRow() {
- // isAdd = true
- // } else {
- // br.Msg = "获取数据失败!"
- // br.ErrMsg = "获取数据失败!GetRsCalendarResearcherById:" + err.Error()
- // return
- // }
- // }
- // if rsCalendarResearcherItem == nil {
- // isAdd = true
- // }
- // if _, ok := existResearcherMap[v.ResearcherId]; !ok {
- // isAdd = true
- // }
- // fmt.Println("isAdd:", isAdd)
- // if isAdd {
- // exist, err := roadshow.GetRsCalendarResearcherExist(req.RsCalendarResearcherId, req.RsCalendarId, v.ResearcherId)
- // if err != nil && err.Error() != utils.ErrNoRow() {
- // br.Msg = "保存失败!"
- // br.ErrMsg = "保存失败!GetRsCalendarResearcherExist:" + err.Error()
- // return
- // }
- // if exist > 0 {
- // br.Msg = "研究员 " + v.ResearcherName + " 已存在相同活动"
- // br.ErrMsg = "研究员 " + v.ResearcherName + " 已存在相同活动"
- // return
- // }
- // 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
- // }
- // rsCalendarResearcherId, err := roadshow.AddRsCalendarResearcher(researcher)
- // if err != nil {
- // br.Msg = "保存失败!"
- // br.ErrMsg = "保存日历活动-研究员信息失败!Err:" + err.Error()
- // return
- // }
- //
- // //模板消息通知
- // {
- // sysAdmin, _ := system.GetSysAdminById(v.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)
- // var keyword4 string
- // if req.ActivityType == "路演" {
- // keyword4 = startDateSub + "(" + v.StartWeek + ")" + " " + v.StartTime[:5] + "~" + v.EndTime[:5] + " ," + req.CompanyName + "(" + req.RoadshowType + req.ActivityType + ")"
- // } else {
- // keyword4 = startDateSub + "(" + v.StartWeek + ")" + " " + v.StartTime[:5] + "~" + v.EndTime[:5] + " ," + req.Theme + "(" + req.RoadshowType + req.ActivityType + ")"
- // }
- // remark := "请尽快完成审批"
- // wxAppPath := "pages-approve/activity/detail?RsCalendarId=" + strconv.Itoa(req.RsCalendarId) + "&RsCalendarResearcherId=" + strconv.Itoa(int(rsCalendarResearcherId))
- // openIdList, _ := models.GetOpenIdListByMobile(sysAdmin.Mobile)
- // if len(openIdList) > 0 {
- // go services.SendWxMsgWithRoadshowPending(first, keyword1, keyword2, keyword3, keyword4, remark, wxAppPath, openIdList)
- // }
- // }
- // }
- // } else {
- // calendarResearcherWhereParams := make(map[string]interface{})
- // calendarResearcherUpdateParams := make(map[string]interface{})
- //
- // calendarResearcherWhereParams["rs_calendar_researcher_id"] = req.RsCalendarResearcherId
- //
- // exist, err := roadshow.GetRsCalendarResearcherExist(req.RsCalendarResearcherId, req.RsCalendarId, v.ResearcherId)
- // if err != nil && err.Error() != utils.ErrNoRow() {
- // br.Msg = "保存失败!"
- // br.ErrMsg = "保存失败!GetRsCalendarResearcherExist:" + err.Error()
- // return
- // }
- // if exist > 0 {
- // br.Msg = "研究员 " + v.ResearcherName + " 已存在相同活动"
- // br.ErrMsg = "研究员 " + v.ResearcherName + " 已存在相同活动"
- // return
- // }
- //
- // calendarResearcherUpdateParams["researcher_id"] = v.ResearcherId
- // calendarResearcherUpdateParams["researcher_name"] = v.ResearcherName
- //
- // if rsCalendarResearcherItem.Status == 3 || rsCalendarResearcherItem.Status == 5 {
- // calendarResearcherUpdateParams["status"] = 1
- // }
- // 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 {
- // br.Msg = "保存失败!"
- // br.ErrMsg = "保存失败!UpdateCalendarResearcher:" + err.Error()
- // return
- // }
- // if req.EditType == 2 {
- // //模板消息通知
- // {
- // sysAdmin, _ := system.GetSysAdminById(v.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)
- // var keyword4 string
- // if req.ActivityType == "路演" {
- // keyword4 = startDateSub + "(" + v.StartWeek + ")" + " " + v.StartTime[:5] + "~" + v.EndTime[:5] + " ," + req.CompanyName + "(" + req.RoadshowType + req.ActivityType + ")"
- // } else {
- // keyword4 = startDateSub + "(" + v.StartWeek + ")" + " " + v.StartTime[:5] + "~" + v.EndTime[:5] + " ," + req.Theme + "(" + req.RoadshowType + req.ActivityType + ")"
- // }
- // remark := "请尽快完成审批"
- // wxAppPath := "pages-approve/activity/detail?RsCalendarId=" + strconv.Itoa(req.RsCalendarId) + "&RsCalendarResearcherId=" + strconv.Itoa(rsCalendarResearcherItem.RsCalendarResearcherId)
- // openIdList, _ := models.GetOpenIdListByMobile(sysAdmin.Mobile)
- // if len(openIdList) > 0 {
- // go services.SendWxMsgWithRoadshowPending(first, keyword1, keyword2, keyword3, keyword4, remark, wxAppPath, openIdList)
- // }
- // }
- // }
- // }
- //
- // }
- // newResearcherMap[v.ResearcherId] = v.ResearcherName
- //}
- //处理删除情况
- //{
- // if req.EditType == 1 {
- // researchList, err := roadshow.GetRsCalendarResearcherListByRsCalendarId(req.RsCalendarId)
- // if err != nil {
- // br.Msg = "保存失败!"
- // br.ErrMsg = "保存失败!UpdateCalendarResearcher:" + err.Error()
- // return
- // }
- // for _, ev := range researchList {
- // if _, ok := newResearcherMap[ev.ResearcherId]; !ok {
- // roadshow.DeleteCalendar(req.RsCalendarId, ev.RsCalendarResearcherId)
- // }
- // }
- // }
- //}
- //if req.ActivityType == "公开会议" {
- // go roadshowService.SetPublicMeetingUnionCode()
- //}
- br.Ret = 200
- br.Success = true
- br.Msg = "保存成功"
- br.IsAddLog = true
- }
- // ResearcherList
- // @Title 研究员列表
- // @Description 研究员列表接口
- // @Success 200 {object} roadshow.ResearcherGroup
- // @router /researcher/list [get]
- func (this *CalendarController) ResearcherList() {
- br := new(models.BaseResponse).Init()
- defer func() {
- this.Data["json"] = br
- this.ServeJSON()
- }()
- group, err := roadshow.GetResearcherGroup()
- if err != nil {
- br.Msg = "获取信息失败!"
- br.ErrMsg = "获取分组信息失败!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 {
- br.Msg = "获取失败"
- br.ErrMsg = "获取admin列表失败, Err:" + err.Error()
- return
- }
- adminMap := make(map[int]*system.Admin, 0)
- for _, v := range sysUserList {
- adminMap[v.AdminId] = v
- }
- askUserList, err := cygx.GetAskEmailList()
- if err != nil {
- br.Msg = "获取失败"
- br.ErrMsg = "获取失败,GetAskEmailList Err: " + err.Error()
- return
- }
- mapPermissionUser := make(map[string][]*roadshow.ResearcherGroup)
- listPermission, err := cygx.GetChartPermissionAll()
- if err != nil {
- br.Msg = "获取信息失败"
- br.ErrMsg = "获取品种信息失败,Err:" + err.Error()
- return
- }
- mapPermissionId := make(map[string]int)
- for _, v := range listPermission {
- mapPermissionId[v.PermissionName] = v.ChartPermissionId
- }
- sysUserFwang, e := system.GetSysUserByAdminName("fwang") // 手动拼接王芳到权益的策略行业下 start
- if e != nil {
- if e.Error() == utils.ErrNoRow() {
- br.Msg = "用户不存在, 请检查"
- return
- }
- br.Msg = "账号错误, 请重新输入"
- br.ErrMsg = "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)
- br.Ret = 200
- br.Success = true
- br.Msg = "获取成功"
- br.Data = resp
- }
- // CalendarList
- // @Title 我的日历列表
- // @Description 我的日历列表接口
- // @Param PageSize query int true "每页数据条数"
- // @Param CurrentIndex query int true "当前页页码,从1开始"
- // @Param CalendarType query int true "1:待处理申请,2:已处理申请,3:内部会议,4:报告电话会"
- // @Success 200 {object} roadshow.CalendarListResp
- // @router /calendar/list [get]
- func (this *CalendarController) CalendarList() {
- br := new(models.BaseResponse).Init()
- defer func() {
- this.Data["json"] = br
- this.ServeJSON()
- }()
- sysUser := this.SysUser
- if sysUser == nil {
- br.Msg = "请登录"
- br.ErrMsg = "请登录,SysUser Is Empty"
- br.Ret = 408
- return
- }
- calendarType, _ := this.GetInt("CalendarType")
- 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 := sysUser.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_FICC_TEAM ||
- 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_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)
- //}
- }
- 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 {
- if calendarType != 3 {
- condition += ` AND b.researcher_id=?`
- pars = append(pars, sysUser.AdminId)
- }
- }
- if roleTypeCode == utils.ROLE_TYPE_CODE_ADMIN {
- condition += ` AND a.sys_user_id=?`
- pars = append(pars, sysUser.AdminId)
- }
- if calendarType == 1 {
- condition += ` AND b.status=1`
- }
- if calendarType == 2 {
- condition += ` AND b.status>=2`
- condition += ` AND a.activity_type IN('路演','公开会议','沙龙') `
- }
- if calendarType == 3 {
- condition += ` AND a.activity_type='内部会议' `
- condition += ` AND a.sys_user_id=?`
- pars = append(pars, sysUser.AdminId)
- }
- if calendarType == 4 {
- condition += ` AND a.activity_type='报告电话会' `
- }
- if calendarType < 0 || calendarType > 4 {
- br.Msg = "参数错误"
- br.ErrMsg = "参数错误,calendarType:" + strconv.Itoa(calendarType)
- return
- }
- fmt.Println(condition)
- resp := new(roadshow.CalendarListResp)
- total, err := roadshow.GetCalendarListCount(condition, pars, calendarType)
- if err != nil && err.Error() != utils.ErrNoRow() {
- br.Msg = "获取信息失败"
- br.ErrMsg = "获取数据总数失败,GetCalendarListCount,Err:" + err.Error()
- return
- }
- page = paging.GetPaging(currentIndex, pageSize, total)
- dataList, err := roadshow.GetCalendarList(condition, pars, startSize, pageSize, calendarType)
- if err != nil {
- br.Msg = "获取指标信息失败"
- br.ErrMsg = "获取数据失败,GetCalendarList,Err:" + err.Error()
- return
- }
- // 英文客户的国家以及点击量
- englishIds := make([]int, 0)
- adminIds := make([]int, 0) // 管理员ID
- rsCalendarId := make([]int, 0) //路演ID
- for i := range dataList {
- if dataList[i].EnglishCompany == 1 {
- englishIds = append(englishIds, dataList[i].CompanyId)
- }
- if calendarType == 2 {
- adminIds = append(adminIds, dataList[i].SysUserId)
- rsCalendarId = append(rsCalendarId, dataList[i].RsCalendarId)
- }
- }
- englishMap := make(map[int]*models.EnglishCompany)
- if len(englishIds) > 0 {
- englishCond := ` AND company_id IN (` + utils.GetOrmInReplace(len(englishIds)) + `)`
- englishPars := make([]interface{}, 0)
- englishPars = append(englishPars, englishIds)
- englishList, e := models.GetEnglishCompanyList(englishCond, englishPars, "")
- if e != nil {
- br.Msg = "获取英文客户失败"
- br.ErrMsg = "获取英文客户失败, Err:" + e.Error()
- return
- }
- for i := range englishList {
- englishMap[englishList[i].CompanyId] = englishList[i]
- }
- }
- //获取所有自定义的权益研究员
- sysUserList, err := cygx.GetAskEmailList()
- if err != nil {
- br.Msg = "获取失败"
- br.ErrMsg = "获取失败,GetAskEmailList Err: " + err.Error()
- return
- }
- raiAskadminMap := make(map[string]bool, 0)
- for _, v := range sysUserList {
- raiAskadminMap[strconv.Itoa(v.AdminId)] = true
- }
- mapRaiSllerId := make(map[int]bool) // 是否为权益销售
- mapMeetingCount := make(map[int]int) // 路演参会人员数量
- if len(adminIds) > 0 {
- listAdmin, e := system.GetAdminListByIdListWithoutEnable(adminIds)
- if e != nil {
- br.Msg = "获取信息失败"
- br.ErrMsg = "获取管理员信息失败, Err:" + e.Error()
- return
- }
- for _, v := range listAdmin { //权益销售与权益销售组长、权益管理员
- if v.RoleTypeCode == utils.ROLE_TYPE_CODE_RAI_SELLER || v.RoleTypeCode == utils.ROLE_TYPE_CODE_RAI_GROUP || v.RoleTypeCode == utils.ROLE_TYPE_CODE_RAI_ADMIN {
- mapRaiSllerId[v.AdminId] = true
- }
- }
- listMeetingCount, e := roadshow.GetRsCalendarMeetingUserListCount(rsCalendarId)
- if e != nil {
- br.Msg = "获取信息失败"
- br.ErrMsg = "获取路演参会人员数量信息失败, Err:" + e.Error()
- return
- }
- for _, v := range listMeetingCount {
- mapMeetingCount[v.RsCalendarId] = v.Total
- }
- }
- 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
- }
- }
- //如果是已结束的权益销售添加的活动,就行进行按钮展示
- if mapRaiSllerId[dataList[i].SysUserId] && utils.InArrayByInt([]int{2, 6}, dataList[i].Status) && dataList[i].ActivityType != "沙龙" {
- if mapMeetingCount[dataList[i].RsCalendarId] == 0 {
- dataList[i].SubmitButton = true
- } else {
- dataList[i].ViewButton = true
- }
- }
- //权益研究员的【路演】和【沙龙】,未结束时,显示修改按钮
- if raiAskadminMap[dataList[i].ResearcherId] && utils.InArrayByStr([]string{"路演", "沙龙"}, dataList[i].ActivityType) && dataList[i].Status == 2 {
- //未开始的才展示修改按钮
- startTimeStr := dataList[i].StartDate + " " + dataList[i].StartTime
- startTime := utils.StrTimeToTime(startTimeStr)
- if startTime.After(time.Now()) {
- dataList[i].EditButton = true
- }
- }
- }
- resp.Paging = page
- resp.List = dataList
- br.Ret = 200
- br.Success = true
- br.Msg = "获取成功"
- br.Data = resp
- }
- // Accept
- // @Description 接受路演活动接口
- // @Param request body roadshow.AcceptReq true "type json string"
- // @Success Ret=200 保存成功
- // @router /accept [post]
- func (this *CalendarController) Accept() {
- br := new(models.BaseResponse).Init()
- defer func() {
- this.Data["json"] = br
- this.ServeJSON()
- }()
- sysUser := this.SysUser
- if sysUser == nil {
- br.Msg = "请登录"
- br.ErrMsg = "请登录,SysUser Is Empty"
- br.Ret = 408
- return
- }
- var req roadshow.AcceptReq
- err := json.Unmarshal(this.Ctx.Input.RequestBody, &req)
- if err != nil {
- br.Msg = "参数解析异常!"
- br.ErrMsg = "参数解析失败,Err:" + err.Error()
- return
- }
- if req.RsCalendarId <= 0 || req.RsCalendarResearcherId <= 0 {
- br.Msg = "参数错误!"
- br.ErrMsg = "参数错误!RsCalendarId:" + strconv.Itoa(req.RsCalendarId) + ";RsCalendarResearcherId:" + strconv.Itoa(req.RsCalendarResearcherId)
- return
- }
- rsCalendar, err := roadshow.GetRsCalendarById(req.RsCalendarId)
- if err != nil {
- br.Msg = "获取数据失败!"
- br.ErrMsg = "获取数据失败!GetRsCalendarById:" + err.Error()
- return
- }
- rsCalendarResearcher, err := roadshow.GetRsCalendarResearcherById(req.RsCalendarResearcherId)
- if err != nil {
- br.Msg = "获取数据失败!"
- br.ErrMsg = "获取数据失败!GetRsCalendarResearcherById:" + err.Error()
- return
- }
- if rsCalendarResearcher.Status == 2 {
- br.Msg = "已接受,不可重复操作!"
- return
- } else if rsCalendarResearcher.Status == 3 {
- br.Msg = "已拒绝,不可进行接受操作!"
- return
- } else if rsCalendarResearcher.Status == 4 {
- br.Msg = "已删除,不可进行接受操作!"
- return
- } else if rsCalendarResearcher.Status == 5 {
- br.Msg = "已撤回,不可进行接受操作!"
- 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 {
- br.Msg = "保存失败!"
- br.ErrMsg = "保存失败!UpdateCalendarResearcher:" + err.Error()
- return
- }
- //模板消息通知
- {
- if rsCalendar != nil {
- go func(tmpRsCalendar roadshow.RsCalendar) {
- sysAdmin, _ := system.GetSysAdminById(tmpRsCalendar.SysUserId)
- first := "【" + sysUser.RealName + "】接受了你的【" + tmpRsCalendar.ActivityType + "】申请"
- var keyword1, keyword2, keyword3, keyword4, keyword5 string
- keyword1 = tmpRsCalendar.CompanyName + "(" + tmpRsCalendar.RoadshowType + tmpRsCalendar.ActivityType + ")"
- keyword2 = tmpRsCalendar.ActivityType
- keyword4 = `【` + sysUser.RealName + `】已接受`
- remark := ""
- wxAppPath := ""
- openIdObj := &system.OpenIdList{
- OpenId: sysAdmin.OpenId,
- AdminId: sysAdmin.AdminId,
- }
- openIdList := make([]*system.OpenIdList, 0)
- openIdList = append(openIdList, openIdObj)
- if sysAdmin.OpenId != "" {
- services.SendWxMsgWithRoadshowDetailResult(first, keyword1, keyword2, keyword3, keyword4, keyword5, remark, wxAppPath, openIdList)
- }
- }(*rsCalendar)
- }
- }
- br.Ret = 200
- br.Success = true
- br.Msg = "保存成功"
- br.IsAddLog = true
- }
- // @Title 拒绝路演活动接口
- // @Description 拒绝路演活动接口
- // @Param request body roadshow.RefuseReq true "type json string"
- // @Success Ret=200 保存成功
- // @router /refuse [post]
- func (this *CalendarController) Refuse() {
- br := new(models.BaseResponse).Init()
- defer func() {
- this.Data["json"] = br
- this.ServeJSON()
- }()
- sysUser := this.SysUser
- if sysUser == nil {
- br.Msg = "请登录"
- br.ErrMsg = "请登录,SysUser Is Empty"
- br.Ret = 408
- return
- }
- var req roadshow.RefuseReq
- err := json.Unmarshal(this.Ctx.Input.RequestBody, &req)
- if err != nil {
- br.Msg = "参数解析异常!"
- br.ErrMsg = "参数解析失败,Err:" + err.Error()
- return
- }
- if req.RsCalendarId <= 0 || req.RsCalendarResearcherId <= 0 {
- br.Msg = "参数错误!"
- br.ErrMsg = "参数错误!RsCalendarId:" + strconv.Itoa(req.RsCalendarId) + ";RsCalendarResearcherId:" + strconv.Itoa(req.RsCalendarResearcherId)
- return
- }
- rsCalendar, err := roadshow.GetRsCalendarById(req.RsCalendarId)
- if err != nil {
- br.Msg = "获取数据失败!"
- br.ErrMsg = "获取数据失败!GetRsCalendarById:" + err.Error()
- return
- }
- rsCalendarResearcher, err := roadshow.GetRsCalendarResearcherById(req.RsCalendarResearcherId)
- if err != nil {
- br.Msg = "获取数据失败!"
- br.ErrMsg = "获取数据失败!GetRsCalendarResearcherById:" + err.Error()
- return
- }
- if rsCalendarResearcher.Status == 2 {
- br.Msg = "已接受,不可进行拒绝操作!"
- return
- } else if rsCalendarResearcher.Status == 3 {
- br.Msg = "已拒绝,不可进行重复操作!"
- return
- } else if rsCalendarResearcher.Status == 4 {
- br.Msg = "已删除,不可进行拒绝操作!"
- return
- } else if rsCalendarResearcher.Status == 5 {
- br.Msg = "已撤回,不可进行拒绝操作!"
- 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 {
- br.Msg = "保存失败!"
- br.ErrMsg = "保存失败!UpdateCalendarResearcher:" + err.Error()
- return
- }
- //拒绝后,需要删除该日程
- go roadshowService.DeleteSHCalendar(req.RsCalendarResearcherId)
- //模板消息通知
- {
- if rsCalendar != nil {
- go func(tmpRsCalendar roadshow.RsCalendar) {
- sysAdmin, _ := system.GetSysAdminById(tmpRsCalendar.SysUserId)
- first := "【" + sysUser.RealName + "】拒绝了你的【" + tmpRsCalendar.ActivityType + "】申请"
- var keyword1, keyword2, keyword3, keyword4, keyword5 string
- keyword1 = tmpRsCalendar.CompanyName + "(" + tmpRsCalendar.RoadshowType + tmpRsCalendar.ActivityType + ")"
- keyword2 = tmpRsCalendar.ActivityType
- keyword4 = `【` + sysUser.RealName + `】已拒绝`
- keyword5 = req.RefuseReason
- remark := req.RefuseReason
- wxAppPath := ""
- openIdObj := &system.OpenIdList{
- OpenId: sysAdmin.OpenId,
- AdminId: sysAdmin.AdminId,
- }
- openIdList := make([]*system.OpenIdList, 0)
- openIdList = append(openIdList, openIdObj)
- if sysAdmin.OpenId != "" {
- services.SendWxMsgWithRoadshowDetailResult(first, keyword1, keyword2, keyword3, keyword4, keyword5, remark, wxAppPath, openIdList)
- }
- }(*rsCalendar)
- }
- }
- br.Ret = 200
- br.Success = true
- br.Msg = "保存成功"
- br.IsAddLog = true
- }
- // @Title 撤回路演活动接口
- // @Description 撤回路演活动接口
- // @Param request body roadshow.AcceptReq true "type json string"
- // @Success Ret=200 保存成功
- // @router /back [post]
- func (this *CalendarController) Back() {
- br := new(models.BaseResponse).Init()
- defer func() {
- this.Data["json"] = br
- this.ServeJSON()
- }()
- sysUser := this.SysUser
- if sysUser == nil {
- br.Msg = "请登录"
- br.ErrMsg = "请登录,SysUser Is Empty"
- br.Ret = 408
- return
- }
- var req roadshow.AcceptReq
- err := json.Unmarshal(this.Ctx.Input.RequestBody, &req)
- if err != nil {
- br.Msg = "参数解析异常!"
- br.ErrMsg = "参数解析失败,Err:" + err.Error()
- return
- }
- if req.RsCalendarId <= 0 || req.RsCalendarResearcherId <= 0 {
- br.Msg = "参数错误!"
- br.ErrMsg = "参数错误!RsCalendarId:" + strconv.Itoa(req.RsCalendarId) + ";RsCalendarResearcherId:" + strconv.Itoa(req.RsCalendarResearcherId)
- return
- }
- _, err = roadshow.GetRsCalendarById(req.RsCalendarId)
- if err != nil {
- br.Msg = "获取数据失败!"
- br.ErrMsg = "获取数据失败!GetRsCalendarById:" + err.Error()
- return
- }
- rsCalendarResearcher, err := roadshow.GetRsCalendarResearcherById(req.RsCalendarResearcherId)
- if err != nil {
- br.Msg = "获取数据失败!"
- br.ErrMsg = "获取数据失败!GetRsCalendarResearcherById:" + err.Error()
- return
- }
- if rsCalendarResearcher.Status == 2 {
- br.Msg = "已接受,不可进行撤回操作!"
- return
- } else if rsCalendarResearcher.Status == 3 {
- br.Msg = "已拒绝,不可进行撤回操作!"
- return
- } else if rsCalendarResearcher.Status == 4 {
- br.Msg = "已删除,不可进行撤回操作!"
- return
- } else if rsCalendarResearcher.Status == 5 {
- br.Msg = "已撤回,不可进行重复操作!"
- 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 roadshowService.DeleteSHCalendar(req.RsCalendarResearcherId)
- if err != nil {
- br.Msg = "保存失败!"
- br.ErrMsg = "保存失败!UpdateCalendarResearcher:" + err.Error()
- return
- }
- br.Ret = 200
- br.Success = true
- br.Msg = "保存成功"
- br.IsAddLog = true
- }
- // @Title 删除路演活动接口
- // @Description 删除路演活动接口
- // @Param request body roadshow.DeleteReq true "type json string"
- // @Success Ret=200 保存成功
- // @router /delete [post]
- func (this *CalendarController) Delete() {
- br := new(models.BaseResponse).Init()
- defer func() {
- this.Data["json"] = br
- this.ServeJSON()
- }()
- sysUser := this.SysUser
- if sysUser == nil {
- br.Msg = "请登录"
- br.ErrMsg = "请登录,SysUser Is Empty"
- br.Ret = 408
- return
- }
- var req roadshow.DeleteReq
- err := json.Unmarshal(this.Ctx.Input.RequestBody, &req)
- if err != nil {
- br.Msg = "参数解析异常!"
- br.ErrMsg = "参数解析失败,Err:" + err.Error()
- return
- }
- if req.RsCalendarId <= 0 || req.RsCalendarResearcherId <= 0 {
- br.Msg = "参数错误!"
- br.ErrMsg = "参数错误!RsCalendarId:" + strconv.Itoa(req.RsCalendarId) + ";RsCalendarResearcherId:" + strconv.Itoa(req.RsCalendarResearcherId)
- return
- }
- rsCalendarItem, err := roadshow.GetRsCalendarById(req.RsCalendarId)
- if err != nil {
- br.Msg = "获取数据失败!"
- br.ErrMsg = "获取数据失败!GetRsCalendarById:" + err.Error()
- return
- }
- rsCalendarResearcherItemList, err := roadshow.GetRsCalendarResearcherListById(req.RsCalendarId)
- if err != nil {
- br.Msg = "获取数据失败!"
- br.ErrMsg = "获取数据失败!GetRsCalendarResearcherById:" + err.Error()
- return
- }
- if rsCalendarItem.ActivityType == "报告电话会" || rsCalendarItem.ActivityType == "内部会议" {
- err = roadshow.DeleteCalendar(req.RsCalendarId, req.RsCalendarResearcherId)
- if err != nil {
- br.Msg = "删除失败!"
- br.ErrMsg = "删除失败!DeleteCalendar:" + err.Error()
- return
- }
- //检测报表记录中是否已经存在,如果存在,则删除
- {
- err = roadshow.DeleteRsReportRecord(req.RsCalendarId, req.RsCalendarResearcherId)
- if err != nil {
- br.Msg = "删除失败!"
- br.ErrMsg = "删除失败!DeleteRsReportRecord:" + err.Error()
- return
- }
- }
- } else {
- //只获取一条路演数据
- rsCalendarResearcherItemList, err = roadshow.GetRsCalendarResearcherListByCalendarResearcherId(req.RsCalendarResearcherId)
- if err != nil {
- br.Msg = "获取数据失败!"
- br.ErrMsg = "获取数据失败!GetRsCalendarResearcherById:" + err.Error()
- 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 {
- br.Msg = "删除失败!"
- br.ErrMsg = "删除失败!UpdateCalendarResearcher:" + err.Error()
- return
- }
- itemApiLog := new(roadshow.RsCalendarApiLog)
- itemApiLog.CreateTime = time.Now()
- itemApiLog.Remark = "CRM手动删除"
- itemApiLog.Url = sysUser.RealName
- itemApiLog.Body = ""
- itemApiLog.Result = ""
- itemApiLog.RsCalendarResearcherId = req.RsCalendarResearcherId
- go roadshow.AddRsCalendarApiLog(itemApiLog)
- }
- //`status` int(11) DEFAULT '0' COMMENT '1:待接受,2:已接受,3:已拒绝,4:已删除,5:已撤回,6:已结束',
- //待接受、已接受的情况,需要同步删除上海那边的日程
- for _, rsCalendarResearcherItem := range rsCalendarResearcherItemList {
- //删除上海的活动
- if rsCalendarResearcherItem.Status == 1 || rsCalendarResearcherItem.Status == 2 {
- go roadshowService.DeleteSHCalendar(rsCalendarResearcherItem.RsCalendarResearcherId)
- }
- //模板消息通知
- {
- if rsCalendarItem != nil && rsCalendarResearcherItem != nil {
- go func(tmpRsCalendarItem roadshow.RsCalendar, tmpRsCalendarResearcherItem roadshow.RsCalendarResearcher) {
- sysAdmin, _ := system.GetSysAdminById(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 != "" {
- openIdObj := &system.OpenIdList{
- OpenId: sysAdmin.OpenId,
- AdminId: sysAdmin.AdminId,
- }
- openIdList := make([]*system.OpenIdList, 0)
- openIdList = append(openIdList, openIdObj)
- if len(openIdList) > 0 {
- services.SendWxMsgWithRoadshowDeleteNotice(first, keyword1, keyword2, remark, wxAppPath, openIdList)
- }
- }
- }(*rsCalendarItem, *rsCalendarResearcherItem)
- }
- }
- }
- br.Ret = 200
- br.Success = true
- br.Msg = "删除成功"
- br.IsAddLog = true
- }
- // @Title 新增事项接口
- // @Description 新增事项接口
- // @Param request body roadshow.AddMattersReq true "type json string"
- // @Success Ret=200 保存成功
- // @router /matters/add [post]
- func (this *CalendarController) MattersAdd() {
- br := new(models.BaseResponse).Init()
- defer func() {
- this.Data["json"] = br
- this.ServeJSON()
- }()
- sysUser := this.SysUser
- if sysUser == nil {
- br.Msg = "请登录"
- br.ErrMsg = "请登录,SysUser Is Empty"
- br.Ret = 408
- 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
- br.Msg = "系统处理中,请稍后重试!"
- br.ErrMsg = "系统处理中,请稍后重试!" + sysUser.RealName + ";data:" + string(this.Ctx.Input.RequestBody)
- return
- }
- var req roadshow.AddMattersReq
- err := json.Unmarshal(this.Ctx.Input.RequestBody, &req)
- if err != nil {
- br.Msg = "参数解析异常!"
- br.ErrMsg = "参数解析失败,Err:" + err.Error()
- return
- }
- if req.StartDate == "" {
- br.Msg = "请选择开始日期!"
- return
- }
- if req.EndDate == "" {
- br.Msg = "请选择结束日期!"
- return
- }
- if req.StartTime == "" {
- br.Msg = "请选择开始时间!"
- return
- }
- if req.EndTime == "" {
- br.Msg = "请选择结束时间!"
- return
- }
- if req.StartWeek == "" {
- br.Msg = "请选择周!"
- return
- }
- if req.EndWeek == "" {
- br.Msg = "请选择周!"
- return
- }
- if req.MatterContent == "" {
- br.Msg = "请选择研究员!"
- return
- }
- // 是否为销售
- sales := isSellerRole(sysUser.RoleTypeCode)
- startDateTime := req.StartDate + " " + req.StartTime
- endDateTime := req.EndDate + " " + req.EndTime
- //校验事项时间冲突
- {
- matterCount, err := roadshowService.CheckMatters(startDateTime, endDateTime, sysUser.AdminId, 0)
- if err != nil {
- br.Msg = "时间冲突检测失败!"
- br.ErrMsg = "时间冲突检测失败-CheckMattersCount!Err:" + err.Error()
- return
- }
- if matterCount > 0 {
- br.Msg = "当前时间已被占用!"
- br.ErrMsg = "时间冲突检测失败-CheckMattersCount!"
- br.IsSendEmail = false
- return
- }
- }
- if !sales {
- //校验活动时间冲突--待接受
- {
- calendarCount, err := roadshowService.CheckCalendar(startDateTime, endDateTime, "1", sysUser.AdminId, 0)
- if err != nil {
- br.Msg = "时间冲突检测失败!"
- br.ErrMsg = "时间冲突检测失败-CheckCalendarResearcherCount!Err:" + err.Error()
- return
- }
- if calendarCount > 0 {
- br.Msg = "当前时间与待处理的申请有冲突,请与相关销售沟通!"
- br.ErrMsg = "时间冲突检测失败-CheckCalendarResearcherCount!"
- br.IsSendEmail = false
- return
- }
- }
- //校验活动时间冲突--已接受
- {
- calendarCount, err := roadshowService.CheckCalendar(startDateTime, endDateTime, "2", sysUser.AdminId, 0)
- if err != nil {
- br.Msg = "时间冲突检测失败!"
- br.ErrMsg = "时间冲突检测失败-CheckCalendarResearcherCount!Err:" + err.Error()
- return
- }
- if calendarCount > 0 {
- br.Msg = "当前时间已被占用!"
- br.ErrMsg = "时间冲突检测失败-CheckCalendarResearcherCount!"
- br.IsSendEmail = false
- 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()) {
- br.Msg = "事项开始时间不能小于当前时间!"
- return
- }
- if endP.Before(time.Now()) || endP.Equal(time.Now()) {
- br.Msg = "事项结束时间不能小于当前时间!"
- return
- }
- if startP.After(endP) || startP.Equal(endP) {
- br.Msg = "事项开始时间应小于结束时间!"
- 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 {
- br.Msg = "保存失败!"
- br.ErrMsg = "保存失败,AddRsMatters Err:" + err.Error()
- return
- }
- item.RsMattersId = int(id)
- // 销售的事项不同步上海
- if !sales {
- go roadshowService.MatterToSH(*item)
- }
- br.Ret = 200
- br.Success = true
- br.Msg = "保存成功"
- br.IsAddLog = true
- }
- // @Title 修改事项接口
- // @Description 修改事项接口
- // @Param request body roadshow.UpdateMattersReq true "type json string"
- // @Success Ret=200 保存成功
- // @router /matters/update [post]
- func (this *CalendarController) MattersUpdate() {
- br := new(models.BaseResponse).Init()
- defer func() {
- this.Data["json"] = br
- this.ServeJSON()
- }()
- sysUser := this.SysUser
- if sysUser == nil {
- br.Msg = "请登录"
- br.ErrMsg = "请登录,SysUser Is Empty"
- br.Ret = 408
- 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
- br.Msg = "系统处理中,请稍后重试!"
- br.ErrMsg = "系统处理中,请稍后重试!" + sysUser.RealName + ";data:" + string(this.Ctx.Input.RequestBody)
- return
- }
- var req roadshow.UpdateMattersReq
- err := json.Unmarshal(this.Ctx.Input.RequestBody, &req)
- if err != nil {
- br.Msg = "参数解析异常!"
- br.ErrMsg = "参数解析失败,Err:" + err.Error()
- return
- }
- updateParams := make(map[string]interface{})
- if req.RsMattersId <= 0 {
- br.Msg = "参数错误!"
- return
- }
- if req.StartDate == "" {
- br.Msg = "请选择开始日期!"
- return
- } else {
- updateParams["start_date"] = req.StartDate
- }
- if req.EndDate == "" {
- br.Msg = "请选择结束日期!"
- return
- } else {
- updateParams["end_date"] = req.EndDate
- }
- if req.StartTime == "" {
- br.Msg = "请选择开始时间!"
- return
- } else {
- updateParams["start_time"] = req.StartTime
- }
- if req.EndTime == "" {
- br.Msg = "请选择结束时间!"
- return
- } else {
- updateParams["end_time"] = req.EndTime
- }
- if req.StartWeek == "" {
- br.Msg = "请选择周!"
- return
- } else {
- updateParams["start_week"] = req.StartWeek
- }
- if req.EndWeek == "" {
- br.Msg = "请选择周!"
- return
- } else {
- updateParams["end_week"] = req.EndWeek
- }
- if req.MatterContent == "" {
- br.Msg = "请选择研究员!"
- return
- } else {
- updateParams["matter_content"] = req.MatterContent
- }
- req.EditReason = strings.TrimSpace(req.EditReason)
- if req.EditReason == "" {
- br.Msg = "请填写修改原因"
- 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()) {
- br.Msg = "事项开始时间不能小于当前时间!"
- return
- }
- if endP.Before(time.Now()) || endP.Equal(time.Now()) {
- br.Msg = "事项结束时间不能小于当前时间!"
- return
- }
- if startP.After(endP) || startP.Equal(endP) {
- br.Msg = "事项开始时间应小于结束时间!"
- return
- }
- // 结束后14天不可再编辑
- endP = endP.AddDate(0, 0, 14)
- if endP.Before(time.Now().Local()) {
- br.Msg = "事项结束14天后不可再编辑"
- return
- }
- matterItem, err := roadshow.GetMattersById(req.RsMattersId)
- if err != nil {
- br.Msg = "保存失败!"
- br.Msg = "保存失败,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 := roadshowService.CheckMatters(startDateTime, endDateTime, sysUser.AdminId, matterItem.RsMattersId)
- if err != nil {
- br.Msg = "时间冲突检测失败!"
- br.ErrMsg = "时间冲突检测失败-CheckMattersCount!Err:" + err.Error()
- return
- }
- if matterCount > 0 {
- br.Msg = "时间冲突,已存在时间段内的事项!"
- br.ErrMsg = "时间冲突检测失败-CheckMattersCount!"
- br.IsSendEmail = false
- return
- }
- }
- }
- if !sales {
- //校验活动时间冲突--待接受
- {
- calendarCount, err := roadshowService.CheckCalendar(startDateTime, endDateTime, "1", sysUser.AdminId, 0)
- if err != nil {
- br.Msg = "时间冲突检测失败!"
- br.ErrMsg = "时间冲突检测失败-CheckCalendarResearcherCount!Err:" + err.Error()
- return
- }
- if calendarCount > 0 {
- br.Msg = "当前时间与待处理的申请有冲突,请与相关销售沟通!"
- br.ErrMsg = "时间冲突检测失败-CheckCalendarResearcherCount!"
- br.IsSendEmail = false
- return
- }
- }
- //校验活动时间冲突--待接受
- {
- calendarCount, err := roadshowService.CheckCalendar(startDateTime, endDateTime, "2", sysUser.AdminId, 0)
- if err != nil {
- br.Msg = "时间冲突检测失败!"
- br.ErrMsg = "时间冲突检测失败-CheckCalendarResearcherCount!Err:" + err.Error()
- return
- }
- if calendarCount > 0 {
- br.Msg = "时间冲突,已存在时间段内的活动!"
- br.ErrMsg = "时间冲突检测失败-CheckCalendarResearcherCount!"
- br.IsSendEmail = false
- 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 {
- br.Msg = "保存失败!"
- br.ErrMsg = "保存失败!UpdateRsMatters:" + err.Error()
- return
- }
- // 销售不做上海那边的处理
- if !sales {
- go roadshowService.UpdateSHCalendarByMatter(req)
- }
- br.Ret = 200
- br.Success = true
- br.Msg = "保存成功"
- br.IsAddLog = true
- }
- // @Title 删除事项接口
- // @Description 删除事项接口
- // @Param request body roadshow.DeleteMattersReq true "type json string"
- // @Success Ret=200 保存成功
- // @router /matters/delete [post]
- func (this *CalendarController) MattersDelete() {
- br := new(models.BaseResponse).Init()
- defer func() {
- this.Data["json"] = br
- this.ServeJSON()
- }()
- sysUser := this.SysUser
- if sysUser == nil {
- br.Msg = "请登录"
- br.ErrMsg = "请登录,SysUser Is Empty"
- br.Ret = 408
- return
- }
- var req roadshow.DeleteMattersReq
- err := json.Unmarshal(this.Ctx.Input.RequestBody, &req)
- if err != nil {
- br.Msg = "参数解析异常!"
- br.ErrMsg = "参数解析失败,Err:" + err.Error()
- return
- }
- if req.RsMattersId <= 0 {
- br.Msg = "参数错误!"
- return
- }
- matters, e := roadshow.GetMattersById(req.RsMattersId)
- if e != nil {
- if e.Error() == utils.ErrNoRow() {
- br.Msg = "事项已被删除, 请刷新页面"
- return
- }
- br.Msg = "操作失败"
- br.ErrMsg = "获取事项失败, 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()) {
- br.Msg = "事项结束14天后不可再删除"
- return
- }
- err = roadshow.DeleteRsMatters(req.RsMattersId)
- if err != nil {
- br.Msg = "保存失败!"
- br.ErrMsg = "保存失败!DeleteRsMatters:" + err.Error()
- return
- }
- // 是否为销售
- sales := isSellerRole(sysUser.RoleTypeCode)
- // 删除上海的路演活动, 销售不同步
- if !sales {
- go roadshowService.DeleteSHMatter(req.RsMattersId)
- }
- br.Ret = 200
- br.Success = true
- br.Msg = "删除成功"
- br.IsAddLog = true
- }
- // @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() {
- br := new(models.BaseResponse).Init()
- defer func() {
- this.Data["json"] = br
- this.ServeJSON()
- }()
- sysUser := this.SysUser
- if sysUser == nil {
- br.Msg = "请登录"
- br.ErrMsg = "请登录,SysUser Is Empty"
- br.Ret = 408
- return
- }
- startDate := this.GetString("StartDate")
- endDate := this.GetString("EndDate")
- researcherId, _ := this.GetInt("ResearcherId")
- if startDate == "" || endDate == "" {
- br.Msg = "参数错误"
- return
- }
- var condition string
- var pars []interface{}
- if researcherId <= 0 {
- calendarList := make([]*roadshow.CalendarListView, 0)
- matterList := make([]*roadshow.RsMatters, 0)
- resp := new(roadshow.CalendarDetailResp)
- resp.CalendarList = calendarList
- resp.RsMattersList = matterList
- br.Ret = 200
- br.Success = true
- br.Msg = "获取成功"
- br.Data = resp
- return
- } else {
- condition += ` AND b.researcher_id =? `
- pars = append(pars, researcherId)
- }
- //同步上海数据
- researcherInfo, err := system.GetSysAdminById(researcherId)
- if err != nil {
- br.Msg = "研究员异常"
- return
- }
- //go roadshowService.SyncCalendarFromShanghai(researcherInfo.Mobile, startDate, endDate)
- go roadshowService.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 {
- br.Msg = "获取数据失败"
- br.ErrMsg = "获取数据失败,GetCalendarDetailList Err:" + err.Error()
- return
- }
- matterList, err := roadshow.GetRsMattersList(startDate, endDate, researcherId)
- if err != nil {
- br.Msg = "获取数据失败"
- br.ErrMsg = "获取数据失败,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 := system.GetAdminListByIdListWithoutEnable(sysUserIds)
- if err != nil {
- br.Msg = "获取数据失败"
- br.ErrMsg = "获取数据失败,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.GetCompanyProductList(conditionProduct, parsProduct)
- if err != nil {
- br.Msg = "获取数据失败"
- br.ErrMsg = "获取数据失败,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.CalendarDetailResp)
- resp.CalendarList = calendarList
- resp.RsMattersList = matterList
- br.Ret = 200
- br.Success = true
- br.Msg = "获取成功"
- br.Data = 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() {
- br := new(models.BaseResponse).Init()
- defer func() {
- this.Data["json"] = br
- this.ServeJSON()
- }()
- sysUser := this.SysUser
- if sysUser == nil {
- br.Msg = "请登录"
- br.ErrMsg = "请登录,SysUser Is Empty"
- br.Ret = 408
- return
- }
- startDate := this.GetString("StartDate")
- endDate := this.GetString("EndDate")
- if startDate == "" || endDate == "" {
- br.Msg = "参数错误"
- return
- }
- var condition string
- var pars []interface{}
- roleTypeCode := sysUser.RoleTypeCode
- fmt.Println("roleTypeCode:", 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 {
- //销售
- sales := isSellerRole(sysUser.RoleTypeCode)
- if sales || 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 := system.GetSysAdminById(sysUser.AdminId)
- if err != nil {
- br.Msg = "研究员异常"
- return
- }
- //go roadshowService.SyncCalendarFromShanghai(researcherInfo.Mobile, startDate, endDate)
- go roadshowService.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)
- fmt.Println("condition:" + condition)
- calendarList, err := roadshow.GetCalendarDetailList(condition, pars)
- if err != nil {
- br.Msg = "获取数据失败"
- br.ErrMsg = "获取数据失败,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 := system.GetAdminListByIdListWithoutEnable(sysUserIds)
- if err != nil {
- br.Msg = "获取数据失败"
- br.ErrMsg = "获取数据失败,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.GetCompanyProductList(conditionProduct, parsProduct)
- if err != nil {
- br.Msg = "获取数据失败"
- br.ErrMsg = "获取数据失败,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 {
- br.Msg = "获取数据失败"
- br.ErrMsg = "获取数据失败,GetRsMattersList Err:" + err.Error()
- return
- }
- resp := new(roadshow.CalendarDetailResp)
- resp.CalendarList = calendarList
- resp.RsMattersList = matterList
- br.Ret = 200
- br.Success = true
- br.Msg = "获取成功"
- br.Data = resp
- }
- // @Title 事项列表
- // @Description 事项列表接口
- // @Param PageSize query int true "每页数据条数"
- // @Param CurrentIndex query int true "当前页页码,从1开始"
- // @Success 200 {object} roadshow.MattersListResp
- // @router /matters/list [get]
- func (this *CalendarController) MattersList() {
- br := new(models.BaseResponse).Init()
- defer func() {
- this.Data["json"] = br
- this.ServeJSON()
- }()
- sysUser := this.SysUser
- if sysUser == nil {
- br.Msg = "请登录"
- br.ErrMsg = "请登录,SysUser Is Empty"
- br.Ret = 408
- 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() {
- br.Msg = "获取事项信息失败"
- br.ErrMsg = "获取事项信息失败,GetMattersListCount,Err:" + err.Error()
- return
- }
- page = paging.GetPaging(currentIndex, pageSize, total)
- dataList, err := roadshow.GetMattersList(condition, pars, startSize, pageSize)
- if err != nil {
- br.Msg = "获取事项信息失败"
- br.ErrMsg = "获取事项信息失败,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 {
- br.Msg = "事项结束日期有误"
- br.ErrMsg = "事项结束日期有误, Err: " + e.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
- br.Ret = 200
- br.Success = true
- br.Msg = "获取成功"
- br.Data = resp
- }
- 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 StartDate query string true "开始日期"
- // @Param EndDate query string true "结束日期日期"
- // @Success 200 {object} roadshow.PublicMeetingDetailResp
- // @router /public_meeting/detail [get]
- func (this *CalendarController) PublicMeetingDetail() {
- br := new(models.BaseResponse).Init()
- defer func() {
- this.Data["json"] = br
- this.ServeJSON()
- }()
- sysUser := this.SysUser
- if sysUser == nil {
- br.Msg = "请登录"
- br.ErrMsg = "请登录,SysUser Is Empty"
- br.Ret = 408
- return
- }
- startDate := this.GetString("StartDate")
- endDate := this.GetString("EndDate")
- if startDate == "" || endDate == "" {
- br.Msg = "参数错误"
- return
- }
- var condition string
- var pars []interface{}
- roleTypeCode := sysUser.RoleTypeCode
- fmt.Println("roleTypeCode:", roleTypeCode)
- condition += ` AND a.activity_type = '公开会议' `
- condition += ` AND b.start_date>=?`
- pars = append(pars, startDate)
- condition += ` AND b.end_date<=?`
- pars = append(pars, endDate)
- condition += ` AND b.status IN(2) `
- //pars = append(pars, 2)
- fmt.Println("condition:" + condition)
- //calendarList, err := roadshow.GetCalendarDetailList(condition, pars)
- calendarList, err := roadshow.GetPublicCalendarDetailList(condition, pars)
- if err != nil {
- br.Msg = "获取数据失败"
- br.ErrMsg = "获取数据失败,GetCalendarDetailList Err:" + err.Error()
- return
- }
- groupMap := make(map[string][]*roadshow.CalendarListView)
- var groupArr []string
- for _, v := range calendarList {
- if findGroup, ok := groupMap[v.UnionCode]; !ok {
- newGroup := make([]*roadshow.CalendarListView, 0)
- newGroup = append(newGroup, v)
- groupMap[v.UnionCode] = newGroup
- groupArr = append(groupArr, v.UnionCode)
- } else {
- findGroup = append(findGroup, v)
- groupMap[v.UnionCode] = findGroup
- }
- }
- resp := new(roadshow.PublicMeetingDetailResp)
- for _, v := range groupArr {
- newGroup := new(roadshow.PublicMeetingGroup)
- newGroup.UnionCode = v
- calendarList := groupMap[v]
- var minTimeStr, maxTimeStr string
- var minTime, maxTime time.Time
- for _, cv := range calendarList {
- startTimeStr := cv.StartDate + " " + cv.StartTime
- endTimeStr := cv.EndDate + " " + cv.EndTime
- startTime, _ := time.ParseInLocation(utils.FormatDateTime, startTimeStr, time.Local)
- endTime, _ := time.ParseInLocation(utils.FormatDateTime, endTimeStr, time.Local)
- if minTime.IsZero() {
- minTime = startTime
- } else {
- if startTime.Before(minTime) {
- minTime = startTime
- }
- }
- if maxTime.IsZero() {
- maxTime = endTime
- } else {
- if endTime.After(maxTime) {
- maxTime = endTime
- }
- }
- }
- minTimeStr = minTime.Format(utils.FormatDateTime)
- maxTimeStr = maxTime.Format(utils.FormatDateTime)
- newGroup.MinTime = minTimeStr
- newGroup.MaxTime = maxTimeStr
- newGroup.CalendarList = calendarList
- resp.Group = append(resp.Group, newGroup)
- }
- br.Ret = 200
- br.Success = true
- br.Msg = "获取成功"
- br.Data = resp
- }
- //func init() {
- // fmt.Println("start")
- // mobile := `13818594925`
- // roadshowService.SyncCalendarFromShanghai(mobile, "", "2023-03-09")
- // //err := roadshowService.SetPublicMeetingUnionCode()
- // //if err != nil {
- // // fmt.Println("SetPublicMeetingUnionCode Err:" + err.Error())
- // //}
- // fmt.Println("end")
- //}
- // 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() {
- br := new(models.BaseResponse).Init()
- defer func() {
- if br.ErrMsg == "" {
- br.IsSendEmail = false
- }
- this.Data["json"] = br
- this.ServeJSON()
- }()
- sysUser := this.SysUser
- if sysUser == nil {
- br.Msg = "请登录"
- br.ErrMsg = "请登录,SysUser Is Empty"
- br.Ret = 408
- return
- }
- startDate := this.GetString("StartDate")
- endDate := this.GetString("EndDate")
- sellerId, _ := this.GetInt("SellerId")
- if startDate == "" || endDate == "" {
- br.Msg = "参数错误"
- return
- }
- if sellerId <= 0 {
- calendarList := make([]*roadshow.CalendarListView, 0)
- matterList := make([]*roadshow.RsMatters, 0)
- resp := new(roadshow.CalendarDetailResp)
- resp.CalendarList = calendarList
- resp.RsMattersList = matterList
- br.Ret = 200
- br.Success = true
- br.Msg = "获取成功"
- br.Data = 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 {
- br.Msg = "获取数据失败"
- br.ErrMsg = "获取数据失败,GetCalendarDetailList Err:" + err.Error()
- return
- }
- if calendarList == nil {
- calendarList = make([]*roadshow.CalendarListView, 0)
- }
- // 事项
- matterList, err := roadshow.GetRsMattersList(startDate, endDate, sellerId)
- if err != nil {
- br.Msg = "获取数据失败"
- br.ErrMsg = "获取数据失败,GetRsMattersList Err:" + err.Error()
- return
- }
- if matterList == nil {
- matterList = make([]*roadshow.RsMatters, 0)
- }
- resp := new(roadshow.CalendarDetailResp)
- resp.CalendarList = calendarList
- resp.RsMattersList = matterList
- br.Ret = 200
- br.Success = true
- br.Msg = "获取成功"
- br.Data = 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
- }
- //func init() {
- // init16_2()
- //}
- //func init16_2() {
- // listDate, err := roadshow.GetRsCalendarResearcherListInit16_2()
- // if err != nil {
- // fmt.Println(err)
- // return
- // }
- //
- // sysUserList, err := system.GetAdminList()
- // if err != nil {
- // fmt.Println(err)
- // return
- // }
- // adminMap := make(map[int]*system.Admin, 0)
- // for _, v := range sysUserList {
- // adminMap[v.AdminId] = v
- // }
- //
- // for k, v := range listDate {
- // fmt.Println(k, "__", v.CompanyId)
- // //如果是权益客户,添加销售跟共享销售的信息
- // var productItemRai *company.CompanyProduct
- //
- // productItemRai, err = company.GetCompanyProductByCompanyIdAndProductId(v.CompanyId, utils.COMPANY_PRODUCT_RAI_ID)
- // if err != nil && err.Error() != utils.ErrNoRow() {
- // fmt.Println(err)
- // return
- // }
- //
- // var RoleTypeCode string
- // if adminMap[v.SysUserId] != nil {
- // RoleTypeCode = adminMap[v.SysUserId].RoleTypeCode
- // }
- //
- // if productItemRai != nil && (RoleTypeCode == utils.ROLE_TYPE_CODE_RAI_GROUP || RoleTypeCode == utils.ROLE_TYPE_CODE_RAI_SELLER || RoleTypeCode == utils.ROLE_TYPE_CODE_RAI_ADMIN) {
- // err = roadshow.UpdateRsCalendarSeller(productItemRai.SellerId, productItemRai.ShareSellerId, v.RsCalendarId)
- // if err != nil && err.Error() != utils.ErrNoRow() {
- // fmt.Println(err)
- // return
- // }
- // }
- // }
- //
- //}
|