|
@@ -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,
|