Commit ad60817b by wang

解决冲突

parents 542e0f5b 756df35c
...@@ -2,14 +2,14 @@ ...@@ -2,14 +2,14 @@
[default_redis_read] [default_redis_read]
host = 192.168.1.235:6379 host = 192.168.1.235:6379
password = icDb29mLy2s password = icDb29mLy2s
max_idle = 1000 max_idle = 2000
max_active = 5000 max_active = 5000
idle_timeout = 20 idle_timeout = 20
[default_redis_write] [default_redis_write]
host = 192.168.1.235:6379 host = 192.168.1.235:6379
password = icDb29mLy2s password = icDb29mLy2s
max_idle = 1000 max_idle = 2000
max_active = 5000 max_active = 5000
idle_timeout = 20 idle_timeout = 20
......
package controller package controller
import ( import (
"encoding/json"
"github.com/gin-gonic/gin" "github.com/gin-gonic/gin"
"github.com/gogf/gf/util/gconv"
"github.com/syyongx/php2go" "github.com/syyongx/php2go"
"go_sku_server/pkg/common" "go_sku_server/pkg/common"
"go_sku_server/pkg/gredis"
"go_sku_server/pkg/logger" "go_sku_server/pkg/logger"
"go_sku_server/service" "go_sku_server/service"
"sync" "sync"
...@@ -117,3 +120,25 @@ func Synchronization(ctx *gin.Context) { ...@@ -117,3 +120,25 @@ func Synchronization(ctx *gin.Context) {
func Hbsdata(ctx *gin.Context) { func Hbsdata(ctx *gin.Context) {
ctx.String(200, "ok") ctx.String(200, "ok")
} }
/*
测试redis
*/
func Testr(ctx *gin.Context) {
time1 := time.Now().UnixNano() / 1e6
redisConn := gredis.Conn("search_r")
defer func() {
redisConn.Close()
}()
goods_ids := ctx.Request.FormValue("goods_ids")
skuArr := gredis.Hmget("default_r", "sku", php2go.Explode(",", goods_ids));
skustr,_ := json.Marshal(skuArr)
time2 := time.Now().UnixNano() / 1e6
ctx.String(200, "查询redis开始时间毫秒:"+gconv.String(time1)+" 结束时间毫秒:"+gconv.String(time2)+" 查询时间毫秒:"+gconv.String(time2-time1)+ " "+ string(skustr))
}
package main
import (
"fmt"
"math"
"reflect"
"strconv"
)
func main() {
a:=0.000
if(a==0){
fmt.Println("=0")
}
return
numF:=1.56984
fmt.Println(Round(numF,9))
return
//fmt.Printf("%.2f", 12.0)
fmt.Print(strconv.ParseFloat(fmt.Sprintf("%.2f", 12.0), 64))
// 保留两位小数, 通用
fmt.Println(fmt.Sprintf("%.2f", numF))
value, _ := strconv.ParseFloat(fmt.Sprintf("%.2f", numF), 64)
fmt.Println(reflect.TypeOf(value), value)
num, _ := FormatFloat(numF, 2)
fmt.Println(reflect.TypeOf(num), num)
// 舍弃的尾数不为0,强制进位
num, _ = FormatFloatCeil(0.2205, 2)
fmt.Println(reflect.TypeOf(num), num)
// 强制舍弃尾数
num, _ = FormatFloatFloor(0.2295, 2)
fmt.Println(reflect.TypeOf(num), num)
// 四舍六入五考虑,五后非零就进一,五后为零看奇偶,五前为偶应舍去,五前为奇要进一
fmt.Printf("9.8249 => %0.2f(四舍)\n", 9.8249)
fmt.Printf("9.82671 => %0.2f(六入)\n", 9.82671)
fmt.Printf("9.8351 => %0.2f(五后非零就进一)\n", 9.8351)
fmt.Printf("9.82501 => %0.2f(五后非零就进一)\n", 9.82501)
fmt.Printf("9.8250 => %0.2f(五后为零看奇偶,五前为偶应舍去)\n", 9.8250)
fmt.Printf("9.8350 => %0.2f(五后为零看奇偶,五前为奇要进一)\n", 9.8350)
}
// 保留两位小数,舍弃尾数,无进位运算
// 主要逻辑就是先乘,trunc之后再除回去,就达到了保留N位小数的效果
func FormatFloat(num float64, decimal int) (float64, error) {
// 默认乘1
d := float64(1)
if decimal > 0 {
// 10的N次方
d = math.Pow10(decimal)
}
// math.trunc作用就是返回浮点数的整数部分
// 再除回去,小数点后无效的0也就不存在了
res := strconv.FormatFloat(math.Trunc(num*d)/d, 'f', -1, 64)
return strconv.ParseFloat(res, 64)
}
// 舍弃的尾数不为0,强制进位
func FormatFloatCeil(num float64, decimal int) (float64, error) {
// 默认乘1
d := float64(1)
if decimal > 0 {
// 10的N次方
d = math.Pow10(decimal)
}
// math.trunc作用就是返回浮点数的整数部分
// 再除回去,小数点后无效的0也就不存在了
res := strconv.FormatFloat(math.Ceil(num*d)/d, 'f', -1, 64)
return strconv.ParseFloat(res, 64)
}
// 强制舍弃尾数
func FormatFloatFloor(num float64, decimal int) (float64, error) {
// 默认乘1
d := float64(1)
if decimal > 0 {
// 10的N次方
d = math.Pow10(decimal)
}
// math.trunc作用就是返回浮点数的整数部分
// 再除回去,小数点后无效的0也就不存在了
res := strconv.FormatFloat(math.Floor(num*d)/d, 'f', -1, 64)
return strconv.ParseFloat(res, 64)
}
/*
四舍五入取多少位
@param float64 x 目标分析字符串
@param int wei 取小数多少位
*/
func MyRound(x float64, wei int) float64 {
if wei == 0 {
return math.Floor(x + 0.5)
}
weis := map[int]float64{
1: 10,
2: 100,
3: 1000,
4: 10000,
5: 100000,
6: 1000000,
}
weishu := weis[wei]
s:=math.Floor(x*weishu+0.5)
fmt.Println(s)
return s/weishu
}
func Round(val float64, precision int) (valueFloat64 float64) {
//strconv.ParseFloat(fmt.Sprintf("%.2f", 12.0), 64) //两位
format:="%."+strconv.Itoa(precision)+"f"
valueFloat64,err:= strconv.ParseFloat(fmt.Sprintf(format, val), 64)
if(err!=nil){
panic("round err"+err.Error())
}
return
}
\ No newline at end of file
package main
import (
"fmt"
"github.com/gogf/gf/util/gconv"
"github.com/tidwall/gjson"
"go_sku_server/pkg/common"
)
func main() {
a:="123"
fmt.Println(gconv.Int(a))
ladderprice()
}
func ladderprice() error{
jsonStr:=jsonStr()
goodsId:="1160551099531105977"
costly:=1 //
var num int64
num=94
var data =make(map[string]interface{})
goodsResult:=gjson.Get(jsonStr,goodsId)
if(goodsResult.Exists()){
ladderPriceS:=goodsResult.Get("ladder_price")
if(len(ladderPriceS.Array())>0){
var price =gjson.Result{}
for k,item:=range ladderPriceS.Array(){
purchases:=item.Get("purchases").Int()
if(k==0){
price=item//默认最小数量
if(purchases>num){
num=purchases//如果小于最小的,J
break
}
}
if(costly==1){//人民币就使用最小数量的阶梯价
break
}
if(purchases<=num){
price=item
}
}
if(price.Exists()==false){
fmt.Println("这个SKU没有阶梯价 504003")
}
data["price_cn"]=price.Get("price_cn").Float()
price_cn_total:=gconv.Float64(data["price_cn"])*gconv.Float64(num)
data["price_cn_total"]=common.MyRound(price_cn_total,4)
data["ladder_price"]=price.Get("price_cn").Int()
data["num"]=num
/*if(price.Get("price_ac").Exists()){
data["price_ac"]
}*/
}else{
fmt.Println("这个SKU没有阶梯价 104002")
}
}else{
fmt.Println("未找到对应SKU 20001")
}
return nil
}
func GetLadderPrice(goodsId string,num int64,costly int) (gjson.Result,error){
jsonStr:=jsonStr()
goodsResult:=gjson.Get(jsonStr,goodsId)
if(goodsResult.Exists()){
ladderPriceS:=goodsResult.Get("ladder_price")
if(len(ladderPriceS.Array())>0){
var price =gjson.Result{}
for k,item:=range ladderPriceS.Array(){
purchases:=item.Get("purchases").Int()
if(k==0){
price=item//默认最小数量
if(purchases>num){
num=purchases//如果小于最小的,J
break
}
}
if(costly==1){//人民币就使用最小数量的阶梯价
break
}
if(purchases<=num){
price=item
}
}
if(price.Exists()==false){
fmt.Println("这个SKU没有阶梯价 504003")
}
}else{
fmt.Println("这个SKU没有阶梯价 104002")
}
}else{
fmt.Println("未找到对应SKU 20001")
}
}
func jsonStr() string{
/*
data["price_cn"]=price.Get("price_cn").Float()
price_cn_total:=gconv.Float64(data["price_cn"])*gconv.Float64(num)
data["price_cn_total"]=common.MyRound(price_cn_total,4)
data["ladder_price"]=price.Get("price_cn").Int()
data["num"]=num
*/
str:=`{
"1160551099531105977": {
"spu_id": "2160551099534657107",
"old_goods_id": 15000000037,
"update_time": 1607657661,
"cp_time": 0,
"goods_status": 1,
"goods_type": 1,
"supplier_id": 7,
"encoded": "",
"batch_sn": "",
"moq": 95,
"mpq": 1,
"stock": 9999999,
"hk_delivery_time": "2-3个工作日",
"cn_delivery_time": "1-3个工作日",
"ladder_price": [
{
"purchases": 95,
"price_us": 1.2431,
"price_cn": 10.1276
},
{
"purchases": 190,
"price_us": 1.0584,
"price_cn": 8.6231
},
{
"purchases": 950,
"price_us": 0.8384,
"price_cn": 6.8304
}
],
"goods_images": "//media.digikey.com/Photos/Rohm%20Photos/RPM871-H14E2_sml.JPG",
"canal": "",
"packing": "",
"goods_id": "1160551099531105977",
"goods_name": "RPM871-H14E2",
"brand_name": "ROHM",
"supplier_name": "digikey",
"attrs": [
{
"attr_name": "25°C 时待机电流,典型值",
"attr_value": "73µA"
},
{
"attr_name": "产品族",
"attr_value": "IrDA 收发器模块"
},
{
"attr_name": "关断",
"attr_value": "-"
},
{
"attr_name": "其它名称",
"attr_value": "RPM871-H14E2-ND\n\t\t\t\t\t\t\t\t\t\t\n\t\t\t\t\t\t\t\t\tRPM871-H14E2TR\n\t\t\t\t\t\t\t\t\t\t\n\t\t\t\t\t\t\t\t\tRPM871H14E2"
},
{
"attr_name": "包装",
"attr_value": "标准卷带"
},
{
"attr_name": "尺寸",
"attr_value": "8.00mm x 2.90mm x 2.40mm"
},
{
"attr_name": "工作温度",
"attr_value": "-20°C ~ 85°C"
},
{
"attr_name": "数据速率",
"attr_value": "115.2kbs(SIR)"
},
{
"attr_name": "方向",
"attr_value": "侧视图"
},
{
"attr_name": "标准",
"attr_value": "IrDA 1.2"
},
{
"attr_name": "标准包装",
"attr_value": "1,000"
},
{
"attr_name": "电压 - 供电",
"attr_value": "2.6V ~ 3.6V"
},
{
"attr_name": "类别",
"attr_value": "传感器,变送器"
},
{
"attr_name": "系列",
"attr_value": "-"
},
{
"attr_name": "链路范围,低功耗",
"attr_value": "20cm,60cm"
}
],
"scm_brand": [],
"ac_type": 0,
"allow_coupon": 1,
"brand_id": 1749,
"coefficient": {
"cn": 1.03,
"hk": 1,
"extra_ratio": 1,
"ratio": 7,
"tax": 1.13
},
"original_price": [
{
"purchases": 95,
"price_us": 1.243068,
"price_cn": 9.4233255876,
"cost_price": 0
},
{
"purchases": 190,
"price_us": 1.058397,
"price_cn": 8.0233901379,
"cost_price": 0
},
{
"purchases": 950,
"price_us": 0.838368,
"price_cn": 6.3554162976,
"cost_price": 0
}
],
"supp_extend_fee": {
"cn": {
"max": "10000",
"price": "20"
},
"hk": {
"max": 69000,
"price": 138
}
},
"is_buy": 1,
"class_id1": 13287,
"class_id2": 13288,
"class_id3": 0,
"spu_name": "RPM871-H14E2",
"status": 1,
"images_l": "//media.digikey.com/Photos/Rohm%20Photos/RPM871-H14E2_sml.JPG",
"encap": "",
"pdf": "//media.digikey.com/pdf/Data%20Sheets/Rohm%20PDFs/RPM871-H14.pdf",
"spu_brief": "MODULE IRDA 115.2KBPS 8SMD",
"class_name": "其他",
"erp_tax": false,
"goods_sn": "",
"goods_details": "",
"content": null
}
}`
return str
}
\ No newline at end of file
package main
import (
"encoding/json"
"fmt"
"reflect"
)
type jj struct {
zz int
}
func main() {
var s string
var a int
byte,err:=json.Marshal(jj{})
return
dd(s)
dd(a)
dd(jj{})
//byte,err:=json.Marshal(jj{})
if(err!=nil){
panic("")
}
str:=string(byte)
dd(str)
dd(jj{})
s="123"
a=123
dd(s)
dd(a)
}
func dd(a interface{}) {
if(reflect.ValueOf(a).IsNil()){
fmt.Println("是否为空")
}
if(reflect.ValueOf(a).IsZero()){
fmt.Println("是否为零值")
}
if(reflect.ValueOf(a).IsValid()){
fmt.Println("是否无效")
}
/*if(a==nil){
fmt.Println("==nil")
}*/
fmt.Print(reflect.TypeOf(a),a)
}
\ No newline at end of file
package main
import (
"fmt"
"reflect"
)
type ss struct {
d string
}
func main() {
g:=ss{}
g.d="dfdf"
flag:=g.isEmpty()
fmt.Print(flag,reflect.TypeOf(flag))
}
func (S *ss)isEmpty() bool{
return *S==ss{}
}
\ No newline at end of file
package main
import (
"encoding/json"
"fmt"
"github.com/iancoleman/orderedmap"
"github.com/tidwall/gjson"
//"github.com/tidwall/gjson"
)
func main() {
test2();
return
jsonStream:= `
{
"name": {"first": "Tom", "last": "Anderson"},
"age":37,
"age1":56.6,
"age2":"67.3",
"children": ["Sara","Alex","Jack"],
"fav.movie": "Deer Hunter",
"friends": [
{"first": "Dale", "last": "Murphy", "age": 44, "nets": ["ig", "fb", "tw"]},
{"first": "Roger", "last": "Craig", "age": 68, "nets": ["fb", "tw"]},
{"first": "Jane", "last": "Murphy", "age": 47, "nets": ["ig", "tw"]}
]
}
`
n:=gjson.Get(jsonStream,"abc").Int()
fmt.Print(n)
o := orderedmap.New()
o.UnmarshalJSON([]byte(jsonStream))
o.Get("children")
//s:=o.Keys()
//fmt.Println(s)
//err := json.Unmarshal([]byte(jsonStream), &o)
/*json.Unmarshal([]byte(jsonStream),)
a:=gjson.Parse(jsonStream).Map()*/
//fmt.Println(a[1].Type)
//fmt.Print(s)
}
var packConfig string
func test2() {
packJson:= `
{
"编带": {
"packing": 5,
"pick_type": 1
},
"袋装": {
"packing": 6,
"pick_type": 3
},
"包": {
"packing": 6,
"pick_type": 3
},
"管装": {
"packing": 8,
"pick_type": 3
},
"管": {
"packing": 8,
"pick_type": 3
},
"盒装": {
"packing": 7,
"pick_type": 3
},
"盒": {
"packing": 7,
"pick_type": 3
},
"托盘": {
"packing": 9,
"pick_type": 3
},
"盘": {
"packing": 5,
"pick_type": 1
},
"大盘": {
"packing": 5,
"pick_type": 1
}
}
`
o := orderedmap.New()
err:=o.UnmarshalJSON([]byte(packJson))
if(err!=nil){
panic("解析错误")
}
//o.Get("dfd")
s:=gjson.Get(packJson,"abc").String()
if(s==""){}
}
func PackGet() (*PackData) {
config:=getConfig()
s:=gjson.Get(config,"abc").String()
p:=&PackData{}
if(s==""){
return p
}
err:=json.Unmarshal([]byte(s),p)
if(err!=nil){
panic("mmethod:PackGet"+err.Error())
}
return p
}
type PackData struct {
PacKing int
PickType int
}
func getConfig() string{
if(packConfig!=""){
return packConfig
}
return packConfigs()
}
func packConfigs() string {
packJson:= `
{
"编带": {
"packing": 5,
"pick_type": 1
},
"袋装": {
"packing": 6,
"pick_type": 3
},
"包": {
"packing": 6,
"pick_type": 3
},
"管装": {
"packing": 8,
"pick_type": 3
},
"管": {
"packing": 8,
"pick_type": 3
},
"盒装": {
"packing": 7,
"pick_type": 3
},
"盒": {
"packing": 7,
"pick_type": 3
},
"托盘": {
"packing": 9,
"pick_type": 3
},
"盘": {
"packing": 5,
"pick_type": 1
},
"大盘": {
"packing": 5,
"pick_type": 1
}
}
`
return packJson
}
\ No newline at end of file
package main
import "fmt"
type a struct {
Purchases int64 `json:"purchases"` //购买数量
}
func main() {
s:=&a{}
if(s!=nil){
fmt.Println("非空")
}else{
fmt.Print("空")
}
}
\ No newline at end of file
package main
import "github.com/ichunt2019/go-rabbitmq/utils/rabbitmq"
func main() {
PushMsg("ws_test","abc")
}
func PushMsg(listName string, data string) {
queueExchange := rabbitmq.QueueExchange{
listName,
listName,
"",
"direct",
"amqp://guest:guest@192.168.2.232:5672/",
}
rabbitmq.Send(queueExchange, data)
}
\ No newline at end of file
package main
import "fmt"
func main() {
a := []int{0, 1, 5, 3, 4}
//删除第i个元素
i := 2
fmt.Println(a[:i])
fmt.Println(a[i+1:])
a = append(a[:i], a[i+1:]...)
fmt.Print(a)
}
\ No newline at end of file
package main
import (
"fmt"
"github.com/gin-gonic/gin"
"go_sku_server/pkg/logger"
"strings"
)
func main() {
path:="/SaveZySku"
str:=strings.Replace(path,"/","",1)
fmt.Print(str)
//strings.ToLower(str)
switch str {
case "SaveZySku":
logger.Select("zysku_save")
break
case "SaveSku":
logger.Select("lysku_save")
break
default:
}
}
func errlogHandle(ctx *gin.Context) func(msg string){
fullPath:=ctx.FullPath()
logPath:=""
switch fullPath {
case "SaveZySku":
logPath="zysku_save"
break
case "SaveSku":
logPath="lysku_save"
break
default:
}
return func(msg string) {
logger.Select(logPath)
}
}
}
\ No newline at end of file
package main
import (
"encoding/json"
"fmt"
)
type Testjson struct {
Name interface{} `json:"name"`
}
func main() {
strJson:=`{"name":"123"}`
testjson:=&Testjson{}
json.Unmarshal([]byte(strJson),&testjson)
fmt.Print(testjson)
}
\ No newline at end of file
package main
import (
"fmt"
"github.com/gogf/gf/util/gconv"
"reflect"
)
type abc struct {
GoodsId string `json:"goods_id" form:"goods_id" binding:"required" required_errcode:"10086" `
Num string `json:"num" form:"num" binding:"required"`
}
func main() {
abc:=abc{}
typeof:=reflect.TypeOf(abc)
filed,_:=typeof.FieldByName("GoodsId")
s:=filed.Tag.Get("required_errcode")
gconv.Int(s)
si:=int(int64(s))
fmt.Print(s,si)
}
package model
type Activity struct {
Id int64 `json:"id"`
SupplierIds string `json:"supplier_ids"`
SupplierIdList []string
SupplierType int `json:"supplier_type"`
UserScope int `json:"user_scope"`
SignText string `json:"sign_text"`
BrandIds string `json:"brand_ids"`
BrandIdList []string
ClassIds string `json:"class_ids"`
ClassIdList []string
Canals string `json:"canals"`
CanalList []string
Ratio float64 `json:"ratio"`
StartTime int `json:"start_time"`
EndTime int `json:"end_time"`
AddTime int `json:"add_time"`
UpdateTime int `json:"update_time"`
Status int `json:"status"`
AllowCoupon int `json:"allow_coupon"`
ActivityName string `json:"activity_name"`
ShowName string `json:"show_name"`
Sign string `json:"sign"`
ActivityType int `json:"activity_type"`
GoodsScope int `json:"goods_scope"`
ExcludeBrandIds string `json:"exclude_brand_ids"`
ExcludeBrandIdList []string
ExcludeSkuIds string `json:"exclude_sku_ids"`
ExcludeSkuIdList []string
SkuIds string `json:"sku_ids"`
SkuIdList []string
AdminId int `json:"admin_id"`
AdminName string `json:"admin_name"`
ActivityId int `json:"activity_id"`
ItemList []ActivityItem `json:"item_list"`
}
type ActivityItem struct {
ActivityId int `json:"activity_id"`
Amount float64 `json:"amount"`
Num int `json:"num"`
ItemName string `json:"item_name"`
Pic string `json:"pic"`
Remark string `json:"remark"`
AddTime int `json:"add_time"`
}
//用于检查是否有活动情况的结构体
type ActivityCheckData struct {
SupplierId int
BrandId int
GoodsId string
Canal string
ClassId int
}
...@@ -60,12 +60,25 @@ type LySku struct { ...@@ -60,12 +60,25 @@ type LySku struct {
ClassName3 string `json:"class_name3,omitempty"` ClassName3 string `json:"class_name3,omitempty"`
Ratio float64 `json:"ratio,omitempty"` Ratio float64 `json:"ratio,omitempty"`
SpuDetail string `json:"spu_detail,omitempty"` SpuDetail string `json:"spu_detail,omitempty"`
//活动信息 //活动信息
ActivityEndTime int64 `json:"activity_end_time,omitempty"` HasGiftActivity int `json:"has_gift_activity"`
ActivityInfo map[string]interface{} `json:"activity_info,omitempty"` GiftActivity GiftActivity `json:"gift_activity"`
Content interface{} `json:"content"` }
type PriceActivity struct {
HasActivity bool `json:"-"`
ActivityId int `json:"activity_id,omitempty"`
Ratio float64 `json:"ratio"`
} }
type GiftActivity struct {
HasActivity bool `json:"-"`
ActivityId int `json:"activity_id,omitempty"`
ItemList []ActivityItem `json:"items,omitempty"`
}
//为什么不直接映射到结构,而要用gjson,因为redis存的数据结构不一定正常,可能类型不一致 //为什么不直接映射到结构,而要用gjson,因为redis存的数据结构不一定正常,可能类型不一致
func InitSkuData(sku string) (data LySku) { func InitSkuData(sku string) (data LySku) {
goodsSn := gjson.Get(sku, "goods_sn").String() goodsSn := gjson.Get(sku, "goods_sn").String()
......
...@@ -7,7 +7,7 @@ poolskuSave 返回是这样的格式 ...@@ -7,7 +7,7 @@ poolskuSave 返回是这样的格式
"errmsg": "ok", "errmsg": "ok",
"goods_id": 1160699091498808475 "goods_id": 1160699091498808475
} }
*/ */
type LySaveResponse struct { type LySaveResponse struct {
ErrCode int `json:"errcode"` ErrCode int `json:"errcode"`
ErrMsg string `json:"errmsg"` ErrMsg string `json:"errmsg"`
...@@ -15,34 +15,33 @@ type LySaveResponse struct { ...@@ -15,34 +15,33 @@ type LySaveResponse struct {
} }
func ResponseSucess(GoodsId int64) LySaveResponse { func ResponseSucess(GoodsId int64) LySaveResponse {
return LySaveResponse{0,"ok",GoodsId} return LySaveResponse{0, "ok", GoodsId}
} }
func (L *LySaveResponse)GetErrorMsg() string { func (L *LySaveResponse) GetErrorMsg() string {
return L.ErrMsg return L.ErrMsg
} }
func (L *LySaveResponse)GetErrorCode() int { func (L *LySaveResponse) GetErrorCode() int {
return L.ErrCode return L.ErrCode
} }
func ResponseError(opts ...interface{}) LySaveResponse { func ResponseError(opts ...interface{}) LySaveResponse {
var ErrMsg string; var ErrMsg string
Code:=1001; Code := 1001
for num,opt:=range opts{ for num, opt := range opts {
if(num>1){ if num > 1 {
break; break
} }
switch num { switch num {
case 0: case 0:
ErrMsg=opt.(string) ErrMsg = opt.(string)
case 1: case 1:
Code=opt.(int) Code = opt.(int)
break break
} }
} }
return LySaveResponse{ErrCode: Code, ErrMsg: ErrMsg} return LySaveResponse{ErrCode: Code, ErrMsg: ErrMsg}
} }
...@@ -14,18 +14,27 @@ func InitRouter() *gin.Engine { ...@@ -14,18 +14,27 @@ func InitRouter() *gin.Engine {
//联营参数选择搜索 //联营参数选择搜索
r.GET("synchronization", controller.Synchronization) r.GET("synchronization", controller.Synchronization)
r.POST("synchronization",controller.Synchronization) r.POST("synchronization", controller.Synchronization)
//联营参数选择搜索 //联营参数选择搜索
r.GET("Synchronization", controller.Synchronization) r.GET("Synchronization", controller.Synchronization)
r.POST("Synchronization",controller.Synchronization) r.POST("Synchronization", controller.Synchronization)
//心跳 //心跳
r.GET("hbsdata", controller.Hbsdata) r.GET("hbsdata", controller.Hbsdata)
r.POST("hbsdata",controller.Hbsdata) r.POST("hbsdata", controller.Hbsdata)
//测试redis
r.POST("testr", controller.Testr)
//自营SaveSku //自营SaveSku
r.POST("SaveSku",controller.Error_Middleware(),controller.SaveSku) r.POST("SaveSku", controller.Error_Middleware(), controller.SaveSku)
r.POST("SkuEdit",controller.Error_Middleware(),controller.SkuEdit) r.POST("SkuEdit", controller.Error_Middleware(), controller.SkuEdit)
//ly := service.LyService{}
//sku := model.ActivityCheckData{
// SupplierId: 2,
// BrandId: 1,
// GoodsId: "1",
// Canal: "lmxs",
//}
//ly.GetActivityData(sku)
return r return r
} }
package service
import (
"encoding/json"
"fmt"
"github.com/gogf/gf/util/gconv"
"github.com/gomodule/redigo/redis"
"github.com/syyongx/php2go"
"go_sku_server/model"
"go_sku_server/pkg/gredis"
"strings"
)
type ActivityService struct {
}
//获取活动信息,目前是包括促销活动(系数打折)以及满赠活动
func (as *ActivityService) GetActivityData(checkData model.ActivityCheckData) (priceActivity model.PriceActivity, giftActivity model.GiftActivity) {
supplierId := checkData.SupplierId
redisCon := gredis.Conn("default_r")
//处理满赠活动
activityStr, _ := redis.String(redisCon.Do("hget", "lie_gift_activity", supplierId))
if activityStr != "" {
var activities []model.Activity
err := json.Unmarshal([]byte(activityStr), &activities)
if err != nil {
fmt.Println(err)
}
if len(activities) != 0 {
giftActivity = as.GetGiftActivity(checkData, activities)
}
}
//处理单品促销活动(打折活动)
activityStr, _ = redis.String(redisCon.Do("hget", "lie_price_activity", supplierId))
if activityStr != "" {
var activities []model.Activity
err := json.Unmarshal([]byte(activityStr), &activities)
if err != nil {
fmt.Println(err)
}
if len(activities) != 0 {
priceActivity = as.GetPriceActivity(checkData, activities)
}
}
return
}
//获取满赠活动信息
func (as *ActivityService) GetGiftActivity(checkData model.ActivityCheckData, activities []model.Activity) (giftActivity model.GiftActivity) {
var hasActivity bool
for _, activity := range activities {
//判断是否是排除的sku或者品牌,如果是的话,直接返回没活动
if as.CheckExcludeSku(checkData.GoodsId, activity) || as.CheckExcludeBrand(checkData.BrandId, activity) {
hasActivity = false
}
//判断是否是搞活动的品牌
if as.CheckBrand(checkData.BrandId, activity) {
hasActivity = true
giftActivity.ItemList = activity.ItemList
giftActivity.ActivityId = activity.ActivityId
}
//如果是专卖,则要去判断canal,如果是自营,则去判断分类
if checkData.SupplierId == 17 {
if as.CheckCanal(checkData.Canal, activity) {
hasActivity = true
giftActivity.ItemList = activity.ItemList
giftActivity.ActivityId = activity.ActivityId
}
} else {
if as.CheckClass(checkData.ClassId, activity) {
hasActivity = true
giftActivity.ItemList = activity.ItemList
giftActivity.ActivityId = activity.ActivityId
}
}
}
giftActivity.HasActivity = hasActivity
return
}
func (as *ActivityService) GetPriceActivity(checkData model.ActivityCheckData, activities []model.Activity) (priceActivity model.PriceActivity) {
var hasActivity bool
for _, activity := range activities {
//判断是否是排除的sku或者品牌,如果是的话,直接返回没活动
if as.CheckExcludeSku(checkData.GoodsId, activity) || as.CheckExcludeBrand(checkData.BrandId, activity) {
hasActivity = false
}
//判断是否是搞活动的品牌
if as.CheckBrand(checkData.BrandId, activity) {
hasActivity = true
priceActivity.Ratio = activity.Ratio
}
//如果是专卖,则要去判断canal,如果是自营,则去判断分类
if checkData.SupplierId == 17 {
if as.CheckCanal(checkData.Canal, activity) {
hasActivity = true
priceActivity.Ratio = activity.Ratio
}
} else {
if as.CheckClass(checkData.ClassId, activity) {
hasActivity = true
priceActivity.Ratio = activity.Ratio
}
}
//判断是否是搞活动的品牌
if as.CheckSkuId(checkData.GoodsId, activity) {
hasActivity = true
priceActivity.Ratio = activity.Ratio
}
}
priceActivity.HasActivity = hasActivity
return
}
//检查是否属于被排除的品牌
func (as *ActivityService) CheckExcludeBrand(brandId int, activity model.Activity) bool {
if brandId == 0 {
return false
}
//先去判断品牌
activity.ExcludeBrandIdList = strings.Split(activity.ExcludeBrandIds, ",")
brandIdStr := gconv.String(brandId)
//如果存在于有活动价的品牌,就是有折扣活动了
if php2go.InArray(brandIdStr, activity.ExcludeBrandIdList) {
return true
}
return false
}
//检查是否属于被排除的sku
func (as *ActivityService) CheckExcludeSku(skuId string, activity model.Activity) bool {
if skuId == "" {
return false
}
//先去判断品牌
activity.ExcludeSkuIdList = strings.Split(activity.ExcludeSkuIds, ",")
//如果存在于有活动价的品牌,就是有折扣活动了
if php2go.InArray(skuId, activity.ExcludeSkuIdList) {
return true
}
return false
}
//检查是否属于活动分类(只有自营需要判断)
func (as *ActivityService) CheckClass(classId int, activity model.Activity) bool {
if classId == 0 {
return false
}
//先去判断品牌
activity.ClassIdList = strings.Split(activity.ClassIds, ",")
classIdStr := gconv.String(classId)
//如果存在于有活动价的品牌,就是有折扣活动了
if php2go.InArray(classIdStr, activity.ClassIdList) {
return true
}
return false
}
//检查是否属于活动品牌
func (as *ActivityService) CheckBrand(brandId int, activity model.Activity) bool {
if brandId == 0 {
return false
}
//先去判断品牌
activity.BrandIdList = strings.Split(activity.BrandIds, ",")
brandIdStr := gconv.String(brandId)
//如果存在于有活动价的品牌,就是有折扣活动了
if php2go.InArray(brandIdStr, activity.BrandIdList) {
return true
}
return false
}
//检查是否属于供应商渠道
func (as *ActivityService) CheckCanal(canal string, activity model.Activity) bool {
if canal == "" {
return false
}
//先去判断品牌
activity.CanalList = strings.Split(activity.Canals, ",")
//如果存在于有活动价的品牌,就是有折扣活动了
if php2go.InArray(canal, activity.CanalList) {
return true
}
return false
}
//检查是否属于活动sku_id
func (as *ActivityService) CheckSkuId(skuId string, activity model.Activity) bool {
if skuId == "" {
return false
}
//先去判断品牌
activity.SkuIdList = strings.Split(activity.SkuIds, ",")
skuIdStr := gconv.String(skuId)
//如果存在于有活动价的品牌,就是有折扣活动了
if php2go.InArray(skuIdStr, activity.SkuIdList) {
return true
}
return false
}
package service
import (
"encoding/json"
"fmt"
"github.com/iancoleman/orderedmap"
"github.com/ichunt2019/logger"
"go_sku_server/pkg/mongo"
"gopkg.in/mgo.v2"
"gopkg.in/mgo.v2/bson"
"strconv"
)
//获取Spu的属性
func (ls *LyService) GetSpuAttr(spuId string) (attrsResult interface{}) {
var spuAttr SpuAttr
var attrsList []interface{}
mongodb := mongo.Conn("default")
defer func() {
mongodb.Close()
}()
spuIdInt, _ := strconv.Atoi(spuId)
err := mongodb.DB("ichunt").C("spu_attrs").Find(bson.M{"spu_id": spuIdInt}).One(&spuAttr)
//err := mongo.Conn("default").DB("ichunt").C("spu_attrs").Find(bson.M{"spu_id": spuId}).One(&spuAttr)
if err != nil && err != mgo.ErrNotFound {
fmt.Println("mongodb连接错误:")
fmt.Println(err)
}
if spuAttr.Attrs != "" {
o := orderedmap.New()
err := json.Unmarshal([]byte(spuAttr.Attrs), &o)
if err != nil {
logger.Error("%s", err)
}
for _, value := range o.Keys() {
data := make(map[string]interface{})
data["attr_name"] = value
data["attr_value"], _ = o.Get(value)
attrsList = append(attrsList, data)
attrsResult = attrsList
}
return attrsResult
}
return false
}
...@@ -2,11 +2,13 @@ package service ...@@ -2,11 +2,13 @@ package service
import ( import (
"github.com/gin-gonic/gin" "github.com/gin-gonic/gin"
"github.com/gogf/gf/util/gconv"
"github.com/gomodule/redigo/redis" "github.com/gomodule/redigo/redis"
"github.com/syyongx/php2go" "github.com/syyongx/php2go"
"github.com/tidwall/gjson" "github.com/tidwall/gjson"
"go_sku_server/model" "go_sku_server/model"
"go_sku_server/pkg/gredis" "go_sku_server/pkg/gredis"
"go_sku_server/service/sorter"
"sort" "sort"
"sync" "sync"
) )
...@@ -30,24 +32,24 @@ type Power struct { ...@@ -30,24 +32,24 @@ type Power struct {
func (ls *LyService) LyGoodsDetail(ctx *gin.Context, goodsIds []string, ch chan sync.Map) { func (ls *LyService) LyGoodsDetail(ctx *gin.Context, goodsIds []string, ch chan sync.Map) {
redisConn := gredis.Conn("search_r") redisConn := gredis.Conn("search_r")
defer func() { defer func() {
//wg.Done()
redisConn.Close() redisConn.Close()
}() }()
fast := ctx.Request.FormValue("power[fast]") fast := ctx.Request.FormValue("power[fast]")
isNewCustomer := ctx.Request.FormValue("power[newCustomer]") //isNewCustomer := ctx.Request.FormValue("power[newCustomer]")
power := Power{ //power := Power{
UserId: ctx.Request.FormValue("power[user_id]"), // UserId: ctx.Request.FormValue("power[user_id]"),
Mobile: ctx.Request.FormValue("power[mobile]"), // Mobile: ctx.Request.FormValue("power[mobile]"),
Email: ctx.Request.FormValue("power[email]"), // Email: ctx.Request.FormValue("power[email]"),
Member: ctx.Request.FormValue("power[member]"), // Member: ctx.Request.FormValue("power[member]"),
Invoice: ctx.Request.FormValue("power[invoice]"), // Invoice: ctx.Request.FormValue("power[invoice]"),
SpecialInvoice: ctx.Request.FormValue("power[special_invoice]"), // SpecialInvoice: ctx.Request.FormValue("power[special_invoice]"),
VerifyBlacklist: ctx.Request.FormValue("power[verify_blacklist]"), // VerifyBlacklist: ctx.Request.FormValue("power[verify_blacklist]"),
} //}
//批量获取商品详情 //批量获取商品详情
skuArr := gredis.Hmget("default_r", "sku", goodsIds) skuArr := gredis.Hmget("default_r", "sku", goodsIds)
//为了性能着想,这边也先去批量获取spu的信息 //为了性能着想,这边也先去批量获取spu的信息
spuList := ls.getSpuList(skuArr) var spuService SpuService
spuList := spuService.getSpuList(skuArr)
GoodsRes := sync.Map{} GoodsRes := sync.Map{}
for goodsId, skuStr := range skuArr { for goodsId, skuStr := range skuArr {
...@@ -56,7 +58,6 @@ func (ls *LyService) LyGoodsDetail(ctx *gin.Context, goodsIds []string, ch chan ...@@ -56,7 +58,6 @@ func (ls *LyService) LyGoodsDetail(ctx *gin.Context, goodsIds []string, ch chan
continue continue
} }
//初始化有序map,拼接data 数据 //初始化有序map,拼接data 数据
//A := orderedmap.New()
sku := model.InitSkuData(skuStr) sku := model.InitSkuData(skuStr)
sku.GoodsId = goodsId sku.GoodsId = goodsId
spu := spuList[sku.SpuId] spu := spuList[sku.SpuId]
...@@ -117,35 +118,28 @@ func (ls *LyService) LyGoodsDetail(ctx *gin.Context, goodsIds []string, ch chan ...@@ -117,35 +118,28 @@ func (ls *LyService) LyGoodsDetail(ctx *gin.Context, goodsIds []string, ch chan
sku.AllowCoupon = 1 sku.AllowCoupon = 1
sku.BrandId = brandId sku.BrandId = brandId
//活动标识 //去判断是否有活动(促销打折活动和满赠活动)
hasActivity := false checkData := model.ActivityCheckData{
//判断是否有新客价权利 SupplierId: int(sku.SupplierId),
if isNewCustomer == "true" || isNewCustomer == "1" { BrandId: int(sku.BrandId),
//获取新客价 GoodsId: sku.GoodsId,
sku = ls.GetActivityPrice(sku, "_NewCustomer", power) Canal: sku.Canal,
if sku.AcType > 0 { ClassId: sku.ClassID2,
hasActivity = true
}
} }
//获取活动价 var activityService ActivityService
if !hasActivity { priceActivity, giftActivity := activityService.GetActivityData(checkData)
sku = ls.GetActivityPrice(sku, "", power) if priceActivity.HasActivity {
if sku.AcType > 0 { sku.AcType = 9
hasActivity = true
} }
if giftActivity.HasActivity {
sku.HasGiftActivity = gconv.Int(giftActivity.HasActivity)
sku.GiftActivity = giftActivity
} }
//获取会员价
if !hasActivity {
sku = ls.GetActivityPrice(sku, "_Member", power)
if sku.AcType > 0 {
hasActivity = true
}
}
//处理阶梯价数据 //处理阶梯价数据
if len(sku.LadderPrice) > 0 { if len(sku.LadderPrice) > 0 {
//排序 //排序
sort.Sort(LadderPriceSorter(sku.LadderPrice)) sort.Sort(sorter.LadderPriceSorter(sku.LadderPrice))
//取出第一个阶梯价 //取出第一个阶梯价
purchases := sku.LadderPrice[0].Purchases purchases := sku.LadderPrice[0].Purchases
if purchases > sku.Moq { if purchases > sku.Moq {
...@@ -194,14 +188,3 @@ func (ls *LyService) LyGoodsDetail(ctx *gin.Context, goodsIds []string, ch chan ...@@ -194,14 +188,3 @@ func (ls *LyService) LyGoodsDetail(ctx *gin.Context, goodsIds []string, ch chan
} }
ch <- GoodsRes ch <- GoodsRes
} }
func (ls *LyService) getSpuList(skuArr map[string]string) (spuList map[string]string) {
var spuIds []string
for _, skuStr := range skuArr {
spuId := gjson.Get(skuStr, "spu_id").String()
spuIds = append(spuIds, spuId)
}
//批量获取spu详情
spuList = gredis.Hmget("default_r", "spu", spuIds)
return
}
...@@ -2,9 +2,7 @@ package service ...@@ -2,9 +2,7 @@ package service
import ( import (
"encoding/json" "encoding/json"
"fmt"
"github.com/gomodule/redigo/redis" "github.com/gomodule/redigo/redis"
"github.com/iancoleman/orderedmap"
_ "github.com/iancoleman/orderedmap" _ "github.com/iancoleman/orderedmap"
"github.com/ichunt2019/logger" "github.com/ichunt2019/logger"
"github.com/syyongx/php2go" "github.com/syyongx/php2go"
...@@ -12,12 +10,8 @@ import ( ...@@ -12,12 +10,8 @@ import (
"go_sku_server/model" "go_sku_server/model"
"go_sku_server/pkg/common" "go_sku_server/pkg/common"
"go_sku_server/pkg/gredis" "go_sku_server/pkg/gredis"
"go_sku_server/pkg/mongo"
_ "go_sku_server/pkg/mongo" _ "go_sku_server/pkg/mongo"
"gopkg.in/mgo.v2"
"gopkg.in/mgo.v2/bson"
_ "gopkg.in/mgo.v2/bson" _ "gopkg.in/mgo.v2/bson"
"strconv"
"strings" "strings"
) )
...@@ -95,38 +89,6 @@ type SpuAttr struct { ...@@ -95,38 +89,6 @@ type SpuAttr struct {
Attrs string `bson:"attrs"` Attrs string `bson:"attrs"`
} }
//获取Spu的属性
func (ls *LyService) GetSpuAttr(spuId string) (attrsResult interface{}) {
var spuAttr SpuAttr
var attrsList []interface{}
mongodb := mongo.Conn("default")
defer func() {
mongodb.Close()
}()
spuIdInt, _ := strconv.Atoi(spuId)
err := mongodb.DB("ichunt").C("spu_attrs").Find(bson.M{"spu_id": spuIdInt}).One(&spuAttr)
//err := mongo.Conn("default").DB("ichunt").C("spu_attrs").Find(bson.M{"spu_id": spuId}).One(&spuAttr)
if err != nil && err != mgo.ErrNotFound {
fmt.Println("mongodb连接错误:")
fmt.Println(err)
}
if spuAttr.Attrs != "" {
o := orderedmap.New()
err := json.Unmarshal([]byte(spuAttr.Attrs), &o)
if err != nil {
logger.Error("%s", err)
}
for _, value := range o.Keys() {
data := make(map[string]interface{})
data["attr_name"] = value
data["attr_value"], _ = o.Get(value)
attrsList = append(attrsList, data)
attrsResult = attrsList
}
return attrsResult
}
return false
}
//H获取供应链标准品牌 //H获取供应链标准品牌
func (ls *LyService) GetScmBrand(brandId int64) (res interface{}) { func (ls *LyService) GetScmBrand(brandId int64) (res interface{}) {
...@@ -279,7 +241,6 @@ func (ls *LyService) GetCoefficient(sku model.LySku) model.LySku { ...@@ -279,7 +241,6 @@ func (ls *LyService) GetCoefficient(sku model.LySku) model.LySku {
} }
if !hasCoefficient && !hasDefault { if !hasCoefficient && !hasDefault {
logger.Error("%s", "系数获取异常,供应商:"+common.ToString(sku.SupplierId)) logger.Error("%s", "系数获取异常,供应商:"+common.ToString(sku.SupplierId))
sku.Content = "系数获取异常,供应商:"+common.ToString(sku.SupplierId)
return sku return sku
} }
......
...@@ -14,6 +14,7 @@ import ( ...@@ -14,6 +14,7 @@ import (
"go_sku_server/pkg/e" "go_sku_server/pkg/e"
"go_sku_server/pkg/logger" "go_sku_server/pkg/logger"
"go_sku_server/pkg/mysql" "go_sku_server/pkg/mysql"
"go_sku_server/service/sorter"
"reflect" "reflect"
"sort" "sort"
"time" "time"
...@@ -151,7 +152,7 @@ func (S *LySaveService) ladderPriceHandle(ladderPrice []model.LadderPrice,lySkuE ...@@ -151,7 +152,7 @@ func (S *LySaveService) ladderPriceHandle(ladderPrice []model.LadderPrice,lySkuE
if(len(ladderPrice)>0){//有传阶梯价 if(len(ladderPrice)>0){//有传阶梯价
//获取最便宜的价格 //获取最便宜的价格
sort.Sort(LadderPriceSorter(ladderPrice))//按照购买数量,小到大排序,数量越大优惠越多,所以[num-1]是最便宜的 sort.Sort(sorter.LadderPriceSorter(ladderPrice))//按照购买数量,小到大排序,数量越大优惠越多,所以[num-1]是最便宜的
if(ladderPrice[num-1].PriceUs>=0){//如果有最低美元价,就直接读最低美元价 if(ladderPrice[num-1].PriceUs>=0){//如果有最低美元价,就直接读最低美元价
lySkuEntity.SinglePrice=ladderPrice[num-1].PriceUs//获取最便宜的价钱 lySkuEntity.SinglePrice=ladderPrice[num-1].PriceUs//获取最便宜的价钱
......
...@@ -163,27 +163,6 @@ func (ls *LyService) GetActivityPrice(sku model.LySku, suffix string, power Powe ...@@ -163,27 +163,6 @@ func (ls *LyService) GetActivityPrice(sku model.LySku, suffix string, power Powe
activityType := gjson.Get(activityInfo, "activity_type").Int() activityType := gjson.Get(activityInfo, "activity_type").Int()
if suffix == "" && blacklistType != 0 && hasActivity && activityId != "" && activityType == 2 && if suffix == "" && blacklistType != 0 && hasActivity && activityId != "" && activityType == 2 &&
power.VerifyBlacklist == "true" { power.VerifyBlacklist == "true" {
////_1 是用来区分活动价和折扣价,活动和折扣价(折扣价有黑名单,活动价没有黑名单)
//blackList, _ := redis.String(redisCon.Do("HGET", "activity_roster", activityId+"_1"))
////拼接是为了方便判断是否包含在黑名单内
//blackList = "," + blackList + ","
//blacklistTypeList := make(map[int]string)
//blacklistTypeList = map[int]string{
// 1: "invoice",
// 2: "special_invoice",
// 3: "user_id",
// 4: "mobile",
// 5: "email",
//}
//遍历黑名单类型
//黑名单就不显示折扣价吗,黑名单只针对折扣价
//activityBlackListTypes := gjson.Get(activityInfo, "blacklist_type").Array()
//for _, value := range activityBlackListTypes {
// //验证是否有对应的黑名单类型
// blackListType := blacklistTypeList[int(value.Int())]
// blackListItem :=
//
//}
} }
} }
//判断是否有活动 //判断是否有活动
...@@ -215,13 +194,6 @@ func (ls *LyService) GetActivityPrice(sku model.LySku, suffix string, power Powe ...@@ -215,13 +194,6 @@ func (ls *LyService) GetActivityPrice(sku model.LySku, suffix string, power Powe
if allowNotLogin == 0 { if allowNotLogin == 0 {
allowNotLogin = 2 allowNotLogin = 2
} }
sku.ActivityInfo = map[string]interface{}{
"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 sku.AcType = 8
} }
break break
...@@ -233,7 +205,6 @@ func (ls *LyService) GetActivityPrice(sku model.LySku, suffix string, power Powe ...@@ -233,7 +205,6 @@ func (ls *LyService) GetActivityPrice(sku model.LySku, suffix string, power Powe
allCoupon = 1 allCoupon = 1
} }
sku.AllowCoupon = int(allCoupon) sku.AllowCoupon = int(allCoupon)
sku.ActivityEndTime = endTime
return sku return sku
} }
...@@ -253,18 +224,3 @@ func getMouserActivityPrice(sku model.LySku) model.LySku { ...@@ -253,18 +224,3 @@ func getMouserActivityPrice(sku model.LySku) model.LySku {
} }
return sku return sku
} }
//阶梯价格排序算法
type LadderPriceSorter []model.LadderPrice
func (a LadderPriceSorter) Len() int {
return len(a)
}
func (a LadderPriceSorter) Swap(i, j int) {
a[i], a[j] = a[j], a[i]
}
func (a LadderPriceSorter) Less(i, j int) bool {
return a[j].Purchases > a[i].Purchases
}
package service
import (
"github.com/tidwall/gjson"
"go_sku_server/pkg/gredis"
)
type SpuService struct {
}
func (ss *SpuService) getSpuList(skuArr map[string]string) (spuList map[string]string) {
var spuIds []string
for _, skuStr := range skuArr {
spuId := gjson.Get(skuStr, "spu_id").String()
spuIds = append(spuIds, spuId)
}
//批量获取spu详情
spuList = gredis.Hmget("default_r", "spu", spuIds)
return
}
...@@ -3,6 +3,7 @@ package service ...@@ -3,6 +3,7 @@ package service
import ( import (
"github.com/gin-gonic/gin" "github.com/gin-gonic/gin"
"github.com/iancoleman/orderedmap" "github.com/iancoleman/orderedmap"
"github.com/syyongx/php2go"
"github.com/tidwall/gjson" "github.com/tidwall/gjson"
"go_sku_server/model" "go_sku_server/model"
"go_sku_server/pkg/common" "go_sku_server/pkg/common"
...@@ -238,15 +239,16 @@ func (qs *ZiyingService) ZyGoodsDetail(ctx *gin.Context,goodsIds []string, ch ch ...@@ -238,15 +239,16 @@ func (qs *ZiyingService) ZyGoodsDetail(ctx *gin.Context,goodsIds []string, ch ch
if v.Get("purchases").String() == "" { if v.Get("purchases").String() == "" {
continue; continue;
} }
price_cn := php2go.Round(v.Get("price_cn").Float()*10000)/10000
if PriceAcXi == 0 { if PriceAcXi == 0 {
ladderPrice = append(ladderPrice, model.LadderPrice{ ladderPrice = append(ladderPrice, model.LadderPrice{
Purchases: v.Get("purchases").Int(), Purchases: v.Get("purchases").Int(),
PriceCn: v.Get("price_cn").Float(), PriceCn: price_cn,
}) })
}else{ }else{
ladderPrice = append(ladderPrice, model.LadderPrice{ ladderPrice = append(ladderPrice, model.LadderPrice{
Purchases: v.Get("purchases").Int(), Purchases: v.Get("purchases").Int(),
PriceCn: v.Get("price_cn").Float(), PriceCn: price_cn,
PriceAc: PriceAcXi, PriceAc: PriceAcXi,
}) })
} }
......
package sorter
import "go_sku_server/model"
//阶梯价格排序算法
type LadderPriceSorter []model.LadderPrice
func (a LadderPriceSorter) Len() int {
return len(a)
}
func (a LadderPriceSorter) Swap(i, j int) {
a[i], a[j] = a[j], a[i]
}
func (a LadderPriceSorter) Less(i, j int) bool {
return a[j].Purchases > a[i].Purchases
}
\ No newline at end of file
package transformer
import (
"go_sku_server/model"
"strings"
)
func TransformActivity(activities []model.Activity) []model.Activity {
for key, activity := range activities {
activities[key].ClassIdList = strings.Split(activity.ClassIds, ",")
activities[key].BrandIdList = strings.Split(activity.BrandIds, ",")
activities[key].SkuIdList = strings.Split(activity.SkuIds, ",")
activities[key].ExcludeBrandIdList = strings.Split(activity.ExcludeBrandIds, ",")
activities[key].ExcludeSkuIdList = strings.Split(activity.ExcludeSkuIds, ",")
activities[key].CanalList = strings.Split(activity.Canals, ",")
}
return activities
}
package main package main
import ( import (
"fmt" "go_sku_server/service"
"github.com/syyongx/php2go"
) )
func main() { func main() {
var a = []string{"3923"} ly := service.LyService{}
var b = 3923 ly.GetActivityData()
fmt.Println(php2go.InArray(b,a))
} }
...@@ -14,6 +14,6 @@ chmod +x ${Cur_Dir}"/cmd/http/http" ...@@ -14,6 +14,6 @@ chmod +x ${Cur_Dir}"/cmd/http/http"
go build -o ${Cur_Dir}"/cmd/cron/cron" ${Cur_Dir}"/cmd/cron/cron_server.go" 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}"/cmd/cron/cron"
chmod +x ${Cur_Dir}"/update.sh" chmod +x ${Cur_Dir}"/update.sh"
supervisorctl restart go_sku_server_60005:* supervisorctl restart go_sku_server_60014:*
echo "更新执行成功" echo "更新执行成功"
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or sign in to comment