Commit 36950f81 by huangchengyi

1.0

parent 62482bda
package main
import (
"fmt"
"github.com/tidwall/gjson"
)
func main() {
var json = `{"mykey":[{"a":10},{"a":20},{"a":30},{"a":40}]}`
dd := gjson.Get(json,"mykey").Array()
for _,v := range dd {
fmt.Print(v.Get("a").String())
import "fmt"
func main() {
for a:=0;a<5;a++{
fmt.Println(a)
if a>3{
goto Loop
}
}
//json := `{"bar": {"id": 99, "xyz": "my xyz"}, "foo": {"myfoo": [605]}}`
//paths := []string{"foo.myfoo", "bar.id", "bar.xyz", "bar.abc"}
//expected := []string{"[605]", "99", "my xyz", ""}
//results := gjson.GetMany(json, paths...)
//if len(expected) != len(results) {
// fmt.Print(len(expected),len(results))
//}
//for i, path := range paths {
// if results[i].String() != expected[i] {
// fmt.Println( expected[i],results[i].String(),path)
// }
// fmt.Println(results[i].String())
//}
print("nin")
}
Loop: //放在for后边
fmt.Println("test")
}
\ No newline at end of file
package service
import (
"github.com/gomodule/redigo/redis"
"github.com/iancoleman/orderedmap"
"github.com/tidwall/gjson"
"goods_machining/middleware"
"goods_machining/pkg/gredis"
"sync"
)
......@@ -36,6 +36,7 @@ func (qs *ZiyingService) ZyGoodsDetail(goodsIds []string,goodsRes *map[string]in
}()
skuArr := gredis.HgetPi("search_r","Self_SelfGoods",goodsIds) //批量获取商品详情
fast := middleware.REQUEST["power[fast]"]
for goods_id,info := range skuArr {
......@@ -52,8 +53,6 @@ func (qs *ZiyingService) ZyGoodsDetail(goodsIds []string,goodsRes *map[string]in
A.Set("encap", gjson.Get(info, "encap").String()) //
A.Set("packing", gjson.Get(info, "packing").String()) //
A.Set("goods_unit", gjson.Get(info, "goods_unit").String()) //
A.Set("goods_images", gjson.Get(info, "goods_images").String()) //
A.Set("pdf", gjson.Get(info, "pdf").String()) //
A.Set("goods_brief", gjson.Get(info, "goods_brief").String()) //
A.Set("moq", gjson.Get(info, "moq").String()) //
A.Set("mpq", gjson.Get(info, "mpq").String()) //
......@@ -61,7 +60,13 @@ func (qs *ZiyingService) ZyGoodsDetail(goodsIds []string,goodsRes *map[string]in
A.Set("update_time", gjson.Get(info, "update_time").String()) //
A.Set("sku_name", gjson.Get(info, "sku_name").String()) //
A.Set("mpl", gjson.Get(info, "mpl").String()) //
A.Set("stock", gjson.Get(info, "stock").String()) //
//处理库存
lockStock := qs.skuLockNum(&redisConn,goods_id) //当前锁库库存
dbStock := gjson.Get(info, "stock").Int() //当前db库存
stock := dbStock-lockStock //当前可购买库存
A.Set("stock",stock)
A.Set("attrs", gjson.Get(info, "attrs").String()) //
A.Set("cost", gjson.Get(info, "cost").String()) //
A.Set("new_cost", gjson.Get(info, "new_cost").String()) //
......@@ -77,23 +82,56 @@ func (qs *ZiyingService) ZyGoodsDetail(goodsIds []string,goodsRes *map[string]in
A.Set("brand_name", gjson.Get(info, "brand_name").String()) //
// 供应商名称
supplier_id := gjson.Get(info, "supplier_id").String()
supplier_name := ""
if supplier_id != "" {
supplier_name,_ = gredis.String(redisConn.Do("HGET","Self_SelfSupplierInfo",supplier_id))
if fast != "1" { //不是快速查询
// 供应商名称
supplier_id := gjson.Get(info, "supplier_id").String()
supplier_name := ""
if supplier_id != "" {
supplier_name,_ = gredis.String(redisConn.Do("HGET","Self_SelfSupplierInfo",supplier_id))
}
A.Set("supplier_name", supplier_name)
//商品单位
goods_unit := gjson.Get(info, "goods_unit").String()
goods_unit_name := ""
if goods_unit != "" {
goods_unit_name,_ = gredis.String(redisConn.Do("HGET","Self_Unit",goods_unit))
}
A.Set("goods_unit_name", goods_unit_name)
//包装名称
packing := gjson.Get(info, "packing").String()
packing_name := ""
if packing != "" {
packing_name,_ = gredis.String(redisConn.Do("HGET","Self_Unit",packing))
}
A.Set("packing_name",packing_name) //
//mpq包装名称
mpq_unit_name := ""
if packing != "" {
mpq_unit_name,_ = gredis.String(redisConn.Do("HGET","Self_UnitAlias",packing))
}
A.Set("mpq_unit_name",mpq_unit_name) //
//图片
img := gjson.Get(info, "goods_images").String()
goods_images := ""
if img != "" {
goods_images,_ = gredis.String(redisConn.Do("HGET","Self_SelfGoodsSource",img))
}
A.Set("goods_images", goods_images) //
//图片
pdf := gjson.Get(info, "pdf").String()
if pdf != "" {
pdf,_ = gredis.String(redisConn.Do("HGET","Self_SelfGoodsSource",pdf))
}
A.Set("pdf", gjson.Get(info, "pdf").String())
}
A.Set("supplier_name", supplier_name)
// 供应商名称
goods_unit := gjson.Get(info, "goods_unit").String()
goods_unit_name := ""
if goods_unit_name != "" {
goods_unit_name,_ = gredis.String(redisConn.Do("HGET","Self_Unit",goods_unit))
}
A.Set("goods_unit_name", goods_unit_name) //
A.Set("packing_name", gjson.Get(info, "packing_name").String()) //
A.Set("mpq_unit_name", gjson.Get(info, "mpq_unit_name").String()) //
A.Set("scm_brand_name", gjson.Get(info, "scm_brand_name").String()) //
A.Set("actual_stock", gjson.Get(info, "actual_stock").String()) //
A.Set("ac_type", gjson.Get(info, "ac_type").String()) //
......@@ -111,26 +149,6 @@ func (qs *ZiyingService) ZyGoodsDetail(goodsIds []string,goodsRes *map[string]in
}
/*
计算单个sku总锁库数量
*/
func skuLockNum(c *redis.Conn,goodsId string) int64{
reply, err := redis.Values((*c).Do("hvals", "Self_StockLock"+goodsId))
if err != nil {
return 0;
}
var albums []int64
if err := redis.ScanSlice(reply, &albums); err != nil {
return 0;
}
if len(albums) == 0 {
return 0;
}else{
var all int64 = 0
for _,n := range albums {
all = all+n
}
return all
}
}
\ No newline at end of file
package service
import (
"github.com/gomodule/redigo/redis"
"github.com/syyongx/php2go"
"github.com/tidwall/gjson"
"goods_machining/middleware"
"goods_machining/pkg/gredis"
)
//自营公共函数类
/*
计算单个sku总锁库数量
*/
func (qs *ZiyingService) skuLockNum(c *redis.Conn,goodsId string) int64{
reply, err := redis.Values((*c).Do("hvals", "Self_StockLock"+goodsId))
if err != nil {
return 0;
}
var albums []int64
if err := redis.ScanSlice(reply, &albums); err != nil {
return 0;
}
if len(albums) == 0 {
return 0;
}else{
var all int64 = 0
for _,n := range albums {
all = all+n
}
return all
}
}
/*
获取自营活动价
*/
func (qs *ZiyingService) ActivityPrice(c *redis.Conn,goodsId string) map[string]string {
//新客价处理
if middleware.REQUEST["power[newCustomer]"] == "true" ||
middleware.REQUEST["power[newCustomer]"] == "1" {
goodsActivityPrice,_ := gredis.String((*c).Do("get","Self_ActivityPrice_10000_NewCustomer"))
if goodsActivityPrice != "" {
}
}
return nil
}
/*
计算活动价
ac_type说明: 0 没有活动
活动名称 ac_type 类型
限时限量活动 1 自营
活动价 2 自营 and 联营
会员价 3 自营 and 联营
折扣价(废除)4 自营 and 联营
新客价 5 自营 and 联营
自营系数 6 自营
团购价 7 联营
折扣价 8 自营 and 联营
*/
func (qs *ZiyingService) HDActivityPrice(GoodsActivityPrice string,SkuInfo string,Actype string) map[string]string{
Ratio := true //是否符合活动价
if Actype == "5" { //新客价
ratio_goods_id := gjson.Get(GoodsActivityPrice,"goods_id").String() //活动型号id
ratio_brand_id := gjson.Get(GoodsActivityPrice,"brand_id").String() //活动品牌id
ratio_class_id := gjson.Get(GoodsActivityPrice,"class_id").String() //活动分类id
//指定参与新客价型号
if ratio_goods_id != "" {
if php2go.Stripos(","+ratio_goods_id+",",","+gjson.Get(SkuInfo,"goods_id").String()+",",0) == -1 {
Ratio = false; //不符合新客价
goto End
}
}
//指定品牌
if ratio_brand_id != "" {
if php2go.Stripos(","+ratio_brand_id+",",","+gjson.Get(SkuInfo,"brand_id").String()+",",0) == -1 {
Ratio = false; //不符合新客价
goto End
}
}
//指定分类
if ratio_class_id != "" {
if php2go.Stripos(","+ratio_class_id+",",","+gjson.Get(SkuInfo,"class_id2").String()+",",0) == -1 {
Ratio = false; //不符合新客价
goto End
}
}
}else{
ratio_brand_id := gjson.Get(GoodsActivityPrice,"brand_id").String() //活动品牌id
if ratio_brand_id != "" { //
}
//php2go.InArray()
}
End: //最终执行
if Ratio {
}
return nil
}
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