1234567891011121314151617181920212223242526272829303132333435363738394041 |
- package db
- import (
- "context"
- "github.com/sirupsen/logrus"
- "youngee_b_api/model/gorm_model"
- )
- // CreateSupplierWithdraw 创建服务商提现信息
- func CreateSupplierWithdraw(ctx context.Context, supplierWithdraw []*gorm_model.YounggeeSupplierWithdraw) error {
- db := GetWriteDB(ctx)
- err := db.Create(&supplierWithdraw).Error
- if err != nil {
- return err
- }
- return nil
- }
- // GetSupplierWithdrawList 查询服务商提现列表
- func GetSupplierWithdrawList(ctx context.Context, pageSize int32, pageNum int32, supplierId int, withdrawStatus int) ([]*gorm_model.YounggeeSupplierWithdraw, int64, error) {
- db := GetReadDB(ctx)
- // 1. 根据基本信息过滤
- db = db.Debug().Model(gorm_model.YounggeeSupplierWithdraw{}).Where("supplier_id = ? and withdraw_status = ?", supplierId, withdrawStatus)
- // 2. 确定查询总数和返回当前页数据
- var total int64
- var SupplierWithdrawList []*gorm_model.YounggeeSupplierWithdraw
- if err := db.Count(&total).Error; err != nil {
- logrus.WithContext(ctx).Errorf("[SupplierWithdrawList] error query mysql total, err:%+v", err)
- return nil, 0, err
- }
- limit := pageSize
- offset := pageSize * pageNum // assert pageNum start with 0
- err := db.Order("supplier_withdraw_id desc").Limit(int(limit)).Offset(int(offset)).Find(&SupplierWithdrawList).Error
- if err != nil {
- logrus.WithContext(ctx).Errorf("[SupplierWithdrawList] error query mysql total, err:%+v", err)
- return nil, 0, err
- }
- return SupplierWithdrawList, total, nil
- }
|