Commit 24775923 by huangchengyi

1.0

parent 762e1bab
......@@ -13,7 +13,7 @@ func main() {
flag.StringVar(&path, "config", "conf", "配置文件")
var goods_id string;
flag.StringVar(&goods_id, "goods_id", "", "请输入模块id") // 单独计算某个模块,默认计算全部,0计算全部
flag.StringVar(&goods_id, "goods_id", "", "请输入单独查询的型号goods_id") // 单独计算某个模块,默认计算全部,0计算全部
flag.Parse()
if err := boot.Boot(path); err != nil {
......
package main
import (
"fmt"
"sort"
)
//阶梯价格排序算法
type SorterRatio []map[string]string
func (a SorterRatio) Len() int {
return len(a)
}
func (a SorterRatio) Swap(i, j int) {
a[i], a[j] = a[j], a[i]
}
func (a SorterRatio) Less(i, j int) bool {
return a[j]["sort"] < a[i]["sort"]
}
func main() {
s := make(map[string]string)
s["sort"] = "45"
s2 := make(map[string]string)
s2["sort"] = "89"
var slic SorterRatio
slic = append(slic, s)
slic = append(slic, s2)
sort.Sort(SorterRatio(slic))
fmt.Printf("%+v", slic)
}
......@@ -6,13 +6,14 @@ require (
github.com/denisenkom/go-mssqldb v0.0.0-20191124224453-732737034ffd // indirect
github.com/dgraph-io/badger v1.6.2 // 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/go-ini/ini v1.57.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
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/gopherjs/gopherjs v0.0.0-20181103185306-d547d1d9531e // indirect
github.com/gorilla/websocket v1.4.2 // indirect
......@@ -24,11 +25,11 @@ require (
github.com/imroc/req v0.3.0
github.com/jasonlvhit/gocron v0.0.1 // 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/orcaman/concurrent-map v0.0.0-20190826125027-8c72a8bb44f6
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/semihalev/gin-stats v0.0.0-20180505163755-30fdcbbd3533
github.com/sirupsen/logrus v1.5.0
......@@ -37,19 +38,19 @@ require (
github.com/syyongx/php2go v0.9.4
github.com/tidwall/gjson v1.6.1
github.com/tidwall/sjson v1.1.1
github.com/uniplaces/carbon v0.1.6
go.etcd.io/bbolt v1.3.4
github.com/uniplaces/carbon v0.1.6 // indirect
go.etcd.io/bbolt v1.3.4 // indirect
go.mongodb.org/mongo-driver v1.3.5 // indirect
go.uber.org/zap v1.14.1 // indirect
golang.org/x/tools v0.0.0-20191216173652-a0e659d51361
google.golang.org/genproto v0.0.0-20200527145253-8367513e4ece
golang.org/x/tools v0.0.0-20191216173652-a0e659d51361 // indirect
google.golang.org/genproto v0.0.0-20200527145253-8367513e4ece // 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/mgo.v2 v2.0.0-20190816093944-a6b53ec6cb22
gopkg.in/olivere/elastic.v5 v5.0.85
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
......@@ -9,7 +9,7 @@ type LyResponse struct {
//原始sku梯度
type LadderPrice struct {
Purchases int64 `json:"purchases"` //购买数量
PriceUs float64 `json:"price_us"` //数量对应的英文价格
PriceUs float64 `json:"price_us,omitempty"` //数量对应的英文价格
PriceCn float64 `json:"price_cn"` //数量对应的中文价格
PriceAc float64 `json:"price_ac,omitempty"`
CostPrice float64 `json:"-"`
......
package model
//系数价格排序
type SorterRatio []map[string]string
func (a SorterRatio) Len() int {
return len(a)
}
func (a SorterRatio) Swap(i, j int) {
a[i], a[j] = a[j], a[i]
}
func (a SorterRatio) Less(i, j int) bool {
return a[j]["sort"] < a[i]["sort"]
}
......@@ -48,19 +48,6 @@ func (qs *ZiyingService) ZyGoodsDetail(ctx *gin.Context,goodsIds []string, ch ch
continue;
}
//拼接梯度价格
ladderPriceArr := gjson.Get(info,"ladder_price").Array()
ladderPrice := make([]model.LadderPrice,0)
for _,v := range ladderPriceArr{
if v.Get("purchases").String() == "" {
continue;
}
ladderPrice = append(ladderPrice, model.LadderPrice{
Purchases: v.Get("purchases").Int(),
PriceUs: v.Get("price_us").Float(),
PriceCn: v.Get("price_cn").Float(),
})
}
//拼接属性
attrJsonArr := gjson.Parse(gjson.Get(info,"attrs").String()).Array()
......@@ -120,11 +107,7 @@ func (qs *ZiyingService) ZyGoodsDetail(ctx *gin.Context,goodsIds []string, ch ch
A.Set("moq", gjson.Get(info, "moq").Int()) //
A.Set("mpq", gjson.Get(info, "mpq").Int()) //
if len(ladderPrice) == 0 {
A.Set("ladder_price", "") //
}else{
A.Set("ladder_price", ladderPrice) //
}
A.Set("update_time", gjson.Get(info, "update_time").Int()) //
A.Set("sku_name", strings.Trim(gjson.Get(info, "sku_name").String()," ")) //
......@@ -227,25 +210,52 @@ func (qs *ZiyingService) ZyGoodsDetail(ctx *gin.Context,goodsIds []string, ch ch
}
//处理系数
ratio,_ := gredis.String(redisConn.Do("HGET","zy_ratio_sku",goods_id))
var PriceAc float64 = 0
if ratio != "" {
//拼接梯度价格
for _,v := range ladderPrice{
v.PriceAc = gjson.Get(ratio,"price_ac").Float()
}
PriceAc = gjson.Get(ratio,"price_ac").Float()
//获取立创价格
szlcPriceStr := `{"mykey":`+gjson.Get(ratio,"szlc_price").String()+`}`
ladder_price_arr := gjson.Get(szlcPriceStr,"mykey").Array()
ladderPriceLc := make([]model.LadderPriceLc,0)
for _,v := range ladder_price_arr{
ladderPriceLc = append(ladderPriceLc, model.LadderPriceLc{
Purchases: v.Get("Purchases").Int(),
Price: v.Get("price").Float(),
})
if gjson.Parse("szlc_price").String() == "" {
A.Set("szlc_price",nil)
}else{
ladderPriceLc := make([]model.LadderPriceLc,0)
for _,v := range gjson.Parse("szlc_price").Array(){
ladderPriceLc = append(ladderPriceLc, model.LadderPriceLc{
Purchases: v.Get("Purchases").Int(),
Price: v.Get("price").Float(),
})
}
A.Set("szlc_price",ladderPriceLc)
}
A.Set("allow_coupon",gjson.Get(ratio,"allow_coupon").String())
A.Set("allow_presale",gjson.Get(ratio,"allow_presale").String())
A.Set("szlc_price",ladderPriceLc)
}
//拼接梯度价格
ladderPriceArr := gjson.Get(info,"ladder_price").Array()
ladderPrice := make([]model.LadderPrice,0)
for _,v := range ladderPriceArr{
if v.Get("purchases").String() == "" {
continue;
}
if PriceAc == 0 {
ladderPrice = append(ladderPrice, model.LadderPrice{
Purchases: v.Get("purchases").Int(),
PriceCn: v.Get("price_cn").Float(),
})
}else{
ladderPrice = append(ladderPrice, model.LadderPrice{
Purchases: v.Get("purchases").Int(),
PriceCn: v.Get("price_cn").Float(),
PriceAc: PriceAc,
})
}
}
if len(ladderPrice) == 0 {
A.Set("ladder_price", "") //
}else{
A.Set("ladder_price", ladderPrice) //
}
//处理限额
......
......@@ -6,10 +6,12 @@ import (
"github.com/gomodule/redigo/redis"
"github.com/syyongx/php2go"
"github.com/tidwall/gjson"
"go_sku_server/model"
"go_sku_server/pkg/common"
"go_sku_server/pkg/gredis"
"go_sku_server/pkg/logger"
"go_sku_server/pkg/mysql"
"github.com/gogf/gf/util/gconv"
"sort"
)
......@@ -36,18 +38,19 @@ func (a *ZyCronService) ZyDiscount(checkGoodsId string) {
page_size := 1000 //查数据库每页大小
OuterLoop:
for i=1;i<=1000;i++ {
for i=0;i<1000;i++ {
start := 0;
if i== 1 {
if i == 0 {
start = 0;
}else{
start = (i-1)*page_size
}
sql := "select goods_id,class_id2,brand_id,cost,ladder_price from lie_goods where self_supplier_type = 1 and stock >0 and status=1 limit "+common.MyIntToStr(page_size)+","+common.MyIntToStr(start);
sql := "select goods_id,class_id2,brand_id,cost,ladder_price from lie_goods where self_supplier_type = 1 and stock >0 and status=1 limit "+gconv.String(start)+","+gconv.String(page_size);
if checkGoodsId != "" {
sql = "select goods_id,class_id2,brand_id,cost,ladder_price from lie_goods where goods_id="+checkGoodsId;
}
fmt.Println(sql)
goodsInfos, err := dbSpu.QueryString(sql)
if err != nil || len(goodsInfos) == 0{
fmt.Print("查询没有数据",err)
......@@ -61,7 +64,7 @@ func (a *ZyCronService) ZyDiscount(checkGoodsId string) {
fmt.Println("开始计算系数"+now_goods_id)
goodsBatch,_ := gredis.String(redisConn.Do("HGET","Self_goods_batch",now_goods_id)) //获取商品批次信息
apiGoodsList := gjson.Get("{\"Parts\":"+goodsBatch+"}", "Parts").Array()
apiGoodsList := gjson.Parse(goodsBatch).Array()
var EarlyBatchTime int64 = 0; //最早的批次
for _, goods := range apiGoodsList {
......@@ -77,7 +80,7 @@ func (a *ZyCronService) ZyDiscount(checkGoodsId string) {
if EarlyBatchTime == 0 {
fmt.Println("没有批次信息,goods_id :"+now_goods_id)
break;
continue;
}
//查询所有的系数列表
ratioAll, _ := redis.Values(redisConn.Do("hgetall", "Self_goods_ratio"))
......@@ -89,30 +92,32 @@ func (a *ZyCronService) ZyDiscount(checkGoodsId string) {
}
//系数排序,sort最高的优先排序
keys := make([]int,0)
rationList := make(map[int][]map[string]string,0)
var slic model.SorterRatio
for _,v:=range retioArr{
keys = append(keys,int(gjson.Get(v,"sort").Int()))
rationTemp := make([]map[string]string,0)
rationTemp = append(rationTemp,map[string]string{
"goods_id":gjson.Get(v,"goods_id").String(),
"name":gjson.Get(v,"name").String(), //系数名称
"ratio":gjson.Get(v,"ratio").String(), //折扣价
"min_ratio":gjson.Get(v,"min_ratio").String(), //保本折扣价
"class_id":gjson.Get(v,"class_id").String(),
"brand_id":gjson.Get(v,"brand_id").String(),
"expire_time":gjson.Get(v,"expire_time").String(),
"allow_coupon":gjson.Get(v,"allow_coupon").String(),
"allow_presale":gjson.Get(v,"allow_presale").String(),
})
rationList[int(gjson.Get(v,"sort").Int())] =rationTemp
if len(v) > 10 {
slic = append(slic,map[string]string{
"goods_id":gjson.Get(v,"goods_id").String(),
"sort":gjson.Get(v,"sort").String(), //系数名称
"name":gjson.Get(v,"name").String(), //系数名称
"ratio":gjson.Get(v,"ratio").String(), //折扣价
"min_ratio":gjson.Get(v,"min_ratio").String(), //保本折扣价
"class_id":gjson.Get(v,"class_id").String(),
"brand_id":gjson.Get(v,"brand_id").String(),
"expire_time":gjson.Get(v,"expire_time").String(),
"allow_coupon":gjson.Get(v,"allow_coupon").String(),
"allow_presale":gjson.Get(v,"allow_presale").String(),
})
}
}
sort.Sort(sort.Reverse(sort.IntSlice(keys))) //倒叙排
//计算系数
for _,sort :=range keys{
rationInfo := rationList[sort]
for _,info := range rationInfo {
sort.Sort(model.SorterRatio(slic))
//fmt.Println(slic)
//return
//计算系数价格
OuterLoop2:
for _,info :=range slic{
fmt.Println(info)
//不参与系数的商品
if info["goods_id"] != "" {
if php2go.Stripos(info["goods_id"],","+now_goods_id+",",0) > -1 {
......@@ -122,7 +127,7 @@ func (a *ZyCronService) ZyDiscount(checkGoodsId string) {
}
//不参与分类的商品
if info["class_id"] != "" {
if php2go.Stripos(info["class_id"],","+now_class_id+",",0) > -1 {
if php2go.Stripos(info["class_id2"],","+now_class_id+",",0) > -1 {
fmt.Println("1002 不参与分类的商品"+now_goods_id)
continue;
}
......@@ -156,8 +161,8 @@ func (a *ZyCronService) ZyDiscount(checkGoodsId string) {
}
}
fmt.Print(EarlyBatchTime,"<br/>")
fmt.Print(twoYearsAgotime,"<br/>")
//fmt.Println(EarlyBatchTime)
//fmt.Println(twoYearsAgotime)
if isExpire == false {
fmt.Println("1001 本商品不存在过期"+now_goods_id,info)
......@@ -165,9 +170,7 @@ func (a *ZyCronService) ZyDiscount(checkGoodsId string) {
}
//处理清库存系数,几个系数符合,往下面算
var ratioPrice float64;
ratioPrice = common.MyFloat64(a["cost"]) * common.MyFloat64(info["ratio"])
fmt.Print(ratioPrice,"<br/>")
ratioPrice = gconv.Float64(a["cost"]) * gconv.Float64(info["ratio"])
//查询立创数据
szlcPriceStr,_ := gredis.String(redisConn.Do("HGET","Self_szlc_price",now_goods_id)) //获取立创价格
......@@ -175,8 +178,7 @@ func (a *ZyCronService) ZyDiscount(checkGoodsId string) {
nowLadder := gjson.Get(a["ladder_price"], "purchases").Array()
endnowLadder := nowLadder[len(nowLadder)-1].Get("purchases").Int() //最后一个梯度
//获取立创对应的梯度价格
szlcPriceStr = `{"mykey":`+szlcPriceStr+`}`
szlcPriceArr := gjson.Get(szlcPriceStr, "mykey").Array()
szlcPriceArr := gjson.Parse(szlcPriceStr).Array()
var szlcPrice float64 =0 //找到立创对应的梯度价格
for _,b := range szlcPriceArr{
if b.Get("purchases").Int() <= endnowLadder {
......@@ -209,15 +211,14 @@ func (a *ZyCronService) ZyDiscount(checkGoodsId string) {
"allow_coupon":allow_coupon,
"allow_presale":allow_presale,
"szlc_price":szlcPriceStr,
"price_ac":common.MyFloat64ToStr(ratioPrice),
"price_ac":gconv.String(ratioPrice),
})
redisConn.Do("HSET","zy_ratio_sku",now_goods_id,string(ratioRes)) //写入缓存
//最后写日志
logger.Log("计算阶梯价成功 goods_id: "+now_goods_id+" 原始梯度价:"+a["ladder_price"]+" 立创梯度价: "+ szlcPriceStr +" 结果:"+string(ratioRes),"ratio_sku_",1)
break OuterLoop2;
}
}
if checkGoodsId != "" {
break OuterLoop; //只跑一个跳出所有循环
......
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