Quellcode durchsuchen

修改样叽页面bug

yuliang1112 vor 2 Jahren
Ursprung
Commit
336a8fef13
7 geänderte Dateien mit 60 neuen und 40 gelöschten Zeilen
  1. 17 15
      db/enterprise.go
  2. 35 22
      db/invoice.go
  3. 1 1
      db/pay_record.go
  4. 2 0
      handler/getCodeUrl.go
  5. 2 1
      handler/rechargeBalance.go
  6. 2 0
      handler/transferToPublic.go
  7. 1 1
      service/wechatPay.go

+ 17 - 15
db/enterprise.go

@@ -5,6 +5,7 @@ import (
 	"fmt"
 	"github.com/issue9/conv"
 	"log"
+	"strconv"
 	"time"
 	"youngee_b_api/model/gorm_model"
 	"youngee_b_api/model/http_model"
@@ -64,27 +65,26 @@ func GetEnterpriseBalance(ctx context.Context, EnterpriseID int64) (*http_model.
 			return nil, err
 		}
 	}
-	var Invoicings []float64
 	var Invoicing float64
-	var BillableAmounts []float64
 	var BillableAmount float64
 	db1 := GetReadDB(ctx)
-	db1.Model(gorm_model.YounggeeInvoiceRecord{}).Select("invoice_amount").
-		Where("enterprise_id = ? AND status = 1", EnterpriseID).Find(&Invoicings)
-	for _, v := range Invoicings {
-		Invoicing += v
-	}
+	db1.Model(gorm_model.YounggeeInvoiceRecord{}).Select("sum(invoice_amount) as Invoicing").
+		Where("enterprise_id = ? AND status = 1", EnterpriseID).Find(&Invoicing)
+	Invoicing, _ = strconv.ParseFloat(fmt.Sprintf("%.2f", Invoicing), 64)
 	db2 := GetReadDB(ctx)
-	db2.Model(gorm_model.YounggeeRechargeRecord{}).Select("recharge_amount").
-		Where("enterprise_id = ? AND status = 2 AND invoice_status = 2", EnterpriseID).Find(&BillableAmounts)
-	for _, v := range BillableAmounts {
-		BillableAmount += v
-	}
+	db2.Model(gorm_model.YounggeeRechargeRecord{}).Select("sum(recharge_amount) as BillableAmount").
+		Where("enterprise_id = ? AND status = 2 AND invoice_status = 2", EnterpriseID).Find(&BillableAmount)
+	BillableAmount, _ = strconv.ParseFloat(fmt.Sprintf("%.2f", BillableAmount), 64)
+	db3 := GetReadDB(ctx)
+	var Recharging float64
+	db3.Model(gorm_model.YounggeeRechargeRecord{}).Select("sum(recharge_amount) as Recharging").
+		Where("enterprise_id = ? AND status = 1 AND invoice_status = 1", EnterpriseID).Find(&Recharging)
+	Recharging, _ = strconv.ParseFloat(fmt.Sprintf("%.2f", Recharging), 64)
 	res := &http_model.EnterpriseBalanceData{
 		Balance:          enterprise.Balance,
 		FrozenBalance:    enterprise.FrozenBalance,
 		AvailableBalance: enterprise.AvailableBalance,
-		Recharging:       enterprise.Recharging,
+		Recharging:       Recharging,
 		BillableAmount:   BillableAmount,
 		Invoicing:        Invoicing,
 	}
@@ -146,7 +146,7 @@ func MakeRechargeId(ctx context.Context, EnterpriseID int64) string {
 	return rechargeIdPrefix + last
 }
 
-func RechargeAmount(ctx context.Context, EnterpriseID int64, Amount float64) error {
+func RechargeAmount(ctx context.Context, EnterpriseID int64, Amount float64, phone string) error {
 	db := GetReadDB(ctx)
 	err := db.Model(gorm_model.Enterprise{}).Where("enterprise_id", EnterpriseID).
 		Updates(map[string]interface{}{"balance": gorm.Expr("balance + ?", Amount), "available_balance": gorm.Expr("available_balance + ?", Amount)}).Error
@@ -164,10 +164,11 @@ func RechargeAmount(ctx context.Context, EnterpriseID int64, Amount float64) err
 		RechargeAmount:     Amount,
 		EnterpriseID:       EnterpriseID,
 		Status:             2,
-		InvoiceStatus:      1,
+		InvoiceStatus:      2,
 		CommitAt:           time.Now(),
 		RechargeMethod:     3,
 		TransferVoucherUrl: "--",
+		Phone:              phone,
 		ConfirmAt:          time.Now(),
 	}).Error
 	if err != nil {
@@ -179,6 +180,7 @@ func RechargeAmount(ctx context.Context, EnterpriseID int64, Amount float64) err
 func TransferToPublic(ctx context.Context, Amount float64, phone string, EnterpriseID int64, transferVoucherUrl string) error {
 	db := GetReadDB(ctx)
 	rechargeId := MakeRechargeId(ctx, EnterpriseID)
+	fmt.Println("Amount:", Amount)
 	err := db.Model(gorm_model.YounggeeRechargeRecord{}).Create(&gorm_model.YounggeeRechargeRecord{
 		RechargeID:         rechargeId,
 		RechargeAmount:     Amount,

+ 35 - 22
db/invoice.go

@@ -3,6 +3,7 @@ package db
 import (
 	context "context"
 	"encoding/json"
+	"fmt"
 	"github.com/issue9/conv"
 	"github.com/sirupsen/logrus"
 	"time"
@@ -131,6 +132,36 @@ func AddInvoiceRecord(ctx context.Context, enterpriseId int64, req *http_model.A
 	db2 := GetReadDB(ctx)
 	db2.Debug().Model(gorm_model.YounggeeInvoiceAddress{}).Where("address_id = ?", req.AddressID).First(&addressInfo)
 	addressInfoToJson, _ := json.Marshal(addressInfo)
+
+	for _, rechargeId := range req.RechargeIds {
+		rechargeId1 := rechargeId
+		rechargeInfo := gorm_model.YounggeeRechargeRecord{}
+		fmt.Println("rechargeId1:", rechargeId1)
+		db3 := GetReadDB(ctx)
+		db3.Model(gorm_model.YounggeeRechargeRecord{}).Where("recharge_id = ?", rechargeId1).Find(&rechargeInfo)
+		db := GetReadDB(ctx)
+		err := db.Debug().Model(gorm_model.YounggeeInvoiceRecord{}).Create(&gorm_model.YounggeeInvoiceRecord{
+			BillingID:     GetBillingId(ctx, enterpriseId),
+			EnterpriseID:  enterpriseId,
+			InvoiceAmount: rechargeInfo.RechargeAmount,
+			InvoiceSnap:   string(invoiceInfoToJson),
+			AddressSnap:   string(addressInfoToJson),
+			Status:        1,
+			InvoiceType:   invoiceInfo.InvoiceType,
+			Phone:         invoiceInfo.RegisteredPhone,
+			SubmitAt:      time.Now(),
+		}).Error
+		if err != nil {
+			return err
+		}
+	}
+	db3 := GetReadDB(ctx)
+	return db3.Debug().Model(gorm_model.YounggeeRechargeRecord{}).Where("recharge_id IN ?", req.RechargeIds).Updates(gorm_model.YounggeeRechargeRecord{
+		InvoiceStatus: 3,
+	}).Error
+}
+
+func GetBillingId(ctx context.Context, enterpriseId int64) string {
 	db := GetReadDB(ctx)
 	// 1、年月日
 	year := time.Now().Year()
@@ -150,13 +181,13 @@ func AddInvoiceRecord(ctx context.Context, enterpriseId int64, req *http_model.A
 	}
 	last := ""
 	billingIdPrefix := "9" + conv.MustString(enterpriseId)[len(conv.MustString(enterpriseId))-2:] + conv.MustString(sum)
-	var rechargeIdLast string
+	var billingIdLast string
 	err := db.Model(gorm_model.YounggeeInvoiceRecord{}).Select("billing_id").Where("billing_id like ?", billingIdPrefix+"%").
-		Last(&rechargeIdLast).Error
+		Last(&billingIdLast).Error
 	if err != nil {
 		last = "0"
 	} else {
-		last = rechargeIdLast[len(rechargeIdLast)-2:]
+		last = billingIdLast[len(billingIdLast)-2:]
 	}
 	var lastInt int
 	lastInt = conv.MustInt(last)
@@ -165,26 +196,8 @@ func AddInvoiceRecord(ctx context.Context, enterpriseId int64, req *http_model.A
 	} else {
 		last = conv.MustString(conv.MustInt(last) + 1)
 	}
-	err = db.Debug().Model(gorm_model.YounggeeInvoiceRecord{}).Create(&gorm_model.YounggeeInvoiceRecord{
-		BillingID:     billingIdPrefix + last,
-		EnterpriseID:  enterpriseId,
-		InvoiceAmount: req.Amount,
-		InvoiceSnap:   string(invoiceInfoToJson),
-		AddressSnap:   string(addressInfoToJson),
-		Status:        1,
-		InvoiceType:   invoiceInfo.InvoiceType,
-		Phone:         invoiceInfo.RegisteredPhone,
-		SubmitAt:      time.Now(),
-	}).Error
-	if err != nil {
-		return err
-	}
-	db3 := GetReadDB(ctx)
-	return db3.Debug().Model(gorm_model.YounggeeRechargeRecord{}).Where("recharge_id IN ?", req.RechargeIds).Updates(gorm_model.YounggeeRechargeRecord{
-		InvoiceStatus: 3,
-	}).Error
+	return billingIdPrefix + last
 }
-
 func GetInvoiceRecords(ctx context.Context, req *http_model.GetInvoiceRecordRequest) (*http_model.InvoiceRecordsData, error) {
 	db := GetReadDB(ctx)
 	var invoiceRecords []*gorm_model.YounggeeInvoiceRecord

+ 1 - 1
db/pay_record.go

@@ -37,7 +37,7 @@ func GetRechargeRecord(ctx context.Context, enterpriseID int64, confirmAt string
 	// 根据企业id过滤
 	db = db.Debug().Model(gorm_model.YounggeeRechargeRecord{}).Where("enterprise_id = ?", enterpriseID)
 	if method == 2 {
-		db = db.Where("invoice_status = 2")
+		db = db.Debug().Model(gorm_model.YounggeeRechargeRecord{}).Where("invoice_status = 2")
 	}
 	if confirmAt != "" {
 		db = db.Where("confirm_at like ?", confirmAt+"%")

+ 2 - 0
handler/getCodeUrl.go

@@ -1,6 +1,7 @@
 package handler
 
 import (
+	"fmt"
 	"github.com/gin-gonic/gin"
 	"github.com/sirupsen/logrus"
 	"youngee_b_api/consts"
@@ -35,6 +36,7 @@ func (g getCodeUrlHandler) getRequest() interface{} {
 func (g getCodeUrlHandler) run() {
 	tradeId := util.GetRandomString(32)
 	if g.req.Type == 1 {
+		fmt.Println("amount:", g.req.Amount)
 		data, err := service.NativeApiServicePrepay(tradeId, g.req.Amount)
 		if err != nil {
 			logrus.WithContext(g.ctx).Errorf("[getCodeUrlHandler] error NativeApiServicePrepay, err:%+v", err)

+ 2 - 1
handler/rechargeBalance.go

@@ -35,7 +35,8 @@ func (r RechargeBalanceHandler) getRequest() interface{} {
 
 func (r RechargeBalanceHandler) run() {
 	enterpriseID := middleware.GetSessionAuth(r.ctx).EnterpriseID
-	err := db.RechargeAmount(r.ctx, enterpriseID, r.req.Amount)
+	phone := middleware.GetSessionAuth(r.ctx).Phone
+	err := db.RechargeAmount(r.ctx, enterpriseID, r.req.Amount, phone)
 	if err != nil {
 		logrus.WithContext(r.ctx).Errorf("[QueryOrderByTradeIdHandler] error QueryOrderByOutTradeNo, err:%+v", err)
 		util.HandlerPackErrorResp(r.resp, consts.ErrorInternal, consts.DefaultToast)

+ 2 - 0
handler/transferToPublic.go

@@ -1,6 +1,7 @@
 package handler
 
 import (
+	"fmt"
 	"github.com/gin-gonic/gin"
 	"github.com/sirupsen/logrus"
 	"youngee_b_api/consts"
@@ -36,6 +37,7 @@ func (t TransferToPublicHandler) getRequest() interface{} {
 func (t TransferToPublicHandler) run() {
 	enterpriseID := middleware.GetSessionAuth(t.ctx).EnterpriseID
 	phone := middleware.GetSessionAuth(t.ctx).Phone
+	fmt.Println("Amount:", t.req.Amount)
 	err := db.TransferToPublic(t.ctx, t.req.Amount, phone, enterpriseID, t.req.TransferVoucherUrl)
 	if err != nil {
 		logrus.Errorf("[TransferToPublicHandler] call TransferToPublic err:%+v\n", err)

+ 1 - 1
service/wechatPay.go

@@ -47,7 +47,7 @@ func NativeApiServicePrepay(tradeId string, amount int64) (codeUrl string, err e
 			SupportFapiao: core.Bool(true),
 			Amount: &native.Amount{
 				Currency: core.String("CNY"),
-				Total:    core.Int64(amount * 100),
+				Total:    core.Int64(amount),
 			},
 		},
 	)