Commit 07aab597 by wang

解决合并冲突

parents ad60817b 0c850e87
......@@ -17,4 +17,5 @@ cmd.exe~
/vm.sh
/cmd/http
/doc/spuTest
/doc/test3
......@@ -32,7 +32,7 @@ const goods_slice_count = 10 //每多少个型号id开启一个协程
*/
func Synchronization(ctx *gin.Context) {
func CommonController(ctx *gin.Context) map[string]interface{}{
common.PrintDebugHeader(ctx) //开启debug调试
zyService := service.ZiyingService{} //实例化自营查询
......@@ -42,7 +42,7 @@ func Synchronization(ctx *gin.Context) {
GoodsIdStr := ctx.Request.FormValue("goods_id")
if GoodsIdStr == "" {
common.Output(ctx, 1001, "查询型号ID不得为空", "")
return
return nil
}
goodsIdArr := php2go.Explode(",", GoodsIdStr)
......@@ -111,7 +111,18 @@ func Synchronization(ctx *gin.Context) {
logger.Log("协程超时", "sku", 1)
}
}
common.Output(ctx, 0, "success", temp)
return temp
}
func Synchronization(ctx *gin.Context) {
res:=CommonController(ctx)
common.Output(ctx, 0, "success", res)
}
func Synchronization1(ctx *gin.Context) {
res:=CommonController(ctx)
common.Output(ctx, 0, "success", res)
}
/*
......
package controller
import (
"github.com/gin-gonic/gin"
"go_sku_server/model"
"go_sku_server/pkg/common"
"go_sku_server/service"
)
/**
请求参数格式如下
(
[goods_id] => 1160551099531105977
[num] => 475
[currency] => 1
[power] => Array
(
[member] => true
[newCustomer] => false
[user_id] => 69797
[email] =>
[mobile] => 13277999723
)
)
必填参数 goods_id num currency
参考业务逻辑:http://119.23.72.7/ymx/GoodsMachining/blob/master/app/Http/Controllers/ServicesController.php#L66
*/
func SkuLadderprice(ctx *gin.Context) {
//ctx.Request.ParseMultipartForm(32 << 20)
//postForm := ctx.Request.Form
if ladderPriceRequest, err :=model.NewPriceRequest(ctx); err!=nil{
common.Output(ctx, err.Code, err.Error(), "")
}else{
goodsInfo:=CommonController(ctx)//获取商品详情(调用树贤和黄哥之前写好的Controller)
if data,err:=service.NewLadderPriceService().GetPriceInfoByNum(ladderPriceRequest,goodsInfo); err!=nil{
common.Output(ctx, err.Code, err.Error(), data)
}else{
common.Output(ctx, 0, "success", data)
}
return
}
}
\ No newline at end of file
......@@ -6,6 +6,7 @@ require (
github.com/denisenkom/go-mssqldb v0.0.0-20191124224453-732737034ffd // indirect
github.com/gin-gonic/gin v1.6.3
github.com/go-ini/ini v1.57.0
github.com/go-playground/validator/v10 v10.2.0
github.com/go-sql-driver/mysql v1.5.0
github.com/go-xorm/xorm v0.7.9
github.com/gogf/gf v1.14.5
......
package model
import (
"github.com/gin-gonic/gin"
"github.com/go-playground/validator/v10"
"github.com/gogf/gf/util/gconv"
"go_sku_server/pkg/e"
"reflect"
)
type LadderPriceRequest struct {
GoodsId string `json:"goods_id" form:"goods_id" binding:"required" required_errcode:"104004"`
Num int64 `json:"num" form:"num" binding:"required" required_errcode:"104005"`
Currency int `json:"currency" form:"currency" binding:"required" required_errcode:"104006"`
Costly int `json:"costly" form:"costly" `//暂时不知道是什么意思
}
type requiredCode struct {
msgMap map[string]int
}
// 验证并返回 LadderPriceRequest
func NewPriceRequest(ctx *gin.Context) ( LadderPriceRequest, *e.ApiError) {
ladderPriceRequest:=LadderPriceRequest{}
typeOfLadderPrice:=reflect.TypeOf(ladderPriceRequest)
if err:= ctx.ShouldBind(&ladderPriceRequest); err != nil {
if fieldError,ok:=err.(validator.ValidationErrors);ok{
if(fieldError[0].Tag()=="required"){
fieldName:=fieldError[0].StructField()
requiredCode:=104001
if field,bool:=typeOfLadderPrice.FieldByName(fieldName);bool==true{
requiredCode=gconv.Int(field.Tag.Get("required_errcode"))
}
return ladderPriceRequest,e.NewApiError("缺少参数:"+fieldName,requiredCode)
}
}
}
return ladderPriceRequest, nil
}
......@@ -78,8 +78,8 @@ func GetRequestParam(ctx *gin.Context) string {
}
return BodyJson
default:
ctx.Request.ParseForm()
postForm := ctx.Request.PostForm
ctx.Request.ParseMultipartForm(32 << 20)
postForm := ctx.Request.Form
formData, _ := json.Marshal(postForm)
params := string(formData)
return params
......
......@@ -14,27 +14,23 @@ func InitRouter() *gin.Engine {
//联营参数选择搜索
r.GET("synchronization", controller.Synchronization)
r.POST("synchronization", controller.Synchronization)
r.POST("synchronization",controller.Synchronization)
//联营参数选择搜索
r.GET("Synchronization", controller.Synchronization)
r.POST("Synchronization", controller.Synchronization)
r.POST("Synchronization",controller.Synchronization)
r.POST("Ladderprice",controller.SkuLadderprice)
r.POST("ladderprice",controller.SkuLadderprice)
//心跳
r.GET("hbsdata", controller.Hbsdata)
r.POST("hbsdata", controller.Hbsdata)
//测试redis
r.POST("testr", controller.Testr)
r.POST("hbsdata",controller.Hbsdata)
//自营SaveSku
r.POST("SaveSku", controller.Error_Middleware(), controller.SaveSku)
r.POST("SkuEdit", controller.Error_Middleware(), controller.SkuEdit)
//ly := service.LyService{}
//sku := model.ActivityCheckData{
// SupplierId: 2,
// BrandId: 1,
// GoodsId: "1",
// Canal: "lmxs",
//}
//ly.GetActivityData(sku)
r.POST("SaveSku",controller.Error_Middleware(),controller.SaveSku)
r.POST("SkuEdit",controller.Error_Middleware(),controller.SkuEdit)
return r
}
package service
import (
"encoding/json"
"github.com/gogf/gf/util/gconv"
"github.com/tidwall/gjson"
"go_sku_server/model"
"go_sku_server/pkg/common"
"go_sku_server/pkg/e"
)
type LadderPriceService struct {
}
func adderprice() {
}
/**
* 指定数量从阶梯中选择价格
* @param [type] $ladder 价格阶梯
* @param [type] $num 购买数量
* @param integer $currency 币种 1人民币 2美元
* @return [type]
*/
func (LP *LadderPriceService) GetPriceInfoByNum(ladderPriceRequest model.LadderPriceRequest, goodsInfo map[string]interface{}) (map[string]interface{},*e.ApiError) {
//此service 对 商详数据的操作都是使用的 gjson包
res:=make(map[string]interface{})
goodsJsonResult,err:=LP.getGoodsInfo(goodsInfo,ladderPriceRequest.GoodsId)
if(err!=nil){
return res,err
}
costly:=ladderPriceRequest.Costly//这个字段暂时不知道什么意思
//根据num 从 多个阶梯价数组 获取到对应的阶梯价
ladderPriceOne,err:=LP.getLadderPrice(goodsJsonResult,ladderPriceRequest.GoodsId,ladderPriceRequest.Num,costly)
num:=ladderPriceRequest.Num
purchases:=ladderPriceOne.Get("purchases").Int();
if purchases>ladderPriceRequest.Num{
num=purchases
}
goodsType:=goodsJsonResult.Get("goods_type").Int()
acType:=goodsJsonResult.Get("ac_type").Int()
if((goodsType==1 || goodsType==2) && acType!=1 && ladderPriceRequest.Currency!=1){//美元
res["price_us"]=ladderPriceOne.Get("price_us").Float()
res["price_us_total"]=common.MyRound(gconv.Float64(res["price_us"])*gconv.Float64(num),4)
goodsInfo["ac_type"]=0
}else{//人民币
res["price_cn"]=ladderPriceOne.Get("price_cn").Float()
res["price_cn_total"]=common.MyRound(gconv.Float64(res["price_cn"])*gconv.Float64(num),4)//人民币原价总价
priceAc:=ladderPriceOne.Get("price_ac").Float()
if priceAc != 0{
res["price_ac"]=priceAc
res["price_ac_total"]=common.MyRound(priceAc*gconv.Float64(num),4)
}
}
ladder:=make([]map[string]interface{},0)
a:=goodsJsonResult.Get("ladder_price").String()
err1:=json.Unmarshal([]byte(a),&ladder)//json Unmarshal一下,为了让返回格式没那么多斜划线
if(err1!=nil){
return res,e.NewApiError("json.Unmarshal ladder_price 报错"+err1.Error())
}
res["ladder_price"]=ladder
res["goods_info"]=goodsInfo
res["num"]=num
return res,nil
}
func (LP *LadderPriceService)getGoodsInfo(goodsInfo map[string]interface{}, goodsId string) (gjson.Result, *e.ApiError) {
var info gjson.Result
goodsInfoJson:=""
//把商品详情数据转化为json,方便用gjson处理
if byteS,err:=json.Marshal(goodsInfo);err!=nil{
return info, e.NewApiError(err.Error())
}else{
goodsInfoJson=string(byteS)
}
goodsResult:=gjson.Get(goodsInfoJson,goodsId)
if(goodsResult.Exists()!=true){
return info, e.NewApiError("未找到对应SKU", 20001)
}
return goodsResult, nil
}
func (LP *LadderPriceService )getLadderPrice(goodsJsonResult gjson.Result,goodsId string,num int64,costly int) (gjson.Result,*e.ApiError){
var res gjson.Result
ladderPriceS:=goodsJsonResult.Get("ladder_price")
if(len(ladderPriceS.Array())>0){
var price =gjson.Result{}
for k,item:=range ladderPriceS.Array(){
purchases:=item.Get("purchases").Int()
if(k==0){
price=item//默认最小数量
}
if(gconv.Int(costly)==1){//这一句没懂 Costly 代表什么意思
break
}
if(purchases<=num){
price=item
}
}
if(price.Exists()==false){
return res,e.NewApiError("这个SKU没有阶梯价",504003)
}
return price,nil
}else{
return res,e.NewApiError("这个SKU没有阶梯价",104002)
}
}
func NewLadderPriceService() *LadderPriceService{
return &LadderPriceService{}
}
\ No newline at end of file
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or sign in to comment