//process post alipay return func AlipayReturn(r render.Render, req *http.Request, dbmap *gorp.DbMap, res http.ResponseWriter) { m, _ := url.ParseQuery(req.URL.RawQuery) params := map[string]string{} for k, v := range m { params[k] = v[0] } result := Return(params, req.URL.RawQuery) type OrderInfo struct { Result bool OrderId string GoodId string GoodCnt int64 Tel int64 Name string Addr string Sum float32 } var orderInfo OrderInfo orderInfo.Result = false if result.Status == -1 || result.Status == -5 || result.Status == -3 { r.HTML(400, "orderresult", orderInfo) return } o, err := orders.GetOrderById(result.OrderNo, dbmap) if err != nil { r.HTML(400, "orderresult", orderInfo) return } if result.Status != 1 { orders.UpdateOrderFromStatusToStatus(result.OrderNo, 2, 4, dbmap) r.HTML(400, "orderresult", orderInfo) return } _, err = orders.UpdateOrderFromStatusToStatus(result.OrderNo, 2, 5, dbmap) if err != nil { r.HTML(400, "orderresult", orderInfo) return } orderInfo.Result = true orderInfo.OrderId = o.Id.String orderInfo.GoodId = o.GoodId.String orderInfo.GoodCnt = o.GoodCnt orderInfo.Tel = o.CusTel orderInfo.Name = o.CusName.String orderInfo.Addr = o.CusAddr.String orderInfo.Sum = o.Sum //r.Status(200) r.HTML(200, "orderresult", orderInfo) return }
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()) } } } }
//process post alipay notify func AlipayNotify(r render.Render, req *http.Request, dbmap *gorp.DbMap, res http.ResponseWriter) { // Read the content var bodyBytes []byte if req.Body != nil { bodyBytes, _ = ioutil.ReadAll(req.Body) } // Restore the io.ReadCloser to its original state req.Body = ioutil.NopCloser(bytes.NewBuffer(bodyBytes)) // Use the content bodyString := string(bodyBytes) result := Notify(bodyString) if result.Status == -2 { //r.Status(400) js, _ := json.Marshal("error") res.Write(js) return } _, err := orders.GetOrderById(result.OrderNo, dbmap) if err != nil { js, _ := json.Marshal("error") res.Write(js) return } if result.Status != 1 { orders.UpdateOrderFromStatusToStatus(result.OrderNo, 2, 4, dbmap) js, _ := json.Marshal("error") res.Write(js) return } _, err = orders.UpdateOrderFromStatusToStatus(result.OrderNo, 2, 5, dbmap) if err != nil { js, _ := json.Marshal("error") res.Write(js) return } js, _ := json.Marshal("success") res.Write(js) return }
func PutOrderStatus(r render.Render, dbmap *gorp.DbMap, params martini.Params, res http.ResponseWriter) { orderid := params["id"] newstatuss := params["newstatus"] newstatus, err := strconv.ParseInt(newstatuss, 10, 64) if err != nil { r.JSON(http.StatusBadRequest, map[string]string{"message": "newstatus invalid"}) return } oldtatuss := params["oldstatus"] oldstatus, err := strconv.ParseInt(oldtatuss, 10, 64) if err != nil { r.JSON(http.StatusBadRequest, map[string]string{"message": "oldstatus invalid"}) return } o, err := orders.UpdateOrderFromStatusToStatus(orderid, oldstatus, newstatus, dbmap) if err != nil { r.JSON(http.StatusInternalServerError, map[string]string{"message": err.Error()}) return } r.JSON(http.StatusOK, o) }