provider_add_platform.go 1.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940
  1. package provider
  2. import (
  3. "context"
  4. "gd_management/apis"
  5. "gd_management/errors"
  6. "github.com/astaxie/beego/orm"
  7. "time"
  8. )
  9. func ManagementAddProviderPlatform(ctx context.Context, req *apis.ManagementAddProviderPlatformReq, reply *apis.ManagementAddProviderPlatformReply) error {
  10. if req.PlatformName == "" || req.PlatformCode == "" {
  11. return errors.ArgsError
  12. }
  13. var providerPlatform apis.ProviderPlatform
  14. err := orm.NewOrm().QueryTable("t_gd_provider").Filter("platform_code", req.PlatformCode).One(&providerPlatform)
  15. if err != nil && err != orm.ErrNoRows {
  16. return errors.DataBaseError
  17. } else if err == nil {
  18. return errors.PorviderPlatformExist
  19. }
  20. var timeLayout = "2006-01-02 15:04:05"
  21. timeNow := time.Now().Format(timeLayout)
  22. providerPlatform.PlatformName = req.PlatformName
  23. providerPlatform.PlatformCode = req.PlatformCode
  24. providerPlatform.Contact = req.Contact
  25. providerPlatform.Email = req.Email
  26. providerPlatform.CreateTime = timeNow
  27. providerPlatform.UpdateTime = timeNow
  28. id, err := orm.NewOrm().Insert(&providerPlatform)
  29. if err != nil {
  30. return errors.DataBaseError
  31. }
  32. reply.ProviderId = id
  33. return nil
  34. }