activity_special.go 42 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261
  1. package services
  2. import (
  3. "context"
  4. "errors"
  5. "fmt"
  6. "hongze/hongze_cygx/models"
  7. "hongze/hongze_cygx/utils"
  8. "strconv"
  9. "strings"
  10. "time"
  11. )
  12. //func init() {
  13. // UpdateCygxActivitySpecialSignupNum()
  14. //}
  15. // ActivityLabelSpecialUserSql 专项产业调研用户权限查询数据预处理
  16. func ActivityLabelSpecialUserSql(user *models.WxUserItem) (conditionShengji, conditionZhengshi, conditionHangYe string, err error) {
  17. _, userType, e := HandleActivityLabelSpecialTripPermission(user)
  18. if e != nil {
  19. err = errors.New("HandleActivityLabelSpecialPermission, Err: " + e.Error())
  20. return
  21. }
  22. // 8: 行业升级套餐客户:该活动对应行业为升级权限的客户
  23. permissionShengji, errs := models.GetCompanyPermissionByUserZhengShiTrip(user.CompanyId)
  24. if errs != nil {
  25. err = errs
  26. return
  27. }
  28. if permissionShengji != "" {
  29. slicePerShengji := strings.Split(permissionShengji, ",")
  30. permissionShengji = ""
  31. for _, v := range slicePerShengji {
  32. permissionShengji += "'" + v + "',"
  33. }
  34. permissionShengji = strings.TrimRight(permissionShengji, ",")
  35. conditionShengji = ` art.customer_type_ids LIKE '%8%' AND art.chart_permission_name IN (` + permissionShengji + `)`
  36. }
  37. //9:其他行业正式客户:前述所有正式客户以外的正式客户 查询处理
  38. permissionZhengShiStr, errs := models.GetCompanyPermissionByUserZhengShi(user.CompanyId)
  39. if errs != nil {
  40. err = errs
  41. return
  42. }
  43. if permissionZhengShiStr != "" {
  44. slicePerZhengshi := strings.Split(permissionZhengShiStr, ",")
  45. permissionZhengShiStr = ""
  46. for _, v := range slicePerZhengshi {
  47. if userType == 1 {
  48. //研选权限处理(永续客户无法查看研选)
  49. if !strings.Contains(v, utils.CHART_PERMISSION_NAME_YANXUAN) {
  50. permissionZhengShiStr += "'" + v + "',"
  51. }
  52. } else {
  53. permissionZhengShiStr += "'" + v + "',"
  54. }
  55. }
  56. permissionZhengShiStr = strings.Replace(permissionZhengShiStr, "(主观)", "", -1)
  57. permissionZhengShiStr = strings.Replace(permissionZhengShiStr, "(客观)", "", -1)
  58. permissionZhengShiStr = strings.TrimRight(permissionZhengShiStr, ",")
  59. permissionZhengShiStr += `, '宏观'`
  60. if userType != 1 && userType != 2 && userType != 10 {
  61. conditionHangYe = ` art.customer_type_ids LIKE '%3%' AND art.chart_permission_name IN (` + permissionZhengShiStr + `)`
  62. }
  63. if userType == 3 {
  64. conditionZhengshi = ` art.customer_type_ids LIKE '%9%' AND art.chart_permission_name NOT IN (` + permissionZhengShiStr + `)`
  65. }
  66. }
  67. return
  68. }
  69. // 修改专项调研,用户与公司的参与数量
  70. func UpdateCygxActivitySpecialSignupNum(cont context.Context) (err error) {
  71. defer func() {
  72. if err != nil {
  73. fmt.Println(err)
  74. go utils.SendAlarmMsg("修改活动状态至进行中失败"+err.Error(), 2)
  75. go utils.SendEmail(utils.APPNAME+"【"+utils.RunMode+"】"+"失败提醒", "修改活动状态至进行中失败 ErrMsg:"+err.Error(), utils.EmailSendToUsers)
  76. }
  77. }()
  78. //根据手机号分组获取列表以及数量
  79. var condition string
  80. var pars []interface{}
  81. condition += ` AND s.create_time < ? `
  82. pars = append(pars, time.Now().Format(utils.FormatDate))
  83. listSpecial, err := models.GetActivityListSpecialGroupByMobile(condition, pars)
  84. if err != nil {
  85. return err
  86. }
  87. var mapMobile []string
  88. for _, v := range listSpecial {
  89. mapMobile = append(mapMobile, v.Mobile)
  90. }
  91. //根据手机号获取这些用户的信息
  92. userList, err := models.GetWxUserByMobiles(mapMobile)
  93. if err != nil {
  94. return err
  95. }
  96. //更改这些手机对应的关注关注数量
  97. err = models.UpdateActivitySpecialSignupNumMulti(listSpecial)
  98. if err != nil {
  99. return err
  100. }
  101. //更改这些手机对应的公司ID
  102. err = models.UpdateActivitySpecialSignupCompanyIdMulti(userList)
  103. if err != nil {
  104. return err
  105. }
  106. //根据CompanyId分组获取列表以及数量
  107. listSpecialByCompanyId, err := models.GetActivityListSpecialGroupByCompanyId(condition, pars)
  108. if err != nil {
  109. return err
  110. }
  111. //更改这些公司对应的关注关注数量
  112. err = models.UpdateActivitySpecialSignupCompanyNumMulti(listSpecialByCompanyId)
  113. if err != nil {
  114. return err
  115. }
  116. fmt.Println("UpdateCygxActivitySpecialSignupNum end")
  117. return
  118. }
  119. // 处理专项调研的展示
  120. func GetActivityLabelSpecialList(user *models.WxUserItem, isPower int, chartPermissionIds, permissionNameStr string) (item *models.ActivityTypeHome, err error) {
  121. itemList := new(models.ActivityTypeHome)
  122. if user.CompanyId <= 1 {
  123. itemList.List = make([]*models.CygxActivityLabelList, 0)
  124. item = itemList
  125. return
  126. }
  127. //userType, e := GetSpecialUserType(user)
  128. userType, _, e := GetUserType(user.CompanyId)
  129. if e != nil {
  130. err = errors.New("GetSpecialUserType, Err: " + e.Error())
  131. return
  132. }
  133. if userType == 0 {
  134. itemList.List = make([]*models.CygxActivityLabelList, 0)
  135. item = itemList
  136. return
  137. }
  138. companyDetail, e := models.GetCompanyDetailByIdGroupTrip(user.CompanyId)
  139. if e != nil {
  140. err = errors.New("GetCompanyDetailByIdGroupTrip, Err: " + e.Error())
  141. return
  142. }
  143. //如果是永续的就按照普通的权限逻辑来查,如果不是就按照升级的逻辑来查
  144. var condition string
  145. var conditionUser string
  146. if companyDetail.Status == "永续" {
  147. conditionUser, e = HandleActivityLabelSpecialPermission(user)
  148. if e != nil {
  149. err = errors.New("HandleActivityLabelSpecialPermission, Err: " + e.Error())
  150. return
  151. }
  152. } else {
  153. conditionUser, _, e = HandleActivityLabelSpecialTripPermission(user)
  154. if e != nil {
  155. err = errors.New("HandleActivityLabelSpecialPermission, Err: " + e.Error())
  156. return
  157. }
  158. }
  159. var pars []interface{}
  160. condition += ` AND art.publish_status = 1 AND art.label != '' AND art.is_offline = 0 `
  161. //行业名称
  162. if isPower == 1 {
  163. condition += ` AND art.chart_permission_name IN (` + permissionNameStr + `) `
  164. }
  165. if chartPermissionIds != "" {
  166. condition += ` AND art.chart_permission_id IN (` + chartPermissionIds + `) `
  167. }
  168. //condition += conditionUser
  169. conditionShengji, conditionZhengshi, conditionHangYe, e := ActivityLabelSpecialUserSql(user)
  170. if e != nil {
  171. err = errors.New("ActivityLabelSpecialUserSql, Err: " + e.Error())
  172. return
  173. }
  174. conditionTrip := condition
  175. conditionNoTrip := condition
  176. conditionTripSql := condition
  177. conditionNoTripSql := condition
  178. conditionTrip += ` AND art.days > 0 AND art.activity_time_end > '` + time.Now().Format(utils.FormatDateTime) + ` '`
  179. var conditionZhengshiTrip string
  180. var conditionShengjiTrip string
  181. var conditionHangYeTrip string
  182. //处理专项调研确认行程的其它正式客户权限查询
  183. if conditionZhengshi != "" {
  184. conditionZhengshiTrip = ` OR ( ` + conditionZhengshi + conditionTrip + ` )`
  185. }
  186. //处理升级权限查询
  187. if conditionShengji != "" {
  188. conditionShengjiTrip = ` OR ( ` + conditionShengji + conditionTrip + ` )`
  189. }
  190. //处理行业套餐客户权限查询
  191. if conditionHangYe != "" {
  192. conditionHangYeTrip = ` OR ( ` + conditionHangYe + conditionTrip + ` )`
  193. }
  194. if conditionZhengshi != "" {
  195. conditionTrip += conditionZhengshiTrip
  196. }
  197. if conditionShengjiTrip != "" {
  198. conditionTrip += conditionShengjiTrip
  199. }
  200. if conditionHangYeTrip != "" {
  201. conditionTrip += conditionHangYeTrip
  202. }
  203. //行业套餐客户勾选项单独处理
  204. if userType == 3 {
  205. conditionTripSql += ` AND art.chart_permission_name IN (` + permissionNameStr + `) `
  206. }
  207. conditionTripSql += conditionUser + conditionTrip + ` ORDER BY art.activity_time ASC `
  208. specialList, err := models.GetActivityLabelSpecialListAll(conditionTripSql, pars, 0, 80)
  209. if err != nil {
  210. return
  211. }
  212. conditionNoTrip += ` AND art.days = 0 `
  213. var conditionShengjiNoTrip string
  214. var conditionZhengshiNoTrip string
  215. var conditionHangYeNoTrip string
  216. if conditionShengji != "" {
  217. conditionShengjiNoTrip = ` OR ( ` + conditionShengji + conditionNoTrip + ` )`
  218. }
  219. if conditionZhengshi != "" {
  220. conditionZhengshiNoTrip = ` OR ( ` + conditionZhengshi + conditionNoTrip + ` )`
  221. }
  222. if conditionHangYe != "" {
  223. conditionHangYeNoTrip = ` OR ( ` + conditionHangYe + conditionNoTrip + ` )`
  224. }
  225. if conditionShengji != "" {
  226. conditionNoTrip += conditionShengjiNoTrip
  227. }
  228. if conditionZhengshi != "" {
  229. conditionNoTrip += conditionZhengshiNoTrip
  230. }
  231. if conditionHangYe != "" {
  232. conditionNoTrip += conditionHangYeNoTrip
  233. }
  234. //行业套餐客户勾选项单独处理
  235. if userType == 3 {
  236. conditionNoTripSql += ` AND art.chart_permission_name IN (` + permissionNameStr + `) `
  237. }
  238. conditionNoTripSql += conditionUser + conditionNoTrip + ` ORDER BY art.last_updated_time DESC`
  239. specialListNotrip, e := models.GetActivityLabelSpecialListAll(conditionNoTripSql, pars, 0, 200)
  240. if e != nil {
  241. err = e
  242. return
  243. }
  244. for _, v := range specialListNotrip {
  245. specialList = append(specialList, v)
  246. }
  247. //}
  248. for k2, v2 := range specialList {
  249. if v2.Days == 0 {
  250. specialList[k2].TripStatus = 1
  251. } else {
  252. specialList[k2].TripStatus = 2
  253. }
  254. specialList[k2].KeyWord = LabelStrV5(v2.KeyWord, v2.IsShowSubjectName, v2.TemporaryLabel)
  255. specialList[k2].ImgUrlBg = "https://hzstatic.hzinsights.com/static/temp/20220426202204/20220426/XDLLsjC9XAAy8LIzQr7GsjrBbtX6.png"
  256. specialList[k2].ImgUrlBg = utils.ACTIVITY_ZXDY_ImgUrl3
  257. }
  258. itemList.ActivityTypeName = "专项产业调研"
  259. itemList.Resource = 2
  260. itemList.List = specialList
  261. itemList.ActivityTypeId = 7
  262. itemList.ImgUrl = utils.ACTIVITY_ZXDY_ImgUrl1
  263. itemList.ImgUrlBg = utils.ACTIVITY_ZXDY_ImgUrl2
  264. item = itemList
  265. return
  266. }
  267. // HandleActivityLabelSpecialPermission 处理专项产业调研的查询权限sql 永续
  268. func HandleActivityLabelSpecialPermission(user *models.WxUserItem) (condition string, err error) {
  269. permissionStr, e := GetCompanyPermission(user.CompanyId)
  270. if e != nil {
  271. err = errors.New("GetCompanyPermission, Err: " + e.Error())
  272. return
  273. }
  274. userType, e := GetSpecialUserType(user)
  275. if e != nil {
  276. err = errors.New("GetSpecialUserType, Err: " + e.Error())
  277. return
  278. }
  279. slicePer := strings.Split(permissionStr, ",")
  280. var permissionSqlStr string
  281. for _, v := range slicePer {
  282. if userType == 1 {
  283. if !strings.Contains(v, "研选") {
  284. permissionSqlStr += "'" + v + "',"
  285. }
  286. } else {
  287. permissionSqlStr += "'" + v + "',"
  288. }
  289. }
  290. permissionSqlStr = strings.TrimRight(permissionSqlStr, ",")
  291. condition = ` AND art.publish_status = 1 AND art.label != '' AND art.is_offline = 0 `
  292. //if permissionSqlStr != "" {
  293. // condition += ` AND art.chart_permission_name IN (` + permissionSqlStr + `) `
  294. //}
  295. condition += ` AND art.customer_type_ids LIKE '%` + strconv.Itoa(userType) + `%' `
  296. return
  297. }
  298. // HandleActivityLabelSpecialPermisseion 处理专项产业调研的查询权限sql
  299. func HandleActivityLabelSpecialTripPermission(user *models.WxUserItem) (condition string, userType int, err error) {
  300. permissionStr, e := GetCompanyPermission(user.CompanyId)
  301. if e != nil {
  302. err = errors.New("GetCompanyPermission, Err: " + e.Error())
  303. return
  304. }
  305. userType, _, e = GetUserType(user.CompanyId)
  306. //userType, e := GetSpecialUserType(user)
  307. if e != nil {
  308. err = errors.New("GetSpecialUserType, Err: " + e.Error())
  309. return
  310. }
  311. mapUserType, e := GetActivityCcustomerTypeList()
  312. if e != nil {
  313. err = e
  314. return
  315. }
  316. var userTypeStr string
  317. userTypeStr = mapUserType[userType]
  318. //fmt.Println(userType)
  319. slicePer := strings.Split(permissionStr, ",")
  320. var permissionSqlStr string
  321. for _, v := range slicePer {
  322. if userType == 1 {
  323. if !strings.Contains(v, "研选") {
  324. permissionSqlStr += "'" + v + "',"
  325. }
  326. } else {
  327. permissionSqlStr += "'" + v + "',"
  328. }
  329. }
  330. permissionSqlStr = strings.TrimRight(permissionSqlStr, ",")
  331. condition = ` AND art.publish_status = 1 AND art.label != '' AND art.is_offline = 0 `
  332. if permissionSqlStr != "" && userType == 3 {
  333. condition += ` AND art.chart_permission_name IN (` + permissionSqlStr + `) `
  334. }
  335. condition += ` AND art.customer_type_ids LIKE '%` + userTypeStr + `%' `
  336. //if userType != 2 {
  337. return
  338. }
  339. // 获取预报名列表
  340. func GetActivitySpecialPrepareList(user *models.WxUserItem, startSize, pageSize int, keywords string) (list []*models.CygxActivitySpecialDetail, totalPrepare int, err error) {
  341. companyDetail, e := models.GetCompanyDetailByIdGroupTrip(user.CompanyId)
  342. if e != nil {
  343. err = errors.New("GetCompanyDetailByIdGroupTrip, Err: " + e.Error())
  344. return
  345. }
  346. //如果是永续的就按照普通的权限逻辑来查,如果不是就按照升级的逻辑来查
  347. var condition string
  348. var conditionUser string
  349. if companyDetail.Status == "永续" {
  350. conditionUser, e = HandleActivityLabelSpecialPermission(user)
  351. if e != nil {
  352. err = errors.New("HandleActivityLabelSpecialPermission, Err: " + e.Error())
  353. return
  354. }
  355. } else {
  356. conditionUser, _, e = HandleActivityLabelSpecialTripPermission(user)
  357. if e != nil {
  358. err = errors.New("HandleActivityLabelSpecialPermission, Err: " + e.Error())
  359. return
  360. }
  361. }
  362. var pars []interface{}
  363. condition += ` AND art.days = 0 AND art.publish_status = 1 AND art.is_offline = 0 `
  364. if keywords != "" {
  365. keywords = "%" + keywords + "%"
  366. condition += ` AND art.research_theme LIKE ? `
  367. pars = append(pars, keywords)
  368. }
  369. conditionShengji, conditionZhengshi, conditionHangYe, e := ActivityLabelSpecialUserSql(user)
  370. if e != nil {
  371. err = errors.New("ActivityLabelSpecialUserSql, Err: " + e.Error())
  372. return
  373. }
  374. conditionNoTrip := condition
  375. var conditionShengjiNoTrip string
  376. var conditionZhengshiNoTrip string
  377. var conditionHangYeNoTrip string
  378. if conditionShengji != "" {
  379. conditionShengjiNoTrip = ` OR ( ` + conditionShengji + conditionNoTrip + ` )`
  380. }
  381. if conditionZhengshi != "" {
  382. conditionZhengshiNoTrip = ` OR ( ` + conditionZhengshi + conditionNoTrip + ` )`
  383. }
  384. //处理行业套餐权限查询
  385. if conditionHangYe != "" {
  386. conditionHangYeNoTrip = ` OR ( ` + conditionHangYe + conditionNoTrip + ` )`
  387. }
  388. if conditionShengji != "" {
  389. conditionNoTrip += conditionShengjiNoTrip
  390. }
  391. if conditionZhengshi != "" {
  392. conditionNoTrip += conditionZhengshiNoTrip
  393. }
  394. if conditionHangYe != "" {
  395. conditionNoTrip += conditionHangYeNoTrip
  396. }
  397. conditionNoTripSql := conditionUser + conditionNoTrip
  398. //condition += conditionUser + conditionOr
  399. totalPrepare, e = models.GetActivitySpecialCount(conditionNoTripSql, pars)
  400. if e != nil {
  401. err = errors.New("GetActivitySpecialCount, Err: " + e.Error())
  402. return
  403. }
  404. conditionNoTripSql += ` ORDER BY art.last_updated_time DESC `
  405. list, e = models.GetCygxActivitySpecialDetailList(conditionNoTripSql, pars, user.UserId, startSize, pageSize)
  406. if e != nil {
  407. err = errors.New("GetCygxActivitySpecialDetailList, Err: " + e.Error())
  408. return
  409. }
  410. return
  411. }
  412. /*
  413. 确定行程的查询 GetActivityLabelSpecialConfirmList
  414. state 进行状态 1:未开始,2:进行中,3:已结束,4:未开始、进行中 不传默认查询全部items []*CygxActivitySpecialDetail
  415. */
  416. func GetActivityLabelSpecialConfirmList(user *models.WxUserItem, startSize, pageSize, state int, keywords string) (list []*models.CygxActivitySpecialDetail, totalConfirm int, err error) {
  417. companyDetail, e := models.GetCompanyDetailByIdGroupTrip(user.CompanyId)
  418. if e != nil && e.Error() != utils.ErrNoRow() {
  419. err = errors.New("GetCompanyDetailByIdGroupTrip, Err: " + e.Error())
  420. return
  421. }
  422. if companyDetail == nil {
  423. return
  424. }
  425. //如果是永续的就按照普通的权限逻辑来查,如果不是就按照升级的逻辑来查
  426. var condition string
  427. var conditionUser string
  428. //var userType int
  429. if companyDetail.Status == "永续" {
  430. conditionUser, e = HandleActivityLabelSpecialPermission(user)
  431. if e != nil {
  432. err = errors.New("HandleActivityLabelSpecialPermission, Err: " + e.Error())
  433. return
  434. }
  435. } else {
  436. conditionUser, _, e = HandleActivityLabelSpecialTripPermission(user)
  437. if e != nil {
  438. err = errors.New("HandleActivityLabelSpecialPermission, Err: " + e.Error())
  439. return
  440. }
  441. }
  442. var pars []interface{}
  443. condition += ` AND art.days >0 AND art.publish_status =1 AND art.is_offline = 0 `
  444. if state == 1 {
  445. condition += ` AND art.activity_time > '` + time.Now().Format(utils.FormatDateTime) + `'`
  446. }
  447. if state == 2 {
  448. condition += ` AND art.activity_time < '` + time.Now().Format(utils.FormatDateTime) + `'`
  449. condition += ` AND art.activity_time_end > '` + time.Now().Format(utils.FormatDateTime) + `'`
  450. }
  451. if state == 3 {
  452. condition += ` AND art.activity_time_end < '` + time.Now().Format(utils.FormatDateTime) + `'`
  453. }
  454. if state == 4 {
  455. condition += ` AND art.activity_time_end > '` + time.Now().Format(utils.FormatDateTime) + `'`
  456. }
  457. if keywords != "" {
  458. keywords = "%" + keywords + "%"
  459. condition += ` AND art.research_theme LIKE ` + keywords
  460. //pars = append(pars, keywords)
  461. }
  462. conditionTrip := condition
  463. conditionTripSql := condition
  464. conditionShengji, conditionZhengshi, conditionHangYe, e := ActivityLabelSpecialUserSql(user)
  465. if e != nil {
  466. err = errors.New("ActivityLabelSpecialUserSql, Err: " + e.Error())
  467. return
  468. }
  469. conditionTrip += ` AND art.days > 0 AND art.activity_time_end > '` + time.Now().Format(utils.FormatDateTime) + ` '`
  470. var conditionZhengshiTrip string
  471. var conditionShengjiTrip string
  472. var conditionHangYeTrip string
  473. //处理专项调研确认行程的其它正式客户权限查询
  474. if conditionZhengshi != "" {
  475. conditionZhengshiTrip = ` OR ( ` + conditionZhengshi + conditionTrip + ` )`
  476. }
  477. //处理专项调研确认行程的升级权限查询
  478. if conditionShengji != "" {
  479. conditionShengjiTrip = ` OR ( ` + conditionShengji + conditionTrip + ` )`
  480. }
  481. //处理行业套餐客户权限查询
  482. if conditionHangYe != "" {
  483. conditionHangYeTrip = ` OR ( ` + conditionHangYe + conditionTrip + ` )`
  484. }
  485. if conditionZhengshi != "" {
  486. conditionTrip += conditionZhengshiTrip
  487. }
  488. if conditionShengjiTrip != "" {
  489. conditionTrip += conditionShengjiTrip
  490. }
  491. if conditionHangYeTrip != "" {
  492. conditionTrip += conditionHangYeTrip
  493. }
  494. conditionTripSql += conditionUser + conditionTrip + ` ORDER BY art.activity_time ASC `
  495. totalConfirm, e = models.GetActivitySpecialCount(conditionTripSql, pars)
  496. if e != nil {
  497. err = errors.New("GetActivitySpecialCount, Err: " + e.Error())
  498. return
  499. }
  500. condition += ` ORDER BY art.activity_time ASC `
  501. list, e = models.GetCygxActivitySpecialDetailList(conditionTripSql, pars, user.UserId, startSize, pageSize)
  502. if e != nil {
  503. err = errors.New("GetCygxActivitySpecialDetailList, Err: " + e.Error())
  504. return
  505. }
  506. var activityIds []int
  507. for k, v := range list {
  508. resultTimeStart := utils.StrTimeToTime(v.ActivityTime) //时间字符串格式转时间格式
  509. resultTimeEnd := utils.StrTimeToTime(v.ActivityTimeEnd) //时间字符串格式转时间格式
  510. if resultTimeStart.After(time.Now()) {
  511. list[k].ActiveState = 1
  512. } else if time.Now().After(resultTimeEnd) {
  513. list[k].ActiveState = 3
  514. } else {
  515. list[k].ActiveState = 2
  516. }
  517. if list[k].Days == 0 {
  518. list[k].TripStatus = 1
  519. } else {
  520. list[k].TripStatus = 2
  521. }
  522. activityIds = append(activityIds, v.ActivityId)
  523. }
  524. //处理用户已经报名了的行程
  525. UserMap, e := GetSpecialTripUserMap(activityIds, user.UserId)
  526. if e != nil {
  527. err = errors.New("GetSpecialTripUserMap, Err: " + e.Error())
  528. return
  529. }
  530. for k, v := range list {
  531. if _, ok := UserMap[v.ActivityId]; ok {
  532. list[k].IsTrip = 1
  533. }
  534. }
  535. return
  536. }
  537. // 获取用户已经报名的活动
  538. func GetSpecialTripUserMap(activityIds []int, userId int) (mapUserId map[int]int, err error) {
  539. var condition string
  540. var pars []interface{}
  541. activityIdsLen := len(activityIds)
  542. if activityIdsLen > 0 {
  543. condition += ` AND activity_id IN (` + utils.GetOrmInReplace(activityIdsLen) + `)`
  544. pars = append(pars, activityIds)
  545. }
  546. condition += ` AND user_id = ? AND is_cancel = 0 `
  547. pars = append(pars, userId)
  548. list, e := models.GetCygxActivitySpecialTripList(condition, pars)
  549. if e != nil {
  550. err = errors.New("GetCygxActivitySpecialTripList, Err: " + e.Error())
  551. return
  552. }
  553. mapUid := make(map[int]int)
  554. for _, v := range list {
  555. mapUid[v.ActivityId] = v.UserId
  556. }
  557. mapUserId = mapUid
  558. return
  559. }
  560. // 获取用户已经报名的活动数量
  561. func GetSpecialTripUserSchedule(userId int) (total int, err error) {
  562. var condition string
  563. var pars []interface{}
  564. condition += ` AND t.user_id = ? AND t.is_cancel = 0 `
  565. pars = append(pars, userId)
  566. condition += ` AND a.activity_time_end >= ? `
  567. pars = append(pars, time.Now())
  568. condition += ` AND is_valid = 1 `
  569. total, err = models.GetActivitySpecialTripCountByActivitySpecial(condition, pars)
  570. return
  571. }
  572. // GetActivitySpecialList 获取专项调研列表
  573. func GetActivitySpecialList(user *models.WxUserItem, currentIndex, pageSize int, keywords string) (list []*models.CygxActivitySpecialDetail, total int, err error) {
  574. listConfirm, totalConfirm, e := GetActivityLabelSpecialConfirmList(user, (currentIndex-1)*pageSize, pageSize, 4, keywords)
  575. if e != nil && e.Error() != utils.ErrNoRow() {
  576. err = errors.New("GetActivityLabelSpecialConfirmList11, Err: " + e.Error())
  577. return
  578. }
  579. //if totalConfirm == 0 {
  580. // return
  581. //}
  582. if currentIndex == 1 && len(listConfirm) > 0 {
  583. listConfirm[0].Explain = utils.ACtIVITY_SPECIAL_TRIP_EXPLAIN
  584. }
  585. list = listConfirm
  586. total = totalConfirm
  587. var startSizePrepare, pageSizePrepare int
  588. //全是确定行程的查询数据
  589. if totalConfirm >= currentIndex*pageSize {
  590. startSizePrepare = 0
  591. pageSizePrepare = 0
  592. } else if totalConfirm > (currentIndex-1)*pageSize && totalConfirm < currentIndex*pageSize {
  593. //一半确认行程一半预报名
  594. startSizePrepare = 0
  595. pageSizePrepare = pageSize - len(listConfirm)
  596. } else {
  597. //全是预报名
  598. startSizePrepare = (currentIndex-1)*pageSize - totalConfirm
  599. pageSizePrepare = pageSize - len(listConfirm)
  600. }
  601. listPrepare, totalPrepare, e := GetActivitySpecialPrepareList(user, startSizePrepare, pageSizePrepare, keywords)
  602. if e != nil && e.Error() != utils.ErrNoRow() {
  603. err = errors.New("GetActivityLabelSpecialConfirmList, Err: " + e.Error())
  604. return
  605. }
  606. if len(listPrepare) > 0 {
  607. for _, v := range listPrepare {
  608. list = append(list, v)
  609. }
  610. if startSizePrepare == 0 {
  611. listPrepare[0].Explain = utils.ACtIVITY_SPECIAL_EXPLAIN
  612. }
  613. } else {
  614. err = nil
  615. return
  616. }
  617. total = totalConfirm + totalPrepare
  618. //处理封面图片
  619. detail, e := models.GetConfigByCode("city_img_url")
  620. if e != nil {
  621. err = errors.New("GetConfigByCode, Err: " + e.Error())
  622. return
  623. }
  624. detailChart, e := models.GetConfigByCode("chart_img_url")
  625. if e != nil {
  626. err = errors.New("GetConfigByCode, Err: " + e.Error())
  627. return
  628. }
  629. addressList := strings.Split(detail.ConfigValue, "{|}")
  630. mapAddress := make(map[string]string)
  631. chartList := strings.Split(detailChart.ConfigValue, "{|}")
  632. mapChart := make(map[string]string)
  633. var cityName string
  634. var chartName string
  635. var imgUrl string
  636. var imgUrlChart string
  637. for _, v := range addressList {
  638. vslice := strings.Split(v, "_")
  639. cityName = vslice[0]
  640. imgUrl = vslice[len(vslice)-1]
  641. mapAddress[cityName] = imgUrl
  642. }
  643. for _, v := range chartList {
  644. vslice := strings.Split(v, "_")
  645. chartName = vslice[0]
  646. imgUrlChart = vslice[len(vslice)-1]
  647. mapChart[chartName] = imgUrlChart
  648. }
  649. for k, v := range list {
  650. //list[k].ImgUrlText = "https://hongze.oss-cn-shanghai.aliyuncs.com/static/images/202112/20211221/bIdfv8t86xrFRpDOeGGHXOmKEuKl.png"
  651. if mapChart[v.ChartPermissionName] != "" {
  652. list[k].ImgUrl = mapChart[v.ChartPermissionName]
  653. }
  654. list[k].ActivityTypeName = "专项调研"
  655. if list[k].Days == 0 {
  656. list[k].TripStatus = 1
  657. } else {
  658. list[k].TripStatus = 2
  659. list[k].TripImgLink = list[k].TripImgLinkFix
  660. }
  661. }
  662. return
  663. }
  664. // HandleActivitySpecialShow 处理活动的状态
  665. func HandleActivitySpecialShow(activityDetail *models.CygxActivitySpecialDetail, user *models.WxUserItem) (item *models.CygxActivitySpecialDetail, err error) {
  666. var activityIds []int
  667. resultTimeStart := utils.StrTimeToTime(activityDetail.ActivityTime) //时间字符串格式转时间格式
  668. resultTimeEnd := utils.StrTimeToTime(activityDetail.ActivityTimeEnd) //时间字符串格式转时间格式
  669. if resultTimeStart.After(time.Now()) {
  670. activityDetail.ActiveState = 1
  671. } else if time.Now().After(resultTimeEnd) {
  672. activityDetail.ActiveState = 3
  673. } else {
  674. activityDetail.ActiveState = 2
  675. }
  676. activityIds = append(activityIds, activityDetail.ActivityId)
  677. //处理用户已经报名了的行程
  678. UserMap, e := GetSpecialTripUserMap(activityIds, user.UserId)
  679. if e != nil {
  680. err = errors.New("GetSpecialTripUserMap, Err: " + e.Error())
  681. return
  682. }
  683. if activityDetail.Days == 0 {
  684. activityDetail.TripStatus = 1
  685. activityDetail.Explain = utils.ACtIVITY_SPECIAL_EXPLAIN
  686. } else {
  687. activityDetail.TripStatus = 2
  688. activityDetail.TripImgLink = activityDetail.TripImgLinkFix
  689. activityDetail.Explain = utils.ACtIVITY_SPECIAL_TRIP_EXPLAIN
  690. }
  691. if _, ok := UserMap[activityDetail.ActivityId]; ok {
  692. activityDetail.IsTrip = 1
  693. }
  694. item = activityDetail
  695. return
  696. }
  697. // 活动与专项调研搜索 GetActivitySpecialSearcheList
  698. func GetActivitySpecialSearcheList(user *models.WxUserItem, condition string, startSize, pageSize int, keywords string) (items []*models.ActivityDetail, total int, err error) {
  699. var conditionSpecil string
  700. var pars, parsSpecil []interface{}
  701. keyword := keywords
  702. if keywords != "" {
  703. keywords = "%" + keywords + "%"
  704. conditionSpecil += ` AND art.days > 0 AND (art.research_theme LIKE ? OR art.label LIKE ? OR art.industrial_name LIKE ? OR art.industrial_subject_name LIKE ? ) `
  705. parsSpecil = append(parsSpecil, keywords, keywords, keywords, keywords)
  706. }
  707. list, totalSearche, e := models.GetActivitySpecialSearcheList(condition, pars, conditionSpecil, parsSpecil, startSize, pageSize)
  708. if e != nil {
  709. err = errors.New("GetActivitySpecialSearcheList, Err: " + e.Error())
  710. return
  711. }
  712. keyWordArr, e := GetIndustryMapNameSliceV3(keywords)
  713. if e != nil {
  714. err = errors.New("GetActivityonditionList, Err: " + e.Error())
  715. return
  716. }
  717. var totalIk int
  718. if len(keyWordArr) > 1 {
  719. // 查询IK分词后那一部分的数据
  720. conditionActivityIk, e := GetActivityonditionList(user, "", "", "", "", "", 0, 1, keyword, 0, 2)
  721. if e != nil && e.Error() != utils.ErrNoRow() {
  722. err = errors.New("GetActivityonditionList, Err: " + e.Error())
  723. return
  724. }
  725. conditionActivityIk += " AND art.is_limit_people = 1 AND art.publish_status = 1 "
  726. totalIk, e = models.GetActivityCount(conditionActivityIk, 0, pars, 0)
  727. if e != nil {
  728. err = errors.New("GetActivityonditionList, Err: " + e.Error())
  729. return
  730. }
  731. keyWordArr = RemoveDuplicatesAndEmpty(keyWordArr)
  732. startSizeIk := startSize - totalSearche
  733. if startSizeIk < 0 {
  734. startSizeIk = 0
  735. }
  736. var pageSizeIk int
  737. pageSizeIk = pageSize - len(list)
  738. if pageSizeIk > 0 {
  739. //搜索关键词联想
  740. conditionActivityIk += ` ORDER BY art.activity_time DESC , art.active_state ASC `
  741. listIk, e := models.GetActivityListNew(conditionActivityIk, pars, user.UserId, startSizeIk, pageSizeIk, 0, 0, "")
  742. if e != nil {
  743. err = errors.New("GetActivityonditionList, Err: " + e.Error())
  744. return
  745. }
  746. for _, item := range listIk {
  747. list = append(list, item)
  748. }
  749. }
  750. }
  751. total = totalSearche + totalIk
  752. items, e = HandleActivityListButton(list, user)
  753. if e != nil {
  754. err = errors.New("HandleActivityListButton, Err: " + e.Error())
  755. return
  756. }
  757. return
  758. }
  759. // 获取 专项调研客户类型 //1、永续客户 //2、大套餐客户(4个行业全开通的正式客户) //8、行业升级套餐客户 //9、其余正式客户;5、试用客户
  760. func GetActivitySpecialUserType(companyId int) (userType int, permissionStrnew string, err error) {
  761. var permissionStr string
  762. if companyId <= 1 {
  763. userType = 0
  764. } else {
  765. total, e := models.GetCountCompanyDetailByIdGroupTrip(companyId)
  766. if e != nil {
  767. err = errors.New("GetCountCompanyDetailByIdGroupTrip, Err: " + e.Error())
  768. return
  769. }
  770. if total == 0 {
  771. userType = 0
  772. } else {
  773. companyDetail, e := models.GetCompanyDetailByIdGroupTrip(companyId)
  774. if e != nil {
  775. err = errors.New("GetCompanyDetailByIdGroupTrip, Err: " + e.Error())
  776. return
  777. }
  778. permissionStr, e = models.GetCompanyPermissionByUserTrip(companyId)
  779. if e != nil {
  780. err = errors.New("GetCompanyPermissionByUserTrip, Err: " + e.Error())
  781. return
  782. }
  783. //permissionZhengShiStr, e = models.GetCompanyPermissionByUserZhengShiTrip(companyId)
  784. //if e != nil {
  785. // err = errors.New("GetCompanyPermissionByUserZhengShiTrip, Err: " + e.Error())
  786. // return
  787. //}
  788. //大套餐客户定义:医药、消费、科技、智造。4个行业中为升级,策略是正式,属于大套餐客户
  789. if companyDetail.Status == "永续" {
  790. userType = 1
  791. } else if companyDetail.Status == "试用" {
  792. userType = 5
  793. } else if companyDetail.Status == "正式" {
  794. if permissionStr == "专家" {
  795. userType = 4
  796. } else if strings.Count(permissionStr, "医药") == 2 && strings.Count(permissionStr, "消费") == 2 && strings.Count(permissionStr, "科技") == 2 && strings.Count(permissionStr, "智造") == 2 && strings.Count(permissionStr, "策略") == 1 {
  797. userType = 2
  798. } else {
  799. userType = 3
  800. }
  801. if userType == 3 {
  802. if !strings.Contains(permissionStr, "医药") && !strings.Contains(permissionStr, "消费") && !strings.Contains(permissionStr, "科技") && !strings.Contains(permissionStr, "智造") {
  803. userType = 4
  804. }
  805. }
  806. } else if companyDetail.Status == "冻结" {
  807. userType = 6
  808. } else if companyDetail.Status == "流失" {
  809. userType = 7
  810. }
  811. }
  812. }
  813. permissionStrnew = permissionStr
  814. return
  815. }
  816. // GetSpecialUserType 获取专项产业调研的用户身份类型
  817. // 获取 专项调研客户类型 //1、永续客户 //2、大套餐客户(4个行业全开通的正式客户) //8、行业升级套餐客户 //9、其余正式客户;5、试用客户
  818. func GetSpecialUserType(user *models.WxUserItem) (userType int, err error) {
  819. companyId := user.CompanyId
  820. companyDetail, e := models.GetCompanyDetailByIdGroupTrip(companyId)
  821. if e != nil && e.Error() != utils.ErrNoRow() {
  822. err = errors.New("GetCompanyDetailByIdGroupTrip, Err: " + e.Error())
  823. return
  824. }
  825. if companyDetail == nil {
  826. return
  827. }
  828. if companyId <= 1 {
  829. userType = 0
  830. } else {
  831. if companyDetail.Status == "永续" {
  832. userType = 1
  833. } else {
  834. if companyDetail.Status == "正式" {
  835. list, e := models.GetCompanyReportPermissionUpgrade(companyId, 2)
  836. if e != nil && e.Error() != utils.ErrNoRow() {
  837. err = errors.New("GetCompanyReportPermissionUpgrade, Err: " + e.Error())
  838. }
  839. if len(list) == 0 {
  840. userType = 9
  841. }
  842. if len(list) == 4 {
  843. totalName, e := models.GetCompanyPermissionNameCheck(companyId, 2, "策略")
  844. if e != nil {
  845. err = errors.New("获取品种信息失败, Err:" + e.Error())
  846. return
  847. }
  848. if totalName > 0 {
  849. userType = 2
  850. } else {
  851. userType = 8
  852. }
  853. } else {
  854. userType = 8
  855. }
  856. } else if companyDetail.Status == "试用" {
  857. userType = 5
  858. }
  859. }
  860. }
  861. return
  862. }
  863. // GetSpecialDetailUserPower 处理用户查看专项调研详情的权限
  864. func GetSpecialDetailUserPower(user *models.WxUserItem, activityInfo *models.CygxActivitySpecialDetail) (havePower bool, err error) {
  865. if user.CompanyId == utils.HZ_COMPANY_ID {
  866. havePower = true
  867. return
  868. }
  869. userType, _, e := GetUserType(user.CompanyId)
  870. if e != nil {
  871. err = errors.New("GetSpecialUserType, Err: " + e.Error())
  872. return
  873. }
  874. if userType == 0 {
  875. return
  876. }
  877. mapUserType, e := GetActivityCcustomerTypeList()
  878. if e != nil {
  879. err = e
  880. return
  881. }
  882. var userTypeStr string
  883. userTypeStr = mapUserType[userType]
  884. // 永续客户、大套餐客户可以查看行业升级套餐客户 权限
  885. if userTypeStr == "1" || userTypeStr == "2" {
  886. if strings.Contains(activityInfo.CustomerTypeIds, userTypeStr) || strings.Contains(activityInfo.CustomerTypeIds, "8") {
  887. havePower = true
  888. return
  889. }
  890. }
  891. permissionStr, e := GetCompanyPermissionUpgrade(user.CompanyId)
  892. if e != nil {
  893. err = errors.New("GetCompanyPermissionUpgrade, Err: " + e.Error())
  894. return
  895. }
  896. //如果没有对应的升级权限,则返回
  897. if !strings.Contains(permissionStr, activityInfo.ChartPermissionName) {
  898. return
  899. }
  900. //userType, e := GetSpecialUserType(user)
  901. var pars []interface{}
  902. var condition string
  903. var userTypes string
  904. condition += ` AND art.publish_status = 1 AND art.is_offline = 0 `
  905. userTypes = "%" + userTypeStr + "%"
  906. condition += ` AND art.customer_type_ids LIKE ? `
  907. pars = append(pars, userTypes)
  908. condition += ` AND art.activity_id = ? `
  909. pars = append(pars, activityInfo.ActivityId)
  910. total, e := models.GetActivitySpecialCount(condition, pars)
  911. if e != nil {
  912. err = errors.New("GetSpecialUserType, Err: " + e.Error())
  913. return
  914. }
  915. if total == 1 {
  916. havePower = true
  917. return
  918. }
  919. if strings.Contains(permissionStr, activityInfo.ChartPermissionName) && strings.Contains(activityInfo.CustomerTypeIds, "8") {
  920. havePower = true
  921. return
  922. }
  923. return
  924. }
  925. // 预报名活动,感兴趣人数满10人时,推送给活动负责人和王芳
  926. func SendWxMsgActivitySpecial10(activityInfo *models.CygxActivitySpecialDetail) (err error) {
  927. activityId := activityInfo.ActivityId
  928. var msg string
  929. defer func() {
  930. if err != nil {
  931. go utils.SendEmail("发送模版消息失败"+"【"+utils.APPNAME+"】"+time.Now().Format("2006-01-02 15:04:05"), msg+";Err:"+err.Error(), utils.EmailSendToUsers)
  932. go utils.SendAlarmMsg(fmt.Sprint("预报名活动,感兴趣人数满10人时,推送给活动负责人和王芳消息发送失败", activityInfo.ResearchTheme, ", activityId"), 2)
  933. utils.FileLog.Info("发送模版消息失败,Err:%s", err.Error())
  934. }
  935. }()
  936. var first string
  937. var keyword1 string
  938. var keyword2 string
  939. var keyword3 string
  940. var keyword4 string
  941. var remark string
  942. adminUser, e := models.GetSellerByAdminId(activityInfo.AdminId)
  943. if e != nil {
  944. err = errors.New("GetSellerByAdminId, Err: " + e.Error())
  945. return
  946. }
  947. cnf, _ := models.GetConfigByCode("tpl_msg")
  948. mobile := adminUser.Mobile + "," + cnf.ConfigValue
  949. specialSignupList, e := models.GetActivityListSpecialByActivityId(activityId)
  950. if e != nil {
  951. err = errors.New("GetActivityListSpecialAll, Err: " + e.Error())
  952. return
  953. }
  954. for _, v := range specialSignupList {
  955. keyword1 += "【" + v.RealName + "--" + v.CompanyName + "】"
  956. }
  957. openIdList, e := models.GetWxOpenIdByMobileList(mobile)
  958. if e != nil {
  959. err = errors.New("GetSellerByAdminId, Err: " + e.Error())
  960. return
  961. }
  962. first = "【" + activityInfo.ResearchTheme + "】已有10人预报名"
  963. keyword3 = "-"
  964. keyword2 = "-"
  965. keyword4 = "【" + activityInfo.ResearchTheme + "】已有10人预报名"
  966. openIdArr := make([]string, 0)
  967. for _, v := range openIdList {
  968. openIdArr = append(openIdArr, v.OpenId)
  969. }
  970. redirectUrl := utils.WX_MSG_PATH_ACTIVITY_SPECIAL_DETAIL + strconv.Itoa(activityId)
  971. sendInfo := new(SendWxTemplate)
  972. sendInfo.First = first
  973. sendInfo.Keyword1 = keyword1
  974. sendInfo.Keyword2 = keyword2
  975. sendInfo.Keyword3 = keyword3
  976. sendInfo.Keyword4 = keyword4
  977. sendInfo.Remark = remark
  978. sendInfo.TemplateId = utils.WxMsgTemplateIdAskMsgXzs
  979. sendInfo.RedirectUrl = redirectUrl
  980. sendInfo.RedirectTarget = 3
  981. sendInfo.Resource = strconv.Itoa(activityId)
  982. sendInfo.SendType = utils.TEMPLATE_MSG_CYGX_ARTICLE_ADD
  983. sendInfo.OpenIdArr = openIdArr
  984. err = PublicSendTemplateMsg(sendInfo)
  985. if err != nil {
  986. return
  987. }
  988. return
  989. }
  990. // SendWxMsgActivitySpecialTwoDays 活动开始前两天08:00,提醒报名客户 \提醒报名客户的对口销售
  991. func SendWxMsgActivitySpecialTwoDays(cont context.Context) (err error) {
  992. //func SendWxMsgActivitySpecialTwoDays() (err error) {
  993. var msg string
  994. defer func() {
  995. if err != nil {
  996. fmt.Println(err)
  997. go utils.SendEmail("发送模版消息失败"+"【"+utils.APPNAME+"】"+time.Now().Format("2006-01-02 15:04:05"), msg+";Err:"+err.Error(), utils.EmailSendToUsers)
  998. go utils.SendAlarmMsg(fmt.Sprint(" 活动开始前两天08:00,提醒报名客户、提醒报名客户的对口销售消息发送失败"), 2)
  999. utils.FileLog.Info("发送模版消息失败,Err:%s", err.Error())
  1000. }
  1001. }()
  1002. twoDayTime := time.Now().AddDate(0, 0, 2)
  1003. startTime := twoDayTime.Format(utils.FormatDate) + " 00:00:00"
  1004. endTime := twoDayTime.Format(utils.FormatDate) + " 23:59:59"
  1005. var condition string
  1006. var pars []interface{}
  1007. condition = ` AND days >0 AND activity_time BETWEEN ? AND ? `
  1008. pars = append(pars, startTime, endTime)
  1009. listActivitySpecial, e := models.GetActivitySpecialListAll(condition, pars, 0, 1000)
  1010. if e != nil {
  1011. err = errors.New("GetSellerByAdminId, Err: " + e.Error())
  1012. return
  1013. }
  1014. if len(listActivitySpecial) == 0 {
  1015. return
  1016. }
  1017. var activityIds []int
  1018. for _, v := range listActivitySpecial {
  1019. activityIds = append(activityIds, v.ActivityId)
  1020. condition = ` AND is_cancel = 0 AND activity_id = ` + strconv.Itoa(v.ActivityId)
  1021. pars = make([]interface{}, 0)
  1022. listSpecialTrip, e := models.GetCygxActivitySpecialTripList(condition, pars)
  1023. if e != nil {
  1024. err = errors.New("GetCygxActivitySpecialTripList, Err: " + e.Error())
  1025. return
  1026. }
  1027. if len(listSpecialTrip) == 0 {
  1028. return
  1029. }
  1030. var mobile string
  1031. var companyIds []int
  1032. for _, vT := range listSpecialTrip {
  1033. mobile += "'" + vT.Mobile + "',"
  1034. companyIds = append(companyIds, vT.CompanyId)
  1035. }
  1036. mobile = strings.TrimRight(mobile, ",")
  1037. openIdList, e := models.GetWxOpenIdByMobileList(mobile)
  1038. if e != nil {
  1039. err = errors.New("GetSellerByAdminId, Err: " + e.Error())
  1040. return
  1041. }
  1042. first := ""
  1043. keyword1 := "专项调研【" + v.ResearchTheme + "】"
  1044. keyword2 := "将在两天后进行,如不能参加,请及时取消报名"
  1045. keyword3 := ""
  1046. keyword4 := ""
  1047. remark := "点击查看活动详情"
  1048. SendWxMsgWithFrequencySpecial(first, keyword1, keyword2, keyword3, keyword4, remark, openIdList, v.ActivityId)
  1049. //活动开始前两天08:00,提醒报名客户的对口销售
  1050. companyIdsLen := len(companyIds)
  1051. if companyIdsLen == 0 {
  1052. continue
  1053. } else {
  1054. pars = make([]interface{}, 0)
  1055. condition = ` AND p.company_id IN (` + utils.GetOrmInReplace(companyIdsLen) + `) GROUP BY p.company_id `
  1056. pars = append(pars, companyIds)
  1057. listSeller, e := models.GetAdminOpendidByCompany(condition, pars)
  1058. if e != nil && e.Error() != utils.ErrNoRow() {
  1059. err = errors.New("GetAdminOpendidByCompany, Err: " + e.Error())
  1060. return
  1061. }
  1062. if len(listSeller) == 0 {
  1063. continue
  1064. }
  1065. mapSller := make(map[string]string)
  1066. mapSllerOpenid := make(map[string]string)
  1067. for _, vS := range listSeller {
  1068. for _, vT := range listSpecialTrip {
  1069. if vT.CompanyId == vS.CompanyId {
  1070. mapSller[vS.Mobile] += "【" + vT.RealName + "--" + vT.CompanyName + "】"
  1071. mapSllerOpenid[vS.Mobile] = vS.OpenId
  1072. }
  1073. }
  1074. }
  1075. for k, _ := range mapSller {
  1076. keyword2 = "将在两天后进行,请及时提醒您的报名客户"
  1077. openIdList = make([]*models.OpenIdList, 0)
  1078. openIdList = append(openIdList, &models.OpenIdList{OpenId: mapSllerOpenid[k]})
  1079. SendWxMsgWithFrequencySpecial(first, keyword1, keyword2, keyword3, keyword4, remark, openIdList, v.ActivityId)
  1080. }
  1081. }
  1082. }
  1083. return
  1084. }
  1085. // SendWxMsgActivitySpecialCancel 线下活动前4天08:00报名人数不足7人,线上活动前3天08:00报名人数不足10人,活动自动取消发布,并推送模板消息至报名客户及对口销售
  1086. func SendWxMsgActivitySpecialCancel(cont context.Context) (err error) {
  1087. var msg string
  1088. defer func() {
  1089. if err != nil {
  1090. fmt.Println(err)
  1091. go utils.SendEmail("发送模版消息失败"+"【"+utils.APPNAME+"】"+time.Now().Format("2006-01-02 15:04:05"), msg+";Err:"+err.Error(), utils.EmailSendToUsers)
  1092. go utils.SendAlarmMsg(fmt.Sprint(" 活动开始前两天08:00,提醒报名客户、提醒报名客户的对口销售消息发送失败"), 2)
  1093. utils.FileLog.Info("发送模版消息失败,Err:%s", err.Error())
  1094. }
  1095. }()
  1096. dayTime3 := time.Now().AddDate(0, 0, 3)
  1097. startTime := dayTime3.Format(utils.FormatDate) + " 00:00:00"
  1098. endTime := dayTime3.Format(utils.FormatDate) + " 23:59:59"
  1099. dayTime4 := time.Now().AddDate(0, 0, 4)
  1100. startTime4 := dayTime4.Format(utils.FormatDate) + " 00:00:00"
  1101. endTime4 := dayTime4.Format(utils.FormatDate) + " 23:59:59"
  1102. var condition string
  1103. var pars []interface{}
  1104. condition = ` AND days >0 AND activity_time BETWEEN ? AND ? AND special_type= 1 `
  1105. pars = append(pars, startTime, endTime)
  1106. condition += ` OR ( days >0 AND activity_time BETWEEN ? AND ? AND special_type= 2 ) `
  1107. pars = append(pars, startTime4, endTime4)
  1108. listActivitySpecial, e := models.GetActivitySpecialListAll(condition, pars, 0, 1000)
  1109. if e != nil {
  1110. err = errors.New("GetSellerByAdminId, Err: " + e.Error())
  1111. return
  1112. }
  1113. if len(listActivitySpecial) == 0 {
  1114. return
  1115. }
  1116. var activityIds []int
  1117. for _, v := range listActivitySpecial {
  1118. activityIds = append(activityIds, v.ActivityId)
  1119. condition = ` AND is_cancel = 0 AND activity_id = ` + strconv.Itoa(v.ActivityId)
  1120. pars = make([]interface{}, 0)
  1121. listSpecialTrip, e := models.GetCygxActivitySpecialTripList(condition, pars)
  1122. if e != nil {
  1123. err = errors.New("GetCygxActivitySpecialTripList, Err: " + e.Error())
  1124. return
  1125. }
  1126. if v.SpecialType == 1 {
  1127. if len(listSpecialTrip) >= 10 {
  1128. continue
  1129. }
  1130. }
  1131. if v.SpecialType == 2 {
  1132. if len(listSpecialTrip) >= 7 {
  1133. continue
  1134. }
  1135. }
  1136. e = models.UpdateActivitySpecialPublishStatus(0, v.ActivityId)
  1137. if e != nil {
  1138. err = errors.New("UpdateActivitySpecialPublishStatus,自动取消专项调研日程失败 Err: " + e.Error() + strconv.Itoa(v.ActivityId))
  1139. return
  1140. }
  1141. if len(listSpecialTrip) < 0 {
  1142. return
  1143. }
  1144. var mobile string
  1145. var companyIds []int
  1146. for _, vT := range listSpecialTrip {
  1147. mobile += "'" + vT.Mobile + "',"
  1148. companyIds = append(companyIds, vT.CompanyId)
  1149. }
  1150. mobile = strings.TrimRight(mobile, ",")
  1151. openIdList, e := models.GetWxOpenIdByMobileList(mobile)
  1152. if e != nil {
  1153. err = errors.New("GetSellerByAdminId, Err: " + e.Error())
  1154. return
  1155. }
  1156. first := "【" + v.ResearchTheme + "】专项调研因专家安排变动,本次调研活动延期举办,具体时间另行通知"
  1157. keyword1 := v.ResearchTheme
  1158. keyword2 := "已取消"
  1159. keyword3 := ""
  1160. keyword4 := ""
  1161. remark := ""
  1162. openIdArr := make([]string, 0)
  1163. for _, vOpenid := range openIdList {
  1164. openIdArr = append(openIdArr, vOpenid.OpenId)
  1165. }
  1166. companyIdsLen := len(companyIds)
  1167. if len(companyIds) > 0 {
  1168. pars = make([]interface{}, 0)
  1169. condition = ` AND p.company_id IN (` + utils.GetOrmInReplace(companyIdsLen) + `) GROUP BY p.company_id `
  1170. pars = append(pars, companyIds)
  1171. listSeller, e := models.GetAdminOpendidByCompany(condition, pars)
  1172. if e != nil && e.Error() != utils.ErrNoRow() {
  1173. err = errors.New("GetAdminOpendidByCompany, Err: " + e.Error())
  1174. return
  1175. }
  1176. if len(listSeller) > 0 {
  1177. for _, vOpenid := range listSeller {
  1178. openIdArr = append(openIdArr, vOpenid.OpenId)
  1179. }
  1180. }
  1181. }
  1182. redirectUrl := ""
  1183. sendInfo := new(SendWxTemplate)
  1184. sendInfo.First = first
  1185. sendInfo.Keyword1 = keyword1
  1186. sendInfo.Keyword2 = keyword2
  1187. sendInfo.Keyword3 = keyword3
  1188. sendInfo.Keyword4 = keyword4
  1189. sendInfo.Remark = remark
  1190. sendInfo.TemplateId = utils.WxMsgTemplateIdArticleUserRemind
  1191. sendInfo.RedirectUrl = redirectUrl
  1192. sendInfo.RedirectTarget = 3
  1193. sendInfo.Resource = strconv.Itoa(v.ActivityId)
  1194. sendInfo.SendType = utils.TEMPLATE_MSG_CYGX_ARTICLE_ADD
  1195. sendInfo.OpenIdArr = openIdArr
  1196. fmt.Println(sendInfo)
  1197. err = PublicSendTemplateMsg(sendInfo)
  1198. }
  1199. return
  1200. }