calendar.go 94 KB

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