supplier_withdraw.go 2.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758
  1. package db
  2. import (
  3. "context"
  4. "github.com/sirupsen/logrus"
  5. "youngee_b_api/model/gorm_model"
  6. )
  7. // CreateSupplierWithdraw 创建服务商提现信息
  8. func CreateSupplierWithdraw(ctx context.Context, supplierWithdraw []*gorm_model.YounggeeSupplierWithdraw) error {
  9. db := GetWriteDB(ctx)
  10. err := db.Create(&supplierWithdraw).Error
  11. if err != nil {
  12. return err
  13. }
  14. return nil
  15. }
  16. // GetSupplierWithdrawList 查询服务商提现列表
  17. func GetSupplierWithdrawList(ctx context.Context, pageSize int32, pageNum int32, supplierId int, withdrawStatus int) ([]*gorm_model.YounggeeSupplierWithdraw, int64, error) {
  18. db := GetReadDB(ctx)
  19. // 1. 根据基本信息过滤
  20. db = db.Debug().Model(gorm_model.YounggeeSupplierWithdraw{}).Where("supplier_id = ? and withdraw_status = ?", supplierId, withdrawStatus)
  21. // 2. 确定查询总数和返回当前页数据
  22. var total int64
  23. var SupplierWithdrawList []*gorm_model.YounggeeSupplierWithdraw
  24. if err := db.Count(&total).Error; err != nil {
  25. logrus.WithContext(ctx).Errorf("[SupplierWithdrawList] error query mysql total, err:%+v", err)
  26. return nil, 0, err
  27. }
  28. limit := pageSize
  29. offset := pageSize * pageNum // assert pageNum start with 0
  30. err := db.Order("supplier_withdraw_id desc").Limit(int(limit)).Offset(int(offset)).Find(&SupplierWithdrawList).Error
  31. if err != nil {
  32. logrus.WithContext(ctx).Errorf("[SupplierWithdrawList] error query mysql total, err:%+v", err)
  33. return nil, 0, err
  34. }
  35. return SupplierWithdrawList, total, nil
  36. }
  37. // GetSupplierWithdrawCount 查询服务商提现记录数量(不分页)
  38. func GetSupplierWithdrawCount(ctx context.Context, supplierId int, withdrawStatus int) (int64, error) {
  39. db := GetReadDB(ctx)
  40. // 1. 基础查询:服务商ID和提现状态
  41. db = db.Model(gorm_model.YounggeeSupplierWithdraw{}).Where("supplier_id = ? AND withdraw_status = ?", supplierId, withdrawStatus)
  42. // 2. 只查询总数(不查询具体数据)
  43. var count int64
  44. if err := db.Count(&count).Error; err != nil {
  45. logrus.WithContext(ctx).Errorf("[GetSupplierWithdrawCount] error query count, err:%+v", err)
  46. return 0, err
  47. }
  48. return count, nil
  49. }