struct.go 27 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954
  1. package p
  2. import (
  3. "encoding/json"
  4. "sort"
  5. "strings"
  6. util "app.yhyue.com/moapp/jybase/common"
  7. "app.yhyue.com/moapp/jybase/logger"
  8. . "app.yhyue.com/moapp/jybase/mongodb"
  9. . "app.yhyue.com/moapp/jybase/mysql"
  10. "bp.jydev.jianyu360.cn/BaseService/pushpkg/dfa"
  11. )
  12. type MgoConf struct {
  13. Address string
  14. Size int
  15. DbName string
  16. ReplSet string
  17. UserName string
  18. Password string
  19. Collection string
  20. ExperienceDbName string
  21. }
  22. type RedisConf struct {
  23. Address string
  24. }
  25. type MysqlConf struct {
  26. DbName string
  27. Address string
  28. UserName string
  29. PassWord string
  30. MaxOpenConns int
  31. MaxIdleConns int
  32. }
  33. type EsConf struct {
  34. Address string
  35. Size int
  36. Version string
  37. UserName string
  38. Password string
  39. }
  40. type MemberService struct {
  41. IsBuy bool
  42. Services map[int]*memberService
  43. }
  44. type memberService struct {
  45. Id int
  46. StartTime string
  47. }
  48. // 关键词
  49. type KeySet struct {
  50. Item string `json:"item"` //分类名称
  51. Keys []string `json:"key"` //关键词
  52. NotKeys []string `json:"notkey"` //排除词
  53. SubTypes []string `json:"infotype"` //信息类型
  54. Areas []string `json:"area"` //地区
  55. AppendKeys []string `json:"appendkey"` //附加词
  56. MatchWay int `json:"matchway"` //匹配模式 0:精准匹配 1:模糊匹配
  57. }
  58. // 解析订阅词
  59. type SubSet struct {
  60. Matchbuyerclass_other int //是否开启其他按钮
  61. ProjectMatch int //项目关联推送
  62. Items []string //关键词分类
  63. Keys []string //过滤后的关键词
  64. Notkeys []string //排除词
  65. Key_item map[string]string //关键词对应的分类名称
  66. Key_notkey map[string]map[string]bool //关键词所对应的排除词
  67. Key_area map[string]map[string]bool //关键词所对应的信息范围
  68. Key_subtype map[string]map[string]bool //关键词所对应的信息类型
  69. OriginalKeys []string //原始关键词
  70. Areas []string //区域-省份
  71. Area map[string]interface{} //区域-省份
  72. District map[string]interface{} //区域-区县
  73. Subtype []interface{} //信息类型-二级分类
  74. Subtypes []string //信息类型-二级分类
  75. Buyerclass []interface{} //采购单位行业
  76. Buyerclasss []string //采购单位行业
  77. IsUpgrade bool //免费用户是否订阅升级
  78. MaxPushSize int //推送最大条数
  79. MaxMailSize int //邮件最大条数
  80. Switch int //开关
  81. MatchMode []string //匹配方式 title detail filetext projectname/purchasing
  82. StartAmount float64 //开始金额
  83. EndAmount float64 //结束金额
  84. }
  85. // 推送设置
  86. type PushSet struct {
  87. Email string //邮箱
  88. SubSet *PushSetChild //订阅推送设置
  89. WeekReport *PushSetChild //周报推送设置
  90. MonthReport *PushSetChild //月报推送设置
  91. NewprojectForecast *PushSetChild //潜在项目预测推送设置
  92. EntInfo *PushSetChild //企业情报监控-企业工商变动推送设置
  93. FollowProject *PushSetChild //项目进度监控推送设置
  94. FollowEnt *PushSetChild //企业情报监控-企业中标动态推送设置
  95. OwnerMonitor *PushSetChild //业主监控推送设置
  96. }
  97. func (p *PushSet) Reset() {
  98. //
  99. if p.SubSet != nil {
  100. if p.SubSet.RateMode < 1 || p.SubSet.RateMode > 4 {
  101. p.SubSet.RateMode = 2
  102. if len(p.SubSet.Times) == 0 {
  103. p.SubSet.Times = append(p.SubSet.Times, "09:00", "14:00")
  104. }
  105. } else if p.SubSet.RateMode == 2 && len(p.SubSet.Times) == 0 {
  106. p.SubSet.Times = append(p.SubSet.Times, "09:00")
  107. }
  108. sort.Strings(p.SubSet.Times)
  109. }
  110. //
  111. if p.EntInfo != nil {
  112. if p.EntInfo.RateMode < 1 || p.EntInfo.RateMode > 4 {
  113. p.EntInfo.RateMode = 1
  114. if len(p.EntInfo.Times) == 0 {
  115. p.EntInfo.Times = append(p.EntInfo.Times, "09:00", "14:00")
  116. }
  117. } else if p.EntInfo.RateMode == 2 && len(p.EntInfo.Times) == 0 {
  118. p.EntInfo.Times = append(p.EntInfo.Times, "09:00")
  119. }
  120. sort.Strings(p.EntInfo.Times)
  121. }
  122. //
  123. if p.NewprojectForecast != nil {
  124. if p.NewprojectForecast.RateMode < 1 || p.NewprojectForecast.RateMode > 4 {
  125. p.NewprojectForecast.RateMode = 1
  126. if len(p.NewprojectForecast.Times) == 0 {
  127. p.NewprojectForecast.Times = append(p.NewprojectForecast.Times, "09:00", "14:00")
  128. }
  129. } else if p.NewprojectForecast.RateMode == 2 && len(p.NewprojectForecast.Times) == 0 {
  130. p.NewprojectForecast.Times = append(p.NewprojectForecast.Times, "09:00")
  131. }
  132. sort.Strings(p.NewprojectForecast.Times)
  133. }
  134. //
  135. if p.FollowProject != nil {
  136. if p.FollowProject.RateMode < 1 || p.FollowProject.RateMode > 4 {
  137. p.FollowProject.RateMode = 1
  138. if len(p.FollowProject.Times) == 0 {
  139. p.FollowProject.Times = append(p.FollowProject.Times, "09:00", "14:00")
  140. }
  141. } else if p.FollowProject.RateMode == 2 && len(p.FollowProject.Times) == 0 {
  142. p.FollowProject.Times = append(p.FollowProject.Times, "09:00")
  143. }
  144. sort.Strings(p.FollowProject.Times)
  145. }
  146. //
  147. if p.FollowEnt != nil {
  148. if p.FollowEnt.RateMode < 1 || p.FollowEnt.RateMode > 4 {
  149. p.FollowEnt.RateMode = 1
  150. if len(p.FollowEnt.Times) == 0 {
  151. p.FollowEnt.Times = append(p.FollowEnt.Times, "09:00", "14:00")
  152. }
  153. } else if p.FollowEnt.RateMode == 2 && len(p.FollowEnt.Times) == 0 {
  154. p.FollowEnt.Times = append(p.FollowEnt.Times, "09:00")
  155. }
  156. sort.Strings(p.FollowEnt.Times)
  157. }
  158. //
  159. if p.OwnerMonitor != nil {
  160. if p.OwnerMonitor.RateMode < 1 || p.OwnerMonitor.RateMode > 4 {
  161. p.OwnerMonitor.RateMode = 1
  162. if len(p.OwnerMonitor.Times) == 0 {
  163. p.OwnerMonitor.Times = append(p.OwnerMonitor.Times, "09:00", "14:00")
  164. }
  165. } else if p.OwnerMonitor.RateMode == 2 && len(p.OwnerMonitor.Times) == 0 {
  166. p.OwnerMonitor.Times = append(p.OwnerMonitor.Times, "09:00")
  167. }
  168. sort.Strings(p.OwnerMonitor.Times)
  169. }
  170. }
  171. type PushSetChild struct {
  172. RateMode int //推送时间
  173. Times []string //自定义推送时间
  174. WxPush int //是否开启微信推送
  175. AppPush int //是否开启app推送
  176. MailPush int //是否开启邮箱推送
  177. Nomsgtip int //是否开启无消息推送提醒
  178. }
  179. // 用户基本信息
  180. type UserInfo struct {
  181. Id string //mongoid
  182. PositionId int64 //职位id
  183. BaseUserId int64 //mysql用户id
  184. AccountId int64 //账户id
  185. S_m_openid string //公众号openid
  186. A_m_openid string //app微信登录openid
  187. Phone string //app手机号登录
  188. Jpushid string //极光推送id
  189. Opushid string //厂商推送id
  190. AppPhoneType string //手机型号
  191. Subscribe int //是否关注
  192. VipStatus int //超级订阅 1--试用 2--正式
  193. MemberStatus int //大会员
  194. NicheStatus int //商机管理
  195. IsMainAccount bool //是否是主账号
  196. SonAccountStatus int //子账号状态 0-禁用 1-启用
  197. MemberMainid string //主账号id
  198. SubPushInactive int //活跃状态
  199. Entniche *Entniche
  200. WxTplMsg *WxTplMsg
  201. SubSet *SubSet
  202. PushSet *PushSet
  203. Extend *UserInfoExtend
  204. }
  205. /*
  206. *获取用户信息
  207. *temp 用户数据
  208. *tp 1-免费 2-超级订阅 3-大会员
  209. */
  210. func NewUserInfo(temp map[string]interface{}, tp int) *UserInfo {
  211. ui := &UserInfo{
  212. Id: BsonIdToSId(temp["_id"]),
  213. BaseUserId: util.Int64All(temp["base_user_id"]),
  214. S_m_openid: util.ObjToString(temp["s_m_openid"]),
  215. A_m_openid: util.ObjToString(temp["a_m_openid"]),
  216. Phone: GetPhone(temp),
  217. Jpushid: util.ObjToString(temp["s_jpushid"]),
  218. Opushid: util.ObjToString(temp["s_opushid"]),
  219. AppPhoneType: util.ObjToString(temp["s_appponetype"]),
  220. Subscribe: util.IntAllDef(temp["i_ispush"], 1),
  221. VipStatus: util.IntAll(temp["i_vip_status"]),
  222. MemberStatus: util.IntAll(temp["i_member_status"]),
  223. SubPushInactive: util.IntAll(temp["subpush_inactive"]),
  224. }
  225. if ui.MemberStatus > 0 {
  226. ui.IsMainAccount = util.IntAll(temp["i_mainaccount"]) == 1
  227. ui.SonAccountStatus = util.IntAllDef(temp["i_member_sub_status"], -1)
  228. ui.MemberMainid = util.ObjToString(temp["s_member_mainid"])
  229. }
  230. if tp == 3 {
  231. obj, _ := temp["o_member_jy"].(map[string]interface{})
  232. ui.GetSubSet(false, ui.Id, obj)
  233. } else if tp == 2 {
  234. obj, _ := temp["o_vipjy"].(map[string]interface{})
  235. ui.GetSubSet(false, ui.Id, obj)
  236. } else if tp == 1 {
  237. obj, _ := temp["o_jy"].(map[string]interface{})
  238. ui.GetSubSet(true, ui.Id, obj)
  239. } else {
  240. ui.SubSet = &SubSet{}
  241. }
  242. o_pushset, _ := temp["o_pushset"].(map[string]interface{})
  243. ui.GetPushSet(o_pushset)
  244. ui.PushSetFilter()
  245. return ui
  246. }
  247. //
  248. func NewMyUserInfo(Mgo *MongodbSim, msl *Mysql, userId string) *UserInfo {
  249. var user *map[string]interface{}
  250. if IsObjectIdHex(userId) {
  251. user, _ = Mgo.FindById(Mgo_User, userId, UserCollFields)
  252. } else {
  253. user = GetAllByEntPositionId(Mgo, msl, util.IntAll(userId))
  254. }
  255. if user == nil || len(*user) == 0 {
  256. logger.Error(userId, "没有找到该用户信息")
  257. return nil
  258. }
  259. ui := NewUserInfo(*user, 0)
  260. ui.Id = userId
  261. return ui
  262. }
  263. //
  264. func NewMyUserInfoByEntUserId(Mgo *MongodbSim, Mysql *Mysql, userId string) *UserInfo {
  265. var user *map[string]interface{}
  266. if IsObjectIdHex(userId) {
  267. user, _ = Mgo.FindById(Mgo_User, userId, UserCollFields)
  268. } else {
  269. user = GetAllByEntUserId(Mgo, Mysql, util.IntAll(userId))
  270. }
  271. if user == nil || len(*user) == 0 {
  272. logger.Error(userId, "没有找到该用户信息")
  273. return nil
  274. }
  275. ui := NewUserInfo(*user, 0)
  276. ui.Id = userId
  277. return ui
  278. }
  279. // 解析用户的推送设置
  280. func (u *UserInfo) GetPushSet(obj map[string]interface{}) {
  281. subSet, _ := obj["o_subset"].(map[string]interface{})
  282. subSet_times, _ := subSet["a_times"].([]interface{})
  283. weekReport, _ := obj["o_week_report"].(map[string]interface{})
  284. monthReport, _ := obj["o_month_report"].(map[string]interface{})
  285. newprojectForecast, _ := obj["o_newproject_forecast"].(map[string]interface{})
  286. newprojectForecast_times, _ := newprojectForecast["a_times"].([]interface{})
  287. entInfo, _ := obj["o_entinfo"].(map[string]interface{})
  288. entInfo_times, _ := entInfo["a_times"].([]interface{})
  289. followProject, _ := obj["o_follow_project"].(map[string]interface{})
  290. followProject_times, _ := followProject["a_times"].([]interface{})
  291. followEnt, _ := obj["o_follow_ent"].(map[string]interface{})
  292. followEnt_times, _ := followEnt["a_times"].([]interface{})
  293. ownerMonitor, _ := obj["o_owner_monitor"].(map[string]interface{})
  294. ownerMonitor_times, _ := ownerMonitor["a_times"].([]interface{})
  295. u.PushSet = &PushSet{
  296. Email: strings.TrimSpace(util.ObjToString(obj["s_email"])),
  297. SubSet: &PushSetChild{
  298. WxPush: util.IntAllDef(subSet["i_wxpush"], 1),
  299. AppPush: util.IntAllDef(subSet["i_apppush"], 0),
  300. MailPush: util.IntAll(subSet["i_mailpush"]),
  301. RateMode: util.IntAll(subSet["i_ratemode"]),
  302. Times: util.ObjArrToStringArr(subSet_times),
  303. Nomsgtip: util.IntAllDef(subSet["i_nomsgtip"], 1), //默认开启
  304. },
  305. WeekReport: &PushSetChild{
  306. WxPush: util.IntAllDef(weekReport["i_wxpush"], 1),
  307. AppPush: util.IntAllDef(weekReport["i_apppush"], 1),
  308. MailPush: util.IntAll(weekReport["i_mailpush"]),
  309. },
  310. MonthReport: &PushSetChild{
  311. WxPush: util.IntAllDef(monthReport["i_wxpush"], 1),
  312. AppPush: util.IntAllDef(monthReport["i_apppush"], 1),
  313. MailPush: util.IntAll(monthReport["i_mailpush"]),
  314. },
  315. NewprojectForecast: &PushSetChild{
  316. WxPush: util.IntAllDef(newprojectForecast["i_wxpush"], 1),
  317. AppPush: util.IntAllDef(newprojectForecast["i_apppush"], 1),
  318. MailPush: util.IntAll(newprojectForecast["i_mailpush"]),
  319. RateMode: util.IntAll(newprojectForecast["i_ratemode"]),
  320. Times: util.ObjArrToStringArr(newprojectForecast_times),
  321. },
  322. EntInfo: &PushSetChild{
  323. WxPush: util.IntAllDef(entInfo["i_wxpush"], 1),
  324. AppPush: util.IntAllDef(entInfo["i_apppush"], 1),
  325. MailPush: util.IntAll(entInfo["i_mailpush"]),
  326. RateMode: util.IntAll(entInfo["i_ratemode"]),
  327. Times: util.ObjArrToStringArr(entInfo_times),
  328. },
  329. FollowProject: &PushSetChild{
  330. WxPush: util.IntAllDef(followProject["i_wxpush"], 1),
  331. AppPush: util.IntAllDef(followProject["i_apppush"], 1),
  332. MailPush: util.IntAll(followProject["i_mailpush"]),
  333. RateMode: util.IntAll(followProject["i_ratemode"]),
  334. Times: util.ObjArrToStringArr(followProject_times),
  335. },
  336. FollowEnt: &PushSetChild{
  337. WxPush: util.IntAllDef(followEnt["i_wxpush"], 1),
  338. AppPush: util.IntAllDef(followEnt["i_apppush"], 1),
  339. MailPush: util.IntAll(followEnt["i_mailpush"]),
  340. RateMode: util.IntAll(followEnt["i_ratemode"]),
  341. Times: util.ObjArrToStringArr(followEnt_times),
  342. },
  343. OwnerMonitor: &PushSetChild{
  344. WxPush: util.IntAllDef(ownerMonitor["i_wxpush"], 1),
  345. AppPush: util.IntAllDef(ownerMonitor["i_apppush"], 1),
  346. MailPush: util.IntAll(ownerMonitor["i_mailpush"]),
  347. RateMode: util.IntAll(ownerMonitor["i_ratemode"]),
  348. Times: util.ObjArrToStringArr(ownerMonitor_times),
  349. },
  350. }
  351. u.PushSet.Reset()
  352. }
  353. // 解析用户的推送设置
  354. func (u *UserInfo) PushSetFilter() {
  355. if u.Subscribe == 0 || u.S_m_openid == "" {
  356. if u.PushSet.SubSet != nil {
  357. u.PushSet.SubSet.WxPush = -1
  358. }
  359. if u.PushSet.WeekReport != nil {
  360. u.PushSet.WeekReport.WxPush = -1
  361. }
  362. if u.PushSet.MonthReport != nil {
  363. u.PushSet.MonthReport.WxPush = -1
  364. }
  365. if u.PushSet.NewprojectForecast != nil {
  366. u.PushSet.NewprojectForecast.WxPush = -1
  367. }
  368. if u.PushSet.EntInfo != nil {
  369. u.PushSet.EntInfo.WxPush = -1
  370. }
  371. if u.PushSet.FollowProject != nil {
  372. u.PushSet.FollowProject.WxPush = -1
  373. }
  374. if u.PushSet.FollowEnt != nil {
  375. u.PushSet.FollowEnt.WxPush = -1
  376. }
  377. }
  378. if u.Jpushid == "" && u.Opushid == "" {
  379. if u.PushSet.SubSet != nil {
  380. u.PushSet.SubSet.AppPush = -1
  381. }
  382. if u.PushSet.WeekReport != nil {
  383. u.PushSet.WeekReport.AppPush = -1
  384. }
  385. if u.PushSet.MonthReport != nil {
  386. u.PushSet.MonthReport.AppPush = -1
  387. }
  388. if u.PushSet.NewprojectForecast != nil {
  389. u.PushSet.NewprojectForecast.AppPush = -1
  390. }
  391. if u.PushSet.EntInfo != nil {
  392. u.PushSet.EntInfo.AppPush = -1
  393. }
  394. if u.PushSet.FollowProject != nil {
  395. u.PushSet.FollowProject.AppPush = -1
  396. }
  397. if u.PushSet.FollowEnt != nil {
  398. u.PushSet.FollowEnt.AppPush = -1
  399. }
  400. }
  401. mailPush := true
  402. if (u.S_m_openid == "" || (u.S_m_openid != "" && u.Subscribe == 0)) && u.Phone == "" && u.A_m_openid == "" {
  403. mailPush = false
  404. } else if (u.S_m_openid == "" || (u.S_m_openid != "" && u.Subscribe == 0)) && u.Phone == "" && u.A_m_openid != "" && u.Jpushid == "" && u.Opushid == "" {
  405. mailPush = false
  406. } else if !MailReg.MatchString(u.PushSet.Email) {
  407. mailPush = false
  408. }
  409. if !mailPush {
  410. if u.PushSet.SubSet != nil {
  411. u.PushSet.SubSet.MailPush = -1
  412. }
  413. if u.PushSet.WeekReport != nil {
  414. u.PushSet.WeekReport.MailPush = -1
  415. }
  416. if u.PushSet.MonthReport != nil {
  417. u.PushSet.MonthReport.MailPush = -1
  418. }
  419. if u.PushSet.NewprojectForecast != nil {
  420. u.PushSet.NewprojectForecast.MailPush = -1
  421. }
  422. if u.PushSet.EntInfo != nil {
  423. u.PushSet.EntInfo.MailPush = -1
  424. }
  425. if u.PushSet.FollowProject != nil {
  426. u.PushSet.FollowProject.MailPush = -1
  427. }
  428. if u.PushSet.FollowEnt != nil {
  429. u.PushSet.FollowEnt.MailPush = -1
  430. }
  431. }
  432. }
  433. // 解析用户的订阅设置
  434. func (u *UserInfo) GetSubSet(isFreeUser bool, userId string, obj map[string]interface{}) {
  435. subSet := &SubSet{
  436. Keys: []string{},
  437. Notkeys: []string{},
  438. Key_item: map[string]string{},
  439. Key_notkey: map[string]map[string]bool{},
  440. Key_area: map[string]map[string]bool{},
  441. Key_subtype: map[string]map[string]bool{},
  442. OriginalKeys: []string{},
  443. Areas: []string{},
  444. Subtypes: []string{},
  445. Buyerclasss: []string{},
  446. Matchbuyerclass_other: util.IntAllDef(obj["i_matchbuyerclass_other"], 1),
  447. ProjectMatch: util.IntAll(obj["i_projectmatch"]),
  448. MaxPushSize: util.IntAll(obj["i_maxpushsize"]),
  449. MaxMailSize: util.IntAll(obj["i_maxmailsize"]),
  450. Switch: util.IntAllDef(obj["i_switch"], 1),
  451. MatchMode: []string{},
  452. }
  453. matchMode, _ := obj["i_matchmode"].([]interface{})
  454. for _, v := range matchMode {
  455. vs, _ := v.(string)
  456. subSet.MatchMode = append(subSet.MatchMode, vs)
  457. }
  458. if len(subSet.MatchMode) == 0 {
  459. subSet.MatchMode = append(subSet.MatchMode, "title")
  460. }
  461. if amount := strings.Split(util.ObjToString(obj["amount"]), "-"); len(amount) == 2 {
  462. subSet.StartAmount = util.Float64All(amount[0]) * 10000
  463. subSet.EndAmount = util.Float64All(amount[1]) * 10000
  464. }
  465. var keySets []*KeySet
  466. if isFreeUser {
  467. var err error
  468. keySets, err = u.GetKeySets(obj["a_key"])
  469. if err != nil {
  470. logger.Error("获取用户关键词错误!", userId, obj["a_key"], err)
  471. return
  472. }
  473. area := obj["o_area"]
  474. if ppStatus := util.IntAll(obj["i_ppstatus"]); ppStatus == 1 {
  475. area = obj["o_area_p"]
  476. }
  477. if newFree := util.IntAll(obj["i_newfree"]); newFree == 1 && area != nil {
  478. subSet.IsUpgrade = true
  479. subSet.Subtype, _ = obj["a_infotype"].([]interface{})
  480. subSet.Area, _ = area.(map[string]interface{})
  481. }
  482. } else {
  483. items, _ := obj["a_items"].([]interface{})
  484. for _, v := range items {
  485. item, _ := v.(map[string]interface{})
  486. itemName := strings.TrimSpace(util.ObjToString(item["s_item"]))
  487. subSet.Items = append(subSet.Items, itemName)
  488. kss, err := u.GetKeySets(item["a_key"])
  489. if err != nil {
  490. logger.Error("获取用户关键词错误!", userId, item["a_key"], err)
  491. continue
  492. }
  493. for _, vv := range kss {
  494. if vv == nil {
  495. continue
  496. }
  497. if vv.MatchWay == 1 {
  498. for _, vvv := range vv.Keys {
  499. keySets = append(keySets, &KeySet{
  500. Item: itemName,
  501. Keys: []string{vvv},
  502. NotKeys: vv.NotKeys,
  503. })
  504. }
  505. for _, vvv := range vv.AppendKeys {
  506. keySets = append(keySets, &KeySet{
  507. Item: itemName,
  508. Keys: []string{vvv},
  509. NotKeys: vv.NotKeys,
  510. })
  511. }
  512. } else {
  513. vv.Item = itemName
  514. keySets = append(keySets, vv)
  515. }
  516. }
  517. }
  518. subSet.Buyerclass, _ = obj["a_buyerclass"].([]interface{})
  519. subSet.Subtype, _ = obj["a_infotype"].([]interface{})
  520. subSet.Area, _ = obj["o_area"].(map[string]interface{})
  521. subSet.District, _ = obj["o_district"].(map[string]interface{})
  522. }
  523. for _, v := range subSet.Buyerclass {
  524. s_v, _ := v.(string)
  525. if s_v == "" {
  526. continue
  527. }
  528. subSet.Buyerclasss = append(subSet.Buyerclasss, s_v)
  529. }
  530. for _, v := range subSet.Subtype {
  531. s_v, _ := v.(string)
  532. if s_v == "" {
  533. continue
  534. }
  535. subSet.Subtypes = append(subSet.Subtypes, s_v)
  536. }
  537. for area, _ := range subSet.Area {
  538. if area == "" {
  539. continue
  540. }
  541. subSet.Areas = append(subSet.Areas, area)
  542. }
  543. ////////////////
  544. for _, vs := range keySets {
  545. if vs == nil {
  546. logger.Error(userId, "关键词设置异常")
  547. continue
  548. }
  549. var vs_keys []string
  550. for _, vs_v := range [][]string{vs.Keys, vs.AppendKeys} {
  551. for _, vs_vv := range vs_v {
  552. vs_vv = strings.TrimSpace(vs_vv)
  553. if vs_vv == "" {
  554. continue
  555. }
  556. vs_keys = append(vs_keys, vs_vv)
  557. }
  558. }
  559. if len(vs_keys) == 0 {
  560. continue
  561. }
  562. key := strings.Join(vs_keys, "+")
  563. subSet.OriginalKeys = append(subSet.OriginalKeys, key)
  564. if KeyFilterReg.MatchString(key) {
  565. continue
  566. } else if !KeyRetainReg.MatchString(key) {
  567. continue
  568. }
  569. subSet.Keys = append(subSet.Keys, key)
  570. subSet.Notkeys = append(subSet.Notkeys, vs.NotKeys...)
  571. //转大写
  572. upperKey := strings.ToUpper(key)
  573. subSet.Key_item[upperKey] = vs.Item
  574. //建立与排除词的对应关系
  575. for _, notkey := range vs.NotKeys {
  576. upperNotkey := strings.ToUpper(notkey)
  577. if subSet.Key_notkey[upperKey] == nil {
  578. subSet.Key_notkey[upperKey] = map[string]bool{}
  579. }
  580. subSet.Key_notkey[upperKey][upperNotkey] = true
  581. }
  582. //免费用户需要进行映射
  583. if isFreeUser {
  584. //建立与信息范围的对应关系
  585. for _, area := range vs.Areas {
  586. if subSet.Key_area[upperKey] == nil {
  587. subSet.Key_area[upperKey] = map[string]bool{}
  588. }
  589. subSet.Key_area[upperKey][area] = true
  590. }
  591. //建立与信息类型的对应关系
  592. for _, subtype := range vs.SubTypes {
  593. if subSet.Key_subtype[upperKey] == nil {
  594. subSet.Key_subtype[upperKey] = map[string]bool{}
  595. }
  596. subSet.Key_subtype[upperKey][subtype] = true
  597. }
  598. }
  599. }
  600. u.SubSet = subSet
  601. }
  602. // 得到用户的关键词
  603. func (u *UserInfo) GetKeySets(a_key interface{}) ([]*KeySet, error) {
  604. var keySets []*KeySet
  605. if a_key == nil {
  606. return keySets, nil
  607. }
  608. _bs, err := json.Marshal(a_key)
  609. if err == nil {
  610. err = json.Unmarshal(_bs, &keySets)
  611. }
  612. if err != nil {
  613. return keySets, err
  614. }
  615. for _, v := range keySets {
  616. if v == nil {
  617. continue
  618. }
  619. keys, appendKeys, notKeys := []string{}, []string{}, []string{}
  620. for _, vv := range v.Keys {
  621. keys = append(keys, SpaceReg.Split(strings.TrimSpace(vv), -1)...)
  622. }
  623. for _, vv := range v.AppendKeys {
  624. appendKeys = append(appendKeys, SpaceReg.Split(strings.TrimSpace(vv), -1)...)
  625. }
  626. for _, vv := range v.NotKeys {
  627. notKeys = append(notKeys, SpaceReg.Split(strings.TrimSpace(vv), -1)...)
  628. }
  629. v.Keys = keys
  630. v.AppendKeys = appendKeys
  631. v.NotKeys = notKeys
  632. }
  633. return keySets, err
  634. }
  635. type Entniche struct {
  636. AccountId int64 //企业账户id
  637. EntId int //企业id
  638. EntName string //企业名称
  639. DeptId int //部门id
  640. DisId string //分发id
  641. UserId int
  642. Unique string
  643. OnlyPush int
  644. IsNew int
  645. PowerSource int //权益来源
  646. ProductType string //产品类型
  647. Mail string //邮箱
  648. IsDis int //是否是分发
  649. DisMember int //分发-超级订阅
  650. DisVip int //分发-大会员
  651. }
  652. // 用户基本信息-扩展
  653. type UserInfoExtend struct {
  654. Object map[string]interface{}
  655. CreateTime int64 //
  656. Size int
  657. }
  658. func (u *UserInfo) Add(k string, m *map[string]map[*UserInfo]bool) {
  659. mk := (*m)[k]
  660. if mk == nil {
  661. mk = map[*UserInfo]bool{}
  662. }
  663. mk[u] = true
  664. (*m)[k] = mk
  665. }
  666. // 添加信息类型映射关系
  667. func (u *UserInfo) AddSubtype(m *map[string]map[*UserInfo]bool) {
  668. if len(u.SubSet.Subtypes) == 0 {
  669. u.Add("", m)
  670. } else {
  671. for _, v := range u.SubSet.Subtypes {
  672. u.Add(v, m)
  673. }
  674. }
  675. }
  676. // 添加采购单位类型映射关系
  677. func (u *UserInfo) AddBuyerclass(m *map[string]map[*UserInfo]bool) {
  678. //如果有关键词 有采购单位行业,行业加上“其它”
  679. if len(u.SubSet.Buyerclasss) == 0 {
  680. u.Add("", m)
  681. } else {
  682. if u.SubSet.Matchbuyerclass_other == 1 && len(u.SubSet.Keys) > 0 {
  683. u.Add("其它", m)
  684. }
  685. for _, v := range u.SubSet.Buyerclasss {
  686. u.Add(v, m)
  687. }
  688. }
  689. }
  690. // 添加区域映射关系
  691. func (u *UserInfo) AddArea(m *map[string]map[*UserInfo]bool) {
  692. if len(u.SubSet.Areas) == 0 {
  693. u.Add("", m)
  694. } else {
  695. for _, v := range u.SubSet.Areas {
  696. u.Add(v, m)
  697. }
  698. }
  699. }
  700. //添加省市映射关系
  701. func (u *UserInfo) AddAreaCity(area, city *map[string]map[*UserInfo]bool) {
  702. if len(u.SubSet.Area) == 0 {
  703. u.Add("", area)
  704. } else {
  705. for k, v := range u.SubSet.Area {
  706. if k == "" {
  707. continue
  708. }
  709. vs, _ := v.([]interface{})
  710. if len(vs) == 0 {
  711. u.Add(k, area)
  712. } else {
  713. for _, vv := range vs {
  714. s_vv, _ := vv.(string)
  715. if s_vv == "" {
  716. continue
  717. }
  718. u.Add(s_vv, city)
  719. }
  720. }
  721. }
  722. }
  723. }
  724. //添加省市县映射关系
  725. func (u *UserInfo) AddAreaCityDistrict(area, city *map[string]map[*UserInfo]bool, district *map[string]map[string]map[*UserInfo]bool) {
  726. if len(u.SubSet.Area) == 0 {
  727. u.Add("", area)
  728. } else {
  729. for k, v := range u.SubSet.Area {
  730. if k == "" {
  731. continue
  732. }
  733. vs, _ := v.([]interface{})
  734. if len(vs) == 0 {
  735. u.Add(k, area)
  736. } else {
  737. for _, vv := range vs {
  738. s_vv, _ := vv.(string)
  739. if s_vv == "" {
  740. continue
  741. }
  742. d_vv, _ := u.SubSet.District[s_vv].([]interface{})
  743. if len(d_vv) == 0 {
  744. u.Add(s_vv, city)
  745. } else {
  746. for _, vvv := range d_vv {
  747. s_vvv, _ := vvv.(string)
  748. if s_vvv == "" {
  749. continue
  750. }
  751. d_mm := (*district)[s_vv]
  752. if d_mm == nil {
  753. d_mm = map[string]map[*UserInfo]bool{}
  754. }
  755. u.Add(s_vvv, &d_mm)
  756. (*district)[s_vv] = d_mm
  757. }
  758. }
  759. }
  760. }
  761. }
  762. }
  763. }
  764. //
  765. func (u *UserInfo) MakeKeyUserByMatchMode(title_pjob, detail_pjob, filetext_pjob, pnp_pjob *KeyDfa) {
  766. for _, v := range u.SubSet.MatchMode {
  767. if v == "title" {
  768. u.MakeKeyUser(u.SubSet.Keys, title_pjob.Key_user)
  769. u.MakeKeyUser(u.SubSet.Notkeys, title_pjob.Notkey_user)
  770. } else if v == "detail" {
  771. u.MakeKeyUser(u.SubSet.Keys, detail_pjob.Key_user)
  772. u.MakeKeyUser(u.SubSet.Notkeys, detail_pjob.Notkey_user)
  773. } else if v == "filetext" {
  774. u.MakeKeyUser(u.SubSet.Keys, filetext_pjob.Key_user)
  775. u.MakeKeyUser(u.SubSet.Notkeys, filetext_pjob.Notkey_user)
  776. } else if v == "projectname/purchasing" {
  777. u.MakeKeyUser(u.SubSet.Keys, pnp_pjob.Key_user)
  778. u.MakeKeyUser(u.SubSet.Notkeys, pnp_pjob.Notkey_user)
  779. }
  780. }
  781. }
  782. // 把用户挂在词下面
  783. func (u *UserInfo) MakeKeyUser(keys []string, key_user *map[string]*[]*UserInfo) {
  784. mp := map[string]bool{}
  785. for _, key := range keys {
  786. v := strings.ToUpper(key)
  787. if v == "" || mp[v] {
  788. continue
  789. }
  790. mp[v] = true
  791. arr := (*key_user)[v]
  792. if arr == nil {
  793. arr = &[]*UserInfo{}
  794. }
  795. *arr = append(*arr, u)
  796. (*key_user)[v] = arr
  797. }
  798. }
  799. type WxTplMsg struct {
  800. Key string
  801. Area string
  802. }
  803. type SortList []*MatchInfo
  804. func (s SortList) Len() int {
  805. return len(s)
  806. }
  807. func (s SortList) Less(i, j int) bool {
  808. return util.Int64All(s[i].Info["publishtime"]) > util.Int64All(s[j].Info["publishtime"])
  809. }
  810. func (s SortList) Swap(i, j int) {
  811. s[i], s[j] = s[j], s[i]
  812. }
  813. type CSortList []map[string]interface{}
  814. func (s CSortList) Len() int {
  815. return len(s)
  816. }
  817. func (s CSortList) Less(i, j int) bool {
  818. return util.Int64All(s[i]["publishtime"]) > util.Int64All(s[j]["publishtime"])
  819. }
  820. func (s CSortList) Swap(i, j int) {
  821. s[i], s[j] = s[j], s[i]
  822. }
  823. type MatchInfo struct {
  824. Info map[string]interface{}
  825. Keys []string
  826. Items []string
  827. MatchWays []string
  828. DisId string
  829. HandDis bool //是否分发
  830. }
  831. type KeyDfa struct {
  832. Key *dfa.DFA
  833. NotKey *dfa.DFA
  834. Key_user *map[string]*[]*UserInfo
  835. Notkey_user *map[string]*[]*UserInfo
  836. }
  837. // 所有用户的关键词和排除词
  838. func (p *KeyDfa) CreateDaf() {
  839. //关键词
  840. p.Key = &dfa.DFA{}
  841. keys := make([]string, 0)
  842. for k, _ := range *p.Key_user {
  843. keys = append(keys, k)
  844. }
  845. p.Key.AddWord(keys...)
  846. //排除关键词
  847. p.NotKey = &dfa.DFA{}
  848. notKeys := make([]string, 0)
  849. for k, _ := range *p.Notkey_user {
  850. notKeys = append(notKeys, k)
  851. }
  852. p.NotKey.AddWord(notKeys...)
  853. }
  854. type MatchUser struct {
  855. Keys []string
  856. Items []string
  857. Item map[string]bool
  858. MatchWays []string
  859. MatchWay map[string]bool
  860. }
  861. type RelationProjectUser struct {
  862. TopTypes []string
  863. }
  864. type PushInfo struct {
  865. Ids []interface{}
  866. Info map[string]interface{}
  867. }
  868. // 推送返回结果
  869. type PushResult struct {
  870. WxStatus int
  871. AppStatus int
  872. MailStatus int
  873. PushDate int64
  874. Infos *SortList
  875. }
  876. type PushParam struct {
  877. JpushTitle string
  878. LastInfoDate int64
  879. TitleArray []string
  880. Infos *SortList
  881. InfosLength int
  882. MailHtml string
  883. PushDate int64
  884. PushCount int
  885. IsPush bool
  886. }
  887. type BiddingInfo struct {
  888. Id string
  889. Title string
  890. ClearTitle string
  891. HighlightTitle string
  892. AreaTitle string
  893. Area string
  894. Publishtime int64
  895. PublishtimeDiff string
  896. PublishtimeYMD string
  897. Buyerclass string
  898. Subscopeclass string
  899. Bidamount interface{}
  900. Budget interface{}
  901. Acount string
  902. Subtype string
  903. Toptype string
  904. Infotype string
  905. }