|
@@ -5,8 +5,8 @@ import (
|
|
|
"context"
|
|
"context"
|
|
|
"math"
|
|
"math"
|
|
|
"strconv"
|
|
"strconv"
|
|
|
- "time"
|
|
|
|
|
|
|
|
|
|
|
|
+ "dashoo.cn/opms_libary/myerrors"
|
|
|
"github.com/360EntSecGroup-Skylar/excelize"
|
|
"github.com/360EntSecGroup-Skylar/excelize"
|
|
|
"github.com/gogf/gf/errors/gerror"
|
|
"github.com/gogf/gf/errors/gerror"
|
|
|
"github.com/gogf/gf/frame/g"
|
|
"github.com/gogf/gf/frame/g"
|
|
@@ -24,17 +24,19 @@ const TIME_LAYOUT = "2006-01-02 15:04:05"
|
|
|
|
|
|
|
|
type CustomerService struct {
|
|
type CustomerService struct {
|
|
|
*service.ContextService
|
|
*service.ContextService
|
|
|
- Dao *cust.CustCustomerDao
|
|
|
|
|
- BelongDao *cust.CustCustomerBelongDao
|
|
|
|
|
- DynamicsDao *cust.CustCustomerDynamicsDao
|
|
|
|
|
- ContactDao *cust.CustCustomerContactDao
|
|
|
|
|
- FollowDao *platdao.PlatFollowupDao
|
|
|
|
|
|
|
+ Dao *cust.CustCustomerDao
|
|
|
|
|
+ BelongDao *cust.CustCustomerBelongDao
|
|
|
|
|
+ DynamicsDao *cust.CustCustomerDynamicsDao
|
|
|
|
|
+ ContactDao *cust.CustCustomerContactDao
|
|
|
|
|
+ FollowDao *platdao.PlatFollowupDao
|
|
|
|
|
+ BelongServer *CustomerbelongService
|
|
|
|
|
+ ContanctServer *CustomercontactService
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
-var isPublic, noPublic = "10", "20" // 公海,非公海
|
|
|
|
|
-var isTransfer int8 = 1 //转移
|
|
|
|
|
-var isAllocation int8 = 2 //分配 Allocation
|
|
|
|
|
-var OperaTion, AllocaTion, Receive = "20", "10", "30"
|
|
|
|
|
|
|
+var isPublic, noPublic = "10", "20" // 公海,非公海
|
|
|
|
|
+var isTransfer int8 = 1 //转移
|
|
|
|
|
+var isAllocation int8 = 2 //分配 Allocation
|
|
|
|
|
+var OperaTion, AllocaTion, Receive, Merge = "20", "10", "30", "40" // 10分配20转移30领取40合并
|
|
|
|
|
|
|
|
type OpnType struct {
|
|
type OpnType struct {
|
|
|
OperaTion string
|
|
OperaTion string
|
|
@@ -50,140 +52,156 @@ func NewCustomerService(ctx context.Context) (svc *CustomerService, err error) {
|
|
|
svc.DynamicsDao = cust.NewCustCustomerDynamicsDao(svc.Tenant)
|
|
svc.DynamicsDao = cust.NewCustCustomerDynamicsDao(svc.Tenant)
|
|
|
svc.ContactDao = cust.NewCustCustomerContactDao(svc.Tenant)
|
|
svc.ContactDao = cust.NewCustCustomerContactDao(svc.Tenant)
|
|
|
svc.FollowDao = platdao.NewPlatFollowupDao(svc.Tenant)
|
|
svc.FollowDao = platdao.NewPlatFollowupDao(svc.Tenant)
|
|
|
|
|
+ svc.BelongServer, _ = NewCustomerBelongService(ctx)
|
|
|
|
|
+ svc.ContanctServer, _ = NewCustomerContactService(ctx)
|
|
|
return svc, nil
|
|
return svc, nil
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
-//导出数据
|
|
|
|
|
-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)
|
|
|
|
|
|
|
+//创建客户
|
|
|
|
|
+func (c *CustomerService) Create(req *model.CustomerAddSeq) (insertId int64, err error) {
|
|
|
|
|
+ cusTomer := new(model.CustCustomer)
|
|
|
|
|
+ count, err := c.Dao.Where(g.Map{"cust_name": req.CustName}).Count()
|
|
|
if err != nil {
|
|
if err != nil {
|
|
|
|
|
+ err = myerrors.New("Sql执行异常", err)
|
|
|
return
|
|
return
|
|
|
}
|
|
}
|
|
|
- f := excelize.NewFile()
|
|
|
|
|
- index := f.NewSheet("Sheet1")
|
|
|
|
|
- for index, item := range req.Columns {
|
|
|
|
|
- sheetPosition := service.Div(index+1) + "1"
|
|
|
|
|
- f.SetCellValue("Sheet1", sheetPosition, item)
|
|
|
|
|
|
|
+ if count > 0 {
|
|
|
|
|
+ err = myerrors.NewMsgError(nil, "该客户信息已存在,不可重复添加")
|
|
|
|
|
+ return
|
|
|
}
|
|
}
|
|
|
- if total > 0 {
|
|
|
|
|
|
|
|
|
|
- for ck, item := range data {
|
|
|
|
|
- for index, v := range req.Columns {
|
|
|
|
|
- if v == "经销商编码" {
|
|
|
|
|
- f.SetCellValue("Sheet1", service.Div(index+1)+strconv.Itoa(ck+2), item.CustCode)
|
|
|
|
|
- }
|
|
|
|
|
- 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 err = gconv.Struct(req, cusTomer); err != nil {
|
|
|
|
|
+ return
|
|
|
|
|
+ }
|
|
|
|
|
+ service.SetCreatedInfo(cusTomer, c.GetCxtUserId(), c.GetCxtUserName())
|
|
|
|
|
+ cusTomer.CustCode = "CT" + strconv.Itoa(int(gtime.Timestamp()))
|
|
|
|
|
+ cusTomer.CustStatus = "10"
|
|
|
|
|
|
|
|
|
|
+ Roles := c.GetCxtUserRoles()
|
|
|
|
|
+ roles := false
|
|
|
|
|
+ for _, v := range Roles {
|
|
|
|
|
+ if v == "Sales" { // 销售角色
|
|
|
|
|
+ roles = true
|
|
|
}
|
|
}
|
|
|
-
|
|
|
|
|
}
|
|
}
|
|
|
- f.SetActiveSheet(index)
|
|
|
|
|
-
|
|
|
|
|
- var buffer *bytes.Buffer
|
|
|
|
|
- buffer, _ = f.WriteToBuffer()
|
|
|
|
|
- con.Content = buffer.Bytes()
|
|
|
|
|
|
|
+ // 销售角色
|
|
|
|
|
+ if roles {
|
|
|
|
|
+ cusTomer.IsPublic = noPublic
|
|
|
|
|
+ cusTomer.SalesId = c.GetCxtUserId()
|
|
|
|
|
+ cusTomer.SalesName = c.GetCxtUserName()
|
|
|
|
|
+ insertId, err = c.Dao.InsertAndGetId(cusTomer)
|
|
|
|
|
+ if err != nil {
|
|
|
|
|
+ return
|
|
|
|
|
+ }
|
|
|
|
|
+ c.CreateContact(int(insertId))
|
|
|
|
|
|
|
|
- return &con, err
|
|
|
|
|
|
|
+ } else {
|
|
|
|
|
+ cusTomer.IsPublic = isPublic
|
|
|
|
|
+ insertId, err = c.Dao.InsertAndGetId(cusTomer)
|
|
|
|
|
+ if err != nil {
|
|
|
|
|
+ err = gerror.New("创建失败")
|
|
|
|
|
+ return
|
|
|
|
|
+ }
|
|
|
|
|
+ }
|
|
|
|
|
+ return
|
|
|
}
|
|
}
|
|
|
|
|
+func (c *CustomerService) CreateContact(cust_id int) (err error) {
|
|
|
|
|
+
|
|
|
|
|
+ belongData := new(model.CustCustomerBelong)
|
|
|
|
|
+ service.SetCreatedInfo(belongData, c.GetCxtUserId(), c.GetCxtUserName())
|
|
|
|
|
+ belongData.CustId = cust_id
|
|
|
|
|
+ belongData.SaleName = c.GetCxtUserName()
|
|
|
|
|
+ belongData.OpnType = AllocaTion
|
|
|
|
|
+ belongData.OpnPeople = c.GetCxtUserName()
|
|
|
|
|
+ belongData.OpnDatetime = gtime.Now()
|
|
|
|
|
+ _, err = c.BelongDao.InsertAndGetId(belongData)
|
|
|
|
|
+ if err != nil {
|
|
|
|
|
|
|
|
-//创建客户
|
|
|
|
|
-func (c *CustomerService) Create(req *model.Customer) (insertId int64, err error) {
|
|
|
|
|
- cusTomer := new(model.CustCustomer)
|
|
|
|
|
- g.Log().Info(err)
|
|
|
|
|
- Model := c.Dao.M
|
|
|
|
|
- record, err := Model.Where(g.Map{"cust_name": req.CustName}).One()
|
|
|
|
|
- g.Log().Info("recordE", record.IsEmpty())
|
|
|
|
|
- if err != nil || !record.IsEmpty() {
|
|
|
|
|
- err = gerror.New("该客户信息已存在,不可重复添加")
|
|
|
|
|
return
|
|
return
|
|
|
}
|
|
}
|
|
|
- //OpnPeopleId int ` json:"opnPeopleId"` // 操作人ID
|
|
|
|
|
- //OpnPeople string ` json:"opnPeople"` // 操作人
|
|
|
|
|
- //OpnDate *gtime.Time ` json:"opnDate"` // 操作日期
|
|
|
|
|
- //OpnType string ` json:"opnType"` // 操作类型
|
|
|
|
|
- //OpnContent string ` json:"opnContent"` // 操作内容
|
|
|
|
|
|
|
+ return
|
|
|
|
|
+}
|
|
|
|
|
|
|
|
- //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
|
|
|
|
|
- // cusTomer.DeptId = c.GetCxtUserDeptId() // 部门名称
|
|
|
|
|
- // cusTomer.SalesId = c.GetCxtUserId() // 销售id
|
|
|
|
|
- // cusTomer.SalesName = c.GetCxtUserName() // 销售名称
|
|
|
|
|
- //}
|
|
|
|
|
- res, err := Model.Insert(cusTomer)
|
|
|
|
|
|
|
+//删除客户
|
|
|
|
|
+func (c *CustomerService) DeleteById(id int) error {
|
|
|
|
|
+ Model := c.Dao
|
|
|
|
|
+ ContactModel := c.ContactDao //联系人
|
|
|
|
|
+ BelongModel := c.BelongDao
|
|
|
|
|
+ regionDetail := new(model.CustCustomer)
|
|
|
|
|
+ err := Model.Where(c.Dao.Columns.Id, id).Scan(®ionDetail)
|
|
|
if err != nil {
|
|
if err != nil {
|
|
|
g.Log().Error(err)
|
|
g.Log().Error(err)
|
|
|
- err = gerror.New("创建失败")
|
|
|
|
|
- return
|
|
|
|
|
|
|
+ err = gerror.New("没有要删除的数据")
|
|
|
|
|
+ return err
|
|
|
}
|
|
}
|
|
|
- //
|
|
|
|
|
-
|
|
|
|
|
- insertId, _ = res.LastInsertId()
|
|
|
|
|
|
|
|
|
|
- //销售人员创建条件成立 同步belong 表
|
|
|
|
|
- //custBelong := new(model.AddCustomerBelong)
|
|
|
|
|
- //custBelong.CustId = int(insertId)
|
|
|
|
|
- //custBelong.SaleName = "xxx"
|
|
|
|
|
- //custBelong.OpnPeople = "xxxx"
|
|
|
|
|
- //custBelong.OpnDatetime = gtime.Now()
|
|
|
|
|
- //err = c.CreateBelong()
|
|
|
|
|
- return
|
|
|
|
|
|
|
+ //删除客户表
|
|
|
|
|
+ _, err = Model.Where(c.Dao.Columns.Id, id).Delete()
|
|
|
|
|
+ if err == nil {
|
|
|
|
|
+ _, err = ContactModel.Where(c.ContactDao.Columns.CustId, id).Delete()
|
|
|
|
|
+ if err == nil {
|
|
|
|
|
+ _, err = BelongModel.Where(c.BelongDao.Columns.CustId, id).Delete()
|
|
|
|
|
+ if err != nil {
|
|
|
|
|
+ err = gerror.New("删除数据失败")
|
|
|
|
|
+ return err
|
|
|
|
|
+ }
|
|
|
|
|
+ } else {
|
|
|
|
|
+ err = gerror.New("删除数据失败")
|
|
|
|
|
+ return err
|
|
|
|
|
+ }
|
|
|
|
|
+ } else {
|
|
|
|
|
+ g.Log().Error(err)
|
|
|
|
|
+ err = gerror.New("删除数据失败")
|
|
|
|
|
+ return err
|
|
|
|
|
+ }
|
|
|
|
|
+ return nil
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
-//销售人员创建 直接认领客户
|
|
|
|
|
-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)
|
|
|
|
|
|
|
+//修改客户
|
|
|
|
|
+func (c *CustomerService) UpdateById(req *model.UpdateCustomer) (err error) {
|
|
|
|
|
+ db := c.Dao.M
|
|
|
|
|
+ count, err := db.Where(c.Dao.Columns.Id, req.Id).Count()
|
|
|
|
|
+ if err != nil {
|
|
|
|
|
+ err = gerror.New("修改用户信息失败")
|
|
|
return
|
|
return
|
|
|
}
|
|
}
|
|
|
- service.SetCreatedInfo(cusTomerBelong, c.GetCxtUserId(), c.GetCxtUserName())
|
|
|
|
|
-
|
|
|
|
|
- cusTomerBelong.OpnType = isPublic
|
|
|
|
|
- cusTomerBelong.OpnDatetime = gtime.Now()
|
|
|
|
|
- service.SetCreatedInfo(cusTomerBelong, c.GetCxtUserId(), c.GetCxtUserName())
|
|
|
|
|
- _, err = c.BelongDao.Insert(cusTomerBelong)
|
|
|
|
|
|
|
+ if count == 0 {
|
|
|
|
|
+ err = gerror.New("用户信息不存在")
|
|
|
|
|
+ return
|
|
|
|
|
+ }
|
|
|
|
|
+ countNums, err := db.Where(c.Dao.Columns.CustName+" = ", req.CustName).Where(c.Dao.Columns.Id+" not in (?)", req.Id).Count()
|
|
|
if err != nil {
|
|
if err != nil {
|
|
|
- g.Log().Error(err)
|
|
|
|
|
- err = gerror.New("创建失败")
|
|
|
|
|
|
|
+ err = gerror.New("修改用户信息失败")
|
|
|
|
|
+ return
|
|
|
|
|
+ }
|
|
|
|
|
+ if countNums > 0 {
|
|
|
|
|
+ err = gerror.New("客户名称已存在")
|
|
|
return
|
|
return
|
|
|
}
|
|
}
|
|
|
- return nil
|
|
|
|
|
|
|
|
|
|
|
|
+ CustomertData := new(model.CustomerAddSeq)
|
|
|
|
|
+ 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 {
|
|
|
|
|
+ err = gerror.New("修改用户信息失败")
|
|
|
|
|
+ return
|
|
|
|
|
+ }
|
|
|
|
|
+ return
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
//客户列表列表
|
|
//客户列表列表
|
|
|
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 := c.Dao.M
|
|
|
- Model = Model.Where(c.Dao.Columns.DeletedTime + " is null")
|
|
|
|
|
if req.TargetType == "" {
|
|
if req.TargetType == "" {
|
|
|
if !req.IsPublic {
|
|
if !req.IsPublic {
|
|
|
- g.Log().Info("ISPUblic", "xxxxxx")
|
|
|
|
|
|
|
+
|
|
|
Model = Model.Where(c.Dao.Columns.SalesId, c.CxtUser.Id).Where(c.Dao.Columns.IsPublic, noPublic)
|
|
Model = Model.Where(c.Dao.Columns.SalesId, c.CxtUser.Id).Where(c.Dao.Columns.IsPublic, noPublic)
|
|
|
} else {
|
|
} else {
|
|
|
- g.Log().Info("serverS", req)
|
|
|
|
|
|
|
+
|
|
|
Model = Model.Where(c.Dao.Columns.IsPublic, isPublic)
|
|
Model = Model.Where(c.Dao.Columns.IsPublic, isPublic)
|
|
|
}
|
|
}
|
|
|
}
|
|
}
|
|
@@ -217,7 +235,8 @@ func (c *CustomerService) GetList(req *model.CustCustomerSearchReq) (total int,
|
|
|
if req.PageNum == 0 {
|
|
if req.PageNum == 0 {
|
|
|
req.PageNum = 1
|
|
req.PageNum = 1
|
|
|
}
|
|
}
|
|
|
- err = Model.Page(req.PageNum, req.PageSize).Order("id desc").Scan(&customerList)
|
|
|
|
|
|
|
+
|
|
|
|
|
+ err = Model.Page(req.GetPage()).Order("id desc").Scan(&customerList)
|
|
|
for _, v := range customerList {
|
|
for _, v := range customerList {
|
|
|
times := gconv.String(v.CreatedTime)
|
|
times := gconv.String(v.CreatedTime)
|
|
|
v.FollowUpDate = gstr.SubStr(v.FollowUpDate, 0, 16)
|
|
v.FollowUpDate = gstr.SubStr(v.FollowUpDate, 0, 16)
|
|
@@ -226,65 +245,9 @@ func (c *CustomerService) GetList(req *model.CustCustomerSearchReq) (total int,
|
|
|
return
|
|
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 {
|
|
func (c *CustomerService) MoveToPubic(ids []int64) error {
|
|
|
Model := c.Dao.M
|
|
Model := c.Dao.M
|
|
|
- //Cust := new(model.CustCustomer)
|
|
|
|
|
list, err := Model.Fields(c.Dao.Columns.CreatedTime).Where(c.Dao.Columns.Id+" in (?) ", ids).All()
|
|
list, err := Model.Fields(c.Dao.Columns.CreatedTime).Where(c.Dao.Columns.Id+" in (?) ", ids).All()
|
|
|
if err != nil || list.Len() <= 0 {
|
|
if err != nil || list.Len() <= 0 {
|
|
|
g.Log().Error(err)
|
|
g.Log().Error(err)
|
|
@@ -313,29 +276,39 @@ func (c *CustomerService) MoveToPubic(ids []int64) error {
|
|
|
|
|
|
|
|
//分配客户
|
|
//分配客户
|
|
|
func (c *CustomerService) DistriCustomer(req *model.DistriCustomer) 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()
|
|
rep, err := custModel.Where(cust.CustCustomer.Columns.Id+" in (?) ", req.Ids).Where(cust.CustCustomer.Columns.IsPublic, isPublic).All()
|
|
|
if err != nil {
|
|
if err != nil {
|
|
|
- err = gerror.New("该数据不存在")
|
|
|
|
|
|
|
+ err = myerrors.New("DistriCustomer Sql执行异常", err)
|
|
|
return err
|
|
return err
|
|
|
}
|
|
}
|
|
|
|
|
+ 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)
|
|
err = c.updateCustomer(req.Ids, req.SalesId, req.SalesName)
|
|
|
if err != nil {
|
|
if err != nil {
|
|
|
err = gerror.New("可配客户失败")
|
|
err = gerror.New("可配客户失败")
|
|
|
return err
|
|
return err
|
|
|
|
|
|
|
|
}
|
|
}
|
|
|
- var maps = make(map[string]string)
|
|
|
|
|
- maps["remark"] = req.Remark
|
|
|
|
|
if req.Receive != "" {
|
|
if req.Receive != "" {
|
|
|
- maps["opn_type"] = AllocaTion
|
|
|
|
|
|
|
+ req.Receive = Receive
|
|
|
} else {
|
|
} 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 {
|
|
if err != nil {
|
|
|
err = gerror.New("分配客户失败")
|
|
err = gerror.New("分配客户失败")
|
|
|
return err
|
|
return err
|
|
@@ -345,59 +318,59 @@ func (c *CustomerService) DistriCustomer(req *model.DistriCustomer) error {
|
|
|
|
|
|
|
|
//客户详情
|
|
//客户详情
|
|
|
func (c *CustomerService) GetEntityById(ids []int64) (entityInfo []*model.CustList, err error) {
|
|
func (c *CustomerService) GetEntityById(ids []int64) (entityInfo []*model.CustList, err error) {
|
|
|
- Model := c.Dao.M //
|
|
|
|
|
- //FollowModel := c.FollowDao.M
|
|
|
|
|
-
|
|
|
|
|
|
|
+ Model := c.Dao //
|
|
|
err = Model.Where(cust.CustCustomer.Columns.Id+" in (?)", ids).Scan(&entityInfo)
|
|
err = Model.Where(cust.CustCustomer.Columns.Id+" in (?)", ids).Scan(&entityInfo)
|
|
|
|
|
+ if err != nil {
|
|
|
|
|
+ return nil, myerrors.New("获取用户数据失败", err)
|
|
|
|
|
+
|
|
|
|
|
+ }
|
|
|
for _, v := range entityInfo {
|
|
for _, v := range entityInfo {
|
|
|
v.FollowUpDate = gstr.SubStr(v.FollowUpDate, 0, 16)
|
|
v.FollowUpDate = gstr.SubStr(v.FollowUpDate, 0, 16)
|
|
|
v.CreatedTime = gstr.SubStr(v.CreatedTime, 0, 16)
|
|
v.CreatedTime = gstr.SubStr(v.CreatedTime, 0, 16)
|
|
|
}
|
|
}
|
|
|
- if err != nil {
|
|
|
|
|
- g.Log().Error(err)
|
|
|
|
|
- return nil, gerror.New("获取用户数据失败")
|
|
|
|
|
- }
|
|
|
|
|
|
|
+
|
|
|
return
|
|
return
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
//客户摘要
|
|
//客户摘要
|
|
|
func (c *CustomerService) CustAbstract(id int64) (followInfo *model.Follow, err error) {
|
|
func (c *CustomerService) CustAbstract(id int64) (followInfo *model.Follow, err error) {
|
|
|
- custModel := c.Dao.M //
|
|
|
|
|
- Model := c.FollowDao.M
|
|
|
|
|
-
|
|
|
|
|
|
|
+ custModel := c.Dao //
|
|
|
|
|
+ Model := c.FollowDao
|
|
|
count, err := Model.Where(c.FollowDao.Columns.CustId, id).Count()
|
|
count, err := Model.Where(c.FollowDao.Columns.CustId, id).Count()
|
|
|
- g.Log().Info("count", count)
|
|
|
|
|
if err != nil {
|
|
if err != nil {
|
|
|
- g.Log().Error(err)
|
|
|
|
|
- return nil, gerror.New("获取用户数据失败")
|
|
|
|
|
- }
|
|
|
|
|
|
|
|
|
|
|
|
+ err = myerrors.New("获取用户数据失败", err)
|
|
|
|
|
+ return
|
|
|
|
|
+ }
|
|
|
followInfo = new(model.Follow)
|
|
followInfo = new(model.Follow)
|
|
|
followInfo.FollowCount = count
|
|
followInfo.FollowCount = count
|
|
|
//
|
|
//
|
|
|
- find, err := custModel.Fields(c.Dao.Columns.FollowUpDate).Where(c.Dao.Columns.Id, id).FindOne()
|
|
|
|
|
- g.Log().Info("find", find)
|
|
|
|
|
|
|
|
|
|
|
|
+ followUpdate, err := custModel.Fields(c.Dao.Columns.FollowUpDate).FindOne(id)
|
|
|
if err != nil {
|
|
if err != nil {
|
|
|
- g.Log().Error(err)
|
|
|
|
|
- return nil, gerror.New("获取用户数据失败")
|
|
|
|
|
- }
|
|
|
|
|
-
|
|
|
|
|
- findOne := find.Map()
|
|
|
|
|
- if findOne["follow_up_date"] == "" {
|
|
|
|
|
- followInfo.NotFollowDay = 0
|
|
|
|
|
|
|
+ err = myerrors.New("CustAbstract Sql执行错误", err)
|
|
|
return
|
|
return
|
|
|
}
|
|
}
|
|
|
- upDate := gconv.String(findOne["follow_up_date"])
|
|
|
|
|
- follow_up, err1 := time.Parse(TIME_LAYOUT, upDate)
|
|
|
|
|
- now := gtime.Now()
|
|
|
|
|
- follow_next, err2 := time.Parse(TIME_LAYOUT, gconv.String(now))
|
|
|
|
|
- if err1 != nil || err2 != nil {
|
|
|
|
|
|
|
+ if followUpdate.FollowUpDate == nil {
|
|
|
followInfo.NotFollowDay = 0
|
|
followInfo.NotFollowDay = 0
|
|
|
return
|
|
return
|
|
|
}
|
|
}
|
|
|
- poor := follow_next.Sub(follow_up)
|
|
|
|
|
- g.Log().Info("xxxxfdsaf", follow_up)
|
|
|
|
|
|
|
+
|
|
|
|
|
+ g.Log().Info("fasa1211", followUpdate)
|
|
|
|
|
+ //g.Log().Info("find", followUpdate)
|
|
|
|
|
+ //if err != nil {
|
|
|
|
|
+ // g.Log().Error(err)
|
|
|
|
|
+ // myerrors.New("获取用户数据失败", err)
|
|
|
|
|
+ // return
|
|
|
|
|
+ //}
|
|
|
|
|
+ //if followUpdate.FollowUpDate != nil {
|
|
|
|
|
+ // followInfo.NotFollowDay = 0
|
|
|
|
|
+ // return
|
|
|
|
|
+ //}
|
|
|
|
|
+ upDate := gtime.New(followUpdate.FollowUpDate)
|
|
|
|
|
+ now := gtime.Now()
|
|
|
|
|
+ //
|
|
|
|
|
+ poor := now.Sub(upDate)
|
|
|
hours := float64(poor.Hours() / 24)
|
|
hours := float64(poor.Hours() / 24)
|
|
|
if hours < 0 {
|
|
if hours < 0 {
|
|
|
followInfo.NotFollowDay = 0
|
|
followInfo.NotFollowDay = 0
|
|
@@ -408,27 +381,26 @@ 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
|
|
|
|
|
- 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("该数据不存在")
|
|
|
|
|
|
|
+func (c *CustomerService) UpdateBytransfer(req *model.DistriCustomer) (err error) {
|
|
|
|
|
+ custModel := c.Dao
|
|
|
|
|
+ data, err := custModel.Fields("sales_id,sales_name,id").Where(cust.CustCustomer.Columns.Id+" in (?)", req.Ids).All()
|
|
|
|
|
+ if err != nil {
|
|
|
|
|
+ err = myerrors.New("Sql执行异常", err)
|
|
|
|
|
+ return err
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ if len(data) == 0 {
|
|
|
|
|
+ err = myerrors.New("该数据不存在", err)
|
|
|
return
|
|
return
|
|
|
}
|
|
}
|
|
|
- err = c.updateCustomer(req.Ids, req.SalesIds, req.SalesName)
|
|
|
|
|
|
|
+ err = c.updateCustomer(req.Ids, req.SalesId, req.SalesName)
|
|
|
if err != nil {
|
|
if err != nil {
|
|
|
- err = gerror.New("转移客户失败")
|
|
|
|
|
return
|
|
return
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
- 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)
|
|
|
|
|
|
|
+ err = c.Createbelong(data, req)
|
|
|
|
|
+ g.Log().Info("err", err)
|
|
|
if err != nil {
|
|
if err != nil {
|
|
|
- err = gerror.New("转移客户失败")
|
|
|
|
|
return
|
|
return
|
|
|
}
|
|
}
|
|
|
return
|
|
return
|
|
@@ -448,8 +420,7 @@ func (c *CustomerService) updateCustomer(ids []int64, salesId int64, salesName s
|
|
|
}).Where(cust.CustCustomer.Columns.Id+" in (?)", ids).Update()
|
|
}).Where(cust.CustCustomer.Columns.Id+" in (?)", ids).Update()
|
|
|
|
|
|
|
|
if err != nil {
|
|
if err != nil {
|
|
|
- g.Log().Error(err)
|
|
|
|
|
- err = gerror.New("变更失败")
|
|
|
|
|
|
|
+ err = myerrors.New("updateCustomer 变更执行失败", err)
|
|
|
return err
|
|
return err
|
|
|
}
|
|
}
|
|
|
return nil
|
|
return nil
|
|
@@ -482,10 +453,13 @@ func (c *CustomerService) OperationLog(ctx context.Context, ids []int64, req *mo
|
|
|
contact["opn_content"] = req.OpnContent
|
|
contact["opn_content"] = req.OpnContent
|
|
|
maps = append(maps, contact)
|
|
maps = append(maps, contact)
|
|
|
}
|
|
}
|
|
|
- _, err = Model.Insert(maps)
|
|
|
|
|
|
|
+ lastId, err := Model.InsertAndGetId(maps)
|
|
|
if err != nil {
|
|
if err != nil {
|
|
|
- g.Log().Error(err)
|
|
|
|
|
- err = gerror.New("创建失败")
|
|
|
|
|
|
|
+ err = myerrors.New("OperationLog Sql执行失败", err)
|
|
|
|
|
+ return
|
|
|
|
|
+ }
|
|
|
|
|
+ if lastId == 0 {
|
|
|
|
|
+ err = myerrors.New("客户操作日志失败", err)
|
|
|
return
|
|
return
|
|
|
}
|
|
}
|
|
|
return
|
|
return
|
|
@@ -500,11 +474,11 @@ func (c *CustomerService) DynamicsList(req *model.CustomerDynameicsReq) (total i
|
|
|
err = gerror.New("获取总行数失败")
|
|
err = gerror.New("获取总行数失败")
|
|
|
return
|
|
return
|
|
|
}
|
|
}
|
|
|
- if req.PageNum == 0 {
|
|
|
|
|
- req.PageNum = 1
|
|
|
|
|
- }
|
|
|
|
|
|
|
+ //if req.PageNum == 0 {
|
|
|
|
|
+ // req.PageNum = 1
|
|
|
|
|
+ //}
|
|
|
dynamics := []*model.CustomerDynameicsRep{}
|
|
dynamics := []*model.CustomerDynameicsRep{}
|
|
|
- err = Model.Page(req.PageNum, req.PageSize).Where("cust_id = ", req.CustId).Order("created_time desc").Scan(&dynamics)
|
|
|
|
|
|
|
+ err = Model.Where("cust_id = ", req.CustId).Order("created_time desc").Scan(&dynamics)
|
|
|
dynamicsList := make(map[string][]*model.CustomerDynameicsRep)
|
|
dynamicsList := make(map[string][]*model.CustomerDynameicsRep)
|
|
|
|
|
|
|
|
for _, v := range dynamics {
|
|
for _, v := range dynamics {
|
|
@@ -518,150 +492,178 @@ func (c *CustomerService) DynamicsList(req *model.CustomerDynameicsReq) (total i
|
|
|
})
|
|
})
|
|
|
|
|
|
|
|
}
|
|
}
|
|
|
- g.Log().Info("DynamicsList----", dynamics)
|
|
|
|
|
- //var ks []string
|
|
|
|
|
- //for k, _ := range dynamicsList {
|
|
|
|
|
- // ks = append(ks, k)
|
|
|
|
|
- //}
|
|
|
|
|
- //sort.Sort(sort.Reverse(ks))
|
|
|
|
|
- result = append(result, dynamicsList)
|
|
|
|
|
- //var sslice []string
|
|
|
|
|
- //for key, _ := range result {
|
|
|
|
|
- // sslice = append(sslice, key)
|
|
|
|
|
- //}
|
|
|
|
|
- //sort.Strings(sslice)
|
|
|
|
|
-
|
|
|
|
|
- g.Log().Info("Dy---", result)
|
|
|
|
|
|
|
+ //g.Log().Info("DynamicsList----", dynamicsList)
|
|
|
|
|
+ //result = append(result, dynamicsList)
|
|
|
|
|
+ //g.Log().Info("Dy---", result)
|
|
|
return
|
|
return
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
//合并客户
|
|
//合并客户
|
|
|
func (c *CustomerService) Mergecustomer(req *model.MergecustomerRep) (err error) {
|
|
func (c *CustomerService) Mergecustomer(req *model.MergecustomerRep) (err error) {
|
|
|
Model := c.Dao.M
|
|
Model := c.Dao.M
|
|
|
- ContactModel := c.ContactDao.M
|
|
|
|
|
- BelongDao := c.BelongDao.M
|
|
|
|
|
|
|
+ //ContactModel := c.ContactDao.M
|
|
|
|
|
+ BelongDao := c.BelongDao
|
|
|
//当前目标客户是否存在
|
|
//当前目标客户是否存在
|
|
|
FindOne, err := Model.Where(c.Dao.Columns.DeletedTime+" is null").Where(c.Dao.Columns.Id, req.Id).FindOne()
|
|
FindOne, err := Model.Where(c.Dao.Columns.DeletedTime+" is null").Where(c.Dao.Columns.Id, req.Id).FindOne()
|
|
|
if err != nil || FindOne.IsEmpty() {
|
|
if err != nil || FindOne.IsEmpty() {
|
|
|
err = gerror.New("该数据不存在")
|
|
err = gerror.New("该数据不存在")
|
|
|
return
|
|
return
|
|
|
}
|
|
}
|
|
|
- //所选客户联系人信息
|
|
|
|
|
- List, err := ContactModel.Where(c.ContactDao.Columns.CustId+" in (?)", req.ChooseId).All()
|
|
|
|
|
- g.Log().Info("list", List.List())
|
|
|
|
|
- CustomertData := new(model.Customer)
|
|
|
|
|
|
|
+ ContactModel := c.ContactDao
|
|
|
|
|
+ _, err = ContactModel.Where(c.ContactDao.Columns.CustId+" in (?)", req.ChooseId).WhereOr(c.ContactDao.Columns.CustId, req.Id).Delete()
|
|
|
|
|
+ if err != nil {
|
|
|
|
|
+ err = gerror.New("合并联系人失败")
|
|
|
|
|
+ return
|
|
|
|
|
+ }
|
|
|
|
|
+ CustomertData := new(model.CustomerAddSeq)
|
|
|
if err = gconv.Struct(req, CustomertData); err != nil {
|
|
if err = gconv.Struct(req, CustomertData); err != nil {
|
|
|
return
|
|
return
|
|
|
}
|
|
}
|
|
|
service.SetUpdatedInfo(CustomertData, c.GetCxtUserId(), c.GetCxtUserName())
|
|
service.SetUpdatedInfo(CustomertData, c.GetCxtUserId(), c.GetCxtUserName())
|
|
|
_, err = Model.FieldsEx(c.Dao.Columns.CreatedTime, c.Dao.Columns.CreatedBy,
|
|
_, err = Model.FieldsEx(c.Dao.Columns.CreatedTime, c.Dao.Columns.CreatedBy,
|
|
|
c.Dao.Columns.CreatedName, c.Dao.Columns.Id,
|
|
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)
|
|
|
|
|
|
|
+ c.Dao.Columns.CustCode).WherePri(c.Dao.Columns.Id, req.Id).Update(CustomertData)
|
|
|
if err != nil {
|
|
if err != nil {
|
|
|
err = gerror.New("合并失败")
|
|
err = gerror.New("合并失败")
|
|
|
return
|
|
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
|
|
|
|
|
- }
|
|
|
|
|
|
|
+ //删除被合并的客户信息
|
|
|
|
|
+ Model.Where(c.Dao.Columns.Id+" in (?)", req.ChooseId).Delete()
|
|
|
|
|
+ //删除 所选客户销售联系人
|
|
|
|
|
+ _, err = BelongDao.Where(c.BelongDao.Columns.CustId+" in (?)", req.ChooseId).WhereOr(c.BelongDao.Columns.CustId, req.Id).Delete()
|
|
|
|
|
+ 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
|
|
|
|
|
- }
|
|
|
|
|
|
|
+
|
|
|
|
|
+ //插入一条合并成功的归属记录
|
|
|
|
|
+ belongService := c.BelongServer //
|
|
|
|
|
+ req.AddCustomerBelong.CustId = req.Id
|
|
|
|
|
+ req.AddCustomerBelong.OpnType = Merge
|
|
|
|
|
+ req.AddCustomerBelong.OpnPeople = c.GetCxtUserName()
|
|
|
|
|
+ req.AddCustomerBelong.OpnDatetime = gtime.Now()
|
|
|
|
|
+ req.AddCustomerBelong.SaleName = req.SalesName
|
|
|
|
|
+ err = belongService.Create(req.AddCustomerBelong)
|
|
|
|
|
+ if err != nil {
|
|
|
|
|
+ err = gerror.New("合并失败")
|
|
|
|
|
+ return
|
|
|
}
|
|
}
|
|
|
return
|
|
return
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
-//联系人
|
|
|
|
|
-func (c *CustomerService) contactInster(id int, Ids []int64, list []map[string]interface{}) (err error) {
|
|
|
|
|
|
|
+//联系人(合并)
|
|
|
|
|
+func (c *CustomerService) Createcontact(id int, Ids []int64, req *model.CustCustomerContactSeq) (err error) {
|
|
|
ContactModel := c.ContactDao.M
|
|
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)
|
|
|
|
|
|
|
+ _, err = ContactModel.Where(c.ContactDao.Columns.CustId+" in (?)", Ids).WhereOr(c.ContactDao.Columns.CustId, id).Delete()
|
|
|
if err != nil {
|
|
if err != nil {
|
|
|
- err = gerror.New("操作失败")
|
|
|
|
|
- g.Log().Info("contactInster", err)
|
|
|
|
|
|
|
+ err = gerror.New("合并联系人失败")
|
|
|
return
|
|
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)
|
|
|
|
|
|
|
+ contactService := c.ContanctServer //new(CustomercontactService)
|
|
|
|
|
+ err = contactService.Create(req)
|
|
|
if err != nil {
|
|
if err != nil {
|
|
|
- g.Log().Info("BeloongInster", err)
|
|
|
|
|
- err = gerror.New("操作失败")
|
|
|
|
|
|
|
+ err = gerror.New("合并联系人失败")
|
|
|
return
|
|
return
|
|
|
}
|
|
}
|
|
|
return
|
|
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()
|
|
date_time := gtime.Now()
|
|
|
|
|
+ userName := c.GetCxtUserName()
|
|
|
for _, v := range rep {
|
|
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)
|
|
|
|
|
+ }
|
|
|
|
|
+ lastId, err := belongModel.InsertAndGetId(belongData)
|
|
|
|
|
+ g.Log().Info("belong", belongData)
|
|
|
if err != nil {
|
|
if err != nil {
|
|
|
- err = gerror.New("插入失败")
|
|
|
|
|
|
|
+ err = myerrors.New("Createbelong Sql执行异常", err)
|
|
|
|
|
+ return err
|
|
|
|
|
+ }
|
|
|
|
|
+ if lastId == 0 {
|
|
|
|
|
+ err = myerrors.New("Createbelong 插入", err)
|
|
|
return err
|
|
return err
|
|
|
}
|
|
}
|
|
|
-
|
|
|
|
|
return
|
|
return
|
|
|
}
|
|
}
|
|
|
|
|
+
|
|
|
|
|
+//导出数据
|
|
|
|
|
+func (c *CustomerService) Export(req *model.CustCustomerExport) (content *model.CustExport, err error) {
|
|
|
|
|
+ var con model.CustExport
|
|
|
|
|
+ total, data, err := c.GetList(&req.CustCustomerSearchReq)
|
|
|
|
|
+ if err != nil {
|
|
|
|
|
+ return
|
|
|
|
|
+ }
|
|
|
|
|
+ f := excelize.NewFile()
|
|
|
|
|
+ index := f.NewSheet("Sheet1")
|
|
|
|
|
+ for index, item := range req.Columns {
|
|
|
|
|
+ sheetPosition := service.Div(index+1) + "1"
|
|
|
|
|
+ f.SetCellValue("Sheet1", sheetPosition, item)
|
|
|
|
|
+ }
|
|
|
|
|
+ if total > 0 {
|
|
|
|
|
+
|
|
|
|
|
+ for ck, item := range data {
|
|
|
|
|
+ for index, v := range req.Columns {
|
|
|
|
|
+ // "CustCode":客户编码
|
|
|
|
|
+ if v == "客户编码" {
|
|
|
|
|
+ f.SetCellValue("Sheet1", service.Div(index+1)+strconv.Itoa(ck+2), item.CustCode)
|
|
|
|
|
+ }
|
|
|
|
|
+ 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.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)
|
|
|
|
|
+ }
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ }
|
|
|
|
|
+ f.SetActiveSheet(index)
|
|
|
|
|
+
|
|
|
|
|
+ var buffer *bytes.Buffer
|
|
|
|
|
+ buffer, _ = f.WriteToBuffer()
|
|
|
|
|
+ con.Content = buffer.Bytes()
|
|
|
|
|
+
|
|
|
|
|
+ return &con, err
|
|
|
|
|
+}
|