正在显示
6 个修改的文件
包含
63 行增加
和
33 行删除
@@ -27,12 +27,6 @@ func (adminUserSrv AdminUserService) GetAdminUser(getAdminUserQuery *query.GetAd | @@ -27,12 +27,6 @@ func (adminUserSrv AdminUserService) GetAdminUser(getAdminUserQuery *query.GetAd | ||
27 | if err != nil { | 27 | if err != nil { |
28 | return nil, lib.ThrowError(lib.TRANSACTION_ERROR, err.Error()) | 28 | return nil, lib.ThrowError(lib.TRANSACTION_ERROR, err.Error()) |
29 | } | 29 | } |
30 | - // if err := transactionContext.StartTransaction(); err != nil { | ||
31 | - // return nil, lib.ThrowError(lib.TRANSACTION_ERROR, err.Error()) | ||
32 | - // } | ||
33 | - // defer func() { | ||
34 | - // transactionContext.RollbackTransaction() | ||
35 | - // }() | ||
36 | var ( | 30 | var ( |
37 | adminuserRepository domain.AdminUserRepository | 31 | adminuserRepository domain.AdminUserRepository |
38 | adminuser *domain.AdminUser | 32 | adminuser *domain.AdminUser |
@@ -104,7 +98,7 @@ func (adminUserSrv AdminUserService) SaveAdminUser(saveUserCmd *command.SaveAdmi | @@ -104,7 +98,7 @@ func (adminUserSrv AdminUserService) SaveAdminUser(saveUserCmd *command.SaveAdmi | ||
104 | } | 98 | } |
105 | permissionBases = append(permissionBases, p) | 99 | permissionBases = append(permissionBases, p) |
106 | } | 100 | } |
107 | - | 101 | + var accountChance bool |
108 | if saveUserCmd.Id > 0 { | 102 | if saveUserCmd.Id > 0 { |
109 | adminuser, err = adminuserRepository.FindOne(domain.AdminUserFindOneQuery{ | 103 | adminuser, err = adminuserRepository.FindOne(domain.AdminUserFindOneQuery{ |
110 | AdminUserId: saveUserCmd.Id, | 104 | AdminUserId: saveUserCmd.Id, |
@@ -112,12 +106,16 @@ func (adminUserSrv AdminUserService) SaveAdminUser(saveUserCmd *command.SaveAdmi | @@ -112,12 +106,16 @@ func (adminUserSrv AdminUserService) SaveAdminUser(saveUserCmd *command.SaveAdmi | ||
112 | if err != nil { | 106 | if err != nil { |
113 | return nil, lib.ThrowError(lib.TRANSACTION_ERROR, err.Error()) | 107 | return nil, lib.ThrowError(lib.TRANSACTION_ERROR, err.Error()) |
114 | } | 108 | } |
109 | + if adminuser.Account != saveUserCmd.Account { | ||
110 | + accountChance = true | ||
111 | + } | ||
115 | adminuser.Account = saveUserCmd.Account | 112 | adminuser.Account = saveUserCmd.Account |
116 | adminuser.AdminName = saveUserCmd.Name | 113 | adminuser.AdminName = saveUserCmd.Name |
117 | adminuser.IsUsable = saveUserCmd.IsUsable | 114 | adminuser.IsUsable = saveUserCmd.IsUsable |
118 | adminuser.Permission = permissionBases | 115 | adminuser.Permission = permissionBases |
119 | 116 | ||
120 | } else { | 117 | } else { |
118 | + accountChance = true | ||
121 | defaultPwd := fmt.Sprintf("%x", sha1.Sum([]byte("123456"))) | 119 | defaultPwd := fmt.Sprintf("%x", sha1.Sum([]byte("123456"))) |
122 | adminuser = &domain.AdminUser{ | 120 | adminuser = &domain.AdminUser{ |
123 | Id: saveUserCmd.Id, | 121 | Id: saveUserCmd.Id, |
@@ -128,6 +126,27 @@ func (adminUserSrv AdminUserService) SaveAdminUser(saveUserCmd *command.SaveAdmi | @@ -128,6 +126,27 @@ func (adminUserSrv AdminUserService) SaveAdminUser(saveUserCmd *command.SaveAdmi | ||
128 | Permission: permissionBases, | 126 | Permission: permissionBases, |
129 | } | 127 | } |
130 | } | 128 | } |
129 | + if accountChance { | ||
130 | + //检查账号是否已存在 | ||
131 | + var ( | ||
132 | + adminuserDao *dao.AdminUserDao | ||
133 | + ) | ||
134 | + if v, err := factory.CreateAdminUserkDao(map[string]interface{}{ | ||
135 | + "transactionContext": transactionContext, | ||
136 | + }); err != nil { | ||
137 | + return nil, lib.ThrowError(lib.TRANSACTION_ERROR, err.Error()) | ||
138 | + } else { | ||
139 | + adminuserDao = v | ||
140 | + } | ||
141 | + ok, err := adminuserDao.AdminUserAccountExist(saveUserCmd.Account) | ||
142 | + if err != nil { | ||
143 | + return nil, lib.ThrowError(lib.TRANSACTION_ERROR, err.Error()) | ||
144 | + } | ||
145 | + if ok { | ||
146 | + return nil, lib.ThrowError(lib.BUSINESS_ERROR, "账号已存在") | ||
147 | + } | ||
148 | + } | ||
149 | + | ||
131 | adminuser, err = adminuserRepository.Save(adminuser) | 150 | adminuser, err = adminuserRepository.Save(adminuser) |
132 | if err != nil { | 151 | if err != nil { |
133 | return nil, lib.ThrowError(lib.INTERNAL_SERVER_ERROR, err.Error()) | 152 | return nil, lib.ThrowError(lib.INTERNAL_SERVER_ERROR, err.Error()) |
@@ -141,12 +160,6 @@ func (adminUserSrv AdminUserService) PageListAdminUser(listAdminUserQuery *query | @@ -141,12 +160,6 @@ func (adminUserSrv AdminUserService) PageListAdminUser(listAdminUserQuery *query | ||
141 | if err != nil { | 160 | if err != nil { |
142 | return nil, 0, lib.ThrowError(lib.TRANSACTION_ERROR, err.Error()) | 161 | return nil, 0, lib.ThrowError(lib.TRANSACTION_ERROR, err.Error()) |
143 | } | 162 | } |
144 | - // if err := transactionContext.StartTransaction(); err != nil { | ||
145 | - // return nil, 0, lib.ThrowError(lib.TRANSACTION_ERROR, err.Error()) | ||
146 | - // } | ||
147 | - // defer func() { | ||
148 | - // transactionContext.RollbackTransaction() | ||
149 | - // }() | ||
150 | var ( | 163 | var ( |
151 | adminuserRepository domain.AdminUserRepository | 164 | adminuserRepository domain.AdminUserRepository |
152 | adminusers []domain.AdminUser | 165 | adminusers []domain.AdminUser |
@@ -173,7 +186,6 @@ func (adminUserSrv AdminUserService) PageListAdminUser(listAdminUserQuery *query | @@ -173,7 +186,6 @@ func (adminUserSrv AdminUserService) PageListAdminUser(listAdminUserQuery *query | ||
173 | if err != nil { | 186 | if err != nil { |
174 | return nil, 0, lib.ThrowError(lib.INTERNAL_SERVER_ERROR, err.Error()) | 187 | return nil, 0, lib.ThrowError(lib.INTERNAL_SERVER_ERROR, err.Error()) |
175 | } | 188 | } |
176 | - transactionContext.CommitTransaction() | ||
177 | return adminusers, cnt, nil | 189 | return adminusers, cnt, nil |
178 | } | 190 | } |
179 | 191 | ||
@@ -228,6 +240,11 @@ func (adminUserSrv AdminUserService) UpdateAdminIsUsable(uid int64, isUsable boo | @@ -228,6 +240,11 @@ func (adminUserSrv AdminUserService) UpdateAdminIsUsable(uid int64, isUsable boo | ||
228 | } else { | 240 | } else { |
229 | adminuserDao = v | 241 | adminuserDao = v |
230 | } | 242 | } |
243 | + if ok, err := adminuserDao.AdminUserIsDefault(uid); err != nil { | ||
244 | + return lib.ThrowError(lib.TRANSACTION_ERROR, err.Error()) | ||
245 | + } else if ok { | ||
246 | + return lib.ThrowError(lib.BUSINESS_ERROR, "请勿禁用超级管理员") | ||
247 | + } | ||
231 | err = adminuserDao.UpdateIsUsable(uid, isUsable) | 248 | err = adminuserDao.UpdateIsUsable(uid, isUsable) |
232 | if err != nil { | 249 | if err != nil { |
233 | return lib.ThrowError(lib.TRANSACTION_ERROR, err.Error()) | 250 | return lib.ThrowError(lib.TRANSACTION_ERROR, err.Error()) |
@@ -3,10 +3,12 @@ package domain | @@ -3,10 +3,12 @@ package domain | ||
3 | //权限代码 | 3 | //权限代码 |
4 | //权限配置 1合作管理人 2订单管理 3分红管理 4管理员管理 | 4 | //权限配置 1合作管理人 2订单管理 3分红管理 4管理员管理 |
5 | const ( | 5 | const ( |
6 | - PERMINSSION_PARTNER string = "1合作管理人" //1合作管理人 | ||
7 | - PERMISSION_ORDER string = "2订单管理" //2订单管理 | ||
8 | - PERMISSION_DIVIDEND string = "3分红管理" //3分红管理 | ||
9 | - PERMINSSION_ADMIN_USER string = "4管理员管理" //4管理员管理 | 6 | + PERMINSSION_PARTNER string = "PARTER" //合作管理人 |
7 | + PERMISSION_ORDER string = "ORDER" //订单管理 | ||
8 | + PERMISSION_DIVIDEND string = "DIVIDEND" //分红管理 | ||
9 | + PERMINSSION_ADMIN_USER string = "ADMIN" //管理员管理 | ||
10 | + PERMINSSION_ORDER_ACTUA string = "ORDER_ACTUA" //实际订单 | ||
11 | + PERMINSSION_ORDER_INTENTION string = "ORDER_INTENTION" //意向订单 | ||
10 | ) | 12 | ) |
11 | 13 | ||
12 | type AdminPermissionBase struct { | 14 | type AdminPermissionBase struct { |
@@ -44,7 +44,7 @@ func (dao *AdminUserDao) UpdateIsUsable(id int64, isUsable bool) error { | @@ -44,7 +44,7 @@ func (dao *AdminUserDao) UpdateIsUsable(id int64, isUsable bool) error { | ||
44 | return err | 44 | return err |
45 | } | 45 | } |
46 | _, err = tx.Model(m).Where("id=?", id). | 46 | _, err = tx.Model(m).Where("id=?", id). |
47 | - Set("is-usable=?", isUsable). | 47 | + Set("is_usable=?", isUsable). |
48 | Update() | 48 | Update() |
49 | return err | 49 | return err |
50 | } | 50 | } |
@@ -59,3 +59,14 @@ func (dao *AdminUserDao) AdminUserAccountExist(account string) (bool, error) { | @@ -59,3 +59,14 @@ func (dao *AdminUserDao) AdminUserAccountExist(account string) (bool, error) { | ||
59 | 59 | ||
60 | return ok, err | 60 | return ok, err |
61 | } | 61 | } |
62 | + | ||
63 | +func (dao *AdminUserDao) AdminUserIsDefault(id int64) (bool, error) { | ||
64 | + tx := dao.transactionContext.PgDd | ||
65 | + m := &models.AdminUser{} | ||
66 | + err := tx.Model(m). | ||
67 | + Where("id=?", id). | ||
68 | + Column("is_default"). | ||
69 | + First() | ||
70 | + | ||
71 | + return m.IsDefault, err | ||
72 | +} |
@@ -59,6 +59,7 @@ func (reponsitory AdminUserRepository) updateAdminUser(adminuser *domain.AdminUs | @@ -59,6 +59,7 @@ func (reponsitory AdminUserRepository) updateAdminUser(adminuser *domain.AdminUs | ||
59 | tx := reponsitory.transactionContext.PgTx | 59 | tx := reponsitory.transactionContext.PgTx |
60 | adminUserModel := &models.AdminUser{ | 60 | adminUserModel := &models.AdminUser{ |
61 | Id: adminuser.Id, | 61 | Id: adminuser.Id, |
62 | + Account: adminuser.Account, | ||
62 | AdminName: adminuser.AdminName, | 63 | AdminName: adminuser.AdminName, |
63 | Password: adminuser.Password, | 64 | Password: adminuser.Password, |
64 | IsUsable: adminuser.IsUsable, | 65 | IsUsable: adminuser.IsUsable, |
@@ -66,7 +67,7 @@ func (reponsitory AdminUserRepository) updateAdminUser(adminuser *domain.AdminUs | @@ -66,7 +67,7 @@ func (reponsitory AdminUserRepository) updateAdminUser(adminuser *domain.AdminUs | ||
66 | } | 67 | } |
67 | _, err := tx.Model(adminUserModel). | 68 | _, err := tx.Model(adminUserModel). |
68 | Where("id=?", adminUserModel.Id). | 69 | Where("id=?", adminUserModel.Id). |
69 | - Column("admin_name", "password", "is_usable", "permission"). | 70 | + Column("admin_name", "account", "password", "is_usable", "permission"). |
70 | Update() | 71 | Update() |
71 | if err != nil { | 72 | if err != nil { |
72 | return nil, fmt.Errorf("更新用户数据失败:%s", err) | 73 | return nil, fmt.Errorf("更新用户数据失败:%s", err) |
@@ -106,7 +107,7 @@ func (reponsitory AdminUserRepository) Find(queryOption domain.AdminUserFindQuer | @@ -106,7 +107,7 @@ func (reponsitory AdminUserRepository) Find(queryOption domain.AdminUserFindQuer | ||
106 | adminuserModels := []models.AdminUser{} | 107 | adminuserModels := []models.AdminUser{} |
107 | query := db.Model(&adminuserModels) | 108 | query := db.Model(&adminuserModels) |
108 | if len(queryOption.AccountLike) > 0 { | 109 | if len(queryOption.AccountLike) > 0 { |
109 | - query = query.Where("admin_account like ?", "%"+queryOption.AccountLike) | 110 | + query = query.Where("account like ?", "%"+queryOption.AccountLike+"%") |
110 | } | 111 | } |
111 | 112 | ||
112 | if queryOption.Offset > -1 { | 113 | if queryOption.Offset > -1 { |
@@ -121,7 +122,7 @@ func (reponsitory AdminUserRepository) Find(queryOption domain.AdminUserFindQuer | @@ -121,7 +122,7 @@ func (reponsitory AdminUserRepository) Find(queryOption domain.AdminUserFindQuer | ||
121 | err error | 122 | err error |
122 | adminuserReturn = make([]domain.AdminUser, 0) | 123 | adminuserReturn = make([]domain.AdminUser, 0) |
123 | ) | 124 | ) |
124 | - err = query.Order("id DESC").Select() | 125 | + err = query.Select() |
125 | if err != nil { | 126 | if err != nil { |
126 | return adminuserReturn, err | 127 | return adminuserReturn, err |
127 | } | 128 | } |
@@ -140,7 +141,7 @@ func (reponsitory AdminUserRepository) CountAll(queryOption domain.AdminUserFind | @@ -140,7 +141,7 @@ func (reponsitory AdminUserRepository) CountAll(queryOption domain.AdminUserFind | ||
140 | adminuserModels := []models.AdminUser{} | 141 | adminuserModels := []models.AdminUser{} |
141 | query := db.Model(&adminuserModels) | 142 | query := db.Model(&adminuserModels) |
142 | if len(queryOption.AccountLike) > 0 { | 143 | if len(queryOption.AccountLike) > 0 { |
143 | - query = query.Where("admin_account like ?", "%"+queryOption.AccountLike) | 144 | + query = query.Where("account like ?", "%"+queryOption.AccountLike+"%") |
144 | } | 145 | } |
145 | cnt, err := query.Count() | 146 | cnt, err := query.Count() |
146 | return cnt, err | 147 | return cnt, err |
@@ -9,6 +9,8 @@ func init() { | @@ -9,6 +9,8 @@ func init() { | ||
9 | logs.SetLevel(logLevel(constant.LOG_LEVEL)) | 9 | logs.SetLevel(logLevel(constant.LOG_LEVEL)) |
10 | logs.SetLogFuncCall(false) | 10 | logs.SetLogFuncCall(false) |
11 | logs.SetLogger("file", `{"filename":"log/partnermg.log"}`) | 11 | logs.SetLogger("file", `{"filename":"log/partnermg.log"}`) |
12 | + logs.Async() | ||
13 | + logs.Async(2 * 1e3) | ||
12 | } | 14 | } |
13 | 15 | ||
14 | //LogLevel ... | 16 | //LogLevel ... |
@@ -4,7 +4,6 @@ import ( | @@ -4,7 +4,6 @@ import ( | ||
4 | "encoding/json" | 4 | "encoding/json" |
5 | "errors" | 5 | "errors" |
6 | "fmt" | 6 | "fmt" |
7 | - "io/ioutil" | ||
8 | "strconv" | 7 | "strconv" |
9 | "strings" | 8 | "strings" |
10 | 9 | ||
@@ -22,12 +21,12 @@ type BaseController struct { | @@ -22,12 +21,12 @@ type BaseController struct { | ||
22 | } | 21 | } |
23 | 22 | ||
24 | func (controller BaseController) BindJsonData(v interface{}) error { | 23 | func (controller BaseController) BindJsonData(v interface{}) error { |
25 | - bodyData := controller.Ctx.Input.GetData("requestBody") | ||
26 | - bodyByte, ok := bodyData.([]byte) | ||
27 | - if !ok { | ||
28 | - return errors.New("requestBody is not []byte") | ||
29 | - } | ||
30 | - return json.Unmarshal(bodyByte, v) | 24 | + // bodyData := controller.Ctx.Input.GetData("requestBody") |
25 | + // bodyByte, ok := bodyData.([]byte) | ||
26 | + // if !ok { | ||
27 | + // return errors.New("requestBody is not []byte") | ||
28 | + // } | ||
29 | + return json.Unmarshal(controller.Ctx.Input.RequestBody, v) | ||
31 | } | 30 | } |
32 | 31 | ||
33 | func (controller BaseController) ResponseError(err error) { | 32 | func (controller BaseController) ResponseError(err error) { |
@@ -98,9 +97,7 @@ func (controller *BaseController) Finish() { | @@ -98,9 +97,7 @@ func (controller *BaseController) Finish() { | ||
98 | func (controller *BaseController) Prepare() { | 97 | func (controller *BaseController) Prepare() { |
99 | logs.Info("====>Recv Request:", controller.Ctx.Input.URI()) | 98 | logs.Info("====>Recv Request:", controller.Ctx.Input.URI()) |
100 | if controller.Ctx.Input.IsPost() || controller.Ctx.Input.IsPut() { | 99 | if controller.Ctx.Input.IsPost() || controller.Ctx.Input.IsPut() { |
101 | - bodyByte, _ := ioutil.ReadAll(controller.Ctx.Request.Body) | ||
102 | - controller.Ctx.Input.SetData("requestBody", bodyByte) | ||
103 | - controller.Ctx.Request.Body.Close() | 100 | + bodyByte := controller.Ctx.Input.RequestBody |
104 | if len(bodyByte) > 1000 { | 101 | if len(bodyByte) > 1000 { |
105 | logs.Info("====>Recv data from client: BodyData:\n ", string(bodyByte[0:1000])) | 102 | logs.Info("====>Recv data from client: BodyData:\n ", string(bodyByte[0:1000])) |
106 | } else { | 103 | } else { |
-
请 注册 或 登录 后发表评论