作者 tangxvhui

bug 修复

... ... @@ -27,12 +27,6 @@ func (adminUserSrv AdminUserService) GetAdminUser(getAdminUserQuery *query.GetAd
if err != nil {
return nil, lib.ThrowError(lib.TRANSACTION_ERROR, err.Error())
}
// if err := transactionContext.StartTransaction(); err != nil {
// return nil, lib.ThrowError(lib.TRANSACTION_ERROR, err.Error())
// }
// defer func() {
// transactionContext.RollbackTransaction()
// }()
var (
adminuserRepository domain.AdminUserRepository
adminuser *domain.AdminUser
... ... @@ -104,7 +98,7 @@ func (adminUserSrv AdminUserService) SaveAdminUser(saveUserCmd *command.SaveAdmi
}
permissionBases = append(permissionBases, p)
}
var accountChance bool
if saveUserCmd.Id > 0 {
adminuser, err = adminuserRepository.FindOne(domain.AdminUserFindOneQuery{
AdminUserId: saveUserCmd.Id,
... ... @@ -112,12 +106,16 @@ func (adminUserSrv AdminUserService) SaveAdminUser(saveUserCmd *command.SaveAdmi
if err != nil {
return nil, lib.ThrowError(lib.TRANSACTION_ERROR, err.Error())
}
if adminuser.Account != saveUserCmd.Account {
accountChance = true
}
adminuser.Account = saveUserCmd.Account
adminuser.AdminName = saveUserCmd.Name
adminuser.IsUsable = saveUserCmd.IsUsable
adminuser.Permission = permissionBases
} else {
accountChance = true
defaultPwd := fmt.Sprintf("%x", sha1.Sum([]byte("123456")))
adminuser = &domain.AdminUser{
Id: saveUserCmd.Id,
... ... @@ -128,6 +126,27 @@ func (adminUserSrv AdminUserService) SaveAdminUser(saveUserCmd *command.SaveAdmi
Permission: permissionBases,
}
}
if accountChance {
//检查账号是否已存在
var (
adminuserDao *dao.AdminUserDao
)
if v, err := factory.CreateAdminUserkDao(map[string]interface{}{
"transactionContext": transactionContext,
}); err != nil {
return nil, lib.ThrowError(lib.TRANSACTION_ERROR, err.Error())
} else {
adminuserDao = v
}
ok, err := adminuserDao.AdminUserAccountExist(saveUserCmd.Account)
if err != nil {
return nil, lib.ThrowError(lib.TRANSACTION_ERROR, err.Error())
}
if ok {
return nil, lib.ThrowError(lib.BUSINESS_ERROR, "账号已存在")
}
}
adminuser, err = adminuserRepository.Save(adminuser)
if err != nil {
return nil, lib.ThrowError(lib.INTERNAL_SERVER_ERROR, err.Error())
... ... @@ -141,12 +160,6 @@ func (adminUserSrv AdminUserService) PageListAdminUser(listAdminUserQuery *query
if err != nil {
return nil, 0, lib.ThrowError(lib.TRANSACTION_ERROR, err.Error())
}
// if err := transactionContext.StartTransaction(); err != nil {
// return nil, 0, lib.ThrowError(lib.TRANSACTION_ERROR, err.Error())
// }
// defer func() {
// transactionContext.RollbackTransaction()
// }()
var (
adminuserRepository domain.AdminUserRepository
adminusers []domain.AdminUser
... ... @@ -173,7 +186,6 @@ func (adminUserSrv AdminUserService) PageListAdminUser(listAdminUserQuery *query
if err != nil {
return nil, 0, lib.ThrowError(lib.INTERNAL_SERVER_ERROR, err.Error())
}
transactionContext.CommitTransaction()
return adminusers, cnt, nil
}
... ... @@ -228,6 +240,11 @@ func (adminUserSrv AdminUserService) UpdateAdminIsUsable(uid int64, isUsable boo
} else {
adminuserDao = v
}
if ok, err := adminuserDao.AdminUserIsDefault(uid); err != nil {
return lib.ThrowError(lib.TRANSACTION_ERROR, err.Error())
} else if ok {
return lib.ThrowError(lib.BUSINESS_ERROR, "请勿禁用超级管理员")
}
err = adminuserDao.UpdateIsUsable(uid, isUsable)
if err != nil {
return lib.ThrowError(lib.TRANSACTION_ERROR, err.Error())
... ...
... ... @@ -3,10 +3,12 @@ package domain
//权限代码
//权限配置 1合作管理人 2订单管理 3分红管理 4管理员管理
const (
PERMINSSION_PARTNER string = "1合作管理人" //1合作管理人
PERMISSION_ORDER string = "2订单管理" //2订单管理
PERMISSION_DIVIDEND string = "3分红管理" //3分红管理
PERMINSSION_ADMIN_USER string = "4管理员管理" //4管理员管理
PERMINSSION_PARTNER string = "PARTER" //合作管理人
PERMISSION_ORDER string = "ORDER" //订单管理
PERMISSION_DIVIDEND string = "DIVIDEND" //分红管理
PERMINSSION_ADMIN_USER string = "ADMIN" //管理员管理
PERMINSSION_ORDER_ACTUA string = "ORDER_ACTUA" //实际订单
PERMINSSION_ORDER_INTENTION string = "ORDER_INTENTION" //意向订单
)
type AdminPermissionBase struct {
... ...
... ... @@ -44,7 +44,7 @@ func (dao *AdminUserDao) UpdateIsUsable(id int64, isUsable bool) error {
return err
}
_, err = tx.Model(m).Where("id=?", id).
Set("is-usable=?", isUsable).
Set("is_usable=?", isUsable).
Update()
return err
}
... ... @@ -59,3 +59,14 @@ func (dao *AdminUserDao) AdminUserAccountExist(account string) (bool, error) {
return ok, err
}
func (dao *AdminUserDao) AdminUserIsDefault(id int64) (bool, error) {
tx := dao.transactionContext.PgDd
m := &models.AdminUser{}
err := tx.Model(m).
Where("id=?", id).
Column("is_default").
First()
return m.IsDefault, err
}
... ...
... ... @@ -59,6 +59,7 @@ func (reponsitory AdminUserRepository) updateAdminUser(adminuser *domain.AdminUs
tx := reponsitory.transactionContext.PgTx
adminUserModel := &models.AdminUser{
Id: adminuser.Id,
Account: adminuser.Account,
AdminName: adminuser.AdminName,
Password: adminuser.Password,
IsUsable: adminuser.IsUsable,
... ... @@ -66,7 +67,7 @@ func (reponsitory AdminUserRepository) updateAdminUser(adminuser *domain.AdminUs
}
_, err := tx.Model(adminUserModel).
Where("id=?", adminUserModel.Id).
Column("admin_name", "password", "is_usable", "permission").
Column("admin_name", "account", "password", "is_usable", "permission").
Update()
if err != nil {
return nil, fmt.Errorf("更新用户数据失败:%s", err)
... ... @@ -106,7 +107,7 @@ func (reponsitory AdminUserRepository) Find(queryOption domain.AdminUserFindQuer
adminuserModels := []models.AdminUser{}
query := db.Model(&adminuserModels)
if len(queryOption.AccountLike) > 0 {
query = query.Where("admin_account like ?", "%"+queryOption.AccountLike)
query = query.Where("account like ?", "%"+queryOption.AccountLike+"%")
}
if queryOption.Offset > -1 {
... ... @@ -121,7 +122,7 @@ func (reponsitory AdminUserRepository) Find(queryOption domain.AdminUserFindQuer
err error
adminuserReturn = make([]domain.AdminUser, 0)
)
err = query.Order("id DESC").Select()
err = query.Select()
if err != nil {
return adminuserReturn, err
}
... ... @@ -140,7 +141,7 @@ func (reponsitory AdminUserRepository) CountAll(queryOption domain.AdminUserFind
adminuserModels := []models.AdminUser{}
query := db.Model(&adminuserModels)
if len(queryOption.AccountLike) > 0 {
query = query.Where("admin_account like ?", "%"+queryOption.AccountLike)
query = query.Where("account like ?", "%"+queryOption.AccountLike+"%")
}
cnt, err := query.Count()
return cnt, err
... ...
... ... @@ -9,6 +9,8 @@ func init() {
logs.SetLevel(logLevel(constant.LOG_LEVEL))
logs.SetLogFuncCall(false)
logs.SetLogger("file", `{"filename":"log/partnermg.log"}`)
logs.Async()
logs.Async(2 * 1e3)
}
//LogLevel ...
... ...
... ... @@ -4,7 +4,6 @@ import (
"encoding/json"
"errors"
"fmt"
"io/ioutil"
"strconv"
"strings"
... ... @@ -22,12 +21,12 @@ type BaseController struct {
}
func (controller BaseController) BindJsonData(v interface{}) error {
bodyData := controller.Ctx.Input.GetData("requestBody")
bodyByte, ok := bodyData.([]byte)
if !ok {
return errors.New("requestBody is not []byte")
}
return json.Unmarshal(bodyByte, v)
// bodyData := controller.Ctx.Input.GetData("requestBody")
// bodyByte, ok := bodyData.([]byte)
// if !ok {
// return errors.New("requestBody is not []byte")
// }
return json.Unmarshal(controller.Ctx.Input.RequestBody, v)
}
func (controller BaseController) ResponseError(err error) {
... ... @@ -98,9 +97,7 @@ func (controller *BaseController) Finish() {
func (controller *BaseController) Prepare() {
logs.Info("====>Recv Request:", controller.Ctx.Input.URI())
if controller.Ctx.Input.IsPost() || controller.Ctx.Input.IsPut() {
bodyByte, _ := ioutil.ReadAll(controller.Ctx.Request.Body)
controller.Ctx.Input.SetData("requestBody", bodyByte)
controller.Ctx.Request.Body.Close()
bodyByte := controller.Ctx.Input.RequestBody
if len(bodyByte) > 1000 {
logs.Info("====>Recv data from client: BodyData:\n ", string(bodyByte[0:1000]))
} else {
... ...