pay_record.go 2.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859
  1. package db
  2. import (
  3. "context"
  4. "time"
  5. "youngee_b_api/consts"
  6. "youngee_b_api/model/gorm_model"
  7. "youngee_b_api/model/http_model"
  8. "github.com/issue9/conv"
  9. "github.com/sirupsen/logrus"
  10. )
  11. // CreatePayRecord 新增
  12. func CreatePayRecord(ctx context.Context, enterpriseId string, payment float64, balance float64, payType int64, projectId string) (*int64, error) {
  13. db := GetReadDB(ctx)
  14. payRecord := gorm_model.EnterprisePayRecord{
  15. EnterpriseID: enterpriseId,
  16. Payment: payment,
  17. Balance: balance,
  18. PayType: payType,
  19. PayAt: time.Now(),
  20. ProjectID: projectId,
  21. }
  22. err := db.Create(&payRecord).Error
  23. if err != nil {
  24. logrus.WithContext(ctx).Errorf("[logistics db] call CreatePayRecord error,err:%+v", err)
  25. return nil, err
  26. }
  27. return &payRecord.ID, nil
  28. }
  29. func GetRechargeRecord(ctx context.Context, enterpriseID string, confirmAt string, method int) (*http_model.RechargeRecordPreview, error) {
  30. db := GetReadDB(ctx)
  31. // 根据企业id过滤
  32. db = db.Debug().Model(gorm_model.YounggeeRechargeRecord{}).Where("enterprise_id = ? and status = 2", enterpriseID)
  33. if method == 2 {
  34. db = db.Debug().Model(gorm_model.YounggeeRechargeRecord{}).Where("invoice_status = 2")
  35. }
  36. if confirmAt != "" {
  37. db = db.Where("confirm_at like ?", confirmAt+"%")
  38. }
  39. var rechargeRecords []gorm_model.YounggeeRechargeRecord
  40. db = db.Order("confirm_at desc").Find(&rechargeRecords)
  41. RechargeRecordPreview := http_model.RechargeRecordPreview{}
  42. for _, rechargeRecord := range rechargeRecords {
  43. RechargeRecordData := new(http_model.RechargeRecordData)
  44. RechargeRecordData.RechargeId = rechargeRecord.RechargeID
  45. RechargeRecordData.RechargeAmount = conv.MustString(rechargeRecord.RechargeAmount)
  46. RechargeRecordData.RechargeAmountReal = conv.MustString(rechargeRecord.RechargeAmount)
  47. RechargeRecordData.TransferVoucher = conv.MustString(rechargeRecord.TransferVoucherUrl)
  48. RechargeRecordData.PayMethod = consts.GetRechargeMethod(rechargeRecord.RechargeMethod)
  49. RechargeRecordData.ConfirmAt = conv.MustString(rechargeRecord.ConfirmAt)[0:19]
  50. RechargeRecordPreview.RechargeRecordData = append(RechargeRecordPreview.RechargeRecordData, RechargeRecordData)
  51. }
  52. return &RechargeRecordPreview, nil
  53. }