mh_server/controller/cb_rent_order.go

140 lines
3.0 KiB
Go
Raw Normal View History

2022-05-10 07:17:34 +00:00
package controller
import (
"github.com/codinl/go-logger"
"github.com/gin-gonic/gin"
"mh-server/lib/auth"
"mh-server/lib/status"
"mh-server/model"
)
func CooperativeRentCardOrderList(c *gin.Context) {
req := model.CooperativeRentCardOrderListReq{}
if c.ShouldBindJSON(&req) != nil {
logger.Error("ShouldBindJSON err")
RespJson(c, status.BadRequest, nil)
return
}
uc := auth.GetCurrentUser(c)
if uc == nil {
logger.Error("uc is nil")
RespJson(c, status.Unauthorized, nil)
return
}
req.AssistantUid = uc.Uid
list, count, err := req.List()
if err != nil {
2022-05-28 07:24:17 +00:00
logger.Errorf("err:%#v", err)
2022-05-10 07:17:34 +00:00
RespJson(c, status.InternalServerError, nil)
return
}
ret := map[string]interface{}{
"count": count,
"list": list,
"pageIndex": req.PageNum,
"total_page": req.PageSize,
}
RespOK(c, ret)
return
}
func CooperativeRentCardOrderInfo(c *gin.Context) {
req := model.CooperativeRentCardOrderReq{}
if c.ShouldBindJSON(&req) != nil {
logger.Error("ShouldBindJSON err")
RespJson(c, status.BadRequest, nil)
return
}
uc := auth.GetCurrentUser(c)
if uc == nil {
logger.Error("uc is nil")
RespJson(c, status.Unauthorized, nil)
return
}
2022-05-12 05:42:45 +00:00
assistant := model.GetUserByUid(uc.Uid)
if assistant.UserType != 2 {
logger.Error("not assistant")
RespJson(c, status.InternalServerError, nil)
return
}
2022-05-10 07:17:34 +00:00
order, err := req.Info()
if err != nil {
logger.Error("rent card order err:", err)
if err.Error() == "parameter_err" {
RespJson(c, status.BadRequest, nil)
} else {
RespJson(c, status.InternalServerError, nil)
}
return
}
RespOK(c, order)
return
}
func CooperativeRentCardOrderDeliver(c *gin.Context) {
req := model.CooperativeRentCardOrderDeliverReq{}
if c.ShouldBindJSON(&req) != nil {
logger.Error("ShouldBindJSON err")
RespJson(c, status.BadRequest, nil)
return
}
uc := auth.GetCurrentUser(c)
if uc == nil {
logger.Error("uc is nil")
RespJson(c, status.Unauthorized, nil)
return
}
assistant := model.GetUserByUid(uc.Uid)
2022-05-12 05:42:45 +00:00
if assistant.UserType != 2 {
logger.Error("not assistant")
RespJson(c, status.InternalServerError, nil)
return
}
2022-05-10 07:17:34 +00:00
req.OperationUid = uc.Uid
req.StoreId = uint32(assistant.StoreId)
err, _ := req.Deliver()
if err != nil {
logger.Error("rent card order err:", err)
RespJson(c, status.InternalServerError, nil)
return
}
RespOK(c, nil)
return
}
func CooperativeRentCardOrderRevert(c *gin.Context) {
req := model.CooperativeRentCardOrderRevertReq{}
if c.ShouldBindJSON(&req) != nil {
logger.Error("ShouldBindJSON err")
RespJson(c, status.BadRequest, nil)
return
}
uc := auth.GetCurrentUser(c)
if uc == nil {
logger.Error("uc is nil")
RespJson(c, status.Unauthorized, nil)
return
}
2022-05-12 05:42:45 +00:00
assistant := model.GetUserByUid(uc.Uid)
if assistant.UserType != 2 {
logger.Error("not assistant")
RespJson(c, status.InternalServerError, nil)
return
}
2022-05-10 07:17:34 +00:00
req.OperationUid = uc.Uid
err := req.Revert()
if err != nil {
logger.Error("rent card order revert err:", err)
RespJson(c, status.InternalServerError, nil)
return
}
RespOK(c, nil)
return
}