Commit 60c30781 by huangchengyi

1.0

parent 36950f81
package main
import (
"fmt"
"github.com/tidwall/gjson"
"reflect"
"math"
)
func main() {
fmt.Print(round(1.163,1))
return
json := `{"supplier_id":"10000","brand_id":[1,2],"start_time":1600790400,"end_time":1606492800,"ratio":"75","allow_coupon":1,"is_part":1,"visible_roster":"","sign_name":"","activity_ad":"","activity_id":86,"blacklist_type":null,"activity_type":"1","class_id":"","canal":""}`
s := gjson.Get(json,"brand_id").Array()
d := make([]string,0)
for _,a := range s {
c := a.String()
d = append(d,c)
fmt.Print(c,reflect.TypeOf(c))
}
//flag := php2go.InArray(1,d)
//flag := php2go.InArray("1",[]string{"1","2"})
// fmt.Print(d,flag)
}
/*
四舍五入取多少位
@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]
a := math.Floor(x*weishu + 0.5)/weishu
return a
}
......@@ -4,6 +4,7 @@ go 1.14
require (
github.com/denisenkom/go-mssqldb v0.0.0-20191124224453-732737034ffd // indirect
github.com/dgraph-io/badger v1.6.2 // indirect
github.com/elliotchance/orderedmap v1.3.0 // indirect
github.com/gin-contrib/cors v1.3.1
github.com/gin-gonic/gin v1.6.3
......
package model
import (
"goods_machining/pkg/config"
)
//获取需要排除的品牌id
//branType = 1 : 联营 2 : 自营
func GetExcludeBrandIds(brandType int) (excludeBrandIds []int) {
isNoTi := config.Get("BRAND.IS_NOT_TI").String()
//如果关闭,直接返回空数据
if isNoTi == "0" {
return
}
//返回联营的brand_id切片
if brandType == 1 {
tiLyBrandIds := config.Get("BRAND.TI_LY_BRAND_IDS").Ints(",")
excludeBrandIds = tiLyBrandIds
//获取的是字符串
return
}
//返回自营的ti的brand_id切片
tiZyBrandId := config.Get("BRAND.TI_ZY_BRAND_IDS").Ints(",")
excludeBrandIds = tiZyBrandId
return
}
package model
type ApiGoods struct {
PickType int `json:"pick_type,omitempty"`
BarCode string `json:"barcode,omitempty"`
GoodsId string `json:"goods_id"`
GoodsName string `json:"goods_name"`
GoodsSn string `json:"goods_sn"`
GoodsType int `json:"goods_type"`
GoodsStatus int `json:"goods_status"`
SupplierId int `json:"supplier_id"`
Moq int `json:"-"`
MoqStr interface{} `json:"moq"`
Mpq int `json:"-"`
MpqStr interface{} `json:"mpq"`
Mpl int `json:"-"`
MplStr interface{} `json:"mpl,omitempty"`
Stock int `json:"-"`
StockStr interface{} `json:"stock"`
HkDeliveryTime string `json:"hk_delivery_time"`
CnDeliveryTime string `json:"cn_delivery_time"`
LadderPrice []LadderPrice `json:"ladder_price"`
BrandName string `json:"brand_name"`
SupplierName string `json:"supplier_name"`
BrandId int `json:"brand_id"`
ClassId1 int `json:"class_id1"`
ClassId2 int `json:"class_id2"`
ClassName string `json:"class_name"`
Encoded string `json:"encoded"`
Packing string `json:"packing,omitempty"`
GoodsUnit string `json:"goods_unit,goods_unit"`
GoodsImages string `json:"goods_images"`
GoodsDetails string `json:"goods_details"`
GoodsBrief string `json:"goods_brief,omitempty"`
IsBuy int `json:"is_buy"`
Status int `json:"status"`
Pdf string `json:"pdf"`
Encap string `json:"encap"`
AcType int `json:"ac_type"`
OtherAttrs OtherAttrs `json:"other_attrs"`
UpdateTime int `json:"update_time"`
SkuName string `json:"sku_name,omitempty"`
Attrs Attrs `json:"attrs"`
Cost string `json:"cost,omitempty"`
NewCost string `json:"new_cost,omitempty"`
SupplierStock int `json:"supplier_stock,omitempty"`
SelfSupplierType int `json:"self_supplier_type,omitempty"`
GoodsUnitName string `json:"goods_unit_name,omitempty"`
PackingName string `json:"packing_name,omitempty"`
MpgUnitName string `json:"mpg_unit_name,omitempty"`
ScmBrandName string `json:"scm_brand_name,omitempty"`
AllowCoupon int `json:"allow_coupon"`
ClassId1Name string `json:"class_id1_name"`
CLassId2Name string `json:"class_id2_name"`
SpuId string `json:"spu_id,omitempty"`
BatchSn string `json:"batch_sn"`
Canal string `json:"canal"`
CpTime int `json:"cp_time"`
Coefficient Coefficient `json:"coefficient,omitempty"`
OriginalPrice []OriginalPrice `json:"original_price,omitempty"`
SuppExtendFee SuppExtendFee `json:"supp_extend_fee,omitempty"`
ClassId3 int `json:"class_id3"`
SpuName string `json:"spu_name,omitempty"`
ImagesL string `json:"images_l,omitempty"`
SpuBrief string `json:"spu_brief"`
SpuDetail string `json:"spu_detail"`
ClassName3 string `json:"class_name3"`
ErpTax bool `json:"erp_tax"`
ScmBrand ScmBrand `json:"scm_brand,omitempty"`
ActivityEndTime int64 `json:"activity_end_time,omitempty"`
//联营统一返回格式
type LyResponse struct {
ErrorCode int `json:"error_code"`
ErrorMsg string `json:"error_msg"`
Data interface{} `json:"data"`
}
type ZiyinGoodsInfo struct {
GoodsNameOrg string `json:"goods_name_org"`
SampleStatus string `json:"sample_status"`
SampleMaxNumber string `json:"sample_max_number"`
SampleClassId string `json:"sample_class_id"`
SampleClassIdName string `json:"sample_class_id_name"`
Quota int `json:"quota"`
DullGoodsData
}
//经过处理后的商品数据
type DullGoodsData struct {
ApiGoods
//额外增加的字段
GoodsNameTemp string `json:"goods_name_temp,omitempty"`
Multiple int `json:"-"`
MultipleStr interface{} `json:"multiple,omitempty"`
SupplierLogo string `json:"supplier_logo,omitempty"`
SupplierSort int `json:"supplier_sort,omitempty"`
SupplierAd interface{} `json:"supplier_ad"`
SearchSampleApplication string `json:"search_sample_application"`
SearchContactExperts string `json:"search_contact_experts"`
PageFlag int `json:"page_flag"`
SupplierWebsite string `json:"supplier_website"`
PurchaseName string `json:"purchase_name"`
Ratio int `json:"ratio"`
PriceXs float64 `json:"price_xs"`
PriceProfit float64 `json:"price_profit"`
PriceHkxs float64 `json:"price_hkxs"`
CouponId int `json:"coupon_id"`
CouponTitle string `json:"coupon_title"`
LastSearchTime int `json:"last_search_time"`
CustomsTax string `json:"customs_tax"`
Alike string `json:"alike"`
BrandUrl string `json:"brand_url"`
GoodsUrl string `json:"goods_url"`
CompanyName string `json:"-"`
ProviderName string `json:"-"`
}
type Attr struct {
AttrName string `json:"attr_name,omitempty"`
AttrValue string `json:"attr_value,omitempty"`
}
type Attrs map[string]Attr
type OtherAttrs struct {
GrossWeight string `json:"gross_weight,omitempty"`
}
//原始sku梯度
type LadderPrice struct {
Purchases int `json:"-"`
PurchasesStr interface{} `json:"purchases"`
PriceUs float64 `json:"price_us"`
PriceCn float64 `json:"price_cn"`
PriceAc float64 `json:"price_ac,omitempty"`
}
type Coefficient struct {
Cn float64 `json:"cn"`
Hk float64 `json:"hk"`
ExtraRatio float64 `json:"extra_ratio"`
Ratio float64 `json:"ratio"`
Tax float64 `json:"tax"`
}
type OriginalPrice struct {
Purchases int `json:"purchases"`
PriceCn float64 `json:"price_cn"`
PriceUs float64 `json:"price_us"`
}
type SuppExtendFee struct {
Cn struct {
Max int `json:"max"`
Price float64 `json:"price"`
} `json:"cn,omitempty"`
Hk struct {
Max int `json:"max"`
Price float64 `json:"price"`
} `json:"hk,omitempty"`
}
type ScmBrand struct {
ErpBrandName string `json:"erp_brand_name,omitempty"`
ErpBrandId string `json:"erp_brand_id,omitempty"`
ScmBrandId string `json:"scm_brand_id,omitempty"`
Purchases int64 `json:"purchases"` //购买数量
PriceUs float64 `json:"price_us"` //数量对应的英文价格
PriceCn float64 `json:"price_cn"` //数量对应的中文价格
PriceAc float64 `json:"price_ac"`
}
//立创价格梯度
type LadderPriceLc struct {
Purchases int64 `json:"purchases"` //购买数量
Price float64 `json:"price"` //立创价格,人民币
}
package model
//联营统一返回格式
type LyResponse struct {
ErrorCode int `json:"error_code"`
ErrorMsg string `json:"error_msg"`
Data interface{} `json:"data"`
}
//联营请求外链后格式化数据
type LyClearGoodsList struct {
SkuId string `json:"sku_id"` //平台型号id (非必填)
SpuId string `json:"spu_id"` //平台spuId (非必填)
BrandId string `json:"brand_id"` //平台品牌id (非必填)
GoodsName string `json:"goods_name"` //型号名称
BrandName string `json:"brand_name"` //品牌名称
Desc string `json:"desc"` //描述
BatchSn string `json:"batch_sn"` //批次号
GoodsSn string `json:"goods_sn"` //api唯一编码
Docurl string `json:"docurl"` //sku对应供应商的文档路径
Url string `json:"url"` //sku对应供应商的商品详情
GoodsImg string `json:"goods_img"` //sku图片
Cat string `json:"cat"` //分类
Encap string `json:"encap"` //包装
Canal string `json:"canal"` //渠道标签
Encoded string `json:"encoded"` //内部编码
RestrictionMessage string `json:"RestrictionMessage"` //额外购买限制内容,如 ‘当前商品不在本地区销售’
Increment int64 `json:"increment"` //最小包装量、倍数 =Mpq
SinglePrice float64 `json:"single_price"` //最小单价
Stock int64 `json:"stock"` //库存
Moq int64 `json:"moq"` //最小起订量、起订量
Packaging string `json:"Packaging"` //包装
RawGoodsId string `json:"raw_goods_id"` //外链原始goods_sn,如digikey:{'raw_goods_id': 'AT28C64X-25PC-ND', 'raw_brand_name': 'Microchip Technology'}
RawBrandName string `json:"raw_brand_name"` //外链原始品牌名称,如digikey:{'raw_goods_id': 'AT28C64X-25PC-ND', 'raw_brand_name': 'Microchip Technology'}
Tiered []*TierItem `json:"tiered"` //价格梯度数量
PriceTemp []interface{} `json:"price_temp"` //拼接梯度,目前只有联营推送队列用
DigiKeyPartNumber string `json:"DigiKeyPartNumber"` //digkey 唯一编码 (额外字段)
ManufacturerLeadWeeks string `json:"ManufacturerLeadWeeks"` //digikey交期(额外字段)
}
type TierItem struct {
Purchases int64 `json:"purchases"` //购买数量
PriceUs float64 `json:"price_us"` //数量对应的英文价格
PriceCn float64 `json:"price_cn"` //数量对应的中文价格
PriceAc float64 `json:"price_ac"`
}
//原始品牌(目前只有digikey使用)
type RawGoods struct {
RawGoodsId string `json:"raw_goods_id"` //原始goods_sn
RawBrandName string `json:"raw_brand_name"` //原始品牌名称
Pack string `json:"pack"` //包装
}
/*
供应商详情
Array
(
[supplier_id] => 4
[supplier_nickname] => tme
[ad_text] => 电子元器件、电工产品和工业自动化元件的全球分销商
[cn_delivery] => 5-9工作日
[hk_delivery] => 4-7工作日
[ad_url] => https://www.ichunt.com/
[sort] => 0
[supplier_logo] => http://img.ichunt.com/images/cms/201912/11/b2c4e3aae9a2312dfe6b9c318b430354.jpg
[status] => 1
[describe] => 电子元器件、电工产品和工业自动化元件的全球分销商
[price_json] => Array
(
[0] => Array
(
[hk] => 1.197
[cn] => 9.2534796
[rate] => 6.9
)
)
)
*/
type SUPPLIER_REDIS_INFO struct {
SupplierId int64 `json:"supplier_id"` //供应商id
SupplierNickname string `json:"supplier_nickname"` //供应商名称
AdText string `json:"ad_text"` //供应商描述
CnDelivery string `json:"cn_delivery"` //国内交货时间
HkDelivery string `json:"hk_delivery"` //香港交货时间
AdUrl string `json:"ad_url"` //供应商官网
Sort string `json:"sort"` //排序
SupplierLogo string `json:"supplier_logo"` //供应商logo
Status string `json:"status"` //状态,1开启
Describe string `json:"describe"` //描述
PriceJson []*PriceJsonItem //价格
}
type PriceJsonItem struct {
hk float64 //购买数量
cn float64 //数量对应的英文价格
rate float64 //数量对应的中文价格
}
/*
联营sku详情
Array
(
[spu_id] => 2.1540893752409E+18
[encoded] =>
[moq] => 624
[mpq] => 1
[old_goods_id] => 0
[goods_type] => 1
[goods_status] => 1
[batch_sn] =>
[stock] => 0
[hk_delivery_time] =>
[cn_delivery_time] =>
[update_time] => 1540967156
[goods_images] =>
[canal] =>
[supplier_id] => 10
[is_expire] => 1
[ladder_price] => Array
(
[0] => Array
(
[purchases] => 624
[price_cn] => 0
[price_us] => 13.42
)
[1] => Array
(
[purchases] => 6240
[price_cn] => 0
[price_us] => 12.12
)
[2] => Array
(
[purchases] => 624000
[price_cn] => 0
[price_us] => 2.383
)
)
)
*/
type LySkuInfo struct {
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
(
[class_id1] => 0
[class_id2] => 0
[class_id3] => 0
[brand_id] => 7087
[spu_name] => SI4704-D50-GM
[status] => 1
[images_l] =>
[encap] =>
[pdf] =>
[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 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"` //更新时间
}
......@@ -10,6 +10,8 @@ import (
"encoding/json"
"fmt"
"github.com/syyongx/php2go"
"github.com/tidwall/gjson"
"math"
"math/big"
"math/rand"
"reflect"
......@@ -24,6 +26,24 @@ import (
)
/*
gjson 判断某值是否存在 map
@param json string 分析json字符串
@param arrk string 分析的json键值转成map
@param targetk string 目标ID
*/
func GInArray(json string,arrK string,targetK string) bool{
s := gjson.Get(json,"brand_id").Array()
d := make([]string,0)
for _,a := range s {
c := a.String()
d = append(d,c)
fmt.Print(c,reflect.TypeOf(c))
}
return php2go.InArray(targetK,d)
}
/*
sha1加密(tme目前在用)
@param string query 查询字符串
@param string pri_key 加密字符串
......@@ -424,4 +444,26 @@ func MyInt64ToStr(numb int64) string {
func MyIntToStr(i int) string {
return strconv.Itoa(i)
}
/*
四舍五入取多少位
@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]
a := math.Floor(x*weishu + 0.5)/weishu
return a
}
////////////类型转换/////////////////////
\ No newline at end of file
......@@ -4,7 +4,10 @@ import (
"github.com/iancoleman/orderedmap"
"github.com/tidwall/gjson"
"goods_machining/middleware"
"goods_machining/model"
"goods_machining/pkg/common"
"goods_machining/pkg/gredis"
"strings"
"sync"
)
......@@ -40,26 +43,38 @@ func (qs *ZiyingService) ZyGoodsDetail(goodsIds []string,goodsRes *map[string]in
for goods_id,info := range skuArr {
//拼接梯度价格
ladder_price_arr := gjson.Get(info,"ladder_price").Array()
ladderPrice := make([]model.LadderPrice,0)
for _,v := range ladder_price_arr{
ladderPrice = append(ladderPrice, model.LadderPrice{
Purchases: v.Get("purchases").Int(),
PriceUs: v.Get("price_us").Float(),
PriceCn: v.Get("price_cn").Float(),
})
}
//数组
A := orderedmap.New() //初始化有序map,拼接data 数据
A.Set("goods_id",goods_id)
A.Set("goods_id",common.MyInt64(goods_id))
A.Set("goods_type", gjson.Get(info, "goods_type").Int()) //查询总条数
A.Set("supplier_id", gjson.Get(info, "supplier_id").String()) //查询总条数
A.Set("brand_id", gjson.Get(info, "brand_id").String()) //
A.Set("class_id1", gjson.Get(info, "class_id1").String()) //
A.Set("class_id2", gjson.Get(info, "class_id2").String()) //
A.Set("supplier_id", gjson.Get(info, "supplier_id").Int()) //查询总条数
A.Set("brand_id", gjson.Get(info, "brand_id").Int()) //
A.Set("class_id1", gjson.Get(info, "class_id1").Int()) //
A.Set("class_id2", gjson.Get(info, "class_id2").Int()) //
A.Set("goods_name", gjson.Get(info, "goods_name").String()) //
A.Set("status", gjson.Get(info, "status").Int()) //
A.Set("encoded", gjson.Get(info, "encoded").String()) //
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("packing", gjson.Get(info, "packing").Int()) //
A.Set("goods_unit", gjson.Get(info, "goods_unit").Int()) //
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()) //
A.Set("ladder_price", gjson.Get(info, "ladder_price").String()) //
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("moq", gjson.Get(info, "moq").Int()) //
A.Set("mpq", gjson.Get(info, "mpq").Int()) //
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()) //
//处理库存
lockStock := qs.skuLockNum(&redisConn,goods_id) //当前锁库库存
......@@ -70,8 +85,8 @@ func (qs *ZiyingService) ZyGoodsDetail(goodsIds []string,goodsRes *map[string]in
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()) //
A.Set("supplier_stock", gjson.Get(info, "supplier_stock").String()) //
A.Set("self_supplier_type", gjson.Get(info, "self_supplier_type").String()) //
A.Set("supplier_stock", gjson.Get(info, "supplier_stock").Int()) //
A.Set("self_supplier_type", gjson.Get(info, "self_supplier_type").Int()) //
//处理货期
cn_delivery_time := gjson.Get(info, "cn_delivery_time").String()
......@@ -133,17 +148,60 @@ func (qs *ZiyingService) ZyGoodsDetail(goodsIds []string,goodsRes *map[string]in
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()) //
A.Set("allow_coupon", gjson.Get(info, "allow_coupon").String()) //
A.Set("allow_presale", gjson.Get(info, "allow_presale").String()) //
A.Set("actual_stock", gjson.Get(info, "actual_stock").Int()) //
A.Set("ac_type", gjson.Get(info, "ac_type").Int()) //
A.Set("saler_atio", gjson.Get(info, "saler_atio").String()) //
A.Set("szlc_price", gjson.Get(info, "szlc_price").String()) //
A.Set("class_id1_name", gjson.Get(info, "class_id1_name").String()) //
A.Set("class_id2_name", gjson.Get(info, "class_id2_name").String()) //
A.Set("is_buy", gjson.Get(info, "is_buy").String()) //
//处理活动价
A.Set("ac_type",0)
A.Set("allow_coupon",1)
Ac_price := qs.ActivityPrice(info,&redisConn)
if Ac_price != nil {
keys := Ac_price.Keys()
for _, k := range keys {
v, _ := Ac_price.Get(k)
A.Set(k,v) //活动价格覆盖
}
}
//处理系数
ratio,_ := gredis.String(redisConn.Do("HGET","zy_ratio_sku",goods_id))
if ratio != "" {
//拼接梯度价格
for _,v := range ladderPrice{
v.PriceAc = gjson.Get(ratio,"price_ac").Float()
}
//获取立创价格
szlcPriceStr := `{"mykey":`+gjson.Get(ratio,"szlc_price").String()+`}`
ladder_price_arr := gjson.Get(szlcPriceStr,"mykey").Array()
ladderPriceLc := make([]model.LadderPriceLc,0)
for _,v := range ladder_price_arr{
ladderPriceLc = append(ladderPriceLc, model.LadderPriceLc{
Purchases: v.Get("Purchases").Int(),
Price: v.Get("price").Float(),
})
}
A.Set("allow_coupon",gjson.Get(ratio,"allow_coupon").String())
A.Set("allow_presale",gjson.Get(ratio,"allow_presale").String())
A.Set("szlc_price",ladderPriceLc)
}
//处理限额
goods_quota,_ := gredis.String(redisConn.Do("HGET","Self_goods_quota",goods_id))
if goods_quota != "" {
A.Set("is_quota",1)
A.Set("quota_num",gjson.Get(goods_quota,"num").Int())
}
//处理是否能购买
if gjson.Get(info, "status").String() != "1" ||
len(ladder_price_arr) == 0 {
A.Set("is_buy",0)
}else{
A.Set("is_buy",1)
}
(*goodsRes)[goods_id] = A
}
......
......@@ -2,9 +2,12 @@ package service
import (
"github.com/gomodule/redigo/redis"
"github.com/iancoleman/orderedmap"
"github.com/syyongx/php2go"
"github.com/tidwall/gjson"
"goods_machining/middleware"
"goods_machining/model"
"goods_machining/pkg/common"
"goods_machining/pkg/gredis"
)
//自营公共函数类
......@@ -35,18 +38,42 @@ func (qs *ZiyingService) skuLockNum(c *redis.Conn,goodsId string) int64{
/*
获取自营活动价
*/
func (qs *ZiyingService) ActivityPrice(c *redis.Conn,goodsId string) map[string]string {
//新客价处理
func (qs *ZiyingService) ActivityPrice(SkuInfo string,c *redis.Conn) *orderedmap.OrderedMap {
//新客价处理
if middleware.REQUEST["power[newCustomer]"] == "true" ||
middleware.REQUEST["power[newCustomer]"] == "1" {
goodsActivityPrice,_ := gredis.String((*c).Do("get","Self_ActivityPrice_10000_NewCustomer"))
if goodsActivityPrice != "" {
data := qs.HDActivityPrice(goodsActivityPrice,SkuInfo,"5")
if data != nil {
return data
}
}
}
//团购限制
data := qs.HDGoodsLimit(gjson.Get(SkuInfo,"goods_id").String(),gjson.Get(SkuInfo,"stock").String(),c)
if data != nil {
return data
}
//活动价
GoodsActivityPrice,_ := gredis.String((*c).Do("get","Self_ActivityPrice_10000"))
if GoodsActivityPrice != "" {
data := qs.HDActivityPrice(GoodsActivityPrice,SkuInfo,"2")
if data != nil {
return data
}
}
//会员价
GoodsActivityPrice,_ = gredis.String((*c).Do("get","Self_ActivityPrice_10000_Member"))
if GoodsActivityPrice != "" {
data := qs.HDActivityPrice(GoodsActivityPrice,SkuInfo,"3")
if data != nil {
return data
}
}
}
return nil
return nil
}
/*
......@@ -64,7 +91,12 @@ ac_type说明: 0 没有活动
折扣价 8 自营 and 联营
*/
func (qs *ZiyingService) HDActivityPrice(GoodsActivityPrice string,SkuInfo string,Actype string) map[string]string{
func (qs *ZiyingService) HDActivityPrice(GoodsActivityPrice string,SkuInfo string,Actype string) *orderedmap.OrderedMap {
visible_roster := gjson.Get(GoodsActivityPrice,"visible_roster").String()
activity_id := gjson.Get(GoodsActivityPrice,"activity_id").String()
is_part := gjson.Get(GoodsActivityPrice,"is_part").String()
activity_type := gjson.Get(GoodsActivityPrice,"activity_type").String()
Ratio := true //是否符合活动价
if Actype == "5" { //新客价
ratio_goods_id := gjson.Get(GoodsActivityPrice,"goods_id").String() //活动型号id
......@@ -93,18 +125,140 @@ func (qs *ZiyingService) HDActivityPrice(GoodsActivityPrice string,SkuInfo strin
}
}
}else{
ratio_brand_id := gjson.Get(GoodsActivityPrice,"brand_id").String() //活动品牌id
if ratio_brand_id != "" { //
if !common.GInArray(GoodsActivityPrice,"brand_id",gjson.Get(SkuInfo,"brand_id").String()) {
Ratio = false; //不符合活动价
goto End
}
if !common.GInArray(GoodsActivityPrice,"class_id",gjson.Get(SkuInfo,"class_id2").String()) {
Ratio = false; //不符合活动价
goto End
}
//会员价处理
if Actype == "3" && is_part == "1" && visible_roster != "" {
visible_roster = ","+visible_roster+","
if php2go.Stripos(visible_roster,","+middleware.REQUEST["power[user_id]"]+",",0) == -1 ||
php2go.Stripos(visible_roster,","+middleware.REQUEST["power[mobile]"]+",",0) == -1 ||
php2go.Stripos(visible_roster,","+middleware.REQUEST["power[email]"]+",",0) == -1 {
Ratio = false; //不符合新客价
goto End
}
}
//php2go.InArray()
//处理黑名单,只有折扣活动才有黑名单,并且是下单页面,debug
if Actype == "2" &&
activity_id != "" &&
activity_type == "2" &&
middleware.REQUEST["power[verify_blacklist]"] == "true" {
//redisConn := gredis.Conn("search_r")
//defer redisConn.Close();
//
//blacklist, _ := redis.String(redisConn.Do("hget", "activity_roster",activity_id+"_1"))
//blacklist_type := config.Cfg.Section("blacklist_type").KeysHash()
//
//blacklistArr := php2go.Explode(",",blacklist)
//for p,d := range blacklist_type {
//
// //backval,ok := blacklist_type[d]
//
// if php2go.Stripos(visible_roster,","+middleware.REQUEST["power[user_id]"]+",",0) == -1 {
// Ratio = false; //不符合新客价
// goto End
// }
//}
}
}
End: //最终执行
if Ratio {
discount_type := gjson.Get(GoodsActivityPrice,"discount_type").String()
ratio := gjson.Get(GoodsActivityPrice,"ratio").Float() //当前活动折扣
ladder_price_arr := gjson.Get(SkuInfo,"ladder_price").Array()
A := orderedmap.New();
ladderType := make([]model.LadderPrice,0)
for _,v := range ladder_price_arr{
if Actype != "7" || (Actype =="7" && discount_type != "") || discount_type == "1" {
price_cn := v.Get("price_cn").Float()
price_ac := php2go.Round(price_cn*ratio/100)
ladderType = append(ladderType, model.LadderPrice{
Purchases: v.Get("Purchases").Int(),
PriceUs: v.Get("price_us").Float(),
PriceCn: price_cn,
PriceAc: price_ac,
})
}
}
A.Set("ratio",ratio)
A.Set("ac_type",Actype)
A.Set("allow_coupon",ratio)
A.Set("activity_end_time",ratio)
A.Set("activity_info",ratio)
return A
}
return nil
}
/*
获取当前锁住的库存
*/
func (qs *ZiyingService) HDGoodsLimit(SkuID string,Stock string,c *redis.Conn) *orderedmap.OrderedMap {
GoodsLimit, _ := redis.String((*c).Do("get", "Self_GoodsLimit_"+SkuID))
if GoodsLimit == "" {
return nil
}
start_time := gjson.Get(GoodsLimit,"start_time").Int()
end_time := gjson.Get(GoodsLimit,"end_time").Int()
buy_stock := gjson.Get(GoodsLimit,"buy_stock").Float()
ac_stock := gjson.Get(GoodsLimit,"ac_stock").Float()
schedule := gjson.Get(GoodsLimit,"schedule").Float()
allow_coupon := gjson.Get(GoodsLimit,"allow_coupon").Int()
if start_time < php2go.Time() && end_time >php2go.Time() {
buy := buy_stock/ac_stock*100
schedule := common.MyRound(buy+schedule,2)
if schedule < 100 {
A := orderedmap.New();
//拼接梯度价格
ladder_price_arr := gjson.Get(GoodsLimit,"ac_price").Array()
ladderType := make([]model.LadderPrice,0)
for _,v := range ladder_price_arr{
ladderType = append(ladderType, model.LadderPrice{
Purchases: v.Get("Purchases").Int(),
PriceCn: v.Get("price_cn").Float(),
PriceAc: v.Get("price_ac").Float(),
})
}
now_stock := ac_stock*((100-schedule)/100)
A.Set("ac_type",1)
A.Set("ac_id",gjson.Get(GoodsLimit,"id").Int())
A.Set("ladder_price",ladderType)
A.Set("ac_stock",ac_stock)
A.Set("stock",now_stock)
A.Set("schedule",schedule)
A.Set("activity_end_time",end_time)
if allow_coupon >0 {
A.Set("allow_coupon",allow_coupon)
}else{
A.Set("allow_coupon",1)
}
//活动库存大于当前可售库存,强制结束活动
if now_stock > common.MyFloat64(Stock) || now_stock == 0 {
return nil
}
return A
}
}
return nil
}
......@@ -163,7 +163,7 @@ func (a *ZyCronService) ZyDiscount(checkGoodsId string) {
var ratioPrice float64;
ratioPrice = common.MyFloat64(a["cost"]) * common.MyFloat64(info["ratio"])
//查询立创数据
szlcPriceStr,_ := gredis.String(redisConn.Do("HGET","Self_szlc_price",now_goods_id)) //获取商品批次信息
szlcPriceStr,_ := gredis.String(redisConn.Do("HGET","Self_szlc_price",now_goods_id)) //获取立创价格
if szlcPriceStr != "" { //有立创的价格
nowLadder := gjson.Get(a["ladder_price"], "purchases").Array()
endnowLadder := nowLadder[len(nowLadder)-1].Get("purchases").Int() //最后一个梯度
......
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