pushSet.go 16 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430
  1. package service
  2. import (
  3. "app.yhyue.com/moapp/jybase/common"
  4. "bp.jydev.jianyu360.cn/BaseService/powerCheckCenter/rpc/pb"
  5. "fmt"
  6. IC "bp.jydev.jianyu360.cn/BaseService/jyMicroservices/jyBXSubscribe/rpc/init"
  7. "bp.jydev.jianyu360.cn/BaseService/jyMicroservices/jyBXSubscribe/rpc/type/bxsubscribe"
  8. "bp.jydev.jianyu360.cn/BaseService/jyMicroservices/jyBXSubscribe/rpc/util"
  9. "regexp"
  10. )
  11. type PushSetService struct {
  12. UserId string //mongodb 的用户id
  13. PositionType int64
  14. EntId int64
  15. EntUserId int64
  16. BaseUserId int64
  17. AccountId int64
  18. PositionId int64
  19. MgoUserId string
  20. }
  21. func (this *PushSetService) Update(item, setType, pushType string, ratemode, pushValue, interested int64, times []string) bool {
  22. set := map[string]interface{}{}
  23. switch setType {
  24. case "pushRoute":
  25. set = map[string]interface{}{
  26. fmt.Sprintf("o_pushset.%s.%s", item, pushType): common.IntAll(pushValue),
  27. }
  28. break
  29. case "a_times":
  30. if ratemode == 2 {
  31. if len(times) == 0 {
  32. return false
  33. }
  34. }
  35. set = map[string]interface{}{
  36. fmt.Sprintf("o_pushset.%s.a_times", item): times,
  37. fmt.Sprintf("o_pushset.%s.i_ratemode", item): common.IntAll(ratemode),
  38. }
  39. case "message":
  40. set = map[string]interface{}{
  41. fmt.Sprintf("o_pushset.%s.%s", item, pushType): common.IntAll(pushValue),
  42. }
  43. default:
  44. set = map[string]interface{}{
  45. "o_pushset.i_interested": common.IntAll(interested),
  46. }
  47. }
  48. update := false
  49. if (setType == "message" && this.PositionType == 1) || this.PositionType == 0 {
  50. update = IC.Mgo.UpdateById(util.USER, this.UserId, map[string]interface{}{
  51. "$set": set,
  52. })
  53. } else {
  54. update = IC.Mgo.Update(util.ENTUSER, map[string]interface{}{"i_entid": this.EntId, "i_userid": this.EntUserId}, map[string]interface{}{
  55. "$set": set,
  56. }, true, false)
  57. }
  58. return update
  59. }
  60. func (this *PushSetService) Find() map[string]*bxsubscribe.PushSet {
  61. pushSetMap := &map[string]interface{}{}
  62. o_msgPushSet := map[string]interface{}{}
  63. //
  64. ShowWx := false
  65. s_m_openid := ""
  66. pushSetMap, _ = IC.Mgo.FindById(util.USER, this.UserId, `{"o_pushset":":1,"s_m_openid":1,"l_registedate",1}`)
  67. if pushSetMap != nil && len(*pushSetMap) > 0 {
  68. s_m_openid = common.InterfaceToStr((*pushSetMap)["s_m_openid"])
  69. o_msgPushSet, _ = (*pushSetMap)["o_pushset"].(map[string]interface{})
  70. }
  71. registedate := int64(0)
  72. if s_m_openid != "" {
  73. //微信是否关注处理
  74. subscribeList := &[]map[string]interface{}{}
  75. subscribeList, _ = IC.Mgo.Find(util.SUBSCRIBE, map[string]interface{}{"s_m_openid": s_m_openid}, `{"l_date":-1}`, `{"s_event":1"}`, true, -1, -1)
  76. if subscribeList != nil && len(*subscribeList) > 0 {
  77. s_event := common.InterfaceToStr((*subscribeList)[0]["s_event"])
  78. if s_event == "subscribe" {
  79. ShowWx = true
  80. }
  81. }
  82. }
  83. registedate = common.Int64All((*pushSetMap)["l_registedate"])
  84. if this.PositionType == 1 {
  85. pushSetMap, _ = IC.Mgo.FindOne(util.ENTUSER, map[string]interface{}{"i_entid": this.EntId, "i_userid": this.EntUserId})
  86. }
  87. pushSet := map[string]*bxsubscribe.PushSet{}
  88. //用户权益获取
  89. powerData := IC.Middleground.PowerCheckCenter.Check("10000", this.MgoUserId, this.BaseUserId, this.AccountId, this.EntId, this.PositionType, this.PositionId)
  90. o_pushset := map[string]interface{}{}
  91. if pushSetMap != nil && len(*pushSetMap) > 0 {
  92. o_pushset, _ = (*pushSetMap)["o_pushset"].(map[string]interface{})
  93. }
  94. if o_pushset != nil {
  95. pushSet["interested"] = &bxsubscribe.PushSet{
  96. Interested: common.Int64All(common.If(o_pushset["i_interested"] == nil, 1, common.Int64All(o_pushset["i_interested"]))),
  97. }
  98. } else {
  99. pushSet["interested"] = &bxsubscribe.PushSet{
  100. Interested: 1,
  101. }
  102. }
  103. //推送设置
  104. fool, o_subset := pushSetMontage(o_pushset["o_subset"], "o_subset", powerData, ShowWx, registedate)
  105. if fool {
  106. pushSet["o_subset"] = o_subset
  107. }
  108. fool, o_week_report := pushSetMontage(o_pushset["o_week_report"], "o_week_report", powerData, ShowWx, registedate)
  109. if fool {
  110. pushSet["o_week_report"] = o_week_report
  111. }
  112. fool, o_month_report := pushSetMontage(o_pushset["o_month_report"], "o_month_report", powerData, ShowWx, registedate)
  113. if fool {
  114. pushSet["o_month_report"] = o_month_report
  115. }
  116. fool, o_newproject_forecast := pushSetMontage(o_pushset["o_newproject_forecast"], "o_newproject_forecast", powerData, ShowWx, registedate)
  117. if fool {
  118. pushSet["o_newproject_forecast"] = o_newproject_forecast
  119. }
  120. //企业信息
  121. fool, o_entinfo := pushSetMontage(o_pushset["o_entinfo"], "o_entinfo", powerData, ShowWx, registedate)
  122. if fool {
  123. pushSet["o_entinfo"] = o_entinfo
  124. }
  125. //项目关注
  126. fool, o_follow_project := pushSetMontage(o_pushset["o_follow_project"], "o_follow_project", powerData, ShowWx, registedate)
  127. if fool {
  128. pushSet["o_follow_project"] = o_follow_project
  129. }
  130. //业主监控 P303
  131. fool, o_owner_monitor := pushSetMontage(o_pushset["o_owner_monitor"], "o_owner_monitor", powerData, ShowWx, registedate)
  132. if fool {
  133. pushSet["o_owner_monitor"] = o_owner_monitor
  134. }
  135. //企业关注
  136. fool, o_follow_ent := pushSetMontage(o_pushset["o_follow_ent"], "o_follow_ent", powerData, ShowWx, registedate)
  137. if fool {
  138. pushSet["o_follow_ent"] = o_follow_ent
  139. }
  140. //消息
  141. fool, o_msg_active := pushSetMontage(o_msgPushSet["o_msg_active"], "o_msg_active", powerData, ShowWx, registedate)
  142. if fool {
  143. pushSet["o_msg_active"] = o_msg_active
  144. }
  145. //消息服务
  146. fool, o_msg_service := pushSetMontage(o_msgPushSet["o_msg_service"], "o_msg_service", powerData, ShowWx, registedate)
  147. if fool {
  148. pushSet["o_msg_service"] = o_msg_service
  149. }
  150. //剑鱼学堂
  151. fool, o_msg_jyschool := pushSetMontage(o_msgPushSet["o_msg_jyschool"], "o_msg_jyschool", powerData, ShowWx, registedate)
  152. if fool {
  153. pushSet["o_msg_jyschool"] = o_msg_jyschool
  154. }
  155. fool, o_msg_business := pushSetMontage(o_msgPushSet["o_msg_business"], "o_msg_business", powerData, ShowWx, registedate)
  156. if fool {
  157. pushSet["o_msg_business"] = o_msg_business
  158. }
  159. //私信
  160. fool, o_msg_pending := pushSetMontage(o_msgPushSet["o_msg_pending"], "o_msg_business", powerData, ShowWx, registedate)
  161. if fool {
  162. pushSet["o_msg_pending"] = o_msg_pending
  163. }
  164. fool, o_msg_privateletter := pushSetMontage(o_msgPushSet["o_msg_privateletter"], "o_msg_privateletter", powerData, ShowWx, registedate)
  165. if fool {
  166. pushSet["o_msg_privateletter"] = o_msg_privateletter
  167. }
  168. return pushSet
  169. }
  170. func pushSetMontage(in interface{}, name string, powerData *pb.CheckResp, ShowWx bool, registedate int64) (bool, *bxsubscribe.PushSet) {
  171. data := common.ObjToMap(in)
  172. a_times := []string{}
  173. isMailShow := int64(1)
  174. isReturnMailShow := true
  175. if !(data == nil || len(*data) == 0) {
  176. if (*data)["a_times"] != nil {
  177. a_times = common.ObjArrToStringArr((*data)["a_times"].([]interface{}))
  178. }
  179. }
  180. power := make(map[int]bool)
  181. for _, v := range powerData.Member.MemberPowerList {
  182. power[common.IntAll(v)] = true
  183. }
  184. returnData := &bxsubscribe.PushSet{}
  185. switch name {
  186. case "o_subset":
  187. if powerData.Free.IsFree {
  188. returnData = &bxsubscribe.PushSet{
  189. ATimes: []string{"每日上午、下午各推送1次"},
  190. IApppush: common.Int64All(common.If((*data)["i_apppush"] == nil, 0, (*data)["i_apppush"])),
  191. IApppushTip: common.Int64All(common.If((*data)["i_apppush_tip"] == nil, 0, (*data)["i_apppush_tip"])),
  192. IWxpush: common.Int64All(common.If((*data)["i_wxpush"] == nil, common.If(ShowWx, 1, 0), common.If(ShowWx, (*data)["i_wxpush"], 0))),
  193. IMailpush: common.Int64All(common.If((*data)["i_mailpush"] == nil, 0, (*data)["i_mailpush"])),
  194. IRatemode: 2,
  195. IsWxShow: 1,
  196. INomsgtip: common.Int64All(common.If((*data)["i_nomsgtip"] == nil, 1, (*data)["i_nomsgtip"])),
  197. }
  198. } else {
  199. if data == nil || len(*data) == 0 {
  200. returnData = &bxsubscribe.PushSet{
  201. ATimes: util.TimeMap[2],
  202. IApppush: 0,
  203. IApppushTip: 0,
  204. IWxpush: common.Int64All(common.If(ShowWx, 1, 0)),
  205. IMailpush: 0,
  206. IRatemode: 2,
  207. IsWxShow: 1,
  208. INomsgtip: 1,
  209. }
  210. } else {
  211. returnData = &bxsubscribe.PushSet{
  212. ATimes: common.If((*data)["i_ratemode"] == nil, util.TimeMap[2], a_times).([]string),
  213. IApppush: common.Int64All(common.If((*data)["i_apppush"] == nil, 0, (*data)["i_apppush"])),
  214. IApppushTip: common.Int64All(common.If((*data)["i_apppush_tip"] == nil, 0, (*data)["i_apppush_tip"])),
  215. IWxpush: common.Int64All(common.If((*data)["i_wxpush"] == nil, common.If(ShowWx, 1, 0), common.If(ShowWx, (*data)["i_wxpush"], 0))),
  216. IMailpush: common.Int64All(common.If((*data)["i_mailpush"] == nil, 0, (*data)["i_mailpush"])),
  217. IRatemode: common.Int64All(common.If((*data)["i_ratemode"] == nil, 2, (*data)["i_ratemode"])),
  218. IsWxShow: 1,
  219. INomsgtip: common.Int64All(common.If((*data)["i_nomsgtip"] == nil, 1, (*data)["i_nomsgtip"])),
  220. }
  221. if common.Int64All((*data)["i_ratemode"]) == 5 {
  222. returnData.ATimes = []string{"14:00"}
  223. }
  224. }
  225. }
  226. case "o_follow_project", "o_follow_ent":
  227. if powerData.Free.IsFree {
  228. returnData = &bxsubscribe.PushSet{
  229. ATimes: []string{"实时推送"},
  230. IApppush: common.Int64All(common.If((*data)["i_apppush"] == nil, 1, (*data)["i_apppush"])),
  231. IWxpush: common.Int64All(common.If((*data)["i_wxpush"] == nil, common.If(ShowWx, 1, 0), common.If(ShowWx, (*data)["i_wxpush"], 0))),
  232. IMailpush: common.Int64All(common.If((*data)["i_mailpush"] == nil, 0, (*data)["i_mailpush"])),
  233. IRatemode: 1,
  234. IsWxShow: 1,
  235. }
  236. } else if data == nil || len(*data) == 0 {
  237. a_times = append(a_times, "实时推送")
  238. returnData = &bxsubscribe.PushSet{
  239. ATimes: a_times,
  240. IApppush: 1,
  241. IWxpush: common.Int64All(common.If(ShowWx, 1, 0)),
  242. IMailpush: 0,
  243. IRatemode: 1,
  244. IsWxShow: 1,
  245. }
  246. } else {
  247. returnData = &bxsubscribe.PushSet{
  248. ATimes: a_times,
  249. IApppush: common.Int64All(common.If((*data)["i_apppush"] == nil, 1, (*data)["i_apppush"])),
  250. IWxpush: common.Int64All(common.If((*data)["i_wxpush"] == nil, common.If(ShowWx, 1, 0), common.If(ShowWx, (*data)["i_wxpush"], 0))),
  251. IMailpush: common.Int64All(common.If((*data)["i_mailpush"] == nil, 0, (*data)["i_mailpush"])),
  252. IRatemode: common.Int64All(common.If((*data)["i_ratemode"] == nil, 1, (*data)["i_ratemode"])),
  253. IsWxShow: 1,
  254. }
  255. }
  256. case "o_newproject_forecast":
  257. if powerData.Member.Status > 0 && power[9] {
  258. if data == nil || len(*data) == 0 {
  259. a_times = append(a_times, "实时推送")
  260. returnData = &bxsubscribe.PushSet{
  261. ATimes: a_times,
  262. IApppush: 1,
  263. IWxpush: common.Int64All(common.If(ShowWx, 1, 0)),
  264. IMailpush: 0,
  265. IRatemode: 1,
  266. IsWxShow: 1,
  267. }
  268. } else {
  269. returnData = &bxsubscribe.PushSet{
  270. ATimes: a_times,
  271. IApppush: common.Int64All(common.If((*data)["i_apppush"] == nil, 1, (*data)["i_apppush"])),
  272. IWxpush: common.Int64All(common.If((*data)["i_wxpush"] == nil, common.If(ShowWx, 1, 0), common.If(ShowWx, (*data)["i_wxpush"], 0))),
  273. IMailpush: common.Int64All(common.If((*data)["i_mailpush"] == nil, 0, (*data)["i_mailpush"])),
  274. IRatemode: common.Int64All(common.If((*data)["i_ratemode"] == nil, 1, (*data)["i_ratemode"])),
  275. IsWxShow: 1,
  276. }
  277. }
  278. } else {
  279. return false, nil
  280. }
  281. case "o_owner_monitor":
  282. //付费用户
  283. if !powerData.Free.IsFree {
  284. if data == nil || len(*data) == 0 {
  285. a_times = append(a_times, "实时推送")
  286. returnData = &bxsubscribe.PushSet{
  287. ATimes: a_times,
  288. IApppush: 1,
  289. IWxpush: common.Int64All(common.If(ShowWx, 1, 0)),
  290. IMailpush: 0,
  291. IRatemode: 1,
  292. IsWxShow: 1,
  293. }
  294. } else {
  295. returnData = &bxsubscribe.PushSet{
  296. ATimes: a_times,
  297. IApppush: common.Int64All(common.If((*data)["i_apppush"] == nil, 1, (*data)["i_apppush"])),
  298. IWxpush: common.Int64All(common.If((*data)["i_wxpush"] == nil, common.If(ShowWx, 1, 0), common.If(ShowWx, (*data)["i_wxpush"], 0))),
  299. IMailpush: common.Int64All(common.If((*data)["i_mailpush"] == nil, 0, (*data)["i_mailpush"])),
  300. IRatemode: common.Int64All(common.If((*data)["i_ratemode"] == nil, 1, (*data)["i_ratemode"])),
  301. IsWxShow: 1,
  302. }
  303. }
  304. } else {
  305. return false, nil
  306. }
  307. case "o_entinfo":
  308. if powerData.Member.Status > 0 && power[12] {
  309. if data == nil || len(*data) == 0 {
  310. a_times = append(a_times, "实时推送")
  311. returnData = &bxsubscribe.PushSet{
  312. ATimes: a_times,
  313. IApppush: 1,
  314. IWxpush: common.Int64All(common.If(ShowWx, 1, 0)),
  315. IMailpush: 0,
  316. IRatemode: 1,
  317. IsWxShow: 0,
  318. }
  319. } else {
  320. returnData = &bxsubscribe.PushSet{
  321. ATimes: a_times,
  322. IApppush: common.Int64All(common.If((*data)["i_apppush"] == nil, 1, (*data)["i_apppush"])),
  323. IWxpush: common.Int64All(common.If((*data)["i_wxpush"] == nil, common.If(ShowWx, 1, 0), common.If(ShowWx, (*data)["i_wxpush"], 0))),
  324. IMailpush: common.Int64All(common.If((*data)["i_mailpush"] == nil, 0, (*data)["i_mailpush"])),
  325. IRatemode: common.Int64All(common.If((*data)["i_ratemode"] == nil, 1, (*data)["i_ratemode"])),
  326. IsWxShow: 0,
  327. }
  328. }
  329. } else {
  330. return false, nil
  331. }
  332. case "o_week_report", "o_month_report":
  333. if powerData.Vip.Status > 0 || power[10] {
  334. if name == "o_week_report" {
  335. a_times = append(a_times, "每周推送 (周一 08:00)")
  336. } else {
  337. a_times = append(a_times, "每月推送 (1日 08:00)")
  338. }
  339. IsWxShow := int64(0)
  340. if powerData.Vip.Status > 0 {
  341. IsWxShow = int64(1)
  342. }
  343. if !power[10] {
  344. isMailShow = int64(0)
  345. }
  346. if data == nil || len(*data) == 0 {
  347. returnData = &bxsubscribe.PushSet{
  348. ATimes: a_times,
  349. IApppush: 1,
  350. IWxpush: common.Int64All(common.If(ShowWx, 1, 0)),
  351. IMailpush: 0,
  352. IRatemode: 3,
  353. IsWxShow: IsWxShow,
  354. }
  355. } else {
  356. returnData = &bxsubscribe.PushSet{
  357. ATimes: a_times,
  358. IApppush: common.Int64All(common.If((*data)["i_apppush"] == nil, 1, (*data)["i_apppush"])),
  359. IWxpush: common.Int64All(common.If((*data)["i_wxpush"] == nil, common.If(ShowWx, 1, 0), common.If(ShowWx, (*data)["i_wxpush"], 0))),
  360. IMailpush: common.Int64All(common.If((*data)["i_mailpush"] == nil, 0, (*data)["i_mailpush"])),
  361. IRatemode: 3,
  362. IsWxShow: IsWxShow,
  363. }
  364. }
  365. } else {
  366. return false, nil
  367. }
  368. case "o_msg_active", "o_msg_service", "o_msg_jyschool", "o_msg_privateletter", "o_msg_business", "o_msg_pending":
  369. isReturnMailShow = false
  370. var isWXShow int64
  371. isWXShow = 1
  372. if name == "o_msg_active" {
  373. isWXShow = 0
  374. }
  375. iApppush := int64(0)
  376. iWxpush := int64(0)
  377. if registedate > IC.C.Registedate {
  378. iApppush = 1
  379. if ShowWx {
  380. iWxpush = 1
  381. }
  382. }
  383. if data == nil || len(*data) == 0 {
  384. returnData = &bxsubscribe.PushSet{
  385. IApppush: iApppush,
  386. IWxpush: iWxpush,
  387. IsWxShow: isWXShow,
  388. }
  389. } else {
  390. returnData = &bxsubscribe.PushSet{
  391. IApppush: common.Int64All(common.If((*data)["i_apppush"] == nil, iApppush, (*data)["i_apppush"])),
  392. IWxpush: common.Int64All(common.If((*data)["i_wxpush"] == nil, iWxpush, (*data)["i_wxpush"])),
  393. IsWxShow: isWXShow,
  394. }
  395. }
  396. }
  397. if isReturnMailShow {
  398. returnData.IsMailShow = isMailShow
  399. }
  400. return true, returnData
  401. }
  402. func (this *PushSetService) SetUser(mail string) (bool, string) {
  403. var emailPattern = regexp.MustCompile("^([a-zA-Z0-9_\\-\\.]+)@((\\[[0-9]{1,3}\\.[0-9]{1,3}\\.[0-9]{1,3}\\.)|(([a-zA-Z0-9\\-]+\\.)+))([a-zA-Z]{2,4}|[0-9]{1,3})(\\]?)$")
  404. if !emailPattern.MatchString(mail) {
  405. return false, "邮箱格式不正确"
  406. }
  407. set := map[string]interface{}{
  408. "o_pushset.s_email": mail,
  409. }
  410. update := false
  411. if this.PositionType == 0 {
  412. update = IC.Mgo.UpdateById(util.USER, this.UserId, map[string]interface{}{
  413. "$set": set,
  414. })
  415. } else {
  416. update = IC.Mgo.Update(util.ENTUSER, map[string]interface{}{"i_entid": this.EntId, "i_userid": this.EntUserId}, map[string]interface{}{
  417. "$set": set,
  418. }, true, false)
  419. IC.MainMysql.UpdateOrDeleteBySql(`update entniche_user set mail=? where id=? and ent_id=?`, mail, this.EntUserId, this.EntId)
  420. }
  421. return update, ""
  422. }