activity.go 99 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032203320342035203620372038203920402041204220432044204520462047204820492050205120522053205420552056205720582059206020612062206320642065206620672068206920702071207220732074207520762077207820792080208120822083208420852086208720882089209020912092209320942095209620972098209921002101210221032104210521062107210821092110211121122113211421152116211721182119212021212122212321242125212621272128212921302131213221332134213521362137213821392140214121422143214421452146214721482149215021512152215321542155215621572158215921602161216221632164216521662167216821692170217121722173217421752176217721782179218021812182218321842185218621872188218921902191219221932194219521962197219821992200220122022203220422052206220722082209221022112212221322142215221622172218221922202221222222232224222522262227222822292230223122322233223422352236223722382239224022412242224322442245224622472248224922502251225222532254225522562257225822592260226122622263226422652266226722682269227022712272227322742275227622772278227922802281228222832284228522862287228822892290229122922293229422952296229722982299230023012302230323042305230623072308230923102311231223132314231523162317231823192320232123222323232423252326232723282329233023312332233323342335233623372338233923402341234223432344234523462347234823492350235123522353235423552356235723582359236023612362236323642365236623672368236923702371237223732374237523762377237823792380238123822383238423852386238723882389239023912392239323942395239623972398239924002401240224032404240524062407240824092410241124122413241424152416241724182419242024212422242324242425242624272428242924302431243224332434243524362437243824392440244124422443244424452446244724482449245024512452245324542455245624572458245924602461246224632464246524662467246824692470247124722473247424752476247724782479248024812482248324842485248624872488248924902491249224932494249524962497249824992500250125022503250425052506250725082509251025112512251325142515251625172518251925202521252225232524252525262527252825292530253125322533253425352536253725382539254025412542254325442545254625472548254925502551255225532554255525562557255825592560256125622563256425652566256725682569257025712572257325742575257625772578257925802581258225832584258525862587258825892590259125922593259425952596259725982599260026012602260326042605260626072608260926102611261226132614261526162617261826192620262126222623262426252626262726282629263026312632263326342635263626372638263926402641264226432644264526462647264826492650265126522653265426552656265726582659266026612662266326642665266626672668266926702671267226732674267526762677267826792680268126822683268426852686268726882689269026912692269326942695269626972698269927002701270227032704270527062707270827092710271127122713271427152716271727182719272027212722272327242725272627272728272927302731273227332734273527362737273827392740274127422743274427452746274727482749275027512752275327542755275627572758275927602761276227632764276527662767276827692770277127722773277427752776277727782779278027812782278327842785278627872788278927902791279227932794279527962797279827992800280128022803280428052806280728082809281028112812281328142815281628172818281928202821282228232824282528262827282828292830283128322833283428352836283728382839284028412842284328442845284628472848284928502851285228532854285528562857285828592860286128622863286428652866286728682869287028712872287328742875287628772878287928802881288228832884288528862887288828892890289128922893289428952896289728982899290029012902290329042905290629072908290929102911291229132914291529162917291829192920292129222923292429252926292729282929293029312932293329342935293629372938293929402941294229432944294529462947294829492950295129522953295429552956295729582959296029612962296329642965296629672968296929702971297229732974297529762977297829792980298129822983298429852986298729882989299029912992299329942995299629972998299930003001300230033004300530063007300830093010301130123013301430153016301730183019302030213022302330243025302630273028302930303031303230333034303530363037303830393040304130423043304430453046304730483049305030513052305330543055305630573058305930603061306230633064306530663067306830693070307130723073307430753076307730783079308030813082308330843085308630873088308930903091309230933094309530963097309830993100310131023103310431053106310731083109311031113112311331143115311631173118311931203121312231233124312531263127312831293130313131323133313431353136313731383139314031413142
  1. package controllers
  2. import (
  3. "encoding/json"
  4. "fmt"
  5. "github.com/medivhzhan/weapp/v2"
  6. "github.com/rdlucklib/rdluck_tools/paging"
  7. "hongze/hongze_cygx/models"
  8. "hongze/hongze_cygx/services"
  9. "hongze/hongze_cygx/utils"
  10. "sort"
  11. "strconv"
  12. "strings"
  13. "time"
  14. )
  15. //活动
  16. type ActivityCoAntroller struct {
  17. BaseAuthController
  18. }
  19. type ActivityABaseController struct {
  20. BaseCommonController
  21. }
  22. // @Title 活动类型列表
  23. // @Description活动类型列表接口
  24. // @Success 200 {object} models.ActivityTypeListResp
  25. // @router /activityTypelist [get]
  26. func (this *ActivityCoAntroller) List() {
  27. br := new(models.BaseResponse).Init()
  28. defer func() {
  29. this.Data["json"] = br
  30. this.ServeJSON()
  31. }()
  32. user := this.User
  33. if user == nil {
  34. br.Msg = "请登录"
  35. br.ErrMsg = "请登录,SysUser Is Empty"
  36. br.Ret = 408
  37. return
  38. }
  39. resp := new(models.ActivityTypeListResp)
  40. list, err := models.GetActivityTypeList()
  41. if err != nil {
  42. br.Msg = "获取失败"
  43. br.ErrMsg = "获取数据失败,Err:" + err.Error()
  44. return
  45. }
  46. resp.List = list
  47. br.Ret = 200
  48. br.Success = true
  49. br.Msg = "获取成功"
  50. br.Data = resp
  51. }
  52. // @Title 活动列表
  53. // @Description 获取活动列表接口
  54. // @Param PageSize query int true "每页数据条数"
  55. // @Param CurrentIndex query int true "当前页页码,从1开始"
  56. // @Param ChartPermissionIds query string false "行业id 多个用 , 隔开"
  57. // @Param ActivityTypeIds query string false "活动类型id 多个用 , 隔开"
  58. // @Param KeyWord query string false "搜索关键词 多个用 , 隔开"
  59. // @Param ActiveState query string false "活动进行状态 未开始:1、进行中2、已结束3"
  60. // @Param WhichDay query string false "哪一天 今天:1、明天:2,多个用 , 隔开"
  61. // @Param IsShowJurisdiction query int false "是否仅展示有权限的,1是,2否 默认为零"
  62. // @Param Label query string false "搜索主题 多个用 , 隔开"
  63. // @Success 200 {object} models.GetCygxActivityListRep
  64. // @router /list [get]
  65. func (this *ActivityCoAntroller) ActivityList() {
  66. br := new(models.BaseResponse).Init()
  67. defer func() {
  68. this.Data["json"] = br
  69. this.ServeJSON()
  70. }()
  71. user := this.User
  72. if user == nil {
  73. br.Msg = "请登录"
  74. br.ErrMsg = "请登录,SysUser Is Empty"
  75. return
  76. }
  77. uid := user.UserId
  78. pageSize, _ := this.GetInt("PageSize")
  79. currentIndex, _ := this.GetInt("CurrentIndex")
  80. chartPermissionIds := this.GetString("ChartPermissionIds")
  81. activityTypeIds := this.GetString("ActivityTypeIds")
  82. whichDay := this.GetString("WhichDay")
  83. isShowJurisdiction, _ := this.GetInt("IsShowJurisdiction")
  84. keyWord := this.GetString("KeyWord")
  85. keyWordSearch := this.GetString("KeyWord")
  86. activeState := this.GetString("ActiveState")
  87. label := this.GetString("Label")
  88. //入参为 undefined 时的处理
  89. if chartPermissionIds == "undefined" {
  90. chartPermissionIds = ""
  91. }
  92. if activityTypeIds == "undefined" {
  93. activityTypeIds = ""
  94. }
  95. if whichDay == "undefined" {
  96. whichDay = ""
  97. }
  98. if activeState == "undefined" {
  99. activeState = ""
  100. }
  101. if label == "undefined" {
  102. label = ""
  103. }
  104. //更新用户的搜索信息
  105. itemSearch := new(models.CygxActivityUserSearchContent)
  106. itemSearch.UserId = uid
  107. itemSearch.CreateTime = time.Now()
  108. itemSearch.Mobile = user.Mobile
  109. itemSearch.Email = user.Email
  110. itemSearch.CompanyId = user.CompanyId
  111. itemSearch.CompanyName = user.CompanyName
  112. itemSearch.ModifyTime = time.Now()
  113. itemSearch.ChartPermissionids = chartPermissionIds
  114. itemSearch.ActivityTypeids = activityTypeIds
  115. itemSearch.ActiveState = activeState
  116. itemSearch.IsShowJurisdiction = isShowJurisdiction
  117. //并发缓存校验
  118. cacheKey := fmt.Sprint("xygx:activity_user_search:add:", uid)
  119. ttlTime := utils.Rc.GetRedisTTL(cacheKey)
  120. _, errSearch := models.AddUserSearchContent(itemSearch, ttlTime)
  121. if errSearch != nil {
  122. br.Msg = "操作失败"
  123. br.ErrMsg = "操作失败,Err:" + errSearch.Error()
  124. return
  125. }
  126. utils.Rc.SetNX(cacheKey, user.Mobile, time.Second*10)
  127. userType, permissionStr, err := services.GetUserType(user.CompanyId)
  128. if isShowJurisdiction == 1 && chartPermissionIds == "" && userType == 4 {
  129. activityTypeIds = "1,3"
  130. }
  131. var startSize int
  132. if pageSize <= 0 {
  133. pageSize = utils.PageSize20
  134. }
  135. if currentIndex <= 0 {
  136. currentIndex = 1
  137. }
  138. startSize = utils.StartIndex(currentIndex, pageSize)
  139. var condition string
  140. var pars []interface{}
  141. //活动可见限制
  142. var sqlExport string
  143. slicePer := strings.Split(permissionStr, ",")
  144. var permissionSqlStr string
  145. for _, v := range slicePer {
  146. if userType == 1 {
  147. if v != "研选" {
  148. permissionSqlStr += "'" + v + "',"
  149. }
  150. } else {
  151. permissionSqlStr += "'" + v + "',"
  152. }
  153. }
  154. permissionSqlStr = strings.TrimRight(permissionSqlStr, ",")
  155. permissionSqlStr = strings.Replace(permissionSqlStr, "(主观)", "", -1)
  156. permissionSqlStr = strings.Replace(permissionSqlStr, "(客观)", "", -1)
  157. permissionSqlStr = ` AND art.chart_permission_name IN (` + permissionSqlStr + `)`
  158. sqlExport = ` AND (art.customer_type_ids LIKE '%` + strconv.Itoa(userType) + `%' `
  159. if userType == 2 {
  160. sqlExport += ` OR art.customer_type_ids LIKE '%3%' `
  161. }
  162. if (userType == 2 || userType == 3) && strings.Contains(permissionStr, "专家") {
  163. sqlExport += ` OR art.customer_type_ids LIKE '%4%' `
  164. }
  165. sqlExport += `) `
  166. if keyWord != "" {
  167. var mirrorword string
  168. var mirrorwordSql string
  169. slicemirrorword := strings.Split(keyWord, ",")
  170. for _, v := range slicemirrorword {
  171. mirrorwordSql += "'" + v + "'" + ","
  172. }
  173. mirrorwordSql = strings.TrimRight(mirrorwordSql, ",")
  174. total, err := models.GetActivityMirrorWordCount(mirrorwordSql)
  175. if err != nil {
  176. br.Msg = "获取失败"
  177. br.ErrMsg = "获取失败,Err:" + err.Error()
  178. return
  179. }
  180. if total > 0 {
  181. mirrorword, err = models.GetMirrorWord(mirrorwordSql)
  182. if err != nil {
  183. br.Msg = "获取信息失败"
  184. br.ErrMsg = "关系词映射获取失败,Err:" + err.Error()
  185. return
  186. }
  187. }
  188. keyWord = keyWord + "," + mirrorword
  189. slicekeyWord := strings.Split(keyWord, ",")
  190. var sqlKeyOr string
  191. if len(slicekeyWord) >= 2 {
  192. for _, v := range slicekeyWord {
  193. if v != "" {
  194. sqlKeyOr += ` OR art.activity_name LIKE '%` + v + `%' `
  195. }
  196. }
  197. condition += ` AND (art.activity_name LIKE '%` + keyWord + `%' ` + sqlKeyOr + ` )`
  198. } else {
  199. condition += ` AND (art.activity_name LIKE '%` + keyWord + `%' )`
  200. }
  201. }
  202. //主题
  203. if label != "" {
  204. sliceLabel := strings.Split(label, ",")
  205. var labelSqlStr string
  206. for _, v := range sliceLabel {
  207. labelSqlStr += "'" + v + "',"
  208. }
  209. labelSqlStr = strings.TrimRight(labelSqlStr, ",")
  210. condition = ` AND art.label IN (` + labelSqlStr + `)`
  211. }
  212. //行业名称
  213. if len(chartPermissionIds) > 0 {
  214. condition += ` AND art.chart_permission_id IN (` + chartPermissionIds + `)`
  215. }
  216. if activityTypeIds != "" {
  217. condition += ` AND art.activity_type_id IN (` + activityTypeIds + `)`
  218. }
  219. if whichDay != "" {
  220. var startDate string
  221. var endDate string
  222. if whichDay == "1" {
  223. startDate = time.Now().Format(utils.FormatDate)
  224. endDate = startDate
  225. } else if whichDay == "2" {
  226. startDate = time.Now().AddDate(0, 0, +1).Format(utils.FormatDate)
  227. endDate = startDate
  228. } else {
  229. startDate = time.Now().Format(utils.FormatDate)
  230. endDate = time.Now().AddDate(0, 0, +1).Format(utils.FormatDate)
  231. }
  232. condition += ` AND art.activity_time >= ` + "'" + startDate + " 00:00:00'"
  233. condition += ` AND art.activity_time <= ` + "'" + endDate + " 23:59:59'"
  234. }
  235. if activeState != "" {
  236. condition += ` AND art.active_state IN (` + activeState + `)`
  237. }
  238. condition += ` AND art.publish_status = 1 `
  239. var conditionOr string
  240. // 有专家权限的这几种用户,不做行业权限校验
  241. if (userType == 2 || userType == 3 || userType == 4) && strings.Contains(permissionStr, "专家") {
  242. conditionOr += ` OR ( art.is_limit_people = 1 AND art.customer_type_ids LIKE '%4%' ` + condition + `) `
  243. }
  244. if (userType == 5) && strings.Contains(permissionStr, "专家") {
  245. conditionOr += ` OR ( art.is_limit_people = 1 AND art.customer_type_ids LIKE '%5%' ` + condition + `) `
  246. }
  247. if userType == 1 {
  248. conditionOr += ` OR ( art.is_limit_people = 0 ` + condition + permissionSqlStr + `) `
  249. } else {
  250. conditionOr += ` OR ( art.is_limit_people = 0 ` + condition + `) `
  251. }
  252. //判断客户规模是否属于可见范围的活动
  253. companyProduct, err := models.GetCompanyProductDetail(user.CompanyId, 2)
  254. if err != nil {
  255. br.Msg = "获取信息失败"
  256. br.ErrMsg = "获取客户信息失败,Err:" + err.Error()
  257. return
  258. }
  259. if companyProduct.Scale != "" {
  260. conditionOr += ` OR ( art.scale LIKE '%` + companyProduct.Scale + `%' ` + condition + `) `
  261. }
  262. condition += ` AND art.is_limit_people = 1 ` + permissionSqlStr + sqlExport + conditionOr
  263. total, err := models.GetActivityCount(condition, pars)
  264. if err != nil {
  265. br.Msg = "获取失败"
  266. br.ErrMsg = "获取失败,Err:" + err.Error()
  267. return
  268. }
  269. if activeState == "2" || activeState == "3" {
  270. condition += ` ORDER BY art.activity_time DESC `
  271. } else {
  272. condition += ` ORDER BY art.active_state ASC, art.activity_time ASC `
  273. }
  274. list, errList := models.GetActivityListAll(condition, pars, uid, startSize, pageSize)
  275. if errList != nil {
  276. br.Msg = "获取失败"
  277. br.ErrMsg = "获取失败,Err:" + errList.Error()
  278. return
  279. }
  280. var isShow bool
  281. isShow = services.GetShowSustainable()
  282. detail, err := models.GetConfigByCode("city_img_url")
  283. if err != nil {
  284. br.Msg = "获取数据失败"
  285. br.ErrMsg = "城市配置信息失败,Err:" + err.Error()
  286. return
  287. }
  288. detailChart, err := models.GetConfigByCode("chart_img_url")
  289. if err != nil {
  290. br.Msg = "获取数据失败"
  291. br.ErrMsg = "行业配置信息失败,Err:" + err.Error()
  292. return
  293. }
  294. addressList := strings.Split(detail.ConfigValue, "{|}")
  295. mapAddress := make(map[string]string)
  296. chartList := strings.Split(detailChart.ConfigValue, "{|}")
  297. mapChart := make(map[string]string)
  298. var cityName string
  299. var chartName string
  300. var imgUrl string
  301. var imgUrlChart string
  302. for _, v := range addressList {
  303. vslice := strings.Split(v, "_")
  304. cityName = vslice[0]
  305. imgUrl = vslice[len(vslice)-1]
  306. mapAddress[cityName] = imgUrl
  307. }
  308. for _, v := range chartList {
  309. vslice := strings.Split(v, "_")
  310. chartName = vslice[0]
  311. imgUrlChart = vslice[len(vslice)-1]
  312. mapChart[chartName] = imgUrlChart
  313. }
  314. for k, v := range list {
  315. if strings.Contains(v.ActivityName, "【") {
  316. list[k].IsBrackets = 1
  317. }
  318. if v.SignupNum > v.LimitPeopleNum {
  319. list[k].SignupNum = v.LimitPeopleNum
  320. }
  321. if isShow && v.ChartPermissionName == "研选" {
  322. list[k].IsShowSustainable = true
  323. }
  324. if v.ChartPermissionName == "研选" && v.ActivityTypeId == 1 {
  325. list[k].ActivityTypeName = "研选电话会"
  326. list[k].ImgUrlText = "https://hongze.oss-cn-shanghai.aliyuncs.com/static/images/202112/20211221/bIdfv8t86xrFRpDOeGGHXOmKEuKl.png"
  327. }
  328. if v.ActivityType == 0 {
  329. if mapAddress[v.City] != "" {
  330. list[k].ImgUrl = mapAddress[v.City]
  331. } else {
  332. list[k].ImgUrl = mapAddress["其它"]
  333. }
  334. } else {
  335. if mapChart[v.ChartPermissionName] != "" {
  336. list[k].ImgUrl = mapChart[v.ChartPermissionName]
  337. }
  338. }
  339. expertTxt, _ := services.GetReportContentTextSub(v.Expert)
  340. list[k].Expert = expertTxt
  341. }
  342. if keyWordSearch != "" {
  343. keyWordItem := new(models.CygxUserSearchKeyWord)
  344. keyWordItem.UserId = user.UserId
  345. keyWordItem.KeyWord = keyWordSearch
  346. keyWordItem.PageType = "ActivitSearch"
  347. keyWordItem.CreateTime = time.Now()
  348. go models.AddUserSearchKeyWord(keyWordItem)
  349. }
  350. page := paging.GetPaging(currentIndex, pageSize, total)
  351. resp := new(models.GetCygxActivityListRep)
  352. resp.List = list
  353. resp.Paging = page
  354. br.Ret = 200
  355. br.Success = true
  356. br.Msg = "获取成功"
  357. br.Data = resp
  358. }
  359. // @Title 我的日程
  360. // @Description 我的日程列表接口
  361. // @Param PageSize query int true "每页数据条数"
  362. // @Param CurrentIndex query int true "当前页页码,从1开始"
  363. // @Success 200 {object} models.GetCygxActivityListRep
  364. // @router /scheduleList [get]
  365. func (this *ActivityCoAntroller) ScheduleList() {
  366. br := new(models.BaseResponse).Init()
  367. defer func() {
  368. this.Data["json"] = br
  369. this.ServeJSON()
  370. }()
  371. user := this.User
  372. if user == nil {
  373. br.Msg = "请登录"
  374. br.ErrMsg = "请登录,SysUser Is Empty"
  375. return
  376. }
  377. uid := user.UserId
  378. pageSize, _ := this.GetInt("PageSize")
  379. currentIndex, _ := this.GetInt("CurrentIndex")
  380. var startSize int
  381. if pageSize <= 0 {
  382. pageSize = utils.PageSize20
  383. }
  384. if currentIndex <= 0 {
  385. currentIndex = 1
  386. }
  387. startSize = utils.StartIndex(currentIndex, pageSize)
  388. var condition string
  389. var conditionCount string
  390. var pars []interface{}
  391. condition += ` AND art.publish_status = 1 `
  392. total, err := models.GetScheduleCount(conditionCount, uid)
  393. page := paging.GetPaging(currentIndex, pageSize, total)
  394. if err != nil {
  395. br.Msg = "获取失败"
  396. br.ErrMsg = "获取失败,Err:" + err.Error()
  397. return
  398. }
  399. conditionCount = ` AND art.active_state = 2 `
  400. totalCount, err := models.GetScheduleCount(conditionCount, uid) //获取正在进行中的活动数量
  401. if err != nil {
  402. br.Msg = "获取失败"
  403. br.ErrMsg = "获取失败,Err:" + err.Error()
  404. return
  405. }
  406. var list []*models.CygxActivityList
  407. //全部都是进行中的活动
  408. if totalCount > currentIndex*pageSize {
  409. condition += ` AND art.active_state IN(2) `
  410. listHave, errList := models.GetScheduleList(condition, pars, uid, startSize, pageSize)
  411. list = listHave
  412. if errList != nil {
  413. br.Msg = "获取失败"
  414. br.ErrMsg = "获取失败,Err:" + errList.Error()
  415. return
  416. }
  417. } else if totalCount > currentIndex-1*pageSize && totalCount < currentIndex*pageSize { //部分是进行中的活动
  418. condition = ` AND art.publish_status = 1 AND art.active_state IN(2) `
  419. listHave, errList := models.GetScheduleList(condition, pars, uid, startSize, pageSize)
  420. list = listHave
  421. if errList != nil {
  422. br.Msg = "获取失败"
  423. br.ErrMsg = "获取失败,Err:" + errList.Error()
  424. return
  425. }
  426. pageSize = pageSize - len(listHave)
  427. condition = ` AND art.publish_status = 1 AND art.active_state IN(1,3) `
  428. listOther, errList := models.GetScheduleList(condition, pars, uid, startSize, pageSize)
  429. if errList != nil {
  430. br.Msg = "获取失败"
  431. br.ErrMsg = "获取失败,Err:" + errList.Error()
  432. return
  433. }
  434. if len(listOther) > 0 {
  435. for _, v := range listOther {
  436. list = append(list, v)
  437. }
  438. }
  439. } else {
  440. condition += ` AND art.active_state IN(1,3)` //全部都不是进行中的活动
  441. listOther, errList := models.GetScheduleList(condition, pars, uid, startSize, pageSize)
  442. list = listOther
  443. if errList != nil {
  444. br.Msg = "获取失败"
  445. br.ErrMsg = "获取失败,Err:" + errList.Error()
  446. return
  447. }
  448. }
  449. var isShow bool
  450. isShow = services.GetShowSustainable()
  451. detail, err := models.GetConfigByCode("city_img_url")
  452. if err != nil {
  453. br.Msg = "获取数据失败"
  454. br.ErrMsg = "城市配置信息失败,Err:" + err.Error()
  455. return
  456. }
  457. detailChart, err := models.GetConfigByCode("chart_img_url")
  458. if err != nil {
  459. br.Msg = "获取数据失败"
  460. br.ErrMsg = "行业配置信息失败,Err:" + err.Error()
  461. return
  462. }
  463. addressList := strings.Split(detail.ConfigValue, "{|}")
  464. mapAddress := make(map[string]string)
  465. chartList := strings.Split(detailChart.ConfigValue, "{|}")
  466. mapChart := make(map[string]string)
  467. var cityName string
  468. var chartName string
  469. var imgUrl string
  470. var imgUrlChart string
  471. for _, v := range addressList {
  472. vslice := strings.Split(v, "_")
  473. cityName = vslice[0]
  474. imgUrl = vslice[len(vslice)-1]
  475. mapAddress[cityName] = imgUrl
  476. }
  477. for _, v := range chartList {
  478. vslice := strings.Split(v, "_")
  479. chartName = vslice[0]
  480. imgUrlChart = vslice[len(vslice)-1]
  481. mapChart[chartName] = imgUrlChart
  482. }
  483. for k, v := range list {
  484. if strings.Contains(v.ActivityName, "【") {
  485. list[k].IsBrackets = 1
  486. }
  487. if v.SignupNum > v.LimitPeopleNum {
  488. list[k].SignupNum = v.LimitPeopleNum
  489. }
  490. //是否展示限免标签
  491. if isShow && v.ChartPermissionName == "研选" {
  492. list[k].IsShowSustainable = true
  493. }
  494. if v.ChartPermissionName == "研选" && v.ActivityTypeId == 1 {
  495. list[k].ActivityTypeName = "研选电话会"
  496. list[k].ImgUrlText = "https://hongze.oss-cn-shanghai.aliyuncs.com/static/images/202112/20211221/bIdfv8t86xrFRpDOeGGHXOmKEuKl.png"
  497. }
  498. if v.ActivityType == 0 {
  499. if mapAddress[v.City] != "" {
  500. list[k].ImgUrl = mapAddress[v.City]
  501. } else {
  502. list[k].ImgUrl = mapAddress["其它"]
  503. }
  504. } else {
  505. if mapChart[v.ChartPermissionName] != "" {
  506. list[k].ImgUrl = mapChart[v.ChartPermissionName]
  507. }
  508. }
  509. expertTxt, _ := services.GetReportContentTextSub(v.Expert)
  510. list[k].Expert = expertTxt
  511. }
  512. //添加我的日程访问记录
  513. item := new(models.CygxPageHistoryRecord)
  514. item.UserId = user.UserId
  515. item.CreateTime = time.Now()
  516. item.Mobile = user.Mobile
  517. item.Email = user.Email
  518. item.CompanyId = user.CompanyId
  519. item.CompanyName = user.CompanyName
  520. item.PageType = "MySchedule"
  521. go models.AddCygxPageHistoryRecord(item)
  522. resp := new(models.GetCygxActivityListRep)
  523. resp.List = list
  524. resp.Paging = page
  525. br.Ret = 200
  526. br.Success = true
  527. br.Msg = "获取成功"
  528. br.Data = resp
  529. }
  530. // @Title 活动详情
  531. // @Description 获取活动详情接口
  532. // @Param ActivityId query int true "活动ID"
  533. // @Success Ret=200 {object} models.CygxActivityResp
  534. // @router /detail [get]
  535. func (this *ActivityCoAntroller) Detail() {
  536. br := new(models.BaseResponse).Init()
  537. defer func() {
  538. this.Data["json"] = br
  539. this.ServeJSON()
  540. }()
  541. user := this.User
  542. if user == nil {
  543. br.Msg = "请登录"
  544. br.ErrMsg = "请登录,用户信息为空"
  545. br.Ret = 408
  546. return
  547. }
  548. uid := user.UserId
  549. activityId, _ := this.GetInt("ActivityId")
  550. if activityId < 1 {
  551. br.Msg = "请输入活动ID"
  552. return
  553. }
  554. resp := new(models.CygxActivityResp)
  555. hasPermission := 0
  556. var companyDetailStatus string
  557. activityInfo, err := models.GetAddActivityInfoByIdShow(uid, activityId)
  558. if err != nil && err.Error() != utils.ErrNoRow() {
  559. br.Msg = "获取信息失败"
  560. br.ErrMsg = "判断是否已申请过试用失败,Err:" + err.Error()
  561. return
  562. }
  563. if activityInfo == nil {
  564. br.Msg = "活动不存在"
  565. br.ErrMsg = "活动ID错误,Err:" + "activityId:" + strconv.Itoa(activityId)
  566. return
  567. }
  568. applyCount, err := models.GetApplyRecordCount(uid)
  569. if err != nil && err.Error() != utils.ErrNoRow() {
  570. br.Msg = "获取信息失败"
  571. br.ErrMsg = "判断是否已申请过试用失败,Err:" + err.Error()
  572. return
  573. }
  574. //获取FICC销售信息 如果是FICC的客户类型,则默认他申请过
  575. sellerItem, err := models.GetSellerByCompanyIdCheckFicc(user.CompanyId, 1)
  576. if err != nil && err.Error() != utils.ErrNoRow() {
  577. br.Msg = "获取信息失败"
  578. br.ErrMsg = "获取销售信息失败,Err:" + err.Error()
  579. return
  580. }
  581. if user.CompanyId <= 1 {
  582. companyDetailStatus = ""
  583. } else {
  584. companyPermission, err := models.GetCompanyPermission(user.CompanyId)
  585. if err != nil {
  586. br.Msg = "获取信息失败"
  587. br.ErrMsg = "获取客户详情失败,Err:" + err.Error()
  588. return
  589. }
  590. if companyPermission == "" {
  591. if applyCount > 0 {
  592. hasPermission = 4
  593. } else {
  594. if sellerItem != nil {
  595. hasPermission = 5
  596. } else {
  597. //获取权益销售信息 如果是FICC的客户类型,则默认他申请过
  598. sellerItemQy, err := models.GetSellerByCompanyIdCheckFicc(user.CompanyId, 2)
  599. if err != nil && err.Error() != utils.ErrNoRow() {
  600. br.Msg = "获取信息失败"
  601. br.ErrMsg = "获取销售信息失败,Err:" + err.Error()
  602. return
  603. }
  604. if sellerItemQy != nil {
  605. hasPermission = 2
  606. resp.SellerMobile = sellerItemQy.Mobile
  607. resp.SellerName = sellerItemQy.RealName
  608. } else {
  609. hasPermission = 3
  610. }
  611. }
  612. }
  613. resp.HasPermission = hasPermission
  614. resp.OperationMode = "Apply"
  615. resp.PopupMsg = "您暂无权限参加此活动,若想参加可以申请开通对应的试用权限"
  616. br.Ret = 200
  617. br.Success = true
  618. br.Msg = "获取成功"
  619. br.Data = resp
  620. return
  621. }
  622. companyDetail, err := models.GetCompanyDetailById(user.CompanyId)
  623. if err != nil {
  624. br.Msg = "获取信息失败!"
  625. br.ErrMsg = "获取客户详情失败,Err:" + err.Error()
  626. return
  627. }
  628. if companyDetail == nil {
  629. br.Msg = "获取信息失败!"
  630. br.ErrMsg = "客户不存在,uid:" + strconv.Itoa(user.UserId) + "CompanyId:" + strconv.Itoa(user.CompanyId)
  631. return
  632. }
  633. companyDetailStatus = companyDetail.Status
  634. }
  635. userType, permissionStr, err := services.GetUserType(user.CompanyId)
  636. if err != nil {
  637. br.Msg = "获取信息失败"
  638. br.ErrMsg = "获取客户信息失败,Err:" + err.Error()
  639. return
  640. }
  641. if activityInfo.IsLimitPeople > 0 {
  642. noPower, err := services.GetShareNoPowe(activityInfo, permissionStr, userType)
  643. if err != nil {
  644. br.Msg = "获取信息失败"
  645. br.ErrMsg = "获取客户信息失败,Err:" + err.Error()
  646. return
  647. }
  648. //获取用户的产业规模,判断是否允许可见
  649. companyProduct, err := models.GetCompanyProductDetail(user.CompanyId, 2)
  650. if err != nil {
  651. br.Msg = "获取信息失败"
  652. br.ErrMsg = "获取客户信息失败,Err:" + err.Error()
  653. return
  654. }
  655. if companyProduct.Scale != "" {
  656. if strings.Count(activityInfo.Scale, companyProduct.Scale) > 0 {
  657. noPower = false
  658. }
  659. }
  660. if noPower {
  661. br.Msg = "您暂无查看该活动权限"
  662. br.ErrMsg = "被分享客户不可见,获取信息失败"
  663. return
  664. }
  665. }
  666. if userType == 1 && activityInfo.ChartPermissionName == "研选" {
  667. br.Msg = "您暂无查看该活动权限"
  668. br.ErrMsg = "被分享客户不可见,永续客户无法查看研选行业"
  669. return
  670. }
  671. detail, errDetail := models.GetActivityTypeDetailById(activityInfo.ActivityTypeId)
  672. if errDetail != nil {
  673. br.Msg = "获取信息失败"
  674. br.ErrMsg = "获取信息失败,Err:" + errDetail.Error()
  675. return
  676. }
  677. if activityInfo.IsSignup > 0 {
  678. detail, errDetail := models.GetActivitySignupDetail(activityId, uid)
  679. if errDetail != nil {
  680. br.Msg = "获取信息失败"
  681. br.ErrMsg = "获取信息失败,Err:" + errDetail.Error()
  682. return
  683. }
  684. activityInfo.SignupType = detail.SignupType
  685. }
  686. activityInfo.ShowType = detail.ShowType
  687. //判断是否已经申请过
  688. if user.CompanyId > 1 {
  689. permissionStr, err := models.GetCompanyPermissionByUser(user.CompanyId)
  690. if err != nil {
  691. br.Msg = "获取信息失败"
  692. br.ErrMsg = "获取客户权限信息失败,Err:" + err.Error()
  693. return
  694. }
  695. companyItem, err := models.GetCompanyDetailById(user.CompanyId)
  696. //冻结客户
  697. if err != nil {
  698. if err.Error() == utils.ErrNoRow() {
  699. if applyCount > 0 {
  700. hasPermission = 4
  701. } else {
  702. if sellerItem != nil {
  703. hasPermission = 5
  704. } else {
  705. //获取权益销售信息 如果是FICC的客户类型,则默认他申请过
  706. sellerItemQy, err := models.GetSellerByCompanyIdCheckFicc(user.CompanyId, 2)
  707. if err != nil && err.Error() != utils.ErrNoRow() {
  708. br.Msg = "获取信息失败"
  709. br.ErrMsg = "获取销售信息失败,Err:" + err.Error()
  710. return
  711. }
  712. if sellerItemQy != nil {
  713. hasPermission = 2
  714. resp.SellerMobile = sellerItemQy.Mobile
  715. resp.SellerName = sellerItemQy.RealName
  716. } else {
  717. hasPermission = 3
  718. }
  719. }
  720. }
  721. resp.HasPermission = hasPermission
  722. resp.OperationMode = "Apply"
  723. resp.PopupMsg = "您暂无权限参加此活动,若想参加可以申请开通对应的试用权限"
  724. br.Ret = 200
  725. br.Success = true
  726. br.Msg = "获取成功"
  727. br.Data = resp
  728. return
  729. } else {
  730. br.Msg = "获取信息失败"
  731. br.ErrMsg = "获取客户公司信息失败,Err:" + err.Error()
  732. return
  733. }
  734. }
  735. havePower, err := services.GetHavePower(activityInfo, permissionStr, companyDetailStatus, userType)
  736. if havePower {
  737. hasPermission = 1
  738. resp.HaqveJurisdiction = true
  739. } else {
  740. if permissionStr == "专家" {
  741. resp.PopupMsg = "您暂无权限参加此活动,若想参加可以申请开通对应的试用权限"
  742. resp.MsgType = "Type"
  743. } else {
  744. //if strings.Contains("医药,消费,科技,智造", activityInfo.ChartPermissionName) {
  745. // if activityInfo.ActivityTypeId == 1 || activityInfo.ActivityTypeId == 3 || activityInfo.ActivityTypeId == 5 || activityInfo.ActivityTypeId == 6 {
  746. // activityInfo.ChartPermissionName += "(主观)"
  747. // } else {
  748. // activityInfo.ChartPermissionName += "(客观)"
  749. // }
  750. //}
  751. resp.PopupMsg = "您暂无权限参加此活动,若想参加可以申请开通对应的试用权限"
  752. resp.MsgType = "Industry"
  753. }
  754. if companyItem.ProductId == 2 {
  755. resp.SellerMobile = companyItem.Mobile
  756. resp.SellerName = companyItem.SellerName
  757. resp.OperationMode = "Call"
  758. hasPermission = 2
  759. } else {
  760. hasPermission = 5
  761. }
  762. }
  763. } else { //潜在客户
  764. if applyCount > 0 {
  765. hasPermission = 4
  766. } else {
  767. if sellerItem != nil {
  768. hasPermission = 5
  769. } else {
  770. hasPermission = 3
  771. }
  772. }
  773. resp.OperationMode = "Apply"
  774. resp.PopupMsg = "您暂无权限参加此活动,若想参加可以申请开通对应的试用权限"
  775. }
  776. if hasPermission == 1 {
  777. //是否展示限免标签
  778. if services.GetShowSustainable() && activityInfo.ChartPermissionName == "研选" {
  779. activityInfo.IsShowSustainable = true
  780. }
  781. configCode := "description_of_research"
  782. detail, err := models.GetConfigByCode(configCode)
  783. if err != nil {
  784. br.Msg = "获取数据失败"
  785. br.ErrMsg = "获取数据失败,Err:" + err.Error()
  786. return
  787. }
  788. activityInfo.Description = detail.ConfigValue
  789. if activityInfo.SignupNum > activityInfo.LimitPeopleNum {
  790. activityInfo.SignupNum = activityInfo.LimitPeopleNum
  791. }
  792. if activityInfo.ChartPermissionNames != "" {
  793. activityInfo.ChartPermissionName = activityInfo.ChartPermissionNames
  794. }
  795. resp.Detail = activityInfo
  796. }
  797. resp.HasPermission = hasPermission
  798. br.Ret = 200
  799. br.Success = true
  800. br.Msg = "获取成功"
  801. br.Data = resp
  802. }
  803. // @Title 活动报名
  804. // @Description 活动报名接口
  805. // @Param request body models.ActivitySingnupRep true "type json string"
  806. // @Success Ret=200 {object} models.SignupStatus
  807. // @router /signup/add [post]
  808. func (this *ActivityCoAntroller) SignupAdd() {
  809. br := new(models.BaseResponse).Init()
  810. defer func() {
  811. this.Data["json"] = br
  812. this.ServeJSON()
  813. }()
  814. user := this.User
  815. if user == nil {
  816. br.Msg = "请登录"
  817. br.ErrMsg = "请登录,用户信息为空"
  818. br.Ret = 408
  819. return
  820. }
  821. uid := user.UserId
  822. signupStatus := ""
  823. var req models.ActivitySingnupRep
  824. resp := new(models.SignupStatus)
  825. var total int
  826. err := json.Unmarshal(this.Ctx.Input.RequestBody, &req)
  827. if err != nil {
  828. br.Msg = "参数解析异常!"
  829. br.ErrMsg = "参数解析失败,Err:" + err.Error()
  830. return
  831. }
  832. activityId := req.ActivityId
  833. signupType := req.SignupType
  834. hasPermission := 0
  835. if signupType == 1 && user.Mobile == "" && user.OutboundMobile == "" {
  836. resp.GoBindEmail = true
  837. }
  838. //判断是否已经申请过
  839. applyCount, err := models.GetApplyRecordCount(uid)
  840. if err != nil && err.Error() != utils.ErrNoRow() {
  841. br.Msg = "获取信息失败"
  842. br.ErrMsg = "判断是否已申请过试用失败,Err:" + err.Error()
  843. return
  844. }
  845. //获取FICC销售信息
  846. sellerItem, err := models.GetSellerByCompanyIdCheckFicc(user.CompanyId, 1)
  847. if err != nil && err.Error() != utils.ErrNoRow() {
  848. br.Msg = "申请失败"
  849. br.ErrMsg = "获取销售信息失败,Err:" + err.Error()
  850. return
  851. }
  852. activityInfo, errInfo := models.GetAddActivityInfoById(activityId)
  853. if activityInfo == nil {
  854. br.Msg = "操作失败"
  855. br.ErrMsg = "活动ID错误,不存在activityId:" + strconv.Itoa(activityId)
  856. return
  857. }
  858. if errInfo != nil {
  859. br.Msg = "操作失败"
  860. br.ErrMsg = "操作失败,Err:" + errInfo.Error()
  861. return
  862. }
  863. //SignupStatus "报名状态:人数已满:FullStarffed、单机构超过两人:TwoPeople、爽约次数过多:BreakPromise、超时:Overtime 、成功:Success"`
  864. //HasPermission "1:有该行业权限,正常展示,2:无该行业权限,3:潜在客户,未提交过申请,4:潜在客户,已提交过申请"`
  865. var companyDetailStatus string
  866. if user.CompanyId <= 1 {
  867. companyDetailStatus = ""
  868. } else {
  869. companyPermission, err := models.GetCompanyPermission(user.CompanyId)
  870. if err != nil {
  871. br.Msg = "获取信息失败"
  872. br.ErrMsg = "获取客户详情失败,Err:" + err.Error()
  873. return
  874. }
  875. if companyPermission == "" {
  876. if applyCount > 0 {
  877. hasPermission = 4
  878. } else {
  879. if sellerItem != nil {
  880. hasPermission = 5
  881. } else {
  882. //获取权益销售信息 如果是FICC的客户类型,则默认他申请过
  883. sellerItemQy, err := models.GetSellerByCompanyIdCheckFicc(user.CompanyId, 2)
  884. if err != nil && err.Error() != utils.ErrNoRow() {
  885. br.Msg = "获取信息失败"
  886. br.ErrMsg = "获取销售信息失败,Err:" + err.Error()
  887. return
  888. }
  889. if sellerItemQy != nil {
  890. hasPermission = 2
  891. resp.SellerMobile = sellerItemQy.Mobile
  892. resp.SellerName = sellerItemQy.RealName
  893. } else {
  894. hasPermission = 3
  895. }
  896. }
  897. }
  898. resp.HasPermission = hasPermission
  899. resp.ActivityId = activityId
  900. resp.OperationMode = "Apply"
  901. resp.PopupMsg = "您暂无权限参加此活动,若想参加可以申请开通对应的试用权限"
  902. br.Ret = 200
  903. br.Success = true
  904. br.Msg = "获取成功"
  905. br.Data = resp
  906. return
  907. }
  908. companyDetail, err := models.GetCompanyDetailById(user.CompanyId)
  909. if err != nil {
  910. br.Msg = "获取信息失败!"
  911. br.ErrMsg = "获取客户详情失败,Err:" + err.Error()
  912. return
  913. }
  914. if companyDetail == nil {
  915. br.Msg = "获取信息失败!"
  916. br.ErrMsg = "客户不存在,uid:" + strconv.Itoa(user.UserId) + "CompanyId:" + strconv.Itoa(user.CompanyId)
  917. return
  918. }
  919. companyDetailStatus = companyDetail.Status
  920. }
  921. var userType int
  922. var permissionStr string
  923. userType, permissionStr, err = services.GetUserType(user.CompanyId)
  924. if err != nil {
  925. br.Msg = "获取信息失败!"
  926. br.ErrMsg = "获取失败,Err:" + err.Error()
  927. return
  928. }
  929. if userType == 1 && activityInfo.ChartPermissionName == "研选" {
  930. br.Msg = "您暂无查看该活动权限"
  931. br.ErrMsg = "被分享客户不可见,永续客户无法查看研选行业"
  932. return
  933. }
  934. item := new(models.CygxActivitySignup)
  935. if user.CompanyId > 1 {
  936. companyItem, err := models.GetCompanyDetailById(user.CompanyId)
  937. //冻结客户
  938. if err != nil {
  939. if err.Error() == utils.ErrNoRow() {
  940. if applyCount > 0 {
  941. hasPermission = 4
  942. } else {
  943. if sellerItem != nil {
  944. hasPermission = 5
  945. } else {
  946. hasPermission = 3
  947. }
  948. }
  949. resp.ActivityId = activityId
  950. resp.HasPermission = hasPermission
  951. resp.OperationMode = "Apply"
  952. resp.PopupMsg = "您暂无权限参加此活动,若想参加可以申请开通对应的试用权限"
  953. br.Ret = 200
  954. br.Success = true
  955. br.Msg = "获取成功"
  956. br.Data = resp
  957. return
  958. } else {
  959. br.Msg = "获取信息失败"
  960. br.ErrMsg = "获取客户公司信息失败,Err:" + err.Error()
  961. return
  962. }
  963. }
  964. //1专家电话会、2分析师电话会、3公司调研电话会、4公司线下调研、5专家线下沙龙、6分析师线下沙龙
  965. //OperationMode string `description:"操作方式 Apply:立即申请、Call:拨号 为空则为有权限"`
  966. havePower, err := services.GetHavePower(activityInfo, permissionStr, companyDetailStatus, userType)
  967. if err != nil {
  968. br.Msg = "获取信息失败!"
  969. br.ErrMsg = "获取失败,Err:" + err.Error()
  970. return
  971. }
  972. if havePower {
  973. hasPermission = 1
  974. signupStatus = "Success"
  975. resultTime := utils.StrTimeToTime(activityInfo.ActivityTime) //时间字符串格式转时间格式
  976. if time.Now().After(resultTime.Add(-time.Minute * 60)) {
  977. signupStatus = "Overtime"
  978. resp.SignupType = signupType
  979. resp.SignupStatus = signupStatus
  980. resp.HasPermission = hasPermission
  981. br.Ret = 200
  982. br.Success = true
  983. br.Msg = ""
  984. br.Data = resp
  985. return
  986. }
  987. var sellerName string
  988. sellerName, err = models.GetCompanySellerName(user.CompanyId)
  989. if err != nil {
  990. br.Msg = "报名失败!"
  991. br.ErrMsg = "获取对应销售失败,Err:" + err.Error()
  992. return
  993. }
  994. //人数已满:FullStarffed、单机构超过两人:TwoPeople、爽约次数过多:BreakPromise、超时:Overtime 、成功:Success"`
  995. //如果是下面几种情况则对报名信息做判断限制 (公司调研电话会(限制人数)、公司线下调研、专家/分析师线下沙龙)
  996. if (activityInfo.ActivityTypeId == 3 && activityInfo.IsLimitPeople == 1) || activityInfo.ActivityTypeId > 3 {
  997. //判断优先级:总人数限制→单机构2人限制→爽约3次限制
  998. totalRestrict, err := models.GetUserRestrictCount(user.Mobile)
  999. if err != nil {
  1000. br.Msg = "获取信息失败"
  1001. br.ErrMsg = "获取客户信息失败,Err:" + err.Error()
  1002. return
  1003. }
  1004. if totalRestrict >= 1 {
  1005. signupStatus = "BreakPromise"
  1006. item.FailType = 3
  1007. }
  1008. totalSignupCompany, err := models.GetActivitySignupCompanyCount(activityId, user.CompanyId)
  1009. if err != nil {
  1010. br.Msg = "获取信息失败"
  1011. br.ErrMsg = "获取客户信息失败,Err:" + err.Error()
  1012. return
  1013. }
  1014. if totalSignupCompany >= 2 {
  1015. signupStatus = "TwoPeople"
  1016. item.FailType = 2
  1017. }
  1018. totaSignupPeopleNum, err := models.GetActivitySignupSuccessCount(activityId)
  1019. if err != nil {
  1020. br.Msg = "获取信息失败"
  1021. br.ErrMsg = "获取客户信息失败,Err:" + err.Error()
  1022. return
  1023. }
  1024. if totaSignupPeopleNum >= activityInfo.LimitPeopleNum {
  1025. signupStatus = "FullStarffed"
  1026. item.FailType = 1
  1027. }
  1028. totalUserRestrictCount, err := models.GetActivitySignupByUserRestrictCount(uid, activityId)
  1029. if err != nil {
  1030. br.Msg = "获取失败"
  1031. br.ErrMsg = "获取失败,Err:" + err.Error()
  1032. return
  1033. }
  1034. //解除报名限制之后二次报名相同活动
  1035. if totalUserRestrictCount > 0 && totalRestrict == 0 && resp.GoBindEmail != true {
  1036. item.UserId = uid
  1037. item.RealName = user.RealName
  1038. item.SellerName = sellerName
  1039. item.ActivityId = activityId
  1040. item.CreateTime = time.Now()
  1041. item.Mobile = user.Mobile
  1042. item.Email = user.Email
  1043. item.CompanyId = user.CompanyId
  1044. item.CompanyName = user.CompanyName
  1045. item.SignupType = signupType
  1046. item.FailType = 0
  1047. item.DoFailType = 0
  1048. _, errSignup := models.AddActivitySignupByRestrict(item)
  1049. if errSignup != nil {
  1050. br.Msg = "操作失败"
  1051. br.ErrMsg = "操作失败,Err:" + errSignup.Error()
  1052. return
  1053. }
  1054. resp.HaqveJurisdiction = true
  1055. resp.SignupType = signupType
  1056. resp.SignupStatus = "Success"
  1057. resp.HasPermission = hasPermission
  1058. resp.ActivityId = activityId
  1059. total, err = models.GetUserMeetingReminderCount(user.UserId)
  1060. if err != nil {
  1061. br.Msg = "获取信息失败"
  1062. br.ErrMsg = "获取日程数量信息失败,Err:" + err.Error()
  1063. return
  1064. }
  1065. if total == 0 {
  1066. resp.GoFollow = true
  1067. }
  1068. br.Ret = 200
  1069. br.Success = true
  1070. br.Msg = "操作成功"
  1071. br.Data = resp
  1072. return
  1073. }
  1074. totalMy, err := models.GetActivitySignupByUserCount(uid, activityId)
  1075. if err != nil {
  1076. br.Msg = "获取失败"
  1077. br.ErrMsg = "获取失败,Err:" + err.Error()
  1078. return
  1079. }
  1080. if signupStatus != "Success" && totalMy == 0 && resp.GoBindEmail != true {
  1081. item.UserId = uid
  1082. item.RealName = user.RealName
  1083. item.SellerName = sellerName
  1084. item.ActivityId = activityId
  1085. item.CreateTime = time.Now()
  1086. item.Mobile = user.Mobile
  1087. item.Email = user.Email
  1088. item.CompanyId = user.CompanyId
  1089. item.CompanyName = user.CompanyName
  1090. item.SignupType = signupType
  1091. item.DoFailType = item.FailType
  1092. if user.OutboundMobile != "" {
  1093. item.OutboundMobile = user.OutboundMobile
  1094. if user.OutboundCountryCode == "" {
  1095. item.CountryCode = "86"
  1096. } else {
  1097. item.CountryCode = user.OutboundCountryCode
  1098. }
  1099. } else {
  1100. item.OutboundMobile = user.Mobile
  1101. if user.CountryCode == "" {
  1102. item.CountryCode = "86"
  1103. } else {
  1104. item.CountryCode = user.CountryCode
  1105. }
  1106. }
  1107. //添加报名信息,但是不加入日程
  1108. _, errSignup := models.AddActivitySignupNoSchedule(item)
  1109. if errSignup != nil {
  1110. br.Msg = "操作失败"
  1111. br.ErrMsg = "操作失败,Err:" + errSignup.Error()
  1112. return
  1113. }
  1114. }
  1115. }
  1116. totalMySuccess, err := models.GetActivitySignupCount(uid, activityId)
  1117. if err != nil {
  1118. br.Msg = "获取失败"
  1119. br.ErrMsg = "获取失败,Err:" + err.Error()
  1120. return
  1121. }
  1122. if totalMySuccess > 0 {
  1123. br.Msg = "您已报名这个活动"
  1124. return
  1125. }
  1126. if signupStatus == "Success" && resp.GoBindEmail != true {
  1127. item.UserId = uid
  1128. item.RealName = user.RealName
  1129. item.SellerName = sellerName
  1130. item.ActivityId = activityId
  1131. item.CreateTime = time.Now()
  1132. item.Mobile = user.Mobile
  1133. item.Email = user.Email
  1134. item.CompanyId = user.CompanyId
  1135. item.CompanyName = user.CompanyName
  1136. item.SignupType = signupType
  1137. item.FailType = 0
  1138. item.DoFailType = 0
  1139. item.OutboundMobile = user.Mobile
  1140. if user.OutboundMobile != "" {
  1141. item.OutboundMobile = user.OutboundMobile
  1142. if user.OutboundCountryCode == "" {
  1143. item.CountryCode = "86"
  1144. } else {
  1145. item.CountryCode = user.OutboundCountryCode
  1146. }
  1147. } else {
  1148. item.OutboundMobile = user.Mobile
  1149. if user.CountryCode == "" {
  1150. item.CountryCode = "86"
  1151. } else {
  1152. item.CountryCode = user.CountryCode
  1153. }
  1154. }
  1155. _, errSignup := models.AddActivitySignup(item)
  1156. if errSignup != nil {
  1157. br.Msg = "操作失败"
  1158. br.ErrMsg = "操作失败,Err:" + errSignup.Error()
  1159. return
  1160. }
  1161. resp.HaqveJurisdiction = true
  1162. }
  1163. } else {
  1164. if companyItem.ProductId == 2 {
  1165. hasPermission = 2
  1166. resp.SellerMobile = companyItem.Mobile
  1167. resp.SellerName = companyItem.SellerName
  1168. resp.MsgType = "Type"
  1169. resp.OperationMode = "Call"
  1170. if permissionStr == "专家" {
  1171. resp.PopupMsg = "您暂无权限参加【" + activityInfo.ActivityTypeName + "】类型活动,若想参加请联系对口销售--" + companyItem.SellerName + ":" + companyItem.Mobile
  1172. resp.MsgType = "Type"
  1173. } else {
  1174. resp.PopupMsg = "您暂无权限参加【" + activityInfo.ChartPermissionName + "】行业活动,若想参加请联系对口销售--" + companyItem.SellerName + ":" + companyItem.Mobile
  1175. resp.MsgType = "Industry"
  1176. }
  1177. } else {
  1178. hasPermission = 5
  1179. }
  1180. }
  1181. } else { //潜在客户
  1182. if applyCount > 0 {
  1183. hasPermission = 4
  1184. } else {
  1185. if sellerItem != nil {
  1186. hasPermission = 5
  1187. } else {
  1188. hasPermission = 3
  1189. }
  1190. }
  1191. resp.OperationMode = "Apply"
  1192. resp.PopupMsg = "您暂无权限参加此活动,若想参加可以申请开通对应的试用权限"
  1193. }
  1194. if signupType == 1 && user.IsMsgOutboundMobile == 0 {
  1195. resp.GoOutboundMobile = true
  1196. if user.Mobile != "" || user.OutboundMobile != "" {
  1197. go models.ModifyWxUserIsMsgOutboundMobile(user.UserId)
  1198. }
  1199. }
  1200. if user.OutboundMobile == "" {
  1201. resp.Mobile = user.Mobile
  1202. if user.CountryCode == "" && len(user.Mobile) == 11 {
  1203. resp.CountryCode = "86"
  1204. } else {
  1205. resp.CountryCode = user.CountryCode
  1206. }
  1207. } else {
  1208. resp.Mobile = user.OutboundMobile
  1209. resp.CountryCode = user.OutboundCountryCode
  1210. }
  1211. //如果用户有绑定手机号,但是没有绑定外呼手机号
  1212. if signupType == 1 && user.Mobile != "" && user.OutboundMobile == "" {
  1213. var countryCode string
  1214. if len(user.Mobile) == 8 {
  1215. countryCode = "852"
  1216. } else if len(user.Mobile) == 9 {
  1217. countryCode = "886"
  1218. } else if len(user.Mobile) == 10 {
  1219. countryCode = "1"
  1220. } else if len(user.Mobile) >= 11 {
  1221. countryCode = "86"
  1222. }
  1223. models.BindUserOutboundMobileByMobile(user.Mobile, countryCode, uid)
  1224. }
  1225. resp.SignupType = signupType
  1226. resp.SignupStatus = signupStatus
  1227. resp.HasPermission = hasPermission
  1228. //if signupStatus == "Success" {
  1229. resp.ActivityId = activityId
  1230. //}
  1231. total, err = models.GetUserSignupCount(user.UserId)
  1232. if err != nil {
  1233. br.Msg = "获取信息失败"
  1234. br.ErrMsg = "获取日程数量信息失败,Err:" + err.Error()
  1235. return
  1236. }
  1237. if total <= 1 {
  1238. resp.GoFollow = true
  1239. }
  1240. br.Ret = 200
  1241. br.Success = true
  1242. br.Msg = "操作成功"
  1243. br.Data = resp
  1244. }
  1245. // @Title 活动取消报名
  1246. // @Description 活动取消报名接口
  1247. // @Param request body models.ActivitySingnupRep true "type json string"
  1248. // @Success Ret=200 {object} models.SignupStatus
  1249. // @router /signup/cancel [post]
  1250. func (this *ActivityCoAntroller) SignupCancel() {
  1251. br := new(models.BaseResponse).Init()
  1252. defer func() {
  1253. this.Data["json"] = br
  1254. this.ServeJSON()
  1255. }()
  1256. user := this.User
  1257. if user == nil {
  1258. br.Msg = "请登录"
  1259. br.ErrMsg = "请登录,用户信息为空"
  1260. br.Ret = 408
  1261. return
  1262. }
  1263. uid := user.UserId
  1264. var req models.ActivitySingnupRep
  1265. err := json.Unmarshal(this.Ctx.Input.RequestBody, &req)
  1266. if err != nil {
  1267. br.Msg = "参数解析异常!"
  1268. br.ErrMsg = "参数解析失败,Err:" + err.Error()
  1269. return
  1270. }
  1271. activityId := req.ActivityId
  1272. signupType := req.SignupType
  1273. item := new(models.CygxActivitySignup)
  1274. activityInfo, errInfo := models.GetAddActivityInfoById(activityId)
  1275. if activityInfo == nil {
  1276. br.Msg = "操作失败"
  1277. br.ErrMsg = "活动ID错误,不存在activityId:" + strconv.Itoa(activityId)
  1278. return
  1279. }
  1280. if errInfo != nil {
  1281. br.Msg = "操作失败"
  1282. br.ErrMsg = "操作失败,Err:" + errInfo.Error()
  1283. return
  1284. }
  1285. resultTime := utils.StrTimeToTime(activityInfo.ActivityTime) //时间字符串格式转时间格式
  1286. if time.Now().After(resultTime.Add(-time.Minute * 60)) {
  1287. if signupType == 1 {
  1288. br.Msg = "活动开始前1小时内无法取消预约外呼,请联系对口销售处理"
  1289. } else {
  1290. br.Msg = "活动开始前1小时内无法取消报名,请联系对口销售处理"
  1291. }
  1292. return
  1293. }
  1294. total, err := models.GetActivitySignupCount(uid, activityId)
  1295. if err != nil {
  1296. br.Msg = "获取失败"
  1297. br.ErrMsg = "获取失败,Err:" + err.Error()
  1298. return
  1299. }
  1300. if total == 0 {
  1301. br.Msg = "您暂未报名这个活动"
  1302. return
  1303. }
  1304. item.UserId = uid
  1305. item.ActivityId = activityId
  1306. item.CreateTime = time.Now()
  1307. item.Mobile = user.Mobile
  1308. item.Email = user.Email
  1309. item.CompanyId = user.CompanyId
  1310. item.CompanyName = user.CompanyName
  1311. resp := new(models.SignupStatus)
  1312. resp.ActivityId = activityId
  1313. _, errSignup := models.CancelActivitySignup(item)
  1314. if errSignup != nil {
  1315. br.Msg = "操作失败"
  1316. br.ErrMsg = "操作失败,Err:" + errSignup.Error()
  1317. return
  1318. }
  1319. br.Ret = 200
  1320. br.Success = true
  1321. br.Msg = "操作成功"
  1322. br.Data = resp
  1323. }
  1324. // @Title 用户搜索详情
  1325. // @Description 获取用户搜索详情接口
  1326. // @Param IsShowJurisdiction query int true "是否仅展示有权限的,默认为0,1是,2否 "
  1327. // @Success Ret=200 {object} models.ActivityUserSearchContentList
  1328. // @router /getUserSearchContent [get]
  1329. func (this *ActivityCoAntroller) GetUserSearchContent() {
  1330. br := new(models.BaseResponse).Init()
  1331. defer func() {
  1332. this.Data["json"] = br
  1333. this.ServeJSON()
  1334. }()
  1335. user := this.User
  1336. if user == nil {
  1337. br.Msg = "请登录"
  1338. br.ErrMsg = "请登录,用户信息为空"
  1339. br.Ret = 408
  1340. return
  1341. }
  1342. uid := user.UserId
  1343. detailSeearch := new(models.CygxActivityUserSearchContent)
  1344. detailSeearch.IsShowJurisdiction = 0
  1345. detailSeearch.ChartPermissionids = ""
  1346. detailSeearch.ActiveState = ""
  1347. resp := new(models.ActivityUserSearchContentList)
  1348. detail, _ := models.GetUserSearchContentByUid(uid)
  1349. if detail == nil {
  1350. detail = detailSeearch
  1351. }
  1352. isShowJurisdiction, _ := this.GetInt("IsShowJurisdiction")
  1353. listActivityType, errActivityType := models.GetActivityTypeList()
  1354. if errActivityType != nil {
  1355. br.Msg = "获取失败"
  1356. br.ErrMsg = "获取数据失败,Err:" + errActivityType.Error()
  1357. return
  1358. }
  1359. var listChartPermissionid []*models.ActivityChartPermission
  1360. var errChart error
  1361. if isShowJurisdiction == 1 {
  1362. listChartPermissionidAll, errChartAll := models.GetUserCompanyPermission(user.CompanyId)
  1363. listChartPermissionid = listChartPermissionidAll
  1364. errChart = errChartAll
  1365. } else if isShowJurisdiction == 2 {
  1366. listChartPermissionidAll, errChartAll := models.GetChartPermissionActivity()
  1367. listChartPermissionid = listChartPermissionidAll
  1368. errChart = errChartAll
  1369. } else {
  1370. if detail.IsShowJurisdiction == 1 {
  1371. listChartPermissionidAll, errChartAll := models.GetUserCompanyPermission(user.CompanyId)
  1372. listChartPermissionid = listChartPermissionidAll
  1373. errChart = errChartAll
  1374. } else {
  1375. listChartPermissionidAll, errChartAll := models.GetChartPermissionActivity()
  1376. listChartPermissionid = listChartPermissionidAll
  1377. errChart = errChartAll
  1378. }
  1379. }
  1380. if errChart != nil {
  1381. br.Msg = "获取信息失败"
  1382. br.ErrMsg = "获取品种信息失败,Err:" + errChart.Error()
  1383. return
  1384. }
  1385. if detail.IsShowJurisdiction == 1 {
  1386. resp.IsShowJurisdiction = true
  1387. }
  1388. if isShowJurisdiction == 1 || detail.IsShowJurisdiction == 1 {
  1389. resp.IsShowJurisdiction = true
  1390. for k, _ := range listChartPermissionid {
  1391. listChartPermissionid[k].IsChoose = true
  1392. }
  1393. }
  1394. if isShowJurisdiction == 2 {
  1395. resp.IsShowJurisdiction = false
  1396. }
  1397. activeStateList := []models.ActivityStaus{models.ActivityStaus{Id: 1, StatusName: "未开始", IsChoose: true}, models.ActivityStaus{Id: 2, StatusName: "进行中"}, models.ActivityStaus{Id: 3, StatusName: "已结束"}}
  1398. list2, err := models.GetChartPermissionActivity()
  1399. if err != nil {
  1400. br.Msg = "获取信息失败"
  1401. br.ErrMsg = "获取品种信息失败,Err:" + err.Error()
  1402. return
  1403. }
  1404. if activeStateList[1].IsChoose == activeStateList[2].IsChoose == false {
  1405. activeStateList[0].IsChoose = true
  1406. }
  1407. var userType int
  1408. userType, _, err = services.GetUserType(user.CompanyId)
  1409. if err != nil {
  1410. br.Msg = "获取信息失败!"
  1411. br.ErrMsg = "获取失败,Err:" + err.Error()
  1412. return
  1413. }
  1414. var listChartPermissionidNew2 []*models.ActivityChartPermission
  1415. for _, v := range list2 {
  1416. if userType == 1 {
  1417. if v.PermissionName != "研选" {
  1418. listChartPermissionidNew2 = append(listChartPermissionidNew2, v)
  1419. }
  1420. } else {
  1421. listChartPermissionidNew2 = append(listChartPermissionidNew2, v)
  1422. }
  1423. }
  1424. resp.ListChartPermission2 = listChartPermissionidNew2
  1425. var listChartPermissionidNew []*models.ActivityChartPermission
  1426. for _, v := range listChartPermissionid {
  1427. if userType == 1 {
  1428. if v.PermissionName != "研选" {
  1429. listChartPermissionidNew = append(listChartPermissionidNew, v)
  1430. }
  1431. } else {
  1432. listChartPermissionidNew = append(listChartPermissionidNew, v)
  1433. }
  1434. }
  1435. resp.ListActivityType = listActivityType
  1436. resp.ListChartPermission = listChartPermissionidNew
  1437. resp.ListActivityStaus = activeStateList
  1438. br.Ret = 200
  1439. br.Success = true
  1440. br.Msg = "获取成功"
  1441. br.Data = resp
  1442. }
  1443. // @Title 添加会议提醒
  1444. // @Description 添加会议提醒接口
  1445. // @Param request body models.ActivityIdRep true "type json string"
  1446. // @Success Ret=200 {object} models.SignupStatus
  1447. // @router /meetingReminder/add [post]
  1448. func (this *ActivityCoAntroller) MeetingReminderAdd() {
  1449. br := new(models.BaseResponse).Init()
  1450. defer func() {
  1451. this.Data["json"] = br
  1452. this.ServeJSON()
  1453. }()
  1454. user := this.User
  1455. if user == nil {
  1456. br.Msg = "请登录"
  1457. br.ErrMsg = "请登录,用户信息为空"
  1458. br.Ret = 408
  1459. return
  1460. }
  1461. uid := user.UserId
  1462. //var signupStatus string
  1463. signupStatus := "Success"
  1464. var req models.ActivityIdRep
  1465. err := json.Unmarshal(this.Ctx.Input.RequestBody, &req)
  1466. if err != nil {
  1467. br.Msg = "参数解析异常!"
  1468. br.ErrMsg = "参数解析失败,Err:" + err.Error()
  1469. return
  1470. }
  1471. activityId := req.ActivityId
  1472. activityInfo, errInfo := models.GetAddActivityInfoById(activityId)
  1473. if activityInfo == nil {
  1474. br.Msg = "操作失败"
  1475. br.ErrMsg = "活动ID错误,不存在activityId:" + strconv.Itoa(activityId)
  1476. return
  1477. }
  1478. if errInfo != nil {
  1479. br.Msg = "操作失败"
  1480. br.ErrMsg = "操作失败,Err:" + errInfo.Error()
  1481. return
  1482. }
  1483. //判断是否已经申请过
  1484. applyCount, err := models.GetApplyRecordCount(uid)
  1485. if err != nil && err.Error() != utils.ErrNoRow() {
  1486. br.Msg = "获取信息失败"
  1487. br.ErrMsg = "判断是否已申请过试用失败,Err:" + err.Error()
  1488. return
  1489. }
  1490. //获取销售信息
  1491. sellerItem, err := models.GetSellerByCompanyIdCheckFicc(user.CompanyId, 1)
  1492. if err != nil && err.Error() != utils.ErrNoRow() {
  1493. br.Msg = "申请失败"
  1494. br.ErrMsg = "获取销售信息失败,Err:" + err.Error()
  1495. return
  1496. }
  1497. //SignupStatus string `description:"报名状态:人数已满:FullStarffed、单机构超过两人:TwoPeople、爽约次数过多:BreakPromise、超时:Overtime 、成功:Success"`
  1498. item := new(models.CygxActivityMeetingReminder)
  1499. resp := new(models.SignupStatus)
  1500. hasPermission := 0
  1501. var companyDetailStatus string
  1502. if user.CompanyId <= 1 {
  1503. companyDetailStatus = ""
  1504. } else {
  1505. companyPermission, err := models.GetCompanyPermission(user.CompanyId)
  1506. if err != nil {
  1507. br.Msg = "获取信息失败"
  1508. br.ErrMsg = "获取客户详情失败,Err:" + err.Error()
  1509. return
  1510. }
  1511. if companyPermission == "" {
  1512. if applyCount > 0 {
  1513. hasPermission = 4
  1514. } else {
  1515. if sellerItem != nil {
  1516. hasPermission = 5
  1517. } else {
  1518. //获取权益销售信息 如果是FICC的客户类型,则默认他申请过
  1519. sellerItemQy, err := models.GetSellerByCompanyIdCheckFicc(user.CompanyId, 2)
  1520. if err != nil && err.Error() != utils.ErrNoRow() {
  1521. br.Msg = "获取信息失败"
  1522. br.ErrMsg = "获取销售信息失败,Err:" + err.Error()
  1523. return
  1524. }
  1525. if sellerItemQy != nil {
  1526. hasPermission = 2
  1527. resp.SellerMobile = sellerItemQy.Mobile
  1528. resp.SellerName = sellerItemQy.RealName
  1529. } else {
  1530. hasPermission = 3
  1531. }
  1532. }
  1533. }
  1534. resp.ActivityId = activityId
  1535. resp.HasPermission = hasPermission
  1536. resp.OperationMode = "Apply"
  1537. resp.PopupMsg = "您暂无权限参加此活动,若想参加可以申请开通对应的试用权限"
  1538. br.Ret = 200
  1539. br.Success = true
  1540. br.Msg = "获取成功"
  1541. br.Data = resp
  1542. return
  1543. }
  1544. companyDetail, err := models.GetCompanyDetailById(user.CompanyId)
  1545. if err != nil {
  1546. br.Msg = "获取信息失败!"
  1547. br.ErrMsg = "获取客户详情失败,Err:" + err.Error()
  1548. return
  1549. }
  1550. if companyDetail == nil {
  1551. br.Msg = "获取信息失败!"
  1552. br.ErrMsg = "客户不存在,uid:" + strconv.Itoa(user.UserId) + "CompanyId:" + strconv.Itoa(user.CompanyId)
  1553. return
  1554. }
  1555. companyDetailStatus = companyDetail.Status
  1556. }
  1557. var userType int
  1558. var permissionStr string
  1559. userType, permissionStr, err = services.GetUserType(user.CompanyId)
  1560. if err != nil {
  1561. br.Msg = "获取信息失败!"
  1562. br.ErrMsg = "获取失败,Err:" + err.Error()
  1563. return
  1564. }
  1565. if userType == 1 && activityInfo.ChartPermissionName == "研选" {
  1566. br.Msg = "您暂无查看该活动权限"
  1567. br.ErrMsg = "被分享客户不可见,永续客户无法查看研选行业"
  1568. return
  1569. }
  1570. resultTime := utils.StrTimeToTime(activityInfo.ActivityTime) //时间字符串格式转时间格式
  1571. if time.Now().After(resultTime.Add(-time.Minute * 15)) {
  1572. br.Msg = "活动开始前15分钟无法设置会议提醒"
  1573. return
  1574. }
  1575. if user.CompanyId > 1 {
  1576. companyItem, err := models.GetCompanyDetailById(user.CompanyId)
  1577. //冻结客户
  1578. if err != nil {
  1579. if err.Error() == utils.ErrNoRow() {
  1580. //如果是FICC的客户类型,则默认他申请过
  1581. if applyCount > 0 {
  1582. hasPermission = 4
  1583. } else {
  1584. if sellerItem != nil {
  1585. hasPermission = 5
  1586. } else {
  1587. hasPermission = 3
  1588. }
  1589. }
  1590. resp.ActivityId = activityId
  1591. resp.HasPermission = hasPermission
  1592. resp.OperationMode = "Apply"
  1593. resp.PopupMsg = "您暂无权限参加此活动,若想参加可以申请开通对应的试用权限"
  1594. br.Ret = 200
  1595. br.Success = true
  1596. br.Msg = "获取成功"
  1597. br.Data = resp
  1598. return
  1599. } else {
  1600. br.Msg = "获取信息失败"
  1601. br.ErrMsg = "获取客户公司信息失败,Err:" + err.Error()
  1602. return
  1603. }
  1604. }
  1605. havePower, err := services.GetHavePower(activityInfo, permissionStr, companyDetailStatus, userType)
  1606. if err != nil {
  1607. br.Msg = "获取信息失败!"
  1608. br.ErrMsg = "获取失败,Err:" + err.Error()
  1609. return
  1610. }
  1611. if havePower {
  1612. hasPermission = 1
  1613. signupStatus = "Success"
  1614. totalMeeting, errMeeting := models.GetActivityMeetingReminderCount(uid, activityId)
  1615. if errMeeting != nil {
  1616. br.Msg = "获取失败"
  1617. br.ErrMsg = "获取失败,Err:" + errMeeting.Error()
  1618. return
  1619. }
  1620. if totalMeeting > 0 {
  1621. br.Msg = "您已预约,请勿重复预约"
  1622. return
  1623. }
  1624. item.UserId = uid
  1625. item.ActivityId = activityId
  1626. item.CreateTime = time.Now()
  1627. item.Mobile = user.Mobile
  1628. item.Email = user.Email
  1629. item.CompanyId = user.CompanyId
  1630. item.CompanyName = user.CompanyName
  1631. _, errSignup := models.AddActivityMeetingReminder(item)
  1632. if errSignup != nil {
  1633. br.Msg = "操作失败"
  1634. br.ErrMsg = "操作失败,Err:" + errSignup.Error()
  1635. return
  1636. }
  1637. resp.HaqveJurisdiction = true
  1638. } else {
  1639. if companyItem.ProductId == 2 {
  1640. hasPermission = 2
  1641. resp.SellerMobile = companyItem.Mobile
  1642. resp.SellerName = companyItem.SellerName
  1643. resp.MsgType = "Type"
  1644. resp.OperationMode = "Call"
  1645. if permissionStr == "专家" {
  1646. resp.PopupMsg = "您暂无权限参加【" + activityInfo.ActivityTypeName + "】类型活动,若想参加请联系对口销售--" + companyItem.SellerName + ":" + companyItem.Mobile
  1647. resp.MsgType = "Type"
  1648. } else {
  1649. resp.PopupMsg = "您暂无权限参加【" + activityInfo.ChartPermissionName + "】行业活动,若想参加请联系对口销售--" + companyItem.SellerName + ":" + companyItem.Mobile
  1650. resp.MsgType = "Industry"
  1651. }
  1652. } else {
  1653. hasPermission = 5
  1654. }
  1655. }
  1656. } else { //潜在客户
  1657. if applyCount > 0 {
  1658. hasPermission = 4
  1659. } else {
  1660. if sellerItem != nil {
  1661. hasPermission = 5
  1662. } else {
  1663. hasPermission = 3
  1664. }
  1665. }
  1666. resp.OperationMode = "Apply"
  1667. resp.PopupMsg = "您暂无权限参加此活动,若想参加可以申请开通对应的试用权限"
  1668. }
  1669. resp.HasPermission = hasPermission
  1670. resp.SignupStatus = signupStatus
  1671. resp.ActivityId = activityId
  1672. var total int
  1673. total, err = models.GetUserActivityMeetingReminderCount(user.UserId)
  1674. if err != nil {
  1675. br.Msg = "获取信息失败"
  1676. br.ErrMsg = "获取日程数量信息失败,Err:" + err.Error()
  1677. return
  1678. }
  1679. if total <= 1 {
  1680. resp.GoFollow = true
  1681. }
  1682. br.Ret = 200
  1683. br.Success = true
  1684. if hasPermission == 1 {
  1685. br.Msg = "设置成功,会前15分钟会为您推送微信消息提醒"
  1686. }
  1687. br.Data = resp
  1688. }
  1689. // @Title 取消会议提醒
  1690. // @Description 取消会议提醒接口
  1691. // @Param request body models.ActivityIdRep true "type json string"
  1692. // @Success Ret=200 {object} models.SignupStatus
  1693. // @router /meetingReminder/cancel [post]
  1694. func (this *ActivityCoAntroller) MeetingReminderCancel() {
  1695. br := new(models.BaseResponse).Init()
  1696. defer func() {
  1697. this.Data["json"] = br
  1698. this.ServeJSON()
  1699. }()
  1700. user := this.User
  1701. if user == nil {
  1702. br.Msg = "请登录"
  1703. br.ErrMsg = "请登录,用户信息为空"
  1704. br.Ret = 408
  1705. return
  1706. }
  1707. uid := user.UserId
  1708. var req models.ActivityIdRep
  1709. err := json.Unmarshal(this.Ctx.Input.RequestBody, &req)
  1710. if err != nil {
  1711. br.Msg = "参数解析异常!"
  1712. br.ErrMsg = "参数解析失败,Err:" + err.Error()
  1713. return
  1714. }
  1715. activityId := req.ActivityId
  1716. signupStatus := "Success"
  1717. item := new(models.CygxActivityMeetingReminder)
  1718. activityInfo, errInfo := models.GetAddActivityInfoById(activityId)
  1719. if activityInfo == nil {
  1720. br.Msg = "操作失败"
  1721. br.ErrMsg = "活动ID错误,不存在activityId:" + strconv.Itoa(activityId)
  1722. return
  1723. }
  1724. if errInfo != nil {
  1725. br.Msg = "操作失败"
  1726. br.ErrMsg = "操作失败,Err:" + errInfo.Error()
  1727. return
  1728. }
  1729. //if signupStatus == "Success" {
  1730. total, err := models.GetActivityMeetingReminderCount(uid, activityId)
  1731. if err != nil {
  1732. br.Msg = "获取失败"
  1733. br.ErrMsg = "获取失败,Err:" + err.Error()
  1734. return
  1735. }
  1736. if total == 0 {
  1737. br.Msg = "您暂未添加该活动会议提醒"
  1738. return
  1739. }
  1740. resultTime := utils.StrTimeToTime(activityInfo.ActivityTime) //时间字符串格式转时间格式
  1741. if time.Now().After(resultTime.Add(-time.Minute * 15)) {
  1742. br.Msg = "活动开始前15分钟无法取消会议提醒"
  1743. return
  1744. }
  1745. item.UserId = uid
  1746. item.ActivityId = activityId
  1747. item.CreateTime = time.Now()
  1748. item.Mobile = user.Mobile
  1749. item.Email = user.Email
  1750. item.CompanyId = user.CompanyId
  1751. item.CompanyName = user.CompanyName
  1752. _, errSignup := models.CancelActivityMeetingReminder(item)
  1753. if errSignup != nil {
  1754. br.Msg = "操作失败"
  1755. br.ErrMsg = "操作失败,Err:" + errSignup.Error()
  1756. return
  1757. }
  1758. //}
  1759. resp := new(models.SignupStatus)
  1760. resp.SignupStatus = signupStatus
  1761. resp.ActivityId = activityId
  1762. br.Ret = 200
  1763. br.Success = true
  1764. br.Msg = "会议提醒已取消"
  1765. br.Data = resp
  1766. }
  1767. // @Title 敏捷搜索关键词的列表
  1768. // @Description 获取敏捷搜索关键词的列表接口
  1769. // @Success 200 {object} models.ActivityFastsearchKeywordsListResp
  1770. // @router /fastSearchKeWord [get]
  1771. func (this *ActivityABaseController) FastSearch() {
  1772. br := new(models.BaseResponse).Init()
  1773. defer func() {
  1774. this.Data["json"] = br
  1775. this.ServeJSON()
  1776. }()
  1777. resp := new(models.ActivityFastsearchKeywordsListResp)
  1778. list, err := models.GetActivityFastsearchKeywordsList()
  1779. if err != nil {
  1780. br.Msg = "获取失败"
  1781. br.ErrMsg = "获取数据失败,Err:" + err.Error()
  1782. return
  1783. }
  1784. resp.List = list
  1785. br.Ret = 200
  1786. br.Success = true
  1787. br.Msg = "获取成功"
  1788. br.Data = resp
  1789. }
  1790. // @Title 主题列表
  1791. // @Description 获取活动主题列表接口
  1792. // @Param ChartPermissionIds query string false "行业id 多个用 , 隔开"
  1793. // @Param ActivityTypeIds query string false "活动类型id 多个用 , 隔开"
  1794. // @Param ActiveState query string false "活动进行状态 未开始:1、进行中2、已结束3"
  1795. // @Param WhichDay query string false "哪一天 今天:1、明天:2,多个用 , 隔开"
  1796. // @Param Label query string false "搜索主题 多个用 , 隔开 (空为活动主题,非空为更多主题)"
  1797. // @Success 200 {object} models.GetCygxActivityLabelListRep
  1798. // @router /labelList [get]
  1799. func (this *ActivityCoAntroller) LabelList() {
  1800. br := new(models.BaseResponse).Init()
  1801. defer func() {
  1802. this.Data["json"] = br
  1803. this.ServeJSON()
  1804. }()
  1805. user := this.User
  1806. if user == nil {
  1807. br.Msg = "请登录"
  1808. br.ErrMsg = "请登录,SysUser Is Empty"
  1809. return
  1810. }
  1811. pageSize, _ := this.GetInt("PageSize")
  1812. chartPermissionIds := this.GetString("ChartPermissionIds")
  1813. activityTypeIds := this.GetString("ActivityTypeIds")
  1814. whichDay := this.GetString("WhichDay")
  1815. isShowJurisdiction, _ := this.GetInt("IsShowJurisdiction")
  1816. activeState := this.GetString("ActiveState")
  1817. label := this.GetString("Label")
  1818. //入参为 undefined 时的处理
  1819. if chartPermissionIds == "undefined" {
  1820. chartPermissionIds = ""
  1821. }
  1822. if activityTypeIds == "undefined" {
  1823. activityTypeIds = ""
  1824. }
  1825. if whichDay == "undefined" {
  1826. whichDay = ""
  1827. }
  1828. if activeState == "undefined" {
  1829. activeState = ""
  1830. }
  1831. if label == "undefined" {
  1832. label = ""
  1833. }
  1834. userType, permissionStr, err := services.GetUserType(user.CompanyId)
  1835. if err != nil {
  1836. br.Msg = "获取失败"
  1837. br.ErrMsg = "获取失败,Err:" + err.Error()
  1838. return
  1839. }
  1840. if isShowJurisdiction == 1 && chartPermissionIds == "" && userType == 4 {
  1841. activityTypeIds = "1,3"
  1842. }
  1843. var startSize int
  1844. pageSize = 15
  1845. var condition string
  1846. var sortTime string
  1847. var pars []interface{}
  1848. //活动可见限制
  1849. var sqlExport string
  1850. slicePer := strings.Split(permissionStr, ",")
  1851. var permissionSqlStr string
  1852. for _, v := range slicePer {
  1853. if userType == 1 {
  1854. if v != "研选" {
  1855. permissionSqlStr += "'" + v + "',"
  1856. }
  1857. } else {
  1858. permissionSqlStr += "'" + v + "',"
  1859. }
  1860. }
  1861. permissionSqlStr = strings.TrimRight(permissionSqlStr, ",")
  1862. permissionSqlStr = strings.Replace(permissionSqlStr, "(主观)", "", -1)
  1863. permissionSqlStr = strings.Replace(permissionSqlStr, "(客观)", "", -1)
  1864. permissionSqlStr = ` AND art.chart_permission_name IN (` + permissionSqlStr + `)`
  1865. sqlExport = ` AND (art.customer_type_ids LIKE '%` + strconv.Itoa(userType) + `%' `
  1866. if userType == 2 {
  1867. sqlExport += ` OR art.customer_type_ids LIKE '%3%' `
  1868. }
  1869. if (userType == 2 || userType == 3) && strings.Contains(permissionStr, "专家") {
  1870. sqlExport += ` OR art.customer_type_ids LIKE '%4%' `
  1871. }
  1872. sqlExport += `) `
  1873. condition += ` AND art.publish_status = 1 AND art.label != '' `
  1874. var conditionOr string
  1875. if (userType == 2 || userType == 3 || userType == 4) && strings.Contains(permissionStr, "专家") {
  1876. conditionOr += ` OR ( art.is_limit_people = 1 AND art.customer_type_ids LIKE '%4%' ` + condition + `) `
  1877. }
  1878. if (userType == 5) && strings.Contains(permissionStr, "专家") {
  1879. conditionOr += ` OR ( art.is_limit_people = 1 AND art.customer_type_ids LIKE '%5%' ` + condition + `) `
  1880. }
  1881. if userType == 1 {
  1882. conditionOr += ` OR ( art.is_limit_people = 0 ` + condition + permissionSqlStr + `) `
  1883. } else {
  1884. conditionOr += ` OR ( art.is_limit_people = 0 ` + condition + `) `
  1885. }
  1886. condition += `AND art.is_limit_people = 1 ` + permissionSqlStr + sqlExport + conditionOr
  1887. resp := new(models.GetCygxActivityLabelListRep)
  1888. //主题
  1889. if label != "" {
  1890. sortTime = ` timesort DESC `
  1891. listAll, errList := models.GetActivityLabelListAll(condition, sortTime, pars, startSize, 32)
  1892. if errList != nil {
  1893. br.Msg = "获取失败"
  1894. br.ErrMsg = "获取失败,Err:" + errList.Error()
  1895. return
  1896. }
  1897. sortTime = ` mintimesort ASC `
  1898. condition += ` AND art.active_state = 1 `
  1899. list1, errList := models.GetActivityLabelListAll(condition, sortTime, pars, startSize, 16)
  1900. if errList != nil {
  1901. br.Msg = "获取失败"
  1902. br.ErrMsg = "获取失败,Err:" + errList.Error()
  1903. return
  1904. }
  1905. for _, v := range listAll {
  1906. var isHAve bool
  1907. for _, v2 := range list1 {
  1908. if v2.KeyWord == v.KeyWord {
  1909. isHAve = true
  1910. }
  1911. }
  1912. if !isHAve {
  1913. resp.List = append(resp.List, v)
  1914. }
  1915. }
  1916. resp.Label = label
  1917. resp.ImgUrl = ""
  1918. br.Ret = 200
  1919. br.Success = true
  1920. br.Msg = "获取成功"
  1921. br.Data = resp
  1922. return
  1923. } else {
  1924. //行业名称
  1925. condition = ` AND art.publish_status = 1 AND art.label != '' `
  1926. if len(chartPermissionIds) > 0 {
  1927. condition += ` AND art.chart_permission_id IN (` + chartPermissionIds + `)`
  1928. }
  1929. if activityTypeIds != "" {
  1930. condition += ` AND art.activity_type_id IN (` + activityTypeIds + `)`
  1931. }
  1932. var conditionOr string
  1933. if whichDay != "" {
  1934. var startDate string
  1935. var endDate string
  1936. if whichDay == "1" {
  1937. startDate = time.Now().Format(utils.FormatDate)
  1938. endDate = startDate
  1939. } else if whichDay == "2" {
  1940. startDate = time.Now().AddDate(0, 0, +1).Format(utils.FormatDate)
  1941. endDate = startDate
  1942. } else {
  1943. startDate = time.Now().Format(utils.FormatDate)
  1944. endDate = time.Now().AddDate(0, 0, +1).Format(utils.FormatDate)
  1945. }
  1946. condition += ` AND art.activity_time >= ` + "'" + startDate + " 00:00:00'"
  1947. condition += ` AND art.activity_time <= ` + "'" + endDate + " 23:59:59'"
  1948. }
  1949. if activeState != "" {
  1950. condition += ` AND art.active_state IN (` + activeState + `)`
  1951. } else {
  1952. condition += ` AND art.active_state IN (1)`
  1953. }
  1954. if (userType == 2 || userType == 3 || userType == 4) && strings.Contains(permissionStr, "专家") {
  1955. conditionOr += ` OR ( art.is_limit_people = 1 AND art.customer_type_ids LIKE '%4%' ` + condition + `) `
  1956. }
  1957. if (userType == 5) && strings.Contains(permissionStr, "专家") {
  1958. conditionOr += ` OR ( art.is_limit_people = 1 AND art.customer_type_ids LIKE '%5%' ` + condition + `) `
  1959. }
  1960. if userType == 1 {
  1961. conditionOr += ` OR ( art.is_limit_people = 0 ` + condition + permissionSqlStr + `) `
  1962. } else {
  1963. conditionOr += ` OR ( art.is_limit_people = 0 ` + condition + `) `
  1964. }
  1965. condition += `AND art.is_limit_people = 1 ` + permissionSqlStr + sqlExport + conditionOr
  1966. }
  1967. sortTime = ` mintimesort ASC `
  1968. list, errList := models.GetActivityLabelListAll(condition, sortTime, pars, startSize, pageSize)
  1969. if errList != nil {
  1970. br.Msg = "获取失败"
  1971. br.ErrMsg = "获取失败,Err:" + errList.Error()
  1972. return
  1973. }
  1974. resp.List = list
  1975. br.Ret = 200
  1976. br.Success = true
  1977. br.Msg = "获取成功"
  1978. br.Data = resp
  1979. }
  1980. // @Title 活动带问
  1981. // @Description 新增活动带问接口
  1982. // @Param request body models.AddCygxActivityHelpAsk true "type json string"
  1983. // @Success Ret=200 新增成功
  1984. // @router /askAdd [post]
  1985. func (this *ActivityCoAntroller) AskAdd() {
  1986. br := new(models.BaseResponse).Init()
  1987. defer func() {
  1988. this.Data["json"] = br
  1989. this.ServeJSON()
  1990. }()
  1991. user := this.User
  1992. if user == nil {
  1993. br.Msg = "请登录"
  1994. br.ErrMsg = "请登录,SysUser Is Empty"
  1995. br.Ret = 408
  1996. return
  1997. }
  1998. var req models.CygxActivityHelpAsk
  1999. err := json.Unmarshal(this.Ctx.Input.RequestBody, &req)
  2000. if err != nil {
  2001. br.Msg = "参数解析异常!"
  2002. br.ErrMsg = "参数解析失败,Err:" + err.Error()
  2003. return
  2004. }
  2005. if req.Content == "" {
  2006. br.Msg = "建议内容不可为空"
  2007. return
  2008. }
  2009. content := req.Content
  2010. itemToken, err := services.WxGetToken()
  2011. if err != nil {
  2012. br.Msg = "GetWxAccessToken Err:" + err.Error()
  2013. return
  2014. }
  2015. if itemToken.AccessToken == "" {
  2016. br.Msg = "accessToken is empty"
  2017. return
  2018. }
  2019. commerr, err := weapp.MSGSecCheck(itemToken.AccessToken, content)
  2020. if err != nil {
  2021. br.Msg = "内容校验失败!"
  2022. br.ErrMsg = "内容校验失败,Err:" + err.Error()
  2023. return
  2024. }
  2025. if commerr.ErrCode != 0 {
  2026. br.Msg = "内容违规,请重新提交!"
  2027. br.ErrMsg = "颜文字内容违规,Err:" + commerr.ErrMSG
  2028. return
  2029. }
  2030. activityId := req.ActivityId
  2031. activityInfo, errInfo := models.GetAddActivityInfoById(activityId)
  2032. if activityInfo == nil {
  2033. br.Msg = "操作失败"
  2034. br.ErrMsg = "活动ID错误,不存在activityId:" + strconv.Itoa(activityId)
  2035. return
  2036. }
  2037. if errInfo != nil {
  2038. br.Msg = "操作失败"
  2039. br.ErrMsg = "操作失败,Err:" + errInfo.Error()
  2040. return
  2041. }
  2042. companyDetail, err := models.GetCompanyDetailById(user.CompanyId)
  2043. if err != nil {
  2044. br.Msg = "提交失败!"
  2045. br.ErrMsg = "获取客户详情失败,Err:" + err.Error()
  2046. return
  2047. }
  2048. if companyDetail == nil {
  2049. br.Msg = "提交失败!"
  2050. br.ErrMsg = "客户不存在,uid:" + strconv.Itoa(user.UserId)
  2051. return
  2052. }
  2053. item := new(models.CygxActivityHelpAsk)
  2054. item.UserId = user.UserId
  2055. item.ActivityId = req.ActivityId
  2056. item.CompanyId = user.CompanyId
  2057. item.CompanyName = companyDetail.CompanyName
  2058. item.CreateTime = time.Now()
  2059. item.Mobile = user.Mobile
  2060. item.Email = user.Email
  2061. item.Content = content
  2062. _, err = models.AddActivityHelpAsk(item)
  2063. if err != nil {
  2064. br.Msg = "提交失败"
  2065. br.ErrMsg = "提交带问失败,Err:" + err.Error()
  2066. return
  2067. }
  2068. var isSendMsg bool
  2069. resultTime := utils.StrTimeToTime(activityInfo.ActivityTime) //时间字符串格式转时间格式
  2070. if activityInfo.ActivityTypeId == 1 && activityInfo.ChartPermissionId != 31 {
  2071. if time.Now().After(resultTime.Add(-time.Minute * 15)) {
  2072. isSendMsg = true
  2073. }
  2074. } else {
  2075. if time.Now().After(resultTime.Add(-time.Minute * 60)) {
  2076. isSendMsg = true
  2077. }
  2078. }
  2079. if isSendMsg {
  2080. listEmail, err := models.GetAskEmail()
  2081. if err != nil {
  2082. br.Msg = "提交失败"
  2083. br.ErrMsg = "提交带问失败,Err:" + err.Error()
  2084. return
  2085. }
  2086. var sendMobile string
  2087. for _, v := range listEmail {
  2088. if strings.Index(activityInfo.Host, v.Name) > 0 {
  2089. sendMobile = v.Mobile
  2090. }
  2091. }
  2092. if activityInfo.ChartPermissionId == 31 {
  2093. sendMobile = utils.ActSendMsgMobile
  2094. }
  2095. //获取销售信息
  2096. sellerItem, err := models.GetSellerByCompanyIdCheckFicc(user.CompanyId, 2)
  2097. if err != nil && err.Error() != utils.ErrNoRow() {
  2098. br.Msg = "提交失败"
  2099. br.ErrMsg = "获取销售信息失败,Err:" + err.Error()
  2100. return
  2101. }
  2102. //给研究员发送消息
  2103. if sendMobile != "" {
  2104. openIpItem, _ := models.GetUserRecordByMobile(4, sendMobile)
  2105. if openIpItem != nil && openIpItem.OpenId != "" {
  2106. if sellerItem != nil {
  2107. services.SendActivityAskApplyTemplateMsg(user.RealName+"——"+user.CompanyName+"(所属销售:"+sellerItem.RealName+")", time.Now().Format(utils.FormatDateTime), req.Content, activityInfo.ActivityName, openIpItem.OpenId, activityInfo.ActivityId)
  2108. }
  2109. }
  2110. }
  2111. // 给所属销售发送消息
  2112. if sellerItem != nil {
  2113. openIpItem, _ := models.GetUserRecordByMobile(4, sellerItem.Mobile)
  2114. if openIpItem != nil && openIpItem.OpenId != "" {
  2115. services.SendActivityAskApplyTemplateMsg(user.RealName+"——"+user.CompanyName+"(所属销售:"+sellerItem.RealName+")", time.Now().Format(utils.FormatDateTime), req.Content, activityInfo.ActivityName, openIpItem.OpenId, activityInfo.ActivityId)
  2116. }
  2117. }
  2118. }
  2119. br.Ret = 200
  2120. br.Success = true
  2121. br.Msg = "提交成功"
  2122. }
  2123. // @Title 活动类型下的主题列表(4.3版本)
  2124. // @Description 获取活动类型下的主题列表接口(4.3版本)
  2125. // @Param ChartPermissionIds query string false "行业id 多个用 , 隔开"
  2126. // @Param ActivityTypeIds query string false "活动类型id 多个用 , 隔开"
  2127. // @Param ActiveState query string false "活动进行状态 未开始:1、进行中2、已结束3"
  2128. // @Param WhichDay query string false "哪一天 今天:1、明天:2,多个用 , 隔开"
  2129. // @Param IsPower query int false "是否选择有权限行业 ,1是 0 否 默认0"
  2130. // @Success 200 {object} models.ActivityTypeListHomeResp
  2131. // @router /labelTypeList [get]
  2132. func (this *ActivityCoAntroller) LabelTypeList() {
  2133. br := new(models.BaseResponse).Init()
  2134. defer func() {
  2135. this.Data["json"] = br
  2136. this.ServeJSON()
  2137. }()
  2138. user := this.User
  2139. if user == nil {
  2140. br.Msg = "请登录"
  2141. br.ErrMsg = "请登录,SysUser Is Empty"
  2142. return
  2143. }
  2144. pageSize, _ := this.GetInt("PageSize")
  2145. isPower, _ := this.GetInt("IsPower")
  2146. //currentIndex, _ := this.GetInt("CurrentIndex")
  2147. chartPermissionIds := this.GetString("ChartPermissionIds")
  2148. //activityTypeIds := this.GetString("ActivityTypeIds")
  2149. whichDay := this.GetString("WhichDay")
  2150. activeState := this.GetString("ActiveState")
  2151. //入参为 undefined 时的处理
  2152. if chartPermissionIds == "undefined" {
  2153. chartPermissionIds = ""
  2154. }
  2155. if whichDay == "undefined" {
  2156. whichDay = ""
  2157. }
  2158. if activeState == "undefined" || activeState == "" {
  2159. activeState = "1"
  2160. }
  2161. userType, permissionStr, err := services.GetUserType(user.CompanyId)
  2162. if err != nil {
  2163. br.Msg = "获取失败"
  2164. br.ErrMsg = "获取失败,Err:" + err.Error()
  2165. return
  2166. }
  2167. var startSize int
  2168. pageSize = 40
  2169. var sortTime string
  2170. var pars []interface{}
  2171. //活动可见限制
  2172. slicePer := strings.Split(permissionStr, ",")
  2173. var permissionSqlStr string
  2174. var permissionNameStr string
  2175. for _, v := range slicePer {
  2176. if userType == 1 {
  2177. if v != "研选" {
  2178. permissionNameStr += "'" + v + "',"
  2179. }
  2180. } else {
  2181. permissionNameStr += "'" + v + "',"
  2182. }
  2183. }
  2184. permissionNameStr = strings.Replace(permissionNameStr, "(主观)", "", -1)
  2185. permissionNameStr = strings.Replace(permissionNameStr, "(客观)", "", -1)
  2186. permissionNameStr = strings.TrimRight(permissionNameStr, ",")
  2187. list, err := models.GetActivityTypeHomeList()
  2188. if err != nil {
  2189. br.Msg = "获取失败"
  2190. br.ErrMsg = "获取数据失败,Err:" + err.Error()
  2191. return
  2192. }
  2193. resp := new(models.ActivityTypeListHomeResp)
  2194. for k, v := range list {
  2195. var sqlExport string
  2196. var condition string
  2197. permissionSqlStr = ` AND art.chart_permission_name IN (` + permissionNameStr + `)`
  2198. sqlExport = ` AND (art.customer_type_ids LIKE '%` + strconv.Itoa(userType) + `%' `
  2199. if userType == 2 {
  2200. sqlExport += ` OR art.customer_type_ids LIKE '%3%' `
  2201. }
  2202. if (userType == 2 || userType == 3) && strings.Contains(permissionStr, "专家") {
  2203. sqlExport += ` OR art.customer_type_ids LIKE '%4%' `
  2204. }
  2205. sqlExport += `) `
  2206. condition = ` AND art.publish_status = 1 AND art.label != '' AND art.activity_type_id = ` + strconv.Itoa(v.ActivityTypeId)
  2207. if isPower == 1 {
  2208. condition += permissionSqlStr
  2209. }
  2210. //行业名称
  2211. if len(chartPermissionIds) > 0 {
  2212. condition += ` AND art.chart_permission_id IN (` + chartPermissionIds + `)`
  2213. }
  2214. var conditionOr string
  2215. if whichDay != "" {
  2216. var startDate string
  2217. var endDate string
  2218. if whichDay == "1" {
  2219. startDate = time.Now().Format(utils.FormatDate)
  2220. endDate = startDate
  2221. } else if whichDay == "2" {
  2222. startDate = time.Now().AddDate(0, 0, +1).Format(utils.FormatDate)
  2223. endDate = startDate
  2224. } else {
  2225. startDate = time.Now().Format(utils.FormatDate)
  2226. endDate = time.Now().AddDate(0, 0, +1).Format(utils.FormatDate)
  2227. }
  2228. condition += ` AND art.activity_time >= ` + "'" + startDate + " 00:00:00'"
  2229. condition += ` AND art.activity_time <= ` + "'" + endDate + " 23:59:59'"
  2230. }
  2231. if activeState != "" {
  2232. condition += ` AND art.active_state IN (` + activeState + `)`
  2233. } else {
  2234. condition += ` AND art.active_state IN (1)`
  2235. }
  2236. if (userType == 2 || userType == 3 || userType == 4) && strings.Contains(permissionStr, "专家") {
  2237. conditionOr += ` OR ( art.is_limit_people = 1 AND art.customer_type_ids LIKE '%4%' ` + condition + `) `
  2238. }
  2239. if (userType == 5) && strings.Contains(permissionStr, "专家") {
  2240. conditionOr += ` OR ( art.is_limit_people = 1 AND art.customer_type_ids LIKE '%5%' ` + condition + `) `
  2241. }
  2242. if userType == 1 {
  2243. conditionOr += ` OR ( art.is_limit_people = 0 ` + condition + permissionSqlStr + `) `
  2244. } else {
  2245. conditionOr += ` OR ( art.is_limit_people = 0 ` + condition + `) `
  2246. }
  2247. //判断客户规模是否属于可见范围的活动
  2248. companyProduct, err := models.GetCompanyProductDetail(user.CompanyId, 2)
  2249. if err != nil {
  2250. br.Msg = "获取信息失败"
  2251. br.ErrMsg = "获取客户信息失败,Err:" + err.Error()
  2252. return
  2253. }
  2254. if companyProduct.Scale != "" {
  2255. conditionOr += ` OR ( art.scale LIKE '%` + companyProduct.Scale + `%' ` + condition + `) `
  2256. }
  2257. condition += `AND art.is_limit_people = 1 ` + permissionSqlStr + sqlExport + conditionOr
  2258. sortTime = ` mintimesort ASC `
  2259. labelList, err := models.GetActivityLabelListAll(condition, sortTime, pars, startSize, pageSize)
  2260. if err != nil {
  2261. br.Msg = "获取失败"
  2262. br.ErrMsg = "获取失败,Err:" + err.Error()
  2263. return
  2264. }
  2265. //标签字段关联的产业与标签处理
  2266. for k2, v2 := range labelList {
  2267. labelList[k2].KeyWord = services.LabelStr(v2.KeyWord)
  2268. labelList[k2].ImgUrlBg = v.ImgUrlBgs
  2269. }
  2270. list[k].List = labelList
  2271. }
  2272. //获取对应活动的数量并排序
  2273. intArr := make([]int, 0)
  2274. var items []*models.ActivityTypeHome
  2275. for _, v := range list {
  2276. item := new(models.ActivityTypeHome)
  2277. if len(v.List) > 0 {
  2278. item.List = v.List
  2279. item.ActivityTypeName = v.ActivityTypeName
  2280. item.ActivityTypeId = v.ActivityTypeId
  2281. item.ImgUrlBg = v.ImgUrlBg
  2282. item.ImgUrl = v.ImgUrl
  2283. items = append(items, item)
  2284. intArr = append(intArr, len(v.List))
  2285. }
  2286. }
  2287. sort.Sort(sort.Reverse(sort.IntSlice(intArr)))
  2288. var itemsNew []*models.ActivityTypeHome
  2289. activityMap := make(map[int]int)
  2290. for _, v := range intArr {
  2291. for _, v2 := range items {
  2292. item := new(models.ActivityTypeHome)
  2293. if len(v2.List) > 0 && v == len(v2.List) && activityMap[v2.ActivityTypeId] == 0 {
  2294. item.List = v2.List
  2295. item.ActivityTypeName = v2.ActivityTypeName
  2296. item.ActivityTypeId = v2.ActivityTypeId
  2297. item.ImgUrlBg = v2.ImgUrlBg
  2298. item.ImgUrl = v2.ImgUrl
  2299. itemsNew = append(itemsNew, item)
  2300. activityMap[v2.ActivityTypeId] = len(v2.List)
  2301. }
  2302. }
  2303. }
  2304. //如果第三个活动数量比第四个多,则两者调换
  2305. if len(itemsNew) > 3 {
  2306. if len(itemsNew[2].List) > len(itemsNew[3].List) {
  2307. var itemsNewCopy []*models.ActivityTypeHome
  2308. for _, v := range itemsNew {
  2309. itemsNewCopy = append(itemsNewCopy, v)
  2310. }
  2311. itemsNew[2] = itemsNewCopy[3]
  2312. itemsNew[3] = itemsNewCopy[2]
  2313. }
  2314. }
  2315. //记录用户搜索的筛选条件
  2316. item := new(models.CygxActivitySearchHistory)
  2317. item.UserId = user.UserId
  2318. item.Mobile = user.Mobile
  2319. item.CompanyId = user.CompanyId
  2320. item.CompanyName = user.CompanyName
  2321. item.CreateTime = time.Now()
  2322. item.ChartPermissionIds = chartPermissionIds
  2323. item.IsPower = isPower
  2324. item.WhichDay = whichDay
  2325. go models.AddCygxActivitySearchHistory(item)
  2326. resp.List = itemsNew
  2327. br.Ret = 200
  2328. br.Success = true
  2329. br.Msg = "获取成功"
  2330. br.Data = resp
  2331. }
  2332. // @Title 更多主题列表(4.3版本)
  2333. // @Description 获取活动更多主题列表接口(4.3版本)
  2334. // @Success 200 {object} models.GetCygxActivityLabelListRep
  2335. // @router /labelMoreList [get]
  2336. func (this *ActivityCoAntroller) LabelMoreList() {
  2337. br := new(models.BaseResponse).Init()
  2338. defer func() {
  2339. this.Data["json"] = br
  2340. this.ServeJSON()
  2341. }()
  2342. user := this.User
  2343. if user == nil {
  2344. br.Msg = "请登录"
  2345. br.ErrMsg = "请登录,SysUser Is Empty"
  2346. return
  2347. }
  2348. userType, permissionStr, err := services.GetUserType(user.CompanyId)
  2349. if err != nil {
  2350. br.Msg = "获取失败"
  2351. br.ErrMsg = "获取失败,Err:" + err.Error()
  2352. return
  2353. }
  2354. var startSize, pageSize int
  2355. pageSize = 24
  2356. var condition string
  2357. var sortTime string
  2358. //var conditionStatus string
  2359. var pars []interface{}
  2360. //活动可见限制
  2361. var sqlExport string
  2362. resp := new(models.GetCygxActivityLabelListRep)
  2363. slicePer := strings.Split(permissionStr, ",")
  2364. var permissionSqlStr string
  2365. for _, v := range slicePer {
  2366. if userType == 1 {
  2367. if v != "研选" {
  2368. permissionSqlStr += "'" + v + "',"
  2369. }
  2370. } else {
  2371. permissionSqlStr += "'" + v + "',"
  2372. }
  2373. }
  2374. permissionSqlStr = strings.TrimRight(permissionSqlStr, ",")
  2375. permissionSqlStr = strings.Replace(permissionSqlStr, "(主观)", "", -1)
  2376. permissionSqlStr = strings.Replace(permissionSqlStr, "(客观)", "", -1)
  2377. permissionSqlStr = ` AND art.chart_permission_name IN (` + permissionSqlStr + `)`
  2378. sqlExport = ` AND (art.customer_type_ids LIKE '%` + strconv.Itoa(userType) + `%' `
  2379. if userType == 2 {
  2380. sqlExport += ` OR art.customer_type_ids LIKE '%3%' `
  2381. }
  2382. if (userType == 2 || userType == 3) && strings.Contains(permissionStr, "专家") {
  2383. sqlExport += ` OR art.customer_type_ids LIKE '%4%' `
  2384. }
  2385. sqlExport += `) `
  2386. //进行中的活动
  2387. condition = ` AND art.publish_status = 1 AND art.label != '' AND art.active_state = 2 `
  2388. var conditionOr string
  2389. if (userType == 2 || userType == 3 || userType == 4) && strings.Contains(permissionStr, "专家") {
  2390. conditionOr += ` OR ( art.is_limit_people = 1 AND art.customer_type_ids LIKE '%4%' ` + condition + `) `
  2391. }
  2392. if (userType == 5) && strings.Contains(permissionStr, "专家") {
  2393. conditionOr += ` OR ( art.is_limit_people = 1 AND art.customer_type_ids LIKE '%5%' ` + condition + `) `
  2394. }
  2395. if userType == 1 {
  2396. conditionOr += ` OR ( art.is_limit_people = 0 ` + condition + permissionSqlStr + `) `
  2397. } else {
  2398. conditionOr += ` OR ( art.is_limit_people = 0 ` + condition + `) `
  2399. }
  2400. //判断客户规模是否属于可见范围的活动
  2401. companyProduct, err := models.GetCompanyProductDetail(user.CompanyId, 2)
  2402. if err != nil {
  2403. br.Msg = "获取信息失败"
  2404. br.ErrMsg = "获取客户信息失败,Err:" + err.Error()
  2405. return
  2406. }
  2407. if companyProduct.Scale != "" {
  2408. conditionOr += ` OR ( art.scale LIKE '%` + companyProduct.Scale + `%' ` + condition + `) `
  2409. }
  2410. condition += `AND art.is_limit_people = 1 ` + permissionSqlStr + sqlExport + conditionOr
  2411. //进行中的活动
  2412. sortTime = ` mintimesort ASC `
  2413. list, errList := models.GetActivityLabelListAll(condition, sortTime, pars, startSize, pageSize)
  2414. if errList != nil {
  2415. br.Msg = "获取失败"
  2416. br.ErrMsg = "获取失败,Err:" + errList.Error()
  2417. return
  2418. }
  2419. //已结束的活动
  2420. conditionOr = ""
  2421. condition = ` AND art.publish_status = 1 AND art.label != '' AND art.active_state = 3 `
  2422. if (userType == 2 || userType == 3 || userType == 4) && strings.Contains(permissionStr, "专家") {
  2423. conditionOr += ` OR ( art.is_limit_people = 1 AND art.customer_type_ids LIKE '%4%' ` + condition + `) `
  2424. }
  2425. if (userType == 5) && strings.Contains(permissionStr, "专家") {
  2426. conditionOr += ` OR ( art.is_limit_people = 1 AND art.customer_type_ids LIKE '%5%' ` + condition + `) `
  2427. }
  2428. if userType == 1 {
  2429. conditionOr += ` OR ( art.is_limit_people = 0 ` + condition + permissionSqlStr + `) `
  2430. } else {
  2431. conditionOr += ` OR ( art.is_limit_people = 0 ` + condition + `) `
  2432. }
  2433. condition += `AND art.is_limit_people = 1 ` + permissionSqlStr + sqlExport + conditionOr
  2434. startSize = 0
  2435. pageSize = 24 - len(list)
  2436. //已结束的活动
  2437. sortTime = ` timesort DESC `
  2438. listEnd, err := models.GetActivityLabelListAll(condition, sortTime, pars, startSize, pageSize)
  2439. if err != nil {
  2440. br.Msg = "获取失败"
  2441. br.ErrMsg = "获取失败,Err:" + err.Error()
  2442. return
  2443. }
  2444. for _, v := range listEnd {
  2445. list = append(list, v)
  2446. }
  2447. //标签字段关联的产业与标签处理
  2448. for k, v := range list {
  2449. list[k].KeyWord = services.LabelStr(v.KeyWord)
  2450. }
  2451. //添加更多主题访问记录
  2452. item := new(models.CygxPageHistoryRecord)
  2453. item.UserId = user.UserId
  2454. item.CreateTime = time.Now()
  2455. item.Mobile = user.Mobile
  2456. item.Email = user.Email
  2457. item.CompanyId = user.CompanyId
  2458. item.CompanyName = user.CompanyName
  2459. item.PageType = "LabelMore"
  2460. go models.AddCygxPageHistoryRecord(item)
  2461. resp.List = list
  2462. br.Ret = 200
  2463. br.Success = true
  2464. br.Msg = "获取成功"
  2465. br.Data = resp
  2466. }
  2467. // @Title 活动列表(4.3版本)
  2468. // @Description 获取活动列表接口(4.3版本)
  2469. // @Param PageSize query int true "每页数据条数"
  2470. // @Param CurrentIndex query int true "当前页页码,从1开始"
  2471. // @Param Label query string false "搜索主题 多个用 , 隔开"
  2472. // @Param ChartPermissionIds query string false "行业id 多个用 , 隔开"
  2473. // @Param WhichDay query string false "哪一天 今天:1、明天:2,多个用 , 隔开"
  2474. // @Param ActiveState query string false "活动进行状态 未开始:1、进行中2、已结束3"
  2475. // @Param ActivityTypeId query string false "活动类型id 多个用 , 隔开"
  2476. // @Success 200 {object} models.GetCygxActivityListRep
  2477. // @router /listNew [get]
  2478. func (this *ActivityCoAntroller) ActivityListNew() {
  2479. br := new(models.BaseResponse).Init()
  2480. defer func() {
  2481. this.Data["json"] = br
  2482. this.ServeJSON()
  2483. }()
  2484. user := this.User
  2485. if user == nil {
  2486. br.Msg = "请登录"
  2487. br.ErrMsg = "请登录,SysUser Is Empty"
  2488. return
  2489. }
  2490. uid := user.UserId
  2491. pageSize, _ := this.GetInt("PageSize")
  2492. currentIndex, _ := this.GetInt("CurrentIndex")
  2493. label := this.GetString("Label")
  2494. chartPermissionIds := this.GetString("ChartPermissionIds")
  2495. whichDay := this.GetString("WhichDay")
  2496. activeState := this.GetString("ActiveState")
  2497. activityTypeId := this.GetString("ActivityTypeId")
  2498. if label == "undefined" {
  2499. label = ""
  2500. }
  2501. if chartPermissionIds == "undefined" {
  2502. chartPermissionIds = ""
  2503. }
  2504. if whichDay == "undefined" {
  2505. whichDay = ""
  2506. }
  2507. if activeState == "undefined" {
  2508. activeState = ""
  2509. }
  2510. if activityTypeId == "undefined" {
  2511. activityTypeId = ""
  2512. }
  2513. var startSize int
  2514. if pageSize <= 0 {
  2515. pageSize = utils.PageSize20
  2516. }
  2517. if currentIndex <= 0 {
  2518. currentIndex = 1
  2519. }
  2520. startSize = utils.StartIndex(currentIndex, pageSize)
  2521. userType, permissionStr, err := services.GetUserType(user.CompanyId)
  2522. var condition string
  2523. var pars []interface{}
  2524. //活动可见限制
  2525. var sqlExport string
  2526. slicePer := strings.Split(permissionStr, ",")
  2527. var permissionSqlStr string
  2528. for _, v := range slicePer {
  2529. if userType == 1 {
  2530. if v != "研选" {
  2531. permissionSqlStr += "'" + v + "',"
  2532. }
  2533. } else {
  2534. permissionSqlStr += "'" + v + "',"
  2535. }
  2536. }
  2537. permissionSqlStr = strings.TrimRight(permissionSqlStr, ",")
  2538. permissionSqlStr = strings.Replace(permissionSqlStr, "(主观)", "", -1)
  2539. permissionSqlStr = strings.Replace(permissionSqlStr, "(客观)", "", -1)
  2540. permissionSqlStr = ` AND art.chart_permission_name IN (` + permissionSqlStr + `)`
  2541. sqlExport = ` AND (art.customer_type_ids LIKE '%` + strconv.Itoa(userType) + `%' `
  2542. if userType == 2 {
  2543. sqlExport += ` OR art.customer_type_ids LIKE '%3%' `
  2544. }
  2545. if (userType == 2 || userType == 3) && strings.Contains(permissionStr, "专家") {
  2546. sqlExport += ` OR art.customer_type_ids LIKE '%4%' `
  2547. }
  2548. sqlExport += `) `
  2549. //主题
  2550. if label != "" {
  2551. condition = ` AND art.label LIKE '%` + label + `%' `
  2552. }
  2553. if whichDay != "" {
  2554. var startDate string
  2555. var endDate string
  2556. if whichDay == "1" {
  2557. startDate = time.Now().Format(utils.FormatDate)
  2558. endDate = startDate
  2559. } else if whichDay == "2" {
  2560. startDate = time.Now().AddDate(0, 0, +1).Format(utils.FormatDate)
  2561. endDate = startDate
  2562. } else {
  2563. startDate = time.Now().Format(utils.FormatDate)
  2564. endDate = time.Now().AddDate(0, 0, +1).Format(utils.FormatDate)
  2565. }
  2566. condition += ` AND art.activity_time >= ` + "'" + startDate + " 00:00:00'"
  2567. condition += ` AND art.activity_time <= ` + "'" + endDate + " 23:59:59'"
  2568. }
  2569. //行业名称
  2570. if len(chartPermissionIds) > 0 {
  2571. condition += ` AND art.chart_permission_id IN (` + chartPermissionIds + `)`
  2572. }
  2573. if activeState != "" {
  2574. condition += ` AND art.active_state IN (` + activeState + `)`
  2575. } else {
  2576. condition += ` AND art.active_state IN (1)`
  2577. }
  2578. if activityTypeId != "" {
  2579. condition += ` AND art.activity_type_id IN (` + activityTypeId + `)`
  2580. }
  2581. condition += ` AND art.publish_status = 1 `
  2582. var conditionOr string
  2583. // 有专家权限的这几种用户,不做行业权限校验
  2584. if (userType == 2 || userType == 3 || userType == 4) && strings.Contains(permissionStr, "专家") {
  2585. conditionOr += ` OR ( art.is_limit_people = 1 AND art.customer_type_ids LIKE '%4%' ` + condition + `) `
  2586. }
  2587. if (userType == 5) && strings.Contains(permissionStr, "专家") {
  2588. conditionOr += ` OR ( art.is_limit_people = 1 AND art.customer_type_ids LIKE '%5%' ` + condition + `) `
  2589. }
  2590. if userType == 1 {
  2591. conditionOr += ` OR ( art.is_limit_people = 0 ` + condition + permissionSqlStr + `) `
  2592. } else {
  2593. conditionOr += ` OR ( art.is_limit_people = 0 ` + condition + `) `
  2594. }
  2595. //判断客户规模是否属于可见范围的活动
  2596. companyProduct, err := models.GetCompanyProductDetail(user.CompanyId, 2)
  2597. if err != nil {
  2598. br.Msg = "获取信息失败"
  2599. br.ErrMsg = "获取客户信息失败,Err:" + err.Error()
  2600. return
  2601. }
  2602. if companyProduct.Scale != "" {
  2603. conditionOr += ` OR ( art.scale LIKE '%` + companyProduct.Scale + `%' ` + condition + `) `
  2604. }
  2605. condition += ` AND art.is_limit_people = 1 ` + permissionSqlStr + sqlExport + conditionOr
  2606. total, err := models.GetActivityCount(condition, pars)
  2607. if err != nil {
  2608. br.Msg = "获取失败"
  2609. br.ErrMsg = "获取失败,Err:" + err.Error()
  2610. return
  2611. }
  2612. if activeState == "2" || activeState == "3" {
  2613. condition += ` ORDER BY art.activity_time DESC `
  2614. } else if activeState == "2,3" {
  2615. condition += ` ORDER BY art.active_state ASC, art.activity_time DESC `
  2616. } else {
  2617. condition += ` ORDER BY art.active_state ASC, art.activity_time ASC `
  2618. }
  2619. list, errList := models.GetActivityListAll(condition, pars, uid, startSize, pageSize)
  2620. if errList != nil {
  2621. br.Msg = "获取失败"
  2622. br.ErrMsg = "获取失败,Err:" + errList.Error()
  2623. return
  2624. }
  2625. var isShow bool
  2626. isShow = services.GetShowSustainable()
  2627. detail, err := models.GetConfigByCode("city_img_url")
  2628. if err != nil {
  2629. br.Msg = "获取数据失败"
  2630. br.ErrMsg = "城市配置信息失败,Err:" + err.Error()
  2631. return
  2632. }
  2633. detailChart, err := models.GetConfigByCode("chart_img_url")
  2634. if err != nil {
  2635. br.Msg = "获取数据失败"
  2636. br.ErrMsg = "行业配置信息失败,Err:" + err.Error()
  2637. return
  2638. }
  2639. addressList := strings.Split(detail.ConfigValue, "{|}")
  2640. mapAddress := make(map[string]string)
  2641. chartList := strings.Split(detailChart.ConfigValue, "{|}")
  2642. mapChart := make(map[string]string)
  2643. var cityName string
  2644. var chartName string
  2645. var imgUrl string
  2646. var imgUrlChart string
  2647. for _, v := range addressList {
  2648. vslice := strings.Split(v, "_")
  2649. cityName = vslice[0]
  2650. imgUrl = vslice[len(vslice)-1]
  2651. mapAddress[cityName] = imgUrl
  2652. }
  2653. for _, v := range chartList {
  2654. vslice := strings.Split(v, "_")
  2655. chartName = vslice[0]
  2656. imgUrlChart = vslice[len(vslice)-1]
  2657. mapChart[chartName] = imgUrlChart
  2658. }
  2659. for k, v := range list {
  2660. if strings.Contains(v.ActivityName, "【") {
  2661. list[k].IsBrackets = 1
  2662. }
  2663. if v.SignupNum > v.LimitPeopleNum {
  2664. list[k].SignupNum = v.LimitPeopleNum
  2665. }
  2666. if isShow && v.ChartPermissionName == "研选" {
  2667. list[k].IsShowSustainable = true
  2668. }
  2669. if v.ChartPermissionName == "研选" && v.ActivityTypeId == 1 {
  2670. list[k].ActivityTypeName = "研选电话会"
  2671. list[k].ImgUrlText = "https://hongze.oss-cn-shanghai.aliyuncs.com/static/images/202112/20211221/bIdfv8t86xrFRpDOeGGHXOmKEuKl.png"
  2672. }
  2673. if v.ActivityType == 0 {
  2674. if mapAddress[v.City] != "" {
  2675. list[k].ImgUrl = mapAddress[v.City]
  2676. } else {
  2677. list[k].ImgUrl = mapAddress["其它"]
  2678. }
  2679. } else {
  2680. if mapChart[v.ChartPermissionName] != "" {
  2681. list[k].ImgUrl = mapChart[v.ChartPermissionName]
  2682. }
  2683. }
  2684. expertTxt, _ := services.GetReportContentTextSub(v.Expert)
  2685. list[k].Expert = expertTxt
  2686. }
  2687. page := paging.GetPaging(currentIndex, pageSize, total)
  2688. resp := new(models.GetCygxActivityListRep)
  2689. resp.Label = label
  2690. if activityTypeId != "" {
  2691. activityTypeIdint, err := strconv.Atoi(activityTypeId)
  2692. if err == nil {
  2693. detail, errDetail := models.GetActivityTypeDetailById(activityTypeIdint)
  2694. if errDetail != nil {
  2695. br.Msg = "获取信息失败"
  2696. br.ErrMsg = "获取信息失败,Err:" + errDetail.Error()
  2697. return
  2698. }
  2699. resp.ImgUrl = detail.OnlineIco
  2700. resp.Label = detail.ActivityTypeName
  2701. }
  2702. }
  2703. resp.List = list
  2704. resp.Paging = page
  2705. br.Ret = 200
  2706. br.Success = true
  2707. br.Msg = "获取成功"
  2708. br.Data = resp
  2709. }
  2710. // @Title 活动类型下的主题列表Pc端
  2711. // @Description 获取活动类型下的主题列表接口Pc端
  2712. // @Param ChartPermissionIds query string false "行业id 多个用 , 隔开"
  2713. // @Param ActivityTypeIds query string false "活动类型id 多个用 , 隔开"
  2714. // @Param ActiveState query string false "活动进行状态 未开始:1、进行中2、已结束3"
  2715. // @Param WhichDay query string false "哪一天 今天:1、明天:2,多个用 , 隔开"
  2716. // @Param IsPower query int false "是否选择有权限行业 ,1是 0 否 默认0"
  2717. // @Success 200 {object} models.ActivityTypeListHomeRespPc
  2718. // @router /labelTypeListPc [get]
  2719. func (this *ActivityCoAntroller) LabelTypeListPc() {
  2720. br := new(models.BaseResponse).Init()
  2721. defer func() {
  2722. this.Data["json"] = br
  2723. this.ServeJSON()
  2724. }()
  2725. user := this.User
  2726. if user == nil {
  2727. br.Msg = "请登录"
  2728. br.ErrMsg = "请登录,SysUser Is Empty"
  2729. return
  2730. }
  2731. pageSize, _ := this.GetInt("PageSize")
  2732. isPower, _ := this.GetInt("IsPower")
  2733. //currentIndex, _ := this.GetInt("CurrentIndex")
  2734. chartPermissionIds := this.GetString("ChartPermissionIds")
  2735. //activityTypeIds := this.GetString("ActivityTypeIds")
  2736. whichDay := this.GetString("WhichDay")
  2737. activeState := this.GetString("ActiveState")
  2738. //入参为 undefined 时的处理
  2739. if chartPermissionIds == "undefined" {
  2740. chartPermissionIds = ""
  2741. }
  2742. if whichDay == "undefined" {
  2743. whichDay = ""
  2744. }
  2745. if activeState == "undefined" || activeState == "" {
  2746. activeState = "1"
  2747. }
  2748. userType, permissionStr, err := services.GetUserType(user.CompanyId)
  2749. if err != nil {
  2750. br.Msg = "获取失败"
  2751. br.ErrMsg = "获取失败,Err:" + err.Error()
  2752. return
  2753. }
  2754. var startSize int
  2755. pageSize = 8
  2756. var sortTime string
  2757. var pars []interface{}
  2758. //活动可见限制
  2759. slicePer := strings.Split(permissionStr, ",")
  2760. var permissionSqlStr string
  2761. var permissionNameStr string
  2762. for _, v := range slicePer {
  2763. if userType == 1 {
  2764. if v != "研选" {
  2765. permissionNameStr += "'" + v + "',"
  2766. }
  2767. } else {
  2768. permissionNameStr += "'" + v + "',"
  2769. }
  2770. }
  2771. permissionNameStr = strings.Replace(permissionNameStr, "(主观)", "", -1)
  2772. permissionNameStr = strings.Replace(permissionNameStr, "(客观)", "", -1)
  2773. permissionNameStr = strings.TrimRight(permissionNameStr, ",")
  2774. list, err := models.GetActivityTypeHomeListPc()
  2775. if err != nil {
  2776. br.Msg = "获取失败"
  2777. br.ErrMsg = "获取数据失败,Err:" + err.Error()
  2778. return
  2779. }
  2780. resp := new(models.ActivityTypeListHomeRespPc)
  2781. for k, v := range list {
  2782. var sqlExport string
  2783. var condition string
  2784. permissionSqlStr = ` AND art.chart_permission_name IN (` + permissionNameStr + `)`
  2785. sqlExport = ` AND (art.customer_type_ids LIKE '%` + strconv.Itoa(userType) + `%' `
  2786. if userType == 2 {
  2787. sqlExport += ` OR art.customer_type_ids LIKE '%3%' `
  2788. }
  2789. if (userType == 2 || userType == 3) && strings.Contains(permissionStr, "专家") {
  2790. sqlExport += ` OR art.customer_type_ids LIKE '%4%' `
  2791. }
  2792. sqlExport += `) `
  2793. condition = ` AND art.publish_status = 1 AND art.label != '' AND art.activity_type_id = ` + strconv.Itoa(v.ActivityTypeId)
  2794. if isPower == 1 {
  2795. condition += permissionSqlStr
  2796. }
  2797. //行业名称
  2798. if len(chartPermissionIds) > 0 {
  2799. condition += ` AND art.chart_permission_id IN (` + chartPermissionIds + `)`
  2800. }
  2801. var conditionOr string
  2802. if whichDay != "" {
  2803. var startDate string
  2804. var endDate string
  2805. if whichDay == "1" {
  2806. startDate = time.Now().Format(utils.FormatDate)
  2807. endDate = startDate
  2808. } else if whichDay == "2" {
  2809. startDate = time.Now().AddDate(0, 0, +1).Format(utils.FormatDate)
  2810. endDate = startDate
  2811. } else {
  2812. startDate = time.Now().Format(utils.FormatDate)
  2813. endDate = time.Now().AddDate(0, 0, +1).Format(utils.FormatDate)
  2814. }
  2815. condition += ` AND art.activity_time >= ` + "'" + startDate + " 00:00:00'"
  2816. condition += ` AND art.activity_time <= ` + "'" + endDate + " 23:59:59'"
  2817. }
  2818. if activeState != "" {
  2819. condition += ` AND art.active_state IN (` + activeState + `)`
  2820. } else {
  2821. condition += ` AND art.active_state IN (1)`
  2822. }
  2823. if (userType == 2 || userType == 3 || userType == 4) && strings.Contains(permissionStr, "专家") {
  2824. conditionOr += ` OR ( art.is_limit_people = 1 AND art.customer_type_ids LIKE '%4%' ` + condition + `) `
  2825. }
  2826. if (userType == 5) && strings.Contains(permissionStr, "专家") {
  2827. conditionOr += ` OR ( art.is_limit_people = 1 AND art.customer_type_ids LIKE '%5%' ` + condition + `) `
  2828. }
  2829. if userType == 1 {
  2830. conditionOr += ` OR ( art.is_limit_people = 0 ` + condition + permissionSqlStr + `) `
  2831. } else {
  2832. conditionOr += ` OR ( art.is_limit_people = 0 ` + condition + `) `
  2833. }
  2834. //判断客户规模是否属于可见范围的活动
  2835. companyProduct, err := models.GetCompanyProductDetail(user.CompanyId, 2)
  2836. if err != nil {
  2837. br.Msg = "获取信息失败"
  2838. br.ErrMsg = "获取客户信息失败,Err:" + err.Error()
  2839. return
  2840. }
  2841. if companyProduct.Scale != "" {
  2842. conditionOr += ` OR ( art.scale LIKE '%` + companyProduct.Scale + `%' ` + condition + `) `
  2843. }
  2844. condition += `AND art.is_limit_people = 1 ` + permissionSqlStr + sqlExport + conditionOr
  2845. sortTime = ` mintimesort ASC `
  2846. labelList, err := models.GetActivityLabelListAll(condition, sortTime, pars, startSize, pageSize)
  2847. if err != nil {
  2848. br.Msg = "获取失败"
  2849. br.ErrMsg = "获取失败,Err:" + err.Error()
  2850. return
  2851. }
  2852. //标签字段关联的产业与标签处理
  2853. for k2, v2 := range labelList {
  2854. labelList[k2].KeyWord = services.LabelStr(v2.KeyWord)
  2855. }
  2856. list[k].List = labelList
  2857. }
  2858. //记录用户搜索的筛选条件
  2859. item := new(models.CygxActivitySearchHistory)
  2860. item.UserId = user.UserId
  2861. item.Mobile = user.Mobile
  2862. item.CompanyId = user.CompanyId
  2863. item.CompanyName = user.CompanyName
  2864. item.CreateTime = time.Now()
  2865. item.ChartPermissionIds = chartPermissionIds
  2866. item.IsPower = isPower
  2867. item.WhichDay = whichDay
  2868. go models.AddCygxActivitySearchHistory(item)
  2869. resp.List = list
  2870. br.Ret = 200
  2871. br.Success = true
  2872. br.Msg = "获取成功"
  2873. br.Data = resp
  2874. }
  2875. // @Title 校验活动带问是否有权限
  2876. // @Description 校验活动带问是否有权限接口
  2877. // @Param request body models.ActivityIdRep true "type json string"
  2878. // @Success Ret=200 {object} models.SignupStatus
  2879. // @router /checkAsk [post]
  2880. func (this *ActivityCoAntroller) CheckAsk() {
  2881. br := new(models.BaseResponse).Init()
  2882. defer func() {
  2883. this.Data["json"] = br
  2884. this.ServeJSON()
  2885. }()
  2886. user := this.User
  2887. if user == nil {
  2888. br.Msg = "请登录"
  2889. br.ErrMsg = "请登录,用户信息为空"
  2890. br.Ret = 408
  2891. return
  2892. }
  2893. uid := user.UserId
  2894. signupStatus := "Success"
  2895. var req models.ActivityIdRep
  2896. err := json.Unmarshal(this.Ctx.Input.RequestBody, &req)
  2897. if err != nil {
  2898. br.Msg = "参数解析异常!"
  2899. br.ErrMsg = "参数解析失败,Err:" + err.Error()
  2900. return
  2901. }
  2902. activityId := req.ActivityId
  2903. activityInfo, errInfo := models.GetAddActivityInfoById(activityId)
  2904. if activityInfo == nil {
  2905. br.Msg = "操作失败"
  2906. br.ErrMsg = "活动ID错误,不存在activityId:" + strconv.Itoa(activityId)
  2907. return
  2908. }
  2909. if errInfo != nil {
  2910. br.Msg = "操作失败"
  2911. br.ErrMsg = "操作失败,Err:" + errInfo.Error()
  2912. return
  2913. }
  2914. //判断是否已经申请过
  2915. applyCount, err := models.GetApplyRecordCount(uid)
  2916. if err != nil && err.Error() != utils.ErrNoRow() {
  2917. br.Msg = "获取信息失败"
  2918. br.ErrMsg = "判断是否已申请过试用失败,Err:" + err.Error()
  2919. return
  2920. }
  2921. //获取销售信息
  2922. sellerItem, err := models.GetSellerByCompanyIdCheckFicc(user.CompanyId, 1)
  2923. if err != nil && err.Error() != utils.ErrNoRow() {
  2924. br.Msg = "申请失败"
  2925. br.ErrMsg = "获取销售信息失败,Err:" + err.Error()
  2926. return
  2927. }
  2928. resp := new(models.SignupStatus)
  2929. hasPermission := 0
  2930. var companyDetailStatus string
  2931. if user.CompanyId <= 1 {
  2932. companyDetailStatus = ""
  2933. } else {
  2934. companyPermission, err := models.GetCompanyPermission(user.CompanyId)
  2935. if err != nil {
  2936. br.Msg = "获取信息失败"
  2937. br.ErrMsg = "获取客户详情失败,Err:" + err.Error()
  2938. return
  2939. }
  2940. if companyPermission == "" {
  2941. if applyCount > 0 {
  2942. hasPermission = 4
  2943. } else {
  2944. if sellerItem != nil {
  2945. hasPermission = 5
  2946. } else {
  2947. //获取权益销售信息 如果是FICC的客户类型,则默认他申请过
  2948. sellerItemQy, err := models.GetSellerByCompanyIdCheckFicc(user.CompanyId, 2)
  2949. if err != nil && err.Error() != utils.ErrNoRow() {
  2950. br.Msg = "获取信息失败"
  2951. br.ErrMsg = "获取销售信息失败,Err:" + err.Error()
  2952. return
  2953. }
  2954. if sellerItemQy != nil {
  2955. hasPermission = 2
  2956. resp.SellerMobile = sellerItemQy.Mobile
  2957. resp.SellerName = sellerItemQy.RealName
  2958. } else {
  2959. hasPermission = 3
  2960. }
  2961. }
  2962. }
  2963. resp.ActivityId = activityId
  2964. resp.HasPermission = hasPermission
  2965. resp.OperationMode = "Apply"
  2966. resp.PopupMsg = "您暂无权限参加此活动,若想参加可以申请开通对应的试用权限"
  2967. br.Ret = 200
  2968. br.Success = true
  2969. br.Msg = "获取成功"
  2970. br.Data = resp
  2971. return
  2972. }
  2973. companyDetail, err := models.GetCompanyDetailById(user.CompanyId)
  2974. if err != nil {
  2975. br.Msg = "获取信息失败!"
  2976. br.ErrMsg = "获取客户详情失败,Err:" + err.Error()
  2977. return
  2978. }
  2979. if companyDetail == nil {
  2980. br.Msg = "获取信息失败!"
  2981. br.ErrMsg = "客户不存在,uid:" + strconv.Itoa(user.UserId) + "CompanyId:" + strconv.Itoa(user.CompanyId)
  2982. return
  2983. }
  2984. companyDetailStatus = companyDetail.Status
  2985. }
  2986. var userType int
  2987. var permissionStr string
  2988. userType, permissionStr, err = services.GetUserType(user.CompanyId)
  2989. if err != nil {
  2990. br.Msg = "获取信息失败!"
  2991. br.ErrMsg = "获取失败,Err:" + err.Error()
  2992. return
  2993. }
  2994. if userType == 1 && activityInfo.ChartPermissionName == "研选" {
  2995. br.Msg = "您暂无查看该活动权限"
  2996. br.ErrMsg = "被分享客户不可见,永续客户无法查看研选行业"
  2997. return
  2998. }
  2999. if user.CompanyId > 1 {
  3000. companyItem, err := models.GetCompanyDetailById(user.CompanyId)
  3001. //冻结客户
  3002. if err != nil {
  3003. if err.Error() == utils.ErrNoRow() {
  3004. if applyCount > 0 {
  3005. hasPermission = 4
  3006. } else {
  3007. if sellerItem != nil {
  3008. hasPermission = 5
  3009. } else {
  3010. hasPermission = 3
  3011. }
  3012. }
  3013. resp.ActivityId = activityId
  3014. resp.HasPermission = hasPermission
  3015. resp.OperationMode = "Apply"
  3016. resp.PopupMsg = "您暂无权限参加此活动,若想参加可以申请开通对应的试用权限"
  3017. br.Ret = 200
  3018. br.Success = true
  3019. br.Msg = "获取成功"
  3020. br.Data = resp
  3021. return
  3022. } else {
  3023. br.Msg = "获取信息失败"
  3024. br.ErrMsg = "获取客户公司信息失败,Err:" + err.Error()
  3025. return
  3026. }
  3027. }
  3028. havePower, err := services.GetHavePower(activityInfo, permissionStr, companyDetailStatus, userType)
  3029. if err != nil {
  3030. br.Msg = "获取信息失败!"
  3031. br.ErrMsg = "获取失败,Err:" + err.Error()
  3032. return
  3033. }
  3034. if havePower {
  3035. hasPermission = 1
  3036. signupStatus = "Success"
  3037. resp.HaqveJurisdiction = true
  3038. } else {
  3039. if companyItem.ProductId == 2 {
  3040. hasPermission = 2
  3041. resp.SellerMobile = companyItem.Mobile
  3042. resp.SellerName = companyItem.SellerName
  3043. resp.MsgType = "Type"
  3044. resp.OperationMode = "Call"
  3045. if permissionStr == "专家" {
  3046. resp.PopupMsg = "您暂无权限参加【" + activityInfo.ActivityTypeName + "】类型活动,若想参加请联系对口销售--" + companyItem.SellerName + ":" + companyItem.Mobile
  3047. resp.MsgType = "Type"
  3048. } else {
  3049. resp.PopupMsg = "您暂无权限参加【" + activityInfo.ChartPermissionName + "】行业活动,若想参加请联系对口销售--" + companyItem.SellerName + ":" + companyItem.Mobile
  3050. resp.MsgType = "Industry"
  3051. }
  3052. } else {
  3053. hasPermission = 5
  3054. }
  3055. }
  3056. } else { //潜在客户
  3057. if applyCount > 0 {
  3058. hasPermission = 4
  3059. } else {
  3060. if sellerItem != nil {
  3061. hasPermission = 5
  3062. } else {
  3063. hasPermission = 3
  3064. }
  3065. }
  3066. resp.OperationMode = "Apply"
  3067. resp.PopupMsg = "您暂无权限参加此活动,若想参加可以申请开通对应的试用权限"
  3068. }
  3069. resp.HasPermission = hasPermission
  3070. resp.SignupStatus = signupStatus
  3071. resp.ActivityId = activityId
  3072. br.Ret = 200
  3073. br.Success = true
  3074. br.Data = resp
  3075. }