pay
This commit is contained in:
parent
bf4de8a8d8
commit
2644ad9c57
|
@ -43,6 +43,11 @@ type UpdateSalaryReq struct {
|
||||||
Status string `json:"status"`
|
Status string `json:"status"`
|
||||||
}
|
}
|
||||||
|
|
||||||
|
type PaySalaryReq struct {
|
||||||
|
SalaryId string `json:"salary_id"`
|
||||||
|
PayType string `json:"pay_type"`
|
||||||
|
}
|
||||||
|
|
||||||
type ListSalaryReq struct {
|
type ListSalaryReq struct {
|
||||||
BaseRequest
|
BaseRequest
|
||||||
StartMonth string `form:"start_month"`
|
StartMonth string `form:"start_month"`
|
||||||
|
|
|
@ -52,6 +52,13 @@ type StaffCreateReq struct {
|
||||||
Username string `json:"username"`
|
Username string `json:"username"`
|
||||||
}
|
}
|
||||||
|
|
||||||
|
type StaffPayReq struct {
|
||||||
|
StaffId string `json:"staff_id"`
|
||||||
|
PayType string `json:"pay_type"`
|
||||||
|
Title string `json:"title"`
|
||||||
|
Amount string `json:"amount"`
|
||||||
|
}
|
||||||
|
|
||||||
type StaffUpdateReq struct {
|
type StaffUpdateReq struct {
|
||||||
Id string `json:"id"`
|
Id string `json:"id"`
|
||||||
Phone string `json:"phone"`
|
Phone string `json:"phone"`
|
||||||
|
|
|
@ -46,8 +46,11 @@ func (q *Payment) Pay(ctx *gin.Context) {
|
||||||
if req.Password != corp.GetConfig().Password {
|
if req.Password != corp.GetConfig().Password {
|
||||||
panic(config.ErrParam.New().Append("密码错误"))
|
panic(config.ErrParam.New().Append("密码错误"))
|
||||||
}
|
}
|
||||||
|
user, err := dao.NewStaffUserDao().GetByUsername(corp.Id, req.Username)
|
||||||
|
session.CheckDBError(err)
|
||||||
|
session.CheckNilError(user, fmt.Sprintf("用户[%s]不存在", req.Username))
|
||||||
|
|
||||||
service.NewPay().Pay(corp, &req)
|
service.NewPay().Pay(corp, user, req.Title, req.PayType, req.Amount)
|
||||||
ctx.JSON(http.StatusOK, session.NewRspOk())
|
ctx.JSON(http.StatusOK, session.NewRspOk())
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -40,6 +40,14 @@ func (s *Salary) Update(ctx *gin.Context) {
|
||||||
ctx.JSON(http.StatusOK, session.NewRspOk())
|
ctx.JSON(http.StatusOK, session.NewRspOk())
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (s *Salary) Pay(ctx *gin.Context) {
|
||||||
|
var req api.PaySalaryReq
|
||||||
|
session.CheckParamError(ctx.ShouldBind(&req))
|
||||||
|
ctx.Keys[session.ContextRequest] = req
|
||||||
|
service.NewStaffSalary().Pay(ctx.Keys[session.ContextSession].(*session.AdminSession), &req)
|
||||||
|
ctx.JSON(http.StatusOK, session.NewRspOk())
|
||||||
|
}
|
||||||
|
|
||||||
func (s *Salary) Delete(ctx *gin.Context) {
|
func (s *Salary) Delete(ctx *gin.Context) {
|
||||||
id := cast.ToInt64(ctx.Query("id"))
|
id := cast.ToInt64(ctx.Query("id"))
|
||||||
dao.NewStaffSalaryDao().Delete(id)
|
dao.NewStaffSalaryDao().Delete(id)
|
||||||
|
|
|
@ -61,6 +61,15 @@ func (s *Staff) Create(ctx *gin.Context) {
|
||||||
ctx.JSON(http.StatusOK, session.NewRspOk())
|
ctx.JSON(http.StatusOK, session.NewRspOk())
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (s *Staff) Pay(ctx *gin.Context) {
|
||||||
|
sess := ctx.Keys[session.ContextSession].(*session.AdminSession)
|
||||||
|
var req api.StaffPayReq
|
||||||
|
session.CheckParamError(ctx.ShouldBindJSON(&req))
|
||||||
|
ctx.Keys[session.ContextRequest] = req
|
||||||
|
service.NewStaffUser().Pay(sess, &req)
|
||||||
|
ctx.JSON(http.StatusOK, session.NewRspOk())
|
||||||
|
}
|
||||||
|
|
||||||
func (s *Staff) Update(ctx *gin.Context) {
|
func (s *Staff) Update(ctx *gin.Context) {
|
||||||
var req api.StaffUpdateReq
|
var req api.StaffUpdateReq
|
||||||
sess := ctx.Keys[session.ContextSession].(*session.AdminSession)
|
sess := ctx.Keys[session.ContextSession].(*session.AdminSession)
|
||||||
|
|
|
@ -34,10 +34,12 @@ func initRoutge(engine *gin.Engine) {
|
||||||
|
|
||||||
apiGroup.GET("/staff/salary", controller.NewSalary().List)
|
apiGroup.GET("/staff/salary", controller.NewSalary().List)
|
||||||
apiGroup.POST("/staff/salary", controller.NewSalary().Create)
|
apiGroup.POST("/staff/salary", controller.NewSalary().Create)
|
||||||
|
apiGroup.POST("/staff/salary/pay", controller.NewSalary().Pay)
|
||||||
apiGroup.PUT("/staff/salary", controller.NewSalary().Update)
|
apiGroup.PUT("/staff/salary", controller.NewSalary().Update)
|
||||||
apiGroup.DELETE("/staff/salary", controller.NewSalary().Delete)
|
apiGroup.DELETE("/staff/salary", controller.NewSalary().Delete)
|
||||||
|
|
||||||
apiGroup.GET("/staff/suggest", controller.NewStaff().Suggest)
|
apiGroup.GET("/staff/suggest", controller.NewStaff().Suggest)
|
||||||
|
apiGroup.POST("/staff/pay", controller.NewStaff().Pay)
|
||||||
apiGroup.POST("/staff", controller.NewStaff().Create)
|
apiGroup.POST("/staff", controller.NewStaff().Create)
|
||||||
apiGroup.PUT("/staff", controller.NewStaff().Update)
|
apiGroup.PUT("/staff", controller.NewStaff().Update)
|
||||||
apiGroup.DELETE("/staff", controller.NewStaff().Delete)
|
apiGroup.DELETE("/staff", controller.NewStaff().Delete)
|
||||||
|
|
|
@ -6,7 +6,6 @@ import (
|
||||||
"enterprise/common/dao"
|
"enterprise/common/dao"
|
||||||
"enterprise/common/global"
|
"enterprise/common/global"
|
||||||
"enterprise/common/model"
|
"enterprise/common/model"
|
||||||
"enterprise/server/api"
|
|
||||||
"enterprise/server/session"
|
"enterprise/server/session"
|
||||||
"fmt"
|
"fmt"
|
||||||
"git.u8t.cn/open/gosdk/qyweixin"
|
"git.u8t.cn/open/gosdk/qyweixin"
|
||||||
|
@ -58,52 +57,48 @@ func (p *Pay) AlipayAuth(sess *session.AdminSession, authCode, state string) (st
|
||||||
return res.UserId, staffUser
|
return res.UserId, staffUser
|
||||||
}
|
}
|
||||||
|
|
||||||
func (p *Pay) Pay(corp *model.Corp, req *api.PayReq) {
|
func (p *Pay) Pay(corp *model.Corp, user *model.StaffUser, title, payType string, amount int64) {
|
||||||
|
var err error
|
||||||
user, err := dao.NewStaffUserDao().GetByUsername(corp.Id, req.Username)
|
realPayType := ""
|
||||||
session.CheckDBError(err)
|
|
||||||
session.CheckNilError(user, fmt.Sprintf("用户[%s]不存在", req.Username))
|
|
||||||
|
|
||||||
payType := ""
|
|
||||||
payee := user.GetPayee()
|
payee := user.GetPayee()
|
||||||
if req.PayType == "alipay" {
|
if payType == "alipay" {
|
||||||
if payee.AlipayUid == "" {
|
if payee.AlipayUid == "" {
|
||||||
panic("请绑定支付宝账号")
|
panic("请绑定支付宝账号")
|
||||||
}
|
}
|
||||||
err = p.payAlipay(corp, user, req)
|
err = p.payAlipay(corp, user, title, amount)
|
||||||
payType = "alipay"
|
realPayType = "alipay"
|
||||||
} else {
|
} else {
|
||||||
err = p.payWeixin(corp, user, req)
|
err = p.payWeixin(corp, user, title, amount)
|
||||||
payType = "weixin"
|
realPayType = "weixin"
|
||||||
}
|
}
|
||||||
|
|
||||||
message := make([]string, 0)
|
message := make([]string, 0)
|
||||||
message = append(message, fmt.Sprintf("【企业转账】[%s]", req.Username))
|
message = append(message, fmt.Sprintf("【企业转账】[%s]", user.Username))
|
||||||
message = append(message, fmt.Sprintf("发放金额:%s", goutil.FormatMoney(req.Amount)))
|
message = append(message, fmt.Sprintf("发放金额:%s", goutil.FormatMoney(amount)))
|
||||||
message = append(message, fmt.Sprintf("支付类型:%s", payType))
|
message = append(message, fmt.Sprintf("支付类型:%s", realPayType))
|
||||||
message = append(message, fmt.Sprintf("员工名称:%s", req.Username))
|
message = append(message, fmt.Sprintf("员工名称:%s", user.Username))
|
||||||
message = append(message, fmt.Sprintf("费用说明:%s", req.Title))
|
message = append(message, fmt.Sprintf("费用说明:%s", title))
|
||||||
if err != nil {
|
if err != nil {
|
||||||
message = append(message, fmt.Sprintf("错误信息:%s", err.Error()))
|
message = append(message, fmt.Sprintf("错误信息:%s", err.Error()))
|
||||||
global.SendMessage([]string{"jiangyong"}, strings.Join(message, "\n"))
|
global.SendMessage([]string{"jiangyong"}, strings.Join(message, "\n"))
|
||||||
log.Errorf("pay req[%s] error :%s", goutil.EncodeJSON(req), err.Error())
|
log.Errorf("pay req[%s:%d] error :%s", title, amount, err.Error())
|
||||||
panic(config.ErrInternal.New().Append(err))
|
panic(config.ErrInternal.New().Append(err))
|
||||||
}
|
}
|
||||||
|
|
||||||
global.SendMessage([]string{"jiangyong"}, strings.Join(message, "\n"))
|
global.SendMessage([]string{"jiangyong"}, strings.Join(message, "\n"))
|
||||||
}
|
}
|
||||||
|
|
||||||
func (p *Pay) payAlipay(corp *model.Corp, user *model.StaffUser, req *api.PayReq) error {
|
func (p *Pay) payAlipay(corp *model.Corp, user *model.StaffUser, title string, amount int64) error {
|
||||||
corpConfig := corp.GetConfig()
|
corpConfig := corp.GetConfig()
|
||||||
userPayee := user.GetPayee()
|
userPayee := user.GetPayee()
|
||||||
cli := config.GetAliPayClient(goutil.If(corpConfig.PayChannel != "", corpConfig.PayChannel, "batiao"))
|
cli := config.GetAliPayClient(goutil.If(corpConfig.PayChannel != "", corpConfig.PayChannel, "batiao"))
|
||||||
var payReq alipay.FundTransUniTransfer
|
var payReq alipay.FundTransUniTransfer
|
||||||
payReq.Remark = req.Title
|
payReq.Remark = title
|
||||||
payReq.OutBizNo = cast.ToString(goutil.GetBigID(0, 0))
|
payReq.OutBizNo = cast.ToString(goutil.GetBigID(0, 0))
|
||||||
payReq.TransAmount = goutil.FormatMoney(req.Amount)
|
payReq.TransAmount = goutil.FormatMoney(amount)
|
||||||
payReq.ProductCode = "TRANS_ACCOUNT_NO_PWD"
|
payReq.ProductCode = "TRANS_ACCOUNT_NO_PWD"
|
||||||
payReq.BizScene = "DIRECT_TRANSFER"
|
payReq.BizScene = "DIRECT_TRANSFER"
|
||||||
payReq.OrderTitle = req.Title
|
payReq.OrderTitle = title
|
||||||
payee := new(alipay.PayeeInfo)
|
payee := new(alipay.PayeeInfo)
|
||||||
payReq.PayeeInfo = payee
|
payReq.PayeeInfo = payee
|
||||||
payee.IdentityType = "ALIPAY_USER_ID"
|
payee.IdentityType = "ALIPAY_USER_ID"
|
||||||
|
@ -120,7 +115,7 @@ func (p *Pay) payAlipay(corp *model.Corp, user *model.StaffUser, req *api.PayReq
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func (p *Pay) payWeixin(corp *model.Corp, user *model.StaffUser, req *api.PayReq) error {
|
func (p *Pay) payWeixin(corp *model.Corp, user *model.StaffUser, title string, amount int64) error {
|
||||||
|
|
||||||
cfg := corp.GetConfig()
|
cfg := corp.GetConfig()
|
||||||
|
|
||||||
|
@ -130,18 +125,18 @@ func (p *Pay) payWeixin(corp *model.Corp, user *model.StaffUser, req *api.PayReq
|
||||||
Secret: cfg.EnterpriseSecret,
|
Secret: cfg.EnterpriseSecret,
|
||||||
Agent: cfg.EnterpriseAgent,
|
Agent: cfg.EnterpriseAgent,
|
||||||
})
|
})
|
||||||
openid, err := approve.GetOpenid(req.Username)
|
openid, err := approve.GetOpenid(user.Username)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.Errorf("GetOpenid[%s] error :%s ", req.Username, err.Error())
|
log.Errorf("GetOpenid[%s] error :%s ", user.Username, err.Error())
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
// 支付费用
|
// 支付费用
|
||||||
var payReq qyweixin.PayReq
|
var payReq qyweixin.PayReq
|
||||||
payReq.BillNo = cast.ToString(goutil.GetBigID(0, 0))
|
payReq.BillNo = cast.ToString(goutil.GetBigID(0, 0))
|
||||||
payReq.Title = req.Title
|
payReq.Title = title
|
||||||
payReq.Openid = openid
|
payReq.Openid = openid
|
||||||
payReq.TotalAmount = req.Amount
|
payReq.TotalAmount = amount
|
||||||
qyPay := qyweixin.NewAppPay(&qyweixin.PayConfig{
|
qyPay := qyweixin.NewAppPay(&qyweixin.PayConfig{
|
||||||
Corpid: cfg.CorpId,
|
Corpid: cfg.CorpId,
|
||||||
Secret: cfg.PaySecret,
|
Secret: cfg.PaySecret,
|
||||||
|
@ -154,7 +149,7 @@ func (p *Pay) payWeixin(corp *model.Corp, user *model.StaffUser, req *api.PayReq
|
||||||
})
|
})
|
||||||
|
|
||||||
if err = qyPay.PayMoney(&payReq); err != nil {
|
if err = qyPay.PayMoney(&payReq); err != nil {
|
||||||
log.Errorf("pay req[%s] error :%s", goutil.EncodeJSON(req), err.Error())
|
log.Errorf("pay req[%s:%d] error :%s", title, amount, err.Error())
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
return nil
|
return nil
|
||||||
|
|
|
@ -11,6 +11,7 @@ import (
|
||||||
"fmt"
|
"fmt"
|
||||||
"github.com/gin-gonic/gin"
|
"github.com/gin-gonic/gin"
|
||||||
log "github.com/sirupsen/logrus"
|
log "github.com/sirupsen/logrus"
|
||||||
|
"github.com/smbrave/goutil"
|
||||||
"github.com/spf13/cast"
|
"github.com/spf13/cast"
|
||||||
excelize "github.com/xuri/excelize/v2"
|
excelize "github.com/xuri/excelize/v2"
|
||||||
"os"
|
"os"
|
||||||
|
@ -123,6 +124,33 @@ func (s *StaffSalary) Update(sess *session.AdminSession, req *api.UpdateSalaryRe
|
||||||
session.CheckDBError(err)
|
session.CheckDBError(err)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (s *StaffSalary) Pay(sess *session.AdminSession, req *api.PaySalaryReq) {
|
||||||
|
|
||||||
|
salary, err := dao.NewStaffSalaryDao().Get(cast.ToInt64(req.SalaryId))
|
||||||
|
session.CheckDBError(err)
|
||||||
|
session.CheckNilError(salary, "工资单")
|
||||||
|
if salary.Status == model.StaffSalaryStatusPayed {
|
||||||
|
panic("工资单已支付")
|
||||||
|
}
|
||||||
|
|
||||||
|
corp, err := dao.NewCorpDao().Get(sess.GetCorpId())
|
||||||
|
session.CheckDBError(err)
|
||||||
|
session.CheckNilError(corp, "企业不存在")
|
||||||
|
|
||||||
|
user, err := dao.NewStaffUserDao().Get(salary.UserId)
|
||||||
|
session.CheckDBError(err)
|
||||||
|
session.CheckNilError(user, "用户不存在")
|
||||||
|
|
||||||
|
title := fmt.Sprintf("%s工资", salary.Month)
|
||||||
|
|
||||||
|
log.Errorf("title[%s] stalary:%s req:%s", title, goutil.EncodeJSON(salary), goutil.EncodeJSON(req))
|
||||||
|
salary.Status = model.StaffSalaryStatusPayed
|
||||||
|
dao.NewStaffSalaryDao().Update(salary)
|
||||||
|
|
||||||
|
return
|
||||||
|
//NewPay().Pay(corp, user, title, req.PayType, int64(salary.GetRealSalary()*100))
|
||||||
|
}
|
||||||
|
|
||||||
func (s *StaffSalary) Agent(cid int64, month string, ctx *gin.Context) {
|
func (s *StaffSalary) Agent(cid int64, month string, ctx *gin.Context) {
|
||||||
xls := ctx.Query("xls")
|
xls := ctx.Query("xls")
|
||||||
staffSalarys, err := dao.NewStaffSalaryDao().QueryAll(cid, month)
|
staffSalarys, err := dao.NewStaffSalaryDao().QueryAll(cid, month)
|
||||||
|
|
|
@ -189,6 +189,21 @@ func (s *StaffUser) Update(sess *session.AdminSession, req *api.StaffUpdateReq)
|
||||||
session.CheckDBError(err)
|
session.CheckDBError(err)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (s *StaffUser) Pay(sess *session.AdminSession, req *api.StaffPayReq) {
|
||||||
|
corp, err := dao.NewCorpDao().Get(sess.GetCorpId())
|
||||||
|
session.CheckDBError(err)
|
||||||
|
session.CheckNilError(corp, "企业不存在")
|
||||||
|
|
||||||
|
var payReq api.PayReq
|
||||||
|
payReq.Title = req.Title
|
||||||
|
payReq.Amount = cast.ToInt64(req.Amount)
|
||||||
|
|
||||||
|
user, err := dao.NewStaffUserDao().Get(cast.ToInt64(req.StaffId))
|
||||||
|
session.CheckDBError(err)
|
||||||
|
session.CheckNilError(user, "用户不存在")
|
||||||
|
NewPay().Pay(corp, user, req.Title, req.PayType, cast.ToInt64(req.Amount))
|
||||||
|
}
|
||||||
|
|
||||||
func (s *StaffUser) getHrAssiant(corpId int64) *qyweixin.AppHr {
|
func (s *StaffUser) getHrAssiant(corpId int64) *qyweixin.AppHr {
|
||||||
corp, err := dao.NewCorpDao().Get(corpId)
|
corp, err := dao.NewCorpDao().Get(corpId)
|
||||||
session.CheckDBError(err)
|
session.CheckDBError(err)
|
||||||
|
|
Loading…
Reference in New Issue