activity_special.go 42 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268
  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
  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. var msg string
  993. defer func() {
  994. if err != nil {
  995. fmt.Println(err)
  996. go utils.SendEmail("发送模版消息失败"+"【"+utils.APPNAME+"】"+time.Now().Format("2006-01-02 15:04:05"), msg+";Err:"+err.Error(), utils.EmailSendToUsers)
  997. go utils.SendAlarmMsg(fmt.Sprint(" 活动开始前两天08:00,提醒报名客户、提醒报名客户的对口销售消息发送失败"), 2)
  998. utils.FileLog.Info("发送模版消息失败,Err:%s", err.Error())
  999. }
  1000. }()
  1001. twoDayTime := time.Now().AddDate(0, 0, 2)
  1002. startTime := twoDayTime.Format(utils.FormatDate) + " 00:00:00"
  1003. endTime := twoDayTime.Format(utils.FormatDate) + " 23:59:59"
  1004. var condition string
  1005. var pars []interface{}
  1006. condition = ` AND days >0 AND activity_time BETWEEN ? AND ? `
  1007. pars = append(pars, startTime, endTime)
  1008. listActivitySpecial, e := models.GetActivitySpecialListAll(condition, pars, 0, 1000)
  1009. if e != nil {
  1010. err = errors.New("GetSellerByAdminId, Err: " + e.Error())
  1011. return
  1012. }
  1013. if len(listActivitySpecial) == 0 {
  1014. return
  1015. }
  1016. var activityIds []int
  1017. for _, v := range listActivitySpecial {
  1018. activityIds = append(activityIds, v.ActivityId)
  1019. condition = ` AND is_cancel = 0 AND activity_id = ` + strconv.Itoa(v.ActivityId)
  1020. pars = make([]interface{}, 0)
  1021. listSpecialTrip, e := models.GetCygxActivitySpecialTripList(condition, pars)
  1022. if e != nil {
  1023. err = errors.New("GetCygxActivitySpecialTripList, Err: " + e.Error())
  1024. return
  1025. }
  1026. if len(listSpecialTrip) == 0 {
  1027. return
  1028. }
  1029. var mobile string
  1030. var companyIds []int
  1031. for _, vT := range listSpecialTrip {
  1032. mobile += "'" + vT.Mobile + "',"
  1033. companyIds = append(companyIds, vT.CompanyId)
  1034. }
  1035. mobile = strings.TrimRight(mobile, ",")
  1036. openIdList, e := models.GetWxOpenIdByMobileList(mobile)
  1037. if e != nil {
  1038. err = errors.New("GetSellerByAdminId, Err: " + e.Error())
  1039. return
  1040. }
  1041. first := "【" + v.ResearchTheme + "】专项调研将在两天后进行,如不能参加,请及时取消报名"
  1042. keyword1 := v.ResearchTheme
  1043. keyword2 := "已报名"
  1044. keyword3 := v.ActivityTimeTextByDay
  1045. keyword4 := "线上"
  1046. if v.SpecialType == 2 {
  1047. keyword4 = v.City
  1048. }
  1049. remark := "点击查看活动详情"
  1050. SendWxMsgWithFrequencySpecial(first, keyword1, keyword2, keyword3, keyword4, remark, openIdList, v.ActivityId)
  1051. //活动开始前两天08:00,提醒报名客户的对口销售
  1052. companyIdsLen := len(companyIds)
  1053. if companyIdsLen == 0 {
  1054. continue
  1055. } else {
  1056. pars = make([]interface{}, 0)
  1057. condition = ` AND p.company_id IN (` + utils.GetOrmInReplace(companyIdsLen) + `) GROUP BY p.company_id `
  1058. pars = append(pars, companyIds)
  1059. listSeller, e := models.GetAdminOpendidByCompany(condition, pars)
  1060. if e != nil && e.Error() != utils.ErrNoRow() {
  1061. err = errors.New("GetAdminOpendidByCompany, Err: " + e.Error())
  1062. return
  1063. }
  1064. if len(listSeller) == 0 {
  1065. continue
  1066. }
  1067. type SllerData struct {
  1068. Openid string `description:"Openid"`
  1069. Keyword string `description:"Keyword "`
  1070. }
  1071. mapSller := make(map[string]string)
  1072. mapSllerOpenid := make(map[string]string)
  1073. for _, vS := range listSeller {
  1074. for _, vT := range listSpecialTrip {
  1075. if vT.CompanyId == vS.CompanyId {
  1076. mapSller[vS.Mobile] += "【" + vT.RealName + "--" + vT.CompanyName + "】"
  1077. mapSllerOpenid[vS.Mobile] = vS.OpenId
  1078. }
  1079. }
  1080. }
  1081. for k, vM := range mapSller {
  1082. first = "【" + v.ResearchTheme + "】专项调研将在两天后进行,请及时提醒您的报名客户"
  1083. keyword2 = vM
  1084. openIdList = make([]*models.OpenIdList, 0)
  1085. openIdList = append(openIdList, &models.OpenIdList{OpenId: mapSllerOpenid[k]})
  1086. SendWxMsgWithFrequencySpecial(first, keyword1, keyword2, keyword3, keyword4, remark, openIdList, v.ActivityId)
  1087. }
  1088. }
  1089. }
  1090. return
  1091. }
  1092. // SendWxMsgActivitySpecialCancel 线下活动前4天08:00报名人数不足7人,线上活动前3天08:00报名人数不足10人,活动自动取消发布,并推送模板消息至报名客户及对口销售
  1093. func SendWxMsgActivitySpecialCancel(cont context.Context) (err error) {
  1094. var msg string
  1095. defer func() {
  1096. if err != nil {
  1097. fmt.Println(err)
  1098. go utils.SendEmail("发送模版消息失败"+"【"+utils.APPNAME+"】"+time.Now().Format("2006-01-02 15:04:05"), msg+";Err:"+err.Error(), utils.EmailSendToUsers)
  1099. go utils.SendAlarmMsg(fmt.Sprint(" 活动开始前两天08:00,提醒报名客户、提醒报名客户的对口销售消息发送失败"), 2)
  1100. utils.FileLog.Info("发送模版消息失败,Err:%s", err.Error())
  1101. }
  1102. }()
  1103. dayTime3 := time.Now().AddDate(0, 0, 3)
  1104. startTime := dayTime3.Format(utils.FormatDate) + " 00:00:00"
  1105. endTime := dayTime3.Format(utils.FormatDate) + " 23:59:59"
  1106. dayTime4 := time.Now().AddDate(0, 0, 4)
  1107. startTime4 := dayTime4.Format(utils.FormatDate) + " 00:00:00"
  1108. endTime4 := dayTime4.Format(utils.FormatDate) + " 23:59:59"
  1109. var condition string
  1110. var pars []interface{}
  1111. condition = ` AND days >0 AND activity_time BETWEEN ? AND ? AND special_type= 1 `
  1112. pars = append(pars, startTime, endTime)
  1113. condition += ` OR ( days >0 AND activity_time BETWEEN ? AND ? AND special_type= 2 ) `
  1114. pars = append(pars, startTime4, endTime4)
  1115. listActivitySpecial, e := models.GetActivitySpecialListAll(condition, pars, 0, 1000)
  1116. if e != nil {
  1117. err = errors.New("GetSellerByAdminId, Err: " + e.Error())
  1118. return
  1119. }
  1120. if len(listActivitySpecial) == 0 {
  1121. return
  1122. }
  1123. var activityIds []int
  1124. for _, v := range listActivitySpecial {
  1125. activityIds = append(activityIds, v.ActivityId)
  1126. condition = ` AND is_cancel = 0 AND activity_id = ` + strconv.Itoa(v.ActivityId)
  1127. pars = make([]interface{}, 0)
  1128. listSpecialTrip, e := models.GetCygxActivitySpecialTripList(condition, pars)
  1129. if e != nil {
  1130. err = errors.New("GetCygxActivitySpecialTripList, Err: " + e.Error())
  1131. return
  1132. }
  1133. if v.SpecialType == 1 {
  1134. if len(listSpecialTrip) >= 10 {
  1135. continue
  1136. }
  1137. }
  1138. if v.SpecialType == 2 {
  1139. if len(listSpecialTrip) >= 7 {
  1140. continue
  1141. }
  1142. }
  1143. e = models.UpdateActivitySpecialPublishStatus(0, v.ActivityId)
  1144. if e != nil {
  1145. err = errors.New("UpdateActivitySpecialPublishStatus,自动取消专项调研日程失败 Err: " + e.Error() + strconv.Itoa(v.ActivityId))
  1146. return
  1147. }
  1148. if len(listSpecialTrip) < 0 {
  1149. return
  1150. }
  1151. var mobile string
  1152. var companyIds []int
  1153. for _, vT := range listSpecialTrip {
  1154. mobile += "'" + vT.Mobile + "',"
  1155. companyIds = append(companyIds, vT.CompanyId)
  1156. }
  1157. mobile = strings.TrimRight(mobile, ",")
  1158. openIdList, e := models.GetWxOpenIdByMobileList(mobile)
  1159. if e != nil {
  1160. err = errors.New("GetSellerByAdminId, Err: " + e.Error())
  1161. return
  1162. }
  1163. first := "【" + v.ResearchTheme + "】专项调研因专家安排变动,本次调研活动延期举办,具体时间另行通知"
  1164. keyword1 := v.ResearchTheme
  1165. keyword2 := "已取消"
  1166. keyword3 := ""
  1167. keyword4 := ""
  1168. remark := ""
  1169. openIdArr := make([]string, 0)
  1170. for _, vOpenid := range openIdList {
  1171. openIdArr = append(openIdArr, vOpenid.OpenId)
  1172. }
  1173. companyIdsLen := len(companyIds)
  1174. if len(companyIds) > 0 {
  1175. pars = make([]interface{}, 0)
  1176. condition = ` AND p.company_id IN (` + utils.GetOrmInReplace(companyIdsLen) + `) GROUP BY p.company_id `
  1177. pars = append(pars, companyIds)
  1178. listSeller, e := models.GetAdminOpendidByCompany(condition, pars)
  1179. if e != nil && e.Error() != utils.ErrNoRow() {
  1180. err = errors.New("GetAdminOpendidByCompany, Err: " + e.Error())
  1181. return
  1182. }
  1183. if len(listSeller) > 0 {
  1184. for _, vOpenid := range listSeller {
  1185. openIdArr = append(openIdArr, vOpenid.OpenId)
  1186. }
  1187. }
  1188. }
  1189. redirectUrl := ""
  1190. sendInfo := new(SendWxTemplate)
  1191. sendInfo.First = first
  1192. sendInfo.Keyword1 = keyword1
  1193. sendInfo.Keyword2 = keyword2
  1194. sendInfo.Keyword3 = keyword3
  1195. sendInfo.Keyword4 = keyword4
  1196. sendInfo.Remark = remark
  1197. sendInfo.TemplateId = utils.WxMsgTemplateIdArticleUserRemind
  1198. sendInfo.RedirectUrl = redirectUrl
  1199. sendInfo.RedirectTarget = 3
  1200. sendInfo.Resource = strconv.Itoa(v.ActivityId)
  1201. sendInfo.SendType = utils.TEMPLATE_MSG_CYGX_ARTICLE_ADD
  1202. sendInfo.OpenIdArr = openIdArr
  1203. fmt.Println(sendInfo)
  1204. err = PublicSendTemplateMsg(sendInfo)
  1205. }
  1206. return
  1207. }