浏览代码

提交拉取

wangxingcheng 3 年之前
父节点
当前提交
461220633f

+ 8 - 0
.idea/.gitignore

@@ -0,0 +1,8 @@
+# Default ignored files
+/shelf/
+/workspace.xml
+# Datasource local storage ignored files
+/dataSources/
+/dataSources.local.xml
+# Editor-based HTTP Client requests
+/httpRequests/

+ 4 - 0
.idea/misc.xml

@@ -0,0 +1,4 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<project version="4">
+  <component name="GOROOT" path="$USER_HOME$/Go/go1.19.3" />
+</project>

+ 8 - 0
.idea/modules.xml

@@ -0,0 +1,8 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<project version="4">
+  <component name="ProjectModuleManager">
+    <modules>
+      <module fileurl="file://$PROJECT_DIR$/.idea/opms_backend.iml" filepath="$PROJECT_DIR$/.idea/opms_backend.iml" />
+    </modules>
+  </component>
+</project>

+ 8 - 0
.idea/opms_backend.iml

@@ -0,0 +1,8 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<module type="WEB_MODULE" version="4">
+  <component name="NewModuleRootManager">
+    <content url="file://$MODULE_DIR$" />
+    <orderEntry type="inheritedJdk" />
+    <orderEntry type="sourceFolder" forTests="false" />
+  </component>
+</module>

+ 6 - 0
.idea/vcs.xml

@@ -0,0 +1,6 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<project version="4">
+  <component name="VcsDirectoryMappings">
+    <mapping directory="$PROJECT_DIR$" vcs="Git" />
+  </component>
+</project>

+ 1 - 1
opms_admin/go.mod

@@ -8,7 +8,7 @@ require (
 	github.com/go-redis/redis/v8 v8.11.5 // indirect
 	github.com/gogf/gcache-adapter v0.1.2
 	github.com/gogf/gf v1.16.4
-	github.com/mssola/user_agent v0.5.3 // indirect
+	github.com/mssola/user_agent v0.5.3
 	github.com/smallnest/rpcx v1.6.10
 	github.com/stretchr/testify v1.7.1 // indirect
 	golang.org/x/crypto v0.0.0-20220817201139-bc19a97f63c8 // indirect

+ 38 - 2
opms_parent/app/handler/base/distributor.go

@@ -43,11 +43,47 @@ func (p *DistributorHandler) Create(ctx context.Context, req *model.AddDistribut
 		return err
 	}
 	distributorServer.Create(req)
-
+	_, err, rsp.Code, rsp.Msg = myerrors.CheckError(err)
+	if err != nil {
+		g.Log().Error(err)
+		return err
+	}
 	return nil
-
 }
 
 // 编辑
+func (p *DistributorHandler) UpdateById(ctx context.Context, req *model.UpdateDistributorReq, rsp *comm_def.CommonMsg) error {
+
+	if err := gvalid.CheckStruct(ctx, req, nil); err != nil {
+		return err
+	}
+	distributorServer, err := server.NewDistributorService(ctx)
+	if err != nil {
+		g.Log().Error(err)
+		return err
+	}
+	distributorServer.UpdateById(req)
+	_, err, rsp.Code, rsp.Msg = myerrors.CheckError(err)
+	if err != nil {
+		g.Log().Error(err)
+		return err
+	}
+	return nil
+}
 
 //删掉
+func (p *DistributorHandler) DeleteByIds(ctx context.Context, req *model.DeleteDistributorReq, rsp *comm_def.CommonMsg) error {
+	distributorServer, err := server.NewDistributorService(ctx)
+	if err != nil {
+		g.Log().Error(err)
+		return err
+	}
+	err = distributorServer.DeleteByIds(req.Ids)
+	g.Log().Info("req", req)
+	_, err, rsp.Code, rsp.Msg = myerrors.CheckError(err)
+	if err != nil {
+		g.Log().Error(err)
+		return err
+	}
+	return nil
+}

+ 15 - 0
opms_parent/app/handler/base/district.go

@@ -13,12 +13,27 @@ type DistrictHandler struct{}
 
 //GetList 所属区域列表
 func (d *DistrictHandler) GetList(ctx context.Context, req *comm_def.IdReq, rsp *comm_def.CommonMsg) error {
+	districtServer, err := server.NewDistrictService(ctx)
+	if err != nil {
+		g.Log().Error(err)
+		return err
+	}
+	//list := districtServer.ListToRegions()
+	list := districtServer.ListToTree(req.Id)
+	g.Log().Info("ID", req.Id)
+	rsp.Data = g.Map{"list": list}
+	return nil
+}
+
+//区域下所有的省份
+func (d *DistrictHandler) GetRegionList(ctx context.Context, req *comm_def.IdReq, rsp *comm_def.CommonMsg) error {
 	districtServer, err := server.NewDistrictService(ctx)
 	if err != nil {
 		g.Log().Error(err)
 		return err
 	}
 	list := districtServer.ListToRegions()
+	//list := districtServer.ListToTree(req.Id)
 	g.Log().Info("ID", req.Id)
 	rsp.Data = g.Map{"list": list}
 	return nil

+ 2 - 4
opms_parent/app/handler/base/region.go

@@ -100,13 +100,13 @@ func (p *RegionHandler) CreateRegion(ctx context.Context, req *model.AddRegionRe
 }
 
 //删除区域省份
-func (p *RegionHandler) DeleteByIds(ctx context.Context, req *model.DeleteBaseRegionDetailReq, rsp *comm_def.CommonMsg) error {
+func (p *RegionHandler) DeleteById(ctx context.Context, req *model.DeleteBaseRegionDetailReq, rsp *comm_def.CommonMsg) error {
 	regionDetailServer, err := server.NewSalesRegionDetailService(ctx)
 	if err != nil {
 		g.Log().Error(err)
 		return err
 	}
-	err = regionDetailServer.DeleteByIds(req.Ids)
+	err = regionDetailServer.DeleteById(req.Ids)
 	g.Log().Info("req", req)
 	_, err, rsp.Code, rsp.Msg = myerrors.CheckError(err)
 	if err != nil {
@@ -114,6 +114,4 @@ func (p *RegionHandler) DeleteByIds(ctx context.Context, req *model.DeleteBaseRe
 		return err
 	}
 	return nil
-
-	return nil
 }

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

@@ -5,6 +5,7 @@ import (
 
 	"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"
 
@@ -32,3 +33,19 @@ func (c *CustomerContantHeader) Create(ctx context.Context, req *model.CustCusto
 	}
 	return nil
 }
+
+//修改联系人
+func (c *CustomerContantHeader) UpdateById(ctx context.Context, req *model.UpdateCustCustomerContactSeq, rsp *comm_def.CommonMsg) error {
+	customerServer, err := server.NewCustomerContactService(ctx)
+	if err != nil {
+		g.Log().Error(err)
+		return gerror.New("系统异常,请重新尝试")
+	}
+	err = customerServer.UpdateById(req)
+	_, err, rsp.Code, rsp.Msg = myerrors.CheckError(err)
+	if err != nil {
+		g.Log().Error(err)
+		return err
+	}
+	return nil
+}

+ 92 - 2
opms_parent/app/handler/cust/customer.go

@@ -74,7 +74,7 @@ func (c *CustomerHeader) Create(ctx context.Context, req *model.Customer, rsp *c
 		g.Log().Error(err)
 		return err
 	}
-	rsp.Data = g.Map{"list": id}
+	rsp.Data = g.Map{"lastId": id}
 	return nil
 }
 
@@ -139,4 +139,94 @@ func (c *CustomerHeader) DistriCustomer(ctx context.Context, req *model.DistriCu
 
 }
 
-//删除用户
+//删除客户
+func (c *CustomerHeader) DeleteById(ctx context.Context, req *model.DelCustomer, rsp *comm_def.CommonMsg) error {
+	if req.Id == 0 {
+		return gerror.New("参数有误!")
+	}
+	customerServer, err := server.NewCustomerService(ctx)
+	if err != nil {
+		g.Log().Error(err)
+		return gerror.New("系统异常,请重新尝试")
+	}
+	err = customerServer.DeleteById(req.Id)
+	_, err, rsp.Code, rsp.Msg = myerrors.CheckError(err)
+	if err != nil {
+		g.Log().Error(err)
+		return err
+	}
+	return nil
+}
+
+//移入公海
+func (c *CustomerHeader) MoveToPubic(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)
+	if err != nil {
+		g.Log().Error(err)
+		return gerror.New("系统异常,请重新尝试")
+	}
+	err = customerServer.MoveToPubic(req.Ids)
+	_, err, rsp.Code, rsp.Msg = myerrors.CheckError(err)
+	if err != nil {
+		g.Log().Error(err)
+		return err
+	}
+	return nil
+}
+
+//客户动态
+func (c *CustomerHeader) DynamicsList(ctx context.Context, req *model.CustomerDynameicsReq, rsp *comm_def.CommonMsg) error {
+	customerServer, err := server.NewCustomerService(ctx)
+	if err != nil {
+
+		g.Log().Error(err)
+		return err
+	}
+	total, list, err := customerServer.DynamicsList(req)
+	_, err, rsp.Code, rsp.Msg = myerrors.CheckError(err)
+	if err != nil {
+		g.Log().Error(err)
+		return err
+	}
+	rsp.Data = g.Map{"list": list, "total": total}
+	return nil
+
+}
+
+//合并客户
+func (c *CustomerHeader) Mergecustomer(ctx context.Context, req *model.MergecustomerRep, rsp *comm_def.CommonMsg) error {
+	customerServer, err := server.NewCustomerService(ctx)
+	if err != nil {
+		g.Log().Error(err)
+		return err
+	}
+	if err := gvalid.CheckStruct(ctx, req, nil); err != nil {
+		return err
+	}
+	err = customerServer.Mergecustomer(req)
+	_, err, rsp.Code, rsp.Msg = myerrors.CheckError(err)
+	if err != nil {
+		g.Log().Error(err)
+		return err
+	}
+	return nil
+}
+
+//修改客户
+func (c *CustomerHeader) UpdateById(ctx context.Context, req *model.UpdateCustomer, rsp *comm_def.CommonMsg) error {
+	customerServer, err := server.NewCustomerService(ctx)
+	if err != nil {
+		g.Log().Error(err)
+		return gerror.New("系统异常,请重新尝试")
+	}
+	err = customerServer.UpdateById(req)
+	_, err, rsp.Code, rsp.Msg = myerrors.CheckError(err)
+	if err != nil {
+		g.Log().Error(err)
+		return err
+	}
+	return nil
+}

+ 13 - 1
opms_parent/app/model/base/base_distributor.go

@@ -47,13 +47,25 @@ type DistributorRonp struct {
 	DistBossPhone int         `orm:"dist_boss_phone" json:"distBossPhone"` // 负责人电话
 	BelongSale    string      `orm:"belong_sale"     json:"belongSale"`    // 销售
 	ProvinceDesc  string      `orm:"province_desc"   json:"provinceDesc"`  // 省份描述
+	ProvinceId    string      `orm:"province_id"   json:"provinceId"`      // 省份Id
 	BusinessScope string      `orm:"business_scope"  json:"businessScope"` // 业务范围
 	CreatedName   string      `orm:"created_name"    json:"createdName"`   // 创建人名字
 	CreatedTime   *gtime.Time `orm:"created_time"    json:"createdTime"`   // 创建时间
-	Pid           int
+	DistDesc      string      `orm:"dist_desc"    json:"distDesc"`         // 说明
 	//District      *BaseDistrict `orm:"with:id=province_id"`
 	//*Contanct
 }
+
+//编辑参数
+type UpdateDistributorReq struct {
+	*AddDistributor
+	Id int `p:"id" json:"id" v:"required# id不能为空"`
+}
+
+//删除
+type DeleteDistributorReq struct {
+	Ids int `p:"id" json:"ids" v:"required# id不能为空"`
+}
 type Contanct struct {
 	Name string `json:"name"` // 销售名
 }

+ 36 - 13
opms_parent/app/model/cust/cust_customer.go

@@ -37,13 +37,15 @@ type Customer struct {
 	AbbrName string `p:"abbrName"        json:"abbrName"   ` // 助计名
 	//IndusTry     string      `p:"indusTry"        json:"indusTry"  v:"required#客户行业不能为空" ` //客户行业
 	//Level        string      `p:"level"        json:"level"  v:"required#客户级别不能为空" `
-	CustLocation string      `p:"custLocation"    json:"custLocation"    ` // 所在地区
-	CustAddress  string      `p:"custAddress"     json:"custAddress"   `   // 详细地址
-	FollowUpDate *gtime.Time `p:"followUpDate"     json:"followUpDate"   ` //跟进时间
-	Remark       string
-	//SalesName    string `p:"salesName"       json:"salesName"   `    //
-	//SalesId      string `p:"salesId"         json:"salesId"   `      //
-
+	CustLocation string      `p:"custLocation"    json:"custLocation"    `                    // 所在地区
+	CustAddress  string      `p:"custAddress"     json:"custAddress"   `                      // 详细地址
+	FollowUpDate *gtime.Time `p:"followUpDate"     json:"followUpDate"   `                    //跟进时间
+	CustIndustry string      `p:"custIndustry"     json:"custIndustry" v:"required#客户行业不能为空"` //客户行业
+	CustLevel    string      `p:"custLevel"     json:"custLevel"       v:"required#客户级别不能为空"` //客户级别
+	CustDistCode int         `p:"custDistCode" json custDistCode`                             // 省份Id
+	Remark       string      `p:"remark" json remark`                                         //备注
+	SalesName    string      `p:"salesName"       json:"salesName"   `                        //
+	SalesId      string      `p:"salesId"         json:"salesId"   `                          //
 }
 
 //客户联系人信息
@@ -67,7 +69,7 @@ type CustList struct {
 	CustStatus   string      `orm:"cust_status"    json:"custStatus"`   // 客户状态(10正常20)
 	FollowUpDate *gtime.Time `orm:"follow_up_date" json:"followUpDate"` // 最后跟进时间
 	CustIndustry string      `orm:"cust_industry"  json:"custIndustry"` // 客户行业
-	CustLevel    string      `orm:"cust_level"     json:"custLlevel"`   // 客户级别(10 重点客户 20 普通客户 30非优客户)
+	CustLevel    string      `orm:"cust_level"     json:"custLevel"`    // 客户级别(10 重点客户 20 普通客户 30非优客户)
 	CreatedName  string      `orm:"created_name"   json:"createdName"`  // 创建人
 	CreatedTime  *gtime.Time `orm:"created_time"   json:"createdTime"`  // 创建时间
 
@@ -75,13 +77,34 @@ type CustList struct {
 
 //转移客户参数
 type CustSalesReq struct {
-	Ids      []int64 `json:"ids,omitempty"`
-	SalesIds int64   `json:"salesids,omitempty"`
-	Remark   string  `json:"remark,omitempty"`
+	Ids       []int64 `json:"ids,omitempty"`
+	SalesIds  int64   `json:"salesIds,omitempty"`
+	SalesName string  `json:"salesName,omitempty"`
+	Remark    string  `json:"remark,omitempty"`
 }
 
 //分配客户参数
 type DistriCustomer struct {
-	Ids     []int64 `json:"ids,omitempty"`     //客户id
-	SalesId int64   `json:"salesid,omitempty"` //分配到销售人员的id
+	Ids       []int64 `json:"ids,omitempty"`       //客户id
+	SalesId   int64   `json:"salesId,omitempty"`   //分配到销售人员的id
+	SalesName string  `json:"salesName,omitempty"` //分配到销售人员的姓名
+	Remark    string  `json:"remark,omitempty"`
+}
+
+//删除客户参数
+type DelCustomer struct {
+	Id int `json:"id"` //客户id
+}
+
+//合并客户参数
+type MergecustomerRep struct {
+	Id       int       `    json:"id"` //目标Id
+	Customer *Customer `json:"customer,omitempty"`
+	ChooseId []int64   `json:"chooseId,omitempty"` //被合并的客户id
+}
+
+//修改客户
+type UpdateCustomer struct {
+	Id int `json:"ids,omitempty"` //客户id
+	*Customer
 }

+ 6 - 0
opms_parent/app/model/cust/cust_customer_contact.go

@@ -24,3 +24,9 @@ type CustCustomerContactSeq struct {
 	Remark     string `      json:"remark"`                                      // 备注
 	Policy     int    `      json:"policy"`                                      //
 }
+
+//修改联系人
+type UpdateCustCustomerContactSeq struct {
+	Id int `  json:"id"      v:"required#ID不能为空" `
+	*CustCustomerContact
+}

+ 6 - 2
opms_parent/app/model/cust/cust_customer_dynamics.go

@@ -5,6 +5,7 @@
 package cust
 
 import (
+	"dashoo.cn/opms_libary/request"
 	"github.com/gogf/gf/os/gtime"
 
 	"dashoo.cn/micro/app/model/cust/internal"
@@ -21,10 +22,13 @@ type AddCustomerDynameicsReq struct {
 	OpnPeople   string      ` json:"opnPeople"`   // 操作人
 	OpnDate     *gtime.Time ` json:"opnDate"`     // 操作日期
 	OpnType     string      ` json:"opnType"`     // 操作类型
-	OpnContent  string      ` json:"opnContent"`  // 操作内容
+	OpnContent  interface{} ` json:"opnContent"`  // 操作内容
+}
+type CustomerDynameicsReq struct {
+	request.PageReq
 }
 
-//详情
+//客户表动态记录
 type CustomerDynameicsRep struct {
 	OpnPeople  string      `    json:"opnPeople"` // 操作人
 	OpnDate    *gtime.Time `      json:"opnDate"` // 操作日期

+ 24 - 23
opms_parent/app/model/cust/internal/cust_customer.go

@@ -10,29 +10,30 @@ import (
 
 // CustCustomer is the golang structure for table cust_customer.
 type CustCustomer struct {
-	Id           int         `orm:"id,primary"     json:"id"`            // 主键
-	CustCode     string      `orm:"cust_code"      json:"custCode"`      // 客户编号
-	CustName     string      `orm:"cust_name"      json:"custName"`      // 客户名称
-	AbbrName     string      `orm:"abbr_name"      json:"abbrName"`      // 助记名
-	CustLocation string      `orm:"cust_location"  json:"custLocation"`  // 所在地区
-	CustAddress  string      `orm:"cust_address"   json:"custAddress"`   // 详细地址
-	CustIndustry string      `orm:"cust_industry"   json:"custIndustry"` //客户行业
-	CustLevel    string      `orm:"cust_level"   json:"custLevel"`       //客户级别(10 重点客户 20 普通客户 30非优客户)
-	CustStatus   string      `orm:"cust_status"    json:"custStatus"`    // 客户状态(10正常20)
-	IsPublic     string      `orm:"is_public"      json:"isPublic"`      // 公海客户(10是20否)
-	DeptId       int         `orm:"dept_id"        json:"deptId"`        // 所属部门ID
-	DeptName     string      `orm:"dept_name"      json:"deptName"`      // 所属部门
-	SalesId      int         `orm:"sales_id"       json:"salesId"`       // 所属销售ID
-	SalesName    string      `orm:"sales_name"     json:"salesName"`     // 所属销售
-	FollowUpDate *gtime.Time `orm:"follow_up_date" json:"followUpDate"`  // 最后跟进时间
-	Remark       string      `orm:"remark"         json:"remark"`        // 备注
-	CreatedBy    int         `orm:"created_by"     json:"createdBy"`     // 创建者
-	CreatedName  string      `orm:"created_name"   json:"createdName"`   // 创建人
-	CreatedTime  *gtime.Time `orm:"created_time"   json:"createdTime"`   // 创建时间
-	UpdatedBy    int         `orm:"updated_by"     json:"updatedBy"`     // 更新者
-	UpdatedName  string      `orm:"updated_name"   json:"updatedName"`   // 更新人
-	UpdatedTime  *gtime.Time `orm:"updated_time"   json:"updatedTime"`   // 更新时间
-	DeletedTime  *gtime.Time `orm:"deleted_time"   json:"deletedTime"`   // 删除时间
+	Id           int         `orm:"id,primary"     json:"id"`              // 主键
+	CustCode     string      `orm:"cust_code"      json:"custCode"`        // 客户编号
+	CustName     string      `orm:"cust_name"      json:"custName"`        // 客户名称
+	CustDistCode int         `orm:"cust_dist_code"  json:"cust_dist_code"` //客户所在省级ID
+	AbbrName     string      `orm:"abbr_name"      json:"abbrName"`        // 助记名
+	CustLocation string      `orm:"cust_location"  json:"custLocation"`    // 所在地区
+	CustAddress  string      `orm:"cust_address"   json:"custAddress"`     // 详细地址
+	CustIndustry string      `orm:"cust_industry"   json:"custIndustry"`   //客户行业
+	CustLevel    string      `orm:"cust_level"   json:"custLevel"`         //客户级别(10 重点客户 20 普通客户 30非优客户)
+	CustStatus   string      `orm:"cust_status"    json:"custStatus"`      // 客户状态(10正常20)
+	IsPublic     string      `orm:"is_public"      json:"isPublic"`        // 公海客户(10是20否)
+	DeptId       int         `orm:"dept_id"        json:"deptId"`          // 所属部门ID
+	DeptName     string      `orm:"dept_name"      json:"deptName"`        // 所属部门
+	SalesId      int         `orm:"sales_id"       json:"salesId"`         // 所属销售ID
+	SalesName    string      `orm:"sales_name"     json:"salesName"`       // 所属销售
+	FollowUpDate *gtime.Time `orm:"follow_up_date" json:"followUpDate"`    // 最后跟进时间
+	Remark       string      `orm:"remark"         json:"remark"`          // 备注
+	CreatedBy    int         `orm:"created_by"     json:"createdBy"`       // 创建者
+	CreatedName  string      `orm:"created_name"   json:"createdName"`     // 创建人
+	CreatedTime  *gtime.Time `orm:"created_time"   json:"createdTime"`     // 创建时间
+	UpdatedBy    int         `orm:"updated_by"     json:"updatedBy"`       // 更新者
+	UpdatedName  string      `orm:"updated_name"   json:"updatedName"`     // 更新人
+	UpdatedTime  *gtime.Time `orm:"updated_time"   json:"updatedTime"`     // 更新时间
+	DeletedTime  *gtime.Time `orm:"deleted_time"   json:"deletedTime"`     // 删除时间
 	//Distributor  *base.BaseDistributor `orm:"with:belong_sale_id =sales_id"`      //
 	Contact *CustCustomerContact `orm:"with:cust_id=id"`
 }

+ 54 - 1
opms_parent/app/service/base/base_distributor.go

@@ -3,9 +3,12 @@ package base
 import (
 	"context"
 	"fmt"
+	"strconv"
 
 	"github.com/gogf/gf/errors/gerror"
 	"github.com/gogf/gf/frame/g"
+	"github.com/gogf/gf/os/gtime"
+	"github.com/gogf/gf/text/gstr"
 	"github.com/gogf/gf/util/gconv"
 
 	"dashoo.cn/micro/app/dao/base"
@@ -31,7 +34,7 @@ func NewDistributorService(ctx context.Context) (svc *distributorService, err er
 //经销商信息列表
 func (d *distributorService) GetList(req *model.BaseDistributorSearchReq) (total int, distributorList []*model.DistributorRonp, err error) {
 	distributorModel := d.Dao.M
-
+	distributorModel = distributorModel.Where(d.Dao.Columns.DeletedTime + " is null")
 	if req.DistCode != "" {
 		distributorModel = distributorModel.Where(d.Dao.Columns.DistCode+"like ?", "%"+req.DistCode+"%")
 	}
@@ -68,6 +71,7 @@ func (d *distributorService) Create(req *model.AddDistributor) (err error) {
 	}
 	service.SetCreatedInfo(DistributorData, d.GetCxtUserId(), d.GetCxtUserName())
 	Model := d.Dao.M
+	DistributorData.DistCode = gstr.SubStr(strconv.Itoa(int(gtime.Now().UnixNano()/1e6))+"Code", 0, -5)
 	res, err := Model.Insert(DistributorData)
 	if err != nil {
 		return
@@ -75,5 +79,54 @@ func (d *distributorService) Create(req *model.AddDistributor) (err error) {
 	InsertId, _ := res.LastInsertId()
 	fmt.Println(InsertId)
 	return
+}
+
+//修改
+//修改数据
+func (p *distributorService) UpdateById(req *model.UpdateDistributorReq) (err error) {
+	//uptime := gtime.New(time.Now())
+	Model := p.Dao.M
+	record, err := Model.FindOne("Id", req.Id)
+	if err != nil || record.IsEmpty() {
+		err = gerror.New("该数据不存在")
+		return err
+	}
+	proInfo := record.Map()
+	fmt.Println(proInfo["created_time"])
+	distData := new(model.BaseDistributor)
+	if err = gconv.Struct(req, distData); err != nil {
+		return
+	}
+	service.SetUpdatedInfo(distData, p.GetCxtUserId(), p.GetCxtUserName())
+	_, err = Model.FieldsEx(p.Dao.Columns.DistCode, p.Dao.Columns.Id, p.Dao.Columns.CreatedName, p.Dao.Columns.CreatedBy, p.Dao.Columns.CreatedTime).WherePri(p.Dao.Columns.Id, req.Id).Update(distData)
+	if err != nil {
+		g.Log().Error(err)
+		err = gerror.New("修改信息失败")
+		return
+	}
+	return
+}
+
+//删除
+func (p *distributorService) DeleteByIds(req int) (err error) {
+	Model := p.Dao.M
+	distributor := new(model.BaseDistributor)
+	err = Model.Where(base.BaseProduct.Columns.Id, req).Scan(&distributor)
+
+	g.Log().Info("DeleteByIds", distributor)
+	if err != nil || distributor.Id == 0 {
+		g.Log().Error(err)
+		err = gerror.New("没有要删除的数据")
+		return
+	}
+	distributor.DeletedTime = gtime.Now()
+	_, err = Model.FieldsEx(EgionDetailFieldEx).
+		WherePri(p.Dao.Columns.Id, req).Update(distributor)
+	if err != nil {
+		g.Log().Error(err)
+		err = gerror.New("删除数据失败")
+		return err
+	}
+	return
 
 }

+ 5 - 5
opms_parent/app/service/base/base_district.go

@@ -29,7 +29,7 @@ func NewDistrictService(ctx context.Context) (svc *districtService, err error) {
 	svc.RegionDao = base.NewBaseSalesRegionDao(svc.Tenant)
 	return svc, nil
 }
-func (d *districtService) ListToTree(Id int) []*model.T {
+func (d *districtService) ListToTree(Id int64) []*model.T {
 	Model := d.Dao.M
 	ms := make(map[int]*model.T)
 	var distributorList []model.BaseDistrict
@@ -48,10 +48,10 @@ func (d *districtService) ListToTree(Id int) []*model.T {
 		}
 	}
 	for _, v := range ms {
-		//if _, ok := ms[v.ParentId]; ok {
-		//	ms[v.ParentId].Children = append(ms[v.ParentId].Children, v)
-		//	continue
-		//}
+		if _, ok := ms[v.ParentId]; ok {
+			ms[v.ParentId].Children = append(ms[v.ParentId].Children, v)
+			continue
+		}
 		treeList = append(treeList, v)
 	}
 	return treeList

+ 2 - 2
opms_parent/app/service/base/base_sales_region_detail.go

@@ -147,10 +147,10 @@ func (p *salesRegionDetailService) UpdateById(req *model.UpdateBaseRegionDetailR
 }
 
 //删除
-func (p *salesRegionDetailService) DeleteByIds(req int) (err error) {
+func (p *salesRegionDetailService) DeleteById(req int) (err error) {
 	Model := p.Dao.M
 	regionDetail := new(model.BaseSalesRegionDetail)
-	err = Model.Where(base.BaseProduct.Columns.Id, req).Scan(&regionDetail)
+	err = Model.Where(p.Dao.Columns.Id, req).Scan(&regionDetail)
 	//g.Log().Info("DeleteByIds", one)
 	if err != nil {
 		g.Log().Error(err)

+ 262 - 62
opms_parent/app/service/cust/cust_customer.go

@@ -19,11 +19,17 @@ type customerService struct {
 	Dao         *cust.CustCustomerDao
 	BelongDao   *cust.CustCustomerBelongDao
 	DynamicsDao *cust.CustCustomerDynamicsDao
+	ContactDao  *cust.CustCustomerContactDao
 }
 
 var isPublic, noPublic = "10", "20" // 公海,非公海
 var isTransfer int8 = 1             //转移
 var isAllocation int8 = 2           //分配 Allocation
+var OperaTion, AllocaTion = "20", "10"
+
+type OpnType struct {
+	OperaTion string
+}
 
 func NewCustomerService(ctx context.Context) (svc *customerService, err error) {
 	svc = new(customerService)
@@ -33,16 +39,13 @@ func NewCustomerService(ctx context.Context) (svc *customerService, err error) {
 	svc.Dao = cust.NewCustCustomerDao(svc.Tenant)
 	svc.BelongDao = cust.NewCustCustomerBelongDao(svc.Tenant)
 	svc.DynamicsDao = cust.NewCustCustomerDynamicsDao(svc.Tenant)
+	svc.ContactDao = cust.NewCustCustomerContactDao(svc.Tenant)
 	return svc, nil
 }
 
 //创建客户
 func (c *customerService) Create(req *model.Customer) (insertId int64, err error) {
 	cusTomer := new(model.CustCustomer)
-	if err = gconv.Struct(req, cusTomer); err != nil {
-		g.Log().Info("error", err)
-		return
-	}
 	g.Log().Info(err)
 	Model := c.Dao.M
 	record, err := Model.Where(g.Map{"cust_name": req.CustName}).One()
@@ -58,7 +61,9 @@ func (c *customerService) Create(req *model.Customer) (insertId int64, err error
 	//OpnContent  string      ` json:"opnContent"`  // 操作内容
 
 	//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()))
@@ -76,7 +81,24 @@ func (c *customerService) Create(req *model.Customer) (insertId int64, err error
 		err = gerror.New("创建失败")
 		return
 	}
+	//
+
 	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)
@@ -113,6 +135,7 @@ func (c *customerService) CreateBelong(req *model.AddCustomerBelong) (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")
 	if !req.IsPublic {
 		Model = Model.Where(c.Dao.Columns.SalesId, c.CxtUser.Id).Where(c.Dao.Columns.IsPublic, noPublic)
 	} else {
@@ -148,7 +171,85 @@ func (c *customerService) GetList(req *model.CustCustomerSearchReq) (total int,
 	return
 }
 
-//
+//删除客户
+func (c *customerService) DeleteById(id int) error {
+
+	Model := c.Dao.M
+	regionDetail := new(model.CustCustomer)
+	err := Model.Where(c.Dao.Columns.Id, id).Scan(&regionDetail)
+	//g.Log().Info("DeleteByIds", one)
+	if err != nil {
+		g.Log().Error(err)
+		err = gerror.New("没有要删除的数据")
+		return err
+	}
+	regionDetail.DeletedTime = gtime.Now()
+	_, err = Model.Data(g.Map{
+		"deleted_time": gtime.Now(),
+	}).Where(c.Dao.Columns.Id, id).Update()
+
+	//_, err = Model.
+	//	WherePri(c.Dao.Columns.Id, id).Update(regionDetail)
+	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("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).
+		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 {
+	Model := c.Dao.M
+	//Cust := new(model.CustCustomer)
+	list, err := Model.Fields(c.Dao.Columns.CreatedTime).Where(c.Dao.Columns.Id+" in (?) ", ids).All()
+	if err != nil || list.Len() <= 0 {
+		g.Log().Error(err)
+		err = gerror.New("没有要移除的数据")
+		return err
+	}
+	_, err = Model.Data(g.Map{
+		"is_public":    isPublic,
+		"sales_id":     0,
+		"sales_name":   "",
+		"dept_id":      0,
+		"dept_name":    "",
+		"create_time":  gtime.Now(),
+		"updated_by":   c.GetCxtUserId(),
+		"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("移入公海失败")
+		return err
+	}
+	return nil
+}
 
 //分配客户
 func (c *customerService) DistriCustomer(req *model.DistriCustomer) error {
@@ -167,13 +268,21 @@ func (c *customerService) DistriCustomer(req *model.DistriCustomer) error {
 		err = gerror.New("该数据不存在")
 		return err
 	}
-	err = c.UpdateCustomer(req.Ids, req.SalesId, isAllocation)
+	err = c.updateCustomer(req.Ids, req.SalesId, req.SalesName)
 	if err != nil {
 		err = gerror.New("可配客户失败")
 		return err
 
 	}
-
+	var maps = make(map[string]string)
+	maps["remark"] = req.Remark
+	maps["opn_type"] = AllocaTion
+	maps["sale_name"] = req.SalesName
+	err = c.belongInsters(rep.List(), maps)
+	if err != nil {
+		err = gerror.New("转移客户失败")
+		return err
+	}
 	return nil
 }
 
@@ -197,67 +306,37 @@ func (c *customerService) UpdateBytransfer(req *model.CustSalesReq) (entityInfo
 		err = gerror.New("该数据不存在")
 		return
 	}
-	err = c.UpdateCustomer(req.Ids, req.SalesIds, isTransfer)
+	err = c.updateCustomer(req.Ids, req.SalesIds, req.SalesName)
 	if err != nil {
 		err = gerror.New("转移客户失败")
 		return
 	}
-	belongModel := c.BelongDao.M
-	maps := []map[string]interface{}{}
-	date_time := gtime.Now()
-	for _, v := range rep {
-		old_id := v.GMap().Get("id")
-		orig_sale_name := v.GMap().Get("sales_name")
-		g.Log().Info("orig_sale_name", orig_sale_name)
-		belong := map[string]interface{}{}
-		belong["cust_id"] = old_id.(int)
-		belong["sale_name"] = ""
-		belong["orig_sale_name"] = orig_sale_name
-		belong["opn_type"] = "20"
-		belong["opn_people"] = 1
-		belong["opn_datetime"] = date_time
-		belong["created_by"] = 1
-		belong["remark"] = req.Remark
-		belong["created_name"] = "admin"
-		belong["created_time"] = date_time
-		belong["opn_datetime"] = date_time
-		maps = append(maps, belong)
-	}
-	_, err = belongModel.Insert(maps)
+
+	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)
 	if err != nil {
 		err = gerror.New("转移客户失败")
 		return
 	}
-
 	return
 }
 
 //变更客户所属关系
-func (c *customerService) UpdateCustomer(ids []int64, salesId int64, behavior int8) error {
+func (c *customerService) updateCustomer(ids []int64, salesId int64, salesName string) error {
 	custModel := c.Dao.M
-	custCustomerData := new(model.CustCustomer)
-	custCustomerData.SalesId = int(salesId)
-	switch behavior {
-	case 1:
-		custCustomerData.SalesName = "转移销售"
-		custCustomerData.IsPublic = isPublic
-	case 2:
-		custCustomerData.SalesName = "分配销售"
-		custCustomerData.IsPublic = noPublic
-	}
-	service.SetUpdatedInfo(custCustomerData, c.GetCxtUserId(), c.GetCxtUserName())
-	_, err := custModel.FieldsEx(
-		cust.CustCustomer.Columns.CustCode,
-		cust.CustCustomer.Columns.CustName,
-		cust.CustCustomer.Columns.AbbrName,
-		cust.CustCustomer.Columns.CustLocation,
-		cust.CustCustomer.Columns.Id,
-		cust.CustCustomer.Columns.CustAddress,
-		cust.CustCustomer.Columns.CreatedTime,
-		cust.CustCustomer.Columns.CustStatus,
-		cust.CustCustomer.Columns.CreatedBy,
-		cust.CustCustomer.Columns.CreatedName).
-		WherePri(cust.CustCustomer.Columns.Id+" in (?)", ids).Update(custCustomerData)
+
+	_, err := custModel.Data(g.Map{
+		"sales_id":     salesId,
+		"is_public":    noPublic,
+		"sales_name":   salesName,
+		"updated_by":   c.GetCxtUserId(),
+		"updated_name": c.GetCxtUserName(),
+		"updated_time": gtime.Now(),
+	}).Where(cust.CustCustomer.Columns.Id+" in (?)", ids).Update()
+
 	if err != nil {
 		g.Log().Error(err)
 		err = gerror.New("变更失败")
@@ -273,7 +352,7 @@ func (c *customerService) OperationLog(req *model.AddCustomerDynameicsReq) (err
 		g.Log().Info("error", err)
 		return
 	}
-	Model := c.Dao.M
+	Model := c.DynamicsDao.M
 	service.SetCreatedInfo(cusDynameics, c.GetCxtUserId(), c.GetCxtUserName())
 	_, err = Model.Insert(cusDynameics)
 	if err != nil {
@@ -284,13 +363,134 @@ func (c *customerService) OperationLog(req *model.AddCustomerDynameicsReq) (err
 	return
 }
 
-//日志详情
-func (c *customerService) OperationLogInfo(id int64) (dynamics *model.CustomerDynameicsRep, err error) {
-	Model := c.Dao.M
-	err = Model.Where(cust.CustCustomerDynamics.Columns.Id, id).Scan(&dynamics)
+//客户动态
+func (c *customerService) DynamicsList(req *model.CustomerDynameicsReq) (total int, dynamics []*model.CustomerDynameicsRep, err error) {
+	Model := c.DynamicsDao.M
+	total, err = Model.Fields().Count()
 	if err != nil {
 		g.Log().Error(err)
-		return nil, gerror.New("获取用户数据失败")
+		err = gerror.New("获取总行数失败")
+		return
 	}
+	if req.PageNum == 0 {
+		req.PageNum = 1
+	}
+	err = Model.Page(req.PageNum, req.PageSize).Order("id desc").Scan(&dynamics)
+	return
+}
+
+//合并客户
+func (c *customerService) Mergecustomer(req *model.MergecustomerRep) (err error) {
+	Model := c.Dao.M
+	ContactModel := c.ContactDao.M
+	BelongDao := c.BelongDao.M
+	//当前目标客户是否存在
+	FindOne, err := Model.Where(c.Dao.Columns.DeletedTime+" is  null").Where(c.Dao.Columns.Id, req.Id).FindOne()
+	if err != nil || FindOne.IsEmpty() {
+		err = gerror.New("该数据不存在")
+		return
+	}
+	//所选客户联系人信息
+	List, err := ContactModel.Where(c.ContactDao.Columns.CustId+" in (?)", req.ChooseId).All()
+	g.Log().Info("list", List.List())
+	if err != nil || List.Len() > 0 {
+		err = c.contactInster(req.Id, req.ChooseId, List.List())
+		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
+		}
+	}
+	return
+}
+
+//联系人
+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()
+	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)
+	if err != nil {
+		err = gerror.New("操作失败")
+		g.Log().Info("contactInster", err)
+		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.Id+" 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)
+	if err != nil {
+		g.Log().Info("BeloongInster", err)
+		err = gerror.New("操作失败")
+		return
+	}
+	return
+}
+
+//批量插入客户归属记录表
+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()
+	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"] = 1
+		belong["opn_datetime"] = date_time
+		belong["created_by"] = 1
+		belong["remark"] = parameter["remark"]
+		belong["created_name"] = "admin"
+		belong["created_time"] = date_time
+		belong["opn_datetime"] = date_time
+		maps = append(maps, belong)
+	}
+	_, err = belongModel.Insert(maps)
+	if err != nil {
+		err = gerror.New("插入失败")
+		return err
+	}
+
 	return
 }

+ 24 - 0
opms_parent/app/service/cust/cust_customer_contact.go

@@ -3,6 +3,7 @@ package cust
 import (
 	"context"
 
+	"github.com/gogf/gf/errors/gerror"
 	"github.com/gogf/gf/frame/g"
 	"github.com/gogf/gf/util/gconv"
 
@@ -44,3 +45,26 @@ func (c *customercontactService) Create(req *model.CustCustomerContactSeq) (err
 	fmt.Println(InsertId)
 	return
 }
+
+//修改联系人
+func (c *customercontactService) UpdateById(req *model.UpdateCustCustomerContactSeq) (err error) {
+	Model := c.Dao.M
+	record, err := Model.FindOne("Id", req.Id)
+	if err != nil || record.IsEmpty() {
+		err = gerror.New("该数据不存在")
+		return err
+	}
+	CustomertData := new(model.CustCustomerContact)
+	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).
+		WherePri(c.Dao.Columns.Id, req.Id).Update(CustomertData)
+	if err != nil {
+		g.Log().Error(err)
+		err = gerror.New("修改用户信息失败")
+		return
+	}
+	return
+}