فهرست منبع

提交客户模块代码

wangxingcheng 3 سال پیش
والد
کامیت
32f62af3cd

+ 3 - 0
opms_parent/app/dao/cust/internal/cust_customer_dynamics.go

@@ -29,6 +29,7 @@ type CustCustomerDynamicsDao struct {
 type custCustomerDynamicsColumns struct {
 	Id          string // 主键
 	OpnPeopleId string // 操作人ID
+	CustId      int    // 客户Id
 	OpnPeople   string // 操作人
 	OpnDate     string // 操作日期
 	OpnType     string // 操作类型
@@ -53,6 +54,7 @@ var (
 			Id:          "id",
 			OpnPeopleId: "opn_people_id",
 			OpnPeople:   "opn_people",
+
 			OpnDate:     "opn_date",
 			OpnType:     "opn_type",
 			OpnContent:  "opn_content",
@@ -78,6 +80,7 @@ func NewCustCustomerDynamicsDao(tenant string) CustCustomerDynamicsDao {
 			Id:          "id",
 			OpnPeopleId: "opn_people_id",
 			OpnPeople:   "opn_people",
+			//	CustId:      "cust_id",
 			OpnDate:     "opn_date",
 			OpnType:     "opn_type",
 			OpnContent:  "opn_content",

+ 36 - 0
opms_parent/app/handler/cust/belong.go

@@ -0,0 +1,36 @@
+package cust
+
+import (
+	"context"
+
+	"dashoo.cn/common_definition/comm_def"
+	"dashoo.cn/opms_libary/myerrors"
+	"github.com/gogf/gf/errors/gerror"
+	"github.com/gogf/gf/frame/g"
+	"github.com/gogf/gf/util/gvalid"
+
+	model "dashoo.cn/micro/app/model/cust"
+	server "dashoo.cn/micro/app/service/cust"
+)
+
+type CustBelongHeader struct{}
+
+//客户归属详情
+func (c *CustBelongHeader) GetEntityById(ctx context.Context, req *model.ContactSeq, rsp *comm_def.CommonMsg) error {
+	if err := gvalid.CheckStruct(ctx, req, nil); err != nil {
+		return err
+	}
+	belongServer, err := server.NewCustomerBelongService(ctx)
+	if err != nil {
+		g.Log().Error(err)
+		return gerror.New("系统异常,请重新尝试")
+	}
+	list, err := belongServer.GetEntityById(req.CustId)
+	_, err, rsp.Code, rsp.Msg = myerrors.CheckError(err)
+	if err != nil {
+		g.Log().Error(err)
+		return err
+	}
+	rsp.Data = g.Map{"list": list}
+	return nil
+}

+ 71 - 0
opms_parent/app/handler/cust/contant.go

@@ -7,6 +7,8 @@ import (
 	"dashoo.cn/opms_libary/myerrors"
 	"github.com/gogf/gf/errors/gerror"
 	"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"
@@ -15,6 +17,12 @@ import (
 
 type CustomerContantHeader struct{}
 
+const (
+	ContantCreate     = "创建联系人"
+	ContantUpdateById = "修改联系人"
+	ContantDeleteById = "删除联系人"
+)
+
 //创建客户联系人
 func (c *CustomerContantHeader) Create(ctx context.Context, req *model.CustCustomerContactSeq, rsp *comm_def.CommonMsg) error {
 	if err := gvalid.CheckStruct(ctx, req, nil); err != nil {
@@ -26,6 +34,9 @@ func (c *CustomerContantHeader) Create(ctx context.Context, req *model.CustCusto
 		return err
 	}
 	err = contactService.Create(req)
+	var Ids []int64
+	Ids = append(Ids, gconv.Int64(req.CustId))
+	c.WriteCustLog(ctx, ContantCreate, Ids, req)
 	_, err, rsp.Code, rsp.Msg = myerrors.CheckError(err)
 	if err != nil {
 		g.Log().Error(err)
@@ -36,12 +47,19 @@ func (c *CustomerContantHeader) Create(ctx context.Context, req *model.CustCusto
 
 //修改联系人
 func (c *CustomerContantHeader) UpdateById(ctx context.Context, req *model.UpdateCustCustomerContactSeq, rsp *comm_def.CommonMsg) error {
+	if err := gvalid.CheckStruct(ctx, req, nil); err != nil {
+		return err
+	}
 	customerServer, err := server.NewCustomerContactService(ctx)
 	if err != nil {
 		g.Log().Error(err)
 		return gerror.New("系统异常,请重新尝试")
 	}
+
 	err = customerServer.UpdateById(req)
+	var Ids []int64
+	Ids = append(Ids, gconv.Int64(req.CustId))
+	c.WriteCustLog(ctx, ContantUpdateById, Ids, req)
 	_, err, rsp.Code, rsp.Msg = myerrors.CheckError(err)
 	if err != nil {
 		g.Log().Error(err)
@@ -49,3 +67,56 @@ func (c *CustomerContantHeader) UpdateById(ctx context.Context, req *model.Updat
 	}
 	return nil
 }
+
+//客户联系人详情
+func (c *CustomerContantHeader) GetEntityById(ctx context.Context, req *model.ContactSeq, rsp *comm_def.CommonMsg) error {
+	if err := gvalid.CheckStruct(ctx, req, nil); err != nil {
+		return err
+	}
+	customerServer, err := server.NewCustomerContactService(ctx)
+	if err != nil {
+		g.Log().Error(err)
+		return gerror.New("系统异常,请重新尝试")
+	}
+	list, err := customerServer.GetEntityById(req.CustId)
+	_, err, rsp.Code, rsp.Msg = myerrors.CheckError(err)
+	if err != nil {
+		g.Log().Error(err)
+		return err
+	}
+	rsp.Data = g.Map{"list": list}
+	return nil
+}
+
+//删除联系人
+func (c *CustomerContantHeader) DeleteById(ctx context.Context, req *model.DelCustomerContact, rsp *comm_def.CommonMsg) error {
+	if req.Id == 0 {
+		return gerror.New("参数有误!")
+	}
+	customerServer, err := server.NewCustomerContactService(ctx)
+	if err != nil {
+		g.Log().Error(err)
+		return gerror.New("系统异常,请重新尝试")
+	}
+	err = customerServer.DeleteById(req.Id)
+	var Ids []int64
+	Ids = append(Ids, gconv.Int64(req.CustId))
+	c.WriteCustLog(ctx, ContantDeleteById, Ids, req)
+	_, err, rsp.Code, rsp.Msg = myerrors.CheckError(err)
+	if err != nil {
+		g.Log().Error(err)
+		return err
+	}
+	return nil
+}
+
+//DeleteById
+//操作日志
+func (c *CustomerContantHeader) WriteCustLog(ctx context.Context, custType string, Id []int64, req interface{}) {
+	CustomerService, _ := server.NewCustomerService(ctx)
+	custDynameics := new(model.AddCustomerDynameicsReq)
+	custDynameics.OpnType = custType
+	custDynameics.OpnDate = gtime.Now()
+	custDynameics.OpnContent = req
+	CustomerService.OperationLog(ctx, Id, custDynameics)
+}

+ 52 - 6
opms_parent/app/handler/cust/customer.go

@@ -7,6 +7,8 @@ import (
 	"dashoo.cn/opms_libary/myerrors"
 	"github.com/gogf/gf/errors/gerror"
 	"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"
@@ -17,6 +19,15 @@ type CustomerHeader struct{}
 
 var isPublic, noPublic = "10", "20" // 公海,非公海
 var noCustomer = true               // 区分公海列表 和 客户列表 true  公海
+const (
+	Creates          = "创建客户"
+	UpdateBytransfer = "转移客户"
+	DistriCustomer   = "分配客户"
+	DeleteById       = "删除客户"
+	MoveToPubic      = "移入公海"
+	Mergecustomer    = "合并客户"
+	UpdateById       = "修改客户"
+)
 
 //公海列表
 func (c *CustomerHeader) PublicGetList(ctx context.Context, req *model.CustCustomerSearchReq, rsp *comm_def.CommonMsg) error {
@@ -25,6 +36,7 @@ func (c *CustomerHeader) PublicGetList(ctx context.Context, req *model.CustCusto
 		g.Log().Error(err)
 		return err
 	}
+
 	req.IsPublic = noCustomer
 	g.Log().Info("publicGetlist", req)
 
@@ -69,18 +81,22 @@ func (c *CustomerHeader) Create(ctx context.Context, req *model.Customer, rsp *c
 		return err
 	}
 	id, err := customerServer.Create(req)
+	var Ids []int64
+	Ids = append(Ids, gconv.Int64(id))
 	_, err, rsp.Code, rsp.Msg = myerrors.CheckError(err)
 	if err != nil {
 		g.Log().Error(err)
 		return err
 	}
+	//创建客户
+	c.WriteCustLog(ctx, Creates, Ids, req)
 	rsp.Data = g.Map{"lastId": id}
 	return nil
 }
 
 //客户详情
-func (c *CustomerHeader) GetEntityById(ctx context.Context, req *comm_def.IdReq, rsp *comm_def.CommonMsg) error {
-	if req.Id == 0 {
+func (c *CustomerHeader) GetEntityById(ctx context.Context, req *comm_def.IdsReq, rsp *comm_def.CommonMsg) error {
+	if len(req.Ids) == 0 {
 		return gerror.New("参数有误!")
 	}
 	customerServer, err := server.NewCustomerService(ctx)
@@ -88,7 +104,7 @@ func (c *CustomerHeader) GetEntityById(ctx context.Context, req *comm_def.IdReq,
 		g.Log().Error(err)
 		return gerror.New("系统异常,请重新尝试")
 	}
-	list, err := customerServer.GetEntityById(req.Id)
+	list, err := customerServer.GetEntityById(req.Ids)
 	_, err, rsp.Code, rsp.Msg = myerrors.CheckError(err)
 	if err != nil {
 		g.Log().Error(err)
@@ -109,7 +125,10 @@ func (c *CustomerHeader) UpdateBytransfer(ctx context.Context, req *model.CustSa
 		return gerror.New("系统异常,请重新尝试")
 	}
 	_, err = customerServer.UpdateBytransfer(req)
-	//g.Log().Info("List", list)
+	var Ids []int64
+	Ids = append(Ids, gconv.Int64(req.Ids))
+	//转移客户
+	c.WriteCustLog(ctx, UpdateBytransfer, Ids, req)
 	_, err, rsp.Code, rsp.Msg = myerrors.CheckError(err)
 	if err != nil {
 		g.Log().Error(err)
@@ -129,6 +148,8 @@ func (c *CustomerHeader) DistriCustomer(ctx context.Context, req *model.DistriCu
 		return gerror.New("系统异常,请重新尝试")
 	}
 	err = customerServer.DistriCustomer(req)
+
+	c.WriteCustLog(ctx, DistriCustomer, req.Ids, req)
 	_, err, rsp.Code, rsp.Msg = myerrors.CheckError(err)
 	if err != nil {
 		g.Log().Error(err)
@@ -150,6 +171,11 @@ func (c *CustomerHeader) DeleteById(ctx context.Context, req *model.DelCustomer,
 		return gerror.New("系统异常,请重新尝试")
 	}
 	err = customerServer.DeleteById(req.Id)
+	var Ids []int64
+	Ids = append(Ids, gconv.Int64(req.Id))
+	//删除客户
+	c.WriteCustLog(ctx, DeleteById, Ids, req)
+
 	_, err, rsp.Code, rsp.Msg = myerrors.CheckError(err)
 	if err != nil {
 		g.Log().Error(err)
@@ -159,7 +185,7 @@ func (c *CustomerHeader) DeleteById(ctx context.Context, req *model.DelCustomer,
 }
 
 //移入公海
-func (c *CustomerHeader) MoveToPubic(ctx context.Context, req *comm_def.IdsReq, rsp *comm_def.CommonMsg) error {
+func (c *CustomerHeader) MoveToPubic(ctx context.Context, req *model.MoveToPubicRep, rsp *comm_def.CommonMsg) error {
 	if len(req.Ids) == 0 {
 		return gerror.New("参数有误!")
 	}
@@ -168,7 +194,12 @@ func (c *CustomerHeader) MoveToPubic(ctx context.Context, req *comm_def.IdsReq,
 		g.Log().Error(err)
 		return gerror.New("系统异常,请重新尝试")
 	}
+
 	err = customerServer.MoveToPubic(req.Ids)
+	if req.Remark == "" {
+		req.Remark = ""
+	}
+	c.WriteCustLog(ctx, MoveToPubic, req.Ids, req)
 	_, err, rsp.Code, rsp.Msg = myerrors.CheckError(err)
 	if err != nil {
 		g.Log().Error(err)
@@ -193,7 +224,6 @@ func (c *CustomerHeader) DynamicsList(ctx context.Context, req *model.CustomerDy
 	}
 	rsp.Data = g.Map{"list": list, "total": total}
 	return nil
-
 }
 
 //合并客户
@@ -207,11 +237,14 @@ func (c *CustomerHeader) Mergecustomer(ctx context.Context, req *model.Mergecust
 		return err
 	}
 	err = customerServer.Mergecustomer(req)
+	var Ids []int64
+	Ids = append(Ids, gconv.Int64(req.Id))
 	_, err, rsp.Code, rsp.Msg = myerrors.CheckError(err)
 	if err != nil {
 		g.Log().Error(err)
 		return err
 	}
+	c.WriteCustLog(ctx, Mergecustomer, Ids, req)
 	return nil
 }
 
@@ -223,6 +256,9 @@ func (c *CustomerHeader) UpdateById(ctx context.Context, req *model.UpdateCustom
 		return gerror.New("系统异常,请重新尝试")
 	}
 	err = customerServer.UpdateById(req)
+	var Ids []int64
+	Ids = append(Ids, gconv.Int64(req.Id))
+	c.WriteCustLog(ctx, UpdateById, Ids, req)
 	_, err, rsp.Code, rsp.Msg = myerrors.CheckError(err)
 	if err != nil {
 		g.Log().Error(err)
@@ -230,3 +266,13 @@ func (c *CustomerHeader) UpdateById(ctx context.Context, req *model.UpdateCustom
 	}
 	return nil
 }
+
+//操作日志
+func (c *CustomerHeader) WriteCustLog(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)
+}

+ 14 - 0
opms_parent/app/model/cust/cust_customer_belong.go

@@ -23,3 +23,17 @@ type AddCustomerBelong struct {
 	OpnPeople    string      `      json:"opnPeople" v:"required#操作人必填"`    // 操作人
 	OpnDatetime  *gtime.Time `   json:"opnDatetime" v:"required#操作时间必填"`    // 操作时间
 }
+
+type CustomerBelongInfo struct {
+	CustId       int         `       json:"custId"`  // 关联客户
+	SaleName     string      `     json:"saleName"`  // 归属销售
+	OrigSaleName string      ` json:"origSaleName"`  // 原来归属
+	OpnType      string      `      json:"opnType"`  // 操作方式(10分配20转移)
+	OpnPeople    string      `     json:"opnPeople"` // 操作人
+	OpnDatetime  *gtime.Time `   json:"opnDatetime"` // 操作时间
+	Remark       string      `        json:"remark"` // 备注
+	CreatedBy    int         `     json:"createdBy"` // 创建者
+	CreatedName  string      `   json:"createdName"` // 创建人
+	CreatedTime  *gtime.Time `  json:"createdTime"`  // 创建时间
+
+}

+ 36 - 10
opms_parent/app/model/cust/cust_customer_contact.go

@@ -5,6 +5,8 @@
 package cust
 
 import (
+	"github.com/gogf/gf/os/gtime"
+
 	"dashoo.cn/micro/app/model/cust/internal"
 )
 
@@ -14,19 +16,43 @@ type CustCustomerContact internal.CustCustomerContact
 // Fill with you ideas below.
 //添加联系人参数
 type CustCustomerContactSeq struct {
-	CustId     int    `  json:"custId"      v:"required#客户ID不能为空" `              // 关联客户
-	CuctName   string `    json:"cuctName"  v:"required#联系人名字不能为空"`              // 姓名
-	CuctGender string `  json:"cuctGender"`                                      // 性别(10男20女)
-	Postion    string `      json:"postion"`                                     // 职位
-	Telephone  string `    json:"telephone"  v:"required|phone#手机号不能为空|手机号格式错误"` // 电话
-	Wechat     string `       json:"wechat"`                                     // 微信
-	Email      string `       json:"email" v:"email#邮箱格式错误"`                     // 邮箱
-	Remark     string `      json:"remark"`                                      // 备注
-	Policy     int    `      json:"policy"`                                      //
+	CustId     int    `   p:"custId"     json:"custId"      v:"required#客户ID不能为空" `              // 关联客户
+	CuctName   string `   p:"cuctName"     json:"cuctName"  v:"required#联系人名字不能为空"`              // 姓名
+	CuctGender string `   p:"cuctGender"    json:"cuctGender"`                                   // 性别(10男20女)
+	Postion    string `   p:"postion"    json:"postion" v:"required#职位不能为空" `                    // 职位
+	Telephone  string `   p:"telephone"    json:"telephone"  v:"required|phone#手机号不能为空|手机号格式错误"` // 电话
+	Wechat     string `   p:"wechat"    json:"wechat"`                                           // 微信
+	Email      string `   p:"email"    json:"email" v:"email#邮箱格式错误"`                            // 邮箱
+	Remark     string `   p:"remark"    json:"remark"`                                           // 备注
+	Policy     int    `   p:"policy"     json:"policy"`                                          //
 }
 
 //修改联系人
 type UpdateCustCustomerContactSeq struct {
-	Id int `  json:"id"      v:"required#ID不能为空" `
+	Id     int `  json:"id"      v:"required#ID不能为空" `
+	CustId int `  json:"custId"      v:"required#CustID不能为空" `
 	*CustCustomerContact
 }
+
+//客户联系人信息
+type ContactSeq struct {
+	CustId int ` p:"custId"  json:"custId"      v:"required#custId不能为空" `
+}
+
+//详情返回字段
+
+type CustCustomerContactInfo struct {
+	Id          int         `orm:"id,primary"   json:"id"`          // 主键
+	CustId      int         `orm:"cust_id"      json:"custId" `     // 关联客户
+	CuctName    string      `orm:"cuct_name"    json:"cuctName"  `  // 姓名
+	CuctGender  string      `orm:"cuct_gender"  json:"cuctGender"`  // 性别(10男20女)
+	Postion     string      `orm:"postion"      json:"postion"`     // 职位
+	Telephone   string      `orm:"telephone"    json:"telephone"`   // 电话
+	Wechat      string      `orm:"wechat"       json:"wechat"`      // 微信
+	Email       string      `orm:"email"        json:"email"`       // 邮箱
+	Policy      int         ` orm:"policy"     json:"policy"`       //是否决策
+	Remark      string      `orm:"remark"       json:"remark"`      // 备注
+	CreatedName string      `orm:"created_name" json:"createdName"` // 创建人
+	CreatedTime *gtime.Time `orm:"created_time" json:"createdTime"` // 创建时间
+
+}

+ 4 - 0
opms_parent/app/model/cust/cust_customer_dynamics.go

@@ -20,11 +20,14 @@ type CustCustomerDynamics internal.CustCustomerDynamics
 type AddCustomerDynameicsReq struct {
 	OpnPeopleId int         ` json:"opnPeopleId"` // 操作人ID
 	OpnPeople   string      ` json:"opnPeople"`   // 操作人
+	CustId      int64       ` json:"custId"`      //客户Id
 	OpnDate     *gtime.Time ` json:"opnDate"`     // 操作日期
 	OpnType     string      ` json:"opnType"`     // 操作类型
+	Remark      string      `json:"remark"`       //备注
 	OpnContent  interface{} ` json:"opnContent"`  // 操作内容
 }
 type CustomerDynameicsReq struct {
+	CustId int `    json:"custId"` // 客户Id
 	request.PageReq
 }
 
@@ -34,4 +37,5 @@ type CustomerDynameicsRep struct {
 	OpnDate    *gtime.Time `      json:"opnDate"` // 操作日期
 	OpnType    string      `     json:"opnType"`  // 操作类型
 	OpnContent string      `   json:"opnContent"` // 操作内容
+	//List       []*CustCustomer `   json:"list"`
 }

+ 1 - 0
opms_parent/app/model/cust/internal/cust_customer_dynamics.go

@@ -12,6 +12,7 @@ import (
 type CustCustomerDynamics struct {
 	Id          int         `orm:"id,primary"    json:"id"`          // 主键
 	OpnPeopleId int         `orm:"opn_people_id" json:"opnPeopleId"` // 操作人ID
+	CustId      int         `orm:"cust_id" json:"custId"`            // 客户ID
 	OpnPeople   string      `orm:"opn_people"    json:"opnPeople"`   // 操作人
 	OpnDate     *gtime.Time `orm:"opn_date"      json:"opnDate"`     // 操作日期
 	OpnType     string      `orm:"opn_type"      json:"opnType"`     // 操作类型

+ 3 - 4
opms_parent/app/service/base/base_district.go

@@ -34,11 +34,10 @@ func (d *districtService) ListToTree(Id int64) []*model.T {
 	ms := make(map[int]*model.T)
 	var distributorList []model.BaseDistrict
 	treeList := []*model.T{}
-	if Id != 0 {
-		Model = Model.Where("parent_id =", Id).WhereOr("id =", Id)
-	}
+	//if Id != 0 {
+	//	Model = Model.Where("parent_id =", Id).WhereOr("parent_id", Id)
+	//}
 	Model.Order("parent_id asc").Scan(&distributorList)
-	g.Log().Info("distributorList", distributorList)
 
 	for _, v := range distributorList {
 		ms[v.Id] = &model.T{

+ 87 - 46
opms_parent/app/service/cust/cust_customer.go

@@ -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(&regionDetail)
 	//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()

+ 37 - 0
opms_parent/app/service/cust/cust_customer_belong.go

@@ -1 +1,38 @@
 package cust
+
+import (
+	"context"
+
+	"github.com/gogf/gf/errors/gerror"
+	"github.com/gogf/gf/frame/g"
+
+	"dashoo.cn/micro/app/dao/cust"
+	model "dashoo.cn/micro/app/model/cust"
+	"dashoo.cn/micro/app/service"
+)
+
+type customerbelongService struct {
+	*service.ContextService
+	Dao *cust.CustCustomerBelongDao
+}
+
+func NewCustomerBelongService(ctx context.Context) (svc *customerbelongService, err error) {
+	svc = new(customerbelongService)
+	if svc.ContextService, err = svc.Init(ctx); err != nil {
+		return nil, err
+	}
+	svc.Dao = cust.NewCustCustomerBelongDao(svc.Tenant)
+	return svc, nil
+}
+
+//获取客户归属信息
+func (c *customerbelongService) GetEntityById(CustId int) (Info []*model.CustomerBelongInfo, err error) {
+	Model := c.Dao.M
+	err = Model.Where(c.Dao.Columns.CustId, CustId).Where(c.Dao.Columns.DeletedTime + " is null ").Scan(&Info)
+	if err != nil {
+		g.Log().Error(err)
+		err = gerror.New("获取联系人信息失败")
+		return
+	}
+	return
+}

+ 38 - 3
opms_parent/app/service/cust/cust_customer_contact.go

@@ -2,16 +2,17 @@ package cust
 
 import (
 	"context"
+	"fmt"
 
 	"github.com/gogf/gf/errors/gerror"
 	"github.com/gogf/gf/frame/g"
+	"github.com/gogf/gf/os/gtime"
 	"github.com/gogf/gf/util/gconv"
 
-	"fmt"
-
 	"dashoo.cn/micro/app/dao/cust"
 	model "dashoo.cn/micro/app/model/cust"
 	"dashoo.cn/micro/app/service"
+	//serviceLog "dashoo.cn/micro/app/service/cust"
 )
 
 type customercontactService struct {
@@ -21,10 +22,13 @@ type customercontactService struct {
 
 func NewCustomerContactService(ctx context.Context) (svc *customercontactService, err error) {
 	svc = new(customercontactService)
+
 	if svc.ContextService, err = svc.Init(ctx); err != nil {
 		return nil, err
 	}
+
 	svc.Dao = cust.NewCustCustomerContactDao(svc.Tenant)
+
 	return svc, nil
 }
 
@@ -41,6 +45,7 @@ func (c *customercontactService) Create(req *model.CustCustomerContactSeq) (err
 	if err != nil {
 		return
 	}
+
 	InsertId, _ := res.LastInsertId()
 	fmt.Println(InsertId)
 	return
@@ -59,8 +64,9 @@ func (c *customercontactService) UpdateById(req *model.UpdateCustCustomerContact
 		return
 	}
 	service.SetUpdatedInfo(CustomertData, c.GetCxtUserId(), c.GetCxtUserName())
-	_, err = Model.FieldsEx(c.Dao.Columns.CreatedTime, c.Dao.Columns.CreatedBy, c.Dao.Columns.CreatedName).
+	_, err = Model.FieldsEx(c.Dao.Columns.CreatedTime, c.Dao.Columns.CreatedBy, c.Dao.Columns.CreatedName, c.Dao.Columns.CustId, c.Dao.Columns.Id).
 		WherePri(c.Dao.Columns.Id, req.Id).Update(CustomertData)
+
 	if err != nil {
 		g.Log().Error(err)
 		err = gerror.New("修改用户信息失败")
@@ -68,3 +74,32 @@ func (c *customercontactService) UpdateById(req *model.UpdateCustCustomerContact
 	}
 	return
 }
+
+//获取联系人信息
+func (c *customercontactService) GetEntityById(CustId int) (Info []*model.CustCustomerContactInfo, err error) {
+	Model := c.Dao.M
+	err = Model.Where(c.Dao.Columns.CustId, CustId).Where(c.Dao.Columns.DeletedTime + " is null").Scan(&Info)
+	if err != nil {
+		g.Log().Error(err)
+		err = gerror.New("获取联系人信息失败")
+		return
+	}
+	return
+}
+
+//删除联系人
+func (c *customercontactService) DeleteById(id int) error {
+	Model := c.Dao.M
+
+	deleteTime := gtime.Now()
+	// 删除客户联系人表
+	_, err := Model.Data(g.Map{
+		"deleted_time": deleteTime,
+	}).Where(c.Dao.Columns.Id, id).Update()
+	if err != nil {
+		g.Log().Error(err)
+		err = gerror.New("删除数据失败")
+		return err
+	}
+	return nil
+}

+ 1 - 0
opms_parent/main.go

@@ -22,6 +22,7 @@ func main() {
 	s.RegisterName("Region", new(base.RegionHandler), "")
 	s.RegisterName("Customer", new(cust.CustomerHeader), "")
 	s.RegisterName("Contant", new(cust.CustomerContantHeader), "")
+	s.RegisterName("Belong", new(cust.CustBelongHeader), "")
 
 	// 注册服务对象
 	//s.RegisterName("Auth", new(handler.Auth), "")