custom.go 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422
  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. customType, _ := this.GetInt("CustomType", 0)
  48. var startSize int
  49. if pageSize <= 0 {
  50. pageSize = utils.PageSize20
  51. }
  52. if currentIndex <= 0 {
  53. currentIndex = 1
  54. }
  55. startSize = paging.StartIndex(currentIndex, pageSize)
  56. obj := new(overseas_custom.Custom)
  57. var condition string
  58. var pars []interface{}
  59. if keywords != "" {
  60. k := "%" + keywords + "%"
  61. enCompanyIds, e := models.GetEnCompanyIdsByKeyword(k)
  62. if e != nil {
  63. br.Msg = "获取失败"
  64. br.ErrMsg = "关键词获取英文客户IDs失败, Err: " + e.Error()
  65. return
  66. }
  67. //获取中文客户
  68. companyIds, err := obj.GetCompanyIdsByKeyword(k)
  69. if err != nil {
  70. br.Msg = "获取失败"
  71. br.ErrMsg = "关键词获取客户IDs失败, Err: " + err.Error()
  72. return
  73. }
  74. companyIds = append(companyIds, enCompanyIds...)
  75. if len(companyIds) > 0 {
  76. condition += fmt.Sprintf(` AND m.company_id IN (%s) `, utils.GetOrmInReplace(len(companyIds)))
  77. pars = append(pars, companyIds)
  78. }
  79. }
  80. if sellerId > 0 {
  81. condition += ` AND m.seller_id=? `
  82. pars = append(pars, sellerId)
  83. }
  84. if overseasLabel > 0 {
  85. condition += ` AND m.overseas_label=? `
  86. pars = append(pars, overseasLabel)
  87. }
  88. if customType == 2 {
  89. condition += ` AND m.is_hide=? `
  90. pars = append(pars, 1)
  91. } else {
  92. condition += ` AND m.is_hide=? `
  93. pars = append(pars, 0)
  94. }
  95. if companyStatus == "试用" {
  96. condition += ` AND m.company_status='试用' AND m.overseas_status='' `
  97. } else if companyStatus == "正式" {
  98. condition += ` AND m.company_status='正式' `
  99. }
  100. total, err := obj.GetCustomListCount(condition, pars, companyStatus)
  101. if err != nil {
  102. br.Msg = "获取失败"
  103. br.ErrMsg = "获取数据总数失败, Err: " + err.Error()
  104. return
  105. }
  106. list, err := obj.GetCustomList(condition, pars, companyStatus, sortField, startSize, pageSize, sortDesc)
  107. if err != nil {
  108. br.Msg = "获取失败"
  109. br.ErrMsg = "获取数据失败, Err: " + err.Error()
  110. return
  111. }
  112. for _, v := range list {
  113. if v.Source == 1 && v.OverseasStatus != "" {
  114. v.CompanyStatus = v.OverseasStatus
  115. }
  116. }
  117. statisticsDataList, err := obj.GetCustomTotal(condition, pars)
  118. if err != nil {
  119. br.Msg = "获取失败"
  120. br.ErrMsg = "获取各状态总数失败, Err: " + err.Error()
  121. return
  122. }
  123. statisticsDataStatusList := make([]*overseas_custom.CustomTotal, 0)
  124. statisticsDataMap := make(map[string]int)
  125. for _, v := range statisticsDataList {
  126. statisticsDataMap[v.CompanyStatus] = v.Total
  127. }
  128. var statusArr = [3]string{"试用", "正式", "关闭"}
  129. for _, v := range statusArr {
  130. item := new(overseas_custom.CustomTotal)
  131. item.CompanyStatus = v
  132. if val, ok := statisticsDataMap[v]; ok {
  133. item.Total = val
  134. }
  135. statisticsDataStatusList = append(statisticsDataStatusList, item)
  136. }
  137. overseasLabelDataList, err := obj.GetCustomOverseasLabelTotal(condition, pars)
  138. if err != nil {
  139. br.Msg = "获取失败"
  140. br.ErrMsg = "获取子标签总数失败, Err: " + err.Error()
  141. return
  142. }
  143. labelDataMap := make(map[int]int)
  144. for _, v := range overseasLabelDataList {
  145. labelDataMap[v.OverseasLabel] = v.Total
  146. }
  147. var labelArr = [4]int{1, 2, 3, 4}
  148. labelList := make([]*overseas_custom.OverseasLabelTotal, 0)
  149. for _, v := range labelArr {
  150. item := new(overseas_custom.OverseasLabelTotal)
  151. item.OverseasLabel = v
  152. if val, ok := labelDataMap[v]; ok {
  153. item.Total = val
  154. }
  155. labelList = append(labelList, item)
  156. }
  157. page := paging.GetPaging(currentIndex, pageSize, total)
  158. resp := new(overseas_custom.CustomListResp)
  159. resp.Paging = page
  160. resp.List = list
  161. resp.StatisticsData = statisticsDataStatusList
  162. resp.OverseasLabelData = labelList
  163. br.Ret = 200
  164. br.Success = true
  165. br.Msg = "获取成功"
  166. br.Data = resp
  167. }
  168. // @Title 客户隐藏
  169. // @Description 客户隐藏
  170. // @Param request body overseas_custom.CustomHideReq true "type json string"
  171. // @Success 200 string "操作成功"
  172. // @router /custom/hide [post]
  173. func (this *OverseasCustomController) CustomHide() {
  174. br := new(models.BaseResponse).Init()
  175. br.IsSendEmail = false
  176. defer func() {
  177. this.Data["json"] = br
  178. this.ServeJSON()
  179. }()
  180. sysUser := this.SysUser
  181. if sysUser == nil {
  182. br.Msg = "请登录"
  183. br.ErrMsg = "请登录,SysUser Is Empty"
  184. br.Ret = 408
  185. return
  186. }
  187. var req overseas_custom.CustomHideReq
  188. if err := json.Unmarshal(this.Ctx.Input.RequestBody, &req); err != nil {
  189. br.Msg = "参数解析异常!"
  190. br.ErrMsg = "参数解析失败,Err:" + err.Error()
  191. return
  192. }
  193. if req.CompanyId <= 0 {
  194. br.Msg = "参数错误!"
  195. return
  196. }
  197. //if req.CompanyId > utils.EnCompanyIdStep {
  198. // req.CompanyId = req.CompanyId - utils.EnCompanyIdStep
  199. //}
  200. obj := new(overseas_custom.Custom)
  201. item, err := obj.GetCustomByCompanyId(req.CompanyId)
  202. if err != nil {
  203. if err.Error() == utils.ErrNoRow() {
  204. br.Msg = "隐藏失败,客户信息不存在!"
  205. br.ErrMsg = "隐藏失败,Err:" + err.Error()
  206. return
  207. }
  208. br.Msg = "隐藏失败!"
  209. br.ErrMsg = "隐藏失败,Err:" + err.Error()
  210. return
  211. }
  212. //是否隐藏:0:不隐藏,1:隐藏
  213. var isHide int
  214. if item.IsHide == 1 {
  215. isHide = 0
  216. } else {
  217. isHide = 1
  218. }
  219. if req.CompanyId > 1000000 {
  220. enCompanyObj := new(models.EnglishCompany)
  221. // 更新客户
  222. nowTime := time.Now().Local()
  223. enCompanyObj.CompanyId = req.CompanyId - utils.EnCompanyIdStep
  224. enCompanyObj.IsHide = isHide
  225. enCompanyObj.ModifyTime = nowTime
  226. updateCols := []string{"IsHide", "ModifyTime"}
  227. if err = enCompanyObj.Update(updateCols); err != nil {
  228. br.Msg = "隐藏失败"
  229. br.ErrMsg = "更新英文客户隐藏状态失败, Err:" + err.Error()
  230. return
  231. }
  232. } else {
  233. companyObj := new(company.Company)
  234. companyObj.CompanyId = req.CompanyId
  235. companyObj.IsHide = isHide
  236. updateCols := []string{"IsHide"}
  237. err = companyObj.Update(updateCols)
  238. if err != nil {
  239. br.Msg = "隐藏失败"
  240. br.ErrMsg = "更新客户隐藏状态失败, Err:" + err.Error()
  241. return
  242. }
  243. }
  244. br.Ret = 200
  245. br.Success = true
  246. br.Msg = "隐藏成功"
  247. }
  248. // @Title 客户状态设置
  249. // @Description 客户状态设置
  250. // @Param request body overseas_custom.CustomHideReq true "type json string"
  251. // @Success 200 string "操作成功"
  252. // @router /custom/status_set [post]
  253. func (this *OverseasCustomController) CustomStatusSet() {
  254. br := new(models.BaseResponse).Init()
  255. br.IsSendEmail = false
  256. defer func() {
  257. this.Data["json"] = br
  258. this.ServeJSON()
  259. }()
  260. sysUser := this.SysUser
  261. if sysUser == nil {
  262. br.Msg = "请登录"
  263. br.ErrMsg = "请登录,SysUser Is Empty"
  264. br.Ret = 408
  265. return
  266. }
  267. var req overseas_custom.CustomHideReq
  268. if err := json.Unmarshal(this.Ctx.Input.RequestBody, &req); err != nil {
  269. br.Msg = "参数解析异常!"
  270. br.ErrMsg = "参数解析失败,Err:" + err.Error()
  271. return
  272. }
  273. if req.CompanyId <= 0 {
  274. br.Msg = "参数错误!"
  275. return
  276. }
  277. obj := new(overseas_custom.Custom)
  278. item, err := obj.GetCustomByCompanyId(req.CompanyId)
  279. if err != nil {
  280. br.Msg = "隐藏失败!"
  281. br.ErrMsg = "隐藏失败,Err:" + err.Error()
  282. return
  283. }
  284. //是否隐藏:0:不隐藏,1:隐藏
  285. var overseasStatus string
  286. if item.OverseasStatus == "" {
  287. overseasStatus = "正式"
  288. } else {
  289. overseasStatus = ""
  290. }
  291. if req.CompanyId > 1000000 {
  292. enCompanyObj := new(models.EnglishCompany)
  293. // 更新客户
  294. nowTime := time.Now().Local()
  295. enCompanyObj.CompanyId = req.CompanyId - utils.EnCompanyIdStep
  296. enCompanyObj.OverseasStatus = overseasStatus
  297. enCompanyObj.ModifyTime = nowTime
  298. updateCols := []string{"OverseasStatus", "ModifyTime"}
  299. if err = enCompanyObj.Update(updateCols); err != nil {
  300. br.Msg = "隐藏失败"
  301. br.ErrMsg = "更新英文客户转正式状态失败, Err:" + err.Error()
  302. return
  303. }
  304. } else {
  305. companyObj := new(company.Company)
  306. companyObj.CompanyId = req.CompanyId
  307. companyObj.OverseasStatus = overseasStatus
  308. updateCols := []string{"OverseasStatus"}
  309. err = companyObj.Update(updateCols)
  310. if err != nil {
  311. br.Msg = "隐藏失败"
  312. br.ErrMsg = "更新客户转正式状态失败, Err:" + err.Error()
  313. return
  314. }
  315. }
  316. br.Ret = 200
  317. br.Success = true
  318. br.Msg = "操作成功"
  319. }
  320. // @Title 客户子标签设置
  321. // @Description 客户子标签设置
  322. // @Param request body overseas_custom.CustomOverseasLabelSetReq true "type json string"
  323. // @Success 200 string "操作成功"
  324. // @router /custom/overseas_label_set [post]
  325. func (this *OverseasCustomController) CustomOverseasLabelSet() {
  326. br := new(models.BaseResponse).Init()
  327. br.IsSendEmail = false
  328. defer func() {
  329. this.Data["json"] = br
  330. this.ServeJSON()
  331. }()
  332. //海外客户试用子标签:1未分类、2 推进、3 跟踪、4 预备、
  333. sysUser := this.SysUser
  334. if sysUser == nil {
  335. br.Msg = "请登录"
  336. br.ErrMsg = "请登录,SysUser Is Empty"
  337. br.Ret = 408
  338. return
  339. }
  340. var req overseas_custom.CustomOverseasLabelSetReq
  341. if err := json.Unmarshal(this.Ctx.Input.RequestBody, &req); err != nil {
  342. br.Msg = "参数解析异常!"
  343. br.ErrMsg = "参数解析失败,Err:" + err.Error()
  344. return
  345. }
  346. if req.CompanyId <= 0 {
  347. br.Msg = "参数错误!"
  348. return
  349. }
  350. if req.CompanyId > 1000000 {
  351. enCompanyObj := new(models.EnglishCompany)
  352. // 更新客户
  353. nowTime := time.Now().Local()
  354. enCompanyObj.CompanyId = req.CompanyId - utils.EnCompanyIdStep
  355. enCompanyObj.OverseasLabel = req.OverseasLabel
  356. enCompanyObj.ModifyTime = nowTime
  357. updateCols := []string{"OverseasLabel", "ModifyTime"}
  358. if err := enCompanyObj.Update(updateCols); err != nil {
  359. br.Msg = "设置失败"
  360. br.ErrMsg = "设置英文客户标签状态失败, Err:" + err.Error()
  361. return
  362. }
  363. } else {
  364. companyObj := new(company.CompanyProduct)
  365. companyObj.CompanyId = req.CompanyId
  366. companyObj.OverseasLabel = req.OverseasLabel
  367. updateCols := []string{"OverseasLabel"}
  368. err := companyObj.Update(updateCols)
  369. if err != nil {
  370. br.Msg = "设置失败"
  371. br.ErrMsg = "设置客户标签状态失败, Err:" + err.Error()
  372. return
  373. }
  374. }
  375. br.Ret = 200
  376. br.Success = true
  377. br.Msg = "设置成功"
  378. }