english_company.go 7.4 KB

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