activity.go 63 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994199519961997199819992000200120022003200420052006200720082009201020112012201320142015201620172018201920202021202220232024202520262027202820292030203120322033203420352036203720382039204020412042204320442045204620472048204920502051205220532054
  1. package controllers
  2. import (
  3. "encoding/json"
  4. "fmt"
  5. "github.com/medivhzhan/weapp/v2"
  6. "github.com/rdlucklib/rdluck_tools/paging"
  7. "github.com/tealeg/xlsx"
  8. "hongze/hongze_cygx/models"
  9. "hongze/hongze_cygx/services"
  10. "hongze/hongze_cygx/utils"
  11. "os"
  12. "path/filepath"
  13. "strconv"
  14. "strings"
  15. "time"
  16. )
  17. //活动
  18. type ActivityCoAntroller struct {
  19. BaseAuthController
  20. }
  21. type ActivityABaseController struct {
  22. BaseCommonController
  23. }
  24. // @Title 活动类型列表
  25. // @Description活动类型列表接口
  26. // @Success 200 {object} models.ActivityTypeListResp
  27. // @router /activityTypelist [get]
  28. func (this *ActivityCoAntroller) List() {
  29. br := new(models.BaseResponse).Init()
  30. defer func() {
  31. this.Data["json"] = br
  32. this.ServeJSON()
  33. }()
  34. user := this.User
  35. if user == nil {
  36. br.Msg = "请登录"
  37. br.ErrMsg = "请登录,SysUser Is Empty"
  38. br.Ret = 408
  39. return
  40. }
  41. resp := new(models.ActivityTypeListResp)
  42. list, err := models.GetActivityTypeList()
  43. if err != nil {
  44. br.Msg = "获取失败"
  45. br.ErrMsg = "获取数据失败,Err:" + err.Error()
  46. return
  47. }
  48. resp.List = list
  49. br.Ret = 200
  50. br.Success = true
  51. br.Msg = "获取成功"
  52. br.Data = resp
  53. }
  54. // @Title 活动列表
  55. // @Description 获取活动列表接口
  56. // @Param PageSize query int true "每页数据条数"
  57. // @Param CurrentIndex query int true "当前页页码,从1开始"
  58. // @Param ChartPermissionIds query string false "行业id 多个用 , 隔开"
  59. // @Param ActivityTypeIds query string false "活动类型id 多个用 , 隔开"
  60. // @Param KeyWord query string false "搜索关键词 多个用 , 隔开"
  61. // @Param ActiveState query string false "活动进行状态 未开始:1、进行中2、已结束3"
  62. // @Param WhichDay query string false "哪一天 今天:1、明天:2,多个用 , 隔开"
  63. // @Param IsShowJurisdiction query int false "是否仅展示有权限的,1是,2否 默认为零"
  64. // @Param Label query string false "搜索主题 多个用 , 隔开"
  65. // @Success 200 {object} models.GetCygxActivityListRep
  66. // @router /list [get]
  67. func (this *ActivityCoAntroller) ActivityList() {
  68. br := new(models.BaseResponse).Init()
  69. defer func() {
  70. this.Data["json"] = br
  71. this.ServeJSON()
  72. }()
  73. user := this.User
  74. if user == nil {
  75. br.Msg = "请登录"
  76. br.ErrMsg = "请登录,SysUser Is Empty"
  77. return
  78. }
  79. uid := user.UserId
  80. pageSize, _ := this.GetInt("PageSize")
  81. currentIndex, _ := this.GetInt("CurrentIndex")
  82. chartPermissionIds := this.GetString("ChartPermissionIds")
  83. activityTypeIds := this.GetString("ActivityTypeIds")
  84. whichDay := this.GetString("WhichDay")
  85. isShowJurisdiction, _ := this.GetInt("IsShowJurisdiction")
  86. keyWord := this.GetString("KeyWord")
  87. keyWordSearch := this.GetString("KeyWord")
  88. activeState := this.GetString("ActiveState")
  89. label := this.GetString("Label")
  90. //入参为 undefined 时的处理
  91. if chartPermissionIds == "undefined" {
  92. chartPermissionIds = ""
  93. }
  94. if activityTypeIds == "undefined" {
  95. activityTypeIds = ""
  96. }
  97. if whichDay == "undefined" {
  98. whichDay = ""
  99. }
  100. if activeState == "undefined" {
  101. activeState = ""
  102. }
  103. if label == "undefined" {
  104. label = ""
  105. }
  106. //更新用户的搜索信息
  107. itemSearch := new(models.CygxActivityUserSearchContent)
  108. itemSearch.UserId = uid
  109. itemSearch.CreateTime = time.Now()
  110. itemSearch.Mobile = user.Mobile
  111. itemSearch.Email = user.Email
  112. itemSearch.CompanyId = user.CompanyId
  113. itemSearch.CompanyName = user.CompanyName
  114. itemSearch.ModifyTime = time.Now()
  115. itemSearch.ChartPermissionids = chartPermissionIds
  116. itemSearch.ActivityTypeids = activityTypeIds
  117. itemSearch.ActiveState = activeState
  118. itemSearch.IsShowJurisdiction = isShowJurisdiction
  119. //并发缓存校验
  120. cacheKey := fmt.Sprint("xygx:activity_user_search:add:", uid)
  121. ttlTime := utils.Rc.GetRedisTTL(cacheKey)
  122. _, errSearch := models.AddUserSearchContent(itemSearch, ttlTime)
  123. if errSearch != nil {
  124. br.Msg = "操作失败"
  125. br.ErrMsg = "操作失败,Err:" + errSearch.Error()
  126. return
  127. }
  128. utils.Rc.SetNX(cacheKey, user.Mobile, time.Second*10)
  129. userType, permissionStr, err := services.GetUserType(user.CompanyId)
  130. if isShowJurisdiction == 1 && chartPermissionIds == "" && userType == 4 {
  131. activityTypeIds = "1,3"
  132. }
  133. var startSize int
  134. if pageSize <= 0 {
  135. pageSize = utils.PageSize20
  136. }
  137. if currentIndex <= 0 {
  138. currentIndex = 1
  139. }
  140. startSize = utils.StartIndex(currentIndex, pageSize)
  141. var condition string
  142. var pars []interface{}
  143. //活动可见限制
  144. var sqlExport string
  145. slicePer := strings.Split(permissionStr, ",")
  146. var permissionSqlStr string
  147. for _, v := range slicePer {
  148. if userType == 1 {
  149. if v != "研选" {
  150. permissionSqlStr += "'" + v + "',"
  151. }
  152. } else {
  153. permissionSqlStr += "'" + v + "',"
  154. }
  155. }
  156. permissionSqlStr = strings.TrimRight(permissionSqlStr, ",")
  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. condition += ` AND art.is_limit_people = 1 ` + permissionSqlStr + sqlExport + conditionOr
  253. total, err := models.GetActivityCount(condition, pars)
  254. if err != nil {
  255. br.Msg = "获取失败"
  256. br.ErrMsg = "获取失败,Err:" + err.Error()
  257. return
  258. }
  259. if activeState == "2" || activeState == "3" {
  260. condition += ` ORDER BY art.activity_time DESC `
  261. } else {
  262. condition += ` ORDER BY art.active_state ASC, art.activity_time ASC `
  263. }
  264. list, errList := models.GetActivityListAll(condition, pars, uid, startSize, pageSize)
  265. if errList != nil {
  266. br.Msg = "获取失败"
  267. br.ErrMsg = "获取失败,Err:" + errList.Error()
  268. return
  269. }
  270. for k, v := range list {
  271. if strings.Contains(v.ActivityName, "【") {
  272. list[k].IsBrackets = 1
  273. }
  274. if v.SignupNum > v.LimitPeopleNum {
  275. list[k].SignupNum = v.LimitPeopleNum
  276. }
  277. if services.GetShowSustainable() && v.ChartPermissionName == "研选" {
  278. list[k].IsShowSustainable = true
  279. }
  280. }
  281. if keyWordSearch != "" {
  282. keyWordItem := new(models.CygxUserSearchKeyWord)
  283. keyWordItem.UserId = user.UserId
  284. keyWordItem.KeyWord = keyWordSearch
  285. keyWordItem.PageType = "ActivitSearch"
  286. keyWordItem.CreateTime = time.Now()
  287. go models.AddUserSearchKeyWord(keyWordItem)
  288. }
  289. page := paging.GetPaging(currentIndex, pageSize, total)
  290. resp := new(models.GetCygxActivityListRep)
  291. resp.List = list
  292. resp.Paging = page
  293. br.Ret = 200
  294. br.Success = true
  295. br.Msg = "获取成功"
  296. br.Data = resp
  297. }
  298. // @Title 我的日程
  299. // @Description 我的日程列表接口
  300. // @Param PageSize query int true "每页数据条数"
  301. // @Param CurrentIndex query int true "当前页页码,从1开始"
  302. // @Success 200 {object} models.GetCygxActivityListRep
  303. // @router /scheduleList [get]
  304. func (this *ActivityCoAntroller) ScheduleList() {
  305. br := new(models.BaseResponse).Init()
  306. defer func() {
  307. this.Data["json"] = br
  308. this.ServeJSON()
  309. }()
  310. user := this.User
  311. if user == nil {
  312. br.Msg = "请登录"
  313. br.ErrMsg = "请登录,SysUser Is Empty"
  314. return
  315. }
  316. uid := user.UserId
  317. pageSize, _ := this.GetInt("PageSize")
  318. currentIndex, _ := this.GetInt("CurrentIndex")
  319. var startSize int
  320. if pageSize <= 0 {
  321. pageSize = utils.PageSize20
  322. }
  323. if currentIndex <= 0 {
  324. currentIndex = 1
  325. }
  326. startSize = utils.StartIndex(currentIndex, pageSize)
  327. var condition string
  328. var conditionCount string
  329. var pars []interface{}
  330. condition += ` AND art.publish_status = 1 `
  331. total, err := models.GetScheduleCount(conditionCount, uid)
  332. page := paging.GetPaging(currentIndex, pageSize, total)
  333. if err != nil {
  334. br.Msg = "获取失败"
  335. br.ErrMsg = "获取失败,Err:" + err.Error()
  336. return
  337. }
  338. conditionCount = ` AND art.active_state = 2 `
  339. totalCount, err := models.GetScheduleCount(conditionCount, uid) //获取正在进行中的活动数量
  340. if err != nil {
  341. br.Msg = "获取失败"
  342. br.ErrMsg = "获取失败,Err:" + err.Error()
  343. return
  344. }
  345. var list []*models.CygxActivityList
  346. fmt.Println(totalCount)
  347. //全部都是进行中的活动
  348. if totalCount > currentIndex*pageSize {
  349. condition += ` AND art.active_state IN(2) `
  350. listHave, errList := models.GetScheduleList(condition, pars, uid, startSize, pageSize)
  351. list = listHave
  352. if errList != nil {
  353. br.Msg = "获取失败"
  354. br.ErrMsg = "获取失败,Err:" + errList.Error()
  355. return
  356. }
  357. fmt.Println("22222")
  358. } else if totalCount > currentIndex-1*pageSize && totalCount < currentIndex*pageSize { //部分是进行中的活动
  359. condition = ` AND art.publish_status = 1 AND art.active_state IN(2) `
  360. listHave, errList := models.GetScheduleList(condition, pars, uid, startSize, pageSize)
  361. list = listHave
  362. if errList != nil {
  363. br.Msg = "获取失败"
  364. br.ErrMsg = "获取失败,Err:" + errList.Error()
  365. return
  366. }
  367. fmt.Println("33333")
  368. pageSize = pageSize - len(listHave)
  369. condition = ` AND art.publish_status = 1 AND art.active_state IN(1,3) `
  370. listOther, errList := models.GetScheduleList(condition, pars, uid, startSize, pageSize)
  371. if errList != nil {
  372. br.Msg = "获取失败"
  373. br.ErrMsg = "获取失败,Err:" + errList.Error()
  374. return
  375. }
  376. fmt.Println("长度", len(listOther))
  377. if len(listOther) > 0 {
  378. for _, v := range listOther {
  379. list = append(list, v)
  380. }
  381. }
  382. } else {
  383. condition += ` AND art.active_state IN(1,3)` //全部都不是进行中的活动
  384. listOther, errList := models.GetScheduleList(condition, pars, uid, startSize, pageSize)
  385. list = listOther
  386. if errList != nil {
  387. br.Msg = "获取失败"
  388. br.ErrMsg = "获取失败,Err:" + errList.Error()
  389. return
  390. }
  391. }
  392. for k, v := range list {
  393. if strings.Contains(v.ActivityName, "【") {
  394. list[k].IsBrackets = 1
  395. }
  396. if v.SignupNum > v.LimitPeopleNum {
  397. list[k].SignupNum = v.LimitPeopleNum
  398. }
  399. //是否展示限免标签
  400. if services.GetShowSustainable() && v.ChartPermissionName == "研选" {
  401. list[k].IsShowSustainable = true
  402. }
  403. }
  404. resp := new(models.GetCygxActivityListRep)
  405. resp.List = list
  406. resp.Paging = page
  407. br.Ret = 200
  408. br.Success = true
  409. br.Msg = "获取成功"
  410. br.Data = resp
  411. }
  412. // @Title 活动详情
  413. // @Description 获取活动详情接口
  414. // @Param ActivityId query int true "活动ID"
  415. // @Success Ret=200 {object} models.CygxActivityResp
  416. // @router /detail [get]
  417. func (this *ActivityCoAntroller) Detail() {
  418. br := new(models.BaseResponse).Init()
  419. defer func() {
  420. this.Data["json"] = br
  421. this.ServeJSON()
  422. }()
  423. user := this.User
  424. if user == nil {
  425. br.Msg = "请登录"
  426. br.ErrMsg = "请登录,用户信息为空"
  427. br.Ret = 408
  428. return
  429. }
  430. uid := user.UserId
  431. activityId, _ := this.GetInt("ActivityId")
  432. if activityId < 1 {
  433. br.Msg = "请输入活动ID"
  434. return
  435. }
  436. resp := new(models.CygxActivityResp)
  437. hasPermission := 0
  438. var companyDetailStatus string
  439. activityInfo, err := models.GetAddActivityInfoByIdShow(uid, activityId)
  440. if err != nil && err.Error() != utils.ErrNoRow() {
  441. br.Msg = "获取信息失败"
  442. br.ErrMsg = "判断是否已申请过试用失败,Err:" + err.Error()
  443. return
  444. }
  445. if activityInfo == nil {
  446. br.Msg = "活动不存在"
  447. br.ErrMsg = "活动ID错误,Err:" + "activityId:" + strconv.Itoa(activityId)
  448. return
  449. }
  450. applyCount, err := models.GetApplyRecordCount(uid)
  451. if err != nil && err.Error() != utils.ErrNoRow() {
  452. br.Msg = "获取信息失败"
  453. br.ErrMsg = "判断是否已申请过试用失败,Err:" + err.Error()
  454. return
  455. }
  456. if user.CompanyId <= 1 {
  457. companyDetailStatus = ""
  458. } else {
  459. companyPermission, err := models.GetCompanyPermission(user.CompanyId)
  460. if err != nil {
  461. br.Msg = "获取信息失败"
  462. br.ErrMsg = "获取客户详情失败,Err:" + err.Error()
  463. return
  464. }
  465. if companyPermission == "" {
  466. if applyCount > 0 {
  467. hasPermission = 4
  468. } else {
  469. hasPermission = 3
  470. }
  471. resp.HasPermission = hasPermission
  472. resp.OperationMode = "Apply"
  473. resp.PopupMsg = "您暂无权限参加 【" + activityInfo.ChartPermissionName + "】行业活动,若想参加可以申请开通哦"
  474. br.Ret = 200
  475. br.Success = true
  476. br.Msg = "获取成功"
  477. br.Data = resp
  478. return
  479. }
  480. companyDetail, err := models.GetCompanyDetailById(user.CompanyId)
  481. if err != nil {
  482. br.Msg = "获取信息失败!"
  483. br.ErrMsg = "获取客户详情失败,Err:" + err.Error()
  484. return
  485. }
  486. if companyDetail == nil {
  487. br.Msg = "获取信息失败!"
  488. br.ErrMsg = "客户不存在,uid:" + strconv.Itoa(user.UserId) + "CompanyId:" + strconv.Itoa(user.CompanyId)
  489. return
  490. }
  491. companyDetailStatus = companyDetail.Status
  492. }
  493. userType, permissionStr, err := services.GetUserType(user.CompanyId)
  494. if err != nil {
  495. br.Msg = "获取信息失败"
  496. br.ErrMsg = "获取客户信息失败,Err:" + err.Error()
  497. return
  498. }
  499. if activityInfo.IsLimitPeople > 0 {
  500. noPower, err := services.GetShareNoPowe(activityInfo, permissionStr, userType)
  501. if err != nil {
  502. br.Msg = "获取信息失败"
  503. br.ErrMsg = "获取客户信息失败,Err:" + err.Error()
  504. return
  505. }
  506. if noPower {
  507. br.Msg = "您暂无查看该活动权限"
  508. br.ErrMsg = "被分享客户不可见,获取信息失败"
  509. return
  510. }
  511. }
  512. if userType == 1 && activityInfo.ChartPermissionName == "研选" {
  513. br.Msg = "您暂无查看该活动权限"
  514. br.ErrMsg = "被分享客户不可见,永续客户无法查看研选行业"
  515. return
  516. }
  517. detail, errDetail := models.GetActivityTypeDetailById(activityInfo.ActivityTypeId)
  518. if errDetail != nil {
  519. br.Msg = "获取信息失败"
  520. br.ErrMsg = "获取信息失败,Err:" + errDetail.Error()
  521. return
  522. }
  523. if activityInfo.IsSignup > 0 {
  524. detail, errDetail := models.GetActivitySignupDetail(activityId, uid)
  525. if errDetail != nil {
  526. br.Msg = "获取信息失败"
  527. br.ErrMsg = "获取信息失败,Err:" + errDetail.Error()
  528. return
  529. }
  530. activityInfo.SignupType = detail.SignupType
  531. }
  532. activityInfo.ShowType = detail.ShowType
  533. //判断是否已经申请过
  534. if user.CompanyId > 1 {
  535. permissionStr, err := models.GetCompanyPermission(user.CompanyId)
  536. if err != nil {
  537. br.Msg = "获取信息失败"
  538. br.ErrMsg = "获取客户权限信息失败,Err:" + err.Error()
  539. return
  540. }
  541. companyItem, err := models.GetCompanyDetailById(user.CompanyId)
  542. //冻结客户
  543. if err != nil {
  544. if err.Error() == utils.ErrNoRow() {
  545. resp.HasPermission = 4
  546. resp.OperationMode = "Apply"
  547. resp.PopupMsg = "您暂无权限参加 【" + activityInfo.ChartPermissionName + "】行业活动"
  548. br.Ret = 200
  549. br.Success = true
  550. br.Msg = "获取成功"
  551. br.Data = resp
  552. return
  553. } else {
  554. br.Msg = "获取信息失败"
  555. br.ErrMsg = "获取客户公司信息失败,Err:" + err.Error()
  556. return
  557. }
  558. }
  559. havePower, err := services.GetHavePower(activityInfo, permissionStr, companyDetailStatus, userType)
  560. if havePower {
  561. hasPermission = 1
  562. resp.HaqveJurisdiction = true
  563. } else {
  564. if permissionStr == "专家" {
  565. resp.PopupMsg = "您暂无权限参加【" + activityInfo.ActivityTypeName + "】类型活动"
  566. resp.MsgType = "Type"
  567. } else {
  568. resp.PopupMsg = "您暂无权限参加【" + activityInfo.ChartPermissionName + "】行业活动"
  569. resp.MsgType = "Industry"
  570. }
  571. resp.SellerMobile = companyItem.Mobile
  572. resp.SellerName = companyItem.SellerName
  573. resp.OperationMode = "Call"
  574. hasPermission = 2
  575. }
  576. } else { //潜在客户
  577. if applyCount > 0 {
  578. hasPermission = 4
  579. } else {
  580. hasPermission = 3
  581. }
  582. resp.OperationMode = "Apply"
  583. resp.PopupMsg = "您暂无权限参加 【" + activityInfo.ChartPermissionName + "】行业活动,若想参加可以申请开通哦"
  584. }
  585. if hasPermission == 1 {
  586. //是否展示限免标签
  587. if services.GetShowSustainable() && activityInfo.ChartPermissionName == "研选" {
  588. activityInfo.IsShowSustainable = true
  589. }
  590. configCode := "description_of_research"
  591. detail, err := models.GetConfigByCode(configCode)
  592. if err != nil {
  593. br.Msg = "获取数据失败"
  594. br.ErrMsg = "获取数据失败,Err:" + err.Error()
  595. return
  596. }
  597. activityInfo.Description = detail.ConfigValue
  598. if activityInfo.SignupNum > activityInfo.LimitPeopleNum {
  599. activityInfo.SignupNum = activityInfo.LimitPeopleNum
  600. }
  601. if activityInfo.ChartPermissionNames != "" {
  602. activityInfo.ChartPermissionName = activityInfo.ChartPermissionNames
  603. }
  604. resp.Detail = activityInfo
  605. }
  606. resp.HasPermission = hasPermission
  607. br.Ret = 200
  608. br.Success = true
  609. br.Msg = "获取成功"
  610. br.Data = resp
  611. }
  612. // @Title 活动报名
  613. // @Description 活动报名接口
  614. // @Param request body models.ActivitySingnupRep true "type json string"
  615. // @Success Ret=200 {object} models.SignupStatus
  616. // @router /signup/add [post]
  617. func (this *ActivityCoAntroller) SignupAdd() {
  618. br := new(models.BaseResponse).Init()
  619. defer func() {
  620. this.Data["json"] = br
  621. this.ServeJSON()
  622. }()
  623. user := this.User
  624. if user == nil {
  625. br.Msg = "请登录"
  626. br.ErrMsg = "请登录,用户信息为空"
  627. br.Ret = 408
  628. return
  629. }
  630. uid := user.UserId
  631. signupStatus := ""
  632. var req models.ActivitySingnupRep
  633. resp := new(models.SignupStatus)
  634. var total int
  635. err := json.Unmarshal(this.Ctx.Input.RequestBody, &req)
  636. if err != nil {
  637. br.Msg = "参数解析异常!"
  638. br.ErrMsg = "参数解析失败,Err:" + err.Error()
  639. return
  640. }
  641. activityId := req.ActivityId
  642. signupType := req.SignupType
  643. hasPermission := 0
  644. if signupType == 1 && user.Mobile == "" && user.OutboundMobile == "" {
  645. resp.GoBindEmail = true
  646. }
  647. //判断是否已经申请过
  648. applyCount, err := models.GetApplyRecordCount(uid)
  649. if err != nil && err.Error() != utils.ErrNoRow() {
  650. br.Msg = "获取信息失败"
  651. br.ErrMsg = "判断是否已申请过试用失败,Err:" + err.Error()
  652. return
  653. }
  654. activityInfo, errInfo := models.GetAddActivityInfoById(activityId)
  655. if activityInfo == nil {
  656. br.Msg = "操作失败"
  657. br.ErrMsg = "活动ID错误,不存在activityId:" + strconv.Itoa(activityId)
  658. return
  659. }
  660. if errInfo != nil {
  661. br.Msg = "操作失败"
  662. br.ErrMsg = "操作失败,Err:" + errInfo.Error()
  663. return
  664. }
  665. //SignupStatus "报名状态:人数已满:FullStarffed、单机构超过两人:TwoPeople、爽约次数过多:BreakPromise、超时:Overtime 、成功:Success"`
  666. //HasPermission "1:有该行业权限,正常展示,2:无该行业权限,3:潜在客户,未提交过申请,4:潜在客户,已提交过申请"`
  667. var companyDetailStatus string
  668. if user.CompanyId <= 1 {
  669. companyDetailStatus = ""
  670. } else {
  671. companyPermission, err := models.GetCompanyPermission(user.CompanyId)
  672. if err != nil {
  673. br.Msg = "获取信息失败"
  674. br.ErrMsg = "获取客户详情失败,Err:" + err.Error()
  675. return
  676. }
  677. if companyPermission == "" {
  678. if applyCount > 0 {
  679. hasPermission = 4
  680. } else {
  681. hasPermission = 3
  682. }
  683. resp.HasPermission = hasPermission
  684. resp.OperationMode = "Apply"
  685. resp.PopupMsg = "您暂无权限参加 【" + activityInfo.ChartPermissionName + "】行业活动,若想参加可以申请开通哦"
  686. br.Ret = 200
  687. br.Success = true
  688. br.Msg = "获取成功"
  689. br.Data = resp
  690. return
  691. }
  692. companyDetail, err := models.GetCompanyDetailById(user.CompanyId)
  693. if err != nil {
  694. br.Msg = "获取信息失败!"
  695. br.ErrMsg = "获取客户详情失败,Err:" + err.Error()
  696. return
  697. }
  698. if companyDetail == nil {
  699. br.Msg = "获取信息失败!"
  700. br.ErrMsg = "客户不存在,uid:" + strconv.Itoa(user.UserId) + "CompanyId:" + strconv.Itoa(user.CompanyId)
  701. return
  702. }
  703. companyDetailStatus = companyDetail.Status
  704. }
  705. var userType int
  706. var permissionStr string
  707. userType, permissionStr, err = services.GetUserType(user.CompanyId)
  708. if err != nil {
  709. br.Msg = "获取信息失败!"
  710. br.ErrMsg = "获取失败,Err:" + err.Error()
  711. return
  712. }
  713. if userType == 1 && activityInfo.ChartPermissionName == "研选" {
  714. br.Msg = "您暂无查看该活动权限"
  715. br.ErrMsg = "被分享客户不可见,永续客户无法查看研选行业"
  716. return
  717. }
  718. item := new(models.CygxActivitySignup)
  719. if user.CompanyId > 1 {
  720. companyItem, err := models.GetCompanyDetailById(user.CompanyId)
  721. //冻结客户
  722. if err != nil {
  723. if err.Error() == utils.ErrNoRow() {
  724. resp.HasPermission = 4
  725. resp.OperationMode = "Apply"
  726. resp.PopupMsg = "您暂无权限参加 【" + activityInfo.ChartPermissionName + "】行业活动,若想参加可以申请开通哦"
  727. br.Ret = 200
  728. br.Success = true
  729. br.Msg = "获取成功"
  730. br.Data = resp
  731. return
  732. } else {
  733. br.Msg = "获取信息失败"
  734. br.ErrMsg = "获取客户公司信息失败,Err:" + err.Error()
  735. return
  736. }
  737. }
  738. //1专家电话会、2分析师电话会、3公司调研电话会、4公司线下调研、5专家线下沙龙、6分析师线下沙龙
  739. //OperationMode string `description:"操作方式 Apply:立即申请、Call:拨号 为空则为有权限"`
  740. havePower, err := services.GetHavePower(activityInfo, permissionStr, companyDetailStatus, userType)
  741. if err != nil {
  742. br.Msg = "获取信息失败!"
  743. br.ErrMsg = "获取失败,Err:" + err.Error()
  744. return
  745. }
  746. if havePower {
  747. hasPermission = 1
  748. signupStatus = "Success"
  749. resultTime := utils.StrTimeToTime(activityInfo.ActivityTime) //时间字符串格式转时间格式
  750. if time.Now().After(resultTime.Add(-time.Minute * 60)) {
  751. signupStatus = "Overtime"
  752. resp.SignupType = signupType
  753. resp.SignupStatus = signupStatus
  754. resp.HasPermission = hasPermission
  755. br.Ret = 200
  756. br.Success = true
  757. br.Msg = ""
  758. br.Data = resp
  759. return
  760. }
  761. var sellerName string
  762. sellerName, err = models.GetCompanySellerName(user.CompanyId)
  763. if err != nil {
  764. br.Msg = "报名失败!"
  765. br.ErrMsg = "获取对应销售失败,Err:" + err.Error()
  766. return
  767. }
  768. //人数已满:FullStarffed、单机构超过两人:TwoPeople、爽约次数过多:BreakPromise、超时:Overtime 、成功:Success"`
  769. //如果是下面几种情况则对报名信息做判断限制 (公司调研电话会(限制人数)、公司线下调研、专家/分析师线下沙龙)
  770. if (activityInfo.ActivityTypeId == 3 && activityInfo.IsLimitPeople == 1) || activityInfo.ActivityTypeId > 3 {
  771. //判断优先级:总人数限制→单机构2人限制→爽约3次限制
  772. totalRestrict, err := models.GetUserRestrictCount(user.Mobile)
  773. if err != nil {
  774. br.Msg = "获取信息失败"
  775. br.ErrMsg = "获取客户信息失败,Err:" + err.Error()
  776. return
  777. }
  778. if totalRestrict >= 1 {
  779. signupStatus = "BreakPromise"
  780. item.FailType = 3
  781. }
  782. totalSignupCompany, err := models.GetActivitySignupCompanyCount(activityId, user.CompanyId)
  783. if err != nil {
  784. br.Msg = "获取信息失败"
  785. br.ErrMsg = "获取客户信息失败,Err:" + err.Error()
  786. return
  787. }
  788. if totalSignupCompany >= 2 {
  789. signupStatus = "TwoPeople"
  790. item.FailType = 2
  791. }
  792. totaSignupPeopleNum, err := models.GetActivitySignupSuccessCount(activityId)
  793. if err != nil {
  794. br.Msg = "获取信息失败"
  795. br.ErrMsg = "获取客户信息失败,Err:" + err.Error()
  796. return
  797. }
  798. if totaSignupPeopleNum >= activityInfo.LimitPeopleNum {
  799. signupStatus = "FullStarffed"
  800. item.FailType = 1
  801. }
  802. totalUserRestrictCount, err := models.GetActivitySignupByUserRestrictCount(uid, activityId)
  803. if err != nil {
  804. br.Msg = "获取失败"
  805. br.ErrMsg = "获取失败,Err:" + err.Error()
  806. return
  807. }
  808. //解除报名限制之后二次报名相同活动
  809. if totalUserRestrictCount > 0 && totalRestrict == 0 && resp.GoBindEmail != true {
  810. item.UserId = uid
  811. item.RealName = user.RealName
  812. item.SellerName = sellerName
  813. item.ActivityId = activityId
  814. item.CreateTime = time.Now()
  815. item.Mobile = user.Mobile
  816. item.Email = user.Email
  817. item.CompanyId = user.CompanyId
  818. item.CompanyName = user.CompanyName
  819. item.SignupType = signupType
  820. item.FailType = 0
  821. item.DoFailType = 0
  822. _, errSignup := models.AddActivitySignupByRestrict(item)
  823. if errSignup != nil {
  824. br.Msg = "操作失败"
  825. br.ErrMsg = "操作失败,Err:" + errSignup.Error()
  826. return
  827. }
  828. resp.HaqveJurisdiction = true
  829. resp.SignupType = signupType
  830. resp.SignupStatus = "Success"
  831. resp.HasPermission = hasPermission
  832. resp.ActivityId = activityId
  833. total, err = models.GetUserMeetingReminderCount(user.UserId)
  834. if err != nil {
  835. br.Msg = "获取信息失败"
  836. br.ErrMsg = "获取日程数量信息失败,Err:" + err.Error()
  837. return
  838. }
  839. if total == 0 {
  840. resp.GoFollow = true
  841. }
  842. br.Ret = 200
  843. br.Success = true
  844. br.Msg = "操作成功"
  845. br.Data = resp
  846. return
  847. }
  848. totalMy, err := models.GetActivitySignupByUserCount(uid, activityId)
  849. if err != nil {
  850. br.Msg = "获取失败"
  851. br.ErrMsg = "获取失败,Err:" + err.Error()
  852. return
  853. }
  854. if signupStatus != "Success" && totalMy == 0 && resp.GoBindEmail != true {
  855. item.UserId = uid
  856. item.RealName = user.RealName
  857. item.SellerName = sellerName
  858. item.ActivityId = activityId
  859. item.CreateTime = time.Now()
  860. item.Mobile = user.Mobile
  861. item.Email = user.Email
  862. item.CompanyId = user.CompanyId
  863. item.CompanyName = user.CompanyName
  864. item.SignupType = signupType
  865. item.DoFailType = item.FailType
  866. if user.OutboundMobile != "" {
  867. item.OutboundMobile = user.OutboundMobile
  868. if user.OutboundCountryCode == "" {
  869. item.CountryCode = "86"
  870. } else {
  871. item.CountryCode = user.OutboundCountryCode
  872. }
  873. } else {
  874. item.OutboundMobile = user.Mobile
  875. if user.CountryCode == "" {
  876. item.CountryCode = "86"
  877. } else {
  878. item.CountryCode = user.CountryCode
  879. }
  880. }
  881. //添加报名信息,但是不加入日程
  882. _, errSignup := models.AddActivitySignupNoSchedule(item)
  883. if errSignup != nil {
  884. br.Msg = "操作失败"
  885. br.ErrMsg = "操作失败,Err:" + errSignup.Error()
  886. return
  887. }
  888. }
  889. }
  890. totalMySuccess, err := models.GetActivitySignupCount(uid, activityId)
  891. if err != nil {
  892. br.Msg = "获取失败"
  893. br.ErrMsg = "获取失败,Err:" + err.Error()
  894. return
  895. }
  896. if totalMySuccess > 0 {
  897. br.Msg = "您已报名这个活动"
  898. return
  899. }
  900. if signupStatus == "Success" && resp.GoBindEmail != true {
  901. item.UserId = uid
  902. item.RealName = user.RealName
  903. item.SellerName = sellerName
  904. item.ActivityId = activityId
  905. item.CreateTime = time.Now()
  906. item.Mobile = user.Mobile
  907. item.Email = user.Email
  908. item.CompanyId = user.CompanyId
  909. item.CompanyName = user.CompanyName
  910. item.SignupType = signupType
  911. item.FailType = 0
  912. item.DoFailType = 0
  913. item.OutboundMobile = user.Mobile
  914. if user.OutboundMobile != "" {
  915. item.OutboundMobile = user.OutboundMobile
  916. if user.OutboundCountryCode == "" {
  917. item.CountryCode = "86"
  918. } else {
  919. item.CountryCode = user.OutboundCountryCode
  920. }
  921. } else {
  922. item.OutboundMobile = user.Mobile
  923. if user.CountryCode == "" {
  924. item.CountryCode = "86"
  925. } else {
  926. item.CountryCode = user.CountryCode
  927. }
  928. }
  929. _, errSignup := models.AddActivitySignup(item)
  930. if errSignup != nil {
  931. br.Msg = "操作失败"
  932. br.ErrMsg = "操作失败,Err:" + errSignup.Error()
  933. return
  934. }
  935. resp.HaqveJurisdiction = true
  936. }
  937. } else {
  938. hasPermission = 2
  939. resp.SellerMobile = companyItem.Mobile
  940. resp.SellerName = companyItem.SellerName
  941. resp.MsgType = "Type"
  942. resp.OperationMode = "Call"
  943. if permissionStr == "专家" {
  944. resp.PopupMsg = "您暂无权限参加【" + activityInfo.ActivityTypeName + "】类型活动,若想参加请联系对口销售--" + companyItem.SellerName + ":" + companyItem.Mobile
  945. resp.MsgType = "Type"
  946. } else {
  947. resp.PopupMsg = "您暂无权限参加【" + activityInfo.ChartPermissionName + "】行业活动,若想参加请联系对口销售--" + companyItem.SellerName + ":" + companyItem.Mobile
  948. resp.MsgType = "Industry"
  949. }
  950. }
  951. } else { //潜在客户
  952. if applyCount > 0 {
  953. hasPermission = 4
  954. } else {
  955. hasPermission = 3
  956. }
  957. resp.OperationMode = "Apply"
  958. resp.PopupMsg = "您暂无权限参加 【" + activityInfo.ChartPermissionName + "】行业活动,若想参加可以申请开通哦"
  959. }
  960. if signupType == 1 && user.IsMsgOutboundMobile == 0 {
  961. resp.GoOutboundMobile = true
  962. if user.Mobile != "" || user.OutboundMobile != "" {
  963. go models.ModifyWxUserIsMsgOutboundMobile(user.UserId)
  964. }
  965. }
  966. if user.OutboundMobile == "" {
  967. resp.Mobile = user.Mobile
  968. if user.CountryCode == "" && len(user.Mobile) == 11 {
  969. resp.CountryCode = "86"
  970. } else {
  971. resp.CountryCode = user.CountryCode
  972. }
  973. } else {
  974. resp.Mobile = user.OutboundMobile
  975. resp.CountryCode = user.OutboundCountryCode
  976. }
  977. //如果用户有绑定手机号,但是没有绑定外呼手机号
  978. if signupType == 1 && user.Mobile != "" && user.OutboundMobile == "" {
  979. var countryCode string
  980. if len(user.Mobile) == 8 {
  981. countryCode = "852"
  982. } else if len(user.Mobile) == 9 {
  983. countryCode = "886"
  984. } else if len(user.Mobile) == 10 {
  985. countryCode = "1"
  986. } else if len(user.Mobile) >= 11 {
  987. countryCode = "86"
  988. }
  989. models.BindUserOutboundMobileByMobile(user.Mobile, countryCode, uid)
  990. }
  991. resp.SignupType = signupType
  992. resp.SignupStatus = signupStatus
  993. resp.HasPermission = hasPermission
  994. if signupStatus == "Success" {
  995. resp.ActivityId = activityId
  996. }
  997. total, err = models.GetUserSignupCount(user.UserId)
  998. if err != nil {
  999. br.Msg = "获取信息失败"
  1000. br.ErrMsg = "获取日程数量信息失败,Err:" + err.Error()
  1001. return
  1002. }
  1003. if total <= 1 {
  1004. resp.GoFollow = true
  1005. }
  1006. br.Ret = 200
  1007. br.Success = true
  1008. br.Msg = "操作成功"
  1009. br.Data = resp
  1010. }
  1011. // @Title 活动取消报名
  1012. // @Description 活动取消报名接口
  1013. // @Param request body models.ActivitySingnupRep true "type json string"
  1014. // @Success Ret=200 {object} models.SignupStatus
  1015. // @router /signup/cancel [post]
  1016. func (this *ActivityCoAntroller) SignupCancel() {
  1017. br := new(models.BaseResponse).Init()
  1018. defer func() {
  1019. this.Data["json"] = br
  1020. this.ServeJSON()
  1021. }()
  1022. user := this.User
  1023. if user == nil {
  1024. br.Msg = "请登录"
  1025. br.ErrMsg = "请登录,用户信息为空"
  1026. br.Ret = 408
  1027. return
  1028. }
  1029. uid := user.UserId
  1030. var req models.ActivitySingnupRep
  1031. err := json.Unmarshal(this.Ctx.Input.RequestBody, &req)
  1032. if err != nil {
  1033. br.Msg = "参数解析异常!"
  1034. br.ErrMsg = "参数解析失败,Err:" + err.Error()
  1035. return
  1036. }
  1037. activityId := req.ActivityId
  1038. signupType := req.SignupType
  1039. item := new(models.CygxActivitySignup)
  1040. activityInfo, errInfo := models.GetAddActivityInfoById(activityId)
  1041. if activityInfo == nil {
  1042. br.Msg = "操作失败"
  1043. br.ErrMsg = "活动ID错误,不存在activityId:" + strconv.Itoa(activityId)
  1044. return
  1045. }
  1046. if errInfo != nil {
  1047. br.Msg = "操作失败"
  1048. br.ErrMsg = "操作失败,Err:" + errInfo.Error()
  1049. return
  1050. }
  1051. resultTime := utils.StrTimeToTime(activityInfo.ActivityTime) //时间字符串格式转时间格式
  1052. if time.Now().After(resultTime.Add(-time.Minute * 60)) {
  1053. if signupType == 1 {
  1054. br.Msg = "活动开始前1小时内无法取消预约外呼,请联系对口销售处理"
  1055. } else {
  1056. br.Msg = "活动开始前1小时内无法取消报名,请联系对口销售处理"
  1057. }
  1058. return
  1059. }
  1060. total, err := models.GetActivitySignupCount(uid, activityId)
  1061. if err != nil {
  1062. br.Msg = "获取失败"
  1063. br.ErrMsg = "获取失败,Err:" + err.Error()
  1064. return
  1065. }
  1066. if total == 0 {
  1067. br.Msg = "您暂未报名这个活动"
  1068. return
  1069. }
  1070. item.UserId = uid
  1071. item.ActivityId = activityId
  1072. item.CreateTime = time.Now()
  1073. item.Mobile = user.Mobile
  1074. item.Email = user.Email
  1075. item.CompanyId = user.CompanyId
  1076. item.CompanyName = user.CompanyName
  1077. resp := new(models.SignupStatus)
  1078. resp.ActivityId = activityId
  1079. _, errSignup := models.CancelActivitySignup(item)
  1080. if errSignup != nil {
  1081. br.Msg = "操作失败"
  1082. br.ErrMsg = "操作失败,Err:" + errSignup.Error()
  1083. return
  1084. }
  1085. br.Ret = 200
  1086. br.Success = true
  1087. br.Msg = "操作成功"
  1088. br.Data = resp
  1089. }
  1090. // @Title 用户搜索详情
  1091. // @Description 获取用户搜索详情接口
  1092. // @Param IsShowJurisdiction query int true "是否仅展示有权限的,默认为0,1是,2否 "
  1093. // @Success Ret=200 {object} models.ActivityUserSearchContentList
  1094. // @router /getUserSearchContent [get]
  1095. func (this *ActivityCoAntroller) GetUserSearchContent() {
  1096. br := new(models.BaseResponse).Init()
  1097. defer func() {
  1098. this.Data["json"] = br
  1099. this.ServeJSON()
  1100. }()
  1101. user := this.User
  1102. if user == nil {
  1103. br.Msg = "请登录"
  1104. br.ErrMsg = "请登录,用户信息为空"
  1105. br.Ret = 408
  1106. return
  1107. }
  1108. uid := user.UserId
  1109. detailSeearch := new(models.CygxActivityUserSearchContent)
  1110. detailSeearch.IsShowJurisdiction = 0
  1111. detailSeearch.ChartPermissionids = ""
  1112. detailSeearch.ActiveState = ""
  1113. resp := new(models.ActivityUserSearchContentList)
  1114. detail, _ := models.GetUserSearchContentByUid(uid)
  1115. if detail == nil {
  1116. detail = detailSeearch
  1117. }
  1118. isShowJurisdiction, _ := this.GetInt("IsShowJurisdiction")
  1119. listActivityType, errActivityType := models.GetActivityTypeList()
  1120. if errActivityType != nil {
  1121. br.Msg = "获取失败"
  1122. br.ErrMsg = "获取数据失败,Err:" + errActivityType.Error()
  1123. return
  1124. }
  1125. var listChartPermissionid []*models.ActivityChartPermission
  1126. var errChart error
  1127. if isShowJurisdiction == 1 {
  1128. listChartPermissionidAll, errChartAll := models.GetUserCompanyPermission(user.CompanyId)
  1129. listChartPermissionid = listChartPermissionidAll
  1130. errChart = errChartAll
  1131. } else if isShowJurisdiction == 2 {
  1132. listChartPermissionidAll, errChartAll := models.GetChartPermissionActivity()
  1133. listChartPermissionid = listChartPermissionidAll
  1134. errChart = errChartAll
  1135. } else {
  1136. if detail.IsShowJurisdiction == 1 {
  1137. listChartPermissionidAll, errChartAll := models.GetUserCompanyPermission(user.CompanyId)
  1138. listChartPermissionid = listChartPermissionidAll
  1139. errChart = errChartAll
  1140. } else {
  1141. listChartPermissionidAll, errChartAll := models.GetChartPermissionActivity()
  1142. listChartPermissionid = listChartPermissionidAll
  1143. errChart = errChartAll
  1144. }
  1145. }
  1146. if errChart != nil {
  1147. br.Msg = "获取信息失败"
  1148. br.ErrMsg = "获取品种信息失败,Err:" + errChart.Error()
  1149. return
  1150. }
  1151. if detail.IsShowJurisdiction == 1 {
  1152. resp.IsShowJurisdiction = true
  1153. }
  1154. if isShowJurisdiction == 1 || detail.IsShowJurisdiction == 1 {
  1155. resp.IsShowJurisdiction = true
  1156. for k, _ := range listChartPermissionid {
  1157. listChartPermissionid[k].IsChoose = true
  1158. }
  1159. }
  1160. if isShowJurisdiction == 2 {
  1161. resp.IsShowJurisdiction = false
  1162. }
  1163. activeStateList := []models.ActivityStaus{models.ActivityStaus{Id: 1, StatusName: "未开始", IsChoose: true}, models.ActivityStaus{Id: 2, StatusName: "进行中"}, models.ActivityStaus{Id: 3, StatusName: "已结束"}}
  1164. list2, err := models.GetChartPermissionActivity()
  1165. if err != nil {
  1166. br.Msg = "获取信息失败"
  1167. br.ErrMsg = "获取品种信息失败,Err:" + err.Error()
  1168. return
  1169. }
  1170. if activeStateList[1].IsChoose == activeStateList[2].IsChoose == false {
  1171. activeStateList[0].IsChoose = true
  1172. }
  1173. var userType int
  1174. userType, _, err = services.GetUserType(user.CompanyId)
  1175. if err != nil {
  1176. br.Msg = "获取信息失败!"
  1177. br.ErrMsg = "获取失败,Err:" + err.Error()
  1178. return
  1179. }
  1180. var listChartPermissionidNew2 []*models.ActivityChartPermission
  1181. for _, v := range list2 {
  1182. if userType == 1 {
  1183. if v.PermissionName != "研选" {
  1184. listChartPermissionidNew2 = append(listChartPermissionidNew2, v)
  1185. }
  1186. } else {
  1187. listChartPermissionidNew2 = append(listChartPermissionidNew2, v)
  1188. }
  1189. }
  1190. resp.ListChartPermission2 = listChartPermissionidNew2
  1191. var listChartPermissionidNew []*models.ActivityChartPermission
  1192. for _, v := range listChartPermissionid {
  1193. if userType == 1 {
  1194. if v.PermissionName != "研选" {
  1195. listChartPermissionidNew = append(listChartPermissionidNew, v)
  1196. }
  1197. } else {
  1198. listChartPermissionidNew = append(listChartPermissionidNew, v)
  1199. }
  1200. }
  1201. resp.ListActivityType = listActivityType
  1202. resp.ListChartPermission = listChartPermissionidNew
  1203. resp.ListActivityStaus = activeStateList
  1204. br.Ret = 200
  1205. br.Success = true
  1206. br.Msg = "获取成功"
  1207. br.Data = resp
  1208. }
  1209. // @Title 添加会议提醒
  1210. // @Description 添加会议提醒接口
  1211. // @Param request body models.ActivityIdRep true "type json string"
  1212. // @Success Ret=200 {object} models.SignupStatus
  1213. // @router /meetingReminder/add [post]
  1214. func (this *ActivityCoAntroller) MeetingReminderAdd() {
  1215. br := new(models.BaseResponse).Init()
  1216. defer func() {
  1217. this.Data["json"] = br
  1218. this.ServeJSON()
  1219. }()
  1220. user := this.User
  1221. if user == nil {
  1222. br.Msg = "请登录"
  1223. br.ErrMsg = "请登录,用户信息为空"
  1224. br.Ret = 408
  1225. return
  1226. }
  1227. uid := user.UserId
  1228. //var signupStatus string
  1229. signupStatus := "Success"
  1230. var req models.ActivityIdRep
  1231. err := json.Unmarshal(this.Ctx.Input.RequestBody, &req)
  1232. if err != nil {
  1233. br.Msg = "参数解析异常!"
  1234. br.ErrMsg = "参数解析失败,Err:" + err.Error()
  1235. return
  1236. }
  1237. activityId := req.ActivityId
  1238. activityInfo, errInfo := models.GetAddActivityInfoById(activityId)
  1239. if activityInfo == nil {
  1240. br.Msg = "操作失败"
  1241. br.ErrMsg = "活动ID错误,不存在activityId:" + strconv.Itoa(activityId)
  1242. return
  1243. }
  1244. if errInfo != nil {
  1245. br.Msg = "操作失败"
  1246. br.ErrMsg = "操作失败,Err:" + errInfo.Error()
  1247. return
  1248. }
  1249. //判断是否已经申请过
  1250. applyCount, err := models.GetApplyRecordCount(uid)
  1251. if err != nil && err.Error() != utils.ErrNoRow() {
  1252. br.Msg = "获取信息失败"
  1253. br.ErrMsg = "判断是否已申请过试用失败,Err:" + err.Error()
  1254. return
  1255. }
  1256. //SignupStatus string `description:"报名状态:人数已满:FullStarffed、单机构超过两人:TwoPeople、爽约次数过多:BreakPromise、超时:Overtime 、成功:Success"`
  1257. item := new(models.CygxActivityMeetingReminder)
  1258. resp := new(models.SignupStatus)
  1259. hasPermission := 0
  1260. var companyDetailStatus string
  1261. if user.CompanyId <= 1 {
  1262. companyDetailStatus = ""
  1263. } else {
  1264. companyPermission, err := models.GetCompanyPermission(user.CompanyId)
  1265. if err != nil {
  1266. br.Msg = "获取信息失败"
  1267. br.ErrMsg = "获取客户详情失败,Err:" + err.Error()
  1268. return
  1269. }
  1270. if companyPermission == "" {
  1271. if applyCount > 0 {
  1272. hasPermission = 4
  1273. } else {
  1274. hasPermission = 3
  1275. }
  1276. resp.HasPermission = hasPermission
  1277. resp.OperationMode = "Apply"
  1278. resp.PopupMsg = "您暂无权限参加 【" + activityInfo.ChartPermissionName + "】行业活动,若想参加可以申请开通哦"
  1279. br.Ret = 200
  1280. br.Success = true
  1281. br.Msg = "获取成功"
  1282. br.Data = resp
  1283. return
  1284. }
  1285. companyDetail, err := models.GetCompanyDetailById(user.CompanyId)
  1286. if err != nil {
  1287. br.Msg = "获取信息失败!"
  1288. br.ErrMsg = "获取客户详情失败,Err:" + err.Error()
  1289. return
  1290. }
  1291. if companyDetail == nil {
  1292. br.Msg = "获取信息失败!"
  1293. br.ErrMsg = "客户不存在,uid:" + strconv.Itoa(user.UserId) + "CompanyId:" + strconv.Itoa(user.CompanyId)
  1294. return
  1295. }
  1296. companyDetailStatus = companyDetail.Status
  1297. }
  1298. var userType int
  1299. var permissionStr string
  1300. userType, permissionStr, err = services.GetUserType(user.CompanyId)
  1301. if err != nil {
  1302. br.Msg = "获取信息失败!"
  1303. br.ErrMsg = "获取失败,Err:" + err.Error()
  1304. return
  1305. }
  1306. if userType == 1 && activityInfo.ChartPermissionName == "研选" {
  1307. br.Msg = "您暂无查看该活动权限"
  1308. br.ErrMsg = "被分享客户不可见,永续客户无法查看研选行业"
  1309. return
  1310. }
  1311. resultTime := utils.StrTimeToTime(activityInfo.ActivityTime) //时间字符串格式转时间格式
  1312. if time.Now().After(resultTime.Add(-time.Minute * 15)) {
  1313. br.Msg = "活动开始前15分钟无法设置会议提醒"
  1314. return
  1315. }
  1316. if user.CompanyId > 1 {
  1317. companyItem, err := models.GetCompanyDetailById(user.CompanyId)
  1318. //冻结客户
  1319. if err != nil {
  1320. if err.Error() == utils.ErrNoRow() {
  1321. resp.HasPermission = 4
  1322. resp.OperationMode = "Apply"
  1323. resp.PopupMsg = "您暂无权限参加 【" + activityInfo.ChartPermissionName + "】行业活动,若想参加可以申请开通哦"
  1324. br.Ret = 200
  1325. br.Success = true
  1326. br.Msg = "获取成功"
  1327. br.Data = resp
  1328. return
  1329. } else {
  1330. br.Msg = "获取信息失败"
  1331. br.ErrMsg = "获取客户公司信息失败,Err:" + err.Error()
  1332. return
  1333. }
  1334. }
  1335. havePower, err := services.GetHavePower(activityInfo, permissionStr, companyDetailStatus, userType)
  1336. if err != nil {
  1337. br.Msg = "获取信息失败!"
  1338. br.ErrMsg = "获取失败,Err:" + err.Error()
  1339. return
  1340. }
  1341. if havePower {
  1342. hasPermission = 1
  1343. signupStatus = "Success"
  1344. totalMeeting, errMeeting := models.GetActivityMeetingReminderCount(uid, activityId)
  1345. if errMeeting != nil {
  1346. br.Msg = "获取失败"
  1347. br.ErrMsg = "获取失败,Err:" + errMeeting.Error()
  1348. return
  1349. }
  1350. if totalMeeting > 0 {
  1351. br.Msg = "您已预约,请勿重复预约"
  1352. return
  1353. }
  1354. item.UserId = uid
  1355. item.ActivityId = activityId
  1356. item.CreateTime = time.Now()
  1357. item.Mobile = user.Mobile
  1358. item.Email = user.Email
  1359. item.CompanyId = user.CompanyId
  1360. item.CompanyName = user.CompanyName
  1361. _, errSignup := models.AddActivityMeetingReminder(item)
  1362. if errSignup != nil {
  1363. br.Msg = "操作失败"
  1364. br.ErrMsg = "操作失败,Err:" + errSignup.Error()
  1365. return
  1366. }
  1367. resp.HaqveJurisdiction = true
  1368. } else {
  1369. hasPermission = 2
  1370. resp.SellerMobile = companyItem.Mobile
  1371. resp.SellerName = companyItem.SellerName
  1372. resp.MsgType = "Type"
  1373. resp.OperationMode = "Call"
  1374. if permissionStr == "专家" {
  1375. resp.PopupMsg = "您暂无权限参加【" + activityInfo.ActivityTypeName + "】类型活动,若想参加请联系对口销售--" + companyItem.SellerName + ":" + companyItem.Mobile
  1376. resp.MsgType = "Type"
  1377. } else {
  1378. resp.PopupMsg = "您暂无权限参加【" + activityInfo.ChartPermissionName + "】行业活动,若想参加请联系对口销售--" + companyItem.SellerName + ":" + companyItem.Mobile
  1379. resp.MsgType = "Industry"
  1380. }
  1381. }
  1382. } else { //潜在客户
  1383. if applyCount > 0 {
  1384. hasPermission = 4
  1385. } else {
  1386. hasPermission = 3
  1387. }
  1388. resp.OperationMode = "Apply"
  1389. resp.PopupMsg = "您暂无权限参加 【" + activityInfo.ChartPermissionName + "】行业活动,若想参加可以申请开通哦"
  1390. }
  1391. resp.HasPermission = hasPermission
  1392. resp.SignupStatus = signupStatus
  1393. resp.ActivityId = activityId
  1394. var total int
  1395. total, err = models.GetUserActivityMeetingReminderCount(user.UserId)
  1396. if err != nil {
  1397. br.Msg = "获取信息失败"
  1398. br.ErrMsg = "获取日程数量信息失败,Err:" + err.Error()
  1399. return
  1400. }
  1401. if total <= 1 {
  1402. resp.GoFollow = true
  1403. }
  1404. br.Ret = 200
  1405. br.Success = true
  1406. if hasPermission == 1 {
  1407. br.Msg = "设置成功,会前15分钟会为您推送微信消息提醒"
  1408. }
  1409. br.Data = resp
  1410. }
  1411. // @Title 取消会议提醒
  1412. // @Description 取消会议提醒接口
  1413. // @Param request body models.ActivityIdRep true "type json string"
  1414. // @Success Ret=200 {object} models.SignupStatus
  1415. // @router /meetingReminder/cancel [post]
  1416. func (this *ActivityCoAntroller) MeetingReminderCancel() {
  1417. br := new(models.BaseResponse).Init()
  1418. defer func() {
  1419. this.Data["json"] = br
  1420. this.ServeJSON()
  1421. }()
  1422. user := this.User
  1423. if user == nil {
  1424. br.Msg = "请登录"
  1425. br.ErrMsg = "请登录,用户信息为空"
  1426. br.Ret = 408
  1427. return
  1428. }
  1429. uid := user.UserId
  1430. var req models.ActivityIdRep
  1431. err := json.Unmarshal(this.Ctx.Input.RequestBody, &req)
  1432. if err != nil {
  1433. br.Msg = "参数解析异常!"
  1434. br.ErrMsg = "参数解析失败,Err:" + err.Error()
  1435. return
  1436. }
  1437. activityId := req.ActivityId
  1438. signupStatus := "Success"
  1439. item := new(models.CygxActivityMeetingReminder)
  1440. activityInfo, errInfo := models.GetAddActivityInfoById(activityId)
  1441. if activityInfo == nil {
  1442. br.Msg = "操作失败"
  1443. br.ErrMsg = "活动ID错误,不存在activityId:" + strconv.Itoa(activityId)
  1444. return
  1445. }
  1446. if errInfo != nil {
  1447. br.Msg = "操作失败"
  1448. br.ErrMsg = "操作失败,Err:" + errInfo.Error()
  1449. return
  1450. }
  1451. //if signupStatus == "Success" {
  1452. total, err := models.GetActivityMeetingReminderCount(uid, activityId)
  1453. if err != nil {
  1454. br.Msg = "获取失败"
  1455. br.ErrMsg = "获取失败,Err:" + err.Error()
  1456. return
  1457. }
  1458. if total == 0 {
  1459. br.Msg = "您暂未添加该活动会议提醒"
  1460. return
  1461. }
  1462. resultTime := utils.StrTimeToTime(activityInfo.ActivityTime) //时间字符串格式转时间格式
  1463. if time.Now().After(resultTime.Add(-time.Minute * 15)) {
  1464. br.Msg = "活动开始前15分钟无法取消会议提醒"
  1465. return
  1466. }
  1467. item.UserId = uid
  1468. item.ActivityId = activityId
  1469. item.CreateTime = time.Now()
  1470. item.Mobile = user.Mobile
  1471. item.Email = user.Email
  1472. item.CompanyId = user.CompanyId
  1473. item.CompanyName = user.CompanyName
  1474. _, errSignup := models.CancelActivityMeetingReminder(item)
  1475. if errSignup != nil {
  1476. br.Msg = "操作失败"
  1477. br.ErrMsg = "操作失败,Err:" + errSignup.Error()
  1478. return
  1479. }
  1480. //}
  1481. resp := new(models.SignupStatus)
  1482. resp.SignupStatus = signupStatus
  1483. resp.ActivityId = activityId
  1484. br.Ret = 200
  1485. br.Success = true
  1486. br.Msg = "会议提醒已取消"
  1487. br.Data = resp
  1488. }
  1489. // @Title 敏捷搜索关键词的列表
  1490. // @Description 获取敏捷搜索关键词的列表接口
  1491. // @Success 200 {object} models.ActivityFastsearchKeywordsListResp
  1492. // @router /fastSearchKeWord [get]
  1493. func (this *ActivityABaseController) FastSearch() {
  1494. br := new(models.BaseResponse).Init()
  1495. defer func() {
  1496. this.Data["json"] = br
  1497. this.ServeJSON()
  1498. }()
  1499. resp := new(models.ActivityFastsearchKeywordsListResp)
  1500. list, err := models.GetActivityFastsearchKeywordsList()
  1501. if err != nil {
  1502. br.Msg = "获取失败"
  1503. br.ErrMsg = "获取数据失败,Err:" + err.Error()
  1504. return
  1505. }
  1506. resp.List = list
  1507. br.Ret = 200
  1508. br.Success = true
  1509. br.Msg = "获取成功"
  1510. br.Data = resp
  1511. }
  1512. // @Title 主题列表
  1513. // @Description 获取活动主题列表接口
  1514. // @Param ChartPermissionIds query string false "行业id 多个用 , 隔开"
  1515. // @Param ActivityTypeIds query string false "活动类型id 多个用 , 隔开"
  1516. // @Param ActiveState query string false "活动进行状态 未开始:1、进行中2、已结束3"
  1517. // @Param WhichDay query string false "哪一天 今天:1、明天:2,多个用 , 隔开"
  1518. // @Param Label query string false "搜索主题 多个用 , 隔开 (空为活动主题,非空为更多主题)"
  1519. // @Success 200 {object} models.GetCygxActivityLabelListRep
  1520. // @router /labelList [get]
  1521. func (this *ActivityCoAntroller) LabelList() {
  1522. br := new(models.BaseResponse).Init()
  1523. defer func() {
  1524. this.Data["json"] = br
  1525. this.ServeJSON()
  1526. }()
  1527. user := this.User
  1528. if user == nil {
  1529. br.Msg = "请登录"
  1530. br.ErrMsg = "请登录,SysUser Is Empty"
  1531. return
  1532. }
  1533. pageSize, _ := this.GetInt("PageSize")
  1534. //currentIndex, _ := this.GetInt("CurrentIndex")
  1535. chartPermissionIds := this.GetString("ChartPermissionIds")
  1536. activityTypeIds := this.GetString("ActivityTypeIds")
  1537. whichDay := this.GetString("WhichDay")
  1538. isShowJurisdiction, _ := this.GetInt("IsShowJurisdiction")
  1539. activeState := this.GetString("ActiveState")
  1540. label := this.GetString("Label")
  1541. //入参为 undefined 时的处理
  1542. if chartPermissionIds == "undefined" {
  1543. chartPermissionIds = ""
  1544. }
  1545. if activityTypeIds == "undefined" {
  1546. activityTypeIds = ""
  1547. }
  1548. if whichDay == "undefined" {
  1549. whichDay = ""
  1550. }
  1551. if activeState == "undefined" {
  1552. activeState = ""
  1553. }
  1554. if label == "undefined" {
  1555. label = ""
  1556. }
  1557. var userType int
  1558. var permissionStr string
  1559. if user.CompanyId <= 1 {
  1560. userType = 0
  1561. } else {
  1562. total, err := models.GetCountCompanyDetailByIdGroup(user.CompanyId)
  1563. if err != nil {
  1564. br.Msg = "获取失败"
  1565. br.ErrMsg = "获取失败,Err:" + err.Error()
  1566. return
  1567. }
  1568. if total == 0 {
  1569. userType = 0
  1570. } else {
  1571. companyDetail, err := models.GetCompanyDetailByIdGroup(user.CompanyId)
  1572. if err != nil {
  1573. br.Msg = "获取信息失败!"
  1574. br.ErrMsg = "获取客户详情失败,Err:" + err.Error()
  1575. return
  1576. }
  1577. if companyDetail == nil {
  1578. br.Msg = "获取信息失败!"
  1579. br.ErrMsg = "客户不存在,uid:" + strconv.Itoa(user.UserId) + "CompanyId:" + strconv.Itoa(user.CompanyId)
  1580. return
  1581. }
  1582. permissionStr, err = models.GetCompanyPermission(user.CompanyId)
  1583. if err != nil {
  1584. br.Msg = "获取信息失败"
  1585. br.ErrMsg = "获取客户信息失败,Err:" + err.Error()
  1586. return
  1587. }
  1588. //1、永续客户
  1589. //2、大套餐客户(4个行业全开通的正式客户)
  1590. //3、分行业套餐客户(开通对应行业的正式客户)
  1591. //4、仅开通专家套餐的正式客户
  1592. //5、开通对应行业套餐或专家套餐的试用客户
  1593. if companyDetail.Status == "永续" {
  1594. userType = 1
  1595. } else if companyDetail.Status == "试用" {
  1596. userType = 5
  1597. } else if companyDetail.Status == "正式" {
  1598. if permissionStr == "专家" {
  1599. userType = 4
  1600. } else if strings.Contains(permissionStr, "医药") && strings.Contains(permissionStr, "消费") && strings.Contains(permissionStr, "科技") && strings.Contains(permissionStr, "智造") {
  1601. userType = 2
  1602. } else {
  1603. userType = 3
  1604. }
  1605. if userType == 3 {
  1606. if !strings.Contains(permissionStr, "医药") && !strings.Contains(permissionStr, "消费") && !strings.Contains(permissionStr, "科技") && !strings.Contains(permissionStr, "智造") {
  1607. userType = 4
  1608. }
  1609. }
  1610. }
  1611. }
  1612. }
  1613. if isShowJurisdiction == 1 && chartPermissionIds == "" && userType == 4 {
  1614. activityTypeIds = "1,3"
  1615. }
  1616. var startSize int
  1617. //if pageSize <= 0 {
  1618. // pageSize = utils.PageSize20
  1619. //}
  1620. //currentIndex = 1
  1621. pageSize = 15
  1622. //startSize = utils.StartIndex(currentIndex, pageSize)
  1623. var condition string
  1624. var sortTime string
  1625. var pars []interface{}
  1626. //活动可见限制
  1627. var sqlExport string
  1628. slicePer := strings.Split(permissionStr, ",")
  1629. var permissionSqlStr string
  1630. //for _, v := range slicePer {
  1631. // permissionSqlStr += "'" + v + "',"
  1632. //}
  1633. for _, v := range slicePer {
  1634. if userType == 1 {
  1635. if v != "研选" {
  1636. permissionSqlStr += "'" + v + "',"
  1637. }
  1638. } else {
  1639. permissionSqlStr += "'" + v + "',"
  1640. }
  1641. }
  1642. permissionSqlStr = strings.TrimRight(permissionSqlStr, ",")
  1643. permissionSqlStr = ` AND art.chart_permission_name IN (` + permissionSqlStr + `)`
  1644. sqlExport = ` AND (art.customer_type_ids LIKE '%` + strconv.Itoa(userType) + `%' `
  1645. if userType == 2 {
  1646. sqlExport += ` OR art.customer_type_ids LIKE '%3%' `
  1647. }
  1648. if (userType == 2 || userType == 3) && strings.Contains(permissionStr, "专家") {
  1649. sqlExport += ` OR art.customer_type_ids LIKE '%4%' `
  1650. }
  1651. sqlExport += `) `
  1652. condition += ` AND art.publish_status = 1 AND art.label != '' `
  1653. //condition += ` AND art.active_state = 1 `
  1654. var conditionOr string
  1655. if (userType == 2 || userType == 3 || userType == 4) && strings.Contains(permissionStr, "专家") {
  1656. conditionOr += ` OR ( art.is_limit_people = 1 AND art.customer_type_ids LIKE '%4%' ` + condition + `) `
  1657. }
  1658. if (userType == 5) && strings.Contains(permissionStr, "专家") {
  1659. conditionOr += ` OR ( art.is_limit_people = 1 AND art.customer_type_ids LIKE '%5%' ` + condition + `) `
  1660. }
  1661. if userType == 1 {
  1662. conditionOr += ` OR ( art.is_limit_people = 0 ` + condition + permissionSqlStr + `) `
  1663. } else {
  1664. conditionOr += ` OR ( art.is_limit_people = 0 ` + condition + `) `
  1665. }
  1666. //conditionOr += ` OR ( art.is_limit_people = 0 ` + condition + `) `
  1667. condition += `AND art.is_limit_people = 1 ` + permissionSqlStr + sqlExport + conditionOr
  1668. resp := new(models.GetCygxActivityLabelListRep)
  1669. //conditionLaable := condition
  1670. //主题
  1671. if label != "" {
  1672. sortTime = ` timesort DESC `
  1673. listAll, errList := models.GetActivityLabelListAll(condition, sortTime, pars, startSize, 32)
  1674. if errList != nil {
  1675. br.Msg = "获取失败"
  1676. br.ErrMsg = "获取失败,Err:" + errList.Error()
  1677. return
  1678. }
  1679. sortTime = ` mintimesort ASC `
  1680. condition += ` AND art.active_state = 1 `
  1681. list1, errList := models.GetActivityLabelListAll(condition, sortTime, pars, startSize, 16)
  1682. if errList != nil {
  1683. br.Msg = "获取失败"
  1684. br.ErrMsg = "获取失败,Err:" + errList.Error()
  1685. return
  1686. }
  1687. for _, v := range listAll {
  1688. var isHAve bool
  1689. for _, v2 := range list1 {
  1690. if v2.KeyWord == v.KeyWord {
  1691. isHAve = true
  1692. }
  1693. }
  1694. if !isHAve {
  1695. resp.List = append(resp.List, v)
  1696. }
  1697. }
  1698. br.Ret = 200
  1699. br.Success = true
  1700. br.Msg = "获取成功"
  1701. br.Data = resp
  1702. return
  1703. } else {
  1704. //行业名称
  1705. condition = ` AND art.publish_status = 1 AND art.label != '' `
  1706. if len(chartPermissionIds) > 0 {
  1707. condition += ` AND art.chart_permission_id IN (` + chartPermissionIds + `)`
  1708. }
  1709. if activityTypeIds != "" {
  1710. condition += ` AND art.activity_type_id IN (` + activityTypeIds + `)`
  1711. }
  1712. var conditionOr string
  1713. if whichDay != "" {
  1714. var startDate string
  1715. var endDate string
  1716. if whichDay == "1" {
  1717. startDate = time.Now().Format(utils.FormatDate)
  1718. endDate = startDate
  1719. } else if whichDay == "2" {
  1720. startDate = time.Now().AddDate(0, 0, +1).Format(utils.FormatDate)
  1721. endDate = startDate
  1722. } else {
  1723. startDate = time.Now().Format(utils.FormatDate)
  1724. endDate = time.Now().AddDate(0, 0, +1).Format(utils.FormatDate)
  1725. }
  1726. condition += ` AND art.activity_time >= ` + "'" + startDate + " 00:00:00'"
  1727. condition += ` AND art.activity_time <= ` + "'" + endDate + " 23:59:59'"
  1728. }
  1729. if activeState != "" {
  1730. condition += ` AND art.active_state IN (` + activeState + `)`
  1731. } else {
  1732. condition += ` AND art.active_state IN (1)`
  1733. }
  1734. if (userType == 2 || userType == 3 || userType == 4) && strings.Contains(permissionStr, "专家") {
  1735. conditionOr += ` OR ( art.is_limit_people = 1 AND art.customer_type_ids LIKE '%4%' ` + condition + `) `
  1736. }
  1737. if (userType == 5) && strings.Contains(permissionStr, "专家") {
  1738. conditionOr += ` OR ( art.is_limit_people = 1 AND art.customer_type_ids LIKE '%5%' ` + condition + `) `
  1739. }
  1740. if userType == 1 {
  1741. conditionOr += ` OR ( art.is_limit_people = 0 ` + condition + permissionSqlStr + `) `
  1742. } else {
  1743. conditionOr += ` OR ( art.is_limit_people = 0 ` + condition + `) `
  1744. }
  1745. condition += `AND art.is_limit_people = 1 ` + permissionSqlStr + sqlExport + conditionOr
  1746. }
  1747. sortTime = ` mintimesort ASC `
  1748. list, errList := models.GetActivityLabelListAll(condition, sortTime, pars, startSize, pageSize)
  1749. if errList != nil {
  1750. br.Msg = "获取失败"
  1751. br.ErrMsg = "获取失败,Err:" + errList.Error()
  1752. return
  1753. }
  1754. //resp := new(models.GetCygxActivityLabelListRep)
  1755. resp.List = list
  1756. br.Ret = 200
  1757. br.Success = true
  1758. br.Msg = "获取成功"
  1759. br.Data = resp
  1760. }
  1761. // @Title 上传公司名称excel
  1762. // @Description 上传参会表格数据
  1763. // @Param File query file true "文件"
  1764. // @Success 200 Ret=200 导入成功
  1765. // @router /activityMeet/import [post]
  1766. func (this *ActivityCoAntroller) Import() {
  1767. br := new(models.BaseResponse).Init()
  1768. defer func() {
  1769. this.Data["json"] = br
  1770. this.ServeJSON()
  1771. }()
  1772. sysUser := this.User
  1773. if sysUser == nil {
  1774. br.Msg = "请重新登录"
  1775. return
  1776. }
  1777. file, h, err := this.GetFile("File")
  1778. if err != nil {
  1779. br.Msg = "获取文件失败"
  1780. br.ErrMsg = "获取文件失败,Err:" + err.Error()
  1781. return
  1782. }
  1783. uploadDir := "static/xls"
  1784. err = os.MkdirAll(uploadDir, 766)
  1785. if err != nil {
  1786. br.Msg = "存储目录创建失败"
  1787. br.ErrMsg = "存储目录创建失败,Err:" + err.Error()
  1788. return
  1789. }
  1790. path := uploadDir + "/" + time.Now().Format(utils.FormatDateTimeUnSpace) + h.Filename
  1791. defer file.Close()
  1792. err = this.SaveToFile("File", path)
  1793. if err != nil {
  1794. br.Msg = "文件保存失败"
  1795. br.ErrMsg = "文件保存失败,Err:" + err.Error()
  1796. return
  1797. }
  1798. xlFile, err := xlsx.OpenFile(path)
  1799. if err != nil {
  1800. br.Msg = "文件导入失败"
  1801. br.ErrMsg = "文件导入失败,Err:" + err.Error()
  1802. return
  1803. }
  1804. //允许添加的联系人
  1805. needAddAttendanc := make([]*models.UserWhiteList, 0)
  1806. // 遍历sheet页读取
  1807. for _, sheet := range xlFile.Sheets {
  1808. //遍历行读取
  1809. maxRow := sheet.MaxRow
  1810. for i := 0; i < maxRow; i++ {
  1811. if i >= 1 {
  1812. row := sheet.Row(i)
  1813. cells := row.Cells
  1814. var companyName, permission string
  1815. for k, cell := range cells {
  1816. if k == 0 {
  1817. companyName = cell.String()
  1818. }
  1819. if k == 2 {
  1820. permission = cell.String()
  1821. }
  1822. }
  1823. //这些字段都没有的话,系统认为excel到底了
  1824. if companyName == "" {
  1825. break
  1826. }
  1827. item := new(models.UserWhiteList)
  1828. item.CompanyName = companyName
  1829. item.Permission = permission
  1830. needAddAttendanc = append(needAddAttendanc, item)
  1831. }
  1832. }
  1833. }
  1834. //var mobileStr string
  1835. var permissionStr string
  1836. for k, v := range needAddAttendanc {
  1837. if k > 0 && v.CompanyName != needAddAttendanc[k-1].CompanyName {
  1838. permissionStr, err = models.GetCompanyPermissionByName(v.CompanyName)
  1839. if err != nil {
  1840. br.Msg = "获取信息失败"
  1841. br.ErrMsg = "获取客户信息失败,Err:" + err.Error()
  1842. return
  1843. }
  1844. }
  1845. if k == 0 {
  1846. permissionStr, err = models.GetCompanyPermissionByName(v.CompanyName)
  1847. if err != nil {
  1848. br.Msg = "获取信息失败"
  1849. br.ErrMsg = "获取客户信息失败,Err:" + err.Error()
  1850. return
  1851. }
  1852. }
  1853. needAddAttendanc[k].Permission = permissionStr
  1854. fmt.Println(permissionStr)
  1855. }
  1856. defer func() {
  1857. os.Remove(path)
  1858. }()
  1859. //创建excel
  1860. dir, errFile := os.Executable()
  1861. exPath := filepath.Dir(dir)
  1862. downLoadnFilePath := exPath + "/" + time.Now().Format(utils.FormatDateTimeUnSpace) + ".xlsx"
  1863. xlsxFile := xlsx.NewFile()
  1864. if errFile != nil {
  1865. br.Msg = "生成文件失败Err:" + errFile.Error()
  1866. return
  1867. }
  1868. style := xlsx.NewStyle()
  1869. alignment := xlsx.Alignment{
  1870. Horizontal: "center",
  1871. Vertical: "center",
  1872. WrapText: true,
  1873. }
  1874. style.Alignment = alignment
  1875. style.ApplyAlignment = true
  1876. sheet, err := xlsxFile.AddSheet("白名单")
  1877. if err != nil {
  1878. br.Msg = "新增Sheet失败,Err:" + err.Error()
  1879. return
  1880. }
  1881. //标头
  1882. rowTitle := sheet.AddRow()
  1883. cellA := rowTitle.AddCell()
  1884. cellA.Value = ""
  1885. cellB := rowTitle.AddCell()
  1886. cellB.Value = "公司"
  1887. cellC := rowTitle.AddCell()
  1888. cellC.Value = "权限"
  1889. for _, item := range needAddAttendanc {
  1890. row := sheet.AddRow()
  1891. cellA := row.AddCell()
  1892. cellA.Value = item.CompanyName
  1893. cellB := row.AddCell()
  1894. if item.Permission == "" {
  1895. //item.Permission = "专家/医药/智造/消费/研选/科技/策略/路演服务"
  1896. }
  1897. cellB.Value = item.Permission
  1898. }
  1899. errFile = xlsxFile.Save(downLoadnFilePath)
  1900. if errFile != nil {
  1901. br.Msg = "保存文件失败Err:" + errFile.Error()
  1902. return
  1903. }
  1904. br.Msg = "导入成功"
  1905. br.Ret = 200
  1906. br.Success = true
  1907. }
  1908. // @Title 活动带问
  1909. // @Description 新增活动带问接口
  1910. // @Param request body models.AddCygxActivityHelpAsk true "type json string"
  1911. // @Success Ret=200 新增成功
  1912. // @router /askAdd [post]
  1913. func (this *ActivityCoAntroller) AskAdd() {
  1914. br := new(models.BaseResponse).Init()
  1915. defer func() {
  1916. this.Data["json"] = br
  1917. this.ServeJSON()
  1918. }()
  1919. user := this.User
  1920. if user == nil {
  1921. br.Msg = "请登录"
  1922. br.ErrMsg = "请登录,SysUser Is Empty"
  1923. br.Ret = 408
  1924. return
  1925. }
  1926. var req models.CygxActivityHelpAsk
  1927. err := json.Unmarshal(this.Ctx.Input.RequestBody, &req)
  1928. if err != nil {
  1929. br.Msg = "参数解析异常!"
  1930. br.ErrMsg = "参数解析失败,Err:" + err.Error()
  1931. return
  1932. }
  1933. if req.Content == "" {
  1934. br.Msg = "建议内容不可为空"
  1935. return
  1936. }
  1937. content := req.Content
  1938. itemToken, err := services.WxGetToken()
  1939. if err != nil {
  1940. br.Msg = "GetWxAccessToken Err:" + err.Error()
  1941. return
  1942. }
  1943. if itemToken.AccessToken == "" {
  1944. br.Msg = "accessToken is empty"
  1945. return
  1946. }
  1947. commerr, err := weapp.MSGSecCheck(itemToken.AccessToken, content)
  1948. if err != nil {
  1949. br.Msg = "内容校验失败!"
  1950. br.ErrMsg = "内容校验失败,Err:" + err.Error()
  1951. return
  1952. }
  1953. if commerr.ErrCode != 0 {
  1954. br.Msg = "内容违规,请重新提交!"
  1955. br.ErrMsg = "颜文字内容违规,Err:" + commerr.ErrMSG
  1956. return
  1957. }
  1958. activityId := req.ActivityId
  1959. activityInfo, errInfo := models.GetAddActivityInfoById(activityId)
  1960. if activityInfo == nil {
  1961. br.Msg = "操作失败"
  1962. br.ErrMsg = "活动ID错误,不存在activityId:" + strconv.Itoa(activityId)
  1963. return
  1964. }
  1965. if errInfo != nil {
  1966. br.Msg = "操作失败"
  1967. br.ErrMsg = "操作失败,Err:" + errInfo.Error()
  1968. return
  1969. }
  1970. resultTime := utils.StrTimeToTime(activityInfo.ActivityTime) //时间字符串格式转时间格式
  1971. if activityInfo.ActivityTypeId == 1 && activityInfo.ChartPermissionId != 31 {
  1972. if time.Now().After(resultTime.Add(-time.Minute * 15)) {
  1973. br.Msg = "活动开始前15分钟内无法提交问题"
  1974. return
  1975. }
  1976. } else {
  1977. if time.Now().After(resultTime.Add(-time.Minute * 60)) {
  1978. br.Msg = "活动开始前1小时内无法提交问题"
  1979. return
  1980. }
  1981. }
  1982. companyDetail, err := models.GetCompanyDetailById(user.CompanyId)
  1983. if err != nil {
  1984. br.Msg = "提交失败!"
  1985. br.ErrMsg = "获取客户详情失败,Err:" + err.Error()
  1986. return
  1987. }
  1988. if companyDetail == nil {
  1989. br.Msg = "提交失败!"
  1990. br.ErrMsg = "客户不存在,uid:" + strconv.Itoa(user.UserId)
  1991. return
  1992. }
  1993. item := new(models.CygxActivityHelpAsk)
  1994. item.UserId = user.UserId
  1995. item.ActivityId = req.ActivityId
  1996. item.CompanyId = user.CompanyId
  1997. item.CompanyName = companyDetail.CompanyName
  1998. item.CreateTime = time.Now()
  1999. item.Mobile = user.Mobile
  2000. item.Email = user.Email
  2001. item.Content = content
  2002. _, err = models.AddActivityHelpAsk(item)
  2003. if err != nil {
  2004. br.Msg = "提交失败"
  2005. br.ErrMsg = "提交带问失败,Err:" + err.Error()
  2006. return
  2007. }
  2008. br.Ret = 200
  2009. br.Success = true
  2010. br.Msg = "提交成功"
  2011. }