wangxingcheng 2 years ago
parent
commit
c266d1135a

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

+ 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#建议成交价"`

+ 4 - 0
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"`
 }
 
@@ -134,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"}
 )

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

@@ -3,20 +3,26 @@ 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
 	// 获取租户码
@@ -35,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
 }
 
@@ -65,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
+}

+ 74 - 136
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,6 +52,8 @@ 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
 }
 
@@ -70,6 +74,7 @@ func (c *CustomerService) Derive(req *model.CustCustomerExport) (content *model.
 
 		for ck, item := range data {
 			for index, v := range req.Columns {
+				// "CustCode":客户编码
 				if v == "客户编码" {
 					f.SetCellValue("Sheet1", service.Div(index+1)+strconv.Itoa(ck+2), item.CustCode)
 				}
@@ -130,75 +135,37 @@ 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()
-	_, 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 {
 
@@ -238,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)
@@ -249,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)
@@ -260,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
@@ -361,9 +334,6 @@ func (c *CustomerService) DistriCustomer(req *model.DistriCustomer) error {
 		return err
 
 	}
-
-	//belongServer := new(CustomerbelongService)
-
 	if req.Receive != "" {
 		req.Receive = Receive
 	} else {
@@ -565,23 +535,19 @@ 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())
-	if err != nil || List.Len() > 0 {
-		err = c.Createcontact(req.Id, req.ChooseId, List.List())
-		if err != nil {
-			err = gerror.New("合并失败")
-			return
-		}
+	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 {
@@ -590,75 +556,47 @@ 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.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
 	}
-	Model.Data(g.Map{"deleted_time": gtime.Now()}).Where(c.ContactDao.Columns.Id+" in (?)", req.ChooseId).Update()
 
-	////所选客户销售联系人信息
-	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) Createcontact(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("Createcontact", 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

+ 48 - 27
opms_parent/app/service/cust/cust_customer_belong.go

@@ -6,6 +6,7 @@ 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"
@@ -27,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)
@@ -38,32 +39,52 @@ func (c *CustomerbelongService) GetEntityById(CustId int) (Info []*model.Custome
 	return
 }
 
-//批量插入客户归属记录表
-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)
+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
 	}
-	_, err = belongModel.Insert(belongData)
-	g.Log().Info("belong", belongData)
+	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 {
-		err = gerror.New("插入失败")
-		return err
+		g.Log().Error(err)
+		err = gerror.New("创建失败")
+		return
 	}
-	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) GetList(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) GetList(CustId int) (Info []*model.CustCustomer
 }
 
 //删除联系人
-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), "")