295 lines
7.0 KiB
Go
295 lines
7.0 KiB
Go
|
package controller
|
||
|
|
||
|
import (
|
||
|
"github.com/codinl/go-logger"
|
||
|
"github.com/gin-gonic/gin"
|
||
|
"mh-server/lib/auth"
|
||
|
"mh-server/lib/status"
|
||
|
"mh-server/lib/xianmai"
|
||
|
"mh-server/model"
|
||
|
)
|
||
|
|
||
|
func GameCassetteList(c *gin.Context) {
|
||
|
req := struct {
|
||
|
Keyword string `json:"keyword"`
|
||
|
PageNum int `json:"page_num"`
|
||
|
PageSize int `json:"page_size"`
|
||
|
}{}
|
||
|
if c.ShouldBindJSON(&req) != nil {
|
||
|
logger.Error("ShouldBindJSON err")
|
||
|
RespJson(c, status.BadRequest, nil)
|
||
|
return
|
||
|
}
|
||
|
cassettes, count, err := xianmai.GameCassetteList(req.Keyword, req.PageNum, req.PageSize)
|
||
|
if err != nil {
|
||
|
logger.Error("game cassette err", err)
|
||
|
RespJson(c, status.InternalServerError, nil)
|
||
|
return
|
||
|
}
|
||
|
|
||
|
ret := map[string]interface{}{
|
||
|
"count": count,
|
||
|
"list": cassettes,
|
||
|
"pageIndex": req.PageNum,
|
||
|
"total_page": req.PageSize,
|
||
|
}
|
||
|
|
||
|
RespOK(c, ret)
|
||
|
return
|
||
|
}
|
||
|
|
||
|
func GameCheckGoods(c *gin.Context) {
|
||
|
req := xianmai.GameCheckGoodsReq{}
|
||
|
if c.ShouldBindJSON(&req) != nil {
|
||
|
logger.Error("ShouldBindJSON err")
|
||
|
RespJson(c, status.BadRequest, nil)
|
||
|
return
|
||
|
}
|
||
|
resp, err := req.Get()
|
||
|
if err != nil {
|
||
|
logger.Error("game cassette err", err)
|
||
|
RespJson(c, status.InternalServerError, nil)
|
||
|
return
|
||
|
}
|
||
|
|
||
|
RespOK(c, resp)
|
||
|
return
|
||
|
}
|
||
|
|
||
|
func GameEvaluation(c *gin.Context) {
|
||
|
req := xianmai.GameEvaluationReq{}
|
||
|
if c.ShouldBindJSON(&req) != nil {
|
||
|
logger.Error("ShouldBindJSON err")
|
||
|
RespJson(c, status.BadRequest, nil)
|
||
|
return
|
||
|
}
|
||
|
price, err := req.Evaluation()
|
||
|
if err != nil {
|
||
|
logger.Error("game cassette err", err)
|
||
|
RespJson(c, status.InternalServerError, nil)
|
||
|
return
|
||
|
}
|
||
|
|
||
|
ret := map[string]interface{}{
|
||
|
"price": price,
|
||
|
}
|
||
|
RespOK(c, ret)
|
||
|
return
|
||
|
}
|
||
|
|
||
|
func RecycleCardCreateOrder(c *gin.Context) {
|
||
|
req := xianmai.GameEvaluationReq{}
|
||
|
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
|
||
|
}
|
||
|
//uc = &auth.UserClaims{Uid: 8588420}
|
||
|
order, err := model.RecycleCardOrderCreate(uc.Uid, req)
|
||
|
if err != nil {
|
||
|
logger.Error("game cassette err", err)
|
||
|
RespJson(c, status.InternalServerError, nil)
|
||
|
return
|
||
|
}
|
||
|
|
||
|
RespOK(c, order)
|
||
|
return
|
||
|
}
|
||
|
|
||
|
func RecycleCardOrderList(c *gin.Context) {
|
||
|
req := model.RecycleCardOrderListReq{}
|
||
|
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
|
||
|
}
|
||
|
//uc = &auth.UserClaims{Uid: 8588420}
|
||
|
req.Uid = uc.Uid
|
||
|
orders, totalPage, err := req.List()
|
||
|
if err != nil {
|
||
|
logger.Error("game cassette err", err)
|
||
|
RespJson(c, status.InternalServerError, nil)
|
||
|
return
|
||
|
}
|
||
|
|
||
|
ret := map[string]interface{}{
|
||
|
"list": orders,
|
||
|
"cur_page": req.PageIdx,
|
||
|
"total_page": totalPage,
|
||
|
}
|
||
|
|
||
|
RespOK(c, ret)
|
||
|
return
|
||
|
}
|
||
|
|
||
|
func RecycleCardOrderDetail(c *gin.Context) {
|
||
|
req := struct {
|
||
|
OrderId uint32 `json:"order_id" binding:"required"`
|
||
|
}{}
|
||
|
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
|
||
|
}
|
||
|
//uc = &auth.UserClaims{Uid: 8588420}
|
||
|
user := model.GetUserByUid(uc.Uid)
|
||
|
var order model.RecycleCardOrder
|
||
|
err := model.NewRecycleCardOrderQuerySet(model.DB).IDEq(req.OrderId).One(&order)
|
||
|
if err != nil {
|
||
|
logger.Error("game cassette err", err)
|
||
|
RespJson(c, status.InternalServerError, nil)
|
||
|
return
|
||
|
}
|
||
|
order.User = user
|
||
|
|
||
|
RespOK(c, order)
|
||
|
return
|
||
|
}
|
||
|
|
||
|
func RecycleCardOrderCancel(c *gin.Context) {
|
||
|
req := struct {
|
||
|
OrderId uint32 `json:"order_id" binding:"required"`
|
||
|
}{}
|
||
|
if c.ShouldBindJSON(&req) != nil {
|
||
|
logger.Error("ShouldBindJSON err")
|
||
|
RespJson(c, status.BadRequest, nil)
|
||
|
return
|
||
|
}
|
||
|
|
||
|
var order model.RecycleCardOrder
|
||
|
err := model.NewRecycleCardOrderQuerySet(model.DB).IDEq(req.OrderId).One(&order)
|
||
|
if err != nil {
|
||
|
logger.Error("game cassette err:", err)
|
||
|
RespJson(c, status.InternalServerError, nil)
|
||
|
return
|
||
|
}
|
||
|
if order.State != 1 {
|
||
|
logger.Error("order state err")
|
||
|
RespJson(c, status.StateNotCancel, nil)
|
||
|
return
|
||
|
}
|
||
|
err = model.NewRecycleCardOrderQuerySet(model.DB).IDEq(req.OrderId).GetUpdater().
|
||
|
SetState(4).Update()
|
||
|
if err != nil {
|
||
|
logger.Error("game cassette err", err)
|
||
|
RespJson(c, status.InternalServerError, nil)
|
||
|
return
|
||
|
}
|
||
|
order.State = 4
|
||
|
RespOK(c, order)
|
||
|
return
|
||
|
}
|
||
|
|
||
|
func RecycleCardOrderImageUpdate(c *gin.Context) {
|
||
|
req := struct {
|
||
|
OrderId uint32 `json:"order_id" binding:"required"`
|
||
|
Images string `json:"images" binding:"required"`
|
||
|
}{}
|
||
|
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
|
||
|
}
|
||
|
|
||
|
//uc = &auth.UserClaims{Uid: 8588420}
|
||
|
assistant := model.GetUserByUid(uc.Uid)
|
||
|
if assistant.UserType != 2 {
|
||
|
logger.Error("not assistant")
|
||
|
RespJson(c, status.InternalServerError, nil)
|
||
|
return
|
||
|
}
|
||
|
|
||
|
err := model.NewRecycleCardOrderQuerySet(model.DB).IDEq(req.OrderId).GetUpdater().
|
||
|
SetImages(req.Images).Update()
|
||
|
if err != nil {
|
||
|
logger.Error("game cassette err", err)
|
||
|
RespJson(c, status.InternalServerError, nil)
|
||
|
return
|
||
|
}
|
||
|
operationLog := &model.OperationLog{
|
||
|
Uid: assistant.Uid,
|
||
|
Description: "回收卡上传图片",
|
||
|
OperationType: model.OperationTypeRecycleCardOrderImageUpdate,
|
||
|
CorrelationName: model.LogCorrelationRecycleCardOrderId,
|
||
|
StoreId: uint32(assistant.StoreId),
|
||
|
StoreName: "",
|
||
|
CooperativeName: assistant.CooperativeName,
|
||
|
CooperativeBusinessId: assistant.CooperativeBusinessId,
|
||
|
}
|
||
|
operationLog.AddLog()
|
||
|
RespOK(c, nil)
|
||
|
return
|
||
|
}
|
||
|
|
||
|
func RecycleCardOrderCheck(c *gin.Context) {
|
||
|
req := struct {
|
||
|
OrderId uint32 `json:"order_id" binding:"required"`
|
||
|
}{}
|
||
|
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
|
||
|
}
|
||
|
|
||
|
//uc = &auth.UserClaims{Uid: 8588420}
|
||
|
assistant := model.GetUserByUid(uc.Uid)
|
||
|
if assistant.UserType != 2 {
|
||
|
logger.Error("not assistant")
|
||
|
RespJson(c, status.InternalServerError, nil)
|
||
|
return
|
||
|
}
|
||
|
|
||
|
//err := model.NewRecycleCardOrderQuerySet(model.DB).IDEq(req.OrderId).GetUpdater().
|
||
|
// SetImages(req.Images).Update()
|
||
|
//if err != nil {
|
||
|
// logger.Error("game cassette err", err)
|
||
|
// RespJson(c, status.InternalServerError, nil)
|
||
|
// return
|
||
|
//}
|
||
|
operationLog := &model.OperationLog{
|
||
|
Uid: assistant.Uid,
|
||
|
Description: "回收卡上传图片",
|
||
|
OperationType: model.OperationTypeRecycleCardOrderImageUpdate,
|
||
|
CorrelationName: model.LogCorrelationRecycleCardOrderId,
|
||
|
StoreId: uint32(assistant.StoreId),
|
||
|
StoreName: "",
|
||
|
CooperativeName: assistant.CooperativeName,
|
||
|
CooperativeBusinessId: assistant.CooperativeBusinessId,
|
||
|
}
|
||
|
operationLog.AddLog()
|
||
|
RespOK(c, nil)
|
||
|
return
|
||
|
}
|