supplier_income.go 2.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354
  1. package db
  2. import (
  3. "context"
  4. "github.com/sirupsen/logrus"
  5. "youngee_b_api/model/gorm_model"
  6. )
  7. // GetSupplierIncomeList 查询服务商收入列表
  8. func GetSupplierIncomeList(ctx context.Context, pageSize int32, pageNum int32, supplierId int, incomeStatus int) ([]*gorm_model.YounggeeSupplierIncome, int64, error) {
  9. db := GetReadDB(ctx)
  10. // 1. 根据基本信息过滤
  11. db = db.Debug().Model(gorm_model.YounggeeSupplierIncome{}).Where("supplier_id = ? and income_status = ?", supplierId, incomeStatus)
  12. // 2. 确定查询总数和返回当前页数据
  13. var total int64
  14. var SupplierIncomeList []*gorm_model.YounggeeSupplierIncome
  15. if err := db.Count(&total).Error; err != nil {
  16. logrus.WithContext(ctx).Errorf("[GetSupplierIncomeList] error query mysql total, err:%+v", err)
  17. return nil, 0, err
  18. }
  19. limit := pageSize
  20. offset := pageSize * pageNum // assert pageNum start with 0
  21. err := db.Order("s_project_id desc").Limit(int(limit)).Offset(int(offset)).Find(&SupplierIncomeList).Error
  22. if err != nil {
  23. logrus.WithContext(ctx).Errorf("[GetSupplierIncomeList] error query mysql total, err:%+v", err)
  24. return nil, 0, err
  25. }
  26. return SupplierIncomeList, total, nil
  27. }
  28. // UpdateSupplierIncomeStatus 修改服务商收入状态
  29. func UpdateSupplierIncomeStatus(ctx context.Context, incomeIds []int, incomeStatus int) error {
  30. // 1. 建立数据库连接并修改
  31. db := GetReadDB(ctx)
  32. if err := db.Debug().Model(&gorm_model.YounggeeSupplierIncome{}).Where("income_id IN ?", incomeIds).
  33. Updates(gorm_model.YounggeeSupplierIncome{IncomeStatus: incomeStatus}).Error; err != nil {
  34. logrus.WithContext(ctx).Errorf("[ChangeTaskStatus]2 error query mysql total, err:%+v", err)
  35. return err
  36. }
  37. return nil
  38. }
  39. // GetIncomeInfoByIncomeId 根据income_id查询收入信息
  40. func GetIncomeInfoByIncomeId(ctx context.Context, incomeId int) (*gorm_model.YounggeeSupplierIncome, error) {
  41. db := GetReadDB(ctx)
  42. var incomeInfo *gorm_model.YounggeeSupplierIncome
  43. err := db.Model(&gorm_model.YounggeeSupplierIncome{}).Where("income_id = ?", incomeId).Find(&incomeInfo).Error
  44. if err != nil {
  45. return nil, err
  46. }
  47. return incomeInfo, nil
  48. }