activity_points.go 41 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200
  1. package services
  2. import (
  3. "encoding/json"
  4. "errors"
  5. "fmt"
  6. "hongze/hongze_cygx/models"
  7. "hongze/hongze_cygx/models/company"
  8. "hongze/hongze_cygx/utils"
  9. "strconv"
  10. "time"
  11. )
  12. //func init() {
  13. // GetActivityPointsAll()
  14. //}
  15. // GetActivityPointsByUserAllMap 获取所有针对用户扣点的活动
  16. func GetActivityPointsByUserAllMap() (mapResp map[int]bool) {
  17. var err error
  18. defer func() {
  19. if err != nil {
  20. fmt.Println(err)
  21. go utils.SendAlarmMsg("GetActivityPointsByUserAllMap,Err:"+err.Error(), 2)
  22. }
  23. }()
  24. var condition string
  25. var pars []interface{}
  26. //获取所有研选类型的活动
  27. condition = ` AND chart_permission_id = ` + strconv.Itoa(utils.CHART_PERMISSION_ID_YANXUAN)
  28. listActivity, e := models.GetActivityListByCondition(condition, pars)
  29. if e != nil {
  30. err = errors.New("GetActivityListByCondition, Err: " + e.Error())
  31. return
  32. }
  33. var activityIds []int
  34. condition = ""
  35. pars = make([]interface{}, 0)
  36. for _, v := range listActivity {
  37. activityIds = append(activityIds, v.ActivityId)
  38. }
  39. condition += ` AND points_object IN (1,3) `
  40. condition += ` AND activity_id IN (` + utils.GetOrmInReplace(len(activityIds)) + `) `
  41. pars = append(pars, activityIds)
  42. list, e := models.GetCygxActivityPointsSetList(condition, pars, 0, 0)
  43. if e != nil {
  44. err = errors.New("GetCygxActivityPointsSetList, Err: " + e.Error())
  45. return
  46. }
  47. mapResp = make(map[int]bool, 0)
  48. for _, v := range list {
  49. mapResp[v.ActivityId] = true
  50. }
  51. return
  52. }
  53. // GetActivityPointsAll 获取所有带有扣点的活动
  54. func GetActivityPointsAll() (mapResp map[int]bool, err error) {
  55. defer func() {
  56. if err != nil {
  57. fmt.Println(err)
  58. go utils.SendAlarmMsg("获取所有带有扣点的活动失败"+err.Error(), 2)
  59. }
  60. }()
  61. var condition string
  62. var pars []interface{}
  63. mapResp = make(map[int]bool, 0)
  64. list, e := models.GetCygxActivityPointsSetList(condition, pars, 0, 0)
  65. if e != nil && e.Error() != utils.ErrNoRow() {
  66. err = errors.New("GetCygxActivityPointsSetList,Err: " + e.Error())
  67. return
  68. }
  69. for _, v := range list {
  70. mapResp[v.ActivityId] = true
  71. }
  72. return
  73. }
  74. // 用户报名添加到处理研选扣点
  75. func YanXuanActivityPointsBillSignupAdd(activityId, uid int) (err error) {
  76. defer func() {
  77. if err != nil {
  78. fmt.Println(err)
  79. msg := fmt.Sprint("activityId:", activityId, "userId:", uid)
  80. go utils.SendAlarmMsg("用户报名添加到处理研选扣点,写入Redis队列消息失败:"+err.Error()+msg, 2)
  81. }
  82. }()
  83. //SourceType int `description:"1:报名、 2:取消报名、3:活动编辑、4:活动发布,取消发布、5:活动到会。"`
  84. log := &models.YanXuanActivityPointsRedis{UserId: uid, ActivityId: activityId, SourceType: 1, RegisterPlatform: utils.REGISTER_PLATFORM, Source: 1, CreateTime: time.Now()}
  85. if utils.Re == nil {
  86. err := utils.Rc.LPush(utils.CYGX_YANXUAN_POINTS_KEY, log)
  87. if err != nil {
  88. fmt.Println("YanXuanActivityPointsRedis LPush Err:" + err.Error())
  89. }
  90. }
  91. return
  92. }
  93. // 用户取消报名添加到处理研选扣点
  94. func YanXuanActivityPointsBillSignupCancel(activityId, uid int) (err error) {
  95. defer func() {
  96. if err != nil {
  97. fmt.Println(err)
  98. msg := fmt.Sprint("activityId:", activityId, "userId:", uid)
  99. go utils.SendAlarmMsg("用户取消报名添加到处理研选扣点,写入Redis队列消息失败:"+err.Error()+msg, 2)
  100. }
  101. }()
  102. //SourceType int `description:"1:报名、 2:取消报名、3:活动编辑、4:活动发布,取消发布、5:活动到会。"`
  103. log := &models.YanXuanActivityPointsRedis{UserId: uid, ActivityId: activityId, SourceType: 2, RegisterPlatform: utils.REGISTER_PLATFORM, Source: 1, CreateTime: time.Now()}
  104. if utils.Re == nil {
  105. err := utils.Rc.LPush(utils.CYGX_YANXUAN_POINTS_KEY, log)
  106. if err != nil {
  107. fmt.Println("YanXuanActivityPointsRedis LPush Err:" + err.Error())
  108. }
  109. }
  110. return
  111. }
  112. // 5 活动到会研选扣点处理
  113. func YanXuanActivityPointsBillSubmitMeeting(activityId, adminId int) (err error) {
  114. defer func() {
  115. if err != nil {
  116. fmt.Println(err)
  117. msg := fmt.Sprint("activityId:", activityId)
  118. go utils.SendAlarmMsg("活动到会研选扣点处理,写入Redis队列消息失败:"+err.Error()+msg, 2)
  119. }
  120. }()
  121. //SourceType int `description:"1:报名、 2:取消报名、3:活动编辑、4:活动发布,取消发布、5:活动到会。6:研选审批通过的时候研选扣点更新、 7:正式专试用定时任务更新研选扣点"`
  122. log := &models.YanXuanActivityPointsRedis{ActivityId: activityId, SourceType: 5, AdminId: adminId, Source: 2, CreateTime: time.Now()}
  123. if utils.Re == nil {
  124. err := utils.Rc.LPush(utils.CYGX_YANXUAN_POINTS_KEY, log)
  125. if err != nil {
  126. fmt.Println("YanXuanActivityPointsRedis LPush Err:" + err.Error())
  127. }
  128. }
  129. return
  130. }
  131. // YanXuanActivityPointsBillReduce 处理研选活动扣点
  132. func YanXuanActivityPointsBillReduce() (err error) {
  133. for {
  134. //SourceType int `description:"1:报名、 2:取消报名、3:活动编辑、4:活动发布,取消发布、5:活动到会。"`
  135. utils.Rc.Brpop(utils.CYGX_YANXUAN_POINTS_KEY, func(b []byte) {
  136. var log models.YanXuanActivityPointsRedis
  137. if err := json.Unmarshal(b, &log); err != nil {
  138. fmt.Println("json unmarshal wrong!")
  139. go utils.SendAlarmMsg("处理研选活动扣点处理Redis队列消息失败:"+err.Error()+string(b), 2)
  140. }
  141. switch log.SourceType {
  142. case 1:
  143. go YanXuanActivityPointsBillSignupAddReduce(log)
  144. fmt.Println("1:报名")
  145. break
  146. case 2:
  147. go YanXuanActivityPointsBillSignupCancelReduce(log)
  148. fmt.Println(" 2:取消报名")
  149. break
  150. case 3:
  151. go YanXuanActivityPointsBillActivityEditReduce(log)
  152. fmt.Println("3:活动编辑")
  153. break
  154. case 4:
  155. go YanXuanActivityPointsBillActivityPublishAndCancelReduce(log)
  156. fmt.Println("4:活动发布、取消发布")
  157. break
  158. case 5:
  159. go YanXuanActivityPointsBillSubmitMeetingReduce(log)
  160. fmt.Println("5:活动到会研选扣点处理。")
  161. case 6:
  162. go YanXuanCompanyApprovalReduce(log)
  163. fmt.Println("6:研选审批通过的时候研选扣点更新。")
  164. break
  165. case 7:
  166. go YanXuanCompanyCompanyTryOutReduce(log)
  167. fmt.Println("7:正式专试用定时任务更新研选扣点。")
  168. break
  169. case 8:
  170. go YanXuanActivityVivoPointsBillSignupReduce(log)
  171. fmt.Println("8:播放研选扣点音视频。")
  172. break
  173. default:
  174. fmt.Println(string(b))
  175. go utils.SendAlarmMsg("处理研选活动扣点处理Redis队列消息失败:"+string(b), 2)
  176. }
  177. })
  178. }
  179. }
  180. // 1:用户报名
  181. func YanXuanActivityPointsBillSignupAddReduce(log models.YanXuanActivityPointsRedis) (err error) {
  182. defer func() {
  183. if err != nil {
  184. fmt.Println(err)
  185. go utils.SendAlarmMsg("用户报名活动扣点,处理Redis队列消息失败:"+err.Error()+fmt.Sprint("ActivityId", log.ActivityId, "userId", log.UserId), 2)
  186. }
  187. }()
  188. //加2000毫秒的延迟
  189. time.Sleep(2 * time.Second)
  190. activityId := log.ActivityId
  191. userId := log.UserId
  192. activtyPayTotal := GetCygxOrderVirtualAssetdCountTotal(userId, activityId) // 单场付费活动不处理扣点明细
  193. if activtyPayTotal > 0 {
  194. return
  195. }
  196. //获取活动是否扣点以及扣点规则明细
  197. activityPointsSetDetail, e := models.GetCygxActivityPointsSetDetail(activityId)
  198. if e != nil && e.Error() != utils.ErrNoRow() {
  199. err = errors.New("GetCygxActivityPointsSetDetail" + e.Error())
  200. return
  201. }
  202. if activityPointsSetDetail == nil {
  203. return
  204. }
  205. if activityPointsSetDetail.UserPointsNum == 0 || activityPointsSetDetail.PointsType != 1 {
  206. return // 如果不是报名即扣点的这种形式,那么就不做任何处理
  207. }
  208. activityInfo, e := models.GetAddActivityInfoById(activityId)
  209. if e != nil {
  210. err = errors.New("GetAddActivityInfoById" + e.Error())
  211. return
  212. }
  213. user, e := models.GetWxUserItemByUserId(userId)
  214. if e != nil {
  215. err = errors.New("GetWxUserItemByUserId" + e.Error())
  216. return
  217. }
  218. companyId := user.CompanyId
  219. //判断公司是不是满足扣点情况,如果是后台超管手动给试用客户报名,就写入一条点数初始化数据
  220. total, e := models.GetCygxActivityPointsCompanyCountByCompanyId(companyId)
  221. if e != nil {
  222. err = errors.New("GetCygxActivityPointsCompanyCountByCompanyId, Err: " + e.Error())
  223. return
  224. }
  225. var companyPointsNum float64
  226. if total == 0 {
  227. companyPointsNum = 0
  228. itemPointsCompany := new(models.CygxActivityPointsCompany)
  229. itemPointsCompany.CompanyId = companyId
  230. itemPointsCompany.CompanyName = user.CompanyName
  231. itemPointsCompany.CreateTime = time.Now()
  232. itemPointsCompany.ModifyTime = time.Now()
  233. e = models.AddCygxActivityPointsCompany(itemPointsCompany)
  234. if e != nil {
  235. err = errors.New("AddCygxActivityPointsCompany, Err: " + e.Error())
  236. return
  237. }
  238. } else {
  239. // 获取用户所在公司剩余的点
  240. companyPointsNum, e = models.GetCompanyPoints(user.CompanyId)
  241. if e != nil && e.Error() != utils.ErrNoRow() {
  242. err = errors.New("GetCompanyPoints, Err: " + e.Error())
  243. return
  244. }
  245. }
  246. //获取需要添加的流水信息
  247. var items []*models.CygxActivityPointsBill
  248. item := new(models.CygxActivityPointsBill)
  249. item.UserId = user.UserId
  250. item.ActivityId = activityId
  251. item.CreateTime = time.Now()
  252. item.Mobile = user.Mobile
  253. item.Email = user.Email
  254. item.CompanyId = user.CompanyId
  255. item.CompanyName = user.CompanyName
  256. item.RealName = user.RealName
  257. item.BillDetailed = -activityPointsSetDetail.UserPointsNum
  258. item.RegisterPlatform = log.RegisterPlatform
  259. item.AdminId = log.AdminId
  260. item.Source = log.Source
  261. item.ChartPermissionId = activityInfo.ChartPermissionId
  262. item.DoType = 1
  263. item.Content = activityInfo.ActivityName + "--报名"
  264. item.Points = companyPointsNum - activityPointsSetDetail.UserPointsNum
  265. items = append(items, item)
  266. //更新对应机构的剩余点数
  267. var itemCompanys []*models.CygxActivityPointsCompany
  268. itemCompany := new(models.CygxActivityPointsCompany)
  269. itemCompany.CompanyId = user.CompanyId
  270. itemCompany.Points = item.Points
  271. itemCompany.ModifyTime = time.Now()
  272. itemCompanys = append(itemCompanys, itemCompany)
  273. err = models.AddCygxActivityPointsBillMulti(items, itemCompanys)
  274. return
  275. }
  276. // 2:用户取消报名
  277. func YanXuanActivityPointsBillSignupCancelReduce(log models.YanXuanActivityPointsRedis) (err error) {
  278. defer func() {
  279. if err != nil {
  280. fmt.Println(err)
  281. go utils.SendAlarmMsg("用户取消报名扣点,处理Redis队列消息失败:"+err.Error()+fmt.Sprint("ActivityId", log.ActivityId, "userId", log.UserId), 2)
  282. }
  283. }()
  284. activityId := log.ActivityId
  285. userId := log.UserId
  286. activtyPayTotal := GetCygxOrderVirtualAssetdCountTotal(userId, activityId) // 单场付费活动不处理扣点明细
  287. if activtyPayTotal > 0 {
  288. return
  289. }
  290. //获取活动是否扣点以及扣点规则明细
  291. activityPointsSetDetail, e := models.GetCygxActivityPointsSetDetail(activityId)
  292. if e != nil && e.Error() != utils.ErrNoRow() {
  293. err = errors.New("GetCygxActivityPointsSetDetail" + e.Error())
  294. return
  295. }
  296. if activityPointsSetDetail == nil {
  297. return
  298. }
  299. if activityPointsSetDetail.UserPointsNum == 0 || activityPointsSetDetail.PointsType != 1 {
  300. return // 如果不是报名即扣点的这种形式,那么就不做任何处理
  301. }
  302. activityInfo, e := models.GetAddActivityInfoById(activityId)
  303. if e != nil {
  304. err = errors.New("GetAddActivityInfoById" + e.Error())
  305. return
  306. }
  307. user, e := models.GetWxUserItemByUserId(userId)
  308. if e != nil {
  309. err = errors.New("GetWxUserItemByUserId" + e.Error())
  310. return
  311. }
  312. // 获取用户所在公司剩余的点
  313. companyPointsNum, e := models.GetCompanyPoints(user.CompanyId)
  314. if e != nil && e.Error() != utils.ErrNoRow() {
  315. err = errors.New("GetCompanyPoints, Err: " + e.Error())
  316. return
  317. }
  318. //查询最新的一条针对这个用户的扣点记录
  319. var condition string
  320. var pars []interface{}
  321. condition += ` AND activity_id = ? AND user_id = ? AND bill_detailed < 0 ORDER BY id DESC LIMIT 1 `
  322. pars = append(pars, activityId, userId)
  323. activityPointsBillDetail, e := models.GetCygxActivityPointsBillDetailByCondition(condition, pars)
  324. if e != nil {
  325. err = errors.New("activityPointsBillDetail" + e.Error())
  326. return
  327. }
  328. //获取需要添加的流水信息
  329. var items []*models.CygxActivityPointsBill
  330. item := new(models.CygxActivityPointsBill)
  331. item.UserId = user.UserId
  332. item.ActivityId = activityId
  333. item.CreateTime = time.Now()
  334. item.Mobile = user.Mobile
  335. item.Email = user.Email
  336. item.CompanyId = user.CompanyId
  337. item.CompanyName = user.CompanyName
  338. item.RealName = user.RealName
  339. item.BillDetailed = -activityPointsBillDetail.BillDetailed
  340. item.RegisterPlatform = log.RegisterPlatform
  341. item.AdminId = log.AdminId
  342. item.Source = log.Source
  343. item.ChartPermissionId = activityInfo.ChartPermissionId
  344. item.DoType = 2
  345. item.Content = activityInfo.ActivityName + "--取消报名"
  346. item.Points = companyPointsNum - activityPointsBillDetail.BillDetailed
  347. items = append(items, item)
  348. //更新对应机构的剩余点数
  349. var itemCompanys []*models.CygxActivityPointsCompany
  350. itemCompany := new(models.CygxActivityPointsCompany)
  351. itemCompany.CompanyId = user.CompanyId
  352. itemCompany.Points = item.Points
  353. itemCompany.ModifyTime = time.Now()
  354. itemCompanys = append(itemCompanys, itemCompany)
  355. err = models.AddCygxActivityPointsBillMulti(items, itemCompanys)
  356. return
  357. }
  358. // 3:活动编辑
  359. func YanXuanActivityPointsBillActivityEditReduce(log models.YanXuanActivityPointsRedis) (err error) {
  360. defer func() {
  361. if err != nil {
  362. fmt.Println(err)
  363. go utils.SendAlarmMsg("用户报名活动扣点,处理Redis队列消息失败:"+err.Error()+fmt.Sprint("ActivityId", log.ActivityId, "userId", log.UserId), 2)
  364. }
  365. }()
  366. activityId := log.ActivityId
  367. //获取活动是否扣点以及扣点规则明细
  368. activityPointsSetDetail, e := models.GetCygxActivityPointsSetDetail(activityId)
  369. if e != nil && e.Error() != utils.ErrNoRow() {
  370. err = errors.New("GetCygxActivityPointsSetDetail" + e.Error())
  371. return
  372. }
  373. if activityPointsSetDetail == nil {
  374. return
  375. }
  376. if activityPointsSetDetail.CompanyPointsNum == 0 {
  377. return // 如果不是办会人,即扣点的这种形式,那么就不做任何处理
  378. }
  379. comapnyId := activityPointsSetDetail.CompanyId
  380. activityInfo, e := models.GetAddActivityInfoByActivityId(activityId)
  381. if e != nil {
  382. err = errors.New("GetAddActivityInfoByActivityId" + e.Error())
  383. return
  384. }
  385. if activityInfo.PublishStatus == 0 {
  386. return // 未发布的活动不做处理
  387. }
  388. comapny, e := models.GetCompanyById(comapnyId)
  389. if e != nil {
  390. err = errors.New("GetCompanyById" + e.Error())
  391. return
  392. }
  393. // 获取用户所在公司剩余的点
  394. companyPointsNum, e := models.GetCompanyPoints(comapny.CompanyId)
  395. if e != nil && e.Error() != utils.ErrNoRow() {
  396. err = errors.New("GetCompanyPoints, Err: " + e.Error())
  397. return
  398. }
  399. //查询最新的一条针对这个公司的扣点记录
  400. var condition string
  401. var pars []interface{}
  402. condition += ` AND activity_id = ? AND company_id = ? AND mobile = '' AND bill_detailed < 0 ORDER BY id DESC LIMIT 1 `
  403. pars = append(pars, activityId, comapnyId)
  404. activityPointsBillDetail, e := models.GetCygxActivityPointsBillDetailByCondition(condition, pars)
  405. if e != nil && e.Error() != utils.ErrNoRow() {
  406. err = errors.New("GetCompanyPoints, Err: " + e.Error())
  407. return
  408. }
  409. var items []*models.CygxActivityPointsBill
  410. item := new(models.CygxActivityPointsBill)
  411. var itemCompanys []*models.CygxActivityPointsCompany
  412. itemCompany := new(models.CygxActivityPointsCompany)
  413. if activityPointsBillDetail == nil { //如果是空的就添加
  414. //获取需要添加的流水信息
  415. //item.UserId = user.UserId
  416. item.ActivityId = activityId
  417. item.CreateTime = time.Now()
  418. //item.Mobile = user.Mobile
  419. //item.Email = user.Email
  420. item.CompanyId = comapny.CompanyId
  421. item.CompanyName = comapny.CompanyName
  422. //item.RealName = user.RealName
  423. item.BillDetailed = -activityPointsSetDetail.CompanyPointsNum
  424. item.RegisterPlatform = log.RegisterPlatform
  425. item.AdminId = log.AdminId
  426. item.Source = log.Source
  427. item.ChartPermissionId = activityInfo.ChartPermissionId
  428. item.DoType = 1
  429. item.Content = activityInfo.ActivityName + "--办会"
  430. item.Points = companyPointsNum - activityPointsSetDetail.CompanyPointsNum
  431. items = append(items, item)
  432. //更新对应机构的剩余点数
  433. itemCompany.CompanyId = comapny.CompanyId
  434. itemCompany.Points = item.Points
  435. itemCompany.ModifyTime = time.Now()
  436. itemCompanys = append(itemCompanys, itemCompany)
  437. e = models.AddCygxActivityPointsBillMulti(items, itemCompanys)
  438. if e != nil && e.Error() != utils.ErrNoRow() {
  439. err = errors.New("AddCygxActivityPointsBillMulti, Err: " + e.Error())
  440. return
  441. }
  442. } else {
  443. //如果存在就进行对比修改
  444. if activityPointsSetDetail.CompanyPointsNum != -activityPointsBillDetail.BillDetailed {
  445. item.Id = activityPointsBillDetail.Id
  446. item.BillDetailed = -activityPointsSetDetail.CompanyPointsNum
  447. item.Points = companyPointsNum - activityPointsBillDetail.BillDetailed - activityPointsSetDetail.CompanyPointsNum
  448. items = append(items, item)
  449. //更新对应机构的剩余点数
  450. itemCompany.CompanyId = comapny.CompanyId
  451. itemCompany.Points = item.Points
  452. itemCompany.ModifyTime = time.Now()
  453. itemCompanys = append(itemCompanys, itemCompany)
  454. e = models.UpdateCygxActivityPointsBillMulti(items, itemCompanys)
  455. if e != nil && e.Error() != utils.ErrNoRow() {
  456. err = errors.New("UpdateCygxActivityPointsBillMulti, Err: " + e.Error())
  457. return
  458. }
  459. }
  460. }
  461. return
  462. }
  463. // 4:活动发布取消发布
  464. func YanXuanActivityPointsBillActivityPublishAndCancelReduce(log models.YanXuanActivityPointsRedis) (err error) {
  465. defer func() {
  466. if err != nil {
  467. fmt.Println(err)
  468. go utils.SendAlarmMsg("活动发布扣点,处理Redis队列消息失败:"+err.Error()+fmt.Sprint("ActivityId", log.ActivityId, "userId", log.UserId), 2)
  469. }
  470. }()
  471. activityId := log.ActivityId
  472. publishStatus := log.PublishStatus
  473. //comapnyId := log.ComapnyId
  474. //获取活动是否扣点以及扣点规则明细
  475. activityPointsSetDetail, e := models.GetCygxActivityPointsSetDetail(activityId)
  476. if e != nil && e.Error() != utils.ErrNoRow() {
  477. err = errors.New("GetCygxActivityPointsSetDetail" + e.Error())
  478. return
  479. }
  480. if activityPointsSetDetail == nil {
  481. return
  482. }
  483. if activityPointsSetDetail.CompanyPointsNum == 0 && activityPointsSetDetail.PointsType == 2 {
  484. //if activityPointsSetDetail.CompanyPointsNum == 0 {
  485. return // 如果不是办会人扣点,且对用户是到会扣点的这种形式,那么就不做任何处理
  486. }
  487. activityInfo, e := models.GetAddActivityInfoByActivityId(activityId)
  488. if e != nil {
  489. err = errors.New("GetAddActivityInfoByActivityId" + e.Error())
  490. return
  491. }
  492. comapnyId := activityPointsSetDetail.CompanyId
  493. var items []*models.CygxActivityPointsBill
  494. var itemCompanys []*models.CygxActivityPointsCompany
  495. mapCompanyPoints := make(map[int]float64) //一组公司的剩余点数
  496. if publishStatus == 1 {
  497. fmt.Println("//活动发布")
  498. if comapnyId > 0 {
  499. comapny, e := models.GetCompanyById(comapnyId)
  500. if e != nil {
  501. err = errors.New("GetCompanyById" + e.Error())
  502. return
  503. }
  504. // 获取用户所在公司剩余的点
  505. companyPointsNum, e := models.GetCompanyPoints(comapny.CompanyId)
  506. if e != nil && e.Error() != utils.ErrNoRow() {
  507. err = errors.New("GetCompanyPoints, Err: " + e.Error())
  508. return
  509. }
  510. item := new(models.CygxActivityPointsBill)
  511. item.ActivityId = activityId
  512. item.CreateTime = time.Now()
  513. //item.Mobile = user.Mobile
  514. //item.Email = user.Email
  515. item.CompanyId = comapny.CompanyId
  516. item.CompanyName = comapny.CompanyName
  517. //item.RealName = user.RealName
  518. item.BillDetailed = -activityPointsSetDetail.CompanyPointsNum
  519. item.RegisterPlatform = log.RegisterPlatform
  520. item.AdminId = log.AdminId
  521. item.Source = log.Source
  522. item.ChartPermissionId = activityInfo.ChartPermissionId
  523. item.DoType = 1
  524. item.Content = activityInfo.ActivityName + "--办会"
  525. item.Points = companyPointsNum - activityPointsSetDetail.CompanyPointsNum
  526. items = append(items, item)
  527. //更新对应机构的剩余点数
  528. itemCompany := new(models.CygxActivityPointsCompany)
  529. itemCompany.CompanyId = comapny.CompanyId
  530. itemCompany.Points = item.Points
  531. itemCompany.ModifyTime = time.Now()
  532. itemCompanys = append(itemCompanys, itemCompany)
  533. mapCompanyPoints[comapnyId] = item.Points
  534. }
  535. if activityPointsSetDetail.UserPointsNum > 0 && activityPointsSetDetail.PointsType == 1 {
  536. //如果扣点形式选的是报名即扣点,那么就对已经报名的用户所在机构进行扣点
  537. var condition string
  538. var pars []interface{}
  539. condition = ` AND do_fail_type = 0 AND activity_id = ?`
  540. pars = append(pars, activityId)
  541. listSignup, e := models.GetActivitySignupList(condition, pars)
  542. if e != nil && e.Error() != utils.ErrNoRow() {
  543. err = errors.New("GetActivitySignupList, Err: " + e.Error())
  544. return
  545. }
  546. var companyIds []int
  547. if len(listSignup) > 0 {
  548. for _, v := range listSignup {
  549. companyIds = append(companyIds, v.CompanyId)
  550. }
  551. pars = make([]interface{}, 0)
  552. condition = ` AND company_id IN (` + utils.GetOrmInReplace(len(companyIds)) + `)`
  553. pars = append(pars, companyIds)
  554. //获取这些公司剩余的点数
  555. conpanyList, e := models.GetCygxActivityPointsCompanyList(condition, pars)
  556. if e != nil && e.Error() != utils.ErrNoRow() {
  557. err = errors.New("GetCygxActivityPointsCompanyList, Err: " + e.Error())
  558. return
  559. }
  560. for _, v := range conpanyList {
  561. if mapCompanyPoints[v.CompanyId] == 0 {
  562. mapCompanyPoints[v.CompanyId] = v.Points
  563. }
  564. }
  565. for _, user := range listSignup {
  566. item := new(models.CygxActivityPointsBill)
  567. item.ActivityId = activityId
  568. item.CreateTime = time.Now()
  569. item.Mobile = user.Mobile
  570. item.UserId = user.UserId
  571. item.Email = user.Email
  572. item.CompanyId = user.CompanyId
  573. item.CompanyName = user.CompanyName
  574. item.RealName = user.RealName
  575. item.BillDetailed = -activityPointsSetDetail.UserPointsNum
  576. item.RegisterPlatform = log.RegisterPlatform
  577. item.AdminId = log.AdminId
  578. item.Source = log.Source
  579. item.ChartPermissionId = activityInfo.ChartPermissionId
  580. item.DoType = 1
  581. item.Content = activityInfo.ActivityName + "--发布活动"
  582. mapCompanyPoints[user.CompanyId] -= activityPointsSetDetail.UserPointsNum //通过map处理机构剩余点数
  583. item.Points = mapCompanyPoints[user.CompanyId]
  584. items = append(items, item)
  585. //更新对应机构的剩余点数
  586. itemCompany := new(models.CygxActivityPointsCompany)
  587. itemCompany.CompanyId = user.CompanyId
  588. itemCompany.Points = item.Points
  589. itemCompany.ModifyTime = time.Now()
  590. itemCompanys = append(itemCompanys, itemCompany)
  591. mapCompanyPoints[user.CompanyId] = item.Points
  592. }
  593. }
  594. }
  595. } else {
  596. fmt.Println("//活动取消发布")
  597. //活动取消发布
  598. if comapnyId > 0 {
  599. comapny, e := models.GetCompanyById(comapnyId)
  600. if e != nil {
  601. err = errors.New("GetCompanyById" + e.Error())
  602. return
  603. }
  604. // 获取用户所在公司剩余的点
  605. companyPointsNum, e := models.GetCompanyPoints(comapny.CompanyId)
  606. if e != nil && e.Error() != utils.ErrNoRow() {
  607. err = errors.New("GetCompanyPoints, Err: " + e.Error())
  608. return
  609. }
  610. item := new(models.CygxActivityPointsBill)
  611. item.ActivityId = activityId
  612. item.CreateTime = time.Now()
  613. //item.Mobile = user.Mobile
  614. //item.Email = user.Email
  615. item.CompanyId = comapny.CompanyId
  616. item.CompanyName = comapny.CompanyName
  617. //item.RealName = user.RealName
  618. item.BillDetailed = activityPointsSetDetail.CompanyPointsNum
  619. item.RegisterPlatform = log.RegisterPlatform
  620. item.AdminId = log.AdminId
  621. item.Source = log.Source
  622. item.ChartPermissionId = activityInfo.ChartPermissionId
  623. item.DoType = 2
  624. item.Content = activityInfo.ActivityName + "--取消办会"
  625. item.Points = companyPointsNum + activityPointsSetDetail.CompanyPointsNum
  626. items = append(items, item)
  627. //更新对应机构的剩余点数
  628. itemCompany := new(models.CygxActivityPointsCompany)
  629. itemCompany.CompanyId = comapny.CompanyId
  630. itemCompany.Points = item.Points
  631. itemCompany.ModifyTime = time.Now()
  632. itemCompanys = append(itemCompanys, itemCompany)
  633. mapCompanyPoints[comapnyId] = item.Points
  634. }
  635. if activityPointsSetDetail.UserPointsNum > 0 && activityPointsSetDetail.PointsType == 1 {
  636. //如果扣点形式选的是报名即扣点,那么就对已经报名的用户所在机构进行返点
  637. var condition string
  638. var pars []interface{}
  639. condition = ` AND do_fail_type = 0 AND activity_id = ?`
  640. pars = append(pars, activityId)
  641. listSignup, e := models.GetActivitySignupList(condition, pars)
  642. if e != nil && e.Error() != utils.ErrNoRow() {
  643. err = errors.New("GetActivitySignupList, Err: " + e.Error())
  644. return
  645. }
  646. var companyIds []int
  647. if len(listSignup) > 0 {
  648. for _, v := range listSignup {
  649. companyIds = append(companyIds, v.CompanyId)
  650. }
  651. pars = make([]interface{}, 0)
  652. condition = ` AND company_id IN (` + utils.GetOrmInReplace(len(companyIds)) + `)`
  653. pars = append(pars, companyIds)
  654. //获取这些公司剩余的点数
  655. conpanyList, e := models.GetCygxActivityPointsCompanyList(condition, pars)
  656. if e != nil && e.Error() != utils.ErrNoRow() {
  657. err = errors.New("GetCygxActivityPointsCompanyList, Err: " + e.Error())
  658. return
  659. }
  660. for _, v := range conpanyList {
  661. if mapCompanyPoints[v.CompanyId] == 0 {
  662. mapCompanyPoints[v.CompanyId] = v.Points
  663. }
  664. }
  665. pars = make([]interface{}, 0)
  666. condition = ` AND activity_id = ? `
  667. pars = append(pars, activityId)
  668. //获取扣点的流水记录
  669. activityPointsBillList, e := models.GetCygxActivityPointsBillList(condition, pars)
  670. if e != nil && e.Error() != utils.ErrNoRow() {
  671. err = errors.New("GetCygxActivityPointsBillList" + e.Error())
  672. return
  673. }
  674. mapUserBill := make(map[int]bool)
  675. for _, v := range activityPointsBillList {
  676. mapUserBill[v.UserId] = true
  677. }
  678. for _, user := range listSignup {
  679. if !mapUserBill[user.UserId] {
  680. continue // 如果用户的扣点记录不存在,那么就不进行返点处理
  681. }
  682. item := new(models.CygxActivityPointsBill)
  683. item.ActivityId = activityId
  684. item.CreateTime = time.Now()
  685. item.Mobile = user.Mobile
  686. item.UserId = user.UserId
  687. item.Email = user.Email
  688. item.CompanyId = user.CompanyId
  689. item.CompanyName = user.CompanyName
  690. item.RealName = user.RealName
  691. item.BillDetailed = activityPointsSetDetail.UserPointsNum
  692. item.RegisterPlatform = log.RegisterPlatform
  693. item.AdminId = log.AdminId
  694. item.Source = log.Source
  695. item.ChartPermissionId = activityInfo.ChartPermissionId
  696. item.DoType = 2
  697. item.Content = activityInfo.ActivityName + "--取消活动"
  698. mapCompanyPoints[user.CompanyId] += activityPointsSetDetail.UserPointsNum //通过map处理机构剩余点数
  699. item.Points = mapCompanyPoints[user.CompanyId]
  700. items = append(items, item)
  701. //更新对应机构的剩余点数
  702. itemCompany := new(models.CygxActivityPointsCompany)
  703. itemCompany.CompanyId = user.CompanyId
  704. itemCompany.Points = item.Points
  705. itemCompany.ModifyTime = time.Now()
  706. itemCompanys = append(itemCompanys, itemCompany)
  707. mapCompanyPoints[user.CompanyId] = item.Points
  708. }
  709. }
  710. }
  711. }
  712. e = models.AddCygxActivityPointsBillMulti(items, itemCompanys)
  713. if e != nil && e.Error() != utils.ErrNoRow() {
  714. err = errors.New("AddCygxActivityPointsBillMulti, Err: " + e.Error())
  715. return
  716. }
  717. return
  718. }
  719. //func init() {
  720. // log := models.YanXuanActivityPointsRedis{ActivityId: 2385, SourceType: 5, RegisterPlatform: utils.REGISTER_PLATFORM, Source: 4, CreateTime: time.Now()}
  721. // YanXuanActivityPointsBillSubmitMeetingReduce(log)
  722. //}
  723. // 5:活动到会研选扣点处理
  724. func YanXuanActivityPointsBillSubmitMeetingReduce(log models.YanXuanActivityPointsRedis) (err error) {
  725. //func YanXuanActivityPointsBillSubmitMeetingReduce(activityId int) (err error) {
  726. defer func() {
  727. if err != nil {
  728. fmt.Println(err)
  729. go utils.SendAlarmMsg("活动到会研选扣点,处理Redis队列消息失败:"+err.Error()+fmt.Sprint("ActivityId", log.ActivityId, "adminId", log.AdminId), 2)
  730. }
  731. }()
  732. activityId := log.ActivityId
  733. //获取活动是否扣点以及扣点规则明细
  734. activityPointsSetDetail, e := models.GetCygxActivityPointsSetDetail(activityId)
  735. if e != nil && e.Error() != utils.ErrNoRow() {
  736. err = errors.New("GetCygxActivityPointsSetDetail" + e.Error())
  737. return
  738. }
  739. if activityPointsSetDetail == nil {
  740. return
  741. }
  742. if activityPointsSetDetail.PointsType != 2 {
  743. return // 如果不是到会即扣点,的这种形式,那么就不做任何处理
  744. }
  745. activityInfo, e := models.GetAddActivityInfoByActivityId(activityId)
  746. if e != nil {
  747. err = errors.New("GetAddActivityInfoByActivityId" + e.Error())
  748. return
  749. }
  750. var companyIds []int
  751. mapCompanyPoints := make(map[int]float64) //一组公司的剩余点数
  752. var condition string
  753. var pars []interface{}
  754. condition += ` AND activity_id = ? AND is_meeting = 1 `
  755. pars = append(pars, activityId)
  756. //获取提交到会的人员信息
  757. signUpDetailList, e := models.GetSignupDetailList(condition, pars)
  758. if e != nil && e.Error() != utils.ErrNoRow() {
  759. err = errors.New("GetSignupDetailList" + e.Error())
  760. return
  761. }
  762. if len(signUpDetailList) == 0 {
  763. return
  764. }
  765. for _, v := range signUpDetailList {
  766. companyIds = append(companyIds, v.CompanyId)
  767. }
  768. //return
  769. pars = make([]interface{}, 0)
  770. condition = ` AND company_id IN (` + utils.GetOrmInReplace(len(companyIds)) + `)`
  771. pars = append(pars, companyIds)
  772. //获取这些公司剩余的点数
  773. conpanyList, e := models.GetCygxActivityPointsCompanyList(condition, pars)
  774. if e != nil && e.Error() != utils.ErrNoRow() {
  775. err = errors.New("GetCygxActivityPointsCompanyList, Err: " + e.Error())
  776. return
  777. }
  778. pars = make([]interface{}, 0)
  779. condition = ` AND activity_id = ? AND mobile != '' `
  780. pars = append(pars, activityId)
  781. //获取扣点的流水记录
  782. activityPointsBillList, e := models.GetCygxActivityPointsBillList(condition, pars)
  783. if e != nil && e.Error() != utils.ErrNoRow() {
  784. err = errors.New("GetCygxActivityPointsBillList" + e.Error())
  785. return
  786. }
  787. mapActivityPointsBill := make(map[string]*models.CygxActivityPointsBill)
  788. for _, v := range activityPointsBillList {
  789. mapActivityPointsBill[v.Mobile] = v
  790. }
  791. //return
  792. for _, v := range conpanyList {
  793. if v.CompanyId != 0 {
  794. mapCompanyPoints[v.CompanyId] = v.Points
  795. }
  796. }
  797. //return
  798. var items []*models.CygxActivityPointsBill
  799. var itemCompanys []*models.CygxActivityPointsCompany
  800. for _, user := range signUpDetailList {
  801. item := new(models.CygxActivityPointsBill)
  802. item.ActivityId = activityId
  803. item.CreateTime = time.Now()
  804. item.UserId = user.UserId
  805. item.Mobile = user.Mobile
  806. item.Email = user.Email
  807. item.CompanyId = user.CompanyId
  808. item.CompanyName = user.CompanyName
  809. item.RealName = user.RealName
  810. item.RegisterPlatform = log.RegisterPlatform
  811. item.AdminId = log.AdminId
  812. item.Source = log.Source
  813. item.ChartPermissionId = activityInfo.ChartPermissionId
  814. //如果没有扣点记录就对他们进行扣点处理
  815. if mapActivityPointsBill[user.Mobile] == nil {
  816. item.BillDetailed = -activityPointsSetDetail.UserPointsNum
  817. item.DoType = 1
  818. item.Content = activityInfo.ActivityName + "--活动到会"
  819. item.Points = mapCompanyPoints[user.CompanyId] - activityPointsSetDetail.UserPointsNum
  820. items = append(items, item)
  821. //更新对应机构的剩余点数
  822. itemCompany := new(models.CygxActivityPointsCompany)
  823. itemCompany.CompanyId = user.CompanyId
  824. itemCompany.Points = item.Points
  825. itemCompany.ModifyTime = time.Now()
  826. itemCompanys = append(itemCompanys, itemCompany)
  827. mapCompanyPoints[user.CompanyId] = item.Points
  828. } else {
  829. //第二次提交改成未到会的,对其进行返点处理
  830. if mapActivityPointsBill[user.Mobile].BillDetailed < 0 {
  831. item.BillDetailed = activityPointsSetDetail.UserPointsNum
  832. item.DoType = 2
  833. item.Content = activityInfo.ActivityName + "--活动取消到会"
  834. item.Points = mapCompanyPoints[user.CompanyId] + activityPointsSetDetail.UserPointsNum
  835. items = append(items, item)
  836. //更新对应机构的剩余点数
  837. itemCompany := new(models.CygxActivityPointsCompany)
  838. itemCompany.CompanyId = user.CompanyId
  839. itemCompany.Points = item.Points
  840. itemCompany.ModifyTime = time.Now()
  841. itemCompanys = append(itemCompanys, itemCompany)
  842. mapCompanyPoints[user.CompanyId] = item.Points
  843. }
  844. }
  845. }
  846. e = models.AddCygxActivityPointsBillMulti(items, itemCompanys)
  847. if e != nil && e.Error() != utils.ErrNoRow() {
  848. err = errors.New("AddCygxActivityPointsBillMulti, Err: " + e.Error())
  849. return
  850. }
  851. return
  852. }
  853. // 6:研选审批通过的时候研选扣点更新
  854. func YanXuanCompanyApprovalReduce(log models.YanXuanActivityPointsRedis) (err error) {
  855. time.Sleep(5 * time.Second) // 延迟5秒处理
  856. defer func() {
  857. if err != nil {
  858. fmt.Println(err)
  859. go utils.SendAlarmMsg("研选审批通过的时候研选扣点更新,处理Redis队列消息失败:"+err.Error()+fmt.Sprint(log), 2)
  860. }
  861. }()
  862. comapnyId := log.ComapnyId
  863. companyContractId := log.CompanyContractId
  864. comapnyDetail, e := models.GetCompanyById(comapnyId)
  865. if e != nil {
  866. err = errors.New("GetCompanyById" + e.Error())
  867. return
  868. }
  869. total, e := models.GetCygxActivityPointsCompanyCountByCompanyId(comapnyId)
  870. if e != nil {
  871. err = errors.New("GetCygxActivityPointsCompanyCountByCompanyId, Err: " + e.Error())
  872. return
  873. }
  874. //查询研选的权限状态
  875. var condition string
  876. var pars []interface{}
  877. condition += " AND company_id = ? AND company_contract_id =? AND chart_permission_id = ? ORDER BY id DESC LIMIT 1 "
  878. pars = append(pars, comapnyId, companyContractId, utils.YAN_XUAN_KOU_DIAN_BAO_ID)
  879. companyPointDetail, e := company.GetCompanyContractPermissionDetail(condition, pars)
  880. if e != nil && e.Error() != utils.ErrNoRow() {
  881. err = errors.New("GetCompanyContractPermissionDetail, Err: " + e.Error())
  882. return
  883. }
  884. if companyPointDetail == nil {
  885. return // 如果不存在就不做研选扣点处理
  886. }
  887. //获取最近的一条审批合同信息
  888. //newCompanyApprovalDetail, e := company.GetCompanyApprovalById(comapnyId)
  889. //if e != nil && e.Error() != utils.ErrNoRow() {
  890. // err = errors.New("GetCompanyApprovalById, Err: " + e.Error())
  891. // return
  892. //}
  893. //if newCompanyApprovalDetail == nil {
  894. // return
  895. //}
  896. //companyContractId := newCompanyApprovalDetail.CompanyContractId
  897. //totalYxPerminssion, e := company.GetCompanyContractPermissionCheck(companyContractId, utils.CHART_PERMISSION_ID_YANXUAN)
  898. //if e != nil {
  899. // err = errors.New("GetCompanyContractPermissionCheck, Err: " + e.Error())
  900. // return
  901. //}
  902. //// 如果最新的审批合同里没有研选的权限,那么就不做处理
  903. //if totalYxPerminssion == 0 {
  904. // return
  905. //}
  906. var billDetailed float64
  907. var content string
  908. //ExpensiveYx int `description:"权益研选: 0->3w; 1->5w;2->10W"` 3W3次、5W 15次,20w:40次 ,
  909. //if companyReportPermissionDetail.ExpensiveYx == 1 {
  910. // billDetailed = 15
  911. // content = "买方研选(5W)转正"
  912. //} else if companyReportPermissionDetail.ExpensiveYx == 2 {
  913. // billDetailed = 40
  914. // content = "买方研选(10w)转正"
  915. //} else {
  916. // billDetailed = 3
  917. // content = "买方研选(3W)转正"
  918. //}
  919. // 获取用户所在公司剩余的点
  920. companyPointsNum, e := models.GetCompanyPoints(comapnyId)
  921. if e != nil && e.Error() != utils.ErrNoRow() {
  922. err = errors.New("GetCompanyPoints, Err: " + e.Error())
  923. return
  924. }
  925. billDetailed = companyPointDetail.Points + companyPointsNum
  926. content = "签约研选扣点包"
  927. //获取需要添加的流水信息
  928. var items []*models.CygxActivityPointsBill
  929. item := new(models.CygxActivityPointsBill)
  930. //item.UserId = user.UserId
  931. //item.ActivityId = activityId
  932. item.CreateTime = time.Now()
  933. //item.Mobile = user.Mobile
  934. //item.Email = user.Email
  935. item.CompanyId = comapnyDetail.CompanyId
  936. item.CompanyName = comapnyDetail.CompanyName
  937. //item.RealName = user.RealName
  938. item.BillDetailed = billDetailed
  939. item.RegisterPlatform = log.RegisterPlatform
  940. item.AdminId = log.AdminId
  941. item.Source = log.Source
  942. //item.ChartPermissionId = activityInfo.ChartPermissionId
  943. item.DoType = 2
  944. item.Content = content
  945. item.Points = billDetailed
  946. items = append(items, item)
  947. //更新对应机构的剩余点数
  948. var itemCompanys []*models.CygxActivityPointsCompany
  949. itemCompany := new(models.CygxActivityPointsCompany)
  950. itemCompany.CompanyId = comapnyDetail.CompanyId
  951. itemCompany.CompanyName = comapnyDetail.CompanyName
  952. itemCompany.Points = item.Points
  953. itemCompany.CreateTime = time.Now()
  954. itemCompany.ModifyTime = time.Now()
  955. itemCompanys = append(itemCompanys, itemCompany)
  956. //判断是否存在记录,如果有就一个新增一个修改,如果没有就同时新增
  957. if total == 0 {
  958. err = models.AddCygxActivityPointsBillAndCompanyMulti(items, itemCompanys)
  959. } else {
  960. err = models.AddCygxActivityPointsBillMulti(items, itemCompanys)
  961. }
  962. return
  963. }
  964. // 7:正式专试用定时任务更新研选扣点
  965. func YanXuanCompanyCompanyTryOutReduce(log models.YanXuanActivityPointsRedis) (err error) {
  966. defer func() {
  967. if err != nil {
  968. fmt.Println(err)
  969. go utils.SendAlarmMsg("正式专试用定时任务更新研选扣点更新,处理Redis队列消息失败:"+err.Error()+fmt.Sprint(log), 2)
  970. }
  971. }()
  972. comapnyId := log.ComapnyId
  973. comapny, e := models.GetCompanyById(comapnyId)
  974. if e != nil {
  975. err = errors.New("GetCompanyById" + e.Error())
  976. return
  977. }
  978. // 获取用户所在公司剩余的点
  979. companyPointsNum, e := models.GetCompanyPoints(comapnyId)
  980. if e != nil && e.Error() != utils.ErrNoRow() {
  981. err = errors.New("GetCompanyPoints, Err: " + e.Error())
  982. return
  983. }
  984. if companyPointsNum <= 0 {
  985. return
  986. }
  987. //获取需要添加的流水信息
  988. var items []*models.CygxActivityPointsBill
  989. item := new(models.CygxActivityPointsBill)
  990. //item.UserId = user.UserId
  991. //item.ActivityId = activityId
  992. item.CreateTime = time.Now()
  993. //item.Mobile = user.Mobile
  994. //item.Email = user.Email
  995. item.CompanyId = comapny.CompanyId
  996. item.CompanyName = comapny.CompanyName
  997. //item.RealName = user.RealName
  998. item.BillDetailed = -companyPointsNum
  999. item.RegisterPlatform = log.RegisterPlatform
  1000. item.AdminId = log.AdminId
  1001. item.Source = log.Source
  1002. //item.ChartPermissionId = activityInfo.ChartPermissionId
  1003. item.DoType = 2
  1004. item.Content = "研选扣点包到期清零"
  1005. item.Points = 0
  1006. items = append(items, item)
  1007. //更新对应机构的剩余点数
  1008. var itemCompanys []*models.CygxActivityPointsCompany
  1009. itemCompany := new(models.CygxActivityPointsCompany)
  1010. itemCompany.CompanyId = comapny.CompanyId
  1011. itemCompany.Points = 0
  1012. itemCompany.CreateTime = time.Now()
  1013. itemCompany.ModifyTime = time.Now()
  1014. itemCompanys = append(itemCompanys, itemCompany)
  1015. err = models.AddCygxActivityPointsBillMulti(items, itemCompanys)
  1016. return
  1017. }
  1018. // 8:用户观看音视频研选扣点处理
  1019. func YanXuanActivityVivoPointsBillSignupReduce(log models.YanXuanActivityPointsRedis) (err error) {
  1020. //func YanXuanActivityPointsBillSubmitMeetingReduce(activityId int) (err error) {
  1021. defer func() {
  1022. if err != nil {
  1023. fmt.Println(err)
  1024. go utils.SendAlarmMsg("用户观看音视频研选扣点处理,处理Redis队列消息失败:"+err.Error()+fmt.Sprint("ActivityId", log.ActivityId, "UserId", log.UserId), 2)
  1025. }
  1026. }()
  1027. activityId := log.ActivityId
  1028. userId := log.UserId
  1029. //获取活动是否扣点以及扣点规则明细
  1030. vivoPointsSetDetail, e := models.GetCygxActivityVivoPointsSetByActivityId(activityId)
  1031. if e != nil && e.Error() != utils.ErrNoRow() {
  1032. err = errors.New("GetCygxActivityVivoPointsSetByActivityId" + e.Error())
  1033. return
  1034. }
  1035. if vivoPointsSetDetail == nil {
  1036. return
  1037. }
  1038. var vivoName string
  1039. activityInfo, e := models.GetAddActivityInfoByActivityId(activityId)
  1040. if e != nil {
  1041. err = errors.New("GetAddActivityInfoByActivityId" + e.Error())
  1042. return
  1043. }
  1044. totalVi, e := models.GetCygxActivityVideoCount(activityId)
  1045. if e != nil {
  1046. err = errors.New("GetCygxActivityVideoCount" + e.Error())
  1047. return
  1048. }
  1049. if totalVi > 0 {
  1050. activityVideoInfo, e := models.GetCygxActivityVideoByActivityId(activityId)
  1051. if e != nil {
  1052. err = errors.New("GetCygxActivityVideoByActivityId, Err: " + e.Error())
  1053. return
  1054. }
  1055. vivoName = activityVideoInfo.VideoName // 视频名称
  1056. } else {
  1057. totalVo, e := models.GetCygxActivityVoiceCount(activityId)
  1058. if e != nil {
  1059. err = errors.New("GetCygxActivityVoiceCount" + e.Error())
  1060. return
  1061. }
  1062. if totalVo > 0 {
  1063. activityVoiceInfo, e := models.GetCygxActivityVoiceByActivityId(activityId)
  1064. if e != nil {
  1065. err = errors.New("GetCygxActivityVoiceByActivityId, Err: " + e.Error())
  1066. return
  1067. }
  1068. vivoName = activityVoiceInfo.VoiceName // 音频名称
  1069. }
  1070. }
  1071. user, e := models.GetWxUserItemByUserId(userId)
  1072. if e != nil {
  1073. err = errors.New("GetWxUserItemByUserId" + e.Error())
  1074. return
  1075. }
  1076. // 获取用户所在公司剩余的点
  1077. companyPointsNum, e := models.GetCompanyPoints(user.CompanyId)
  1078. if e != nil && e.Error() != utils.ErrNoRow() {
  1079. err = errors.New("GetCompanyPoints, Err: " + e.Error())
  1080. return
  1081. }
  1082. //获取需要添加的流水信息
  1083. var items []*models.CygxActivityPointsBill
  1084. item := new(models.CygxActivityPointsBill)
  1085. item.UserId = user.UserId
  1086. item.ActivityId = activityId
  1087. item.CreateTime = time.Now()
  1088. item.Mobile = user.Mobile
  1089. item.Email = user.Email
  1090. item.CompanyId = user.CompanyId
  1091. item.CompanyName = user.CompanyName
  1092. item.RealName = user.RealName
  1093. item.BillDetailed = -vivoPointsSetDetail.PointsNum
  1094. item.RegisterPlatform = log.RegisterPlatform
  1095. item.AdminId = log.AdminId
  1096. item.Source = log.Source
  1097. item.ChartPermissionId = activityInfo.ChartPermissionId
  1098. item.DoType = 1
  1099. item.Content = "查看活动回放-" + vivoName
  1100. item.Points = companyPointsNum - vivoPointsSetDetail.PointsNum
  1101. items = append(items, item)
  1102. //更新对应机构的剩余点数
  1103. var itemCompanys []*models.CygxActivityPointsCompany
  1104. itemCompany := new(models.CygxActivityPointsCompany)
  1105. itemCompany.CompanyId = user.CompanyId
  1106. itemCompany.Points = item.Points
  1107. itemCompany.ModifyTime = time.Now()
  1108. itemCompanys = append(itemCompanys, itemCompany)
  1109. err = models.AddCygxActivityPointsBillMulti(items, itemCompanys)
  1110. return
  1111. }