2022-08-01 07:14:53 +00:00
|
|
|
package controller
|
|
|
|
|
|
|
|
import (
|
|
|
|
"github.com/codinl/go-logger"
|
|
|
|
"github.com/gin-gonic/gin"
|
|
|
|
"mh-server/lib/auth"
|
|
|
|
"mh-server/lib/status"
|
2022-08-12 02:41:33 +00:00
|
|
|
"mh-server/lib/wxpay"
|
2022-08-01 07:14:53 +00:00
|
|
|
"mh-server/lib/xianmai"
|
|
|
|
"mh-server/model"
|
2022-08-12 02:41:33 +00:00
|
|
|
"time"
|
2022-08-01 07:14:53 +00:00
|
|
|
)
|
|
|
|
|
|
|
|
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
|
|
|
|
}
|
2022-08-12 02:41:33 +00:00
|
|
|
if count == 0 {
|
|
|
|
count = 1
|
|
|
|
}
|
2022-08-01 07:14:53 +00:00
|
|
|
ret := map[string]interface{}{
|
2022-08-12 02:41:33 +00:00
|
|
|
//"count": count,
|
2022-08-01 07:14:53 +00:00
|
|
|
"list": cassettes,
|
|
|
|
"pageIndex": req.PageNum,
|
2022-08-12 02:41:33 +00:00
|
|
|
"pageSize": req.PageSize,
|
|
|
|
"total_page": count,
|
2022-08-01 07:14:53 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
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
|
|
|
|
}
|
2022-08-12 02:41:33 +00:00
|
|
|
info, err := model.RecycleCardConfigInfo()
|
|
|
|
if err != nil {
|
|
|
|
logger.Error("config err:", err)
|
|
|
|
RespJson(c, status.InternalServerError, nil)
|
|
|
|
return
|
|
|
|
}
|
2022-08-01 07:14:53 +00:00
|
|
|
|
2022-08-12 02:41:33 +00:00
|
|
|
if info.RebateRate > 0 && info.RebateRate < 10000 {
|
|
|
|
price = (price * int(10000-info.RebateRate)) / 100
|
|
|
|
} else {
|
|
|
|
price = price * 100
|
|
|
|
}
|
|
|
|
if price > 70000 {
|
|
|
|
logger.Error("price err")
|
|
|
|
RespJson(c, status.InternalServerError, nil)
|
|
|
|
return
|
|
|
|
}
|
|
|
|
price = (price / 100) * 100
|
|
|
|
//price = 40 // TODO
|
2022-08-01 07:14:53 +00:00
|
|
|
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
|
|
|
|
}
|
2022-08-12 02:41:33 +00:00
|
|
|
//uc := auth.GetCurrentUser(c)
|
|
|
|
//if uc == nil {
|
|
|
|
// logger.Error("uc is nil")
|
|
|
|
// RespJson(c, status.Unauthorized, nil)
|
|
|
|
// return
|
|
|
|
//}
|
2022-08-01 07:14:53 +00:00
|
|
|
//uc = &auth.UserClaims{Uid: 8588420}
|
2022-08-12 02:41:33 +00:00
|
|
|
|
2022-08-01 07:14:53 +00:00
|
|
|
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
|
|
|
|
}
|
2022-08-12 02:41:33 +00:00
|
|
|
user := model.GetUserByUid(order.Uid)
|
2022-08-01 07:14:53 +00:00
|
|
|
order.User = user
|
2022-08-12 02:41:33 +00:00
|
|
|
store, err := model.GetStore(order.StoreId)
|
|
|
|
if err != nil {
|
|
|
|
logger.Error("order store err:", err)
|
|
|
|
RespJson(c, status.InternalServerError, nil)
|
|
|
|
return
|
|
|
|
}
|
|
|
|
order.Store = store
|
2022-08-01 07:14:53 +00:00
|
|
|
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
|
|
|
|
}
|
2022-08-12 02:41:33 +00:00
|
|
|
var order model.RecycleCardOrder
|
|
|
|
err := model.NewRecycleCardOrderQuerySet(model.DB).IDEq(req.OrderId).One(&order)
|
|
|
|
if err != nil {
|
|
|
|
logger.Error("order err:%#v", err)
|
|
|
|
RespJson(c, status.InternalServerError, nil)
|
|
|
|
return
|
|
|
|
}
|
|
|
|
if order.State != 1 {
|
|
|
|
logger.Error("order state err")
|
|
|
|
RespJson(c, status.InternalServerError, nil)
|
|
|
|
return
|
|
|
|
}
|
|
|
|
userInfo := model.GetUserByUid(order.Uid)
|
|
|
|
if userInfo == nil {
|
|
|
|
logger.Error("user info err:", err)
|
|
|
|
RespJson(c, status.InternalServerError, nil)
|
|
|
|
return
|
|
|
|
}
|
|
|
|
//order.Price = 40 // TODO
|
2022-08-01 07:14:53 +00:00
|
|
|
|
2022-08-12 02:41:33 +00:00
|
|
|
transfer, err := wxpay.Transfer(order.Price, userInfo.WxOpenID, "回收卡带")
|
|
|
|
if err != nil {
|
|
|
|
logger.Error("err:", err)
|
|
|
|
RespJson(c, status.InternalServerError, nil)
|
|
|
|
return
|
|
|
|
}
|
|
|
|
|
|
|
|
err = model.NewRecycleCardOrderQuerySet(model.DB).IDEq(req.OrderId).GetUpdater().
|
|
|
|
SetImages(req.Images).SetState(2).SetCheckTime(time.Now()).
|
2022-08-15 09:51:41 +00:00
|
|
|
SetAssistantName(assistant.ShopAssistantName).SetRetrieveState(1).Update()
|
2022-08-01 07:14:53 +00:00
|
|
|
if err != nil {
|
|
|
|
logger.Error("game cassette err", err)
|
|
|
|
RespJson(c, status.InternalServerError, nil)
|
|
|
|
return
|
|
|
|
}
|
2022-08-12 02:41:33 +00:00
|
|
|
|
|
|
|
fundRecord := &model.FundRecord{
|
|
|
|
Uid: order.Uid,
|
|
|
|
FundType: model.FundTypeRecycleCard,
|
|
|
|
Amount: int64(order.Price) * (-1),
|
|
|
|
OutTradeNo: transfer.PartnerTradeNo,
|
|
|
|
PaymentNo: transfer.PaymentNo,
|
|
|
|
Status: 2,
|
|
|
|
Remark: "回收卡带",
|
|
|
|
//TransactionId: ,
|
|
|
|
}
|
|
|
|
err = model.DB.Create(fundRecord).Error
|
|
|
|
if err != nil {
|
|
|
|
logger.Error("create fund record err:", err)
|
|
|
|
}
|
|
|
|
|
2022-08-01 07:14:53 +00:00
|
|
|
operationLog := &model.OperationLog{
|
|
|
|
Uid: assistant.Uid,
|
2022-08-12 02:41:33 +00:00
|
|
|
Description: "回收卡带转款",
|
2022-08-01 07:14:53 +00:00
|
|
|
OperationType: model.OperationTypeRecycleCardOrderImageUpdate,
|
2022-08-12 02:41:33 +00:00
|
|
|
CorrelationId: order.ID,
|
2022-08-01 07:14:53 +00:00
|
|
|
CorrelationName: model.LogCorrelationRecycleCardOrderId,
|
|
|
|
StoreId: uint32(assistant.StoreId),
|
|
|
|
StoreName: "",
|
|
|
|
CooperativeName: assistant.CooperativeName,
|
|
|
|
CooperativeBusinessId: assistant.CooperativeBusinessId,
|
2022-08-12 02:41:33 +00:00
|
|
|
Detail: "",
|
2022-08-01 07:14:53 +00:00
|
|
|
}
|
|
|
|
operationLog.AddLog()
|
2022-08-12 02:41:33 +00:00
|
|
|
|
2022-08-01 07:14:53 +00:00
|
|
|
RespOK(c, nil)
|
|
|
|
return
|
|
|
|
}
|
|
|
|
|
|
|
|
func RecycleCardOrderCheck(c *gin.Context) {
|
|
|
|
req := struct {
|
2022-08-12 02:41:33 +00:00
|
|
|
OrderId uint32 `json:"order_id" binding:"required"`
|
|
|
|
CheckType uint32 `json:"check_type" binding:"required"` // 1-拒绝
|
2022-08-01 07:14:53 +00:00
|
|
|
}{}
|
|
|
|
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-08-12 02:41:33 +00:00
|
|
|
var order model.RecycleCardOrder
|
|
|
|
err := model.NewRecycleCardOrderQuerySet(model.DB).IDEq(req.OrderId).One(&order)
|
|
|
|
if err != nil {
|
|
|
|
logger.Error("recycle card order err:", err)
|
|
|
|
return
|
|
|
|
}
|
|
|
|
if order.State != 1 {
|
|
|
|
logger.Error("order state err")
|
|
|
|
RespJson(c, status.InternalServerError, nil)
|
|
|
|
return
|
|
|
|
}
|
2022-08-01 07:14:53 +00:00
|
|
|
//uc = &auth.UserClaims{Uid: 8588420}
|
|
|
|
assistant := model.GetUserByUid(uc.Uid)
|
|
|
|
if assistant.UserType != 2 {
|
|
|
|
logger.Error("not assistant")
|
|
|
|
RespJson(c, status.InternalServerError, nil)
|
|
|
|
return
|
|
|
|
}
|
|
|
|
|
2022-08-12 02:41:33 +00:00
|
|
|
if req.CheckType == 1 {
|
|
|
|
err := model.NewRecycleCardOrderQuerySet(model.DB).IDEq(req.OrderId).GetUpdater().
|
2022-08-15 09:51:41 +00:00
|
|
|
SetState(3).SetCheckTime(time.Now()).SetAssistantName(assistant.ShopAssistantName).
|
|
|
|
Update()
|
2022-08-12 02:41:33 +00:00
|
|
|
if err != nil {
|
|
|
|
logger.Error("update recycle card order err:", err)
|
|
|
|
return
|
|
|
|
}
|
2022-08-01 07:14:53 +00:00
|
|
|
}
|
2022-08-12 02:41:33 +00:00
|
|
|
|
2022-08-01 07:14:53 +00:00
|
|
|
RespOK(c, nil)
|
|
|
|
return
|
|
|
|
}
|
2022-08-12 02:41:33 +00:00
|
|
|
|
|
|
|
func ConsoleRecycleCardOrderList(c *gin.Context) {
|
|
|
|
req := model.ConsoleRecycleCardOrderListReq{}
|
|
|
|
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)
|
|
|
|
if user != nil {
|
|
|
|
req.StoreId = uint32(user.StoreId)
|
|
|
|
}
|
|
|
|
|
|
|
|
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
|
|
|
|
}
|