123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119 |
- package shanghu
- import (
- "duoduo/apis/shanghu/models"
- "duoduo/models/shanghu"
- "duoduo/tools/app"
- "errors"
- "github.com/gin-gonic/gin"
- "time"
- )
- // 待核销金额
- func PendingCancelAmount(c *gin.Context) {
- var inData models.PendingCancelAmountRequest
- var activePayTransSql shanghu.ClientActivePayTrans
- var outData models.PendingCancelAmountReply
- err := c.ShouldBindJSON(&inData)
- if err != nil {
- app.Error(c, 400, err, err.Error())
- return
- }
- if inData.Type == 1 { //商家
- activePayTransSql.MerchantOpenID = inData.OpenId
- activeAmount, err := activePayTransSql.GetPendingCancelByMerchant()
- if err != nil {
- app.Error(c, 500, err, err.Error())
- return
- }
- outData.Amount = activeAmount.MerchantAmount.String()
- } else if inData.Type == 2 { //个人
- activePayTransSql.ClientOpenID = inData.OpenId
- activeAmount, err := activePayTransSql.GetPendingCancelByClient()
- if err != nil {
- app.Error(c, 500, err, err.Error())
- return
- }
- outData.Amount = activeAmount.ClientAmount.String()
- } else {
- app.Error(c, 500, errors.New("type 类型错误"), err.Error())
- return
- }
- app.OK(c, outData, app.Success)
- }
- // 拼团购买
- func GetGroupBuyPay(c *gin.Context) {
- var inData models.GetGroupBuyPayRequest
- var sqlData shanghu.ClientActivePayTrans
- var outData []models.GetGroupBuyPayReply
- err := c.ShouldBindJSON(&inData)
- if err != nil {
- app.Error(c, 400, err, err.Error())
- return
- }
- // 不是商家也不是c端客户
- if inData.UserType != 1 && inData.UserType != 2 {
- app.Error(c, 500, errors.New("用户类型错误"), err.Error())
- return
- }
- // 核销类型错误
- if inData.GroupBuyType != 1 && inData.GroupBuyType != 2 {
- app.Error(c, 500, errors.New("核销类型错误"), err.Error())
- return
- }
- var pageSize = 10
- var pageIndex = 1
- if inData.PageSize != 0 {
- pageSize = inData.PageSize
- }
- if inData.PageIndex != 0 {
- pageIndex = inData.PageIndex
- }
- activeDrawLogList, count, err := sqlData.GetActivePayTransList(pageSize, pageIndex, inData.UserType, inData.GroupBuyType, inData.OpenId)
- if err != nil {
- app.Error(c, 500, err, err.Error())
- return
- }
- for _, v := range activeDrawLogList {
- var data models.GetGroupBuyPayReply
- var activeSql shanghu.MerchantActiveConfig
- var groupBuySql shanghu.MerchantActiveGroupBuy
- data.MerchantAmount = v.MerchantAmount.String()
- data.Amount = v.Amount.String()
- data.ClientAmount = v.ClientAmount.String()
- data.PayTime = v.PayTime.Format(time.DateTime)
- activeSql.ID = v.ActiveConfigID
- activeInfo, err := activeSql.GetConfigInfoById()
- if err != nil {
- app.Error(c, 500, err, err.Error())
- return
- }
- data.ActiveName = activeInfo.ActiveName
- groupBuySql.ID = v.GroupBuyID
- groupBuyInfo, err := groupBuySql.GetMerchantActiveGroupBuyById()
- if err != nil {
- app.Error(c, 500, err, err.Error())
- return
- }
- data.GroupBuyName = groupBuyInfo.GroupBuyName
- data.PayTime = v.PayTime.Format(time.DateTime)
- outData = append(outData, data)
- }
- app.PageOK(c, outData, count, pageIndex, pageSize, app.Success)
- }
|