Commit b02d98af by wang

暂存一下

parent bfdb8c21
......@@ -16,3 +16,9 @@ SEARCH_API_MONITOR = 6d0fa85e01a02c39347d011ae973fd21b76c6c7ce582d3ea470c6b65a31
[spu_server]
;api_domain = http://192.168.2.72:8005
api_domain = http://localhost:8005
[save_zy_config]
supplier_rule = {"10000_2":{"price":{"is_ladder":true,"ratio":1.13},"supplier_stock":{"ratio":0.78},"fill_field":{"encoded":"10142"}},"10000_3":{"price":{"is_ladder":false,"ratio":1.13,"ladder_ratio":1.13},"supplier_stock":{"ratio":1},"fill_field":{"encoded":"10011"}},"10000_4":{"price":{"is_ladder":true,"ratio":1.15,"ladder_ratio":1},"supplier_stock":{"ratio":1},"fill_field":{"encoded":"10142"}}}
pack_rule = {"编带":{"packing":5,"pick_type":1},"袋装":{"packing":6,"pick_type":3},"包":{"packing":6,"pick_type":3},"管装":{"packing":8,"pick_type":3},"管":{"packing":8,"pick_type":3},"盒装":{"packing":7,"pick_type":3},"盒":{"packing":7,"pick_type":3},"托盘":{"packing":9,"pick_type":3},"盘":{"packing":5,"pick_type":1},"大盘":{"packing":5,"pick_type":1}}
goods_unit = {"个":1,"米":2}
sku_name = {"class_id2":["custom1",-1,"分类名称",2],"brand_id":["custom2",252,"制造商",1],"encap":["custom3",253,"封装",1],"goods_name":["custom4",255,"商品型号",2],"packing":["custom5",254,"包装/方式",2]}
;存放数据库连接信息
[xorm]
ShowSQL = false
ShowSQL = true
[spu]
user_name = spu
......
; 比如 sku_save,5000 路径 sku_save 即文件夹是 sku 文件名类似 是save_2020-12-10.log,5000代表队列的容量为5000
[log_config]
1=lysku_save,5000
2=sku_query,5000
3=default_sku,5000
2=zysku_save,5000
3=sku_query,5000
4=default_sku,5000
......@@ -6,6 +6,7 @@ import (
"go_sku_server/framework/gin_"
"go_sku_server/pkg/common"
"go_sku_server/pkg/config"
"go_sku_server/pkg/e"
"net/http"
)
......@@ -52,8 +53,13 @@ func Error_Middleware() gin.HandlerFunc {
return func(ctx *gin.Context) {
defer func() {
if err:=recover(); err!=nil{
errMsg:=fmt.Sprintf("%s",err)
common.NResponse(errMsg).SetLogHandel(saveLogHandle).OutPut(ctx)
if apiError,ok:=err.(*e.ApiError);ok{
fmt.Println(apiError.ErrMsg)
common.NResponse(apiError.ErrMsg,apiError.Code).SetLogHandel(saveLogHandle).OutPut(ctx)
}else{
errMsg:=fmt.Sprintf("%s",err)
common.NResponse(errMsg,500).SetLogHandel(saveLogHandle).OutPut(ctx)
}
}
}()
ctx.Next()
......
......@@ -75,7 +75,6 @@ func SaveZySku(ctx *gin.Context) {
common.NResponse(err.Error()).SetLogHandel(saveLogHandle).OutPut(ctx)
return
}
zySave:=service.ZySaveService{}
serviceErr:=zySave.SaveZySku(zySaveRequest,ctx)
//错误处理
......
#### 说明
此dao层目前只有 新增自营sku的接口在使用
\ No newline at end of file
package dao
import (
"encoding/json"
"fmt"
"github.com/gogf/gf/util/gconv"
"github.com/gomodule/redigo/redis"
"github.com/tidwall/gjson"
"go_sku_server/model"
"go_sku_server/pkg/gredis"
"go_sku_server/pkg/mysql"
)
/*
@author wangsong
@desc 封装单纯的自营品牌 增删改查
*/
/**
查询BrandId,查询自营品牌映射(根据 supplier_id self_supplier_type self_supplier_id)
@param supplier_id 供应商ID
@param self_supplier_type 自采标记
@param self_supplier_id 自采供应商唯一商品ID(采集那边的id)
*/
func GetBrandMappingId(supplierId int, selfSupplierType int, supplierBrandId int) (err error,brandId int64) {
redisReadConn := gredis.Conn("search_r")
defer redisReadConn.Close()
gconv.String(supplierId)
brandKey:=gconv.String(supplierId)+"_"+gconv.String(selfSupplierType)+"_"+gconv.String(supplierBrandId)
fmt.Print(brandKey)
brandJsonStr,err:=redis.String(redisReadConn.Do("Hget","Self_supplier_brand_mapping",brandKey))
if(err!=nil ){
if(err==redis.ErrNil){
return nil,0
}
return fmt.Errorf("method:GetBrandMapping"+err.Error()),0
}
return nil,gjson.Get(brandJsonStr,"brand_id").Int()
}
func GetRedisBrand(brandId int) (string,error){
redisReadConn := gredis.Conn("search_r")
defer redisReadConn.Close()
brandJsonStr,err:=redis.String(redisReadConn.Do("Hget","Self_Brand",brandId))
if(err!=nil ){
if(err==redis.ErrNil){
return "",nil
}
return "",fmt.Errorf("method:GetBrandMapping"+err.Error())
}
return brandJsonStr,nil
}
//获取品牌mysq
func GetDbBrand(brandId int) (brandModel *model.ZyBrand,err error){
dbSpu:= mysql.Conn("liexin_data") //spu实例化链接
brandModel.BrandId=brandId
_,err=dbSpu.Table("lie_brand").Get(brandModel)
if(err!=nil){
return brandModel,fmt.Errorf("method:GetDbBrand,"+err.Error())
}
return
}
//插入品牌到redis
func InSertRedisBrand(brandModel model.ZyBrand ) error{
redisWriteConn := gredis.Conn("search_w")
defer redisWriteConn.Close()
byte,err:=json.Marshal(brandModel)
if(err!=nil){
return fmt.Errorf("method:InSertRedisBrand,"+err.Error())
}
_,err=redisWriteConn.Do("HSET","Self_Brand",brandModel.BrandId,string(byte))
return err
}
\ No newline at end of file
package dao
import (
"fmt"
"github.com/gogf/gf/util/gconv"
"github.com/gomodule/redigo/redis"
"go_sku_server/model"
"go_sku_server/pkg/gredis"
"go_sku_server/pkg/mysql"
)
/**
获取分类映射
*/
func GetClassMapping(supplierId int, selfSupplierType int, supplierClassId int) (classJsonStr string) {
redisReadConn := gredis.Conn("search_r")
defer redisReadConn.Close()
gconv.String(supplierId)
classKey:=gconv.String(supplierId)+"_"+gconv.String(selfSupplierType)+"_"+gconv.String(supplierClassId)
fmt.Print(classKey)
classJsonStr,err:=redis.String(redisReadConn.Do("Hget","Self_supplier_class_mapping",classKey))
if(err!=nil ){
if(err==redis.ErrNil){
return ""
}
panic("method:GetClassMapping"+err.Error())
}
return
}
/**
获取分类税务详情(获取根据 税务分类编码获取税务分类详情)
*/
func GetFinancialClassInfo(classifySn string) (zyFinancialClassify model.ZyFinancialClassify,err error){
dbSpu:= mysql.Conn("liexin_data") //spu实例化链接
whereStr:="classify_sn =?"
_,err= dbSpu.Table("lie_self_financial_classify").Where(whereStr,classifySn).Get(&zyFinancialClassify)
if(err!=nil){
return zyFinancialClassify,fmt.Errorf("method:GetFinancialClassInfo,"+err.Error())
}
return
}
/**
获取分类信息
*/
func GetClassInfo(classId int) (zyClassify *model.ZyClassify,err error) {
dbSpu:= mysql.Conn("liexin_data") //spu实例化链接
zyClassify=&model.ZyClassify{}
zyClassify.ClassId=classId
_,err= dbSpu.Table("lie_self_classify").Get(zyClassify)
if(err!=nil){
return zyClassify,fmt.Errorf("method:GetClassInfo,"+err.Error())
}
return
}
package dao
import (
"encoding/json"
"fmt"
"go_sku_server/model"
"go_sku_server/pkg/gredis"
"go_sku_server/pkg/mysql"
)
/*
@author wangsong
@desc 封装单纯的自营商品 增删改查
*/
/**
获取商品ID查询自营商品信息
@param goodsId int 商品id
*/
func GetZyGoodSInfoById(goodsId int) {
}
/**
查询自营商品信息(根据 supplier_id self_supplier_type self_supplier_id)
@param supplier_id 供应商ID
@param self_supplier_type 自采标记
@param self_supplier_id 自采供应商唯一商品ID(采集那边的id)
*/
func GetZyGoodSInfoByCollect(supplierId int ,selfSupplierType int,selfSupplierId string) (zySkuEntity model.ZySkuEntity,err error) {
dbSpu:= mysql.Conn("liexin_data") //spu实例化链接
zySkuEntity.SupplierId=supplierId
zySkuEntity.SelfSupplierType=selfSupplierType
zySkuEntity.SelfSupplierId=selfSupplierId
_,err= dbSpu.Table("lie_goods").Get(&zySkuEntity)
if(err!=nil){
return zySkuEntity,fmt.Errorf("method:GetZyGoodSInfoByCollect,"+err.Error())
}
return
}
/**
获取相似商品
@param self_supplier_type 自采标记
@param brandId 品牌Id
*/
func GetSimilarGoods(selfSupplierType int,brandId int64) (zySkuEntity []model.ZySkuEntity,err error) {
dbSpu:= mysql.Conn("liexin_data") //spu实例化链接
zySkuEntityS := make([]model.ZySkuEntity, 0)
whereStr:="self_supplier_type =? and self_supplier_id ='' and brand_id=?"
err= dbSpu.Table("lie_goods").Where(whereStr,selfSupplierType,brandId).Find(&zySkuEntityS)
if(err!=nil){
return zySkuEntity,fmt.Errorf("method:GetSimilarGoods,"+err.Error())
}
return
}
//插入自营sku到redis
func InsertDbGoods(zySkuEntity model.ZySkuEntity) (affected int64, err error) {
db:= mysql.Conn("liexin_data") //spu实例化链接
return db.Table("lie_goods").Where("goods_id=?",zySkuEntity.GoodsId).Update(zySkuEntity)
}
//插入自营sku到mysql
func InsertRedisGoods(zySkuEntity model.ZySkuEntity) error {
redisWriteConn := gredis.Conn("search_w")
defer redisWriteConn.Close()
byte,err:=json.Marshal(zySkuEntity)
if(err!=nil){
return fmt.Errorf("method:InsertDbGoods,"+err.Error())
}
_,err=redisWriteConn.Do("HSET","Self_SelfGoods",zySkuEntity.GoodsId,string(byte))
return err
}
package dao
import (
"fmt"
"github.com/gomodule/redigo/redis"
"go_sku_server/pkg/gredis"
)
func GetRedisUnit(key int) (err error,packingCn string){
redisReadConn := gredis.Conn("search_r")
defer redisReadConn.Close()
packingCn,err=redis.String(redisReadConn.Do("HGET","Self_Unit",key))
if(err!=nil ){
if(err==redis.ErrNil){
return nil,packingCn
}
return fmt.Errorf("method:GetRedisUnit"+err.Error()),packingCn
}
return
}
\ No newline at end of file
package saveModel
import (
"go_sku_server/model/saveZyRule"
)
type SaveZyRule interface {
Configs() string
Init(configs ...string)
}
type RuleConfig struct {
SkuNameRule *saveZyRule.SkuNameRule
PackRule *saveZyRule.PackRule
GoodsUnitRule *saveZyRule.GoodsUnitRule
SupplierRule *saveZyRule.SupplierRule
}
func RuleInitObj() (*RuleConfig){
ruleConfig:= &RuleConfig{}
ruleConfig.instance(&saveZyRule.SupplierRule{})
ruleConfig.instance(&saveZyRule.GoodsUnitRule{})
ruleConfig.instance(&saveZyRule.PackRule{})
ruleConfig.instance(&saveZyRule.SkuNameRule{})
return ruleConfig
}
func (R *RuleConfig) instance(rule SaveZyRule) {
rule.Init()
switch rule.(type) {
case *saveZyRule.SkuNameRule:
obj,_:=rule.(*saveZyRule.SkuNameRule)
R.SkuNameRule=obj
case *saveZyRule.SupplierRule:
obj,_:=rule.(*saveZyRule.SupplierRule)
R.SupplierRule=obj
case *saveZyRule.PackRule:
obj,_:=rule.(*saveZyRule.PackRule)
R.PackRule=obj
case *saveZyRule.GoodsUnitRule:
obj,_:=rule.(*saveZyRule.GoodsUnitRule)
R.GoodsUnitRule=obj
}
}
package saveModel
import (
"fmt"
"github.com/go-playground/validator/v10"
"math"
)
import "go_sku_server/model"
/**
return [
'cn'=>[
......@@ -75,12 +72,13 @@ var ZyCodes =ZySaveErrcodeCn{}
type ZySaveRequest struct {
SupplierId int `json:"supplier_id" form:"supplier_id" binding:"required"`//供应商ID
Status int `json:"status" form:"status" `//供应商ID
SelfSupplierType int `json:"self_supplier_type" form:"self_supplier_type" binding:"required"`//自采标记:寄售填1,京北3,立创2,油柑4(商品类别是猎芯自采)
SelfSupplierId string `json:"self_supplier_id" form:"self_supplier_id" binding:"required"`
GoodsId int `json:"goods_id" form:"goods_id"`
IsAdd bool //是否新增,默认为false
SupplierBrandId int `json:"supplier_brand_id" form:"supplier_brand_id" binding:"required_with=IsAdd"`// 新增时必填,必须要是建立了映射关系的品牌ID
SupplierBrandId int `json:"supplier_brand_id" form:"supplier_brand_id" validate:"required_with=IsAdd"`// 新增时必填,必须要是建立了映射关系的品牌ID
GoodsName string `json:"goods_name" form:"goods_name" validate:"required_with=IsAdd"`//新增时必填
Encap string `json:"encap" form:"encap" validate:"required_with=IsAdd"`//新增时必填
Packing string `json:"packing" form:"packing" validate:"required_with=IsAdd"`//新增时必填
......@@ -91,12 +89,12 @@ type ZySaveRequest struct {
Cost float64 `json:"cost" form:"cost" `//成本(用于生成阶梯价的价钱),新增时,与ladder_price必填一个,取决于商品价格生成规则
LadderPrice []LadderPrice `json:"ladder_price" form:"ladder_price" `
LadderPrice []model.LadderPrice `json:"ladder_price" form:"ladder_price" `
Mpl int `json:"mpl" form:"mpl" `//倍数
Barcode string `json:"barcode" form:"barcode" `//原厂条码,新增时默认goods_name
SupplierStock string `json:"supplier_stock" form:"supplier_stock" `//供应商库存
OtherAttrs interface{} `json:"other_attrs" form:"other_attrs" `//其他参数,长度(cm暂时未用到)和重量(kg)
SupplierStock int `json:"supplier_stock" form:"supplier_stock" `//供应商库存
OtherAttrs map[string]interface{} `json:"other_attrs" form:"other_attrs" `//其他参数,长度(cm暂时未用到)和重量(kg)
}
type ZySaveErrcodeCn map[int]string
......@@ -126,45 +124,4 @@ type LadderPrice struct {
PriceCn float64 `json:"price_cn"` //数量对应的中文价格
}
//新增sku数据验证,ladder_price 和 cost必填一个,有些字段必填
func (Z *ZySaveRequest)AddDataAlidator() error{
validate:= validator.New()
if(Z.LadderPrice==nil && math.Float64bits(Z.Cost) == 0){
return fmt.Errorf("新增sku时,LadderPrice 和 Cost必填一个")
}
err:= validate.Struct(Z)
if(err!=nil){
if fieldError,ok:=err.(validator.ValidationErrors);ok{
if(fieldError[0].Tag()=="required_with"){
return fmt.Errorf("新增sku缺少必填字段:"+fieldError[0].Field())
}
}
}
return nil
}
/*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 saveZyRule
import (
"encoding/json"
"go_sku_server/pkg/config"
)
//新增自营单位规则
type GoodsUnitRule struct {
Data map[string]int
}
func (GU *GoodsUnitRule) Configs() string{
return config.Get("save_zy_config.goods_unit").String()
}
func (GU *GoodsUnitRule) Get(packCnName string) int{
return GU.Data[packCnName]
}
func (GU *GoodsUnitRule) Init(configs ...string) {
config:=GU.Configs()
err:=json.Unmarshal([]byte(config),&GU.Data)
if(err!=nil){
panic("SkuNameRule init "+err.Error())
}
}
\ No newline at end of file
package saveZyRule
import (
"encoding/json"
"go_sku_server/pkg/config"
)
//新增自营包装规则
type PackRule struct {
data map[string]packData
}
type packData struct {
PickType int `json:"pick_type"`
Packing int `json:"packing" `
}
func (P *PackRule) Configs() string{
return config.Get("save_zy_config.pack_rule").String()
}
func (P *PackRule) Get(packCnName string) packData{
return P.data[packCnName]
}
func (P *PackRule) Init(configs ...string){
config:=P.Configs()
err:=json.Unmarshal([]byte(config),&P.data)
if(err!=nil){
panic("SkuNameRule init "+err.Error())
}
}
\ No newline at end of file
php 对于新增sku 有很多,有很多数组配置,此文件夹里的go文件就是那些配置
* 封装规则
* 供应商规则
* sku_name生成规则
* 商品单位配置规则
\ No newline at end of file
package saveZyRule
import (
"encoding/json"
"github.com/gogf/gf/util/gconv"
"go_sku_server/pkg/config"
"sort"
)
/**
新增自营sku sku_name生成规则
以下为sku_name json 配置格式
{
"class_id2": [
"custom1",
-1,
"分类名称",
2
],
"brand_id": [
"custom2",
252,
"制造商",
1
],
"encap": [
"custom3",
253,
"封装",
1
],
"goods_name": [
"custom4",
255,
"商品型号",
2
],
"packing": [
"custom5",
254,
"包装/方式",
2
]
}
*/
type SkuNameRule struct {
data []skuNameRuleConfig
}
type skuNameRuleConfig struct {
AttrId string `json:"attr_id"` //参与自定义的元素 custom1 分类名称 custom2 制造商品牌ID custom3 封装 custom4 商品型号 custom5 包装方式
NameSort int `json:"name_sort"` //排序,组成sku_name 字符串的位置
AttrName string `json:"attr_name"`//查看了php代码,此字段在组成sku_name没有一点用
IsName int `json:"is_name"` //是否参与自定义sku_name 1:否 2:是'
}
func (SR *SkuNameRule) Configs() string{
return config.Get("save_zy_config.sku_name").String()
}
//根据json配置转换成 SkuNameRule
func (SR *SkuNameRule) Init(configs ...string) {
config:=""
if(len(configs)>0){
config=configs[0]
}else{
config=SR.Configs()
}
var mapNew=make(map[string][]interface{})
err:=json.Unmarshal([]byte(config),&mapNew)
skuNameRuleConfigObj:=skuNameRuleConfig{}
for _,v:=range mapNew {
IsName:=gconv.Int(v[3])
if(IsName==2){
skuNameRuleConfigObj.AttrName=gconv.String(v[2])
skuNameRuleConfigObj.NameSort=gconv.Int(v[1])
skuNameRuleConfigObj.IsName=gconv.Int(v[3])
skuNameRuleConfigObj.AttrId=gconv.String(v[0])
SR.data=append(SR.data,skuNameRuleConfigObj)
}
}
if(err!=nil){
panic("SkuNameRule init "+err.Error())
}
}
func (SR *SkuNameRule) ResetRule(config string) {
SR.Init(config)
}
func (SR *SkuNameRule) ConfigList() []skuNameRuleConfig {
return SR.data
}
//排序 按照NameSort 从小到大
func (SR *SkuNameRule) Sort() {
sort.Sort(skuNameRuleSorter(SR.data))
}
type skuNameRuleSorter []skuNameRuleConfig
func (a skuNameRuleSorter) Len() int {
return len(a)
}
func (a skuNameRuleSorter) Swap(i, j int) {
a[i], a[j] = a[j], a[i]
}
func (a skuNameRuleSorter) Less(i, j int) bool {
return a[j].NameSort < a[i].NameSort
}
package saveZyRule
import (
"encoding/json"
"go_sku_server/pkg/config"
)
/**
新增自营sku 供应商规则
配置格式json如下
{
"10000_2": {
"price": {
"is_ladder": true,
"ratio": 1.13
},
"supplier_stock": {
"ratio": 0.78
},
"fill_field": {
"encoded": "10142"
}
}
}
*/
type SupplierRule struct {
data map[string]SupplierData
}
type SupplierData struct {
Price zyPriceData `json:"price"`//阶梯价格
SupplierStock SupplierStock `json:"supplier_stock"`//供应商库存
FillField FillField `json:"fill_field"`//填充字段
}
//阶梯价格
type zyPriceData struct {
IsLadder bool `json:"is_ladder"`
Ratio float64 `json:"ratio"` //ratio 价格比率
LadderRatio float64 `json:"ladder_ratio"` //ladder_ratio 购买数量比率
}
func (ZP *zyPriceData)IsEmpty() bool {
return *ZP==zyPriceData{}
}
//供应商库存
type SupplierStock struct {
Ratio float64 `json:"ratio"`
}
//填充字段
type FillField struct {
Encoded string `json:"encoded"`
}
func (ZP *SupplierRule) Configs() string{
return config.Get("save_zy_config.supplier_rule").String()
}
func (ZP *SupplierRule) Get(supplierId_Type string) SupplierData {
return ZP.data[supplierId_Type]
}
func (ZP *SupplierRule) Init(configs ...string){
config:=ZP.Configs()
err:=json.Unmarshal([]byte(config),&ZP.data)
if(err!=nil){
panic("SupplierRule init "+err.Error())
}
}
package model
type ZyBrand struct {
BrandLogo string `json:"brand_logo" form:"brand_logo" `
BrandId int `json:"brand_id" form:"brand_id" `
BrandName string `json:"brand_name" form:"brand_name" `
BrandArea int `json:"brand_area" form:"brand_area" `
Status int `json:"brand_area" form:"brand_area" `
}
package model
type ZyClassify struct {
ClassName string `json:"class_name" form:"class_name" `
Custom string `json:"custom" form:"custom" `
ClassId int `json:"class_id" form:"class_id" `
}
package model
//财务分类
type ZyFinancialClassify struct {
ClassifySn string `json:"classify_sn" form:"classify_sn" `
ClassifyParentSn string `json:"classify_parent_sn" form:"classify_parent_sn" `
Level int `json:"level" form:"level" `
ClassifyName string `json:"classify_name" form:"classify_name" `
}
type SelfClassify struct {
Custom string `json:"custom" form:"custom" `
}
package model
package model
//php
/**
$fieldArr=['other_attrs', 'pick_type', 'barcode', 'goods_id','goods_type','supplier_id','brand_id','class_id1','class_id2','goods_name','status',
'encoded','encap','packing','goods_unit','goods_images','pdf','goods_brief','moq','mpq',
'ladder_price','update_time','sku_name','mpl','stock','attrs','cost','new_cost','supplier_stock','self_supplier_type'];
$info=$this->where('goods_id', '=', $goods_id)->select($fieldArr)->first();
*/
//@author wangsong
/**
LadderPrice 说明
查看 自营商品表的 LadderPrice字段,里面的 price_cn 有时候是字符串(带引号),有时候不带引号……无语
[{"purchases":1,"price_cn":1.1},{"purchases":2,"price_cn":2.1},{"purchases":3,"price_cn":3.1},{"purchases":4,"price_cn":4.1},{"purchases":5,"price_cn":5.1},{"purchases":6,"price_cn":6.1},{"purchases":7,"price_cn":7.1},{"purchases":8,"price_cn":8.1}]
[{"purchases":"1","price_cn":"6.1","price_us":""},{"purchases":"50","price_cn":"5.6","price_us":""},{"purchases":"100","price_cn":"5.2","price_us":""}]
*/
type ZyHistoryPrice struct {
GoodsId int ` json:"goods_id" form:"goods_id"`//自营classID2
Price float64 `json:"price" form:"price" `//成本(用于生成阶梯价的价钱),新增时,与ladder_price必填一个,取决于商品价格生成规则
AddTime int `json:"add_time" xorm:"created"`
UpdateTime int `json:"update_time" xorm:"updated"`
}
package model
//php
/**
$fieldArr=['other_attrs', 'pick_type', 'barcode', 'goods_id','goods_type','supplier_id','brand_id','class_id1','class_id2','goods_name','status',
'encoded','encap','packing','goods_unit','goods_images','pdf','goods_brief','moq','mpq',
'ladder_price','update_time','sku_name','mpl','stock','attrs','cost','new_cost','supplier_stock','self_supplier_type'];
$info=$this->where('goods_id', '=', $goods_id)->select($fieldArr)->first();
*/
//@author wangsong
/**
LadderPrice 说明
查看 自营商品表的 LadderPrice字段,里面的 price_cn 有时候是字符串(带引号),有时候不带引号……无语
[{"purchases":1,"price_cn":1.1},{"purchases":2,"price_cn":2.1},{"purchases":3,"price_cn":3.1},{"purchases":4,"price_cn":4.1},{"purchases":5,"price_cn":5.1},{"purchases":6,"price_cn":6.1},{"purchases":7,"price_cn":7.1},{"purchases":8,"price_cn":8.1}]
[{"purchases":"1","price_cn":"6.1","price_us":""},{"purchases":"50","price_cn":"5.6","price_us":""},{"purchases":"100","price_cn":"5.2","price_us":""}]
*/
type ZySkuEntity struct {
//tod……
SupplierId int `json:"supplier_id"`
SupplierBrandId int `json:"supplier_brand_id" form:"supplier_brand_id" binding:"required_with=IsAdd"`// 新增时必填,必须要是建立了映射关系的品牌ID
SelfSupplierId string `json:"self_supplier_id" form:"self_supplier_id" binding:"required"`
SelfSupplierType int `json:"self_supplier_type" form:"self_supplier_type" binding:"required"`//自采标记:寄售填1,京北3,立创2,油柑4(商品类别是猎芯自采)
SupplierStock int `json:"supplier_stock" form:"supplier_stock" `//供应商库存
NewCost float64 `json:"new_cost" form:"new_cost" `//成本(用于生成阶梯价的价钱),新增时,与ladder_price必填一个,取决于商品价格生成规则
Cost float64 `json:"cost" form:"cost" `//成本(用于生成阶梯价的价钱),新增时,与ladder_price必填一个,取决于商品价格生成规则
Stock int `json:"stock" form:"stock" `//倍数
Mpl int `json:"mpl" form:"mpl" `//倍数
SkuName string `json:"sku_name" form:"sku_name" ` //skuName
LadderPrice string `json:"ladder_price" form:"ladder_price" `
Moq int `json:"moq" form:"moq" validate:"required_with=IsAdd"`//新增时必填
Mpq int `json:"mpq" form:"mpq" validate:"required_with=IsAdd"`//新增时必填
GoodsBrief string `json:"goods_brief" form:"goods_brief" ` //简短描述
Pdf string `json:"pdf" form:"pdf" ` //PDF地址
GoodsImages string `json:"goods_images" form:"goods_images" `
GoodsUnit int `json:"goods_unit" form:"goods_unit" validate:"required_with=IsAdd"`//SKU单位名称
Packing int `json:"packing" form:"packing" validate:"required_with=IsAdd"`//包装/方式
Encap string `json:"encap" form:"encap" `//封装/规格
Status int `json:"status" `
Encoded string `json:"encoded" `//内部编码
GoodsName string `json:"goods_name" form:"goods_name" `
BrandId int `json:"brand_id" form:"brand_id" `// 品牌ID
SupplierId int `json:"supplier_id" form:"supplier_id" `//供应商ID
GoodsId int `json:"goods_id" form:"goods_id"`
GoodsType int `json:"goods_type" form:"goods_type" `//原厂条码,新增时默认goods_name
Barcode string `json:"barcode" form:"barcode" `//原厂条码,新增时默认goods_name
PickType int `json:"pick_type" form:"pick_type"`//供应商ID
OtherAttrs string `json:"other_attrs" form:"other_attrs" `//其他参数,长度(cm暂时未用到)和重量(kg)
Attrs []Attrs `json:"attrs" form:"attrs" `//参数
FinancialClassifyId string `json:"financial_classify_id" form:"financial_classify_id" `//税务分类ID
TaxClassifyName string `json:"tax_classify_name" form:"tax_classify_name" `//税务分类全称
UniqueMd5 string `json:"unique_md5" form:"unique_md5" `//识别标识(由型号、供应商、品牌、包装、封装拼接MD5加密生成)
ClassId1 int `json:"class_id1" form:"class_id1"`//自营classID
ClassId2 int ` json:"class_id2" form:"class_id2"`//自营classID2
IsPerfect int ` json:"is_perfect" form:"is_perfect"`//自营classID2
IsSelfName int ` json:"is_self_name" form:"is_self_name"`//自营classID2
AddTime int `json:"add_time" xorm:"created"`
SaleTime int `json:"sale_time"`
UpdateTime int `json:"update_time" xorm:"updated"`
}
......@@ -129,6 +129,12 @@ func CopyStruct(struct1 interface{}, struct2 interface{}, Status ...int) {
}
}
if(name=="LadderPrice"){
if dvalue.Kind() != sval.Field(i).Kind() { //类型不一样不复制
continue
}
}
if dvalue.Kind() != sval.Field(i).Kind() { //类型不一样不复制
continue
}
......@@ -600,4 +606,20 @@ func MyRound(x float64, wei int) float64 {
return a
}
/*
@author wangsong
保留小数点几位(四舍五入)
@param float64 val 目标分析字符串
@param int precision 取小数多少位
*/
func Round(val float64, precision int) (valueFloat64 float64) {
//strconv.ParseFloat(fmt.Sprintf("%.2f", 12.0), 64) //两位
format:="%."+strconv.Itoa(precision)+"f"
valueFloat64,err:= strconv.ParseFloat(fmt.Sprintf(format, val), 64)
if(err!=nil){
panic("round err"+err.Error())
}
return
}
////////////类型转换/////////////////////
......@@ -12,6 +12,7 @@ var (
func SetUp(path string) (err error) {
//引入多个文件
Cfg, err = ini.LooseLoad(path+"/config.ini", path+"/database.ini", path+"/redis.ini", path+"/rabmq.ini", path+"/mongo.ini",path+"/log.ini")
//Cfg, err = ini.LooseLoad(path+"/config.ini", path+"/database.ini", path+"/redis.ini", path+"/rabmq.ini", path+"/mongo.ini",path+"/log.ini")
return
}
......
package e
import "fmt"
type ApiError struct {
ErrMsg string
......@@ -34,4 +35,16 @@ func NewApiError(opts ...interface{}) * ApiError{
return &ApiError{ ErrMsg: ErrMsg,Code:Code}
}
/**
检测异常,并抛出异常
*/
func CheckError(err error) {
if err != nil {
fmt.Print(err.Error());
if apiError,ok:=err.(*ApiError);ok{
panic(apiError)
}else{
panic(NewApiError(err.Error()))
}
}
}
package service
import (
"github.com/tidwall/gjson"
"go_sku_server/dao"
)
type ZyBrandService struct {
}
/**
获取自营品牌名称
@ brandId 品牌ID
redis 读不到到mysql读,mysql有数据再入redis缓存
*/
func (ZB *ZyBrandService) GetBrandName (brandId int) (error,string){
redisBrandStr,err:=dao.GetRedisBrand(brandId)
if(err!=nil){
return err,""
}
if(redisBrandStr!=""){
return nil,gjson.Get(redisBrandStr,"brand_name").String()
}else{
res,err:=dao.GetDbBrand(brandId)
if(err!=nil){
return err,""
}
if(res.BrandName!=""){
//todo 设置品牌缓存 ,其实可以用异步
err=dao.InSertRedisBrand(*res)
if(err!=nil){
return err,""
}
return err,res.BrandName
}
}
return nil,""
}
package service
import (
"go_sku_server/dao"
)
type FinancialClassService struct {
TaxClassifyName string
}
/**
获取税务分类名字
@ classifySn 税务分类编码
*/
func (F *FinancialClassService) GetFinancialClassInfoName(classifySn string) (string,error){
if(F.TaxClassifyName!=""){
F.TaxClassifyName=F.TaxClassifyName+"/"
}
zyFinancialClassify,err:=dao.GetFinancialClassInfo(classifySn)
if(err!=nil){
return "",err
}
F.TaxClassifyName=F.TaxClassifyName+zyFinancialClassify.ClassifyName
if(zyFinancialClassify.Level>3){
F.GetFinancialClassInfoName(zyFinancialClassify.ClassifyParentSn)
}
return F.TaxClassifyName,nil
}
func NewFinancialService() *FinancialClassService{
return &FinancialClassService{}
}
\ 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