作者 陈志颖

Merge branch 'dev' of http://gitlab.fjmaimaimai.com/mmm-go/partnermg into v0.8.0-dev

... ... @@ -225,20 +225,14 @@ func (service OrderInfoService) CreateNewOrder(cmd command.CreateOrderCommand) (
}); err != nil {
return nil, lib.ThrowError(lib.TRANSACTION_ERROR, err.Error())
}
//检查order_code是否重复
// if ok, err := orderBaseDao.OrderCodeExist(cmd.OrderCode, cmd.PartnerCategory, cmd.PartnerId); err != nil {
// return nil, lib.ThrowError(lib.TRANSACTION_ERROR, err.Error())
// } else if ok {
// return nil, lib.ThrowError(lib.BUSINESS_ERROR, "订单号已存在")
// }
//检查delivery_code是否重复
if len(cmd.DeliveryCode) > 0 {
if ok, err := orderBaseDao.DeliveryCodeExist(cmd.DeliveryCode, cmd.CompanyId); err != nil {
if ok, err := orderBaseDao.CheckOrderExist(cmd.CompanyId, cmd.OrderCode, cmd.DeliveryCode,
cmd.PartnerCategory, cmd.PartnerId, 0); err != nil {
return nil, lib.ThrowError(lib.TRANSACTION_ERROR, err.Error())
} else if ok {
return nil, lib.ThrowError(lib.BUSINESS_ERROR, "发货号已存在")
}
return nil, lib.ThrowError(lib.BUSINESS_ERROR, "订单已存在")
}
newOrder := &domain.OrderBase{
OrderType: cmd.OrderType, OrderCode: cmd.OrderCode,
DeliveryCode: cmd.DeliveryCode,
... ... @@ -436,12 +430,10 @@ func (service OrderInfoService) UpdateOrderData(cmd command.UpdateOrderCommand)
// }
// }
//检查delivery_code是否重复
if cmd.DeliveryCode != oldOrderData.DeliveryCode {
if ok, err := orderBaseDao.DeliveryCodeExist(cmd.DeliveryCode, cmd.CompanyId, cmd.Id); err != nil {
if ok, err := orderBaseDao.CheckOrderExist(cmd.CompanyId, cmd.OrderCode, cmd.DeliveryCode, cmd.PartnerCategory, cmd.PartnerId, cmd.Id); err != nil {
return nil, lib.ThrowError(lib.TRANSACTION_ERROR, err.Error())
} else if ok {
return nil, lib.ThrowError(lib.BUSINESS_ERROR, "发货号已存在")
}
return nil, lib.ThrowError(lib.BUSINESS_ERROR, "订单已存在")
}
//获取旧的订单中的商品
oldOrderGoods, _, err = orderGoodRepository.Find(domain.OrderGoodFindQuery{
... ...
package command
import (
"errors"
"gitlab.fjmaimaimai.com/mmm-go/partnermg/pkg/domain"
)
type EditUserPermissionCommand struct {
Id int64 `json:"id"`
CompanyId int64 `json:"-"`
PermissionType []int64 `json:"permissionType"` //权限数据
CheckedPartner []int64 `json:"checkedPartner"` //可查看合伙人列表合伙人
IsSenior int8 `json:"isSenior"`
}
func (cmd EditUserPermissionCommand) Validate() error {
if cmd.IsSenior <= 0 {
return errors.New("是否是高管必填")
}
if !(cmd.IsSenior == domain.UserIsSeniorNo || cmd.IsSenior == domain.UserIsSeniorYes) {
return errors.New("是否是高管必填")
}
return nil
}
... ...
... ... @@ -383,6 +383,7 @@ func (service UsersService) buildGetUserData(userData *domain.Users, partnerList
"isAdmin": 0,
"status": 0,
"checkedPartner": []map[string]interface{}{},
"isSenior": userData.IsSenior,
}
if userData.IsSuperAdmin() {
result["isAdmin"] = 1
... ... @@ -433,6 +434,9 @@ func (service UsersService) EditUserPermission(cmd command.EditUserPermissionCom
transactionContext, _ = factory.CreateTransactionContext(nil)
err error
)
if err = cmd.Validate(); err != nil {
return lib.ThrowError(lib.BUSINESS_ERROR, err.Error())
}
if err = transactionContext.StartTransaction(); err != nil {
return lib.ThrowError(lib.TRANSACTION_ERROR, err.Error())
}
... ... @@ -501,9 +505,6 @@ func (service UsersService) EditUserPermission(cmd command.EditUserPermissionCom
partners = append(partners, p)
}
for i := range permissionList {
// if permissionList[i].Code == domain.PERMINSSION_ADMIN_USER && !usersData.IsSuperAdmin() {
// return lib.ThrowError(lib.BUSINESS_ERROR, "操作异常")
// }
p := domain.AdminPermissionBase{
Id: permissionList[i].Id,
Code: permissionList[i].Code,
... ... @@ -512,6 +513,7 @@ func (service UsersService) EditUserPermission(cmd command.EditUserPermissionCom
}
updateMap := map[string]interface{}{
"AccessPartners": partners,
"IsSenior": cmd.IsSenior,
}
if !usersData.IsSuperAdmin() {
updateMap["Permission"] = permissionsBase
... ...
... ... @@ -20,6 +20,12 @@ const (
UserIsAdmin int8 = 2
)
//Users.IsSenior 用户是否是公司高管【1:是】【2:否】
const (
UserIsSeniorYes int8 = 1
UserIsSeniorNo int8 = 2
)
//Users 企业平台的用户
type Users struct {
Id int64 //用户id
... ... @@ -38,11 +44,12 @@ type Users struct {
Avatar string ///头像
Remarks string //备注
ChargeStatus int8 //是否为当前公司主管 【1:是】【2:否】
CreateAt time.Time
UpdateAt time.Time
CreateAt time.Time //
UpdateAt time.Time //
Permission []AdminPermissionBase //权限
AccessPartners []Partner
AccessPartners []Partner //
AdminType int8 //是否是公司负责人,即超级管理员 1普通用户 2主管理员
IsSenior int8 //是否是公司高管【1:是】【2:否】;用于确定是否可以拥有“可查看的合伙人”
}
//IsUsable 用户是否可用
... ... @@ -71,6 +78,17 @@ func (u Users) HasPermissionByCode(code string) bool {
return false
}
func (u *Users) SetIsSenior(senior int8) {
switch senior {
case UserIsSeniorYes:
u.IsSenior = senior
case UserIsSeniorNo:
u.IsSenior = senior
u.AccessPartners = make([]Partner, 0)
default:
}
}
func (u *Users) Update(m map[string]interface{}) error {
if v, ok := m["CompanyId"]; ok {
u.CompanyId = v.(int64)
... ... @@ -126,6 +144,10 @@ func (u *Users) Update(m map[string]interface{}) error {
if v, ok := m["AdminType"]; ok {
u.AdminType = v.(int8)
}
if v, ok := m["IsSenior"]; ok {
senior := v.(int8)
u.SetIsSenior(senior)
}
return nil
}
... ...
... ... @@ -23,26 +23,20 @@ func NewOrderBaseDao(transactionContext *transaction.TransactionContext) (*Order
}
}
//OrderCodeExist 检查order_code是否重复
//
func (dao OrderBaseDao) OrderCodeExist(code string, partnerCategory int64, partnerId int64) (bool, error) {
//CheckOrderUnique 检查订单的是否已存在
//@companyId 公司id
//@orderCode 订单号
//@deliveryCode 发货单号
//@partnerCategoryCode 合伙人类型编号
func (dao OrderBaseDao) CheckOrderExist(companyId int64, orderCode string,
deliveryCode string, partnerCategory int64, partnerId int64, notId int64) (bool, error) {
tx := dao.transactionContext.GetDB()
m := &models.OrderBase{}
query := tx.Model(m).
Where("order_code=?", code).
query := tx.Model(&models.OrderBase{}).
Where("company_id=?", companyId).
Where("order_code=?", orderCode).
Where("partner_id=?", partnerId).
Where(`partner_category @>'{"id":?}'`, partnerCategory)
ok, err := query.Exists()
return ok, err
}
func (dao OrderBaseDao) DeliveryCodeExist(code string, companyId int64, notId ...int64) (bool, error) {
tx := dao.transactionContext.GetDB()
m := &models.OrderBase{}
query := tx.Model(m).Where("delivery_code=?", code).Where("company_id=?", companyId)
if len(notId) > 0 {
query = query.WhereIn("id not in(?)", notId)
}
Where(`partner_category @>'{"id":?}'`, partnerCategory).
Where("id<>?", notId)
ok, err := query.Exists()
return ok, err
}
... ...
... ... @@ -29,6 +29,7 @@ type Users struct {
ChargeStatus int8 //是否为当前公司主管 【1:是】【2:否】
Permission []domain.AdminPermissionBase //权限
AccessPartners []domain.Partner //可查看的合伙人
IsSenior int8 //是否是公司高管【1:是】【2:否】;用于确定是否可以拥有“可查看的合伙人”
CreateAt time.Time
UpdateAt time.Time
DeleteAt time.Time
... ...
... ... @@ -48,6 +48,7 @@ func (repository UsersRepository) transformPgModelToDomainModel(m *models.Users)
Permission: m.Permission,
AccessPartners: m.AccessPartners,
AdminType: m.AdminType,
IsSenior: m.IsSenior,
}, nil
}
... ... @@ -78,6 +79,7 @@ func (reponsitory UsersRepository) Add(u *domain.Users) error {
Permission: u.Permission,
AccessPartners: u.AccessPartners,
AdminType: u.AdminType,
IsSenior: u.IsSenior,
}
_, err = tx.Model(m).Insert()
return err
... ... @@ -110,6 +112,7 @@ func (reponsitory UsersRepository) Edit(u *domain.Users) error {
Permission: u.Permission,
AccessPartners: u.AccessPartners,
AdminType: u.AdminType,
IsSenior: u.IsSenior,
}
_, err = tx.Model(m).WherePK().Update()
return err
... ...
... ... @@ -122,6 +122,7 @@ func (c *UserController) EditUserPermission() {
Id int64 `json:"id"`
PermissionType []int64 `json:"permissionType"`
CheckedPartner []int64 `json:"checkedPartner"` //合伙人
IsSenior int8 `json:"isSenior"` //是否是高管【1:是】【2:否】
}
var (
param UserDetailParam
... ... @@ -139,6 +140,7 @@ func (c *UserController) EditUserPermission() {
CompanyId: companyId,
PermissionType: param.PermissionType,
CheckedPartner: param.CheckedPartner,
IsSenior: param.IsSenior,
})
if err != nil {
c.ResponseError(err)
... ...