activity_special.go 27 KB

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