custom.go 9.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361
  1. package overseas_custom
  2. import (
  3. "encoding/json"
  4. "fmt"
  5. "github.com/rdlucklib/rdluck_tools/paging"
  6. "hongze/hz_crm_api/models"
  7. "hongze/hz_crm_api/models/company"
  8. "hongze/hz_crm_api/models/overseas_custom"
  9. "hongze/hz_crm_api/utils"
  10. "time"
  11. )
  12. // @Title 获取海外客户列表数据
  13. // @Description 获取海外客户列表数据
  14. // @Param PageSize query int true "每页数据条数"
  15. // @Param CurrentIndex query int true "当前页页码,从1开始"
  16. // @Param Keywords query string false "关键词:客户名称/社会信用码/联系人手机号/邮箱"
  17. // @Param CompanyStatus query string false "状态:全部,正式,试用,关闭"
  18. // @Param SellerId query int false "销售ID"
  19. // @Param CustomType query int false "1:海外客户,2:隐藏客户"
  20. // @Param SortField query string false "排序字段:ViewTotal,RoadShowTotal,CreateTime"
  21. // @Param SortDesc query int false "1:降序,默认,2:升序"
  22. // @Param OverseasLabel query int false "海外客户试用子标签:1未分类、2 推进、3 跟踪、4 预备、"
  23. // @Success 200 {object} models.EnglishCompanyPageListResp
  24. // @router /custom/list [get]
  25. func (this *OverseasCustomController) CustomList() {
  26. br := new(models.BaseResponse).Init()
  27. br.IsSendEmail = false
  28. defer func() {
  29. this.Data["json"] = br
  30. this.ServeJSON()
  31. }()
  32. sysUser := this.SysUser
  33. if sysUser == nil {
  34. br.Msg = "请登录"
  35. br.ErrMsg = "请登录,SysUser Is Empty"
  36. br.Ret = 408
  37. return
  38. }
  39. pageSize, _ := this.GetInt("PageSize")
  40. currentIndex, _ := this.GetInt("CurrentIndex")
  41. keywords := this.GetString("Keywords", "")
  42. sellerId, _ := this.GetInt("SellerId", 0)
  43. companyStatus := this.GetString("CompanyStatus")
  44. sortField := this.GetString("SortField")
  45. sortDesc, _ := this.GetInt("SortDesc")
  46. overseasLabel, _ := this.GetInt("OverseasLabel", 0)
  47. var startSize int
  48. if pageSize <= 0 {
  49. pageSize = utils.PageSize20
  50. }
  51. if currentIndex <= 0 {
  52. currentIndex = 1
  53. }
  54. startSize = paging.StartIndex(currentIndex, pageSize)
  55. obj := new(overseas_custom.Custom)
  56. var condition string
  57. var pars []interface{}
  58. if keywords != "" {
  59. k := "%" + keywords + "%"
  60. enCompanyIds, e := models.GetEnCompanyIdsByKeyword(k)
  61. if e != nil {
  62. br.Msg = "获取失败"
  63. br.ErrMsg = "关键词获取英文客户IDs失败, Err: " + e.Error()
  64. return
  65. }
  66. //获取中文客户
  67. companyIds, err := obj.GetCompanyIdsByKeyword(k)
  68. if err != nil {
  69. br.Msg = "获取失败"
  70. br.ErrMsg = "关键词获取客户IDs失败, Err: " + err.Error()
  71. return
  72. }
  73. companyIds = append(companyIds, enCompanyIds...)
  74. condition += fmt.Sprintf(` AND m.company_id IN (%s) `, utils.GetOrmInReplace(len(companyIds)))
  75. pars = append(pars, companyIds)
  76. }
  77. if sellerId > 0 {
  78. condition = ` AND m.seller_id=? `
  79. pars = append(pars, sellerId)
  80. }
  81. if overseasLabel > 0 {
  82. condition = ` AND m.overseas_label=? `
  83. pars = append(pars, overseasLabel)
  84. }
  85. total, err := obj.GetCustomListCount(condition, pars, companyStatus)
  86. if err != nil {
  87. br.Msg = "获取失败"
  88. br.ErrMsg = "获取数据总数失败, Err: " + err.Error()
  89. return
  90. }
  91. list, err := obj.GetCustomList(condition, pars, companyStatus, sortField, startSize, pageSize, sortDesc)
  92. if err != nil {
  93. br.Msg = "获取失败"
  94. br.ErrMsg = "获取数据失败, Err: " + err.Error()
  95. return
  96. }
  97. for _, v := range list {
  98. if v.Source == 1 && v.OverseasStatus != "" {
  99. v.CompanyStatus = v.OverseasStatus
  100. }
  101. }
  102. statisticsDataList, err := obj.GetCustomTotal(condition, pars)
  103. if err != nil {
  104. br.Msg = "获取失败"
  105. br.ErrMsg = "获取各状态总数失败, Err: " + err.Error()
  106. return
  107. }
  108. overseasLabelDataList, err := obj.GetCustomOverseasLabelTotal(condition, pars)
  109. if err != nil {
  110. br.Msg = "获取失败"
  111. br.ErrMsg = "获取各状态总数失败, Err: " + err.Error()
  112. return
  113. }
  114. page := paging.GetPaging(currentIndex, pageSize, total)
  115. resp := new(overseas_custom.CustomListResp)
  116. resp.Paging = page
  117. resp.List = list
  118. resp.StatisticsData = statisticsDataList
  119. resp.OverseasLabelData = overseasLabelDataList
  120. br.Ret = 200
  121. br.Success = true
  122. br.Msg = "获取成功"
  123. br.Data = resp
  124. }
  125. // @Title 客户隐藏
  126. // @Description 客户隐藏
  127. // @Param request body overseas_custom.CustomHideReq true "type json string"
  128. // @Success 200 string "操作成功"
  129. // @router /custom/hide [post]
  130. func (this *OverseasCustomController) CustomHide() {
  131. br := new(models.BaseResponse).Init()
  132. br.IsSendEmail = false
  133. defer func() {
  134. this.Data["json"] = br
  135. this.ServeJSON()
  136. }()
  137. sysUser := this.SysUser
  138. if sysUser == nil {
  139. br.Msg = "请登录"
  140. br.ErrMsg = "请登录,SysUser Is Empty"
  141. br.Ret = 408
  142. return
  143. }
  144. var req overseas_custom.CustomHideReq
  145. if err := json.Unmarshal(this.Ctx.Input.RequestBody, &req); err != nil {
  146. br.Msg = "参数解析异常!"
  147. br.ErrMsg = "参数解析失败,Err:" + err.Error()
  148. return
  149. }
  150. if req.CompanyId <= 0 {
  151. br.Msg = "参数错误!"
  152. return
  153. }
  154. obj := new(overseas_custom.Custom)
  155. item, err := obj.GetCustomByCompanyId(req.CompanyId)
  156. if err != nil {
  157. br.Msg = "隐藏失败!"
  158. br.ErrMsg = "隐藏失败,Err:" + err.Error()
  159. return
  160. }
  161. //是否隐藏:0:不隐藏,1:隐藏
  162. var isHide int
  163. if item.IsHide == 1 {
  164. isHide = 0
  165. } else {
  166. isHide = 1
  167. }
  168. if req.CompanyId > 1000000 {
  169. enCompanyObj := new(models.EnglishCompany)
  170. // 更新客户
  171. nowTime := time.Now().Local()
  172. enCompanyObj.CompanyId = req.CompanyId - utils.EnCompanyIdStep
  173. enCompanyObj.IsHide = isHide
  174. enCompanyObj.ModifyTime = nowTime
  175. updateCols := []string{"IsHide", "ModifyTime"}
  176. if err = enCompanyObj.Update(updateCols); err != nil {
  177. br.Msg = "隐藏失败"
  178. br.ErrMsg = "更新英文客户隐藏状态失败, Err:" + err.Error()
  179. return
  180. }
  181. } else {
  182. companyObj := new(company.Company)
  183. companyObj.CompanyId = req.CompanyId
  184. companyObj.IsHide = isHide
  185. updateCols := []string{"IsHide"}
  186. err = companyObj.Update(updateCols)
  187. if err != nil {
  188. br.Msg = "隐藏失败"
  189. br.ErrMsg = "更新客户隐藏状态失败, Err:" + err.Error()
  190. return
  191. }
  192. }
  193. br.Ret = 200
  194. br.Success = true
  195. br.Msg = "隐藏成功"
  196. }
  197. // @Title 客户状态设置
  198. // @Description 客户状态设置
  199. // @Param request body overseas_custom.CustomHideReq true "type json string"
  200. // @Success 200 string "操作成功"
  201. // @router /custom/status_set [post]
  202. func (this *OverseasCustomController) CustomStatusSet() {
  203. br := new(models.BaseResponse).Init()
  204. br.IsSendEmail = false
  205. defer func() {
  206. this.Data["json"] = br
  207. this.ServeJSON()
  208. }()
  209. sysUser := this.SysUser
  210. if sysUser == nil {
  211. br.Msg = "请登录"
  212. br.ErrMsg = "请登录,SysUser Is Empty"
  213. br.Ret = 408
  214. return
  215. }
  216. var req overseas_custom.CustomHideReq
  217. if err := json.Unmarshal(this.Ctx.Input.RequestBody, &req); err != nil {
  218. br.Msg = "参数解析异常!"
  219. br.ErrMsg = "参数解析失败,Err:" + err.Error()
  220. return
  221. }
  222. if req.CompanyId <= 0 {
  223. br.Msg = "参数错误!"
  224. return
  225. }
  226. obj := new(overseas_custom.Custom)
  227. item, err := obj.GetCustomByCompanyId(req.CompanyId)
  228. if err != nil {
  229. br.Msg = "隐藏失败!"
  230. br.ErrMsg = "隐藏失败,Err:" + err.Error()
  231. return
  232. }
  233. //是否隐藏:0:不隐藏,1:隐藏
  234. var overseasStatus string
  235. if item.OverseasStatus == "" {
  236. overseasStatus = "正式"
  237. } else {
  238. overseasStatus = ""
  239. }
  240. if req.CompanyId > 1000000 {
  241. enCompanyObj := new(models.EnglishCompany)
  242. // 更新客户
  243. nowTime := time.Now().Local()
  244. enCompanyObj.CompanyId = req.CompanyId - utils.EnCompanyIdStep
  245. enCompanyObj.OverseasStatus = overseasStatus
  246. enCompanyObj.ModifyTime = nowTime
  247. updateCols := []string{"OverseasStatus", "ModifyTime"}
  248. if err = enCompanyObj.Update(updateCols); err != nil {
  249. br.Msg = "隐藏失败"
  250. br.ErrMsg = "更新英文客户转正式状态失败, Err:" + err.Error()
  251. return
  252. }
  253. } else {
  254. companyObj := new(company.Company)
  255. companyObj.CompanyId = req.CompanyId
  256. companyObj.OverseasStatus = overseasStatus
  257. updateCols := []string{"OverseasStatus"}
  258. err = companyObj.Update(updateCols)
  259. if err != nil {
  260. br.Msg = "隐藏失败"
  261. br.ErrMsg = "更新客户转正式状态失败, Err:" + err.Error()
  262. return
  263. }
  264. }
  265. br.Ret = 200
  266. br.Success = true
  267. br.Msg = "操作成功"
  268. }
  269. // @Title 客户子标签设置
  270. // @Description 客户子标签设置
  271. // @Param request body overseas_custom.CustomOverseasLabelSetReq true "type json string"
  272. // @Success 200 string "操作成功"
  273. // @router /custom/overseas_label_set [post]
  274. func (this *OverseasCustomController) CustomOverseasLabelSet() {
  275. br := new(models.BaseResponse).Init()
  276. br.IsSendEmail = false
  277. defer func() {
  278. this.Data["json"] = br
  279. this.ServeJSON()
  280. }()
  281. //海外客户试用子标签:1未分类、2 推进、3 跟踪、4 预备、
  282. sysUser := this.SysUser
  283. if sysUser == nil {
  284. br.Msg = "请登录"
  285. br.ErrMsg = "请登录,SysUser Is Empty"
  286. br.Ret = 408
  287. return
  288. }
  289. var req overseas_custom.CustomOverseasLabelSetReq
  290. if err := json.Unmarshal(this.Ctx.Input.RequestBody, &req); err != nil {
  291. br.Msg = "参数解析异常!"
  292. br.ErrMsg = "参数解析失败,Err:" + err.Error()
  293. return
  294. }
  295. if req.CompanyId <= 0 {
  296. br.Msg = "参数错误!"
  297. return
  298. }
  299. if req.CompanyId > 1000000 {
  300. enCompanyObj := new(models.EnglishCompany)
  301. // 更新客户
  302. nowTime := time.Now().Local()
  303. enCompanyObj.CompanyId = req.CompanyId - utils.EnCompanyIdStep
  304. enCompanyObj.OverseasLabel = req.OverseasLabel
  305. enCompanyObj.ModifyTime = nowTime
  306. updateCols := []string{"OverseasLabel", "ModifyTime"}
  307. if err := enCompanyObj.Update(updateCols); err != nil {
  308. br.Msg = "设置失败"
  309. br.ErrMsg = "设置英文客户标签状态失败, Err:" + err.Error()
  310. return
  311. }
  312. } else {
  313. companyObj := new(company.Company)
  314. companyObj.CompanyId = req.CompanyId
  315. companyObj.OverseasLabel = req.OverseasLabel
  316. updateCols := []string{"OverseasLabel"}
  317. err := companyObj.Update(updateCols)
  318. if err != nil {
  319. br.Msg = "设置失败"
  320. br.ErrMsg = "设置客户标签状态失败, Err:" + err.Error()
  321. return
  322. }
  323. }
  324. br.Ret = 200
  325. br.Success = true
  326. br.Msg = "设置成功"
  327. }