feat:回收卡
This commit is contained in:
parent
581633ebe6
commit
5f1dbcaa72
294
controller/recycle_card.go
Normal file
294
controller/recycle_card.go
Normal file
|
@ -0,0 +1,294 @@
|
|||
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
|
||||
}
|
147
lib/xianmai/xian.go
Normal file
147
lib/xianmai/xian.go
Normal file
|
@ -0,0 +1,147 @@
|
|||
package xianmai
|
||||
|
||||
import (
|
||||
"github.com/codinl/go-logger"
|
||||
"strconv"
|
||||
)
|
||||
|
||||
func GameCassetteList(keyword string, pageNum, pageSize int) ([]Cassette, int, error) {
|
||||
paraMap := map[string]interface{}{
|
||||
"keyword": keyword,
|
||||
"pageNum": pageNum,
|
||||
"pageSize": pageSize,
|
||||
}
|
||||
games := make([]Cassette, 0)
|
||||
resp := &GameCassetteListResp{}
|
||||
err := GetXianClient().post("game/cassetteList", paraMap, resp)
|
||||
if err != nil {
|
||||
logger.Error("err:", err)
|
||||
return games, 0, err
|
||||
}
|
||||
|
||||
for i, _ := range resp.Data1.List {
|
||||
cassette := Cassette{
|
||||
GoodsId: resp.Data1.List[i].GoodsId,
|
||||
GoodsName: resp.Data1.List[i].GoodsName,
|
||||
GoodsImg: resp.Data1.List[i].GoodsImg,
|
||||
Keyword: resp.Data1.List[i].Keyword,
|
||||
}
|
||||
games = append(games, cassette)
|
||||
}
|
||||
return games, resp.Data1.Pages, nil
|
||||
}
|
||||
|
||||
type GameCheckGoodsReq struct {
|
||||
GoodsId uint32 `json:"goods_id"`
|
||||
}
|
||||
|
||||
func (m *GameCheckGoodsReq) Get() (*XMCheckGoods, error) {
|
||||
paraMap := map[string]interface{}{
|
||||
"goodsId": m.GoodsId,
|
||||
}
|
||||
var xmGoods *XMCheckGoods
|
||||
resp := &GameCheckGoodsResp{}
|
||||
err := GetXianClient().post("game/check/goods", paraMap, resp)
|
||||
if err != nil {
|
||||
logger.Error("err:", err)
|
||||
return xmGoods, err
|
||||
}
|
||||
xmGoods = &XMCheckGoods{
|
||||
GoodsId: resp.Data1.GoodsId,
|
||||
GoodsName: resp.Data1.GoodsName,
|
||||
GoodsImg: resp.Data1.GoodsImg,
|
||||
}
|
||||
skus := make([]XMSkuTitle, 0)
|
||||
problems := make([]XMProblemTitle, 0)
|
||||
|
||||
for i, _ := range resp.Data1.SkuTitleVos {
|
||||
details := make([]XMSkuDetail, 0)
|
||||
skuTitle := XMSkuTitle{
|
||||
ProblemId: resp.Data1.SkuTitleVos[i].ProblemId,
|
||||
ProblemName: resp.Data1.SkuTitleVos[i].ProblemName,
|
||||
}
|
||||
for _, vo := range resp.Data1.SkuTitleVos[i].SkuDetailVoList {
|
||||
skuDetail := XMSkuDetail{
|
||||
ProblemValueId: vo.ProblemValueId,
|
||||
ProblemValueName: vo.ProblemValueName,
|
||||
}
|
||||
details = append(details, skuDetail)
|
||||
}
|
||||
skuTitle.List = details
|
||||
skus = append(skus, skuTitle)
|
||||
}
|
||||
|
||||
for i, _ := range resp.Data1.ProblemTitleVos {
|
||||
details := make([]XMSkuDetail, 0)
|
||||
problemTitle := XMProblemTitle{
|
||||
ProblemId: resp.Data1.ProblemTitleVos[i].ProblemId,
|
||||
ProblemName: resp.Data1.ProblemTitleVos[i].ProblemName,
|
||||
}
|
||||
for _, vo := range resp.Data1.ProblemTitleVos[i].ProblemDetailVoList {
|
||||
skuDetail := XMSkuDetail{
|
||||
ProblemValueId: vo.ProblemValueId,
|
||||
ProblemValueName: vo.ProblemValueName,
|
||||
}
|
||||
details = append(details, skuDetail)
|
||||
}
|
||||
problemTitle.List = details
|
||||
problems = append(problems, problemTitle)
|
||||
}
|
||||
xmGoods.Skus = skus
|
||||
xmGoods.Problems = problems
|
||||
|
||||
return xmGoods, nil
|
||||
}
|
||||
|
||||
type GameEvaluationReq struct {
|
||||
GoodsId int `json:"goods_id"`
|
||||
GoodsName string `json:"goods_name"`
|
||||
GoodsImg string `json:"goods_img"`
|
||||
Keyword string `json:"keyword"`
|
||||
StoreId uint32 `json:"store_id"`
|
||||
ProblemAttrList []struct {
|
||||
ProblemAttrName string `json:"problem_attr_name"`
|
||||
ProblemAttrId int `json:"problem_attr_id"`
|
||||
ProblemAttrValueName string `json:"problem_attr_value_name"`
|
||||
ProblemAttrValueId int `json:"problem_attr_value_id"`
|
||||
} `json:"problem_attr_list"`
|
||||
SkuList []struct {
|
||||
ProblemAttrName string `json:"problem_attr_name"`
|
||||
ProblemAttrId int `json:"problem_attr_id"`
|
||||
ProblemAttrValueName string `json:"problem_attr_value_name"`
|
||||
ProblemAttrValueId int `json:"problem_attr_value_id"`
|
||||
} `json:"sku_list"`
|
||||
}
|
||||
|
||||
func (m *GameEvaluationReq) Evaluation() (int, error) {
|
||||
paraMap := map[string]interface{}{
|
||||
"goodsId": m.GoodsId,
|
||||
}
|
||||
problems := make([]XMProblemAttr, 0)
|
||||
skus := make([]XMProblemAttr, 0)
|
||||
for i, _ := range m.ProblemAttrList {
|
||||
attr := XMProblemAttr{
|
||||
ProblemAttrId: strconv.Itoa(m.ProblemAttrList[i].ProblemAttrId),
|
||||
ProblemAttrValueId: strconv.Itoa(m.ProblemAttrList[i].ProblemAttrValueId),
|
||||
}
|
||||
problems = append(problems, attr)
|
||||
}
|
||||
for i, _ := range m.SkuList {
|
||||
attr := XMProblemAttr{
|
||||
ProblemAttrId: strconv.Itoa(m.SkuList[i].ProblemAttrId),
|
||||
ProblemAttrValueId: strconv.Itoa(m.SkuList[i].ProblemAttrValueId),
|
||||
}
|
||||
skus = append(skus, attr)
|
||||
}
|
||||
paraMap["problemAttrList"] = problems
|
||||
paraMap["skuList"] = skus
|
||||
|
||||
resp := &GameEvaluationResp{}
|
||||
err := GetXianClient().post("game/evaluation", paraMap, resp)
|
||||
if err != nil {
|
||||
logger.Error("err:", err)
|
||||
return 0, err
|
||||
}
|
||||
|
||||
return resp.Data, nil
|
||||
}
|
173
lib/xianmai/xian_http.go
Normal file
173
lib/xianmai/xian_http.go
Normal file
|
@ -0,0 +1,173 @@
|
|||
package xianmai
|
||||
|
||||
import (
|
||||
"encoding/json"
|
||||
"fmt"
|
||||
"io/ioutil"
|
||||
"net/http"
|
||||
"strings"
|
||||
)
|
||||
|
||||
type XianMaiClient struct {
|
||||
CustomPhone string `json:"custom_phone"`
|
||||
BaseURL string `json:"base_url"`
|
||||
}
|
||||
|
||||
var xian *XianMaiClient
|
||||
|
||||
func GetXianClient() *XianMaiClient {
|
||||
if xian == nil {
|
||||
xian = &XianMaiClient{
|
||||
CustomPhone: "17080320980",
|
||||
//BaseURL:"https://oam.xianmai.net.cn",
|
||||
BaseURL: "https://test.oam.xianmai.net.cn/",
|
||||
}
|
||||
}
|
||||
return xian
|
||||
}
|
||||
|
||||
func (m *XianMaiClient) post(xmApi string, params map[string]interface{}, resp interface{}) error {
|
||||
//params.Set("customPhone", m.CustomPhone)
|
||||
//uri := m.BaseURL + xmApi + params.Encode()
|
||||
params["customPhone"] = m.CustomPhone
|
||||
|
||||
uri := m.BaseURL + xmApi
|
||||
data, err := json.Marshal(params)
|
||||
if err != nil {
|
||||
fmt.Println(err)
|
||||
return err
|
||||
}
|
||||
|
||||
res, err := http.Post(uri, "application/json;charset=utf-8", strings.NewReader(string(data)))
|
||||
if err != nil {
|
||||
fmt.Println(err)
|
||||
return err
|
||||
}
|
||||
//headers["Content-Type"] = "application/json;charset=utf-8"
|
||||
//res.Header.Set("Content-Type", "application/x-www-form-urlencoded")
|
||||
defer res.Body.Close()
|
||||
|
||||
dataRsp, err := ioutil.ReadAll(res.Body)
|
||||
if err != nil {
|
||||
fmt.Println(err)
|
||||
return err
|
||||
}
|
||||
if err = json.Unmarshal(dataRsp, resp); err != nil {
|
||||
fmt.Println(err)
|
||||
return err
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
type GameCassetteListResp struct {
|
||||
Flag bool `json:"flag"`
|
||||
Code int `json:"code"`
|
||||
Message string `json:"message"`
|
||||
Data1 struct {
|
||||
Total int `json:"total"`
|
||||
List []struct {
|
||||
GoodsId int `json:"goodsId"`
|
||||
GoodsName string `json:"goodsName"`
|
||||
GoodsImg string `json:"goodsImg"`
|
||||
Keyword string `json:"keyword"`
|
||||
} `json:"list"`
|
||||
PageNum int `json:"pageNum"`
|
||||
PageSize int `json:"pageSize"`
|
||||
Size int `json:"size"`
|
||||
StartRow int `json:"startRow"`
|
||||
EndRow int `json:"endRow"`
|
||||
Pages int `json:"pages"`
|
||||
PrePage int `json:"prePage"`
|
||||
NextPage int `json:"nextPage"`
|
||||
IsFirstPage bool `json:"isFirstPage"`
|
||||
IsLastPage bool `json:"isLastPage"`
|
||||
HasPreviousPage bool `json:"hasPreviousPage"`
|
||||
HasNextPage bool `json:"hasNextPage"`
|
||||
NavigatePages int `json:"navigatePages"`
|
||||
NavigatepageNums []int `json:"navigatepageNums"`
|
||||
NavigateFirstPage int `json:"navigateFirstPage"`
|
||||
NavigateLastPage int `json:"navigateLastPage"`
|
||||
} `json:"data1"`
|
||||
Data interface{} `json:"data"`
|
||||
}
|
||||
|
||||
type Cassette struct {
|
||||
GoodsId int `json:"goods_id"`
|
||||
GoodsName string `json:"goods_name"`
|
||||
GoodsImg string `json:"goods_img"`
|
||||
Keyword string `json:"keyword"`
|
||||
}
|
||||
|
||||
type GameCheckGoodsResp struct {
|
||||
Flag bool `json:"flag"`
|
||||
Code int `json:"code"`
|
||||
Message string `json:"message"`
|
||||
Data1 struct {
|
||||
GoodsId int `json:"goodsId"`
|
||||
GoodsName string `json:"goodsName"`
|
||||
GoodsImg string `json:"goodsImg"`
|
||||
SkuTitleVos []struct {
|
||||
ProblemId int `json:"problemId"`
|
||||
ProblemName string `json:"problemName"`
|
||||
Interval int `json:"interval"`
|
||||
SkuDetailVoList []struct {
|
||||
ProblemValueId int `json:"problemValueId"`
|
||||
ProblemValueName string `json:"problemValueName"`
|
||||
} `json:"skuDetailVoList"`
|
||||
Toption int `json:"toption"`
|
||||
Tindex int `json:"tindex"`
|
||||
} `json:"skuTitleVos"`
|
||||
ProblemTitleVos []struct {
|
||||
ProblemId int `json:"problemId"`
|
||||
ProblemName string `json:"problemName"`
|
||||
Interval int `json:"interval"`
|
||||
SkuDetailVoList interface{} `json:"skuDetailVoList"`
|
||||
ProblemDetailVoList []struct {
|
||||
ProblemValueId int `json:"problemValueId"`
|
||||
ProblemValueName string `json:"problemValueName"`
|
||||
} `json:"problemDetailVoList"`
|
||||
Toption int `json:"toption"`
|
||||
Tindex int `json:"tindex"`
|
||||
} `json:"problemTitleVos"`
|
||||
} `json:"data1"`
|
||||
Data interface{} `json:"data"`
|
||||
}
|
||||
|
||||
type XMCheckGoods struct {
|
||||
GoodsId int `json:"goods_id"`
|
||||
GoodsName string `json:"goods_name"`
|
||||
GoodsImg string `json:"goods_img"`
|
||||
Skus []XMSkuTitle `json:"skus"`
|
||||
Problems []XMProblemTitle `json:"problems"`
|
||||
}
|
||||
|
||||
type XMSkuTitle struct {
|
||||
ProblemId int `json:"problem_id"`
|
||||
ProblemName string `json:"problem_name"`
|
||||
List []XMSkuDetail `json:"list"`
|
||||
}
|
||||
|
||||
type XMSkuDetail struct {
|
||||
ProblemValueId int `json:"problem_value_id"`
|
||||
ProblemValueName string `json:"problem_value_name"`
|
||||
}
|
||||
|
||||
type XMProblemTitle struct {
|
||||
ProblemId int `json:"problem_id"`
|
||||
ProblemName string `json:"problem_name"`
|
||||
List []XMSkuDetail `json:"list"`
|
||||
}
|
||||
|
||||
type XMProblemAttr struct {
|
||||
ProblemAttrId string `json:"problemAttrId"`
|
||||
ProblemAttrValueId string `json:"problemAttrValueId"`
|
||||
}
|
||||
|
||||
type GameEvaluationResp struct {
|
||||
Flag bool `json:"flag"`
|
||||
Code int `json:"code"`
|
||||
Message string `json:"message"`
|
||||
Data1 interface{} `json:"data1"`
|
||||
Data int `json:"data"`
|
||||
}
|
1699
model/autogenerated_recycle_card.go
Normal file
1699
model/autogenerated_recycle_card.go
Normal file
File diff suppressed because it is too large
Load Diff
|
@ -157,6 +157,7 @@ func InitTestDB() {
|
|||
&UserInvite{},
|
||||
&UserInviteRecord{},
|
||||
&CooperativeMemberPromotionStore{},
|
||||
&RecycleCardOrder{},
|
||||
)
|
||||
|
||||
fmt.Println("DB init success")
|
||||
|
|
148
model/recycle_card.go
Normal file
148
model/recycle_card.go
Normal file
|
@ -0,0 +1,148 @@
|
|||
package model
|
||||
|
||||
import (
|
||||
"encoding/json"
|
||||
"fmt"
|
||||
"github.com/codinl/go-logger"
|
||||
"math/rand"
|
||||
"mh-server/lib/xianmai"
|
||||
"time"
|
||||
)
|
||||
|
||||
//go:generate goqueryset -in recycle_card.go
|
||||
// gen:qs
|
||||
type RecycleCardOrder struct {
|
||||
Model
|
||||
|
||||
Uid uint32 `json:"uid" gorm:"index"`
|
||||
GoodsId uint32 `json:"goods_id" gorm:"index"`
|
||||
GoodsName string `json:"goods_name"`
|
||||
GoodsImg string `json:"goods_img"`
|
||||
Keyword string `json:"keyword"`
|
||||
Price uint32 `json:"price"`
|
||||
State uint32 `json:"state"` // 1-待回收 2-已完成 3-已被拒 4-已取消
|
||||
StoreId uint32 `json:"store_id" gorm:"index"`
|
||||
StoreName string `json:"store_name"`
|
||||
Images string `json:"images" gorm:"type:text"` // 图片
|
||||
SerialNumber string `json:"serial_number"`
|
||||
EvaluationTime time.Time `json:"evaluation_time"`
|
||||
Attribute string `json:"attribute" gorm:"type:text"` //
|
||||
Number string `json:"number"` // 订单
|
||||
DepressionRate uint32 `json:"depression_rate"` //
|
||||
User *User `json:"user" gorm:"-"`
|
||||
}
|
||||
|
||||
type RecycleAttribute struct {
|
||||
Id uint32 `json:"id"`
|
||||
Name string `json:"name"`
|
||||
ValueId uint32 `json:"value_id"`
|
||||
ValueName string `json:"value_name"`
|
||||
Type uint32 `json:"type"` // 1-sku 2-问题
|
||||
}
|
||||
|
||||
//type GameEvaluationReq struct {
|
||||
// GoodsId uint32 `json:"goods_id"`
|
||||
// ProblemAttrList []struct {
|
||||
// ProblemAttrId int `json:"problem_attr_id"`
|
||||
// ProblemAttrValueId int `json:"problem_attr_value_id"`
|
||||
// } `json:"problem_attr_list"`
|
||||
// SkuList []struct {
|
||||
// ProblemAttrId int `json:"problem_attr_id"`
|
||||
// ProblemAttrValueId int `json:"problem_attr_value_id"`
|
||||
// } `json:"sku_list"`
|
||||
//}
|
||||
|
||||
func RecycleCardOrderCreate(uid uint32, req xianmai.GameEvaluationReq) (*RecycleCardOrder, error) {
|
||||
|
||||
order := &RecycleCardOrder{
|
||||
Uid: uid,
|
||||
GoodsId: uint32(req.GoodsId),
|
||||
GoodsName: req.GoodsName,
|
||||
GoodsImg: req.GoodsImg,
|
||||
Keyword: req.Keyword,
|
||||
State: 1,
|
||||
StoreId: req.StoreId,
|
||||
StoreName: "",
|
||||
Images: "",
|
||||
SerialNumber: "",
|
||||
Attribute: "",
|
||||
DepressionRate: 0,
|
||||
}
|
||||
evaluation, err := req.Evaluation()
|
||||
if err != nil {
|
||||
logger.Error("evaluation err:", err)
|
||||
return order, err
|
||||
}
|
||||
evaluation = (evaluation * 1) / 100
|
||||
order.Price = uint32(evaluation)
|
||||
attributes := make([]RecycleAttribute, 0, len(req.ProblemAttrList)+len(req.SkuList))
|
||||
rand.Seed(time.Now().UnixNano())
|
||||
order.Number = fmt.Sprintf("%d%s", rand.Int31n(899999)+100000, time.Now().Format("06-01-02"))
|
||||
for i, _ := range req.ProblemAttrList {
|
||||
attribute := RecycleAttribute{
|
||||
Id: uint32(req.ProblemAttrList[i].ProblemAttrId),
|
||||
Name: req.ProblemAttrList[i].ProblemAttrName,
|
||||
ValueId: uint32(req.ProblemAttrList[i].ProblemAttrValueId),
|
||||
ValueName: req.ProblemAttrList[i].ProblemAttrValueName,
|
||||
Type: 2,
|
||||
}
|
||||
attributes = append(attributes, attribute)
|
||||
}
|
||||
for i, _ := range req.SkuList {
|
||||
attribute := RecycleAttribute{
|
||||
Id: uint32(req.SkuList[i].ProblemAttrId),
|
||||
Name: req.SkuList[i].ProblemAttrName,
|
||||
ValueId: uint32(req.SkuList[i].ProblemAttrValueId),
|
||||
ValueName: req.SkuList[i].ProblemAttrValueName,
|
||||
Type: 1,
|
||||
}
|
||||
attributes = append(attributes, attribute)
|
||||
}
|
||||
attributeByte, err := json.Marshal(&attributes)
|
||||
if err != nil {
|
||||
logger.Error("attributes marshal err:", err)
|
||||
return order, err
|
||||
}
|
||||
order.Attribute = string(attributeByte)
|
||||
err = DB.Create(order).Error
|
||||
if err != nil {
|
||||
logger.Error("create order err:", err)
|
||||
return order, err
|
||||
}
|
||||
|
||||
return order, err
|
||||
}
|
||||
|
||||
type RecycleCardOrderListReq struct {
|
||||
PageIdx int `json:"page_idx"`
|
||||
PageSize int `json:"page_size"`
|
||||
Uid uint32 `json:"uid"`
|
||||
}
|
||||
|
||||
func (m *RecycleCardOrderListReq) List() ([]RecycleCardOrder, int, error) {
|
||||
page := m.PageIdx - 1
|
||||
if page < 0 {
|
||||
page = 0
|
||||
}
|
||||
if m.PageSize == 0 {
|
||||
m.PageSize = 10
|
||||
}
|
||||
|
||||
var list []RecycleCardOrder
|
||||
qs := NewRecycleCardOrderQuerySet(DB).UidEq(m.Uid)
|
||||
|
||||
count, err := qs.Count()
|
||||
if err != nil {
|
||||
logger.Error("err:", err)
|
||||
return nil, 0, err
|
||||
}
|
||||
totalPage := count/m.PageSize + 1
|
||||
|
||||
err = qs.OrderDescByID().Offset(page * m.PageSize).Limit(m.PageSize).All(&list)
|
||||
if err != nil {
|
||||
logger.Error("err:", err)
|
||||
return nil, 0, err
|
||||
}
|
||||
|
||||
return list, totalPage, nil
|
||||
}
|
|
@ -292,13 +292,15 @@ func (m UserOpenMemberRecord) Insert() error {
|
|||
}
|
||||
|
||||
const (
|
||||
LogCorrelationOrderId = "order_id"
|
||||
LogCorrelationOrderCard = "order_card_id"
|
||||
LogCorrelationOrderId = "order_id"
|
||||
LogCorrelationOrderCard = "order_card_id"
|
||||
LogCorrelationRecycleCardOrderId = "recycle_card_order_id"
|
||||
)
|
||||
const (
|
||||
OperationTypeRentCardRevert = "rent_card_revert"
|
||||
OperationTypeRentCardDeliver = "rent_card_deliver"
|
||||
OperationTypeGameCardGoodsInStock = "game_card_goods_in_stock" // 入库
|
||||
OperationTypeRentCardRevert = "rent_card_revert"
|
||||
OperationTypeRentCardDeliver = "rent_card_deliver"
|
||||
OperationTypeGameCardGoodsInStock = "game_card_goods_in_stock" // 入库
|
||||
OperationTypeRecycleCardOrderImageUpdate = "recycle_card_order_image_update" // 回收卡上传图片
|
||||
)
|
||||
|
||||
// gen:qs
|
||||
|
|
|
@ -250,5 +250,18 @@ func ConfigAppRouter(r gin.IRouter) {
|
|||
cooperative.POST("/cannibalize_task/del", controller.CooperativeCannibalizeTaskDel) //
|
||||
//order.POST("/card/adds", stockmanage.GameCardGoodsStockAdds) // 游戏卡入库
|
||||
}
|
||||
recycle := api.Group("recycle_card")
|
||||
{
|
||||
recycle.Use(auth.UserAccessAuth)
|
||||
recycle.POST("cassette/list", controller.GameCassetteList)
|
||||
recycle.POST("check/goods", controller.GameCheckGoods)
|
||||
recycle.POST("cassette/evaluation", controller.GameEvaluation)
|
||||
recycle.POST("order/create", controller.RecycleCardCreateOrder)
|
||||
recycle.POST("order/list", controller.RecycleCardOrderList)
|
||||
recycle.POST("order/detail", controller.RecycleCardOrderDetail)
|
||||
recycle.POST("order/cancel", controller.RecycleCardOrderCancel)
|
||||
recycle.POST("cassette_image/update", controller.RecycleCardOrderImageUpdate) // 管理端
|
||||
recycle.POST("order/check", controller.RecycleCardOrderCheck) // 管理端
|
||||
}
|
||||
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue
Block a user