Commit 185f1838 by wang

Merge branch 'master' of http://119.23.72.7/q578953158/go_sku_server into master

parents e93734cc e30e7e5c
...@@ -12,5 +12,8 @@ cmd.exe~ ...@@ -12,5 +12,8 @@ cmd.exe~
/go.mod /go.mod
/conf /conf
/logs /logs
<<<<<<< HEAD
/mylogs /mylogs
/doc/test /doc/test
=======
>>>>>>> e30e7e5cf1e4c03c945073b5e6d46fabceff385a
...@@ -2,6 +2,7 @@ package main ...@@ -2,6 +2,7 @@ package main
import ( import (
"flag" "flag"
"fmt"
"go_sku_server/boot" "go_sku_server/boot"
"go_sku_server/pkg/logger" "go_sku_server/pkg/logger"
"go_sku_server/service" "go_sku_server/service"
...@@ -13,12 +14,13 @@ func main() { ...@@ -13,12 +14,13 @@ func main() {
flag.StringVar(&path, "config", "conf", "配置文件") flag.StringVar(&path, "config", "conf", "配置文件")
var goods_id string; var goods_id string;
flag.StringVar(&goods_id, "goods_id", "", "请输入模块id") // 单独计算某个模块,默认计算全部,0计算全部 flag.StringVar(&goods_id, "goods_id", "", "请输入单独查询的型号goods_id") // 单独计算某个模块,默认计算全部,0计算全部
flag.Parse() flag.Parse()
if err := boot.Boot(path); err != nil { if err := boot.Boot(path); err != nil {
panic(err) panic(err)
} }
fmt.Print(goods_id)
logger.Log("启动任务","ratio",1) logger.Log("启动任务","ratio",1)
ZyCronService := service.ZyCronService{} ZyCronService := service.ZyCronService{}
......
2020-10-13 16:44:56----dddd
2020-10-13 16:59:28----dddd
\ No newline at end of file
2020-10-28 16:46:54.51 ERROR (service_ly_common.go:service.(*LyService).GetSpuAttr:98) not found
2020-10-28 16:46:54.511 ERROR (service_ly_common.go:service.(*LyService).GetScmBrand:123) redigo: nil returned
2020-10-28 15:58:29.4 ERROR (service_ly_common.go:service.(*LyService).GetScmBrand:125) redigo: nil returned
...@@ -2,14 +2,14 @@ ...@@ -2,14 +2,14 @@
[default_redis_read] [default_redis_read]
host = 192.168.1.235:6379 host = 192.168.1.235:6379
password = icDb29mLy2s password = icDb29mLy2s
max_idle = 3000 max_idle = 1000
max_active = 5000 max_active = 5000
idle_timeout = 20 idle_timeout = 20
[default_redis_write] [default_redis_write]
host = 192.168.1.235:6379 host = 192.168.1.235:6379
password = icDb29mLy2s password = icDb29mLy2s
max_idle = 3000 max_idle = 1000
max_active = 5000 max_active = 5000
idle_timeout = 20 idle_timeout = 20
......
...@@ -4,15 +4,17 @@ import ( ...@@ -4,15 +4,17 @@ import (
"github.com/gin-gonic/gin" "github.com/gin-gonic/gin"
"github.com/syyongx/php2go" "github.com/syyongx/php2go"
"go_sku_server/pkg/common" "go_sku_server/pkg/common"
"go_sku_server/pkg/logger"
"go_sku_server/service" "go_sku_server/service"
"sync" "sync"
"time"
) )
const goods_slice_count = 10 //每多少个型号id开启一个协程 const goods_slice_count = 10 //每多少个型号id开启一个协程
/* /*
查询商品详情(自营或者联营) 查询商品详情(自营或者联营)
@doc http://192.168.2.232:3000/project/128/interface/api/649 @doc http://192.168.1.237:3000/project/128/interface/api/649
@param goods_id 支持批量,不建议超过40个,超过会导致处理时间超过2秒,进程异常 : 74564,65897,456464131 @param goods_id 支持批量,不建议超过40个,超过会导致处理时间超过2秒,进程异常 : 74564,65897,456464131
@param power[newCustomer] 是否获取新客价 :true @param power[newCustomer] 是否获取新客价 :true
...@@ -39,36 +41,37 @@ func Synchronization(ctx *gin.Context) { ...@@ -39,36 +41,37 @@ func Synchronization(ctx *gin.Context) {
common.Output(ctx, 1001, "查询型号ID不得为空", "") common.Output(ctx, 1001, "查询型号ID不得为空", "")
return return
} }
//gjson.Parse(string).Array()
GoodsRes := sync.Map{}
goodsIdArr := php2go.Explode(",", GoodsIdStr) goodsIdArr := php2go.Explode(",", GoodsIdStr)
wg := sync.WaitGroup{} //协程 //wg := sync.WaitGroup{} //协程
ch := make(chan sync.Map) //管道
p := 0 //总共协程
zyGoodsId := make([]string, 0) zyGoodsId := make([]string, 0)
lyGoodsId := make([]string, 0) lyGoodsId := make([]string, 0)
for _, goods_id := range goodsIdArr { for _, goodsId := range goodsIdArr {
if goods_id == "" { if goodsId == "" {
continue; continue
} }
if len(goods_id) < 19 { //自营 if len(goodsId) < 19 { //自营
zyGoodsId = append(zyGoodsId, goods_id) zyGoodsId = append(zyGoodsId, goodsId)
if len(zyGoodsId) >= goods_slice_count { if len(zyGoodsId) >= goods_slice_count {
common.PrintDebugHtml(ctx, "zy增加协程1001:") common.PrintDebugHtml(ctx, "zy增加协程1001:")
common.PrintDebugHtml(ctx, zyGoodsId) common.PrintDebugHtml(ctx, zyGoodsId)
wg.Add(1) //协程计数一 //wg.Add(1) //协程计数一
go zyService.ZyGoodsDetail(ctx, zyGoodsId, &GoodsRes, &wg) go zyService.ZyGoodsDetail(ctx, zyGoodsId, ch)
zyGoodsId = zyGoodsId[:0:0] zyGoodsId = zyGoodsId[:0:0]
p++
} }
} else { //联营 } else { //联营
lyGoodsId = append(lyGoodsId, goods_id) lyGoodsId = append(lyGoodsId, goodsId)
if len(lyGoodsId) >= goods_slice_count { if len(lyGoodsId) >= goods_slice_count {
common.PrintDebugHtml(ctx, "ly增加协程1002:") common.PrintDebugHtml(ctx, "ly增加协程1002:")
common.PrintDebugHtml(ctx, zyGoodsId) common.PrintDebugHtml(ctx, lyGoodsId)
wg.Add(1) //wg.Add(1)
go lyService.LyGoodsDetail(ctx, lyGoodsId, &GoodsRes, &wg) go lyService.LyGoodsDetail(ctx, lyGoodsId, ch)
lyGoodsId = lyGoodsId[:0:0] lyGoodsId = lyGoodsId[:0:0]
p++
} }
} }
} }
...@@ -76,34 +79,41 @@ func Synchronization(ctx *gin.Context) { ...@@ -76,34 +79,41 @@ func Synchronization(ctx *gin.Context) {
if len(zyGoodsId) > 0 { if len(zyGoodsId) > 0 {
common.PrintDebugHtml(ctx, "zy增加协程1003:") common.PrintDebugHtml(ctx, "zy增加协程1003:")
common.PrintDebugHtml(ctx, zyGoodsId) common.PrintDebugHtml(ctx, zyGoodsId)
wg.Add(1) //协程计数一 //wg.Add(1) //协程计数一
go zyService.ZyGoodsDetail(ctx, zyGoodsId, &GoodsRes, &wg) go zyService.ZyGoodsDetail(ctx, zyGoodsId, ch)
p++
} }
if len(lyGoodsId) > 0 { if len(lyGoodsId) > 0 {
common.PrintDebugHtml(ctx, "ly增加协程1004:") common.PrintDebugHtml(ctx, "ly增加协程1004:")
common.PrintDebugHtml(ctx, zyGoodsId) common.PrintDebugHtml(ctx, zyGoodsId)
wg.Add(1) //wg.Add(1)
go lyService.LyGoodsDetail(ctx, lyGoodsId, &GoodsRes, &wg) go lyService.LyGoodsDetail(ctx, lyGoodsId, ch)
p++
} }
wg.Wait() //wg.Wait()
//异步map最后转成map //异步map最后转成map
temp := make(map[string]interface{}) temp := make(map[string]interface{})
for i := 0; i < p; i++ {
select {
case GoodsRes := <-ch:
GoodsRes.Range(func(k, v interface{}) bool { GoodsRes.Range(func(k, v interface{}) bool {
s, _ := k.(string) s, _ := k.(string)
temp[s] = v temp[s] = v
return true return true
}) })
case <-time.After(time.Second * 20):
logger.Log("协程超时", "sku", 1)
}
}
common.Output(ctx, 0, "success", temp) common.Output(ctx, 0, "success", temp)
} }
/* /*
健康监测 健康监测
*/ */
func Health(ctx *gin.Context) { func Hbsdata(ctx *gin.Context) {
ctx.String(200, "ok") ctx.String(200, "ok")
} }
/*
go通道选择 Select
go 的select关键字可以让你同时等待多个通道操作
将协程
通道和select结合起来构成了go的一个强大特性
*/
package main
import (
"fmt"
"github.com/syyongx/php2go"
"time"
)
func main() {
c1 := make(chan string)
go func() {
fmt.Println(php2go.Time())
time.Sleep(time.Second * 1)
c1 <- "one"
}()
go func() {
fmt.Println(php2go.Time())
time.Sleep(time.Second * 2)
c1 <- "two"
}()
go func() {
fmt.Println(php2go.Time())
time.Sleep(time.Second * 10)
c1 <- "10"
}()
/*
如我们所期望的 程序输出了正确的值 对于select语句而言
它不断地检测通道是否有值过来 一旦有值过来立刻获取输出
*/
//我们使用select来等待通道的值 然后输出
for i := 0; i < 3; i++ {
select {
case x := <-c1:
fmt.Println(x)
case <- time.After(time.Second *2):
fmt.Println("read time out")
}
}
}
\ No newline at end of file
package main
import (
"errors"
"fmt"
"time"
)
func main() {
// 构建一个通道
ch := make(chan string)
// 开启一个并发匿名函数
go func() {
ch <- "gagagagagga111"
}()
go func() {
ch <- "gagagagagga223"
}()
go func() {
time.Sleep(1*time.Second)
ch <- "gagagagagga44444"
}()
//无限循环从通道中读取数据
for {
i,err := ReadWithSelect(ch)
//i, ok := <-ch
if err != nil {
fmt.Println(err)
break
}
fmt.Println(i)
}
}
//使用Select+超时改善无阻塞读写
func ReadWithSelect(ch chan string) (x string, err error) {
timeout := time.NewTimer(time.Microsecond * 50000).C //等待5s
select {
case x = <-ch:
return x, nil
case <-timeout.C:
return "", errors.New("read time out")
}
}
func WriteChWithSelect(ch chan int) error {
timeout := time.NewTimer(time.Microsecond * 500)
select {
case ch <- 1:
return nil
case <-timeout.C:
return errors.New("write time out")
}
}
package main
import (
"fmt"
"github.com/syyongx/php2go"
"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)
fmt.Println(php2go.Stripos(",10005,10006,","100205",0))
return
if php2go.Stripos("10005",",10005,10006,",0) > -1 {
fmt.Println("1002 不参与分类的商品")
return
}
}
...@@ -48,22 +48,33 @@ require ( ...@@ -48,22 +48,33 @@ require (
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 // indirect github.com/uniplaces/carbon v0.1.6 // indirect
<<<<<<< HEAD
go.etcd.io/bbolt v1.3.4 // indirect go.etcd.io/bbolt v1.3.4 // indirect
=======
>>>>>>> e30e7e5cf1e4c03c945073b5e6d46fabceff385a
go.mongodb.org/mongo-driver v1.3.5 // indirect go.mongodb.org/mongo-driver v1.3.5 // indirect
go.starlark.net v0.0.0-20201204201740-42d4f566359b // indirect go.starlark.net v0.0.0-20201204201740-42d4f566359b // indirect
go.uber.org/zap v1.14.1 // indirect go.uber.org/zap v1.14.1 // indirect
<<<<<<< HEAD
golang.org/x/arch v0.0.0-20201207015849-377592649dd6 // indirect golang.org/x/arch v0.0.0-20201207015849-377592649dd6 // indirect
golang.org/x/sys v0.0.0-20201204225414-ed752295db88 // indirect golang.org/x/sys v0.0.0-20201204225414-ed752295db88 // indirect
golang.org/x/tools v0.0.0-20191216173652-a0e659d51361 // indirect golang.org/x/tools v0.0.0-20191216173652-a0e659d51361 // indirect
google.golang.org/genproto v0.0.0-20200527145253-8367513e4ece // indirect 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 // indirect google.golang.org/protobuf v1.24.0 // indirect
=======
google.golang.org/genproto v0.0.0-20200527145253-8367513e4ece // indirect
google.golang.org/grpc v1.29.1 // indirect
>>>>>>> e30e7e5cf1e4c03c945073b5e6d46fabceff385a
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
gopkg.in/yaml.v2 v2.4.0 // indirect gopkg.in/yaml.v2 v2.4.0 // indirect
sigs.k8s.io/yaml v1.2.0 // indirect sigs.k8s.io/yaml v1.2.0 // indirect
<<<<<<< HEAD
xorm.io/core v0.7.2-0.20190928055935-90aeac8d08eb // indirect xorm.io/core v0.7.2-0.20190928055935-90aeac8d08eb // indirect
=======
>>>>>>> e30e7e5cf1e4c03c945073b5e6d46fabceff385a
) )
replace google.golang.org/grpc => google.golang.org/grpc v1.26.0 replace google.golang.org/grpc => google.golang.org/grpc v1.26.0
...@@ -9,7 +9,7 @@ type LyResponse struct { ...@@ -9,7 +9,7 @@ type LyResponse struct {
//原始sku梯度 //原始sku梯度
type LadderPrice struct { type LadderPrice struct {
Purchases int64 `json:"purchases"` //购买数量 Purchases int64 `json:"purchases"` //购买数量
PriceUs float64 `json:"price_us"` //数量对应的英文价格 PriceUs float64 `json:"price_us,omitempty"` //数量对应的英文价格
PriceCn float64 `json:"price_cn"` //数量对应的中文价格 PriceCn float64 `json:"price_cn"` //数量对应的中文价格
PriceAc float64 `json:"price_ac,omitempty"` PriceAc float64 `json:"price_ac,omitempty"`
CostPrice float64 `json:"-"` CostPrice float64 `json:"-"`
......
...@@ -6,6 +6,7 @@ import ( ...@@ -6,6 +6,7 @@ import (
//联营sku结构体 //联营sku结构体
type LySku struct { type LySku struct {
LadderPrice []LadderPrice `json:"-"`
SpuId string `json:"spu_id"` SpuId string `json:"spu_id"`
OldGoodsId int64 `json:"old_goods_id"` OldGoodsId int64 `json:"old_goods_id"`
UpdateTime int64 `json:"update_time"` UpdateTime int64 `json:"update_time"`
...@@ -20,9 +21,10 @@ type LySku struct { ...@@ -20,9 +21,10 @@ type LySku struct {
Stock int64 `json:"stock"` Stock int64 `json:"stock"`
HkDeliveryTime string `json:"hk_delivery_time"` HkDeliveryTime string `json:"hk_delivery_time"`
CnDeliveryTime string `json:"cn_delivery_time"` CnDeliveryTime string `json:"cn_delivery_time"`
LadderPrice []LadderPrice `json:"ladder_price"` LadderPriceResult interface{} `json:"ladder_price"`
GoodsImages string `json:"goods_images"` GoodsImages string `json:"goods_images"`
Canal string `json:"canal"` Canal string `json:"canal"`
IsExpire int `json:"is_expire,omitempty"`
Packing string `json:"packing"` Packing string `json:"packing"`
GoodsId string `json:"goods_id"` GoodsId string `json:"goods_id"`
GoodsName string `json:"goods_name"` GoodsName string `json:"goods_name"`
...@@ -35,13 +37,13 @@ type LySku struct { ...@@ -35,13 +37,13 @@ type LySku struct {
BrandId int64 `json:"brand_id"` BrandId int64 `json:"brand_id"`
//系数相关 //系数相关
Coefficient interface{} `json:"coefficient,omitempty"` Coefficient interface{} `json:"coefficient,omitempty"`
Original []LadderPrice `json:"original_price"` Original interface{} `json:"original_price,omitempty"`
SuppExtendFee interface{} `json:"supp_extend_fee"` SuppExtendFee interface{} `json:"supp_extend_fee"`
IsBuy int `json:"is_buy"` IsBuy int `json:"is_buy"`
//spu信息 //spu信息
ClassID1 int `json:"class_id1"` ClassID1 int `json:"class_id1"`
ClassID2 int `json:"class_id2"` ClassID2 int `json:"class_id2"`
ClassID3 int `json:"class_id3,omitempty"` ClassID3 int `json:"class_id3"`
SpuName string `json:"spu_name"` SpuName string `json:"spu_name"`
Status int `json:"status"` Status int `json:"status"`
ImagesL string `json:"images_l"` ImagesL string `json:"images_l"`
...@@ -61,6 +63,7 @@ type LySku struct { ...@@ -61,6 +63,7 @@ type LySku struct {
//活动信息 //活动信息
ActivityEndTime int64 `json:"activity_end_time,omitempty"` ActivityEndTime int64 `json:"activity_end_time,omitempty"`
ActivityInfo map[string]interface{} `json:"activity_info,omitempty"` ActivityInfo map[string]interface{} `json:"activity_info,omitempty"`
Content interface{} `json:"content"`
} }
//为什么不直接映射到结构,而要用gjson,因为redis存的数据结构不一定正常,可能类型不一致 //为什么不直接映射到结构,而要用gjson,因为redis存的数据结构不一定正常,可能类型不一致
...@@ -104,6 +107,9 @@ func InitSkuData(sku string) (data LySku) { ...@@ -104,6 +107,9 @@ func InitSkuData(sku string) (data LySku) {
stock := gjson.Get(sku, "stock").Int() stock := gjson.Get(sku, "stock").Int()
data.Stock = stock data.Stock = stock
isExpire := gjson.Get(sku, "is_expire").Int()
data.IsExpire = int(isExpire)
hkDeliveryTime := gjson.Get(sku, "hk_delivery_time").String() hkDeliveryTime := gjson.Get(sku, "hk_delivery_time").String()
data.HkDeliveryTime = hkDeliveryTime data.HkDeliveryTime = hkDeliveryTime
...@@ -124,6 +130,7 @@ func InitSkuData(sku string) (data LySku) { ...@@ -124,6 +130,7 @@ func InitSkuData(sku string) (data LySku) {
LadderPriceStr := gjson.Get(sku, "ladder_price").String() LadderPriceStr := gjson.Get(sku, "ladder_price").String()
data.LadderPrice = getLadderPrice(LadderPriceStr) data.LadderPrice = getLadderPrice(LadderPriceStr)
data.Original = getOriginPrice(LadderPriceStr)
return return
} }
...@@ -146,3 +153,22 @@ func getLadderPrice(ladderPriceStr string) (ladderPrice []LadderPrice) { ...@@ -146,3 +153,22 @@ func getLadderPrice(ladderPriceStr string) (ladderPrice []LadderPrice) {
} }
return return
} }
//获取原始价格
func getOriginPrice(ladderPriceStr string) (ladderPrice []OriginPrice) {
ladderPriceArr := gjson.Parse(ladderPriceStr).Array()
for _, price := range ladderPriceArr {
ladderPrice = append(ladderPrice, OriginPrice{
Purchases: price.Get("purchases").Int(),
PriceUs: price.Get("price_us").Float(),
PriceCn: price.Get("price_cn").Float(),
PriceAc: price.Get("price_ac").Float(),
CostPrice: price.Get("cost_price").Float(),
})
}
if len(ladderPrice) == 0 {
ladderPrice = []OriginPrice{}
return
}
return
}
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"]
}
...@@ -33,14 +33,12 @@ gjson 判断某值是否存在 map ...@@ -33,14 +33,12 @@ gjson 判断某值是否存在 map
@param targetk string 目标ID @param targetk string 目标ID
*/ */
func GInArray(json string,arrK string,targetK string) bool{ func GInArray(json string,arrK string,targetK string) bool{
s := gjson.Get(json,"brand_id").Array() s := gjson.Get(json,arrK).Array()
d := make([]string,0) d := make([]string,0)
for _,a := range s { for _,a := range s {
c := a.String() c := a.String()
d = append(d,c) d = append(d,c)
} }
return php2go.InArray(targetK,d) return php2go.InArray(targetK,d)
} }
/* /*
......
...@@ -48,9 +48,9 @@ func Output(ctx *gin.Context,errCode int, errMsg string, data interface{}) { ...@@ -48,9 +48,9 @@ func Output(ctx *gin.Context,errCode int, errMsg string, data interface{}) {
ErrMsg: errMsg, ErrMsg: errMsg,
Data: data, Data: data,
} }
if errCode >= 100 { //if errCode >= 100 {
SearchApiLogger(ctx,errCode, errMsg) // //SearchApiLogger(ctx,errCode, errMsg)
} //}
if ctx.DefaultQuery("callback", "") != "" { if ctx.DefaultQuery("callback", "") != "" {
ctx.JSONP(200, response) ctx.JSONP(200, response)
} else { } else {
......
...@@ -60,6 +60,7 @@ func getConn(writeHost, password string, maxIdle, maxActive int) (pool *redis.Po ...@@ -60,6 +60,7 @@ func getConn(writeHost, password string, maxIdle, maxActive int) (pool *redis.Po
_, err := c.Do("PING") _, err := c.Do("PING")
return err return err
}, },
Wait: true,
} }
return return
} }
......
...@@ -34,12 +34,12 @@ func Log(writeString string,log_file_pre string,types int) { ...@@ -34,12 +34,12 @@ func Log(writeString string,log_file_pre string,types int) {
date := time.Now().Format("2006-01-02") date := time.Now().Format("2006-01-02")
date2 := time.Now().Format("2006-01-02 15:04:05") date2 := time.Now().Format("2006-01-02 15:04:05")
path,_:=os.Getwd() path,_:=os.Getwd()
CreateDateDir(path,"mylogs") CreateDateDir(path,"logs")
var filename = path+"/mylogs/"+date+log_file_pre+".txt" var filename = path+"/logs/"+date+log_file_pre+".txt"
var f *os.File var f *os.File
var err1 error var err1 error
if checkFileIsExist(filename) { //如果文件存在 if checkFileIsExist(filename) { //如果文件存在
f, err1 = os.OpenFile(filename, os.O_APPEND, 0666) //打开文件 f, err1 = os.OpenFile(filename, os.O_APPEND|os.O_WRONLY|os.O_CREATE,0755)
} else { } else {
f, err1 = os.Create(filename) //创建文件 f, err1 = os.Create(filename) //创建文件
} }
...@@ -49,6 +49,7 @@ func Log(writeString string,log_file_pre string,types int) { ...@@ -49,6 +49,7 @@ func Log(writeString string,log_file_pre string,types int) {
if types == 1 { if types == 1 {
fmt.Print(writeString) fmt.Print(writeString)
} }
defer f.Close()
//fmt.Print(err) //fmt.Print(err)
} }
......
...@@ -20,8 +20,8 @@ func InitRouter() *gin.Engine { ...@@ -20,8 +20,8 @@ func InitRouter() *gin.Engine {
r.GET("Synchronization", controller.Synchronization) r.GET("Synchronization", controller.Synchronization)
r.POST("Synchronization",controller.Synchronization) r.POST("Synchronization",controller.Synchronization)
//心跳 //心跳
r.GET("Health", controller.Health) r.GET("hbsdata", controller.Hbsdata)
r.POST("Health",controller.Health) r.POST("hbsdata",controller.Hbsdata)
//自营SaveSku //自营SaveSku
r.POST("SaveSku",controller.Error_Middleware(),controller.SaveSku) r.POST("SaveSku",controller.Error_Middleware(),controller.SaveSku)
......
...@@ -6,6 +6,7 @@ import ( ...@@ -6,6 +6,7 @@ import (
"github.com/syyongx/php2go" "github.com/syyongx/php2go"
"github.com/tidwall/gjson" "github.com/tidwall/gjson"
"go_sku_server/model" "go_sku_server/model"
"go_sku_server/pkg/common"
"go_sku_server/pkg/gredis" "go_sku_server/pkg/gredis"
"sort" "sort"
"sync" "sync"
...@@ -27,13 +28,12 @@ type Power struct { ...@@ -27,13 +28,12 @@ type Power struct {
/* /*
联营数据详情 联营数据详情
*/ */
func (ls *LyService) LyGoodsDetail(ctx *gin.Context, goodsIds []string, goodsRes *sync.Map, wg *sync.WaitGroup) (results model.LyResponse) { func (ls *LyService) LyGoodsDetail(ctx *gin.Context, goodsIds []string, ch chan sync.Map) {
redisConn := gredis.Conn("search_r") redisConn := gredis.Conn("search_r")
defer func() { defer func() {
wg.Done() //wg.Done()
redisConn.Close() redisConn.Close()
}() }()
fast := ctx.Request.FormValue("power[fast]") fast := ctx.Request.FormValue("power[fast]")
isNewCustomer := ctx.Request.FormValue("power[newCustomer]") isNewCustomer := ctx.Request.FormValue("power[newCustomer]")
power := Power{ power := Power{
...@@ -45,12 +45,18 @@ func (ls *LyService) LyGoodsDetail(ctx *gin.Context, goodsIds []string, goodsRes ...@@ -45,12 +45,18 @@ func (ls *LyService) LyGoodsDetail(ctx *gin.Context, goodsIds []string, goodsRes
SpecialInvoice: ctx.Request.FormValue("power[special_invoice]"), SpecialInvoice: ctx.Request.FormValue("power[special_invoice]"),
VerifyBlacklist: ctx.Request.FormValue("power[verify_blacklist]"), VerifyBlacklist: ctx.Request.FormValue("power[verify_blacklist]"),
} }
common.PrintDebugHtml(ctx,power)
//批量获取商品详情 //批量获取商品详情
skuArr := gredis.Hmget("default_r", "sku", goodsIds) skuArr := gredis.Hmget("default_r", "sku", goodsIds)
//为了性能着想,这边也先去批量获取spu的信息 //为了性能着想,这边也先去批量获取spu的信息
spuList := ls.getSpuList(skuArr) spuList := ls.getSpuList(skuArr)
GoodsRes := sync.Map{}
for goodsId, skuStr := range skuArr { for goodsId, skuStr := range skuArr {
if skuStr == "" {
GoodsRes.Store(goodsId, false)
continue
}
//初始化有序map,拼接data 数据 //初始化有序map,拼接data 数据
//A := orderedmap.New() //A := orderedmap.New()
sku := model.InitSkuData(skuStr) sku := model.InitSkuData(skuStr)
...@@ -116,15 +122,13 @@ func (ls *LyService) LyGoodsDetail(ctx *gin.Context, goodsIds []string, goodsRes ...@@ -116,15 +122,13 @@ func (ls *LyService) LyGoodsDetail(ctx *gin.Context, goodsIds []string, goodsRes
//活动标识 //活动标识
hasActivity := false hasActivity := false
//判断是否有新客价权利 //判断是否有新客价权利
if isNewCustomer == "true" { if isNewCustomer == "true" || isNewCustomer == "1" {
//获取新客价 //获取新客价
//todo test
sku = ls.GetActivityPrice(sku, "_NewCustomer", power) sku = ls.GetActivityPrice(sku, "_NewCustomer", power)
if sku.AcType > 0 { if sku.AcType > 0 {
hasActivity = true hasActivity = true
} }
} }
//获取活动价 //获取活动价
if !hasActivity { if !hasActivity {
sku = ls.GetActivityPrice(sku, "", power) sku = ls.GetActivityPrice(sku, "", power)
...@@ -132,15 +136,16 @@ func (ls *LyService) LyGoodsDetail(ctx *gin.Context, goodsIds []string, goodsRes ...@@ -132,15 +136,16 @@ func (ls *LyService) LyGoodsDetail(ctx *gin.Context, goodsIds []string, goodsRes
hasActivity = true hasActivity = true
} }
} }
common.PrintDebugHtml(ctx,power.Member)
//获取会员价 //获取会员价
if !hasActivity && power.Member == "true" { if !hasActivity && (power.Member == "true" || power.Member == "1") {
common.PrintDebugHtml(ctx,power.Member)
sku = ls.GetActivityPrice(sku, "_Member", power) sku = ls.GetActivityPrice(sku, "_Member", power)
if sku.AcType > 0 { if sku.AcType > 0 {
hasActivity = true hasActivity = true
} }
} }
//处理阶梯价数据 //处理阶梯价数据
if len(sku.LadderPrice) > 0 { if len(sku.LadderPrice) > 0 {
//排序 //排序
...@@ -151,7 +156,6 @@ func (ls *LyService) LyGoodsDetail(ctx *gin.Context, goodsIds []string, goodsRes ...@@ -151,7 +156,6 @@ func (ls *LyService) LyGoodsDetail(ctx *gin.Context, goodsIds []string, goodsRes
sku.Moq = purchases sku.Moq = purchases
} }
} }
//获取系数 //获取系数
sku = ls.GetCoefficient(sku) sku = ls.GetCoefficient(sku)
...@@ -160,12 +164,14 @@ func (ls *LyService) LyGoodsDetail(ctx *gin.Context, goodsIds []string, goodsRes ...@@ -160,12 +164,14 @@ func (ls *LyService) LyGoodsDetail(ctx *gin.Context, goodsIds []string, goodsRes
if sku.SupplierId != 0 { if sku.SupplierId != 0 {
sku.SuppExtendFee = ls.GetExtendFee(sku.SupplierId, sku.Canal) sku.SuppExtendFee = ls.GetExtendFee(sku.SupplierId, sku.Canal)
} }
//还要处理货期 //还要处理货期
delivery := ls.GetDelivery(sku.SupplierId, sku.Canal) delivery := ls.GetDelivery(sku.SupplierId, sku.Canal)
if delivery["cn_delivery"] != "" {
sku.CnDeliveryTime = delivery["cn_delivery"] sku.CnDeliveryTime = delivery["cn_delivery"]
}
if delivery["hk_delivery"] != "" {
sku.HkDeliveryTime = delivery["hk_delivery"] sku.HkDeliveryTime = delivery["hk_delivery"]
}
} }
//处理是否可以购买 //处理是否可以购买
...@@ -173,6 +179,12 @@ func (ls *LyService) LyGoodsDetail(ctx *gin.Context, goodsIds []string, goodsRes ...@@ -173,6 +179,12 @@ func (ls *LyService) LyGoodsDetail(ctx *gin.Context, goodsIds []string, goodsRes
sku.Mpq = 1 sku.Mpq = 1
} }
if len(sku.LadderPrice) > 0 {
sku.LadderPriceResult = sku.LadderPrice
} else {
sku.LadderPriceResult = []int{}
}
//判断是否可以购买 //判断是否可以购买
sku.IsBuy = ls.GetIsBuy(sku) sku.IsBuy = ls.GetIsBuy(sku)
...@@ -180,13 +192,11 @@ func (ls *LyService) LyGoodsDetail(ctx *gin.Context, goodsIds []string, goodsRes ...@@ -180,13 +192,11 @@ func (ls *LyService) LyGoodsDetail(ctx *gin.Context, goodsIds []string, goodsRes
sku = ls.CombineSup(sku, spu) sku = ls.CombineSup(sku, spu)
//最后一步,将sku的全部信息放到有序map里面 //最后一步,将sku的全部信息放到有序map里面
GoodsRes.Store(goodsId, sku)
(*goodsRes).Store(goodsId, sku)
//(*goodsRes)[goodsId] = A //(*goodsRes)[goodsId] = A
} }
ch <- GoodsRes
return
} }
func (ls *LyService) getSpuList(skuArr map[string]string) (spuList map[string]string) { func (ls *LyService) getSpuList(skuArr map[string]string) (spuList map[string]string) {
......
...@@ -166,6 +166,9 @@ func (ls *LyService) GetExtendFee(supplierId int64, canal string) interface{} { ...@@ -166,6 +166,9 @@ func (ls *LyService) GetExtendFee(supplierId int64, canal string) interface{} {
if supplierId == 17 { if supplierId == 17 {
//为什么专卖的redis键会不一样,专卖的附加费管理在供应商系统,其它的在基石 //为什么专卖的redis键会不一样,专卖的附加费管理在供应商系统,其它的在基石
value, _ := redis.String(redisCon.Do("HGET", "supp_extend_fee", "17."+canal)) value, _ := redis.String(redisCon.Do("HGET", "supp_extend_fee", "17."+canal))
if value == "" {
return false
}
//专卖的存了两种形式的数据,真是搞人心态 //专卖的存了两种形式的数据,真是搞人心态
if strings.Contains(value, "cn") { if strings.Contains(value, "cn") {
var extendFee ExtendFee var extendFee ExtendFee
...@@ -178,6 +181,9 @@ func (ls *LyService) GetExtendFee(supplierId int64, canal string) interface{} { ...@@ -178,6 +181,9 @@ func (ls *LyService) GetExtendFee(supplierId int64, canal string) interface{} {
} }
} else { } else {
value, _ := redis.String(redisCon.Do("HGET", "supp_extend_fee", supplierId)) value, _ := redis.String(redisCon.Do("HGET", "supp_extend_fee", supplierId))
if value == "" {
return false
}
var extendFee ExtendFee var extendFee ExtendFee
json.Unmarshal([]byte(value), &extendFee) json.Unmarshal([]byte(value), &extendFee)
return extendFee return extendFee
...@@ -187,30 +193,35 @@ func (ls *LyService) GetExtendFee(supplierId int64, canal string) interface{} { ...@@ -187,30 +193,35 @@ func (ls *LyService) GetExtendFee(supplierId int64, canal string) interface{} {
//获取系数 //获取系数
func (ls *LyService) GetCoefficient(sku model.LySku) model.LySku { func (ls *LyService) GetCoefficient(sku model.LySku) model.LySku {
if len(sku.LadderPrice) == 0 { if len(sku.LadderPrice) == 0 {
sku.Original = nil
return sku return sku
} }
flag := 0 flag := 0
data := make([]model.LadderPrice, len(sku.LadderPrice))
//专卖 //专卖
originalLadderPrice := sku.LadderPrice
if sku.SupplierId == 17 { if sku.SupplierId == 17 {
ladderPrice := sku.LadderPrice ladderPrice := sku.LadderPrice
for key, price := range ladderPrice { for key, price := range ladderPrice {
if price.Purchases == 0 { if price.Purchases == 0 {
continue continue
} }
ladderPrice[key].PriceUs = common.MyRound(price.PriceUs, 4) data[key].Purchases = price.Purchases
ladderPrice[key].PriceCn = common.MyRound(price.PriceCn, 4) if price.PriceUs != 0 {
data[key].PriceUs = common.MyRound(price.PriceUs, 4)
}
if price.PriceCn != 0 {
data[key].PriceCn = common.MyRound(price.PriceCn, 4)
}
//联营或者专卖 同时 存在活动价格 //联营或者专卖 同时 存在活动价格
if (sku.GoodsType == 1 || sku.GoodsType == 2) && sku.AcType > 1 && sku.Ratio > 0 { if (sku.GoodsType == 1 || sku.GoodsType == 2) && sku.AcType > 1 && sku.Ratio > 0 {
acPrice := price.PriceCn tempAcPrice := common.MyRound(price.PriceCn*(sku.Ratio/100), 4)
ladderPrice[key].PriceAc = common.MyRound(price.PriceCn*(sku.Ratio/100), 4) data[key].PriceAc = tempAcPrice
//优惠价后等于0,就代表没有搞活动 //优惠价后等于0,就代表没有搞活动
if ladderPrice[key].PriceAc <= 0 { if tempAcPrice <= 0 {
sku.AcType = 0 sku.AcType = 0
} }
//价格与原价一样 //价格与原价一样
if acPrice == ladderPrice[key].PriceAc && key < 2 { if data[key].PriceCn == tempAcPrice && key < 2 {
flag++ flag++
if flag >= 2 || (len(ladderPrice) < 2) { if flag >= 2 || (len(ladderPrice) < 2) {
sku.AcType = 0 sku.AcType = 0
...@@ -274,66 +285,67 @@ func (ls *LyService) GetCoefficient(sku model.LySku) model.LySku { ...@@ -274,66 +285,67 @@ func (ls *LyService) GetCoefficient(sku model.LySku) model.LySku {
if !hasCoefficient { if !hasCoefficient {
coefficient = defaultCoefficient coefficient = defaultCoefficient
} }
// 为何是固定的1.13,关税基本不会变,有变的话跟产品沟通手动修改即可 // 为何是固定的1.13,关税基本不会变,有变的话跟产品沟通手动修改即可
//$tax = config('website.tax'); //$tax = config('website.tax');
tax := 1.13 tax := 1.13
for key, price := range sku.LadderPrice { for key, price := range sku.LadderPrice {
if price.Purchases == 0 { if price.Purchases == 0 {
continue continue
} }
data[key].Purchases = price.Purchases
//根据系数处理美金 //根据系数处理美金
sku.LadderPrice[key].PriceUs = common.MyRound(price.PriceUs*coefficient.ExtraRatio*coefficient.Hk, 4) data[key].PriceUs = common.MyRound(price.PriceUs*coefficient.ExtraRatio*coefficient.Hk, 4)
//处理人民币 //处理人民币
sku.LadderPrice[key].PriceCn = common.MyRound(price.PriceUs*coefficient.ExtraRatio*coefficient.Cn*coefficient.Ratio*tax, 4) data[key].PriceCn = common.MyRound(price.PriceUs*coefficient.ExtraRatio*coefficient.Cn*coefficient.Ratio*tax, 4)
//处理mouser的成本价 //处理mouser的成本价
//mouser成本价是什么,斌哥同步过来的成本价 //mouser成本价是什么,斌哥同步过来的成本价
//price.CostPrice是专门针对贸泽(mouser)的 //sku.LadderPrice[key].CostPrice是专门针对贸泽(mouser)的
if sku.AcType == 2 && sku.SupplierId == 14 { if sku.AcType == 2 && sku.SupplierId == 14 {
if price.CostPrice != 0 { if price.CostPrice != 0 {
sku.LadderPrice[key].PriceAc = common.MyRound(price.CostPrice*coefficient.ExtraRatio*coefficient.Cn*coefficient.Ratio, 4) data[key].PriceAc = common.MyRound(price.CostPrice*coefficient.ExtraRatio*coefficient.Cn*coefficient.Ratio, 4)
sku.LadderPrice[key].PriceUs = common.MyRound(price.CostPrice*coefficient.ExtraRatio*coefficient.Hk, 4) data[key].PriceUs = common.MyRound(price.CostPrice*coefficient.ExtraRatio*coefficient.Hk, 4)
} else { } else {
sku.LadderPrice[key].PriceAc = price.PriceCn data[key].PriceAc = data[key].PriceCn
} }
continue continue
} }
//处理活动价和原价相同的情况 //处理活动价和原价相同的情况
if (sku.GoodsType == 1 || sku.GoodsType == 2) && sku.AcType > 1 && sku.Ratio > 0 { if (sku.GoodsType == 1 || sku.GoodsType == 2) && sku.AcType > 1 && sku.Ratio > 0 {
priceAc := common.MyRound(price.PriceCn*(sku.Ratio/100), 4) priceAc := common.MyRound(data[key].PriceCn*(sku.Ratio/100), 4)
sku.LadderPrice[key].PriceAc = priceAc data[key].PriceAc = priceAc
if priceAc <= 0 { if priceAc <= 0 {
sku.AcType = 0 sku.AcType = 0
break break
} else { } else {
if sku.AcType == 4 { if sku.AcType == 4 {
sku.LadderPrice[key].PriceCn = priceAc data[key].PriceCn = priceAc
sku.AcType = 0 sku.AcType = 0
} }
} }
//为什么$kp < 2,如果第一阶梯或第二阶梯价格和活动价一样,就不输出活动价了 //为什么$kp < 2,如果第一阶梯或第二阶梯价格和活动价一样,就不输出活动价了
//活动价都是有样式的和平时不一样,如果价格一样,但是样子是活动价,客户会迷惑,所以不输出即可,保持原来的样式 //活动价都是有样式的和平时不一样,如果价格一样,但是样子是活动价,客户会迷惑,所以不输出即可,保持原来的样式
if sku.LadderPrice[key].PriceCn == priceAc && key < 2 { if data[key].PriceCn == priceAc && key < 2 {
flag++ flag++
if flag >= 2 { if flag >= 2 {
sku.AcType = 0 sku.AcType = 0
} }
if len(sku.LadderPrice) > 1 { if len(data) > 1 {
if sku.LadderPrice[1].PriceCn == 0 { if data[1].PriceCn == 0 {
sku.AcType = 0 sku.AcType = 0
} }
} }
} }
} }
} }
if len(data) > 0 {
sku.LadderPrice = data
}
//输出税费到前端 //输出税费到前端
coefficient.Tax = tax coefficient.Tax = tax
sku.Coefficient = coefficient sku.Coefficient = coefficient
} }
sku.Original = originalLadderPrice
return sku return sku
} }
...@@ -344,7 +356,6 @@ func (ls *LyService) GetDelivery(supplierId int64, canal string) (delivery map[s ...@@ -344,7 +356,6 @@ func (ls *LyService) GetDelivery(supplierId int64, canal string) (delivery map[s
defer redisCon.Close() defer redisCon.Close()
if canal != "" { if canal != "" {
supplierRatio, _ := redis.String(redisCon.Do("HGET", "supp_ratio", canal)) supplierRatio, _ := redis.String(redisCon.Do("HGET", "supp_ratio", canal))
fmt.Println(supplierRatio)
if supplierRatio != "" { if supplierRatio != "" {
delivery["cn_delivery"] = gjson.Get(supplierRatio, "cn_delivery_time").String() delivery["cn_delivery"] = gjson.Get(supplierRatio, "cn_delivery_time").String()
delivery["hk_delivery"] = gjson.Get(supplierRatio, "us_delivery_time").String() delivery["hk_delivery"] = gjson.Get(supplierRatio, "us_delivery_time").String()
......
...@@ -22,13 +22,13 @@ func (ls *LyService) GetActivityPrice(sku model.LySku, suffix string, power Powe ...@@ -22,13 +22,13 @@ func (ls *LyService) GetActivityPrice(sku model.LySku, suffix string, power Powe
if suffix == "" && sku.SupplierId == 14 { if suffix == "" && sku.SupplierId == 14 {
return getMouserActivityPrice(sku) return getMouserActivityPrice(sku)
} }
//先获取活动信息,针对不同供应商不同活动类型做活动吗,每个活动只能针对一个供应商 //先获取活动信息,针对不同供应商不同活动类型做活动吗,每个活动只能针对一个供应商
//比如有 Self_ActivityPrice_2_Discount,Self_ActivityPrice_1_NewCustomer //比如有 Self_ActivityPrice_2_Discount,Self_ActivityPrice_1_NewCustomer
redisCon := gredis.Conn("default_r") redisCon := gredis.Conn("default_r")
defer redisCon.Close() defer redisCon.Close()
supplierIdStr := strconv.Itoa(int(sku.SupplierId)) supplierIdStr := strconv.Itoa(int(sku.SupplierId))
activityInfo, _ := redis.String(redisCon.Do("HGET", "Self_ActivityPrice_"+supplierIdStr+suffix)) activityInfo, _ := redis.String(redisCon.Do("GET", "Self_ActivityPrice_"+supplierIdStr+suffix))
//找不到对应的活动价格信息,就直接返回空 //找不到对应的活动价格信息,就直接返回空
if activityInfo == "" { if activityInfo == "" {
return sku return sku
...@@ -44,9 +44,11 @@ func (ls *LyService) GetActivityPrice(sku model.LySku, suffix string, power Powe ...@@ -44,9 +44,11 @@ func (ls *LyService) GetActivityPrice(sku model.LySku, suffix string, power Powe
//获取redis里面存储的活动相关信息 //获取redis里面存储的活动相关信息
brandIdArray := gjson.Get(activityInfo, "brand_id").Array() brandIdArray := gjson.Get(activityInfo, "brand_id").Array()
var brandIds []string var brandIds []int64
for _, brandId := range brandIdArray { for _, brandId := range brandIdArray {
brandIds = append(brandIds, brandId.String()) if brandId.String() != "" {
brandIds = append(brandIds, brandId.Int())
}
} }
goodsNameArray := gjson.Get(activityInfo, "goods_name").Array() goodsNameArray := gjson.Get(activityInfo, "goods_name").Array()
var goodsNames []string var goodsNames []string
...@@ -132,7 +134,7 @@ func (ls *LyService) GetActivityPrice(sku model.LySku, suffix string, power Powe ...@@ -132,7 +134,7 @@ func (ls *LyService) GetActivityPrice(sku model.LySku, suffix string, power Powe
if suffix == "_Member" && gjson.Get(activityInfo, "is_part").Int() == 1 && if suffix == "_Member" && gjson.Get(activityInfo, "is_part").Int() == 1 &&
visibleRoster != "" { visibleRoster != "" {
//为了用字符串匹配 //为了用字符串匹配
visibleRoster = visibleRoster + "," visibleRoster = "," + visibleRoster + ","
//提取出user_id、手机号、邮箱 //提取出user_id、手机号、邮箱
userInfo := make(map[string]string) userInfo := make(map[string]string)
userInfo["user_id"] = power.UserId userInfo["user_id"] = power.UserId
...@@ -144,9 +146,9 @@ func (ls *LyService) GetActivityPrice(sku model.LySku, suffix string, power Powe ...@@ -144,9 +146,9 @@ func (ls *LyService) GetActivityPrice(sku model.LySku, suffix string, power Powe
hasActivity = false hasActivity = false
continue continue
} }
if !strings.Contains(visibleRoster, ","+value+",") { if strings.Contains(visibleRoster, ","+value+",") {
hasActivity = true hasActivity = true
continue break
} else { } else {
hasActivity = false hasActivity = false
} }
...@@ -183,7 +185,6 @@ func (ls *LyService) GetActivityPrice(sku model.LySku, suffix string, power Powe ...@@ -183,7 +185,6 @@ func (ls *LyService) GetActivityPrice(sku model.LySku, suffix string, power Powe
//} //}
} }
} }
//判断是否有活动 //判断是否有活动
if !hasActivity { if !hasActivity {
return sku return sku
...@@ -214,8 +215,10 @@ func (ls *LyService) GetActivityPrice(sku model.LySku, suffix string, power Powe ...@@ -214,8 +215,10 @@ func (ls *LyService) GetActivityPrice(sku model.LySku, suffix string, power Powe
allowNotLogin = 2 allowNotLogin = 2
} }
sku.ActivityInfo = map[string]interface{}{ sku.ActivityInfo = map[string]interface{}{
"activity_id": gjson.Get(activityInfo, "activity_ad").String(), "activity_ad": gjson.Get(activityInfo, "activity_ad").String(),
"sign_name": gjson.Get(activityInfo, "sign_name").String(), "sign_name": gjson.Get(activityInfo, "sign_name").String(),
"id": gjson.Get(activityInfo, "id").String(),
"activity_name": gjson.Get(activityInfo, "activity_name").String(),
"allow_not_login": allowNotLogin, "allow_not_login": allowNotLogin,
} }
sku.AcType = 8 sku.AcType = 8
......
package service package service
import ( import (
"fmt"
"github.com/gin-gonic/gin" "github.com/gin-gonic/gin"
"github.com/iancoleman/orderedmap" "github.com/iancoleman/orderedmap"
"github.com/tidwall/gjson" "github.com/tidwall/gjson"
...@@ -31,34 +30,24 @@ type ZiyingService struct { ...@@ -31,34 +30,24 @@ type ZiyingService struct {
@param power[special_invoice] 增值税专用发票公司名字,活动价时需要,否则可能导致用户无法享受活动价 : 深圳是猎芯科技有限公司 @param power[special_invoice] 增值税专用发票公司名字,活动价时需要,否则可能导致用户无法享受活动价 : 深圳是猎芯科技有限公司
@param power[verify_blacklist] 是否验证黑名单,用于折扣活动提交订单页面与后台下单 :true @param power[verify_blacklist] 是否验证黑名单,用于折扣活动提交订单页面与后台下单 :true
*/ */
func (qs *ZiyingService) ZyGoodsDetail(ctx *gin.Context,goodsIds []string,goodsRes *sync.Map, wg *sync.WaitGroup) { func (qs *ZiyingService) ZyGoodsDetail(ctx *gin.Context,goodsIds []string, ch chan sync.Map) {
redisConn := gredis.Conn("search_r") redisConn := gredis.Conn("search_r")
defer func() { defer func() {
wg.Done(); //wg.Done();
redisConn.Close(); redisConn.Close();
}() }()
skuArr := gredis.Hmget("search_r","Self_SelfGoods",goodsIds) //批量获取商品详情 skuArr := gredis.Hmget("search_r","Self_SelfGoods",goodsIds) //批量获取商品详情
fast := ctx.Request.FormValue("power[fast]") fast := ctx.Request.FormValue("power[fast]")
GoodsRes := sync.Map{}
for goods_id,info := range skuArr { for goods_id,info := range skuArr {
if gjson.Get(info, "goods_name").String() == "" { if gjson.Get(info, "goods_name").String() == "" {
fmt.Print("zy goods_name为空-----",goods_id,skuArr) //fmt.Print("zy goods_name为空-----",goods_id,skuArr)
} GoodsRes.Store(goods_id,false)
//拼接梯度价格
ladderPriceArr := gjson.Get(info,"ladder_price").Array()
ladderPrice := make([]model.LadderPrice,0)
for _,v := range ladderPriceArr{
if v.Get("purchases").String() == "" {
continue; 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() attrJsonArr := gjson.Parse(gjson.Get(info,"attrs").String()).Array()
...@@ -79,8 +68,43 @@ func (qs *ZiyingService) ZyGoodsDetail(ctx *gin.Context,goodsIds []string,goodsR ...@@ -79,8 +68,43 @@ func (qs *ZiyingService) ZyGoodsDetail(ctx *gin.Context,goodsIds []string,goodsR
A.Set("goods_type", gjson.Get(info, "goods_type").Int()) //查询总条数 A.Set("goods_type", gjson.Get(info, "goods_type").Int()) //查询总条数
A.Set("supplier_id", gjson.Get(info, "supplier_id").Int()) //查询总条数 A.Set("supplier_id", gjson.Get(info, "supplier_id").Int()) //查询总条数
A.Set("brand_id", gjson.Get(info, "brand_id").Int()) // A.Set("brand_id", gjson.Get(info, "brand_id").Int()) //
A.Set("class_id1", gjson.Get(info, "class_id1").Int()) //
A.Set("class_id2", gjson.Get(info, "class_id2").Int()) // other_attrs := gjson.Get(info,"other_attrs").String()
if other_attrs == "" {
A.Set("other_attrs","")
}else{
B := make(map[string]string)
pick_type := gjson.Get(other_attrs,"pick_type").String()
length := gjson.Get(other_attrs,"length").String()
gross_wegiht := gjson.Get(other_attrs,"gross_wegiht").String()
if pick_type != "" {
B["pick_type"] = pick_type
}
B["length"] = length
if gross_wegiht != "" {
B["gross_wegiht"] = gross_wegiht
}
A.Set("other_attrs",B)
}
class_id1 := gjson.Get(info, "class_id1").Int()
class_id2 := gjson.Get(info, "class_id2").Int()
class_id1_name := "";
if class_id1 >0 {
class_id1_info,_ := gredis.String(redisConn.Do("HGET","Self_SelfClassInfo",class_id1))
class_id1_name = gjson.Get(class_id1_info,"class_name").String()
}
class_id2_name := "";
if class_id2 >0 {
class_id2_info,_ := gredis.String(redisConn.Do("HGET","Self_SelfClassInfo",class_id2))
class_id2_name = gjson.Get(class_id2_info,"class_name").String()
}
A.Set("class_id1", class_id1) //
A.Set("class_id2", class_id2) //
A.Set("class_id1_name", class_id1_name) //
A.Set("class_id2_name", class_id2_name) //
A.Set("goods_name", gjson.Get(info, "goods_name").String()) // A.Set("goods_name", gjson.Get(info, "goods_name").String()) //
A.Set("status", gjson.Get(info, "status").Int()) // A.Set("status", gjson.Get(info, "status").Int()) //
A.Set("encoded", gjson.Get(info, "encoded").String()) // A.Set("encoded", gjson.Get(info, "encoded").String()) //
...@@ -91,22 +115,24 @@ func (qs *ZiyingService) ZyGoodsDetail(ctx *gin.Context,goodsIds []string,goodsR ...@@ -91,22 +115,24 @@ func (qs *ZiyingService) ZyGoodsDetail(ctx *gin.Context,goodsIds []string,goodsR
A.Set("moq", gjson.Get(info, "moq").Int()) // A.Set("moq", gjson.Get(info, "moq").Int()) //
A.Set("mpq", gjson.Get(info, "mpq").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("update_time", gjson.Get(info, "update_time").Int()) //
A.Set("sku_name", strings.Trim(gjson.Get(info, "sku_name").String()," ")) // A.Set("sku_name", strings.Trim(gjson.Get(info, "sku_name").String()," ")) //
A.Set("mpl", gjson.Get(info, "mpl").Int()) // A.Set("mpl", gjson.Get(info, "mpl").Int()) //
//处理库存 //处理库存
lockStock := qs.skuLockNum(&redisConn,goods_id) //当前锁库库存 A.Set("stock",0) //默认库存为0
dbStock := gjson.Get(info, "stock").Int() //当前db库存 dbStock := gjson.Get(info, "stock").Int() //当前db库存
stock := dbStock-lockStock //当前可购买库存 if dbStock > 0 {
A.Set("stock",stock) lockStock := qs.skuLockNum(&redisConn,goods_id) //当前锁库库存
stockG := dbStock-lockStock //当前可购买库存
if stockG >0 {
A.Set("actual_stock", gjson.Get(info, "actual_stock").Int()) //锁定库存
A.Set("stock",dbStock)
}
A.Set("saler_atio", "") //
}
if len(attrs) == 0 { if len(attrs) == 0 {
A.Set("attrs", "") //属性值 A.Set("attrs", "") //属性值
...@@ -126,7 +152,10 @@ func (qs *ZiyingService) ZyGoodsDetail(ctx *gin.Context,goodsIds []string,goodsR ...@@ -126,7 +152,10 @@ func (qs *ZiyingService) ZyGoodsDetail(ctx *gin.Context,goodsIds []string,goodsR
} }
A.Set("cn_delivery_time", cn_delivery_time) // 货期 A.Set("cn_delivery_time", cn_delivery_time) // 货期
A.Set("brand_name", gjson.Get(info, "brand_name").String()) // //查询品牌名称
brand_id := gjson.Get(info, "brand_id").Int()
brand_info,_ := gredis.String(redisConn.Do("HGET","Self_Brand",brand_id))
A.Set("brand_name", gjson.Get(brand_info, "brand_name").String()) //
if fast != "1" { //不是快速查询 if fast != "1" { //不是快速查询
// 供应商名称 // 供应商名称
...@@ -167,55 +196,67 @@ func (qs *ZiyingService) ZyGoodsDetail(ctx *gin.Context,goodsIds []string,goodsR ...@@ -167,55 +196,67 @@ func (qs *ZiyingService) ZyGoodsDetail(ctx *gin.Context,goodsIds []string,goodsR
if img != "" { if img != "" {
goods_images,_ = gredis.String(redisConn.Do("HGET","Self_SelfGoodsSource",img)) goods_images,_ = gredis.String(redisConn.Do("HGET","Self_SelfGoodsSource",img))
} }
A.Set("goods_images", goods_images) // A.Set("goods_images", gjson.Get(goods_images,"url").String())
//图片
pdf := gjson.Get(info, "pdf").String() pdf := gjson.Get(info, "pdf").String()
if pdf != "" { if pdf != "" {
pdf,_ = gredis.String(redisConn.Do("HGET","Self_SelfGoodsSource",pdf)) pdf,_ = gredis.String(redisConn.Do("HGET","Self_SelfGoodsSource",pdf))
} }
A.Set("pdf", gjson.Get(info, "pdf").String()) A.Set("pdf", gjson.Get(pdf, "url").String())
} }
A.Set("scm_brand_name", gjson.Get(info, "scm_brand_name").String()) // A.Set("scm_brand_name", gjson.Get(info, "scm_brand_name").String()) //
A.Set("actual_stock", gjson.Get(info, "actual_stock").Int()) //
A.Set("ac_type", gjson.Get(info, "ac_type").Int()) //
A.Set("saler_atio", gjson.Get(info, "saler_atio").String()) //
A.Set("class_id1_name", gjson.Get(info, "class_id1_name").String()) //
A.Set("class_id2_name", gjson.Get(info, "class_id2_name").String()) //
//处理活动价
A.Set("ac_type",0)
A.Set("allow_coupon",1)
Ac_price := qs.ActivityPrice(ctx,info,&redisConn)
if Ac_price != nil {
keys := Ac_price.Keys()
for _, k := range keys {
v, _ := Ac_price.Get(k)
A.Set(k,v) //活动价格覆盖
}
}
//处理系数 //处理系数
ratio,_ := gredis.String(redisConn.Do("HGET","zy_ratio_sku",goods_id)) ratio,_ := gredis.String(redisConn.Do("HGET","zy_ratio_sku",goods_id))
var PriceAcXi float64 = 0 //系数
if ratio != "" { if ratio != "" {
//拼接梯度价格 PriceAcXi = gjson.Get(ratio,"price_ac").Float()
for _,v := range ladderPrice{
v.PriceAc = gjson.Get(ratio,"price_ac").Float()
}
//获取立创价格 //获取立创价格
szlcPriceStr := `{"mykey":`+gjson.Get(ratio,"szlc_price").String()+`}` if gjson.Parse("szlc_price").String() == "" {
ladder_price_arr := gjson.Get(szlcPriceStr,"mykey").Array() A.Set("szlc_price",nil)
}else{
ladderPriceLc := make([]model.LadderPriceLc,0) ladderPriceLc := make([]model.LadderPriceLc,0)
for _,v := range ladder_price_arr{ for _,v := range gjson.Parse("szlc_price").Array(){
ladderPriceLc = append(ladderPriceLc, model.LadderPriceLc{ ladderPriceLc = append(ladderPriceLc, model.LadderPriceLc{
Purchases: v.Get("Purchases").Int(), Purchases: v.Get("Purchases").Int(),
Price: v.Get("price").Float(), Price: v.Get("price").Float(),
}) })
} }
A.Set("szlc_price",ladderPriceLc)
}
A.Set("allow_coupon",gjson.Get(ratio,"allow_coupon").String()) A.Set("allow_coupon",gjson.Get(ratio,"allow_coupon").String())
A.Set("allow_presale",gjson.Get(ratio,"allow_presale").String()) A.Set("allow_presale",gjson.Get(ratio,"allow_presale").String())
A.Set("szlc_price",ladderPriceLc) A.Set("ac_type", 6) //系数
}
//拼接梯度价格
ladderPriceArr := gjson.Get(info,"ladder_price").Array()
ladderPrice := make([]model.LadderPrice,0)
for _,v := range ladderPriceArr{
if v.Get("purchases").String() == "" {
continue;
}
if PriceAcXi == 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: PriceAcXi,
})
}
}
if len(ladderPrice) == 0 {
A.Set("ladder_price", "") //
}else{
A.Set("ladder_price", ladderPrice) //
} }
//处理限额 //处理限额
...@@ -231,10 +272,24 @@ func (qs *ZiyingService) ZyGoodsDetail(ctx *gin.Context,goodsIds []string,goodsR ...@@ -231,10 +272,24 @@ func (qs *ZiyingService) ZyGoodsDetail(ctx *gin.Context,goodsIds []string,goodsR
A.Set("is_buy",1) A.Set("is_buy",1)
} }
//最后写入sync map if PriceAcXi == 0 { //没有系数价格才处理活动价
(*goodsRes).Store(goods_id,A) //处理活动价
A.Set("ac_type",0)
A.Set("allow_coupon",1)
Ac_price := qs.ActivityPrice(ctx,info,&redisConn)
if Ac_price != nil {
keys := Ac_price.Keys()
for _, k := range keys {
v, _ := Ac_price.Get(k)
A.Set(k,v) //活动价格覆盖
}
}
} }
//最后写入sync map
(GoodsRes).Store(goods_id,A)
}
ch <- GoodsRes
} }
......
...@@ -39,9 +39,21 @@ func (qs *ZiyingService) skuLockNum(c *redis.Conn,goodsId string) int64{ ...@@ -39,9 +39,21 @@ func (qs *ZiyingService) skuLockNum(c *redis.Conn,goodsId string) int64{
获取自营活动价 获取自营活动价
*/ */
func (qs *ZiyingService) ActivityPrice(ctx *gin.Context,SkuInfo string,c *redis.Conn) *orderedmap.OrderedMap { func (qs *ZiyingService) ActivityPrice(ctx *gin.Context,SkuInfo string,c *redis.Conn) *orderedmap.OrderedMap {
goodsId := gjson.Get(SkuInfo,"goods_id").String()
//团购价
//assemble := ctx.Request.FormValue("power[assemble]")
//if php2go.InArray(assemble,[]string{"true","1",""}) {
// teamAc,_ := gredis.String((*c).Do("get","Self_activity_assemble_list"))
// if teamAc != "" && goodsId == gjson.Get(teamAc,"goods_id").String() {
// data := qs.HDActivityPrice(ctx,teamAc,SkuInfo,"7")
// if data != nil {
// return data
// }
// }
//}
//新客价处理 //新客价处理
if ctx.Request.FormValue("power[newCustomer]") == "true" || if ctx.Request.FormValue("power[newCustomer]") == "true" || ctx.Request.FormValue("power[newCustomer]") == "1" {
ctx.Request.FormValue("power[newCustomer]") == "1" {
goodsActivityPrice,_ := gredis.String((*c).Do("get","Self_ActivityPrice_10000_NewCustomer")) goodsActivityPrice,_ := gredis.String((*c).Do("get","Self_ActivityPrice_10000_NewCustomer"))
if goodsActivityPrice != "" { if goodsActivityPrice != "" {
data := qs.HDActivityPrice(ctx,goodsActivityPrice,SkuInfo,"5") data := qs.HDActivityPrice(ctx,goodsActivityPrice,SkuInfo,"5")
...@@ -49,10 +61,11 @@ func (qs *ZiyingService) ActivityPrice(ctx *gin.Context,SkuInfo string,c *redis. ...@@ -49,10 +61,11 @@ func (qs *ZiyingService) ActivityPrice(ctx *gin.Context,SkuInfo string,c *redis.
return data return data
} }
} }
} }
//团购限制 //团购限制
data := qs.HDGoodsLimit(gjson.Get(SkuInfo,"goods_id").String(),gjson.Get(SkuInfo,"stock").String(),c) data := qs.HDGoodsLimit(goodsId,gjson.Get(SkuInfo,"stock").String(),c)
common.PrintDebugHtml(ctx,data)
if data != nil { if data != nil {
return data return data
} }
...@@ -125,30 +138,42 @@ func (qs *ZiyingService) HDActivityPrice(ctx *gin.Context,GoodsActivityPrice str ...@@ -125,30 +138,42 @@ func (qs *ZiyingService) HDActivityPrice(ctx *gin.Context,GoodsActivityPrice str
} }
} }
}else{ }else{
//fmt.Println(GoodsActivityPrice,SkuInfo)
brand_id := gjson.Get(GoodsActivityPrice,"brand_id").String()
class_id := gjson.Get(GoodsActivityPrice,"class_id").String()
if brand_id != "" {
if !common.GInArray(GoodsActivityPrice,"brand_id",gjson.Get(SkuInfo,"brand_id").String()) { if !common.GInArray(GoodsActivityPrice,"brand_id",gjson.Get(SkuInfo,"brand_id").String()) {
Ratio = false; //不符合活动价 Ratio = false; //不符合活动价
//fmt.Println("不符合活动价1")
goto End goto End
} }
}
if class_id != "" {
if !common.GInArray(GoodsActivityPrice,"class_id",gjson.Get(SkuInfo,"class_id2").String()) { if !common.GInArray(GoodsActivityPrice,"class_id",gjson.Get(SkuInfo,"class_id2").String()) {
Ratio = false; //不符合活动价 Ratio = false; //不符合活动价
//fmt.Println("不符合活动价2")
goto End goto End
} }
}
//会员价处理 //会员价处理
if Actype == "3" && is_part == "1" && visible_roster != "" { if Actype == "3" && is_part == "1" && visible_roster != "" {
Ratio = false; //
visible_roster = ","+visible_roster+"," visible_roster = ","+visible_roster+","
if php2go.Stripos(visible_roster,","+ctx.Request.FormValue("power[user_id]")+",",0) == -1 || if php2go.Stripos(visible_roster,","+ctx.Request.FormValue("power[user_id]")+",",0) != -1 {
php2go.Stripos(visible_roster,","+ctx.Request.FormValue("power[mobile]")+",",0) == -1 || Ratio = true;
php2go.Stripos(visible_roster,","+ctx.Request.FormValue("power[email]")+",",0) == -1 { }
Ratio = false; //不符合新客价 if php2go.Stripos(visible_roster,","+ctx.Request.FormValue("power[mobile]")+",",0) != -1 {
goto End Ratio = true;
} }
if php2go.Stripos(visible_roster,","+ctx.Request.FormValue("power[email]")+",",0) != -1 {
Ratio = true;
}
//fmt.Println("不符合活动价3")
} }
//处理黑名单,只有折扣活动才有黑名单,并且是下单页面,debug //处理黑名单,只有折扣活动才有黑名单,并且是下单页面,debug
if Actype == "2" && if Ratio == true && Actype == "2" && activity_id != "" && activity_type == "2" && ctx.Request.FormValue("power[verify_blacklist]") == "true" {
activity_id != "" &&
activity_type == "2" &&
ctx.Request.FormValue("power[verify_blacklist]") == "true" {
//redisConn := gredis.Conn("search_r") //redisConn := gredis.Conn("search_r")
//defer redisConn.Close(); //defer redisConn.Close();
...@@ -171,21 +196,19 @@ func (qs *ZiyingService) HDActivityPrice(ctx *gin.Context,GoodsActivityPrice str ...@@ -171,21 +196,19 @@ func (qs *ZiyingService) HDActivityPrice(ctx *gin.Context,GoodsActivityPrice str
} }
End: //最终执行 End: //最终执行
if Ratio { ladder_price_arr := gjson.Get(SkuInfo,"ladder_price").Array()
if Ratio && len(ladder_price_arr) > 0 {
discount_type := gjson.Get(GoodsActivityPrice,"discount_type").String() discount_type := gjson.Get(GoodsActivityPrice,"discount_type").String()
ratio := gjson.Get(GoodsActivityPrice,"ratio").Float() //当前活动折扣 ratio := gjson.Get(GoodsActivityPrice,"ratio").Float() //当前活动折扣
ladder_price_arr := gjson.Get(SkuInfo,"ladder_price").Array()
A := orderedmap.New(); A := orderedmap.New();
ladderType := make([]model.LadderPrice,0) ladderType := make([]model.LadderPrice,0)
for _,v := range ladder_price_arr{ for _,v := range ladder_price_arr{
if Actype != "7" || (Actype =="7" && discount_type != "") || discount_type == "1" { if Actype != "7" || (Actype =="7" && discount_type != "") || discount_type == "1" {
price_cn := v.Get("price_cn").Float() price_cn := v.Get("price_cn").Float()
price_ac := php2go.Round(price_cn*ratio/100) price_ac := php2go.Round(price_cn*ratio/100*10000)/10000
ladderType = append(ladderType, model.LadderPrice{ ladderType = append(ladderType, model.LadderPrice{
Purchases: v.Get("Purchases").Int(), Purchases: v.Get("purchases").Int(),
PriceUs: v.Get("price_us").Float(), PriceUs: v.Get("price_us").Float(),
PriceCn: price_cn, PriceCn: price_cn,
PriceAc: price_ac, PriceAc: price_ac,
...@@ -193,11 +216,26 @@ End: //最终执行 ...@@ -193,11 +216,26 @@ End: //最终执行
}) })
} }
} }
allow_not_login := gjson.Get(GoodsActivityPrice,"allow_not_login").Int()
if allow_not_login == 0 {
allow_not_login = 2
}
A.Set("activity_info",map[string]interface{}{
"activity_ad":gjson.Get(GoodsActivityPrice,"activity_ad").String(),
"sign_name":gjson.Get(GoodsActivityPrice,"sign_name").String(),
"allow_not_login":allow_not_login,
})
A.Set("ladder_price",ladderType)
A.Set("ratio",ratio) A.Set("ratio",ratio)
A.Set("ac_type",Actype) A.Set("ac_type",Actype)
A.Set("allow_coupon",ratio) allow_coupon := gjson.Get(GoodsActivityPrice,"allow_coupon").Int()
A.Set("activity_end_time",ratio) if gjson.Get(GoodsActivityPrice,"allow_coupon").Int() == 0 {
A.Set("activity_info",ratio) allow_coupon = 1
}
A.Set("allow_coupon",allow_coupon)
A.Set("activity_end_time",gjson.Get(GoodsActivityPrice,"end_time").Int())
return A return A
} }
return nil return nil
...@@ -229,7 +267,7 @@ func (qs *ZiyingService) HDGoodsLimit(SkuID string,Stock string,c *redis.Conn) ...@@ -229,7 +267,7 @@ func (qs *ZiyingService) HDGoodsLimit(SkuID string,Stock string,c *redis.Conn)
ladderType := make([]model.LadderPrice,0) ladderType := make([]model.LadderPrice,0)
for _,v := range ladder_price_arr{ for _,v := range ladder_price_arr{
ladderType = append(ladderType, model.LadderPrice{ ladderType = append(ladderType, model.LadderPrice{
Purchases: v.Get("Purchases").Int(), Purchases: v.Get("purchases").Int(),
PriceCn: v.Get("price_cn").Float(), PriceCn: v.Get("price_cn").Float(),
PriceAc: v.Get("price_ac").Float(), PriceAc: v.Get("price_ac").Float(),
}) })
...@@ -253,7 +291,6 @@ func (qs *ZiyingService) HDGoodsLimit(SkuID string,Stock string,c *redis.Conn) ...@@ -253,7 +291,6 @@ func (qs *ZiyingService) HDGoodsLimit(SkuID string,Stock string,c *redis.Conn)
if now_stock > common.MyFloat64(Stock) || now_stock == 0 { if now_stock > common.MyFloat64(Stock) || now_stock == 0 {
return nil return nil
} }
return A return A
} }
......
...@@ -6,10 +6,12 @@ import ( ...@@ -6,10 +6,12 @@ import (
"github.com/gomodule/redigo/redis" "github.com/gomodule/redigo/redis"
"github.com/syyongx/php2go" "github.com/syyongx/php2go"
"github.com/tidwall/gjson" "github.com/tidwall/gjson"
"go_sku_server/model"
"go_sku_server/pkg/common" "go_sku_server/pkg/common"
"go_sku_server/pkg/gredis" "go_sku_server/pkg/gredis"
"go_sku_server/pkg/logger" "go_sku_server/pkg/logger"
"go_sku_server/pkg/mysql" "go_sku_server/pkg/mysql"
"github.com/gogf/gf/util/gconv"
"sort" "sort"
) )
...@@ -20,37 +22,42 @@ type ZyCronService struct { ...@@ -20,37 +22,42 @@ type ZyCronService struct {
/* /*
计算自营折扣信息 计算自营折扣信息
@param checkGoodsId 单独一个sku运行 @param checkGoodsId 单独一个sku运行
fmt.Println(php2go.Stripos("10005,10006","10006",0))
*/ */
func (a *ZyCronService) ZyDiscount(checkGoodsId string) { func (a *ZyCronService) ZyDiscount(checkGoodsId string) {
var ( var (
i int i int
dbSpu = mysql.Conn("liexin_data") //spu实例化链接 dbSpu = mysql.Conn("liexin_data") //spu实例化链接
redisConn = gredis.Conn("search_r") redisConn = gredis.Conn("search_w")
) )
defer redisConn.Close() defer redisConn.Close()
redisConn.Do("del","zy_ratio_sku") //删除阶梯价缓存 if checkGoodsId == "" {
redisConn.Do("del","zy_ratio_sku") //删除所有系数缓存
}
twoYearsAgotime := php2go.Time()-60 * 60 * 24 * 365 * 2 //两年前时间戳 twoYearsAgotime := php2go.Time()-60 * 60 * 24 * 365 * 2 //两年前时间戳
page_size := 1000 //查数据库每页大小 page_size := 1000 //查数据库每页大小
OuterLoop: OuterLoop:
for i=1;i<=1000;i++ { for i=0;i<1000;i++ {
start := 0; start := 0;
if i== 1 { if i == 0 {
start = 0; start = 0;
}else{ }else{
start = (i-1)*page_size 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 != "" { if checkGoodsId != "" {
sql = "select goods_id,class_id2,brand_id,cost,ladder_price from lie_goods where goods_id="+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) goodsInfos, err := dbSpu.QueryString(sql)
if err != nil || len(goodsInfos) == 0{ if err != nil || len(goodsInfos) == 0{
fmt.Print("查询没有数据",err) //fmt.Print("查询没有数据",err)
break; break;
} }
for _,a := range goodsInfos{ for _,a := range goodsInfos{
...@@ -58,10 +65,10 @@ func (a *ZyCronService) ZyDiscount(checkGoodsId string) { ...@@ -58,10 +65,10 @@ func (a *ZyCronService) ZyDiscount(checkGoodsId string) {
now_class_id := a["class_id2"] now_class_id := a["class_id2"]
now_brand_id := a["brand_id"] now_brand_id := a["brand_id"]
/********开始计算系数******/ /********开始计算系数******/
fmt.Println("开始计算系数"+now_goods_id) //fmt.Println("开始计算系数"+now_goods_id)
goodsBatch,_ := gredis.String(redisConn.Do("HGET","Self_goods_batch",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; //最早的批次 var EarlyBatchTime int64 = 0; //最早的批次
for _, goods := range apiGoodsList { for _, goods := range apiGoodsList {
...@@ -76,8 +83,8 @@ func (a *ZyCronService) ZyDiscount(checkGoodsId string) { ...@@ -76,8 +83,8 @@ func (a *ZyCronService) ZyDiscount(checkGoodsId string) {
} }
if EarlyBatchTime == 0 { if EarlyBatchTime == 0 {
fmt.Println("没有批次信息,goods_id :"+now_goods_id) //fmt.Println("没有批次信息,goods_id :"+now_goods_id)
break; continue;
} }
//查询所有的系数列表 //查询所有的系数列表
ratioAll, _ := redis.Values(redisConn.Do("hgetall", "Self_goods_ratio")) ratioAll, _ := redis.Values(redisConn.Do("hgetall", "Self_goods_ratio"))
...@@ -89,13 +96,12 @@ func (a *ZyCronService) ZyDiscount(checkGoodsId string) { ...@@ -89,13 +96,12 @@ func (a *ZyCronService) ZyDiscount(checkGoodsId string) {
} }
//系数排序,sort最高的优先排序 //系数排序,sort最高的优先排序
keys := make([]int,0) var slic model.SorterRatio
rationList := make(map[int][]map[string]string,0)
for _,v:=range retioArr{ for _,v:=range retioArr{
keys = append(keys,int(gjson.Get(v,"sort").Int())) if len(v) > 10 {
rationTemp := make([]map[string]string,0) slic = append(slic,map[string]string{
rationTemp = append(rationTemp,map[string]string{
"goods_id":gjson.Get(v,"goods_id").String(), "goods_id":gjson.Get(v,"goods_id").String(),
"sort":gjson.Get(v,"sort").String(), //系数名称
"name":gjson.Get(v,"name").String(), //系数名称 "name":gjson.Get(v,"name").String(), //系数名称
"ratio":gjson.Get(v,"ratio").String(), //折扣价 "ratio":gjson.Get(v,"ratio").String(), //折扣价
"min_ratio":gjson.Get(v,"min_ratio").String(), //保本折扣价 "min_ratio":gjson.Get(v,"min_ratio").String(), //保本折扣价
...@@ -105,32 +111,35 @@ func (a *ZyCronService) ZyDiscount(checkGoodsId string) { ...@@ -105,32 +111,35 @@ func (a *ZyCronService) ZyDiscount(checkGoodsId string) {
"allow_coupon":gjson.Get(v,"allow_coupon").String(), "allow_coupon":gjson.Get(v,"allow_coupon").String(),
"allow_presale":gjson.Get(v,"allow_presale").String(), "allow_presale":gjson.Get(v,"allow_presale").String(),
}) })
rationList[int(gjson.Get(v,"sort").Int())] =rationTemp
} }
sort.Sort(sort.Reverse(sort.IntSlice(keys))) //倒叙排 }
//计算系数 sort.Sort(model.SorterRatio(slic))
for _,sort :=range keys{ //fmt.Println(slic)
rationInfo := rationList[sort] //return
for _,info := range rationInfo {
//计算系数价格
OuterLoop2:
for _,info :=range slic{
//fmt.Println(info)
//不参与系数的商品 //不参与系数的商品
if info["goods_id"] != "" { if info["goods_id"] != "" {
if php2go.Stripos(info["goods_id"],","+now_goods_id+",",0) > -1 { if php2go.Stripos(info["goods_id"],","+now_goods_id+",",0) > -1 {
fmt.Println("1001 本商品不参与系数"+now_goods_id) //fmt.Println("1001 本商品不参与系数"+now_goods_id)
continue; continue;
} }
} }
//不参与分类的商品 //不参与分类的商品
if info["class_id"] != "" { if info["class_id"] != "" {
if php2go.Stripos(info["class_id"],","+now_class_id+",",0) > -1 { if php2go.Stripos(info["class_id"],","+now_class_id+",",0) == -1 {
fmt.Println("1002 不参与分类的商品"+now_goods_id) //fmt.Println("1002 不参与分类的商品"+now_goods_id)
continue; continue;
} }
} }
//不参与分类的商品 //不参与分类的商品
if info["brand_id"] != "" { if info["brand_id"] != "" {
if php2go.Stripos(info["brand_id"],","+now_brand_id+",",0) > -1 { if php2go.Stripos(info["brand_id"],","+now_brand_id+",",0) == -1 {
fmt.Println("1003 不参与分类的商品"+now_goods_id) //fmt.Println("1003 不参与分类的商品"+now_goods_id)
continue; continue;
} }
} }
...@@ -156,27 +165,25 @@ func (a *ZyCronService) ZyDiscount(checkGoodsId string) { ...@@ -156,27 +165,25 @@ func (a *ZyCronService) ZyDiscount(checkGoodsId string) {
} }
} }
fmt.Print(EarlyBatchTime,"<br/>") //fmt.Println(EarlyBatchTime)
fmt.Print(twoYearsAgotime,"<br/>") //fmt.Println(twoYearsAgotime)
if isExpire == false { if isExpire == false {
fmt.Println("1001 本商品不存在过期"+now_goods_id,info) //fmt.Println("1001 本商品不存在过期"+now_goods_id)
continue; continue;
} }
//处理清库存系数,几个系数符合,往下面算 //处理清库存系数,几个系数符合,往下面算
var ratioPrice float64; var ratioPrice float64;
ratioPrice = common.MyFloat64(a["cost"]) * common.MyFloat64(info["ratio"]) ratioPrice = php2go.Round(gconv.Float64(a["cost"]) * gconv.Float64(info["ratio"])*10000)/10000
fmt.Print(ratioPrice,"<br/>")
//查询立创数据 //查询立创数据
szlcPriceStr,_ := gredis.String(redisConn.Do("HGET","Self_szlc_price",now_goods_id)) //获取立创价格 szlcPriceStr,_ := gredis.String(redisConn.Do("HGET","Self_szlc_price",now_goods_id)) //获取立创价格
if szlcPriceStr != "" { //有立创的价格 if szlcPriceStr != "" { //有立创的价格
nowLadder := gjson.Get(a["ladder_price"], "purchases").Array() nowLadder := gjson.Parse(a["ladder_price"]).Array()
endnowLadder := nowLadder[len(nowLadder)-1].Get("purchases").Int() //最后一个梯度 endnowLadder := nowLadder[len(nowLadder)-1].Get("purchases").Int() //最后一个梯度
//fmt.Println(endnowLadder)
//获取立创对应的梯度价格 //获取立创对应的梯度价格
szlcPriceStr = `{"mykey":`+szlcPriceStr+`}` szlcPriceArr := gjson.Parse(szlcPriceStr).Array()
szlcPriceArr := gjson.Get(szlcPriceStr, "mykey").Array()
var szlcPrice float64 =0 //找到立创对应的梯度价格 var szlcPrice float64 =0 //找到立创对应的梯度价格
for _,b := range szlcPriceArr{ for _,b := range szlcPriceArr{
if b.Get("purchases").Int() <= endnowLadder { if b.Get("purchases").Int() <= endnowLadder {
...@@ -185,7 +192,7 @@ func (a *ZyCronService) ZyDiscount(checkGoodsId string) { ...@@ -185,7 +192,7 @@ func (a *ZyCronService) ZyDiscount(checkGoodsId string) {
} }
szlcPrice = szlcPrice*0.95 //立创95折 szlcPrice = szlcPrice*0.95 //立创95折
if ratioPrice > szlcPrice { //比立创的95折大 if ratioPrice > szlcPrice { //比立创的95折大
minPrice := common.MyFloat64(a["cost"]) * common.MyFloat64(info["min_ratio"]) minPrice := php2go.Round(gconv.Float64(a["cost"]) * gconv.Float64(info["min_ratio"])*10000)/10000
if szlcPrice < minPrice { if szlcPrice < minPrice {
ratioPrice = minPrice ratioPrice = minPrice
}else{ }else{
...@@ -209,14 +216,16 @@ func (a *ZyCronService) ZyDiscount(checkGoodsId string) { ...@@ -209,14 +216,16 @@ func (a *ZyCronService) ZyDiscount(checkGoodsId string) {
"allow_coupon":allow_coupon, "allow_coupon":allow_coupon,
"allow_presale":allow_presale, "allow_presale":allow_presale,
"szlc_price":szlcPriceStr, "szlc_price":szlcPriceStr,
"price_ac":common.MyFloat64ToStr(ratioPrice), "price_ac":gconv.String(ratioPrice),
}) })
redisConn.Do("HSET","zy_ratio_sku",now_goods_id,string(ratioRes)) //写入缓存 _,err := redisConn.Do("HSET","zy_ratio_sku",now_goods_id,string(ratioRes)) //写入缓存
if err != nil {
fmt.Println(err)
}
//最后写日志 //最后写日志
logger.Log("计算阶梯价成功 goods_id: "+now_goods_id+" 原始梯度价:"+a["ladder_price"]+" 立创梯度价: "+ szlcPriceStr +" 结果:"+string(ratioRes),"ratio_sku_",1) logger.Log("计算阶梯价成功 goods_id: "+now_goods_id+" 原始梯度价:"+a["ladder_price"]+" 立创梯度价: "+ szlcPriceStr +" 结果:"+string(ratioRes),"ratio_sku_",2)
break OuterLoop2;
}
} }
if checkGoodsId != "" { if checkGoodsId != "" {
......
...@@ -6,9 +6,7 @@ import ( ...@@ -6,9 +6,7 @@ import (
) )
func main() { func main() {
str := `{"cn":{"max":"10000","price":"20"},"hk":{"max":69000,"price":138}}` var a = []string{"3923"}
var res interface{} var b = 3923
fmt.Println(php2go.JSONDecode([]byte(str), &res)) fmt.Println(php2go.InArray(b,a))
tem, _ := php2go.JSONEncode(res)
fmt.Println(string(tem))
} }
...@@ -10,6 +10,8 @@ export GO111MODULE=on ...@@ -10,6 +10,8 @@ export GO111MODULE=on
go env -w GOPROXY=https://goproxy.cn,direct go env -w GOPROXY=https://goproxy.cn,direct
go build -o ${Cur_Dir}"/cmd/http/http" ${Cur_Dir}"/cmd/http/http_server.go" go build -o ${Cur_Dir}"/cmd/http/http" ${Cur_Dir}"/cmd/http/http_server.go"
chmod +x ${Cur_Dir}"/cmd/http/http" chmod +x ${Cur_Dir}"/cmd/http/http"
go build -o ${Cur_Dir}"/cmd/cron/cron" ${Cur_Dir}"/cmd/cron/cron_server.go"
chmod +x ${Cur_Dir}"/cmd/cron/cron"
chmod +x ${Cur_Dir}"/update.sh" chmod +x ${Cur_Dir}"/update.sh"
supervisorctl restart go_sku_server_60005:* supervisorctl restart go_sku_server_60005:*
echo "更新执行成功" echo "更新执行成功"
......
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