supplier_withdraw.go 1.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041
  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. }