|
|
@@ -14,7 +14,7 @@ import (
|
|
|
"dashoo.cn/micro/app/service"
|
|
|
)
|
|
|
|
|
|
-type customerService struct {
|
|
|
+type CustomerService struct {
|
|
|
*service.ContextService
|
|
|
Dao *cust.CustCustomerDao
|
|
|
BelongDao *cust.CustCustomerBelongDao
|
|
|
@@ -31,8 +31,8 @@ type OpnType struct {
|
|
|
OperaTion string
|
|
|
}
|
|
|
|
|
|
-func NewCustomerService(ctx context.Context) (svc *customerService, err error) {
|
|
|
- svc = new(customerService)
|
|
|
+func NewCustomerService(ctx context.Context) (svc *CustomerService, err error) {
|
|
|
+ svc = new(CustomerService)
|
|
|
if svc.ContextService, err = svc.Init(ctx); err != nil {
|
|
|
return nil, err
|
|
|
}
|
|
|
@@ -44,7 +44,7 @@ func NewCustomerService(ctx context.Context) (svc *customerService, err error) {
|
|
|
}
|
|
|
|
|
|
//创建客户
|
|
|
-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)
|
|
|
g.Log().Info(err)
|
|
|
Model := c.Dao.M
|
|
|
@@ -68,6 +68,7 @@ func (c *customerService) Create(req *model.Customer) (insertId int64, err error
|
|
|
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
|
|
|
@@ -84,21 +85,7 @@ func (c *customerService) Create(req *model.Customer) (insertId int64, err error
|
|
|
//
|
|
|
|
|
|
insertId, _ = res.LastInsertId()
|
|
|
- //操作动态
|
|
|
- custDynameics := new(model.AddCustomerDynameicsReq)
|
|
|
- custDynameics.OpnPeopleId = c.GetCxtUserId()
|
|
|
- custDynameics.OpnPeople = c.GetCxtUserName()
|
|
|
- custDynameics.OpnDate = gtime.Now()
|
|
|
- custDynameics.OpnType = "创建客户"
|
|
|
- g.Log().Info("log----", cusTomer)
|
|
|
- log := map[string]interface{}{}
|
|
|
- log["CustName"] = req.CustName
|
|
|
- log["CustLocation"] = req.CustLocation
|
|
|
- log["CustAddress"] = req.CustAddress
|
|
|
- log["Remark"] = req.Remark
|
|
|
- log["custId"] = insertId
|
|
|
- custDynameics.OpnContent = log
|
|
|
- c.OperationLog(custDynameics)
|
|
|
+
|
|
|
//销售人员创建条件成立 同步belong 表
|
|
|
//custBelong := new(model.AddCustomerBelong)
|
|
|
//custBelong.CustId = int(insertId)
|
|
|
@@ -110,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)
|
|
|
@@ -132,7 +119,7 @@ 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
|
|
|
Model = Model.Where(c.Dao.Columns.DeletedTime + " is null")
|
|
|
@@ -172,9 +159,10 @@ func (c *customerService) GetList(req *model.CustCustomerSearchReq) (total int,
|
|
|
}
|
|
|
|
|
|
//删除客户
|
|
|
-func (c *customerService) DeleteById(id int) error {
|
|
|
+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)
|
|
|
@@ -183,13 +171,16 @@ func (c *customerService) DeleteById(id int) error {
|
|
|
err = gerror.New("没有要删除的数据")
|
|
|
return err
|
|
|
}
|
|
|
- regionDetail.DeletedTime = gtime.Now()
|
|
|
+ deleteTime := gtime.Now()
|
|
|
+ //删除客户表
|
|
|
_, err = Model.Data(g.Map{
|
|
|
- "deleted_time": gtime.Now(),
|
|
|
+ "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()
|
|
|
|
|
|
- //_, err = Model.
|
|
|
- // WherePri(c.Dao.Columns.Id, id).Update(regionDetail)
|
|
|
if err != nil {
|
|
|
g.Log().Error(err)
|
|
|
err = gerror.New("删除数据失败")
|
|
|
@@ -199,9 +190,9 @@ func (c *customerService) DeleteById(id int) error {
|
|
|
}
|
|
|
|
|
|
//修改客户
|
|
|
-func (c *customerService) UpdateById(req *model.UpdateCustomer) (err error) {
|
|
|
+func (c *CustomerService) UpdateById(req *model.UpdateCustomer) (err error) {
|
|
|
db := c.Dao.M
|
|
|
- record, err := db.FindOne("Id", req.Id)
|
|
|
+ record, err := db.FindOne(c.Dao.Columns.Id, req.Id)
|
|
|
if err != nil || record.IsEmpty() {
|
|
|
err = gerror.New("该数据不存在")
|
|
|
return err
|
|
|
@@ -211,7 +202,7 @@ func (c *customerService) UpdateById(req *model.UpdateCustomer) (err error) {
|
|
|
return
|
|
|
}
|
|
|
service.SetUpdatedInfo(CustomertData, c.GetCxtUserId(), c.GetCxtUserName())
|
|
|
- _, err = db.FieldsEx(c.Dao.Columns.CreatedTime, c.Dao.Columns.CreatedBy, c.Dao.Columns.CreatedName).
|
|
|
+ _, 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 {
|
|
|
@@ -223,7 +214,7 @@ func (c *customerService) UpdateById(req *model.UpdateCustomer) (err error) {
|
|
|
}
|
|
|
|
|
|
//移入公海
|
|
|
-func (c *customerService) MoveToPubic(ids []int64) error {
|
|
|
+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()
|
|
|
@@ -243,6 +234,7 @@ func (c *customerService) MoveToPubic(ids []int64) error {
|
|
|
"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("移入公海失败")
|
|
|
@@ -252,7 +244,7 @@ func (c *customerService) MoveToPubic(ids []int64) error {
|
|
|
}
|
|
|
|
|
|
//分配客户
|
|
|
-func (c *customerService) DistriCustomer(req *model.DistriCustomer) error {
|
|
|
+func (c *CustomerService) DistriCustomer(req *model.DistriCustomer) error {
|
|
|
/**
|
|
|
待写逻辑(销售总监或销售助理将公海客户分配给指定销售工程师)
|
|
|
if c.user.id != 销售总监 || c.user.id!=销售助理 {
|
|
|
@@ -287,10 +279,10 @@ func (c *customerService) DistriCustomer(req *model.DistriCustomer) error {
|
|
|
}
|
|
|
|
|
|
//客户详情
|
|
|
-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("获取用户数据失败")
|
|
|
@@ -299,7 +291,7 @@ 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() {
|
|
|
@@ -325,7 +317,7 @@ func (c *customerService) UpdateBytransfer(req *model.CustSalesReq) (entityInfo
|
|
|
}
|
|
|
|
|
|
//变更客户所属关系
|
|
|
-func (c *customerService) updateCustomer(ids []int64, salesId int64, salesName string) error {
|
|
|
+func (c *CustomerService) updateCustomer(ids []int64, salesId int64, salesName string) error {
|
|
|
custModel := c.Dao.M
|
|
|
|
|
|
_, err := custModel.Data(g.Map{
|
|
|
@@ -346,15 +338,33 @@ func (c *customerService) updateCustomer(ids []int64, salesId int64, salesName s
|
|
|
}
|
|
|
|
|
|
//客户操作日志
|
|
|
-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.DynamicsDao.M
|
|
|
- service.SetCreatedInfo(cusDynameics, c.GetCxtUserId(), c.GetCxtUserName())
|
|
|
- _, err = Model.Insert(cusDynameics)
|
|
|
+ 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("创建失败")
|
|
|
@@ -364,7 +374,7 @@ func (c *customerService) OperationLog(req *model.AddCustomerDynameicsReq) (err
|
|
|
}
|
|
|
|
|
|
//客户动态
|
|
|
-func (c *customerService) DynamicsList(req *model.CustomerDynameicsReq) (total int, dynamics []*model.CustomerDynameicsRep, err error) {
|
|
|
+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 {
|
|
|
@@ -375,12 +385,28 @@ func (c *customerService) DynamicsList(req *model.CustomerDynameicsReq) (total i
|
|
|
if req.PageNum == 0 {
|
|
|
req.PageNum = 1
|
|
|
}
|
|
|
- err = Model.Page(req.PageNum, req.PageSize).Order("id desc").Scan(&dynamics)
|
|
|
+ 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) {
|
|
|
+func (c *CustomerService) Mergecustomer(req *model.MergecustomerRep) (err error) {
|
|
|
Model := c.Dao.M
|
|
|
ContactModel := c.ContactDao.M
|
|
|
BelongDao := c.BelongDao.M
|
|
|
@@ -393,6 +419,21 @@ 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())
|
|
|
+ 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 {
|
|
|
@@ -413,9 +454,9 @@ 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) 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.Id+" in (?)", Ids).Update()
|
|
|
+ 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{}{}
|
|
|
@@ -445,9 +486,9 @@ func (c *customerService) contactInster(id int, Ids []int64, list []map[string]i
|
|
|
}
|
|
|
|
|
|
//销售
|
|
|
-func (c *customerService) belongInster(Id int, BelongIds []int64, SaleName string) (err error) {
|
|
|
+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.Id+" in (?)", BelongIds).Update()
|
|
|
+ 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())
|
|
|
@@ -466,7 +507,7 @@ func (c *customerService) belongInster(Id int, BelongIds []int64, SaleName strin
|
|
|
}
|
|
|
|
|
|
//批量插入客户归属记录表
|
|
|
-func (c *customerService) belongInsters(rep []map[string]interface{}, parameter map[string]string) (err error) {
|
|
|
+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()
|