english_company.go 7.4 KB

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