|
@@ -5,10 +5,12 @@ import (
|
|
|
"fmt"
|
|
|
"github.com/caixw/lib.go/conv"
|
|
|
"github.com/sirupsen/logrus"
|
|
|
+ "gorm.io/gorm"
|
|
|
"reflect"
|
|
|
"strconv"
|
|
|
"strings"
|
|
|
"time"
|
|
|
+ "youngee_m_api/consts"
|
|
|
"youngee_m_api/model/common_model"
|
|
|
"youngee_m_api/model/gorm_model"
|
|
|
"youngee_m_api/model/http_model"
|
|
@@ -90,7 +92,7 @@ func GetWithdrawRecords(ctx context.Context, pageSize, pageNum int32, req *http_
|
|
|
|
|
|
func GetWithdrawRecord(ctx context.Context, req *http_model.GetWithdrawalRecordRequest) (*http_model.WithdrawalRecordPreview, error) {
|
|
|
db := GetReadDB(ctx)
|
|
|
- fmt.Println("talentId:", req.TalentId)
|
|
|
+ //fmt.Println("talentId:", req.TalentId)
|
|
|
var withdrawRecords []*gorm_model.YounggeeWithdrawRecord
|
|
|
db = db.Debug().Model(gorm_model.YounggeeWithdrawRecord{}).Where("talent_id = ? AND status = ?", req.TalentId, 2).Find(&withdrawRecords)
|
|
|
var withdrawRecordsPreview http_model.WithdrawalRecordPreview
|
|
@@ -149,7 +151,7 @@ func GetBankInfo(ctx context.Context, req *http_model.GetBankInfoRequest) (*http
|
|
|
data := new(http_model.BankInfo)
|
|
|
data.BankName = infoBank.Name
|
|
|
data.BankOpenAddress = province.RegionName + city.RegionName + infoRegion.RegionName
|
|
|
- db.Model(gorm_model.InfoBank{}).Where("")
|
|
|
+ //db.Model(gorm_model.InfoBank{}).Where("")
|
|
|
return data, nil
|
|
|
}
|
|
|
|
|
@@ -203,7 +205,7 @@ func GetInvoiceRecords(ctx context.Context, req *http_model.InvoiceRecordsReques
|
|
|
if req.InvoiceStatus == 1 {
|
|
|
db.Order("submit_at")
|
|
|
} else {
|
|
|
- db.Order("submit_at desc")
|
|
|
+ db.Order("billing_at desc")
|
|
|
}
|
|
|
// 查询该页数据
|
|
|
limit := req.PageSize
|
|
@@ -256,3 +258,118 @@ func ConfirmInvoice(ctx context.Context, request *http_model.ConfirmInvoiceReque
|
|
|
Status: 2,
|
|
|
}).Error
|
|
|
}
|
|
|
+
|
|
|
+func GetRechargeRecords(ctx context.Context, req *http_model.GetRechargeRecordsRequest, condition *common_model.RechargeRecordsCondition) (*http_model.RechargeRecordsData, error) {
|
|
|
+ db := GetReadDB(ctx)
|
|
|
+ var rechargeRecords []*gorm_model.YounggeeRechargeRecord
|
|
|
+ db = db.Debug().Model(gorm_model.YounggeeRechargeRecord{}).Where("status = ?", req.Status)
|
|
|
+ conditionType := reflect.TypeOf(condition).Elem()
|
|
|
+ conditionValue := reflect.ValueOf(condition).Elem()
|
|
|
+ for i := 0; i < conditionType.NumField(); i++ {
|
|
|
+ field := conditionType.Field(i)
|
|
|
+ tag := field.Tag.Get("condition")
|
|
|
+ value := conditionValue.FieldByName(field.Name)
|
|
|
+ if tag == "commit_at" && value.Interface() != "" {
|
|
|
+ db = db.Where(fmt.Sprintf("commit_at like '%s%%'", value.Interface()))
|
|
|
+ }
|
|
|
+ if tag == "confirm_at" && value.Interface() != "" {
|
|
|
+ db = db.Where(fmt.Sprintf("confirm_at like '%s%%'", value.Interface()))
|
|
|
+ }
|
|
|
+ }
|
|
|
+ if req.BusinessName != "" {
|
|
|
+ enterpriseId := GetEnterpriseIDByBusiness(ctx, req.BusinessName)
|
|
|
+ db = db.Where("enterprise_id = ?", enterpriseId)
|
|
|
+ }
|
|
|
+ if req.UserId != 0 {
|
|
|
+ enterpriseId := GetEnterpriseIDByUserId(ctx, req.UserId)
|
|
|
+ db = db.Where("enterprise_id = ?", enterpriseId)
|
|
|
+ }
|
|
|
+ if req.RechargeMethod == 1 {
|
|
|
+ db = db.Where("recharge_method = ?", 1)
|
|
|
+ } else if req.RechargeMethod == 2 {
|
|
|
+ db = db.Where("recharge_method = ?", 2)
|
|
|
+ } else if req.RechargeMethod == 3 {
|
|
|
+ db = db.Where("recharge_method = ?", 3)
|
|
|
+ }
|
|
|
+ // 查询总数
|
|
|
+ var total int64
|
|
|
+ if err := db.Count(&total).Error; err != nil {
|
|
|
+ logrus.WithContext(ctx).Errorf("[GetRechargeRecords] error query mysql total, err:%+v", err)
|
|
|
+ return nil, err
|
|
|
+ }
|
|
|
+ if req.Status == 1 {
|
|
|
+ db = db.Order("commit_at")
|
|
|
+ } else {
|
|
|
+ db = db.Order("confirm_at desc")
|
|
|
+ }
|
|
|
+ // 查询该页数据
|
|
|
+ limit := req.PageSize
|
|
|
+ offset := req.PageSize * req.PageNum // assert pageNum start with 0
|
|
|
+ err := db.Limit(int(limit)).Offset(int(offset)).Find(&rechargeRecords).Error
|
|
|
+ if err != nil {
|
|
|
+ logrus.WithContext(ctx).Errorf("[GetInvoiceRecords] error query mysql limit, err:%+v", err)
|
|
|
+ return nil, err
|
|
|
+ }
|
|
|
+ var enterpriseIds []int64
|
|
|
+ for _, rechargeRecord := range rechargeRecords {
|
|
|
+ enterpriseIds = append(enterpriseIds, rechargeRecord.EnterpriseID)
|
|
|
+ }
|
|
|
+ util.RemoveRepByMap(enterpriseIds)
|
|
|
+ enterpriseIdToUserInfoMap := make(map[int64]gorm_model.Enterprise)
|
|
|
+ db1 := GetReadDB(ctx)
|
|
|
+ for _, v := range enterpriseIds {
|
|
|
+ enterpriseInfo := gorm_model.Enterprise{}
|
|
|
+ db1.Model(gorm_model.Enterprise{}).Where("enterprise_id = ?", v).Find(&enterpriseInfo)
|
|
|
+ enterpriseIdToUserInfoMap[v] = enterpriseInfo
|
|
|
+ }
|
|
|
+ var RechargeRecords []*http_model.RechargeRecordsPreview
|
|
|
+ for _, rechargeRecord := range rechargeRecords {
|
|
|
+ RechargeRecord := new(http_model.RechargeRecordsPreview)
|
|
|
+ RechargeRecord.RechargeId = rechargeRecord.RechargeID
|
|
|
+ RechargeRecord.EnterpriseID = rechargeRecord.EnterpriseID
|
|
|
+ RechargeRecord.RechargeAmount = rechargeRecord.RechargeAmount
|
|
|
+ RechargeRecord.ConfirmAt = conv.MustString(rechargeRecord.ConfirmAt, "")[:19]
|
|
|
+ RechargeRecord.CommitAt = conv.MustString(rechargeRecord.CommitAt, "")[:19]
|
|
|
+ RechargeRecord.Phone = rechargeRecord.Phone
|
|
|
+ RechargeRecord.TransferVoucher = rechargeRecord.TransferVoucherUrl
|
|
|
+ RechargeRecord.RechargeMethod = consts.GetRechargeMethod(rechargeRecord.RechargeMethod)
|
|
|
+ RechargeRecord.UserId = enterpriseIdToUserInfoMap[rechargeRecord.EnterpriseID].UserID
|
|
|
+ RechargeRecord.BusinessName = enterpriseIdToUserInfoMap[rechargeRecord.EnterpriseID].BusinessName
|
|
|
+ RechargeRecords = append(RechargeRecords, RechargeRecord)
|
|
|
+ }
|
|
|
+ var RechargeRecordsData http_model.RechargeRecordsData
|
|
|
+ RechargeRecordsData.RechargeRecordsPreview = RechargeRecords
|
|
|
+ RechargeRecordsData.Total = conv.MustString(total, "")
|
|
|
+ return &RechargeRecordsData, nil
|
|
|
+}
|
|
|
+
|
|
|
+func OperateRecharge(ctx context.Context, req *http_model.OperateRechargeRequest) error {
|
|
|
+ db := GetReadDB(ctx)
|
|
|
+ db1 := GetReadDB(ctx)
|
|
|
+ //rechargeInfo := gorm_model.YounggeeRechargeRecord{}
|
|
|
+ //db = db.Model(gorm_model.YounggeeRechargeRecord{}).Where("recharge_id = ?", req.RechargeId).Find(&rechargeInfo)
|
|
|
+ //enterpriseInfo := gorm_model.Enterprise{}
|
|
|
+ //db1.Model(gorm_model.Enterprise{}).Where("enterprise_id = ?", req.EnterpriseId).Find(&enterpriseInfo)
|
|
|
+ err := db1.Model(gorm_model.Enterprise{}).Where("enterprise_id = ?", req.EnterpriseId).Updates(map[string]interface{}{
|
|
|
+ "balance": gorm.Expr("balance + ?", req.RechargeAmount),
|
|
|
+ "available_balance": gorm.Expr("available_balance + ?", req.RechargeAmount)}).Error
|
|
|
+ if err != nil {
|
|
|
+ logrus.WithContext(ctx).Errorf("[OperateRecharge] error Updates balance, err:%+v", err)
|
|
|
+ return err
|
|
|
+ }
|
|
|
+ err1 := db.Model(gorm_model.YounggeeRechargeRecord{}).Where("recharge_id = ?", req.RechargeId).Updates(gorm_model.YounggeeRechargeRecord{
|
|
|
+ Status: 2,
|
|
|
+ ConfirmAt: time.Now(),
|
|
|
+ }).Error
|
|
|
+ if err1 != nil {
|
|
|
+ logrus.WithContext(ctx).Errorf("[OperateRecharge] error Updates Status, err:%+v", err)
|
|
|
+ return err1
|
|
|
+ }
|
|
|
+ if req.Method == 1 {
|
|
|
+ db2 := GetReadDB(ctx)
|
|
|
+ db2.Model(gorm_model.YounggeeRechargeRecord{}).Where("recharge_id = ?", req.RechargeId).Updates(gorm_model.YounggeeRechargeRecord{
|
|
|
+ RechargeAmount: req.RechargeAmount,
|
|
|
+ })
|
|
|
+ }
|
|
|
+ return nil
|
|
|
+}
|