staff user
This commit is contained in:
parent
0b37523657
commit
e8d795443e
|
@ -29,7 +29,6 @@ type UserConfig struct {
|
|||
type StaffUser struct {
|
||||
Id int64
|
||||
CorpId int64
|
||||
RoleId int64
|
||||
Username string
|
||||
Password string
|
||||
Realname string
|
||||
|
|
|
@ -4,3 +4,36 @@ type StaffLoginReq struct {
|
|||
Username string `json:"username"`
|
||||
Password string `json:"password"`
|
||||
}
|
||||
|
||||
type StaffListReq struct {
|
||||
BaseRequest
|
||||
Phone string `form:"phone"`
|
||||
Idno string `form:"idno"`
|
||||
Username string `form:"username"`
|
||||
Realname string `form:"realname"`
|
||||
}
|
||||
|
||||
type StaffCreateReq struct {
|
||||
Username string `json:"username"`
|
||||
}
|
||||
|
||||
type StaffUpdateReq struct {
|
||||
Id string `json:"id"`
|
||||
Phone string `json:"phone"`
|
||||
Idno string `json:"idno"`
|
||||
Username string `json:"username"`
|
||||
Realname string `json:"realname"`
|
||||
EntryDate string `json:"entry_date"`
|
||||
OfficialDate string `json:"official_date"`
|
||||
LeaveDate string `json:"leave_date"`
|
||||
|
||||
SalaryBase string `json:"salary_base"`
|
||||
SalaryTarget string `json:"salary_target"`
|
||||
SalaryCalculator string `json:"salary_calculator"`
|
||||
|
||||
PayeeBankName string `json:"payee_bank_name"`
|
||||
PayeeBankCard string `json:"payee_bank_card"`
|
||||
PayeeApliayUid string `json:"payee_apliay_uid"`
|
||||
|
||||
Config string `json:"config"`
|
||||
}
|
||||
|
|
|
@ -2,11 +2,13 @@ package controller
|
|||
|
||||
import (
|
||||
"enterprise/common/dao"
|
||||
"enterprise/common/model"
|
||||
"enterprise/server/api"
|
||||
"enterprise/server/service"
|
||||
"enterprise/server/session"
|
||||
"enterprise/worker"
|
||||
"github.com/gin-gonic/gin"
|
||||
"github.com/smbrave/goutil"
|
||||
"github.com/spf13/cast"
|
||||
"net/http"
|
||||
"strings"
|
||||
|
@ -28,6 +30,65 @@ func (s *Staff) Login(ctx *gin.Context) {
|
|||
ctx.JSON(http.StatusOK, session.NewRsp(data))
|
||||
}
|
||||
|
||||
func (s *Staff) List(ctx *gin.Context) {
|
||||
|
||||
}
|
||||
|
||||
func (s *Staff) Create(ctx *gin.Context) {
|
||||
sess := ctx.Keys[session.ContextSession].(*session.AdminSession)
|
||||
var req api.StaffCreateReq
|
||||
session.CheckParamError(ctx.ShouldBindJSON(&req))
|
||||
|
||||
staffUser, err := dao.NewStaffUserDao().GetByUsername(sess.GetAdmin().CorpId, req.Username)
|
||||
session.CheckDBError(err)
|
||||
if staffUser != nil {
|
||||
panic("用户已存在")
|
||||
}
|
||||
staffUser = new(model.StaffUser)
|
||||
staffUser.CorpId = sess.GetAdmin().CorpId
|
||||
staffUser.Username = req.Username
|
||||
_, err = dao.NewStaffUserDao().Create(staffUser)
|
||||
session.CheckDBError(err)
|
||||
ctx.JSON(http.StatusOK, session.NewRspOk())
|
||||
}
|
||||
|
||||
func (s *Staff) Update(ctx *gin.Context) {
|
||||
var req api.StaffUpdateReq
|
||||
session.CheckParamError(ctx.ShouldBindJSON(&req))
|
||||
|
||||
staffUser, err := dao.NewStaffUserDao().Get(cast.ToInt64(req.Id))
|
||||
session.CheckDBError(err)
|
||||
session.CheckNilError(staffUser, "用户不存在")
|
||||
|
||||
staffUser.Username = goutil.If(req.Username != "", req.Username, staffUser.Username)
|
||||
staffUser.Realname = goutil.If(req.Realname != "", req.Realname, staffUser.Realname)
|
||||
staffUser.Phone = goutil.If(req.Phone != "", req.Phone, staffUser.Phone)
|
||||
staffUser.Idno = goutil.If(req.Idno != "", req.Idno, staffUser.Idno)
|
||||
staffUser.EntryDate = goutil.If(req.EntryDate != "", req.EntryDate, staffUser.EntryDate)
|
||||
staffUser.OfficialDate = goutil.If(req.OfficialDate != "", req.OfficialDate, staffUser.OfficialDate)
|
||||
staffUser.LeaveDate = goutil.If(req.LeaveDate != "", req.LeaveDate, staffUser.LeaveDate)
|
||||
|
||||
staffSalary := staffUser.GetSalary()
|
||||
staffPayee := staffUser.GetPayee()
|
||||
staffSalary.Base = goutil.If(req.SalaryBase != "", req.SalaryBase, staffSalary.Base)
|
||||
staffSalary.Target = goutil.If(req.SalaryTarget != "", req.SalaryTarget, staffSalary.Target)
|
||||
staffPayee.BankName = goutil.If(req.PayeeBankName != "", req.PayeeBankName, staffPayee.BankName)
|
||||
staffPayee.BankCard = goutil.If(req.PayeeBankCard != "", req.PayeeBankCard, staffPayee.BankCard)
|
||||
staffPayee.AlipayUid = goutil.If(req.PayeeApliayUid != "", req.PayeeApliayUid, staffPayee.AlipayUid)
|
||||
|
||||
staffUser.Config = goutil.If(req.Config != "", req.Config, staffUser.Config)
|
||||
|
||||
err = dao.NewStaffUserDao().Update(staffUser)
|
||||
session.CheckDBError(err)
|
||||
ctx.JSON(http.StatusOK, session.NewRspOk())
|
||||
}
|
||||
|
||||
func (s *Staff) Delete(ctx *gin.Context) {
|
||||
id := cast.ToInt64(ctx.Query("id"))
|
||||
session.CheckDBError(dao.NewStaffUserDao().Delete(id))
|
||||
ctx.JSON(http.StatusOK, session.NewRspOk())
|
||||
}
|
||||
|
||||
func (s *Staff) Salary(ctx *gin.Context) {
|
||||
|
||||
sess := ctx.Keys[session.ContextSession].(*session.AdminSession)
|
||||
|
|
Loading…
Reference in New Issue