pay_mode_set.go 1.6 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667
  1. // Copyright 2019 getensh.com. All rights reserved.
  2. // Use of this source code is governed by getensh.com.
  3. package garden
  4. import (
  5. "context"
  6. "encoding/json"
  7. "fmt"
  8. "gorm.io/gorm"
  9. "property-system/errors"
  10. dbmodel "property-system/model"
  11. pb_v1 "property-system/pb/v1"
  12. "git.getensh.com/common/gopkgs/database"
  13. "git.getensh.com/common/gopkgs/logger"
  14. "go.uber.org/zap"
  15. "google.golang.org/grpc/status"
  16. )
  17. //
  18. func GardenSetMchPayMode(ctx context.Context, req *pb_v1.GardenSetMchPayModeRequest) (reply *pb_v1.GardenSetMchPayModeReply, err error) {
  19. reply = &pb_v1.GardenSetMchPayModeReply{}
  20. // 捕获各个task中的异常并返回给调用者
  21. defer func() {
  22. if r := recover(); r != nil {
  23. err = fmt.Errorf("%+v", r)
  24. e := &status.Status{}
  25. if er := json.Unmarshal([]byte(err.Error()), e); er != nil {
  26. logger.Error("err",
  27. zap.String("system_err", err.Error()),
  28. zap.Stack("stacktrace"))
  29. }
  30. }
  31. }()
  32. if req.Cid < 1 && req.GardenId < 1 && (req.PayMode < 1 || req.PayMode > 3) {
  33. return nil, errors.ParamsError
  34. }
  35. p := dbmodel.TGardenApproved{}
  36. where := map[string]interface{}{
  37. "cid": req.Cid,
  38. "id": req.GardenId,
  39. }
  40. err = p.Find(database.DB(), where)
  41. if err != nil && err != gorm.ErrRecordNotFound {
  42. return nil, errors.DataBaseError
  43. }
  44. if p.ID == 0 {
  45. return nil, errors.ErrRecordNotFound
  46. }
  47. if req.PayMode == 2 && p.MchId == "" {
  48. return nil, status.Error(10003, "支付到物业公司账户请先设置商户号")
  49. }
  50. values := map[string]interface{}{
  51. "pay_mode": req.PayMode,
  52. }
  53. err = p.Update(database.DB(), where, values)
  54. if err != nil {
  55. return nil, errors.DataBaseError
  56. }
  57. return reply, nil
  58. }