Commit 21f42d26 by hcy

Merge branch 'hcy/2025.9.10-香港自营' into dev

parents b2fe0668 932a1cb0
/go.sum
/.idea/
gowatch.yml
*.exe
*.exe~
cmd.exe~
/cmd/logs/
/cmd/*.exe~
/cmd/logs
/bat/logs/
/conf/prod/*.ini
/go.mod
/logs
/mylogs
/doc/test
/vm.sh
/cmd/http
/doc/spuTest
/doc/test3
/.history
/.vscode
......@@ -4,9 +4,11 @@ import (
"flag"
"github.com/gin-gonic/gin"
"github.com/micro/go-micro/v2/web"
"github.com/syyongx/php2go"
"go_sku_server/boot"
"go_sku_server/pkg/config"
"go_sku_server/routes"
"go_sku_server/service"
)
func main() {
......@@ -16,21 +18,23 @@ func main() {
if err := boot.Boot(path); err != nil {
panic(err)
}
Self_supplier_code_str := config.Get("web.self_supplier_code").String()
service.Self_supplier_code = php2go.Explode(",", Self_supplier_code_str)
gin.SetMode(config.Get("web.mode").String())
r := routes.InitRouter()
port := config.Get("web.port").String()
//web改成micro 就是grpc,并直接注册到etcd里面
service := web.NewService(
serviceT := web.NewService(
web.Name("go.micro.api.http.search"),
web.Handler(r),
web.Address(":"+port),
)
if err := service.Init(); err != nil {
if err := serviceT.Init(); err != nil {
panic(err)
}
if err := service.Run(); err != nil {
if err := serviceT.Run(); err != nil {
panic(err)
}
......
......@@ -4,9 +4,11 @@ import (
"flag"
"github.com/gin-gonic/gin"
"github.com/micro/go-micro/v2/web"
"github.com/syyongx/php2go"
"go_sku_server/boot"
"go_sku_server/pkg/config"
"go_sku_server/routes"
"go_sku_server/service"
)
func main() {
......@@ -16,6 +18,8 @@ func main() {
if err := boot.Boot(path); err != nil {
panic(err)
}
Self_supplier_code_str := config.Get("web.self_supplier_code").String()
service.Self_supplier_code = php2go.Explode(",", Self_supplier_code_str)
gin.SetMode(config.Get("web.mode").String())
r := routes.InitRouter()
......
......@@ -3,6 +3,8 @@
port = 60014
mode = debug
cors_domain = http://bom.liexin.com
;专营自营
self_supplier_code =L0012413,L0017764,L0018319,L0018562
[message]
api_domain = http://api.ichunt.com/msg/sendMessageByAuto
......@@ -16,3 +18,5 @@ SEARCH_API_MONITOR = 6d0fa85e01a02c39347d011ae973fd21b76c6c7ce582d3ea470c6b65a31
[spu_server]
;api_domain = http://192.168.2.72:8005
api_domain = http://localhost:8005
......@@ -5,3 +5,10 @@ username = "ichunt"
password = "huntmon6699"
database = ichunt
maxPoolSize=8000
[pre_sku_mongo]
host = 192.168.1.237:27017
username = "ichunt"
password = "huntmon6699"
database = ichunt
maxPoolSize=8000
\ No newline at end of file
......@@ -2,15 +2,16 @@ package controller
import (
"encoding/json"
"github.com/gin-gonic/gin"
"github.com/gogf/gf/util/gconv"
"github.com/syyongx/php2go"
"go_sku_server/pkg/common"
"go_sku_server/pkg/gredis"
"go_sku_server/pkg/logger"
"go_sku_server/service"
"sync"
"time"
"github.com/gin-gonic/gin"
"github.com/gogf/gf/util/gconv"
"github.com/syyongx/php2go"
)
const goodsSliceCount = 10 //每多少个型号id开启一个协程
......@@ -52,11 +53,16 @@ func CommonController(ctx *gin.Context) map[string]interface{} {
return nil
}
ch := make(chan sync.Map) //管道
p := 0 //总共协程
zyGoodsId := make([]string, 0)
lyGoodsId := make([]string, 0)
var wg sync.WaitGroup
ch := make(chan sync.Map, 50) //管道
zyGoodsId := make([]string, 0, goodsSliceCount)
lyGoodsId := make([]string, 0, goodsSliceCount)
for _, goodsId := range goodsIdArr {
//if len(goodsIdArr) > 100 {
// common.Output(ctx, 1001, "查询型号ID不得超过100个", "")
// return nil
//}
if goodsId == "" {
continue
}
......@@ -65,20 +71,32 @@ func CommonController(ctx *gin.Context) map[string]interface{} {
if len(zyGoodsId) >= goodsSliceCount {
common.PrintDebugHtml(ctx, "zy增加协程1001:")
common.PrintDebugHtml(ctx, zyGoodsId)
//wg.Add(1) //协程计数一
go zyService.ZyGoodsDetail(ctx, zyGoodsId, ch)
zyGoodsId = zyGoodsId[:0:0]
p++
wg.Add(1) //协程计数一
idsToProcess := make([]string, len(zyGoodsId))
copy(idsToProcess, zyGoodsId)
go func(ctx_in *gin.Context, goodsIds_in []string, chs_in chan sync.Map) {
defer wg.Done()
zyService.ZyGoodsDetail(ctx_in, goodsIds_in, chs_in)
}(ctx, idsToProcess, ch)
zyGoodsId = zyGoodsId[:0]
}
} else { //联营
lyGoodsId = append(lyGoodsId, goodsId)
if len(lyGoodsId) >= goodsSliceCount {
common.PrintDebugHtml(ctx, "ly增加协程1002:")
common.PrintDebugHtml(ctx, lyGoodsId)
//wg.Add(1)
go lyService.LyGoodsDetail(ctx, lyGoodsId, ch)
lyGoodsId = lyGoodsId[:0:0]
p++
wg.Add(1)
idsToProcess := make([]string, len(lyGoodsId))
copy(idsToProcess, lyGoodsId)
go func(ctx_in *gin.Context, goodsIds_in []string, chs_in chan sync.Map) {
defer wg.Done()
lyService.LyGoodsDetail(ctx_in, goodsIds_in, chs_in)
}(ctx, idsToProcess, ch)
lyGoodsId = lyGoodsId[:0]
}
}
}
......@@ -86,35 +104,55 @@ func CommonController(ctx *gin.Context) map[string]interface{} {
if len(zyGoodsId) > 0 {
common.PrintDebugHtml(ctx, "zy增加协程1003:")
common.PrintDebugHtml(ctx, zyGoodsId)
//wg.Add(1) //协程计数一
go zyService.ZyGoodsDetail(ctx, zyGoodsId, ch)
p++
wg.Add(1) //协程计数一
idsToProcess := make([]string, len(zyGoodsId))
copy(idsToProcess, zyGoodsId)
go func(ctx_in *gin.Context, goodsIds_in []string, chs_in chan sync.Map) {
defer wg.Done()
zyService.ZyGoodsDetail(ctx_in, goodsIds_in, chs_in)
}(ctx, zyGoodsId, ch)
}
if len(lyGoodsId) > 0 {
common.PrintDebugHtml(ctx, "ly增加协程1004:")
common.PrintDebugHtml(ctx, zyGoodsId)
go lyService.LyGoodsDetail(ctx, lyGoodsId, ch)
p++
common.PrintDebugHtml(ctx, lyGoodsId)
wg.Add(1)
idsToProcess := make([]string, len(lyGoodsId))
copy(idsToProcess, lyGoodsId)
go func(ctx_in *gin.Context, goodsIds_in []string, chs_in chan sync.Map) {
defer wg.Done()
lyService.LyGoodsDetail(ctx_in, goodsIds_in, chs_in)
}(ctx, idsToProcess, ch)
}
// 开启一个协程,等待所有任务完成,然后关闭channel
go func() {
wg.Wait()
close(ch)
}()
//异步map最后转成map
temp := make(map[string]interface{})
for i := 0; i < p; i++ {
timeout := time.After(time.Second * 20)
for {
select {
case GoodsRes := <-ch:
case GoodsRes, ok := <-ch:
if !ok { // channel被关闭,说明所有协程都已执行完毕
return temp
}
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)
case <-timeout:
logger.Log("协程整体处理超时", "sku", 1)
return temp // 超时,返回已经收到的部分数据
}
}
return temp
}
func Synchronization(ctx *gin.Context) {
......@@ -130,7 +168,7 @@ func Hbsdata(ctx *gin.Context) {
}
/*
测试redis
测试redis
*/
func Testr(ctx *gin.Context) {
......
......@@ -46,6 +46,8 @@ type Activity struct {
CurrencyUs int `json:"currency_us"`
UseType int `json:"use_type"`
SignUrl string `json:"sign_url"`
Source string `json:"source"`
SourceList []string `json:"source_list"`
}
type ActivityItem struct {
......@@ -70,4 +72,5 @@ type ActivityCheckData struct {
Canal string
ClassId int
OrgId int
Source int
}
......@@ -243,7 +243,7 @@ func InitSkuData(sku string) (data LySku) {
isExpire := gjson.Get(sku, "is_expire").Int()
data.IsExpire = int(isExpire)
data.IsExpire = 0
//data.IsExpire = 0
hkDeliveryTime := gjson.Get(sku, "hk_delivery_time").String()
data.HkDeliveryTime = hkDeliveryTime
......
package model
import "gopkg.in/mgo.v2/bson"
// PrevSku 对应prev_sku集合的数据结构
type PrevSku struct {
ID bson.ObjectId `bson:"_id"`
SkuId int64 `bson:"sku_id"`
SpuId int64 `bson:"spu_id"`
SupplierId int64 `bson:"supplier_id"`
}
package config
type MongoDbDatabase struct {
Host string
UserName string
......@@ -9,17 +8,21 @@ type MongoDbDatabase struct {
MaxPoolSize string
}
func BuildMongoDbConfgs () map[string]MongoDbDatabase{
func BuildMongoDbConfgs() map[string]MongoDbDatabase {
return map[string]MongoDbDatabase{
"default" : {
Host:Get("mongo.host").String(),
UserName:Get("mongo.username").String(),
Password:Get("mongo.password").String(),
Database:Get("mongo.database").String(),
MaxPoolSize:Get("mongo.maxPoolSize").String(),
"default": {
Host: Get("mongo.host").String(),
UserName: Get("mongo.username").String(),
Password: Get("mongo.password").String(),
Database: Get("mongo.database").String(),
MaxPoolSize: Get("mongo.maxPoolSize").String(),
},
"pre_sku": {
Host: Get("pre_sku_mongo.host").String(),
UserName: Get("pre_sku_mongo.username").String(),
Password: Get("pre_sku_mongo.password").String(),
Database: Get("pre_sku_mongo.database").String(),
MaxPoolSize: Get("pre_sku_mongo.maxPoolSize").String(),
},
}
}
......@@ -6,42 +6,48 @@ type RedisDatabase struct {
Database string
MaxIdle int
MaxActive int
IdleTimeout int
MaxAIdleTimeoutctive string
Prefix string
}
//多数据库配置
// 多数据库配置
func BuildRedisConfigs() (RedisDatabaseMap map[string]RedisDatabase) {
redisReadMaxIdle,_ := Get("default_redis_read.max_idle").Int()
redisReadMaxActive,_ := Get("default_redis_read.max_active").Int()
redisWriteMaxIdle,_ := Get("default_redis_write.max_idle").Int()
redisWriteMaxActive,_ := Get("default_redis_write.max_active").Int()
redisSpuMaxIdle,_ := Get("default_redis_spu.max_idle").Int()
redisSpuMaxActive,_ := Get("default_redis_spu.max_active").Int()
redisReadMaxIdle, _ := Get("default_redis_read.max_idle").Int()
redisReadMaxActive, _ := Get("default_redis_read.max_active").Int()
redisWriteMaxIdle, _ := Get("default_redis_write.max_idle").Int()
redisWriteMaxActive, _ := Get("default_redis_write.max_active").Int()
redisSpuMaxIdle, _ := Get("default_redis_spu.max_idle").Int()
redisSpuMaxActive, _ := Get("default_redis_spu.max_active").Int()
redisIdleTimeout, _ := Get("default_redis_read.idle_timeout").Int()
return map[string]RedisDatabase{
"search_r": {
Host: Get("default_redis_read.host").String(),
Password: Get("default_redis_read.password").String(),
MaxIdle: redisReadMaxIdle,
MaxActive: redisReadMaxActive,
IdleTimeout: redisIdleTimeout,
},
"default_r": {
Host: Get("default_redis_read.host").String(),
Password: Get("default_redis_read.password").String(),
MaxIdle: redisReadMaxIdle,
MaxActive: redisReadMaxActive,
IdleTimeout: redisIdleTimeout,
},
"search_w": {
Host: Get("default_redis_write.host").String(),
Password: Get("default_redis_write.password").String(),
MaxIdle: redisWriteMaxIdle,
MaxActive: redisWriteMaxActive,
IdleTimeout: redisIdleTimeout,
},
"spu": {
Host: Get("default_redis_spu.host").String(),
Password: Get("default_redis_spu.password").String(),
MaxIdle: redisSpuMaxIdle,
MaxActive: redisSpuMaxActive,
IdleTimeout: redisIdleTimeout,
},
}
}
......@@ -2,9 +2,10 @@ package gredis
import (
"fmt"
"github.com/gomodule/redigo/redis"
"go_sku_server/pkg/config"
"time"
"github.com/gomodule/redigo/redis"
)
type ichuntRedis struct {
......@@ -32,7 +33,7 @@ func Setup() (err error) {
return nil
}
//格式化成字符串
// 格式化成字符串
func String(a interface{}, err error) (string, error) {
return redis.String(a, err)
}
......@@ -43,8 +44,13 @@ func getConn(writeHost, password string, maxIdle, maxActive int) (pool *redis.Po
pool = &redis.Pool{
MaxIdle: maxIdle,
MaxActive: maxActive,
IdleTimeout: 240 * time.Second,
Dial: func() (redis.Conn, error) {
c, err := redis.Dial("tcp", writeHost)
c, err := redis.Dial("tcp", writeHost,
redis.DialConnectTimeout(2*time.Second),
redis.DialReadTimeout(2*time.Second),
redis.DialWriteTimeout(2*time.Second),
)
if err != nil {
return nil, err
}
......@@ -70,6 +76,7 @@ func getConn(writeHost, password string, maxIdle, maxActive int) (pool *redis.Po
@param hkey string 集合键值,如sku
@param targetIds string 查询的id 切片
eg:
redisConn := gredis.Conn("search_r")
skuArr := gredis.HgetPi(&redisConn,"Self_SelfGoods",[]string{"1001","10005"})
*/
......@@ -86,7 +93,8 @@ func Hmget(redisCon string, hkey string, targetIds []string) map[string]string {
goods_id := targetIds[0]
info, err := String(redisConn.Do("HGET", hkey, goods_id))
if err != nil && err != redis.ErrNil {
fmt.Print("连接redis错误991:", err)
fmt.Printf("redis HGET error for key %s, field %s: %v\n", hkey, goods_id, err)
return nil
}
if info == "" {
skuArr[goods_id] = ""
......@@ -102,9 +110,14 @@ func Hmget(redisCon string, hkey string, targetIds []string) map[string]string {
}
res1, err1 := redisConn.Do("hmget", param...)
reply, _ := redis.Strings(res1, err1)
if err1 != nil {
fmt.Println(err1)
fmt.Printf("redis HMGET error for key %s: %v\n", hkey, err1)
return nil
}
reply, err := redis.Strings(res1, err1)
if err != nil {
fmt.Printf("redis Strings conversion error after HMGET for key %s: %v\n", hkey, err)
return nil
}
for k, goodsInfo := range reply {
......@@ -120,6 +133,7 @@ func Hmget(redisCon string, hkey string, targetIds []string) map[string]string {
@param hkey string 集合键值,如sku
@param targetIds string 查询的id 切片
eg:
redisConn := gredis.Conn("search_r")
skuArr := gredis.HgetPi(&redisConn,"Self_SelfGoods",[]string{"1001","10005"})
*/
......@@ -131,8 +145,9 @@ func HgetPi(redisCon string, hkey string, targetIds []string) map[string]string
if len(targetIds) == 1 {
oneId := targetIds[0]
info, err := String(redisConn.Do("HGET", hkey, oneId))
if err != nil {
fmt.Print(err)
if err != nil && err != redis.ErrNil {
fmt.Printf("redis HGET error for key %s, field %s: %v\n", hkey, oneId, err)
return nil
}
if info == "" {
skuArr[oneId] = ""
......@@ -148,7 +163,11 @@ func HgetPi(redisCon string, hkey string, targetIds []string) map[string]string
redisConn.Flush()
for _, goods_id := range targetIds {
info, _ := redisConn.Receive()
info, err := redisConn.Receive()
if err != nil {
fmt.Printf("redis Receive error for key %s: %v\n", hkey, err)
return nil
}
if info == nil {
skuArr[goods_id] = ""
continue
......@@ -164,6 +183,7 @@ func HgetPi(redisCon string, hkey string, targetIds []string) map[string]string
@param hkey string 集合键值,如sku
@param targetIds string 查询的id 切片
eg:
redisConn := gredis.Conn("search_r")
skuArr := gredis.HgetPi(&redisConn,"Self_SelfGoods",[]string{"1001","10005"})
*/
......@@ -174,8 +194,9 @@ func HgetPi2(redisCon string, hkey string, targetIds []string) map[string]string
skuArr := make(map[string]string, 0)
for _, goods_id := range targetIds {
info, err := String(redisConn.Do("HGET", hkey, goods_id))
if err != nil {
fmt.Print("连接redis错误991:", err)
if err != nil && err != redis.ErrNil {
fmt.Printf("redis HGET error in HgetPi2 for key %s, field %s: %v\n", hkey, goods_id, err)
return nil
}
if info == "" {
skuArr[goods_id] = ""
......
......@@ -49,74 +49,6 @@ func (as *ActivityService) GetActivityData(checkData model.ActivityCheckData) (p
return
}
// 获取满赠活动信息
func (as *ActivityService) GetGiftActivity(checkData model.ActivityCheckData, activities []model.Activity) (giftActivity model.GiftActivity) {
var hasActivity bool
nowTimestamp := int(time.Now().Unix())
for _, activity := range activities {
if activity.Status != 1 {
continue
}
//判断时间是否过期
if activity.StartTime > nowTimestamp || activity.EndTime < nowTimestamp {
continue
}
//如果是整个供应商搞活动,则直接返回系数
if activity.EntireSupplierActivity {
hasActivity = true
goto INFO
}
//判断是否是排除的sku或者品牌,如果是的话,直接返回没活动
if as.CheckExcludeSku(checkData.GoodsId, activity) || as.CheckExcludeBrand(checkData.BrandId, activity) {
continue
}
//判断是否是搞活动的品牌
if as.CheckBrand(checkData.BrandId, activity) {
hasActivity = true
goto INFO
}
//如果是专卖,则要去判断canal,如果是自营,则去判断分类
if checkData.SupplierId == 17 {
if as.CheckCanal(checkData.Canal, activity) {
hasActivity = true
goto INFO
}
} else {
if as.CheckClass(checkData.ClassId, activity) {
hasActivity = true
goto INFO
}
}
INFO:
if hasActivity {
for key, item := range activity.ItemList {
activity.ItemList[key].Content = "订单满" + gconv.String(item.Amount) + "元赠" +
gconv.String(item.ItemName) + "X" + gconv.String(item.Num) + "" + item.Remark
}
giftActivity.ActivityName = activity.ActivityName
giftActivity.ActivityId = activity.ActivityId
giftActivity = model.GiftActivity{
CanAdminOrder: activity.CanAdminOrder,
ItemList: activity.ItemList,
ActivityCommon: model.ActivityCommon{
HasActivity: hasActivity,
ActivityId: activity.ActivityId,
ActivityName: activity.ActivityName,
AllowCoupon: activity.AllowCoupon,
UserScope: activity.UserScope,
},
}
break
}
}
return
}
func (as *ActivityService) GetPriceActivity(checkData model.ActivityCheckData, activities []model.Activity) (priceActivity model.PriceActivity) {
redisConn := gredis.Conn("default_r")
defer redisConn.Close()
......@@ -140,6 +72,10 @@ func (as *ActivityService) GetPriceActivity(checkData model.ActivityCheckData, a
if as.CheckExcludeSku(checkData.GoodsId, activity) || as.CheckExcludeStandardBrand(checkData.StandardBrandId, activity) {
continue
}
//checkSource
if !as.CheckSource(checkData.Source, activity) {
continue
}
//如果是专卖,则要去判断canal,如果是自营,则去判断分类
if checkData.SupplierId == 17 {
......@@ -175,8 +111,6 @@ func (as *ActivityService) GetPriceActivity(checkData model.ActivityCheckData, a
} else if checkData.SupplierId == 10000 {
//自营活动特殊判断
//fmt.Println(activity.ClassIds)
//fmt.Println(activity.UseType)
if activity.ClassIds != "" {
if !as.CheckClass(checkData.ClassId, activity) {
continue
......@@ -275,10 +209,7 @@ func (as *ActivityService) CheckExcludeBrand(brandId int, activity model.Activit
activity.ExcludeBrandIdList = strings.Split(activity.ExcludeBrandIds, ",")
brandIdStr := gconv.String(brandId)
//如果存在于有活动价的品牌,就是有折扣活动了
if php2go.InArray(brandIdStr, activity.ExcludeBrandIdList) {
return true
}
return false
return php2go.InArray(brandIdStr, activity.ExcludeBrandIdList)
}
// 检查是否属于被排除的标准品牌
......@@ -290,10 +221,7 @@ func (as *ActivityService) CheckExcludeStandardBrand(standardBrandId int, activi
activity.ExcludeStandardBrandIdList = strings.Split(activity.ExcludeStandardBrandIds, ",")
standardBrandIdStr := gconv.String(standardBrandId)
//如果存在于有活动价的品牌,就是有折扣活动了
if php2go.InArray(standardBrandIdStr, activity.ExcludeStandardBrandIdList) {
return true
}
return false
return php2go.InArray(standardBrandIdStr, activity.ExcludeStandardBrandIdList)
}
// 检查是否属于被排除的sku
......@@ -304,10 +232,7 @@ func (as *ActivityService) CheckExcludeSku(skuId string, activity model.Activity
//先去判断品牌
activity.ExcludeSkuIdList = strings.Split(activity.ExcludeSkuIds, ",")
//如果存在于有活动价的品牌,就是有折扣活动了
if php2go.InArray(skuId, activity.ExcludeSkuIdList) {
return true
}
return false
return php2go.InArray(skuId, activity.ExcludeSkuIdList)
}
// 检查是否属于活动分类(只有自营需要判断)
......@@ -319,10 +244,7 @@ func (as *ActivityService) CheckClass(classId int, activity model.Activity) bool
activity.ClassIdList = strings.Split(activity.ClassIds, ",")
classIdStr := gconv.String(classId)
//如果存在于有活动价的品牌,就是有折扣活动了
if php2go.InArray(classIdStr, activity.ClassIdList) {
return true
}
return false
return php2go.InArray(classIdStr, activity.ClassIdList)
}
// 检查是否属于活动品牌
......@@ -334,10 +256,7 @@ func (as *ActivityService) CheckBrand(brandId int, activity model.Activity) bool
activity.BrandIdList = strings.Split(activity.BrandIds, ",")
brandIdStr := gconv.String(brandId)
//如果存在于有活动价的品牌,就是有折扣活动了
if php2go.InArray(brandIdStr, activity.BrandIdList) {
return true
}
return false
return php2go.InArray(brandIdStr, activity.BrandIdList)
}
// 检测是否属于活动标准品牌
......@@ -349,10 +268,7 @@ func (as *ActivityService) CheckStandardBrand(standardBrandId int, activity mode
activity.StandardBrandIdList = strings.Split(activity.StandardBrandIds, ",")
standardBrandIdStr := gconv.String(standardBrandId)
//如果存在于有活动价的品牌,就是有折扣活动了
if php2go.InArray(standardBrandIdStr, activity.StandardBrandIdList) {
return true
}
return false
return php2go.InArray(standardBrandIdStr, activity.StandardBrandIdList)
}
// 检查是否属于供应商渠道
......@@ -363,8 +279,23 @@ func (as *ActivityService) CheckCanal(canal string, activity model.Activity) boo
//先去判断品牌
activity.CanalList = strings.Split(activity.Canals, ",")
//如果存在于有活动价的品牌,就是有折扣活动了
if php2go.InArray(canal, activity.CanalList) {
return php2go.InArray(canal, activity.CanalList)
}
// 检查来源是否有配置,有配置的话是否符合
func (as *ActivityService) CheckSource(source int, activity model.Activity) bool {
if source == 0 {
source = 1
}
//如果source为空,则默认为所有来源
if activity.Source == "" {
return true
}
return false
//先去判断品牌
activity.SourceList = strings.Split(activity.Source, ",")
sourceStr := gconv.String(source)
// fmt.Println(sourceStr)
// fmt.Println(activity.SourceList)
//如果存在于有活动价的品牌,就是有折扣活动了
return php2go.InArray(sourceStr, activity.SourceList)
}
......@@ -2,15 +2,17 @@ package service
import (
"encoding/json"
"github.com/iancoleman/orderedmap"
"go_sku_server/pkg/logger"
"go_sku_server/pkg/mongo"
"strconv"
"strings"
"github.com/iancoleman/orderedmap"
"gopkg.in/mgo.v2"
"gopkg.in/mgo.v2/bson"
"strconv"
)
//获取Spu的属性
// 获取Spu的属性
func (ls *LyService) GetSpuAttr(spuId string) (attrsResult interface{}) {
var spuAttr SpuAttr
var attrsList []interface{}
......@@ -26,7 +28,17 @@ func (ls *LyService) GetSpuAttr(spuId string) (attrsResult interface{}) {
//fmt.Println(spuAttr.AttrsExtend)
//如果有attrs_extend,就去取attrs_extend
if len(spuAttr.AttrsExtend) != 0 {
return spuAttr.AttrsExtend
//便利AttrsExtend的值
for _, value := range spuAttr.AttrsExtend {
data := make(map[string]interface{})
data["attr_name"] = value.AttrName
//€符号全部替换为逗号
data["attr_value"] = strings.ReplaceAll(value.AttrValue, "€", ",")
data["attr_unit"] = value.AttrUnit
attrsList = append(attrsList, data)
attrsResult = attrsList
}
return attrsResult
} else if spuAttr.Attrs != "" {
o := orderedmap.New()
err := json.Unmarshal([]byte(spuAttr.Attrs), &o)
......
......@@ -8,6 +8,7 @@ import (
"go_sku_server/pkg/mongo"
"go_sku_server/service/sorter"
"sort"
"strconv"
"sync"
"gopkg.in/mgo.v2"
......@@ -38,7 +39,10 @@ type Power struct {
func (ls *LyService) LyGoodsDetail(ctx *gin.Context, goodsIds []string, ch chan sync.Map) {
redisConn := gredis.Conn("search_r")
redisConnSpu := gredis.Conn("spu")
// 连接prev_sku MongoDB
prevSkuMongo := mongo.Conn("pre_sku")
defer func() {
prevSkuMongo.Close()
redisConn.Close()
redisConnSpu.Close()
}()
......@@ -63,14 +67,40 @@ func (ls *LyService) LyGoodsDetail(ctx *gin.Context, goodsIds []string, ch chan
GoodsRes := sync.Map{}
for goodsId, skuStr := range skuArr {
//初始化有序map,拼接data数据,就是从redis取出初始数据
sku := model.InitSkuData(skuStr)
var spu string
if skuStr == "" {
// 如果redis中找不到sku数据,尝试从prev_sku MongoDB中查找
skuId, err := strconv.ParseInt(goodsId, 10, 64)
if err != nil {
GoodsRes.Store(goodsId, false)
continue
}
//初始化有序map,拼接data数据,就是从redis取出初始数据
sku := model.InitSkuData(skuStr)
var prevSku model.PrevSku
err = prevSkuMongo.DB("ichunt").C("prev_sku").Find(bson.M{"sku_id": skuId}).One(&prevSku)
if err != nil {
// 如果在prev_sku中也找不到,则保持默认值
GoodsRes.Store(goodsId, false)
continue
}
// 根据找到的spu_id去spu的redis中查找
spuIdStr := strconv.FormatInt(prevSku.SpuId, 10)
spuStr, _ := redis.String(redisConnSpu.Do("HGET", "spu", spuIdStr))
if spuStr == "" {
// 如果spu缓存也没有,保持默认值
GoodsRes.Store(goodsId, false)
continue
}
sku.SupplierId = prevSku.SupplierId
sku.SpuId = spuIdStr
spu = spuStr
} else {
spu = spuList[sku.SpuId]
}
sku.GoodsId = goodsId
spu := spuList[sku.SpuId]
//读取包装字段的缓存(分别是DGK,avnet,mro)
if sku.SupplierId == 7 || sku.SupplierId == 13 || sku.SupplierId == 1688 || sku.SupplierId == 17 {
//sku_raw_map哪里写入(成意写的)
......@@ -79,12 +109,12 @@ func (ls *LyService) LyGoodsDetail(ctx *gin.Context, goodsIds []string, ch chan
}
sku = ls.GetGoodsImages(sku, spu)
sku = ls.GetPdf(sku, spu)
//用spuInfo补全信息
sku = ls.CombineSup(sku, spu)
// 2023.11.20 DGK商品的包装若为“Tape & Reel (TR)”,则递增量=起订量
if sku.SupplierId == 7 && sku.Packing == "Tape & Reel (TR)" {
sku.Multiple = sku.Moq
}
//获取商品名称
//1688就是mro的sku spuName和GoodsName不是一个东西,不能公用
if sku.GoodsName != "" && (sku.SupplierId == 1688 || sku.OrgId == 3) {
......@@ -182,16 +212,13 @@ func (ls *LyService) LyGoodsDetail(ctx *gin.Context, goodsIds []string, ch chan
//case为0是为了兼容价格体系之前的价格
case 0:
case 1:
//如果是寄售的,也不走价格体系
if sku.Source != 12 {
//这里猎芯和华云都是走同一套的价格体系了
//这里猎芯和寄售都是走同一套的价格体系了
//获取系数和价格
sku = ls.GetCoefficientAndPrice(sku)
//获取自定义价格后的阶梯价
customPriceService := CustomPrice{}
sku.CustomPriceList, _ = customPriceService.getCustomPriceList(sku)
sku = priceService.GetActivityPrice(sku)
}
case 3:
//如果是寄售的,不走价格体系
if sku.Source == 12 {
......@@ -240,6 +267,11 @@ func (ls *LyService) LyGoodsDetail(ctx *gin.Context, goodsIds []string, ch chan
sku.HkDeliveryTime = delivery["hk_delivery"]
}
//只要是寄售的,大陆交期都是0.5工作日
if sku.Source == 12 {
sku.CnDeliveryTime = "0.5工作日"
}
}
//处理是否可以购买
......@@ -255,8 +287,8 @@ func (ls *LyService) LyGoodsDetail(ctx *gin.Context, goodsIds []string, ch chan
//判断是否可以购买
sku.IsBuy = ls.GetIsBuy(sku)
if sku.IsBuy ==0 && sku.OrgId != 1 {
sku.AcType = 0;
if sku.IsBuy == 0 && sku.OrgId != 1 {
sku.AcType = 0
}
sku.Stock = ls.GetStock(sku)
......@@ -268,8 +300,6 @@ func (ls *LyService) LyGoodsDetail(ctx *gin.Context, goodsIds []string, ch chan
//获取关税以及价格转换
sku = ls.GetTariffAndPrice(sku)
//用spuInfo补全信息
sku = ls.CombineSup(sku, spu)
//最后一步,将sku的全部信息放到有序map里面
GoodsRes.Store(goodsId, sku)
//(*goodsRes)[goodsId] = A
......@@ -290,6 +320,7 @@ func (ls *LyService) GetActivity(sku model.LySku) model.LySku {
GoodsName: sku.GoodsName,
ClassId: sku.ClassID2,
OrgId: sku.OrgId,
Source: sku.Source,
}
var activityService ActivityService
priceActivity, giftActivity := activityService.GetActivityData(checkData)
......
......@@ -19,6 +19,8 @@ import (
_ "gopkg.in/mgo.v2/bson"
)
var Self_supplier_code []string //所有自营的编码
// 获取图片信息
func (ls *LyService) GetGoodsImages(sku model.LySku, spu string) model.LySku {
//图片
......@@ -262,7 +264,7 @@ func (ls *LyService) GetStock(sku model.LySku) (stock int64) {
}
//这里还有一个逻辑
//如果是寄售的数据(source=12),获取的库存还要减去锁库的库存
if sku.Source == 12 {
if sku.Source == 12 || php2go.InArray(sku.Canal, Self_supplier_code) {
//获取锁库库存
redisCon := gredis.Conn("search_r")
stockStr, _ := redis.String(redisCon.Do("HGET", "sku_lock_stock", sku.GoodsId))
......
......@@ -60,14 +60,13 @@ func (ps *PriceService) GenerateLadderPrice(sku model.LySku) model.LySku {
//拿出里面的所有排序
priceRatioSortMap := gjson.Get(priceRatioCache, ratioDataKey).Map()
var sortNumbers []int
for sortNumberString, _ := range priceRatioSortMap {
for sortNumberString := range priceRatioSortMap {
sortNumber, _ := strconv.Atoi(sortNumberString)
sortNumbers = append(sortNumbers, sortNumber)
}
//然后确定排序
sortNumbers = sorter.IntSliceSortDesc(sortNumbers)
//确定排序以后,就可以进行按排序(从大到小)取系数
outerLoop:
for _, sortNumber := range sortNumbers {
priceRatioSort = sortNumber
priceRatioList = nil
......@@ -83,15 +82,15 @@ func (ps *PriceService) GenerateLadderPrice(sku model.LySku) model.LySku {
}
//是否满足特定条件的判断
var hasSpecialCheck = false
conditionsMet := true
//判断是否有符合的商品名称
goodsNames := gjson.Get(priceRatioCache, "goods_name."+sortString).String()
if goodsNames != "" {
hasSpecialCheck = true
goodsNameList := strings.Split(goodsNames, "@€@")
//找到有对应的商品名称,那么优先级肯定是最高的了
if php2go.InArray(sku.GoodsName, goodsNameList) {
foundRatio = true
break
if !php2go.InArray(sku.GoodsName, goodsNameList) {
conditionsMet = false
}
}
......@@ -100,12 +99,20 @@ func (ps *PriceService) GenerateLadderPrice(sku model.LySku) model.LySku {
if brandIds != "" {
hasSpecialCheck = true
standardBrandIdList := strings.Split(brandIds, ",")
//fmt.Println(standardBrandIdList)
standardBrandId := strconv.Itoa(sku.StandardBrand.StandardBrandId)
//找到有对应的品牌,那么优先级肯定是最高的了
if php2go.InArray(standardBrandId, standardBrandIdList) {
foundRatio = true
break
if !php2go.InArray(standardBrandId, standardBrandIdList) {
conditionsMet = false
}
}
//判断是否有符合的分类ID
classIds := gjson.Get(priceRatioCache, "class_ids."+sortString).String()
if classIds != "" {
hasSpecialCheck = true
classIdList := strings.Split(classIds, ",")
classId := strconv.Itoa(sku.ClassID2)
if !php2go.InArray(classId, classIdList) {
conditionsMet = false
}
}
......@@ -113,11 +120,9 @@ func (ps *PriceService) GenerateLadderPrice(sku model.LySku) model.LySku {
eccns := gjson.Get(priceRatioCache, "eccn."+sortString).String()
if eccns != "" {
hasSpecialCheck = true
eccnMatched := false
eccnList := strings.Split(eccns, ",")
//找到有对应的eccn,那么优先级肯定是最高的了
for _, eccn := range eccnList {
//判断是否有百分号匹配
//如果是纯%,那就是不对的,要跳过
if strings.Replace(eccn, "%", "", 10) == "" {
continue
}
......@@ -127,36 +132,44 @@ func (ps *PriceService) GenerateLadderPrice(sku model.LySku) model.LySku {
if hasPrefix && hasSuffix {
eccn = strings.Replace(eccn, "%", "", 10)
if strings.Contains(sku.Eccn, eccn) {
foundRatio = true
break outerLoop
}
eccnMatched = true
break
}
if hasPrefix && !hasSuffix {
} else if hasPrefix {
eccn = strings.Replace(eccn, "%", "", 10)
if strings.HasSuffix(sku.Eccn, eccn) {
foundRatio = true
break outerLoop
}
eccnMatched = true
break
}
if !hasPrefix && hasSuffix {
} else if hasSuffix {
eccn = strings.Replace(eccn, "%", "", 10)
if strings.HasPrefix(sku.Eccn, eccn) {
foundRatio = true
break outerLoop
eccnMatched = true
break
}
}
} else {
if sku.Eccn == eccn {
foundRatio = true
break outerLoop
eccnMatched = true
break
}
}
}
if !eccnMatched {
conditionsMet = false
}
//如果没有设置品牌和商品,那么这个优先级高的就会覆盖下面的了,不需要再去判断品牌和型号了
}
if hasSpecialCheck {
if conditionsMet {
foundRatio = true
break
} else {
continue
}
}
// 如果没有设置任何特殊条件,则默认匹配
foundRatio = true
break
}
......@@ -534,14 +547,13 @@ func (ps PriceService) GetPriceRatio(sku model.LySku) (model.LySku, []model.Pric
//拿出里面的所有排序
priceRatioSortMap := gjson.Get(priceRatioCache, "ladder_price").Map()
var sortNumbers []int
for sortNumberString, _ := range priceRatioSortMap {
for sortNumberString := range priceRatioSortMap {
sortNumber, _ := strconv.Atoi(sortNumberString)
sortNumbers = append(sortNumbers, sortNumber)
}
//然后确定排序
sortNumbers = sorter.IntSliceSortDesc(sortNumbers)
//确定排序以后,就可以进行按排序(从大到小)取系数
outerLoop:
for _, sortNumber := range sortNumbers {
priceRatioSort = sortNumber
priceRatioList = nil
......@@ -555,16 +567,15 @@ func (ps PriceService) GetPriceRatio(sku model.LySku) (model.LySku, []model.Pric
}
var hasSpecialCheck = false
conditionsMet := true
//判断是否有符合的商品名称
goodsNames := gjson.Get(priceRatioCache, "goods_name."+sortString).String()
if goodsNames != "" {
hasSpecialCheck = true
goodsNameList := strings.Split(goodsNames, "@€@")
//找到有对应的商品名称,那么优先级肯定是最高的了
if php2go.InArray(sku.GoodsName, goodsNameList) {
foundRatio = true
break
if !php2go.InArray(sku.GoodsName, goodsNameList) {
conditionsMet = false
}
}
......@@ -574,10 +585,19 @@ func (ps PriceService) GetPriceRatio(sku model.LySku) (model.LySku, []model.Pric
hasSpecialCheck = true
standardBrandIdList := strings.Split(brandIds, ",")
standardBrandId := strconv.Itoa(sku.StandardBrand.StandardBrandId)
//找到有对应的品牌,那么优先级肯定是最高的了
if php2go.InArray(standardBrandId, standardBrandIdList) {
foundRatio = true
break
if !php2go.InArray(standardBrandId, standardBrandIdList) {
conditionsMet = false
}
}
//判断是否有符合的分类ID
classIds := gjson.Get(priceRatioCache, "class_ids."+sortString).String()
if classIds != "" {
hasSpecialCheck = true
classIdList := strings.Split(classIds, ",")
classId := strconv.Itoa(sku.ClassID2)
if !php2go.InArray(classId, classIdList) {
conditionsMet = false
}
}
......@@ -585,11 +605,9 @@ func (ps PriceService) GetPriceRatio(sku model.LySku) (model.LySku, []model.Pric
eccns := gjson.Get(priceRatioCache, "eccn."+sortString).String()
if eccns != "" {
hasSpecialCheck = true
eccnMatched := false
eccnList := strings.Split(eccns, ",")
//找到有对应的eccn,那么优先级肯定是最高的了
for _, eccn := range eccnList {
//判断是否有百分号匹配
//如果是纯%,那就是不对的,要跳过
if strings.Replace(eccn, "%", "", 10) == "" {
continue
}
......@@ -599,36 +617,44 @@ func (ps PriceService) GetPriceRatio(sku model.LySku) (model.LySku, []model.Pric
if hasPrefix && hasSuffix {
eccn = strings.Replace(eccn, "%", "", 10)
if strings.Contains(sku.Eccn, eccn) {
foundRatio = true
break outerLoop
}
eccnMatched = true
break
}
if hasPrefix && !hasSuffix {
} else if hasPrefix {
eccn = strings.Replace(eccn, "%", "", 10)
if strings.HasSuffix(sku.Eccn, eccn) {
foundRatio = true
break outerLoop
}
eccnMatched = true
break
}
if !hasPrefix && hasSuffix {
} else if hasSuffix {
eccn = strings.Replace(eccn, "%", "", 10)
if strings.HasPrefix(sku.Eccn, eccn) {
foundRatio = true
break outerLoop
eccnMatched = true
break
}
}
} else {
if sku.Eccn == eccn {
foundRatio = true
break outerLoop
eccnMatched = true
break
}
}
}
if !eccnMatched {
conditionsMet = false
}
//如果没有设置品牌和商品,那么这个优先级高的就会覆盖下面的了,不需要再去判断品牌和型号了
}
if hasSpecialCheck {
if conditionsMet {
foundRatio = true
break
} else {
continue
}
}
// 如果没有设置任何特殊条件,则默认匹配
foundRatio = true
break
}
......
package service
import (
"github.com/gomodule/redigo/redis"
"github.com/syyongx/php2go"
"github.com/tidwall/gjson"
"go_sku_server/model"
"go_sku_server/pkg/gredis"
"go_sku_server/pkg/vars"
"github.com/gomodule/redigo/redis"
"github.com/syyongx/php2go"
"github.com/tidwall/gjson"
)
//标签相关服务,包括goods_label
......@@ -14,10 +15,10 @@ import (
type TagsService struct {
}
//当天发货标签
// 当天发货标签
const TagZiyingSku = 4
//获取Spu的属性
// 获取Spu的属性
func (ts *TagsService) GetTags(skuId string, selfSupplierType int64) (goodsTags model.GoodsTag) {
redisCon := gredis.Conn("default_r")
defer redisCon.Close()
......@@ -52,13 +53,13 @@ func (ts *TagsService) GetTags(skuId string, selfSupplierType int64) (goodsTags
goodsTags.GoodsLabelName = vars.GoodsTags[TagZiyingSku]
}
}
goodsTags.GoodsTagNames = tagNames
goodsTags.GoodsTag = tags
return goodsTags
}
//获取联营tags
// 获取联营tags
func (ts *TagsService) GetLyTags(sku model.LySku) (goodsTags model.GoodsTag) {
skuId := sku.GoodsId
redisCon := gredis.Conn("default_r")
......@@ -83,14 +84,52 @@ func (ts *TagsService) GetLyTags(sku model.LySku) (goodsTags model.GoodsTag) {
for _, cname := range customerTagArr {
//如果是爱智的话,去掉可议价标签
if sku.OrgId ==3 && cname == "可议价" {
if sku.OrgId == 3 && cname == "可议价" {
continue
}
tagNames = append(tagNames, cname)
}
}
}
if sku.Source == 12 {
if !php2go.InArray("当天发货", tagNames) {
tagNames = append(tagNames, "当天发货")
}
}
//还要判断source的标签
sourceTagsStr, _ := redis.String(redisCon.Do("HGET", "goods_source_tags", sku.Source))
if sourceTagsStr != "" {
systemTags := gjson.Get(sourceTagsStr, "system_tags").Array()
for _, tag := range systemTags {
tagNames = append(tagNames, tag.String())
}
}
//判断goods_label的标签
labelTagsStr, _ := redis.String(redisCon.Do("HGET", "goods_label_tags", sku.GoodsTag.GoodsLabel))
if labelTagsStr != "" {
labelTags := gjson.Get(labelTagsStr, "system_tags").Array()
for _, tag := range labelTags {
tagNames = append(tagNames, tag.String())
}
}
//去重tagNames
tagNames = removeDuplicateString(tagNames)
goodsTags.GoodsTagNames = tagNames
goodsTags.GoodsTag = tags
return goodsTags
}
func removeDuplicateString(s []string) []string {
result := []string{}
temp := map[string]struct{}{}
for _, item := range s {
if _, ok := temp[item]; !ok {
temp[item] = struct{}{}
result = append(result, item)
}
}
return result
}
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