Commit dfec0977 by huangchengyi

1.0

parent 018ce295
......@@ -15,4 +15,12 @@ password = root
host = 192.168.2.250
database = test
table_prefix =
type = mysql
[spu]
user_name = spu
password = spu
host = 192.168.1.234
database = liexin_spu
table_prefix =lie_
type = mysql
\ No newline at end of file
......@@ -21,4 +21,10 @@ SEARCH_API_ERORR_PRE=search_api_overtime_
;曝光时间记录哈希集合
SEARCH_SHOW_SKU_TIME=search_show_sku_time
;获取关税信息,根据goods_name,brand_name获取
TAX_CUSTOMS_INFO=tax_customs_info
\ No newline at end of file
TAX_CUSTOMS_INFO=tax_customs_info
;存放联营所有sku
SKU=sku
;存放联营所有spu
SPU=SPU
;存放digikey 型号映射
SKU_RAW_MAP=sku_raw_map
\ No newline at end of file
......@@ -4,7 +4,7 @@
3 ="tme"
[common]
'MOUSER_API'='http://footstone.liexin.net/webapi/handle_mouser'
MOUSER_API='http://footstone.liexin.net/webapi/handle_mouser'
[brand]
is_not_ti = 0
......
......@@ -2,43 +2,33 @@ package controller
import (
"github.com/gin-gonic/gin"
"search_server/framework/gin_"
"search_server/protopb/mouser"
"search_server/model"
"search_server/pkg/common"
"search_server/service"
)
func init() {
MouserService := service.NewMouserServiceImpl()
gin_.NewBuilder().WithService(MouserService).
WithEndpoint(MouserGetData(MouserService)).
WithRequest(MouserRequest()).
WithResponse(MouserResponse()).Build("/search/mouser/test", "POST")
//搜索型号
func GetMouserData(c *gin.Context) {
goodsName, _ := c.GetPostForm("goods_name")
lycon := new(service.CommonLyService)
}
//处理请求
func MouserGetData(c *service.MouserServiceImpl) gin_.Endpoint {
return func(context *gin.Context, request interface{}) (response interface{}, err error) {
rsp := &mouser.MouserResponse{}
//err = c.MouserGetData(context, request.(*mouser.MouserRequest), rsp)
return rsp, err
//调外链拿数据
apiData := service.OutLink(&goodsName,"1")
//供应商详情
supplierInfo := model.SUPPLIER_REDIS_INFO_{
SupplierId:14,
SupplierNickname: "mouser",
}
}
//接收请求
func MouserRequest() gin_.EncodeRequestFunc {
return func(context *gin.Context) (i interface{}, e error) {
bReq := &mouser.MouserRequest{}
err := context.BindQuery(bReq) //使用的是query 参数
bReq.GoodsName, _ = context.GetPostForm("goods_name")
if err != nil {
return nil, err
}
return bReq, nil
goods := lycon.GetSkuByGoodsSn(apiData,&supplierInfo)
var errCode int
if len(goods) == 0 {
errCode = 1
}
}
//响应请求
func MouserResponse() gin_.DecodeResponseFunc {
return func(context *gin.Context, res interface{}) error {
context.JSON(200, res)
return nil
res := common.BomResponse{
ErrCode: errCode,
ErrMsg: "",
Data: goods,
}
c.JSON(200, res)
}
......@@ -12,6 +12,13 @@ import (
//check_button=2&pf=1&keyword=123213&supplier_id=7&offset=2&follow_hit=1&p=1&_=1593582814402
func QuoteIndex(c *gin.Context) {
var request requests.QuoteIndexRequest
for k, v := range c.Request.Form {
fmt.Printf("k:%v\n", k)
fmt.Printf("v:%v\n", v)
}
if err := c.ShouldBind(&request); err != nil {
fmt.Println(err)
}
......
......@@ -4,6 +4,7 @@ go 1.14
require (
github.com/basgys/goxml2json v1.1.0
github.com/coreos/etcd v3.3.18+incompatible
github.com/gin-contrib/cors v1.3.1
github.com/gin-gonic/gin v1.6.3
github.com/go-ini/ini v1.57.0
......
......@@ -11,14 +11,17 @@ type LyClearGoodsList struct {
GoodsImg string `json:"goods_img"` //sku图片
Cat string `json:"cat"` //分类
RestrictionMessage string `json:"RestrictionMessage"` //额外购买限制内容,如 ‘当前商品不在本地区销售’
Increment uint64 `json:"increment"` //最小包装量、倍数
Increment int64 `json:"increment"` //最小包装量、倍数 =Mpq
SinglePrice float64 `json:"single_price"` //最小单价
Tiered []*TierItem //价格梯度数量
Stock int64 `json:"increment"` //库存
Moq int64 `json:"moq"` //最小起订量、起订量
Tiered []*TierItem //价格梯度数量
}
type TierItem struct {
Purchases uint64 //购买数量
PriceUs float64 //数量对应的英文价格
PriceCn float64 //数量对应的中文价格
PriceAc float64 `json:"price_ac"`
}
/*
......@@ -48,7 +51,7 @@ Array
)
*/
type SUPPLIER_REDIS_INFO_ struct {
SupplierId string `json:"supplier_id"` //供应商id
SupplierId int64 `json:"supplier_id"` //供应商id
SupplierNickname string `json:"supplier_nickname"` //供应商名称
AdText string `json:"ad_text"` //供应商描述
CnDelivery string `json:"cn_delivery"` //国内交货时间
......@@ -114,30 +117,25 @@ Array
)
*/
type LySkuInfo struct {
SpuId string `json:"spu_id"` //spu_id
Encoded string `json:"encoded"`
Moq int `json:"moq"`
Mpq int `json:"mpq"`
OldGoodsId int `json:"old_goods_id"`
GoodsType int `json:"goods_type"`
GoodsStatus int `json:"goods_status"`
BatchSn string `json:"batch_sn"`
Stock string `json:"stock"`
UpdateTime string `json:"update_time"`
GoodsImages string `json:"goods_images"`
Canal string `json:"canal"`
SupplierId string `json:"supplier_id"`
IsExpire string `json:"is_expire"`
HkDeliveryTime string `json:"hk_delivery_time"`
CnDeliveryTime string `json:"cn_delivery_time"`
LadderPrice []*LadderPrice2 `json:"ladder_price"`
}
type LadderPrice2 struct {
Purchases int `json:"purchases"` //数量
PriceUs float64 `json:"price_us"` //英文价格
PriceCn float64 `json:"price_cn"` //中文价格
PriceAc float64 `json:"price_ac"`
SpuId string `json:"spu_id"` //spu_id
Encoded string `json:"encoded"`
Moq int64 `json:"moq"`
Mpq int64 `json:"mpq"`
OldGoodsId int64 `json:"old_goods_id"`
GoodsType int `json:"goods_type"`
GoodsStatus int `json:"goods_status"`
BatchSn string `json:"batch_sn"`
Stock int64 `json:"stock"`
UpdateTime int64 `json:"update_time"`
GoodsImages string `json:"goods_images"`
Canal string `json:"canal"`
SupplierId int64 `json:"supplier_id"`
IsExpire string `json:"is_expire"`
HkDeliveryTime string `json:"hk_delivery_time"`
CnDeliveryTime string `json:"cn_delivery_time"`
LadderPrice []*TierItem `json:"ladder_price"`
}
/*
spu详情
Array
......@@ -154,17 +152,17 @@ Array
[spu_brief] =>
[update_time] => 1540893752
)
*/
*/
type LySpuInfo struct {
ClassId1 int64 `json:"class_id1"` //一级分类
ClassId2 int64 `json:"class_id2"` //二级分类
ClassId3 int64 `json:"class_id3"` //三级分类
BrandId int64 `json:"brand_id"` //品牌ID
SpuName string `json:"spu_name"` //型号名称
Status string `json:"status"` // 状态
ImagesL string `json:"images_l"` //图片
Encap string `json:"encap"` //封装
Pdf string `json:"pdf"` //pdf
SpuBrief string `json:"spu_brief"` //描述
UpdateTime string `json:"update_time"` //更新时间
}
\ No newline at end of file
ClassId1 int64 `json:"class_id1"` //一级分类
ClassId2 int64 `json:"class_id2"` //二级分类
ClassId3 int64 `json:"class_id3"` //三级分类
BrandId int64 `json:"brand_id"` //品牌ID
SpuName string `json:"spu_name"` //型号名称
Status int `json:"status"` // 状态
ImagesL string `json:"images_l"` //图片
Encap string `json:"encap"` //封装
Pdf string `json:"pdf"` //pdf
SpuBrief string `json:"spu_brief"` //描述
UpdateTime int64 `json:"update_time"` //更新时间
}
......@@ -4,7 +4,10 @@ import (
"crypto/md5"
"encoding/hex"
"github.com/syyongx/php2go"
"math/rand"
"strconv"
"strings"
"time"
)
// Md5 md5()
......@@ -58,9 +61,31 @@ func ToString(a interface{}) string {
return "change to String error"
}
/*
md5字符串
*/
func GetKey(s string) string{
return php2go.Md5(strings.ToLower(s))
}
/**
* 获取联营活动价
*/
func lyActivityPrice() {
}
\ No newline at end of file
}
/*构造SPU和SKU的ID
*生成19位纯数组id
*/
func CreateId(types string) string{
var id,db string
if types == "sku" {
id = "1"
db = strconv.Itoa(php2go.Rand(0,9))+strconv.Itoa(php2go.Rand(0,9))
}else{
id = "2"
db = "0"+strconv.Itoa(php2go.Rand(0,9))
}
s := rand.New(rand.NewSource(time.Now().UnixNano())).Int31n(1000000)
return id+strconv.FormatInt(int64(s),10)+strconv.FormatInt(php2go.Time(),10)+db
}
......@@ -27,5 +27,12 @@ func BuildDatabaseList() (DatabaseList map[string]BaseDatabase) {
Database: Get("bom.database").String(),
Prefix: Get("mysql.prefix").String(),
},
"spu": {
UserName: Get("spu.user_name").String(),
Password: Get("spu.password").String(),
Host: Get("spu.host").String(),
Database: Get("spu.database").String(),
Prefix: Get("spu.table_prefix").String(),
},
}
}
......@@ -48,3 +48,4 @@ func Setup() error{
func Conn(conName string) *xorm.Engine {
return DatabaseConMap[conName]
}
......@@ -16,6 +16,7 @@ func InitRouter() *gin.Engine {
r.POST("/search/bom/autospu", controller.AutoSpu)
r.POST("/search/bom/recommend", controller.Recommend)
r.POST("search/ZiYing/zyh", controller.Zyh)
r.POST("search/mouser/GetMouserData", controller.GetMouserData)
//快手平台相关
//r.GET("/search/quote", controller.QuoteIndex)
......
package service
import (
"github.com/gomodule/redigo/redis"
"github.com/syyongx/php2go"
"search_server/model"
"search_server/pkg/common"
"search_server/pkg/config"
"search_server/pkg/gredis"
"search_server/pkg/mysql"
"strconv"
"strings"
"fmt"
"encoding/json"
)
//定义类名
type CommonLyService struct {
supplier_over_time map[string]int64
supplierId int64 //调用当前方法的供应商ID
supplierName string //调用当前方法的供应商名称
skuEsUpdataList []map[string]interface{} //组装批量更新es数据
SKU_UNIQUE_JUDGE string //
SPU_UNIQUE_JUDGE string //
BRAND_NAME_ALL string //
SUPPLIER_BRAND_ALL string //
BRAND string //
SKU string //
SPU string
SKU_RAW_MAP string
}
//初始化类
func (t *CommonLyService) LyServerRun(){
CommonLyService := new(CommonLyService)
CommonLyService.supplier_over_time = map[string]int64{
"arrow":3600,
"verical":3600,
"mouser":3600,
"master":3600,
"tme":3600,
"buerklin":3600,
}
//用到的redis键值
CommonLyService.SKU_UNIQUE_JUDGE = config.Get("redis_all.SKU_UNIQUE_JUDGE").String() //
CommonLyService.SPU_UNIQUE_JUDGE = config.Get("redis_all.SPU_UNIQUE_JUDGE").String() //
CommonLyService.BRAND_NAME_ALL = config.Get("redis_all.BRAND_NAME_ALL").String() //
CommonLyService.SUPPLIER_BRAND_ALL = config.Get("redis_all.SUPPLIER_BRAND_ALL").String() //
CommonLyService.BRAND = config.Get("redis_all.BRAND").String() //
CommonLyService.SKU = config.Get("redis_all.SKU").String() //
CommonLyService.SPU = config.Get("redis_all.SPU").String()
CommonLyService.SKU_RAW_MAP = config.Get("redis_all.SKU_RAW_MAP").String()
}
/*
联营公共类
联营大类,包括修改新增 sku es redis ,推送数据到队列让其他go服务更新数据到mysql
@param goods_list 请求联营格式化后的数据
@param supplier_info 供应商商品详情
*/
func (t *CommonLyService) GetSkuByGoodsSn(goodsList map[string]*model.LyClearGoodsList,supplierInfo *model.SUPPLIER_REDIS_INFO_) map[string]interface{}{
t.LyServerRun(); //初始化变量
redisRead := gredis.Conn("search_r")
defer redisRead.Close()
t.supplierId = supplierInfo.SupplierId
t.supplierName = supplierInfo.SupplierNickname
originGoods := make(map[string]interface{},0)
for goods_sn, info := range goodsList {
snSku := php2go.Md5(strings.ToLower(goods_sn))
skuId,_ := gredis.String(redisRead.Do("HGET",t.SKU_UNIQUE_JUDGE,snSku)) //查询唯一值,反查sku_id
var sku_flag bool = false; //是否新增或者更新db+redis,为true则新增
if skuId == "" { //为空,先创建sku
lock_key := "searchapi_"+snSku;
flag,_ := redis.Bool(redisRead.Do("SETNX", lock_key,php2go.Time()+2))
if flag { //不存在锁,直接新增
sku_flag = true
redisRead.Do("EXP",lock_key,2) //给锁有效时间2秒
//sku_id = t.writeSkuInfo(info)
}else{ //存在锁
}
}
print(info)
print(sku_flag)
//productList[goodsSn] = &LyClearGoodsList
}
fmt.Println(originGoods)
return originGoods
}
/*
生成或者更新 sku信息
*/
func (t *CommonLyService) writeSkuInfo(skuInfo *model.LyClearGoodsList,skuId string,) {
redisWrite := gredis.Conn("search_w")
defer redisWrite.Close()
spuKey := common.GetKey(skuInfo.GoodsName+"_"+skuInfo.BrandName)
spuId,_ := gredis.String(redisWrite.Do("HGET",t.SKU_UNIQUE_JUDGE,spuKey))
if spuId == "" { //不存在spu,创建新的spu
spuId = t.writeSpuInfo(skuInfo)
}
if skuId == "" {
skuId = common.CreateId("sku");
}
inSkuInfo := model.LySkuInfo{
SpuId: spuId,
Encoded: "",
Moq: skuInfo.Moq,
Mpq: skuInfo.Increment,
OldGoodsId: 0,
GoodsType: 1,
GoodsStatus: 1,
BatchSn:"",
Stock:skuInfo.Stock,
HkDeliveryTime: "",
CnDeliveryTime: "",
LadderPrice: skuInfo.Tiered,
UpdateTime: php2go.Time(),
GoodsImages: "",
Canal: "",
SupplierId:t.supplierId,
}
jsonStr, _ := json.Marshal(inSkuInfo)
redisWrite.Do("HSET","sku",spuId,jsonStr)
skuKey := common.GetKey(skuInfo.GoodsSn+"_"+strconv.FormatInt(t.supplierId,10))
redisWrite.Do("HSET",t.SKU_UNIQUE_JUDGE,skuKey,skuId)
//todo 如果是digikey新增,需要插入原始映射表
if t.supplierId == 7 {
//redisWrite.Do("HSET",SKU_RAW_MAP,skuKey,skuId)
}
}
/*
生成spu
*/
func (t *CommonLyService) writeSpuInfo(skuInfo *model.LyClearGoodsList) string {
redisWrite := gredis.Conn("search_w")
defer redisWrite.Close()
brand_key := common.GetKey(strings.ToLower(skuInfo.BrandName))
brandId,_ := redis.Int64(redisWrite.Do("HGET", t.BRAND_NAME_ALL,brand_key))
if brandId == 0 {
brandId,_ = redis.Int64(redisWrite.Do("HGET",t.SUPPLIER_BRAND_ALL,brand_key))
if brandId == 0 {
brandId = t.writeBrandInfo(skuInfo)
}
}
spuId := common.CreateId("spu") //创建spu的id
Spuinfo := model.LySpuInfo{
ClassId1:0,
ClassId2:0,
ClassId3:0,
BrandId:brandId,
SpuName:skuInfo.GoodsName,
Status:1,
ImagesL:"",
Encap:"",
Pdf:"",
SpuBrief:"",
UpdateTime:php2go.Time(),
}
jsonStr, _ := json.Marshal(Spuinfo)
redisWrite.Do("HSET","spu",spuId,jsonStr)
spuKey := common.GetKey(skuInfo.GoodsName+"_"+skuInfo.BrandName)
redisWrite.Do("HSET",t.SPU_UNIQUE_JUDGE,spuKey,spuId)
return spuId
}
/*
生成品牌
*/
func (t *CommonLyService) writeBrandInfo(skuInfo *model.LyClearGoodsList) int64 {
var (
dbSpu = mysql.Conn("spu") //spu实例化链接
brandId int64 //品牌id
brandkey = common.GetKey(skuInfo.BrandName) //品牌唯一值
redisWrite = gredis.Conn("search_w")
)
defer redisWrite.Close()
has, err := dbSpu.Table("brand").Where("brand_name = ?", skuInfo.BrandName).Cols("id").Get(&brandId)
if err != nil {
fmt.Println(err) //查询错误
return 0
}
if has {//不存在品牌,则创建品牌
sql :="insert into brand(brand_name,create_time,insert_type) values (?, ?, ?)"
results, err := dbSpu.Exec(sql,skuInfo.BrandName, php2go.Time(),1)
if err != nil {
fmt.Println(err) //查询错误
return 0
}
brandId,_ = results.LastInsertId()
}
//更新redis 品牌数据
redisWrite.Do("HSET",t.BRAND_NAME_ALL,brandkey,brandId)
redisWrite.Do("HSET",t.BRAND,brandkey,brandId)
return brandId;
}
/*
组装推送到es数据
*/
func esSkuInfo(skuInfo *model.LyClearGoodsList) {
}
/*
推入队列
*/
func toGoRabmq() {
}
/*
更新es
*/
func toEs() {
}
package service
import (
"fmt"
"github.com/syyongx/php2go"
_ "github.com/tidwall/gjson"
"search_server/model"
"search_server/pkg/gredis"
"search_server/pkg/config"
"strings"
)
//关键词搜索过期时间
var supplier_over_time = map[string]int64{
"arrow":3600,
"verical":3600,
"mouser":3600,
"master":3600,
"tme":3600,
"buerklin":3600,
}
//调用当前方法的供应商名称
var supplier_name string="";
//组装批量更新es数据
var sku_list []map[string]interface{}
//redis 相关
var sku_uique_judge string = config.Get("redis_all.SKU_UNIQUE_JUDGE").String() //sku唯一键
var spu_uique_judge string = config.Get("redis_all.SPU_UNIQUE_JUDGE").String() //spu唯一键
var brand_name_all string = config.Get("redis_all.BRAND_NAME_ALL").String() //品牌键
/*
联营公共类
联营大类,包括修改新增 sku es redis ,推送数据到队列让其他go服务更新数据到mysql
@param goods_list 请求联营格式化后的数据
@param supplier_info 供应商商品详情
*/
func getSkuByGoodsSn(goods_list map[string]*model.LyClearGoodsList,supplier_info *model.SUPPLIER_REDIS_INFO_) map[string]interface{}{
originGoods := make(map[string]interface{},0)
searredis := gredis.Conn("search_r")
defer searredis.Close()
for goods_sn, info := range goods_list {
sn_sku := php2go.Md5(strings.ToLower(goods_sn))
searredis.Do("set","hcttest","dddd")
sku_id,_ := redis.String(redisConn.Do("GET", "hcy1"))(sku_uique_judge,sn_sku) //查询唯一值,反查sku_id
var sku_flag bool = false; //是否新增或者更新db+redis,true则新增
if sku_id == "" { //为空,先创建sku
lock_key := "searchapi_"+sn_sku;
flag,_ := gredis.Setnx(lock_key,php2go.Time()+2)
if flag { //不存在锁,直接新增
sku_flag = true
gredis.EXP(lock_key,2) //给锁有效时间2
sku_id =
}else{ //存在锁
}
/*
if($flag){
$sku_flag = true;
//给锁有效时间
$redis->expire($lock_key,2);
//创建sku_id等信息
$sku_id = $this->writeSkuInfo($v,$redis);
//删除key
$redis->del($lock_key);
}else{
//已经存在锁则等待
$lock_flag = true;
while ($lock_flag){
$lock_flag = $redis->get($lock_key);
usleep(10);
}
$sku_id = $redis->hget(C('SKU_UNIQUE_JUDGE'),$sn_sku);
if(!$sku_id){
continue;
}
}
*/
}
print(info)
//productList[goodsSn] = &LyClearGoodsList
}
fmt.Println(originGoods)
return originGoods
}
/*
生成sku信息并写入redis
*/
func writeSkuInfo(sku_info *model.LyClearGoodsList) {
spu_key := php2go.Md5(sku_info.GoodsName+"_"+sku_info.BrandName)
spu_id,_ := gredis.HGet(spu_uique_judge,spu_key)
if spu_id == "" { //不存在spu,创建新的spu
}
}
/*
生成spu
*/
func writeSpuInfo(sku_info *model.LyClearGoodsList) {
brand_key := php2go.Md5(sku_info.BrandName)
Spuinfo := model.LySpuInfo{
ClassId1:0,
ClassId2:0,
ClassId3:0,
BrandId:$brand_id,
SpuName:$sku_info['goods_name'],
Status:1,
ImagesL:'',
Encap:$sku_info['encap']? $sku_info['encap']:'',
Pdf:'',
SpuBrief:'',
UpdateTime:,
}
}
/*
生成品牌
*/
func writeBrandInfo(sku_info *model.LyClearGoodsList) {
brand_key := php2go.Md5(sku_info.BrandName)
Spuinfo := model.LySpuInfo{
ClassId1:0,
ClassId2:0,
ClassId3:0,
BrandId:$brand_id,
SpuName:$sku_info['goods_name'],
Status:1,
ImagesL:'',
Encap:$sku_info['encap']? $sku_info['encap']:'',
Pdf:'',
SpuBrief:'',
UpdateTime:,
}
}
/*
组装推送到es数据
*/
func esSkuInfo(sku_info *model.LyClearGoodsList) {
}
/*
推入队列
*/
func toGoRabmq() {
}
/*
更新es
*/
func toEs() {
}
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