custom.go 10 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378
  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. }
  92. total, err := obj.GetCustomListCount(condition, pars, companyStatus)
  93. if err != nil {
  94. br.Msg = "获取失败"
  95. br.ErrMsg = "获取数据总数失败, Err: " + err.Error()
  96. return
  97. }
  98. list, err := obj.GetCustomList(condition, pars, companyStatus, sortField, startSize, pageSize, sortDesc)
  99. if err != nil {
  100. br.Msg = "获取失败"
  101. br.ErrMsg = "获取数据失败, Err: " + err.Error()
  102. return
  103. }
  104. for _, v := range list {
  105. if v.Source == 1 && v.OverseasStatus != "" {
  106. v.CompanyStatus = v.OverseasStatus
  107. }
  108. }
  109. statisticsDataList, err := obj.GetCustomTotal(condition, pars)
  110. if err != nil {
  111. br.Msg = "获取失败"
  112. br.ErrMsg = "获取各状态总数失败, Err: " + err.Error()
  113. return
  114. }
  115. overseasLabelDataList, err := obj.GetCustomOverseasLabelTotal(condition, pars)
  116. if err != nil {
  117. br.Msg = "获取失败"
  118. br.ErrMsg = "获取子标签总数失败, Err: " + err.Error()
  119. return
  120. }
  121. page := paging.GetPaging(currentIndex, pageSize, total)
  122. resp := new(overseas_custom.CustomListResp)
  123. resp.Paging = page
  124. resp.List = list
  125. resp.StatisticsData = statisticsDataList
  126. resp.OverseasLabelData = overseasLabelDataList
  127. br.Ret = 200
  128. br.Success = true
  129. br.Msg = "获取成功"
  130. br.Data = resp
  131. }
  132. // @Title 客户隐藏
  133. // @Description 客户隐藏
  134. // @Param request body overseas_custom.CustomHideReq true "type json string"
  135. // @Success 200 string "操作成功"
  136. // @router /custom/hide [post]
  137. func (this *OverseasCustomController) CustomHide() {
  138. br := new(models.BaseResponse).Init()
  139. br.IsSendEmail = false
  140. defer func() {
  141. this.Data["json"] = br
  142. this.ServeJSON()
  143. }()
  144. sysUser := this.SysUser
  145. if sysUser == nil {
  146. br.Msg = "请登录"
  147. br.ErrMsg = "请登录,SysUser Is Empty"
  148. br.Ret = 408
  149. return
  150. }
  151. var req overseas_custom.CustomHideReq
  152. if err := json.Unmarshal(this.Ctx.Input.RequestBody, &req); err != nil {
  153. br.Msg = "参数解析异常!"
  154. br.ErrMsg = "参数解析失败,Err:" + err.Error()
  155. return
  156. }
  157. if req.CompanyId <= 0 {
  158. br.Msg = "参数错误!"
  159. return
  160. }
  161. //if req.CompanyId > utils.EnCompanyIdStep {
  162. // req.CompanyId = req.CompanyId - utils.EnCompanyIdStep
  163. //}
  164. obj := new(overseas_custom.Custom)
  165. item, err := obj.GetCustomByCompanyId(req.CompanyId)
  166. if err != nil {
  167. if err.Error() == utils.ErrNoRow() {
  168. br.Msg = "隐藏失败,客户信息不存在!"
  169. br.ErrMsg = "隐藏失败,Err:" + err.Error()
  170. return
  171. }
  172. br.Msg = "隐藏失败!"
  173. br.ErrMsg = "隐藏失败,Err:" + err.Error()
  174. return
  175. }
  176. //是否隐藏:0:不隐藏,1:隐藏
  177. var isHide int
  178. if item.IsHide == 1 {
  179. isHide = 0
  180. } else {
  181. isHide = 1
  182. }
  183. if req.CompanyId > 1000000 {
  184. enCompanyObj := new(models.EnglishCompany)
  185. // 更新客户
  186. nowTime := time.Now().Local()
  187. enCompanyObj.CompanyId = req.CompanyId - utils.EnCompanyIdStep
  188. enCompanyObj.IsHide = isHide
  189. enCompanyObj.ModifyTime = nowTime
  190. updateCols := []string{"IsHide", "ModifyTime"}
  191. if err = enCompanyObj.Update(updateCols); err != nil {
  192. br.Msg = "隐藏失败"
  193. br.ErrMsg = "更新英文客户隐藏状态失败, Err:" + err.Error()
  194. return
  195. }
  196. } else {
  197. companyObj := new(company.Company)
  198. companyObj.CompanyId = req.CompanyId
  199. companyObj.IsHide = isHide
  200. updateCols := []string{"IsHide"}
  201. err = companyObj.Update(updateCols)
  202. if err != nil {
  203. br.Msg = "隐藏失败"
  204. br.ErrMsg = "更新客户隐藏状态失败, Err:" + err.Error()
  205. return
  206. }
  207. }
  208. br.Ret = 200
  209. br.Success = true
  210. br.Msg = "隐藏成功"
  211. }
  212. // @Title 客户状态设置
  213. // @Description 客户状态设置
  214. // @Param request body overseas_custom.CustomHideReq true "type json string"
  215. // @Success 200 string "操作成功"
  216. // @router /custom/status_set [post]
  217. func (this *OverseasCustomController) CustomStatusSet() {
  218. br := new(models.BaseResponse).Init()
  219. br.IsSendEmail = false
  220. defer func() {
  221. this.Data["json"] = br
  222. this.ServeJSON()
  223. }()
  224. sysUser := this.SysUser
  225. if sysUser == nil {
  226. br.Msg = "请登录"
  227. br.ErrMsg = "请登录,SysUser Is Empty"
  228. br.Ret = 408
  229. return
  230. }
  231. var req overseas_custom.CustomHideReq
  232. if err := json.Unmarshal(this.Ctx.Input.RequestBody, &req); err != nil {
  233. br.Msg = "参数解析异常!"
  234. br.ErrMsg = "参数解析失败,Err:" + err.Error()
  235. return
  236. }
  237. if req.CompanyId <= 0 {
  238. br.Msg = "参数错误!"
  239. return
  240. }
  241. obj := new(overseas_custom.Custom)
  242. item, err := obj.GetCustomByCompanyId(req.CompanyId)
  243. if err != nil {
  244. br.Msg = "隐藏失败!"
  245. br.ErrMsg = "隐藏失败,Err:" + err.Error()
  246. return
  247. }
  248. //是否隐藏:0:不隐藏,1:隐藏
  249. var overseasStatus string
  250. if item.OverseasStatus == "" {
  251. overseasStatus = "正式"
  252. } else {
  253. overseasStatus = ""
  254. }
  255. if req.CompanyId > 1000000 {
  256. enCompanyObj := new(models.EnglishCompany)
  257. // 更新客户
  258. nowTime := time.Now().Local()
  259. enCompanyObj.CompanyId = req.CompanyId - utils.EnCompanyIdStep
  260. enCompanyObj.OverseasStatus = overseasStatus
  261. enCompanyObj.ModifyTime = nowTime
  262. updateCols := []string{"OverseasStatus", "ModifyTime"}
  263. if err = enCompanyObj.Update(updateCols); err != nil {
  264. br.Msg = "隐藏失败"
  265. br.ErrMsg = "更新英文客户转正式状态失败, Err:" + err.Error()
  266. return
  267. }
  268. } else {
  269. companyObj := new(company.Company)
  270. companyObj.CompanyId = req.CompanyId
  271. companyObj.OverseasStatus = overseasStatus
  272. updateCols := []string{"OverseasStatus"}
  273. err = companyObj.Update(updateCols)
  274. if err != nil {
  275. br.Msg = "隐藏失败"
  276. br.ErrMsg = "更新客户转正式状态失败, Err:" + err.Error()
  277. return
  278. }
  279. }
  280. br.Ret = 200
  281. br.Success = true
  282. br.Msg = "操作成功"
  283. }
  284. // @Title 客户子标签设置
  285. // @Description 客户子标签设置
  286. // @Param request body overseas_custom.CustomOverseasLabelSetReq true "type json string"
  287. // @Success 200 string "操作成功"
  288. // @router /custom/overseas_label_set [post]
  289. func (this *OverseasCustomController) CustomOverseasLabelSet() {
  290. br := new(models.BaseResponse).Init()
  291. br.IsSendEmail = false
  292. defer func() {
  293. this.Data["json"] = br
  294. this.ServeJSON()
  295. }()
  296. //海外客户试用子标签:1未分类、2 推进、3 跟踪、4 预备、
  297. sysUser := this.SysUser
  298. if sysUser == nil {
  299. br.Msg = "请登录"
  300. br.ErrMsg = "请登录,SysUser Is Empty"
  301. br.Ret = 408
  302. return
  303. }
  304. var req overseas_custom.CustomOverseasLabelSetReq
  305. if err := json.Unmarshal(this.Ctx.Input.RequestBody, &req); err != nil {
  306. br.Msg = "参数解析异常!"
  307. br.ErrMsg = "参数解析失败,Err:" + err.Error()
  308. return
  309. }
  310. if req.CompanyId <= 0 {
  311. br.Msg = "参数错误!"
  312. return
  313. }
  314. if req.CompanyId > 1000000 {
  315. enCompanyObj := new(models.EnglishCompany)
  316. // 更新客户
  317. nowTime := time.Now().Local()
  318. enCompanyObj.CompanyId = req.CompanyId - utils.EnCompanyIdStep
  319. enCompanyObj.OverseasLabel = req.OverseasLabel
  320. enCompanyObj.ModifyTime = nowTime
  321. updateCols := []string{"OverseasLabel", "ModifyTime"}
  322. if err := enCompanyObj.Update(updateCols); err != nil {
  323. br.Msg = "设置失败"
  324. br.ErrMsg = "设置英文客户标签状态失败, Err:" + err.Error()
  325. return
  326. }
  327. } else {
  328. companyObj := new(company.CompanyProduct)
  329. companyObj.CompanyId = req.CompanyId
  330. companyObj.OverseasLabel = req.OverseasLabel
  331. updateCols := []string{"OverseasLabel"}
  332. err := companyObj.Update(updateCols)
  333. if err != nil {
  334. br.Msg = "设置失败"
  335. br.ErrMsg = "设置客户标签状态失败, Err:" + err.Error()
  336. return
  337. }
  338. }
  339. br.Ret = 200
  340. br.Success = true
  341. br.Msg = "设置成功"
  342. }