users.go 2.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576
  1. package models
  2. import (
  3. "rdluck_tools/orm"
  4. )
  5. type HongzeUsers struct {
  6. RealName string
  7. CompanyName string
  8. Mobile string
  9. IsRegister string
  10. UserType string
  11. }
  12. func GetHongzeUsers() (items []*HongzeUsers, err error) {
  13. sql := `select wu.real_name,c.company_name,left(wu.mobile, 11) as mobile ,if(wu.open_id='','否','是') as is_register,if(c.type in (1),'是','否') as user_type
  14. from wx_user wu
  15. inner join company c on c.company_id = wu.company_id
  16. where c.company_id <> 1 and c.company_id <> 16
  17. and c.type in (1)
  18. order by company_name desc `
  19. _, err = orm.NewOrm().Raw(sql).QueryRows(&items)
  20. return
  21. }
  22. type WxUser struct {
  23. UserId int64
  24. Mobile string
  25. Email string
  26. CompanyId int
  27. ExpiredIn int64
  28. OpenId string
  29. }
  30. func GetWxUserByUserId(userId int) (item *WxUser, err error) {
  31. sql := `SELECT * FROM wx_user WHERE user_id=? `
  32. err = orm.NewOrm().Raw(sql, userId).QueryRow(&item)
  33. return
  34. }
  35. func GetWxUserByMobile(mobile string) (item *WxUser, err error) {
  36. sql := `SELECT * FROM wx_user WHERE mobile=? `
  37. err = orm.NewOrm().Raw(sql, mobile).QueryRow(&item)
  38. return
  39. }
  40. func AddWxUser(companyId int, mobile, realName, email string) (err error) {
  41. sql := `INSERT INTO wx_user(company_id,real_name,mobile,first_login,enabled,is_note,from_type,apply_method,email) VALUES (?,?,?,1,1,1,'report',0,?);`
  42. orm.NewOrm().Raw(sql, companyId, realName, mobile, email).Exec()
  43. return
  44. }
  45. func GetPotentialUser() (items []*WxUser, err error) {
  46. sql := ` SELECT * FROM wx_user WHERE company_id=1 AND report_last_view_time <> '' `
  47. o := orm.NewOrm()
  48. _, err = o.Raw(sql).QueryRows(&items)
  49. return
  50. }
  51. func GetMaxReviewTime(uid int) (max_time string, err error) {
  52. o := orm.NewOrm()
  53. sql := `SELECT MAX(a.max_time) AS max_time FROM (
  54. SELECT MAX(created_time)AS max_time FROM user_view_history AS a WHERE user_id=?
  55. UNION
  56. SELECT MAX(create_time)AS max_time FROM hongze_rddp.report_view_record AS a WHERE user_id=?
  57. )AS a`
  58. err = o.Raw(sql, uid, uid).QueryRow(&max_time)
  59. return
  60. }
  61. func ModifyUserLastViewTime(uid int, lastViewTime string) (err error) {
  62. o := orm.NewOrm()
  63. sql := `UPDATE wx_user SET report_last_view_time=? WHERE user_id=? `
  64. _, err = o.Raw(sql, lastViewTime, uid).Exec()
  65. return
  66. }