Переглянути джерело

Merge branch 'feature/customer_1.0' into develop

wangxingcheng 2 роки тому
батько
коміт
115f786b69

+ 25 - 7
doc/订单全流程管理平台.pdma.json

@@ -2,9 +2,9 @@
   "name": "订单全流程管理平台",
   "describe": "订单全流程管理平台",
   "avatar": "",
-  "version": "4.1.1",
-  "createdTime": "2022-12-6 07:35:33",
-  "updatedTime": "2023-1-5 10:48:12",
+  "version": "4.2.2",
+  "createdTime": "2023-1-6 11:43:05",
+  "updatedTime": "2023-1-6 11:43:05",
   "dbConns": [],
   "profile": {
     "default": {
@@ -11634,6 +11634,24 @@
           "notes": {},
           "id": "BD26C064-7BB5-4B2F-B462-0204CF0A0347"
         },
+        {
+          "defKey": "prod_id",
+          "defName": "关联产品",
+          "comment": "",
+          "type": "",
+          "len": "",
+          "scale": "",
+          "primaryKey": false,
+          "notNull": true,
+          "autoIncrement": false,
+          "defaultValue": "",
+          "hideInGraph": false,
+          "domain": "16120F75-6AA7-4483-868D-F07F511BB081",
+          "refDict": "",
+          "extProps": {},
+          "notes": {},
+          "id": "812C6609-3FE8-454F-BE38-1829D55490C9"
+        },
         {
           "defKey": "name",
           "defName": "产品名称",
@@ -11699,7 +11717,7 @@
           "hideInGraph": false,
           "refDict": "",
           "extProps": {},
-          "domain": "6BC8F04B-6CFA-4995-98D3-318F5CDD774E",
+          "domain": "C3B1681B-99F9-4818-9E80-DE1652A51D85",
           "id": "3A8526D9-EBBA-4DA0-A6CD-71B224D17702"
         },
         {
@@ -11716,7 +11734,7 @@
           "hideInGraph": false,
           "refDict": "",
           "extProps": {},
-          "domain": "6BC8F04B-6CFA-4995-98D3-318F5CDD774E",
+          "domain": "C3B1681B-99F9-4818-9E80-DE1652A51D85",
           "id": "EA13B6AB-39D6-440F-B7DD-2BFF30F68038"
         },
         {
@@ -11750,7 +11768,7 @@
           "hideInGraph": false,
           "refDict": "",
           "extProps": {},
-          "domain": "6BC8F04B-6CFA-4995-98D3-318F5CDD774E",
+          "domain": "C3B1681B-99F9-4818-9E80-DE1652A51D85",
           "id": "DEC06D76-4CEB-49DD-B4A9-29690B3141EE"
         },
         {
@@ -11767,7 +11785,7 @@
           "hideInGraph": false,
           "refDict": "",
           "extProps": {},
-          "domain": "6BC8F04B-6CFA-4995-98D3-318F5CDD774E",
+          "domain": "C3B1681B-99F9-4818-9E80-DE1652A51D85",
           "id": "94C71517-F3A6-4A1A-B308-7F9E10C23922"
         },
         {

+ 35 - 5
opms_admin/app/service/context.go

@@ -2,29 +2,36 @@ package service
 
 import (
 	"context"
-	"dashoo.cn/micro/app/dao"
-	"dashoo.cn/micro/app/model"
-	"dashoo.cn/opms_libary/micro_srv"
-	"dashoo.cn/opms_libary/request"
 	"fmt"
+	"reflect"
+
 	"github.com/gogf/gf/container/gset"
 	"github.com/gogf/gf/database/gdb"
 	"github.com/gogf/gf/errors/gerror"
 	"github.com/gogf/gf/frame/g"
 	"github.com/gogf/gf/os/glog"
 	"github.com/gogf/gf/util/gconv"
-	"reflect"
+
+	"dashoo.cn/micro/app/dao"
+	"dashoo.cn/micro/app/model"
+	"dashoo.cn/opms_libary/micro_srv"
+	"dashoo.cn/opms_libary/request"
 )
 
 // Context 上下文管理服务
 type contextService struct {
 	Tenant  string            `json:"tenant"`
 	Table   string            `json:"table"`
+	Ctx     context.Context   `json:"ctx"`
 	CxtUser *request.UserInfo `json:"cxtUser"`
 }
 
 // Init 初始化上下文对象指针到上下文对象中,以便后续的请求流程中可以修改。
 func (c *contextService) Init(ctx context.Context) (*contextService, error) {
+	cs := ctx.Value("contextService")
+	if cs != nil {
+		return cs.(*contextService), nil
+	}
 	c = new(contextService)
 	// 获取租户码
 	tenant, err := micro_srv.GetTenant(ctx)
@@ -42,6 +49,8 @@ func (c *contextService) Init(ctx context.Context) (*contextService, error) {
 		}
 		c.CxtUser = &userInfo
 	}
+
+	c.Ctx = context.WithValue(ctx, "contextService", c)
 	return c, nil
 }
 
@@ -156,3 +165,24 @@ func (c *contextService) GetCxtUserDeptId() int {
 	}
 	return c.CxtUser.DeptId
 }
+
+func (c *contextService) GetCxtUserRoles() []string {
+	if c.CxtUser == nil {
+		return []string{}
+	}
+	return c.CxtUser.Roles
+}
+
+func (c *contextService) GetCxtUserPosts() []string {
+	if c.CxtUser == nil {
+		return []string{}
+	}
+	return c.CxtUser.Posts
+}
+
+func (c *contextService) GetCxtUserGroups() []string {
+	if c.CxtUser == nil {
+		return []string{}
+	}
+	return c.CxtUser.Groups
+}

+ 37 - 15
opms_admin/app/service/sys_user.go

@@ -40,10 +40,10 @@ func NewUserService(ctx context.Context) (svc *userService, err error) {
 func (s *userService) Login(username, password string) (*request.UserInfo, error) {
 	record, err := s.Dao.Where("user_name", username).Where("status='10'").FindOne()
 	if err != nil {
-		return nil, errors.New("系统异常")
+		return nil, gerror.New("系统异常")
 	}
 	if record == nil {
-		return nil, errors.New("账号或密码错误,或限制登录")
+		return nil, gerror.New("账号或密码错误,或限制登录")
 	}
 	// 验证密码
 	if utils.EncryptPassword(password, record.UserSalt) != record.Password {
@@ -58,15 +58,10 @@ func (s *userService) Login(username, password string) (*request.UserInfo, error
 		return nil, err
 	}
 	// 权限
-	//permissionService, err := permission.NewService(s.Tenant)
-	//if err != nil {
-	//	return nil, errors.New("系统异常,请重新尝试")
-	//}
-	//userRoles, err := permissionService.GetRoleIdsByUser(userInfo.Id)
-	//if err != nil {
-	//	return nil, err
-	//}
-	//userInfo.Roles = userRoles
+	userInfo.Roles, userInfo.Posts, userInfo.Groups, err = s.GetUserPermission(userInfo.Id)
+	if err != nil {
+		return nil, gerror.New("获取用户权限失败")
+	}
 	return userInfo, nil
 }
 
@@ -120,8 +115,8 @@ func (s *userService) GetUserList(req *model.SysUserSearchReq) (total int, userL
 	return
 }
 
-// 获取部门下用户
-func (s userService) GetUserByDept(deptId int) (userList []*model.SysUser, err error) {
+// GetUserByDept 获取部门下用户
+func (s *userService) GetUserByDept(deptId int) (userList []*model.SysUser, err error) {
 	count, err := dao.NewSysDeptDao(s.Tenant).Where(dao.SysDept.Columns.Id, deptId).Where(dao.SysDept.Columns.Status, "10").Count()
 	if err != nil {
 		return nil, err
@@ -133,8 +128,8 @@ func (s userService) GetUserByDept(deptId int) (userList []*model.SysUser, err e
 	return userList, err
 }
 
-// 获取角色关联的用户
-func (s userService) GetUserByRole(roleId int) (userList []*model.SysUser, err error) {
+// GetUserByRole 获取角色关联的用户
+func (s *userService) GetUserByRole(roleId int) (userList []*model.SysUser, err error) {
 	count, err := dao.NewSysRoleDao(s.Tenant).Where(dao.SysRole.Columns.Id, roleId).Where(dao.SysRole.Columns.Status, "10").Count()
 	if err != nil {
 		return nil, err
@@ -204,6 +199,33 @@ func (s *userService) GetUserInfoById(id int, withPwd ...bool) (user *model.SysU
 	return
 }
 
+// GetUserPermission 获取用户权限字符(角色、岗位、用户组)
+func (s *userService) GetUserPermission(userId int) ([]string, []string, []string, error) {
+	s.userRoleDao = dao.NewSysUserRoleDao(s.Tenant)
+	s.userPostDao = dao.NewSysUserPostDao(s.Tenant)
+	s.userGroupDao = dao.NewSysUserGroupDao(s.Tenant)
+	roleList, err := s.userRoleDao.As("user_role").LeftJoin(dao.SysRole.Table, "role", "user_role.role_id=role.id").
+		Fields(dao.SysRole.Columns.RoleKey).Where(s.userRoleDao.Columns.UserId, userId).Array()
+	if err != nil {
+		g.Log().Error(err)
+		return nil, nil, nil, err
+	}
+	postList, err := s.userPostDao.As("user_post").LeftJoin(dao.SysPost.Table, "post", "user_post.post_id=post.id").
+		Fields(dao.SysPost.Columns.PostCode).Where(s.userPostDao.Columns.UserId, userId).Array()
+	if err != nil {
+		g.Log().Error(err)
+		return nil, nil, nil, err
+	}
+	groupList, err := s.userGroupDao.As("user_group").LeftJoin(dao.SysGroup.Table, "group", "user_group.group_id=group.id").
+		Fields(dao.SysGroup.Columns.GroupCode).Where(s.userGroupDao.Columns.UserId, userId).Array()
+	if err != nil {
+		g.Log().Error(err)
+		return nil, nil, nil, err
+	}
+
+	return gconv.Strings(roleList), gconv.Strings(postList), gconv.Strings(groupList), err
+}
+
 // GetUserRoleIds 获取用户角色
 func (s *userService) GetUserRoleIds(userId int) (roleIds []int, err error) {
 	s.userRoleDao = dao.NewSysUserRoleDao(s.Tenant)

+ 8 - 6
opms_libary/request/request.go

@@ -29,12 +29,14 @@ func (p *PageReq) GetPage() (int, int) {
 
 // UserInfo 登录用户信息
 type UserInfo struct {
-	Id       int    `json:"id"`
-	Uuid     string `json:"uuid"`
-	UserName string `json:"userName"`
-	NickName string `json:"nickName"`
-	DeptId   int    `json:"deptId"` // 所属部门
-	Roles    string `json:"roles"`  // 所属角色
+	Id       int      `json:"id"`
+	Uuid     string   `json:"uuid"`
+	UserName string   `json:"userName"`
+	NickName string   `json:"nickName"`
+	DeptId   int      `json:"deptId"` // 所属部门
+	Roles    []string `json:"roles"`  // 所属角色
+	Posts    []string `json:"posts"`  // 所属岗位
+	Groups   []string `json:"groups"` // 所属用户组
 }
 
 // 设置当前登录用户信息

+ 3 - 3
opms_parent/app/dao/cust/internal/cust_customer_belong.go

@@ -29,7 +29,7 @@ type CustCustomerBelongDao struct {
 type custCustomerBelongColumns struct {
 	Id           string // 主键
 	CustId       string // 关联客户
-	SaleName     string // 归属销售
+	SalesName    string // 归属销售
 	OrigSaleName string // 原来归属
 	OpnType      string // 操作方式(10分配20转移)
 	OpnPeople    string // 操作人
@@ -53,7 +53,7 @@ var (
 		Columns: custCustomerBelongColumns{
 			Id:           "id",
 			CustId:       "cust_id",
-			SaleName:     "sale_name",
+			SalesName:    "sales_name",
 			OrigSaleName: "orig_sale_name",
 			OpnType:      "opn_type",
 			OpnPeople:    "opn_people",
@@ -79,7 +79,7 @@ func NewCustCustomerBelongDao(tenant string) CustCustomerBelongDao {
 		Columns: custCustomerBelongColumns{
 			Id:           "id",
 			CustId:       "cust_id",
-			SaleName:     "sale_name",
+			SalesName:    "sales_name",
 			OrigSaleName: "orig_sale_name",
 			OpnType:      "opn_type",
 			OpnPeople:    "opn_people",

+ 23 - 0
opms_parent/app/handler/base/distributor.go

@@ -51,6 +51,29 @@ func (p *DistributorHandler) Create(ctx context.Context, req *model.AddDistribut
 	return nil
 }
 
+//详情
+func (p *DistributorHandler) GetEntityById(ctx context.Context, req *comm_def.IdReq, 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
+	}
+	list, err := distributorServer.GetEntityById(req.Id)
+	_, 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 (p *DistributorHandler) UpdateById(ctx context.Context, req *model.UpdateDistributorReq, rsp *comm_def.CommonMsg) error {
 

+ 3 - 3
opms_parent/app/handler/cust/contant.go

@@ -68,8 +68,8 @@ 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 {
+//客户联系人详情 //GetEntityById
+func (c *CustomerContantHeader) GetList(ctx context.Context, req *model.ContactSeq, rsp *comm_def.CommonMsg) error {
 	if err := gvalid.CheckStruct(ctx, req, nil); err != nil {
 		return err
 	}
@@ -78,7 +78,7 @@ func (c *CustomerContantHeader) GetEntityById(ctx context.Context, req *model.Co
 		g.Log().Error(err)
 		return gerror.New("系统异常,请重新尝试")
 	}
-	list, err := customerServer.GetEntityById(req.CustId)
+	list, err := customerServer.GetList(req.CustId)
 	_, err, rsp.Code, rsp.Msg = myerrors.CheckError(err)
 	if err != nil {
 		g.Log().Error(err)

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

@@ -117,8 +117,8 @@ func (c *CustomerHeader) GetEntityById(ctx context.Context, req *comm_def.IdsReq
 }
 
 //转移客户
-func (c *CustomerHeader) UpdateBytransfer(ctx context.Context, req *model.CustSalesReq, rsp *comm_def.CommonMsg) error {
-	if len(req.Ids) == 0 || req.SalesIds == 0 {
+func (c *CustomerHeader) UpdateBytransfer(ctx context.Context, req *model.DistriCustomer, rsp *comm_def.CommonMsg) error {
+	if len(req.Ids) == 0 || req.SalesId == 0 {
 		return gerror.New("参数有误!")
 	}
 	customerServer, err := server.NewCustomerService(ctx)
@@ -126,7 +126,11 @@ func (c *CustomerHeader) UpdateBytransfer(ctx context.Context, req *model.CustSa
 		g.Log().Error(err)
 		return gerror.New("系统异常,请重新尝试")
 	}
-	_, err = customerServer.UpdateBytransfer(req)
+	err = customerServer.UpdateBytransfer(req)
+	if err != nil {
+		return gerror.New("转移失败")
+
+	}
 	var Ids []int64
 	Ids = append(Ids, gconv.Int64(req.Ids))
 	//转移客户
@@ -151,12 +155,17 @@ func (c *CustomerHeader) DistriCustomer(ctx context.Context, req *model.DistriCu
 		return gerror.New("系统异常,请重新尝试")
 	}
 	err = customerServer.DistriCustomer(req)
-
+	if err != nil {
+		return err
+	}
+	var behavior string
 	if req.Receive == "" {
-		c.WriteCustLog(ctx, DistriCustomer, req.Ids, req)
+		behavior = DistriCustomer
+		//c.WriteCustLog(ctx, DistriCustomer, req.Ids, req)
 	} else {
-		c.WriteCustLog(ctx, Receive, req.Ids, req)
+		behavior = Receive
 	}
+	c.WriteCustLog(ctx, behavior, req.Ids, req)
 	_, err, rsp.Code, rsp.Msg = myerrors.CheckError(err)
 	if err != nil {
 		g.Log().Error(err)
@@ -300,6 +309,7 @@ func (c *CustomerHeader) WriteCustLog(ctx context.Context, custType string, cust
 	CustomerService.OperationLog(ctx, custId, custDynameics)
 }
 
+//导出
 func (c *CustomerHeader) DeriveList(ctx context.Context, req *model.CustCustomerExport, rsp *comm_def.CommonMsg) error {
 
 	customerServer, err := server.NewCustomerService(ctx)

+ 14 - 14
opms_parent/app/model/base/base_distributor.go

@@ -39,20 +39,20 @@ type AddDistributor struct {
 
 //列表返回字段
 type DistributorRonp struct {
-	Id            int         `orm:"id,primary"      json:"id"`            // 主健
-	DistCode      string      `orm:"dist_code"       json:"distCode"`      // 经销商编码
-	DistName      string      `orm:"dist_name"       json:"distName"`      // 经销商名字
-	AbbrName      string      `orm:"abbr_name"       json:"abbrName"`      // 助记名
-	DistBoss      string      `orm:"dist_boss"       json:"distBoss"`      // 负责人
-	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"`   // 创建时间
-	DistDesc      string      `orm:"dist_desc"    json:"distDesc"`         // 说明
-	//District      *BaseDistrict `orm:"with:id=province_id"`
+	Id            int           `orm:"id,primary"      json:"id"`            // 主健
+	DistCode      string        `orm:"dist_code"       json:"distCode"`      // 经销商编码
+	DistName      string        `orm:"dist_name"       json:"distName"`      // 经销商名字
+	AbbrName      string        `orm:"abbr_name"       json:"abbrName"`      // 助记名
+	DistBoss      string        `orm:"dist_boss"       json:"distBoss"`      // 负责人
+	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"`   // 创建时间
+	DistDesc      string        `orm:"dist_desc"    json:"distDesc"`         // 说明
+	District      *BaseDistrict `orm:"with:id=province_id"`
 	//*Contanct
 }
 

+ 1 - 1
opms_parent/app/model/base/base_product.go

@@ -22,7 +22,7 @@ type BaseProductSearchReq struct {
 
 //添加数据
 type AddBaseProductReq struct {
-	ProdCode    string `p:"prodCode"    json:"prodCode"   v:"required#产品编号不能为空"`
+	ProdCode    string `p:"prodCode"    json:"prodCode"  `
 	ProdName    string `p:"prodName"    json:"prodName"   v:"required#产品名称不能为空"`
 	ProdClass   string `p:"prodClass"   json:"prodClass"  v:"required#产品分类不能为空"`
 	GuidPrice   string `p:"guidPrice"   json:"guidPrice"      v:"required#建议成交价"`

+ 6 - 1
opms_parent/app/model/cust/cust_customer.go

@@ -86,6 +86,8 @@ type CustList struct {
 	CustLevel    string `orm:"cust_level"     json:"custLevel"`    // 客户级别(10 重点客户 20 普通客户 30非优客户)
 	CreatedName  string `orm:"created_name"   json:"createdName"`  // 创建人
 	CreatedTime  string `orm:"created_time"   json:"createdTime"`  // 创建时间
+	SalesId      int    `orm:"sales_id"   json:"salesId"`          //
+	SalesName    string `orm:"sales_name"   json:"salesName"`      //
 	//Follow       *Follow     `json:"follow"`
 }
 
@@ -108,9 +110,10 @@ type CustSalesReq struct {
 	SalesIds  int64   `json:"salesIds,omitempty"`
 	SalesName string  `json:"salesName,omitempty"`
 	Remark    string  `json:"remark,omitempty"`
+	Receive   string  `json:"receive,omitempty"` //有值领取 无值分配
 }
 
-//分配客户参数
+//分配 领取 转移 客户参数
 type DistriCustomer struct {
 	Ids       []int64 `json:"ids,omitempty"`       //客户id
 	SalesId   int64   `json:"salesId,omitempty"`   //分配到销售人员的id
@@ -133,6 +136,8 @@ type DelCustomerContact struct {
 type MergecustomerRep struct {
 	Id int `json:"id"` //目标Id
 	*Customer
+	//*CustCustomerContactSeq
+	*AddCustomerBelong
 	ChooseId []int64 `json:"chooseId,omitempty"` //被合并的客户id
 }
 

+ 2 - 2
opms_parent/app/model/cust/cust_customer_belong.go

@@ -20,8 +20,8 @@ type AddCustomerBelong struct {
 	SaleName     string      `      json:"saleName" v:"required#归属销售不能为空"`  // 归属销售
 	OrigSaleName string      `      json:"origSaleName"   `                 // 原来归属
 	OpnType      string      `      json:"opnType"`                         // 操作方式(10分配20转移)
-	OpnPeople    string      `      json:"opnPeople" v:"required#操作人必填"`    // 操作人
-	OpnDatetime  *gtime.Time `   json:"opnDatetime" v:"required#操作时间必填"`    // 操作时间
+	OpnPeople    string      `      json:"opnPeople" `                      // 操作人
+	OpnDatetime  *gtime.Time `   json:"opnDatetime" `                       // 操作时间
 }
 
 type CustomerBelongInfo struct {

+ 0 - 2
opms_parent/app/model/cust/internal/cust_customer.go

@@ -34,6 +34,4 @@ type CustCustomer struct {
 	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"`
 }

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

@@ -7,7 +7,7 @@ import (
 )
 
 var (
-	// CommonUpdateFieldEx, UpdateFieldEx 更新过滤字段
+	// CommonUpdateFieldEx  UpdateFieldEx 更新过滤字段
 	CommonUpdateFieldEx = []interface{}{"created_by", "created_name", "created_time"}
 	UpdateFieldEx       = []interface{}{"id", "created_by", "created_name", "created_time"}
 )

+ 11 - 5
opms_parent/app/service/base/base_distributor.go

@@ -55,10 +55,7 @@ func (d *distributorService) GetList(req *model.BaseDistributorSearchReq) (total
 		err = gerror.New("获取总行数失败")
 		return
 	}
-	if req.PageNum == 0 {
-		req.PageNum = 1
-	}
-	err = distributorModel.Page(req.PageNum, req.PageSize).Order("id desc").Scan(&distributorList)
+	err = distributorModel.Page(req.GetPage()).Order("id desc").Scan(&distributorList)
 	g.Log().Info("返回列表", distributorList)
 	return
 }
@@ -81,7 +78,16 @@ func (d *distributorService) Create(req *model.AddDistributor) (err error) {
 	return
 }
 
-//修改
+//详情
+func (p *distributorService) GetEntityById(id int64) (distributorInfo *model.DistributorRonp, err error) {
+	err = p.Dao.Where(base.BaseProduct.Columns.Id, id).Scan(&distributorInfo)
+	if err != nil {
+		g.Log().Error(err)
+		return nil, gerror.New("获取经销商数据失败")
+	}
+	return
+}
+
 //修改数据
 func (p *distributorService) UpdateById(req *model.UpdateDistributorReq) (err error) {
 	//uptime := gtime.New(time.Now())

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

@@ -86,11 +86,6 @@ func (d *districtService) ListToRegions() (region []*model.Region) {
 		})
 	}
 	for _, v := range region {
-		g.Log().Info("msssss", ms[v.Id])
-		//if _, ok := ms[v.Id]; ok {
-		//	v.Children = ms[v.Id]
-		//	continue
-		//}
 		v.Children = ms[v.Id]
 	}
 	g.Log().Info("return", region)

+ 22 - 22
opms_parent/app/service/base/base_product.go

@@ -50,6 +50,16 @@ func (p *productService) GetList(req *model.BaseProductSearchReq) (total int, pr
 	return
 }
 
+//编辑查询单条查询
+func (p *productService) GetEntityById(id int64) (product *model.BaseProduct, err error) {
+	err = p.Dao.Where(base.BaseProduct.Columns.Id, id).Scan(&product)
+	if err != nil {
+		g.Log().Error(err)
+		return nil, gerror.New("获取用户数据失败")
+	}
+	return
+}
+
 //添加信息
 func (p *productService) Create(req *model.AddBaseProductReq) (err error) {
 	productData := new(model.BaseProduct)
@@ -67,24 +77,6 @@ func (p *productService) Create(req *model.AddBaseProductReq) (err error) {
 	return
 }
 
-//删掉数据
-func (p *productService) DeleteByIds(dicIds []int64) (err error) {
-	_, err = base.BaseProduct.Fields(base.BaseProduct.Columns.CreatedTime).
-		Where(base.BaseProduct.Columns.Id+" in (?) ", dicIds).All()
-	if err != nil {
-		g.Log().Error(err)
-		err = gerror.New("没有要删除的数据")
-		return
-	}
-	_, err = p.Dao.Delete(base.BaseProduct.Columns.Id+" in (?) ", dicIds)
-	if err != nil {
-		g.Log().Error(err)
-		err = gerror.New("删除数据失败")
-		return err
-	}
-	return
-}
-
 //修改数据
 func (p *productService) UpdateById(req *model.UpdateBaseProductReq) (err error) {
 	//uptime := gtime.New(time.Now())
@@ -112,12 +104,20 @@ func (p *productService) UpdateById(req *model.UpdateBaseProductReq) (err error)
 	return
 }
 
-//编辑查询单条查询
-func (p *productService) GetEntityById(id int64) (product *model.BaseProduct, err error) {
-	err = p.Dao.Where(base.BaseProduct.Columns.Id, id).Scan(&product)
+//删掉数据
+func (p *productService) DeleteByIds(dicIds []int64) (err error) {
+	_, err = base.BaseProduct.Fields(base.BaseProduct.Columns.CreatedTime).
+		Where(base.BaseProduct.Columns.Id+" in (?) ", dicIds).All()
 	if err != nil {
 		g.Log().Error(err)
-		return nil, gerror.New("获取用户数据失败")
+		err = gerror.New("没有要删除的数据")
+		return
+	}
+	_, err = p.Dao.Delete(base.BaseProduct.Columns.Id+" in (?) ", dicIds)
+	if err != nil {
+		g.Log().Error(err)
+		err = gerror.New("删除数据失败")
+		return err
 	}
 	return
 }

+ 0 - 1
opms_parent/app/service/base/base_sales_region.go

@@ -53,7 +53,6 @@ func (p *salesRegionService) Create(req *model.AddRegionReq) (err error) {
 	}
 	service.SetCreatedInfo(regionData, p.GetCxtUserId(), p.GetCxtUserName())
 	regionData.RegionCode = strconv.Itoa(int(gtime.Timestamp()))
-	service.SetCreatedInfo(regionData, p.GetCxtUserId(), p.GetCxtUserName())
 	_, err = Model.Insert(regionData)
 	if err != nil {
 		return err

+ 0 - 1
opms_parent/app/service/base/base_sales_region_detail.go

@@ -108,7 +108,6 @@ func (p *salesRegionDetailService) Create(req *model.AddBaseRegionDetailReq) (er
 	if err = gconv.Struct(req, detailData); err != nil {
 		return
 	}
-	service.SetCreatedInfo(detailData, p.GetCxtUserId(), p.GetCxtUserName())
 	detailData.RegionId = req.RegionId
 	detailData.ProvinceCode = req.ProvinceCode
 	service.SetCreatedInfo(detailData, p.GetCxtUserId(), p.GetCxtUserName())

+ 32 - 2
opms_parent/app/service/context.go

@@ -3,20 +3,28 @@ package service
 import (
 	"context"
 
+	"github.com/gogf/gf/os/glog"
+
 	"dashoo.cn/opms_libary/micro_srv"
 	"dashoo.cn/opms_libary/request"
-	"github.com/gogf/gf/os/glog"
 )
 
-// Context 上下文管理服务
+// ContextService 上下文管理服务
 type ContextService struct {
 	Tenant  string            `json:"tenant"`
+	Table   string            `json:"table"`
+	Ctx     context.Context   `json:"ctx"`
 	CxtUser *request.UserInfo `json:"cxtUser"`
 }
 
 // Init 初始化上下文对象指针到上下文对象中,以便后续的请求流程中可以修改。
 func (c *ContextService) Init(ctx context.Context) (*ContextService, error) {
+	cs := ctx.Value("contextService")
+	if cs != nil {
+		return cs.(*ContextService), nil
+	}
 	c = new(ContextService)
+	c.Ctx = ctx
 	// 获取租户码
 	tenant, err := micro_srv.GetTenant(ctx)
 	if err != nil {
@@ -33,6 +41,7 @@ func (c *ContextService) Init(ctx context.Context) (*ContextService, error) {
 		}
 		c.CxtUser = &userInfo
 	}
+	c.Ctx = context.WithValue(ctx, "contextService", c)
 	return c, nil
 }
 
@@ -63,3 +72,24 @@ func (c *ContextService) GetCxtUserDeptId() int {
 	}
 	return c.CxtUser.DeptId
 }
+
+func (c *ContextService) GetCxtUserRoles() []string {
+	if c.CxtUser == nil {
+		return []string{}
+	}
+	return c.CxtUser.Roles
+}
+
+func (c *ContextService) GetCxtUserPosts() []string {
+	if c.CxtUser == nil {
+		return []string{}
+	}
+	return c.CxtUser.Posts
+}
+
+func (c *ContextService) GetCxtUserGroups() []string {
+	if c.CxtUser == nil {
+		return []string{}
+	}
+	return c.CxtUser.Groups
+}

+ 1 - 0
opms_parent/app/service/contract/ctr_contract.go

@@ -206,6 +206,7 @@ func (s CtrContractService) BindProduct(tx *gdb.TX, id int, product []model.CtrA
 			DeletedTime:   gtime.Now(),
 		})
 	}
+
 	if len(tocreate) != 0 {
 		_, err = tx.Insert("ctr_contract_product", tocreate)
 		if err != nil {

+ 159 - 184
opms_parent/app/service/cust/cust_customer.go

@@ -24,17 +24,19 @@ const TIME_LAYOUT = "2006-01-02 15:04:05"
 
 type CustomerService struct {
 	*service.ContextService
-	Dao         *cust.CustCustomerDao
-	BelongDao   *cust.CustCustomerBelongDao
-	DynamicsDao *cust.CustCustomerDynamicsDao
-	ContactDao  *cust.CustCustomerContactDao
-	FollowDao   *platdao.PlatFollowupDao
+	Dao            *cust.CustCustomerDao
+	BelongDao      *cust.CustCustomerBelongDao
+	DynamicsDao    *cust.CustCustomerDynamicsDao
+	ContactDao     *cust.CustCustomerContactDao
+	FollowDao      *platdao.PlatFollowupDao
+	BelongServer   *CustomerbelongService
+	ContanctServer *CustomercontactService
 }
 
-var isPublic, noPublic = "10", "20" // 公海,非公海
-var isTransfer int8 = 1             //转移
-var isAllocation int8 = 2           //分配 Allocation
-var OperaTion, AllocaTion, Receive = "20", "10", "30"
+var isPublic, noPublic = "10", "20"                                // 公海,非公海
+var isTransfer int8 = 1                                            //转移
+var isAllocation int8 = 2                                          //分配 Allocation
+var OperaTion, AllocaTion, Receive, Merge = "20", "10", "30", "40" // 10分配20转移30领取40合并
 
 type OpnType struct {
 	OperaTion string
@@ -50,13 +52,14 @@ func NewCustomerService(ctx context.Context) (svc *CustomerService, err error) {
 	svc.DynamicsDao = cust.NewCustCustomerDynamicsDao(svc.Tenant)
 	svc.ContactDao = cust.NewCustCustomerContactDao(svc.Tenant)
 	svc.FollowDao = platdao.NewPlatFollowupDao(svc.Tenant)
+	svc.BelongServer, _ = NewCustomerBelongService(ctx)
+	svc.ContanctServer, _ = NewCustomerContactService(ctx)
 	return svc, nil
 }
 
 //导出数据
 func (c *CustomerService) Derive(req *model.CustCustomerExport) (content *model.CustExport, err error) {
 	var con model.CustExport
-	req.CustCustomerSearchReq.TargetType = "11"
 	total, data, err := c.GetList(&req.CustCustomerSearchReq)
 	if err != nil {
 		return
@@ -71,18 +74,42 @@ func (c *CustomerService) Derive(req *model.CustCustomerExport) (content *model.
 
 		for ck, item := range data {
 			for index, v := range req.Columns {
-				if v == "经销商编码" {
+				// "CustCode":客户编码
+				if v == "客户编码" {
 					f.SetCellValue("Sheet1", service.Div(index+1)+strconv.Itoa(ck+2), item.CustCode)
 				}
-				if v == "经销商名称" {
+				if v == "客户名称" {
 					f.SetCellValue("Sheet1", service.Div(index+1)+strconv.Itoa(ck+2), item.CustName)
 				}
 				if v == "助记名" {
 					f.SetCellValue("Sheet1", service.Div(index+1)+strconv.Itoa(ck+2), item.AbbrName)
 				}
-				//if v == "所在地区" {
-				//	f.SetCellValue("Sheet1", service.Div(index+1)+strconv.Itoa(ck+2), item.)
-				//}
+				if v == "助记名" {
+					f.SetCellValue("Sheet1", service.Div(index+1)+strconv.Itoa(ck+2), item.AbbrName)
+				}
+				if v == "所在地区" {
+					f.SetCellValue("Sheet1", service.Div(index+1)+strconv.Itoa(ck+2), item.CustLocation)
+				}
+				if v == "客户行业" {
+					f.SetCellValue("Sheet1", service.Div(index+1)+strconv.Itoa(ck+2), item.CustIndustry)
+				}
+				if v == "客户级别" {
+					f.SetCellValue("Sheet1", service.Div(index+1)+strconv.Itoa(ck+2), item.CustLevel)
+				}
+				if v == "客户状态" {
+					var CustStatus string
+					CustStatus = "正常"
+					if item.CustStatus != "10" {
+						CustStatus = "异常"
+					}
+					f.SetCellValue("Sheet1", service.Div(index+1)+strconv.Itoa(ck+2), CustStatus)
+				}
+				if v == "最后跟进时间" {
+					f.SetCellValue("Sheet1", service.Div(index+1)+strconv.Itoa(ck+2), item.FollowUpDate)
+				}
+				if v == "创建时间" {
+					f.SetCellValue("Sheet1", service.Div(index+1)+strconv.Itoa(ck+2), item.CreatedTime)
+				}
 			}
 
 		}
@@ -108,82 +135,43 @@ func (c *CustomerService) Create(req *model.Customer) (insertId int64, err error
 		err = gerror.New("该客户信息已存在,不可重复添加")
 		return
 	}
-	//OpnPeopleId int         ` json:"opnPeopleId"` // 操作人ID
-	//OpnPeople   string      ` json:"opnPeople"`   // 操作人
-	//OpnDate     *gtime.Time ` json:"opnDate"`     // 操作日期
-	//OpnType     string      ` json:"opnType"`     // 操作类型
-	//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()))
+
 	cusTomer.IsPublic = isPublic
 	cusTomer.CustStatus = "10"
-	//if c.CxtUser.DeptId == 2 {
-	//	cusTomer.IsPublic = noPublic            //   非公海用户
-	//	cusTomer.DeptId = c.GetCxtUserDeptId()  //   部门id
-	//	cusTomer.DeptId = c.GetCxtUserDeptId()  //   部门名称
-	//	cusTomer.SalesId = c.GetCxtUserId()     //   销售id
-	//	cusTomer.SalesName = c.GetCxtUserName() //   销售名称
-	//}
 	res, err := Model.Insert(cusTomer)
 	if err != nil {
 		g.Log().Error(err)
 		err = gerror.New("创建失败")
 		return
 	}
-	//
 
-	insertId, _ = res.LastInsertId()
+	/**
+	    	CustomerbelongService :=  new(CustomerbelongService)
+	  	    err = CustomerbelongService.Create(req)
+	*/
 
-	//销售人员创建条件成立 同步belong 表
-	//custBelong := new(model.AddCustomerBelong)
-	//custBelong.CustId = int(insertId)
-	//custBelong.SaleName = "xxx"
-	//custBelong.OpnPeople = "xxxx"
-	//custBelong.OpnDatetime = gtime.Now()
-	//err = c.CreateBelong()
+	insertId, _ = res.LastInsertId()
 	return
 }
 
-//销售人员创建 直接认领客户
-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)
-		return
-	}
-	service.SetCreatedInfo(cusTomerBelong, c.GetCxtUserId(), c.GetCxtUserName())
-
-	cusTomerBelong.OpnType = isPublic
-	cusTomerBelong.OpnDatetime = gtime.Now()
-	service.SetCreatedInfo(cusTomerBelong, c.GetCxtUserId(), c.GetCxtUserName())
-	_, err = c.BelongDao.Insert(cusTomerBelong)
-	if err != nil {
-		g.Log().Error(err)
-		err = gerror.New("创建失败")
-		return
-	}
-	return nil
-
-}
-
 //客户列表列表
 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")
+	//Model = Model.Where(c.Dao.Columns.DeletedTime + " is null")
 	if req.TargetType == "" {
 		if !req.IsPublic {
-			g.Log().Info("ISPUblic", "xxxxxx")
+
 			Model = Model.Where(c.Dao.Columns.SalesId, c.CxtUser.Id).Where(c.Dao.Columns.IsPublic, noPublic)
 		} else {
-			g.Log().Info("serverS", req)
+
 			Model = Model.Where(c.Dao.Columns.IsPublic, isPublic)
 		}
 	}
@@ -217,7 +205,8 @@ func (c *CustomerService) GetList(req *model.CustCustomerSearchReq) (total int,
 	if req.PageNum == 0 {
 		req.PageNum = 1
 	}
-	err = Model.Page(req.PageNum, req.PageSize).Order("id desc").Scan(&customerList)
+
+	err = Model.Page(req.GetPage()).Order("id desc").Scan(&customerList)
 	for _, v := range customerList {
 		times := gconv.String(v.CreatedTime)
 		v.FollowUpDate = gstr.SubStr(v.FollowUpDate, 0, 16)
@@ -228,9 +217,9 @@ func (c *CustomerService) GetList(req *model.CustCustomerSearchReq) (total int,
 
 //删除客户
 func (c *CustomerService) DeleteById(id int) error {
-
-	Model := c.Dao.M
+	Model := c.Dao
 	ContactModel := c.ContactDao //联系人
+	BelongModel := c.BelongDao
 	regionDetail := new(model.CustCustomer)
 	err := Model.Where(c.Dao.Columns.Id, id).Scan(&regionDetail)
 	//g.Log().Info("DeleteByIds", one)
@@ -239,17 +228,22 @@ func (c *CustomerService) DeleteById(id int) error {
 		err = gerror.New("没有要删除的数据")
 		return err
 	}
-	deleteTime := gtime.Now()
-	//删除客户表
-	_, err = Model.Data(g.Map{
-		"deleted_time": deleteTime,
-	}).Where(c.Dao.Columns.Id, id).Update()
-	// 删除客户联系人表
-	_, err = ContactModel.Data(g.Map{
-		"deleted_time": deleteTime,
-	}).Where(c.ContactDao.Columns.CustId, id).Update()
 
-	if err != nil {
+	//删除客户表
+	_, err = Model.Where(c.Dao.Columns.Id, id).Delete()
+	if err == nil {
+		_, err = ContactModel.Where(c.ContactDao.Columns.CustId, id).Delete()
+		if err == nil {
+			_, err = BelongModel.Where(c.BelongDao.Columns.CustId, id).Delete()
+			if err != nil {
+				err = gerror.New("删除数据失败")
+				return err
+			}
+		} else {
+			err = gerror.New("删除数据失败")
+			return err
+		}
+	} else {
 		g.Log().Error(err)
 		err = gerror.New("删除数据失败")
 		return err
@@ -313,29 +307,42 @@ func (c *CustomerService) MoveToPubic(ids []int64) error {
 
 //分配客户
 func (c *CustomerService) DistriCustomer(req *model.DistriCustomer) error {
-	custModel := c.Dao.M
+	custModel := c.Dao
 	rep, err := custModel.Where(cust.CustCustomer.Columns.Id+" in (?)  ", req.Ids).Where(cust.CustCustomer.Columns.IsPublic, isPublic).All()
-	if err != nil {
+
+	g.Log().Info("fdasfsa", len(rep))
+	if err != nil || len(rep) == 0 {
 		err = gerror.New("该数据不存在")
 		return err
 	}
+	//cust := new(model.CustCustomer)
+	var custMap = make(map[int]string)
+	for _, v := range rep {
+		custMap[v.Id] = v.SalesName
+	}
+	g.Log().Info("fadfadsfaf", custMap)
+	for _, v := range req.Ids {
+		g.Log().Info("req.Ids", v)
+		if custMap[gconv.Int(v)] != "" {
+			err = gerror.New("ID" + gconv.String(v) + "已被认领")
+			return err
+		}
+	}
 	err = c.updateCustomer(req.Ids, req.SalesId, req.SalesName)
 	if err != nil {
 		err = gerror.New("可配客户失败")
 		return err
 
 	}
-	var maps = make(map[string]string)
-	maps["remark"] = req.Remark
 	if req.Receive != "" {
-		maps["opn_type"] = AllocaTion
+		req.Receive = Receive
 	} else {
-		maps["opn_type"] = Receive
+		req.Receive = AllocaTion
 	}
-	maps["sale_name"] = req.SalesName
-	maps["opn_people"] = c.GetCxtUserName()
-	//maps["created_by"] = c.GetCxtUserId()
-	err = c.belongInsters(rep.List(), maps)
+
+	err = c.Createbelong(rep, req)
+	g.Log().Info("errr", req)
+
 	if err != nil {
 		err = gerror.New("分配客户失败")
 		return err
@@ -356,6 +363,7 @@ func (c *CustomerService) GetEntityById(ids []int64) (entityInfo []*model.CustLi
 	if err != nil {
 		g.Log().Error(err)
 		return nil, gerror.New("获取用户数据失败")
+
 	}
 	return
 }
@@ -369,7 +377,8 @@ func (c *CustomerService) CustAbstract(id int64) (followInfo *model.Follow, err
 	g.Log().Info("count", count)
 	if err != nil {
 		g.Log().Error(err)
-		return nil, gerror.New("获取用户数据失败")
+		gerror.New("获取用户数据失败")
+		return
 	}
 
 	followInfo = new(model.Follow)
@@ -380,7 +389,8 @@ func (c *CustomerService) CustAbstract(id int64) (followInfo *model.Follow, err
 
 	if err != nil {
 		g.Log().Error(err)
-		return nil, gerror.New("获取用户数据失败")
+		gerror.New("获取用户数据失败")
+		return
 	}
 
 	findOne := find.Map()
@@ -408,25 +418,22 @@ func (c *CustomerService) CustAbstract(id int64) (followInfo *model.Follow, err
 }
 
 //转移客户
-func (c *CustomerService) UpdateBytransfer(req *model.CustSalesReq) (entityInfo []*model.CustCustomer, err error) {
-	custModel := c.Dao.M
+func (c *CustomerService) UpdateBytransfer(req *model.DistriCustomer) (err error) {
+	custModel := c.Dao
 	rep, err := custModel.Fields("sales_id,sales_name,id").Where(cust.CustCustomer.Columns.Id+" in (?)", req.Ids).All()
-	if err != nil || rep.IsEmpty() {
+	if err != nil || len(rep) == 0 {
 		err = gerror.New("该数据不存在")
 		return
 	}
-	err = c.updateCustomer(req.Ids, req.SalesIds, req.SalesName)
+	err = c.updateCustomer(req.Ids, req.SalesId, req.SalesName)
 	if err != nil {
 		err = gerror.New("转移客户失败")
 		return
 	}
 
-	var maps = make(map[string]string)
-	maps["remark"] = req.Remark
-	maps["opn_type"] = OperaTion
-	maps["sale_name"] = req.SalesName
+	err = c.Createbelong(rep, req)
 
-	err = c.belongInsters(rep.List(), maps)
+	g.Log().Info("err", err)
 	if err != nil {
 		err = gerror.New("转移客户失败")
 		return
@@ -528,17 +535,20 @@ func (c *CustomerService) DynamicsList(req *model.CustomerDynameicsReq) (total i
 //合并客户
 func (c *CustomerService) Mergecustomer(req *model.MergecustomerRep) (err error) {
 	Model := c.Dao.M
-	ContactModel := c.ContactDao.M
-	BelongDao := c.BelongDao.M
+	//ContactModel := c.ContactDao.M
+	BelongDao := c.BelongDao
 	//当前目标客户是否存在
 	FindOne, err := Model.Where(c.Dao.Columns.DeletedTime+" is  null").Where(c.Dao.Columns.Id, req.Id).FindOne()
 	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())
+	ContactModel := c.ContactDao
+	_, err = ContactModel.Where(c.ContactDao.Columns.CustId+" in (?)", req.ChooseId).WhereOr(c.ContactDao.Columns.CustId, req.Id).Delete()
+	if err != nil {
+		err = gerror.New("合并联系人失败")
+		return
+	}
 	CustomertData := new(model.Customer)
 	if err = gconv.Struct(req, CustomertData); err != nil {
 		return
@@ -546,112 +556,77 @@ func (c *CustomerService) Mergecustomer(req *model.MergecustomerRep) (err error)
 	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)
+		c.Dao.Columns.CustCode).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 {
-			err = gerror.New("合并失败")
-			return
-		}
+	//删除被合并的客户信息
+	Model.Where(c.Dao.Columns.Id+" in (?)", req.ChooseId).Delete()
+	//删除 所选客户销售联系人
+	_, err = BelongDao.Where(c.BelongDao.Columns.CustId+" in (?)", req.ChooseId).WhereOr(c.BelongDao.Columns.CustId, req.Id).Delete()
+	if err != nil {
+		err = gerror.New("合并失败")
+		return
 	}
-	////所选客户销售联系人信息
-	BelongList, err := BelongDao.Where(c.BelongDao.Columns.CustId+" in (?)", req.ChooseId).All()
-	if err != nil || BelongList.Len() > 0 {
-		err = c.belongInster(req.Id, req.ChooseId, req.Customer.SalesName)
-		if err != nil {
-			err = gerror.New("合并失败")
-			return
-		}
+
+	//插入一条合并成功的归属记录
+	belongService := c.BelongServer //
+	req.AddCustomerBelong.CustId = req.Id
+	req.AddCustomerBelong.OpnType = Merge
+	req.AddCustomerBelong.OpnPeople = c.GetCxtUserName()
+	req.AddCustomerBelong.OpnDatetime = gtime.Now()
+	req.AddCustomerBelong.SaleName = req.SalesName
+	err = belongService.Create(req.AddCustomerBelong)
+	if err != nil {
+		err = gerror.New("合并失败")
+		return
 	}
 	return
 }
 
-//联系人
-func (c *CustomerService) contactInster(id int, Ids []int64, list []map[string]interface{}) (err error) {
+//联系人(合并)
+func (c *CustomerService) Createcontact(id int, Ids []int64, req *model.CustCustomerContactSeq) (err error) {
 	ContactModel := c.ContactDao.M
-	ContactModel.Data(g.Map{"deleted_time": gtime.Now()}).Where(c.ContactDao.Columns.CustId+" in (?)", Ids).Update()
-	maps := []map[string]interface{}{}
-	for _, v := range list {
-		contact := map[string]interface{}{}
-		contact["cust_id"] = id
-		contact["cuct_name"] = v["cuct_name"]
-		contact["cuct_gender"] = v["cuct_gender"]
-		contact["postion"] = v["postion"]
-		contact["telephone"] = v["telephone"]
-		contact["wechat"] = v["wechat"]
-		contact["email"] = v["email"]
-		contact["policy"] = v["policy"]
-		contact["remark"] = v["remark"]
-		contact["created_by"] = v["created_by"]
-		contact["created_name"] = v["created_name"]
-		contact["created_time"] = v["created_time"]
-		maps = append(maps, contact)
-	}
-	_, err = ContactModel.Insert(maps)
+	_, err = ContactModel.Where(c.ContactDao.Columns.CustId+" in (?)", Ids).WhereOr(c.ContactDao.Columns.CustId, id).Delete()
 	if err != nil {
-		err = gerror.New("操作失败")
-		g.Log().Info("contactInster", err)
+		err = gerror.New("合并联系人失败")
 		return
-
 	}
-
-	return
-}
-
-//销售
-func (c *CustomerService) belongInster(Id int, BelongIds []int64, SaleName string) (err error) {
-	BelongDao := c.BelongDao.M
-	BelongDao.Data(g.Map{"deleted_time": gtime.Now()}).Where(c.BelongDao.Columns.CustId+" in (?)", BelongIds).Update()
-	BelongData := new(model.CustCustomerBelong)
-	BelongData.CustId = Id
-	service.SetCreatedInfo(BelongData, c.GetCxtUserId(), c.GetCxtUserName())
-	BelongData.SaleName = SaleName
-	BelongData.OpnType = AllocaTion
-	BelongData.OrigSaleName = ""
-	BelongData.OpnPeople = "admin"
-	BelongData.OpnDatetime = gtime.Now()
-	_, err = BelongDao.Insert(BelongData)
+	contactService := c.ContanctServer //new(CustomercontactService)
+	err = contactService.Create(req)
 	if err != nil {
-		g.Log().Info("BeloongInster", err)
-		err = gerror.New("操作失败")
+		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{}{}
+//批量插入客户归属记录表//parameter map[string]string
+func (c *CustomerService) Createbelong(rep []*model.CustCustomer, req *model.DistriCustomer) (err error) {
+	belongModel := c.BelongDao
+	var belongData []*model.CustCustomerBelong
 	date_time := gtime.Now()
+	userName := c.GetCxtUserName()
 	for _, v := range rep {
-		orig_sale_name := v["sales_name"]
-		belong := map[string]interface{}{}
-		belong["cust_id"] = v["id"].(int)
-		belong["sale_name"] = parameter["sale_name"]
-		belong["orig_sale_name"] = orig_sale_name
-		belong["opn_type"] = parameter["opn_type"]
-		belong["opn_people"] = parameter["opn_people"]
-		belong["opn_datetime"] = date_time
-		belong["created_by"] = c.GetCxtUserId()
-		belong["remark"] = parameter["remark"]
-		belong["created_name"] = c.GetCxtUserName()
-		belong["created_time"] = date_time
-		belong["opn_datetime"] = date_time
-		maps = append(maps, belong)
-	}
-	_, err = belongModel.Insert(maps)
+		orig_sale_name := v.SalesName
+		belong := new(model.CustCustomerBelong) //map[string]interface{}{}
+		belong.CustId = v.Id
+		belong.SaleName = req.SalesName
+		belong.OrigSaleName = orig_sale_name
+		belong.OpnType = req.Receive
+		belong.OpnPeople = userName
+		belong.CreatedName = userName
+		belong.OpnDatetime = date_time
+		belong.Remark = req.Remark
+		belong.CreatedBy = c.GetCxtUserId()
+		belongData = append(belongData, belong)
+	}
+	_, err = belongModel.Insert(belongData)
+	g.Log().Info("belong", belongData)
 	if err != nil {
 		err = gerror.New("插入失败")
 		return err
 	}
-
 	return
 }

+ 57 - 5
opms_parent/app/service/cust/cust_customer_belong.go

@@ -5,19 +5,21 @@ import (
 
 	"github.com/gogf/gf/errors/gerror"
 	"github.com/gogf/gf/frame/g"
+	"github.com/gogf/gf/os/gtime"
+	"github.com/gogf/gf/util/gconv"
 
 	"dashoo.cn/micro/app/dao/cust"
 	model "dashoo.cn/micro/app/model/cust"
 	"dashoo.cn/micro/app/service"
 )
 
-type customerbelongService struct {
+type CustomerbelongService struct {
 	*service.ContextService
 	Dao *cust.CustCustomerBelongDao
 }
 
-func NewCustomerBelongService(ctx context.Context) (svc *customerbelongService, err error) {
-	svc = new(customerbelongService)
+func NewCustomerBelongService(ctx context.Context) (svc *CustomerbelongService, err error) {
+	svc = new(CustomerbelongService)
 	if svc.ContextService, err = svc.Init(ctx); err != nil {
 		return nil, err
 	}
@@ -26,8 +28,8 @@ func NewCustomerBelongService(ctx context.Context) (svc *customerbelongService,
 }
 
 //获取客户归属信息
-func (c *customerbelongService) GetEntityById(CustId int) (Info []*model.CustomerBelongInfo, err error) {
-	Model := c.Dao.M
+func (c *CustomerbelongService) GetList(CustId int) (Info []*model.CustomerBelongInfo, err error) {
+	Model := c.Dao
 	err = Model.Where(c.Dao.Columns.CustId, CustId).Where(c.Dao.Columns.DeletedTime + " is null ").Scan(&Info)
 	if err != nil {
 		g.Log().Error(err)
@@ -36,3 +38,53 @@ func (c *customerbelongService) GetEntityById(CustId int) (Info []*model.Custome
 	}
 	return
 }
+
+func (c *CustomerbelongService) Create(req *model.AddCustomerBelong) (err error) {
+	Model := c.Dao
+	cusTomerBelong := new(model.CustCustomerBelong)
+	if err = gconv.Struct(req, cusTomerBelong); err != nil {
+		g.Log().Info("error", err)
+		return
+	}
+	service.SetCreatedInfo(cusTomerBelong, c.GetCxtUserId(), c.GetCxtUserName())
+	cusTomerBelong.OpnType = noPublic
+	cusTomerBelong.OpnPeople = c.GetCxtUserName()
+	cusTomerBelong.OpnDatetime = gtime.Now()
+	_, err = Model.Insert(cusTomerBelong)
+	if err != nil {
+		g.Log().Error(err)
+		err = gerror.New("创建失败")
+		return
+	}
+	return nil
+}
+
+//批量插入客户归属记录表
+//func (c *CustomerbelongService) Create(rep []*model.CustCustomer, req *model.DistriCustomer) (err error) {
+//	belongModel := c.Dao
+//	var belongData []*model.CustCustomerBelong
+//	date_time := gtime.Now()
+//	userName := c.GetCxtUserName()
+//	for _, v := range rep {
+//		orig_sale_name := v.SalesName
+//		belong := new(model.CustCustomerBelong) //map[string]interface{}{}
+//		belong.CustId = v.Id
+//		belong.SaleName = req.SalesName
+//		belong.OrigSaleName = orig_sale_name
+//		belong.OpnType = req.Receive
+//		belong.OpnPeople = userName
+//		belong.CreatedName = userName
+//		belong.OpnDatetime = date_time
+//		belong.Remark = req.Remark
+//		belong.CreatedBy = c.GetCxtUserId()
+//		belongData = append(belongData, belong)
+//	}
+//	_, err = belongModel.Insert(belongData)
+//	g.Log().Info("belong", belongData)
+//	if err != nil {
+//		err = gerror.New("插入失败")
+//		return err
+//	}
+//	return
+//
+//}

+ 9 - 12
opms_parent/app/service/cust/cust_customer_contact.go

@@ -6,7 +6,6 @@ import (
 
 	"github.com/gogf/gf/errors/gerror"
 	"github.com/gogf/gf/frame/g"
-	"github.com/gogf/gf/os/gtime"
 	"github.com/gogf/gf/util/gconv"
 
 	"dashoo.cn/micro/app/dao/cust"
@@ -15,13 +14,13 @@ import (
 	//serviceLog "dashoo.cn/micro/app/service/cust"
 )
 
-type customercontactService struct {
+type CustomercontactService struct {
 	*service.ContextService
 	Dao *cust.CustCustomerContactDao
 }
 
-func NewCustomerContactService(ctx context.Context) (svc *customercontactService, err error) {
-	svc = new(customercontactService)
+func NewCustomerContactService(ctx context.Context) (svc *CustomercontactService, err error) {
+	svc = new(CustomercontactService)
 
 	if svc.ContextService, err = svc.Init(ctx); err != nil {
 		return nil, err
@@ -33,7 +32,7 @@ func NewCustomerContactService(ctx context.Context) (svc *customercontactService
 }
 
 //添加联系人
-func (c *customercontactService) Create(req *model.CustCustomerContactSeq) (err error) {
+func (c *CustomercontactService) Create(req *model.CustCustomerContactSeq) (err error) {
 	contact := new(model.CustCustomerContact)
 	if err = gconv.Struct(req, contact); err != nil {
 		g.Log().Info("error", err)
@@ -52,7 +51,7 @@ func (c *customercontactService) Create(req *model.CustCustomerContactSeq) (err
 }
 
 //修改联系人
-func (c *customercontactService) UpdateById(req *model.UpdateCustCustomerContactSeq) (err error) {
+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() {
@@ -76,7 +75,7 @@ func (c *customercontactService) UpdateById(req *model.UpdateCustCustomerContact
 }
 
 //获取联系人信息
-func (c *customercontactService) GetEntityById(CustId int) (Info []*model.CustCustomerContactInfo, err error) {
+func (c *CustomercontactService) GetList(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 {
@@ -88,14 +87,12 @@ func (c *customercontactService) GetEntityById(CustId int) (Info []*model.CustCu
 }
 
 //删除联系人
-func (c *customercontactService) DeleteById(id int) error {
+func (c *CustomercontactService) DeleteById(id int) error {
 	Model := c.Dao.M
 
-	deleteTime := gtime.Now()
+	//deleteTime := gtime.Now()
 	// 删除客户联系人表
-	_, err := Model.Data(g.Map{
-		"deleted_time": deleteTime,
-	}).Where(c.Dao.Columns.Id, id).Update()
+	_, err := Model.Where(c.Dao.Columns.Id, id).Delete()
 	if err != nil {
 		g.Log().Error(err)
 		err = gerror.New("删除数据失败")

+ 1 - 1
opms_parent/main.go

@@ -28,7 +28,7 @@ func main() {
 	s.RegisterName("District", new(base.DistrictHandler), "")
 	s.RegisterName("Region", new(base.RegionHandler), "")
 	s.RegisterName("Customer", new(cust.CustomerHeader), "")
-	s.RegisterName("Contant", new(cust.CustomerContantHeader), "")
+	s.RegisterName("Contact", new(cust.CustomerContantHeader), "")
 	s.RegisterName("Belong", new(cust.CustBelongHeader), "")
 	s.RegisterName("FollowUp", new(plat.FollowUpHandler), "")
 	s.RegisterName("FollowUpComment", new(plat.FollowUpCommentHandler), "")