123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596 |
- // Copyright 2019 getensh.com. All rights reserved.
- // Use of this source code is governed by getensh.com.
- package house_rent
- import (
- "context"
- "encoding/json"
- "fmt"
- "git.getensh.com/common/gopkgs/database"
- "git.getensh.com/common/gopkgs/logger"
- "go.uber.org/zap"
- "google.golang.org/grpc/status"
- "gorm.io/gorm"
- "property-household/errors"
- "property-household/impl/v1/public_msg"
- dbmodel "property-household/model"
- pb_v1 "property-household/pb/v1"
- "time"
- )
- //
- func HouseRentAppointmentStatus(ctx context.Context, req *pb_v1.HouseRentAppointmentStatusRequest) (reply *pb_v1.HouseRentAppointmentStatusReply, err error) {
- reply = &pb_v1.HouseRentAppointmentStatusReply{}
- // 捕获各个task中的异常并返回给调用者
- defer func() {
- if r := recover(); r != nil {
- err = fmt.Errorf("%+v", r)
- e := &status.Status{}
- if er := json.Unmarshal([]byte(err.Error()), e); er != nil {
- logger.Error("err",
- zap.String("system_err", err.Error()),
- zap.Stack("stacktrace"))
- }
- }
- }()
- // 参数检查
- if req.Id < 1 || req.GardenId < 1 {
- return nil, errors.ParamsError
- }
- if req.Status > HouseRentAppointmentVisited ||
- req.Status < HouseRentAppointmentAccess {
- return nil, status.Error(10003, "状态错误")
- }
- p := dbmodel.THouseRentAppointment{}
- where := map[string]interface{}{
- "id": req.Id,
- "garden_id": req.GardenId,
- }
- err = p.Find(database.DB(), where)
- if err != nil && err != gorm.ErrRecordNotFound {
- return nil, errors.DataBaseError
- }
- if p.ID == 0 {
- return nil, errors.ErrRecordNotFound
- }
- switch p.Status {
- //case HouseRentAppointmentWait:
- //case HouseRentAppointmentAccess:
- case HouseRentAppointmentRefruse:
- return nil, status.Error(10003, "当前状态不能修改")
- case HouseRentAppointmentNotVisit:
- return nil, status.Error(10003, "当前状态不能修改")
- //case HouseRentAppointmentVisited:
- }
- values := map[string]interface{}{
- "feedback": req.Feedback,
- "status": req.Status,
- "updated_at": time.Now(),
- }
- oldStatus := p.Status
- err = p.Update(database.DB(), where, values)
- if err != nil {
- return nil, errors.DataBaseError
- }
- if req.Status == oldStatus {
- return reply, nil
- }
- serviceInfo := public_msg.ServiceInfo{
- Name: "预约看房",
- State: HouseRentAppointmentStatusM[int(req.Status)],
- }
- public_msg.SendMsgWx(p.Uid, p.GardenId, serviceInfo)
- return reply, nil
- }
|