12345678910111213141516171819202122232425262728293031323334353637383940 |
- package provider
- import (
- "context"
- "gd_management/apis"
- "gd_management/errors"
- "github.com/astaxie/beego/orm"
- "time"
- )
- func ManagementAddProviderPlatform(ctx context.Context, req *apis.ManagementAddProviderPlatformReq, reply *apis.ManagementAddProviderPlatformReply) error {
- if req.PlatformName == "" || req.PlatformCode == "" {
- return errors.ArgsError
- }
- var providerPlatform apis.ProviderPlatform
- err := orm.NewOrm().QueryTable("t_gd_provider").Filter("platform_code", req.PlatformCode).One(&providerPlatform)
- if err != nil && err != orm.ErrNoRows {
- return errors.DataBaseError
- } else if err == nil {
- return errors.PorviderPlatformExist
- }
- var timeLayout = "2006-01-02 15:04:05"
- timeNow := time.Now().Format(timeLayout)
- providerPlatform.PlatformName = req.PlatformName
- providerPlatform.PlatformCode = req.PlatformCode
- providerPlatform.Contact = req.Contact
- providerPlatform.Email = req.Email
- providerPlatform.CreateTime = timeNow
- providerPlatform.UpdateTime = timeNow
- id, err := orm.NewOrm().Insert(&providerPlatform)
- if err != nil {
- return errors.DataBaseError
- }
- reply.ProviderId = id
- return nil
- }
|