payment
This commit is contained in:
parent
3604d3a237
commit
04baf5046d
|
@ -2,7 +2,9 @@ package dao
|
|||
|
||||
import (
|
||||
"enterprise/common/model"
|
||||
"fmt"
|
||||
"gorm.io/gorm"
|
||||
"sort"
|
||||
"time"
|
||||
)
|
||||
|
||||
|
@ -77,3 +79,56 @@ func (d *ApprovalPaymentDao) GetByUsername(username, month string) ([]*model.App
|
|||
}
|
||||
return u, nil
|
||||
}
|
||||
|
||||
func (d *ApprovalPaymentDao) Query(page, size int, corpId int64, username, startDay, endDay, payer, payee string) ([]*model.ApprovalPayment, int64, error) {
|
||||
var u []*model.ApprovalPayment
|
||||
tx := GetDB().Table(d.TableName())
|
||||
|
||||
tx.Where("corp_id = ?", corpId)
|
||||
|
||||
if username != "" {
|
||||
tx.Where("username = ?", username)
|
||||
}
|
||||
if startDay != "" {
|
||||
tx.Where("payment_date >= ?", startDay)
|
||||
}
|
||||
if endDay != "" {
|
||||
tx.Where("payment_date <= ?", endDay)
|
||||
}
|
||||
if payer != "" {
|
||||
tx.Where("payment_pyer <= ?", payer)
|
||||
}
|
||||
if payee != "" {
|
||||
tx.Where("payment_pyee <= ?", payee)
|
||||
}
|
||||
|
||||
var count int64
|
||||
tx.Count(&count)
|
||||
|
||||
tx.Offset((page - 1) * size).Limit(size)
|
||||
res := tx.Find(&u)
|
||||
if res.Error != nil {
|
||||
return nil, 0, res.Error
|
||||
}
|
||||
return u, count, nil
|
||||
}
|
||||
|
||||
func (d *ApprovalPaymentDao) Count(corpId int64, startDay, endDay string, field string) ([]*CountValue, error) {
|
||||
var u []*CountValue
|
||||
tx := GetDB().Table(d.TableName())
|
||||
tx.Where("corp_id = ?", corpId)
|
||||
if startDay != "" {
|
||||
tx.Where("payment_date >= ?", startDay)
|
||||
}
|
||||
if endDay != "" {
|
||||
tx.Where("payment_date <= ?", endDay)
|
||||
}
|
||||
tx.Select(fmt.Sprintf("%s AS `key`,COUNT(1)", field))
|
||||
tx.Group(field)
|
||||
res := tx.Find(&u)
|
||||
if res.Error != nil {
|
||||
return nil, res.Error
|
||||
}
|
||||
sort.Sort(SortCountValue(u))
|
||||
return u, nil
|
||||
}
|
||||
|
|
|
@ -8,6 +8,30 @@ var (
|
|||
corpDB *gorm.DB
|
||||
)
|
||||
|
||||
type CountValue struct {
|
||||
Key string `json:"key"`
|
||||
Name string `json:"name"`
|
||||
Value int64 `json:"value"`
|
||||
}
|
||||
|
||||
type SortCountValue []*CountValue
|
||||
|
||||
func (a SortCountValue) Len() int {
|
||||
return len(a)
|
||||
}
|
||||
|
||||
func (a SortCountValue) len() int {
|
||||
return len(a)
|
||||
}
|
||||
|
||||
func (a SortCountValue) Swap(i, j int) {
|
||||
a[i], a[j] = a[j], a[i]
|
||||
}
|
||||
|
||||
func (a SortCountValue) Less(i, j int) bool {
|
||||
return a[i].Value > a[j].Value
|
||||
}
|
||||
|
||||
func SetDB(d *gorm.DB) {
|
||||
db = d
|
||||
}
|
||||
|
|
|
@ -0,0 +1,41 @@
|
|||
package api
|
||||
|
||||
import (
|
||||
"enterprise/common/model"
|
||||
"github.com/smbrave/goutil"
|
||||
"github.com/spf13/cast"
|
||||
)
|
||||
|
||||
type Payment struct {
|
||||
Id string `json:"id"`
|
||||
Username string `json:"username" `
|
||||
SpNo string `json:"sp_no"`
|
||||
ApplyTime string `json:"apply_time"`
|
||||
CostSubject string `json:"cost_subject"`
|
||||
PaymentType string `json:"payment_type"`
|
||||
PaymentDate string `json:"payment_date"`
|
||||
PaymentAmount string `json:"payment_amount"`
|
||||
PaymentRemark string `json:"payment_remark"`
|
||||
PaymentPayer string `json:"payment_payer"`
|
||||
PaymentPayee string `json:"payment_payee"`
|
||||
CreateTime string `json:"create_time"`
|
||||
UpdateTime string `json:"update_time"`
|
||||
}
|
||||
|
||||
type ListPaymentReq struct {
|
||||
BaseRequest
|
||||
StartDay string `from:"start_day"`
|
||||
EndDay string `from:"end_day"`
|
||||
Username string `from:"username"`
|
||||
Payer string `from:"payer"`
|
||||
Payee string `from:"payee"`
|
||||
}
|
||||
|
||||
func (p *Payment) From(m *model.ApprovalPayment) {
|
||||
goutil.CopyStruct(p, m)
|
||||
p.Id = cast.ToString(m.Id)
|
||||
p.CreateTime = goutil.TimeToDateTime(m.CreateTime)
|
||||
p.UpdateTime = goutil.TimeToDateTime(m.UpdateTime)
|
||||
p.PaymentAmount = cast.ToString(m.PaymentAmount)
|
||||
|
||||
}
|
|
@ -1,35 +0,0 @@
|
|||
package controller
|
||||
|
||||
import (
|
||||
"enterprise/common/config"
|
||||
"enterprise/common/dao"
|
||||
"enterprise/server/api"
|
||||
"enterprise/server/service"
|
||||
"enterprise/server/session"
|
||||
"github.com/gin-gonic/gin"
|
||||
"net/http"
|
||||
)
|
||||
|
||||
type Pay struct {
|
||||
}
|
||||
|
||||
func NewPay() *Pay {
|
||||
return &Pay{}
|
||||
}
|
||||
func (q *Pay) Pay(ctx *gin.Context) {
|
||||
sess := ctx.Keys[session.ContextSession].(*session.AdminSession)
|
||||
corp, err := dao.NewCorpDao().GetByHost(sess.GetHeader().Host)
|
||||
session.CheckDBError(err)
|
||||
session.CheckNilError(corp, "域名未绑定")
|
||||
|
||||
var req api.PayReq
|
||||
session.CheckParamError(ctx.ShouldBindJSON(&req))
|
||||
ctx.Keys[session.ContextRequest] = req
|
||||
|
||||
if req.Password != corp.GetConfig().Password {
|
||||
panic(config.ErrParam.New().Append("密码错误"))
|
||||
}
|
||||
|
||||
service.NewPay().Pay(corp, &req)
|
||||
ctx.JSON(http.StatusOK, session.NewRspOk())
|
||||
}
|
|
@ -0,0 +1,53 @@
|
|||
package controller
|
||||
|
||||
import (
|
||||
"enterprise/common/config"
|
||||
"enterprise/common/dao"
|
||||
"enterprise/server/api"
|
||||
"enterprise/server/service"
|
||||
"enterprise/server/session"
|
||||
"github.com/gin-gonic/gin"
|
||||
"net/http"
|
||||
)
|
||||
|
||||
type Payment struct {
|
||||
}
|
||||
|
||||
func NewPayment() *Payment {
|
||||
return &Payment{}
|
||||
}
|
||||
func (q *Payment) Pay(ctx *gin.Context) {
|
||||
sess := ctx.Keys[session.ContextSession].(*session.AdminSession)
|
||||
corp, err := dao.NewCorpDao().GetByHost(sess.GetHeader().Host)
|
||||
session.CheckDBError(err)
|
||||
session.CheckNilError(corp, "域名未绑定")
|
||||
|
||||
var req api.PayReq
|
||||
session.CheckParamError(ctx.ShouldBindJSON(&req))
|
||||
ctx.Keys[session.ContextRequest] = req
|
||||
|
||||
if req.Password != corp.GetConfig().Password {
|
||||
panic(config.ErrParam.New().Append("密码错误"))
|
||||
}
|
||||
|
||||
service.NewPay().Pay(corp, &req)
|
||||
ctx.JSON(http.StatusOK, session.NewRspOk())
|
||||
}
|
||||
|
||||
func (q *Payment) List(ctx *gin.Context) {
|
||||
sess := ctx.Keys[session.ContextSession].(*session.AdminSession)
|
||||
var req api.ListPaymentReq
|
||||
session.CheckParamError(ctx.ShouldBind(&req))
|
||||
req.Default()
|
||||
ctx.Keys[session.ContextRequest] = req
|
||||
total, totalAmount, items := service.NewPayment().List(sess, &req)
|
||||
ctx.JSON(http.StatusOK, session.NewListAmountRsp(total, totalAmount, items))
|
||||
}
|
||||
|
||||
func (q *Payment) Suggest(ctx *gin.Context) {
|
||||
sess := ctx.Keys[session.ContextSession].(*session.AdminSession)
|
||||
field := ctx.Query("field")
|
||||
|
||||
data := service.NewPayment().Suggest(sess, field)
|
||||
ctx.JSON(http.StatusOK, session.NewRsp(data))
|
||||
}
|
|
@ -16,7 +16,10 @@ func initRoutge(engine *gin.Engine) {
|
|||
apiGroup.Use(base.Recovery).Use(base.Before).Use(base.Token)
|
||||
noTokenGroup.Use(base.Recovery).Use(base.Before)
|
||||
|
||||
noTokenGroup.POST("/pay", controller.NewPay().Pay)
|
||||
noTokenGroup.POST("/pay", controller.NewPayment().Pay)
|
||||
noTokenGroup.POST("/payment", controller.NewPayment().Pay)
|
||||
apiGroup.GET("/payment", controller.NewPayment().List)
|
||||
apiGroup.GET("/payment/suggest", controller.NewPayment().Suggest)
|
||||
noTokenGroup.Any("/qyweixin/approve/:cid", controller.NewQyWeixin().Approve)
|
||||
noTokenGroup.Any("/qyweixin/handle/refund", controller.NewQyWeixin().HandleRefund)
|
||||
|
||||
|
|
|
@ -0,0 +1,35 @@
|
|||
package service
|
||||
|
||||
import (
|
||||
"enterprise/common/dao"
|
||||
"enterprise/server/api"
|
||||
"enterprise/server/session"
|
||||
"time"
|
||||
)
|
||||
|
||||
type Payment struct {
|
||||
}
|
||||
|
||||
func NewPayment() *Payment {
|
||||
return &Payment{}
|
||||
}
|
||||
|
||||
func (p *Payment) List(sess *session.AdminSession, req *api.ListPaymentReq) (int64, int64, interface{}) {
|
||||
payments, total, err := dao.NewApprovalPaymentDao().Query(req.Page, req.Size, sess.GetCorpId(), req.Username, req.StartDay, req.EndDay, req.Payee, req.Payee)
|
||||
session.CheckDBError(err)
|
||||
items := make([]*api.Payment, 0)
|
||||
for _, payment := range payments {
|
||||
i := new(api.Payment)
|
||||
i.From(payment)
|
||||
items = append(items, i)
|
||||
}
|
||||
return total, 1000, items
|
||||
}
|
||||
|
||||
func (p *Payment) Suggest(sess *session.AdminSession, field string) interface{} {
|
||||
|
||||
counts, err := dao.NewApprovalPaymentDao().Count(sess.GetCorpId(),
|
||||
time.Now().AddDate(-1, 0, 0).Format("2006-01-02"), "", field)
|
||||
session.CheckDBError(err)
|
||||
return counts
|
||||
}
|
Loading…
Reference in New Issue