order_right.go 2.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576
  1. package client
  2. import (
  3. "context"
  4. "encoding/json"
  5. "errors"
  6. "mop-account-system/common"
  7. )
  8. const (
  9. OrderRightsModifyOverLimitErr = "MOP_RIGHT_MAKE_COUNT_ERR"
  10. )
  11. type MakeDefaultRightReq struct {
  12. AccountId string `json:"accountId"`
  13. }
  14. func MakeDefaultRight(ctx context.Context, accountId string) error {
  15. var headers = map[string]string{
  16. "Accept": "application/json, text/plain, */*",
  17. "Content-Type": "application/json",
  18. }
  19. var req MakeDefaultRightReq
  20. req.AccountId = accountId
  21. body, _ := json.Marshal(req)
  22. url := cfg.RightUrlPrefix + "/api/v1/mop/mop-purchasing-rights-manager/rights/default"
  23. rsp, err := Request(ctx).SetHeaders(headers).SetBody(body).Post(url)
  24. if err != nil {
  25. common.GinLog.Error("MakeDefaultRight err:" + err.Error())
  26. return err
  27. } else if rsp.StatusCode() != 200 {
  28. common.GinLog.Error("MakeDefaultRight status err:" + rsp.String())
  29. return errors.New("status err")
  30. }
  31. common.GinLog.Info("MakeDefaultRight success")
  32. return nil
  33. }
  34. type OrderRightsModifyReq struct {
  35. Type int `json:"type"`
  36. Count int `json:"count"`
  37. OrganId string `json:"organId"`
  38. OrganName string `json:"organName"`
  39. Operator string `json:"operator"`
  40. }
  41. type OrderRightsModifyRsp struct {
  42. Error string `json:"error"`
  43. Errcode string `json:"errcode"`
  44. Data map[string]interface{} `json:"data"`
  45. }
  46. func OrderRightsModify(ctx context.Context, req OrderRightsModifyReq) (*OrderRightsModifyRsp, error) {
  47. var headers = map[string]string{
  48. "Accept": "application/json, text/plain, */*",
  49. "Content-Type": "application/json",
  50. }
  51. url := cfg.OrderRightsModifyURL
  52. common.GinLog.Infof("OrderRightsModify url:%s", url)
  53. rsp, err := Request(ctx).SetHeaders(headers).SetBody(req).Post(url)
  54. if err != nil {
  55. common.GinLog.Errorf("OrderRightsModify err:%s", err.Error())
  56. return nil, err
  57. }
  58. rspInfo := OrderRightsModifyRsp{}
  59. if err := json.Unmarshal(rsp.Body(), &rspInfo); err != nil {
  60. common.GinLog.Errorf("OrderRightsModify json unmarshal err:%s,rsp:%+v", err.Error(), rsp.String())
  61. return nil, err
  62. }
  63. common.GinLog.Info("OrderRightsModify rsp:%+v", rsp.String())
  64. return &rspInfo, nil
  65. }