english_company.go 7.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237
  1. package models
  2. import (
  3. "github.com/beego/beego/v2/client/orm"
  4. "github.com/rdlucklib/rdluck_tools/paging"
  5. "time"
  6. )
  7. const (
  8. EnglishCompanyDisabled = iota
  9. EnglishCompanyEnabled
  10. EnglishCompanyHalfEnabled
  11. )
  12. // EnglishCompany 英文客户
  13. type EnglishCompany struct {
  14. CompanyId int `orm:"column(company_id);pk" description:"英文客户ID"`
  15. CompanyName string `description:"客户名称"`
  16. CountryCode string `description:"国家Code"`
  17. Country string `description:"国家"`
  18. SellerId int `description:"销售ID"`
  19. SellerName string `description:"销售姓名"`
  20. ViewTotal int `description:"累计点击量/阅读量"`
  21. IsDeleted int `description:"删除状态:0-正常;1-已删除"`
  22. CreateTime time.Time `description:"创建时间"`
  23. ModifyTime time.Time `description:"更新时间"`
  24. Enabled int `description:"0-禁用; 1-启用; 2-部分禁用"`
  25. Status int `description:"1:正式,2:临时,3:终止"`
  26. Nation string `description:"所属国家"`
  27. IsHide int `description:"是否隐藏:0:不隐藏,1:隐藏"`
  28. OverseasStatus string `description:"海外客户状态:'正式','试用','关闭'"`
  29. OverseasLabel int `description:"海外客户试用子标签:1未分类、2 推进、3 跟踪、4 预备、"`
  30. ResetBtn int `description:"转正式和重置按钮:同步过来默认为0:显示转正式为1:显示重置为2"`
  31. }
  32. type EnglishCompanyListItem struct {
  33. EnglishCompany
  34. TodoStatusStr string
  35. TodoEndTime time.Time
  36. TodoSellerId int
  37. }
  38. func (item *EnglishCompany) TableName() string {
  39. return "english_company"
  40. }
  41. func (item *EnglishCompany) Create() (err error) {
  42. o := orm.NewOrmUsingDB("rddp")
  43. id, err := o.Insert(item)
  44. if err != nil {
  45. return
  46. }
  47. item.CompanyId = int(id)
  48. return
  49. }
  50. // EnglishCompanySaveReq 英文客户-保存请求体
  51. type EnglishCompanySaveReq struct {
  52. CompanyId int `description:"客户ID"`
  53. CompanyName string `description:"客户名称"`
  54. CountryCode string `description:"国家代码"`
  55. Country string `description:"国家"`
  56. SellerId int `description:"销售ID"`
  57. Nation string `description:"所属国家"`
  58. EnPermissions []int `description:"英文权限IDs"`
  59. }
  60. func (item *EnglishCompany) Update(cols []string) (err error) {
  61. o := orm.NewOrmUsingDB("rddp")
  62. _, err = o.Update(item, cols...)
  63. return
  64. }
  65. // GetEnglishCompanyById 主键获取客户
  66. func GetEnglishCompanyById(id int) (item *EnglishCompany, err error) {
  67. o := orm.NewOrmUsingDB("rddp")
  68. sql := `SELECT * FROM english_company WHERE is_deleted = 0 AND company_id = ? LIMIT 1`
  69. err = o.Raw(sql, id).QueryRow(&item)
  70. return
  71. }
  72. // GetEnglishCompanyByName 名称获取客户
  73. func GetEnglishCompanyByName(companyName string) (item *EnglishCompany, err error) {
  74. o := orm.NewOrmUsingDB("rddp")
  75. sql := `SELECT * FROM english_company WHERE is_deleted = 0 AND company_name = ? LIMIT 1`
  76. err = o.Raw(sql, companyName).QueryRow(&item)
  77. return
  78. }
  79. // EnglishCompanyDelReq 英文客户-删除请求体
  80. type EnglishCompanyDelReq struct {
  81. CompanyId int `description:"客户ID"`
  82. }
  83. // DeleteEnglishCompanyAndEmails 删除英文客户及联系人
  84. func DeleteEnglishCompanyAndEmails(companyId int) (err error) {
  85. o := orm.NewOrmUsingDB("rddp")
  86. tx, err := o.Begin()
  87. if err != nil {
  88. return
  89. }
  90. defer func() {
  91. if err != nil {
  92. _ = tx.Rollback()
  93. } else {
  94. _ = tx.Commit()
  95. }
  96. }()
  97. // 删除客户
  98. sql := `UPDATE english_company SET is_deleted = 1,modify_time = NOW() WHERE company_id = ? LIMIT 1`
  99. _, err = tx.Raw(sql, companyId).Exec()
  100. if err != nil {
  101. return
  102. }
  103. // 删除联系人
  104. sql = `UPDATE english_report_email SET is_deleted = 1,modify_time = NOW() WHERE company_id = ?`
  105. _, err = tx.Raw(sql, companyId).Exec()
  106. return
  107. }
  108. // EnglishCompanyPageListResp 英文客户-分页列表响应体
  109. type EnglishCompanyPageListResp struct {
  110. List []*EnglishCompanyResp
  111. Paging *paging.PagingItem `description:"分页数据"`
  112. }
  113. // EnglishCompanyResp 英文客户-列表响应体
  114. type EnglishCompanyResp struct {
  115. CompanyId int `description:"客户ID"`
  116. CompanyName string `description:"客户名称"`
  117. CountryCode string `description:"国家代码"`
  118. Country string `description:"国家"`
  119. SellerId int `description:"销售ID"`
  120. SellerName string `description:"销售姓名"`
  121. ViewTotal int `description:"累计点击量"`
  122. CreateTime string `description:"创建时间"`
  123. Enabled int `description:"0-禁用; 1-启用; 2-部分禁用"`
  124. TodoInfo *EnglishCompanyListTodo `description:"TODO任务信息"`
  125. EnPermissions []int `description:"英文权限"`
  126. }
  127. // EnglishCompanyListTodo 英文客户列表-TODO任务信息
  128. type EnglishCompanyListTodo struct {
  129. Deadline string `description:"未完成的todo任务的截止日期,截止目前还剩余的天数"`
  130. TodoEndTimeStr string `description:"未完成的todo任务的截止日期拼接格式"`
  131. //TodoEndTime time.Time `description:"未完成的todo任务的截止日期"`
  132. TodoStatus bool `description:"是否存在进行中任务"`
  133. CanConfirm bool `description:"是否允许完成任务"`
  134. HiddenConfirm bool `description:"是否隐藏完成任务按钮"`
  135. HiddenCreate bool `description:"是否隐藏新增/编辑按钮"`
  136. TodoButtonColor string `description:"任务按钮颜色: red; green; gray"`
  137. }
  138. // GetEnglishCompanyPageList 获取客户列表-分页
  139. func GetEnglishCompanyPageList(condition string, pars []interface{}, order string, startSize, pageSize int) (total int, list []*EnglishCompanyListItem, err error) {
  140. o := orm.NewOrmUsingDB("rddp")
  141. sql := `SELECT
  142. c.*,
  143. IF
  144. ( ct.status IS NULL, "无任务", ct.status ) AS todo_status_str,
  145. ct.seller_id as todo_seller_id,
  146. IF
  147. ( ct.end_time IS NULL or ct.status !="进行中", "9999-01-01", ct.end_time) AS todo_end_time
  148. FROM
  149. english_company AS c
  150. LEFT JOIN (
  151. SELECT
  152. b.*
  153. FROM
  154. (
  155. SELECT
  156. company_id,
  157. MAX( create_time ) AS ct
  158. FROM
  159. english_company_todo
  160. WHERE
  161. is_delete = 0
  162. AND STATUS != "已作废"
  163. GROUP BY
  164. company_id
  165. ) AS a
  166. LEFT JOIN english_company_todo AS b ON b.company_id = a.company_id
  167. AND b.create_time = a.ct
  168. ) AS ct ON c.company_id = ct.company_id
  169. WHERE
  170. c.is_deleted = 0 AND c.status = 1`
  171. sql += condition
  172. if order != "" {
  173. sql += order
  174. } else {
  175. sql += ` ORDER BY c.create_time DESC, c.company_id DESC`
  176. }
  177. totalSQl := `SELECT COUNT(1) total FROM (` + sql + `) z`
  178. if err = o.Raw(totalSQl, pars).QueryRow(&total); err != nil {
  179. return
  180. }
  181. sql += ` LIMIT ?,?`
  182. _, err = o.Raw(sql, pars, startSize, pageSize).QueryRows(&list)
  183. return
  184. }
  185. // GetEnglishCompanyViewPageListResp 英文客户-点击量分页列表响应体
  186. type GetEnglishCompanyViewPageListResp struct {
  187. List []*EnglishCompanyViewResp
  188. Paging *paging.PagingItem `description:"分页数据"`
  189. }
  190. // EnglishCompanyViewResp 英文客户-点击量响应体
  191. type EnglishCompanyViewResp struct {
  192. EmailId int `description:"联系人ID"`
  193. UserName string `description:"联系人姓名"`
  194. Email string `description:"邮箱地址"`
  195. ViewTotal int `description:"累计点击量"`
  196. LastViewTime string `description:"创建时间"`
  197. }
  198. // GetEnglishCompanyList 获取英文客户列表
  199. func GetEnglishCompanyList(condition string, pars []interface{}, order string) (list []*EnglishCompany, err error) {
  200. o := orm.NewOrmUsingDB("rddp")
  201. sql := `SELECT * FROM english_company WHERE is_deleted = 0 `
  202. sql += condition
  203. if order != "" {
  204. sql += order
  205. } else {
  206. sql += ` ORDER BY create_time DESC`
  207. }
  208. _, err = o.Raw(sql, pars).QueryRows(&list)
  209. return
  210. }
  211. // EnglishCompanyEditEnabledReq 禁启用请求体
  212. type EnglishCompanyEditEnabledReq struct {
  213. CompanyId int `description:"公司ID"`
  214. Enabled int `description:"1:有效,0:禁用"`
  215. }