Ejemplo n.º 1
0
func CheckOrderStatus() {
	os, err := orders.GetOrdersByStatus(3, DbMap)
	if err != nil {
		glog.V(1).Infof("Get Order with PaySuccess fail:%#v", err.Error())
		return
	}
	for _, o := range os {
		//HaoService api
		url := "http://apis.haoservice.com/lifeservice/exp?com=" + o.ShipCom.String + "&no=" + o.ShipNo.String + "&key=" + "798a8f4544184187a48eb9169d5d1ba5"
		resp, body, errs := gorequest.New().Get(url).EndBytes()
		if errs != nil {
			glog.V(1).Infof("Get Order Shipping info fail:%#v", err.Error())
		}

		if resp.StatusCode != 200 {
			glog.V(1).Infof("Get Order Shipping info fail:%#v", err.Error())
		}

		var content ShipInfo
		_ = json.Unmarshal(body, &content)

		if content.Result.IsCheck {
			_, err = orders.UpdateOrderFromStatusToStatus(o.Id.String, 3, 6, DbMap)
			if err != nil {
				glog.V(1).Infof("Update Order %v from Shipping to Completed fail:%#v", err.Error())
			}
		}
	}
}
Ejemplo n.º 2
0
func GetOrdersByStatus(r render.Render, dbmap *gorp.DbMap, params martini.Params, res http.ResponseWriter) {
	status := params["status"]
	var s int64
	if status == "Complete" {
		s = 6
	} else if status == "Paysuccess" {
		s = 5
	} else if status == "Payfail" {
		s = 4
	} else if status == "Shipping" {
		s = 3
	} else {
		r.JSON(http.StatusConflict, map[string]string{"message": "Not support status"})
		return
	}
	o, err := orders.GetOrdersByStatus(s, dbmap)
	if err != nil {
		glog.V(1).Infof("[DEBUG:] Search order by status %v fail:%v", status, err)
		r.JSON(http.StatusConflict, map[string]string{"message": "Order not exists"})
		return
	}
	r.JSON(200, o)
}