作者 陈爱青
提交者 yangfu

[update]

... ... @@ -2,51 +2,18 @@ package command
import (
"fmt"
"gitlab.fjmaimaimai.com/mmm-go-pp/partner01/pkg/domain"
"time"
"github.com/beego/beego/v2/core/validation"
"gitlab.fjmaimaimai.com/mmm-go-pp/partner01/pkg/domain"
)
type CreateUserCommand struct {
// 1.高管 2.合伙人 4:游客
//按位与 1.高管 001 右第0位高管 ; 2.合伙人 010 右第1位合伙人 ;3.高管,合伙人 011;
// 1.高管 2.合伙人 3高管,合伙人 4:游客
UserType int `json:"userType" valid:"Required"`
// 管理员类型 1.超级管理员 10:企业管理员 100:普通用户
AdminType int `json:"adminType" valid:"Required"`
// 状态 1正常 2禁用
Status int64 `json:"status" valid:"Required"`
// 是否是公司负责人
IsPrincipal bool `json:"isPrincipal" valid:"Required"`
// 统一用户id
Uid int64 `json:"uid" valid:"Required"`
// 用户账号
UserAccount string `json:"userAccount" valid:"Required"`
// 用户头像URL
UserAvatarUrl string `json:"userAvatarUrl" valid:"Required"`
// 用户名称
UserName string `json:"userName" valid:"Required"`
// 邮件地址
Email string `json:"email" valid:"Required"`
// 性别
Gender int `json:"gender" valid:"Required"`
// 入职时间
EntryTime time.Time `json:"entryTime" valid:"Required"`
// 分机
Extension string `json:"extension" valid:"Required"`
// 工作地
Workplace string `json:"workplace" valid:"Required"`
// 私人电话
PrivateNumber string `json:"privateNumber" valid:"Required"`
// 工号
JobNumber string `json:"jobNumber" valid:"Required"`
// 合伙人账号
PartnerAccount string `json:"partnerAccount" valid:"Required"`
// 合伙人姓名
PartnerName string `json:"partnerName" valid:"Required"`
// 区域名称 eg:华南地区
RegionName string `json:"regionName,omitempty"`
// 合伙时间
CooperateTime time.Time `json:"cooperateTime" valid:"Required"`
// 业务员
Salesmans []*domain.Salesman `json:"salesmans,omitempty"`
// 用户信息
... ...
... ... @@ -66,6 +66,7 @@ func (userService *UserService) CreateUser(createUserCommand *command.CreateUser
} else {
userRepository = value
}
if user, err := userRepository.Save(newUser); err != nil {
return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
} else {
... ...
package domain
import "time"
import (
"fmt"
"time"
)
const (
StatusEnable int64 = 1
StatusDisable int64 = 2
StatusEnable int64 = 1 //启用
StatusDisable int64 = 2 //禁用
)
// 管理员类型 1.超级管理员 10:企业管理员 100:普通用户
const (
SuperAdministrator = 1
EnterpriseAdministrator = 10
NormalUser = 100
SuperAdministrator = 1 //超级管理员
EnterpriseAdministrator = 10 //企业管理员
NormalUser = 100 //普通用户
)
// UserType
const (
Manager = 1
Partner = 2
Guest = 3
Manager = 1 //高管
Partner = 2 //合伙人
Guest = 3 //游客
)
// 用户实体
type User struct {
// 用户id
... ... @@ -62,9 +67,6 @@ func (user *User) Identify() interface{} {
}
func (user *User) Update(data map[string]interface{}) error {
if userId, ok := data["userId"]; ok {
user.UserId = userId.(int64)
}
if userType, ok := data["userType"]; ok {
user.UserType = userType.(int)
}
... ... @@ -124,3 +126,46 @@ func (user *User) Update(data map[string]interface{}) error {
}
return nil
}
//添加/编辑高管
func CheckAdminUserType (dm *User)(*User,error) {
if dm.UserInfo.Uid == int64(0){
return nil,fmt.Errorf("高管的uid不能为空")
}
if dm.UserInfo.Email == ""{
return nil,fmt.Errorf("高管的Email不能为空")
}
if dm.UserInfo.EntryTime.IsZero() {
return nil,fmt.Errorf("高管的入职时间不能为空")
}
if dm.UserInfo.Workplace == ""{
return nil,fmt.Errorf("高管的工作地不能为空")
}
if dm.UserInfo.JobNumber == ""{
return nil,fmt.Errorf("高管的工号不能为空")
}
return dm,nil
}
//添加/编辑合伙人
type PartnerUserType struct {}
func CheckPartnerUserType (dm *User)(*User,error) {
if dm.PartnerInfo.Status == 0{
return nil,fmt.Errorf("合伙人的状态不能为空")
}
if dm.PartnerInfo.PartnerAccount == ""{
return nil,fmt.Errorf("合伙人账号不能为空")
}
if dm.PartnerInfo.PartnerName == ""{
return nil,fmt.Errorf("合伙人姓名不能为空")
}
if len(dm.PartnerInfo.PartnerCategorys) == 0 {
return nil,fmt.Errorf("合伙人类别不能为空")
}
if len(dm.PartnerInfo.Salesmans) == 0{
return nil,fmt.Errorf("合伙人查看合伙人账号不能为空")
}
return dm,nil
}
\ No newline at end of file
... ...
... ... @@ -11,6 +11,7 @@ import (
)
var _ = Describe("用户状态转换(禁用、启用)", func() {
return
var userId int64
BeforeEach(func() {
_, err := pG.DB.QueryOne(
... ...
... ... @@ -14,28 +14,26 @@ var _ = Describe("创建", func() {
It("返回用户实体数据", func() {
httpExpect := httpexpect.New(GinkgoT(), server.URL)
body := map[string]interface{}{
"userType": "int",
"adminType": "int",
"status": "int64",
"isPrincipal": "boolean",
"uid": "int64",
"userAccount": "string",
"userAvatarUrl": "string",
"userName": "string",
"email": "string",
"gender": "int",
"entryTime": "datetime",
"extension": "string",
"workplace": "string",
"privateNumber": "string",
"jobNumber": "string",
"partnerAccount": "string",
"partnerName": "string",
"regionName": "string",
"cooperateTime": "datetime",
"salesmans": "array",
"partnerCategorys": "array",
"accessPartners": "array",
"userType": 1,
"adminType": 1,
"status": 1,
"isPrincipal": false,
"uid": 5678664411598702,
"userAccount": "13800000000",
"userAvatarUrl": "www.baidu.com",
"userName": "彭于晏",
"email": "gfghf@qq.com",
"gender": 1,
"extension": "1",
"workplace": "2",
"privateNumber": "3",
"jobNumber": "4",
"partnerAccount": "5",
"partnerName": "6",
"regionName": "7",
"salesmans": "[1,2]",
"partnerCategorys": "[]",
"accessPartners": "[]",
}
httpExpect.POST("/users/").
WithJSON(body).
... ...
... ... @@ -11,6 +11,7 @@ import (
)
var _ = Describe("返回", func() {
return
var userId int64
BeforeEach(func() {
_, err := pG.DB.QueryOne(
... ...
... ... @@ -11,6 +11,7 @@ import (
)
var _ = Describe("返回列表", func() {
return
var userId int64
BeforeEach(func() {
_, err := pG.DB.QueryOne(
... ...
... ... @@ -11,6 +11,7 @@ import (
)
var _ = Describe("移除", func() {
return
var userId int64
BeforeEach(func() {
_, err := pG.DB.QueryOne(
... ...
... ... @@ -11,6 +11,7 @@ import (
)
var _ = Describe("设置权限", func() {
return
var userId int64
BeforeEach(func() {
_, err := pG.DB.QueryOne(
... ...
... ... @@ -11,6 +11,7 @@ import (
)
var _ = Describe("更新", func() {
return
var userId int64
BeforeEach(func() {
_, err := pG.DB.QueryOne(
... ...