provider_get_merchant_api_list.go 1.3 KB

123456789101112131415161718192021222324252627282930313233343536
  1. // Copyright 2019 getensh.com. All rights reserved.
  2. // Use of this source code is governed by getensh.com.
  3. package provider
  4. import (
  5. "context"
  6. "gd_management/apis"
  7. "gd_management/errors"
  8. "fmt"
  9. "github.com/astaxie/beego/orm"
  10. )
  11. func ManagementGetProviderMerchantApiList(ctx context.Context, req *apis.ManagementGetProviderMerchantApiListReq, reply *apis.ManagementGetProviderMerchantApiListReply) error {
  12. o := orm.NewOrm()
  13. sql := fmt.Sprintf("select t1.day_count,"+
  14. "sum(t1.enable) as enable_count,"+
  15. " t1.inventory, t1.merchant_child_api_id, "+
  16. "t4.merchant_name, t5.name as api_name from "+
  17. "t_gd_merchant_api_provider_api_relation as t1 "+
  18. "left join t_gd_merchant_child_data_api as t2 on t2.id=t1.merchant_child_api_id "+
  19. "left join t_gd_merchant_data_api as t3 on t3.id=t2.merchant_data_api_id "+
  20. "left join t_gd_merchants as t4 on t4.id=t3.merchant_id "+
  21. "left join t_gd_api as t5 on t5.id=t2.api_id where t1.provider_api_id=%d group by t1.merchant_child_api_id", req.ProviderApiId)
  22. _, err := o.Raw(sql).QueryRows(&reply.ProviderMerchantApiList)
  23. if err != nil && err != orm.ErrNoRows {
  24. return errors.DataBaseError
  25. }
  26. for i, v := range reply.ProviderMerchantApiList {
  27. if v.EnableCount > 0 {
  28. reply.ProviderMerchantApiList[i].Enable = true
  29. }
  30. }
  31. return nil
  32. }