Commit 76ecfcc4 by wang

新增sku进度-spu新增

parent 9a078044
...@@ -9,5 +9,5 @@ cmd.exe~ ...@@ -9,5 +9,5 @@ cmd.exe~
/cmd/logs /cmd/logs
/bat/logs/ /bat/logs/
/conf/prod/*.ini /conf/prod/*.ini
/go.mod
/conf /conf
...@@ -13,4 +13,5 @@ api_md5_str = fh6y5t4rr351d2c3bryi ...@@ -13,4 +13,5 @@ api_md5_str = fh6y5t4rr351d2c3bryi
SEARCH_API_MONITOR = 6d0fa85e01a02c39347d011ae973fd21b76c6c7ce582d3ea470c6b65a318848d SEARCH_API_MONITOR = 6d0fa85e01a02c39347d011ae973fd21b76c6c7ce582d3ea470c6b65a318848d
[spu_server]
api_domain = http://localhost:60015
;存放数据库连接信息 ;存放数据库连接信息
[xorm] [xorm]
ShowSQL = false ShowSQL = true
[spu] [spu]
user_name = spu user_name = spu
......
package controller package controller
import ( import (
"fmt"
"github.com/gin-gonic/gin" "github.com/gin-gonic/gin"
"net/http"
"go_sku_server/framework/gin_" "go_sku_server/framework/gin_"
"go_sku_server/pkg/common"
"go_sku_server/pkg/config" "go_sku_server/pkg/config"
"go_sku_server/pkg/logger"
"net/http"
) )
//放 通用中间件 //放 通用中间件
...@@ -41,3 +44,22 @@ func Cors_Middleware() gin_.Middleware { ...@@ -41,3 +44,22 @@ func Cors_Middleware() gin_.Middleware {
} }
} }
} }
/**
@author wangsong
捕获 系统内部 panic 异常,并加入日志
*/
func Error_Middleware() gin.HandlerFunc {
return func(ctx *gin.Context) {
defer func() {
if err:=recover(); err!=nil{
formDataStr:=common.GetRequestParam(ctx)
errMsg:=fmt.Sprintf("%s",err)
logger.Log("接收参数:"+formDataStr+"错误:"+errMsg,"savesku",1)
common.Output(ctx,500,errMsg,nil);
}
}()
ctx.Next()
}
}
\ No newline at end of file
package controller
import (
"github.com/gin-gonic/gin"
"github.com/gin-gonic/gin/binding"
"go_sku_server/model/saveModel"
"go_sku_server/pkg/common"
"go_sku_server/pkg/e"
"go_sku_server/pkg/logger"
"go_sku_server/service"
)
/**
@author wangsong
Attrs LadderPrice 的值是数组和对象,方便处理 只接收json请求 'Content-Type' => 'application/json'
sku基本数据增加和修改
@param 说明
GoodsName string `json:"goods_name" binding:"required"`
BrandName string `json:"brand_name" binding:"required"`
SupplierId int `json:"supplier_id" binding:"required"`
Moq int `json:"moq" binding:"required"`//起订量
Mpq int `json:"mpq" binding:"required"`//标准包装量
Canal int `json:"canal" `//渠道标签
BatchSn int `json:"batch_sn" `//批次
Stock int `json:"stock" `//库存
HkDeliveryTime string `json:"hk_delivery_time" `//香港货期
CnDeliveryTime string `json:"cn_delivery_time" `//大陆货期
LadderPrice string `json:"ladder_price" `//阶梯价钱
CpTime int `json:"cp_time" `//茂则成本添加时间
GoodsImages int `json:"goods_images" `//商品图片
GoodsSn int `json:"goods_sn" `
Encap int `json:"encap" `
Pdf int `json:"pdf" `
SpuBrief int `json:"spu_brief" `
Attrs int `json:"attrs" `
*/
func SaveSku(ctx *gin.Context) {
//参数验证
var lySaveRequest saveModel.LySaveRequest
if err := ctx.ShouldBindBodyWith(&lySaveRequest,binding.JSON); err != nil {
//加日志
formDataStr:=common.GetRequestParam(ctx)
logger.Log("接收参数:"+formDataStr+"errMsg:"+err.Error(),"savesku",1)
common.Output(ctx,10001,err.Error(),nil)
return
}
//执行skuSave
LySave:=service.LySaveService{}
serviceErr:=LySave.SaveSku(lySaveRequest,ctx)
//执行报错
if(serviceErr!=nil){
if err,ok:=serviceErr.(*e.ApiError);ok{
common.Output(ctx,err.Code,err.ErrMsg,nil)
}else{
common.Output(ctx,10001,err.Error(),nil)
}
//加日志
formDataStr1:=common.GetRequestParam(ctx)
logger.Log("接收参数:"+formDataStr1+"errMsg:"+serviceErr.Error(),"savesku",1)
return
}else {//执行成功
common.Output(ctx, 0, "success", nil)
return
}
}
func SkuEdit(ctx *gin.Context) {
}
package main
import (
"fmt"
"reflect"
)
type A struct {
A int
B int
C string
E string
}
type B struct {
A int
B int
C int
D int
}
func CopyStruct(a interface{}, b interface{}) {
sval := reflect.ValueOf(a).Elem()
dval := reflect.ValueOf(b).Elem()
for i := 0; i < sval.NumField(); i++ {
value := sval.Field(i)
name := sval.Type().Field(i).Name
dvalue := dval.FieldByName(name)
if(dvalue.Kind()!=sval.Field(i).Kind()){
continue
}
if dvalue.IsValid() == false {
continue
}
dvalue.Set(value) //这里默认共同成员的类型一样,否则这个地方可能导致 panic,需要简单修改一下。
}
}
func main() {
a := &A{1, 1, "a", "b"}
b:=&B{}
CopyStruct(a,b)
fmt.Printf("%+v", b)
}
\ No newline at end of file
package main
import (
"fmt"
"sync"
)
var wg sync.WaitGroup
func main() {
var wg sync.WaitGroup
userCount := 5
ch := make(chan bool, 2)
for i := 0; i < userCount; i++ {
wg.Add(1)
//fmt.Println(i)
ch <- true
//fmt.Println("ddd")
go send(ch, i,&wg)
}
wg.Wait()
//time.Sleep(time.Second)
}
func send(ch chan bool, i int,wg *sync.WaitGroup) {
defer wg.Done()
//time.Sleep(time.Second*i)
fmt.Println("dddd",i)
//fmt.Printf("go func: %d\n", i)
<- ch
}
...@@ -6,29 +6,30 @@ require ( ...@@ -6,29 +6,30 @@ require (
github.com/denisenkom/go-mssqldb v0.0.0-20191124224453-732737034ffd // indirect github.com/denisenkom/go-mssqldb v0.0.0-20191124224453-732737034ffd // indirect
github.com/dgraph-io/badger v1.6.2 // indirect github.com/dgraph-io/badger v1.6.2 // indirect
github.com/elliotchance/orderedmap v1.3.0 // indirect github.com/elliotchance/orderedmap v1.3.0 // indirect
github.com/gin-contrib/cors v1.3.1 github.com/gin-contrib/cors v1.3.1 // indirect
github.com/gin-gonic/gin v1.6.3 github.com/gin-gonic/gin v1.6.3
github.com/go-ini/ini v1.57.0 github.com/go-ini/ini v1.57.0
github.com/go-sql-driver/mysql v1.5.0 github.com/go-sql-driver/mysql v1.5.0
github.com/go-xorm/xorm v0.7.9 github.com/go-xorm/xorm v0.7.9
github.com/gogo/protobuf v1.3.1 // indirect github.com/gogo/protobuf v1.3.1 // indirect
github.com/golang/protobuf v1.4.2 github.com/golang/protobuf v1.4.2 // indirect
github.com/gomodule/redigo v2.0.1-0.20180401191855-9352ab68be13+incompatible github.com/gomodule/redigo v2.0.1-0.20180401191855-9352ab68be13+incompatible
github.com/gopherjs/gopherjs v0.0.0-20181103185306-d547d1d9531e // indirect github.com/gopherjs/gopherjs v0.0.0-20181103185306-d547d1d9531e // indirect
github.com/gorilla/websocket v1.4.2 // indirect github.com/gorilla/websocket v1.4.2 // indirect
github.com/grpc-ecosystem/go-grpc-middleware v1.2.0 // indirect github.com/grpc-ecosystem/go-grpc-middleware v1.2.0 // indirect
github.com/grpc-ecosystem/grpc-gateway v1.14.3 // indirect github.com/grpc-ecosystem/grpc-gateway v1.14.3 // indirect
github.com/guonaihong/gout v0.1.3
github.com/iancoleman/orderedmap v0.0.0-20190318233801-ac98e3ecb4b0 github.com/iancoleman/orderedmap v0.0.0-20190318233801-ac98e3ecb4b0
github.com/ichunt2019/go-rabbitmq v1.0.1 github.com/ichunt2019/go-rabbitmq v1.0.1
github.com/ichunt2019/logger v1.0.5 github.com/ichunt2019/logger v1.0.5
github.com/imroc/req v0.3.0 github.com/imroc/req v0.3.0
github.com/jasonlvhit/gocron v0.0.1 // indirect github.com/jasonlvhit/gocron v0.0.1 // indirect
github.com/mattn/go-sqlite3 v2.0.1+incompatible // indirect github.com/mattn/go-sqlite3 v2.0.1+incompatible // indirect
github.com/micro/go-micro v1.16.0 github.com/micro/go-micro v1.16.0 // indirect
github.com/micro/go-micro/v2 v2.9.0 github.com/micro/go-micro/v2 v2.9.0
github.com/orcaman/concurrent-map v0.0.0-20190826125027-8c72a8bb44f6 github.com/orcaman/concurrent-map v0.0.0-20190826125027-8c72a8bb44f6
github.com/prometheus/client_golang v1.5.1 // indirect github.com/prometheus/client_golang v1.5.1 // indirect
github.com/prometheus/common v0.10.0 github.com/prometheus/common v0.10.0 // indirect
github.com/prometheus/procfs v0.0.11 // indirect github.com/prometheus/procfs v0.0.11 // indirect
github.com/semihalev/gin-stats v0.0.0-20180505163755-30fdcbbd3533 github.com/semihalev/gin-stats v0.0.0-20180505163755-30fdcbbd3533
github.com/sirupsen/logrus v1.5.0 github.com/sirupsen/logrus v1.5.0
...@@ -37,19 +38,19 @@ require ( ...@@ -37,19 +38,19 @@ require (
github.com/syyongx/php2go v0.9.4 github.com/syyongx/php2go v0.9.4
github.com/tidwall/gjson v1.6.1 github.com/tidwall/gjson v1.6.1
github.com/tidwall/sjson v1.1.1 github.com/tidwall/sjson v1.1.1
github.com/uniplaces/carbon v0.1.6 github.com/uniplaces/carbon v0.1.6 // indirect
go.etcd.io/bbolt v1.3.4 go.etcd.io/bbolt v1.3.4 // indirect
go.mongodb.org/mongo-driver v1.3.5 // indirect go.mongodb.org/mongo-driver v1.3.5 // indirect
go.uber.org/zap v1.14.1 // indirect go.uber.org/zap v1.14.1 // indirect
golang.org/x/tools v0.0.0-20191216173652-a0e659d51361 golang.org/x/tools v0.0.0-20191216173652-a0e659d51361 // indirect
google.golang.org/genproto v0.0.0-20200527145253-8367513e4ece google.golang.org/genproto v0.0.0-20200527145253-8367513e4ece // indirect
google.golang.org/grpc v1.29.1 // indirect google.golang.org/grpc v1.29.1 // indirect
google.golang.org/protobuf v1.24.0 google.golang.org/protobuf v1.24.0 // indirect
gopkg.in/ini.v1 v1.51.0 // indirect gopkg.in/ini.v1 v1.51.0 // indirect
gopkg.in/mgo.v2 v2.0.0-20190816093944-a6b53ec6cb22 gopkg.in/mgo.v2 v2.0.0-20190816093944-a6b53ec6cb22
gopkg.in/olivere/elastic.v5 v5.0.85 gopkg.in/olivere/elastic.v5 v5.0.85
sigs.k8s.io/yaml v1.2.0 // indirect sigs.k8s.io/yaml v1.2.0 // indirect
xorm.io/core v0.7.2-0.20190928055935-90aeac8d08eb xorm.io/core v0.7.2-0.20190928055935-90aeac8d08eb // indirect
) )
replace google.golang.org/grpc => google.golang.org/grpc v1.26.0 replace google.golang.org/grpc => google.golang.org/grpc v1.26.0
File mode changed
File mode changed
File mode changed
File mode changed
File mode changed
File mode changed
package saveModel
/**
@author wangsong
联营sku实体-新增联营sku用到
为什么不用ly_sku 那个实体,因为ly_sku 包含了spu的信息,LySkuEntity只是针对sku表的实体
*/
type LySkuEntity struct {
GoodsName string `json:"goods_name" form:"goods_name" binding:"required"`
BrandName string `json:"brand_name" form:"brand_name" binding:"required"`
SupplierId int `json:"supplier_id" form:"supplier_id" binding:"required"`
Moq int `json:"moq" form:"moq" binding:"required"`//起订量
Mpq int `json:"mpq" form:"mpq" binding:"required"`//标准包装量
SpuId string `json:"spu_id"`
GoodsType int `json:"goods_type"`//'0:自营 1:联营 2:专卖',
Encoded string `json:"encoded"`//供应商编码
Canal string `json:"canal" form:"canal" `//渠道开发员ID
BatchSn string `json:"batch_sn" form:"batch_sn" `//批次
Stock int `json:"stock" form:"stock" `//库存
HkDeliveryTime string `json:"hk_delivery_time" form:"hk_delivery_time" `//香港货期
CnDeliveryTime string `json:"cn_delivery_time" form:"cn_delivery_time" `//大陆货期
LadderPrice string `json:"ladder_price" form:"ladder_price" `//阶梯价钱
SinglePrice float64 `json:"single_price" form:"ladder_price" `//最低价
CpTime int `json:"cp_time" form:"cp_time" `//茂则成本添加时间
GoodsSn string `json:"goods_sn" form:"goods_sn" ` //供应商自己的唯一标识码
}
package saveModel
//请求spu_server save 接口数据
type LySpuRequest struct {
GoodsName string `json:"goods_name" form:"goods_name" binding:"required"`
BrandName string `json:"brand_name" binding:"required"`
GoodsImages string `json:"goods_images" form:"goods_images" `//商品图片 所属spu
Encap string `json:"encap" form:"encap" ` //封装 所属spu
Pdf string `json:"pdf" form:"pdf" ` //PDF地址 所属spu
SpuBrief int `json:"spu_brief" form:"spu_brief" `//简短描述 所属spu
Attrs map[string]interface{} `json:"attrs" form:"attrs" ` //商品参数 所属spu
}
type LySpuResponse struct {
ErrorCode int `json:"error_code"`
ErrMsg string `json:"err_msg"`
Data interface{} `json:"data"`
}
type ResponseData struct {
SpuId string `json:"spu_id"`
}
\ No newline at end of file
package saveModel
import (
"go_sku_server/model"
"reflect"
)
/**
@author wangsong
新增联营sku请求参数结构
*/
type LySaveRequest struct {
GoodsName string `json:"goods_name" form:"goods_name" binding:"required"`
BrandName string `json:"brand_name" form:"brand_name" binding:"required"`
SupplierId int `json:"supplier_id" form:"supplier_id" binding:"required"`
Moq int `json:"moq" form:"moq" binding:"required"`//起订量
Mpq int `json:"mpq" form:"mpq" binding:"required"`//标准包装量
Canal string `json:"canal" form:"canal" `//渠道开发员ID
BatchSn int `json:"batch_sn" form:"batch_sn" `//批次
Stock int `json:"stock" form:"stock" `//库存
HkDeliveryTime string `json:"hk_delivery_time" form:"hk_delivery_time" `//香港货期
CnDeliveryTime string `json:"cn_delivery_time" form:"cn_delivery_time" `//大陆货期
LadderPrice []model.LadderPrice `json:"ladder_price" form:"ladder_price" `//阶梯价钱
CpTime int `json:"cp_time" form:"cp_time" `//茂则成本添加时间
GoodsImages string `json:"goods_images" form:"goods_images" `//商品图片 所属spu
GoodsSn string `json:"goods_sn" form:"goods_sn" ` //供应商自己的唯一标识码
Encap string `json:"encap" form:"encap" ` //封装 所属spu
Pdf string `json:"pdf" form:"pdf" ` //PDF地址 所属spu
SpuBrief int `json:"spu_brief" form:"spu_brief" `//简短描述 所属spu
Attrs map[string]interface{} `json:"attrs" form:"attrs" ` //商品参数 所属spu
}
/**
将 LySaveRequest 的值赋值到 LySkuEntity(两个结构字段和类型不一样不会赋值)
*/
func (LR *LySaveRequest)ToLySkuEntity() LySkuEntity{
lySkuEntity:=LySkuEntity{}
copyStruct(LR,&lySkuEntity)
return lySkuEntity
}
/**
将 LySaveRequest 的值赋值到 LySpuRequest(字段和类型不一样不会赋值)
*/
func (LR *LySaveRequest)ToLySpuRequest() LySpuRequest{
lySpuRequest:=LySpuRequest{}
copyStruct(LR,&lySpuRequest)
return lySpuRequest
}
//结构复制,内部方法,可能后续会封装到公共函数
func copyStruct(a interface{}, b interface{}) {
sval := reflect.ValueOf(a).Elem()
dval := reflect.ValueOf(b).Elem()
for i := 0; i < sval.NumField(); i++ {
value := sval.Field(i)
name := sval.Type().Field(i).Name
dvalue := dval.FieldByName(name)
if(dvalue.Kind()!=sval.Field(i).Kind()){
continue
}
if dvalue.IsValid() == false {
continue
}
dvalue.Set(value) //这里默认共同成员的类型一样,否则这个地方可能导致 panic,需要简单修改一下。
}
}
/*func (L * LySaveRequest)GetAttrsJson() map[string]interface{} {
if AttrsMap,ok:=L.Attrs.(map[string]interface{});ok{
if(len(AttrsMap)>0){
return AttrsMap
}
}
return nil
}
func (L * LySaveRequest)GetLadderPrice() string {
json_str:="";
if AttrsMap,ok:=L.LadderPrice.([]interface{});ok{
if(len(AttrsMap)>0){
s, _ :=json.Marshal(L.LadderPrice)
json_str=fmt.Sprintf("%s",s)
}
}
return json_str
}*/
package model
//基石供应商表实体(暂时只放用到的字段)
type SupplierEntity struct {
SupplierId int `json:"supplier_id"`
TypeId int `json:"type_id" `
Status int `json:"status" `
SupplierName string `json:"supplier_name" `
}
//联营供应商表实体(暂时只放用到的字段)
type PoolSupplierEntity struct {
SupplierCode string `json:"supplier_code"`//供应商编码
ChannelUid int `json:"channel_uid" `//渠道开发员
}
...@@ -12,13 +12,13 @@ import ( ...@@ -12,13 +12,13 @@ import (
"github.com/gin-gonic/gin" "github.com/gin-gonic/gin"
"github.com/syyongx/php2go" "github.com/syyongx/php2go"
"github.com/tidwall/gjson" "github.com/tidwall/gjson"
"go_sku_server/pkg/config"
"go_sku_server/pkg/vars"
"math" "math"
"math/big" "math/big"
"math/rand" "math/rand"
"reflect" "reflect"
"regexp" "regexp"
"go_sku_server/pkg/config"
"go_sku_server/pkg/vars"
"sort" "sort"
"strconv" "strconv"
"strings" "strings"
...@@ -56,6 +56,38 @@ func Sha1(query string, pri_key string) string { ...@@ -56,6 +56,38 @@ func Sha1(query string, pri_key string) string {
return query return query
} }
/**
@author wangsong
获取请求过来的参数,并转为字符串,作用:为了有时候需要记录请求参数,压入日志
注意:
1.如果请求的是json,接收是需要读取body,而gin大部分函数只能读取一次body,读第二次会读不到
而此函数需要频繁调用,所以需要在调用此函数之前,使用过ShouldBindBodyWith 方法,不然会读取不到。
具体需了解 ShouldBindBodyWith 源码 和 多次使用shouldbindjsond 的问题
2.表单提交不需要读body,则正常使用
*/
func GetRequestParam(ctx *gin.Context) string{
ct := ctx.Request.Header.Get("Content-Type")
switch {
case ct == "application/json":
var BodyJson string
if cb, ok := ctx.Get(gin.BodyBytesKey); ok {
if cbb, ok := cb.([]byte); ok {
BodyJson=string(cbb)
return BodyJson
}
}
return BodyJson
default:
ctx.Request.ParseForm()
postForm := ctx.Request.PostForm
formData, _ := json.Marshal(postForm);
params := string(formData)
return params;
}
}
/* /*
输出header 输出header
*/ */
......
package e
type ApiError struct {
ErrMsg string
Code int
}
func (err *ApiError) Error() string {
return err.ErrMsg
}
/**
参数1 对应 ApiError ErrMsg
参数2 对应 ApiError Code 默认1001
*/
func NewApiError(opts ...interface{}) * ApiError{
var ErrMsg string;
Code:=1001;
for num,opt:=range opts{
if(num>1){
break;
}
switch num {
case 0:
ErrMsg=opt.(string)
case 1:
Code=opt.(int)
break
}
}
return &ApiError{ ErrMsg: ErrMsg,Code:Code}
}
...@@ -24,6 +24,8 @@ func checkFileIsExist(filename string) bool { ...@@ -24,6 +24,8 @@ func checkFileIsExist(filename string) bool {
} }
return exist return exist
} }
/* /*
@param writeString 写入文件字符串 @param writeString 写入文件字符串
@param file_pre 附加文件前缀 @param file_pre 附加文件前缀
......
...@@ -23,5 +23,8 @@ func InitRouter() *gin.Engine { ...@@ -23,5 +23,8 @@ func InitRouter() *gin.Engine {
r.GET("Health", controller.Health) r.GET("Health", controller.Health)
r.POST("Health",controller.Health) r.POST("Health",controller.Health)
//自营SaveSku
r.POST("SaveSku",controller.Error_Middleware(),controller.SaveSku)
return r return r
} }
...@@ -397,3 +397,5 @@ func (ls *LyService) CombineSup(sku model.LySku, spuStr string) model.LySku { ...@@ -397,3 +397,5 @@ func (ls *LyService) CombineSup(sku model.LySku, spuStr string) model.LySku {
sku.Encap = spu.Encap sku.Encap = spu.Encap
return sku return sku
} }
package service
import (
"encoding/json"
"fmt"
"github.com/gin-gonic/gin"
"github.com/syyongx/php2go"
"go_sku_server/model"
"go_sku_server/model/saveModel"
"go_sku_server/pkg/config"
"go_sku_server/pkg/e"
"github.com/guonaihong/gout"
"sort"
)
type LySaveService struct {
}
/**
sku基本数据增加和修改
@author wangsong
@param
GoodsName string `json:"goods_name" binding:"required"`
BrandName string `json:"brand_name" binding:"required"`
SupplierId int `json:"supplier_id" binding:"required"`
Moq int `json:"moq" binding:"required"`//起订量
Mpq int `json:"mpq" binding:"required"`//标准包装量
Canal int `json:"canal" `//渠道标签
BatchSn int `json:"batch_sn" `//批次
Stock int `json:"stock" `//库存
HkDeliveryTime string `json:"hk_delivery_time" `//香港货期
CnDeliveryTime string `json:"cn_delivery_time" `//大陆货期
LadderPrice string `json:"ladder_price" `//阶梯价钱
CpTime int `json:"cp_time" `//茂则成本添加时间
GoodsImages int `json:"goods_images" `//商品图片
GoodsSn int `json:"goods_sn" `
Encap int `json:"encap" `
Pdf int `json:"pdf" `
SpuBrief int `json:"spu_brief" `
Attrs int `json:"attrs" `
*/
func (S *LySaveService)SaveSku(lySaveRequest saveModel.LySaveRequest,ctx *gin.Context) error {
lySkuEntity:=lySaveRequest.ToLySkuEntity()//sku实体
//供应商处理(供应商相关验证,验证通过 将saveSku所需参数 赋值给 &lySkuEntity)
err:=S.supplierHandle(lySaveRequest.SupplierId,lySkuEntity.Canal,&lySkuEntity)
if(err!=nil){
return err
}
//阶梯价格处理(验证阶梯价格,验证通过将 saveSku 所需参数赋值给 &lySkuEntity )
err=S.ladderPriceHandle(lySaveRequest.LadderPrice,&lySkuEntity)
if(err!=nil){
return err
}
//spu处理(请求spu_server saveSpu接口,将spuId赋值给 &lySkuEntity)
lySpuRequest:=lySaveRequest.ToLySpuRequest()
err=S.spuHandle(lySpuRequest,&lySkuEntity)
if(err!=nil){
return err
}
return nil
}
/**
新增sku 供应商处理流程(内部方法)
1.判断供应商是否存在,是否被禁用
2.供应商为专卖,参数 cannal是必传的
3.得到 新增sku所需的 TypeId 和 SupplierCode
*/
func (S *LySaveService) supplierHandle(SupplierId int,Canal string,lySkuEntity *saveModel.LySkuEntity) (error) {
lySupplier:= LySupplier{}
has,err,supplierInfo:=lySupplier.GetSupplirInfo(SupplierId)
if(err!=nil){
return e.NewApiError("获取基石供应商详情失败"+err.Error())
}
if(!has){
fmt.Sprintf("没有在基石获取到此供应商,供应商ID为:%s",SupplierId)
}
if(supplierInfo.Status!=1){
return e.NewApiError("供应商被禁用")
}
//专卖处理(供应商系统)
if(supplierInfo.TypeId==2){
if(Canal==""){
return e.NewApiError("专卖 cannal参数为必传")
}
has,err,poolSupplierInfo:=lySupplier.GetPoolSupplirInfo(Canal)
if(err!=nil){
return e.NewApiError("获取联营供应商详情失败"+err.Error())
}
if(!has){
errmsg:=fmt.Sprintf("没有获取到渠道%s的内部编码",Canal)
return e.NewApiError(errmsg)
}
lySkuEntity.Encoded=poolSupplierInfo.SupplierCode//渠道编码赋值给sku
}
lySkuEntity.GoodsType=supplierInfo.TypeId
return nil
}
/**
阶梯价格处理
1.对阶梯价格排序
2.获取 ladderPrice 最便宜的价格
*/
func (S *LySaveService) ladderPriceHandle(ladderPrice []model.LadderPrice,lySkuEntity *saveModel.LySkuEntity) error {
num:=len(ladderPrice)
if(len(ladderPrice)>0){
sort.Sort(LadderPriceSorter(ladderPrice))
lySkuEntity.SinglePrice=0
if(ladderPrice[0].PriceUs>=0){
lySkuEntity.SinglePrice=ladderPrice[num-1].PriceUs//获取最便宜的价钱
}else{
php2go.Round(ladderPrice[num-1].PriceCn/6.8)
}
}
priceBytes,err:=json.Marshal(ladderPrice)
if(err!=nil){
return e.NewApiError("阶梯价格json化报错"+err.Error())
}else{
lySkuEntity.LadderPrice=string(priceBytes)
}
return nil
}
/**
spu处理(内部方法)
1.调用spu_server saveSpu接口,获取到spuId
| 参数 | 示例值 | 参数描述 |
| :-------- | :----- | :---- |
| error_code | 10001 | 错误码 0代表成功响应 |
| err_msg | | 错误提示 |
| data | | 返回的data |
*/
func (S *LySaveService) spuHandle(lySpuRequest saveModel.LySpuRequest,lySkuEntity *saveModel.LySkuEntity) (error) {
lySpuResponse:=saveModel.LySpuResponse{}
j,_:=json.Marshal(lySpuRequest)
m:=make(map[string]interface{})
err:=json.Unmarshal(j, &m)
if(err!=nil){
return e.NewApiError("请求spu接口参数有误 map化报错"+err.Error())
}
err=gout.POST(config.Get("spu_server.api_domain").String()+"/saveSpu").Debug(true).SetJSON(&m).BindJSON(&lySpuResponse).Do()
if(err!=nil){
return e.NewApiError("调用spu server saveSpu接口报错"+err.Error())
}
if(lySpuResponse.ErrorCode==0){
//lySkuEntity.SpuId=lySpuResponse.Data
}else{
return e.NewApiError("spu Throw out"+lySpuResponse.ErrMsg)
}
return nil
}
func (S *LySaveService)SkuEdit() {
}
\ No newline at end of file
package service
import (
"go_sku_server/model"
"go_sku_server/pkg/mysql"
)
type LySupplier struct {
}
/**
获取基石供应商详情(基石)
@author wangsong
@param SupplierId 供应商Id
*/
func (L *LySupplier) GetSupplirInfo(SupplierId int) (bool,error,*model.SupplierEntity) {
supplierEntity:= &model.SupplierEntity{}
has,err:= mysql.Conn("spu").Table("lie_supplier").Where("supplier_id=?",SupplierId).Get(supplierEntity)
return has,err,supplierEntity
}
/**
获取联营供应商详情(联营供应商)
@author wangsong
@param supplierCode 供应商渠道创建人
*/
func (L *LySupplier) GetPoolSupplirInfo(supplierCode string) (bool,error,*model.PoolSupplierEntity){
poolSupplierEntity:= &model.PoolSupplierEntity{}
has,err:= mysql.Conn("supp").Table("lie_supplier_channel").Where("supplier_code=?",supplierCode).Get(poolSupplierEntity);
return has,err,poolSupplierEntity
}
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