feat:完善项目
This commit is contained in:
@ -124,7 +124,7 @@ func (*Supplier) MaterialAdd(c *gin.Context) {
|
||||
return
|
||||
}
|
||||
err := manage.NewSupplier()(getSession()(c).(*service.Session)).Form(&manage.SupplierParams{
|
||||
Name: form.Name, Mobile: form.Mobile, Address: form.Address, Remark: form.Remark,
|
||||
Name: form.Name, Mobile: form.Mobile, Contacts: form.Contacts, Address: form.Address, Remark: form.Remark,
|
||||
Kind: model.ManageSupplierKindForMaterial,
|
||||
})
|
||||
APIResponse(err)(c)
|
||||
@ -167,7 +167,7 @@ func (*Supplier) MaterialEdit(c *gin.Context) {
|
||||
return
|
||||
}
|
||||
err := manage.NewSupplier()(getSession()(c).(*service.Session)).Form(&manage.SupplierParams{
|
||||
ID: form.Convert(), Name: form.Name, Mobile: form.Mobile, Address: form.Address, Remark: form.Remark,
|
||||
ID: form.Convert(), Name: form.Name, Contacts: form.Contacts, Mobile: form.Mobile, Address: form.Address, Remark: form.Remark,
|
||||
Kind: model.ManageSupplierKindForMaterial,
|
||||
})
|
||||
APIResponse(err)(c)
|
||||
@ -269,7 +269,7 @@ func (*Supplier) Repair(c *gin.Context) {
|
||||
}
|
||||
data, err := manage.NewSupplier()(getSession()(c).(*service.Session)).
|
||||
List(form.Name, form.Mobile, model.ManageSupplierKindForRepair, form.Page, form.PageSize)
|
||||
APIResponse(err, data)
|
||||
APIResponse(err, data)(c)
|
||||
}
|
||||
|
||||
/**
|
||||
@ -306,7 +306,7 @@ func (*Supplier) RepairAdd(c *gin.Context) {
|
||||
return
|
||||
}
|
||||
err := manage.NewSupplier()(getSession()(c).(*service.Session)).Form(&manage.SupplierParams{
|
||||
Name: form.Name, Mobile: form.Mobile, Address: form.Address, Remark: form.Remark,
|
||||
Name: form.Name, Mobile: form.Mobile, Contacts: form.Contacts, Address: form.Address, Remark: form.Remark,
|
||||
Kind: model.ManageSupplierKindForRepair,
|
||||
})
|
||||
APIResponse(err)(c)
|
||||
@ -349,7 +349,7 @@ func (*Supplier) RepairEdit(c *gin.Context) {
|
||||
return
|
||||
}
|
||||
err := manage.NewSupplier()(getSession()(c).(*service.Session)).Form(&manage.SupplierParams{
|
||||
ID: form.Convert(), Name: form.Name, Mobile: form.Mobile, Address: form.Address, Remark: form.Remark,
|
||||
ID: form.Convert(), Name: form.Name, Contacts: form.Contacts, Mobile: form.Mobile, Address: form.Address, Remark: form.Remark,
|
||||
Kind: model.ManageSupplierKindForRepair,
|
||||
})
|
||||
APIResponse(err)(c)
|
||||
@ -493,7 +493,7 @@ func (*Supplier) ManufacturerAdd(c *gin.Context) {
|
||||
return
|
||||
}
|
||||
err := manage.NewSupplier()(getSession()(c).(*service.Session)).Form(&manage.SupplierParams{
|
||||
Name: form.Name, Mobile: form.Mobile, Address: form.Address, Remark: form.Remark,
|
||||
Name: form.Name, Mobile: form.Mobile, Contacts: form.Contacts, Address: form.Address, Remark: form.Remark,
|
||||
Kind: model.ManageSupplierKindForManufacturer,
|
||||
})
|
||||
APIResponse(err)(c)
|
||||
@ -536,7 +536,7 @@ func (*Supplier) ManufacturerEdit(c *gin.Context) {
|
||||
return
|
||||
}
|
||||
err := manage.NewSupplier()(getSession()(c).(*service.Session)).Form(&manage.SupplierParams{
|
||||
ID: form.Convert(), Name: form.Name, Mobile: form.Mobile, Address: form.Address, Remark: form.Remark,
|
||||
ID: form.Convert(), Name: form.Name, Contacts: form.Contacts, Mobile: form.Mobile, Address: form.Address, Remark: form.Remark,
|
||||
Kind: model.ManageSupplierKindForManufacturer,
|
||||
})
|
||||
APIResponse(err)(c)
|
||||
|
@ -10,7 +10,7 @@ import (
|
||||
type Tenant struct{}
|
||||
|
||||
type tenantForm struct {
|
||||
ParentID uint64 `json:"parent_id" form:"parent_id"`
|
||||
ParentID string `json:"parent_id" form:"parent_id"`
|
||||
Name string `json:"name" form:"name" binding:"required"`
|
||||
Remark string `json:"remark" form:"remark"`
|
||||
Province string `json:"province" form:"province"`
|
||||
@ -23,11 +23,80 @@ type tenantForm struct {
|
||||
* @apiDefine Tenant 租户(单位)管理
|
||||
*/
|
||||
|
||||
/**
|
||||
* @api {post} /api/v1/tenant/list 单位列表
|
||||
* @apiVersion 1.0.0
|
||||
* @apiName TenantList
|
||||
* @apiGroup Tenant
|
||||
*
|
||||
* @apiHeader {string} x-token token
|
||||
*
|
||||
* @apiSuccess (200) {Object} data 数据信息
|
||||
* @apiSuccess (200) {Object} data.data 具体信息
|
||||
* @apiSuccess (200) {String} data.id ID
|
||||
* @apiSuccess (200) {String} data.name 名称
|
||||
* @apiSuccess (200) {String} data.province 省
|
||||
* @apiSuccess (200) {String} data.city 市
|
||||
* @apiSuccess (200) {String} data.district 区
|
||||
* @apiSuccess (200) {String} data.address 地址
|
||||
* @apiSuccess (200) {String} data.remark 备注
|
||||
* @apiSuccess (200) {Object} data.children 子集
|
||||
* @apiSuccess (200) {Number} code 成功响应状态码!
|
||||
* @apiSuccess (200) {String} msg 成功提示
|
||||
*
|
||||
* @apiSuccessExample {json} Success response:
|
||||
* HTTPS 200 OK
|
||||
* {
|
||||
* "code": 200
|
||||
* "msg": "ok"
|
||||
* "data": {
|
||||
* [
|
||||
* {
|
||||
* "id": "EgmJ4Ga7LQ",
|
||||
* "name": "合肥市武警支队",
|
||||
* "province": "安徽省",
|
||||
* "city": "合肥市",
|
||||
* "district": "蜀山区",
|
||||
* "address": "大蜀山。 ",
|
||||
* "remark": "",
|
||||
* "children": []
|
||||
* }
|
||||
* ],
|
||||
* }
|
||||
*/
|
||||
func (*Tenant) List(c *gin.Context) {
|
||||
data, err := tenant.NewInstance()(getSession()(c).(*service.Session)).List()
|
||||
APIResponse(err, data)(c)
|
||||
}
|
||||
|
||||
/**
|
||||
* @api {post} /api/v1/tenant/add 单位信息添加
|
||||
* @apiVersion 1.0.0
|
||||
* @apiName TenantAdd
|
||||
* @apiGroup Tenant
|
||||
*
|
||||
* @apiHeader {string} x-token token
|
||||
*
|
||||
* @apiParam {String} [parent_id="''"] 父集
|
||||
* @apiParam {String} name 名称
|
||||
* @apiParam {String} [remark="''"] 名称
|
||||
* @apiParam {String} [province="''"] 省
|
||||
* @apiParam {String} [city="''"] 市
|
||||
* @apiParam {String} [district="''"] 区
|
||||
* @apiParam {String} [address="''"] 地址
|
||||
*
|
||||
* @apiSuccess (200) {Object} data 数据信息
|
||||
* @apiSuccess (200) {Number} code 成功响应状态码!
|
||||
* @apiSuccess (200) {String} msg 成功提示
|
||||
*
|
||||
* @apiSuccessExample {json} Success response:
|
||||
* HTTPS 200 OK
|
||||
* {
|
||||
* "code": 200
|
||||
* "msg": "ok"
|
||||
* "data": null
|
||||
* }
|
||||
*/
|
||||
func (*Tenant) Add(c *gin.Context) {
|
||||
form := new(tenantForm)
|
||||
|
||||
@ -35,8 +104,9 @@ func (*Tenant) Add(c *gin.Context) {
|
||||
APIFailure(err.(error))(c)
|
||||
return
|
||||
}
|
||||
obj := &IDStringForm{ID: form.ParentID}
|
||||
err := tenant.NewInstance()(getSession()(c).(*service.Session)).Form(&tenant.InstanceParams{
|
||||
ParentID: form.ParentID, Name: form.Name, Remark: form.Remark,
|
||||
ParentID: obj.Convert(), Name: form.Name, Remark: form.Remark,
|
||||
CommonArea: basic.CommonArea{
|
||||
Province: form.Province, City: form.City, District: form.District, Address: form.Address,
|
||||
},
|
||||
@ -44,6 +114,35 @@ func (*Tenant) Add(c *gin.Context) {
|
||||
APIResponse(err)(c)
|
||||
}
|
||||
|
||||
/**
|
||||
* @api {post} /api/v1/tenant/edit 单位信息修改
|
||||
* @apiVersion 1.0.0
|
||||
* @apiName TenantEdit
|
||||
* @apiGroup Tenant
|
||||
*
|
||||
* @apiHeader {string} x-token token
|
||||
*
|
||||
* @apiParam {String} id ID
|
||||
* @apiParam {String} [parent_id="''"] 父集
|
||||
* @apiParam {String} name 名称
|
||||
* @apiParam {String} [remark="''"] 名称
|
||||
* @apiParam {String} [province="''"] 省
|
||||
* @apiParam {String} [city="''"] 市
|
||||
* @apiParam {String} [district="''"] 区
|
||||
* @apiParam {String} [address="''"] 地址
|
||||
*
|
||||
* @apiSuccess (200) {Object} data 数据信息
|
||||
* @apiSuccess (200) {Number} code 成功响应状态码!
|
||||
* @apiSuccess (200) {String} msg 成功提示
|
||||
*
|
||||
* @apiSuccessExample {json} Success response:
|
||||
* HTTPS 200 OK
|
||||
* {
|
||||
* "code": 200
|
||||
* "msg": "ok"
|
||||
* "data": null
|
||||
* }
|
||||
*/
|
||||
func (*Tenant) Edit(c *gin.Context) {
|
||||
form := &struct {
|
||||
IDStringForm
|
||||
@ -53,8 +152,9 @@ func (*Tenant) Edit(c *gin.Context) {
|
||||
APIFailure(err.(error))(c)
|
||||
return
|
||||
}
|
||||
obj := &IDStringForm{ID: form.ParentID}
|
||||
err := tenant.NewInstance()(getSession()(c).(*service.Session)).Form(&tenant.InstanceParams{
|
||||
ID: form.Convert(), ParentID: form.ParentID, Name: form.Name, Remark: form.Remark,
|
||||
ID: form.Convert(), ParentID: obj.Convert(), Name: form.Name, Remark: form.Remark,
|
||||
CommonArea: basic.CommonArea{
|
||||
Province: form.Province, City: form.City, District: form.District, Address: form.Address,
|
||||
},
|
||||
@ -62,6 +162,28 @@ func (*Tenant) Edit(c *gin.Context) {
|
||||
APIResponse(err)(c)
|
||||
}
|
||||
|
||||
/**
|
||||
* @api {post} /api/v1/tenant/delete 单位信息删除
|
||||
* @apiVersion 1.0.0
|
||||
* @apiName TenantDelete
|
||||
* @apiGroup Tenant
|
||||
*
|
||||
* @apiHeader {string} x-token token
|
||||
*
|
||||
* @apiParam {String} id ID
|
||||
*
|
||||
* @apiSuccess (200) {Object} data 数据信息
|
||||
* @apiSuccess (200) {Number} code 成功响应状态码!
|
||||
* @apiSuccess (200) {String} msg 成功提示
|
||||
*
|
||||
* @apiSuccessExample {json} Success response:
|
||||
* HTTPS 200 OK
|
||||
* {
|
||||
* "code": 200
|
||||
* "msg": "ok"
|
||||
* "data": null
|
||||
* }
|
||||
*/
|
||||
func (*Tenant) Delete(c *gin.Context) {
|
||||
form := new(IDStringForm)
|
||||
|
||||
|
292
app/api/user.go
292
app/api/user.go
@ -1,17 +1,28 @@
|
||||
package api
|
||||
|
||||
import (
|
||||
model2 "ArmedPolice/app/common/model"
|
||||
"ArmedPolice/app/controller/user"
|
||||
"ArmedPolice/app/service"
|
||||
"github.com/gin-gonic/gin"
|
||||
)
|
||||
|
||||
type User struct{}
|
||||
|
||||
/**
|
||||
* @apiDefine User 用户管理
|
||||
*/
|
||||
|
||||
type User struct{}
|
||||
|
||||
type userForm struct {
|
||||
Account string `json:"account" form:"account" binding:"required"`
|
||||
Name string `json:"name" form:"name" binding:"required"`
|
||||
Avatar string `json:"avatar" form:"avatar"`
|
||||
Mobile string `json:"mobile" form:"mobile" binding:"required"`
|
||||
Password string `json:"password" form:"password"`
|
||||
Gender int `json:"gender" form:"gender"`
|
||||
Remark string `json:"remark" form:"remark"`
|
||||
}
|
||||
|
||||
/**
|
||||
* @api {get} /api/v1/user/info 用户信息
|
||||
* @apiVersion 1.0.0
|
||||
@ -20,11 +31,11 @@ type User struct{}
|
||||
*
|
||||
* @apiHeader {string} x-token token
|
||||
*
|
||||
* @apiSuccess (200) {Number} code 成功响应状态码!
|
||||
* @apiSuccess (200) {String} msg 成功提示
|
||||
* @apiSuccess (200) {Json} data 数据信息
|
||||
* @apiSuccess (200) {Object} data 数据信息
|
||||
* @apiSuccess (200) {String} data.name 用户名
|
||||
* @apiSuccess (200) {String} data.avatar 用户头像
|
||||
* @apiSuccess (200) {Number} code 成功响应状态码!
|
||||
* @apiSuccess (200) {String} msg 成功提示
|
||||
*
|
||||
* @apiSuccessExample {json} Success response:
|
||||
* HTTPS 200 OK
|
||||
@ -63,34 +74,273 @@ func (*User) List(c *gin.Context) {
|
||||
APIResponse(err, data)(c)
|
||||
}
|
||||
|
||||
/**
|
||||
* @api {get} /api/v1/user/add 用户信息添加
|
||||
* @apiVersion 1.0.0
|
||||
* @apiName UserAdd
|
||||
* @apiGroup User
|
||||
*
|
||||
* @apiHeader {string} x-token token
|
||||
*
|
||||
* @apiParam {String} account 登陆账号
|
||||
* @apiParam {String} name 姓名
|
||||
* @apiParam {String} [avatar="''"] 头像
|
||||
* @apiParam {String} mobile 手机号
|
||||
* @apiParam {String} password 密码
|
||||
* @apiParam {Number} gender 性别,1:男,2:女
|
||||
* @apiParam {String} [remark="''"] 备注信息
|
||||
*
|
||||
* @apiSuccess (200) {Object} data 数据信息
|
||||
* @apiSuccess (200) {String} data.name 用户名
|
||||
* @apiSuccess (200) {String} data.avatar 用户头像
|
||||
* @apiSuccess (200) {Number} code 成功响应状态码!
|
||||
* @apiSuccess (200) {String} msg 成功提示
|
||||
*
|
||||
* @apiSuccessExample {json} Success response:
|
||||
* HTTPS 200 OK
|
||||
* {
|
||||
* "code": 200
|
||||
* "msg": "ok"
|
||||
* "data": null
|
||||
* }
|
||||
*/
|
||||
func (*User) Add(c *gin.Context) {
|
||||
form := &struct {
|
||||
Name string `json:"name" form:"name"`
|
||||
Mobile string `json:"mobile" form:"mobile"`
|
||||
TenantID uint64 `json:"tenant_id" form:"tenant_id"`
|
||||
PageForm
|
||||
}{}
|
||||
form := new(userForm)
|
||||
|
||||
if err := bind(form)(c); err != nil {
|
||||
APIFailure(err.(error))(c)
|
||||
return
|
||||
}
|
||||
data, err := user.NewInstance()(getSession()(c).(*service.Session)).List(form.Name, form.Mobile, form.TenantID,
|
||||
form.Page, form.PageSize)
|
||||
APIResponse(err, data)(c)
|
||||
obj := &ImageForm{Image: form.Avatar}
|
||||
|
||||
err := user.NewInstance()(getSession()(c).(*service.Session)).Form(&user.InstanceParams{
|
||||
Account: form.Account, Name: form.Name, Avatar: obj.FilterImageURL(), Mobile: form.Mobile,
|
||||
Password: form.Password, Remark: form.Remark, Gender: form.Gender,
|
||||
})
|
||||
APIResponse(err)(c)
|
||||
}
|
||||
|
||||
/**
|
||||
* @api {get} /api/v1/user/edit 用户信息修改
|
||||
* @apiVersion 1.0.0
|
||||
* @apiName UserEdit
|
||||
* @apiGroup User
|
||||
*
|
||||
* @apiHeader {string} x-token token
|
||||
*
|
||||
* @apiParam {String} id ID
|
||||
* @apiParam {String} account 登陆账号
|
||||
* @apiParam {String} name 姓名
|
||||
* @apiParam {String} [avatar="''"] 头像
|
||||
* @apiParam {String} mobile 手机号
|
||||
* @apiParam {Number} gender 性别,1:男,2:女
|
||||
* @apiParam {String} [remark="''"] 备注信息
|
||||
*
|
||||
* @apiSuccess (200) {Object} data 数据信息
|
||||
* @apiSuccess (200) {String} data.name 用户名
|
||||
* @apiSuccess (200) {String} data.avatar 用户头像
|
||||
* @apiSuccess (200) {Number} code 成功响应状态码!
|
||||
* @apiSuccess (200) {String} msg 成功提示
|
||||
*
|
||||
* @apiSuccessExample {json} Success response:
|
||||
* HTTPS 200 OK
|
||||
* {
|
||||
* "code": 200
|
||||
* "msg": "ok"
|
||||
* "data": null
|
||||
* }
|
||||
*/
|
||||
|
||||
func (*User) Edit(c *gin.Context) {
|
||||
form := &struct {
|
||||
Name string `json:"name" form:"name"`
|
||||
Mobile string `json:"mobile" form:"mobile"`
|
||||
TenantID uint64 `json:"tenant_id" form:"tenant_id"`
|
||||
PageForm
|
||||
IDStringForm
|
||||
userForm
|
||||
}{}
|
||||
if err := bind(form)(c); err != nil {
|
||||
APIFailure(err.(error))(c)
|
||||
return
|
||||
}
|
||||
data, err := user.NewInstance()(getSession()(c).(*service.Session)).List(form.Name, form.Mobile, form.TenantID,
|
||||
form.Page, form.PageSize)
|
||||
APIResponse(err, data)(c)
|
||||
obj := &ImageForm{Image: form.Avatar}
|
||||
|
||||
err := user.NewInstance()(getSession()(c).(*service.Session)).Form(&user.InstanceParams{
|
||||
ID: form.Convert(), Account: form.Account, Name: form.Name, Avatar: obj.FilterImageURL(),
|
||||
Mobile: form.Mobile, Password: form.Password, Remark: form.Remark, Gender: form.Gender,
|
||||
})
|
||||
APIResponse(err)(c)
|
||||
}
|
||||
|
||||
/**
|
||||
* @api {get} /api/v1/user/delete 用户信息删除
|
||||
* @apiVersion 1.0.0
|
||||
* @apiName UserDelete
|
||||
* @apiGroup User
|
||||
*
|
||||
* @apiHeader {string} x-token token
|
||||
*
|
||||
* @apiParam {String} id ID
|
||||
*
|
||||
* @apiSuccess (200) {Number} code 成功响应状态码!
|
||||
* @apiSuccess (200) {String} msg 成功提示
|
||||
* @apiSuccess (200) {Object} data 数据信息
|
||||
*
|
||||
* @apiSuccessExample {json} Success response:
|
||||
* HTTPS 200 OK
|
||||
* {
|
||||
* "code": 200
|
||||
* "msg": "ok"
|
||||
* "data": null
|
||||
* }
|
||||
*/
|
||||
func (*User) Delete(c *gin.Context) {
|
||||
form := new(IDStringForm)
|
||||
|
||||
if err := bind(form)(c); err != nil {
|
||||
APIFailure(err.(error))(c)
|
||||
return
|
||||
}
|
||||
err := user.NewInstance()(getSession()(c).(*service.Session)).Delete(form.Convert())
|
||||
APIResponse(err)(c)
|
||||
}
|
||||
|
||||
/**
|
||||
* @api {get} /api/v1/user/password/quick 用户密码快速设置
|
||||
* @apiVersion 1.0.0
|
||||
* @apiName UserPasswordQuick
|
||||
* @apiGroup User
|
||||
*
|
||||
* @apiHeader {string} x-token token
|
||||
*
|
||||
* @apiParam {String} id ID
|
||||
* @apiParam {String} passowrd 密码
|
||||
*
|
||||
* @apiSuccess (200) {Number} code 成功响应状态码!
|
||||
* @apiSuccess (200) {String} msg 成功提示
|
||||
* @apiSuccess (200) {Json} data 数据信息
|
||||
*
|
||||
* @apiSuccessExample {json} Success response:
|
||||
* HTTPS 200 OK
|
||||
* {
|
||||
* "code": 200
|
||||
* "msg": "ok"
|
||||
* "data": null
|
||||
* }
|
||||
*/
|
||||
func (*User) PasswordQuick(c *gin.Context) {
|
||||
form := &struct {
|
||||
IDStringForm
|
||||
Password string `json:"password" form:"password" binding:"required"`
|
||||
}{}
|
||||
if err := bind(form)(c); err != nil {
|
||||
APIFailure(err.(error))(c)
|
||||
return
|
||||
}
|
||||
err := user.NewInstance()(getSession()(c).(*service.Session)).PasswordQuick(form.Convert(), form.Password)
|
||||
APIResponse(err)(c)
|
||||
}
|
||||
|
||||
/**
|
||||
* @api {get} /api/v1/user/password/tradition 用户密码传统设置
|
||||
* @apiVersion 1.0.0
|
||||
* @apiName UserPasswordTradition
|
||||
* @apiGroup User
|
||||
*
|
||||
* @apiHeader {string} x-token token
|
||||
*
|
||||
* @apiParam {String} id ID
|
||||
* @apiParam {String} original_pwd 旧密码
|
||||
* @apiParam {String} passowrd 新密码
|
||||
* @apiParam {String} repeat_pwd 重复密码
|
||||
*
|
||||
* @apiSuccess (200) {Number} code 成功响应状态码!
|
||||
* @apiSuccess (200) {String} msg 成功提示
|
||||
* @apiSuccess (200) {Json} data 数据信息
|
||||
*
|
||||
* @apiSuccessExample {json} Success response:
|
||||
* HTTPS 200 OK
|
||||
* {
|
||||
* "code": 200
|
||||
* "msg": "ok"
|
||||
* "data": null
|
||||
* }
|
||||
*/
|
||||
func (*User) PasswordTradition(c *gin.Context) {
|
||||
form := &struct {
|
||||
IDStringForm
|
||||
OriginalPwd string `json:"original_pwd" form:"original_pwd" binding:"required"`
|
||||
Password string `json:"password" form:"password" binding:"required"`
|
||||
RepeatPwd string `json:"repeat_pwd" form:"repeat_pwd" binding:"required"`
|
||||
}{}
|
||||
if err := bind(form)(c); err != nil {
|
||||
APIFailure(err.(error))(c)
|
||||
return
|
||||
}
|
||||
err := user.NewInstance()(getSession()(c).(*service.Session)).PasswordTradition(form.Convert(),
|
||||
form.OriginalPwd, form.Password, form.RepeatPwd)
|
||||
APIResponse(err)(c)
|
||||
}
|
||||
|
||||
/**
|
||||
* @api {get} /api/v1/user/password/activate 用户账号激活
|
||||
* @apiVersion 1.0.0
|
||||
* @apiName UserPasswordActivate
|
||||
* @apiGroup User
|
||||
*
|
||||
* @apiHeader {string} x-token token
|
||||
*
|
||||
* @apiParam {String} id ID
|
||||
*
|
||||
* @apiSuccess (200) {Number} code 成功响应状态码!
|
||||
* @apiSuccess (200) {String} msg 成功提示
|
||||
* @apiSuccess (200) {Json} data 数据信息
|
||||
*
|
||||
* @apiSuccessExample {json} Success response:
|
||||
* HTTPS 200 OK
|
||||
* {
|
||||
* "code": 200
|
||||
* "msg": "ok"
|
||||
* "data": null
|
||||
* }
|
||||
*/
|
||||
func (*User) Activate(c *gin.Context) {
|
||||
form := new(IDStringForm)
|
||||
|
||||
if err := bind(form)(c); err != nil {
|
||||
APIFailure(err.(error))(c)
|
||||
return
|
||||
}
|
||||
err := user.NewInstance()(getSession()(c).(*service.Session)).Status(form.Convert(), model2.SysUserStatusForNormal)
|
||||
APIResponse(err)(c)
|
||||
}
|
||||
|
||||
/**
|
||||
* @api {get} /api/v1/user/password/frozen( 用户账号冻结
|
||||
* @apiVersion 1.0.0
|
||||
* @apiName UserPasswordFrozen(
|
||||
* @apiGroup User
|
||||
*
|
||||
* @apiHeader {string} x-token token
|
||||
*
|
||||
* @apiParam {String} id ID
|
||||
*
|
||||
* @apiSuccess (200) {Number} code 成功响应状态码!
|
||||
* @apiSuccess (200) {String} msg 成功提示
|
||||
* @apiSuccess (200) {Json} data 数据信息
|
||||
*
|
||||
* @apiSuccessExample {json} Success response:
|
||||
* HTTPS 200 OK
|
||||
* {
|
||||
* "code": 200
|
||||
* "msg": "ok"
|
||||
* "data": null
|
||||
* }
|
||||
*/
|
||||
func (*User) Frozen(c *gin.Context) {
|
||||
form := new(IDStringForm)
|
||||
|
||||
if err := bind(form)(c); err != nil {
|
||||
APIFailure(err.(error))(c)
|
||||
return
|
||||
}
|
||||
err := user.NewInstance()(getSession()(c).(*service.Session)).Status(form.Convert(), model2.SysUserStatusForDisable)
|
||||
APIResponse(err)(c)
|
||||
}
|
||||
|
@ -18,6 +18,7 @@ type (
|
||||
ID string `json:"id"`
|
||||
Name string `json:"name"`
|
||||
*model2.AreaInfo
|
||||
Remark string `json:"remark"`
|
||||
Children []*InstanceInfo `json:"children"`
|
||||
}
|
||||
// InstanceParams 参数信息
|
||||
@ -37,6 +38,7 @@ func (c *Instance) tree(src []*model2.SysTenant, parentID uint64) []*InstanceInf
|
||||
ID: v.GetEncodeID(),
|
||||
Name: v.Name,
|
||||
AreaInfo: v.Area.Format(),
|
||||
Remark: v.Remark,
|
||||
Children: c.tree(src, v.ID),
|
||||
})
|
||||
}
|
||||
|
@ -5,6 +5,8 @@ import (
|
||||
"ArmedPolice/app/controller/basic"
|
||||
"ArmedPolice/app/model"
|
||||
"ArmedPolice/app/service"
|
||||
"errors"
|
||||
"time"
|
||||
)
|
||||
|
||||
type Instance struct{ *service.Session }
|
||||
@ -22,6 +24,12 @@ type (
|
||||
ID string `json:"id"`
|
||||
*model.SysUserInfo
|
||||
}
|
||||
// InstanceParams 参数信息
|
||||
InstanceParams struct {
|
||||
ID uint64
|
||||
Account, Name, Avatar, Mobile, Password, Remark string
|
||||
Gender int
|
||||
}
|
||||
)
|
||||
|
||||
// Info 基本信息
|
||||
@ -60,11 +68,123 @@ func (c *Instance) List(name, mobile string, tenantID uint64, page, pageSize int
|
||||
return &basic.PageDataResponse{Data: list, Count: count}, nil
|
||||
}
|
||||
|
||||
func (c *Instance) Form() error {
|
||||
// Form 数据操作
|
||||
func (c *Instance) Form(params *InstanceParams) error {
|
||||
mSysUser := model.NewSysUser()
|
||||
|
||||
if params.ID > 0 {
|
||||
mSysUser.ID = params.ID
|
||||
|
||||
isExist, err := model2.FirstField(mSysUser.SysUser, []string{"id", "name", "mobile"})
|
||||
|
||||
if err != nil {
|
||||
return err
|
||||
} else if !isExist {
|
||||
return errors.New("操作错误,用户信息不存在或已被删除")
|
||||
}
|
||||
if mSysUser.Mobile != params.Mobile {
|
||||
var count int64
|
||||
|
||||
if err = model2.Count(mSysUser.SysUser, &count, model2.NewWhere("mobile", params.Mobile)); err != nil {
|
||||
return err
|
||||
} else if count > 0 {
|
||||
return errors.New("操作错误,该手机号已被注册")
|
||||
}
|
||||
}
|
||||
return model2.Updates(mSysUser.SysUser, map[string]interface{}{
|
||||
"name": params.Name, "mobile": params.Mobile, "avatar": params.Avatar, "gender": params.Gender,
|
||||
"remark": params.Remark, "updated_at": time.Now(),
|
||||
})
|
||||
}
|
||||
if params.Password == "" {
|
||||
return errors.New("操作错误,密码不可为空")
|
||||
}
|
||||
var count int64
|
||||
|
||||
err := model2.Count(mSysUser.SysUser, &count, model2.NewWhere("account", params.Account))
|
||||
|
||||
if err != nil {
|
||||
return err
|
||||
} else if count > 0 {
|
||||
return errors.New("操作错误,该账户名已被注册")
|
||||
}
|
||||
if err = model2.Count(mSysUser.SysUser, &count, model2.NewWhere("mobile", params.Mobile)); err != nil {
|
||||
return err
|
||||
} else if count > 0 {
|
||||
return errors.New("操作错误,该手机号已被注册")
|
||||
}
|
||||
mSysUser.Account = params.Account
|
||||
mSysUser.Name = params.Name
|
||||
mSysUser.Mobile = params.Mobile
|
||||
mSysUser.Avatar = params.Avatar
|
||||
mSysUser.Password = params.Password
|
||||
mSysUser.Gender.Gender = model2.GenderKind(params.Gender)
|
||||
mSysUser.Remark = params.Remark
|
||||
|
||||
return model2.Create(mSysUser.SysUser)
|
||||
}
|
||||
|
||||
// Delete 删除信息
|
||||
func (c *Instance) Delete(id uint64) error {
|
||||
mSysUser := model.NewSysUser()
|
||||
mSysUser.ID = id
|
||||
return model2.Delete(mSysUser.SysUser)
|
||||
}
|
||||
|
||||
// PasswordQuick 快速设置密码
|
||||
func (c *Instance) PasswordQuick(id uint64, password string) error {
|
||||
mSysUser := model.NewSysUser()
|
||||
mSysUser.ID = id
|
||||
mSysUser.Password = password
|
||||
mSysUser.Pass()
|
||||
|
||||
if err := model2.Updates(mSysUser.SysUser, map[string]interface{}{
|
||||
"password": mSysUser.Password, "salt": mSysUser.Salt, "updated_at": time.Now(),
|
||||
}); err != nil {
|
||||
return err
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
func (c *Instance) Delete() error {
|
||||
// PasswordTradition 传统设置密码
|
||||
func (c *Instance) PasswordTradition(id uint64, originalPwd, password, repeatPwd string) error {
|
||||
if password != repeatPwd {
|
||||
return errors.New("操作错误,密码输入不正确")
|
||||
}
|
||||
mSysUser := model.NewSysUser()
|
||||
mSysUser.ID = id
|
||||
|
||||
isExist, err := model2.FirstField(mSysUser.SysUser, []string{"id", "password", "salt"})
|
||||
|
||||
if err != nil {
|
||||
return err
|
||||
} else if !isExist {
|
||||
return errors.New("操作错误,用户信息不存在或已被删除")
|
||||
}
|
||||
if !mSysUser.ValidatePassword(originalPwd) {
|
||||
return errors.New("操作错误,旧密码不正确")
|
||||
}
|
||||
mSysUser.Password = password
|
||||
mSysUser.Pass()
|
||||
|
||||
if err := model2.Updates(mSysUser.SysUser, map[string]interface{}{
|
||||
"password": mSysUser.Password, "salt": mSysUser.Salt, "updated_at": time.Now(),
|
||||
}); err != nil {
|
||||
return err
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
// Status 状态处理
|
||||
func (c *Instance) Status(id uint64, status model2.SysUserStatus) error {
|
||||
mSysUser := model.NewSysUser()
|
||||
mSysUser.ID = id
|
||||
|
||||
if err := model2.Updates(mSysUser.SysUser, map[string]interface{}{
|
||||
"status": status, "updated_at": time.Now(),
|
||||
}); err != nil {
|
||||
return err
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
|
@ -78,8 +78,8 @@ func (this *Router) registerAPI() {
|
||||
_api := new(api.Tenant)
|
||||
tenantV1.POST("/list", _api.List)
|
||||
tenantV1.POST("/add", _api.Add)
|
||||
tenantV1.POST("/edit", _api.Add)
|
||||
tenantV1.POST("/delete", _api.Add)
|
||||
tenantV1.POST("/edit", _api.Edit)
|
||||
tenantV1.POST("/delete", _api.Delete)
|
||||
}
|
||||
// User 用户管理
|
||||
userV1 := v1.Group("/user")
|
||||
@ -88,6 +88,13 @@ func (this *Router) registerAPI() {
|
||||
userV1.GET("/info", _api.Info)
|
||||
userV1.GET("/menu", _api.Menu)
|
||||
userV1.POST("/list", _api.List)
|
||||
userV1.POST("/add", _api.Add)
|
||||
userV1.POST("/edit", _api.Edit)
|
||||
userV1.POST("/delete", _api.Delete)
|
||||
userV1.POST("/password/quick", _api.PasswordQuick)
|
||||
userV1.POST("/password/tradition", _api.PasswordTradition)
|
||||
userV1.POST("/activate", _api.Activate)
|
||||
userV1.POST("/frozen", _api.Frozen)
|
||||
}
|
||||
// Menu 菜单管理
|
||||
menuV1 := v1.Group("/menu")
|
||||
|
Reference in New Issue
Block a user