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
#请求参数
```json
goods_id 1160557872621762351
num 105
currency 2
costly 1
```
### golang 响应参数
```json
{
"errcode": 0,
"errmsg": "success",
"data": {
"goods_info": {
"1160557872621762351": {
"spu_id": "2160557872644497609",
"old_goods_id": 532850,
"update_time": 1605578726,
"cp_time": 0,
"goods_status": 1,
"goods_type": 1,
"supplier_id": 17,
"encoded": "",
"batch_sn": "",
"moq": 1,
"mpq": 1,
"stock": 9999999,
"hk_delivery_time": "",
"cn_delivery_time": "",
"ladder_price": [
{
"purchases": 1,
"price_us": 3.16,
"price_cn": 25.6955,
"price_ac": 10.2782
},
{
"purchases": 10,
"price_us": 2.84,
"price_cn": 23.0935,
"price_ac": 9.2374
},
{
"purchases": 25,
"price_us": 2.67,
"price_cn": 21.7111,
"price_ac": 8.6844
},
{
"purchases": 100,
"price_us": 2.32,
"price_cn": 18.8651,
"price_ac": 7.546
},
{
"purchases": 250,
"price_us": 2.17,
"price_cn": 17.6454,
"price_ac": 7.0582
},
{
"purchases": 500,
"price_us": 1.87,
"price_cn": 15.2059,
"price_ac": 6.0824
},
{
"purchases": 750,
"price_us": 1.6,
"price_cn": 13.0104,
"price_ac": 5.2042
},
{
"purchases": 1000,
"price_us": 1.35,
"price_cn": 10.9775,
"price_ac": 4.391
}
],
"goods_images": "",
"canal": "",
"packing": "",
"goods_id": "1160557872621762351",
"goods_name": "UC3526DW",
"brand_name": "TI",
"supplier_name": "猎芯专卖",
"attrs": false,
"scm_brand": [],
"ac_type": 2,
"allow_coupon": 2,
"brand_id": 23,
"original_price": [
{
"purchases": 1,
"price_us": 3.16,
"price_cn": 25.6955,
"cost_price": 0
},
{
"purchases": 10,
"price_us": 2.84,
"price_cn": 23.0935,
"cost_price": 0
},
{
"purchases": 25,
"price_us": 2.67,
"price_cn": 21.7111,
"cost_price": 0
},
{
"purchases": 100,
"price_us": 2.32,
"price_cn": 18.8651,
"cost_price": 0
},
{
"purchases": 250,
"price_us": 2.17,
"price_cn": 17.6454,
"cost_price": 0
},
{
"purchases": 500,
"price_us": 1.87,
"price_cn": 15.2059,
"cost_price": 0
},
{
"purchases": 750,
"price_us": 1.6,
"price_cn": 13.0104,
"cost_price": 0
},
{
"purchases": 1000,
"price_us": 1.35,
"price_cn": 10.9775,
"cost_price": 0
}
],
"supp_extend_fee": false,
"is_buy": 1,
"class_id1": 0,
"class_id2": 0,
"class_id3": 0,
"spu_name": "UC3526DW",
"status": 1,
"images_l": "",
"encap": "",
"pdf": "",
"spu_brief": "UC3526 稳压脉宽调制器",
"class_name": "其他",
"erp_tax": false,
"goods_sn": "",
"goods_details": "",
"ratio": 40,
"activity_end_time": 1639152000,
"content": null
},
"ac_type": 0
},
"ladder_price": [
{
"price_ac": 10.2782,
"price_cn": 25.6955,
"price_us": 3.16,
"purchases": 1
},
{
"price_ac": 9.2374,
"price_cn": 23.0935,
"price_us": 2.84,
"purchases": 10
},
{
"price_ac": 8.6844,
"price_cn": 21.7111,
"price_us": 2.67,
"purchases": 25
},
{
"price_ac": 7.546,
"price_cn": 18.8651,
"price_us": 2.32,
"purchases": 100
},
{
"price_ac": 7.0582,
"price_cn": 17.6454,
"price_us": 2.17,
"purchases": 250
},
{
"price_ac": 6.0824,
"price_cn": 15.2059,
"price_us": 1.87,
"purchases": 500
},
{
"price_ac": 5.2042,
"price_cn": 13.0104,
"price_us": 1.6,
"purchases": 750
},
{
"price_ac": 4.391,
"price_cn": 10.9775,
"price_us": 1.35,
"purchases": 1000
}
],
"num": 105,
"price_us": 3.16,
"price_us_total": 331.8
}
}
```
### php响应参数
```json
{
"errcode": 0,
"errmsg": "success",
"data": {
"price_us": 3.16,
"price_us_total": 331.8,
"ladder_price": [
{
"purchases": 1,
"price_us": 3.16,
"price_cn": 25.6955,
"price_ac": 10.2782
},
{
"purchases": 10,
"price_us": 2.84,
"price_cn": 23.0935,
"price_ac": 9.2374
},
{
"purchases": 25,
"price_us": 2.67,
"price_cn": 21.7111,
"price_ac": 8.6844
},
{
"purchases": 100,
"price_us": 2.32,
"price_cn": 18.8651,
"price_ac": 7.546
},
{
"purchases": 250,
"price_us": 2.17,
"price_cn": 17.6454,
"price_ac": 7.0582
},
{
"purchases": 500,
"price_us": 1.87,
"price_cn": 15.2059,
"price_ac": 6.0824
},
{
"purchases": 750,
"price_us": 1.6,
"price_cn": 13.0104,
"price_ac": 5.2042
},
{
"purchases": 1000,
"price_us": 1.35,
"price_cn": 10.9775,
"price_ac": 4.391
}
],
"num": 105,
"goods_info": {
"spu_id": "2160557872644497609",
"encoded": "",
"moq": 1,
"mpq": 1,
"old_goods_id": 532850,
"goods_type": 1,
"goods_status": 1,
"batch_sn": "",
"stock": 9999999,
"hk_delivery_time": "",
"cn_delivery_time": "",
"ladder_price": [
{
"purchases": 1,
"price_us": 3.16,
"price_cn": 25.6955,
"price_ac": 10.2782
},
{
"purchases": 10,
"price_us": 2.84,
"price_cn": 23.0935,
"price_ac": 9.2374
},
{
"purchases": 25,
"price_us": 2.67,
"price_cn": 21.7111,
"price_ac": 8.6844
},
{
"purchases": 100,
"price_us": 2.32,
"price_cn": 18.8651,
"price_ac": 7.546
},
{
"purchases": 250,
"price_us": 2.17,
"price_cn": 17.6454,
"price_ac": 7.0582
},
{
"purchases": 500,
"price_us": 1.87,
"price_cn": 15.2059,
"price_ac": 6.0824
},
{
"purchases": 750,
"price_us": 1.6,
"price_cn": 13.0104,
"price_ac": 5.2042
},
{
"purchases": 1000,
"price_us": 1.35,
"price_cn": 10.9775,
"price_ac": 4.391
}
],
"update_time": 1605578726,
"goods_images": "",
"canal": "",
"supplier_id": 17,
"cp_time": 0,
"packing": "",
"goods_id": "1160557872621762351",
"goods_name": "UC3526DW",
"brand_name": "TI",
"supplier_name": "猎芯专卖",
"attrs": [
{
"attr_name": "属性名称",
"attr_value": "属性值3471"
}
],
"scm_brand": [],
"ac_type": 0,
"allow_coupon": 2,
"brand_id": 23,
"ratio": 40,
"activity_end_time": 1639152000,
"original_price": [
{
"purchases": 1,
"price_cn": 25.6955,
"price_us": 3.16
},
{
"purchases": 10,
"price_cn": 23.0935,
"price_us": 2.84
},
{
"purchases": 25,
"price_cn": 21.7111,
"price_us": 2.67
},
{
"purchases": 100,
"price_cn": 18.8651,
"price_us": 2.32
},
{
"purchases": 250,
"price_cn": 17.6454,
"price_us": 2.17
},
{
"purchases": 500,
"price_cn": 15.2059,
"price_us": 1.87
},
{
"purchases": 750,
"price_cn": 13.0104,
"price_us": 1.6
},
{
"purchases": 1000,
"price_cn": 10.9775,
"price_us": 1.35
}
],
"supp_extend_fee": false,
"is_buy": 1,
"class_id1": 0,
"class_id2": 0,
"class_id3": 0,
"spu_name": "UC3526DW",
"status": 1,
"images_l": "",
"encap": "",
"pdf": "http://www.ti.com/general/docs/lit/getliterature.tsp?genericPartNumber=UC2526AM&&fileType=pdf",
"spu_brief": "UC3526 稳压脉宽调制器",
"class_name": "其他",
"erp_tax": false
}
}
}
```
\ 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