Просмотр исходного кода

Merge branch 'develop' into feature/项目管理

# Conflicts:
#	opms_parent/main.go
ZZH-wl 3 лет назад
Родитель
Сommit
6bc403337b
35 измененных файлов с 1121 добавлено и 631 удалено
  1. 0 22
      opms_admin/app/common/global/cache_key.go
  2. 0 245
      opms_admin/app/common/service/cache.go
  3. 3 0
      opms_admin/app/dao/internal/sys_menu.go
  4. 14 9
      opms_admin/app/handler/menu.go
  5. 80 115
      opms_admin/app/handler/user.go
  6. 1 0
      opms_admin/app/model/internal/sys_menu.go
  7. 2 0
      opms_admin/app/model/sys_menu.go
  8. 0 11
      opms_admin/app/service/sys_config.go
  9. 16 32
      opms_admin/app/service/sys_dict_data.go
  10. 0 11
      opms_admin/app/service/sys_dict_type.go
  11. 18 0
      opms_admin/app/service/sys_menu.go
  12. 9 16
      opms_admin/app/service/sys_role.go
  13. 12 11
      opms_admin/app/service/sys_user.go
  14. 1 1
      opms_admin/go.mod
  15. 3 0
      opms_parent/app/dao/cust/internal/cust_customer_dynamics.go
  16. 38 2
      opms_parent/app/handler/base/distributor.go
  17. 15 0
      opms_parent/app/handler/base/district.go
  18. 2 4
      opms_parent/app/handler/base/region.go
  19. 36 0
      opms_parent/app/handler/cust/belong.go
  20. 88 0
      opms_parent/app/handler/cust/contant.go
  21. 142 6
      opms_parent/app/handler/cust/customer.go
  22. 13 1
      opms_parent/app/model/base/base_distributor.go
  23. 50 17
      opms_parent/app/model/cust/cust_customer.go
  24. 14 0
      opms_parent/app/model/cust/cust_customer_belong.go
  25. 41 9
      opms_parent/app/model/cust/cust_customer_contact.go
  26. 10 2
      opms_parent/app/model/cust/cust_customer_dynamics.go
  27. 24 23
      opms_parent/app/model/cust/internal/cust_customer.go
  28. 1 0
      opms_parent/app/model/cust/internal/cust_customer_dynamics.go
  29. 54 1
      opms_parent/app/service/base/base_distributor.go
  30. 8 9
      opms_parent/app/service/base/base_district.go
  31. 2 2
      opms_parent/app/service/base/base_sales_region_detail.go
  32. 323 80
      opms_parent/app/service/cust/cust_customer.go
  33. 37 0
      opms_parent/app/service/cust/cust_customer_belong.go
  34. 61 2
      opms_parent/app/service/cust/cust_customer_contact.go
  35. 3 0
      opms_parent/main.go

+ 0 - 22
opms_admin/app/common/global/cache_key.go

@@ -1,22 +0,0 @@
-package global
-
-const (
-	// CachePrefix 缓存前缀
-	CachePrefix = "cacheOv2_"
-
-	// SysAuthMenu 缓存菜单KEY
-	SysAuthMenu = CachePrefix + "sysAuthMenu"
-	// SysDict 字典缓存菜单KEY
-	SysDict = CachePrefix + "sysDict"
-	// SysRole 角色缓存key
-	SysRole = CachePrefix + "sysRole"
-	// SysWebSet 站点配置缓存key
-	SysWebSet = CachePrefix + "sysWebSet"
-
-	// SysAuthTag 权限缓存TAG标签
-	SysAuthTag = CachePrefix + "sysAuthTag"
-	// SysDictTag 字典缓存标签
-	SysDictTag = CachePrefix + "sysDictTag"
-	// SysConfigTag 系统参数配置
-	SysConfigTag = CachePrefix + "sysConfigTag"
-)

+ 0 - 245
opms_admin/app/common/service/cache.go

@@ -1,245 +0,0 @@
-package service
-
-import (
-	"context"
-	"dashoo.cn/micro/app/common/global"
-	"fmt"
-	"github.com/gogf/gcache-adapter/adapter"
-	"github.com/gogf/gf/crypto/gmd5"
-	"github.com/gogf/gf/encoding/gjson"
-	"github.com/gogf/gf/frame/g"
-	"github.com/gogf/gf/os/gcache"
-	"github.com/gogf/gf/util/gconv"
-	"reflect"
-	"sync"
-	"time"
-)
-
-type cache struct {
-}
-
-type cacheTagService struct {
-	tagKey    interface{}
-	cache     *gcache.Cache
-	tagSetMux *sync.Mutex
-}
-
-var (
-	Cache     = new(cache)
-	userRedis = g.Cfg().GetBool("redis.open")
-	gChe      = gcache.New()
-)
-
-func (s *cache) New() *cacheTagService {
-	gChe.Ctx(context.Background())
-	if userRedis {
-		adapter := adapter.NewRedis(g.Redis())
-		gChe.SetAdapter(adapter)
-	}
-	return &cacheTagService{
-		cache:     gChe,
-		tagSetMux: new(sync.Mutex),
-	}
-}
-
-// 设置tag缓存的keys
-func (c *cacheTagService) cacheTagKey(key interface{}, tag interface{}) {
-	c.setTagKey(tag)
-	if c.tagKey != nil {
-		tagValue := []interface{}{key}
-		value, _ := c.cache.Get(c.tagKey)
-		if value != nil {
-			var keyValue []interface{}
-			//若是字符串
-			if kStr, ok := value.(string); ok {
-				js, err := gjson.DecodeToJson(kStr)
-				if err != nil {
-					g.Log().Error(err)
-					return
-				}
-				keyValue = gconv.SliceAny(js.Value())
-			} else {
-				keyValue = gconv.SliceAny(value)
-			}
-			for _, v := range keyValue {
-				if !reflect.DeepEqual(key, v) {
-					tagValue = append(tagValue, v)
-				}
-			}
-		}
-		c.cache.Set(c.tagKey, tagValue, 0)
-	}
-}
-
-// 获取带标签的键名
-func (c *cacheTagService) setTagKey(tag interface{}) {
-	if tag != nil {
-		c.tagKey = interface{}(fmt.Sprintf("%s_tag_%s", global.CachePrefix, gmd5.MustEncryptString(gconv.String(tag))))
-	}
-}
-
-// Set sets cache with <tagKey>-<value> pair, which is expired after <duration>.
-// It does not expire if <duration> <= 0.
-func (c *cacheTagService) Set(key interface{}, value interface{}, duration time.Duration, tag ...interface{}) {
-	c.tagSetMux.Lock()
-	if len(tag) > 0 {
-		c.cacheTagKey(key, tag[0])
-	}
-	err := c.cache.Set(key, value, duration)
-	if err != nil {
-		g.Log().Error(err)
-	}
-	c.tagSetMux.Unlock()
-}
-
-// SetIfNotExist sets cache with <tagKey>-<value> pair if <tagKey> does not exist in the cache,
-// which is expired after <duration>. It does not expire if <duration> <= 0.
-func (c *cacheTagService) SetIfNotExist(key interface{}, value interface{}, duration time.Duration, tag interface{}) bool {
-	c.tagSetMux.Lock()
-	defer c.tagSetMux.Unlock()
-	c.cacheTagKey(key, tag)
-	v, _ := c.cache.SetIfNotExist(key, value, duration)
-	return v
-}
-
-// Sets batch sets cache with tagKey-value pairs by <data>, which is expired after <duration>.
-//
-// It does not expire if <duration> <= 0.
-func (c *cacheTagService) Sets(data map[interface{}]interface{}, duration time.Duration, tag interface{}) {
-	c.tagSetMux.Lock()
-	if tag != nil {
-		for k, _ := range data {
-			c.cacheTagKey(k, tag)
-		}
-		c.cache.Sets(data, duration)
-	} else {
-		c.cache.Sets(data, duration)
-	}
-	c.tagSetMux.Unlock()
-}
-
-// Get returns the value of <tagKey>.
-// It returns nil if it does not exist or its value is nil.
-func (c *cacheTagService) Get(key interface{}) interface{} {
-	v, err := c.cache.Get(key)
-	if err != nil {
-		g.Log().Error(err)
-	}
-	return v
-}
-
-// GetOrSet returns the value of <tagKey>,
-// or sets <tagKey>-<value> pair and returns <value> if <tagKey> does not exist in the cache.
-// The tagKey-value pair expires after <duration>.
-//
-// It does not expire if <duration> <= 0.
-func (c *cacheTagService) GetOrSet(key interface{}, value interface{}, duration time.Duration, tag interface{}) interface{} {
-	c.tagSetMux.Lock()
-	defer c.tagSetMux.Unlock()
-	c.cacheTagKey(key, tag)
-	v, _ := c.cache.GetOrSet(key, value, duration)
-	return v
-}
-
-// GetOrSetFunc returns the value of <tagKey>, or sets <tagKey> with result of function <f>
-// and returns its result if <tagKey> does not exist in the cache. The tagKey-value pair expires
-// after <duration>. It does not expire if <duration> <= 0.
-func (c *cacheTagService) GetOrSetFunc(key interface{}, f func() (interface{}, error), duration time.Duration, tag interface{}) interface{} {
-	c.tagSetMux.Lock()
-	defer c.tagSetMux.Unlock()
-	c.cacheTagKey(key, tag)
-	v, _ := c.cache.GetOrSetFunc(key, f, duration)
-	return v
-}
-
-// GetOrSetFuncLock returns the value of <tagKey>, or sets <tagKey> with result of function <f>
-// and returns its result if <tagKey> does not exist in the cache. The tagKey-value pair expires
-// after <duration>. It does not expire if <duration> <= 0.
-//
-// Note that the function <f> is executed within writing mutex lock.
-func (c *cacheTagService) GetOrSetFuncLock(key interface{}, f func() (interface{}, error), duration time.Duration, tag interface{}) interface{} {
-	c.tagSetMux.Lock()
-	defer c.tagSetMux.Unlock()
-	c.cacheTagKey(key, tag)
-	v, _ := c.cache.GetOrSetFuncLock(key, f, duration)
-	return v
-}
-
-// Contains returns true if <tagKey> exists in the cache, or else returns false.
-func (c *cacheTagService) Contains(key interface{}) bool {
-	v, _ := c.cache.Contains(key)
-	return v
-}
-
-// Remove deletes the <tagKey> in the cache, and returns its value.
-func (c *cacheTagService) Remove(key interface{}) interface{} {
-	v, _ := c.cache.Remove(key)
-	return v
-}
-
-// Removes deletes <keys> in the cache.
-func (c *cacheTagService) Removes(keys []interface{}) {
-	c.cache.Remove(keys...)
-}
-
-// Remove deletes the <tag> in the cache, and returns its value.
-func (c *cacheTagService) RemoveByTag(tag interface{}) {
-	c.tagSetMux.Lock()
-	c.setTagKey(tag)
-	//删除tagKey 对应的 key和值
-	keys := c.Get(c.tagKey)
-	if keys != nil {
-		//如果是字符串
-		if kStr, ok := keys.(string); ok {
-			js, err := gjson.DecodeToJson(kStr)
-			if err != nil {
-				g.Log().Error(err)
-				return
-			}
-			ks := gconv.SliceAny(js.Value())
-			c.Removes(ks)
-		} else {
-			ks := gconv.SliceAny(keys)
-			c.Removes(ks)
-		}
-	}
-	c.Remove(c.tagKey)
-	c.tagSetMux.Unlock()
-}
-
-// Removes deletes <tags> in the cache.
-func (c *cacheTagService) RemoveByTags(tag []interface{}) {
-	for _, v := range tag {
-		c.RemoveByTag(v)
-	}
-}
-
-// Data returns a copy of all tagKey-value pairs in the cache as map type.
-func (c *cacheTagService) Data() map[interface{}]interface{} {
-	v, _ := c.cache.Data()
-	return v
-}
-
-// Keys returns all keys in the cache as slice.
-func (c *cacheTagService) Keys() []interface{} {
-	v, _ := c.cache.Keys()
-	return v
-}
-
-// KeyStrings returns all keys in the cache as string slice.
-func (c *cacheTagService) KeyStrings() []string {
-	v, _ := c.cache.KeyStrings()
-	return v
-}
-
-// Values returns all values in the cache as slice.
-func (c *cacheTagService) Values() []interface{} {
-	v, _ := c.cache.Values()
-	return v
-}
-
-// Size returns the size of the cache.
-func (c *cacheTagService) Size() int {
-	v, _ := c.cache.Size()
-	return v
-}

+ 3 - 0
opms_admin/app/dao/internal/sys_menu.go

@@ -41,6 +41,7 @@ type sysMenuColumns struct {
 	PlatformId  string // 所属平台
 	Sort        string // 显示顺序
 	ActiveMenu  string // 高亮路由
+	NoColumn    string // 是否展示栏目20 不展示
 	Remark      string // 备注
 	CreatedBy   string // 创建者
 	CreatedName string // 创建人
@@ -74,6 +75,7 @@ var (
 			PlatformId:  "platform_id",
 			Sort:        "sort",
 			ActiveMenu:  "active_menu",
+			NoColumn:    "no_column",
 			Remark:      "remark",
 			CreatedBy:   "created_by",
 			CreatedName: "created_name",
@@ -109,6 +111,7 @@ func NewSysMenuDao(tenant string) SysMenuDao {
 			PlatformId:  "platform_id",
 			Sort:        "sort",
 			ActiveMenu:  "active_menu",
+			NoColumn:    "no_column",
 			Remark:      "remark",
 			CreatedBy:   "created_by",
 			CreatedName: "created_name",

+ 14 - 9
opms_admin/app/handler/menu.go

@@ -106,18 +106,17 @@ func (h *MenuHandler) DeleteById(ctx context.Context, req *comm_def.IdReq, rsp *
 
 // GetRoleMenuIds 根据角色获取菜单
 //func (o *MenuHandler) GetRoleMenuIds(ctx context.Context, req *menu_def.RoleIdReq, rsp *comm_def.CommonMsg) error {
-//	service, err := role_menu.NewService(tenant)
+//	menuService, err := service.NewMenuService(ctx)
 //	if err != nil {
-//		g.Log().Error(err)
 //		return gerror.New("系统异常,请重新尝试")
 //	}
 //
-//	entity, err := service.GetRoleMenuIds(req.RoleId)
-//	_, err, code, msg := myerrors.CheckError(err)
-//	rsp.Code = code
-//	rsp.Msg = msg
+//	entity, err := menuService.GetRoleMenuIds(req.RoleId)
+//	_, err, rsp.Code, rsp.Msg = myerrors.CheckError(err)
+//	if err != nil {
+//		return err
+//	}
 //	rsp.Data = entity
-//
 //	return nil
 //}
 
@@ -125,14 +124,20 @@ func (h *MenuHandler) DeleteById(ctx context.Context, req *comm_def.IdReq, rsp *
 func (h *MenuHandler) GetMenuTree(ctx context.Context, req map[string]interface{}, rsp *comm_def.CommonMsg) error {
 	menuService, err := service.NewMenuService(ctx)
 	if err != nil {
-		g.Log().Error(err)
 		return gerror.New("系统异常,请重新尝试")
 	}
 	isAll := false
 	if val, ok := req["isAll"]; ok && val == "all" {
 		isAll = true
 	}
-	list, err := menuService.GetMenuTree(isAll)
+	var list interface{}
+	if menuService.GetCxtUserName() == "dashoo" {
+		list, err = menuService.GetMenuTree(isAll)
+	} else {
+		userService, _ := service.NewUserService(ctx)
+		userRoles, _ := userService.GetUserRoleIds(userService.GetCxtUserId())
+		list, err = menuService.GetUserRoleMenuTree(userRoles)
+	}
 	_, _, rsp.Code, rsp.Msg = myerrors.CheckError(err)
 	rsp.Data = list
 	return nil

+ 80 - 115
opms_admin/app/handler/user.go

@@ -2,8 +2,10 @@ package handler
 
 import (
 	"context"
+	"dashoo.cn/common_definition/admin/user_def"
 	"dashoo.cn/micro/app/model"
 	"dashoo.cn/micro/app/service"
+	"dashoo.cn/opms_libary/micro_srv"
 	"dashoo.cn/opms_libary/myerrors"
 	"github.com/gogf/gf/errors/gerror"
 	"github.com/gogf/gf/util/gvalid"
@@ -90,18 +92,16 @@ func (h *UserHandler) UpdateById(ctx context.Context, req *model.EditUserReq, rs
 func (e *UserHandler) GetUserInfo(ctx context.Context, req *comm_def.IdReq, rsp *comm_def.CommonMsg) error {
 	userService, err := service.NewUserService(ctx)
 	if err != nil {
-		g.Log().Error(err)
 		return gerror.New("系统异常,请重新尝试")
 	}
-	userId := int(req.Id)
-	if req.Id == 0 {
-		// 从上下文中获取用户
-		userId = userService.GetCxtUserId()
+	// 从上下文中获取用户
+	userId := userService.GetCxtUserId()
+	if req.Id != 0 {
+		userId = int(req.Id)
 	}
 
 	data, err := userService.GetUserInfoById(userId)
 	if err != nil {
-		g.Log().Error(err)
 		return err
 	}
 	// 获取用户权限 角色
@@ -110,6 +110,13 @@ func (e *UserHandler) GetUserInfo(ctx context.Context, req *comm_def.IdReq, rsp
 	if err != nil {
 		return err
 	}
+	roleService, _ := service.NewRoleService(ctx)
+	permissions, err := roleService.GetRolesMenuPermissions(userRoles)
+	_, err, rsp.Code, rsp.Msg = myerrors.CheckError(err)
+	if err != nil {
+		return err
+	}
+
 	userPosts, err := userService.GetUserPostIds(userId)
 	_, err, rsp.Code, rsp.Msg = myerrors.CheckError(err)
 	if err != nil {
@@ -122,38 +129,30 @@ func (e *UserHandler) GetUserInfo(ctx context.Context, req *comm_def.IdReq, rsp
 	}
 
 	rsp.Data = g.Map{
-		"entity":   data,
-		"roleIds":  userRoles,
-		"postIds":  userPosts,
-		"groupIds": userGroups,
+		"entity":      data,
+		"permissions": permissions,
+		"roleIds":     userRoles,
+		"postIds":     userPosts,
+		"groupIds":    userGroups,
 	}
 	return nil
 }
 
 //// GetEntityByUuId 根据UUID获取用户实体信息
 //func (e *UserHandler) GetEntityByUuId(ctx context.Context, req *user_def.UuIdReq, rsp *comm_def.CommonMsg) error {
-//	// 获取租户码
-//	tenant, err := micro_srv.GetTenant(ctx)
-//	if err != nil {
-//		return err
-//	}
-//	g.Log().Info("Received UserHandler.GetEntityByUuId request @ " + tenant)
 //	// 参数校验
 //	if req.Uuid == "" {
 //		return NoParamsErr
 //	}
-//	service, err := user.NewService(tenant)
+//	userService, err := service.NewUserService(ctx)
 //	if err != nil {
-//		g.Log().Error(err)
 //		return gerror.New("系统异常,请重新尝试")
 //	}
-//	data, err := service.GetEntityByUuId(req.Uuid)
-//	_, err, code, msg := myerrors.CheckError(err)
+//	data, err := userService.GetEntityByUuId(req.Uuid)
+//	_, err, rsp.Code, rsp.Msg = myerrors.CheckError(err)
 //	if err != nil {
 //		return err
 //	}
-//	rsp.Code = code
-//	rsp.Msg = msg
 //	rsp.Data = data
 //	return nil
 //}
@@ -178,71 +177,41 @@ func (h *UserHandler) DeleteByIds(ctx context.Context, req *comm_def.IdsReq, rsp
 	return nil
 }
 
-//// ResetPassword 密码重置(管理员进行操作)
-//func (e *UserHandler) ResetPassword(ctx context.Context, req *user_def.ResetPwdReq, rsp *comm_def.CommonMsg) error {
-//	// 获取租户码
-//	tenant, err := micro_srv.GetTenant(ctx)
-//	if err != nil {
-//		return err
-//	}
-//	g.Log().Info("Received UserHandler.ResetPassword request @ " + tenant)
-//	if req.Id == 0 || req.Password == "" {
-//		return NoParamsErr
-//	}
-//	if err = gvalid.CheckStruct(ctx, req, nil); err != nil {
-//		return err
-//	}
-//	// todo:校验用户是否有修改权限
-//	service, err := user.NewService(tenant)
-//	if err != nil {
-//		g.Log().Error(err)
-//		return gerror.New("系统异常,请重新尝试")
-//	}
-//	userInfo, err := micro_srv.GetUserInfo(ctx)
-//	if err != nil {
-//		return err
-//	}
-//	err = service.ResetPassword(&userInfo, req.Id, req.Password)
-//	_, err, code, msg := myerrors.CheckError(err)
-//	if err != nil {
-//		return err
-//	}
-//	rsp.Code = code
-//	rsp.Msg = msg
-//	return nil
-//}
-//
-//// SetStatus 设置用户状态
-//func (e *UserHandler) SetStatus(ctx context.Context, req *user_def.SetStatusReq, rsp *comm_def.CommonMsg) error {
-//	// 获取租户码
-//	tenant, err := micro_srv.GetTenant(ctx)
-//	if err != nil {
-//		return err
-//	}
-//	g.Log().Info("Received UserHandler.SetStatus request @ " + tenant)
-//	// 参数校验
-//	if req.Id == 0 {
-//		return NoParamsErr
-//	}
-//	service, err := user.NewService(tenant)
-//	if err != nil {
-//		g.Log().Error(err)
-//		return gerror.New("系统异常,请重新尝试")
-//	}
-//	userInfo, err := micro_srv.GetUserInfo(ctx)
-//	if err != nil {
-//		return err
-//	}
-//	err = service.SetStatus(&userInfo, req.Id, req.Enabled)
-//	_, err, code, msg := myerrors.CheckError(err)
-//	if err != nil {
-//		return err
-//	}
-//	rsp.Code = code
-//	rsp.Msg = msg
-//	return nil
-//}
-//
+// ResetPassword 密码重置(管理员进行操作)
+func (e *UserHandler) ResetPassword(ctx context.Context, req *model.SysUserResetPwdReq, rsp *comm_def.CommonMsg) error {
+	if err := gvalid.CheckStruct(ctx, req, nil); err != nil {
+		return err
+	}
+	// todo:校验用户是否有修改权限
+	userService, err := service.NewUserService(ctx)
+	if err != nil {
+		return gerror.New("系统异常,请重新尝试")
+	}
+	err = userService.ResetUserPwd(req)
+	_, err, rsp.Code, rsp.Msg = myerrors.CheckError(err)
+	if err != nil {
+		return err
+	}
+	return nil
+}
+
+// SetStatus 设置用户状态
+func (e *UserHandler) SetStatus(ctx context.Context, req *model.SysUserStatusReq, rsp *comm_def.CommonMsg) error {
+	if err := gvalid.CheckStruct(ctx, req, nil); err != nil {
+		return err
+	}
+	userService, err := service.NewUserService(ctx)
+	if err != nil {
+		return gerror.New("系统异常,请重新尝试")
+	}
+	err = userService.ChangeUserStatus(req)
+	_, err, rsp.Code, rsp.Msg = myerrors.CheckError(err)
+	if err != nil {
+		return err
+	}
+	return nil
+}
+
 //// GetUserBelongDept 获取部门下所属用户
 //func (e *UserHandler) GetUserBelongDept(ctx context.Context, req *user_def.DeptIdReq, rsp *comm_def.CommonMsg) error {
 //	// 获取租户码
@@ -441,34 +410,30 @@ func (h *UserHandler) DeleteByIds(ctx context.Context, req *comm_def.IdsReq, rsp
 //	rsp.Msg = msg
 //	return nil
 //}
-//
-//// ChangePassword 用户修改密码
-//func (e *UserHandler) ChangePassword(ctx context.Context, req *user_def.PWDReq, rsp *comm_def.CommonMsg) error {
-//	// 获取租户码
-//	tenant, err := micro_srv.GetTenant(ctx)
-//	if err != nil {
-//		return err
-//	}
-//	g.Log().Info("Received UserHandler.ChangePassword request @ " + tenant)
-//	gvalidErr := gvalid.CheckStruct(ctx, req, nil)
-//	if gvalidErr != nil {
-//		return gvalidErr.Current()
-//	}
-//	service, err := user.NewService(tenant)
-//	if flag, err, _, _ := myerrors.CheckError(err); flag {
-//		return err
-//	}
-//	userInfo, err := micro_srv.GetUserInfo(ctx)
-//	if err != nil {
-//		return err
-//	}
-//	err = service.ChangePassword(&userInfo, req.OldPassword, req.NewPassword)
-//	_, err, code, msg := myerrors.CheckError(err)
-//	rsp.Code = code
-//	rsp.Msg = msg
-//	return err
-//}
-//
+
+// ChangePassword 用户修改密码
+func (e *UserHandler) ChangePassword(ctx context.Context, req *user_def.PWDReq, rsp *comm_def.CommonMsg) error {
+	gvalidErr := gvalid.CheckStruct(ctx, req, nil)
+	if gvalidErr != nil {
+		return gvalidErr.Current()
+	}
+	userService, err := service.NewUserService(ctx)
+	if err != nil {
+		return gerror.New("系统异常,请重新尝试")
+	}
+	userInfo, err := micro_srv.GetUserInfo(ctx)
+	if err != nil {
+		return err
+	}
+	err = userService.ProfileUpdatePwd(&model.ProfileUpdatePwdReq{
+		UserId:      userInfo.Id,
+		OldPassword: req.OldPassword,
+		NewPassword: req.NewPassword,
+	})
+	_, err, rsp.Code, rsp.Msg = myerrors.CheckError(err)
+	return err
+}
+
 //// GetUserByUserName 根据用户名获取用户信息
 //func (e *UserHandler) GetUserByUserName(ctx context.Context, req *user_def.UserNameReq, rsp *comm_def.CommonMsg) error {
 //	// 获取租户码

+ 1 - 0
opms_admin/app/model/internal/sys_menu.go

@@ -26,6 +26,7 @@ type SysMenu struct {
 	PlatformId  int         `orm:"platform_id"  json:"platformId"`  // 所属平台
 	Sort        int         `orm:"sort"         json:"sort"`        // 显示顺序
 	ActiveMenu  string      `orm:"active_menu"  json:"activeMenu"`  // 高亮路由
+	NoColumn    string      `orm:"no_column"    json:"noColumn"`    // 是否展示栏目20 不展示
 	Remark      string      `orm:"remark"       json:"remark"`      // 备注
 	CreatedBy   int         `orm:"created_by"   json:"createdBy"`   // 创建者
 	CreatedName string      `orm:"created_name" json:"createdName"` // 创建人

+ 2 - 0
opms_admin/app/model/sys_menu.go

@@ -54,6 +54,7 @@ type Meta struct {
 	Hidden           bool   `json:"hidden,omitempty"`
 	ActiveMenu       string `json:"activeMenu,omitempty"`
 	Target           string `json:"target,omitempty"`
+	NoColumn         bool   `json:"noColumn,omitempty"`
 }
 
 func (m SysMenu) ConvName() string {
@@ -84,6 +85,7 @@ func (m SysMenu) ConvMenuTree() MenuTree {
 			ActiveMenu:  m.ActiveMenu,
 			NoKeepAlive: m.IsCache != 1,
 			Hidden:      m.Visible != "10",
+			NoColumn:    m.NoColumn == "20",
 		},
 		Children: nil,
 	}

+ 0 - 11
opms_admin/app/service/sys_config.go

@@ -1,8 +1,6 @@
 package service
 
 import (
-	"dashoo.cn/micro/app/common/global"
-	comService "dashoo.cn/micro/app/common/service"
 	"dashoo.cn/micro/app/dao"
 	"dashoo.cn/micro/app/model"
 	"github.com/gogf/gf/errors/gerror"
@@ -112,19 +110,10 @@ func (s *sysConfig) GetConfigByKey(key string) (config *model.SysConfig, err err
 		err = gerror.New("参数key不能为空")
 		return
 	}
-	cache := comService.Cache.New()
-	cf := cache.Get(global.SysConfigTag + key)
-	if cf != nil {
-		err = gconv.Struct(cf, &config)
-		return
-	}
 	config, err = s.GetByKey(key)
 	if err != nil {
 		return
 	}
-	if config != nil {
-		cache.Set(global.SysConfigTag+key, config, 0, global.SysConfigTag)
-	}
 	return
 }
 

+ 16 - 32
opms_admin/app/service/sys_dict_data.go

@@ -2,8 +2,6 @@ package service
 
 import (
 	"context"
-	"dashoo.cn/micro/app/common/global"
-	comService "dashoo.cn/micro/app/common/service"
 	"dashoo.cn/micro/app/dao"
 	"dashoo.cn/micro/app/model"
 	"database/sql"
@@ -72,37 +70,23 @@ func (s *dictDataService) GetDictDataById(id int64) (data *model.SysDictData, er
 
 // GetDictWithDataByType 通过字典键类型获取选项
 func (s *dictDataService) GetDictWithDataByType(req *model.GetDictReq) (dict *model.DictRes, err error) {
-	cache := comService.Cache.New()
-	cacheKey := global.SysDict + "_" + req.DictType
-	//从缓存获取
-	iDict := cache.Get(cacheKey)
-	if iDict != nil {
-		err = gconv.Struct(iDict, &dict)
-		if err != nil {
-			return
-		}
-	} else {
-		//从数据库获取
-		dict = &model.DictRes{}
-		//获取类型数据
-		err = s.Dao.DB.Model("sys_dict_type").Where(dao.SysDictType.Columns.DictType, req.DictType).
-			Where(dao.SysDictType.Columns.Status, "10").Fields(model.DictTypeRes{}).Scan(&dict.Info)
-		if err != nil {
-			g.Log().Error(err)
-			err = gerror.New("获取字典类型失败")
-		}
-		err = s.Dao.Where(s.Dao.Columns.DictType, req.DictType).Where(s.Dao.Columns.Status, "10").
-			Order(s.Dao.Columns.DictSort + " asc," + s.Dao.Columns.DictCode + " asc").
-			Scan(&dict.Values)
-		if err != nil {
-			g.Log().Error(err)
-			err = gerror.New("获取字典数据失败")
-		}
-		//缓存菜单
-		if dict.Info != nil && dict.Values != nil {
-			cache.Set(cacheKey, dict, 0, global.SysDictTag)
-		}
+	//从数据库获取
+	dict = &model.DictRes{}
+	//获取类型数据
+	err = s.Dao.DB.Model("sys_dict_type").Where(dao.SysDictType.Columns.DictType, req.DictType).
+		Where(dao.SysDictType.Columns.Status, "10").Fields(model.DictTypeRes{}).Scan(&dict.Info)
+	if err != nil {
+		g.Log().Error(err)
+		err = gerror.New("获取字典类型失败")
+	}
+	err = s.Dao.Where(s.Dao.Columns.DictType, req.DictType).Where(s.Dao.Columns.Status, "10").
+		Order(s.Dao.Columns.DictSort + " asc," + s.Dao.Columns.DictCode + " asc").
+		Scan(&dict.Values)
+	if err != nil {
+		g.Log().Error(err)
+		err = gerror.New("获取字典数据失败")
 	}
+
 	//设置给定的默认值
 	for _, v := range dict.Values {
 		if req.DefaultValue != "" {

+ 0 - 11
opms_admin/app/service/sys_dict_type.go

@@ -2,8 +2,6 @@ package service
 
 import (
 	"context"
-	"dashoo.cn/micro/app/common/global"
-	comService "dashoo.cn/micro/app/common/service"
 	"dashoo.cn/micro/app/dao"
 	"dashoo.cn/micro/app/model"
 	"github.com/gogf/gf/container/garray"
@@ -69,21 +67,12 @@ func (s *dictTypeService) GetDictById(id int64) (dict *model.SysDictType, err er
 
 // GetAllDictType 获取所有正常状态下的字典类型
 func (s *dictTypeService) GetAllDictType() (list []*model.SysDictType, err error) {
-	cache := comService.Cache.New()
-	//从缓存获取
-	data := cache.Get(global.SysDict + "_dict_type_all")
-	if data != nil {
-		err = gconv.Structs(data, &list)
-		return
-	}
 	err = s.Dao.Where("status", 1).Order("dict_id ASC").Scan(&list)
 	if err != nil {
 		g.Log().Error(err)
 		err = gerror.New("获取字典类型数据出错")
 		return
 	}
-	//缓存
-	cache.Set(global.SysDict+"_dict_type_all", list, 0, global.SysDictTag)
 	return
 }
 

+ 18 - 0
opms_admin/app/service/sys_menu.go

@@ -183,6 +183,24 @@ func (s menuService) GetMenuTree(isAll bool) ([]model.MenuTree, error) {
 	return menuTree, err
 }
 
+// GetUserRoleMenuTree 用户获取角色菜单树
+func (s menuService) GetUserRoleMenuTree(roles []int) ([]model.MenuTree, error) {
+	menuList := make([]model.SysMenu, 0)
+	err := s.Dao.Where(s.Dao.Columns.Status, "10").WhereIn(s.Dao.Columns.MenuType, g.Slice{"M", "C"}).
+		WhereIn(s.Dao.Columns.Id, dao.NewSysRoleMenuDao(s.Tenant).WhereIn(dao.SysRoleMenu.Columns.RoleId, roles).Fields(dao.SysRoleMenu.Columns.MenuId)).
+		Order("sort").Scan(&menuList)
+
+	treeMap := make(map[int][]model.MenuTree, 0)
+	for _, v := range menuList {
+		treeMap[v.ParentId] = append(treeMap[v.ParentId], v.ConvMenuTree())
+	}
+	menuTree := treeMap[0]
+	for i := 0; i < len(menuTree); i++ {
+		s.getChildrenList(&menuTree[i], treeMap)
+	}
+	return menuTree, err
+}
+
 // getChildrenList 获取菜单的子菜单
 func (s menuService) getChildrenList(menu *model.MenuTree, treeMap map[int][]model.MenuTree) {
 	if value, ok := treeMap[menu.Id]; ok {

+ 9 - 16
opms_admin/app/service/sys_role.go

@@ -2,8 +2,6 @@ package service
 
 import (
 	"context"
-	"dashoo.cn/micro/app/common/global"
-	"dashoo.cn/micro/app/common/service"
 	"dashoo.cn/micro/app/dao"
 	"dashoo.cn/micro/app/model"
 	"dashoo.cn/opms_libary/utils"
@@ -34,22 +32,12 @@ func NewRoleService(ctx context.Context) (svc *roleService, err error) {
 
 // GetRoleList 获取角色列表
 func (s *roleService) GetRoleList() (list []*model.SysRole, err error) {
-	cache := service.Cache.New()
-	//从缓存获取
-	iList := cache.Get(global.SysRole)
-	if iList != nil {
-		err = gconv.Struct(iList, &list)
-		return
-	}
 	//从数据库获取
 	list, err = s.Dao.Order(s.Dao.Columns.Sort + " asc," + s.Dao.Columns.Id + " asc").All()
 	if err != nil {
 		g.Log().Error(err)
 		err = gerror.New("获取角色数据失败")
 	}
-	//缓存数据
-	cache.Set(global.SysRole, list, 0, global.SysAuthTag)
-	iList = cache.Get(global.SysRole)
 	return
 }
 
@@ -117,6 +105,15 @@ func (s *roleService) GetRoleDeptTreeselect(id int64) (deptIds []int, err error)
 	return
 }
 
+// GetRolesMenuPermissions 获取角色菜单权限
+func (s roleService) GetRolesMenuPermissions(ids []int) (perms []string, err error) {
+	result, err := dao.NewSysMenuDao(s.Tenant).Fields(dao.SysMenu.Columns.Perms).WhereIn(dao.SysMenu.Columns.MenuType, g.Slice{"C", "F"}).
+		WhereIn(dao.SysMenu.Columns.Id, s.roleMenuDao.WhereIn(s.roleMenuDao.Columns.RoleId, ids).Fields(s.roleMenuDao.Columns.MenuId)).
+		WhereNot(dao.SysMenu.Columns.Perms, "").Array()
+	perms = gconv.Strings(result)
+	return perms, err
+}
+
 func (s *roleService) CreateRole(req *model.SysRoleReq) error {
 	data := new(model.SysRole)
 	if err := gconv.Struct(req, data); err != nil {
@@ -195,10 +192,6 @@ func (s *roleService) DeleteByIds(ids []int64) (err error) {
 
 func (s *roleService) UpdateRoleStatus(req *model.StatusSetReq) error {
 	_, err := s.Dao.Where(s.Dao.Columns.Id, req.RoleId).Data(s.Dao.Columns.Status, req.Status).Update()
-	if err == nil {
-		//清除TAG缓存
-		service.Cache.New().RemoveByTag(global.SysAuthTag)
-	}
 	return err
 }
 

+ 12 - 11
opms_admin/app/service/sys_user.go

@@ -146,11 +146,6 @@ func (s *userService) GetUserByUsername(ctx context.Context, userName string) (u
 	return dao.SysUser.FindByUsername(ctx, userName)
 }
 
-// SaveOnline 保存用户登录在线状态信息
-//func (s *sysUser) SaveOnline(params *model.SysUserOnline) {
-//	dao.SysUserOnline.SaveOnline(params)
-//}
-
 // GetUserInfoById 通过Id获取用户信息
 func (s *userService) GetUserInfoById(id int, withPwd ...bool) (user *model.SysUser, err error) {
 	if len(withPwd) > 0 && withPwd[0] {
@@ -425,17 +420,21 @@ func (s *userService) UpdateUser(req *model.EditUserReq) (err error) {
 func (s *userService) ResetUserPwd(req *model.SysUserResetPwdReq) error {
 	salt := grand.S(10)
 	password := utils.EncryptPassword(req.Password, salt)
-	_, err := dao.SysUser.WherePri(req.Id).Update(g.Map{
+	data := g.Map{
 		dao.SysUser.Columns.UserSalt: salt,
 		dao.SysUser.Columns.Password: password,
-	})
+	}
+	SetCurrentUpdatedInfo(data, s.CxtUser)
+	_, err := dao.SysUser.WherePri(req.Id).Update()
 	return err
 }
 
 func (s *userService) ChangeUserStatus(req *model.SysUserStatusReq) error {
-	_, err := dao.SysUser.WherePri(req.Id).Update(g.Map{
+	data := g.Map{
 		dao.SysUser.Columns.Status: req.UserStatus,
-	})
+	}
+	SetCurrentUpdatedInfo(data, s.CxtUser)
+	_, err := dao.SysUser.WherePri(req.Id).Update()
 	return err
 }
 
@@ -475,10 +474,12 @@ func (s *userService) ProfileUpdatePwd(req *model.ProfileUpdatePwdReq) error {
 	}
 	salt := grand.S(10)
 	newPassword := utils.EncryptPassword(req.NewPassword, salt)
-	_, err = dao.SysUser.WherePri(req.UserId).Unscoped().Update(g.Map{
+	data := g.Map{
 		dao.SysUser.Columns.UserSalt: salt,
 		dao.SysUser.Columns.Password: newPassword,
-	})
+	}
+	SetCurrentUpdatedInfo(data, s.CxtUser)
+	_, err = dao.SysUser.WherePri(req.UserId).Unscoped().Update(data)
 	return err
 }
 

+ 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

+ 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",

+ 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
 }

+ 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
+}

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

@@ -5,7 +5,10 @@ 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/os/gtime"
+	"github.com/gogf/gf/util/gconv"
 	"github.com/gogf/gf/util/gvalid"
 
 	model "dashoo.cn/micro/app/model/cust"
@@ -14,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 {
@@ -25,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)
@@ -32,3 +44,79 @@ 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 {
+	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)
+		return err
+	}
+	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)
+}

+ 142 - 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
 	}
-	rsp.Data = g.Map{"list": id}
+	//创建客户
+	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)
@@ -139,4 +160,119 @@ 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)
+	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)
+		return err
+	}
+	return nil
+}
+
+//移入公海
+func (c *CustomerHeader) MoveToPubic(ctx context.Context, req *model.MoveToPubicRep, 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)
+	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)
+		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)
+	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
+}
+
+//修改客户
+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)
+	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)
+		return err
+	}
+	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)
+}

+ 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"` // 销售名
 }

+ 50 - 17
opms_parent/app/model/cust/cust_customer.go

@@ -22,6 +22,7 @@ type CustCustomerSearchReq struct {
 	CustName     string `json:"custName"`
 	CustIndustry string `json:"custIndustry"`
 	CustLevel    string `json:"custLevel"`
+	TargetType   string `json:"targetType,omitempty"`
 	request.PageReq
 }
 
@@ -33,17 +34,17 @@ type AddCustCustomerReq struct {
 
 // 单表添加客户信息表
 type Customer struct {
-	CustName string `p:"custName"        json:"custName"   v:"required#客户名称不能为空"`
-	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"   `      //
-
+	CustName     string      `p:"custName"        json:"custName"   v:"required#客户名称不能为空"`
+	AbbrName     string      `p:"abbrName"        json:"abbrName"   `                         // 助计名
+	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"  v:"required#省份不能为空" `     // 省份Id
+	Remark       string      `p:"remark" json:"remark""`                                      //备注
+	SalesName    string      `p:"salesName"       json:"salesName"   `                        //
+	SalesId      string      `p:"salesId"         json:"salesId"   `                          //
 }
 
 //客户联系人信息
@@ -67,7 +68,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 +76,45 @@ 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 DelCustomerContact struct {
+	Id     int `json:"id"`   //联系人id
+	CustId int `json:custId` //客户Id
+}
+
+//合并客户参数
+type MergecustomerRep struct {
+	Id int `json:"id"` //目标Id
+	*Customer
+	ChooseId []int64 `json:"chooseId,omitempty"` //被合并的客户id
+}
+
+//修改客户
+type UpdateCustomer struct {
+	Id int `json:"id,omitempty"` //客户id
+	*Customer
+}
+
+//移入公海
+type MoveToPubicRep struct {
+	Ids    []int64 `json:"ids,omitempty"`
+	Remark string  `json:"remark,omitempty"`
 }

+ 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"`  // 创建时间
+
+}

+ 41 - 9
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,13 +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不能为空" `
+	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"` // 创建时间
+
 }

+ 10 - 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"
@@ -19,15 +20,22 @@ 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"`     // 操作类型
-	OpnContent  string      ` json:"opnContent"`  // 操作内容
+	Remark      string      `json:"remark"`       //备注
+	OpnContent  interface{} ` json:"opnContent"`  // 操作内容
+}
+type CustomerDynameicsReq struct {
+	CustId int `    json:"custId"` // 客户Id
+	request.PageReq
 }
 
-//详情
+//客户表动态记录
 type CustomerDynameicsRep struct {
 	OpnPeople  string      `    json:"opnPeople"` // 操作人
 	OpnDate    *gtime.Time `      json:"opnDate"` // 操作日期
 	OpnType    string      `     json:"opnType"`  // 操作类型
 	OpnContent string      `   json:"opnContent"` // 操作内容
+	//List       []*CustCustomer `   json:"list"`
 }

+ 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"`
 }

+ 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"`     // 操作类型

+ 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
 
 }

+ 8 - 9
opms_parent/app/service/base/base_district.go

@@ -29,16 +29,15 @@ 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
 	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{
@@ -48,10 +47,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)

+ 323 - 80
opms_parent/app/service/cust/cust_customer.go

@@ -14,35 +14,38 @@ import (
 	"dashoo.cn/micro/app/service"
 )
 
-type customerService struct {
+type CustomerService struct {
 	*service.ContextService
 	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"
 
-func NewCustomerService(ctx context.Context) (svc *customerService, err error) {
-	svc = new(customerService)
+type OpnType struct {
+	OperaTion string
+}
+
+func NewCustomerService(ctx context.Context) (svc *CustomerService, err error) {
+	svc = new(CustomerService)
 	if svc.ContextService, err = svc.Init(ctx); err != nil {
 		return nil, err
 	}
 	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) {
+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,11 +61,14 @@ 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()))
 	cusTomer.IsPublic = isPublic
+	cusTomer.CustStatus = "10"
 	//if c.CxtUser.DeptId == 2 {
 	//	cusTomer.IsPublic = noPublic            //   非公海用户
 	//	cusTomer.DeptId = c.GetCxtUserDeptId()  //   部门id
@@ -76,7 +82,10 @@ func (c *customerService) Create(req *model.Customer) (insertId int64, err error
 		err = gerror.New("创建失败")
 		return
 	}
+	//
+
 	insertId, _ = res.LastInsertId()
+
 	//销售人员创建条件成立 同步belong 表
 	//custBelong := new(model.AddCustomerBelong)
 	//custBelong.CustId = int(insertId)
@@ -88,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)
@@ -110,14 +119,17 @@ 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
-	if !req.IsPublic {
-		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)
+	Model = Model.Where(c.Dao.Columns.DeletedTime + " is null")
+	if req.TargetType != "" {
+		if !req.IsPublic {
+			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)
+		}
 	}
 	//客户名称
 	if req.CustName != "" {
@@ -148,10 +160,93 @@ func (c *customerService) GetList(req *model.CustCustomerSearchReq) (total int,
 	return
 }
 
-//
+//删除客户
+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)
+	if err != nil {
+		g.Log().Error(err)
+		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 {
+		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(c.Dao.Columns.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, 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 {
+		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 {
+func (c *CustomerService) DistriCustomer(req *model.DistriCustomer) error {
 	/**
 	   待写逻辑(销售总监或销售助理将公海客户分配给指定销售工程师)
 	   if c.user.id != 销售总监 || c.user.id!=销售助理 {
@@ -167,21 +262,29 @@ 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
 }
 
 //客户详情
-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("获取用户数据失败")
@@ -190,74 +293,44 @@ 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() {
 		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("变更失败")
@@ -267,15 +340,33 @@ func (c *customerService) UpdateCustomer(ids []int64, salesId int64, behavior in
 }
 
 //客户操作日志
-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.Dao.M
-	service.SetCreatedInfo(cusDynameics, c.GetCxtUserId(), c.GetCxtUserName())
-	_, err = Model.Insert(cusDynameics)
+	Model := c.DynamicsDao.M
+	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("创建失败")
@@ -284,13 +375,165 @@ 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, result []interface{}, 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
+	}
+	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) {
+	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())
+	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 {
+			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.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)
+	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.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)
+	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
 }

+ 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
+}

+ 61 - 2
opms_parent/app/service/cust/cust_customer_contact.go

@@ -2,15 +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 {
@@ -20,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
 }
 
@@ -40,7 +45,61 @@ func (c *customercontactService) Create(req *model.CustCustomerContactSeq) (err
 	if err != nil {
 		return
 	}
+
 	InsertId, _ := res.LastInsertId()
 	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, 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("修改用户信息失败")
+		return
+	}
+	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
+}

+ 3 - 0
opms_parent/main.go

@@ -24,6 +24,9 @@ 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("FollowUp", new(plat.FollowUpHandler), "")
 	s.RegisterName("FollowUpComment", new(plat.FollowUpCommentHandler), "")
 	s.RegisterName("FollowUpFile", new(plat.FollowUpFileHandler), "")