sale.go 3.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152
  1. package overseas_custom
  2. import (
  3. "encoding/json"
  4. "hongze/hz_crm_api/controllers"
  5. "hongze/hz_crm_api/models"
  6. "hongze/hz_crm_api/models/overseas_custom"
  7. "hongze/hz_crm_api/utils"
  8. "time"
  9. )
  10. // 海外客户
  11. type OverseasCustomController struct {
  12. controllers.BaseAuthController
  13. }
  14. // @Title 保存销售
  15. // @Description 保存销售
  16. // @Param request body overseas_custom.OverseasCustomerSaleSaveReq true "type json string"
  17. // @Success Ret=200 操作成功
  18. // @router /sale/save [post]
  19. func (this *OverseasCustomController) SaleSave() {
  20. br := new(models.BaseResponse).Init()
  21. defer func() {
  22. this.Data["json"] = br
  23. this.ServeJSON()
  24. }()
  25. sysUser := this.SysUser
  26. if sysUser == nil {
  27. br.Msg = "请登录"
  28. br.ErrMsg = "请登录,SysUser Is Empty"
  29. br.Ret = 408
  30. return
  31. }
  32. var req overseas_custom.OverseasCustomerSaleSaveReq
  33. err := json.Unmarshal(this.Ctx.Input.RequestBody, &req)
  34. if err != nil {
  35. br.Msg = "参数解析异常!"
  36. br.ErrMsg = "参数解析失败,Err:" + err.Error()
  37. return
  38. }
  39. if len(req.AddSellerIdArr) <= 0 && len(req.DelSellerIdArr) <= 0 {
  40. br.Msg = "参数错误!"
  41. return
  42. }
  43. obj := new(overseas_custom.OverseasCustomerSale)
  44. list, err := obj.GetOverseasCustomerSaleAll()
  45. if err != nil && err.Error() != utils.ErrNoRow() {
  46. br.Msg = "保存失败!"
  47. br.ErrMsg = "保存失败,GetOverseasCustomerSaleAll,Err:" + err.Error()
  48. return
  49. }
  50. existMap := make(map[int]string)
  51. for _, v := range list {
  52. existMap[v.SellerId] = v.RealName
  53. }
  54. if len(req.AddSellerIdArr) > 0 {
  55. for _, v := range req.AddSellerIdArr {
  56. if _, ok := existMap[v]; !ok {
  57. item := new(overseas_custom.OverseasCustomerSale)
  58. item.SellerId = v
  59. item.CreateTime = time.Now()
  60. err = item.Create()
  61. if err != nil {
  62. br.Msg = "保存失败!"
  63. br.ErrMsg = "保存失败,Err:" + err.Error()
  64. return
  65. }
  66. err = obj.HandelOverseasCustomerSale(v, 1)
  67. if err != nil {
  68. br.Msg = "保存失败!"
  69. br.ErrMsg = "保存失败,处理特定销售客户信息失败,Err:" + err.Error()
  70. return
  71. }
  72. //修改客户状态
  73. err = obj.HandelCompanyStatus(v)
  74. if err != nil {
  75. br.Msg = "保存失败!"
  76. br.ErrMsg = "保存失败,同步客户状态失败,Err:" + err.Error()
  77. return
  78. }
  79. }
  80. }
  81. }
  82. if len(req.DelSellerIdArr) > 0 {
  83. for _, id := range req.DelSellerIdArr {
  84. obj.SellerId = id
  85. err = obj.Delete()
  86. if err != nil {
  87. br.Msg = "保存失败!"
  88. br.ErrMsg = "删除销售失败,Err:" + err.Error()
  89. return
  90. }
  91. err = obj.HandelOverseasCustomerSale(id, 1)
  92. if err != nil {
  93. br.Msg = "保存失败!"
  94. br.ErrMsg = "保存失败,处理特定销售客户信息失败,Err:" + err.Error()
  95. return
  96. }
  97. ////修改客户状态
  98. //err = obj.HandelCompanyStatus(id)
  99. //if err != nil {
  100. // br.Msg = "保存失败!"
  101. // br.ErrMsg = "保存失败,同步客户状态失败,Err:" + err.Error()
  102. // return
  103. //}
  104. }
  105. }
  106. br.Ret = 200
  107. br.Success = true
  108. br.Msg = "保存成功"
  109. }
  110. // @Title 获取已保存销售列表
  111. // @Description 获取已保存销售列表
  112. // @Success 200 {object} overseas_custom.OverseasCustomerSaleView
  113. // @router /sale/list [get]
  114. func (this *OverseasCustomController) SaleList() {
  115. br := new(models.BaseResponse).Init()
  116. defer func() {
  117. this.Data["json"] = br
  118. this.ServeJSON()
  119. }()
  120. sysUser := this.SysUser
  121. if sysUser == nil {
  122. br.Msg = "请登录"
  123. br.ErrMsg = "请登录,SysUser Is Empty"
  124. br.Ret = 408
  125. return
  126. }
  127. obj := new(overseas_custom.OverseasCustomerSale)
  128. list, err := obj.GetOverseasCustomerSaleAll()
  129. if err != nil && err.Error() != utils.ErrNoRow() {
  130. br.Msg = "获取失败!"
  131. br.ErrMsg = "获取失败,GetOverseasCustomerSaleAll,Err:" + err.Error()
  132. return
  133. }
  134. br.Ret = 200
  135. br.Success = true
  136. br.Msg = "获取成功"
  137. br.Data = list
  138. }