settle_account_main.go 2.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788
  1. package settle_account_main
  2. import (
  3. "dashoo.cn/micro_libary/request"
  4. "errors"
  5. "fmt"
  6. "github.com/gogf/gf/os/gtime"
  7. "github.com/gogf/gf/util/gconv"
  8. "lims_adapter/dao/account"
  9. "lims_adapter/model"
  10. accountModel "lims_adapter/model/account"
  11. )
  12. // Service 会议室服务
  13. type Service struct {
  14. Dao *account.SettleAccountMainDao
  15. Tenant string
  16. }
  17. // NewSrv 服务初始化
  18. func NewService(tenant string) Service {
  19. return Service{Dao: account.NewSettleAccountMainDao(tenant), Tenant: tenant}
  20. }
  21. // List 会议室列表
  22. func (s Service) List(req model.ListReq) ([]accountModel.SettleAccountMain, int, error) {
  23. entityModel := s.Dao.M
  24. where := "1=1"
  25. if req.Entity != nil {
  26. entity := new(accountModel.SettleAccountMainReq)
  27. err := gconv.Struct(req.Entity, entity)
  28. if err != nil {
  29. return nil, 0, err
  30. }
  31. if entity.MainUserId != 0 {
  32. where += fmt.Sprintf(" AND MainUserId='%v'", entity.MainUserId)
  33. }
  34. if entity.AttachUserId != 0 {
  35. where += fmt.Sprintf(" AND AttachUserId='%v'", entity.AttachUserId)
  36. }
  37. if entity.InstrumentId != 0 {
  38. where += fmt.Sprintf(" AND InstrumentId='%v'", entity.InstrumentId)
  39. }
  40. if entity.Status != "" {
  41. where += fmt.Sprintf(" AND Status='%v'", entity.Status)
  42. }
  43. if entity.SettleStatus != "" {
  44. where += fmt.Sprintf(" AND SettleStatus='%v'", entity.SettleStatus)
  45. }
  46. if entity.FeeType != "" {
  47. where += fmt.Sprintf(" AND FeeType='%v'", entity.FeeType)
  48. }
  49. }
  50. entityModel = entityModel.Where(where)
  51. total, err := entityModel.Count()
  52. if err != nil {
  53. return nil, 0, err
  54. }
  55. if total == 0 {
  56. return nil, 0, nil
  57. }
  58. res, err := entityModel.Page(req.Current, req.Size).Order("settle_account_main.CreateOn DESC").Fields("settle_account_main.*").FindAll()
  59. if err != nil {
  60. return nil, 0, err
  61. }
  62. if res.IsEmpty() {
  63. return nil, 0, nil
  64. }
  65. list := make([]accountModel.SettleAccountMain, 0)
  66. err = res.Structs(&list)
  67. if err != nil {
  68. return nil, 0, err
  69. }
  70. return list, total, nil
  71. }
  72. func (s Service) Confirm(req accountModel.AccountMainConfirmReq, user request.UserInfo) error {
  73. if req.MainId == 0 {
  74. return errors.New("参数缺失")
  75. }
  76. _, err := s.Dao.M.Update(fmt.Sprintf("SettleStatus='1',SettleUserId='%v',SettleUser='%v',SettleDate='%v'", user.Id, user.RealName, gtime.Now()), fmt.Sprintf("Id='%v'", req.MainId))
  77. return err
  78. }