english_company.go 6.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206
  1. package english_report
  2. import (
  3. "eta/eta_mobile/controllers"
  4. "eta/eta_mobile/models"
  5. "eta/eta_mobile/services"
  6. "eta/eta_mobile/utils"
  7. "fmt"
  8. "github.com/rdlucklib/rdluck_tools/paging"
  9. "strconv"
  10. "strings"
  11. )
  12. // EnglishCompanyController 英文客户
  13. type EnglishCompanyController struct {
  14. controllers.BaseAuthController
  15. }
  16. // List
  17. // @Title 英文客户列表
  18. // @Description 英文客户列表
  19. // @Param Keywords query string false "关键词:客户名称/联系人邮箱/联系人手机号"
  20. // @Param SortType query int false "点击量排序:1-降序; 2-升序"
  21. // @Param EnPermissionIds query string false "品种权限IDs(字符串)"
  22. // @Success 200 {object} models.EnglishCompanyPageListResp
  23. // @router /company/list [get]
  24. func (this *EnglishCompanyController) List() {
  25. br := new(models.BaseResponse).Init()
  26. br.IsSendEmail = false
  27. defer func() {
  28. this.Data["json"] = br
  29. this.ServeJSON()
  30. }()
  31. sysUser := this.SysUser
  32. if sysUser == nil {
  33. br.Msg = "请登录"
  34. br.ErrMsg = "请登录,SysUser Is Empty"
  35. br.Ret = 408
  36. return
  37. }
  38. var startSize int
  39. pageSize, _ := this.GetInt("PageSize")
  40. currentIndex, _ := this.GetInt("CurrentIndex")
  41. if pageSize <= 0 {
  42. pageSize = utils.PageSize20
  43. }
  44. if currentIndex <= 0 {
  45. currentIndex = 1
  46. }
  47. startSize = paging.StartIndex(currentIndex, pageSize)
  48. keywords := this.GetString("Keywords", "")
  49. sortType, _ := this.GetInt("SortType", 0)
  50. sortParam := this.GetString("SortParam", "")
  51. strPermissionIds := this.GetString("EnPermissionIds", "")
  52. var cond, order string
  53. var pars []interface{}
  54. if keywords != "" {
  55. k := "%" + keywords + "%"
  56. companyIds, e := models.GetEnCompanyIdsByKeyword(k)
  57. if e != nil {
  58. br.Msg = "获取失败"
  59. br.ErrMsg = "关键词获取英文客户IDs失败, Err: " + e.Error()
  60. return
  61. }
  62. if len(companyIds) == 0 {
  63. page := paging.GetPaging(currentIndex, pageSize, 0)
  64. resp := &models.EnglishCompanyPageListResp{
  65. Paging: page,
  66. List: make([]*models.EnglishCompanyResp, 0),
  67. }
  68. br.Ret = 200
  69. br.Success = true
  70. br.Msg = "获取成功"
  71. br.Data = resp
  72. return
  73. }
  74. cond += fmt.Sprintf(` AND c.company_id IN (%s) `, utils.GetOrmInReplace(len(companyIds)))
  75. pars = append(pars, companyIds)
  76. }
  77. // 品种权限
  78. if strPermissionIds != "" {
  79. permissionIdArr := strings.Split(strPermissionIds, ",")
  80. permissionIds := make([]int, 0)
  81. for _, s := range permissionIdArr {
  82. p, e := strconv.Atoi(s)
  83. if e != nil {
  84. br.Msg = "品种权限有误"
  85. br.ErrMsg = "品种权限筛选有误"
  86. return
  87. }
  88. permissionIds = append(permissionIds, p)
  89. }
  90. if len(permissionIds) == 0 {
  91. br.Msg = "品种权限有误"
  92. br.ErrMsg = "品种权限筛选ID为空"
  93. return
  94. }
  95. queryCond := fmt.Sprintf(` AND %s IN (%s)`, models.EnCompanyPermissionColumns.EnPermissionId, utils.GetOrmInReplace(len(permissionIds)))
  96. queryPars := make([]interface{}, 0)
  97. queryPars = append(queryPars, permissionIds)
  98. queryOB := new(models.EnCompanyPermission)
  99. queryList, e := queryOB.GetItemsByCondition(queryCond, queryPars, []string{"DISTINCT en_company_id"}, "")
  100. if e != nil {
  101. br.Msg = "品种筛选有误"
  102. br.ErrMsg = "品种筛选失败, Err: " + e.Error()
  103. return
  104. }
  105. companyIds := make([]int, 0)
  106. for _, q := range queryList {
  107. companyIds = append(companyIds, q.EnCompanyId)
  108. }
  109. if len(companyIds) == 0 {
  110. page := paging.GetPaging(currentIndex, pageSize, 0)
  111. resp := &models.EnglishCompanyPageListResp{
  112. Paging: page,
  113. List: make([]*models.EnglishCompanyResp, 0),
  114. }
  115. br.Ret = 200
  116. br.Success = true
  117. br.Msg = "获取成功"
  118. br.Data = resp
  119. return
  120. }
  121. cond += fmt.Sprintf(` AND c.company_id IN (%s) `, utils.GetOrmInReplace(len(companyIds)))
  122. pars = append(pars, companyIds)
  123. }
  124. if sortParam == "" {
  125. if sortType == 1 {
  126. order = ` ORDER BY c.view_total DESC`
  127. }
  128. if sortType == 2 {
  129. order = ` ORDER BY c.view_total ASC`
  130. }
  131. } else if sortParam == "deadLine" {
  132. order = ` ORDER BY todo_end_time asc, c.view_total desc, c.company_id desc`
  133. } else if sortParam == "todoStatusStr" {
  134. order = ` ORDER BY FIELD (todo_status_str,'进行中','已完成','无任务'), c.view_total desc, c.company_id desc`
  135. }
  136. total, list, e := models.GetEnglishCompanyPageList(cond, pars, order, startSize, pageSize)
  137. if e != nil {
  138. br.Msg = "获取失败"
  139. br.ErrMsg = "获取英文客户列表失败, Err: " + e.Error()
  140. return
  141. }
  142. // 客户列表TODO信息
  143. todoMap := services.GetEnglishCompanyListTodoMap(list, sysUser)
  144. // 品种权限
  145. permissionMap := make(map[int][]int)
  146. {
  147. companyIds := make([]int, 0)
  148. for _, v := range list {
  149. companyIds = append(companyIds, v.CompanyId)
  150. }
  151. if len(companyIds) > 0 {
  152. cond := fmt.Sprintf(` AND %s IN (%s)`, models.EnCompanyPermissionColumns.EnCompanyId, utils.GetOrmInReplace(len(companyIds)))
  153. pars := make([]interface{}, 0)
  154. pars = append(pars, companyIds)
  155. ob := new(models.EnCompanyPermission)
  156. items, e := ob.GetItemsByCondition(cond, pars, []string{}, "")
  157. if e != nil {
  158. br.Msg = "获取失败"
  159. br.ErrMsg = "获取客户权限列表失败, Err: " + e.Error()
  160. return
  161. }
  162. for _, v := range items {
  163. if permissionMap[v.EnCompanyId] == nil {
  164. permissionMap[v.EnCompanyId] = make([]int, 0)
  165. }
  166. permissionMap[v.EnCompanyId] = append(permissionMap[v.EnCompanyId], v.EnPermissionId)
  167. }
  168. }
  169. }
  170. respList := make([]*models.EnglishCompanyResp, 0)
  171. for i := range list {
  172. respList = append(respList, &models.EnglishCompanyResp{
  173. CompanyId: list[i].CompanyId,
  174. CompanyName: list[i].CompanyName,
  175. CountryCode: list[i].CountryCode,
  176. Country: list[i].Country,
  177. SellerId: list[i].SellerId,
  178. SellerName: list[i].SellerName,
  179. ViewTotal: list[i].ViewTotal,
  180. CreateTime: list[i].CreateTime.Format(utils.FormatDateTime),
  181. Enabled: list[i].Enabled,
  182. TodoInfo: todoMap[list[i].CompanyId],
  183. EnPermissions: permissionMap[list[i].CompanyId],
  184. })
  185. }
  186. page := paging.GetPaging(currentIndex, pageSize, total)
  187. resp := &models.EnglishCompanyPageListResp{
  188. Paging: page,
  189. List: respList,
  190. }
  191. br.Ret = 200
  192. br.Success = true
  193. br.Msg = "获取成功"
  194. br.Data = resp
  195. }