custom.go 17 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635
  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/overseas_custom"
  8. "hongze/hz_crm_api/utils"
  9. "time"
  10. )
  11. // @Title 获取海外客户列表数据
  12. // @Description 获取海外客户列表数据
  13. // @Param PageSize query int true "每页数据条数"
  14. // @Param CurrentIndex query int true "当前页页码,从1开始"
  15. // @Param Keywords query string false "关键词:客户名称/社会信用码/联系人手机号/邮箱"
  16. // @Param CompanyStatus query string false "状态:全部,正式,试用,关闭"
  17. // @Param SellerId query int false "销售ID"
  18. // @Param CustomType query int false "1:海外客户,2:隐藏客户"
  19. // @Param SortField query string false "排序字段:ViewTotal,RoadShowTotal,CreateTime"
  20. // @Param SortDesc query int false "1:降序,默认,2:升序"
  21. // @Param OverseasLabel query int false "海外客户试用子标签:1未分类、2 推进、3 跟踪、4 预备、"
  22. // @Success 200 {object} models.EnglishCompanyPageListResp
  23. // @router /custom/list [get]
  24. func (this *OverseasCustomController) CustomList() {
  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. pageSize, _ := this.GetInt("PageSize")
  39. currentIndex, _ := this.GetInt("CurrentIndex")
  40. keywords := this.GetString("Keywords", "")
  41. sellerId, _ := this.GetInt("SellerId", 0)
  42. companyStatus := this.GetString("CompanyStatus")
  43. sortField := this.GetString("SortField")
  44. sortDesc, _ := this.GetInt("SortDesc")
  45. overseasLabel, _ := this.GetInt("OverseasLabel", 0)
  46. customType, _ := this.GetInt("CustomType", 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. page := paging.GetPaging(currentIndex, pageSize, 0)
  56. resp := new(overseas_custom.CustomListResp)
  57. obj := new(overseas_custom.Custom)
  58. var condition string
  59. var pars []interface{}
  60. if keywords != "" {
  61. k := "%" + keywords + "%"
  62. enCompanyIds, e := overseas_custom.GetEnCompanyIdsByKeyword(k)
  63. if e != nil {
  64. br.Msg = "获取失败"
  65. br.ErrMsg = "关键词获取英文客户IDs失败, Err: " + e.Error()
  66. return
  67. }
  68. //获取中文客户
  69. companyIds, err := obj.GetCompanyIdsByKeyword(k)
  70. if err != nil {
  71. br.Msg = "获取失败"
  72. br.ErrMsg = "关键词获取客户IDs失败, Err: " + err.Error()
  73. return
  74. }
  75. companyIds = append(companyIds, enCompanyIds...)
  76. if len(companyIds) > 0 {
  77. condition += fmt.Sprintf(` AND m.company_id IN (%s) `, utils.GetOrmInReplace(len(companyIds)))
  78. pars = append(pars, companyIds)
  79. }
  80. if len(companyIds) <= 0 {
  81. list := make([]*overseas_custom.Custom, 0)
  82. resp.Paging = page
  83. resp.List = list
  84. br.Ret = 200
  85. br.Success = true
  86. br.Msg = "获取成功"
  87. br.Data = resp
  88. return
  89. }
  90. }
  91. if sellerId > 0 {
  92. condition += ` AND m.seller_id=? `
  93. pars = append(pars, sellerId)
  94. }
  95. if overseasLabel > 0 {
  96. condition += ` AND m.overseas_label=? `
  97. pars = append(pars, overseasLabel)
  98. }
  99. if customType == 2 {
  100. condition += ` AND m.is_hide=? `
  101. pars = append(pars, 1)
  102. } else {
  103. condition += ` AND m.is_hide=? `
  104. pars = append(pars, 0)
  105. }
  106. if companyStatus == "试用" {
  107. condition += ` AND m.overseas_status='试用'`
  108. } else if companyStatus == "正式" {
  109. condition += ` AND m.overseas_status='正式' `
  110. } else if companyStatus == "关闭" {
  111. condition += ` AND m.overseas_status='关闭' `
  112. }
  113. total, err := obj.GetCustomListCount(condition, pars)
  114. if err != nil {
  115. br.Msg = "获取失败"
  116. br.ErrMsg = "获取数据总数失败, Err: " + err.Error()
  117. return
  118. }
  119. list, err := obj.GetCustomList(condition, pars, sortField, startSize, pageSize, sortDesc)
  120. if err != nil {
  121. br.Msg = "获取失败"
  122. br.ErrMsg = "获取数据失败, Err: " + err.Error()
  123. return
  124. }
  125. for _, v := range list {
  126. if v.Source == 1 && v.OverseasStatus != "" {
  127. v.CompanyStatus = v.OverseasStatus
  128. }
  129. }
  130. page = paging.GetPaging(currentIndex, pageSize, total)
  131. resp.Paging = page
  132. resp.List = list
  133. br.Ret = 200
  134. br.Success = true
  135. br.Msg = "获取成功"
  136. br.Data = resp
  137. }
  138. // @Title 客户隐藏
  139. // @Description 客户隐藏
  140. // @Param request body overseas_custom.CustomHideReq true "type json string"
  141. // @Success 200 string "操作成功"
  142. // @router /custom/hide [post]
  143. func (this *OverseasCustomController) CustomHide() {
  144. br := new(models.BaseResponse).Init()
  145. br.IsSendEmail = false
  146. defer func() {
  147. this.Data["json"] = br
  148. this.ServeJSON()
  149. }()
  150. sysUser := this.SysUser
  151. if sysUser == nil {
  152. br.Msg = "请登录"
  153. br.ErrMsg = "请登录,SysUser Is Empty"
  154. br.Ret = 408
  155. return
  156. }
  157. var req overseas_custom.CustomHideReq
  158. if err := json.Unmarshal(this.Ctx.Input.RequestBody, &req); err != nil {
  159. br.Msg = "参数解析异常!"
  160. br.ErrMsg = "参数解析失败,Err:" + err.Error()
  161. return
  162. }
  163. if req.CompanyId <= 0 {
  164. br.Msg = "参数错误!"
  165. return
  166. }
  167. //if req.CompanyId > utils.EnCompanyIdStep {
  168. // req.CompanyId = req.CompanyId - utils.EnCompanyIdStep
  169. //}
  170. obj := new(overseas_custom.Custom)
  171. item, err := obj.GetCustomByCompanyId(req.CompanyId)
  172. if err != nil {
  173. if err.Error() == utils.ErrNoRow() {
  174. br.Msg = "隐藏失败,客户信息不存在!"
  175. br.ErrMsg = "隐藏失败,Err:" + err.Error()
  176. return
  177. }
  178. br.Msg = "隐藏失败!"
  179. br.ErrMsg = "隐藏失败,Err:" + err.Error()
  180. return
  181. }
  182. //是否隐藏:0:不隐藏,1:隐藏
  183. var isHide int
  184. if item.IsHide == 1 {
  185. isHide = 0
  186. } else {
  187. isHide = 1
  188. }
  189. if req.CompanyId > 1000000 {
  190. enCompanyObj := new(models.EnglishCompany)
  191. // 更新客户
  192. nowTime := time.Now().Local()
  193. enCompanyObj.CompanyId = req.CompanyId - utils.EnCompanyIdStep
  194. enCompanyObj.IsHide = isHide
  195. enCompanyObj.ModifyTime = nowTime
  196. updateCols := []string{"IsHide", "ModifyTime"}
  197. if err = enCompanyObj.Update(updateCols); err != nil {
  198. br.Msg = "隐藏失败"
  199. br.ErrMsg = "更新英文客户隐藏状态失败, Err:" + err.Error()
  200. return
  201. }
  202. } else {
  203. obj := new(overseas_custom.Custom)
  204. updateParams := make(map[string]interface{})
  205. updateParams["is_hide"] = isHide
  206. whereParam := make(map[string]interface{})
  207. whereParam["company_id"] = req.CompanyId
  208. err := obj.UpdateCompany(updateParams, whereParam)
  209. if err != nil {
  210. br.Msg = "设置失败"
  211. br.ErrMsg = "设置客户标签状态失败, Err:" + err.Error()
  212. return
  213. }
  214. }
  215. br.Ret = 200
  216. br.Success = true
  217. br.Msg = "隐藏成功"
  218. }
  219. // @Title 客户状态设置
  220. // @Description 客户状态设置
  221. // @Param request body overseas_custom.CustomHideReq true "type json string"
  222. // @Success 200 string "操作成功"
  223. // @router /custom/status_set [post]
  224. func (this *OverseasCustomController) CustomStatusSet() {
  225. br := new(models.BaseResponse).Init()
  226. br.IsSendEmail = false
  227. defer func() {
  228. this.Data["json"] = br
  229. this.ServeJSON()
  230. }()
  231. sysUser := this.SysUser
  232. if sysUser == nil {
  233. br.Msg = "请登录"
  234. br.ErrMsg = "请登录,SysUser Is Empty"
  235. br.Ret = 408
  236. return
  237. }
  238. var req overseas_custom.CustomHideReq
  239. if err := json.Unmarshal(this.Ctx.Input.RequestBody, &req); err != nil {
  240. br.Msg = "参数解析异常!"
  241. br.ErrMsg = "参数解析失败,Err:" + err.Error()
  242. return
  243. }
  244. if req.CompanyId <= 0 {
  245. br.Msg = "参数错误!"
  246. return
  247. }
  248. obj := new(overseas_custom.Custom)
  249. item, err := obj.GetCustomByCompanyId(req.CompanyId)
  250. if err != nil {
  251. br.Msg = "设置失败!"
  252. br.ErrMsg = "设置失败,Err:" + err.Error()
  253. return
  254. }
  255. //是否隐藏:0:不隐藏,1:隐藏
  256. var overseasStatus string
  257. var resetBtn int
  258. if item.OverseasStatus == "正式" && item.ResetBtn == 2 { //重置,获取当前客户的状态
  259. overseasStatus = item.CompanyStatus
  260. resetBtn = 1
  261. } else if item.OverseasStatus == "试用" && (item.ResetBtn == 1 || item.ResetBtn == 0) { //转正式,获取当前客户的状态
  262. overseasStatus = "正式"
  263. resetBtn = 2
  264. }
  265. if req.CompanyId > 1000000 {
  266. enCompanyObj := new(models.EnglishCompany)
  267. // 更新客户
  268. nowTime := time.Now().Local()
  269. enCompanyObj.CompanyId = req.CompanyId - utils.EnCompanyIdStep
  270. enCompanyObj.OverseasStatus = overseasStatus
  271. enCompanyObj.ModifyTime = nowTime
  272. enCompanyObj.ResetBtn = resetBtn
  273. updateCols := []string{"OverseasStatus", "ResetBtn", "ModifyTime"}
  274. if err = enCompanyObj.Update(updateCols); err != nil {
  275. br.Msg = "设置失败"
  276. br.ErrMsg = "更新英文客户转正式状态失败, Err:" + err.Error()
  277. return
  278. }
  279. } else {
  280. obj := new(overseas_custom.Custom)
  281. updateParams := make(map[string]interface{})
  282. updateParams["overseas_status"] = overseasStatus
  283. updateParams["reset_btn"] = resetBtn
  284. updateParams["modify_time"] = time.Now()
  285. whereParam := make(map[string]interface{})
  286. whereParam["company_id"] = req.CompanyId
  287. err := obj.UpdateCompany(updateParams, whereParam)
  288. if err != nil {
  289. br.Msg = "设置失败"
  290. br.ErrMsg = "设置客户标签状态失败, Err:" + err.Error()
  291. return
  292. }
  293. }
  294. br.Ret = 200
  295. br.Success = true
  296. br.Msg = "操作成功"
  297. }
  298. // @Title 客户子标签设置
  299. // @Description 客户子标签设置
  300. // @Param request body overseas_custom.CustomOverseasLabelSetReq true "type json string"
  301. // @Success 200 string "操作成功"
  302. // @router /custom/overseas_label_set [post]
  303. func (this *OverseasCustomController) CustomOverseasLabelSet() {
  304. br := new(models.BaseResponse).Init()
  305. br.IsSendEmail = false
  306. defer func() {
  307. this.Data["json"] = br
  308. this.ServeJSON()
  309. }()
  310. //海外客户试用子标签:1未分类、2 推进、3 跟踪、4 预备、
  311. sysUser := this.SysUser
  312. if sysUser == nil {
  313. br.Msg = "请登录"
  314. br.ErrMsg = "请登录,SysUser Is Empty"
  315. br.Ret = 408
  316. return
  317. }
  318. var req overseas_custom.CustomOverseasLabelSetReq
  319. if err := json.Unmarshal(this.Ctx.Input.RequestBody, &req); err != nil {
  320. br.Msg = "参数解析异常!"
  321. br.ErrMsg = "参数解析失败,Err:" + err.Error()
  322. return
  323. }
  324. if req.CompanyId <= 0 {
  325. br.Msg = "参数错误!"
  326. return
  327. }
  328. nowTime := time.Now().Local()
  329. if req.CompanyId > 1000000 {
  330. enCompanyObj := new(models.EnglishCompany)
  331. // 更新客户
  332. enCompanyObj.CompanyId = req.CompanyId - utils.EnCompanyIdStep
  333. enCompanyObj.OverseasLabel = req.OverseasLabel
  334. enCompanyObj.ModifyTime = nowTime
  335. updateCols := []string{"OverseasLabel", "ModifyTime"}
  336. if err := enCompanyObj.Update(updateCols); err != nil {
  337. br.Msg = "设置失败"
  338. br.ErrMsg = "设置英文客户标签状态失败, Err:" + err.Error()
  339. return
  340. }
  341. } else {
  342. obj := new(overseas_custom.Custom)
  343. updateParams := make(map[string]interface{})
  344. updateParams["overseas_label"] = req.OverseasLabel
  345. updateParams["modify_time"] = time.Now()
  346. whereParam := make(map[string]interface{})
  347. whereParam["company_id"] = req.CompanyId
  348. whereParam["product_id"] = 1
  349. err := obj.UpdateCompanyProduct(updateParams, whereParam)
  350. if err != nil {
  351. br.Msg = "设置失败"
  352. br.ErrMsg = "设置客户标签状态失败, Err:" + err.Error()
  353. return
  354. }
  355. }
  356. br.Ret = 200
  357. br.Success = true
  358. br.Msg = "设置成功"
  359. }
  360. // @Title 海外客户统计数据
  361. // @Description 海外客户统计数据
  362. // @Param Keywords query string false "关键词:客户名称/社会信用码/联系人手机号/邮箱"
  363. // @Param SellerId query int false "销售ID"
  364. // @Success 200 {object} models.EnglishCompanyPageListResp
  365. // @router /custom/statistics [get]
  366. func (this *OverseasCustomController) CustomStatistics() {
  367. br := new(models.BaseResponse).Init()
  368. br.IsSendEmail = false
  369. defer func() {
  370. this.Data["json"] = br
  371. this.ServeJSON()
  372. }()
  373. sysUser := this.SysUser
  374. if sysUser == nil {
  375. br.Msg = "请登录"
  376. br.ErrMsg = "请登录,SysUser Is Empty"
  377. br.Ret = 408
  378. return
  379. }
  380. keywords := this.GetString("Keywords", "")
  381. sellerId, _ := this.GetInt("SellerId", 0)
  382. customType, _ := this.GetInt("CustomType", 0)
  383. obj := new(overseas_custom.Custom)
  384. var condition string
  385. var pars []interface{}
  386. if keywords != "" {
  387. k := "%" + keywords + "%"
  388. enCompanyIds, e := overseas_custom.GetEnCompanyIdsByKeyword(k)
  389. if e != nil {
  390. br.Msg = "获取失败"
  391. br.ErrMsg = "关键词获取英文客户IDs失败, Err: " + e.Error()
  392. return
  393. }
  394. //获取中文客户
  395. companyIds, err := obj.GetCompanyIdsByKeyword(k)
  396. if err != nil {
  397. br.Msg = "获取失败"
  398. br.ErrMsg = "关键词获取客户IDs失败, Err: " + err.Error()
  399. return
  400. }
  401. companyIds = append(companyIds, enCompanyIds...)
  402. if len(companyIds) > 0 {
  403. condition += fmt.Sprintf(` AND m.company_id IN (%s) `, utils.GetOrmInReplace(len(companyIds)))
  404. pars = append(pars, companyIds)
  405. } else {
  406. statisticsDataStatusList := make([]*overseas_custom.CustomTotal, 0)
  407. var statusArr = [3]string{"试用", "正式", "关闭"}
  408. for _, v := range statusArr {
  409. item := new(overseas_custom.CustomTotal)
  410. item.CompanyStatus = v
  411. statisticsDataStatusList = append(statisticsDataStatusList, item)
  412. }
  413. br.Ret = 200
  414. br.Success = true
  415. br.Msg = "获取成功"
  416. br.Data = statisticsDataStatusList
  417. return
  418. }
  419. }
  420. if sellerId > 0 {
  421. condition += ` AND m.seller_id=? `
  422. pars = append(pars, sellerId)
  423. }
  424. if customType == 2 {
  425. condition += ` AND m.is_hide=? `
  426. pars = append(pars, 1)
  427. } else {
  428. condition += ` AND m.is_hide=? `
  429. pars = append(pars, 0)
  430. }
  431. list, err := obj.GetCustomTotal(condition, pars)
  432. if err != nil {
  433. br.Msg = "获取失败"
  434. br.ErrMsg = "获取各状态总数失败, Err: " + err.Error()
  435. return
  436. }
  437. //total, err := obj.GetCustomOverseasStatusTotal(condition, pars)
  438. //if err != nil && err.Error() != utils.ErrNoRow() {
  439. // br.Msg = "获取失败"
  440. // br.ErrMsg = "获取海外客户总计状态失败, Err: " + err.Error()
  441. // return
  442. //}
  443. statisticsDataStatusList := make([]*overseas_custom.CustomTotal, 0)
  444. statisticsDataMap := make(map[string]int)
  445. for _, v := range list {
  446. statisticsDataMap[v.CompanyStatus] = v.Total
  447. }
  448. var statusArr = [3]string{"试用", "正式", "关闭"}
  449. for _, v := range statusArr {
  450. item := new(overseas_custom.CustomTotal)
  451. item.CompanyStatus = v
  452. if val, ok := statisticsDataMap[v]; ok {
  453. item.Total = val
  454. }
  455. statisticsDataStatusList = append(statisticsDataStatusList, item)
  456. }
  457. br.Ret = 200
  458. br.Success = true
  459. br.Msg = "获取成功"
  460. br.Data = statisticsDataStatusList
  461. }
  462. // @Title 海外客户标签统计数据
  463. // @Description 海外客户标签统计数据
  464. // @Param Keywords query string false "关键词:客户名称/社会信用码/联系人手机号/邮箱"
  465. // @Param SellerId query int false "销售ID"
  466. // @Success 200 {object} models.EnglishCompanyPageListResp
  467. // @router /custom/label/statistics [get]
  468. func (this *OverseasCustomController) CustomLabelStatistics() {
  469. br := new(models.BaseResponse).Init()
  470. br.IsSendEmail = false
  471. defer func() {
  472. this.Data["json"] = br
  473. this.ServeJSON()
  474. }()
  475. sysUser := this.SysUser
  476. if sysUser == nil {
  477. br.Msg = "请登录"
  478. br.ErrMsg = "请登录,SysUser Is Empty"
  479. br.Ret = 408
  480. return
  481. }
  482. keywords := this.GetString("Keywords", "")
  483. sellerId, _ := this.GetInt("SellerId", 0)
  484. customType, _ := this.GetInt("CustomType", 0)
  485. obj := new(overseas_custom.Custom)
  486. var condition string
  487. var pars []interface{}
  488. condition += " AND m.overseas_status='试用' "
  489. if keywords != "" {
  490. k := "%" + keywords + "%"
  491. enCompanyIds, e := overseas_custom.GetEnCompanyIdsByKeyword(k)
  492. if e != nil {
  493. br.Msg = "获取失败"
  494. br.ErrMsg = "关键词获取英文客户IDs失败, Err: " + e.Error()
  495. return
  496. }
  497. //获取中文客户
  498. companyIds, err := obj.GetCompanyIdsByKeyword(k)
  499. if err != nil {
  500. br.Msg = "获取失败"
  501. br.ErrMsg = "关键词获取客户IDs失败, Err: " + err.Error()
  502. return
  503. }
  504. companyIds = append(companyIds, enCompanyIds...)
  505. if len(companyIds) > 0 {
  506. condition += fmt.Sprintf(` AND m.company_id IN (%s) `, utils.GetOrmInReplace(len(companyIds)))
  507. pars = append(pars, companyIds)
  508. } else {
  509. var labelArr = [4]int{1, 2, 3, 4}
  510. labelList := make([]*overseas_custom.OverseasLabelTotal, 0)
  511. for _, v := range labelArr {
  512. item := new(overseas_custom.OverseasLabelTotal)
  513. item.OverseasLabel = v
  514. labelList = append(labelList, item)
  515. }
  516. br.Ret = 200
  517. br.Success = true
  518. br.Msg = "获取成功"
  519. br.Data = labelList
  520. return
  521. }
  522. }
  523. if sellerId > 0 {
  524. condition += ` AND m.seller_id=? `
  525. pars = append(pars, sellerId)
  526. }
  527. if customType == 2 {
  528. condition += ` AND m.is_hide=? `
  529. pars = append(pars, 1)
  530. } else {
  531. condition += ` AND m.is_hide=? `
  532. pars = append(pars, 0)
  533. }
  534. overseasLabelDataList, err := obj.GetCustomOverseasLabelTotal(condition, pars)
  535. if err != nil {
  536. br.Msg = "获取失败"
  537. br.ErrMsg = "获取子标签总数失败, Err: " + err.Error()
  538. return
  539. }
  540. labelDataMap := make(map[int]int)
  541. for _, v := range overseasLabelDataList {
  542. labelDataMap[v.OverseasLabel] = v.Total
  543. }
  544. var labelArr = [4]int{1, 2, 3, 4}
  545. labelList := make([]*overseas_custom.OverseasLabelTotal, 0)
  546. for _, v := range labelArr {
  547. item := new(overseas_custom.OverseasLabelTotal)
  548. item.OverseasLabel = v
  549. if val, ok := labelDataMap[v]; ok {
  550. item.Total = val
  551. }
  552. labelList = append(labelList, item)
  553. }
  554. br.Ret = 200
  555. br.Success = true
  556. br.Msg = "获取成功"
  557. br.Data = labelList
  558. }