Skip to content
Toggle navigation
P
Projects
G
Groups
S
Snippets
Help
黄成意
/
go_sku_server
This project
Loading...
Sign in
Toggle navigation
Go to a project
Project
Repository
Issues
0
Merge Requests
0
Pipelines
Wiki
Snippets
Settings
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Commit
3a0ddd74
authored
Nov 18, 2020
by
mushishixian
Browse files
Options
_('Browse Files')
Download
Plain Diff
fix
parents
2ee198aa
a6e892cc
Hide whitespace changes
Inline
Side-by-side
Showing
11 changed files
with
205 additions
and
26 deletions
conf/dev/mongo.ini
conf/dev/redis.ini
controller/sku_controller.go
doc/test/r2.go
doc/test/r3.go
model/goods.go
pkg/gredis/redis.go
service/service_ly.go
service/service_ly_common.go
service/service_zy.go
update.sh
conf/dev/mongo.ini
View file @
3a0ddd74
...
...
@@ -4,4 +4,4 @@ host = 192.168.1.237:27017
username
=
"ichunt"
password
=
"huntmon6699"
database
=
ichunt
maxPoolSize
=
100
\ No newline at end of file
maxPoolSize
=
2000
\ No newline at end of file
conf/dev/redis.ini
View file @
3a0ddd74
...
...
@@ -2,15 +2,15 @@
[default_redis_read]
host
=
192.168.1.235:6379
password
=
icDb29mLy2s
max_idle
=
5
000
max_active
=
3
000
max_idle
=
20
000
max_active
=
20
000
idle_timeout
=
20
[default_redis_write]
host
=
192.168.1.235:6379
password
=
icDb29mLy2s
max_idle
=
5
000
max_active
=
3
000
max_idle
=
20
000
max_active
=
20
000
idle_timeout
=
20
;存放redis所有键
...
...
controller/sku_controller.go
View file @
3a0ddd74
...
...
@@ -49,13 +49,14 @@ func Synchronization(ctx *gin.Context) {
zyGoodsId
:=
make
([]
string
,
0
)
lyGoodsId
:=
make
([]
string
,
0
)
for
_
,
goods_id
:=
range
goodsIdArr
{
if
goods_id
==
""
{
continue
;
}
if
len
(
goods_id
)
<
19
{
//自营
zyGoodsId
=
append
(
zyGoodsId
,
goods_id
)
if
len
(
zyGoodsId
)
>=
goods_slice_count
{
common
.
PrintDebugHtml
(
ctx
,
"zy增加协程:"
)
common
.
PrintDebugHtml
(
ctx
,
"zy增加协程1001:"
)
common
.
PrintDebugHtml
(
ctx
,
zyGoodsId
)
wg
.
Add
(
1
)
//协程计数一
go
zyService
.
ZyGoodsDetail
(
ctx
,
zyGoodsId
,
&
GoodsRes
,
&
wg
)
zyGoodsId
=
zyGoodsId
[
:
0
:
0
]
...
...
@@ -63,7 +64,7 @@ func Synchronization(ctx *gin.Context) {
}
else
{
//联营
lyGoodsId
=
append
(
lyGoodsId
,
goods_id
)
if
len
(
lyGoodsId
)
>=
goods_slice_count
{
common
.
PrintDebugHtml
(
ctx
,
"ly增加协程:"
)
common
.
PrintDebugHtml
(
ctx
,
"ly增加协程
1002
:"
)
common
.
PrintDebugHtml
(
ctx
,
zyGoodsId
)
wg
.
Add
(
1
)
go
lyService
.
LyGoodsDetail
(
ctx
,
lyGoodsId
,
&
GoodsRes
,
&
wg
)
...
...
@@ -73,14 +74,14 @@ func Synchronization(ctx *gin.Context) {
}
if
len
(
zyGoodsId
)
>
0
{
common
.
PrintDebugHtml
(
ctx
,
"zy增加协程:"
)
common
.
PrintDebugHtml
(
ctx
,
"zy增加协程
1003
:"
)
common
.
PrintDebugHtml
(
ctx
,
zyGoodsId
)
wg
.
Add
(
1
)
//协程计数一
go
zyService
.
ZyGoodsDetail
(
ctx
,
zyGoodsId
,
&
GoodsRes
,
&
wg
)
}
if
len
(
lyGoodsId
)
>
=
0
{
common
.
PrintDebugHtml
(
ctx
,
"ly增加协程:"
)
if
len
(
lyGoodsId
)
>
0
{
common
.
PrintDebugHtml
(
ctx
,
"ly增加协程
1004
:"
)
common
.
PrintDebugHtml
(
ctx
,
zyGoodsId
)
wg
.
Add
(
1
)
go
lyService
.
LyGoodsDetail
(
ctx
,
lyGoodsId
,
&
GoodsRes
,
&
wg
)
...
...
doc/test/r2.go
0 → 100644
View file @
3a0ddd74
package
main
import
(
"fmt"
"github.com/gomodule/redigo/redis"
"log"
)
func
main
()
{
c1
,
err
:=
redis
.
Dial
(
"tcp"
,
"192.168.1.235:6379"
)
if
err
!=
nil
{
log
.
Fatalln
(
err
)
}
if
_
,
err
:=
c1
.
Do
(
"AUTH"
,
"icDb29mLy2s"
);
err
!=
nil
{
c1
.
Close
()
log
.
Fatalln
(
err
)
}
defer
c1
.
Close
()
// good_id := []interface{}{"spu","2160558271613306802","2160551632152235701"}
// res1,err := c1.Do("hmget","spu","2160558271613306802","2160551632152235701")
res1
,
err
:=
c1
.
Do
(
"hmget"
,
"spu"
,
"2160558271613306802"
)
reply
,
err
:=
redis
.
Strings
(
res1
,
err
)
//if err != nil {
// fmt.Print(err,"错误")
// // handle error
//}
fmt
.
Println
(
reply
)
//if _, err := redis.Scan(reply, &value1,&value2); err != nil {
// // handle error
// }
// fmt.Print(value1,value2)
return
}
doc/test/r3.go
0 → 100644
View file @
3a0ddd74
package
main
import
(
"fmt"
"github.com/gomodule/redigo/redis"
_
"reflect"
)
type
Student
struct
{
Id
int
Name
string
}
func
(
s
Student
)
EchoName
(
name
string
){
fmt
.
Println
(
"我的名字是:"
,
name
)
}
func
main
()
{
c1
,
err
:=
redis
.
Dial
(
"tcp"
,
"192.168.1.235:6379"
)
if
err
!=
nil
{
}
if
_
,
err
:=
c1
.
Do
(
"AUTH"
,
"icDb29mLy2s"
);
err
!=
nil
{
c1
.
Close
()
}
defer
c1
.
Close
()
s
:=
[]
interface
{}{
"spu"
,
"2160558271613306802"
,
"2160551632152235701"
}
//res1,err := c1.Do("hmget","spu","2160558271613306802","2160551632152235701")
res1
,
err
:=
c1
.
Do
(
"hmget"
,
s
...
)
//res1,err := c1.Do("hmget","spu",good_id)
reply
,
err
:=
redis
.
Strings
(
res1
,
err
)
//if err != nil {
// fmt.Print(err,"错误")
// // handle error
//}
fmt
.
Println
(
reply
)
//s := Student{Id: 1, Name: "咖啡色的羊驼"}
//v := reflect.ValueOf(s)
//// 获取方法控制权
//// 官方解释:返回v的名为name的方法的已绑定(到v的持有值的)状态的函数形式的Value封装
//mv := v.MethodByName("EchoName")
//// 拼凑参数
//args := []reflect.Value{reflect.ValueOf("咖啡色的羊驼")}
//
//// 调用函数
//mv.Call(args)
}
\ No newline at end of file
model/goods.go
View file @
3a0ddd74
...
...
@@ -18,4 +18,10 @@ type LadderPrice struct {
type
LadderPriceLc
struct
{
Purchases
int64
`json:"purchases"`
//购买数量
Price
float64
`json:"price"`
//立创价格,人民币
}
//自营属性列表
type
Attrs
struct
{
AttrName
string
`json:"attr_name"`
//属性名称
AttrValue
string
`json:"attr_value"`
//属性值
}
\ No newline at end of file
pkg/gredis/redis.go
View file @
3a0ddd74
...
...
@@ -64,6 +64,56 @@ func getConn(writeHost, password string, maxIdle, maxActive int) (pool *redis.Po
return
}
/*
批量或者单个查询redis数据,统一返回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"})
*/
func
Hmget
(
redisCon
string
,
hkey
string
,
targetIds
[]
string
)
map
[
string
]
string
{
if
len
(
targetIds
)
==
0
{
fmt
.
Println
(
"批量查询不得传入空"
)
return
nil
}
redisConn
:=
Conn
(
redisCon
)
defer
redisConn
.
Close
()
skuArr
:=
make
(
map
[
string
]
string
,
0
)
if
len
(
targetIds
)
==
1
{
goods_id
:=
targetIds
[
0
];
info
,
err
:=
String
(
redisConn
.
Do
(
"HGET"
,
hkey
,
goods_id
))
if
err
!=
nil
{
fmt
.
Print
(
"连接redis错误991:"
,
err
)
}
if
info
==
""
{
skuArr
[
goods_id
]
=
""
}
else
{
skuArr
[
goods_id
]
=
info
}
//fmt.Println("单个查询")
return
skuArr
}
else
{
//多个查询
param
:=
[]
interface
{}{
hkey
}
for
_
,
goods_id
:=
range
targetIds
{
param
=
append
(
param
,
goods_id
)
}
res1
,
err1
:=
redisConn
.
Do
(
"hmget"
,
param
...
)
reply
,
_
:=
redis
.
Strings
(
res1
,
err1
)
if
err1
!=
nil
{
fmt
.
Println
(
err1
)
}
for
k
,
goodsInfo
:=
range
reply
{
skuArr
[
targetIds
[
k
]]
=
goodsInfo
}
//fmt.Println(skuArr)
return
skuArr
}
}
/*
批量或者单个查询redis数据,统一返回map[string]string
@param hkey string 集合键值,如sku
...
...
service/service_ly.go
View file @
3a0ddd74
...
...
@@ -48,7 +48,7 @@ func (ls *LyService) LyGoodsDetail(ctx *gin.Context, goodsIds []string, goodsRes
}
//批量获取商品详情
skuArr
:=
gredis
.
H
getPi
(
"default_r"
,
"sku"
,
goodsIds
)
skuArr
:=
gredis
.
H
mget
(
"default_r"
,
"sku"
,
goodsIds
)
//为了性能着想,这边也先去批量获取spu的信息
spuList
:=
ls
.
getSpuList
(
skuArr
)
for
goodsId
,
skuStr
:=
range
skuArr
{
...
...
@@ -199,6 +199,6 @@ func (ls *LyService) getSpuList(skuArr map[string]string) (spuList map[string]st
redisConn
:=
gredis
.
Conn
(
"default_r"
)
defer
redisConn
.
Close
()
//批量获取spu详情
spuList
=
gredis
.
H
getPi
(
"default_r"
,
"spu"
,
spuIds
)
spuList
=
gredis
.
H
mget
(
"default_r"
,
"spu"
,
spuIds
)
return
}
service/service_ly_common.go
View file @
3a0ddd74
...
...
@@ -5,6 +5,7 @@ import (
"fmt"
"github.com/gomodule/redigo/redis"
"github.com/iancoleman/orderedmap"
_
"github.com/iancoleman/orderedmap"
"github.com/ichunt2019/logger"
"github.com/syyongx/php2go"
"github.com/tidwall/gjson"
...
...
@@ -12,7 +13,9 @@ import (
"go_sku_server/pkg/common"
"go_sku_server/pkg/gredis"
"go_sku_server/pkg/mongo"
_
"go_sku_server/pkg/mongo"
"gopkg.in/mgo.v2/bson"
_
"gopkg.in/mgo.v2/bson"
"strings"
)
...
...
service/service_zy.go
View file @
3a0ddd74
...
...
@@ -38,18 +38,21 @@ func (qs *ZiyingService) ZyGoodsDetail(ctx *gin.Context,goodsIds []string,goodsR
redisConn
.
Close
();
}()
skuArr
:=
gredis
.
H
getPi2
(
"search_r"
,
"Self_SelfGoods"
,
goodsIds
)
//批量获取商品详情
skuArr
:=
gredis
.
H
mget
(
"search_r"
,
"Self_SelfGoods"
,
goodsIds
)
//批量获取商品详情
fast
:=
ctx
.
Request
.
FormValue
(
"power[fast]"
)
for
goods_id
,
info
:=
range
skuArr
{
if
gjson
.
Get
(
info
,
"goods_name"
)
.
String
()
==
""
{
fmt
.
Print
(
"
报错redis 1001
-----"
,
goods_id
,
skuArr
)
fmt
.
Print
(
"
zy goods_name为空
-----"
,
goods_id
,
skuArr
)
}
//拼接梯度价格
ladder
_price_a
rr
:=
gjson
.
Get
(
info
,
"ladder_price"
)
.
Array
()
ladder
PriceA
rr
:=
gjson
.
Get
(
info
,
"ladder_price"
)
.
Array
()
ladderPrice
:=
make
([]
model
.
LadderPrice
,
0
)
for
_
,
v
:=
range
ladder_price_arr
{
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
(),
...
...
@@ -57,6 +60,19 @@ func (qs *ZiyingService) ZyGoodsDetail(ctx *gin.Context,goodsIds []string,goodsR
})
}
//拼接属性
attrJsonArr
:=
gjson
.
Parse
(
gjson
.
Get
(
info
,
"attrs"
)
.
String
())
.
Array
()
attrs
:=
make
([]
model
.
Attrs
,
0
)
for
_
,
d
:=
range
attrJsonArr
{
if
d
.
Get
(
"attr_name"
)
.
String
()
==
""
{
continue
;
}
attrs
=
append
(
attrs
,
model
.
Attrs
{
AttrName
:
d
.
Get
(
"attr_name"
)
.
String
(),
AttrValue
:
d
.
Get
(
"attr_value"
)
.
String
(),
})
}
//数组
A
:=
orderedmap
.
New
()
//初始化有序map,拼接data 数据
A
.
Set
(
"goods_id"
,
common
.
MyInt64
(
goods_id
))
...
...
@@ -74,7 +90,13 @@ func (qs *ZiyingService) ZyGoodsDetail(ctx *gin.Context,goodsIds []string,goodsR
A
.
Set
(
"goods_brief"
,
gjson
.
Get
(
info
,
"goods_brief"
)
.
String
())
//
A
.
Set
(
"moq"
,
gjson
.
Get
(
info
,
"moq"
)
.
Int
())
//
A
.
Set
(
"mpq"
,
gjson
.
Get
(
info
,
"mpq"
)
.
Int
())
//
A
.
Set
(
"ladder_price"
,
ladderPrice
)
//
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
())
//
...
...
@@ -85,7 +107,13 @@ func (qs *ZiyingService) ZyGoodsDetail(ctx *gin.Context,goodsIds []string,goodsR
stock
:=
dbStock
-
lockStock
//当前可购买库存
A
.
Set
(
"stock"
,
stock
)
A
.
Set
(
"attrs"
,
gjson
.
Get
(
info
,
"attrs"
)
.
String
())
//
if
len
(
attrs
)
==
0
{
A
.
Set
(
"attrs"
,
""
)
//属性值
}
else
{
A
.
Set
(
"attrs"
,
attrs
)
//
}
A
.
Set
(
"cost"
,
gjson
.
Get
(
info
,
"cost"
)
.
String
())
//
A
.
Set
(
"new_cost"
,
gjson
.
Get
(
info
,
"new_cost"
)
.
String
())
//
A
.
Set
(
"supplier_stock"
,
gjson
.
Get
(
info
,
"supplier_stock"
)
.
Int
())
//
...
...
@@ -105,7 +133,8 @@ func (qs *ZiyingService) ZyGoodsDetail(ctx *gin.Context,goodsIds []string,goodsR
supplier_id
:=
gjson
.
Get
(
info
,
"supplier_id"
)
.
String
()
supplier_name
:=
""
if
supplier_id
!=
""
{
supplier_name
,
_
=
gredis
.
String
(
redisConn
.
Do
(
"HGET"
,
"Self_SelfSupplierInfo"
,
supplier_id
))
supplierInfo
,
_
:=
gredis
.
String
(
redisConn
.
Do
(
"HGET"
,
"Self_SelfSupplierInfo"
,
supplier_id
))
supplier_name
=
gjson
.
Get
(
supplierInfo
,
"supplier_name"
)
.
String
()
}
A
.
Set
(
"supplier_name"
,
supplier_name
)
...
...
@@ -148,8 +177,6 @@ func (qs *ZiyingService) ZyGoodsDetail(ctx *gin.Context,goodsIds []string,goodsR
A
.
Set
(
"pdf"
,
gjson
.
Get
(
info
,
"pdf"
)
.
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
())
//
...
...
@@ -198,8 +225,7 @@ func (qs *ZiyingService) ZyGoodsDetail(ctx *gin.Context,goodsIds []string,goodsR
A
.
Set
(
"quota_num"
,
gjson
.
Get
(
goods_quota
,
"num"
)
.
Int
())
}
//处理是否能购买
if
gjson
.
Get
(
info
,
"status"
)
.
String
()
!=
"1"
||
len
(
ladder_price_arr
)
==
0
{
if
gjson
.
Get
(
info
,
"status"
)
.
String
()
!=
"1"
||
len
(
ladderPriceArr
)
==
0
{
A
.
Set
(
"is_buy"
,
0
)
}
else
{
A
.
Set
(
"is_buy"
,
1
)
...
...
update.sh
View file @
3a0ddd74
...
...
@@ -11,5 +11,6 @@ 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"
chmod +x
${
Cur_Dir
}
"/update.sh"
#supervisorctl restart go_sku_server_60005:*
echo
"更新执行成功"
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment