|
|
@@ -56,7 +56,6 @@ func NewCustomerService(ctx context.Context) (svc *CustomerService, err error) {
|
|
|
//导出数据
|
|
|
func (c *CustomerService) Derive(req *model.CustCustomerExport) (content *model.CustExport, err error) {
|
|
|
var con model.CustExport
|
|
|
- req.CustCustomerSearchReq.TargetType = "11"
|
|
|
total, data, err := c.GetList(&req.CustCustomerSearchReq)
|
|
|
if err != nil {
|
|
|
return
|
|
|
@@ -71,18 +70,41 @@ func (c *CustomerService) Derive(req *model.CustCustomerExport) (content *model.
|
|
|
|
|
|
for ck, item := range data {
|
|
|
for index, v := range req.Columns {
|
|
|
- if v == "经销商编码" {
|
|
|
+ if v == "客户编码" {
|
|
|
f.SetCellValue("Sheet1", service.Div(index+1)+strconv.Itoa(ck+2), item.CustCode)
|
|
|
}
|
|
|
- if v == "经销商名称" {
|
|
|
+ if v == "客户名称" {
|
|
|
f.SetCellValue("Sheet1", service.Div(index+1)+strconv.Itoa(ck+2), item.CustName)
|
|
|
}
|
|
|
if v == "助记名" {
|
|
|
f.SetCellValue("Sheet1", service.Div(index+1)+strconv.Itoa(ck+2), item.AbbrName)
|
|
|
}
|
|
|
- //if v == "所在地区" {
|
|
|
- // f.SetCellValue("Sheet1", service.Div(index+1)+strconv.Itoa(ck+2), item.)
|
|
|
- //}
|
|
|
+ if v == "助记名" {
|
|
|
+ f.SetCellValue("Sheet1", service.Div(index+1)+strconv.Itoa(ck+2), item.AbbrName)
|
|
|
+ }
|
|
|
+ if v == "所在地区" {
|
|
|
+ f.SetCellValue("Sheet1", service.Div(index+1)+strconv.Itoa(ck+2), item.CustLocation)
|
|
|
+ }
|
|
|
+ if v == "客户行业" {
|
|
|
+ f.SetCellValue("Sheet1", service.Div(index+1)+strconv.Itoa(ck+2), item.CustIndustry)
|
|
|
+ }
|
|
|
+ if v == "客户级别" {
|
|
|
+ f.SetCellValue("Sheet1", service.Div(index+1)+strconv.Itoa(ck+2), item.CustLevel)
|
|
|
+ }
|
|
|
+ if v == "客户状态" {
|
|
|
+ var CustStatus string
|
|
|
+ CustStatus = "正常"
|
|
|
+ if item.CustStatus != "10" {
|
|
|
+ CustStatus = "异常"
|
|
|
+ }
|
|
|
+ f.SetCellValue("Sheet1", service.Div(index+1)+strconv.Itoa(ck+2), CustStatus)
|
|
|
+ }
|
|
|
+ if v == "最后跟进时间" {
|
|
|
+ f.SetCellValue("Sheet1", service.Div(index+1)+strconv.Itoa(ck+2), item.FollowUpDate)
|
|
|
+ }
|
|
|
+ if v == "创建时间" {
|
|
|
+ f.SetCellValue("Sheet1", service.Div(index+1)+strconv.Itoa(ck+2), item.CreatedTime)
|
|
|
+ }
|
|
|
}
|
|
|
|
|
|
}
|
|
|
@@ -161,7 +183,6 @@ func (c *CustomerService) CreateBelong(req *model.AddCustomerBelong) (err error)
|
|
|
|
|
|
cusTomerBelong.OpnType = isPublic
|
|
|
cusTomerBelong.OpnDatetime = gtime.Now()
|
|
|
- service.SetCreatedInfo(cusTomerBelong, c.GetCxtUserId(), c.GetCxtUserName())
|
|
|
_, err = c.BelongDao.Insert(cusTomerBelong)
|
|
|
if err != nil {
|
|
|
g.Log().Error(err)
|
|
|
@@ -180,10 +201,10 @@ func (c *CustomerService) GetList(req *model.CustCustomerSearchReq) (total int,
|
|
|
Model = Model.Where(c.Dao.Columns.DeletedTime + " is null")
|
|
|
if req.TargetType == "" {
|
|
|
if !req.IsPublic {
|
|
|
- g.Log().Info("ISPUblic", "xxxxxx")
|
|
|
+
|
|
|
Model = Model.Where(c.Dao.Columns.SalesId, c.CxtUser.Id).Where(c.Dao.Columns.IsPublic, noPublic)
|
|
|
} else {
|
|
|
- g.Log().Info("serverS", req)
|
|
|
+
|
|
|
Model = Model.Where(c.Dao.Columns.IsPublic, isPublic)
|
|
|
}
|
|
|
}
|
|
|
@@ -313,29 +334,45 @@ func (c *CustomerService) MoveToPubic(ids []int64) error {
|
|
|
|
|
|
//分配客户
|
|
|
func (c *CustomerService) DistriCustomer(req *model.DistriCustomer) error {
|
|
|
- custModel := c.Dao.M
|
|
|
+ custModel := c.Dao
|
|
|
rep, err := custModel.Where(cust.CustCustomer.Columns.Id+" in (?) ", req.Ids).Where(cust.CustCustomer.Columns.IsPublic, isPublic).All()
|
|
|
- if err != nil {
|
|
|
+
|
|
|
+ g.Log().Info("fdasfsa", len(rep))
|
|
|
+ if err != nil || len(rep) == 0 {
|
|
|
err = gerror.New("该数据不存在")
|
|
|
return err
|
|
|
}
|
|
|
+ //cust := new(model.CustCustomer)
|
|
|
+ var custMap = make(map[int]string)
|
|
|
+ for _, v := range rep {
|
|
|
+ custMap[v.Id] = v.SalesName
|
|
|
+ }
|
|
|
+ g.Log().Info("fadfadsfaf", custMap)
|
|
|
+ for _, v := range req.Ids {
|
|
|
+ g.Log().Info("req.Ids", v)
|
|
|
+ if custMap[gconv.Int(v)] != "" {
|
|
|
+ err = gerror.New("ID" + gconv.String(v) + "已被认领")
|
|
|
+ return err
|
|
|
+ }
|
|
|
+ }
|
|
|
err = c.updateCustomer(req.Ids, req.SalesId, req.SalesName)
|
|
|
if err != nil {
|
|
|
err = gerror.New("可配客户失败")
|
|
|
return err
|
|
|
|
|
|
}
|
|
|
- var maps = make(map[string]string)
|
|
|
- maps["remark"] = req.Remark
|
|
|
+
|
|
|
+ //belongServer := new(CustomerbelongService)
|
|
|
+
|
|
|
if req.Receive != "" {
|
|
|
- maps["opn_type"] = AllocaTion
|
|
|
+ req.Receive = Receive
|
|
|
} else {
|
|
|
- maps["opn_type"] = Receive
|
|
|
+ req.Receive = AllocaTion
|
|
|
}
|
|
|
- maps["sale_name"] = req.SalesName
|
|
|
- maps["opn_people"] = c.GetCxtUserName()
|
|
|
- //maps["created_by"] = c.GetCxtUserId()
|
|
|
- err = c.belongInsters(rep.List(), maps)
|
|
|
+
|
|
|
+ err = c.Createbelong(rep, req)
|
|
|
+ g.Log().Info("errr", req)
|
|
|
+
|
|
|
if err != nil {
|
|
|
err = gerror.New("分配客户失败")
|
|
|
return err
|
|
|
@@ -356,6 +393,7 @@ func (c *CustomerService) GetEntityById(ids []int64) (entityInfo []*model.CustLi
|
|
|
if err != nil {
|
|
|
g.Log().Error(err)
|
|
|
return nil, gerror.New("获取用户数据失败")
|
|
|
+
|
|
|
}
|
|
|
return
|
|
|
}
|
|
|
@@ -369,7 +407,8 @@ func (c *CustomerService) CustAbstract(id int64) (followInfo *model.Follow, err
|
|
|
g.Log().Info("count", count)
|
|
|
if err != nil {
|
|
|
g.Log().Error(err)
|
|
|
- return nil, gerror.New("获取用户数据失败")
|
|
|
+ gerror.New("获取用户数据失败")
|
|
|
+ return
|
|
|
}
|
|
|
|
|
|
followInfo = new(model.Follow)
|
|
|
@@ -380,7 +419,8 @@ func (c *CustomerService) CustAbstract(id int64) (followInfo *model.Follow, err
|
|
|
|
|
|
if err != nil {
|
|
|
g.Log().Error(err)
|
|
|
- return nil, gerror.New("获取用户数据失败")
|
|
|
+ gerror.New("获取用户数据失败")
|
|
|
+ return
|
|
|
}
|
|
|
|
|
|
findOne := find.Map()
|
|
|
@@ -408,25 +448,22 @@ func (c *CustomerService) CustAbstract(id int64) (followInfo *model.Follow, err
|
|
|
}
|
|
|
|
|
|
//转移客户
|
|
|
-func (c *CustomerService) UpdateBytransfer(req *model.CustSalesReq) (entityInfo []*model.CustCustomer, err error) {
|
|
|
- custModel := c.Dao.M
|
|
|
+func (c *CustomerService) UpdateBytransfer(req *model.DistriCustomer) (err error) {
|
|
|
+ custModel := c.Dao
|
|
|
rep, err := custModel.Fields("sales_id,sales_name,id").Where(cust.CustCustomer.Columns.Id+" in (?)", req.Ids).All()
|
|
|
- if err != nil || rep.IsEmpty() {
|
|
|
+ if err != nil || len(rep) == 0 {
|
|
|
err = gerror.New("该数据不存在")
|
|
|
return
|
|
|
}
|
|
|
- err = c.updateCustomer(req.Ids, req.SalesIds, req.SalesName)
|
|
|
+ err = c.updateCustomer(req.Ids, req.SalesId, req.SalesName)
|
|
|
if err != nil {
|
|
|
err = gerror.New("转移客户失败")
|
|
|
return
|
|
|
}
|
|
|
|
|
|
- var maps = make(map[string]string)
|
|
|
- maps["remark"] = req.Remark
|
|
|
- maps["opn_type"] = OperaTion
|
|
|
- maps["sale_name"] = req.SalesName
|
|
|
+ err = c.Createbelong(rep, req)
|
|
|
|
|
|
- err = c.belongInsters(rep.List(), maps)
|
|
|
+ g.Log().Info("err", err)
|
|
|
if err != nil {
|
|
|
err = gerror.New("转移客户失败")
|
|
|
return
|
|
|
@@ -539,6 +576,13 @@ func (c *CustomerService) Mergecustomer(req *model.MergecustomerRep) (err error)
|
|
|
//所选客户联系人信息
|
|
|
List, err := ContactModel.Where(c.ContactDao.Columns.CustId+" in (?)", req.ChooseId).All()
|
|
|
g.Log().Info("list", List.List())
|
|
|
+ if err != nil || List.Len() > 0 {
|
|
|
+ err = c.Createcontact(req.Id, req.ChooseId, List.List())
|
|
|
+ if err != nil {
|
|
|
+ err = gerror.New("合并失败")
|
|
|
+ return
|
|
|
+ }
|
|
|
+ }
|
|
|
CustomertData := new(model.Customer)
|
|
|
if err = gconv.Struct(req, CustomertData); err != nil {
|
|
|
return
|
|
|
@@ -554,13 +598,7 @@ func (c *CustomerService) Mergecustomer(req *model.MergecustomerRep) (err error)
|
|
|
return
|
|
|
}
|
|
|
Model.Data(g.Map{"deleted_time": gtime.Now()}).Where(c.ContactDao.Columns.Id+" in (?)", req.ChooseId).Update()
|
|
|
- if err != nil || List.Len() > 0 {
|
|
|
- err = c.contactInster(req.Id, req.ChooseId, List.List())
|
|
|
- if err != nil {
|
|
|
- err = gerror.New("合并失败")
|
|
|
- return
|
|
|
- }
|
|
|
- }
|
|
|
+
|
|
|
////所选客户销售联系人信息
|
|
|
BelongList, err := BelongDao.Where(c.BelongDao.Columns.CustId+" in (?)", req.ChooseId).All()
|
|
|
if err != nil || BelongList.Len() > 0 {
|
|
|
@@ -574,7 +612,7 @@ func (c *CustomerService) Mergecustomer(req *model.MergecustomerRep) (err error)
|
|
|
}
|
|
|
|
|
|
//联系人
|
|
|
-func (c *CustomerService) contactInster(id int, Ids []int64, list []map[string]interface{}) (err error) {
|
|
|
+func (c *CustomerService) Createcontact(id int, Ids []int64, list []map[string]interface{}) (err error) {
|
|
|
ContactModel := c.ContactDao.M
|
|
|
ContactModel.Data(g.Map{"deleted_time": gtime.Now()}).Where(c.ContactDao.Columns.CustId+" in (?)", Ids).Update()
|
|
|
maps := []map[string]interface{}{}
|
|
|
@@ -597,7 +635,7 @@ func (c *CustomerService) contactInster(id int, Ids []int64, list []map[string]i
|
|
|
_, err = ContactModel.Insert(maps)
|
|
|
if err != nil {
|
|
|
err = gerror.New("操作失败")
|
|
|
- g.Log().Info("contactInster", err)
|
|
|
+ g.Log().Info("Createcontact", err)
|
|
|
return
|
|
|
|
|
|
}
|
|
|
@@ -626,32 +664,31 @@ func (c *CustomerService) belongInster(Id int, BelongIds []int64, SaleName strin
|
|
|
return
|
|
|
}
|
|
|
|
|
|
-//批量插入客户归属记录表
|
|
|
-func (c *CustomerService) belongInsters(rep []map[string]interface{}, parameter map[string]string) (err error) {
|
|
|
- belongModel := c.BelongDao.M
|
|
|
- maps := []map[string]interface{}{}
|
|
|
+//批量插入客户归属记录表//parameter map[string]string
|
|
|
+func (c *CustomerService) Createbelong(rep []*model.CustCustomer, req *model.DistriCustomer) (err error) {
|
|
|
+ belongModel := c.BelongDao
|
|
|
+ var belongData []*model.CustCustomerBelong
|
|
|
date_time := gtime.Now()
|
|
|
+ userName := c.GetCxtUserName()
|
|
|
for _, v := range rep {
|
|
|
- orig_sale_name := v["sales_name"]
|
|
|
- belong := map[string]interface{}{}
|
|
|
- belong["cust_id"] = v["id"].(int)
|
|
|
- belong["sale_name"] = parameter["sale_name"]
|
|
|
- belong["orig_sale_name"] = orig_sale_name
|
|
|
- belong["opn_type"] = parameter["opn_type"]
|
|
|
- belong["opn_people"] = parameter["opn_people"]
|
|
|
- belong["opn_datetime"] = date_time
|
|
|
- belong["created_by"] = c.GetCxtUserId()
|
|
|
- belong["remark"] = parameter["remark"]
|
|
|
- belong["created_name"] = c.GetCxtUserName()
|
|
|
- belong["created_time"] = date_time
|
|
|
- belong["opn_datetime"] = date_time
|
|
|
- maps = append(maps, belong)
|
|
|
- }
|
|
|
- _, err = belongModel.Insert(maps)
|
|
|
+ orig_sale_name := v.SalesName
|
|
|
+ belong := new(model.CustCustomerBelong) //map[string]interface{}{}
|
|
|
+ belong.CustId = v.Id
|
|
|
+ belong.SaleName = req.SalesName
|
|
|
+ belong.OrigSaleName = orig_sale_name
|
|
|
+ belong.OpnType = req.Receive
|
|
|
+ belong.OpnPeople = userName
|
|
|
+ belong.CreatedName = userName
|
|
|
+ belong.OpnDatetime = date_time
|
|
|
+ belong.Remark = req.Remark
|
|
|
+ belong.CreatedBy = c.GetCxtUserId()
|
|
|
+ belongData = append(belongData, belong)
|
|
|
+ }
|
|
|
+ _, err = belongModel.Insert(belongData)
|
|
|
+ g.Log().Info("belong", belongData)
|
|
|
if err != nil {
|
|
|
err = gerror.New("插入失败")
|
|
|
return err
|
|
|
}
|
|
|
-
|
|
|
return
|
|
|
}
|