appointment_status.go 2.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596
  1. // Copyright 2019 getensh.com. All rights reserved.
  2. // Use of this source code is governed by getensh.com.
  3. package house_rent
  4. import (
  5. "context"
  6. "encoding/json"
  7. "fmt"
  8. "git.getensh.com/common/gopkgs/database"
  9. "git.getensh.com/common/gopkgs/logger"
  10. "go.uber.org/zap"
  11. "google.golang.org/grpc/status"
  12. "gorm.io/gorm"
  13. "property-household/errors"
  14. "property-household/impl/v1/public_msg"
  15. dbmodel "property-household/model"
  16. pb_v1 "property-household/pb/v1"
  17. "time"
  18. )
  19. //
  20. func HouseRentAppointmentStatus(ctx context.Context, req *pb_v1.HouseRentAppointmentStatusRequest) (reply *pb_v1.HouseRentAppointmentStatusReply, err error) {
  21. reply = &pb_v1.HouseRentAppointmentStatusReply{}
  22. // 捕获各个task中的异常并返回给调用者
  23. defer func() {
  24. if r := recover(); r != nil {
  25. err = fmt.Errorf("%+v", r)
  26. e := &status.Status{}
  27. if er := json.Unmarshal([]byte(err.Error()), e); er != nil {
  28. logger.Error("err",
  29. zap.String("system_err", err.Error()),
  30. zap.Stack("stacktrace"))
  31. }
  32. }
  33. }()
  34. // 参数检查
  35. if req.Id < 1 || req.GardenId < 1 {
  36. return nil, errors.ParamsError
  37. }
  38. if req.Status > HouseRentAppointmentVisited ||
  39. req.Status < HouseRentAppointmentAccess {
  40. return nil, status.Error(10003, "状态错误")
  41. }
  42. p := dbmodel.THouseRentAppointment{}
  43. where := map[string]interface{}{
  44. "id": req.Id,
  45. "garden_id": req.GardenId,
  46. }
  47. err = p.Find(database.DB(), where)
  48. if err != nil && err != gorm.ErrRecordNotFound {
  49. return nil, errors.DataBaseError
  50. }
  51. if p.ID == 0 {
  52. return nil, errors.ErrRecordNotFound
  53. }
  54. switch p.Status {
  55. //case HouseRentAppointmentWait:
  56. //case HouseRentAppointmentAccess:
  57. case HouseRentAppointmentRefruse:
  58. return nil, status.Error(10003, "当前状态不能修改")
  59. case HouseRentAppointmentNotVisit:
  60. return nil, status.Error(10003, "当前状态不能修改")
  61. //case HouseRentAppointmentVisited:
  62. }
  63. values := map[string]interface{}{
  64. "feedback": req.Feedback,
  65. "status": req.Status,
  66. "updated_at": time.Now(),
  67. }
  68. oldStatus := p.Status
  69. err = p.Update(database.DB(), where, values)
  70. if err != nil {
  71. return nil, errors.DataBaseError
  72. }
  73. if req.Status == oldStatus {
  74. return reply, nil
  75. }
  76. serviceInfo := public_msg.ServiceInfo{
  77. Name: "预约看房",
  78. State: HouseRentAppointmentStatusM[int(req.Status)],
  79. }
  80. public_msg.SendMsgWx(p.Uid, p.GardenId, serviceInfo)
  81. return reply, nil
  82. }