コード例 #1
0
        /// <summary>
        /// 蜂鸟推单
        /// </summary>
        /// <param name="data">订单</param>
        /// <returns></returns>
        public FNApiReponseModel <object> AddOrderToFN(FNOrder data)
        {
            FNApiReponseModel <object> reposemodel = new FNApiReponseModel <object>();

            string url    = FNApi._addorderapi;
            string result = FNApi.SingleModel.UseFNApi(data, url);

            if (!string.IsNullOrEmpty(result))
            {
                reposemodel = JsonConvert.DeserializeObject <FNApiReponseModel <object> >(result);
            }

            return(reposemodel);
        }
コード例 #2
0
        /// <summary>
        /// 获取修改蜂鸟订单状态sql
        /// </summary>
        /// <param name="orderid">小程序订单表ID</param>
        /// <param name="rid"></param>
        /// <param name="ordertype">TmpType枚举</param>
        /// <param name="tran"></param>
        /// <returns></returns>
        public string GetFNOrderUpdateSql(int orderid, int rid, int ordertype, ref TransactionModel tran, bool gettransql = false)
        {
            FNOrderRelation model = FNOrderRelationBLL.SingleModel.GetModelOrder(rid, orderid, ordertype);

            if (model == null)
            {
                return("没有找到蜂鸟订单关联数据");
            }

            FNOrder order = GetModelByOrderNo(model.uniqueorderno);

            if (order == null)
            {
                return("蜂鸟订单不存在");
            }

            FNApiReponseModel <object> result = AddOrderToFN(order);

            if (result == null)
            {
                return("蜂鸟新增订单接口异常");
            }

            if (result.code == 200)
            {
                order.state = (int)FNOrderEnum.推单中;

                if (gettransql)
                {
                    return(base.ExecuteNonQuery($"update fnorder set state={order.state},updatetime=now() where id={order.id}") > 0 ? "" : "修改蜂鸟订单状态出错");
                }
                else
                {
                    tran.Add($"update fnorder set state={order.state},updatetime=now() where id={order.id}");
                }

                return("");
            }

            return(result.msg);
        }
コード例 #3
0
        public DistributionApiConfig GetModelByRedis(string appid)
        {
            string key = string.Format(_eleapi_token_key, appid);
            DistributionApiConfig model = RedisUtil.Get <DistributionApiConfig>(key);

            if (model == null)
            {
                model = GetModel($"app_id='{appid}'");
                if (model == null)
                {
                    log4net.LogHelper.WriteInfo(this.GetType(), "蜂鸟配送获取配置出错,找不到配置");
                    return(new DistributionApiConfig());
                }
            }

            try
            {
                //判断token是否已失效
                if (model.updatetime.AddMinutes(model.refreshtime) < DateTime.Now || string.IsNullOrEmpty(model.access_token))
                {
                    //获取token接口链接
                    string tokenurl = FNApi.SingleModel.GetTokenApiUrl();
                    string result   = HttpHelper.GetData(tokenurl);
                    if (string.IsNullOrEmpty(result))
                    {
                        log4net.LogHelper.WriteInfo(this.GetType(), "获取蜂鸟配送获token出错,返回值:" + result);
                        return(new DistributionApiConfig());
                    }

                    FNApiReponseModel <DistributionApiConfig> eleModel = JsonConvert.DeserializeObject <FNApiReponseModel <DistributionApiConfig> >(result);
                    if (eleModel.code != 200 || eleModel.data == null)
                    {
                        log4net.LogHelper.WriteInfo(this.GetType(), "获取蜂鸟配送获token出错,返回值:" + result);
                        return(new DistributionApiConfig());
                    }

                    //保存token
                    DistributionApiConfig tempModel = eleModel.data;
                    if (tempModel != null)
                    {
                        if (model == null || model.id <= 0)
                        {
                            tempModel.addtime     = DateTime.Now;
                            tempModel.updatetime  = DateTime.Now;
                            tempModel.refreshtime = 60;
                            base.Add(tempModel);
                            model = tempModel;
                        }
                        else
                        {
                            model.access_token = tempModel.access_token;
                            model.expire_time  = tempModel.expire_time;
                            model.updatetime   = DateTime.Now;
                            base.Update(model, "access_token,expire_time,updatetime");
                        }
                        RedisUtil.Set <DistributionApiConfig>(key, model, TimeSpan.FromMinutes(model.refreshtime));
                    }
                }
            }
            catch (Exception ex)
            {
                log4net.LogHelper.WriteError(this.GetType(), ex);
                return(new DistributionApiConfig());
            }

            return(model);
        }
コード例 #4
0
        /// <summary>
        /// 取消订单
        /// </summary>
        /// <returns></returns>
        public ActionResult CancelFNOrder()
        {
            string orderid       = Context.GetRequest("orderid", string.Empty);
            string orderno       = Context.GetRequest("orderno", string.Empty);
            int    cancelcode    = Context.GetRequestInt("cancel_reason_id", 0);
            string cancel_reason = Context.GetRequest("cancel_reason", string.Empty);

            object data = new FNCancelOrderRequestModel()
            {
                partner_order_code       = orderno,
                order_cancel_reason_code = 2,
                order_cancel_code        = cancelcode,
                order_cancel_description = cancel_reason,
                order_cancel_time        = Convert.ToInt64(FNApi.SingleModel.GetTimeStamp()),
            };
            string url    = FNApi._cancelorderapi;
            string result = FNApi.SingleModel.UseFNApi(data, url);

            if (string.IsNullOrEmpty(result))
            {
                return(Json(new { isok = false, msg = "取消订单失败" }, JsonRequestBehavior.AllowGet));
            }

            FNApiReponseModel <object> reposemodel = JsonConvert.DeserializeObject <FNApiReponseModel <object> >(result);

            if (reposemodel == null || reposemodel.code != 200)
            {
                return(Json(new { isok = false, msg = reposemodel == null ?"接口异常":reposemodel.msg }, JsonRequestBehavior.AllowGet));
            }
            else
            {
                FNOrder order = FNOrderBLL.SingleModel.GetModelByOrderNo(orderno);
                if (order == null)
                {
                    return(Json(new { isok = false, msg = "找不到蜂鸟订单" }, JsonRequestBehavior.AllowGet));
                }

                order.state      = (int)FNOrderEnum.已取消;
                order.updatetime = DateTime.Now;
                order.order_cancel_reason_code = 2;
                order.order_cancel_code        = cancelcode;
                order.order_cancel_description = cancel_reason;
                order.order_cancel_time        = FNApi.SingleModel.GetTimeStamp().ToString();
                bool success = FNOrderBLL.SingleModel.Update(order, "state,updatetime,order_cancel_reason_code,order_cancel_code,order_cancel_description,order_cancel_time");

                if (!success)
                {
                    return(Json(new { isok = false, msg = "修改蜂鸟订单状态失败" }, JsonRequestBehavior.AllowGet));
                }

                FoodGoodsOrder foodGoodOrder = FoodGoodsOrderBLL.SingleModel.GetModel($" Id = {orderid} ");
                if (foodGoodOrder == null)
                {
                    return(Json(new { isok = false, msg = "蜂鸟配送:找不到订单" }, JsonRequestBehavior.AllowGet));
                }
                //退款接口 abel
                if (foodGoodOrder.BuyMode == (int)miniAppBuyMode.微信支付)
                {
                    success = FoodGoodsOrderBLL.SingleModel.outOrder(foodGoodOrder, foodGoodOrder.State);
                }
                else if (foodGoodOrder.BuyMode == (int)miniAppBuyMode.储值支付)
                {
                    SaveMoneySetUser userSaveMoney = SaveMoneySetUserBLL.SingleModel.getModelByUserId(foodGoodOrder.UserId) ?? new SaveMoneySetUser();
                    success = FoodGoodsOrderBLL.SingleModel.outOrderBySaveMoneyUser(foodGoodOrder, userSaveMoney, foodGoodOrder.State);
                }
            }

            return(Json(new { isok = true, msg = result }, JsonRequestBehavior.AllowGet));
        }
コード例 #5
0
        /// <summary>
        /// 蜂鸟订单状态改变回调接口
        /// </summary>
        /// <param name="returnModel"></param>
        /// <returns></returns>
        public ActionResult FNnotis(FNApiReponseModel <string> returnModel)
        {
            if (returnModel == null || returnModel.data == null || returnModel.data.Length == 0)
            {
                LogHelper.WriteInfo(this.GetType(), "蜂鸟回调请求参数为空");
                return(Content(""));
            }

            string datajson             = HttpUtility.UrlDecode(returnModel.data);
            FNAccepterOrderModel data   = JsonConvert.DeserializeObject <FNAccepterOrderModel>(datajson);
            string urlencodedata        = returnModel.data;
            DistributionApiConfig model = DistributionApiConfigBLL.SingleModel.GetModelByRedis(FNApi._fnapi_appid);
            string signature            = FNApi.SingleModel.GetSign(model.access_token, urlencodedata, returnModel.salt);

            if (returnModel.signature != signature || data == null)
            {
                LogHelper.WriteInfo(this.GetType(), "蜂鸟配送回调签名错误json:" + JsonConvert.SerializeObject(returnModel) + ",解码后:" + datajson);
                return(Content(""));
            }

            FNOrder order = FNOrderBLL.SingleModel.GetModelByOrderNo(data.partner_order_code);

            if (order == null)
            {
                log4net.LogHelper.WriteInfo(this.GetType(), $"蜂鸟订单回调:找不到订单【{data.partner_order_code}】");
                return(Content(""));
            }

            order.state                = data.order_status;
            order.updatetime           = DateTime.Now;
            order.carrier_driver_name  = data.carrier_driver_name;
            order.carrier_driver_phone = data.carrier_driver_phone;
            order.description          = data.description;
            bool updatebool = FNOrderBLL.SingleModel.Update(order, "state,updatetime,carrier_driver_name,carrier_driver_phone,description");

            if (updatebool && data.order_status == (int)FNOrderEnum.异常)
            {
                FNOrderRelation orelationmodel = FNOrderRelationBLL.SingleModel.GetModelUOrderNo(order.partner_order_code);
                if (orelationmodel == null)
                {
                    log4net.LogHelper.WriteInfo(this.GetType(), "蜂鸟配送取消订单回调发起退款出错:找不到关联该订单的数据");
                    return(Content("success"));
                }

                bool isSuccess = false;
                switch (orelationmodel.ordertype)
                {
                case (int)TmpType.小程序餐饮模板:
                    FoodGoodsOrder foodGoodOrder = FoodGoodsOrderBLL.SingleModel.GetModel($" Id = {orelationmodel.orderid} ");    // and  OrderType ={(int)miniAppFoodOrderType.店内点餐 } ");
                    if (foodGoodOrder == null)
                    {
                        LogHelper.WriteInfo(this.GetType(), "蜂鸟配送:找不到订单");
                        return(Content("success"));
                    }
                    //退款接口 abel
                    if (foodGoodOrder.BuyMode == (int)miniAppBuyMode.微信支付)
                    {
                        isSuccess = FoodGoodsOrderBLL.SingleModel.outOrder(foodGoodOrder, foodGoodOrder.State);
                    }
                    else if (foodGoodOrder.BuyMode == (int)miniAppBuyMode.储值支付)
                    {
                        SaveMoneySetUser userSaveMoney = SaveMoneySetUserBLL.SingleModel.getModelByUserId(foodGoodOrder.UserId) ?? new SaveMoneySetUser();
                        isSuccess = FoodGoodsOrderBLL.SingleModel.outOrderBySaveMoneyUser(foodGoodOrder, userSaveMoney, foodGoodOrder.State);
                    }
                    break;

                case (int)TmpType.小程序专业模板:
                    EntGoodsOrder entorder = EntGoodsOrderBLL.SingleModel.GetModel(orelationmodel.orderid);
                    if (entorder == null)
                    {
                        LogHelper.WriteInfo(this.GetType(), "蜂鸟配送取消订单回调发起退款出错:找不到小程序订单数据");
                        return(Content("success"));
                    }

                    isSuccess = EntGoodsOrderBLL.SingleModel.outOrder(entorder, entorder.State, entorder.BuyMode);
                    if (!isSuccess)
                    {
                        LogHelper.WriteInfo(this.GetType(), "蜂鸟配送取消订单回调发起退款出错:执行退款服务出错");
                        return(Content("success"));
                    }

                    EntGoodsOrderLogBLL.SingleModel.AddLog(entorder.Id, 0, $"蜂鸟:将订单状态改为:{Enum.GetName(typeof(MiniAppEntOrderState), entorder.State)}");
                    break;
                }
            }

            return(Content(""));
        }