activity_special.go 26 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782
  1. package services
  2. import (
  3. "errors"
  4. "fmt"
  5. "hongze/hongze_clpt/models"
  6. "hongze/hongze_clpt/utils"
  7. "strconv"
  8. "strings"
  9. "time"
  10. )
  11. //func init() {
  12. // UpdateCygxActivitySpecialSignupNum()
  13. //}
  14. func ActivityLabelSpecialSql(chartPermissionIds, whichDay, activeState string) (condition string) {
  15. //行业名称
  16. if len(chartPermissionIds) > 0 {
  17. condition += ` AND art.chart_permission_id IN (` + chartPermissionIds + `)`
  18. }
  19. if whichDay != "" {
  20. var startDate string
  21. var endDate string
  22. if whichDay == "1" {
  23. startDate = time.Now().Format(utils.FormatDate)
  24. endDate = startDate
  25. } else if whichDay == "2" {
  26. startDate = time.Now().AddDate(0, 0, +1).Format(utils.FormatDate)
  27. endDate = startDate
  28. } else if whichDay == "1,2" || whichDay == "2,1" {
  29. startDate = time.Now().Format(utils.FormatDate)
  30. endDate = time.Now().AddDate(0, 0, +1).Format(utils.FormatDate)
  31. } else if whichDay == "3" {
  32. startDate = utils.GetNowWeekMonday().Format(utils.FormatDate)
  33. endDate = utils.GetNowWeekSunday().Format(utils.FormatDate)
  34. } else if whichDay == "4" {
  35. startDate = utils.GetLastWeekMonday().Format(utils.FormatDate)
  36. endDate = utils.GetLastWeekSunday().Format(utils.FormatDate)
  37. } else if whichDay == "5" {
  38. startDate = utils.GetNowMonthFirstDay().Format(utils.FormatDate)
  39. endDate = utils.GetNowMonthLastDay().Format(utils.FormatDate)
  40. } else if whichDay == "6" {
  41. startDate = utils.GetLastMonthFirstDay().Format(utils.FormatDate)
  42. endDate = utils.GetLastMonthLastDay().Format(utils.FormatDate)
  43. } else if whichDay == "3,4" || whichDay == "4,3" {
  44. startDate = utils.GetLastWeekMonday().Format(utils.FormatDate)
  45. endDate = utils.GetNowWeekSunday().Format(utils.FormatDate)
  46. } else if whichDay == "5,6" || whichDay == "6,5" {
  47. startDate = utils.GetLastMonthFirstDay().Format(utils.FormatDate)
  48. endDate = utils.GetNowMonthLastDay().Format(utils.FormatDate)
  49. } else {
  50. startDate = utils.GetNowWeekMonday().Format(utils.FormatDate)
  51. endDate = utils.GetNowWeekSunday().Format(utils.FormatDate)
  52. }
  53. condition += ` AND art.activity_time >= ` + "'" + startDate + " 00:00:00'"
  54. condition += ` AND art.activity_time <= ` + "'" + endDate + " 23:59:59'"
  55. }
  56. if activeState == "2" {
  57. condition += ` AND art.days > 0 AND art.activity_time <= ` + "'" + time.Now().Format(utils.FormatDateTime) + " '"
  58. condition += ` AND art.activity_time_end >= ` + "'" + time.Now().Format(utils.FormatDateTime) + " '"
  59. }
  60. if activeState == "3" {
  61. condition += ` AND art.days > 0 AND art.activity_time_end <= ` + "'" + time.Now().Format(utils.FormatDateTime) + " '"
  62. }
  63. //if activeState == "" && whichDay == "" {
  64. // condition += ` AND art.activity_time_end > ` + "'" + time.Now().Format(utils.FormatDateTime) + " '"
  65. //}
  66. if whichDay != "" {
  67. condition += ` AND art.days > 0 `
  68. }
  69. return
  70. }
  71. //处理专项调研的展示
  72. func GetActivityLabelSpecialList(user *models.WxUserItem, conditionActivitySpecial string) (item *models.ActivityTypeHome, err error) {
  73. itemList := new(models.ActivityTypeHome)
  74. if user.CompanyId <= 1 {
  75. itemList.List = make([]*models.CygxActivityLabelList, 0)
  76. item = itemList
  77. return
  78. }
  79. userType, e := GetSpecialUserType(user)
  80. if e != nil {
  81. err = errors.New("GetSpecialUserType, Err: " + e.Error())
  82. return
  83. }
  84. if userType == 0 {
  85. itemList.List = make([]*models.CygxActivityLabelList, 0)
  86. item = itemList
  87. return
  88. }
  89. companyDetail, e := models.GetCompanyDetailByIdGroupTrip(user.CompanyId)
  90. fmt.Println(e)
  91. if e != nil && e.Error() != utils.ErrNoRow() {
  92. err = errors.New("GetCompanyDetailByIdGroupTrip, Err: " + e.Error())
  93. return
  94. }
  95. if companyDetail == nil {
  96. return
  97. }
  98. //如果是永续的就按照普通的权限逻辑来查,如果不是就按照升级的逻辑来查
  99. var condition string
  100. if companyDetail.Status == "永续" {
  101. condition, e = HandleActivityLabelSpecialPermission(user)
  102. if e != nil {
  103. err = errors.New("HandleActivityLabelSpecialPermission, Err: " + e.Error())
  104. return
  105. }
  106. } else {
  107. condition, e = HandleActivityLabelSpecialTripPermission(user)
  108. if e != nil {
  109. err = errors.New("HandleActivityLabelSpecialPermission, Err: " + e.Error())
  110. return
  111. }
  112. }
  113. var pars []interface{}
  114. condition += ` AND art.publish_status = 1 AND art.label != '' AND art.is_offline = 0 ` + conditionActivitySpecial
  115. ////行业名称
  116. //if isPower == 1 {
  117. // condition += ` AND art.chart_permission_name IN (` + permissionNameStr + `) `
  118. //}
  119. //if chartPermissionIds != "" {
  120. // condition += ` AND art.chart_permission_id IN (` + chartPermissionIds + `) `
  121. //}
  122. conditionTrip := condition
  123. conditionTrip += ` AND art.days > 0 ORDER BY art.activity_time ASC `
  124. specialList, err := models.GetActivityLabelSpecialListAll(conditionTrip, pars, 0, 8)
  125. if err != nil {
  126. return
  127. }
  128. if len(specialList) < 8 {
  129. condition += ` AND art.days = 0 ORDER BY art.last_updated_time DESC`
  130. specialListNotrip, e := models.GetActivityLabelSpecialListAll(condition, pars, 0, 20)
  131. if e != nil {
  132. err = e
  133. return
  134. }
  135. for _, v := range specialListNotrip {
  136. specialList = append(specialList, v)
  137. }
  138. }
  139. for k2, v2 := range specialList {
  140. v2.Resource = 2
  141. specialList[k2].KeyWord = LabelStr(v2.KeyWord, v2.IsShowSubjectName, v2.TemporaryLabel)
  142. specialList[k2].ImgUrlBg = "https://hzstatic.hzinsights.com/static/temp/20220426202204/20220426/XDLLsjC9XAAy8LIzQr7GsjrBbtX6.png"
  143. specialList[k2].ImgUrlBg = utils.ACTIVITY_ZXDY_ImgUrl3
  144. }
  145. itemList.ActivityTypeName = "专项产业调研"
  146. itemList.Resource = 2
  147. itemList.List = specialList
  148. itemList.ActivityTypeId = 7
  149. itemList.OnlineIco = utils.ACTIVITY_ZXDY_ImgUrl1
  150. itemList.ImgUrlBgPc = utils.ACTIVITY_ZXDY_ImgUrl2
  151. item = itemList
  152. return
  153. }
  154. //HandleActivityLabelSpecialPermission 处理专项产业调研的查询权限sql 永续
  155. func HandleActivityLabelSpecialPermission(user *models.WxUserItem) (condition string, err error) {
  156. permissionStr, e := GetCompanyPermission(user.CompanyId)
  157. if e != nil {
  158. err = errors.New("GetCompanyPermission, Err: " + e.Error())
  159. return
  160. }
  161. userType, e := GetSpecialUserType(user)
  162. if e != nil {
  163. err = errors.New("GetSpecialUserType, Err: " + e.Error())
  164. return
  165. }
  166. slicePer := strings.Split(permissionStr, ",")
  167. var permissionSqlStr string
  168. for _, v := range slicePer {
  169. if userType == 1 {
  170. if !strings.Contains(v, "研选") {
  171. permissionSqlStr += "'" + v + "',"
  172. }
  173. } else {
  174. permissionSqlStr += "'" + v + "',"
  175. }
  176. }
  177. permissionSqlStr = strings.TrimRight(permissionSqlStr, ",")
  178. condition = ` AND art.publish_status = 1 AND art.label != '' AND art.is_offline = 0 `
  179. if permissionSqlStr != "" {
  180. condition += ` AND art.chart_permission_name IN (` + permissionSqlStr + `) `
  181. }
  182. condition += ` AND art.customer_type_ids LIKE '%` + strconv.Itoa(userType) + `%' `
  183. return
  184. }
  185. //HandleActivityLabelSpecialPermisseion 处理专项产业调研的查询权限sql
  186. func HandleActivityLabelSpecialTripPermission(user *models.WxUserItem) (condition string, err error) {
  187. permissionStr, e := GetCompanyPermission(user.CompanyId)
  188. if e != nil {
  189. err = errors.New("GetCompanyPermission, Err: " + e.Error())
  190. return
  191. }
  192. userType, e := GetSpecialUserType(user)
  193. if e != nil {
  194. err = errors.New("GetSpecialUserType, Err: " + e.Error())
  195. return
  196. }
  197. slicePer := strings.Split(permissionStr, ",")
  198. var permissionSqlStr string
  199. for _, v := range slicePer {
  200. if userType == 1 {
  201. if !strings.Contains(v, "研选") {
  202. permissionSqlStr += "'" + v + "',"
  203. }
  204. } else {
  205. permissionSqlStr += "'" + v + "',"
  206. }
  207. }
  208. permissionSqlStr = strings.TrimRight(permissionSqlStr, ",")
  209. condition = ` AND art.publish_status = 1 AND art.label != '' AND art.is_offline = 0 `
  210. if permissionSqlStr != "" {
  211. condition += ` AND art.chart_permission_name IN (` + permissionSqlStr + `) `
  212. }
  213. condition += ` AND art.customer_type_ids LIKE '%` + strconv.Itoa(userType) + `%' `
  214. return
  215. }
  216. //获取预报名列表
  217. func GetActivitySpecialPrepareList(user *models.WxUserItem, startSize, pageSize int, keywords, conditionActivity string) (list []*models.CygxActivitySpecialDetail, totalPrepare int, err error) {
  218. companyDetail, e := models.GetCompanyDetailByIdGroupTrip(user.CompanyId)
  219. if e != nil && e.Error() != utils.ErrNoRow() {
  220. err = errors.New("GetCompanyDetailByIdGroupTrip, Err: " + e.Error())
  221. return
  222. }
  223. if companyDetail == nil {
  224. return
  225. }
  226. //如果是永续的就按照普通的权限逻辑来查,如果不是就按照升级的逻辑来查
  227. var condition string
  228. if companyDetail.Status == "永续" {
  229. condition, e = HandleActivityLabelSpecialPermission(user)
  230. if e != nil {
  231. err = errors.New("HandleActivityLabelSpecialPermission, Err: " + e.Error())
  232. return
  233. }
  234. } else {
  235. condition, e = HandleActivityLabelSpecialTripPermission(user)
  236. if e != nil {
  237. err = errors.New("HandleActivityLabelSpecialPermission, Err: " + e.Error())
  238. return
  239. }
  240. }
  241. var pars []interface{}
  242. condition += ` AND art.days = 0 AND art.publish_status = 1 AND art.is_offline = 0 ` + conditionActivity
  243. if keywords != "" {
  244. keywords = "%" + keywords + "%"
  245. condition += ` AND art.research_theme LIKE ? `
  246. pars = append(pars, keywords)
  247. }
  248. totalPrepare, e = models.GetActivitySpecialCount(condition, pars)
  249. if e != nil {
  250. err = errors.New("GetActivitySpecialCount, Err: " + e.Error())
  251. return
  252. }
  253. condition += ` ORDER BY art.last_updated_time DESC `
  254. list, e = models.GetCygxActivitySpecialDetailList(condition, pars, user.UserId, startSize, pageSize)
  255. if e != nil {
  256. err = errors.New("GetCygxActivitySpecialDetailList, Err: " + e.Error())
  257. return
  258. }
  259. return
  260. }
  261. /*
  262. 确定行程的查询 GetActivityLabelSpecialConfirmList
  263. state 进行状态 1:未开始,2:进行中,3:已结束,4:未开始、进行中 不传默认查询全部items []*CygxActivitySpecialDetail
  264. */
  265. func GetActivityLabelSpecialConfirmList(user *models.WxUserItem, startSize, pageSize, state int, keywords, conditionActivity string) (list []*models.CygxActivitySpecialDetail, totalConfirm int, err error) {
  266. //var condition string
  267. companyDetail, e := models.GetCompanyDetailByIdGroupTrip(user.CompanyId)
  268. if e != nil && e.Error() != utils.ErrNoRow() {
  269. err = errors.New("GetCompanyDetailByIdGroupTrip, Err: " + e.Error())
  270. return
  271. }
  272. if companyDetail == nil {
  273. return
  274. }
  275. //如果是永续的就按照普通的权限逻辑来查,如果不是就按照升级的逻辑来查
  276. var condition string
  277. if companyDetail.Status == "永续" {
  278. condition, e = HandleActivityLabelSpecialPermission(user)
  279. if e != nil {
  280. err = errors.New("HandleActivityLabelSpecialPermission, Err: " + e.Error())
  281. return
  282. }
  283. } else {
  284. condition, e = HandleActivityLabelSpecialTripPermission(user)
  285. if e != nil {
  286. err = errors.New("HandleActivityLabelSpecialPermission, Err: " + e.Error())
  287. return
  288. }
  289. }
  290. var pars []interface{}
  291. condition += ` AND art.days >0 AND art.publish_status =1 AND art.is_offline = 0 ` + conditionActivity
  292. if state == 1 {
  293. condition += ` AND art.activity_time > ? `
  294. pars = append(pars, time.Now())
  295. }
  296. if state == 2 {
  297. condition += ` AND art.activity_time < ? `
  298. pars = append(pars, time.Now())
  299. condition += ` AND art.activity_time_end > ? `
  300. pars = append(pars, time.Now())
  301. }
  302. if state == 3 {
  303. condition += ` AND art.activity_time_end < ? `
  304. pars = append(pars, time.Now())
  305. }
  306. if state == 4 {
  307. condition += ` AND art.activity_time_end > ? `
  308. pars = append(pars, time.Now())
  309. }
  310. if keywords != "" {
  311. keywords = "%" + keywords + "%"
  312. condition += ` AND art.research_theme LIKE ? `
  313. pars = append(pars, keywords)
  314. }
  315. totalConfirm, e = models.GetActivitySpecialCount(condition, pars)
  316. if e != nil {
  317. err = errors.New("GetActivitySpecialCount, Err: " + e.Error())
  318. return
  319. }
  320. condition += ` ORDER BY art.activity_time ASC `
  321. list, e = models.GetCygxActivitySpecialDetailList(condition, pars, user.UserId, startSize, pageSize)
  322. if e != nil {
  323. err = errors.New("GetCygxActivitySpecialDetailList, Err: " + e.Error())
  324. return
  325. }
  326. var activityIds []int
  327. for k, v := range list {
  328. resultTimeStart := utils.StrTimeToTime(v.ActivityTime) //时间字符串格式转时间格式
  329. resultTimeEnd := utils.StrTimeToTime(v.ActivityTimeEnd) //时间字符串格式转时间格式
  330. if resultTimeStart.After(time.Now()) {
  331. list[k].ActiveState = strconv.Itoa(1)
  332. } else if time.Now().After(resultTimeEnd) {
  333. list[k].ActiveState = strconv.Itoa(3)
  334. } else {
  335. list[k].ActiveState = strconv.Itoa(2)
  336. }
  337. if list[k].Days == 0 {
  338. list[k].TripStatus = 1
  339. } else {
  340. list[k].TripStatus = 2
  341. }
  342. activityIds = append(activityIds, v.ActivityId)
  343. }
  344. //处理用户已经报名了的行程
  345. UserMap, e := GetSpecialTripUserMap(activityIds, user.UserId)
  346. if e != nil {
  347. err = errors.New("GetSpecialTripUserMap, Err: " + e.Error())
  348. return
  349. }
  350. for k, v := range list {
  351. if _, ok := UserMap[v.ActivityId]; ok {
  352. list[k].IsTrip = 1
  353. }
  354. }
  355. return
  356. }
  357. //获取用户已经报名的活动
  358. func GetSpecialTripUserMap(activityIds []int, userId int) (mapUserId map[int]int, err error) {
  359. var condition string
  360. var pars []interface{}
  361. activityIdsLen := len(activityIds)
  362. if activityIdsLen > 0 {
  363. condition += ` AND activity_id IN (` + utils.GetOrmInReplace(activityIdsLen) + `)`
  364. pars = append(pars, activityIds)
  365. }
  366. condition += ` AND user_id = ? AND is_cancel = 0 `
  367. pars = append(pars, userId)
  368. list, e := models.GetCygxActivitySpecialTripList(condition, pars)
  369. if e != nil {
  370. err = errors.New("GetCygxActivitySpecialTripList, Err: " + e.Error())
  371. return
  372. }
  373. mapUid := make(map[int]int)
  374. for _, v := range list {
  375. mapUid[v.ActivityId] = v.UserId
  376. }
  377. mapUserId = mapUid
  378. return
  379. }
  380. //获取用户已经报名的活动数量
  381. func GetSpecialTripUserSchedule(userId int) (total int, err error) {
  382. var condition string
  383. var pars []interface{}
  384. condition += ` AND t.user_id = ? AND t.is_cancel = 0 `
  385. pars = append(pars, userId)
  386. condition += ` AND a.activity_time_end >= ? `
  387. pars = append(pars, time.Now())
  388. condition += ` AND is_valid = 1 `
  389. total, err = models.GetActivitySpecialTripCountByActivitySpecial(condition, pars)
  390. return
  391. }
  392. //GetActivitySpecialList 获取专项调研列表
  393. func GetActivitySpecialList(user *models.WxUserItem, currentIndex, pageSize int, keywords, conditionActivity, activeState string) (list []*models.CygxActivitySpecialDetail, total int, err error) {
  394. state := 4
  395. if activeState == "3" {
  396. state = 3
  397. }
  398. listConfirm, totalConfirm, e := GetActivityLabelSpecialConfirmList(user, (currentIndex-1)*pageSize, pageSize, state, keywords, conditionActivity)
  399. if e != nil {
  400. err = errors.New("GetActivityLabelSpecialConfirmList, Err: " + e.Error())
  401. return
  402. }
  403. if currentIndex == 1 && len(listConfirm) > 0 {
  404. listConfirm[0].Explain = utils.ACtIVITY_SPECIAL_TRIP_EXPLAIN
  405. }
  406. list = listConfirm
  407. total = totalConfirm
  408. var startSizePrepare, pageSizePrepare int
  409. //全是确定行程的查询数据
  410. if totalConfirm >= currentIndex*pageSize {
  411. startSizePrepare = 0
  412. pageSizePrepare = 0
  413. } else if totalConfirm > (currentIndex-1)*pageSize && totalConfirm < currentIndex*pageSize {
  414. //一半确认行程一半预报名
  415. startSizePrepare = 0
  416. pageSizePrepare = pageSize - len(listConfirm)
  417. } else {
  418. //全是预报名
  419. startSizePrepare = (currentIndex-1)*pageSize - totalConfirm
  420. pageSizePrepare = pageSize - len(listConfirm)
  421. }
  422. listPrepare, totalPrepare, e := GetActivitySpecialPrepareList(user, startSizePrepare, pageSizePrepare, keywords, conditionActivity)
  423. if e != nil {
  424. err = errors.New("GetActivitySpecialPrepareList, Err: " + e.Error())
  425. return
  426. }
  427. if len(listPrepare) > 0 {
  428. for _, v := range listPrepare {
  429. list = append(list, v)
  430. }
  431. if startSizePrepare == 0 {
  432. listPrepare[0].Explain = utils.ACtIVITY_SPECIAL_EXPLAIN
  433. }
  434. }
  435. total = totalConfirm + totalPrepare
  436. //处理封面图片
  437. detail, e := models.GetConfigByCode("city_img_url")
  438. if e != nil {
  439. err = errors.New("GetConfigByCode, Err: " + e.Error())
  440. return
  441. }
  442. detailChart, e := models.GetConfigByCode("chart_img_url")
  443. if e != nil {
  444. err = errors.New("GetConfigByCode, Err: " + e.Error())
  445. return
  446. }
  447. addressList := strings.Split(detail.ConfigValue, "{|}")
  448. mapAddress := make(map[string]string)
  449. chartList := strings.Split(detailChart.ConfigValue, "{|}")
  450. mapChart := make(map[string]string)
  451. var cityName string
  452. var chartName string
  453. var imgUrl string
  454. var imgUrlChart string
  455. for _, v := range addressList {
  456. vslice := strings.Split(v, "_")
  457. cityName = vslice[0]
  458. imgUrl = vslice[len(vslice)-1]
  459. mapAddress[cityName] = imgUrl
  460. }
  461. for _, v := range chartList {
  462. vslice := strings.Split(v, "_")
  463. chartName = vslice[0]
  464. imgUrlChart = vslice[len(vslice)-1]
  465. mapChart[chartName] = imgUrlChart
  466. }
  467. for k, v := range list {
  468. //list[k].ImgUrlText = "https://hongze.oss-cn-shanghai.aliyuncs.com/static/images/202112/20211221/bIdfv8t86xrFRpDOeGGHXOmKEuKl.png"
  469. if mapChart[v.ChartPermissionName] != "" {
  470. list[k].ImgUrl = mapChart[v.ChartPermissionName]
  471. }
  472. list[k].ActivityTypeName = "专项调研"
  473. if list[k].Days == 0 {
  474. list[k].TripStatus = 1
  475. } else {
  476. list[k].TripStatus = 2
  477. list[k].TripImgLink = list[k].TripImgLinkFix
  478. }
  479. }
  480. return
  481. }
  482. //HandleActivitySpecialShow 处理活动的状态
  483. func HandleActivitySpecialShow(activityDetail *models.CygxActivitySpecialDetail, user *models.WxUserItem) (item *models.CygxActivitySpecialDetail, err error) {
  484. var activityIds []int
  485. resultTimeStart := utils.StrTimeToTime(activityDetail.ActivityTime) //时间字符串格式转时间格式
  486. resultTimeEnd := utils.StrTimeToTime(activityDetail.ActivityTimeEnd) //时间字符串格式转时间格式
  487. if resultTimeStart.After(time.Now()) {
  488. activityDetail.ActiveState = strconv.Itoa(1)
  489. } else if time.Now().After(resultTimeEnd) {
  490. activityDetail.ActiveState = strconv.Itoa(3)
  491. } else {
  492. activityDetail.ActiveState = strconv.Itoa(2)
  493. }
  494. activityIds = append(activityIds, activityDetail.ActivityId)
  495. //处理用户已经报名了的行程
  496. UserMap, e := GetSpecialTripUserMap(activityIds, user.UserId)
  497. if e != nil {
  498. err = errors.New("GetSpecialTripUserMap, Err: " + e.Error())
  499. return
  500. }
  501. if activityDetail.Days == 0 {
  502. activityDetail.TripStatus = 1
  503. activityDetail.Explain = utils.ACtIVITY_SPECIAL_EXPLAIN
  504. } else {
  505. activityDetail.TripStatus = 2
  506. activityDetail.TripImgLink = activityDetail.TripImgLinkFix
  507. activityDetail.Explain = utils.ACtIVITY_SPECIAL_TRIP_EXPLAIN
  508. }
  509. if _, ok := UserMap[activityDetail.ActivityId]; ok {
  510. activityDetail.IsTrip = 1
  511. }
  512. item = activityDetail
  513. return
  514. }
  515. //活动与专项调研搜索 GetActivitySpecialSearcheList
  516. func GetActivitySpecialSearcheList(user *models.WxUserItem, condition string, startSize, pageSize int, keywords string, playBack int) (items []*models.ActivityDetail, total int, err error) {
  517. var conditionSpecil string
  518. var pars, parsSpecil []interface{}
  519. if keywords != "" {
  520. keywords = "%" + keywords + "%"
  521. conditionSpecil += ` AND art.days > 0 AND art.publish_status = 1 AND (art.research_theme LIKE ? OR art.label LIKE ? OR art.industrial_name LIKE ? OR art.industrial_subject_name LIKE ? ) `
  522. parsSpecil = append(parsSpecil, keywords, keywords, keywords, keywords)
  523. }
  524. if playBack == 1 {
  525. conditionSpecil += ` AND art.activity_id = 0 `
  526. }
  527. list, totalSearche, e := models.GetActivitySpecialSearcheList(condition, pars, conditionSpecil, parsSpecil, startSize, pageSize)
  528. if e != nil {
  529. err = errors.New("GetActivitySpecialSearcheList, Err: " + e.Error())
  530. return
  531. }
  532. items, e = HandleActivityListButton(list, user)
  533. if e != nil {
  534. err = errors.New("HandleActivityListButton, Err: " + e.Error())
  535. return
  536. }
  537. total = totalSearche
  538. return
  539. }
  540. //获取 专项调研客户类型 //1、永续客户 //2、大套餐客户(4个行业全开通的正式客户) //8、行业升级套餐客户 //9、其余正式客户;5、试用客户
  541. func GetActivitySpecialUserType(companyId int) (userType int, permissionStrnew string, err error) {
  542. var permissionStr string
  543. if companyId <= 1 {
  544. userType = 0
  545. } else {
  546. total, e := models.GetCountCompanyDetailByIdGroupTrip(companyId)
  547. if e != nil {
  548. err = errors.New("GetCountCompanyDetailByIdGroupTrip, Err: " + e.Error())
  549. return
  550. }
  551. if total == 0 {
  552. userType = 0
  553. } else {
  554. companyDetail, e := models.GetCompanyDetailByIdGroupTrip(companyId)
  555. if e != nil {
  556. err = errors.New("GetCompanyDetailByIdGroupTrip, Err: " + e.Error())
  557. return
  558. }
  559. permissionStr, e = models.GetCompanyPermissionByUserTrip(companyId)
  560. if e != nil {
  561. err = errors.New("GetCompanyPermissionByUserTrip, Err: " + e.Error())
  562. return
  563. }
  564. //permissionZhengShiStr, e = models.GetCompanyPermissionByUserZhengShiTrip(companyId)
  565. //if e != nil {
  566. // err = errors.New("GetCompanyPermissionByUserZhengShiTrip, Err: " + e.Error())
  567. // return
  568. //}
  569. //大套餐客户定义:医药、消费、科技、智造。4个行业中为升级,策略是正式,属于大套餐客户
  570. if companyDetail.Status == "永续" {
  571. userType = 1
  572. } else if companyDetail.Status == "试用" {
  573. userType = 5
  574. } else if companyDetail.Status == "正式" {
  575. if permissionStr == "专家" {
  576. userType = 4
  577. } else if strings.Count(permissionStr, "医药") == 2 && strings.Count(permissionStr, "消费") == 2 && strings.Count(permissionStr, "科技") == 2 && strings.Count(permissionStr, "智造") == 2 && strings.Count(permissionStr, "策略") == 1 {
  578. userType = 2
  579. } else {
  580. userType = 3
  581. }
  582. if userType == 3 {
  583. if !strings.Contains(permissionStr, "医药") && !strings.Contains(permissionStr, "消费") && !strings.Contains(permissionStr, "科技") && !strings.Contains(permissionStr, "智造") {
  584. userType = 4
  585. }
  586. }
  587. } else if companyDetail.Status == "冻结" {
  588. userType = 6
  589. } else if companyDetail.Status == "流失" {
  590. userType = 7
  591. }
  592. }
  593. }
  594. permissionStrnew = permissionStr
  595. return
  596. }
  597. //GetSpecialUserType 获取专项产业调研的用户身份类型
  598. //获取 专项调研客户类型 //1、永续客户 //2、大套餐客户(4个行业全开通的正式客户) //8、行业升级套餐客户 //9、其余正式客户;5、试用客户
  599. func GetSpecialUserType(user *models.WxUserItem) (userType int, err error) {
  600. companyId := user.CompanyId
  601. companyDetail, e := models.GetCompanyDetailByIdGroupTrip(companyId)
  602. if e != nil && e.Error() != utils.ErrNoRow() {
  603. err = errors.New("GetCompanyDetailByIdGroupTrip, Err: " + e.Error())
  604. return
  605. }
  606. if companyDetail == nil {
  607. return
  608. }
  609. if companyId <= 1 {
  610. userType = 0
  611. } else {
  612. if companyDetail.Status == "永续" {
  613. userType = 1
  614. } else {
  615. if companyDetail.Status == "正式" {
  616. list, e := models.GetCompanyReportPermissionUpgrade(companyId, 2)
  617. if e != nil && e.Error() != utils.ErrNoRow() {
  618. err = errors.New("GetCompanyReportPermissionUpgrade, Err: " + e.Error())
  619. }
  620. if len(list) == 0 {
  621. userType = 9
  622. }
  623. if len(list) == 4 {
  624. totalName, e := models.GetCompanyPermissionNameCheck(companyId, 2, "策略")
  625. if e != nil {
  626. err = errors.New("获取品种信息失败, Err:" + e.Error())
  627. return
  628. }
  629. if totalName > 0 {
  630. userType = 2
  631. } else {
  632. userType = 8
  633. }
  634. } else {
  635. userType = 8
  636. }
  637. } else if companyDetail.Status == "试用" {
  638. userType = 5
  639. }
  640. }
  641. }
  642. return
  643. }
  644. //GetSpecialDetailUserPower 处理用户查看专项调研详情的权限
  645. func GetSpecialDetailUserPower(user *models.WxUserItem, activityInfo *models.CygxActivitySpecialDetail) (havePower bool, err error) {
  646. permissionStr, e := GetCompanyPermissionUpgrade(user.CompanyId)
  647. if e != nil {
  648. err = errors.New("GetCompanyPermissionUpgrade, Err: " + e.Error())
  649. return
  650. }
  651. fmt.Println(permissionStr)
  652. //如果没有对应的升级权限,则返回
  653. if !strings.Contains(permissionStr, activityInfo.ChartPermissionName) {
  654. return
  655. }
  656. userType, e := GetSpecialUserType(user)
  657. if e != nil {
  658. err = errors.New("GetSpecialUserType, Err: " + e.Error())
  659. return
  660. }
  661. if userType == 0 {
  662. return
  663. }
  664. var pars []interface{}
  665. var condition string
  666. var userTypes string
  667. condition += ` AND art.publish_status = 1 AND art.is_offline = 0 `
  668. userTypes = "%" + strconv.Itoa(userType) + "%"
  669. condition += ` AND art.customer_type_ids LIKE ? `
  670. pars = append(pars, userTypes)
  671. condition += ` AND art.activity_id = ? `
  672. pars = append(pars, activityInfo.ActivityId)
  673. total, e := models.GetActivitySpecialCount(condition, pars)
  674. if e != nil {
  675. err = errors.New("GetSpecialUserType, Err: " + e.Error())
  676. return
  677. }
  678. if total == 1 {
  679. havePower = true
  680. }
  681. return
  682. }
  683. //预报名活动,感兴趣人数满10人时,推送给活动负责人和王芳
  684. func SendWxMsgActivitySpecial10(activityInfo *models.CygxActivitySpecialDetail) (err error) {
  685. activityId := activityInfo.ActivityId
  686. var msg string
  687. defer func() {
  688. if err != nil {
  689. go utils.SendEmail("发送模版消息失败"+"【"+utils.APPNAME+"】"+time.Now().Format("2006-01-02 15:04:05"), msg+";Err:"+err.Error(), utils.EmailSendToUsers)
  690. go utils.SendAlarmMsg(fmt.Sprint("预报名活动,感兴趣人数满10人时,推送给活动负责人和王芳消息发送失败", activityInfo.ResearchTheme, ", activityId"), 2)
  691. utils.FileLog.Info("发送模版消息失败,Err:%s", err.Error())
  692. }
  693. }()
  694. var first string
  695. var keyword1 string
  696. var keyword2 string
  697. var keyword3 string
  698. var keyword4 string
  699. var remark string
  700. adminUser, e := models.GetSellerByAdminId(activityInfo.AdminId)
  701. if e != nil {
  702. err = errors.New("GetSellerByAdminId, Err: " + e.Error())
  703. return
  704. }
  705. cnf, _ := models.GetConfigByCode("tpl_msg")
  706. mobile := adminUser.Mobile + "," + cnf.ConfigValue
  707. specialSignupList, e := models.GetActivityListSpecialByActivityId(activityId)
  708. if e != nil {
  709. err = errors.New("GetActivityListSpecialAll, Err: " + e.Error())
  710. return
  711. }
  712. for _, v := range specialSignupList {
  713. keyword1 += "【" + v.RealName + "--" + v.CompanyName + "】"
  714. }
  715. openIdList, e := models.GetWxOpenIdByMobileList(mobile)
  716. if e != nil {
  717. err = errors.New("GetSellerByAdminId, Err: " + e.Error())
  718. return
  719. }
  720. first = "【" + activityInfo.ResearchTheme + "】已有10人预报名"
  721. keyword3 = "-"
  722. keyword2 = "-"
  723. keyword4 = activityInfo.ResearchTheme
  724. openIdArr := make([]string, 0)
  725. for _, v := range openIdList {
  726. openIdArr = append(openIdArr, v.OpenId)
  727. }
  728. redirectUrl := utils.WX_MSG_PATH_ACTIVITY_SPECIAL_DETAIL + strconv.Itoa(activityId)
  729. sendInfo := new(SendWxTemplate)
  730. sendInfo.First = first
  731. sendInfo.Keyword1 = keyword1
  732. sendInfo.Keyword2 = keyword2
  733. sendInfo.Keyword3 = keyword3
  734. sendInfo.Keyword4 = keyword4
  735. sendInfo.Remark = remark
  736. sendInfo.TemplateId = utils.WxMsgTemplateIdAskMsgXzs
  737. sendInfo.RedirectUrl = redirectUrl
  738. sendInfo.RedirectTarget = 3
  739. sendInfo.Resource = strconv.Itoa(activityId)
  740. sendInfo.SendType = utils.TEMPLATE_MSG_CYGX_ARTICLE_ADD
  741. sendInfo.OpenIdArr = openIdArr
  742. err = PublicSendTemplateMsg(sendInfo)
  743. if err != nil {
  744. return
  745. }
  746. return
  747. }