calendar.go 95 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032203320342035203620372038203920402041204220432044204520462047204820492050205120522053205420552056205720582059206020612062206320642065206620672068206920702071207220732074207520762077207820792080208120822083208420852086208720882089209020912092209320942095209620972098209921002101210221032104210521062107210821092110211121122113211421152116211721182119212021212122212321242125212621272128212921302131213221332134213521362137213821392140214121422143214421452146214721482149215021512152215321542155215621572158215921602161216221632164216521662167216821692170217121722173217421752176217721782179218021812182218321842185218621872188218921902191219221932194219521962197219821992200220122022203220422052206220722082209221022112212221322142215221622172218221922202221222222232224222522262227222822292230223122322233223422352236223722382239224022412242224322442245224622472248224922502251225222532254225522562257225822592260226122622263226422652266226722682269227022712272227322742275227622772278227922802281228222832284228522862287228822892290229122922293229422952296229722982299230023012302230323042305230623072308230923102311231223132314231523162317231823192320232123222323232423252326232723282329233023312332233323342335233623372338233923402341234223432344234523462347234823492350235123522353235423552356235723582359236023612362236323642365236623672368236923702371237223732374237523762377237823792380238123822383238423852386238723882389239023912392239323942395239623972398239924002401240224032404240524062407240824092410241124122413241424152416241724182419242024212422242324242425242624272428242924302431243224332434243524362437243824392440244124422443244424452446244724482449245024512452245324542455245624572458245924602461246224632464246524662467246824692470247124722473247424752476247724782479248024812482248324842485248624872488248924902491249224932494249524962497249824992500250125022503250425052506250725082509251025112512251325142515251625172518251925202521252225232524252525262527252825292530253125322533253425352536253725382539254025412542254325442545254625472548254925502551255225532554255525562557255825592560256125622563256425652566256725682569257025712572257325742575257625772578257925802581258225832584258525862587258825892590259125922593259425952596259725982599260026012602260326042605260626072608260926102611261226132614261526162617261826192620262126222623262426252626262726282629263026312632263326342635263626372638263926402641264226432644264526462647264826492650265126522653265426552656265726582659266026612662266326642665266626672668266926702671267226732674267526762677267826792680268126822683268426852686268726882689269026912692269326942695269626972698269927002701270227032704270527062707270827092710271127122713271427152716271727182719272027212722272327242725272627272728272927302731273227332734273527362737273827392740274127422743274427452746274727482749275027512752275327542755275627572758275927602761276227632764276527662767276827692770277127722773277427752776277727782779278027812782278327842785278627872788278927902791279227932794279527962797279827992800280128022803280428052806280728082809281028112812281328142815281628172818281928202821282228232824282528262827282828292830283128322833283428352836283728382839284028412842284328442845284628472848284928502851285228532854285528562857285828592860286128622863286428652866286728682869287028712872287328742875287628772878287928802881288228832884288528862887288828892890289128922893289428952896289728982899290029012902290329042905290629072908290929102911291229132914291529162917291829192920292129222923292429252926292729282929293029312932293329342935293629372938293929402941294229432944294529462947294829492950295129522953295429552956295729582959296029612962296329642965296629672968296929702971297229732974297529762977297829792980298129822983298429852986298729882989299029912992299329942995299629972998299930003001300230033004
  1. package roadshow
  2. import (
  3. "encoding/json"
  4. "fmt"
  5. "github.com/rdlucklib/rdluck_tools/paging"
  6. "hongze/hz_crm_api/controllers"
  7. "hongze/hz_crm_api/models"
  8. "hongze/hz_crm_api/models/company"
  9. "hongze/hz_crm_api/models/cygx"
  10. "hongze/hz_crm_api/models/roadshow"
  11. "hongze/hz_crm_api/models/system"
  12. "hongze/hz_crm_api/services"
  13. roadshowService "hongze/hz_crm_api/services/roadshow"
  14. "hongze/hz_crm_api/utils"
  15. "strconv"
  16. "strings"
  17. "time"
  18. )
  19. // 日历
  20. type CalendarController struct {
  21. controllers.BaseAuthController
  22. }
  23. // @Title 新增路演活动接口
  24. // @Description 新增路演活动接口
  25. // @Param request body roadshow.AddActivityReq true "type json string"
  26. // @Success Ret=200 保存成功
  27. // @router /add [post]
  28. func (this *CalendarController) Add() {
  29. br := new(models.BaseResponse).Init()
  30. defer func() {
  31. this.Data["json"] = br
  32. this.ServeJSON()
  33. }()
  34. sysUser := this.SysUser
  35. if sysUser == nil {
  36. br.Msg = "请登录"
  37. br.ErrMsg = "请登录,SysUser Is Empty"
  38. br.Ret = 408
  39. return
  40. }
  41. deleteCache := true
  42. cacheKey := "CACHE_RS_ACTIVITY_ADD_" + strconv.Itoa(sysUser.AdminId)
  43. defer func() {
  44. if deleteCache {
  45. utils.Rc.Delete(cacheKey)
  46. }
  47. }()
  48. if !utils.Rc.SetNX(cacheKey, 1, 5*time.Second) {
  49. deleteCache = false
  50. br.Msg = "系统处理中,请稍后重试!"
  51. br.ErrMsg = "系统处理中,请稍后重试!" + sysUser.RealName + ";data:" + string(this.Ctx.Input.RequestBody)
  52. return
  53. }
  54. var req roadshow.AddActivityReq
  55. err := json.Unmarshal(this.Ctx.Input.RequestBody, &req)
  56. if err != nil {
  57. br.Msg = "参数解析异常!"
  58. br.ErrMsg = "参数解析失败,Err:" + err.Error()
  59. return
  60. }
  61. if len(req.ResearcherList) <= 0 {
  62. br.Msg = "请选择研究员!"
  63. return
  64. }
  65. researcherMap := make(map[int]string)
  66. var checkIsAdd []string
  67. //获取所有自定义的权益研究员
  68. sysUserList, err := cygx.GetAskEmailList()
  69. if err != nil {
  70. br.Msg = "获取失败"
  71. br.ErrMsg = "获取失败,GetAskEmailList Err: " + err.Error()
  72. return
  73. }
  74. raiAskadminMap := make(map[int]bool, 0)
  75. for _, v := range sysUserList {
  76. raiAskadminMap[v.AdminId] = true
  77. }
  78. sysUserFwang, e := system.GetSysUserByAdminName("fwang") // 手动拼接王芳到权益的策略行业下 start
  79. if e != nil {
  80. if e.Error() == utils.ErrNoRow() {
  81. br.Msg = "用户不存在, 请检查"
  82. return
  83. }
  84. br.Msg = "账号错误, 请重新输入"
  85. br.ErrMsg = "fwang 用户名获取用户失败, Err: " + e.Error()
  86. return
  87. }
  88. raiAskadminMap[sysUserFwang.AdminId] = true // 手动拼接王芳到权益的策略行业下 end
  89. //var tipMsg string
  90. for _, v := range req.ResearcherList {
  91. if v.ResearcherId <= 0 {
  92. br.Msg = "请选择研究员!"
  93. return
  94. }
  95. if v.ResearcherName == "" {
  96. br.Msg = "请选择研究员!"
  97. return
  98. }
  99. if v.StartDate == "" {
  100. br.Msg = "请选择开始日期!"
  101. return
  102. }
  103. if v.EndDate == "" {
  104. br.Msg = "请选择结束日期!"
  105. return
  106. }
  107. if v.StartTime == "" {
  108. br.Msg = "请选择开始时间!"
  109. return
  110. }
  111. if v.EndTime == "" {
  112. br.Msg = "请选择结束时间!"
  113. return
  114. }
  115. if v.StartWeek == "" {
  116. br.Msg = "请选择周!"
  117. return
  118. }
  119. if v.EndWeek == "" {
  120. br.Msg = "请选择周!"
  121. return
  122. }
  123. if req.ActivityType == "沙龙" && !raiAskadminMap[v.ResearcherId] {
  124. br.Msg = "ficc研究员暂不支持添加沙龙"
  125. return
  126. }
  127. startDateTime := v.StartDate + " " + v.StartTime
  128. endDateTime := v.EndDate + " " + v.EndTime
  129. startP, _ := time.ParseInLocation(utils.FormatDateTime, startDateTime, time.Local)
  130. endP, _ := time.ParseInLocation(utils.FormatDateTime, endDateTime, time.Local)
  131. if startP.Before(time.Now()) || startP.Equal(time.Now()) {
  132. br.Msg = "活动开始时间不能小于当前时间!"
  133. return
  134. }
  135. if endP.Before(time.Now()) || endP.Equal(time.Now()) {
  136. br.Msg = "活动结束时间不能小于当前时间!"
  137. return
  138. }
  139. if startP.After(endP) || startP.Equal(endP) {
  140. br.Msg = "活动开始时间应小于结束时间!"
  141. return
  142. }
  143. if realName, ok := researcherMap[v.ResearcherId]; ok {
  144. br.Msg = "研究员:" + realName + " 被重复选择"
  145. return
  146. }
  147. researcherMap[v.ResearcherId] = v.ResearcherName
  148. //同步上海数据
  149. researcherInfo, err := system.GetSysAdminById(v.ResearcherId)
  150. if err != nil {
  151. br.Msg = "研究员异常"
  152. return
  153. }
  154. _ = roadshowService.SyncCalendarFromShanghai(researcherInfo.Mobile, v.StartDate, v.EndDate)
  155. //校验事项时间冲突
  156. {
  157. matterCount, err := roadshowService.CheckMatters(startDateTime, endDateTime, v.ResearcherId, 0)
  158. if err != nil {
  159. br.Msg = "时间冲突检测失败!"
  160. br.ErrMsg = "时间冲突检测失败-CheckMattersCount!Err:" + err.Error()
  161. return
  162. }
  163. if matterCount > 0 {
  164. checkIsAdd = append(checkIsAdd, v.ResearcherName)
  165. }
  166. }
  167. //校验活动时间冲突
  168. {
  169. calendarCount, err := roadshowService.CheckCalendar(startDateTime, endDateTime, "1,2", v.ResearcherId, 0)
  170. if err != nil {
  171. br.Msg = "时间冲突检测失败!"
  172. br.ErrMsg = "时间冲突检测失败-CheckCalendar!Err:" + err.Error()
  173. return
  174. }
  175. if calendarCount > 0 {
  176. checkIsAdd = append(checkIsAdd, v.ResearcherName)
  177. }
  178. }
  179. }
  180. if len(checkIsAdd) > 0 {
  181. br.Msg = strings.Join(checkIsAdd, ",") + " 时间已被占用!"
  182. br.ErrMsg = "时间冲突检测失败-CheckMattersCount!"
  183. br.IsSendEmail = false
  184. return
  185. }
  186. //如果是权益客户,添加销售跟共享销售的信息
  187. var productItemRai *company.CompanyProduct
  188. roleTypeCode := sysUser.RoleTypeCode
  189. //如果是权益销售、权益销售组长、权益管理员 添加的路演信息,做销售与共享销售信息关联查看
  190. if req.CompanyId > 0 && req.ActivityType == "路演" && (roleTypeCode == utils.ROLE_TYPE_CODE_RAI_SELLER ||
  191. roleTypeCode == utils.ROLE_TYPE_CODE_RAI_GROUP || roleTypeCode == utils.ROLE_TYPE_CODE_RAI_ADMIN) {
  192. productItemRai, err = company.GetCompanyProductByCompanyIdAndProductId(req.CompanyId, utils.COMPANY_PRODUCT_RAI_ID)
  193. if err != nil && err.Error() != utils.ErrNoRow() {
  194. br.Msg = "客户信息有误"
  195. br.ErrMsg = "获取客户信息失败, Err: " + err.Error()
  196. return
  197. }
  198. }
  199. rsCalendar := new(roadshow.RsCalendar)
  200. rsCalendar.SysUserId = sysUser.AdminId
  201. rsCalendar.SysUserRealName = sysUser.RealName
  202. rsCalendar.ActivityType = req.ActivityType
  203. rsCalendar.RoadshowType = req.RoadshowType
  204. rsCalendar.RoadshowPlatform = req.RoadshowPlatform
  205. rsCalendar.CompanyId = req.CompanyId
  206. rsCalendar.CompanyName = req.CompanyName
  207. rsCalendar.Province = req.Province
  208. rsCalendar.ProvinceCode = req.ProvinceCode
  209. rsCalendar.City = req.City
  210. rsCalendar.CityCode = req.CityCode
  211. rsCalendar.District = req.District
  212. rsCalendar.Theme = req.Theme
  213. rsCalendar.CooperationName = req.CooperationName
  214. rsCalendar.CreateTime = time.Now()
  215. rsCalendar.ModifyTime = time.Now()
  216. rsCalendar.ActivityCategory = req.ActivityCategory
  217. rsCalendar.Source = 0
  218. rsCalendar.EnglishCompany = req.EnglishCompany
  219. rsCalendar.Title = getTitle(req.ActivityType, req.RoadshowType, req.ActivityCategory, req.RoadshowPlatform, req.Province, req.City)
  220. if productItemRai != nil {
  221. rsCalendar.SellerId = productItemRai.SellerId
  222. rsCalendar.ShareSellerId = productItemRai.ShareSellerId
  223. }
  224. rsCalendarId, err := roadshow.AddRsCalendar(rsCalendar)
  225. if err != nil {
  226. br.Msg = "保存失败!"
  227. br.ErrMsg = "保存日历活动信息失败!Err:" + err.Error()
  228. return
  229. }
  230. //if researcherId != 99 {
  231. for k, v := range req.ResearcherList {
  232. researcher := new(roadshow.RsCalendarResearcher)
  233. researcher.RsCalendarId = int(rsCalendarId)
  234. researcher.ResearcherId = v.ResearcherId
  235. researcher.ResearcherName = v.ResearcherName
  236. researcher.StartDate = v.StartDate
  237. researcher.EndDate = v.EndDate
  238. researcher.StartTime = v.StartTime
  239. researcher.EndTime = v.EndTime
  240. researcher.StartWeek = v.StartWeek
  241. researcher.EndWeek = v.EndWeek
  242. researcher.CreateTime = time.Now()
  243. researcher.ModifyTime = time.Now()
  244. researcher.ResearcherSort = k + 1
  245. if req.ActivityType == "路演" || req.ActivityType == "公开会议" {
  246. researcher.Status = 1
  247. } else {
  248. researcher.Status = 2
  249. }
  250. //CRM15.5 权益研究员直接通过
  251. if raiAskadminMap[v.ResearcherId] {
  252. researcher.Status = 2
  253. }
  254. rsCalendarResearcherId, err := roadshow.AddRsCalendarResearcher(researcher)
  255. if err != nil {
  256. br.Msg = "保存失败!"
  257. br.ErrMsg = "保存日历活动-研究员信息失败!Err:" + err.Error()
  258. return
  259. }
  260. rsCalendar.RsCalendarId = int(rsCalendarId)
  261. researcher.RsCalendarResearcherId = int(rsCalendarResearcherId)
  262. go roadshowService.CalendarToSH(*rsCalendar, *researcher)
  263. //模板消息通知
  264. {
  265. go func(researcherId, tmpRsCalendarId, tmpRsCalendarResearcherId int) { // 研究员id,路演id,路演与研究员记录的id
  266. var wxAppPath string
  267. sysAdmin, _ := system.GetSysAdminById(researcherId)
  268. if sysAdmin != nil && sysAdmin.OpenId != "" {
  269. openIdObj := &system.OpenIdList{
  270. OpenId: sysAdmin.OpenId,
  271. AdminId: sysAdmin.AdminId,
  272. }
  273. openIdList := make([]*system.OpenIdList, 0)
  274. openIdList = append(openIdList, openIdObj)
  275. if req.ActivityType == "路演" || req.ActivityType == "公开会议" {
  276. wxAppPath = "pages-approve/activity/detail?RsCalendarId=" + strconv.Itoa(tmpRsCalendarId) + "&RsCalendarResearcherId=" + strconv.Itoa(tmpRsCalendarResearcherId)
  277. first := "您收到一个新的【" + req.ActivityType + "】申请,请及时处理"
  278. keyword1 := sysUser.RealName
  279. keyword2 := "--"
  280. startDateSub := v.StartDate[5:]
  281. startDateSub = strings.Replace(startDateSub, "-", ".", -1)
  282. //keyword3 := time.Now().Format(utils.FormatDateTime)
  283. keyword3 := startDateSub + "(" + v.StartWeek + ")" + " " + v.StartTime[:5] + "~" + v.EndTime[:5]
  284. var keyword4 string
  285. if req.ActivityType == "路演" {
  286. keyword4 = req.CompanyName + "(" + req.RoadshowType + req.ActivityType + ")"
  287. } else {
  288. keyword4 = req.Theme + "(" + req.RoadshowType + req.ActivityType + ")"
  289. }
  290. remark := "请尽快完成审批"
  291. //wxAppPath := "pages-approve/activity/detail?RsCalendarId=" + strconv.Itoa(int(rsCalendarId)) + "&RsCalendarResearcherId=" + strconv.Itoa(int(rsCalendarResearcherId))
  292. if len(openIdList) > 0 {
  293. services.SendWxMsgWithRoadshowPending(first, keyword1, keyword2, keyword3, keyword4, remark, wxAppPath, openIdList)
  294. }
  295. } else {
  296. wxAppPath = ""
  297. first := sysUser.RealName + "为你添加了一场【" + req.ActivityType + "】"
  298. startDate := researcher.StartDate[5:]
  299. startDate = strings.Replace(startDate, "-", ".", -1)
  300. keyword1 := startDate + "(" + researcher.StartWeek + ")" + " " + researcher.StartTime[:5] + "-" + researcher.EndTime[:5]
  301. keyword2 := sysUser.RealName + "为你添加了【" + req.ActivityType + "】"
  302. if len(openIdList) > 0 {
  303. services.SendWxMsgWithRoadshowDeleteNotice(first, keyword1, keyword2, "", wxAppPath, openIdList)
  304. }
  305. }
  306. }
  307. }(v.ResearcherId, int(rsCalendarId), int(rsCalendarResearcherId))
  308. }
  309. }
  310. //if req.ActivityType == "公开会议" {
  311. // go roadshowService.SetPublicMeetingUnionCode()
  312. //}
  313. br.Ret = 200
  314. br.Success = true
  315. br.Msg = "保存成功"
  316. br.IsAddLog = true
  317. }
  318. // @Title 编辑路演活动接口
  319. // @Description编辑路演活动接口
  320. // @Param request body roadshow.EditActivityReq true "type json string"
  321. // @Success Ret=200 保存成功
  322. // @router /edit [post]
  323. func (this *CalendarController) Edit() {
  324. br := new(models.BaseResponse).Init()
  325. defer func() {
  326. this.Data["json"] = br
  327. this.ServeJSON()
  328. }()
  329. sysUser := this.SysUser
  330. if sysUser == nil {
  331. br.Msg = "请登录"
  332. br.ErrMsg = "请登录,SysUser Is Empty"
  333. br.Ret = 408
  334. return
  335. }
  336. deleteCache := true
  337. cacheKey := "CACHE_RS_ACTIVITY_EDIT_" + strconv.Itoa(sysUser.AdminId)
  338. defer func() {
  339. if deleteCache {
  340. utils.Rc.Delete(cacheKey)
  341. }
  342. }()
  343. if !utils.Rc.SetNX(cacheKey, 1, 5*time.Second) {
  344. deleteCache = false
  345. br.Msg = "系统处理中,请稍后重试!"
  346. br.ErrMsg = "系统处理中,请稍后重试!" + sysUser.RealName + ";data:" + string(this.Ctx.Input.RequestBody)
  347. return
  348. }
  349. var req roadshow.EditActivityReq
  350. err := json.Unmarshal(this.Ctx.Input.RequestBody, &req)
  351. if err != nil {
  352. br.Msg = "参数解析异常!"
  353. br.ErrMsg = "参数解析失败,Err:" + err.Error()
  354. return
  355. }
  356. if req.RsCalendarId <= 0 {
  357. br.Msg = "参数错误!"
  358. br.ErrMsg = "RsCalendarId<=0"
  359. return
  360. }
  361. if req.RsCalendarResearcherId <= 0 {
  362. br.Msg = "参数错误!"
  363. br.ErrMsg = "RsCalendarResearcherId<=0"
  364. return
  365. }
  366. if req.ActivityType == "" {
  367. br.Msg = "请选择活动类型!"
  368. return
  369. }
  370. if len(req.ResearcherList) <= 0 {
  371. br.Msg = "请选择研究员!"
  372. return
  373. }
  374. researcherMap := make(map[int]string)
  375. var checkIsAdd []string
  376. for _, v := range req.ResearcherList {
  377. if v.ResearcherId <= 0 {
  378. br.Msg = "请选择研究员!"
  379. return
  380. }
  381. if v.ResearcherName == "" {
  382. br.Msg = "请选择研究员!"
  383. return
  384. }
  385. if v.StartDate == "" {
  386. br.Msg = "请选择开始日期!"
  387. return
  388. }
  389. if v.EndDate == "" {
  390. br.Msg = "请选择结束日期!"
  391. return
  392. }
  393. if v.StartTime == "" {
  394. br.Msg = "请选择开始时间!"
  395. return
  396. }
  397. if v.EndTime == "" {
  398. br.Msg = "请选择结束时间!"
  399. return
  400. }
  401. if v.StartWeek == "" {
  402. br.Msg = "请选择周!"
  403. return
  404. }
  405. if v.EndWeek == "" {
  406. br.Msg = "请选择周!"
  407. return
  408. }
  409. if realName, ok := researcherMap[v.ResearcherId]; ok {
  410. br.Msg = "研究员:" + realName + " 被重复选择"
  411. return
  412. }
  413. researcherMap[v.ResearcherId] = v.ResearcherName
  414. startDateTime := v.StartDate + " " + v.StartTime
  415. endDateTime := v.EndDate + " " + v.EndTime
  416. startP, _ := time.ParseInLocation(utils.FormatDateTime, startDateTime, time.Local)
  417. endP, _ := time.ParseInLocation(utils.FormatDateTime, endDateTime, time.Local)
  418. if startP.Before(time.Now()) || startP.Equal(time.Now()) {
  419. br.Msg = "活动开始时间不能小于当前时间!"
  420. return
  421. }
  422. if endP.Before(time.Now()) || endP.Equal(time.Now()) {
  423. br.Msg = "活动结束时间不能小于当前时间!"
  424. return
  425. }
  426. if startP.After(endP) || startP.Equal(endP) {
  427. br.Msg = "活动开始时间应小于结束时间!"
  428. return
  429. }
  430. /*
  431. 时间冲突时,提示:xxx时间已被占用
  432. 当有任意一个研究员时间有冲突时,所有申请订单都不发送。
  433. */
  434. rsCalendarResearcherItem, err := roadshow.GetRsCalendarResearcherByRsCalendarIdAndResearcherId(req.RsCalendarId, v.ResearcherId)
  435. var isAdd bool
  436. if err != nil {
  437. if err.Error() == utils.ErrNoRow() {
  438. isAdd = true
  439. } else {
  440. br.Msg = "获取数据失败!"
  441. br.ErrMsg = "获取数据失败!GetRsCalendarResearcherByRsCalendarIdAndResearcherId:" + err.Error()
  442. return
  443. }
  444. }
  445. var rsCalendarResearcherId int
  446. if rsCalendarResearcherItem == nil {
  447. isAdd = true
  448. } else {
  449. rsCalendarResearcherId = rsCalendarResearcherItem.RsCalendarResearcherId
  450. }
  451. //同步上海数据
  452. researcherInfo, err := system.GetSysAdminById(v.ResearcherId)
  453. if err != nil {
  454. br.Msg = "研究员异常"
  455. return
  456. }
  457. _ = roadshowService.SyncCalendarFromShanghai(researcherInfo.Mobile, v.StartDate, v.EndDate)
  458. //校验事项时间冲突
  459. {
  460. if isAdd || (rsCalendarResearcherItem != nil && (rsCalendarResearcherItem.StartDate != v.StartDate ||
  461. rsCalendarResearcherItem.StartTime != v.StartTime ||
  462. rsCalendarResearcherItem.EndDate != v.EndDate ||
  463. rsCalendarResearcherItem.EndTime != v.EndTime)) {
  464. matterCount, err := roadshowService.CheckMatters(startDateTime, endDateTime, v.ResearcherId, 0)
  465. if err != nil {
  466. br.Msg = "时间冲突检测失败!"
  467. br.ErrMsg = "时间冲突检测失败-CheckMattersCount!Err:" + err.Error()
  468. return
  469. }
  470. if matterCount > 0 {
  471. checkIsAdd = append(checkIsAdd, v.ResearcherName)
  472. }
  473. }
  474. }
  475. //校验活动时间冲突
  476. //{
  477. // if isAdd || (rsCalendarResearcherItem != nil && (rsCalendarResearcherItem.StartDate != v.StartDate ||
  478. // rsCalendarResearcherItem.StartTime != v.StartTime ||
  479. // rsCalendarResearcherItem.EndDate != v.EndDate ||
  480. // rsCalendarResearcherItem.EndTime != v.EndTime)) {
  481. //
  482. // calendarCount, err := roadshowService.CheckCalendar(startDateTime, endDateTime, "1,2", v.ResearcherId, rsCalendarResearcherId)
  483. // if err != nil {
  484. // br.Msg = "时间冲突检测失败!"
  485. // br.ErrMsg = "时间冲突检测失败-CheckCalendarResearcherCount!Err:" + err.Error()
  486. // return
  487. // }
  488. // if calendarCount > 0 {
  489. // checkIsAdd = append(checkIsAdd, v.ResearcherName)
  490. // }
  491. // }
  492. //}
  493. calendarCount, err := roadshowService.CheckCalendar(startDateTime, endDateTime, "1,2", v.ResearcherId, rsCalendarResearcherId)
  494. if err != nil {
  495. br.Msg = "时间冲突检测失败!"
  496. br.ErrMsg = "时间冲突检测失败-CheckCalendarResearcherCount!Err:" + err.Error()
  497. return
  498. }
  499. if calendarCount > 0 {
  500. checkIsAdd = append(checkIsAdd, v.ResearcherName)
  501. }
  502. }
  503. if len(checkIsAdd) > 0 {
  504. br.Msg = strings.Join(checkIsAdd, ",") + "时间已被占用!"
  505. br.ErrMsg = "时间冲突检测失败-CheckMattersCount!"
  506. br.IsSendEmail = false
  507. return
  508. }
  509. rsCalendarItem, err := roadshow.GetRsCalendarById(req.RsCalendarId)
  510. if err != nil {
  511. br.Msg = "获取数据失败!"
  512. br.ErrMsg = "获取数据失败!GetRsCalendarById:" + err.Error()
  513. return
  514. }
  515. if rsCalendarItem == nil {
  516. br.Msg = "保存失败!"
  517. br.ErrMsg = "获取数据失败!GetRsCalendarById:" + err.Error()
  518. return
  519. }
  520. calendarWhereParams := make(map[string]interface{})
  521. calendarUpdateParams := make(map[string]interface{})
  522. calendarWhereParams["rs_calendar_id"] = req.RsCalendarId
  523. //if req.ActivityType != "" {
  524. calendarUpdateParams["activity_type"] = req.ActivityType
  525. //}
  526. //if req.RoadshowType != "" {
  527. calendarUpdateParams["roadshow_type"] = req.RoadshowType
  528. // }
  529. //if req.RoadshowPlatform != "" {
  530. calendarUpdateParams["roadshow_platform"] = req.RoadshowPlatform
  531. //}
  532. //if req.CompanyId > 0 {
  533. calendarUpdateParams["company_id"] = req.CompanyId
  534. //}
  535. //if req.CompanyName != "" {
  536. calendarUpdateParams["company_name"] = req.CompanyName
  537. //}
  538. //if req.ActivityCategory != "" {
  539. calendarUpdateParams["activity_category"] = req.ActivityCategory
  540. // }
  541. //if req.Theme != "" {
  542. calendarUpdateParams["theme"] = req.Theme
  543. //}
  544. //if req.CooperationName != "" {
  545. calendarUpdateParams["cooperation_name"] = req.CooperationName
  546. //}
  547. //if req.Province != "" {
  548. calendarUpdateParams["province"] = req.Province
  549. //}
  550. //if req.City != "" {
  551. calendarUpdateParams["city"] = req.City
  552. // }
  553. //if req.District != "" {
  554. calendarUpdateParams["district"] = req.District
  555. //}
  556. calendarUpdateParams["english_company"] = req.EnglishCompany
  557. calendarUpdateParams["modify_time"] = time.Now()
  558. calendarUpdateParams["title"] = getTitle(req.ActivityType, req.RoadshowType, req.ActivityCategory, req.RoadshowPlatform, req.Province, req.City)
  559. //如果是权益客户,添加销售跟共享销售的信息
  560. roleTypeCode := sysUser.RoleTypeCode
  561. //如果是权益销售、权益销售组长、权益管理员 添加的路演信息,做销售与共享销售信息关联查看
  562. if req.CompanyId > 0 && req.ActivityType == "路演" && (roleTypeCode == utils.ROLE_TYPE_CODE_RAI_SELLER ||
  563. roleTypeCode == utils.ROLE_TYPE_CODE_RAI_GROUP || roleTypeCode == utils.ROLE_TYPE_CODE_RAI_ADMIN) {
  564. var productItemRai *company.CompanyProduct
  565. productItemRai, err = company.GetCompanyProductByCompanyIdAndProductId(req.CompanyId, utils.COMPANY_PRODUCT_RAI_ID)
  566. if err != nil && err.Error() != utils.ErrNoRow() {
  567. br.Msg = "客户信息有误"
  568. br.ErrMsg = "获取客户信息失败, Err: " + err.Error()
  569. return
  570. }
  571. if productItemRai != nil {
  572. calendarUpdateParams["seller_id"] = productItemRai.SellerId
  573. calendarUpdateParams["share_seller_id"] = productItemRai.ShareSellerId
  574. }
  575. }
  576. err = roadshow.UpdateRsCalendar(calendarWhereParams, calendarUpdateParams)
  577. if err != nil {
  578. br.Msg = "保存失败!"
  579. br.ErrMsg = "保存失败!UpdateRsCalendar:" + err.Error()
  580. return
  581. }
  582. //newResearcherMap := make(map[int]string)
  583. existList, err := roadshow.GetRsCalendarResearcherByCalendarId(req.RsCalendarId)
  584. if err != nil {
  585. br.Msg = "保存失败!"
  586. br.ErrMsg = "保存失败!GetRsCalendarResearcherByCalendarId:" + err.Error()
  587. return
  588. }
  589. existResearcherMap := make(map[int]string)
  590. for _, ev := range existList {
  591. existResearcherMap[ev.ResearcherId] = ev.ResearcherName
  592. }
  593. sysUserList, err := cygx.GetAskEmailList()
  594. if err != nil {
  595. br.Msg = "获取失败"
  596. br.ErrMsg = "获取失败,GetAskEmailList Err: " + err.Error()
  597. return
  598. }
  599. raiAskadminMap := make(map[int]bool, 0)
  600. for _, v := range sysUserList {
  601. raiAskadminMap[v.AdminId] = true
  602. }
  603. if rsCalendarItem.ActivityType == "路演" || rsCalendarItem.ActivityType == "公开会议" {
  604. // 更新研究员信息
  605. //go roadshowService.UpdateSHCalendar(req.RsCalendarId, req.RsCalendarResearcherId, req.ActivityType, req.RoadshowType, req.ActivityCategory, req.RoadshowPlatform, req.Province, req.City, req.ResearcherList)
  606. for k, v := range req.ResearcherList {
  607. rsCalendarResearcherItem, err := roadshow.GetRsCalendarResearcherById(req.RsCalendarResearcherId)
  608. if err != nil {
  609. br.Msg = "获取数据失败!"
  610. br.ErrMsg = "获取数据失败!GetRsCalendarResearcherById:" + err.Error()
  611. return
  612. }
  613. calendarResearcherWhereParams := make(map[string]interface{})
  614. calendarResearcherUpdateParams := make(map[string]interface{})
  615. calendarResearcherWhereParams["rs_calendar_researcher_id"] = req.RsCalendarResearcherId
  616. calendarResearcherUpdateParams["researcher_id"] = v.ResearcherId
  617. calendarResearcherUpdateParams["researcher_name"] = v.ResearcherName
  618. rsCalendarResearcherItem.ResearcherId = v.ResearcherId
  619. rsCalendarResearcherItem.ResearcherName = v.ResearcherName
  620. if rsCalendarResearcherItem.Status == 3 || rsCalendarResearcherItem.Status == 5 {
  621. calendarResearcherUpdateParams["status"] = 1
  622. rsCalendarResearcherItem.Status = 1
  623. }
  624. //CRM15.5 权益研究员直接通过
  625. if raiAskadminMap[v.ResearcherId] {
  626. calendarResearcherUpdateParams["status"] = 2
  627. rsCalendarResearcherItem.Status = 2
  628. }
  629. calendarResearcherUpdateParams["start_date"] = v.StartDate
  630. rsCalendarResearcherItem.StartDate = v.StartDate
  631. calendarResearcherUpdateParams["end_date"] = v.EndDate
  632. rsCalendarResearcherItem.EndDate = v.EndDate
  633. calendarResearcherUpdateParams["start_time"] = v.StartTime
  634. rsCalendarResearcherItem.StartTime = v.StartTime
  635. calendarResearcherUpdateParams["end_time"] = v.EndTime
  636. rsCalendarResearcherItem.EndTime = v.EndTime
  637. calendarResearcherUpdateParams["start_week"] = v.StartWeek
  638. rsCalendarResearcherItem.StartWeek = v.StartWeek
  639. calendarResearcherUpdateParams["end_week"] = v.EndWeek
  640. rsCalendarResearcherItem.EndWeek = v.EndWeek
  641. calendarResearcherUpdateParams["refuse_reason"] = ""
  642. rsCalendarResearcherItem.RefuseReason = ""
  643. calendarResearcherUpdateParams["refuse_time"] = nil
  644. calendarResearcherUpdateParams["delete_reason"] = ""
  645. rsCalendarResearcherItem.DeleteReason = ""
  646. calendarResearcherUpdateParams["approve_time"] = nil
  647. calendarResearcherUpdateParams["researcher_sort"] = k + 1
  648. rsCalendarResearcherItem.ResearcherSort = k + 1
  649. calendarResearcherUpdateParams["modify_time"] = time.Now()
  650. rsCalendarResearcherItem.ModifyTime = time.Now()
  651. calendarResearcherUpdateParams["create_time"] = time.Now()
  652. rsCalendarResearcherItem.CreateTime = time.Now()
  653. err = roadshow.UpdateCalendarResearcher(calendarResearcherWhereParams, calendarResearcherUpdateParams)
  654. if err != nil {
  655. br.Msg = "保存失败!"
  656. br.ErrMsg = "保存失败!UpdateCalendarResearcher:" + err.Error()
  657. return
  658. }
  659. //上海新增(因为在驳回的时候,就把上海该时间段的日程给删除了,所以修改的时候,需要重新调用新增接口)
  660. calendar := roadshow.RsCalendar{
  661. RsCalendarId: req.RsCalendarId,
  662. SysUserId: this.SysUser.AdminId,
  663. CompanyName: req.CompanyName,
  664. Title: getTitle(req.ActivityType, req.RoadshowType, req.ActivityCategory, req.RoadshowPlatform, req.Province, req.City),
  665. }
  666. researcher := *rsCalendarResearcherItem
  667. researcher.StartDate = v.StartDate
  668. researcher.EndDate = v.EndDate
  669. researcher.StartTime = v.StartTime
  670. researcher.EndTime = v.EndTime
  671. researcher.StartWeek = v.StartWeek
  672. researcher.EndWeek = v.EndWeek
  673. roadshowService.DeleteSHCalendar(req.RsCalendarResearcherId) //删除老的
  674. go roadshowService.CalendarToSH(calendar, researcher)
  675. if req.EditType == 2 {
  676. //模板消息通知
  677. go func(researcherId, tmpRsCalendarId, tmpRsCalendarResearcherId int) {
  678. sysAdmin, _ := system.GetSysAdminById(researcherId)
  679. if sysAdmin != nil && req.ActivityType != "内部会议" && req.ActivityType != "报告电话会" {
  680. first := "您收到一个新的【" + req.ActivityType + "】申请,请及时处理"
  681. keyword1 := sysUser.RealName
  682. keyword2 := "--"
  683. //keyword3 := time.Now().Format(utils.FormatDateTime)
  684. startDateSub := v.StartDate[5:]
  685. startDateSub = strings.Replace(startDateSub, "-", ".", -1)
  686. keyword3 := startDateSub + "(" + v.StartWeek + ")" + " " + v.StartTime[:5] + "~" + v.EndTime[:5]
  687. var keyword4 string
  688. if req.ActivityType == "路演" {
  689. keyword4 = req.CompanyName + "(" + req.RoadshowType + req.ActivityType + ")"
  690. } else {
  691. keyword4 = req.Theme + "(" + req.RoadshowType + req.ActivityType + ")"
  692. }
  693. remark := "请尽快完成审批"
  694. wxAppPath := "pages-approve/activity/detail?RsCalendarId=" + strconv.Itoa(tmpRsCalendarId) + "&RsCalendarResearcherId=" + strconv.Itoa(tmpRsCalendarResearcherId)
  695. openIdObj := &system.OpenIdList{
  696. OpenId: sysAdmin.OpenId,
  697. AdminId: sysAdmin.AdminId,
  698. }
  699. openIdList := make([]*system.OpenIdList, 0)
  700. openIdList = append(openIdList, openIdObj)
  701. if sysAdmin.OpenId != "" {
  702. services.SendWxMsgWithRoadshowPending(first, keyword1, keyword2, keyword3, keyword4, remark, wxAppPath, openIdList)
  703. }
  704. }
  705. }(v.ResearcherId, req.RsCalendarId, rsCalendarResearcherItem.RsCalendarResearcherId)
  706. }
  707. }
  708. } else {
  709. //先获取到所有的研究员日历表id
  710. researchers, err := roadshow.GetRsCalendarResearcherByCalendarId(req.RsCalendarId)
  711. if err != nil {
  712. utils.FileLog.Info("GetRsCalendarResearcherByCalendarId err: ", err)
  713. fmt.Println(err)
  714. return
  715. }
  716. //先删后增
  717. err = roadshow.DeleteRsCalendarResearcher(req.RsCalendarId)
  718. if err != nil {
  719. br.Msg = "保存失败!"
  720. br.ErrMsg = "保存失败!DeleteRsCalendarResearcher:" + err.Error()
  721. return
  722. }
  723. //删除上海
  724. for _, researcher := range researchers {
  725. roadshowService.DeleteSHCalendar(researcher.RsCalendarResearcherId)
  726. }
  727. for k, v := range req.ResearcherList {
  728. researcher := new(roadshow.RsCalendarResearcher)
  729. researcher.RsCalendarId = req.RsCalendarId
  730. researcher.ResearcherId = v.ResearcherId
  731. researcher.ResearcherName = v.ResearcherName
  732. researcher.StartDate = v.StartDate
  733. researcher.EndDate = v.EndDate
  734. researcher.StartTime = v.StartTime
  735. researcher.EndTime = v.EndTime
  736. researcher.StartWeek = v.StartWeek
  737. researcher.EndWeek = v.EndWeek
  738. researcher.CreateTime = time.Now()
  739. researcher.ModifyTime = time.Now()
  740. researcher.ResearcherSort = k + 1
  741. if req.ActivityType == "路演" || req.ActivityType == "公开会议" {
  742. researcher.Status = 1
  743. } else {
  744. researcher.Status = 2
  745. }
  746. //CRM15.5 权益研究员直接通过
  747. if raiAskadminMap[v.ResearcherId] {
  748. researcher.Status = 2
  749. }
  750. rsCalendarResearcherId, err := roadshow.AddRsCalendarResearcher(researcher)
  751. if err != nil {
  752. br.Msg = "保存失败!"
  753. br.ErrMsg = "保存日历活动-研究员信息失败!Err:" + err.Error()
  754. return
  755. }
  756. //上海新增
  757. calendar := roadshow.RsCalendar{
  758. RsCalendarId: req.RsCalendarId,
  759. SysUserId: this.SysUser.AdminId,
  760. Title: getTitle(req.ActivityType, req.RoadshowType, req.ActivityCategory, req.RoadshowPlatform, req.Province, req.City),
  761. }
  762. researcher.RsCalendarResearcherId = int(rsCalendarResearcherId)
  763. go roadshowService.CalendarToSH(calendar, *researcher)
  764. go func(researcherId, tmpRsCalendarId, tmpRsCalendarResearcherId int) {
  765. sysAdmin, _ := system.GetSysAdminById(researcherId)
  766. if sysAdmin != nil && req.ActivityType != "内部会议" && req.ActivityType != "报告电话会" {
  767. first := "您收到一个新的【" + req.ActivityType + "】申请,请及时处理"
  768. keyword1 := sysUser.RealName
  769. keyword2 := "--"
  770. //keyword3 := time.Now().Format(utils.FormatDateTime)
  771. startDateSub := v.StartDate[5:]
  772. startDateSub = strings.Replace(startDateSub, "-", ".", -1)
  773. keyword3 := startDateSub + "(" + v.StartWeek + ")" + " " + v.StartTime[:5] + "~" + v.EndTime[:5]
  774. var keyword4 string
  775. if req.ActivityType == "路演" {
  776. keyword4 = req.CompanyName + "(" + req.RoadshowType + req.ActivityType + ")"
  777. } else {
  778. keyword4 = req.Theme + "(" + req.RoadshowType + req.ActivityType + ")"
  779. }
  780. remark := "请尽快完成审批"
  781. wxAppPath := "pages-approve/activity/detail?RsCalendarId=" + strconv.Itoa(tmpRsCalendarId) + "&RsCalendarResearcherId=" + strconv.Itoa(tmpRsCalendarResearcherId)
  782. openIdObj := &system.OpenIdList{
  783. OpenId: sysAdmin.OpenId,
  784. AdminId: sysAdmin.AdminId,
  785. }
  786. openIdList := make([]*system.OpenIdList, 0)
  787. openIdList = append(openIdList, openIdObj)
  788. if sysAdmin.OpenId != "" {
  789. services.SendWxMsgWithRoadshowPending(first, keyword1, keyword2, keyword3, keyword4, remark, wxAppPath, openIdList)
  790. }
  791. }
  792. }(v.ResearcherId, req.RsCalendarId, int(rsCalendarResearcherId))
  793. }
  794. }
  795. //for k, v := range req.ResearcherList {
  796. // rsCalendarResearcherItem, err := roadshow.GetRsCalendarResearcherById(req.RsCalendarResearcherId)
  797. // var isAdd bool
  798. // if err != nil {
  799. // if err.Error() == utils.ErrNoRow() {
  800. // isAdd = true
  801. // } else {
  802. // br.Msg = "获取数据失败!"
  803. // br.ErrMsg = "获取数据失败!GetRsCalendarResearcherById:" + err.Error()
  804. // return
  805. // }
  806. // }
  807. // if rsCalendarResearcherItem == nil {
  808. // isAdd = true
  809. // }
  810. // if _, ok := existResearcherMap[v.ResearcherId]; !ok {
  811. // isAdd = true
  812. // }
  813. // fmt.Println("isAdd:", isAdd)
  814. // if isAdd {
  815. // exist, err := roadshow.GetRsCalendarResearcherExist(req.RsCalendarResearcherId, req.RsCalendarId, v.ResearcherId)
  816. // if err != nil && err.Error() != utils.ErrNoRow() {
  817. // br.Msg = "保存失败!"
  818. // br.ErrMsg = "保存失败!GetRsCalendarResearcherExist:" + err.Error()
  819. // return
  820. // }
  821. // if exist > 0 {
  822. // br.Msg = "研究员 " + v.ResearcherName + " 已存在相同活动"
  823. // br.ErrMsg = "研究员 " + v.ResearcherName + " 已存在相同活动"
  824. // return
  825. // }
  826. // researcher := new(roadshow.RsCalendarResearcher)
  827. // researcher.RsCalendarId = req.RsCalendarId
  828. // researcher.ResearcherId = v.ResearcherId
  829. // researcher.ResearcherName = v.ResearcherName
  830. // researcher.StartDate = v.StartDate
  831. // researcher.EndDate = v.EndDate
  832. // researcher.StartTime = v.StartTime
  833. // researcher.EndTime = v.EndTime
  834. // researcher.StartWeek = v.StartWeek
  835. // researcher.EndWeek = v.EndWeek
  836. // researcher.CreateTime = time.Now()
  837. // researcher.ModifyTime = time.Now()
  838. // researcher.ResearcherSort = k + 1
  839. // if req.ActivityType == "路演" || req.ActivityType == "公开会议" {
  840. // researcher.Status = 1
  841. // } else {
  842. // researcher.Status = 2
  843. // }
  844. // rsCalendarResearcherId, err := roadshow.AddRsCalendarResearcher(researcher)
  845. // if err != nil {
  846. // br.Msg = "保存失败!"
  847. // br.ErrMsg = "保存日历活动-研究员信息失败!Err:" + err.Error()
  848. // return
  849. // }
  850. //
  851. // //模板消息通知
  852. // {
  853. // sysAdmin, _ := system.GetSysAdminById(v.ResearcherId)
  854. // if sysAdmin != nil && req.ActivityType != "内部会议" && req.ActivityType != "报告电话会" {
  855. // first := "您收到一个新的【" + req.ActivityType + "】申请,请及时处理"
  856. // keyword1 := sysUser.RealName
  857. // keyword2 := "--"
  858. // keyword3 := time.Now().Format(utils.FormatDateTime)
  859. // startDateSub := v.StartDate[5:]
  860. // startDateSub = strings.Replace(startDateSub, "-", ".", -1)
  861. // var keyword4 string
  862. // if req.ActivityType == "路演" {
  863. // keyword4 = startDateSub + "(" + v.StartWeek + ")" + " " + v.StartTime[:5] + "~" + v.EndTime[:5] + " ," + req.CompanyName + "(" + req.RoadshowType + req.ActivityType + ")"
  864. // } else {
  865. // keyword4 = startDateSub + "(" + v.StartWeek + ")" + " " + v.StartTime[:5] + "~" + v.EndTime[:5] + " ," + req.Theme + "(" + req.RoadshowType + req.ActivityType + ")"
  866. // }
  867. // remark := "请尽快完成审批"
  868. // wxAppPath := "pages-approve/activity/detail?RsCalendarId=" + strconv.Itoa(req.RsCalendarId) + "&RsCalendarResearcherId=" + strconv.Itoa(int(rsCalendarResearcherId))
  869. // openIdList, _ := models.GetOpenIdListByMobile(sysAdmin.Mobile)
  870. // if len(openIdList) > 0 {
  871. // go services.SendWxMsgWithRoadshowPending(first, keyword1, keyword2, keyword3, keyword4, remark, wxAppPath, openIdList)
  872. // }
  873. // }
  874. // }
  875. // } else {
  876. // calendarResearcherWhereParams := make(map[string]interface{})
  877. // calendarResearcherUpdateParams := make(map[string]interface{})
  878. //
  879. // calendarResearcherWhereParams["rs_calendar_researcher_id"] = req.RsCalendarResearcherId
  880. //
  881. // exist, err := roadshow.GetRsCalendarResearcherExist(req.RsCalendarResearcherId, req.RsCalendarId, v.ResearcherId)
  882. // if err != nil && err.Error() != utils.ErrNoRow() {
  883. // br.Msg = "保存失败!"
  884. // br.ErrMsg = "保存失败!GetRsCalendarResearcherExist:" + err.Error()
  885. // return
  886. // }
  887. // if exist > 0 {
  888. // br.Msg = "研究员 " + v.ResearcherName + " 已存在相同活动"
  889. // br.ErrMsg = "研究员 " + v.ResearcherName + " 已存在相同活动"
  890. // return
  891. // }
  892. //
  893. // calendarResearcherUpdateParams["researcher_id"] = v.ResearcherId
  894. // calendarResearcherUpdateParams["researcher_name"] = v.ResearcherName
  895. //
  896. // if rsCalendarResearcherItem.Status == 3 || rsCalendarResearcherItem.Status == 5 {
  897. // calendarResearcherUpdateParams["status"] = 1
  898. // }
  899. // calendarResearcherUpdateParams["start_date"] = v.StartDate
  900. // calendarResearcherUpdateParams["end_date"] = v.EndDate
  901. // calendarResearcherUpdateParams["start_time"] = v.StartTime
  902. // calendarResearcherUpdateParams["end_time"] = v.EndTime
  903. // calendarResearcherUpdateParams["start_week"] = v.StartWeek
  904. // calendarResearcherUpdateParams["end_week"] = v.EndWeek
  905. // calendarResearcherUpdateParams["refuse_reason"] = ""
  906. // calendarResearcherUpdateParams["refuse_time"] = nil
  907. // calendarResearcherUpdateParams["delete_reason"] = ""
  908. // calendarResearcherUpdateParams["approve_time"] = nil
  909. // calendarResearcherUpdateParams["researcher_sort"] = k + 1
  910. // calendarResearcherUpdateParams["modify_time"] = time.Now()
  911. // calendarResearcherUpdateParams["create_time"] = time.Now()
  912. //
  913. // err = roadshow.UpdateCalendarResearcher(calendarResearcherWhereParams, calendarResearcherUpdateParams)
  914. // if err != nil {
  915. // br.Msg = "保存失败!"
  916. // br.ErrMsg = "保存失败!UpdateCalendarResearcher:" + err.Error()
  917. // return
  918. // }
  919. // if req.EditType == 2 {
  920. // //模板消息通知
  921. // {
  922. // sysAdmin, _ := system.GetSysAdminById(v.ResearcherId)
  923. // if sysAdmin != nil && req.ActivityType != "内部会议" && req.ActivityType != "报告电话会" {
  924. // first := "您收到一个新的【" + req.ActivityType + "】申请,请及时处理"
  925. // keyword1 := sysUser.RealName
  926. // keyword2 := "--"
  927. // keyword3 := time.Now().Format(utils.FormatDateTime)
  928. // startDateSub := v.StartDate[5:]
  929. // startDateSub = strings.Replace(startDateSub, "-", ".", -1)
  930. // var keyword4 string
  931. // if req.ActivityType == "路演" {
  932. // keyword4 = startDateSub + "(" + v.StartWeek + ")" + " " + v.StartTime[:5] + "~" + v.EndTime[:5] + " ," + req.CompanyName + "(" + req.RoadshowType + req.ActivityType + ")"
  933. // } else {
  934. // keyword4 = startDateSub + "(" + v.StartWeek + ")" + " " + v.StartTime[:5] + "~" + v.EndTime[:5] + " ," + req.Theme + "(" + req.RoadshowType + req.ActivityType + ")"
  935. // }
  936. // remark := "请尽快完成审批"
  937. // wxAppPath := "pages-approve/activity/detail?RsCalendarId=" + strconv.Itoa(req.RsCalendarId) + "&RsCalendarResearcherId=" + strconv.Itoa(rsCalendarResearcherItem.RsCalendarResearcherId)
  938. // openIdList, _ := models.GetOpenIdListByMobile(sysAdmin.Mobile)
  939. // if len(openIdList) > 0 {
  940. // go services.SendWxMsgWithRoadshowPending(first, keyword1, keyword2, keyword3, keyword4, remark, wxAppPath, openIdList)
  941. // }
  942. // }
  943. // }
  944. // }
  945. //
  946. // }
  947. // newResearcherMap[v.ResearcherId] = v.ResearcherName
  948. //}
  949. //处理删除情况
  950. //{
  951. // if req.EditType == 1 {
  952. // researchList, err := roadshow.GetRsCalendarResearcherListByRsCalendarId(req.RsCalendarId)
  953. // if err != nil {
  954. // br.Msg = "保存失败!"
  955. // br.ErrMsg = "保存失败!UpdateCalendarResearcher:" + err.Error()
  956. // return
  957. // }
  958. // for _, ev := range researchList {
  959. // if _, ok := newResearcherMap[ev.ResearcherId]; !ok {
  960. // roadshow.DeleteCalendar(req.RsCalendarId, ev.RsCalendarResearcherId)
  961. // }
  962. // }
  963. // }
  964. //}
  965. //if req.ActivityType == "公开会议" {
  966. // go roadshowService.SetPublicMeetingUnionCode()
  967. //}
  968. br.Ret = 200
  969. br.Success = true
  970. br.Msg = "保存成功"
  971. br.IsAddLog = true
  972. }
  973. // ResearcherList
  974. // @Title 研究员列表
  975. // @Description 研究员列表接口
  976. // @Success 200 {object} roadshow.ResearcherGroup
  977. // @router /researcher/list [get]
  978. func (this *CalendarController) ResearcherList() {
  979. br := new(models.BaseResponse).Init()
  980. defer func() {
  981. this.Data["json"] = br
  982. this.ServeJSON()
  983. }()
  984. group, err := roadshow.GetResearcherGroup()
  985. if err != nil {
  986. br.Msg = "获取信息失败!"
  987. br.ErrMsg = "获取分组信息失败!Err:" + err.Error()
  988. return
  989. }
  990. researcherList, err := roadshow.GetResearcher()
  991. groupMap := make(map[int][]*roadshow.ResearcherGroup)
  992. for _, v := range researcherList {
  993. item := &roadshow.ResearcherGroup{
  994. GroupId: v.GroupId,
  995. GroupName: v.GroupName,
  996. AdminId: v.AdminId,
  997. RealName: v.RealName,
  998. RoleTypeCode: v.RoleTypeCode,
  999. }
  1000. if findItems, ok := groupMap[v.GroupId]; ok {
  1001. findItems = append(findItems, item)
  1002. groupMap[v.GroupId] = findItems
  1003. } else {
  1004. findItems = append(findItems, item)
  1005. groupMap[v.GroupId] = findItems
  1006. }
  1007. //}
  1008. }
  1009. for _, v := range group {
  1010. v.ResearcherList = groupMap[v.GroupId]
  1011. }
  1012. ficcGroup := new(roadshow.ResearcherGroup)
  1013. ficcGroup.GroupId = 999
  1014. ficcGroup.GroupName = "ficc"
  1015. ficcGroup.ResearcherList = group
  1016. sysUserList, err := system.GetAdminList()
  1017. if err != nil {
  1018. br.Msg = "获取失败"
  1019. br.ErrMsg = "获取admin列表失败, Err:" + err.Error()
  1020. return
  1021. }
  1022. adminMap := make(map[int]*system.Admin, 0)
  1023. for _, v := range sysUserList {
  1024. adminMap[v.AdminId] = v
  1025. }
  1026. askUserList, err := cygx.GetAskEmailList()
  1027. if err != nil {
  1028. br.Msg = "获取失败"
  1029. br.ErrMsg = "获取失败,GetAskEmailList Err: " + err.Error()
  1030. return
  1031. }
  1032. mapPermissionUser := make(map[string][]*roadshow.ResearcherGroup)
  1033. listPermission, err := cygx.GetChartPermissionAll()
  1034. if err != nil {
  1035. br.Msg = "获取信息失败"
  1036. br.ErrMsg = "获取品种信息失败,Err:" + err.Error()
  1037. return
  1038. }
  1039. mapPermissionId := make(map[string]int)
  1040. for _, v := range listPermission {
  1041. mapPermissionId[v.PermissionName] = v.ChartPermissionId
  1042. }
  1043. sysUserFwang, e := system.GetSysUserByAdminName("fwang") // 手动拼接王芳到权益的策略行业下 start
  1044. if e != nil {
  1045. if e.Error() == utils.ErrNoRow() {
  1046. br.Msg = "用户不存在, 请检查"
  1047. return
  1048. }
  1049. br.Msg = "账号错误, 请重新输入"
  1050. br.ErrMsg = "fwang 用户名获取用户失败, Err: " + e.Error()
  1051. return
  1052. }
  1053. itemFwang := new(roadshow.ResearcherGroup)
  1054. itemFwang.AdminId = sysUserFwang.AdminId
  1055. itemFwang.GroupId = sysUserFwang.GroupId
  1056. itemFwang.GroupName = sysUserFwang.GroupName
  1057. itemFwang.RealName = sysUserFwang.RealName
  1058. itemFwang.RoleTypeCode = sysUserFwang.RoleTypeCode
  1059. mapPermissionUser["策略"] = append(mapPermissionUser["策略"], itemFwang) // 手动拼接王芳到权益的策略行业下 end
  1060. for _, v := range askUserList {
  1061. if admin, ok := adminMap[v.AdminId]; ok {
  1062. item := &roadshow.ResearcherGroup{
  1063. AdminId: v.AdminId,
  1064. RealName: v.Name,
  1065. GroupId: admin.GroupId,
  1066. GroupName: admin.GroupName,
  1067. RoleTypeCode: admin.RoleTypeCode,
  1068. }
  1069. mapPermissionUser[v.ChartPermissionName] = append(mapPermissionUser[v.ChartPermissionName], item)
  1070. }
  1071. }
  1072. raiList := make([]*roadshow.ResearcherGroup, 0)
  1073. for k, v := range mapPermissionUser {
  1074. respItem := new(roadshow.ResearcherGroup)
  1075. respItem.GroupName = k + "组"
  1076. respItem.GroupId = mapPermissionId[k]
  1077. respItem.ResearcherList = v
  1078. raiList = append(raiList, respItem)
  1079. }
  1080. raiGroup := new(roadshow.ResearcherGroup)
  1081. raiGroup.GroupId = 888
  1082. raiGroup.GroupName = "权益"
  1083. raiGroup.ResearcherList = raiList
  1084. var resp []*roadshow.ResearcherGroup
  1085. resp = append(resp, ficcGroup, raiGroup)
  1086. br.Ret = 200
  1087. br.Success = true
  1088. br.Msg = "获取成功"
  1089. br.Data = resp
  1090. }
  1091. // CalendarList
  1092. // @Title 我的日历列表
  1093. // @Description 我的日历列表接口
  1094. // @Param PageSize query int true "每页数据条数"
  1095. // @Param CurrentIndex query int true "当前页页码,从1开始"
  1096. // @Param CalendarType query int true "1:待处理申请,2:已处理申请,3:内部会议,4:报告电话会"
  1097. // @Success 200 {object} roadshow.CalendarListResp
  1098. // @router /calendar/list [get]
  1099. func (this *CalendarController) CalendarList() {
  1100. br := new(models.BaseResponse).Init()
  1101. defer func() {
  1102. this.Data["json"] = br
  1103. this.ServeJSON()
  1104. }()
  1105. sysUser := this.SysUser
  1106. if sysUser == nil {
  1107. br.Msg = "请登录"
  1108. br.ErrMsg = "请登录,SysUser Is Empty"
  1109. br.Ret = 408
  1110. return
  1111. }
  1112. calendarType, _ := this.GetInt("CalendarType")
  1113. pageSize, _ := this.GetInt("PageSize")
  1114. currentIndex, _ := this.GetInt("CurrentIndex")
  1115. var total int
  1116. page := paging.GetPaging(currentIndex, pageSize, total)
  1117. var startSize int
  1118. if pageSize <= 0 {
  1119. pageSize = utils.PageSize10
  1120. }
  1121. if currentIndex <= 0 {
  1122. currentIndex = 1
  1123. }
  1124. startSize = paging.StartIndex(currentIndex, pageSize)
  1125. var condition string
  1126. var pars []interface{}
  1127. roleTypeCode := sysUser.RoleTypeCode
  1128. //销售
  1129. if roleTypeCode == utils.ROLE_TYPE_CODE_FICC_SELLER ||
  1130. //roleTypeCode == utils.ROLE_TYPE_CODE_RAI_SELLER ||
  1131. roleTypeCode == utils.ROLE_TYPE_CODE_FICC_GROUP ||
  1132. //roleTypeCode == utils.ROLE_TYPE_CODE_RAI_GROUP ||
  1133. roleTypeCode == utils.ROLE_TYPE_CODE_FICC_TEAM ||
  1134. roleTypeCode == utils.ROLE_TYPE_CODE_RAI_ADMIN {
  1135. condition += ` AND a.sys_user_id=?`
  1136. pars = append(pars, sysUser.AdminId)
  1137. //condition += ` AND a.activity_type IN('路演','公开会议') `
  1138. }
  1139. //权益销售
  1140. if roleTypeCode == utils.ROLE_TYPE_CODE_RAI_SELLER ||
  1141. roleTypeCode == utils.ROLE_TYPE_CODE_RAI_GROUP {
  1142. //if calendarType == 2 {
  1143. condition += ` AND ( a.sys_user_id=? OR a.seller_id=? OR a.share_seller_id=? ) `
  1144. pars = append(pars, sysUser.AdminId, sysUser.AdminId, sysUser.AdminId)
  1145. //}
  1146. }
  1147. if roleTypeCode == utils.ROLE_TYPE_CODE_FICC_RESEARCHR ||
  1148. roleTypeCode == utils.ROLE_TYPE_CODE_RESEARCHR ||
  1149. roleTypeCode == utils.ROLE_TYPE_CODE_RAI_RESEARCHR ||
  1150. roleTypeCode == utils.ROLE_TYPE_CODE_FICC_DEPARTMENT ||
  1151. roleTypeCode == utils.ROLE_TYPE_CODE_RAI_DEPARTMENT ||
  1152. roleTypeCode == utils.ROLE_TYPE_CODE_FICC_ADMIN {
  1153. if calendarType != 3 {
  1154. condition += ` AND b.researcher_id=?`
  1155. pars = append(pars, sysUser.AdminId)
  1156. }
  1157. }
  1158. if roleTypeCode == utils.ROLE_TYPE_CODE_ADMIN {
  1159. condition += ` AND a.sys_user_id=?`
  1160. pars = append(pars, sysUser.AdminId)
  1161. }
  1162. if calendarType == 1 {
  1163. condition += ` AND b.status=1`
  1164. }
  1165. if calendarType == 2 {
  1166. condition += ` AND b.status>=2`
  1167. condition += ` AND a.activity_type IN('路演','公开会议','沙龙') `
  1168. }
  1169. if calendarType == 3 {
  1170. condition += ` AND a.activity_type='内部会议' `
  1171. condition += ` AND a.sys_user_id=?`
  1172. pars = append(pars, sysUser.AdminId)
  1173. }
  1174. if calendarType == 4 {
  1175. condition += ` AND a.activity_type='报告电话会' `
  1176. }
  1177. if calendarType < 0 || calendarType > 4 {
  1178. br.Msg = "参数错误"
  1179. br.ErrMsg = "参数错误,calendarType:" + strconv.Itoa(calendarType)
  1180. return
  1181. }
  1182. fmt.Println(condition)
  1183. resp := new(roadshow.CalendarListResp)
  1184. total, err := roadshow.GetCalendarListCount(condition, pars, calendarType)
  1185. if err != nil && err.Error() != utils.ErrNoRow() {
  1186. br.Msg = "获取信息失败"
  1187. br.ErrMsg = "获取数据总数失败,GetCalendarListCount,Err:" + err.Error()
  1188. return
  1189. }
  1190. page = paging.GetPaging(currentIndex, pageSize, total)
  1191. dataList, err := roadshow.GetCalendarList(condition, pars, startSize, pageSize, calendarType)
  1192. if err != nil {
  1193. br.Msg = "获取指标信息失败"
  1194. br.ErrMsg = "获取数据失败,GetCalendarList,Err:" + err.Error()
  1195. return
  1196. }
  1197. // 英文客户的国家以及点击量
  1198. englishIds := make([]int, 0)
  1199. adminIds := make([]int, 0) // 管理员ID
  1200. rsCalendarId := make([]int, 0) //路演ID
  1201. for i := range dataList {
  1202. if dataList[i].EnglishCompany == 1 {
  1203. englishIds = append(englishIds, dataList[i].CompanyId)
  1204. }
  1205. if calendarType == 2 {
  1206. adminIds = append(adminIds, dataList[i].SysUserId)
  1207. rsCalendarId = append(rsCalendarId, dataList[i].RsCalendarId)
  1208. }
  1209. }
  1210. englishMap := make(map[int]*models.EnglishCompany)
  1211. if len(englishIds) > 0 {
  1212. englishCond := ` AND company_id IN (` + utils.GetOrmInReplace(len(englishIds)) + `)`
  1213. englishPars := make([]interface{}, 0)
  1214. englishPars = append(englishPars, englishIds)
  1215. englishList, e := models.GetEnglishCompanyList(englishCond, englishPars, "")
  1216. if e != nil {
  1217. br.Msg = "获取英文客户失败"
  1218. br.ErrMsg = "获取英文客户失败, Err:" + e.Error()
  1219. return
  1220. }
  1221. for i := range englishList {
  1222. englishMap[englishList[i].CompanyId] = englishList[i]
  1223. }
  1224. }
  1225. //获取所有自定义的权益研究员
  1226. sysUserList, err := cygx.GetAskEmailList()
  1227. if err != nil {
  1228. br.Msg = "获取失败"
  1229. br.ErrMsg = "获取失败,GetAskEmailList Err: " + err.Error()
  1230. return
  1231. }
  1232. raiAskadminMap := make(map[string]bool, 0)
  1233. for _, v := range sysUserList {
  1234. raiAskadminMap[strconv.Itoa(v.AdminId)] = true
  1235. }
  1236. mapRaiSllerId := make(map[int]bool) // 是否为权益销售
  1237. mapMeetingCount := make(map[int]int) // 路演参会人员数量
  1238. if len(adminIds) > 0 {
  1239. listAdmin, e := system.GetAdminListByIdListWithoutEnable(adminIds)
  1240. if e != nil {
  1241. br.Msg = "获取信息失败"
  1242. br.ErrMsg = "获取管理员信息失败, Err:" + e.Error()
  1243. return
  1244. }
  1245. for _, v := range listAdmin { //权益销售与权益销售组长、权益管理员
  1246. 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 {
  1247. mapRaiSllerId[v.AdminId] = true
  1248. }
  1249. }
  1250. listMeetingCount, e := roadshow.GetRsCalendarMeetingUserListCount(rsCalendarId)
  1251. if e != nil {
  1252. br.Msg = "获取信息失败"
  1253. br.ErrMsg = "获取路演参会人员数量信息失败, Err:" + e.Error()
  1254. return
  1255. }
  1256. for _, v := range listMeetingCount {
  1257. mapMeetingCount[v.RsCalendarId] = v.Total
  1258. }
  1259. }
  1260. for i := range dataList {
  1261. if dataList[i].EnglishCompany == 1 {
  1262. en := englishMap[dataList[i].CompanyId]
  1263. if en != nil {
  1264. dataList[i].EnglishCountry = en.Country
  1265. dataList[i].EnglishViewTotal = en.ViewTotal
  1266. }
  1267. }
  1268. //如果是已结束的权益销售添加的活动,就行进行按钮展示
  1269. if mapRaiSllerId[dataList[i].SysUserId] && utils.InArrayByInt([]int{2, 6}, dataList[i].Status) && dataList[i].ActivityType != "沙龙" {
  1270. if mapMeetingCount[dataList[i].RsCalendarId] == 0 {
  1271. dataList[i].SubmitButton = true
  1272. } else {
  1273. dataList[i].ViewButton = true
  1274. }
  1275. }
  1276. //权益研究员的【路演】和【沙龙】,未结束时,显示修改按钮
  1277. if raiAskadminMap[dataList[i].ResearcherId] && utils.InArrayByStr([]string{"路演", "沙龙"}, dataList[i].ActivityType) && dataList[i].Status == 2 {
  1278. //未开始的才展示修改按钮
  1279. startTimeStr := dataList[i].StartDate + " " + dataList[i].StartTime
  1280. startTime := utils.StrTimeToTime(startTimeStr)
  1281. if startTime.After(time.Now()) {
  1282. dataList[i].EditButton = true
  1283. }
  1284. }
  1285. }
  1286. resp.Paging = page
  1287. resp.List = dataList
  1288. br.Ret = 200
  1289. br.Success = true
  1290. br.Msg = "获取成功"
  1291. br.Data = resp
  1292. }
  1293. // Accept
  1294. // @Description 接受路演活动接口
  1295. // @Param request body roadshow.AcceptReq true "type json string"
  1296. // @Success Ret=200 保存成功
  1297. // @router /accept [post]
  1298. func (this *CalendarController) Accept() {
  1299. br := new(models.BaseResponse).Init()
  1300. defer func() {
  1301. this.Data["json"] = br
  1302. this.ServeJSON()
  1303. }()
  1304. sysUser := this.SysUser
  1305. if sysUser == nil {
  1306. br.Msg = "请登录"
  1307. br.ErrMsg = "请登录,SysUser Is Empty"
  1308. br.Ret = 408
  1309. return
  1310. }
  1311. var req roadshow.AcceptReq
  1312. err := json.Unmarshal(this.Ctx.Input.RequestBody, &req)
  1313. if err != nil {
  1314. br.Msg = "参数解析异常!"
  1315. br.ErrMsg = "参数解析失败,Err:" + err.Error()
  1316. return
  1317. }
  1318. if req.RsCalendarId <= 0 || req.RsCalendarResearcherId <= 0 {
  1319. br.Msg = "参数错误!"
  1320. br.ErrMsg = "参数错误!RsCalendarId:" + strconv.Itoa(req.RsCalendarId) + ";RsCalendarResearcherId:" + strconv.Itoa(req.RsCalendarResearcherId)
  1321. return
  1322. }
  1323. rsCalendar, err := roadshow.GetRsCalendarById(req.RsCalendarId)
  1324. if err != nil {
  1325. br.Msg = "获取数据失败!"
  1326. br.ErrMsg = "获取数据失败!GetRsCalendarById:" + err.Error()
  1327. return
  1328. }
  1329. rsCalendarResearcher, err := roadshow.GetRsCalendarResearcherById(req.RsCalendarResearcherId)
  1330. if err != nil {
  1331. br.Msg = "获取数据失败!"
  1332. br.ErrMsg = "获取数据失败!GetRsCalendarResearcherById:" + err.Error()
  1333. return
  1334. }
  1335. if rsCalendarResearcher.Status == 2 {
  1336. br.Msg = "已接受,不可重复操作!"
  1337. return
  1338. } else if rsCalendarResearcher.Status == 3 {
  1339. br.Msg = "已拒绝,不可进行接受操作!"
  1340. return
  1341. } else if rsCalendarResearcher.Status == 4 {
  1342. br.Msg = "已删除,不可进行接受操作!"
  1343. return
  1344. } else if rsCalendarResearcher.Status == 5 {
  1345. br.Msg = "已撤回,不可进行接受操作!"
  1346. return
  1347. }
  1348. whereParams := make(map[string]interface{})
  1349. updateParams := make(map[string]interface{})
  1350. whereParams["rs_calendar_researcher_id"] = req.RsCalendarResearcherId
  1351. whereParams["rs_calendar_id"] = req.RsCalendarId
  1352. updateParams["status"] = 2
  1353. updateParams["modify_time"] = time.Now()
  1354. updateParams["approve_time"] = time.Now()
  1355. err = roadshow.UpdateCalendarResearcher(whereParams, updateParams)
  1356. if err != nil {
  1357. br.Msg = "保存失败!"
  1358. br.ErrMsg = "保存失败!UpdateCalendarResearcher:" + err.Error()
  1359. return
  1360. }
  1361. //模板消息通知
  1362. {
  1363. if rsCalendar != nil {
  1364. go func(tmpRsCalendar roadshow.RsCalendar) {
  1365. sysAdmin, _ := system.GetSysAdminById(tmpRsCalendar.SysUserId)
  1366. first := "【" + sysUser.RealName + "】接受了你的【" + tmpRsCalendar.ActivityType + "】申请"
  1367. var keyword1, keyword2, keyword3, keyword4, keyword5 string
  1368. keyword1 = tmpRsCalendar.CompanyName + "(" + tmpRsCalendar.RoadshowType + tmpRsCalendar.ActivityType + ")"
  1369. keyword2 = tmpRsCalendar.ActivityType
  1370. keyword4 = `【` + sysUser.RealName + `】已接受`
  1371. remark := ""
  1372. wxAppPath := ""
  1373. openIdObj := &system.OpenIdList{
  1374. OpenId: sysAdmin.OpenId,
  1375. AdminId: sysAdmin.AdminId,
  1376. }
  1377. openIdList := make([]*system.OpenIdList, 0)
  1378. openIdList = append(openIdList, openIdObj)
  1379. if sysAdmin.OpenId != "" {
  1380. services.SendWxMsgWithRoadshowDetailResult(first, keyword1, keyword2, keyword3, keyword4, keyword5, remark, wxAppPath, openIdList)
  1381. }
  1382. }(*rsCalendar)
  1383. }
  1384. }
  1385. br.Ret = 200
  1386. br.Success = true
  1387. br.Msg = "保存成功"
  1388. br.IsAddLog = true
  1389. }
  1390. // @Title 拒绝路演活动接口
  1391. // @Description 拒绝路演活动接口
  1392. // @Param request body roadshow.RefuseReq true "type json string"
  1393. // @Success Ret=200 保存成功
  1394. // @router /refuse [post]
  1395. func (this *CalendarController) Refuse() {
  1396. br := new(models.BaseResponse).Init()
  1397. defer func() {
  1398. this.Data["json"] = br
  1399. this.ServeJSON()
  1400. }()
  1401. sysUser := this.SysUser
  1402. if sysUser == nil {
  1403. br.Msg = "请登录"
  1404. br.ErrMsg = "请登录,SysUser Is Empty"
  1405. br.Ret = 408
  1406. return
  1407. }
  1408. var req roadshow.RefuseReq
  1409. err := json.Unmarshal(this.Ctx.Input.RequestBody, &req)
  1410. if err != nil {
  1411. br.Msg = "参数解析异常!"
  1412. br.ErrMsg = "参数解析失败,Err:" + err.Error()
  1413. return
  1414. }
  1415. if req.RsCalendarId <= 0 || req.RsCalendarResearcherId <= 0 {
  1416. br.Msg = "参数错误!"
  1417. br.ErrMsg = "参数错误!RsCalendarId:" + strconv.Itoa(req.RsCalendarId) + ";RsCalendarResearcherId:" + strconv.Itoa(req.RsCalendarResearcherId)
  1418. return
  1419. }
  1420. rsCalendar, err := roadshow.GetRsCalendarById(req.RsCalendarId)
  1421. if err != nil {
  1422. br.Msg = "获取数据失败!"
  1423. br.ErrMsg = "获取数据失败!GetRsCalendarById:" + err.Error()
  1424. return
  1425. }
  1426. rsCalendarResearcher, err := roadshow.GetRsCalendarResearcherById(req.RsCalendarResearcherId)
  1427. if err != nil {
  1428. br.Msg = "获取数据失败!"
  1429. br.ErrMsg = "获取数据失败!GetRsCalendarResearcherById:" + err.Error()
  1430. return
  1431. }
  1432. if rsCalendarResearcher.Status == 2 {
  1433. br.Msg = "已接受,不可进行拒绝操作!"
  1434. return
  1435. } else if rsCalendarResearcher.Status == 3 {
  1436. br.Msg = "已拒绝,不可进行重复操作!"
  1437. return
  1438. } else if rsCalendarResearcher.Status == 4 {
  1439. br.Msg = "已删除,不可进行拒绝操作!"
  1440. return
  1441. } else if rsCalendarResearcher.Status == 5 {
  1442. br.Msg = "已撤回,不可进行拒绝操作!"
  1443. return
  1444. }
  1445. whereParams := make(map[string]interface{})
  1446. updateParams := make(map[string]interface{})
  1447. whereParams["rs_calendar_researcher_id"] = req.RsCalendarResearcherId
  1448. whereParams["rs_calendar_id"] = req.RsCalendarId
  1449. updateParams["status"] = 3
  1450. updateParams["refuse_reason"] = req.RefuseReason
  1451. updateParams["refuse_time"] = time.Now()
  1452. updateParams["modify_time"] = time.Now()
  1453. err = roadshow.UpdateCalendarResearcher(whereParams, updateParams)
  1454. if err != nil {
  1455. br.Msg = "保存失败!"
  1456. br.ErrMsg = "保存失败!UpdateCalendarResearcher:" + err.Error()
  1457. return
  1458. }
  1459. //拒绝后,需要删除该日程
  1460. go roadshowService.DeleteSHCalendar(req.RsCalendarResearcherId)
  1461. //模板消息通知
  1462. {
  1463. if rsCalendar != nil {
  1464. go func(tmpRsCalendar roadshow.RsCalendar) {
  1465. sysAdmin, _ := system.GetSysAdminById(tmpRsCalendar.SysUserId)
  1466. first := "【" + sysUser.RealName + "】拒绝了你的【" + tmpRsCalendar.ActivityType + "】申请"
  1467. var keyword1, keyword2, keyword3, keyword4, keyword5 string
  1468. keyword1 = tmpRsCalendar.CompanyName + "(" + tmpRsCalendar.RoadshowType + tmpRsCalendar.ActivityType + ")"
  1469. keyword2 = tmpRsCalendar.ActivityType
  1470. keyword4 = `【` + sysUser.RealName + `】已拒绝`
  1471. keyword5 = req.RefuseReason
  1472. remark := req.RefuseReason
  1473. wxAppPath := ""
  1474. openIdObj := &system.OpenIdList{
  1475. OpenId: sysAdmin.OpenId,
  1476. AdminId: sysAdmin.AdminId,
  1477. }
  1478. openIdList := make([]*system.OpenIdList, 0)
  1479. openIdList = append(openIdList, openIdObj)
  1480. if sysAdmin.OpenId != "" {
  1481. services.SendWxMsgWithRoadshowDetailResult(first, keyword1, keyword2, keyword3, keyword4, keyword5, remark, wxAppPath, openIdList)
  1482. }
  1483. }(*rsCalendar)
  1484. }
  1485. }
  1486. br.Ret = 200
  1487. br.Success = true
  1488. br.Msg = "保存成功"
  1489. br.IsAddLog = true
  1490. }
  1491. // @Title 撤回路演活动接口
  1492. // @Description 撤回路演活动接口
  1493. // @Param request body roadshow.AcceptReq true "type json string"
  1494. // @Success Ret=200 保存成功
  1495. // @router /back [post]
  1496. func (this *CalendarController) Back() {
  1497. br := new(models.BaseResponse).Init()
  1498. defer func() {
  1499. this.Data["json"] = br
  1500. this.ServeJSON()
  1501. }()
  1502. sysUser := this.SysUser
  1503. if sysUser == nil {
  1504. br.Msg = "请登录"
  1505. br.ErrMsg = "请登录,SysUser Is Empty"
  1506. br.Ret = 408
  1507. return
  1508. }
  1509. var req roadshow.AcceptReq
  1510. err := json.Unmarshal(this.Ctx.Input.RequestBody, &req)
  1511. if err != nil {
  1512. br.Msg = "参数解析异常!"
  1513. br.ErrMsg = "参数解析失败,Err:" + err.Error()
  1514. return
  1515. }
  1516. if req.RsCalendarId <= 0 || req.RsCalendarResearcherId <= 0 {
  1517. br.Msg = "参数错误!"
  1518. br.ErrMsg = "参数错误!RsCalendarId:" + strconv.Itoa(req.RsCalendarId) + ";RsCalendarResearcherId:" + strconv.Itoa(req.RsCalendarResearcherId)
  1519. return
  1520. }
  1521. _, err = roadshow.GetRsCalendarById(req.RsCalendarId)
  1522. if err != nil {
  1523. br.Msg = "获取数据失败!"
  1524. br.ErrMsg = "获取数据失败!GetRsCalendarById:" + err.Error()
  1525. return
  1526. }
  1527. rsCalendarResearcher, err := roadshow.GetRsCalendarResearcherById(req.RsCalendarResearcherId)
  1528. if err != nil {
  1529. br.Msg = "获取数据失败!"
  1530. br.ErrMsg = "获取数据失败!GetRsCalendarResearcherById:" + err.Error()
  1531. return
  1532. }
  1533. if rsCalendarResearcher.Status == 2 {
  1534. br.Msg = "已接受,不可进行撤回操作!"
  1535. return
  1536. } else if rsCalendarResearcher.Status == 3 {
  1537. br.Msg = "已拒绝,不可进行撤回操作!"
  1538. return
  1539. } else if rsCalendarResearcher.Status == 4 {
  1540. br.Msg = "已删除,不可进行撤回操作!"
  1541. return
  1542. } else if rsCalendarResearcher.Status == 5 {
  1543. br.Msg = "已撤回,不可进行重复操作!"
  1544. return
  1545. }
  1546. whereParams := make(map[string]interface{})
  1547. updateParams := make(map[string]interface{})
  1548. whereParams["rs_calendar_researcher_id"] = req.RsCalendarResearcherId
  1549. whereParams["rs_calendar_id"] = req.RsCalendarId
  1550. updateParams["status"] = 5
  1551. updateParams["modify_time"] = time.Now()
  1552. err = roadshow.UpdateCalendarResearcher(whereParams, updateParams)
  1553. //撤回后,需要删除该日程
  1554. go roadshowService.DeleteSHCalendar(req.RsCalendarResearcherId)
  1555. if err != nil {
  1556. br.Msg = "保存失败!"
  1557. br.ErrMsg = "保存失败!UpdateCalendarResearcher:" + err.Error()
  1558. return
  1559. }
  1560. br.Ret = 200
  1561. br.Success = true
  1562. br.Msg = "保存成功"
  1563. br.IsAddLog = true
  1564. }
  1565. // @Title 删除路演活动接口
  1566. // @Description 删除路演活动接口
  1567. // @Param request body roadshow.DeleteReq true "type json string"
  1568. // @Success Ret=200 保存成功
  1569. // @router /delete [post]
  1570. func (this *CalendarController) Delete() {
  1571. br := new(models.BaseResponse).Init()
  1572. defer func() {
  1573. this.Data["json"] = br
  1574. this.ServeJSON()
  1575. }()
  1576. sysUser := this.SysUser
  1577. if sysUser == nil {
  1578. br.Msg = "请登录"
  1579. br.ErrMsg = "请登录,SysUser Is Empty"
  1580. br.Ret = 408
  1581. return
  1582. }
  1583. var req roadshow.DeleteReq
  1584. err := json.Unmarshal(this.Ctx.Input.RequestBody, &req)
  1585. if err != nil {
  1586. br.Msg = "参数解析异常!"
  1587. br.ErrMsg = "参数解析失败,Err:" + err.Error()
  1588. return
  1589. }
  1590. if req.RsCalendarId <= 0 || req.RsCalendarResearcherId <= 0 {
  1591. br.Msg = "参数错误!"
  1592. br.ErrMsg = "参数错误!RsCalendarId:" + strconv.Itoa(req.RsCalendarId) + ";RsCalendarResearcherId:" + strconv.Itoa(req.RsCalendarResearcherId)
  1593. return
  1594. }
  1595. rsCalendarItem, err := roadshow.GetRsCalendarById(req.RsCalendarId)
  1596. if err != nil {
  1597. br.Msg = "获取数据失败!"
  1598. br.ErrMsg = "获取数据失败!GetRsCalendarById:" + err.Error()
  1599. return
  1600. }
  1601. rsCalendarResearcherItemList, err := roadshow.GetRsCalendarResearcherListById(req.RsCalendarId)
  1602. if err != nil {
  1603. br.Msg = "获取数据失败!"
  1604. br.ErrMsg = "获取数据失败!GetRsCalendarResearcherById:" + err.Error()
  1605. return
  1606. }
  1607. if rsCalendarItem.ActivityType == "报告电话会" || rsCalendarItem.ActivityType == "内部会议" {
  1608. err = roadshow.DeleteCalendar(req.RsCalendarId, req.RsCalendarResearcherId)
  1609. if err != nil {
  1610. br.Msg = "删除失败!"
  1611. br.ErrMsg = "删除失败!DeleteCalendar:" + err.Error()
  1612. return
  1613. }
  1614. //检测报表记录中是否已经存在,如果存在,则删除
  1615. {
  1616. err = roadshow.DeleteRsReportRecord(req.RsCalendarId, req.RsCalendarResearcherId)
  1617. if err != nil {
  1618. br.Msg = "删除失败!"
  1619. br.ErrMsg = "删除失败!DeleteRsReportRecord:" + err.Error()
  1620. return
  1621. }
  1622. }
  1623. } else {
  1624. //只获取一条路演数据
  1625. rsCalendarResearcherItemList, err = roadshow.GetRsCalendarResearcherListByCalendarResearcherId(req.RsCalendarResearcherId)
  1626. if err != nil {
  1627. br.Msg = "获取数据失败!"
  1628. br.ErrMsg = "获取数据失败!GetRsCalendarResearcherById:" + err.Error()
  1629. return
  1630. }
  1631. whereParams := make(map[string]interface{})
  1632. updateParams := make(map[string]interface{})
  1633. whereParams["rs_calendar_researcher_id"] = req.RsCalendarResearcherId
  1634. whereParams["rs_calendar_id"] = req.RsCalendarId
  1635. updateParams["status"] = 4
  1636. updateParams["delete_reason"] = req.DeleteReason
  1637. updateParams["modify_time"] = time.Now()
  1638. updateParams["delete_time"] = time.Now()
  1639. err = roadshow.UpdateCalendarResearcher(whereParams, updateParams)
  1640. if err != nil {
  1641. br.Msg = "删除失败!"
  1642. br.ErrMsg = "删除失败!UpdateCalendarResearcher:" + err.Error()
  1643. return
  1644. }
  1645. }
  1646. itemApiLog := new(roadshow.RsCalendarApiLog)
  1647. itemApiLog.CreateTime = time.Now()
  1648. itemApiLog.Remark = "CRM手动删除"
  1649. itemApiLog.Url = sysUser.RealName
  1650. itemApiLog.Body = ""
  1651. itemApiLog.Result = ""
  1652. itemApiLog.RsCalendarResearcherId = req.RsCalendarResearcherId
  1653. itemApiLog.RsCalendarId = req.RsCalendarId
  1654. go roadshow.AddRsCalendarApiLog(itemApiLog)
  1655. //`status` int(11) DEFAULT '0' COMMENT '1:待接受,2:已接受,3:已拒绝,4:已删除,5:已撤回,6:已结束',
  1656. //待接受、已接受的情况,需要同步删除上海那边的日程
  1657. for _, rsCalendarResearcherItem := range rsCalendarResearcherItemList {
  1658. //删除上海的活动
  1659. if rsCalendarResearcherItem.Status == 1 || rsCalendarResearcherItem.Status == 2 {
  1660. go roadshowService.DeleteSHCalendar(rsCalendarResearcherItem.RsCalendarResearcherId)
  1661. }
  1662. //模板消息通知
  1663. {
  1664. if rsCalendarItem != nil && rsCalendarResearcherItem != nil {
  1665. go func(tmpRsCalendarItem roadshow.RsCalendar, tmpRsCalendarResearcherItem roadshow.RsCalendarResearcher) {
  1666. sysAdmin, _ := system.GetSysAdminById(tmpRsCalendarResearcherItem.ResearcherId)
  1667. var first string
  1668. var wxAppPath string
  1669. if tmpRsCalendarItem.ActivityType == "路演" || tmpRsCalendarItem.ActivityType == "公开会议" {
  1670. wxAppPath = "pages-approve/activity/detail?RsCalendarId=" + strconv.Itoa(tmpRsCalendarItem.RsCalendarId) + "&RsCalendarResearcherId=" + strconv.Itoa(tmpRsCalendarResearcherItem.RsCalendarResearcherId)
  1671. }
  1672. first = "【" + sysUser.RealName + "】删除了你的【" + tmpRsCalendarItem.ActivityType + "】安排"
  1673. keyword2 := "【" + sysUser.RealName + "】已删除(" + req.DeleteReason + ")"
  1674. var keyword1 string
  1675. if tmpRsCalendarItem.ActivityType == "路演" {
  1676. keyword1 = tmpRsCalendarItem.CompanyName + "," + tmpRsCalendarItem.RoadshowType + tmpRsCalendarItem.ActivityType
  1677. } else if tmpRsCalendarItem.ActivityType == "公开会议" {
  1678. keyword1 = tmpRsCalendarItem.Theme + "," + tmpRsCalendarItem.RoadshowType + tmpRsCalendarItem.ActivityType
  1679. } else {
  1680. startDate := tmpRsCalendarResearcherItem.StartDate[5:]
  1681. startDate = strings.Replace(startDate, "-", ".", -1)
  1682. keyword1 = "会议时间:" + startDate + "(" + tmpRsCalendarResearcherItem.StartWeek + ")" + " " + tmpRsCalendarResearcherItem.StartTime[:5] + "-" + tmpRsCalendarResearcherItem.EndTime[:5]
  1683. keyword2 = "【" + sysUser.RealName + "】已删除" + "【" + tmpRsCalendarItem.ActivityType + ")"
  1684. }
  1685. //keyword2 := "已删除"
  1686. remark := req.DeleteReason
  1687. if sysAdmin.OpenId != "" {
  1688. openIdObj := &system.OpenIdList{
  1689. OpenId: sysAdmin.OpenId,
  1690. AdminId: sysAdmin.AdminId,
  1691. }
  1692. openIdList := make([]*system.OpenIdList, 0)
  1693. openIdList = append(openIdList, openIdObj)
  1694. if len(openIdList) > 0 {
  1695. services.SendWxMsgWithRoadshowDeleteNotice(first, keyword1, keyword2, remark, wxAppPath, openIdList)
  1696. }
  1697. }
  1698. }(*rsCalendarItem, *rsCalendarResearcherItem)
  1699. }
  1700. }
  1701. }
  1702. br.Ret = 200
  1703. br.Success = true
  1704. br.Msg = "删除成功"
  1705. br.IsAddLog = true
  1706. }
  1707. // @Title 新增事项接口
  1708. // @Description 新增事项接口
  1709. // @Param request body roadshow.AddMattersReq true "type json string"
  1710. // @Success Ret=200 保存成功
  1711. // @router /matters/add [post]
  1712. func (this *CalendarController) MattersAdd() {
  1713. br := new(models.BaseResponse).Init()
  1714. defer func() {
  1715. this.Data["json"] = br
  1716. this.ServeJSON()
  1717. }()
  1718. sysUser := this.SysUser
  1719. if sysUser == nil {
  1720. br.Msg = "请登录"
  1721. br.ErrMsg = "请登录,SysUser Is Empty"
  1722. br.Ret = 408
  1723. return
  1724. }
  1725. deleteCache := true
  1726. cacheKey := "CACHE_RS_MATTERS_ADD_" + strconv.Itoa(sysUser.AdminId)
  1727. defer func() {
  1728. if deleteCache {
  1729. utils.Rc.Delete(cacheKey)
  1730. }
  1731. }()
  1732. if !utils.Rc.SetNX(cacheKey, 1, 30*time.Second) {
  1733. deleteCache = false
  1734. br.Msg = "系统处理中,请稍后重试!"
  1735. br.ErrMsg = "系统处理中,请稍后重试!" + sysUser.RealName + ";data:" + string(this.Ctx.Input.RequestBody)
  1736. return
  1737. }
  1738. var req roadshow.AddMattersReq
  1739. err := json.Unmarshal(this.Ctx.Input.RequestBody, &req)
  1740. if err != nil {
  1741. br.Msg = "参数解析异常!"
  1742. br.ErrMsg = "参数解析失败,Err:" + err.Error()
  1743. return
  1744. }
  1745. if req.StartDate == "" {
  1746. br.Msg = "请选择开始日期!"
  1747. return
  1748. }
  1749. if req.EndDate == "" {
  1750. br.Msg = "请选择结束日期!"
  1751. return
  1752. }
  1753. if req.StartTime == "" {
  1754. br.Msg = "请选择开始时间!"
  1755. return
  1756. }
  1757. if req.EndTime == "" {
  1758. br.Msg = "请选择结束时间!"
  1759. return
  1760. }
  1761. if req.StartWeek == "" {
  1762. br.Msg = "请选择周!"
  1763. return
  1764. }
  1765. if req.EndWeek == "" {
  1766. br.Msg = "请选择周!"
  1767. return
  1768. }
  1769. if req.MatterContent == "" {
  1770. br.Msg = "请选择研究员!"
  1771. return
  1772. }
  1773. // 是否为销售
  1774. sales := isSellerRole(sysUser.RoleTypeCode)
  1775. startDateTime := req.StartDate + " " + req.StartTime
  1776. endDateTime := req.EndDate + " " + req.EndTime
  1777. //校验事项时间冲突
  1778. {
  1779. matterCount, err := roadshowService.CheckMatters(startDateTime, endDateTime, sysUser.AdminId, 0)
  1780. if err != nil {
  1781. br.Msg = "时间冲突检测失败!"
  1782. br.ErrMsg = "时间冲突检测失败-CheckMattersCount!Err:" + err.Error()
  1783. return
  1784. }
  1785. if matterCount > 0 {
  1786. br.Msg = "当前时间已被占用!"
  1787. br.ErrMsg = "时间冲突检测失败-CheckMattersCount!"
  1788. br.IsSendEmail = false
  1789. return
  1790. }
  1791. }
  1792. if !sales {
  1793. //校验活动时间冲突--待接受
  1794. {
  1795. calendarCount, err := roadshowService.CheckCalendar(startDateTime, endDateTime, "1", sysUser.AdminId, 0)
  1796. if err != nil {
  1797. br.Msg = "时间冲突检测失败!"
  1798. br.ErrMsg = "时间冲突检测失败-CheckCalendarResearcherCount!Err:" + err.Error()
  1799. return
  1800. }
  1801. if calendarCount > 0 {
  1802. br.Msg = "当前时间与待处理的申请有冲突,请与相关销售沟通!"
  1803. br.ErrMsg = "时间冲突检测失败-CheckCalendarResearcherCount!"
  1804. br.IsSendEmail = false
  1805. return
  1806. }
  1807. }
  1808. //校验活动时间冲突--已接受
  1809. {
  1810. calendarCount, err := roadshowService.CheckCalendar(startDateTime, endDateTime, "2", sysUser.AdminId, 0)
  1811. if err != nil {
  1812. br.Msg = "时间冲突检测失败!"
  1813. br.ErrMsg = "时间冲突检测失败-CheckCalendarResearcherCount!Err:" + err.Error()
  1814. return
  1815. }
  1816. if calendarCount > 0 {
  1817. br.Msg = "当前时间已被占用!"
  1818. br.ErrMsg = "时间冲突检测失败-CheckCalendarResearcherCount!"
  1819. br.IsSendEmail = false
  1820. return
  1821. }
  1822. }
  1823. }
  1824. startP, _ := time.ParseInLocation(utils.FormatDateTime, startDateTime, time.Local)
  1825. endP, _ := time.ParseInLocation(utils.FormatDateTime, endDateTime, time.Local)
  1826. if startP.Before(time.Now()) || startP.Equal(time.Now()) {
  1827. br.Msg = "事项开始时间不能小于当前时间!"
  1828. return
  1829. }
  1830. if endP.Before(time.Now()) || endP.Equal(time.Now()) {
  1831. br.Msg = "事项结束时间不能小于当前时间!"
  1832. return
  1833. }
  1834. if startP.After(endP) || startP.Equal(endP) {
  1835. br.Msg = "事项开始时间应小于结束时间!"
  1836. return
  1837. }
  1838. item := new(roadshow.RsMatters)
  1839. item.SysUserId = sysUser.AdminId
  1840. item.SysUserRealName = sysUser.RealName
  1841. item.StartDate = req.StartDate
  1842. item.EndDate = req.EndDate
  1843. item.StartTime = req.StartTime
  1844. item.EndTime = req.EndTime
  1845. item.StartWeek = req.StartWeek
  1846. item.EndWeek = req.EndWeek
  1847. item.MatterContent = req.MatterContent
  1848. item.Status = 1
  1849. item.CreateTime = time.Now()
  1850. item.ModifyTime = time.Now()
  1851. if sales {
  1852. item.IsSeller = 1
  1853. }
  1854. id, err := roadshow.AddRsMatters(item)
  1855. if err != nil {
  1856. br.Msg = "保存失败!"
  1857. br.ErrMsg = "保存失败,AddRsMatters Err:" + err.Error()
  1858. return
  1859. }
  1860. item.RsMattersId = int(id)
  1861. // 销售的事项不同步上海
  1862. if !sales {
  1863. go roadshowService.MatterToSH(*item)
  1864. }
  1865. br.Ret = 200
  1866. br.Success = true
  1867. br.Msg = "保存成功"
  1868. br.IsAddLog = true
  1869. }
  1870. // @Title 修改事项接口
  1871. // @Description 修改事项接口
  1872. // @Param request body roadshow.UpdateMattersReq true "type json string"
  1873. // @Success Ret=200 保存成功
  1874. // @router /matters/update [post]
  1875. func (this *CalendarController) MattersUpdate() {
  1876. br := new(models.BaseResponse).Init()
  1877. defer func() {
  1878. this.Data["json"] = br
  1879. this.ServeJSON()
  1880. }()
  1881. sysUser := this.SysUser
  1882. if sysUser == nil {
  1883. br.Msg = "请登录"
  1884. br.ErrMsg = "请登录,SysUser Is Empty"
  1885. br.Ret = 408
  1886. return
  1887. }
  1888. deleteCache := true
  1889. cacheKey := "CACHE_RS_MATTERS_UPDATE_" + strconv.Itoa(sysUser.AdminId)
  1890. defer func() {
  1891. if deleteCache {
  1892. utils.Rc.Delete(cacheKey)
  1893. }
  1894. }()
  1895. if !utils.Rc.SetNX(cacheKey, 1, 30*time.Second) {
  1896. deleteCache = false
  1897. br.Msg = "系统处理中,请稍后重试!"
  1898. br.ErrMsg = "系统处理中,请稍后重试!" + sysUser.RealName + ";data:" + string(this.Ctx.Input.RequestBody)
  1899. return
  1900. }
  1901. var req roadshow.UpdateMattersReq
  1902. err := json.Unmarshal(this.Ctx.Input.RequestBody, &req)
  1903. if err != nil {
  1904. br.Msg = "参数解析异常!"
  1905. br.ErrMsg = "参数解析失败,Err:" + err.Error()
  1906. return
  1907. }
  1908. updateParams := make(map[string]interface{})
  1909. if req.RsMattersId <= 0 {
  1910. br.Msg = "参数错误!"
  1911. return
  1912. }
  1913. if req.StartDate == "" {
  1914. br.Msg = "请选择开始日期!"
  1915. return
  1916. } else {
  1917. updateParams["start_date"] = req.StartDate
  1918. }
  1919. if req.EndDate == "" {
  1920. br.Msg = "请选择结束日期!"
  1921. return
  1922. } else {
  1923. updateParams["end_date"] = req.EndDate
  1924. }
  1925. if req.StartTime == "" {
  1926. br.Msg = "请选择开始时间!"
  1927. return
  1928. } else {
  1929. updateParams["start_time"] = req.StartTime
  1930. }
  1931. if req.EndTime == "" {
  1932. br.Msg = "请选择结束时间!"
  1933. return
  1934. } else {
  1935. updateParams["end_time"] = req.EndTime
  1936. }
  1937. if req.StartWeek == "" {
  1938. br.Msg = "请选择周!"
  1939. return
  1940. } else {
  1941. updateParams["start_week"] = req.StartWeek
  1942. }
  1943. if req.EndWeek == "" {
  1944. br.Msg = "请选择周!"
  1945. return
  1946. } else {
  1947. updateParams["end_week"] = req.EndWeek
  1948. }
  1949. if req.MatterContent == "" {
  1950. br.Msg = "请选择研究员!"
  1951. return
  1952. } else {
  1953. updateParams["matter_content"] = req.MatterContent
  1954. }
  1955. req.EditReason = strings.TrimSpace(req.EditReason)
  1956. //if req.EditReason == "" {
  1957. // br.Msg = "请填写修改原因"
  1958. // return
  1959. //}
  1960. //updateParams["edit_reason"] = req.EditReason
  1961. startDateTime := req.StartDate + " " + req.StartTime
  1962. endDateTime := req.EndDate + " " + req.EndTime
  1963. startP, _ := time.ParseInLocation(utils.FormatDateTime, startDateTime, time.Local)
  1964. endP, _ := time.ParseInLocation(utils.FormatDateTime, endDateTime, time.Local)
  1965. if startP.Before(time.Now()) || startP.Equal(time.Now()) {
  1966. br.Msg = "事项开始时间不能小于当前时间!"
  1967. return
  1968. }
  1969. if endP.Before(time.Now()) || endP.Equal(time.Now()) {
  1970. br.Msg = "事项结束时间不能小于当前时间!"
  1971. return
  1972. }
  1973. if startP.After(endP) || startP.Equal(endP) {
  1974. br.Msg = "事项开始时间应小于结束时间!"
  1975. return
  1976. }
  1977. // 结束后14天不可再编辑
  1978. endP = endP.AddDate(0, 0, 14)
  1979. if endP.Before(time.Now().Local()) {
  1980. br.Msg = "事项结束14天后不可再编辑"
  1981. return
  1982. }
  1983. matterItem, err := roadshow.GetMattersById(req.RsMattersId)
  1984. if err != nil {
  1985. br.Msg = "保存失败!"
  1986. br.Msg = "保存失败,GetMattersById,Err:" + err.Error()
  1987. return
  1988. }
  1989. // 是否为销售
  1990. sales := isSellerRole(sysUser.RoleTypeCode)
  1991. //校验事项时间冲突
  1992. {
  1993. if matterItem != nil && (matterItem.StartDate != req.StartDate ||
  1994. matterItem.StartTime != req.StartTime ||
  1995. matterItem.EndDate != req.EndDate ||
  1996. matterItem.EndTime != req.EndTime) {
  1997. matterCount, err := roadshowService.CheckMatters(startDateTime, endDateTime, sysUser.AdminId, matterItem.RsMattersId)
  1998. if err != nil {
  1999. br.Msg = "时间冲突检测失败!"
  2000. br.ErrMsg = "时间冲突检测失败-CheckMattersCount!Err:" + err.Error()
  2001. return
  2002. }
  2003. if matterCount > 0 {
  2004. br.Msg = "时间冲突,已存在时间段内的事项!"
  2005. br.ErrMsg = "时间冲突检测失败-CheckMattersCount!"
  2006. br.IsSendEmail = false
  2007. return
  2008. }
  2009. }
  2010. }
  2011. if !sales {
  2012. //校验活动时间冲突--待接受
  2013. {
  2014. calendarCount, err := roadshowService.CheckCalendar(startDateTime, endDateTime, "1", sysUser.AdminId, 0)
  2015. if err != nil {
  2016. br.Msg = "时间冲突检测失败!"
  2017. br.ErrMsg = "时间冲突检测失败-CheckCalendarResearcherCount!Err:" + err.Error()
  2018. return
  2019. }
  2020. if calendarCount > 0 {
  2021. br.Msg = "当前时间与待处理的申请有冲突,请与相关销售沟通!"
  2022. br.ErrMsg = "时间冲突检测失败-CheckCalendarResearcherCount!"
  2023. br.IsSendEmail = false
  2024. return
  2025. }
  2026. }
  2027. //校验活动时间冲突--待接受
  2028. {
  2029. calendarCount, err := roadshowService.CheckCalendar(startDateTime, endDateTime, "2", sysUser.AdminId, 0)
  2030. if err != nil {
  2031. br.Msg = "时间冲突检测失败!"
  2032. br.ErrMsg = "时间冲突检测失败-CheckCalendarResearcherCount!Err:" + err.Error()
  2033. return
  2034. }
  2035. if calendarCount > 0 {
  2036. br.Msg = "时间冲突,已存在时间段内的活动!"
  2037. br.ErrMsg = "时间冲突检测失败-CheckCalendarResearcherCount!"
  2038. br.IsSendEmail = false
  2039. return
  2040. }
  2041. }
  2042. }
  2043. whereParams := make(map[string]interface{})
  2044. whereParams["rs_matters_id"] = req.RsMattersId
  2045. updateParams["modify_time"] = time.Now()
  2046. err = roadshow.UpdateRsMatters(whereParams, updateParams)
  2047. if err != nil {
  2048. br.Msg = "保存失败!"
  2049. br.ErrMsg = "保存失败!UpdateRsMatters:" + err.Error()
  2050. return
  2051. }
  2052. // 销售不做上海那边的处理
  2053. if !sales {
  2054. go roadshowService.UpdateSHCalendarByMatter(req)
  2055. }
  2056. br.Ret = 200
  2057. br.Success = true
  2058. br.Msg = "保存成功"
  2059. br.IsAddLog = true
  2060. }
  2061. // @Title 删除事项接口
  2062. // @Description 删除事项接口
  2063. // @Param request body roadshow.DeleteMattersReq true "type json string"
  2064. // @Success Ret=200 保存成功
  2065. // @router /matters/delete [post]
  2066. func (this *CalendarController) MattersDelete() {
  2067. br := new(models.BaseResponse).Init()
  2068. defer func() {
  2069. this.Data["json"] = br
  2070. this.ServeJSON()
  2071. }()
  2072. sysUser := this.SysUser
  2073. if sysUser == nil {
  2074. br.Msg = "请登录"
  2075. br.ErrMsg = "请登录,SysUser Is Empty"
  2076. br.Ret = 408
  2077. return
  2078. }
  2079. var req roadshow.DeleteMattersReq
  2080. err := json.Unmarshal(this.Ctx.Input.RequestBody, &req)
  2081. if err != nil {
  2082. br.Msg = "参数解析异常!"
  2083. br.ErrMsg = "参数解析失败,Err:" + err.Error()
  2084. return
  2085. }
  2086. if req.RsMattersId <= 0 {
  2087. br.Msg = "参数错误!"
  2088. return
  2089. }
  2090. matters, e := roadshow.GetMattersById(req.RsMattersId)
  2091. if e != nil {
  2092. if e.Error() == utils.ErrNoRow() {
  2093. br.Msg = "事项已被删除, 请刷新页面"
  2094. return
  2095. }
  2096. br.Msg = "操作失败"
  2097. br.ErrMsg = "获取事项失败, Err: " + e.Error()
  2098. return
  2099. }
  2100. // 事项结束14天后不可再删除
  2101. t := fmt.Sprintf("%s %s", matters.EndDate, matters.EndTime)
  2102. ed, _ := time.ParseInLocation(utils.FormatDateTime, t, time.Local)
  2103. ed = ed.AddDate(0, 0, 14)
  2104. if ed.Before(time.Now().Local()) {
  2105. br.Msg = "事项结束14天后不可再删除"
  2106. return
  2107. }
  2108. err = roadshow.DeleteRsMatters(req.RsMattersId)
  2109. if err != nil {
  2110. br.Msg = "保存失败!"
  2111. br.ErrMsg = "保存失败!DeleteRsMatters:" + err.Error()
  2112. return
  2113. }
  2114. // 是否为销售
  2115. sales := isSellerRole(sysUser.RoleTypeCode)
  2116. // 删除上海的路演活动, 销售不同步
  2117. if !sales {
  2118. go roadshowService.DeleteSHMatter(req.RsMattersId)
  2119. }
  2120. br.Ret = 200
  2121. br.Success = true
  2122. br.Msg = "删除成功"
  2123. br.IsAddLog = true
  2124. }
  2125. // @Title 路演-研究员日历详情
  2126. // @Description 路演-研究员日历详情接口
  2127. // @Param StartDate query string true "开始日期"
  2128. // @Param EndDate query string true "结束日期日期"
  2129. // @Param ResearcherId query int true "研究员id"
  2130. // @Success 200 {object} roadshow.CalendarDetailResp
  2131. // @router /researcher/calendar/detail [get]
  2132. func (this *CalendarController) ResearcherCalendarDetail() {
  2133. br := new(models.BaseResponse).Init()
  2134. defer func() {
  2135. this.Data["json"] = br
  2136. this.ServeJSON()
  2137. }()
  2138. sysUser := this.SysUser
  2139. if sysUser == nil {
  2140. br.Msg = "请登录"
  2141. br.ErrMsg = "请登录,SysUser Is Empty"
  2142. br.Ret = 408
  2143. return
  2144. }
  2145. startDate := this.GetString("StartDate")
  2146. endDate := this.GetString("EndDate")
  2147. researcherId, _ := this.GetInt("ResearcherId")
  2148. if startDate == "" || endDate == "" {
  2149. br.Msg = "参数错误"
  2150. return
  2151. }
  2152. var condition string
  2153. var pars []interface{}
  2154. if researcherId <= 0 {
  2155. calendarList := make([]*roadshow.CalendarListView, 0)
  2156. matterList := make([]*roadshow.RsMatters, 0)
  2157. resp := new(roadshow.CalendarDetailResp)
  2158. resp.CalendarList = calendarList
  2159. resp.RsMattersList = matterList
  2160. br.Ret = 200
  2161. br.Success = true
  2162. br.Msg = "获取成功"
  2163. br.Data = resp
  2164. return
  2165. } else {
  2166. condition += ` AND b.researcher_id =? `
  2167. pars = append(pars, researcherId)
  2168. }
  2169. //同步上海数据
  2170. researcherInfo, err := system.GetSysAdminById(researcherId)
  2171. if err != nil {
  2172. br.Msg = "研究员异常"
  2173. return
  2174. }
  2175. //go roadshowService.SyncCalendarFromShanghai(researcherInfo.Mobile, startDate, endDate)
  2176. go roadshowService.InsertSyncCalendarFromShanghaiLPush(researcherInfo.Mobile, startDate, endDate)
  2177. //condition += ` AND b.start_date>=?`
  2178. //pars = append(pars, startDate)
  2179. //condition += ` AND b.end_date<=?`
  2180. //pars = append(pars, endDate)
  2181. //解决研究员休假,产生跨周的数据查询不到的bug,
  2182. condition += ` AND ( b.start_date >= ? AND b.end_date <= ?
  2183. OR ( b.start_date >= ? AND b.start_date <= ? )
  2184. OR ( b.start_date <= ? AND b.end_date >= ? )
  2185. OR ( b.end_date >= ? AND b.end_date <= ? ) ) `
  2186. pars = append(pars, startDate, endDate, startDate, endDate, startDate, endDate, startDate, endDate)
  2187. condition += ` AND b.status IN(2) `
  2188. //pars = append(pars, 2)
  2189. calendarList, err := roadshow.GetCalendarDetailList(condition, pars)
  2190. if err != nil {
  2191. br.Msg = "获取数据失败"
  2192. br.ErrMsg = "获取数据失败,GetCalendarDetailList Err:" + err.Error()
  2193. return
  2194. }
  2195. matterList, err := roadshow.GetRsMattersList(startDate, endDate, researcherId)
  2196. if err != nil {
  2197. br.Msg = "获取数据失败"
  2198. br.ErrMsg = "获取数据失败,GetRsMattersList Err:" + err.Error()
  2199. return
  2200. }
  2201. if calendarList == nil {
  2202. calendarList = make([]*roadshow.CalendarListView, 0)
  2203. } else {
  2204. var sysUserIds []int //建会人ID
  2205. var companyIds []int //公司ID
  2206. for _, v := range calendarList { //上海同步过来信息展示逻辑替换 需求池 953
  2207. if v.Source == 1 && v.CompanyName == "" {
  2208. v.CompanyName = v.Title
  2209. }
  2210. if v.SysUserId > 0 {
  2211. sysUserIds = append(sysUserIds, v.SysUserId)
  2212. }
  2213. if v.CompanyId > 1 {
  2214. companyIds = append(companyIds, v.CompanyId)
  2215. }
  2216. }
  2217. //如果是权益销售建的会,客户状态替换成权益那边的
  2218. mapSellRai := make(map[int]bool) // 是否是权益销售
  2219. mapStatus := make(map[int]string) //权益客户对应的状态
  2220. if len(sysUserIds) > 0 && len(companyIds) > 0 {
  2221. //判断哪些人是权益销售
  2222. adminList, err := system.GetAdminListByIdListWithoutEnable(sysUserIds)
  2223. if err != nil {
  2224. br.Msg = "获取数据失败"
  2225. br.ErrMsg = "获取数据失败,GetAdminListByIdListWithoutEnable Err:" + err.Error()
  2226. return
  2227. }
  2228. for _, v := range adminList {
  2229. if v.RoleTypeCode == utils.ROLE_TYPE_CODE_RAI_SELLER || v.RoleTypeCode == utils.ROLE_TYPE_CODE_RAI_GROUP {
  2230. mapSellRai[v.AdminId] = true
  2231. }
  2232. }
  2233. conditionProduct := ` AND company_id IN (` + utils.GetOrmInReplace(len(companyIds)) + `) AND product_id = 2 `
  2234. parsProduct := make([]interface{}, 0)
  2235. parsProduct = append(parsProduct, companyIds)
  2236. productList, err := company.GetCompanyProductList(conditionProduct, parsProduct)
  2237. if err != nil {
  2238. br.Msg = "获取数据失败"
  2239. br.ErrMsg = "获取数据失败,GetCompanyProductList Err:" + err.Error()
  2240. return
  2241. }
  2242. for _, v := range productList {
  2243. mapStatus[v.CompanyId] = v.Status
  2244. }
  2245. }
  2246. for _, v := range calendarList {
  2247. if mapSellRai[v.SysUserId] && mapStatus[v.CompanyId] != "" {
  2248. v.CompanyStatus = mapStatus[v.CompanyId]
  2249. }
  2250. }
  2251. }
  2252. if matterList == nil {
  2253. matterList = make([]*roadshow.RsMatters, 0)
  2254. }
  2255. resp := new(roadshow.CalendarDetailResp)
  2256. resp.CalendarList = calendarList
  2257. resp.RsMattersList = matterList
  2258. br.Ret = 200
  2259. br.Success = true
  2260. br.Msg = "获取成功"
  2261. br.Data = resp
  2262. }
  2263. // @Title 路演-我的日历详情
  2264. // @Description 路演-我的日历详情接口
  2265. // @Param StartDate query string true "开始日期"
  2266. // @Param EndDate query string true "结束日期日期"
  2267. // @Success 200 {object} roadshow.CalendarDetailResp
  2268. // @router /my/calendar/detail [get]
  2269. func (this *CalendarController) MyCalendarDetail() {
  2270. br := new(models.BaseResponse).Init()
  2271. defer func() {
  2272. this.Data["json"] = br
  2273. this.ServeJSON()
  2274. }()
  2275. sysUser := this.SysUser
  2276. if sysUser == nil {
  2277. br.Msg = "请登录"
  2278. br.ErrMsg = "请登录,SysUser Is Empty"
  2279. br.Ret = 408
  2280. return
  2281. }
  2282. startDate := this.GetString("StartDate")
  2283. endDate := this.GetString("EndDate")
  2284. if startDate == "" || endDate == "" {
  2285. br.Msg = "参数错误"
  2286. return
  2287. }
  2288. var condition string
  2289. var pars []interface{}
  2290. roleTypeCode := sysUser.RoleTypeCode
  2291. fmt.Println("roleTypeCode:", roleTypeCode)
  2292. //权益销售
  2293. if roleTypeCode == utils.ROLE_TYPE_CODE_RAI_SELLER ||
  2294. roleTypeCode == utils.ROLE_TYPE_CODE_RAI_GROUP {
  2295. //if calendarType == 2 {
  2296. condition += ` AND ( a.sys_user_id=? OR a.seller_id=? OR a.share_seller_id=? ) `
  2297. pars = append(pars, sysUser.AdminId, sysUser.AdminId, sysUser.AdminId)
  2298. //}
  2299. } else {
  2300. //销售
  2301. sales := isSellerRole(sysUser.RoleTypeCode)
  2302. if sales || roleTypeCode == utils.ROLE_TYPE_CODE_RAI_ADMIN { // 王芳也作为销售身份处理
  2303. condition += ` AND a.sys_user_id=?`
  2304. pars = append(pars, sysUser.AdminId)
  2305. condition += ` AND a.activity_type IN('路演','公开会议','沙龙') `
  2306. }
  2307. }
  2308. //研究员
  2309. if roleTypeCode == utils.ROLE_TYPE_CODE_FICC_RESEARCHR ||
  2310. roleTypeCode == utils.ROLE_TYPE_CODE_RESEARCHR ||
  2311. roleTypeCode == utils.ROLE_TYPE_CODE_RAI_RESEARCHR ||
  2312. roleTypeCode == utils.ROLE_TYPE_CODE_FICC_ADMIN {
  2313. condition += ` AND b.researcher_id=?`
  2314. pars = append(pars, sysUser.AdminId)
  2315. //同步上海数据(研究员才需要同步上海的数据)
  2316. researcherInfo, err := system.GetSysAdminById(sysUser.AdminId)
  2317. if err != nil {
  2318. br.Msg = "研究员异常"
  2319. return
  2320. }
  2321. //go roadshowService.SyncCalendarFromShanghai(researcherInfo.Mobile, startDate, endDate)
  2322. go roadshowService.InsertSyncCalendarFromShanghaiLPush(researcherInfo.Mobile, startDate, endDate)
  2323. }
  2324. //中级/普通/admin 管理员
  2325. if roleTypeCode == utils.ROLE_TYPE_CODE_ADMIN {
  2326. condition += ` AND a.sys_user_id=?`
  2327. pars = append(pars, sysUser.AdminId)
  2328. }
  2329. //condition += ` AND b.start_date>=?`
  2330. //pars = append(pars, startDate)
  2331. //condition += ` AND b.end_date<=?`
  2332. //pars = append(pars, endDate)
  2333. //解决研究员休假,产生跨周的数据查询不到的bug,
  2334. condition += ` AND ( b.start_date >= ? AND b.end_date <= ?
  2335. OR ( b.start_date >= ? AND b.start_date <= ? )
  2336. OR ( b.start_date <= ? AND b.end_date >= ? )
  2337. OR ( b.end_date >= ? AND b.end_date <= ? ) ) `
  2338. pars = append(pars, startDate, endDate, startDate, endDate, startDate, endDate, startDate, endDate)
  2339. condition += ` AND b.status IN(2) `
  2340. //pars = append(pars, 2)
  2341. fmt.Println("condition:" + condition)
  2342. calendarList, err := roadshow.GetCalendarDetailList(condition, pars)
  2343. if err != nil {
  2344. br.Msg = "获取数据失败"
  2345. br.ErrMsg = "获取数据失败,GetCalendarDetailList Err:" + err.Error()
  2346. return
  2347. }
  2348. if calendarList == nil {
  2349. calendarList = make([]*roadshow.CalendarListView, 0)
  2350. } else {
  2351. var sysUserIds []int //建会人ID
  2352. var companyIds []int //公司ID
  2353. for _, v := range calendarList { //上海同步过来信息展示逻辑替换 需求池 953
  2354. if v.Source == 1 && v.CompanyName == "" {
  2355. v.CompanyName = v.Title
  2356. }
  2357. if v.SysUserId > 0 {
  2358. sysUserIds = append(sysUserIds, v.SysUserId)
  2359. }
  2360. if v.CompanyId > 1 {
  2361. companyIds = append(companyIds, v.CompanyId)
  2362. }
  2363. }
  2364. //如果是权益销售建的会,客户状态替换成权益那边的
  2365. mapSellRai := make(map[int]bool) // 是否是权益销售
  2366. mapStatus := make(map[int]string) //权益客户对应的状态
  2367. if len(sysUserIds) > 0 && len(companyIds) > 0 {
  2368. //判断哪些人是权益销售
  2369. adminList, err := system.GetAdminListByIdListWithoutEnable(sysUserIds)
  2370. if err != nil {
  2371. br.Msg = "获取数据失败"
  2372. br.ErrMsg = "获取数据失败,GetAdminListByIdListWithoutEnable Err:" + err.Error()
  2373. return
  2374. }
  2375. for _, v := range adminList {
  2376. if v.RoleTypeCode == utils.ROLE_TYPE_CODE_RAI_SELLER || v.RoleTypeCode == utils.ROLE_TYPE_CODE_RAI_GROUP {
  2377. mapSellRai[v.AdminId] = true
  2378. }
  2379. }
  2380. conditionProduct := ` AND company_id IN (` + utils.GetOrmInReplace(len(companyIds)) + `) AND product_id = 2 `
  2381. parsProduct := make([]interface{}, 0)
  2382. parsProduct = append(parsProduct, companyIds)
  2383. productList, err := company.GetCompanyProductList(conditionProduct, parsProduct)
  2384. if err != nil {
  2385. br.Msg = "获取数据失败"
  2386. br.ErrMsg = "获取数据失败,GetCompanyProductList Err:" + err.Error()
  2387. return
  2388. }
  2389. for _, v := range productList {
  2390. mapStatus[v.CompanyId] = v.Status
  2391. }
  2392. }
  2393. for _, v := range calendarList {
  2394. if mapSellRai[v.SysUserId] && mapStatus[v.CompanyId] != "" {
  2395. v.CompanyStatus = mapStatus[v.CompanyId]
  2396. }
  2397. }
  2398. }
  2399. matterList, err := roadshow.GetRsMattersList(startDate, endDate, sysUser.AdminId)
  2400. if err != nil {
  2401. br.Msg = "获取数据失败"
  2402. br.ErrMsg = "获取数据失败,GetRsMattersList Err:" + err.Error()
  2403. return
  2404. }
  2405. resp := new(roadshow.CalendarDetailResp)
  2406. resp.CalendarList = calendarList
  2407. resp.RsMattersList = matterList
  2408. br.Ret = 200
  2409. br.Success = true
  2410. br.Msg = "获取成功"
  2411. br.Data = resp
  2412. }
  2413. // @Title 事项列表
  2414. // @Description 事项列表接口
  2415. // @Param PageSize query int true "每页数据条数"
  2416. // @Param CurrentIndex query int true "当前页页码,从1开始"
  2417. // @Success 200 {object} roadshow.MattersListResp
  2418. // @router /matters/list [get]
  2419. func (this *CalendarController) MattersList() {
  2420. br := new(models.BaseResponse).Init()
  2421. defer func() {
  2422. this.Data["json"] = br
  2423. this.ServeJSON()
  2424. }()
  2425. sysUser := this.SysUser
  2426. if sysUser == nil {
  2427. br.Msg = "请登录"
  2428. br.ErrMsg = "请登录,SysUser Is Empty"
  2429. br.Ret = 408
  2430. return
  2431. }
  2432. pageSize, _ := this.GetInt("PageSize")
  2433. currentIndex, _ := this.GetInt("CurrentIndex")
  2434. var total int
  2435. page := paging.GetPaging(currentIndex, pageSize, total)
  2436. var startSize int
  2437. if pageSize <= 0 {
  2438. pageSize = utils.PageSize10
  2439. }
  2440. if currentIndex <= 0 {
  2441. currentIndex = 1
  2442. }
  2443. startSize = paging.StartIndex(currentIndex, pageSize)
  2444. var condition string
  2445. var pars []interface{}
  2446. condition += ` AND a.sys_user_id=?`
  2447. pars = append(pars, sysUser.AdminId)
  2448. resp := new(roadshow.MattersListResp)
  2449. total, err := roadshow.GetMattersListCount(condition, pars)
  2450. if err != nil && err.Error() != utils.ErrNoRow() {
  2451. br.Msg = "获取事项信息失败"
  2452. br.ErrMsg = "获取事项信息失败,GetMattersListCount,Err:" + err.Error()
  2453. return
  2454. }
  2455. page = paging.GetPaging(currentIndex, pageSize, total)
  2456. dataList, err := roadshow.GetMattersList(condition, pars, startSize, pageSize)
  2457. if err != nil {
  2458. br.Msg = "获取事项信息失败"
  2459. br.ErrMsg = "获取事项信息失败,GetMattersList,Err:" + err.Error()
  2460. return
  2461. }
  2462. // 按钮权限,超过14天无按钮
  2463. now := time.Now().Local()
  2464. for _, v := range dataList {
  2465. // 结束日期14天后无编辑删除按钮权限
  2466. t := fmt.Sprintf("%s %s", v.EndDate, v.EndTime)
  2467. ed, e := time.ParseInLocation(utils.FormatDateTime, t, time.Local)
  2468. if e != nil {
  2469. br.Msg = "事项结束日期有误"
  2470. br.ErrMsg = "事项结束日期有误, Err: " + e.Error()
  2471. return
  2472. }
  2473. ed = ed.AddDate(0, 0, 14)
  2474. if ed.Before(now) {
  2475. v.ButtonAuth.EditDisabled = true
  2476. v.ButtonAuth.RemoveDisabled = true
  2477. }
  2478. }
  2479. resp.Paging = page
  2480. resp.List = dataList
  2481. br.Ret = 200
  2482. br.Success = true
  2483. br.Msg = "获取成功"
  2484. br.Data = resp
  2485. }
  2486. func getTitle(activityType, roadshowType, activityCategory, roadshowPlatform, province, city string) string {
  2487. var title string
  2488. switch activityType {
  2489. case "内部会议":
  2490. title = "内部会议"
  2491. case "公开会议", "路演", "沙龙":
  2492. if roadshowType == "线上" {
  2493. title = roadshowType + activityType + roadshowPlatform
  2494. } else {
  2495. title = roadshowType + activityType + province + city
  2496. }
  2497. case "报告电话会":
  2498. title = activityCategory + "电话会"
  2499. }
  2500. return title
  2501. }
  2502. // @Title 路演-公开会议总览
  2503. // @Description 路演-公开会议总览接口
  2504. // @Param StartDate query string true "开始日期"
  2505. // @Param EndDate query string true "结束日期日期"
  2506. // @Success 200 {object} roadshow.PublicMeetingDetailResp
  2507. // @router /public_meeting/detail [get]
  2508. func (this *CalendarController) PublicMeetingDetail() {
  2509. br := new(models.BaseResponse).Init()
  2510. defer func() {
  2511. this.Data["json"] = br
  2512. this.ServeJSON()
  2513. }()
  2514. sysUser := this.SysUser
  2515. if sysUser == nil {
  2516. br.Msg = "请登录"
  2517. br.ErrMsg = "请登录,SysUser Is Empty"
  2518. br.Ret = 408
  2519. return
  2520. }
  2521. startDate := this.GetString("StartDate")
  2522. endDate := this.GetString("EndDate")
  2523. if startDate == "" || endDate == "" {
  2524. br.Msg = "参数错误"
  2525. return
  2526. }
  2527. var condition string
  2528. var pars []interface{}
  2529. roleTypeCode := sysUser.RoleTypeCode
  2530. fmt.Println("roleTypeCode:", roleTypeCode)
  2531. condition += ` AND a.activity_type = '公开会议' `
  2532. condition += ` AND b.start_date>=?`
  2533. pars = append(pars, startDate)
  2534. condition += ` AND b.end_date<=?`
  2535. pars = append(pars, endDate)
  2536. condition += ` AND b.status IN(2) `
  2537. //pars = append(pars, 2)
  2538. fmt.Println("condition:" + condition)
  2539. //calendarList, err := roadshow.GetCalendarDetailList(condition, pars)
  2540. calendarList, err := roadshow.GetPublicCalendarDetailList(condition, pars)
  2541. if err != nil {
  2542. br.Msg = "获取数据失败"
  2543. br.ErrMsg = "获取数据失败,GetCalendarDetailList Err:" + err.Error()
  2544. return
  2545. }
  2546. groupMap := make(map[string][]*roadshow.CalendarListView)
  2547. var groupArr []string
  2548. for _, v := range calendarList {
  2549. if findGroup, ok := groupMap[v.UnionCode]; !ok {
  2550. newGroup := make([]*roadshow.CalendarListView, 0)
  2551. newGroup = append(newGroup, v)
  2552. groupMap[v.UnionCode] = newGroup
  2553. groupArr = append(groupArr, v.UnionCode)
  2554. } else {
  2555. findGroup = append(findGroup, v)
  2556. groupMap[v.UnionCode] = findGroup
  2557. }
  2558. }
  2559. resp := new(roadshow.PublicMeetingDetailResp)
  2560. for _, v := range groupArr {
  2561. newGroup := new(roadshow.PublicMeetingGroup)
  2562. newGroup.UnionCode = v
  2563. calendarList := groupMap[v]
  2564. var minTimeStr, maxTimeStr string
  2565. var minTime, maxTime time.Time
  2566. for _, cv := range calendarList {
  2567. startTimeStr := cv.StartDate + " " + cv.StartTime
  2568. endTimeStr := cv.EndDate + " " + cv.EndTime
  2569. startTime, _ := time.ParseInLocation(utils.FormatDateTime, startTimeStr, time.Local)
  2570. endTime, _ := time.ParseInLocation(utils.FormatDateTime, endTimeStr, time.Local)
  2571. if minTime.IsZero() {
  2572. minTime = startTime
  2573. } else {
  2574. if startTime.Before(minTime) {
  2575. minTime = startTime
  2576. }
  2577. }
  2578. if maxTime.IsZero() {
  2579. maxTime = endTime
  2580. } else {
  2581. if endTime.After(maxTime) {
  2582. maxTime = endTime
  2583. }
  2584. }
  2585. }
  2586. minTimeStr = minTime.Format(utils.FormatDateTime)
  2587. maxTimeStr = maxTime.Format(utils.FormatDateTime)
  2588. newGroup.MinTime = minTimeStr
  2589. newGroup.MaxTime = maxTimeStr
  2590. newGroup.CalendarList = calendarList
  2591. resp.Group = append(resp.Group, newGroup)
  2592. }
  2593. br.Ret = 200
  2594. br.Success = true
  2595. br.Msg = "获取成功"
  2596. br.Data = resp
  2597. }
  2598. //func init() {
  2599. // fmt.Println("start")
  2600. // mobile := `13818594925`
  2601. // roadshowService.SyncCalendarFromShanghai(mobile, "", "2023-03-09")
  2602. // //err := roadshowService.SetPublicMeetingUnionCode()
  2603. // //if err != nil {
  2604. // // fmt.Println("SetPublicMeetingUnionCode Err:" + err.Error())
  2605. // //}
  2606. // fmt.Println("end")
  2607. //}
  2608. // SellerCalendarDetail
  2609. // @Title 路演-销售日历详情
  2610. // @Description 路演-销售日历详情
  2611. // @Param StartDate query string true "开始日期"
  2612. // @Param EndDate query string true "结束日期日期"
  2613. // @Param SellerId query int true "销售ID"
  2614. // @Success 200 {object} roadshow.CalendarDetailResp
  2615. // @router /seller/calendar/detail [get]
  2616. func (this *CalendarController) SellerCalendarDetail() {
  2617. br := new(models.BaseResponse).Init()
  2618. defer func() {
  2619. if br.ErrMsg == "" {
  2620. br.IsSendEmail = false
  2621. }
  2622. this.Data["json"] = br
  2623. this.ServeJSON()
  2624. }()
  2625. sysUser := this.SysUser
  2626. if sysUser == nil {
  2627. br.Msg = "请登录"
  2628. br.ErrMsg = "请登录,SysUser Is Empty"
  2629. br.Ret = 408
  2630. return
  2631. }
  2632. startDate := this.GetString("StartDate")
  2633. endDate := this.GetString("EndDate")
  2634. sellerId, _ := this.GetInt("SellerId")
  2635. if startDate == "" || endDate == "" {
  2636. br.Msg = "参数错误"
  2637. return
  2638. }
  2639. if sellerId <= 0 {
  2640. calendarList := make([]*roadshow.CalendarListView, 0)
  2641. matterList := make([]*roadshow.RsMatters, 0)
  2642. resp := new(roadshow.CalendarDetailResp)
  2643. resp.CalendarList = calendarList
  2644. resp.RsMattersList = matterList
  2645. br.Ret = 200
  2646. br.Success = true
  2647. br.Msg = "获取成功"
  2648. br.Data = resp
  2649. return
  2650. }
  2651. // 路演
  2652. condition := ` AND a.sys_user_id = ? AND b.start_date >= ? AND b.end_date <= ? AND b.status = 2`
  2653. pars := make([]interface{}, 0)
  2654. pars = append(pars, sellerId, startDate, endDate)
  2655. calendarList, err := roadshow.GetCalendarDetailList(condition, pars)
  2656. if err != nil {
  2657. br.Msg = "获取数据失败"
  2658. br.ErrMsg = "获取数据失败,GetCalendarDetailList Err:" + err.Error()
  2659. return
  2660. }
  2661. if calendarList == nil {
  2662. calendarList = make([]*roadshow.CalendarListView, 0)
  2663. }
  2664. // 事项
  2665. matterList, err := roadshow.GetRsMattersList(startDate, endDate, sellerId)
  2666. if err != nil {
  2667. br.Msg = "获取数据失败"
  2668. br.ErrMsg = "获取数据失败,GetRsMattersList Err:" + err.Error()
  2669. return
  2670. }
  2671. if matterList == nil {
  2672. matterList = make([]*roadshow.RsMatters, 0)
  2673. }
  2674. resp := new(roadshow.CalendarDetailResp)
  2675. resp.CalendarList = calendarList
  2676. resp.RsMattersList = matterList
  2677. br.Ret = 200
  2678. br.Success = true
  2679. br.Msg = "获取成功"
  2680. br.Data = resp
  2681. }
  2682. // isSellerRole 是否为销售角色
  2683. func isSellerRole(roleType string) (ok bool) {
  2684. sellerArr := []string{
  2685. utils.ROLE_TYPE_CODE_FICC_SELLER, utils.ROLE_TYPE_CODE_FICC_GROUP, utils.ROLE_TYPE_CODE_FICC_TEAM,
  2686. utils.ROLE_TYPE_CODE_RAI_SELLER, utils.ROLE_TYPE_CODE_RAI_GROUP,
  2687. }
  2688. if utils.InArrayByStr(sellerArr, roleType) {
  2689. ok = true
  2690. }
  2691. return
  2692. }
  2693. //func init() {
  2694. // init16_2()
  2695. //}
  2696. //func init16_2() {
  2697. // listDate, err := roadshow.GetRsCalendarResearcherListInit16_2()
  2698. // if err != nil {
  2699. // fmt.Println(err)
  2700. // return
  2701. // }
  2702. //
  2703. // sysUserList, err := system.GetAdminList()
  2704. // if err != nil {
  2705. // fmt.Println(err)
  2706. // return
  2707. // }
  2708. // adminMap := make(map[int]*system.Admin, 0)
  2709. // for _, v := range sysUserList {
  2710. // adminMap[v.AdminId] = v
  2711. // }
  2712. //
  2713. // for k, v := range listDate {
  2714. // fmt.Println(k, "__", v.CompanyId)
  2715. // //如果是权益客户,添加销售跟共享销售的信息
  2716. // var productItemRai *company.CompanyProduct
  2717. //
  2718. // productItemRai, err = company.GetCompanyProductByCompanyIdAndProductId(v.CompanyId, utils.COMPANY_PRODUCT_RAI_ID)
  2719. // if err != nil && err.Error() != utils.ErrNoRow() {
  2720. // fmt.Println(err)
  2721. // return
  2722. // }
  2723. //
  2724. // var RoleTypeCode string
  2725. // if adminMap[v.SysUserId] != nil {
  2726. // RoleTypeCode = adminMap[v.SysUserId].RoleTypeCode
  2727. // }
  2728. //
  2729. // if productItemRai != nil && (RoleTypeCode == utils.ROLE_TYPE_CODE_RAI_GROUP || RoleTypeCode == utils.ROLE_TYPE_CODE_RAI_SELLER || RoleTypeCode == utils.ROLE_TYPE_CODE_RAI_ADMIN) {
  2730. // err = roadshow.UpdateRsCalendarSeller(productItemRai.SellerId, productItemRai.ShareSellerId, v.RsCalendarId)
  2731. // if err != nil && err.Error() != utils.ErrNoRow() {
  2732. // fmt.Println(err)
  2733. // return
  2734. // }
  2735. // }
  2736. // }
  2737. //
  2738. //}