supplier_income.go 2.1 KB

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