This commit is contained in:
li 2023-09-12 14:54:27 +08:00
parent 9956caeaba
commit d2f17242f0
11 changed files with 301 additions and 132 deletions

View File

@ -1,6 +1,7 @@
package controller
import (
"fmt"
"github.com/codinl/go-logger"
"github.com/gin-gonic/gin"
"mh-server/lib/auth"
@ -415,8 +416,11 @@ func ConsoleRecycleCardOrderList(c *gin.Context) {
}
func RecycleCardBrandList(c *gin.Context) {
req := xianmai.SmBrandListReq{
CategoryId: 10,
req := &xianmai.SmBrandListReq{}
if c.ShouldBindJSON(req) != nil {
logger.Error("ShouldBindJSON err")
RespJson(c, status.BadRequest, nil)
return
}
resp, err := req.List()
if err != nil {
@ -430,8 +434,11 @@ func RecycleCardBrandList(c *gin.Context) {
}
func RecycleCardGoodsList(c *gin.Context) {
req := xianmai.SmGoodsListReq{
CategoryId: 10,
req := &xianmai.SmGoodsListReq{}
if c.ShouldBindJSON(req) != nil {
logger.Error("ShouldBindJSON err")
RespJson(c, status.BadRequest, nil)
return
}
resp, err := req.List()
if err != nil {
@ -476,12 +483,27 @@ func RecycleCardSubmitOrderEvaluation(c *gin.Context) {
RespJson(c, status.BadRequest, nil)
return
}
uc := auth.GetCurrentUser(c)
if uc == nil {
RespJson(c, status.Unauthorized, nil)
return
}
//uc = &auth.UserClaims{Uid: 63192613}
user := model.GetUserByUid(uc.Uid)
if user.Tel == "" {
logger.Error("GetUserByUid err:")
RespJson(c, status.InternalServerError, nil)
return
}
smExternal := &xianmai.SmExternal{
ParaMap: req,
ApiRoute: "/openapi/order/submitOrderEvaluation",
ParaMap: req,
ApiRoute: "/openapi/order/submitOrderEvaluation",
WechatId: fmt.Sprintf("%d", user.Uid),
WechatMobile: user.Tel,
RequestType: "placeOrder",
}
resp := &model.SubmitOrderEvaluationResp{}
err := smExternal.Pulling(resp)
err := smExternal.EoPulling(resp)
if err != nil {
logger.Error("SubmitOrderEvaluationResp err:", err)
RespJson(c, status.InternalServerError, nil)
@ -499,12 +521,27 @@ func RecycleCardSubmitOrderDelivery(c *gin.Context) {
RespJson(c, status.BadRequest, nil)
return
}
uc := auth.GetCurrentUser(c)
if uc == nil {
RespJson(c, status.Unauthorized, nil)
return
}
//uc = &auth.UserClaims{Uid: 63192613}
user := model.GetUserByUid(uc.Uid)
if user.Tel == "" {
logger.Error("GetUserByUid err:")
RespJson(c, status.InternalServerError, nil)
return
}
smExternal := &xianmai.SmExternal{
ParaMap: req,
ApiRoute: "/openapi/order/submitOrderDelivery",
ParaMap: req,
ApiRoute: "/openapi/order/submitOrderDelivery",
WechatId: fmt.Sprintf("%d", user.Uid),
WechatMobile: user.Tel,
RequestType: "placeOrder",
}
resp := &model.SubmitOrderDeliveryResp{}
err := smExternal.Pulling(resp)
err := smExternal.EoPulling(resp)
if err != nil {
logger.Error("SubmitOrderDeliveryResp err:", err)
RespJson(c, status.InternalServerError, nil)
@ -522,12 +559,27 @@ func RecycleCardCancelOrderDelivery(c *gin.Context) {
RespJson(c, status.BadRequest, nil)
return
}
uc := auth.GetCurrentUser(c)
if uc == nil {
RespJson(c, status.Unauthorized, nil)
return
}
//uc = &auth.UserClaims{Uid: 63192613}
user := model.GetUserByUid(uc.Uid)
if user.Tel == "" {
logger.Error("GetUserByUid err:")
RespJson(c, status.InternalServerError, nil)
return
}
smExternal := &xianmai.SmExternal{
ParaMap: req,
ApiRoute: "/openapi/order/cancelOrderDelivery",
ParaMap: req,
ApiRoute: "/openapi/order/cancelOrderDelivery",
WechatId: fmt.Sprintf("%d", user.Uid),
WechatMobile: user.Tel,
RequestType: "placeOrder",
}
resp := &model.CancelOrderDeliveryResp{}
err := smExternal.Pulling(resp)
err := smExternal.EoPulling(resp)
if err != nil {
logger.Error("CancelOrderDeliveryResp err:", err)
RespJson(c, status.InternalServerError, nil)
@ -545,12 +597,27 @@ func RecycleCardQueryMemberOrderList(c *gin.Context) {
RespJson(c, status.BadRequest, nil)
return
}
uc := auth.GetCurrentUser(c)
if uc == nil {
RespJson(c, status.Unauthorized, nil)
return
}
//uc = &auth.UserClaims{Uid: 63192613}
user := model.GetUserByUid(uc.Uid)
if user.Tel == "" {
logger.Error("GetUserByUid err:")
RespJson(c, status.InternalServerError, nil)
return
}
smExternal := &xianmai.SmExternal{
ParaMap: req,
ApiRoute: "/openapi/order/queryMemberOrderList",
ParaMap: req,
ApiRoute: "/openapi/order/queryMemberOrderList",
WechatId: fmt.Sprintf("%d", user.Uid),
WechatMobile: user.Tel,
RequestType: "placeOrder",
}
resp := &model.QueryMemberOrderListResp{}
err := smExternal.Pulling(resp)
err := smExternal.EoPulling(resp)
if err != nil {
logger.Error("QueryMemberOrderListResp err:", err)
RespJson(c, status.InternalServerError, nil)
@ -568,12 +635,27 @@ func RecycleCardQueryMemberOrderdetail(c *gin.Context) {
RespJson(c, status.BadRequest, nil)
return
}
uc := auth.GetCurrentUser(c)
if uc == nil {
RespJson(c, status.Unauthorized, nil)
return
}
//uc = &auth.UserClaims{Uid: 63192613}
user := model.GetUserByUid(uc.Uid)
if user.Tel == "" {
logger.Error("GetUserByUid err:")
RespJson(c, status.InternalServerError, nil)
return
}
smExternal := &xianmai.SmExternal{
ParaMap: req,
ApiRoute: "/openapi/order/queryMemberOrderdetail",
ParaMap: req,
ApiRoute: "/openapi/order/queryMemberOrderdetail",
WechatId: fmt.Sprintf("%d", user.Uid),
WechatMobile: user.Tel,
RequestType: "placeOrder",
}
resp := &model.QueryMemberOrderdetailResp{}
err := smExternal.Pulling(resp)
err := smExternal.EoPulling(resp)
if err != nil {
logger.Error("QueryMemberOrderdetailResp err:", err)
RespJson(c, status.InternalServerError, nil)
@ -591,12 +673,27 @@ func RecycleCardQueryMemberOrderDelivery(c *gin.Context) {
RespJson(c, status.BadRequest, nil)
return
}
uc := auth.GetCurrentUser(c)
if uc == nil {
RespJson(c, status.Unauthorized, nil)
return
}
//uc = &auth.UserClaims{Uid: 63192613}
user := model.GetUserByUid(uc.Uid)
if user.Tel == "" {
logger.Error("GetUserByUid err:")
RespJson(c, status.InternalServerError, nil)
return
}
smExternal := &xianmai.SmExternal{
ParaMap: req,
ApiRoute: "/openapi/order/queryMemberOrderDelivery",
ParaMap: req,
ApiRoute: "/openapi/order/queryMemberOrderDelivery",
WechatId: fmt.Sprintf("%d", user.Uid),
WechatMobile: user.Tel,
RequestType: "placeOrder",
}
resp := &model.QueryMemberOrderDeliveryResp{}
err := smExternal.Pulling(resp)
err := smExternal.EoPulling(resp)
if err != nil {
logger.Error("QueryMemberOrderDeliveryResp err:", err)
RespJson(c, status.InternalServerError, nil)
@ -614,12 +711,27 @@ func RecycleCardSubmitConfirmPrice(c *gin.Context) {
RespJson(c, status.BadRequest, nil)
return
}
uc := auth.GetCurrentUser(c)
if uc == nil {
RespJson(c, status.Unauthorized, nil)
return
}
//uc = &auth.UserClaims{Uid: 63192613}
user := model.GetUserByUid(uc.Uid)
if user.Tel == "" {
logger.Error("GetUserByUid err:")
RespJson(c, status.InternalServerError, nil)
return
}
smExternal := &xianmai.SmExternal{
ParaMap: req,
ApiRoute: "/openapi/order/submitConfirmPrice",
ParaMap: req,
ApiRoute: "/openapi/order/submitConfirmPrice",
WechatId: fmt.Sprintf("%d", user.Uid),
WechatMobile: user.Tel,
RequestType: "placeOrder",
}
resp := &model.SubmitConfirmPriceResp{}
err := smExternal.Pulling(resp)
err := smExternal.EoPulling(resp)
if err != nil {
logger.Error("QueryMemberOrderDeliveryResp err:", err)
RespJson(c, status.InternalServerError, nil)

View File

@ -245,8 +245,11 @@ func (m *SmGoodsListReq) List() (*SmGoodsListResp, error) {
}
type SmExternal struct {
ParaMap interface{}
ApiRoute string `json:"api_route"`
ParaMap interface{} `json:"para_map"`
ApiRoute string `json:"api_route"`
WechatId string `json:"wechat_id"`
WechatMobile string `json:"wechat_mobile"`
RequestType string `json:"request_type"`
//Resp interface{}
}
@ -258,3 +261,22 @@ func (m *SmExternal) Pulling(resp interface{}) error {
}
return nil
}
func (m *SmExternal) EoPulling(resp interface{}) error {
maiToken, err := EoSanMaiToken(m.WechatId, m.WechatMobile, m.RequestType)
if err != nil {
logger.Error("EoSanMaiToken err:", err)
return err
}
sanMaiClient = &SanMaiClient{
Authentication: maiToken,
BaseURL: SmBaseURL,
}
err = sanMaiClient.post(m.ApiRoute, m.ParaMap, resp)
if err != nil {
logger.Error("post err:", err)
return err
}
return nil
}

View File

@ -3,12 +3,14 @@ package xianmai
import (
"bytes"
"encoding/json"
"errors"
"fmt"
"github.com/codinl/go-logger"
"io"
"io/ioutil"
"net/http"
"strings"
"time"
)
type XianMaiClient struct {
@ -178,23 +180,105 @@ type GameEvaluationResp struct {
}
type SanMaiClient struct {
Authentication string `json:"authentication"`
BaseURL string `json:"base_url"`
Authentication string `json:"authentication"`
BaseURL string `json:"base_url"`
ExpireTime time.Time `json:"expire_time"`
}
const (
SmBaseURL = "https://test.xianmai.net.cn/"
//SmBaseURL = "https://xianmai.net.cn/"
)
var sanMaiClient *SanMaiClient
func GetSanMaiClient() *SanMaiClient {
if sanMaiClient == nil {
nowTime := time.Now()
fmt.Println("time.Now:", nowTime)
if sanMaiClient == nil || sanMaiClient.ExpireTime.Before(nowTime) {
fmt.Println("初始化数据")
sanMaiClient = &SanMaiClient{
Authentication: "",
//BaseURL: "https://xianmai.net.cn/",
BaseURL: "https://test.xianmai.net.cn/",
Authentication: SanMaiToken(),
BaseURL: SmBaseURL,
ExpireTime: nowTime.AddDate(0, 0, 1),
}
return sanMaiClient
}
return sanMaiClient
}
func SanMaiToken() string {
smExternal := SmExternal{
ParaMap: SubmitLoginApiReq{
Username: "13307551242",
Password: "dw123",
},
ApiRoute: "/loginApi",
}
sanMaiClient = &SanMaiClient{
Authentication: "",
BaseURL: SmBaseURL,
}
resp := &SubmitLoginApiResp{}
err := sanMaiClient.post(smExternal.ApiRoute, smExternal.ParaMap, resp)
if err != nil {
logger.Error("SubmitLoginApiResp err:", err)
return ""
}
return resp.Data.Token
}
func EoSanMaiToken(wechatId, wechatMobile, requestType string) (string, error) {
if wechatId == "" || wechatMobile == "" || requestType == "" {
return "", errors.New("para err")
}
smExternal := SmExternal{
ParaMap: SubmitLoginApiReq{
Username: "13307551242",
Password: "dw123",
WechatId: wechatId,
WechatMobile: wechatMobile,
RequestType: requestType,
},
ApiRoute: "/loginApi",
}
sanMaiClient = &SanMaiClient{
Authentication: "",
BaseURL: SmBaseURL,
}
resp := &SubmitLoginApiResp{}
err := sanMaiClient.post(smExternal.ApiRoute, smExternal.ParaMap, resp)
if err != nil {
logger.Error("SubmitLoginApiResp err:", err)
return "", err
}
return resp.Data.Token, nil
}
type SubmitLoginApiReq struct {
Username string `json:"username"`
Password string `json:"password"`
WechatId string `json:"wechatId"`
WechatMobile string `json:"wechatMobile"`
RequestType string `json:"requestType"`
}
type SubmitLoginApiResp struct {
Flag bool `json:"flag"`
Code int `json:"code"`
Message string `json:"message"`
Data1 interface{} `json:"data1"`
Data struct {
ComponyName string `json:"componyName"`
Permissions []string `json:"permissions"`
Roles []string `json:"roles"`
ExipreTime string `json:"exipreTime"`
ComponyId string `json:"componyId"`
Token string `json:"token"`
} `json:"data"`
}
//func (m *SanMaiClient) post(xmApi string, params map[string]interface{}, resp interface{}) error {
// uri := m.BaseURL + xmApi
// data, err := json.Marshal(params)
@ -236,7 +320,7 @@ func GetSanMaiClient() *SanMaiClient {
func (m *SanMaiClient) post(xmApi string, params interface{}, resp interface{}) error {
uri := m.BaseURL + xmApi
data, err := json.Marshal(params)
data, err := json.Marshal(&params)
if err != nil {
logger.Error("Marshal params err:", err)
return err
@ -260,13 +344,13 @@ func (m *SanMaiClient) post(xmApi string, params interface{}, resp interface{})
dataRsp, err := io.ReadAll(res.Body)
if err != nil {
fmt.Println(err)
logger.Error("ReadAll Body err:", err)
return err
}
fmt.Println("dataRsp:", string(dataRsp))
if err = json.Unmarshal(dataRsp, resp); err != nil {
fmt.Println(err)
logger.Error("Unmarshal dataRsp err:", err)
return err
}

View File

@ -2684,7 +2684,7 @@ func TestUserMemberGenreInfo(t *testing.T) {
UserMemberGenreInfo()
}
// 拉新锁卡数据
// 短期会员数据
func UserMemberGenreInfo() {
DB = DBProd
var cards []User
@ -2760,7 +2760,7 @@ func TestEvaluation(t *testing.T) {
if err != nil {
fmt.Println("err:", err)
}
fmt.Println("cassetteList:", cassetteList)
fmt.Println("i:", i)
}

View File

@ -3,6 +3,7 @@ package model
type ProblemSkuListReq struct {
GoodsId int `json:"goodsId"`
}
type ProblemSkuListResp struct {
Flag bool `json:"flag"`
Code int `json:"code"`
@ -16,6 +17,7 @@ type ProblemSkuListResp struct {
ProblemName string `json:"problemName"`
ProblemId int `json:"problemId"`
List []struct {
Isupt string `json:"isupt"`
ProblemValueId string `json:"problemValueId"`
ProblemValueName string `json:"problemValueName"`
} `json:"list"`
@ -27,33 +29,34 @@ type ProblemSkuListResp struct {
ProblemName string `json:"problemName"`
ProblemId int `json:"problemId"`
List []struct {
Isupt string `json:"isupt"`
ProblemValueId string `json:"problemValueId"`
ProblemValueName string `json:"problemValueName"`
} `json:"list"`
} `json:"problemSkuList"`
GoodsInfo struct {
Id int `json:"id"`
Name string `json:"name"`
CategoryId int `json:"categoryId"`
BrandId int `json:"brandId"`
Status int `json:"status"`
Gallery string `json:"gallery"`
Keyword string `json:"keyword"`
CreateTime string `json:"createTime"`
UpdateTime string `json:"updateTime"`
Deleted int `json:"deleted"`
Price int `json:"price"`
PriceHigh int `json:"priceHigh"`
PriceAvg int `json:"priceAvg"`
PriceCycle int `json:"priceCycle"`
OverdueDays int `json:"overdueDays"`
PriceAdjustmentTime string `json:"priceAdjustmentTime"`
TemlateId int `json:"temlateId"`
TemplateName string `json:"templateName"`
BrandName string `json:"brandName"`
CategoryName string `json:"categoryName"`
IsBindCoupon bool `json:"isBindCoupon"`
Tindex int `json:"tindex"`
Id int `json:"id"`
Name string `json:"name"`
CategoryId int `json:"categoryId"`
BrandId int `json:"brandId"`
Status int `json:"status"`
Gallery string `json:"gallery"`
Keyword string `json:"keyword"`
CreateTime string `json:"createTime"`
UpdateTime string `json:"updateTime"`
Deleted int `json:"deleted"`
Price float64 `json:"price"`
PriceHigh float64 `json:"priceHigh"`
PriceAvg float64 `json:"priceAvg"`
PriceCycle int `json:"priceCycle"`
OverdueDays int `json:"overdueDays"`
PriceAdjustmentTime string `json:"priceAdjustmentTime"`
TemlateId int `json:"temlateId"`
TemplateName string `json:"templateName"`
BrandName string `json:"brandName"`
CategoryName string `json:"categoryName"`
IsBindCoupon bool `json:"isBindCoupon"`
Tindex int `json:"tindex"`
} `json:"goodsInfo"`
} `json:"data"`
}
@ -98,7 +101,7 @@ type SubmitOrderDeliveryReq struct {
type SubmitOrderDeliveryResp struct {
Flag bool `json:"flag"`
Code int `json:"code"`
Code interface{} `json:"code"`
Message string `json:"message"`
Data1 interface{} `json:"data1"`
Data string `json:"data"`
@ -109,16 +112,16 @@ type CancelOrderDeliveryReq struct {
}
type CancelOrderDeliveryResp struct {
Flag bool `json:"flag"`
Code int `json:"code"`
Code interface{} `json:"code"`
Message string `json:"message"`
Data1 interface{} `json:"data1"`
Data string `json:"data"`
}
type QueryMemberOrderListReq struct {
DataType int `json:"dataType"`
PageNum string `json:"pageNum"`
PageSize string `json:"pageSize"`
DataType int `json:"dataType"`
PageNum int `json:"pageNum"`
PageSize int `json:"pageSize"`
}
type QueryMemberOrderListResp struct {
Flag bool `json:"flag"`
@ -138,8 +141,8 @@ type QueryMemberOrderListResp struct {
GoodsNum int `json:"goodsNum"`
CourierNumber interface{} `json:"courierNumber"`
Imei string `json:"imei"`
Price int `json:"price"`
EvaluationPrice int `json:"evaluationPrice"`
Price float64 `json:"price"`
EvaluationPrice float64 `json:"evaluationPrice"`
AddTime string `json:"addTime"`
} `json:"list"`
PageNum int `json:"pageNum"`
@ -166,7 +169,7 @@ type QueryMemberOrderdetailReq struct {
}
type QueryMemberOrderdetailResp struct {
Flag bool `json:"flag"`
Code int `json:"code"`
Code interface{} `json:"code"`
Message string `json:"message"`
Data1 interface{} `json:"data1"`
Data struct {
@ -190,7 +193,7 @@ type QueryMemberOrderdetailResp struct {
GoodsId int `json:"goodsId"`
MemberId int `json:"memberId"`
StoreId int `json:"storeId"`
EvaluationPrice int `json:"evaluationPrice"`
EvaluationPrice float64 `json:"evaluationPrice"`
QcPrice interface{} `json:"qcPrice"`
PlatformPrice interface{} `json:"platformPrice"`
ChangeNewPrice interface{} `json:"changeNewPrice"`
@ -234,7 +237,7 @@ type QueryMemberOrderdetailResp struct {
BrandName string `json:"brandName"`
TemplateName interface{} `json:"templateName"`
TemplatePackName interface{} `json:"templatePackName"`
Price int `json:"price"`
Price float64 `json:"price"`
Img string `json:"img"`
AboutPic interface{} `json:"aboutPic"`
ScrewHolePic interface{} `json:"screwHolePic"`
@ -305,9 +308,9 @@ type QueryMemberOrderDeliveryReq struct {
OrderId int `json:"orderId"`
}
type QueryMemberOrderDeliveryResp struct {
Flag bool `json:"flag"`
Code int `json:"code"`
Message string `json:"message"`
Flag bool `json:"flag"`
Code interface{} `json:"code"`
Message string `json:"message"`
Data struct {
Id int `json:"id"`
OrderNo string `json:"orderNo"`
@ -342,7 +345,7 @@ type SubmitConfirmPriceReq struct {
OrderId int `json:"orderId"`
}
type SubmitConfirmPriceResp struct {
Code int `json:"code"`
Flag bool `json:"flag"`
Message string `json:"message"`
Code interface{} `json:"code"`
Flag bool `json:"flag"`
Message string `json:"message"`
}

View File

@ -229,7 +229,7 @@ func GetUserByUid(uid uint32) *User {
user := new(User)
if err := NewUserQuerySet(DB).UidEq(uid).One(user); err != nil {
logger.Error(err, uid)
return nil
return user
}
return user
}

View File

@ -1,12 +0,0 @@
#!/bin/bash
export CONFIG_PATH=configs
export CONFIG_FILE_NAME=cron
export ENV=dev
export APP_NAME=$1
export LOG_FILE_NAME=$1
export LOG_PATH=log_cron
go run ../main.go $1

View File

@ -1,21 +0,0 @@
#!/usr/bin/env bash
export GIN_MODE=release
export CONFIG_PATH=configs
export CONFIG_FILE_NAME=cron
export ENV=pro
export APP_NAME=$1
export LOG_FILE_NAME=$1
app_name=$1
killall -15 ${app_name}
mv -f ./${app_name}_*.cron ./${app_name}.cron
basepath=$(cd `dirname $0`; pwd)
`${basepath}/${app_name}.cron ${app_name}` &

View File

@ -1,20 +0,0 @@
#!/usr/bin/env bash
export GIN_MODE=release
export CONFIG_PATH=configs
export CONFIG_FILE_NAME=cron
export ENV=test
export APP_NAME=$1
app_name=$1
killall -15 ${app_name}
mv -f ./${app_name}_*.cron ./${app_name}.cron
basepath=$(cd `dirname $0`; pwd)
`${basepath}/${app_name}.cron ${app_name}` &

View File

@ -265,6 +265,8 @@ func ConfigAppRouter(r gin.IRouter) {
recycle.POST("query_brand_list", controller.RecycleCardBrandList)
recycle.POST("query_goods_list", controller.RecycleCardGoodsList)
recycle.POST("query_problem_sku_list", controller.RecycleCardProblemSkuList)
recycle.Use(auth.UserAccessAuth)
recycle.POST("submit_order_evaluation", controller.RecycleCardSubmitOrderEvaluation)
recycle.POST("submit_order_delivery", controller.RecycleCardSubmitOrderDelivery)
recycle.POST("cancel_order_delivery", controller.RecycleCardCancelOrderDelivery)
@ -273,7 +275,6 @@ func ConfigAppRouter(r gin.IRouter) {
recycle.POST("query_member_order_delivery", controller.RecycleCardQueryMemberOrderDelivery)
recycle.POST("submit_confirm_price", controller.RecycleCardSubmitConfirmPrice)
recycle.Use(auth.UserAccessAuth)
recycle.POST("cassette/list", controller.GameCassetteList)
recycle.POST("check/goods", controller.GameCheckGoods)
recycle.POST("cassette/evaluation", controller.GameEvaluation)