english_company.go 7.3 KB

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