|
|
@ -0,0 +1,246 @@ |
|
|
|
package productrpc |
|
|
|
|
|
|
|
import ( |
|
|
|
"encoding/json" |
|
|
|
"log" |
|
|
|
"sort" |
|
|
|
"strconv" |
|
|
|
|
|
|
|
// "strconv"
|
|
|
|
// "time"
|
|
|
|
"git.tetele.net/tgo/helper" |
|
|
|
) |
|
|
|
|
|
|
|
/** |
|
|
|
* 获取商品进行中活动 |
|
|
|
* 2021/10/06 |
|
|
|
* GZ |
|
|
|
*/ |
|
|
|
func GetProductActivity(site_id, dbname, id string, url ...string) ([]map[string]string, error) { |
|
|
|
|
|
|
|
conn, err := rpc_server_conn(url...) |
|
|
|
if err != nil { |
|
|
|
return nil, err |
|
|
|
} |
|
|
|
defer conn.Close() |
|
|
|
|
|
|
|
arg := GetActivityParam{site_id, dbname, id, "0"} |
|
|
|
|
|
|
|
req, err := SetReqData(arg) |
|
|
|
if err != nil { |
|
|
|
return nil, err |
|
|
|
} |
|
|
|
|
|
|
|
res := &Response{} |
|
|
|
|
|
|
|
err = conn.GetProductActivity(req, res) |
|
|
|
|
|
|
|
if err != nil { |
|
|
|
return nil, err |
|
|
|
} |
|
|
|
|
|
|
|
res_data_de, err := GetResData(res) |
|
|
|
if err != nil { |
|
|
|
return nil, err |
|
|
|
} |
|
|
|
if res_data_de == "" { |
|
|
|
return nil, nil |
|
|
|
} |
|
|
|
var res_arr []map[string]string |
|
|
|
|
|
|
|
err = json.Unmarshal([]byte(res_data_de), &res_arr) |
|
|
|
|
|
|
|
if err != nil { |
|
|
|
return nil, err |
|
|
|
} |
|
|
|
|
|
|
|
var activitys Activitys |
|
|
|
|
|
|
|
if len(res_arr) > 0 { |
|
|
|
var start int |
|
|
|
|
|
|
|
for _, item := range res_arr { |
|
|
|
start, err = strconv.Atoi(item["Starttime"]) |
|
|
|
if err != nil { |
|
|
|
log.Println(err) |
|
|
|
} |
|
|
|
activitys = append(activitys, Activity{ |
|
|
|
Id: item["Id"], |
|
|
|
Start: start, |
|
|
|
}) |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
sort.Sort(activitys) |
|
|
|
|
|
|
|
var list []map[string]string = make([]map[string]string, 0) |
|
|
|
|
|
|
|
if len(activitys) > 0 { |
|
|
|
for _, v := range activitys { |
|
|
|
for _, old := range res_arr { |
|
|
|
if v.Id == old["Id"] { |
|
|
|
list = append(list, old) |
|
|
|
break |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
return list, nil |
|
|
|
} |
|
|
|
|
|
|
|
/** |
|
|
|
* 获取商品预热中活动 |
|
|
|
* 2021/10/06 |
|
|
|
* GZ |
|
|
|
*/ |
|
|
|
func GetProductWarmingActivity(site_id, dbname, id string, url ...string) ([]map[string]string, error) { |
|
|
|
|
|
|
|
conn, err := rpc_server_conn(url...) |
|
|
|
if err != nil { |
|
|
|
return nil, err |
|
|
|
} |
|
|
|
defer conn.Close() |
|
|
|
|
|
|
|
arg := GetActivityParam{site_id, dbname, id, "0"} |
|
|
|
|
|
|
|
req, err := SetReqData(arg) |
|
|
|
if err != nil { |
|
|
|
return nil, err |
|
|
|
} |
|
|
|
|
|
|
|
res := &Response{} |
|
|
|
|
|
|
|
err = conn.GetProductWarmingActivity(req, res) |
|
|
|
|
|
|
|
if err != nil { |
|
|
|
return nil, err |
|
|
|
} |
|
|
|
|
|
|
|
res_data_de, err := GetResData(res) |
|
|
|
if err != nil { |
|
|
|
return nil, err |
|
|
|
} |
|
|
|
if res_data_de == "" { |
|
|
|
return nil, nil |
|
|
|
} |
|
|
|
var res_arr []map[string]string |
|
|
|
|
|
|
|
err = json.Unmarshal([]byte(res_data_de), &res_arr) |
|
|
|
|
|
|
|
if err != nil { |
|
|
|
return nil, err |
|
|
|
} |
|
|
|
|
|
|
|
var activitys Activitys |
|
|
|
|
|
|
|
if len(res_arr) > 0 { |
|
|
|
var start int |
|
|
|
|
|
|
|
for _, item := range res_arr { |
|
|
|
start, err = strconv.Atoi(item["Starttime"]) |
|
|
|
if err != nil { |
|
|
|
log.Println(err) |
|
|
|
} |
|
|
|
activitys = append(activitys, Activity{ |
|
|
|
Id: item["Id"], |
|
|
|
Start: start, |
|
|
|
}) |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
sort.Sort(activitys) |
|
|
|
|
|
|
|
var list []map[string]string = make([]map[string]string, 0) |
|
|
|
|
|
|
|
if len(activitys) > 0 { |
|
|
|
for _, v := range activitys { |
|
|
|
for _, old := range res_arr { |
|
|
|
if v.Id == old["Id"] { |
|
|
|
list = append(list, old) |
|
|
|
break |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
return list, nil |
|
|
|
} |
|
|
|
|
|
|
|
/** |
|
|
|
* 获取商品进行中活动 |
|
|
|
* 2021/10/06 |
|
|
|
* GZ |
|
|
|
*/ |
|
|
|
func GetProductAllActivity(site_id, dbname, id string, url ...string) ([]map[string]interface{}, error) { |
|
|
|
|
|
|
|
conn, err := rpc_server_conn(url...) |
|
|
|
if err != nil { |
|
|
|
return nil, err |
|
|
|
} |
|
|
|
defer conn.Close() |
|
|
|
|
|
|
|
arg := GetActivityParam{site_id, dbname, id, "0"} |
|
|
|
|
|
|
|
req, err := SetReqData(arg) |
|
|
|
if err != nil { |
|
|
|
return nil, err |
|
|
|
} |
|
|
|
|
|
|
|
res := &Response{} |
|
|
|
|
|
|
|
err = conn.GetProductAllActivity(req, res) |
|
|
|
|
|
|
|
if err != nil { |
|
|
|
return nil, err |
|
|
|
} |
|
|
|
|
|
|
|
res_data_de, err := GetResData(res) |
|
|
|
|
|
|
|
if err != nil { |
|
|
|
return nil, err |
|
|
|
} |
|
|
|
if res_data_de == "" { |
|
|
|
return nil, nil |
|
|
|
} |
|
|
|
var res_arr []map[string]interface{} |
|
|
|
|
|
|
|
err = json.Unmarshal([]byte(res_data_de), &res_arr) |
|
|
|
|
|
|
|
if err != nil { |
|
|
|
log.Println(err) |
|
|
|
return nil, err |
|
|
|
} |
|
|
|
|
|
|
|
var activitys Activitys |
|
|
|
|
|
|
|
if len(res_arr) > 0 { |
|
|
|
var start int |
|
|
|
|
|
|
|
for _, item := range res_arr { |
|
|
|
start = helper.ToInt(item["starttime"]) |
|
|
|
|
|
|
|
activitys = append(activitys, Activity{ |
|
|
|
Id: helper.ToStr(item["id"]), |
|
|
|
Start: start, |
|
|
|
}) |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
sort.Sort(activitys) |
|
|
|
|
|
|
|
var list []map[string]interface{} = make([]map[string]interface{}, 0) |
|
|
|
|
|
|
|
if len(activitys) > 0 { |
|
|
|
for _, v := range activitys { |
|
|
|
for _, old := range res_arr { |
|
|
|
if v.Id == helper.ToStr(old["id"]) { |
|
|
|
list = append(list, old) |
|
|
|
break |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
return list, nil |
|
|
|
} |