struct.go 28 KB

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