struct.go 29 KB

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