english_company.go 8.2 KB

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