|
|
@@ -3,13 +3,15 @@ package cust
|
|
|
import (
|
|
|
"bytes"
|
|
|
"context"
|
|
|
- "dashoo.cn/opms_libary/plugin/dingtalk/workflow"
|
|
|
- "dashoo.cn/opms_libary/utils"
|
|
|
"fmt"
|
|
|
"math"
|
|
|
"strconv"
|
|
|
"strings"
|
|
|
|
|
|
+ "dashoo.cn/opms_libary/plugin/dingtalk/workflow"
|
|
|
+ "dashoo.cn/opms_libary/request"
|
|
|
+ "dashoo.cn/opms_libary/utils"
|
|
|
+
|
|
|
"dashoo.cn/opms_libary/myerrors"
|
|
|
"dashoo.cn/opms_libary/plugin/dingtalk/message"
|
|
|
"github.com/360EntSecGroup-Skylar/excelize"
|
|
|
@@ -290,52 +292,9 @@ func (s *CustomerService) UpdateById(req *model.UpdateCustomer) (err error) {
|
|
|
return
|
|
|
}
|
|
|
|
|
|
-// MoveToPubic 移入公海
|
|
|
-func (s *CustomerService) MoveToPubic(Ids []int64) (err error) {
|
|
|
- count, err := s.Dao.WhereIn(s.Dao.Columns.Id, Ids).Count()
|
|
|
- if err != nil {
|
|
|
- g.Log().Error(err)
|
|
|
- return
|
|
|
- }
|
|
|
- if count == 0 {
|
|
|
- err = myerrors.TipsError("没有要移除的数据")
|
|
|
- return
|
|
|
- }
|
|
|
- userName := s.GetCxtUserName()
|
|
|
- currentTime := gtime.Now() // 当前时间
|
|
|
- s.Dao.Transaction(context.TODO(), func(ctx context.Context, tx *gdb.TX) error {
|
|
|
- //更新客户信息
|
|
|
- _, err = s.Dao.TX(tx).Data(g.Map{
|
|
|
- "is_public": isPublic,
|
|
|
- "sales_id": 0,
|
|
|
- "dept_id": 0,
|
|
|
- "dept_name": "",
|
|
|
- "create_time": currentTime,
|
|
|
- "updated_by": s.GetCxtUserId(),
|
|
|
- "updated_name": userName,
|
|
|
- "updated_time": currentTime,
|
|
|
- }).WhereIn(s.ContactDao.Columns.Id, Ids).Update()
|
|
|
- if err != nil {
|
|
|
- g.Log().Error(err)
|
|
|
- return err
|
|
|
- }
|
|
|
- //更新销售归属表结束时间
|
|
|
- _, err = s.BelongDao.TX(tx).Data(
|
|
|
- g.Map{
|
|
|
- "updated_by": s.GetCxtUserId(),
|
|
|
- "updated_name": userName,
|
|
|
- "end_date": currentTime,
|
|
|
- }).WhereIn(s.BelongDao.Columns.CustId, Ids).Update()
|
|
|
- if err != nil {
|
|
|
- g.Log().Error(err)
|
|
|
- return err
|
|
|
- }
|
|
|
- return nil
|
|
|
- })
|
|
|
- return
|
|
|
-}
|
|
|
-
|
|
|
-var AssignCustomerRequestProcessCode = "PROC-FE42B2D1-6097-4DE8-8AC5-23541B7D5C8A"
|
|
|
+var AssignCustomerRequestProcessCode = "PROC-FE42B2D1-6097-4DE8-8AC5-23541B7D5C8A" // BizCode: 11
|
|
|
+var MoveToPubicRequestProcessCode = "PROC-C030BD3D-74A3-4FE5-9EBA-DF3BA9F8AEF9" // BizCode: 12
|
|
|
+var TransCustomerRequestProcessCode = "PROC-03BE93D3-9A44-43A1-BA6D-D1BB75702542" // BizCode: 13
|
|
|
|
|
|
// AssignCustomerRequest 领取客户申请
|
|
|
func (s *CustomerService) AssignCustomerRequest(ctx context.Context, req *model.AssignCustomerReq) error {
|
|
|
@@ -354,6 +313,15 @@ func (s *CustomerService) AssignCustomerRequest(ctx context.Context, req *model.
|
|
|
if v.CustStatus != "10" {
|
|
|
return myerrors.TipsError(fmt.Sprintf("客户: %s 已被领取", v.CustName))
|
|
|
}
|
|
|
+ if v.CustProvince == "" {
|
|
|
+ return myerrors.TipsError(fmt.Sprintf("请先完善客户: %s 的所在省信息", v.CustName))
|
|
|
+ }
|
|
|
+ if v.CustCity == "" {
|
|
|
+ return myerrors.TipsError(fmt.Sprintf("请先完善客户: %s 的所在市信息", v.CustName))
|
|
|
+ }
|
|
|
+ if v.CustIndustry == "" {
|
|
|
+ return myerrors.TipsError(fmt.Sprintf("请先完善客户: %s 的客户类型信息", v.CustName))
|
|
|
+ }
|
|
|
}
|
|
|
|
|
|
workflowSrv, err := workflowService.NewFlowService(ctx)
|
|
|
@@ -375,6 +343,21 @@ func (s *CustomerService) AssignCustomerRequest(ctx context.Context, req *model.
|
|
|
Name: utils.String("客户名称"),
|
|
|
Value: utils.String(u.CustName),
|
|
|
},
|
|
|
+ {
|
|
|
+ Id: utils.String("TextField_Q32G87K9Y680"),
|
|
|
+ Name: utils.String("所在省"),
|
|
|
+ Value: utils.String(u.CustProvince),
|
|
|
+ },
|
|
|
+ {
|
|
|
+ Id: utils.String("TextField_1C81AAVZELY80"),
|
|
|
+ Name: utils.String("所在市"),
|
|
|
+ Value: utils.String(u.CustCity),
|
|
|
+ },
|
|
|
+ {
|
|
|
+ Id: utils.String("TextField_7EF74WG6AJ40"),
|
|
|
+ Name: utils.String("客户类别"),
|
|
|
+ Value: utils.String(u.CustIndustry),
|
|
|
+ },
|
|
|
{
|
|
|
Id: utils.String("TextField_1ZY48VZY6WG00"),
|
|
|
Name: utils.String("申请人"),
|
|
|
@@ -454,20 +437,392 @@ func (s *CustomerService) AssignCustomerRequestApproval(flow *workflowModel.Plat
|
|
|
return err
|
|
|
}
|
|
|
|
|
|
+ s.CxtUser = &request.UserInfo{Id: user.Id, UserName: user.NickName}
|
|
|
err = s.ChangeCustBelong([]int64{int64(custId)}, int64(userId), user.NickName)
|
|
|
if err != nil {
|
|
|
return err
|
|
|
}
|
|
|
- s.BatchCreatebelong([]*model.CustCustomer{cust}, &model.AssignCustomerReq{
|
|
|
+ err = s.BatchCreatebelong([]*model.CustCustomer{cust}, &model.AssignCustomerReq{
|
|
|
Ids: []int64{int64(custId)},
|
|
|
SalesId: int64(user.Id),
|
|
|
SalesName: user.NickName,
|
|
|
Remark: "",
|
|
|
Receive: Receive,
|
|
|
})
|
|
|
+ if err != nil {
|
|
|
+ return err
|
|
|
+ }
|
|
|
+
|
|
|
+ s.CxtUser = &request.UserInfo{Id: user.Id, UserName: user.NickName}
|
|
|
+ return s.CreateDynamics("领取客户", map[string]interface{}{
|
|
|
+ "userId": user.Id,
|
|
|
+ "custId": cust.Id,
|
|
|
+ }, int64(cust.Id))
|
|
|
+}
|
|
|
+
|
|
|
+// 移回公海
|
|
|
+func (s *CustomerService) MoveToPublicRequest(ctx context.Context, req *model.MoveToPubicRep) error {
|
|
|
+ if req.Remark == "" {
|
|
|
+ return myerrors.TipsError("请输入移回原因")
|
|
|
+ }
|
|
|
+ data, err := s.Dao.Where("id in (?)", req.Ids).All()
|
|
|
+ if err != nil {
|
|
|
+ return err
|
|
|
+ }
|
|
|
+ if len(data) == 0 {
|
|
|
+ return myerrors.TipsError("移回用户不能为空")
|
|
|
+ }
|
|
|
+
|
|
|
+ for _, v := range data {
|
|
|
+ if v.CustStatus == "10" {
|
|
|
+ return myerrors.TipsError(fmt.Sprintf("客户: %s 已被移回公海", v.CustName))
|
|
|
+ }
|
|
|
+ if v.CustStatus == "20" {
|
|
|
+ return myerrors.TipsError(fmt.Sprintf("客户: %s 正在等待审批", v.CustName))
|
|
|
+ }
|
|
|
+ if v.CustProvince == "" {
|
|
|
+ return myerrors.TipsError(fmt.Sprintf("请先完善客户: %s 的所在省信息", v.CustName))
|
|
|
+ }
|
|
|
+ if v.CustCity == "" {
|
|
|
+ return myerrors.TipsError(fmt.Sprintf("请先完善客户: %s 的所在市信息", v.CustName))
|
|
|
+ }
|
|
|
+ if v.CustIndustry == "" {
|
|
|
+ return myerrors.TipsError(fmt.Sprintf("请先完善客户: %s 的客户类型信息", v.CustName))
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ workflowSrv, err := workflowService.NewFlowService(ctx)
|
|
|
+ if err != nil {
|
|
|
+ return err
|
|
|
+ }
|
|
|
+ for _, u := range data {
|
|
|
+ bizCode := strconv.Itoa(u.Id) + ":" + strconv.Itoa(s.GetCxtUserId())
|
|
|
+ _, err = workflowSrv.StartProcessInstance(bizCode, "12", &workflow.StartProcessInstanceRequest{
|
|
|
+ ProcessCode: &MoveToPubicRequestProcessCode,
|
|
|
+ FormComponentValues: []*workflow.StartProcessInstanceRequestFormComponentValues{
|
|
|
+ {
|
|
|
+ Id: utils.String("TextField_JFWRAP0D1IO0"),
|
|
|
+ Name: utils.String("客户编码"),
|
|
|
+ Value: utils.String(u.CustCode),
|
|
|
+ },
|
|
|
+ {
|
|
|
+ Id: utils.String("TextField-K2AD4O5B"),
|
|
|
+ Name: utils.String("客户名称"),
|
|
|
+ Value: utils.String(u.CustName),
|
|
|
+ },
|
|
|
+ {
|
|
|
+ Id: utils.String("TextField_1THUAFLY5RGG0"),
|
|
|
+ Name: utils.String("所在省"),
|
|
|
+ Value: utils.String(u.CustProvince),
|
|
|
+ },
|
|
|
+ {
|
|
|
+ Id: utils.String("TextField_15SRKAQIYY680"),
|
|
|
+ Name: utils.String("所在市"),
|
|
|
+ Value: utils.String(u.CustCity),
|
|
|
+ },
|
|
|
+ {
|
|
|
+ Id: utils.String("TextField_S966SSJHCCG0"),
|
|
|
+ Name: utils.String("客户类别"),
|
|
|
+ Value: utils.String(u.CustIndustry),
|
|
|
+ },
|
|
|
+ {
|
|
|
+ Id: utils.String("TextField_Y3EQ11P49LC0"),
|
|
|
+ Name: utils.String("申请人"),
|
|
|
+ Value: utils.String(s.GetCxtUserName()),
|
|
|
+ },
|
|
|
+ {
|
|
|
+ Id: utils.String("TextareaField_1790F8J2SPJ40"),
|
|
|
+ Name: utils.String("移回原因"),
|
|
|
+ Value: utils.String(req.Remark),
|
|
|
+ },
|
|
|
+ },
|
|
|
+ })
|
|
|
+ if err != nil {
|
|
|
+ return err
|
|
|
+ }
|
|
|
+
|
|
|
+ _, err = s.Dao.Where("id = ?", u.Id).Data(map[string]interface{}{
|
|
|
+ "cust_status": "20",
|
|
|
+ }).Update()
|
|
|
+ if err != nil {
|
|
|
+ return err
|
|
|
+ }
|
|
|
+ }
|
|
|
return nil
|
|
|
}
|
|
|
|
|
|
+// 移入公海回调
|
|
|
+func (s *CustomerService) MoveToPublicApproval(flow *workflowModel.PlatWorkflow, msg *message.MixMessage) error {
|
|
|
+ bizCode := strings.Split(flow.BizCode, ":")
|
|
|
+ if len(bizCode) != 2 {
|
|
|
+ return fmt.Errorf("客户移回审批 bizCode 不合法:%s Id: %d", flow.BizCode, flow.Id)
|
|
|
+ }
|
|
|
+ custId, err := strconv.Atoi(bizCode[0])
|
|
|
+ if err != nil {
|
|
|
+ return fmt.Errorf("客户移回审批 bizCode 不合法:%s Id: %d", flow.BizCode, flow.Id)
|
|
|
+ }
|
|
|
+ userId, err := strconv.Atoi(bizCode[1])
|
|
|
+ if err != nil {
|
|
|
+ return fmt.Errorf("客户移回审批 bizCode 不合法:%s Id: %d", flow.BizCode, flow.Id)
|
|
|
+ }
|
|
|
+ user, err := s.UserDao.Where("id = ?", userId).One()
|
|
|
+ if err != nil {
|
|
|
+ return err
|
|
|
+ }
|
|
|
+ if user == nil {
|
|
|
+ return fmt.Errorf("用户不存在:%s Id: %d", flow.BizCode, flow.Id)
|
|
|
+ }
|
|
|
+ cust, err := s.Dao.Where("id = ?", custId).One()
|
|
|
+ if err != nil {
|
|
|
+ return err
|
|
|
+ }
|
|
|
+ if cust == nil {
|
|
|
+ return fmt.Errorf("客户不存在:%s Id: %d", flow.BizCode, flow.Id)
|
|
|
+ }
|
|
|
+
|
|
|
+ if msg.ProcessType != "finish" && msg.ProcessType != "terminate" {
|
|
|
+ return fmt.Errorf("无法识别的 ProcessType :%s", msg.ProcessType)
|
|
|
+ }
|
|
|
+ if msg.Result != "agree" && msg.Result != "refuse" && msg.Result != "" {
|
|
|
+ return fmt.Errorf("无法识别的 Result :%s", msg.Result)
|
|
|
+ }
|
|
|
+
|
|
|
+ if msg.ProcessType == "terminate" {
|
|
|
+ _, err = s.Dao.Where("id = ?", custId).Data(map[string]interface{}{
|
|
|
+ "cust_status": "30",
|
|
|
+ }).Update()
|
|
|
+ return err
|
|
|
+ }
|
|
|
+
|
|
|
+ pass := msg.Result == "agree"
|
|
|
+ if !pass {
|
|
|
+ _, err = s.Dao.Where("id = ?", custId).Data(map[string]interface{}{
|
|
|
+ "cust_status": "30",
|
|
|
+ }).Update()
|
|
|
+ return err
|
|
|
+ }
|
|
|
+
|
|
|
+ now := gtime.Now()
|
|
|
+ err = s.Dao.Transaction(context.TODO(), func(ctx context.Context, tx *gdb.TX) error {
|
|
|
+ //更新客户信息
|
|
|
+ _, err = s.Dao.TX(tx).Data(g.Map{
|
|
|
+ "cust_status": "10",
|
|
|
+ "is_public": isPublic,
|
|
|
+ "sales_id": 0,
|
|
|
+ "dept_id": 0,
|
|
|
+ "dept_name": "",
|
|
|
+ "create_time": now,
|
|
|
+ "updated_by": user.Id,
|
|
|
+ "updated_name": user.NickName,
|
|
|
+ "updated_time": now,
|
|
|
+ }).Where("id = ?", cust.Id).Update()
|
|
|
+ if err != nil {
|
|
|
+ return err
|
|
|
+ }
|
|
|
+ //更新销售归属表结束时间
|
|
|
+ _, err = s.BelongDao.TX(tx).Data(
|
|
|
+ g.Map{
|
|
|
+ "updated_by": user.Id,
|
|
|
+ "updated_name": user.NickName,
|
|
|
+ "end_date": now,
|
|
|
+ }).Where("cust_id = ?", cust.Id).Update()
|
|
|
+ if err != nil {
|
|
|
+ return err
|
|
|
+ }
|
|
|
+ return nil
|
|
|
+ })
|
|
|
+ if err != nil {
|
|
|
+ return err
|
|
|
+ }
|
|
|
+
|
|
|
+ s.CxtUser = &request.UserInfo{Id: user.Id, UserName: user.NickName}
|
|
|
+ return s.CreateDynamics("移入公海", map[string]interface{}{
|
|
|
+ "userId": user.Id,
|
|
|
+ "custId": cust.Id,
|
|
|
+ }, int64(cust.Id))
|
|
|
+}
|
|
|
+
|
|
|
+// 转移客户
|
|
|
+func (s *CustomerService) TransCustomerRequest(ctx context.Context, req *model.AssignCustomerReq) error {
|
|
|
+ if req.Remark == "" {
|
|
|
+ return myerrors.TipsError("请输入转移原因")
|
|
|
+ }
|
|
|
+ data, err := s.Dao.Where("id in (?)", req.Ids).All()
|
|
|
+ if err != nil {
|
|
|
+ return err
|
|
|
+ }
|
|
|
+ if len(data) == 0 {
|
|
|
+ return myerrors.TipsError("转移用户不能为空")
|
|
|
+ }
|
|
|
+
|
|
|
+ for _, v := range data {
|
|
|
+ if v.CustStatus == "10" {
|
|
|
+ return myerrors.TipsError(fmt.Sprintf("客户: %s 为公海客户", v.CustName))
|
|
|
+ }
|
|
|
+ if v.CustStatus == "20" {
|
|
|
+ return myerrors.TipsError(fmt.Sprintf("客户: %s 正在等待审批", v.CustName))
|
|
|
+ }
|
|
|
+ if v.CustProvince == "" {
|
|
|
+ return myerrors.TipsError(fmt.Sprintf("请先完善客户: %s 的所在省信息", v.CustName))
|
|
|
+ }
|
|
|
+ if v.CustCity == "" {
|
|
|
+ return myerrors.TipsError(fmt.Sprintf("请先完善客户: %s 的所在市信息", v.CustName))
|
|
|
+ }
|
|
|
+ if v.CustIndustry == "" {
|
|
|
+ return myerrors.TipsError(fmt.Sprintf("请先完善客户: %s 的客户类型信息", v.CustName))
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ workflowSrv, err := workflowService.NewFlowService(ctx)
|
|
|
+ if err != nil {
|
|
|
+ return err
|
|
|
+ }
|
|
|
+ for _, u := range data {
|
|
|
+ bizCode := strings.Join([]string{
|
|
|
+ strconv.Itoa(u.Id),
|
|
|
+ strconv.Itoa(s.GetCxtUserId()),
|
|
|
+ strconv.FormatInt(req.SalesId, 10),
|
|
|
+ }, ":")
|
|
|
+ _, err = workflowSrv.StartProcessInstance(bizCode, "13", &workflow.StartProcessInstanceRequest{
|
|
|
+ ProcessCode: &TransCustomerRequestProcessCode,
|
|
|
+ FormComponentValues: []*workflow.StartProcessInstanceRequestFormComponentValues{
|
|
|
+ {
|
|
|
+ Id: utils.String("TextField-K2AD4O5B"),
|
|
|
+ Name: utils.String("客户编码"),
|
|
|
+ Value: utils.String(u.CustCode),
|
|
|
+ },
|
|
|
+ {
|
|
|
+ Id: utils.String("TextField_HMF1CTLP55S0"),
|
|
|
+ Name: utils.String("客户名称"),
|
|
|
+ Value: utils.String(u.CustName),
|
|
|
+ },
|
|
|
+ {
|
|
|
+ Id: utils.String("TextField_SAITVT7MNF40"),
|
|
|
+ Name: utils.String("所在省"),
|
|
|
+ Value: utils.String(u.CustProvince),
|
|
|
+ },
|
|
|
+ {
|
|
|
+ Id: utils.String("TextField_12DGEUTR74NK0"),
|
|
|
+ Name: utils.String("所在市"),
|
|
|
+ Value: utils.String(u.CustCity),
|
|
|
+ },
|
|
|
+ {
|
|
|
+ Id: utils.String("TextField_16FDRGG3URCW0"),
|
|
|
+ Name: utils.String("客户类别"),
|
|
|
+ Value: utils.String(u.CustIndustry),
|
|
|
+ },
|
|
|
+ {
|
|
|
+ Id: utils.String("TextField_1JSO6EU9XQCG0"),
|
|
|
+ Name: utils.String("申请人"),
|
|
|
+ Value: utils.String(s.GetCxtUserName()),
|
|
|
+ },
|
|
|
+ {
|
|
|
+ Id: utils.String("TextareaField_1ZSSTZFCT0G00"),
|
|
|
+ Name: utils.String("转移原因"),
|
|
|
+ Value: utils.String(req.Remark),
|
|
|
+ },
|
|
|
+ },
|
|
|
+ })
|
|
|
+ if err != nil {
|
|
|
+ return err
|
|
|
+ }
|
|
|
+
|
|
|
+ _, err = s.Dao.Where("id = ?", u.Id).Data(map[string]interface{}{
|
|
|
+ "cust_status": "20",
|
|
|
+ }).Update()
|
|
|
+ if err != nil {
|
|
|
+ return err
|
|
|
+ }
|
|
|
+ }
|
|
|
+ return nil
|
|
|
+}
|
|
|
+
|
|
|
+// 转移客户回调
|
|
|
+func (s *CustomerService) TransCustomerApproval(flow *workflowModel.PlatWorkflow, msg *message.MixMessage) error {
|
|
|
+ bizCode := strings.Split(flow.BizCode, ":")
|
|
|
+ if len(bizCode) != 3 {
|
|
|
+ return fmt.Errorf("转移客户审批 bizCode 不合法:%s Id: %d", flow.BizCode, flow.Id)
|
|
|
+ }
|
|
|
+ custId, err := strconv.Atoi(bizCode[0])
|
|
|
+ if err != nil {
|
|
|
+ return fmt.Errorf("转移客户审批 bizCode 不合法:%s Id: %d", flow.BizCode, flow.Id)
|
|
|
+ }
|
|
|
+ userId, err := strconv.Atoi(bizCode[1])
|
|
|
+ if err != nil {
|
|
|
+ return fmt.Errorf("转移客户审批 bizCode 不合法:%s Id: %d", flow.BizCode, flow.Id)
|
|
|
+ }
|
|
|
+ toUserId, err := strconv.Atoi(bizCode[2])
|
|
|
+ if err != nil {
|
|
|
+ return fmt.Errorf("转移客户审批 bizCode 不合法:%s Id: %d", flow.BizCode, flow.Id)
|
|
|
+ }
|
|
|
+ user, err := s.UserDao.Where("id = ?", userId).One()
|
|
|
+ if err != nil {
|
|
|
+ return err
|
|
|
+ }
|
|
|
+ if user == nil {
|
|
|
+ return fmt.Errorf("用户不存在:%s Id: %d", flow.BizCode, flow.Id)
|
|
|
+ }
|
|
|
+ toUser, err := s.UserDao.Where("id = ?", toUserId).One()
|
|
|
+ if err != nil {
|
|
|
+ return err
|
|
|
+ }
|
|
|
+ if toUser == nil {
|
|
|
+ return fmt.Errorf("用户不存在:%s Id: %d", flow.BizCode, flow.Id)
|
|
|
+ }
|
|
|
+ cust, err := s.Dao.Where("id = ?", custId).One()
|
|
|
+ if err != nil {
|
|
|
+ return err
|
|
|
+ }
|
|
|
+ if cust == nil {
|
|
|
+ return fmt.Errorf("客户不存在:%s Id: %d", flow.BizCode, flow.Id)
|
|
|
+ }
|
|
|
+
|
|
|
+ if msg.ProcessType != "finish" && msg.ProcessType != "terminate" {
|
|
|
+ return fmt.Errorf("无法识别的 ProcessType :%s", msg.ProcessType)
|
|
|
+ }
|
|
|
+ if msg.Result != "agree" && msg.Result != "refuse" && msg.Result != "" {
|
|
|
+ return fmt.Errorf("无法识别的 Result :%s", msg.Result)
|
|
|
+ }
|
|
|
+
|
|
|
+ if msg.ProcessType == "terminate" {
|
|
|
+ _, err = s.Dao.Where("id = ?", custId).Data(map[string]interface{}{
|
|
|
+ "cust_status": "30",
|
|
|
+ }).Update()
|
|
|
+ return err
|
|
|
+ }
|
|
|
+
|
|
|
+ pass := msg.Result == "agree"
|
|
|
+ if !pass {
|
|
|
+ _, err = s.Dao.Where("id = ?", custId).Data(map[string]interface{}{
|
|
|
+ "cust_status": "30",
|
|
|
+ }).Update()
|
|
|
+ return err
|
|
|
+ }
|
|
|
+
|
|
|
+ s.CxtUser = &request.UserInfo{Id: user.Id, UserName: user.NickName}
|
|
|
+ err = s.ChangeCustBelong([]int64{int64(custId)}, int64(toUserId), toUser.NickName)
|
|
|
+ if err != nil {
|
|
|
+ return err
|
|
|
+ }
|
|
|
+ err = s.BatchCreatebelong([]*model.CustCustomer{cust}, &model.AssignCustomerReq{
|
|
|
+ Ids: []int64{int64(custId)},
|
|
|
+ SalesId: int64(toUser.Id),
|
|
|
+ SalesName: toUser.NickName,
|
|
|
+ Remark: "",
|
|
|
+ Receive: OperaTion,
|
|
|
+ })
|
|
|
+ if err != nil {
|
|
|
+ return err
|
|
|
+ }
|
|
|
+
|
|
|
+ s.CxtUser = &request.UserInfo{Id: user.Id, UserName: user.NickName}
|
|
|
+ return s.CreateDynamics("转移客户", map[string]interface{}{
|
|
|
+ "userId": user.Id,
|
|
|
+ "custId": cust.Id,
|
|
|
+ "toUserId": toUser.Id,
|
|
|
+ }, int64(cust.Id))
|
|
|
+}
|
|
|
+
|
|
|
// AssignCustomer 分配客户
|
|
|
func (s *CustomerService) AssignCustomer(ctx context.Context, req *model.AssignCustomerReq) (err error) {
|
|
|
if req.Receive != "" {
|
|
|
@@ -493,13 +848,12 @@ func (s *CustomerService) AssignCustomer(ctx context.Context, req *model.AssignC
|
|
|
if err != nil {
|
|
|
return
|
|
|
}
|
|
|
- if req.Receive != "" {
|
|
|
- req.Receive = Receive
|
|
|
- } else {
|
|
|
- req.Receive = AllocaTion
|
|
|
+ req.Receive = AllocaTion
|
|
|
+ err = s.BatchCreatebelong(data, req)
|
|
|
+ if err != nil {
|
|
|
+ return err
|
|
|
}
|
|
|
- s.BatchCreatebelong(data, req)
|
|
|
- return
|
|
|
+ return s.CreateDynamics("分配客户", req, req.Ids...)
|
|
|
}
|
|
|
|
|
|
// GetEntityById 客户详情
|
|
|
@@ -568,26 +922,26 @@ func (s *CustomerService) CustAbstract(Id int64) (followInfo *model.Follow, err
|
|
|
return
|
|
|
}
|
|
|
|
|
|
-// TransCustomer 转移客户
|
|
|
-func (s *CustomerService) TransCustomer(req *model.AssignCustomerReq) (err error) {
|
|
|
- data, err := s.Dao.Fields("sales_id,sales_name,id").Where("id in (?)", req.Ids).All()
|
|
|
- if err != nil {
|
|
|
- g.Log().Error(err)
|
|
|
- return err
|
|
|
- }
|
|
|
-
|
|
|
- if len(data) == 0 {
|
|
|
- return myerrors.TipsError("数据不存在")
|
|
|
- }
|
|
|
- err = s.ChangeCustBelong(req.Ids, req.SalesId, req.SalesName)
|
|
|
- if err != nil {
|
|
|
- g.Log().Error(err)
|
|
|
- return
|
|
|
- }
|
|
|
- req.Receive = OperaTion
|
|
|
- s.BatchCreatebelong(data, req)
|
|
|
- return
|
|
|
-}
|
|
|
+// // TransCustomer 转移客户
|
|
|
+// func (s *CustomerService) TransCustomer(req *model.AssignCustomerReq) (err error) {
|
|
|
+// data, err := s.Dao.Fields("sales_id,sales_name,id").Where("id in (?)", req.Ids).All()
|
|
|
+// if err != nil {
|
|
|
+// g.Log().Error(err)
|
|
|
+// return err
|
|
|
+// }
|
|
|
+
|
|
|
+// if len(data) == 0 {
|
|
|
+// return myerrors.TipsError("数据不存在")
|
|
|
+// }
|
|
|
+// err = s.ChangeCustBelong(req.Ids, req.SalesId, req.SalesName)
|
|
|
+// if err != nil {
|
|
|
+// g.Log().Error(err)
|
|
|
+// return
|
|
|
+// }
|
|
|
+// req.Receive = OperaTion
|
|
|
+// s.BatchCreatebelong(data, req)
|
|
|
+// return
|
|
|
+// }
|
|
|
|
|
|
// ChangeCustBelong 变更客户所属关系
|
|
|
func (s *CustomerService) ChangeCustBelong(Ids []int64, salesId int64, salesName string) (err error) {
|