|
|
@@ -6,8 +6,6 @@ import (
|
|
|
"dashoo.cn/common_definition/comm_def"
|
|
|
"dashoo.cn/opms_libary/myerrors"
|
|
|
"github.com/gogf/gf/frame/g"
|
|
|
- "github.com/gogf/gf/os/gtime"
|
|
|
- "github.com/gogf/gf/util/gconv"
|
|
|
"github.com/gogf/gf/util/gvalid"
|
|
|
|
|
|
model "dashoo.cn/micro/app/model/cust"
|
|
|
@@ -18,60 +16,80 @@ type CustomerHeader struct{}
|
|
|
|
|
|
var isPublic, noPublic = "10", "20" // 公海,非公海
|
|
|
var noCustomer = true // 区分公海列表 和 客户列表 true 公海
|
|
|
-const (
|
|
|
- Creates = "创建客户"
|
|
|
- UpdateBytransfer = "转移客户"
|
|
|
- DistriCustomer = "分配客户"
|
|
|
- DeleteById = "删除客户"
|
|
|
- MoveToPubic = "移入公海"
|
|
|
- Mergecustomer = "合并客户"
|
|
|
- UpdateById = "修改客户"
|
|
|
- Receive = "领取"
|
|
|
-)
|
|
|
+
|
|
|
+//GetList 客户列表
|
|
|
+func (c *CustomerHeader) GetList(ctx context.Context, req *model.CustCustomerSearchReq, rsp *comm_def.CommonMsg) error {
|
|
|
+ customerServer, err := server.NewCustomerService(ctx)
|
|
|
+ if err != nil {
|
|
|
+ return err
|
|
|
+ }
|
|
|
+ total, list, err := customerServer.GetList(req)
|
|
|
+ _, err, rsp.Code, rsp.Msg = myerrors.CheckError(err)
|
|
|
+ if err != nil {
|
|
|
+ return err
|
|
|
+ }
|
|
|
+ rsp.Data = g.Map{"list": list, "total": total}
|
|
|
+ return nil
|
|
|
+
|
|
|
+}
|
|
|
+
|
|
|
+//PublicGetList 公海列表
|
|
|
+func (c *CustomerHeader) PublicGetList(ctx context.Context, req *model.CustCustomerSearchReq, rsp *comm_def.CommonMsg) error {
|
|
|
+ customerServer, err := server.NewCustomerService(ctx)
|
|
|
+ if err != nil {
|
|
|
+
|
|
|
+ return err
|
|
|
+ }
|
|
|
+
|
|
|
+ req.IsPublic = noCustomer
|
|
|
+
|
|
|
+ total, list, err := customerServer.GetList(req)
|
|
|
+ _, err, rsp.Code, rsp.Msg = myerrors.CheckError(err)
|
|
|
+ if err != nil {
|
|
|
+
|
|
|
+ return err
|
|
|
+ }
|
|
|
+ rsp.Data = g.Map{"list": list, "total": total}
|
|
|
+ return nil
|
|
|
+
|
|
|
+}
|
|
|
|
|
|
//Create 创建客户
|
|
|
func (c *CustomerHeader) Create(ctx context.Context, req *model.CustomerAddSeq, rsp *comm_def.CommonMsg) error {
|
|
|
-
|
|
|
if err := gvalid.CheckStruct(ctx, req, nil); err != nil {
|
|
|
return err
|
|
|
}
|
|
|
- customerServer, err := server.NewCustomerService(ctx)
|
|
|
+ s, err := server.NewCustomerService(ctx)
|
|
|
if err != nil {
|
|
|
|
|
|
return err
|
|
|
|
|
|
}
|
|
|
- id, err := customerServer.Create(req)
|
|
|
+ id, err := s.Create(req)
|
|
|
_, err, rsp.Code, rsp.Msg = myerrors.CheckError(err)
|
|
|
if err != nil {
|
|
|
|
|
|
return err
|
|
|
}
|
|
|
- var Ids []int64
|
|
|
- Ids = append(Ids, gconv.Int64(id))
|
|
|
- //创建客户
|
|
|
- c.OperationLog(ctx, Creates, Ids, req)
|
|
|
+ s.CreateDynamics("创建客户", req, id)
|
|
|
rsp.Data = g.Map{"lastId": id}
|
|
|
return nil
|
|
|
}
|
|
|
|
|
|
//UpdateById 修改客户
|
|
|
func (c *CustomerHeader) UpdateById(ctx context.Context, req *model.UpdateCustomer, rsp *comm_def.CommonMsg) error {
|
|
|
-
|
|
|
- customerServer, err := server.NewCustomerService(ctx)
|
|
|
+ s, err := server.NewCustomerService(ctx)
|
|
|
if err != nil {
|
|
|
|
|
|
return err
|
|
|
}
|
|
|
- err = customerServer.UpdateById(req)
|
|
|
+ err = s.UpdateById(req)
|
|
|
_, err, rsp.Code, rsp.Msg = myerrors.CheckError(err)
|
|
|
if err != nil {
|
|
|
|
|
|
return err
|
|
|
}
|
|
|
- var Ids []int64
|
|
|
- Ids = append(Ids, gconv.Int64(req.Id))
|
|
|
- c.OperationLog(ctx, UpdateById, Ids, req)
|
|
|
+ s.CreateDynamics("编辑客户", req, req.Id)
|
|
|
return nil
|
|
|
}
|
|
|
|
|
|
@@ -99,17 +117,17 @@ func (c *CustomerHeader) DeleteById(ctx context.Context, req *model.DelCustomer,
|
|
|
if len(req.Ids) == 0 {
|
|
|
return myerrors.NewMsgError(nil, "参数有误")
|
|
|
}
|
|
|
- customerServer, err := server.NewCustomerService(ctx)
|
|
|
+ s, err := server.NewCustomerService(ctx)
|
|
|
if err != nil {
|
|
|
return err
|
|
|
}
|
|
|
- err = customerServer.DeleteByIds(req.Ids)
|
|
|
+ err = s.DeleteByIds(req.Ids)
|
|
|
_, err, rsp.Code, rsp.Msg = myerrors.CheckError(err)
|
|
|
if err != nil {
|
|
|
return err
|
|
|
}
|
|
|
//删除客户
|
|
|
- c.OperationLog(ctx, DeleteById, req.Ids, req)
|
|
|
+ s.CreateDynamics("删除客户", req, req.Ids...)
|
|
|
return nil
|
|
|
}
|
|
|
|
|
|
@@ -131,85 +149,47 @@ func (c *CustomerHeader) GetCustNameIsExist(ctx context.Context, req *model.Cust
|
|
|
return nil
|
|
|
}
|
|
|
|
|
|
-//PublicGetList 公海列表
|
|
|
-func (c *CustomerHeader) PublicGetList(ctx context.Context, req *model.CustCustomerSearchReq, rsp *comm_def.CommonMsg) error {
|
|
|
- customerServer, err := server.NewCustomerService(ctx)
|
|
|
- if err != nil {
|
|
|
-
|
|
|
- return err
|
|
|
- }
|
|
|
-
|
|
|
- req.IsPublic = noCustomer
|
|
|
-
|
|
|
- total, list, err := customerServer.GetList(req)
|
|
|
- _, err, rsp.Code, rsp.Msg = myerrors.CheckError(err)
|
|
|
- if err != nil {
|
|
|
-
|
|
|
- return err
|
|
|
- }
|
|
|
- rsp.Data = g.Map{"list": list, "total": total}
|
|
|
- return nil
|
|
|
-
|
|
|
-}
|
|
|
-
|
|
|
-//GetList 客户列表
|
|
|
-func (c *CustomerHeader) GetList(ctx context.Context, req *model.CustCustomerSearchReq, rsp *comm_def.CommonMsg) error {
|
|
|
- customerServer, err := server.NewCustomerService(ctx)
|
|
|
- if err != nil {
|
|
|
- return err
|
|
|
- }
|
|
|
- total, list, err := customerServer.GetList(req)
|
|
|
- _, err, rsp.Code, rsp.Msg = myerrors.CheckError(err)
|
|
|
- if err != nil {
|
|
|
- return err
|
|
|
- }
|
|
|
- rsp.Data = g.Map{"list": list, "total": total}
|
|
|
- return nil
|
|
|
-
|
|
|
-}
|
|
|
-
|
|
|
//TransCustomer 转移客户
|
|
|
func (c *CustomerHeader) TransCustomer(ctx context.Context, req *model.AssignCustomerReq, rsp *comm_def.CommonMsg) error {
|
|
|
if len(req.Ids) == 0 || req.SalesId == 0 {
|
|
|
return myerrors.NewMsgError(nil, "参数有误")
|
|
|
}
|
|
|
- customerServer, err := server.NewCustomerService(ctx)
|
|
|
+ s, err := server.NewCustomerService(ctx)
|
|
|
if err != nil {
|
|
|
return err
|
|
|
}
|
|
|
- err = customerServer.TransCustomer(req)
|
|
|
+ err = s.TransCustomer(req)
|
|
|
_, err, rsp.Code, rsp.Msg = myerrors.CheckError(err)
|
|
|
if err != nil {
|
|
|
return err
|
|
|
}
|
|
|
- var Ids []int64
|
|
|
- Ids = append(Ids, gconv.Int64(req.Ids))
|
|
|
+
|
|
|
//转移客户
|
|
|
- c.OperationLog(ctx, UpdateBytransfer, Ids, req)
|
|
|
+ s.CreateDynamics("转移客户", req, req.Ids...)
|
|
|
return nil
|
|
|
}
|
|
|
|
|
|
-//AssignCustomer 分配客户
|
|
|
+//AssignCustomer 分配,领取客户
|
|
|
func (c *CustomerHeader) AssignCustomer(ctx context.Context, req *model.AssignCustomerReq, rsp *comm_def.CommonMsg) error {
|
|
|
if len(req.Ids) == 0 || req.SalesId == 0 {
|
|
|
return myerrors.NewMsgError(nil, "参数有误")
|
|
|
}
|
|
|
- customerServer, err := server.NewCustomerService(ctx)
|
|
|
- if err != nil {
|
|
|
- return err
|
|
|
- }
|
|
|
- err = customerServer.AssignCustomer(req)
|
|
|
- _, err, rsp.Code, rsp.Msg = myerrors.CheckError(err)
|
|
|
+ s, err := server.NewCustomerService(ctx)
|
|
|
if err != nil {
|
|
|
return err
|
|
|
}
|
|
|
var behavior string
|
|
|
if req.Receive == "" {
|
|
|
- behavior = DistriCustomer
|
|
|
+ behavior = "分配客户"
|
|
|
} else {
|
|
|
- behavior = Receive
|
|
|
+ behavior = "领取"
|
|
|
+ }
|
|
|
+ err = s.AssignCustomer(req)
|
|
|
+ _, err, rsp.Code, rsp.Msg = myerrors.CheckError(err)
|
|
|
+ if err != nil {
|
|
|
+ return err
|
|
|
}
|
|
|
- c.OperationLog(ctx, behavior, req.Ids, req)
|
|
|
+ s.CreateDynamics(behavior, req, req.Ids...)
|
|
|
return nil
|
|
|
|
|
|
}
|
|
|
@@ -219,11 +199,11 @@ func (c *CustomerHeader) MoveToPubic(ctx context.Context, req *model.MoveToPubic
|
|
|
if len(req.Ids) == 0 {
|
|
|
return myerrors.NewMsgError(nil, "参数有误")
|
|
|
}
|
|
|
- customerServer, err := server.NewCustomerService(ctx)
|
|
|
+ s, err := server.NewCustomerService(ctx)
|
|
|
if err != nil {
|
|
|
return err
|
|
|
}
|
|
|
- err = customerServer.MoveToPubic(req.Ids)
|
|
|
+ err = s.MoveToPubic(req.Ids)
|
|
|
_, err, rsp.Code, rsp.Msg = myerrors.CheckError(err)
|
|
|
if err != nil {
|
|
|
|
|
|
@@ -232,8 +212,7 @@ func (c *CustomerHeader) MoveToPubic(ctx context.Context, req *model.MoveToPubic
|
|
|
if req.Remark == "" {
|
|
|
req.Remark = ""
|
|
|
}
|
|
|
- c.OperationLog(ctx, MoveToPubic, req.Ids, req)
|
|
|
-
|
|
|
+ s.CreateDynamics("移入公海", req, req.Ids...)
|
|
|
return nil
|
|
|
}
|
|
|
|
|
|
@@ -253,27 +232,26 @@ func (c *CustomerHeader) GetDynamicsList(ctx context.Context, req *model.Custome
|
|
|
}
|
|
|
|
|
|
//MergeCustomer 合并客户
|
|
|
-func (c *CustomerHeader) MergeCustomer(ctx context.Context, req *model.MergecustomerRep, rsp *comm_def.CommonMsg) error {
|
|
|
+func (c *CustomerHeader) MergeCustomer(ctx context.Context, req *model.MergeCustomerRep, rsp *comm_def.CommonMsg) error {
|
|
|
if err := gvalid.CheckStruct(ctx, req, nil); err != nil {
|
|
|
return err
|
|
|
}
|
|
|
- customerServer, err := server.NewCustomerService(ctx)
|
|
|
+ s, err := server.NewCustomerService(ctx)
|
|
|
if err != nil {
|
|
|
return err
|
|
|
}
|
|
|
- err = customerServer.MergeCustomer(req)
|
|
|
+ err = s.MergeCustomer(req)
|
|
|
_, err, rsp.Code, rsp.Msg = myerrors.CheckError(err)
|
|
|
if err != nil {
|
|
|
return err
|
|
|
}
|
|
|
- var Ids []int64
|
|
|
- Ids = append(Ids, gconv.Int64(req.Id))
|
|
|
- c.OperationLog(ctx, Mergecustomer, Ids, req)
|
|
|
+
|
|
|
+ s.CreateDynamics("合并客户", req, req.Id)
|
|
|
return nil
|
|
|
}
|
|
|
|
|
|
-//CustAbstract 客户摘要
|
|
|
-func (c *CustomerHeader) CustAbstract(ctx context.Context, req *comm_def.IdReq, rsp *comm_def.CommonMsg) error {
|
|
|
+//GetCustAbstract 客户摘要
|
|
|
+func (c *CustomerHeader) GetCustAbstract(ctx context.Context, req *comm_def.IdReq, rsp *comm_def.CommonMsg) error {
|
|
|
if req.Id == 0 {
|
|
|
return myerrors.NewMsgError(nil, "参数有误")
|
|
|
}
|
|
|
@@ -290,18 +268,8 @@ func (c *CustomerHeader) CustAbstract(ctx context.Context, req *comm_def.IdReq,
|
|
|
return nil
|
|
|
}
|
|
|
|
|
|
-//OperationLog 操作日志
|
|
|
-func (c *CustomerHeader) OperationLog(ctx context.Context, custType string, custId []int64, req interface{}) {
|
|
|
- CustomerService, _ := server.NewCustomerService(ctx)
|
|
|
- custDynameics := new(model.AddCustomerDynameicsReq)
|
|
|
- custDynameics.OpnDate = gtime.Now()
|
|
|
- custDynameics.OpnType = custType
|
|
|
- custDynameics.OpnContent = req
|
|
|
- CustomerService.OperationLog(ctx, custId, custDynameics)
|
|
|
-}
|
|
|
-
|
|
|
-//DeriveList 导出
|
|
|
-func (c *CustomerHeader) DeriveList(ctx context.Context, req *model.CustCustomerExport, rsp *comm_def.CommonMsg) error {
|
|
|
+//Export 导出
|
|
|
+func (c *CustomerHeader) Export(ctx context.Context, req *model.CustCustomerExport, rsp *comm_def.CommonMsg) error {
|
|
|
customerServer, err := server.NewCustomerService(ctx)
|
|
|
if err != nil {
|
|
|
return err
|