6
0

account.go 1.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869
  1. package account
  2. import (
  3. "dashoo.cn/micro_libary/request"
  4. "fmt"
  5. "github.com/gogf/gf/os/gtime"
  6. dao "lims_adapter/dao/account"
  7. account "lims_adapter/model/account"
  8. "strconv"
  9. )
  10. // Service 账号相关
  11. type Service struct {
  12. Dao *dao.SettleAccountMainDao
  13. Tenant string
  14. }
  15. type AccountService struct {
  16. Dao *dao.BaseAccountDao
  17. Tenant string
  18. }
  19. func NewAccountSrv(tenant string) AccountService {
  20. return AccountService{Dao: dao.NewBaseAccountDao(tenant), Tenant: tenant}
  21. }
  22. // AddAccount 添加财务账号
  23. func (s AccountService) Save(req *account.BaseAccount, user request.UserInfo) error {
  24. now := gtime.Now()
  25. if req.Id == 0 {
  26. req.CreateUserId = int(user.Id)
  27. req.CreateBy = user.RealName
  28. req.CreateOn = now
  29. }
  30. req.UpdateUserId = int(user.Id)
  31. req.UpdateBy = user.RealName
  32. req.UpdateOn = now
  33. _, err := s.Dao.Save(req)
  34. return err
  35. }
  36. // AccountList 财务账号分页查询
  37. func (s AccountService) AccountList(req *account.AccountReq) (infos account.BaseAccountRsp, err error) {
  38. current := req.PageNun
  39. size := req.PageSize
  40. model := s.Dao.DB.Model("base_account a")
  41. if req.Account != "" {
  42. model = model.WhereLike("Account", "%" + req.Account + "%")
  43. }
  44. if req.RealName != "" {
  45. model = model.WhereLike("MainUser", "%" + req.RealName + "%")
  46. }
  47. if req.AccountName != "" {
  48. model = model.WhereLike("AccountName", "%" + req.AccountName + "%")
  49. }
  50. infos.Total, err = model.Count()
  51. if err != nil {
  52. return infos, err
  53. }
  54. err = model.Fields("a.*").Page(current, size).Scan(&infos.Records)
  55. return infos, nil
  56. }
  57. // DepositAccount 充值账户
  58. func (s AccountService) DepositAccount(req *account.BaseAccountResp) error {
  59. _, err := s.Dao.M.Update(fmt.Sprintf("Surplus='%v',Available='%v'", req.Surplus, req.Available), "Id = "+strconv.Itoa(req.Id))
  60. return err
  61. }