|
|
@@ -14,35 +14,38 @@ import (
|
|
|
"dashoo.cn/micro/app/service"
|
|
|
)
|
|
|
|
|
|
-type customerService struct {
|
|
|
+type CustomerService struct {
|
|
|
*service.ContextService
|
|
|
Dao *cust.CustCustomerDao
|
|
|
BelongDao *cust.CustCustomerBelongDao
|
|
|
DynamicsDao *cust.CustCustomerDynamicsDao
|
|
|
+ ContactDao *cust.CustCustomerContactDao
|
|
|
}
|
|
|
|
|
|
var isPublic, noPublic = "10", "20" // 公海,非公海
|
|
|
var isTransfer int8 = 1 //转移
|
|
|
var isAllocation int8 = 2 //分配 Allocation
|
|
|
+var OperaTion, AllocaTion = "20", "10"
|
|
|
|
|
|
-func NewCustomerService(ctx context.Context) (svc *customerService, err error) {
|
|
|
- svc = new(customerService)
|
|
|
+type OpnType struct {
|
|
|
+ OperaTion string
|
|
|
+}
|
|
|
+
|
|
|
+func NewCustomerService(ctx context.Context) (svc *CustomerService, err error) {
|
|
|
+ svc = new(CustomerService)
|
|
|
if svc.ContextService, err = svc.Init(ctx); err != nil {
|
|
|
return nil, err
|
|
|
}
|
|
|
svc.Dao = cust.NewCustCustomerDao(svc.Tenant)
|
|
|
svc.BelongDao = cust.NewCustCustomerBelongDao(svc.Tenant)
|
|
|
svc.DynamicsDao = cust.NewCustCustomerDynamicsDao(svc.Tenant)
|
|
|
+ svc.ContactDao = cust.NewCustCustomerContactDao(svc.Tenant)
|
|
|
return svc, nil
|
|
|
}
|
|
|
|
|
|
//创建客户
|
|
|
-func (c *customerService) Create(req *model.Customer) (insertId int64, err error) {
|
|
|
+func (c *CustomerService) Create(req *model.Customer) (insertId int64, err error) {
|
|
|
cusTomer := new(model.CustCustomer)
|
|
|
- if err = gconv.Struct(req, cusTomer); err != nil {
|
|
|
- g.Log().Info("error", err)
|
|
|
- return
|
|
|
- }
|
|
|
g.Log().Info(err)
|
|
|
Model := c.Dao.M
|
|
|
record, err := Model.Where(g.Map{"cust_name": req.CustName}).One()
|
|
|
@@ -58,11 +61,14 @@ func (c *customerService) Create(req *model.Customer) (insertId int64, err error
|
|
|
//OpnContent string ` json:"opnContent"` // 操作内容
|
|
|
|
|
|
//c.OperationLog()
|
|
|
-
|
|
|
+ if err = gconv.Struct(req, cusTomer); err != nil {
|
|
|
+ return
|
|
|
+ }
|
|
|
g.Log().Info("部门ID", c.CxtUser.DeptId)
|
|
|
service.SetCreatedInfo(cusTomer, c.GetCxtUserId(), c.GetCxtUserName())
|
|
|
cusTomer.CustCode = strconv.Itoa(int(gtime.Timestamp()))
|
|
|
cusTomer.IsPublic = isPublic
|
|
|
+ cusTomer.CustStatus = "10"
|
|
|
//if c.CxtUser.DeptId == 2 {
|
|
|
// cusTomer.IsPublic = noPublic // 非公海用户
|
|
|
// cusTomer.DeptId = c.GetCxtUserDeptId() // 部门id
|
|
|
@@ -76,7 +82,10 @@ func (c *customerService) Create(req *model.Customer) (insertId int64, err error
|
|
|
err = gerror.New("创建失败")
|
|
|
return
|
|
|
}
|
|
|
+ //
|
|
|
+
|
|
|
insertId, _ = res.LastInsertId()
|
|
|
+
|
|
|
//销售人员创建条件成立 同步belong 表
|
|
|
//custBelong := new(model.AddCustomerBelong)
|
|
|
//custBelong.CustId = int(insertId)
|
|
|
@@ -88,7 +97,7 @@ func (c *customerService) Create(req *model.Customer) (insertId int64, err error
|
|
|
}
|
|
|
|
|
|
//销售人员创建 直接认领客户
|
|
|
-func (c *customerService) CreateBelong(req *model.AddCustomerBelong) (err error) {
|
|
|
+func (c *CustomerService) CreateBelong(req *model.AddCustomerBelong) (err error) {
|
|
|
cusTomerBelong := new(model.CustCustomerBelong)
|
|
|
if err = gconv.Struct(req, cusTomerBelong); err != nil {
|
|
|
g.Log().Info("error", err)
|
|
|
@@ -110,14 +119,17 @@ func (c *customerService) CreateBelong(req *model.AddCustomerBelong) (err error)
|
|
|
}
|
|
|
|
|
|
//客户列表列表
|
|
|
-func (c *customerService) GetList(req *model.CustCustomerSearchReq) (total int, customerList []*model.CustList, err error) {
|
|
|
+func (c *CustomerService) GetList(req *model.CustCustomerSearchReq) (total int, customerList []*model.CustList, err error) {
|
|
|
g.Log().Info("serverS", req)
|
|
|
Model := c.Dao.M
|
|
|
- if !req.IsPublic {
|
|
|
- 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)
|
|
|
+ Model = Model.Where(c.Dao.Columns.DeletedTime + " is null")
|
|
|
+ if req.TargetType != "" {
|
|
|
+ if !req.IsPublic {
|
|
|
+ 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)
|
|
|
+ }
|
|
|
}
|
|
|
//客户名称
|
|
|
if req.CustName != "" {
|
|
|
@@ -148,10 +160,93 @@ func (c *customerService) GetList(req *model.CustCustomerSearchReq) (total int,
|
|
|
return
|
|
|
}
|
|
|
|
|
|
-//
|
|
|
+//删除客户
|
|
|
+func (c *CustomerService) DeleteById(id int) error {
|
|
|
+
|
|
|
+ Model := c.Dao.M
|
|
|
+ ContactModel := c.ContactDao //联系人
|
|
|
+ regionDetail := new(model.CustCustomer)
|
|
|
+ err := Model.Where(c.Dao.Columns.Id, id).Scan(®ionDetail)
|
|
|
+ //g.Log().Info("DeleteByIds", one)
|
|
|
+ if err != nil {
|
|
|
+ g.Log().Error(err)
|
|
|
+ err = gerror.New("没有要删除的数据")
|
|
|
+ return err
|
|
|
+ }
|
|
|
+ deleteTime := gtime.Now()
|
|
|
+ //删除客户表
|
|
|
+ _, err = Model.Data(g.Map{
|
|
|
+ "deleted_time": deleteTime,
|
|
|
+ }).Where(c.Dao.Columns.Id, id).Update()
|
|
|
+ // 删除客户联系人表
|
|
|
+ _, err = ContactModel.Data(g.Map{
|
|
|
+ "deleted_time": deleteTime,
|
|
|
+ }).Where(c.ContactDao.Columns.CustId, id).Update()
|
|
|
+
|
|
|
+ if err != nil {
|
|
|
+ g.Log().Error(err)
|
|
|
+ err = gerror.New("删除数据失败")
|
|
|
+ return err
|
|
|
+ }
|
|
|
+ return nil
|
|
|
+}
|
|
|
+
|
|
|
+//修改客户
|
|
|
+func (c *CustomerService) UpdateById(req *model.UpdateCustomer) (err error) {
|
|
|
+ db := c.Dao.M
|
|
|
+ record, err := db.FindOne(c.Dao.Columns.Id, req.Id)
|
|
|
+ if err != nil || record.IsEmpty() {
|
|
|
+ err = gerror.New("该数据不存在")
|
|
|
+ return err
|
|
|
+ }
|
|
|
+ CustomertData := new(model.Customer)
|
|
|
+ if err = gconv.Struct(req, CustomertData); err != nil {
|
|
|
+ return
|
|
|
+ }
|
|
|
+ service.SetUpdatedInfo(CustomertData, c.GetCxtUserId(), c.GetCxtUserName())
|
|
|
+ _, err = db.FieldsEx(c.Dao.Columns.CreatedTime, c.Dao.Columns.CreatedBy, c.Dao.Columns.CreatedName, c.Dao.Columns.Id, c.Dao.Columns.CustCode, c.Dao.Columns.SalesName, c.Dao.Columns.SalesId).
|
|
|
+ WherePri(c.Dao.Columns.Id, req.Id).Update(CustomertData)
|
|
|
+
|
|
|
+ if err != nil {
|
|
|
+ g.Log().Error(err)
|
|
|
+ err = gerror.New("修改用户信息失败")
|
|
|
+ return
|
|
|
+ }
|
|
|
+ return
|
|
|
+}
|
|
|
+
|
|
|
+//移入公海
|
|
|
+func (c *CustomerService) MoveToPubic(ids []int64) error {
|
|
|
+ Model := c.Dao.M
|
|
|
+ //Cust := new(model.CustCustomer)
|
|
|
+ list, err := Model.Fields(c.Dao.Columns.CreatedTime).Where(c.Dao.Columns.Id+" in (?) ", ids).All()
|
|
|
+ if err != nil || list.Len() <= 0 {
|
|
|
+ g.Log().Error(err)
|
|
|
+ err = gerror.New("没有要移除的数据")
|
|
|
+ return err
|
|
|
+ }
|
|
|
+ _, err = Model.Data(g.Map{
|
|
|
+ "is_public": isPublic,
|
|
|
+ "sales_id": 0,
|
|
|
+ "sales_name": "",
|
|
|
+ "dept_id": 0,
|
|
|
+ "dept_name": "",
|
|
|
+ "create_time": gtime.Now(),
|
|
|
+ "updated_by": c.GetCxtUserId(),
|
|
|
+ "updated_name": c.GetCxtUserName(),
|
|
|
+ "updated_time": gtime.Now(),
|
|
|
+ }).Where(c.ContactDao.Columns.Id+" in (?)", ids).Update()
|
|
|
+
|
|
|
+ if err != nil {
|
|
|
+ g.Log().Error(err)
|
|
|
+ err = gerror.New("移入公海失败")
|
|
|
+ return err
|
|
|
+ }
|
|
|
+ return nil
|
|
|
+}
|
|
|
|
|
|
//分配客户
|
|
|
-func (c *customerService) DistriCustomer(req *model.DistriCustomer) error {
|
|
|
+func (c *CustomerService) DistriCustomer(req *model.DistriCustomer) error {
|
|
|
/**
|
|
|
待写逻辑(销售总监或销售助理将公海客户分配给指定销售工程师)
|
|
|
if c.user.id != 销售总监 || c.user.id!=销售助理 {
|
|
|
@@ -167,21 +262,29 @@ func (c *customerService) DistriCustomer(req *model.DistriCustomer) error {
|
|
|
err = gerror.New("该数据不存在")
|
|
|
return err
|
|
|
}
|
|
|
- err = c.UpdateCustomer(req.Ids, req.SalesId, isAllocation)
|
|
|
+ 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
|
|
|
+ maps["opn_type"] = AllocaTion
|
|
|
+ maps["sale_name"] = req.SalesName
|
|
|
+ err = c.belongInsters(rep.List(), maps)
|
|
|
+ if err != nil {
|
|
|
+ err = gerror.New("转移客户失败")
|
|
|
+ return err
|
|
|
+ }
|
|
|
return nil
|
|
|
}
|
|
|
|
|
|
//客户详情
|
|
|
-func (c *customerService) GetEntityById(id int64) (entityInfo []*model.CustCustomer, err error) {
|
|
|
+func (c *CustomerService) GetEntityById(ids []int64) (entityInfo []*model.CustList, err error) {
|
|
|
Model := c.Dao.M
|
|
|
|
|
|
- err = Model.Where(cust.CustCustomer.Columns.Id, id).WithAll().Scan(&entityInfo)
|
|
|
+ err = Model.Where(cust.CustCustomer.Columns.Id+" in (?)", ids).Scan(&entityInfo)
|
|
|
if err != nil {
|
|
|
g.Log().Error(err)
|
|
|
return nil, gerror.New("获取用户数据失败")
|
|
|
@@ -190,74 +293,44 @@ func (c *customerService) GetEntityById(id int64) (entityInfo []*model.CustCusto
|
|
|
}
|
|
|
|
|
|
//转移客户
|
|
|
-func (c *customerService) UpdateBytransfer(req *model.CustSalesReq) (entityInfo []*model.CustCustomer, err error) {
|
|
|
+func (c *CustomerService) UpdateBytransfer(req *model.CustSalesReq) (entityInfo []*model.CustCustomer, err error) {
|
|
|
custModel := c.Dao.M
|
|
|
rep, err := custModel.Fields("sales_id,sales_name,id").Where(cust.CustCustomer.Columns.Id+" in (?)", req.Ids).All()
|
|
|
if err != nil || rep.IsEmpty() {
|
|
|
err = gerror.New("该数据不存在")
|
|
|
return
|
|
|
}
|
|
|
- err = c.UpdateCustomer(req.Ids, req.SalesIds, isTransfer)
|
|
|
+ err = c.updateCustomer(req.Ids, req.SalesIds, req.SalesName)
|
|
|
if err != nil {
|
|
|
err = gerror.New("转移客户失败")
|
|
|
return
|
|
|
}
|
|
|
- belongModel := c.BelongDao.M
|
|
|
- maps := []map[string]interface{}{}
|
|
|
- date_time := gtime.Now()
|
|
|
- for _, v := range rep {
|
|
|
- old_id := v.GMap().Get("id")
|
|
|
- orig_sale_name := v.GMap().Get("sales_name")
|
|
|
- g.Log().Info("orig_sale_name", orig_sale_name)
|
|
|
- belong := map[string]interface{}{}
|
|
|
- belong["cust_id"] = old_id.(int)
|
|
|
- belong["sale_name"] = ""
|
|
|
- belong["orig_sale_name"] = orig_sale_name
|
|
|
- belong["opn_type"] = "20"
|
|
|
- belong["opn_people"] = 1
|
|
|
- belong["opn_datetime"] = date_time
|
|
|
- belong["created_by"] = 1
|
|
|
- belong["remark"] = req.Remark
|
|
|
- belong["created_name"] = "admin"
|
|
|
- belong["created_time"] = date_time
|
|
|
- belong["opn_datetime"] = date_time
|
|
|
- maps = append(maps, belong)
|
|
|
- }
|
|
|
- _, err = belongModel.Insert(maps)
|
|
|
+
|
|
|
+ var maps = make(map[string]string)
|
|
|
+ maps["remark"] = req.Remark
|
|
|
+ maps["opn_type"] = OperaTion
|
|
|
+ maps["sale_name"] = req.SalesName
|
|
|
+ err = c.belongInsters(rep.List(), maps)
|
|
|
if err != nil {
|
|
|
err = gerror.New("转移客户失败")
|
|
|
return
|
|
|
}
|
|
|
-
|
|
|
return
|
|
|
}
|
|
|
|
|
|
//变更客户所属关系
|
|
|
-func (c *customerService) UpdateCustomer(ids []int64, salesId int64, behavior int8) error {
|
|
|
+func (c *CustomerService) updateCustomer(ids []int64, salesId int64, salesName string) error {
|
|
|
custModel := c.Dao.M
|
|
|
- custCustomerData := new(model.CustCustomer)
|
|
|
- custCustomerData.SalesId = int(salesId)
|
|
|
- switch behavior {
|
|
|
- case 1:
|
|
|
- custCustomerData.SalesName = "转移销售"
|
|
|
- custCustomerData.IsPublic = isPublic
|
|
|
- case 2:
|
|
|
- custCustomerData.SalesName = "分配销售"
|
|
|
- custCustomerData.IsPublic = noPublic
|
|
|
- }
|
|
|
- service.SetUpdatedInfo(custCustomerData, c.GetCxtUserId(), c.GetCxtUserName())
|
|
|
- _, err := custModel.FieldsEx(
|
|
|
- cust.CustCustomer.Columns.CustCode,
|
|
|
- cust.CustCustomer.Columns.CustName,
|
|
|
- cust.CustCustomer.Columns.AbbrName,
|
|
|
- cust.CustCustomer.Columns.CustLocation,
|
|
|
- cust.CustCustomer.Columns.Id,
|
|
|
- cust.CustCustomer.Columns.CustAddress,
|
|
|
- cust.CustCustomer.Columns.CreatedTime,
|
|
|
- cust.CustCustomer.Columns.CustStatus,
|
|
|
- cust.CustCustomer.Columns.CreatedBy,
|
|
|
- cust.CustCustomer.Columns.CreatedName).
|
|
|
- WherePri(cust.CustCustomer.Columns.Id+" in (?)", ids).Update(custCustomerData)
|
|
|
+
|
|
|
+ _, err := custModel.Data(g.Map{
|
|
|
+ "sales_id": salesId,
|
|
|
+ "is_public": noPublic,
|
|
|
+ "sales_name": salesName,
|
|
|
+ "updated_by": c.GetCxtUserId(),
|
|
|
+ "updated_name": c.GetCxtUserName(),
|
|
|
+ "updated_time": gtime.Now(),
|
|
|
+ }).Where(cust.CustCustomer.Columns.Id+" in (?)", ids).Update()
|
|
|
+
|
|
|
if err != nil {
|
|
|
g.Log().Error(err)
|
|
|
err = gerror.New("变更失败")
|
|
|
@@ -267,15 +340,33 @@ func (c *customerService) UpdateCustomer(ids []int64, salesId int64, behavior in
|
|
|
}
|
|
|
|
|
|
//客户操作日志
|
|
|
-func (c *customerService) OperationLog(req *model.AddCustomerDynameicsReq) (err error) {
|
|
|
+func (c *CustomerService) OperationLog(ctx context.Context, ids []int64, req *model.AddCustomerDynameicsReq) (err error) {
|
|
|
+ g.Log("fdasfsa", gconv.String(ctx))
|
|
|
cusDynameics := new(model.CustCustomerDynamics)
|
|
|
if err = gconv.Struct(req, cusDynameics); err != nil {
|
|
|
g.Log().Info("error", err)
|
|
|
return
|
|
|
}
|
|
|
- Model := c.Dao.M
|
|
|
- service.SetCreatedInfo(cusDynameics, c.GetCxtUserId(), c.GetCxtUserName())
|
|
|
- _, err = Model.Insert(cusDynameics)
|
|
|
+ Model := c.DynamicsDao.M
|
|
|
+ g.Log().Info("IDS", ids)
|
|
|
+
|
|
|
+ maps := []map[string]interface{}{}
|
|
|
+ for _, v := range ids {
|
|
|
+ contact := map[string]interface{}{}
|
|
|
+ contact["cust_id"] = v
|
|
|
+ contact["opn_people_id"] = c.GetCxtUserId()
|
|
|
+ contact["opn_people"] = c.GetCxtUserName()
|
|
|
+ contact["opn_date"] = req.OpnDate
|
|
|
+ contact["opn_type"] = req.OpnType
|
|
|
+ contact["remark"] = ""
|
|
|
+ contact["created_by"] = c.GetCxtUserId()
|
|
|
+ contact["created_name"] = c.GetCxtUserName()
|
|
|
+ contact["created_by"] = c.GetCxtUserId()
|
|
|
+ contact["created_time"] = gtime.Now()
|
|
|
+ contact["opn_content"] = req.OpnContent
|
|
|
+ maps = append(maps, contact)
|
|
|
+ }
|
|
|
+ _, err = Model.Insert(maps)
|
|
|
if err != nil {
|
|
|
g.Log().Error(err)
|
|
|
err = gerror.New("创建失败")
|
|
|
@@ -284,13 +375,165 @@ func (c *customerService) OperationLog(req *model.AddCustomerDynameicsReq) (err
|
|
|
return
|
|
|
}
|
|
|
|
|
|
-//日志详情
|
|
|
-func (c *customerService) OperationLogInfo(id int64) (dynamics *model.CustomerDynameicsRep, err error) {
|
|
|
- Model := c.Dao.M
|
|
|
- err = Model.Where(cust.CustCustomerDynamics.Columns.Id, id).Scan(&dynamics)
|
|
|
+//客户动态
|
|
|
+func (c *CustomerService) DynamicsList(req *model.CustomerDynameicsReq) (total int, result []interface{}, err error) {
|
|
|
+ Model := c.DynamicsDao.M
|
|
|
+ total, err = Model.Fields().Count()
|
|
|
if err != nil {
|
|
|
g.Log().Error(err)
|
|
|
- return nil, gerror.New("获取用户数据失败")
|
|
|
+ err = gerror.New("获取总行数失败")
|
|
|
+ return
|
|
|
+ }
|
|
|
+ if req.PageNum == 0 {
|
|
|
+ req.PageNum = 1
|
|
|
+ }
|
|
|
+ dynamics := []*model.CustomerDynameicsRep{}
|
|
|
+ err = Model.Page(req.PageNum, req.PageSize).Where("cust_id = ", req.CustId).Order("id desc").Scan(&dynamics)
|
|
|
+ dynamicsList := make(map[string][]*model.CustomerDynameicsRep)
|
|
|
+
|
|
|
+ for _, v := range dynamics {
|
|
|
+ gt1 := gtime.New(v.OpnDate)
|
|
|
+ opnDate := gt1.Format("Y-m-d")
|
|
|
+ dynamicsList[opnDate] = append(dynamicsList[opnDate], &model.CustomerDynameicsRep{
|
|
|
+ OpnPeople: v.OpnPeople,
|
|
|
+ OpnDate: v.OpnDate,
|
|
|
+ OpnType: v.OpnType,
|
|
|
+ OpnContent: v.OpnContent,
|
|
|
+ })
|
|
|
+
|
|
|
+ }
|
|
|
+ g.Log().Info("DynamicsList----", dynamicsList)
|
|
|
+ result = append(result, dynamicsList)
|
|
|
+ return
|
|
|
+}
|
|
|
+
|
|
|
+//合并客户
|
|
|
+func (c *CustomerService) Mergecustomer(req *model.MergecustomerRep) (err error) {
|
|
|
+ Model := c.Dao.M
|
|
|
+ ContactModel := c.ContactDao.M
|
|
|
+ BelongDao := c.BelongDao.M
|
|
|
+ //当前目标客户是否存在
|
|
|
+ FindOne, err := Model.Where(c.Dao.Columns.DeletedTime+" is null").Where(c.Dao.Columns.Id, req.Id).FindOne()
|
|
|
+ if err != nil || FindOne.IsEmpty() {
|
|
|
+ err = gerror.New("该数据不存在")
|
|
|
+ return
|
|
|
+ }
|
|
|
+ //所选客户联系人信息
|
|
|
+ List, err := ContactModel.Where(c.ContactDao.Columns.CustId+" in (?)", req.ChooseId).All()
|
|
|
+ g.Log().Info("list", List.List())
|
|
|
+ CustomertData := new(model.Customer)
|
|
|
+ if err = gconv.Struct(req, CustomertData); err != nil {
|
|
|
+ return
|
|
|
+ }
|
|
|
+ service.SetUpdatedInfo(CustomertData, c.GetCxtUserId(), c.GetCxtUserName())
|
|
|
+ _, err = Model.FieldsEx(c.Dao.Columns.CreatedTime, c.Dao.Columns.CreatedBy,
|
|
|
+ c.Dao.Columns.CreatedName, c.Dao.Columns.Id,
|
|
|
+ c.Dao.Columns.CustCode,
|
|
|
+ c.Dao.Columns.SalesName,
|
|
|
+ c.Dao.Columns.SalesId).WherePri(c.Dao.Columns.Id, req.Id).Update(CustomertData)
|
|
|
+ if err != nil {
|
|
|
+ err = gerror.New("合并失败")
|
|
|
+ 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 {
|
|
|
+ err = c.belongInster(req.Id, req.ChooseId, req.Customer.SalesName)
|
|
|
+ if err != nil {
|
|
|
+ err = gerror.New("合并失败")
|
|
|
+ return
|
|
|
+ }
|
|
|
+ }
|
|
|
+ return
|
|
|
+}
|
|
|
+
|
|
|
+//联系人
|
|
|
+func (c *CustomerService) contactInster(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{}{}
|
|
|
+ for _, v := range list {
|
|
|
+ contact := map[string]interface{}{}
|
|
|
+ contact["cust_id"] = id
|
|
|
+ contact["cuct_name"] = v["cuct_name"]
|
|
|
+ contact["cuct_gender"] = v["cuct_gender"]
|
|
|
+ contact["postion"] = v["postion"]
|
|
|
+ contact["telephone"] = v["telephone"]
|
|
|
+ contact["wechat"] = v["wechat"]
|
|
|
+ contact["email"] = v["email"]
|
|
|
+ contact["policy"] = v["policy"]
|
|
|
+ contact["remark"] = v["remark"]
|
|
|
+ contact["created_by"] = v["created_by"]
|
|
|
+ contact["created_name"] = v["created_name"]
|
|
|
+ contact["created_time"] = v["created_time"]
|
|
|
+ maps = append(maps, contact)
|
|
|
+ }
|
|
|
+ _, err = ContactModel.Insert(maps)
|
|
|
+ if err != nil {
|
|
|
+ err = gerror.New("操作失败")
|
|
|
+ g.Log().Info("contactInster", err)
|
|
|
+ return
|
|
|
+
|
|
|
+ }
|
|
|
+
|
|
|
+ return
|
|
|
+}
|
|
|
+
|
|
|
+//销售
|
|
|
+func (c *CustomerService) belongInster(Id int, BelongIds []int64, SaleName string) (err error) {
|
|
|
+ BelongDao := c.BelongDao.M
|
|
|
+ BelongDao.Data(g.Map{"deleted_time": gtime.Now()}).Where(c.BelongDao.Columns.CustId+" in (?)", BelongIds).Update()
|
|
|
+ BelongData := new(model.CustCustomerBelong)
|
|
|
+ BelongData.CustId = Id
|
|
|
+ service.SetCreatedInfo(BelongData, c.GetCxtUserId(), c.GetCxtUserName())
|
|
|
+ BelongData.SaleName = SaleName
|
|
|
+ BelongData.OpnType = AllocaTion
|
|
|
+ BelongData.OrigSaleName = ""
|
|
|
+ BelongData.OpnPeople = "admin"
|
|
|
+ BelongData.OpnDatetime = gtime.Now()
|
|
|
+ _, err = BelongDao.Insert(BelongData)
|
|
|
+ if err != nil {
|
|
|
+ g.Log().Info("BeloongInster", err)
|
|
|
+ err = gerror.New("操作失败")
|
|
|
+ return
|
|
|
+ }
|
|
|
+ return
|
|
|
+}
|
|
|
+
|
|
|
+//批量插入客户归属记录表
|
|
|
+func (c *CustomerService) belongInsters(rep []map[string]interface{}, parameter map[string]string) (err error) {
|
|
|
+ belongModel := c.BelongDao.M
|
|
|
+ maps := []map[string]interface{}{}
|
|
|
+ date_time := gtime.Now()
|
|
|
+ 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"] = 1
|
|
|
+ belong["opn_datetime"] = date_time
|
|
|
+ belong["created_by"] = 1
|
|
|
+ belong["remark"] = parameter["remark"]
|
|
|
+ belong["created_name"] = "admin"
|
|
|
+ belong["created_time"] = date_time
|
|
|
+ belong["opn_datetime"] = date_time
|
|
|
+ maps = append(maps, belong)
|
|
|
+ }
|
|
|
+ _, err = belongModel.Insert(maps)
|
|
|
+ if err != nil {
|
|
|
+ err = gerror.New("插入失败")
|
|
|
+ return err
|
|
|
+ }
|
|
|
+
|
|
|
return
|
|
|
}
|