Merge branch 'dev' of http://gitlab.fjmaimaimai.com/mmm-go/partnermg into v0.8.0-dev
正在显示
8 个修改的文件
包含
93 行增加
和
60 行删除
@@ -225,20 +225,14 @@ func (service OrderInfoService) CreateNewOrder(cmd command.CreateOrderCommand) ( | @@ -225,20 +225,14 @@ func (service OrderInfoService) CreateNewOrder(cmd command.CreateOrderCommand) ( | ||
225 | }); err != nil { | 225 | }); err != nil { |
226 | return nil, lib.ThrowError(lib.TRANSACTION_ERROR, err.Error()) | 226 | return nil, lib.ThrowError(lib.TRANSACTION_ERROR, err.Error()) |
227 | } | 227 | } |
228 | - //检查order_code是否重复 | ||
229 | - // if ok, err := orderBaseDao.OrderCodeExist(cmd.OrderCode, cmd.PartnerCategory, cmd.PartnerId); err != nil { | ||
230 | - // return nil, lib.ThrowError(lib.TRANSACTION_ERROR, err.Error()) | ||
231 | - // } else if ok { | ||
232 | - // return nil, lib.ThrowError(lib.BUSINESS_ERROR, "订单号已存在") | ||
233 | - // } | ||
234 | - //检查delivery_code是否重复 | ||
235 | - if len(cmd.DeliveryCode) > 0 { | ||
236 | - if ok, err := orderBaseDao.DeliveryCodeExist(cmd.DeliveryCode, cmd.CompanyId); err != nil { | ||
237 | - return nil, lib.ThrowError(lib.TRANSACTION_ERROR, err.Error()) | ||
238 | - } else if ok { | ||
239 | - return nil, lib.ThrowError(lib.BUSINESS_ERROR, "发货号已存在") | ||
240 | - } | 228 | + |
229 | + if ok, err := orderBaseDao.CheckOrderExist(cmd.CompanyId, cmd.OrderCode, cmd.DeliveryCode, | ||
230 | + cmd.PartnerCategory, cmd.PartnerId, 0); err != nil { | ||
231 | + return nil, lib.ThrowError(lib.TRANSACTION_ERROR, err.Error()) | ||
232 | + } else if ok { | ||
233 | + return nil, lib.ThrowError(lib.BUSINESS_ERROR, "订单已存在") | ||
241 | } | 234 | } |
235 | + | ||
242 | newOrder := &domain.OrderBase{ | 236 | newOrder := &domain.OrderBase{ |
243 | OrderType: cmd.OrderType, OrderCode: cmd.OrderCode, | 237 | OrderType: cmd.OrderType, OrderCode: cmd.OrderCode, |
244 | DeliveryCode: cmd.DeliveryCode, | 238 | DeliveryCode: cmd.DeliveryCode, |
@@ -436,12 +430,10 @@ func (service OrderInfoService) UpdateOrderData(cmd command.UpdateOrderCommand) | @@ -436,12 +430,10 @@ func (service OrderInfoService) UpdateOrderData(cmd command.UpdateOrderCommand) | ||
436 | // } | 430 | // } |
437 | // } | 431 | // } |
438 | //检查delivery_code是否重复 | 432 | //检查delivery_code是否重复 |
439 | - if cmd.DeliveryCode != oldOrderData.DeliveryCode { | ||
440 | - if ok, err := orderBaseDao.DeliveryCodeExist(cmd.DeliveryCode, cmd.CompanyId, cmd.Id); err != nil { | ||
441 | - return nil, lib.ThrowError(lib.TRANSACTION_ERROR, err.Error()) | ||
442 | - } else if ok { | ||
443 | - return nil, lib.ThrowError(lib.BUSINESS_ERROR, "发货号已存在") | ||
444 | - } | 433 | + if ok, err := orderBaseDao.CheckOrderExist(cmd.CompanyId, cmd.OrderCode, cmd.DeliveryCode, cmd.PartnerCategory, cmd.PartnerId, cmd.Id); err != nil { |
434 | + return nil, lib.ThrowError(lib.TRANSACTION_ERROR, err.Error()) | ||
435 | + } else if ok { | ||
436 | + return nil, lib.ThrowError(lib.BUSINESS_ERROR, "订单已存在") | ||
445 | } | 437 | } |
446 | //获取旧的订单中的商品 | 438 | //获取旧的订单中的商品 |
447 | oldOrderGoods, _, err = orderGoodRepository.Find(domain.OrderGoodFindQuery{ | 439 | oldOrderGoods, _, err = orderGoodRepository.Find(domain.OrderGoodFindQuery{ |
1 | package command | 1 | package command |
2 | 2 | ||
3 | +import ( | ||
4 | + "errors" | ||
5 | + | ||
6 | + "gitlab.fjmaimaimai.com/mmm-go/partnermg/pkg/domain" | ||
7 | +) | ||
8 | + | ||
3 | type EditUserPermissionCommand struct { | 9 | type EditUserPermissionCommand struct { |
4 | Id int64 `json:"id"` | 10 | Id int64 `json:"id"` |
5 | CompanyId int64 `json:"-"` | 11 | CompanyId int64 `json:"-"` |
6 | PermissionType []int64 `json:"permissionType"` //权限数据 | 12 | PermissionType []int64 `json:"permissionType"` //权限数据 |
7 | CheckedPartner []int64 `json:"checkedPartner"` //可查看合伙人列表合伙人 | 13 | CheckedPartner []int64 `json:"checkedPartner"` //可查看合伙人列表合伙人 |
14 | + IsSenior int8 `json:"isSenior"` | ||
15 | +} | ||
16 | + | ||
17 | +func (cmd EditUserPermissionCommand) Validate() error { | ||
18 | + if cmd.IsSenior <= 0 { | ||
19 | + return errors.New("是否是高管必填") | ||
20 | + } | ||
21 | + if !(cmd.IsSenior == domain.UserIsSeniorNo || cmd.IsSenior == domain.UserIsSeniorYes) { | ||
22 | + return errors.New("是否是高管必填") | ||
23 | + } | ||
24 | + return nil | ||
8 | } | 25 | } |
@@ -383,6 +383,7 @@ func (service UsersService) buildGetUserData(userData *domain.Users, partnerList | @@ -383,6 +383,7 @@ func (service UsersService) buildGetUserData(userData *domain.Users, partnerList | ||
383 | "isAdmin": 0, | 383 | "isAdmin": 0, |
384 | "status": 0, | 384 | "status": 0, |
385 | "checkedPartner": []map[string]interface{}{}, | 385 | "checkedPartner": []map[string]interface{}{}, |
386 | + "isSenior": userData.IsSenior, | ||
386 | } | 387 | } |
387 | if userData.IsSuperAdmin() { | 388 | if userData.IsSuperAdmin() { |
388 | result["isAdmin"] = 1 | 389 | result["isAdmin"] = 1 |
@@ -433,6 +434,9 @@ func (service UsersService) EditUserPermission(cmd command.EditUserPermissionCom | @@ -433,6 +434,9 @@ func (service UsersService) EditUserPermission(cmd command.EditUserPermissionCom | ||
433 | transactionContext, _ = factory.CreateTransactionContext(nil) | 434 | transactionContext, _ = factory.CreateTransactionContext(nil) |
434 | err error | 435 | err error |
435 | ) | 436 | ) |
437 | + if err = cmd.Validate(); err != nil { | ||
438 | + return lib.ThrowError(lib.BUSINESS_ERROR, err.Error()) | ||
439 | + } | ||
436 | if err = transactionContext.StartTransaction(); err != nil { | 440 | if err = transactionContext.StartTransaction(); err != nil { |
437 | return lib.ThrowError(lib.TRANSACTION_ERROR, err.Error()) | 441 | return lib.ThrowError(lib.TRANSACTION_ERROR, err.Error()) |
438 | } | 442 | } |
@@ -501,9 +505,6 @@ func (service UsersService) EditUserPermission(cmd command.EditUserPermissionCom | @@ -501,9 +505,6 @@ func (service UsersService) EditUserPermission(cmd command.EditUserPermissionCom | ||
501 | partners = append(partners, p) | 505 | partners = append(partners, p) |
502 | } | 506 | } |
503 | for i := range permissionList { | 507 | for i := range permissionList { |
504 | - // if permissionList[i].Code == domain.PERMINSSION_ADMIN_USER && !usersData.IsSuperAdmin() { | ||
505 | - // return lib.ThrowError(lib.BUSINESS_ERROR, "操作异常") | ||
506 | - // } | ||
507 | p := domain.AdminPermissionBase{ | 508 | p := domain.AdminPermissionBase{ |
508 | Id: permissionList[i].Id, | 509 | Id: permissionList[i].Id, |
509 | Code: permissionList[i].Code, | 510 | Code: permissionList[i].Code, |
@@ -512,6 +513,7 @@ func (service UsersService) EditUserPermission(cmd command.EditUserPermissionCom | @@ -512,6 +513,7 @@ func (service UsersService) EditUserPermission(cmd command.EditUserPermissionCom | ||
512 | } | 513 | } |
513 | updateMap := map[string]interface{}{ | 514 | updateMap := map[string]interface{}{ |
514 | "AccessPartners": partners, | 515 | "AccessPartners": partners, |
516 | + "IsSenior": cmd.IsSenior, | ||
515 | } | 517 | } |
516 | if !usersData.IsSuperAdmin() { | 518 | if !usersData.IsSuperAdmin() { |
517 | updateMap["Permission"] = permissionsBase | 519 | updateMap["Permission"] = permissionsBase |
@@ -20,29 +20,36 @@ const ( | @@ -20,29 +20,36 @@ const ( | ||
20 | UserIsAdmin int8 = 2 | 20 | UserIsAdmin int8 = 2 |
21 | ) | 21 | ) |
22 | 22 | ||
23 | +//Users.IsSenior 用户是否是公司高管【1:是】【2:否】 | ||
24 | +const ( | ||
25 | + UserIsSeniorYes int8 = 1 | ||
26 | + UserIsSeniorNo int8 = 2 | ||
27 | +) | ||
28 | + | ||
23 | //Users 企业平台的用户 | 29 | //Users 企业平台的用户 |
24 | type Users struct { | 30 | type Users struct { |
25 | - Id int64 //用户id | ||
26 | - CompanyId int64 //公司id | ||
27 | - OpenId int64 //统一用户中心 | ||
28 | - Name string //用户名称 | ||
29 | - Sex int8 //性别:【0:未知】【1:男】【2:女】 | ||
30 | - JobNum string //工号 | ||
31 | - Phone string //手机号,同账号 | ||
32 | - PrivatePhone string //私人手机号 | ||
33 | - Email string //邮件 | ||
34 | - ExtensionNum string //分机号 | ||
35 | - EntryTime time.Time //入职时间 | ||
36 | - Workspace string //工作地 | ||
37 | - Status int8 //状态:【1:正常】【 2:禁用】 | ||
38 | - Avatar string ///头像 | ||
39 | - Remarks string //备注 | ||
40 | - ChargeStatus int8 //是否为当前公司主管 【1:是】【2:否】 | ||
41 | - CreateAt time.Time | ||
42 | - UpdateAt time.Time | 31 | + Id int64 //用户id |
32 | + CompanyId int64 //公司id | ||
33 | + OpenId int64 //统一用户中心 | ||
34 | + Name string //用户名称 | ||
35 | + Sex int8 //性别:【0:未知】【1:男】【2:女】 | ||
36 | + JobNum string //工号 | ||
37 | + Phone string //手机号,同账号 | ||
38 | + PrivatePhone string //私人手机号 | ||
39 | + Email string //邮件 | ||
40 | + ExtensionNum string //分机号 | ||
41 | + EntryTime time.Time //入职时间 | ||
42 | + Workspace string //工作地 | ||
43 | + Status int8 //状态:【1:正常】【 2:禁用】 | ||
44 | + Avatar string ///头像 | ||
45 | + Remarks string //备注 | ||
46 | + ChargeStatus int8 //是否为当前公司主管 【1:是】【2:否】 | ||
47 | + CreateAt time.Time // | ||
48 | + UpdateAt time.Time // | ||
43 | Permission []AdminPermissionBase //权限 | 49 | Permission []AdminPermissionBase //权限 |
44 | - AccessPartners []Partner | ||
45 | - AdminType int8 //是否是公司负责人,即超级管理员 1普通用户 2主管理员 | 50 | + AccessPartners []Partner // |
51 | + AdminType int8 //是否是公司负责人,即超级管理员 1普通用户 2主管理员 | ||
52 | + IsSenior int8 //是否是公司高管【1:是】【2:否】;用于确定是否可以拥有“可查看的合伙人” | ||
46 | } | 53 | } |
47 | 54 | ||
48 | //IsUsable 用户是否可用 | 55 | //IsUsable 用户是否可用 |
@@ -71,6 +78,17 @@ func (u Users) HasPermissionByCode(code string) bool { | @@ -71,6 +78,17 @@ func (u Users) HasPermissionByCode(code string) bool { | ||
71 | return false | 78 | return false |
72 | } | 79 | } |
73 | 80 | ||
81 | +func (u *Users) SetIsSenior(senior int8) { | ||
82 | + switch senior { | ||
83 | + case UserIsSeniorYes: | ||
84 | + u.IsSenior = senior | ||
85 | + case UserIsSeniorNo: | ||
86 | + u.IsSenior = senior | ||
87 | + u.AccessPartners = make([]Partner, 0) | ||
88 | + default: | ||
89 | + } | ||
90 | +} | ||
91 | + | ||
74 | func (u *Users) Update(m map[string]interface{}) error { | 92 | func (u *Users) Update(m map[string]interface{}) error { |
75 | if v, ok := m["CompanyId"]; ok { | 93 | if v, ok := m["CompanyId"]; ok { |
76 | u.CompanyId = v.(int64) | 94 | u.CompanyId = v.(int64) |
@@ -126,6 +144,10 @@ func (u *Users) Update(m map[string]interface{}) error { | @@ -126,6 +144,10 @@ func (u *Users) Update(m map[string]interface{}) error { | ||
126 | if v, ok := m["AdminType"]; ok { | 144 | if v, ok := m["AdminType"]; ok { |
127 | u.AdminType = v.(int8) | 145 | u.AdminType = v.(int8) |
128 | } | 146 | } |
147 | + if v, ok := m["IsSenior"]; ok { | ||
148 | + senior := v.(int8) | ||
149 | + u.SetIsSenior(senior) | ||
150 | + } | ||
129 | return nil | 151 | return nil |
130 | } | 152 | } |
131 | 153 |
@@ -23,26 +23,20 @@ func NewOrderBaseDao(transactionContext *transaction.TransactionContext) (*Order | @@ -23,26 +23,20 @@ func NewOrderBaseDao(transactionContext *transaction.TransactionContext) (*Order | ||
23 | } | 23 | } |
24 | } | 24 | } |
25 | 25 | ||
26 | -//OrderCodeExist 检查order_code是否重复 | ||
27 | -// | ||
28 | -func (dao OrderBaseDao) OrderCodeExist(code string, partnerCategory int64, partnerId int64) (bool, error) { | 26 | +//CheckOrderUnique 检查订单的是否已存在 |
27 | +//@companyId 公司id | ||
28 | +//@orderCode 订单号 | ||
29 | +//@deliveryCode 发货单号 | ||
30 | +//@partnerCategoryCode 合伙人类型编号 | ||
31 | +func (dao OrderBaseDao) CheckOrderExist(companyId int64, orderCode string, | ||
32 | + deliveryCode string, partnerCategory int64, partnerId int64, notId int64) (bool, error) { | ||
29 | tx := dao.transactionContext.GetDB() | 33 | tx := dao.transactionContext.GetDB() |
30 | - m := &models.OrderBase{} | ||
31 | - query := tx.Model(m). | ||
32 | - Where("order_code=?", code). | 34 | + query := tx.Model(&models.OrderBase{}). |
35 | + Where("company_id=?", companyId). | ||
36 | + Where("order_code=?", orderCode). | ||
33 | Where("partner_id=?", partnerId). | 37 | Where("partner_id=?", partnerId). |
34 | - Where(`partner_category @>'{"id":?}'`, partnerCategory) | ||
35 | - ok, err := query.Exists() | ||
36 | - return ok, err | ||
37 | -} | ||
38 | - | ||
39 | -func (dao OrderBaseDao) DeliveryCodeExist(code string, companyId int64, notId ...int64) (bool, error) { | ||
40 | - tx := dao.transactionContext.GetDB() | ||
41 | - m := &models.OrderBase{} | ||
42 | - query := tx.Model(m).Where("delivery_code=?", code).Where("company_id=?", companyId) | ||
43 | - if len(notId) > 0 { | ||
44 | - query = query.WhereIn("id not in(?)", notId) | ||
45 | - } | 38 | + Where(`partner_category @>'{"id":?}'`, partnerCategory). |
39 | + Where("id<>?", notId) | ||
46 | ok, err := query.Exists() | 40 | ok, err := query.Exists() |
47 | return ok, err | 41 | return ok, err |
48 | } | 42 | } |
@@ -29,6 +29,7 @@ type Users struct { | @@ -29,6 +29,7 @@ type Users struct { | ||
29 | ChargeStatus int8 //是否为当前公司主管 【1:是】【2:否】 | 29 | ChargeStatus int8 //是否为当前公司主管 【1:是】【2:否】 |
30 | Permission []domain.AdminPermissionBase //权限 | 30 | Permission []domain.AdminPermissionBase //权限 |
31 | AccessPartners []domain.Partner //可查看的合伙人 | 31 | AccessPartners []domain.Partner //可查看的合伙人 |
32 | + IsSenior int8 //是否是公司高管【1:是】【2:否】;用于确定是否可以拥有“可查看的合伙人” | ||
32 | CreateAt time.Time | 33 | CreateAt time.Time |
33 | UpdateAt time.Time | 34 | UpdateAt time.Time |
34 | DeleteAt time.Time | 35 | DeleteAt time.Time |
@@ -48,6 +48,7 @@ func (repository UsersRepository) transformPgModelToDomainModel(m *models.Users) | @@ -48,6 +48,7 @@ func (repository UsersRepository) transformPgModelToDomainModel(m *models.Users) | ||
48 | Permission: m.Permission, | 48 | Permission: m.Permission, |
49 | AccessPartners: m.AccessPartners, | 49 | AccessPartners: m.AccessPartners, |
50 | AdminType: m.AdminType, | 50 | AdminType: m.AdminType, |
51 | + IsSenior: m.IsSenior, | ||
51 | }, nil | 52 | }, nil |
52 | } | 53 | } |
53 | 54 | ||
@@ -78,6 +79,7 @@ func (reponsitory UsersRepository) Add(u *domain.Users) error { | @@ -78,6 +79,7 @@ func (reponsitory UsersRepository) Add(u *domain.Users) error { | ||
78 | Permission: u.Permission, | 79 | Permission: u.Permission, |
79 | AccessPartners: u.AccessPartners, | 80 | AccessPartners: u.AccessPartners, |
80 | AdminType: u.AdminType, | 81 | AdminType: u.AdminType, |
82 | + IsSenior: u.IsSenior, | ||
81 | } | 83 | } |
82 | _, err = tx.Model(m).Insert() | 84 | _, err = tx.Model(m).Insert() |
83 | return err | 85 | return err |
@@ -110,6 +112,7 @@ func (reponsitory UsersRepository) Edit(u *domain.Users) error { | @@ -110,6 +112,7 @@ func (reponsitory UsersRepository) Edit(u *domain.Users) error { | ||
110 | Permission: u.Permission, | 112 | Permission: u.Permission, |
111 | AccessPartners: u.AccessPartners, | 113 | AccessPartners: u.AccessPartners, |
112 | AdminType: u.AdminType, | 114 | AdminType: u.AdminType, |
115 | + IsSenior: u.IsSenior, | ||
113 | } | 116 | } |
114 | _, err = tx.Model(m).WherePK().Update() | 117 | _, err = tx.Model(m).WherePK().Update() |
115 | return err | 118 | return err |
@@ -122,6 +122,7 @@ func (c *UserController) EditUserPermission() { | @@ -122,6 +122,7 @@ func (c *UserController) EditUserPermission() { | ||
122 | Id int64 `json:"id"` | 122 | Id int64 `json:"id"` |
123 | PermissionType []int64 `json:"permissionType"` | 123 | PermissionType []int64 `json:"permissionType"` |
124 | CheckedPartner []int64 `json:"checkedPartner"` //合伙人 | 124 | CheckedPartner []int64 `json:"checkedPartner"` //合伙人 |
125 | + IsSenior int8 `json:"isSenior"` //是否是高管【1:是】【2:否】 | ||
125 | } | 126 | } |
126 | var ( | 127 | var ( |
127 | param UserDetailParam | 128 | param UserDetailParam |
@@ -139,6 +140,7 @@ func (c *UserController) EditUserPermission() { | @@ -139,6 +140,7 @@ func (c *UserController) EditUserPermission() { | ||
139 | CompanyId: companyId, | 140 | CompanyId: companyId, |
140 | PermissionType: param.PermissionType, | 141 | PermissionType: param.PermissionType, |
141 | CheckedPartner: param.CheckedPartner, | 142 | CheckedPartner: param.CheckedPartner, |
143 | + IsSenior: param.IsSenior, | ||
142 | }) | 144 | }) |
143 | if err != nil { | 145 | if err != nil { |
144 | c.ResponseError(err) | 146 | c.ResponseError(err) |
-
请 注册 或 登录 后发表评论