english_company.go 6.6 KB

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