/// <summary> /// 创建达达订单 /// </summary> /// <param name="order"></param> /// <returns></returns> public async Task <DadaResult <DadaReturn> > SendOrderAsync(Order order, Business business) { var dadaOrder = new DadaOrder(); if (_appData.RunMode == "test") { dadaOrder.shop_no = _appData.DadaShopNo; } else { dadaOrder.shop_no = business.DadaShopNo; } dadaOrder.origin_id = order.OrderCode; dadaOrder.city_code = order.CityCode; dadaOrder.cargo_price = (double)order.Price; dadaOrder.receiver_name = order.GetUserCall(); dadaOrder.receiver_address = order.ReceiverAddress; dadaOrder.receiver_lat = order.Lat; dadaOrder.receiver_lng = order.Lng; dadaOrder.callback = _appData.DadaCallback; dadaOrder.receiver_phone = order.Phone; dadaOrder.origin_mark_no = order.Identifier.ToString(); var url = order.IsSendDada ? "/api/order/reAddOrder" : "/api/order/addOrder"; return(await RequestAsync <DadaReturn>(url, dadaOrder, business.DadaSourceId)); }
/// <summary> /// 创建订单 /// </summary> /// <returns></returns> public ActionResult AddOrder() { string sourceid = Context.GetRequest("sourceid", "73753"); string shop_no = Context.GetRequest("shop_no", "11047059"); string order_id = Context.GetRequest("order_id", ""); int raddorder = Context.GetRequestInt("raddorder", 0); _dadaApi._sourceid = sourceid; _dadaApi._shop_no = shop_no; DadaOrder data = new DadaOrder() { shop_no = _dadaApi._shop_no, origin_id = order_id, city_code = "123456", cargo_price = 20.01f, is_prepay = 1, expected_fetch_time = _dadaApi.GetTimeStamp(), receiver_name = "ceshi", receiver_address = "ceshi", receiver_lat = 20.12548, receiver_lng = 120.548565, callback = _dadaApi._ordercallback, insurance_fee = 0, receiver_phone = "18718463809", receiver_tel = "18718463809", tips = 1, info = "测试", cargo_type = 1, cargo_weight = 1.1, cargo_num = 1, invoice_title = "", deliver_locker_code = "", pickup_locker_code = "", origin_mark = "", origin_mark_no = "", is_finish_code_needed = 0, delay_publish_time = 0 }; string json = _dadaApi.PostParamJson(data); string url = _dadaApi._addorderapi; if (raddorder == 1) { url = _dadaApi._readdorderapi; } else if (raddorder == 2) { url = _dadaApi._querydeliverfeeorderapi; } string result = WxHelper.DoPostJson(url, json); if (!string.IsNullOrEmpty(result)) { DadaApiReponseModel <ResultReponseModel> reposemodel = JsonConvert.DeserializeObject <DadaApiReponseModel <ResultReponseModel> >(result); if (raddorder == 2) { RedisUtil.Set("dada_key_" + order_id, reposemodel.result.deliveryNo, TimeSpan.FromMinutes(3)); } } return(Json(new { isok = true, msg = result }, JsonRequestBehavior.AllowGet)); }
/// <summary> /// 修改订单状态 /// </summary> /// <returns></returns> public ActionResult UpdateDadaOrderState() { string order_id = Context.GetRequest("order_id", ""); string merchantid = Context.GetRequest("merchantid", string.Empty); int state = Context.GetRequestInt("state", -1); int cancel_reason_id = Context.GetRequestInt("cancel_reason_id", 0); string cancel_reason = Context.GetRequest("cancel_reason", string.Empty); if (string.IsNullOrEmpty(merchantid)) { return(Json(new { isok = false, msg = "找不到商户号" }, JsonRequestBehavior.AllowGet)); } if (state == -1) { return(Json(new { isok = false, msg = "订单状态出错" }, JsonRequestBehavior.AllowGet)); } //DadaOrderRelation orelationmodel = _dadaOrderRelationBll.GetModelUOrderNo(order_id); //if (orelationmodel == null) //{ // return Json(new { isok = false, msg = "找不到系统订单,请刷新重试" }, JsonRequestBehavior.AllowGet); //} DadaOrder ordermodel = _dadaOrderBll.GetModelByOrderNo(order_id); if (ordermodel == null || !(ordermodel.state == (int)DadaOrderEnum.待接单 || ordermodel.state == (int)DadaOrderEnum.待取货)) { return(Json(new { isok = false, msg = "找不到系统订单,请刷新重试" }, JsonRequestBehavior.AllowGet)); } _dadaApi._sourceid = merchantid; object data = new object(); string url = string.Empty; switch (state) { case 0: //取消订单 data = new { order_id = order_id, cancel_reason_id = cancel_reason_id, cancel_reason = cancel_reason }; url = _dadaApi._cancelorderapi; break; } string json = _dadaApi.PostParamJson(data); string result = WxHelper.DoPostJson(url, json); if (!string.IsNullOrEmpty(result)) { DadaApiReponseModel <ResultReponseModel> resultmodel = JsonConvert.DeserializeObject <DadaApiReponseModel <ResultReponseModel> >(result); if (resultmodel.status == "success") { ordermodel.state = (int)DadaOrderEnum.取消中; ordermodel.update_time = DateTime.Now; if (!_dadaOrderBll.Update(ordermodel, "state")) { return(Json(new { isok = false, msg = "更新订单状态失败" }, JsonRequestBehavior.AllowGet)); } } return(Json(new { isok = true, msg = resultmodel.msg }, JsonRequestBehavior.AllowGet)); } return(Json(new { isok = false, msg = "系统繁忙" }, JsonRequestBehavior.AllowGet)); }
/// <summary> /// 达达订单状态改变回调接口 /// </summary> /// <param name="orderform"></param> /// <returns></returns> public ActionResult Dadanotis(OrderReponseModel orderform) { if (orderform == null) { LogHelper.WriteInfo(this.GetType(), "达达订单回调请求参数为空"); return(Content("fail")); } DadaOrder order = _dadaOrderBLL.GetModelByOrderNo(orderform.order_id); if (order == null) { LogHelper.WriteInfo(this.GetType(), $"达达订单回调:找不到订单【{orderform.order_id}】"); } //如果状态一样,说明已发送过一次 if (order.state == orderform.order_status) { return(Content("success")); } order.state = orderform.order_status; order.update_time = _dadaApi.GetDateTimeByStamp(orderform.update_time); order.cancel_from = orderform.cancel_from; order.cancel_reason = orderform.cancel_reason; order.dm_id = orderform.dm_id; order.dm_mobile = orderform.dm_mobile; order.dm_name = orderform.dm_name; DadaOrderRelation oRelationModel = DadaOrderRelationBLL.SingleModel.GetModelUOrderNo(order.origin_id); if (oRelationModel == null) { LogHelper.WriteInfo(this.GetType(), "达达配送回调查询达达订单管理数据出错:" + order.origin_id); return(Content("fail")); } XcxAppAccountRelation xcxrelation = _xcxAppAccountRelationBLL.GetModel(oRelationModel.dataid); if (xcxrelation == null) { LogHelper.WriteInfo(this.GetType(), "达达配送回调查询权限表:没有找到ID【" + oRelationModel.dataid + "】数据"); return(Content("fail")); } bool isSuccess = false; try { lock (_dadaLock) { switch (oRelationModel.ordertype) { case (int)TmpType.小程序餐饮模板: isSuccess = _dadaOrderBLL.DadaToFoodReturn(oRelationModel.orderid, order, xcxrelation.AppId); break; case (int)TmpType.智慧餐厅: isSuccess = _dadaOrderBLL.DadaToMutilFoodReturn(oRelationModel.orderid, order, xcxrelation.AppId); break; } } } catch (Exception ex) { LogHelper.WriteInfo(this.GetType(), "达达配送回调异常:" + JsonConvert.SerializeObject(orderform) + ex.Message); } return(Content("success")); }