商品rpc数据格式及调用方法
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

81 lines
2.6 KiB

package productrpc
import (
"strconv"
"time"
)
/*
* 检查商品状态
* 2020/09/16
*/
func CheckStatus(productInfo map[string]string, arrival_time string) (int, string) {
if productInfo["Status"] == "0" { //是否在售
return 8405, "商品已下架"
if productInfo["Status"] == "2" { //是否在售
return 8405, "商品已售罄"
}
}
if productInfo["Status"] != "1" { //是否在售
return 8405, "商品未上架"
}
if productInfo["AutoOnSale"] == "1" {
if productInfo["EndSaleTime"] != "0" && productInfo["EndSaleTime"] != "" { //销售截止日期
end_sale_time, _ := strconv.ParseInt(productInfo["EndSaleTime"], 10, 64)
if time.Unix(end_sale_time, 0).Before(time.Now()) { //截止日期在当前时间之前
return 8407, "商品已过有效期"
}
}
if productInfo["StartSaleTime"] != "0" && productInfo["StartSaleTime"] != "" { //销售开始日期
end_sale_time, _ := strconv.ParseInt(productInfo["StartSaleTime"], 10, 64)
if time.Unix(end_sale_time, 0).After(time.Now()) { //开始日期在当前时间之后
return 8406, "商品未开售"
}
}
}
if productInfo["ValidityType"] == "1" { //用户选定使用日期
if arrival_time == "" {
return 10005, "请选择使用日期"
} else {
advance, _ := strconv.Atoi(productInfo["Advance"]) //提前几天
arrival_time_int64, err := strconv.ParseInt(arrival_time, 10, 64)
var release_time_int64, end_time_int64 int64 = 0, 0
now := time.Now().Unix()
if err != nil { // 转换失败
return 10005, "日期错误"
}
if arrival_time_int64 < now { //不能在当前时间之前
return 10005, "日期选择错误"
}
if productInfo["Releasetime"] != "" && productInfo["Releasetime"] != "0" {
release_time_int64, _ = strconv.ParseInt(productInfo["Releasetime"], 10, 64)
}
if productInfo["Endtime"] != "" && productInfo["Endtime"] != "0" {
end_time_int64, err = strconv.ParseInt(productInfo["Endtime"], 10, 64)
if err == nil {
if advance > 0 {
end_time_int64 = end_time_int64 - int64(advance*24*3600) //提前几天截止预约
if end_time_int64 < now {
return 8409, "已截止购买"
}
}
}
}
if release_time_int64 > 0 && arrival_time_int64 < release_time_int64 { //未到服务时间
return 10006, "请选择" + time.Unix(release_time_int64, 0).Format("2006-01-02") + "之后的日期"
}
if end_time_int64 > 0 {
if arrival_time_int64 > end_time_int64 { //已过服务时间
return 10006, "请选择" + time.Unix(end_time_int64, 0).Format("2006-01-02") + "之前的日期"
}
}
}
}
return 0, ""
}