340 lines
11 KiB
Go
340 lines
11 KiB
Go
|
package authPayment
|
|||
|
|
|||
|
import (
|
|||
|
"context"
|
|||
|
"fmt"
|
|||
|
artShow "github.com/fonchain_enterprise/fonchain-main/api/artShow"
|
|||
|
"github.com/fonchain_enterprise/fonchain-main/api/artistInfoUser"
|
|||
|
"github.com/fonchain_enterprise/fonchain-main/pkg/e"
|
|||
|
"github.com/fonchain_enterprise/fonchain-main/pkg/middleware"
|
|||
|
"github.com/fonchain_enterprise/fonchain-main/pkg/service"
|
|||
|
"github.com/fonchain_enterprise/fonchain-main/pkg/service/artistInfo/asPush"
|
|||
|
"github.com/fonchain_enterprise/fonchain-main/pkg/service/artistInfo/asUser"
|
|||
|
"github.com/fonchain_enterprise/fonchain-main/pkg/service/artistInfo/asUtil"
|
|||
|
"github.com/fonchain_enterprise/fonchain-main/pkg/utils/stime"
|
|||
|
"github.com/gin-gonic/gin"
|
|||
|
"time"
|
|||
|
)
|
|||
|
|
|||
|
var Handler = &AuthPaymentHandler{}
|
|||
|
|
|||
|
type AuthPaymentHandler struct {
|
|||
|
}
|
|||
|
|
|||
|
// 创建AuthPayment
|
|||
|
func (a *AuthPaymentHandler) CreateAuthPayment(c *gin.Context) {
|
|||
|
var req artShow.AuthPaymentData
|
|||
|
if err := c.ShouldBindJSON(&req); err != nil {
|
|||
|
service.Error(c, e.InvalidParams, err, "无效参数")
|
|||
|
return
|
|||
|
}
|
|||
|
_, err := service.GrpcArtShowImpl.CreateAuthPayment(c, &req)
|
|||
|
if err != nil {
|
|||
|
service.ErrorWithMark(c, e.Failed, err, "GrpcArtShowImpl.CreateAuthPayment Err", "创建失败")
|
|||
|
return
|
|||
|
}
|
|||
|
service.Success(c)
|
|||
|
}
|
|||
|
|
|||
|
// 删除AuthPayment
|
|||
|
func (a *AuthPaymentHandler) DeleteAuthPayment(c *gin.Context) {
|
|||
|
c.Set(middleware.OperationTarget, "删除支付记录")
|
|||
|
c.Set(middleware.OperationAction, "DELETE")
|
|||
|
c.Set(middleware.OperationModule, "画家付款")
|
|||
|
var req artShow.DeleteAuthPaymentRequest
|
|||
|
if err := c.ShouldBindJSON(&req); err != nil {
|
|||
|
service.Error(c, e.InvalidParams, err, "无效参数")
|
|||
|
return
|
|||
|
}
|
|||
|
//先更新操作人员
|
|||
|
var ids []int64
|
|||
|
if req.Id > 0 {
|
|||
|
ids = append(ids, req.Id)
|
|||
|
}
|
|||
|
if len(req.Ids) > 0 {
|
|||
|
ids = append(ids, req.Ids...)
|
|||
|
}
|
|||
|
for _, id := range ids {
|
|||
|
var updateReq = artShow.AuthPaymentData{ID: id}
|
|||
|
jwt, err := asUser.GetJwtInfo(c)
|
|||
|
if err == nil && jwt != nil {
|
|||
|
updateReq.UpdaterName = jwt.NickName
|
|||
|
}
|
|||
|
updateReq.UpdaterOptTime = stime.Currentime(stime.Format_Normal_YMDhms)
|
|||
|
_, err = service.GrpcArtShowImpl.UpdateAuthPayment(c, &updateReq)
|
|||
|
if err != nil {
|
|||
|
service.ErrorWithMark(c, e.Failed, err, "GrpcArtShowImpl.UpdateAuthPayment Err", "更新失败")
|
|||
|
return
|
|||
|
}
|
|||
|
}
|
|||
|
//再执行删除
|
|||
|
_, err := service.GrpcArtShowImpl.DeleteAuthPayment(c, &req)
|
|||
|
if err != nil {
|
|||
|
service.ErrorWithMark(c, e.Failed, err, "DeleteAuthPayment Err", "删除失败")
|
|||
|
return
|
|||
|
}
|
|||
|
service.Success(c)
|
|||
|
}
|
|||
|
|
|||
|
// 更新AuthPayment
|
|||
|
func (a *AuthPaymentHandler) UpdateAuthPayment(c *gin.Context) {
|
|||
|
c.Set(middleware.OperationTarget, "更新支付记录")
|
|||
|
c.Set(middleware.OperationAction, "UPDATE")
|
|||
|
c.Set(middleware.OperationModule, "画家付款")
|
|||
|
var req UpdateAuthPaymentDataReq
|
|||
|
if err := c.ShouldBindJSON(&req); err != nil {
|
|||
|
service.Error(c, e.InvalidParams, err, "无效参数")
|
|||
|
return
|
|||
|
}
|
|||
|
if err := req.Validate(); err != nil {
|
|||
|
service.Error(c, e.InvalidParams, err)
|
|||
|
return
|
|||
|
}
|
|||
|
protoReq := artShow.AuthPaymentData{
|
|||
|
ID: req.ID,
|
|||
|
ExpenseType: req.ExpenseType,
|
|||
|
PayType: req.PayType,
|
|||
|
Remark: req.Remark,
|
|||
|
FinalPrice: req.finalPricceF,
|
|||
|
}
|
|||
|
jwt, err := asUser.GetJwtInfo(c)
|
|||
|
if err == nil && jwt != nil {
|
|||
|
protoReq.UpdaterName = jwt.NickName
|
|||
|
}
|
|||
|
protoReq.UpdaterOptTime = stime.Currentime(stime.Format_Normal_YMDhms)
|
|||
|
_, err = service.GrpcArtShowImpl.UpdateAuthPayment(c, &protoReq)
|
|||
|
if err != nil {
|
|||
|
service.Error(c, e.Failed, err)
|
|||
|
return
|
|||
|
}
|
|||
|
service.Success(c)
|
|||
|
}
|
|||
|
|
|||
|
// 使用id查询AuthPayment
|
|||
|
func (a *AuthPaymentHandler) GetAuthPaymentDetail(c *gin.Context) {
|
|||
|
var req artShow.GetAuthPaymentByIdRequest
|
|||
|
if err := c.ShouldBindJSON(&req); err != nil {
|
|||
|
service.Error(c, e.InvalidParams, err, "无效参数")
|
|||
|
return
|
|||
|
}
|
|||
|
resp, err := service.GrpcArtShowImpl.GetAuthPaymentDetail(c, &req)
|
|||
|
if err != nil {
|
|||
|
service.ErrorWithMark(c, e.Failed, err, "GrpcArtShowImpl.GetAuthPaymentDetail Err", "查询失败")
|
|||
|
return
|
|||
|
}
|
|||
|
service.Success(c, resp)
|
|||
|
}
|
|||
|
|
|||
|
// 批量查询AuthPayment
|
|||
|
func (a *AuthPaymentHandler) GetAuthPaymentList(c *gin.Context) {
|
|||
|
var req GetAuthPaymentListRequest
|
|||
|
if err := c.ShouldBindJSON(&req); err != nil {
|
|||
|
service.Error(c, e.InvalidParams, err, "无效参数")
|
|||
|
return
|
|||
|
}
|
|||
|
var protoReq = artShow.GetAuthPaymentListRequest{Query: &artShow.AuthPaymentData{}}
|
|||
|
asUtil.RequestDataConvert(&req, &protoReq)
|
|||
|
resp, err := service.GrpcArtShowImpl.GetAuthPaymentList(c, &protoReq)
|
|||
|
if err != nil {
|
|||
|
service.ErrorWithMark(c, e.Failed, err, "GetAuthPaymentList Err", "查询失败")
|
|||
|
return
|
|||
|
}
|
|||
|
service.ResponseList(c, resp.List, service.OptionPage(resp.Page, resp.PageSize, resp.Total), service.OptionMsg("查询成功"))
|
|||
|
}
|
|||
|
|
|||
|
// 批量查询可发起支付的画展包列表
|
|||
|
func (a *AuthPaymentHandler) GetAuthPaymentArtShowList(c *gin.Context) {
|
|||
|
c.Set(middleware.OperationTarget, "查询可发起支付的画展包列表(二级列表)")
|
|||
|
c.Set(middleware.OperationAction, "GET")
|
|||
|
c.Set(middleware.OperationModule, "画家付款")
|
|||
|
var req = new(GetAuthPaymentArtShowListRequest)
|
|||
|
if err := c.ShouldBindJSON(&req); err != nil {
|
|||
|
service.Error(c, e.InvalidParams, err, "无效参数")
|
|||
|
return
|
|||
|
}
|
|||
|
currentPerValue := int32(GetCurrentPerValue())
|
|||
|
data, page, pageSize, total, err := getViewAuthPaymentArtShowList(req, currentPerValue)
|
|||
|
if err != nil {
|
|||
|
service.ErrorWithMark(c, e.Failed, err, "GetAuthPaymentArtShowList Err", "查询失败")
|
|||
|
return
|
|||
|
}
|
|||
|
service.ResponseQuickMsg(c, e.Ok, "查询成功", map[string]any{
|
|||
|
"list": data,
|
|||
|
"currentEditPer": currentPerValue,
|
|||
|
"page": page, "pageSize": pageSize, "total": total},
|
|||
|
)
|
|||
|
}
|
|||
|
|
|||
|
// 批量查询发起记录
|
|||
|
func (a *AuthPaymentHandler) GetViewAuthPaymentList(c *gin.Context) {
|
|||
|
c.Set(middleware.OperationTarget, "查询已发起的付款记录(二级列表)")
|
|||
|
c.Set(middleware.OperationAction, "GET")
|
|||
|
c.Set(middleware.OperationModule, "画家付款")
|
|||
|
var req GetViewAuthPaymentListRequest
|
|||
|
if err := c.ShouldBindJSON(&req); err != nil {
|
|||
|
service.Error(c, e.InvalidParams, err, "无效参数")
|
|||
|
return
|
|||
|
}
|
|||
|
data, page, pageSize, total, err := getViewAuthPaymentList(&req)
|
|||
|
if err != nil {
|
|||
|
service.ErrorWithMark(c, e.Failed, err, "GetViewAuthPaymentList Err", "查询失败")
|
|||
|
return
|
|||
|
}
|
|||
|
currentPerValue := GetCurrentPerValue() //获取页面左上角设置的比例值
|
|||
|
service.ResponseQuickMsg(c, e.Ok, "查询成功", map[string]any{
|
|||
|
"list": data,
|
|||
|
"currentEditPer": currentPerValue,
|
|||
|
"page": page, "pageSize": pageSize, "total": total},
|
|||
|
)
|
|||
|
}
|
|||
|
func (a *AuthPaymentHandler) UpdateAuthPaymentPercent(c *gin.Context) {
|
|||
|
c.Set(middleware.OperationTarget, "更新比例")
|
|||
|
c.Set(middleware.OperationAction, "UPDATE")
|
|||
|
c.Set(middleware.OperationModule, "画家付款")
|
|||
|
var req UpdateAuthPaymentPercentReq
|
|||
|
if err := c.ShouldBindJSON(&req); err != nil {
|
|||
|
service.Error(c, e.InvalidParams, err, "无效参数")
|
|||
|
return
|
|||
|
}
|
|||
|
if req.CurrentEditPer == 0 {
|
|||
|
service.Error(c, e.InvalidParams, nil, "数值不可为0")
|
|||
|
return
|
|||
|
}
|
|||
|
|
|||
|
//将传过来的比例设置为当前的默认值
|
|||
|
SetCurrentPerValue(int(req.CurrentEditPer))
|
|||
|
//转为proto请求参数
|
|||
|
protoReq := artShow.UpdateAuthPaymentPercentReq{
|
|||
|
Per: req.CurrentEditPer,
|
|||
|
}
|
|||
|
_, err := service.GrpcArtShowImpl.UpdateAuthPaymentPercent(c, &protoReq)
|
|||
|
if err != nil {
|
|||
|
service.ErrorWithMark(c, e.Failed, err, "UpdateAuthPaymentPercent Err", "查询失败")
|
|||
|
return
|
|||
|
}
|
|||
|
service.Success(c)
|
|||
|
}
|
|||
|
|
|||
|
func (a *AuthPaymentHandler) CreateAuthPaymentSend(c *gin.Context) {
|
|||
|
c.Set(middleware.OperationTarget, "发起支付")
|
|||
|
c.Set(middleware.OperationAction, "CREATE")
|
|||
|
c.Set(middleware.OperationModule, "画家付款")
|
|||
|
var req UpdateAuthPaymentHasSendReq
|
|||
|
if err := c.ShouldBindJSON(&req); err != nil {
|
|||
|
service.Error(c, e.InvalidParams, err, "无效参数")
|
|||
|
return
|
|||
|
}
|
|||
|
if err := req.Validate(); err != nil {
|
|||
|
service.Error(c, e.InvalidParams, err)
|
|||
|
return
|
|||
|
}
|
|||
|
//校验画展包是否可以发起支付
|
|||
|
showData, err := service.GrpcArtShowImpl.GetArtShowData(c, &artShow.GetArtShowRequest{ShowUid: req.ShowUid})
|
|||
|
if err != nil {
|
|||
|
service.Error(c, e.Failed, err, "画展包信息查询失败,操作取消")
|
|||
|
return
|
|||
|
}
|
|||
|
// 徐嘉鸿说底价不确认也可以发起
|
|||
|
//if showData.IsConfirm != 2 {
|
|||
|
// service.Error(c, e.Failed, nil, "操作失败,最终金额未补全")
|
|||
|
// return
|
|||
|
//}
|
|||
|
|
|||
|
//更新数据为已发起
|
|||
|
var senderName string
|
|||
|
jwt, err := asUser.GetJwtInfo(c)
|
|||
|
if err == nil && jwt != nil {
|
|||
|
senderName = jwt.NickName
|
|||
|
}
|
|||
|
if showData.Per == 0 {
|
|||
|
showData.Per = int32(GetCurrentPerValue())
|
|||
|
//finalPrice := float32(math.Round(float64(showData.Price)*float64(per)) / 100)
|
|||
|
}
|
|||
|
if req.FinalPrice == "" {
|
|||
|
service.Error(c, e.InvalidParams, nil, "finalPrice不能为空")
|
|||
|
return
|
|||
|
}
|
|||
|
_, err = service.GrpcArtShowImpl.CreateAuthPayment(c, &artShow.AuthPaymentData{
|
|||
|
ShowUid: req.ShowUid,
|
|||
|
SenderName: senderName,
|
|||
|
Per: showData.Per,
|
|||
|
SendTime: time.Now().Format(stime.Format_Normal_YMDhms),
|
|||
|
FinalPrice: req.finalPricceF,
|
|||
|
ExpenseType: req.ExpenseType,
|
|||
|
Remark: req.Remark,
|
|||
|
})
|
|||
|
//_, err = service.GrpcArtShowImpl.UpdateAuthPayment(c, &artShow.AuthPaymentData{ShowUid: req.ShowUid, HasSend: 2, SendTime: time.Now().Format(stime.Format_Normal_YMDhms), SenderName: senderName})
|
|||
|
if err != nil {
|
|||
|
service.ErrorWithMark(c, e.Failed, err, "CreateAuthPayment Err", err.Error())
|
|||
|
return
|
|||
|
}
|
|||
|
go func() {
|
|||
|
//推送消息
|
|||
|
userRes, errs := service.GrpcArtistInfoUserImpl.GetUserList(context.Background(), &artistInfoUser.GetUserListRequest{Query: &artistInfoUser.UserData{MgmtArtistUid: showData.ArtistUID}})
|
|||
|
if errs != nil {
|
|||
|
fmt.Println("待支付app推送发送失败,用户信息查询失败", errs)
|
|||
|
return
|
|||
|
}
|
|||
|
if len(userRes.List) > 0 {
|
|||
|
errs = asPush.NewPusher().AuthpaymentWaitToBePaidNotice(userRes.List[0].ID)
|
|||
|
if errs != nil {
|
|||
|
fmt.Println("待支付app推送发送失败", errs)
|
|||
|
|
|||
|
}
|
|||
|
}
|
|||
|
}()
|
|||
|
service.Success(c)
|
|||
|
}
|
|||
|
|
|||
|
func (a *AuthPaymentHandler) GetAuthPaymentStat(c *gin.Context) {
|
|||
|
c.Set(middleware.OperationTarget, "查询支付统计数据")
|
|||
|
c.Set(middleware.OperationAction, "GET")
|
|||
|
c.Set(middleware.OperationModule, "画家付款")
|
|||
|
var req GetViewAuthPaymentListRequest
|
|||
|
if err := c.ShouldBindJSON(&req); err != nil {
|
|||
|
service.Error(c, e.InvalidParams, err, "无效参数")
|
|||
|
return
|
|||
|
}
|
|||
|
req.Page = 1
|
|||
|
req.PageSize = -1
|
|||
|
var (
|
|||
|
data []*artShow.ViewAuthPaymentData
|
|||
|
total int64
|
|||
|
err error
|
|||
|
)
|
|||
|
data, _, _, total, err = getViewAuthPaymentList(&req)
|
|||
|
if err != nil {
|
|||
|
service.ErrorWithMark(c, e.Failed, err, "GetViewAuthPaymentList Err", "查询失败")
|
|||
|
return
|
|||
|
}
|
|||
|
if total == 0 {
|
|||
|
resp := artShow.GetAuthPaymentStatResp{
|
|||
|
PriceTotal: "0",
|
|||
|
PriceNotSendTotal: "0",
|
|||
|
PriceHasSendTotal: "0",
|
|||
|
PricePayNotTotal: "0",
|
|||
|
PricePayTotal: "0",
|
|||
|
FinalPriceTotal: "0",
|
|||
|
FinalPriceNotSendTotal: "0",
|
|||
|
FinalPriceHasSendTotal: "0",
|
|||
|
FinalPricePayNotTotal: "0",
|
|||
|
FinalPricePayTotal: "0",
|
|||
|
}
|
|||
|
service.Success(c, &resp)
|
|||
|
return
|
|||
|
}
|
|||
|
showUidList := []string{}
|
|||
|
if !req.QueryIsEmpty() {
|
|||
|
for _, v := range data {
|
|||
|
showUidList = append(showUidList, v.ShowUid)
|
|||
|
}
|
|||
|
}
|
|||
|
fmt.Println("debug showUidList:", showUidList)
|
|||
|
resp, err := service.GrpcArtShowImpl.GetAuthPaymentStat(c, &artShow.GetAuthPaymentStatReq{ShowUidQuery: showUidList})
|
|||
|
if err != nil {
|
|||
|
service.ErrorWithMark(c, e.Failed, err, "UpdateAuthPaymentPercent Err", "查询失败")
|
|||
|
return
|
|||
|
}
|
|||
|
service.Success(c, resp)
|
|||
|
}
|