v002.go 1.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081
  1. // Copyright 2019 gentensh.com. All rights reserved.
  2. // Use of this source code is governed by gentensh.com.
  3. package vehicle
  4. import (
  5. "context"
  6. "gd_vehicle/apis"
  7. "gd_vehicle/consts"
  8. "gd_vehicle/errors"
  9. "gd_vehicle/impl/thirdparty_impl"
  10. dutils "gd_vehicle/utils"
  11. "math/rand"
  12. )
  13. // 二要素验证,返回车档
  14. func V002(ctx context.Context, req *apis.CommonReq, reply *apis.CommonReply) error {
  15. rData := req.Data.(map[string]interface{})
  16. plateNo := dutils.GetStringParams(rData,"plate_no")
  17. plateType := dutils.GetStringParams(rData,"plate_type")
  18. owner := dutils.GetStringParams(rData,"owner")
  19. respData := make(map[string]interface{})
  20. reply.Data = respData
  21. tReq := &apis.ThirdpartRequest{
  22. Ctx: ctx,
  23. Params: map[string]interface{}{
  24. "plate_no": plateNo,
  25. "plate_type": plateType,
  26. "owner": owner,
  27. },
  28. ProviderApiCode: dutils.ADMA04,
  29. ProviderMap: req.ProviderMap,
  30. RangeNo: consts.RANGEONE,
  31. Req: req,
  32. Reply: reply,
  33. }
  34. if !req.IsForceUpdate{
  35. tReq.Params["merchant_tag"] = "1"
  36. }
  37. err := thirdparty_impl.CallThirdparty(tReq,respData)
  38. if err != nil {
  39. return errors.NoRecord
  40. }
  41. tReq.ProviderApiCode = dutils.ADMV01
  42. err = thirdparty_impl.CallThirdparty(tReq,respData)
  43. if err != nil {
  44. if req.IsForceUpdate{
  45. return errors.NoRecord
  46. }else{
  47. if err == errors.NoRecordCannotConfirm{
  48. return errors.NoRecord
  49. }else if err == errors.NoRecord{
  50. // 大于3个字的认为是公司名,查无表示公司名已通过校验
  51. if len(owner) > 9 {
  52. respData["is_match"] = "1"
  53. }else {
  54. return errors.NoRecord
  55. }
  56. } else {
  57. return errors.NoRecord
  58. }
  59. }
  60. }else{
  61. if req.RandomPercentage > 0 {
  62. randInt := rand.Intn(100)
  63. if randInt <= req.RandomPercentage{
  64. return errors.NoRecord
  65. }
  66. }
  67. }
  68. return nil
  69. }