english_company.go 7.7 KB

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