|
@@ -0,0 +1,138 @@
|
|
|
+package overseas_custom
|
|
|
+
|
|
|
+import (
|
|
|
+ "encoding/json"
|
|
|
+ "hongze/hz_crm_api/controllers"
|
|
|
+ "hongze/hz_crm_api/models"
|
|
|
+ "hongze/hz_crm_api/models/overseas_custom"
|
|
|
+ "hongze/hz_crm_api/utils"
|
|
|
+ "time"
|
|
|
+)
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+type OverseasCustomController struct {
|
|
|
+ controllers.BaseAuthController
|
|
|
+}
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+func (this *OverseasCustomController) SaleSave() {
|
|
|
+ br := new(models.BaseResponse).Init()
|
|
|
+ defer func() {
|
|
|
+ this.Data["json"] = br
|
|
|
+ this.ServeJSON()
|
|
|
+ }()
|
|
|
+
|
|
|
+ sysUser := this.SysUser
|
|
|
+ if sysUser == nil {
|
|
|
+ br.Msg = "请登录"
|
|
|
+ br.ErrMsg = "请登录,SysUser Is Empty"
|
|
|
+ br.Ret = 408
|
|
|
+ return
|
|
|
+ }
|
|
|
+
|
|
|
+ var req overseas_custom.OverseasCustomerSaleSaveReq
|
|
|
+ err := json.Unmarshal(this.Ctx.Input.RequestBody, &req)
|
|
|
+ if err != nil {
|
|
|
+ br.Msg = "参数解析异常!"
|
|
|
+ br.ErrMsg = "参数解析失败,Err:" + err.Error()
|
|
|
+ return
|
|
|
+ }
|
|
|
+
|
|
|
+ if len(req.AddSellerIdArr) <= 0 && len(req.DelSellerIdArr) <= 0 {
|
|
|
+ br.Msg = "参数错误!"
|
|
|
+ return
|
|
|
+ }
|
|
|
+ obj := new(overseas_custom.OverseasCustomerSale)
|
|
|
+ list, err := obj.GetOverseasCustomerSaleAll()
|
|
|
+ if err != nil && err.Error() != utils.ErrNoRow() {
|
|
|
+ br.Msg = "保存失败!"
|
|
|
+ br.ErrMsg = "保存失败,GetOverseasCustomerSaleAll,Err:" + err.Error()
|
|
|
+ return
|
|
|
+ }
|
|
|
+
|
|
|
+ existMap := make(map[int]string)
|
|
|
+ for _, v := range list {
|
|
|
+ existMap[v.SellerId] = v.RealName
|
|
|
+ }
|
|
|
+ if len(req.AddSellerIdArr) > 0 {
|
|
|
+ for _, v := range req.AddSellerIdArr {
|
|
|
+ if _, ok := existMap[v]; !ok {
|
|
|
+ item := new(overseas_custom.OverseasCustomerSale)
|
|
|
+ item.SellerId = v
|
|
|
+ item.CreateTime = time.Now()
|
|
|
+ err = item.Create()
|
|
|
+ if err != nil {
|
|
|
+ br.Msg = "保存失败!"
|
|
|
+ br.ErrMsg = "保存失败,Err:" + err.Error()
|
|
|
+ return
|
|
|
+ }
|
|
|
+ err = obj.HandelOverseasCustomerSale(v, 1)
|
|
|
+ if err != nil {
|
|
|
+ br.Msg = "保存失败!"
|
|
|
+ br.ErrMsg = "保存失败,处理特定销售客户信息失败,Err:" + err.Error()
|
|
|
+ return
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ if len(req.DelSellerIdArr) > 0 {
|
|
|
+ for _, id := range req.DelSellerIdArr {
|
|
|
+ obj.SellerId = id
|
|
|
+ err = obj.Delete()
|
|
|
+ if err != nil {
|
|
|
+ br.Msg = "保存失败!"
|
|
|
+ br.ErrMsg = "删除销售失败,Err:" + err.Error()
|
|
|
+ return
|
|
|
+ }
|
|
|
+ err = obj.HandelOverseasCustomerSale(id, 1)
|
|
|
+ if err != nil {
|
|
|
+ br.Msg = "保存失败!"
|
|
|
+ br.ErrMsg = "保存失败,处理特定销售客户信息失败,Err:" + err.Error()
|
|
|
+ return
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ br.Ret = 200
|
|
|
+ br.Success = true
|
|
|
+ br.Msg = "保存成功"
|
|
|
+}
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+func (this *OverseasCustomController) SaleList() {
|
|
|
+ br := new(models.BaseResponse).Init()
|
|
|
+ defer func() {
|
|
|
+ this.Data["json"] = br
|
|
|
+ this.ServeJSON()
|
|
|
+ }()
|
|
|
+
|
|
|
+ sysUser := this.SysUser
|
|
|
+ if sysUser == nil {
|
|
|
+ br.Msg = "请登录"
|
|
|
+ br.ErrMsg = "请登录,SysUser Is Empty"
|
|
|
+ br.Ret = 408
|
|
|
+ return
|
|
|
+ }
|
|
|
+
|
|
|
+ obj := new(overseas_custom.OverseasCustomerSale)
|
|
|
+ list, err := obj.GetOverseasCustomerSaleAll()
|
|
|
+ if err != nil && err.Error() != utils.ErrNoRow() {
|
|
|
+ br.Msg = "获取失败!"
|
|
|
+ br.ErrMsg = "获取失败,GetOverseasCustomerSaleAll,Err:" + err.Error()
|
|
|
+ return
|
|
|
+ }
|
|
|
+
|
|
|
+ br.Ret = 200
|
|
|
+ br.Success = true
|
|
|
+ br.Msg = "获取成功"
|
|
|
+ br.Data = list
|
|
|
+}
|