settle_account_detail.go 1.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859
  1. package settle_account_detail
  2. import (
  3. "database/sql"
  4. "fmt"
  5. "github.com/gogf/gf/util/gconv"
  6. "lims_adapter/dao/account"
  7. "lims_adapter/model"
  8. accountModel "lims_adapter/model/account"
  9. )
  10. // Service 会议室服务
  11. type Service struct {
  12. Dao *account.SettleAccountDetailDao
  13. Tenant string
  14. }
  15. // NewSrv 服务初始化
  16. func NewService(tenant string) Service {
  17. return Service{Dao: account.NewSettleAccountDetailDao(tenant), Tenant: tenant}
  18. }
  19. // List 获取数据列表
  20. func (s Service) List(req model.ListReq) ([]accountModel.SettleAccountDetail, error) {
  21. entityModel := s.Dao.M
  22. where := "(PaymentAccount>0 OR Data4='机器被占用,取消不扣费')" // 费用大于0,或者非自身原因的取消操作
  23. if req.Entity != nil {
  24. entity := new(accountModel.SettleAccountDetailReq)
  25. err := gconv.Struct(req.Entity, entity)
  26. if err != nil {
  27. return nil, err
  28. }
  29. if entity.MainUserId != 0 {
  30. where += fmt.Sprintf(" AND MainUserId='%v'", entity.MainUserId)
  31. }
  32. if entity.AttachUserId != 0 {
  33. where += fmt.Sprintf(" AND AttachUserId='%v'", entity.AttachUserId)
  34. }
  35. if entity.Pid != 0 {
  36. where += fmt.Sprintf(" AND pid='%v'", entity.Pid)
  37. }
  38. }
  39. entityModel = entityModel.Where(where)
  40. res, err := entityModel.Fields("settle_account_detail.*").FindAll()
  41. if err != nil {
  42. return nil, err
  43. }
  44. list := make([]accountModel.SettleAccountDetail, 0)
  45. err = res.Structs(&list)
  46. if err != nil && err != sql.ErrNoRows {
  47. return nil, err
  48. }
  49. return list, nil
  50. }