- multi-task for stores in jd.SyncStoreSkus - calculate platform price use platform price_percentage. - GoodsOrder json StoreName.
134 lines
3.6 KiB
Go
134 lines
3.6 KiB
Go
package jxutils
|
||
|
||
import (
|
||
"fmt"
|
||
"math"
|
||
"reflect"
|
||
"strings"
|
||
"time"
|
||
|
||
"git.rosy.net.cn/baseapi/utils"
|
||
)
|
||
|
||
// 合并得到最终的门店状态
|
||
func MergeStoreStatus(status int, vendorStatus int) int {
|
||
if status < vendorStatus {
|
||
return status
|
||
}
|
||
return vendorStatus
|
||
}
|
||
|
||
func MergeSkuStatus(skuStatus int, storeSkuStatus int) int {
|
||
if skuStatus < storeSkuStatus {
|
||
return skuStatus
|
||
}
|
||
return storeSkuStatus
|
||
}
|
||
|
||
func SplitSlice(list interface{}, batchCount int) (listInList [][]interface{}) {
|
||
typeInfo := reflect.TypeOf(list)
|
||
if typeInfo.Kind() != reflect.Slice {
|
||
panic("list must be slice")
|
||
}
|
||
valueInfo := reflect.ValueOf(list)
|
||
len := valueInfo.Len()
|
||
if len > 0 {
|
||
listInListLen := (len-1)/batchCount + 1
|
||
listInList = make([][]interface{}, listInListLen)
|
||
index := 0
|
||
for i := 0; i < len; i++ {
|
||
if i%batchCount == 0 {
|
||
index = i / batchCount
|
||
arrLen := len - i
|
||
if arrLen > batchCount {
|
||
arrLen = batchCount
|
||
}
|
||
listInList[index] = make([]interface{}, arrLen)
|
||
}
|
||
listInList[index][i%batchCount] = valueInfo.Index(i).Interface()
|
||
}
|
||
}
|
||
return listInList
|
||
}
|
||
|
||
func SplitStoreName(fullName, separator, defaultPrefix string) (prefix, bareName string) {
|
||
names := strings.Split(fullName, separator)
|
||
if len(names) == 2 {
|
||
prefix = names[0]
|
||
bareName = names[1]
|
||
} else {
|
||
prefix = defaultPrefix
|
||
bareName = strings.Trim(strings.Trim(fullName, defaultPrefix), separator)
|
||
|
||
}
|
||
return utils.TrimBlanChar(defaultPrefix), utils.TrimBlanChar(bareName)
|
||
}
|
||
|
||
func ComposeStoreName(bareName, separator, prefix string) (fullName string) {
|
||
return prefix + separator + utils.TrimBlanChar(strings.Trim(bareName, separator))
|
||
}
|
||
|
||
func StrTime2JxOperationTime(strTime string, defValue int16) int16 {
|
||
if timeValue, err := time.Parse("15:04:05", strTime); err == nil {
|
||
return int16(timeValue.Hour()*100 + timeValue.Minute())
|
||
}
|
||
return defValue
|
||
}
|
||
|
||
func JxOperationTime2StrTime(value int16) string {
|
||
return fmt.Sprintf("%02d:%02d", value/100, value%100)
|
||
}
|
||
|
||
func GetPolygonFromCircle(lng, lat, distance float64, pointCount int) (points [][2]float64) {
|
||
points = make([][2]float64, pointCount)
|
||
for k := range points {
|
||
angle := float64(k) * 360 / float64(pointCount)
|
||
points[k][0], points[k][1] = ConvertDistanceToLogLat(lng, lat, float64(distance), angle)
|
||
}
|
||
return points
|
||
}
|
||
|
||
func GetPolygonFromCircleStr(lng, lat, distance float64, pointCount int) string {
|
||
points := GetPolygonFromCircle(lng, lat, distance, pointCount)
|
||
points2 := make([]string, len(points))
|
||
for k, v := range points {
|
||
points2[k] = fmt.Sprintf("%.6f,%.6f", v[0], v[1])
|
||
}
|
||
return strings.Join(points2, ";")
|
||
}
|
||
|
||
func ConvertDistanceToLogLat(lng, lat, distance, angle float64) (newLng, newLat float64) {
|
||
oneDu := 111319.55
|
||
newLng = lng + (distance*math.Sin(angle*math.Pi/180))/(oneDu*math.Cos(lat*math.Pi/180)) //将距离转换成经度的计算公式
|
||
newLat = lat + (distance*math.Cos(angle*math.Pi/180))/oneDu //将距离转换成纬度的计算公式
|
||
return newLng, newLat
|
||
}
|
||
|
||
func IntMap2List(intMap map[int]int) []int {
|
||
retVal := make([]int, len(intMap))
|
||
index := 0
|
||
for k := range intMap {
|
||
retVal[index] = k
|
||
}
|
||
return retVal
|
||
}
|
||
|
||
// 计算SKU价格,unitPrice为一斤的单价,specQuality为质量,单位为克
|
||
func CaculateSkuPrice(unitPrice int, specQuality float32, specUnit string, skuNameUnit string) int {
|
||
if skuNameUnit != "份" {
|
||
return unitPrice
|
||
}
|
||
if strings.ToLower(specUnit) == "kg" {
|
||
specQuality *= 1000
|
||
}
|
||
return int(math.Round(float64(float32(unitPrice) * specQuality / 500)))
|
||
}
|
||
|
||
func GetSliceLen(list interface{}) int {
|
||
return reflect.ValueOf(list).Len()
|
||
}
|
||
|
||
func CaculateSkuVendorPrice(price int, percentage int) int {
|
||
return price * percentage / 100
|
||
}
|