english_report_email.go 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295
  1. package models
  2. import (
  3. "eta_gn/eta_api/utils"
  4. "github.com/beego/beego/v2/client/orm"
  5. "github.com/rdlucklib/rdluck_tools/paging"
  6. "time"
  7. )
  8. // EnglishReportEmail 英文研报-邮箱/客户联系人
  9. type EnglishReportEmail struct {
  10. Id int `orm:"column(id);pk" description:"邮箱ID"`
  11. CompanyId int `description:"客户ID"`
  12. Name string `description:"联系人名称"`
  13. Email string `description:"邮箱地址"`
  14. Mobile string `description:"手机号"`
  15. CountryCode string `description:"区号,86、852、886等"`
  16. BusinessCardUrl string `description:"名片"`
  17. ViewTotal int `description:"累计点击量/阅读量"`
  18. LastViewTime time.Time `description:"最后阅读时间"`
  19. IsDeleted int `description:"删除状态:0-正常;1-已删除"`
  20. Enabled int `description:"邮箱状态:1:有效,0:禁用"`
  21. AdminId int `description:"创建人ID"`
  22. AdminName string `description:"创建人姓名"`
  23. Status int `description:"1:正式,2:临时,3:终止"`
  24. CompanyName string `description:"公司名称"`
  25. CreateTime time.Time `description:"创建时间"`
  26. ModifyTime time.Time `description:"更新时间"`
  27. RegisterTime time.Time `description:"注册时间"`
  28. }
  29. func (item *EnglishReportEmail) TableName() string {
  30. return "english_report_email"
  31. }
  32. // EnglishReportEmailSaveReq 保存邮箱请求体
  33. type EnglishReportEmailSaveReq struct {
  34. Id int `description:"邮箱ID, 大于0为编辑"`
  35. CompanyId int `description:"客户ID"`
  36. Name string `description:"客户名称"`
  37. Email string `description:"邮箱地址"`
  38. Mobile string `description:"手机号"`
  39. CountryCode string `description:"区号,86、852、886等"`
  40. BusinessCardUrl string `description:"名片"`
  41. Enabled int `description:"邮箱状态:1:有效,0:禁用"`
  42. }
  43. func (item *EnglishReportEmail) Create() (err error) {
  44. o := orm.NewOrmUsingDB("rddp")
  45. id, err := o.Insert(item)
  46. if err != nil {
  47. return
  48. }
  49. item.Id = int(id)
  50. return
  51. }
  52. func (item *EnglishReportEmail) Update(cols []string) (err error) {
  53. o := orm.NewOrmUsingDB("rddp")
  54. _, err = o.Update(item, cols...)
  55. return
  56. }
  57. // GetEnglishReportEmailById 主键获取邮箱
  58. func GetEnglishReportEmailById(id int) (item *EnglishReportEmail, err error) {
  59. o := orm.NewOrmUsingDB("rddp")
  60. sql := `SELECT * FROM english_report_email WHERE is_deleted = 0 AND id = ? LIMIT 1`
  61. err = o.Raw(sql, id).QueryRow(&item)
  62. return
  63. }
  64. // EnglishReportEmailPageListResp 分页列表响应体
  65. type EnglishReportEmailPageListResp struct {
  66. List []*EnglishReportEmailResp
  67. Paging *paging.PagingItem `description:"分页数据"`
  68. }
  69. // EnglishReportEmailResp 邮箱响应体
  70. type EnglishReportEmailResp struct {
  71. Id int `description:"邮箱ID"`
  72. CompanyId int `description:"客户ID"`
  73. Name string `description:"客户名称"`
  74. Email string `description:"邮箱地址"`
  75. Mobile string `description:"手机号"`
  76. CountryCode string `description:"区号,86、852、886等"`
  77. BusinessCardUrl string `description:"名片"`
  78. AdminName string `description:"创建人姓名"`
  79. CreateTime string `description:"创建时间"`
  80. ViewTotal int `description:"累计点击量"`
  81. Enabled int `description:"邮箱状态:1:有效,0:禁用"`
  82. CompanyName string `description:"公司名称"`
  83. RegisterCompanyName string `description:"注册公司名称"`
  84. Status int `description:"1:正式,2:临时,3:终止"`
  85. LastViewTime time.Time `description:"最后阅读时间"`
  86. IsDeleted int `description:"删除状态:0-正常;1-已删除"`
  87. AdminId int `description:"创建人ID"`
  88. ModifyTime string `description:"更新时间"`
  89. RegisterTime string `description:"注册时间"`
  90. }
  91. // EnglishReportEmailRespItem 邮箱响应体
  92. type EnglishReportEmailRespItem struct {
  93. Id int `description:"邮箱ID"`
  94. Name string `description:"客户名称"`
  95. Email string `description:"邮箱地址"`
  96. Mobile string `description:"手机号"`
  97. CountryCode string `description:"区号,86、852、886等"`
  98. BusinessCardUrl string `description:"名片"`
  99. AdminName string `description:"创建人姓名"`
  100. CreateTime time.Time `description:"创建时间"`
  101. ViewTotal int `description:"累计点击量"`
  102. Enabled int `description:"邮箱状态:1:有效,0:禁用"`
  103. CompanyName string `description:"公司名称"`
  104. RegisterCompanyName string `description:"注册公司名称"`
  105. RegisterTime time.Time `description:"注册时间"`
  106. }
  107. // GetEnglishReportEmailPageList 获取邮箱列表-分页
  108. func GetEnglishReportEmailPageList(condition string, pars []interface{}, order string, startSize, pageSize int) (total int, list []*EnglishReportEmailRespItem, err error) {
  109. o := orm.NewOrmUsingDB("rddp")
  110. sql := `SELECT a.id,a.name,a.email,a.mobile,a.country_code,a.business_card_url,a.view_total,a.company_id,
  111. a.last_view_time,a.admin_id,a.admin_name,a.create_time,a.modify_time,a.enabled,a.status,a.is_deleted,a.register_time,
  112. b.company_name AS company_name,a.company_name AS register_company_name FROM english_report_email AS a LEFT JOIN
  113. english_company AS b ON a.company_id = b.company_id
  114. WHERE a.is_deleted = 0 `
  115. sql += condition
  116. if order != "" {
  117. sql += order
  118. } else {
  119. sql += ` ORDER BY a.create_time DESC`
  120. }
  121. totalSQl := `SELECT COUNT(1) total FROM (` + sql + `) z`
  122. if err = o.Raw(totalSQl, pars).QueryRow(&total); err != nil {
  123. return
  124. }
  125. sql += ` LIMIT ?,?`
  126. _, err = o.Raw(sql, pars, startSize, pageSize).QueryRows(&list)
  127. return
  128. }
  129. // GetEnglishReportEmailList 获取邮箱列表
  130. func GetEnglishReportEmailList(condition string, pars []interface{}, order string) (list []*EnglishReportEmail, err error) {
  131. o := orm.NewOrmUsingDB("rddp")
  132. sql := `SELECT * FROM english_report_email WHERE is_deleted = 0`
  133. sql += condition
  134. if order != "" {
  135. sql += order
  136. } else {
  137. sql += ` ORDER BY create_time DESC`
  138. }
  139. _, err = o.Raw(sql, pars).QueryRows(&list)
  140. return
  141. }
  142. // GetEnglishReportEmailByEmail 地址获取邮箱
  143. func GetEnglishReportEmailByEmail(email string) (item *EnglishReportEmailResp, err error) {
  144. o := orm.NewOrmUsingDB("rddp")
  145. sql := `SELECT a.id,a.name,a.email,a.mobile,a.country_code,a.business_card_url,a.view_total,
  146. a.last_view_time,a.admin_id,a.admin_name,a.create_time,a.modify_time,a.enabled,a.status,
  147. b.company_name AS company_name,a.company_name AS register_company_name FROM english_report_email AS a LEFT JOIN
  148. english_company AS b ON a.company_id = b.company_id WHERE a.is_deleted = 0 AND a.email = ? LIMIT 1`
  149. err = o.Raw(sql, email).QueryRow(&item)
  150. return
  151. }
  152. // EnglishReportEmailDelReq 删除邮箱请求体
  153. type EnglishReportEmailDelReq struct {
  154. EmailId int `description:"邮箱ID"`
  155. }
  156. // EnglishReportEmailDelReq 删除邮箱请求体
  157. type EnglishReportEditEnabledReq struct {
  158. EmailId int `description:"邮箱ID"`
  159. Enabled int `description:"1:有效,0:禁用"`
  160. }
  161. // DelEnglishReportEmail 删除邮箱
  162. func DelEnglishReportEmail(id int) (err error) {
  163. o := orm.NewOrmUsingDB("rddp")
  164. sql := `DELETE FROM english_report_email WHERE id = ? LIMIT 1`
  165. _, err = o.Raw(sql, id).Exec()
  166. return
  167. }
  168. // EnglishReportEmailSendReq 群发邮件请求体
  169. type EnglishReportEmailSendReq struct {
  170. ReportId int `description:"报告ID"`
  171. EmailIds string `description:"邮箱IDs"`
  172. Theme string `description:"邮件主题"`
  173. EnPermissions []int `description:"品种权限IDs"`
  174. NoCompanyIds []int `description:"禁止接收邮件的英文客户IDs"`
  175. }
  176. // EnglishReportEmailConf 英文研报邮件配置
  177. type EnglishReportEmailConf struct {
  178. FromAlias string `description:"发信人昵称" json:"from_alias"`
  179. SendAuthGroup string `description:"群发邮件权限组, 英文逗号分隔" json:"send_auth_group"`
  180. }
  181. // GetEnglishCompanyViewPageList 获取联系人点击量列表-分页
  182. func GetEnglishCompanyViewPageList(condition string, pars []interface{}, order string, startSize, pageSize int) (total int, list []*EnglishReportEmail, err error) {
  183. o := orm.NewOrmUsingDB("rddp")
  184. sql := `SELECT * FROM english_report_email WHERE view_total > 0 `
  185. sql += condition
  186. if order != "" {
  187. sql += order
  188. } else {
  189. sql += ` ORDER BY create_time DESC`
  190. }
  191. totalSQl := `SELECT COUNT(1) total FROM (` + sql + `) z`
  192. if err = o.Raw(totalSQl, pars).QueryRow(&total); err != nil {
  193. return
  194. }
  195. sql += ` LIMIT ?,?`
  196. _, err = o.Raw(sql, pars, startSize, pageSize).QueryRows(&list)
  197. return
  198. }
  199. // MultiCreateEnglishEmail 批量新增英文邮箱/联系人
  200. func MultiCreateEnglishEmail(items []*EnglishReportEmail, logs []*EnglishReportEmailOpLog) (err error) {
  201. o := orm.NewOrmUsingDB("rddp")
  202. tx, err := o.Begin()
  203. if err != nil {
  204. return
  205. }
  206. defer func() {
  207. if err != nil {
  208. _ = tx.Rollback()
  209. } else {
  210. _ = tx.Commit()
  211. }
  212. }()
  213. // 新增联系人
  214. _, err = tx.InsertMulti(len(items), items)
  215. if err != nil {
  216. return
  217. }
  218. // 新增日志
  219. _, err = tx.InsertMulti(len(logs), logs)
  220. return
  221. }
  222. // EnglishReportEmailResendReq 邮件重发请求体
  223. type EnglishReportEmailResendReq struct {
  224. ReportId int `description:"报告ID"`
  225. SendId int `description:"发送ID, 0表示批量发送全部失败邮件"`
  226. }
  227. // UpdateEnglishEmailEnabledByCompanyId 更新客户下所有联系人状态
  228. func UpdateEnglishEmailEnabledByCompanyId(companyId, enabled int) (err error) {
  229. o := orm.NewOrmUsingDB("rddp")
  230. sql := `UPDATE english_report_email SET enabled = ? WHERE company_id = ?`
  231. _, err = o.Raw(sql, enabled, companyId).Exec()
  232. return
  233. }
  234. // EnglishReportMoveReq 移动至当前客户请求体
  235. type EnglishReportMoveReq struct {
  236. EmailId int `description:"邮箱ID"`
  237. CompanyId int `description:"公司id"`
  238. }
  239. // GetEnglishReportEmailListWithCompany 获取邮箱列表
  240. func GetEnglishReportEmailListWithCompany(condition string, pars []interface{}, order string) (list []*EnglishReportEmailRespItem, err error) {
  241. o := orm.NewOrmUsingDB("rddp")
  242. sql := `SELECT a.id,a.name,a.email,a.mobile,a.country_code,a.business_card_url,a.view_total,
  243. a.last_view_time,a.admin_id,a.admin_name,a.create_time,a.modify_time,a.enabled,a.status,
  244. b.company_name AS company_name,a.company_name AS register_company_name FROM english_report_email AS a LEFT JOIN
  245. english_company AS b ON a.company_id = b.company_id WHERE is_deleted = 0 `
  246. sql += condition
  247. if order != "" {
  248. sql += order
  249. } else {
  250. sql += ` ORDER BY create_time DESC`
  251. }
  252. _, err = o.Raw(sql, pars).QueryRows(&list)
  253. return
  254. }
  255. // GetEnCompanyIdsByKeyword 关键词获取英文客户IDs
  256. func GetEnCompanyIdsByKeyword(keyword string) (companyIds []int, err error) {
  257. o := orm.NewOrmUsingDB("rddp")
  258. sql := `SELECT DISTINCT
  259. a.company_id
  260. FROM
  261. english_report_email AS a
  262. JOIN english_company AS b ON a.company_id = b.company_id AND b.is_deleted = 0
  263. WHERE
  264. a.is_deleted = 0 AND a.status = 1 AND (a.email LIKE ? OR a.mobile LIKE ? OR b.company_name LIKE ?)`
  265. _, err = o.Raw(sql, utils.GetLikeKeyword(keyword), utils.GetLikeKeyword(keyword), utils.GetLikeKeyword(keyword)).QueryRows(&companyIds)
  266. return
  267. }