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~
/go.mod
/conf
/logs
<<<<<<< HEAD
/mylogs
/doc/test
=======
>>>>>>> e30e7e5cf1e4c03c945073b5e6d46fabceff385a
......@@ -2,6 +2,7 @@ package main
import (
"flag"
"fmt"
"go_sku_server/boot"
"go_sku_server/pkg/logger"
"go_sku_server/service"
......@@ -13,12 +14,13 @@ 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 {
panic(err)
}
fmt.Print(goods_id)
logger.Log("启动任务","ratio",1)
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 @@
[default_redis_read]
host = 192.168.1.235:6379
password = icDb29mLy2s
max_idle = 3000
max_idle = 1000
max_active = 5000
idle_timeout = 20
[default_redis_write]
host = 192.168.1.235:6379
password = icDb29mLy2s
max_idle = 3000
max_idle = 1000
max_active = 5000
idle_timeout = 20
......
......@@ -4,15 +4,17 @@ import (
"github.com/gin-gonic/gin"
"github.com/syyongx/php2go"
"go_sku_server/pkg/common"
"go_sku_server/pkg/logger"
"go_sku_server/service"
"sync"
"time"
)
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 power[newCustomer] 是否获取新客价 :true
......@@ -39,36 +41,37 @@ func Synchronization(ctx *gin.Context) {
common.Output(ctx, 1001, "查询型号ID不得为空", "")
return
}
//gjson.Parse(string).Array()
GoodsRes := sync.Map{}
goodsIdArr := php2go.Explode(",", GoodsIdStr)
wg := sync.WaitGroup{} //协程
//wg := sync.WaitGroup{} //协程
ch := make(chan sync.Map) //管道
p := 0 //总共协程
zyGoodsId := make([]string, 0)
lyGoodsId := make([]string, 0)
for _, goods_id := range goodsIdArr {
if goods_id == "" {
continue;
for _, goodsId := range goodsIdArr {
if goodsId == "" {
continue
}
if len(goods_id) < 19 { //自营
zyGoodsId = append(zyGoodsId, goods_id)
if len(goodsId) < 19 { //自营
zyGoodsId = append(zyGoodsId, goodsId)
if len(zyGoodsId) >= goods_slice_count {
common.PrintDebugHtml(ctx, "zy增加协程1001:")
common.PrintDebugHtml(ctx, zyGoodsId)
wg.Add(1) //协程计数一
go zyService.ZyGoodsDetail(ctx, zyGoodsId, &GoodsRes, &wg)
//wg.Add(1) //协程计数一
go zyService.ZyGoodsDetail(ctx, zyGoodsId, ch)
zyGoodsId = zyGoodsId[:0:0]
p++
}
} else { //联营
lyGoodsId = append(lyGoodsId, goods_id)
lyGoodsId = append(lyGoodsId, goodsId)
if len(lyGoodsId) >= goods_slice_count {
common.PrintDebugHtml(ctx, "ly增加协程1002:")
common.PrintDebugHtml(ctx, zyGoodsId)
wg.Add(1)
go lyService.LyGoodsDetail(ctx, lyGoodsId, &GoodsRes, &wg)
common.PrintDebugHtml(ctx, lyGoodsId)
//wg.Add(1)
go lyService.LyGoodsDetail(ctx, lyGoodsId, ch)
lyGoodsId = lyGoodsId[:0:0]
p++
}
}
}
......@@ -76,34 +79,41 @@ func Synchronization(ctx *gin.Context) {
if len(zyGoodsId) > 0 {
common.PrintDebugHtml(ctx, "zy增加协程1003:")
common.PrintDebugHtml(ctx, zyGoodsId)
wg.Add(1) //协程计数一
go zyService.ZyGoodsDetail(ctx, zyGoodsId, &GoodsRes, &wg)
//wg.Add(1) //协程计数一
go zyService.ZyGoodsDetail(ctx, zyGoodsId, ch)
p++
}
if len(lyGoodsId) > 0 {
common.PrintDebugHtml(ctx, "ly增加协程1004:")
common.PrintDebugHtml(ctx, zyGoodsId)
wg.Add(1)
go lyService.LyGoodsDetail(ctx, lyGoodsId, &GoodsRes, &wg)
//wg.Add(1)
go lyService.LyGoodsDetail(ctx, lyGoodsId, ch)
p++
}
wg.Wait()
//wg.Wait()
//异步map最后转成map
temp := make(map[string]interface{})
GoodsRes.Range(func(k, v interface{}) bool {
s, _ := k.(string)
temp[s] = v
return true
})
for i := 0; i < p; i++ {
select {
case GoodsRes := <-ch:
GoodsRes.Range(func(k, v interface{}) bool {
s, _ := k.(string)
temp[s] = v
return true
})
case <-time.After(time.Second * 20):
logger.Log("协程超时", "sku", 1)
}
}
common.Output(ctx, 0, "success", temp)
}
/*
健康监测
*/
func Health(ctx *gin.Context) {
func Hbsdata(ctx *gin.Context) {
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 (
github.com/tidwall/gjson v1.6.1
github.com/tidwall/sjson v1.1.1
github.com/uniplaces/carbon v0.1.6 // indirect
<<<<<<< HEAD
go.etcd.io/bbolt v1.3.4 // indirect
=======
>>>>>>> e30e7e5cf1e4c03c945073b5e6d46fabceff385a
go.mongodb.org/mongo-driver v1.3.5 // indirect
go.starlark.net v0.0.0-20201204201740-42d4f566359b // indirect
go.uber.org/zap v1.14.1 // indirect
<<<<<<< HEAD
golang.org/x/arch v0.0.0-20201207015849-377592649dd6 // indirect
golang.org/x/sys v0.0.0-20201204225414-ed752295db88 // indirect
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 // 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/mgo.v2 v2.0.0-20190816093944-a6b53ec6cb22
gopkg.in/olivere/elastic.v5 v5.0.85
gopkg.in/yaml.v2 v2.4.0 // indirect
sigs.k8s.io/yaml v1.2.0 // indirect
<<<<<<< HEAD
xorm.io/core v0.7.2-0.20190928055935-90aeac8d08eb // indirect
=======
>>>>>>> e30e7e5cf1e4c03c945073b5e6d46fabceff385a
)
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:"-"`
......
......@@ -6,42 +6,44 @@ import (
//联营sku结构体
type LySku struct {
SpuId string `json:"spu_id"`
OldGoodsId int64 `json:"old_goods_id"`
UpdateTime int64 `json:"update_time"`
CpTime int64 `json:"cp_time"`
GoodsStatus int64 `json:"goods_status"`
GoodsType int64 `json:"goods_type"`
SupplierId int64 `json:"supplier_id"`
Encoded string `json:"encoded"`
BatchSn string `json:"batch_sn"`
Moq int64 `json:"moq"`
Mpq int64 `json:"mpq"`
Stock int64 `json:"stock"`
HkDeliveryTime string `json:"hk_delivery_time"`
CnDeliveryTime string `json:"cn_delivery_time"`
LadderPrice []LadderPrice `json:"ladder_price"`
GoodsImages string `json:"goods_images"`
Canal string `json:"canal"`
Packing string `json:"packing"`
GoodsId string `json:"goods_id"`
GoodsName string `json:"goods_name"`
BrandName string `json:"brand_name"`
SupplierName string `json:"supplier_name"`
Attrs interface{} `json:"attrs"`
ScmBrand interface{} `json:"scm_brand"`
AcType int `json:"ac_type"`
AllowCoupon int `json:"allow_coupon"`
BrandId int64 `json:"brand_id"`
LadderPrice []LadderPrice `json:"-"`
SpuId string `json:"spu_id"`
OldGoodsId int64 `json:"old_goods_id"`
UpdateTime int64 `json:"update_time"`
CpTime int64 `json:"cp_time"`
GoodsStatus int64 `json:"goods_status"`
GoodsType int64 `json:"goods_type"`
SupplierId int64 `json:"supplier_id"`
Encoded string `json:"encoded"`
BatchSn string `json:"batch_sn"`
Moq int64 `json:"moq"`
Mpq int64 `json:"mpq"`
Stock int64 `json:"stock"`
HkDeliveryTime string `json:"hk_delivery_time"`
CnDeliveryTime string `json:"cn_delivery_time"`
LadderPriceResult interface{} `json:"ladder_price"`
GoodsImages string `json:"goods_images"`
Canal string `json:"canal"`
IsExpire int `json:"is_expire,omitempty"`
Packing string `json:"packing"`
GoodsId string `json:"goods_id"`
GoodsName string `json:"goods_name"`
BrandName string `json:"brand_name"`
SupplierName string `json:"supplier_name"`
Attrs interface{} `json:"attrs"`
ScmBrand interface{} `json:"scm_brand"`
AcType int `json:"ac_type"`
AllowCoupon int `json:"allow_coupon"`
BrandId int64 `json:"brand_id"`
//系数相关
Coefficient interface{} `json:"coefficient,omitempty"`
Original []LadderPrice `json:"original_price"`
SuppExtendFee interface{} `json:"supp_extend_fee"`
IsBuy int `json:"is_buy"`
Coefficient interface{} `json:"coefficient,omitempty"`
Original interface{} `json:"original_price,omitempty"`
SuppExtendFee interface{} `json:"supp_extend_fee"`
IsBuy int `json:"is_buy"`
//spu信息
ClassID1 int `json:"class_id1"`
ClassID2 int `json:"class_id2"`
ClassID3 int `json:"class_id3,omitempty"`
ClassID3 int `json:"class_id3"`
SpuName string `json:"spu_name"`
Status int `json:"status"`
ImagesL string `json:"images_l"`
......@@ -61,6 +63,7 @@ type LySku struct {
//活动信息
ActivityEndTime int64 `json:"activity_end_time,omitempty"`
ActivityInfo map[string]interface{} `json:"activity_info,omitempty"`
Content interface{} `json:"content"`
}
//为什么不直接映射到结构,而要用gjson,因为redis存的数据结构不一定正常,可能类型不一致
......@@ -104,6 +107,9 @@ func InitSkuData(sku string) (data LySku) {
stock := gjson.Get(sku, "stock").Int()
data.Stock = stock
isExpire := gjson.Get(sku, "is_expire").Int()
data.IsExpire = int(isExpire)
hkDeliveryTime := gjson.Get(sku, "hk_delivery_time").String()
data.HkDeliveryTime = hkDeliveryTime
......@@ -124,6 +130,7 @@ func InitSkuData(sku string) (data LySku) {
LadderPriceStr := gjson.Get(sku, "ladder_price").String()
data.LadderPrice = getLadderPrice(LadderPriceStr)
data.Original = getOriginPrice(LadderPriceStr)
return
}
......@@ -146,3 +153,22 @@ func getLadderPrice(ladderPriceStr string) (ladderPrice []LadderPrice) {
}
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
@param targetk string 目标ID
*/
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)
for _,a := range s {
c := a.String()
d = append(d,c)
}
return php2go.InArray(targetK,d)
}
/*
......
......@@ -48,9 +48,9 @@ func Output(ctx *gin.Context,errCode int, errMsg string, data interface{}) {
ErrMsg: errMsg,
Data: data,
}
if errCode >= 100 {
SearchApiLogger(ctx,errCode, errMsg)
}
//if errCode >= 100 {
// //SearchApiLogger(ctx,errCode, errMsg)
//}
if ctx.DefaultQuery("callback", "") != "" {
ctx.JSONP(200, response)
} else {
......
......@@ -60,6 +60,7 @@ func getConn(writeHost, password string, maxIdle, maxActive int) (pool *redis.Po
_, err := c.Do("PING")
return err
},
Wait: true,
}
return
}
......
......@@ -34,12 +34,12 @@ func Log(writeString string,log_file_pre string,types int) {
date := time.Now().Format("2006-01-02")
date2 := time.Now().Format("2006-01-02 15:04:05")
path,_:=os.Getwd()
CreateDateDir(path,"mylogs")
var filename = path+"/mylogs/"+date+log_file_pre+".txt"
CreateDateDir(path,"logs")
var filename = path+"/logs/"+date+log_file_pre+".txt"
var f *os.File
var err1 error
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 {
f, err1 = os.Create(filename) //创建文件
}
......@@ -49,6 +49,7 @@ func Log(writeString string,log_file_pre string,types int) {
if types == 1 {
fmt.Print(writeString)
}
defer f.Close()
//fmt.Print(err)
}
......
......@@ -20,8 +20,8 @@ func InitRouter() *gin.Engine {
r.GET("Synchronization", controller.Synchronization)
r.POST("Synchronization",controller.Synchronization)
//心跳
r.GET("Health", controller.Health)
r.POST("Health",controller.Health)
r.GET("hbsdata", controller.Hbsdata)
r.POST("hbsdata",controller.Hbsdata)
//自营SaveSku
r.POST("SaveSku",controller.Error_Middleware(),controller.SaveSku)
......
......@@ -6,6 +6,7 @@ import (
"github.com/syyongx/php2go"
"github.com/tidwall/gjson"
"go_sku_server/model"
"go_sku_server/pkg/common"
"go_sku_server/pkg/gredis"
"sort"
"sync"
......@@ -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")
defer func() {
wg.Done()
//wg.Done()
redisConn.Close()
}()
fast := ctx.Request.FormValue("power[fast]")
isNewCustomer := ctx.Request.FormValue("power[newCustomer]")
power := Power{
......@@ -45,12 +45,18 @@ func (ls *LyService) LyGoodsDetail(ctx *gin.Context, goodsIds []string, goodsRes
SpecialInvoice: ctx.Request.FormValue("power[special_invoice]"),
VerifyBlacklist: ctx.Request.FormValue("power[verify_blacklist]"),
}
common.PrintDebugHtml(ctx,power)
//批量获取商品详情
skuArr := gredis.Hmget("default_r", "sku", goodsIds)
//为了性能着想,这边也先去批量获取spu的信息
spuList := ls.getSpuList(skuArr)
GoodsRes := sync.Map{}
for goodsId, skuStr := range skuArr {
if skuStr == "" {
GoodsRes.Store(goodsId, false)
continue
}
//初始化有序map,拼接data 数据
//A := orderedmap.New()
sku := model.InitSkuData(skuStr)
......@@ -116,15 +122,13 @@ func (ls *LyService) LyGoodsDetail(ctx *gin.Context, goodsIds []string, goodsRes
//活动标识
hasActivity := false
//判断是否有新客价权利
if isNewCustomer == "true" {
if isNewCustomer == "true" || isNewCustomer == "1" {
//获取新客价
//todo test
sku = ls.GetActivityPrice(sku, "_NewCustomer", power)
if sku.AcType > 0 {
hasActivity = true
}
}
//获取活动价
if !hasActivity {
sku = ls.GetActivityPrice(sku, "", power)
......@@ -132,15 +136,16 @@ func (ls *LyService) LyGoodsDetail(ctx *gin.Context, goodsIds []string, goodsRes
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)
if sku.AcType > 0 {
hasActivity = true
}
}
//处理阶梯价数据
if len(sku.LadderPrice) > 0 {
//排序
......@@ -151,7 +156,6 @@ func (ls *LyService) LyGoodsDetail(ctx *gin.Context, goodsIds []string, goodsRes
sku.Moq = purchases
}
}
//获取系数
sku = ls.GetCoefficient(sku)
......@@ -160,12 +164,14 @@ func (ls *LyService) LyGoodsDetail(ctx *gin.Context, goodsIds []string, goodsRes
if sku.SupplierId != 0 {
sku.SuppExtendFee = ls.GetExtendFee(sku.SupplierId, sku.Canal)
}
//还要处理货期
delivery := ls.GetDelivery(sku.SupplierId, sku.Canal)
sku.CnDeliveryTime = delivery["cn_delivery"]
sku.HkDeliveryTime = delivery["hk_delivery"]
if delivery["cn_delivery"] != "" {
sku.CnDeliveryTime = delivery["cn_delivery"]
}
if delivery["hk_delivery"] != "" {
sku.HkDeliveryTime = delivery["hk_delivery"]
}
}
//处理是否可以购买
......@@ -173,6 +179,12 @@ func (ls *LyService) LyGoodsDetail(ctx *gin.Context, goodsIds []string, goodsRes
sku.Mpq = 1
}
if len(sku.LadderPrice) > 0 {
sku.LadderPriceResult = sku.LadderPrice
} else {
sku.LadderPriceResult = []int{}
}
//判断是否可以购买
sku.IsBuy = ls.GetIsBuy(sku)
......@@ -180,13 +192,11 @@ func (ls *LyService) LyGoodsDetail(ctx *gin.Context, goodsIds []string, goodsRes
sku = ls.CombineSup(sku, spu)
//最后一步,将sku的全部信息放到有序map里面
(*goodsRes).Store(goodsId, sku)
GoodsRes.Store(goodsId, sku)
//(*goodsRes)[goodsId] = A
}
return
ch <- GoodsRes
}
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{} {
if supplierId == 17 {
//为什么专卖的redis键会不一样,专卖的附加费管理在供应商系统,其它的在基石
value, _ := redis.String(redisCon.Do("HGET", "supp_extend_fee", "17."+canal))
if value == "" {
return false
}
//专卖的存了两种形式的数据,真是搞人心态
if strings.Contains(value, "cn") {
var extendFee ExtendFee
......@@ -178,6 +181,9 @@ func (ls *LyService) GetExtendFee(supplierId int64, canal string) interface{} {
}
} else {
value, _ := redis.String(redisCon.Do("HGET", "supp_extend_fee", supplierId))
if value == "" {
return false
}
var extendFee ExtendFee
json.Unmarshal([]byte(value), &extendFee)
return extendFee
......@@ -187,30 +193,35 @@ func (ls *LyService) GetExtendFee(supplierId int64, canal string) interface{} {
//获取系数
func (ls *LyService) GetCoefficient(sku model.LySku) model.LySku {
if len(sku.LadderPrice) == 0 {
sku.Original = nil
return sku
}
flag := 0
data := make([]model.LadderPrice, len(sku.LadderPrice))
//专卖
originalLadderPrice := sku.LadderPrice
if sku.SupplierId == 17 {
ladderPrice := sku.LadderPrice
for key, price := range ladderPrice {
if price.Purchases == 0 {
continue
}
ladderPrice[key].PriceUs = common.MyRound(price.PriceUs, 4)
ladderPrice[key].PriceCn = common.MyRound(price.PriceCn, 4)
data[key].Purchases = price.Purchases
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 {
acPrice := price.PriceCn
ladderPrice[key].PriceAc = common.MyRound(price.PriceCn*(sku.Ratio/100), 4)
tempAcPrice := common.MyRound(price.PriceCn*(sku.Ratio/100), 4)
data[key].PriceAc = tempAcPrice
//优惠价后等于0,就代表没有搞活动
if ladderPrice[key].PriceAc <= 0 {
if tempAcPrice <= 0 {
sku.AcType = 0
}
//价格与原价一样
if acPrice == ladderPrice[key].PriceAc && key < 2 {
if data[key].PriceCn == tempAcPrice && key < 2 {
flag++
if flag >= 2 || (len(ladderPrice) < 2) {
sku.AcType = 0
......@@ -274,66 +285,67 @@ func (ls *LyService) GetCoefficient(sku model.LySku) model.LySku {
if !hasCoefficient {
coefficient = defaultCoefficient
}
// 为何是固定的1.13,关税基本不会变,有变的话跟产品沟通手动修改即可
//$tax = config('website.tax');
tax := 1.13
for key, price := range sku.LadderPrice {
if price.Purchases == 0 {
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成本价是什么,斌哥同步过来的成本价
//price.CostPrice是专门针对贸泽(mouser)的
//sku.LadderPrice[key].CostPrice是专门针对贸泽(mouser)的
if sku.AcType == 2 && sku.SupplierId == 14 {
if price.CostPrice != 0 {
sku.LadderPrice[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].PriceAc = common.MyRound(price.CostPrice*coefficient.ExtraRatio*coefficient.Cn*coefficient.Ratio, 4)
data[key].PriceUs = common.MyRound(price.CostPrice*coefficient.ExtraRatio*coefficient.Hk, 4)
} else {
sku.LadderPrice[key].PriceAc = price.PriceCn
data[key].PriceAc = data[key].PriceCn
}
continue
}
//处理活动价和原价相同的情况
if (sku.GoodsType == 1 || sku.GoodsType == 2) && sku.AcType > 1 && sku.Ratio > 0 {
priceAc := common.MyRound(price.PriceCn*(sku.Ratio/100), 4)
sku.LadderPrice[key].PriceAc = priceAc
priceAc := common.MyRound(data[key].PriceCn*(sku.Ratio/100), 4)
data[key].PriceAc = priceAc
if priceAc <= 0 {
sku.AcType = 0
break
} else {
if sku.AcType == 4 {
sku.LadderPrice[key].PriceCn = priceAc
data[key].PriceCn = priceAc
sku.AcType = 0
}
}
//为什么$kp < 2,如果第一阶梯或第二阶梯价格和活动价一样,就不输出活动价了
//活动价都是有样式的和平时不一样,如果价格一样,但是样子是活动价,客户会迷惑,所以不输出即可,保持原来的样式
if sku.LadderPrice[key].PriceCn == priceAc && key < 2 {
if data[key].PriceCn == priceAc && key < 2 {
flag++
if flag >= 2 {
sku.AcType = 0
}
if len(sku.LadderPrice) > 1 {
if sku.LadderPrice[1].PriceCn == 0 {
if len(data) > 1 {
if data[1].PriceCn == 0 {
sku.AcType = 0
}
}
}
}
}
if len(data) > 0 {
sku.LadderPrice = data
}
//输出税费到前端
coefficient.Tax = tax
sku.Coefficient = coefficient
}
sku.Original = originalLadderPrice
return sku
}
......@@ -344,7 +356,6 @@ func (ls *LyService) GetDelivery(supplierId int64, canal string) (delivery map[s
defer redisCon.Close()
if canal != "" {
supplierRatio, _ := redis.String(redisCon.Do("HGET", "supp_ratio", canal))
fmt.Println(supplierRatio)
if supplierRatio != "" {
delivery["cn_delivery"] = gjson.Get(supplierRatio, "cn_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
if suffix == "" && sku.SupplierId == 14 {
return getMouserActivityPrice(sku)
}
//先获取活动信息,针对不同供应商不同活动类型做活动吗,每个活动只能针对一个供应商
//比如有 Self_ActivityPrice_2_Discount,Self_ActivityPrice_1_NewCustomer
redisCon := gredis.Conn("default_r")
defer redisCon.Close()
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 == "" {
return sku
......@@ -44,9 +44,11 @@ func (ls *LyService) GetActivityPrice(sku model.LySku, suffix string, power Powe
//获取redis里面存储的活动相关信息
brandIdArray := gjson.Get(activityInfo, "brand_id").Array()
var brandIds []string
var brandIds []int64
for _, brandId := range brandIdArray {
brandIds = append(brandIds, brandId.String())
if brandId.String() != "" {
brandIds = append(brandIds, brandId.Int())
}
}
goodsNameArray := gjson.Get(activityInfo, "goods_name").Array()
var goodsNames []string
......@@ -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 &&
visibleRoster != "" {
//为了用字符串匹配
visibleRoster = visibleRoster + ","
visibleRoster = "," + visibleRoster + ","
//提取出user_id、手机号、邮箱
userInfo := make(map[string]string)
userInfo["user_id"] = power.UserId
......@@ -144,9 +146,9 @@ func (ls *LyService) GetActivityPrice(sku model.LySku, suffix string, power Powe
hasActivity = false
continue
}
if !strings.Contains(visibleRoster, ","+value+",") {
if strings.Contains(visibleRoster, ","+value+",") {
hasActivity = true
continue
break
} else {
hasActivity = false
}
......@@ -183,7 +185,6 @@ func (ls *LyService) GetActivityPrice(sku model.LySku, suffix string, power Powe
//}
}
}
//判断是否有活动
if !hasActivity {
return sku
......@@ -214,8 +215,10 @@ func (ls *LyService) GetActivityPrice(sku model.LySku, suffix string, power Powe
allowNotLogin = 2
}
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(),
"id": gjson.Get(activityInfo, "id").String(),
"activity_name": gjson.Get(activityInfo, "activity_name").String(),
"allow_not_login": allowNotLogin,
}
sku.AcType = 8
......
package service
import (
"fmt"
"github.com/gin-gonic/gin"
"github.com/iancoleman/orderedmap"
"github.com/tidwall/gjson"
......@@ -31,34 +30,24 @@ type ZiyingService struct {
@param power[special_invoice] 增值税专用发票公司名字,活动价时需要,否则可能导致用户无法享受活动价 : 深圳是猎芯科技有限公司
@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")
defer func() {
wg.Done();
//wg.Done();
redisConn.Close();
}()
skuArr := gredis.Hmget("search_r","Self_SelfGoods",goodsIds) //批量获取商品详情
fast := ctx.Request.FormValue("power[fast]")
GoodsRes := sync.Map{}
for goods_id,info := range skuArr {
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)
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()
......@@ -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("supplier_id", gjson.Get(info, "supplier_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("status", gjson.Get(info, "status").Int()) //
A.Set("encoded", gjson.Get(info, "encoded").String()) //
......@@ -91,22 +115,24 @@ func (qs *ZiyingService) ZyGoodsDetail(ctx *gin.Context,goodsIds []string,goodsR
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()," ")) //
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库存
stock := dbStock-lockStock //当前可购买库存
A.Set("stock",stock)
if dbStock > 0 {
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 {
A.Set("attrs", "") //属性值
......@@ -126,7 +152,10 @@ func (qs *ZiyingService) ZyGoodsDetail(ctx *gin.Context,goodsIds []string,goodsR
}
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" { //不是快速查询
// 供应商名称
......@@ -167,55 +196,67 @@ func (qs *ZiyingService) ZyGoodsDetail(ctx *gin.Context,goodsIds []string,goodsR
if 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()
if 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("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))
var PriceAcXi float64 = 0 //系数
if ratio != "" {
//拼接梯度价格
for _,v := range ladderPrice{
v.PriceAc = gjson.Get(ratio,"price_ac").Float()
}
PriceAcXi = 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)
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
A.Set("is_buy",1)
}
if PriceAcXi == 0 { //没有系数价格才处理活动价
//处理活动价
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)
(GoodsRes).Store(goods_id,A)
}
ch <- GoodsRes
}
......
......@@ -39,20 +39,33 @@ func (qs *ZiyingService) skuLockNum(c *redis.Conn,goodsId string) int64{
获取自营活动价
*/
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" ||
ctx.Request.FormValue("power[newCustomer]") == "1" {
if ctx.Request.FormValue("power[newCustomer]") == "true" || ctx.Request.FormValue("power[newCustomer]") == "1" {
goodsActivityPrice,_ := gredis.String((*c).Do("get","Self_ActivityPrice_10000_NewCustomer"))
if goodsActivityPrice != "" {
data := qs.HDActivityPrice(ctx,goodsActivityPrice,SkuInfo,"5")
data := qs.HDActivityPrice(ctx,goodsActivityPrice,SkuInfo,"5")
if data != nil {
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 {
return data
}
......@@ -125,30 +138,42 @@ func (qs *ZiyingService) HDActivityPrice(ctx *gin.Context,GoodsActivityPrice str
}
}
}else{
if !common.GInArray(GoodsActivityPrice,"brand_id",gjson.Get(SkuInfo,"brand_id").String()) {
Ratio = false; //不符合活动价
goto End
//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()) {
Ratio = false; //不符合活动价
//fmt.Println("不符合活动价1")
goto End
}
}
if !common.GInArray(GoodsActivityPrice,"class_id",gjson.Get(SkuInfo,"class_id2").String()) {
Ratio = false; //不符合活动价
goto End
if class_id != "" {
if !common.GInArray(GoodsActivityPrice,"class_id",gjson.Get(SkuInfo,"class_id2").String()) {
Ratio = false; //不符合活动价
//fmt.Println("不符合活动价2")
goto End
}
}
//会员价处理
if Actype == "3" && is_part == "1" && visible_roster != "" {
visible_roster = ","+visible_roster+","
if php2go.Stripos(visible_roster,","+ctx.Request.FormValue("power[user_id]")+",",0) == -1 ||
php2go.Stripos(visible_roster,","+ctx.Request.FormValue("power[mobile]")+",",0) == -1 ||
php2go.Stripos(visible_roster,","+ctx.Request.FormValue("power[email]")+",",0) == -1 {
Ratio = false; //不符合新客价
goto End
Ratio = false; //
visible_roster = ","+visible_roster+","
if php2go.Stripos(visible_roster,","+ctx.Request.FormValue("power[user_id]")+",",0) != -1 {
Ratio = true;
}
if php2go.Stripos(visible_roster,","+ctx.Request.FormValue("power[mobile]")+",",0) != -1 {
Ratio = true;
}
if php2go.Stripos(visible_roster,","+ctx.Request.FormValue("power[email]")+",",0) != -1 {
Ratio = true;
}
//fmt.Println("不符合活动价3")
}
//处理黑名单,只有折扣活动才有黑名单,并且是下单页面,debug
if Actype == "2" &&
activity_id != "" &&
activity_type == "2" &&
ctx.Request.FormValue("power[verify_blacklist]") == "true" {
if Ratio == true && Actype == "2" && activity_id != "" && activity_type == "2" && ctx.Request.FormValue("power[verify_blacklist]") == "true" {
//redisConn := gredis.Conn("search_r")
//defer redisConn.Close();
......@@ -171,21 +196,19 @@ func (qs *ZiyingService) HDActivityPrice(ctx *gin.Context,GoodsActivityPrice str
}
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()
ratio := gjson.Get(GoodsActivityPrice,"ratio").Float() //当前活动折扣
ladder_price_arr := gjson.Get(SkuInfo,"ladder_price").Array()
A := orderedmap.New();
ladderType := make([]model.LadderPrice,0)
for _,v := range ladder_price_arr{
if Actype != "7" || (Actype =="7" && discount_type != "") || discount_type == "1" {
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{
Purchases: v.Get("Purchases").Int(),
Purchases: v.Get("purchases").Int(),
PriceUs: v.Get("price_us").Float(),
PriceCn: price_cn,
PriceAc: price_ac,
......@@ -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("ac_type",Actype)
A.Set("allow_coupon",ratio)
A.Set("activity_end_time",ratio)
A.Set("activity_info",ratio)
allow_coupon := gjson.Get(GoodsActivityPrice,"allow_coupon").Int()
if gjson.Get(GoodsActivityPrice,"allow_coupon").Int() == 0 {
allow_coupon = 1
}
A.Set("allow_coupon",allow_coupon)
A.Set("activity_end_time",gjson.Get(GoodsActivityPrice,"end_time").Int())
return A
}
return nil
......@@ -229,7 +267,7 @@ func (qs *ZiyingService) HDGoodsLimit(SkuID string,Stock string,c *redis.Conn)
ladderType := make([]model.LadderPrice,0)
for _,v := range ladder_price_arr{
ladderType = append(ladderType, model.LadderPrice{
Purchases: v.Get("Purchases").Int(),
Purchases: v.Get("purchases").Int(),
PriceCn: v.Get("price_cn").Float(),
PriceAc: v.Get("price_ac").Float(),
})
......@@ -253,7 +291,6 @@ func (qs *ZiyingService) HDGoodsLimit(SkuID string,Stock string,c *redis.Conn)
if now_stock > common.MyFloat64(Stock) || now_stock == 0 {
return nil
}
return A
}
......
......@@ -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"
)
......@@ -20,37 +22,42 @@ type ZyCronService struct {
/*
计算自营折扣信息
@param checkGoodsId 单独一个sku运行
fmt.Println(php2go.Stripos("10005,10006","10006",0))
*/
func (a *ZyCronService) ZyDiscount(checkGoodsId string) {
var (
i int
dbSpu = mysql.Conn("liexin_data") //spu实例化链接
redisConn = gredis.Conn("search_r")
redisConn = gredis.Conn("search_w")
)
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 //两年前时间戳
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)
//fmt.Print("查询没有数据",err)
break;
}
for _,a := range goodsInfos{
......@@ -58,10 +65,10 @@ func (a *ZyCronService) ZyDiscount(checkGoodsId string) {
now_class_id := a["class_id2"]
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)) //获取商品批次信息
apiGoodsList := gjson.Get("{\"Parts\":"+goodsBatch+"}", "Parts").Array()
apiGoodsList := gjson.Parse(goodsBatch).Array()
var EarlyBatchTime int64 = 0; //最早的批次
for _, goods := range apiGoodsList {
......@@ -76,8 +83,8 @@ func (a *ZyCronService) ZyDiscount(checkGoodsId string) {
}
if EarlyBatchTime == 0 {
fmt.Println("没有批次信息,goods_id :"+now_goods_id)
break;
//fmt.Println("没有批次信息,goods_id :"+now_goods_id)
continue;
}
//查询所有的系数列表
ratioAll, _ := redis.Values(redisConn.Do("hgetall", "Self_goods_ratio"))
......@@ -89,48 +96,50 @@ 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 {
fmt.Println("1001 本商品不参与系数"+now_goods_id)
//fmt.Println("1001 本商品不参与系数"+now_goods_id)
continue;
}
}
//不参与分类的商品
if info["class_id"] != "" {
if php2go.Stripos(info["class_id"],","+now_class_id+",",0) > -1 {
fmt.Println("1002 不参与分类的商品"+now_goods_id)
if php2go.Stripos(info["class_id"],","+now_class_id+",",0) == -1 {
//fmt.Println("1002 不参与分类的商品"+now_goods_id)
continue;
}
}
//不参与分类的商品
if info["brand_id"] != "" {
if php2go.Stripos(info["brand_id"],","+now_brand_id+",",0) > -1 {
fmt.Println("1003 不参与分类的商品"+now_goods_id)
if php2go.Stripos(info["brand_id"],","+now_brand_id+",",0) == -1 {
//fmt.Println("1003 不参与分类的商品"+now_goods_id)
continue;
}
}
......@@ -156,27 +165,25 @@ 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)
//fmt.Println("1001 本商品不存在过期"+now_goods_id)
continue;
}
//处理清库存系数,几个系数符合,往下面算
var ratioPrice float64;
ratioPrice = common.MyFloat64(a["cost"]) * common.MyFloat64(info["ratio"])
fmt.Print(ratioPrice,"<br/>")
ratioPrice = php2go.Round(gconv.Float64(a["cost"]) * gconv.Float64(info["ratio"])*10000)/10000
//查询立创数据
szlcPriceStr,_ := gredis.String(redisConn.Do("HGET","Self_szlc_price",now_goods_id)) //获取立创价格
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() //最后一个梯度
//fmt.Println(endnowLadder)
//获取立创对应的梯度价格
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 {
......@@ -185,7 +192,7 @@ func (a *ZyCronService) ZyDiscount(checkGoodsId string) {
}
szlcPrice = szlcPrice*0.95 //立创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 {
ratioPrice = minPrice
}else{
......@@ -209,15 +216,17 @@ 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)) //写入缓存
_,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 != "" {
break OuterLoop; //只跑一个跳出所有循环
......
......@@ -6,9 +6,7 @@ import (
)
func main() {
str := `{"cn":{"max":"10000","price":"20"},"hk":{"max":69000,"price":138}}`
var res interface{}
fmt.Println(php2go.JSONDecode([]byte(str), &res))
tem, _ := php2go.JSONEncode(res)
fmt.Println(string(tem))
var a = []string{"3923"}
var b = 3923
fmt.Println(php2go.InArray(b,a))
}
......@@ -10,6 +10,8 @@ export GO111MODULE=on
go env -w GOPROXY=https://goproxy.cn,direct
go build -o ${Cur_Dir}"/cmd/http/http" ${Cur_Dir}"/cmd/http/http_server.go"
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"
supervisorctl restart go_sku_server_60005:*
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