Example #1
0
        /// <summary>
        /// This method is only applied to platform direct charge
        /// </summary>
        /// <param name="orderId"></param>
        public ChargeResult ProcessOrderAfterPaid(int paymentId, string tradeNo, string buyerAccount)
        {
            ChargeResult result = new ChargeResult();

            using (chargebitEntities db = new chargebitEntities())
            {
                Payment_history payment = (from p in db.Payment_history where p.Id == paymentId select p).FirstOrDefault <Payment_history>();
                if (payment == null)
                {
                    result.Status  = ChargeStatus.FAILED;
                    result.Message = string.Format("编号为:{0}的支付编号不存在", paymentId);
                    return(result);
                }
                payment.Pay_time       = DateTimeUtil.ConvertDateTimeToInt(DateTime.Now);
                payment.PaymentAccount = buyerAccount != null?buyerAccount:"";
                payment.PaymentTradeId = tradeNo != null ? tradeNo : "";
                db.SaveChanges();
                //前台用户直充网络支付成功之后,提交订单到资源充值
                if (payment.PayType == 0)
                {
                    if (payment.ChargeOrderId <= 0)
                    {
                        result.Status  = ChargeStatus.FAILED;
                        result.Message = string.Format("编号为:{0}的支付编号没有相关充值订单", paymentId);
                        return(result);
                    }

                    Charge_Order corder = (from o in db.Charge_Order where o.Id == payment.ChargeOrderId select o).FirstOrDefault <Charge_Order>();
                    corder.Payed = true;
                    db.SaveChanges();

                    ChargeOrder order = new ChargeOrder()
                    {
                        Payed = true, ChargeType = corder.Charge_type, AgencyId = corder.Agent_Id, Id = corder.Id, Province = corder.Province, City = corder.City, MobileSP = corder.MobileSP, MobileNumber = corder.Phone_number, OutId = "", ResourceId = 0, ResourceTaocanId = corder.Resource_taocan_id, RouteId = corder.RuoteId, CreatedTime = corder.Created_time
                    };
                    ChargeBridge cb = new ChargeBridge();
                    result = cb.Charge(order);
                }
            }

            return(result);
        }
Example #2
0
        public static void ProcessOrders()
        {
            logger.Info("Going to process orders...");
            chargebitEntities db = null;

            try
            {
                List <Charge_Order> orders = null;
                db = new chargebitEntities();
                db.Configuration.AutoDetectChangesEnabled = true;
                if (resources == null)
                {
                    resources = (from r in db.Resource where r.Enabled == true select r).ToList <Resource>();
                }
                if (resourceAPIs == null)
                {
                    resourceAPIs = (from r in db.Resrouce_interface select r).ToList <Resrouce_interface>();
                }
                lock (o)
                {
                    logger.Info("Last Max Order Id:" + lastOrderId);
                    orders = (from o in db.Charge_Order where o.Id > lastOrderId && ((o.Payed == true && o.Charge_type == 0 && o.Status == 10) || (o.Charge_type == 1 && o.Status != 3 && o.Status != 2) || (o.Charge_type == 2 && o.Status != 3 && o.Status != 2)) orderby o.Charge_type ascending orderby o.Id ascending select o).ToList <Charge_Order>();
                    logger.Info(string.Format("Get {0} unprocessed orders", orders.Count));
                    if (orders.Count == 0)
                    {
                        logger.Info("No unprocessed orders, thread will exit!");
                        return;
                    }

                    lastOrderId = (from o in orders select o.Id).Max();
                    logger.Info("Max Order Id updated to:" + lastOrderId);
                }

                List <int>   agentIds = (from o in orders where o.Agent_Id > 0 select o.Agent_Id).ToList <int>();
                List <Users> agents   = new List <Users>();
                if (agentIds != null && agentIds.Count > 0)
                {
                    int[] ids = agentIds.ToArray <int>();
                    agents = (from u in db.Users where ids.Contains(u.Id) select u).ToList <Users>();
                }
                List <Charge_Order> frontEndOrders = (from o in orders where o.Payed == true && o.Charge_type == 0 && o.Status == 10 select o).ToList <Charge_Order>();
                List <Charge_Order> agentOrders    = (from o in orders where o.Charge_type == 1 && o.Status != 3 && o.Status != 2 select o).ToList <Charge_Order>();
                List <Charge_Order> backendOrders  = (from o in orders where o.Charge_type == 2 && o.Status != 3 && o.Status != 2 select o).ToList <Charge_Order>();
                //logger.Info(string.Format("{0} unprocessed frontend orders", frontEndOrders.Count));
                //logger.Info(string.Format("{0} unprocessed agent orders", agentOrders.Count));
                //logger.Info(string.Format("{0} unprocessed backend orders", backendOrders.Count));
                ChargeResult result = null;
                logger.Info("");
                foreach (Charge_Order corder in orders)
                {
                    Resource           resource    = (from r in resources where r.Id == corder.Resource_id select r).FirstOrDefault <Resource>();
                    Resrouce_interface resourceAPI = null;
                    if (resource != null)
                    {
                        resourceAPI = (from api in resourceAPIs where api.Resource_id == corder.Resource_id select api).FirstOrDefault <Resrouce_interface>();
                    }
                    logger.Info(string.Format("Processing order Id-{0}, Phone-{1}, Agent-{2}, ChargeType-{3}", corder.Id.ToString(), corder.Phone_number, corder.Agent_Id, corder.Charge_type));
                    ChargeOrder order = new ChargeOrder()
                    {
                        Payed            = corder.Payed,
                        ChargeType       = corder.Charge_type,
                        AgencyId         = corder.Agent_Id,
                        OperateUserId    = corder.Operate_User,
                        Id               = corder.Id,
                        Province         = corder.Province,
                        City             = corder.City,
                        MobileSP         = corder.MobileSP,
                        MobileNumber     = corder.Phone_number,
                        OutOrderId       = "",
                        ResourceId       = 0,
                        ResourceTaocanId = corder.Resource_taocan_id,
                        RouteId          = corder.RuoteId,
                        CreatedTime      = corder.Created_time
                    };

                    result = cb.Charge(order);
                    Users agent = (from u in agents where corder.Agent_Id > 0 && corder.Agent_Id == u.Id select u).FirstOrDefault <Users>();
                    logger.Info("Order status - " + order.Status);

                    //just for Synchronized resources
                    if (!string.IsNullOrEmpty(corder.CallBackUrl) && corder.Agent_Id > 0 &&
                        agent != null &&
                        resourceAPI != null &&
                        (resourceAPI.Synchronized == true || result.Status == ChargeStatus.FAILED)
                        )
                    {
                        logger.Info("Synchronized resource api or failed resource api submission.");
                        //send back the status to agent system
                        NameValueCollection col = new NameValueCollection();
                        SortedDictionary <string, string> param = new SortedDictionary <string, string>();
                        param.Add("OrderId", corder.Id.ToString());
                        param.Add("ClientOrderId", corder.Client_Order_Id != null?corder.Client_Order_Id.ToString():"");
                        param.Add("Message", result.Message);
                        param.Add("Status", result.Status.ToString());
                        string querystr = "";
                        foreach (KeyValuePair <string, string> p in param)
                        {
                            col.Add(p.Key, p.Value != null ? p.Value : "");
                            if (querystr == "")
                            {
                                querystr = p.Key + "=" + (p.Value != null ? p.Value : "");
                            }
                            else
                            {
                                querystr += "&" + p.Key + "=" + (p.Value != null ? p.Value : "");
                            }
                        }
                        logger.Info(string.Format("Post data to callback url - {0}", corder.CallBackUrl));
                        logger.Info(string.Format("Data - {0}", querystr));
                        querystr += "&key=" + agent.SecurityStamp;
                        string sign = UrlSignUtil.GetMD5(querystr);
                        col.Add("Sign", sign);
                        //logger.Info("sign=" + sign);
                        string resStr = HttpSercice.PostHttpRequest(corder.CallBackUrl, col, WeChat.Adapter.Requests.RequestType.POST, null);
                        if (resStr == null)
                        {
                            corder.PushedTimes += 1;
                            corder.Received     = true;
                        }
                        else if (resStr.ToLower() == "fail")
                        {
                            corder.PushedTimes += 1;
                            corder.Received     = false;
                        }
                        db.SaveChanges();
                    }
                    logger.Info(string.Format("Order ID:{2} - {0} - {1}", result.Status, result.Message, corder.Id));
                    logger.Info("");
                }
            }
            catch (Exception ex)
            {
                logger.Error(ex);
            }
            finally
            {
                if (db != null)
                {
                    db.Dispose();
                }
            }
        }
Example #3
0
        public ChargeResult MarketingCharge(BMarketOrderCharge orderCharge)
        {
            logger.Info("MarketingCharge");
            ChargeResult result = new ChargeResult();

            if (orderCharge == null)
            {
                result.Status  = ChargeStatus.FAILED;
                result.Message = "参数不正确";
                return(result);
            }
            if (orderCharge.AgentId == 0 || orderCharge.CustomerId == 0 || orderCharge.ActivityId == 0)
            {
                result.Status  = ChargeStatus.FAILED;
                result.Message = "参数不正确";
                return(result);
            }
            if (string.IsNullOrEmpty(orderCharge.SPName))
            {
                result.Status  = ChargeStatus.FAILED;
                result.Message = "参数不正确";
                return(result);
            }
            if (string.IsNullOrEmpty(orderCharge.Phone))
            {
                result.Status  = ChargeStatus.FAILED;
                result.Message = "参数不正确";
                return(result);
            }
            int sp = 0;

            if (orderCharge.SPName.Contains("联通"))
            {
                sp = 3;
            }
            else if (orderCharge.SPName.Contains("移动"))
            {
                sp = 1;
            }
            else if (orderCharge.SPName.Contains("电信"))
            {
                sp = 2;
            }
            chargebitEntities         db      = new chargebitEntities();
            Marketing_Activity_Taocan mtaocan = null;
            Marketing_Orders          mOrder  = null;

            try
            {
                Marketing_Activities activity = (from a in db.Marketing_Activities where a.Id == orderCharge.ActivityId select a).FirstOrDefault <Marketing_Activities>();
                if (activity == null)
                {
                    result.Status  = ChargeStatus.FAILED;
                    result.Message = "参数不正确";
                    return(result);
                }
                if (activity.CustomerId != orderCharge.CustomerId)
                {
                    result.Status  = ChargeStatus.FAILED;
                    result.Message = "参数不正确";
                    return(result);
                }
                if (activity.AgentId != orderCharge.AgentId)
                {
                    result.Status  = ChargeStatus.FAILED;
                    result.Message = "参数不正确";
                    return(result);
                }
                //非直接扫码活动,必须传入特定的marketing order id
                if (activity.ScanType != 1 && orderCharge.ActivityOrderId == 0)
                {
                    result.Status  = ChargeStatus.FAILED;
                    result.Message = "参数不正确";
                    return(result);
                }
                ChargeOrder order = new ChargeOrder()
                {
                    AgencyId     = orderCharge.AgentId,
                    ChargeType   = 1,
                    City         = orderCharge.City,
                    CreatedTime  = DateTimeUtil.ConvertDateTimeToInt(DateTime.Now),
                    IsMarket     = true,
                    MacAddress   = orderCharge.OpenId,
                    MobileNumber = orderCharge.Phone,
                    MobileSP     = orderCharge.SPName,
                    Payed        = true,
                    Province     = orderCharge.Province,
                };

                //direct scan
                if (activity.ScanType == 1 && orderCharge.ActivityOrderId <= 0)
                {
                    //判断是否还有可用marketing order

                    List <Marketing_Activity_Taocan> rTaocans = (from mt in db.Marketing_Activity_Taocan
                                                                 join t in db.Resource_taocan on mt.ResourceTaocanId equals t.Id
                                                                 where mt.ActivityId == orderCharge.ActivityId && t.Sp_id == sp
                                                                 select mt).ToList <Marketing_Activity_Taocan>();

                    if (rTaocans.Count == 0)
                    {
                        result.Status  = ChargeStatus.FAILED;
                        result.Message = "本次活动" + orderCharge.SPName + "不能扫码充值";
                        return(result);
                    }

                    mtaocan = rTaocans[0];
                    mOrder  = (from o in db.Marketing_Orders where o.ActivityId == orderCharge.ActivityId && o.Sent == false && o.Used == false && o.ActivityTaocanId == mtaocan.Id select o).FirstOrDefault <Marketing_Orders>();
                    if (mOrder == null)
                    {
                        result.Status  = ChargeStatus.FAILED;
                        result.Message = "本次活动的流量充值额度已经全部被扫完,尽请期待下次活动";
                        return(result);
                    }
                    if (mOrder.Used)
                    {
                        result.Status  = ChargeStatus.FAILED;
                        result.Message = "本次活动的流量充值额度已经全部被扫完,尽请期待下次活动";
                        return(result);
                    }
                    mOrder.Used = true;
                    mOrder.Sent = true;
                    //db.SaveChanges();
                    order.MarketOrderId    = mOrder.Id;
                    order.ResourceTaocanId = mtaocan.ResourceTaocanId;
                }//weichat push
                else if (activity.ScanType == 2 && orderCharge.ActivityOrderId > 0)
                {
                    mOrder = (from o in db.Marketing_Orders where o.Id == orderCharge.ActivityOrderId select o).FirstOrDefault <Marketing_Orders>();
                    if (mOrder == null)
                    {
                        result.Status  = ChargeStatus.FAILED;
                        result.Message = "参数有误";
                        return(result);
                    }
                    if (mOrder.Used)
                    {
                        result.Status  = ChargeStatus.FAILED;
                        result.Message = "本次活动的流量充值额度已经全部被扫完,尽请期待下次活动";
                        return(result);
                    }
                    mtaocan = (from mt in db.Marketing_Activity_Taocan where mt.Id == mOrder.ActivityTaocanId select mt).FirstOrDefault <Marketing_Activity_Taocan>();
                    if (mtaocan == null)
                    {
                        result.Status  = ChargeStatus.FAILED;
                        result.Message = "参数有误";
                        return(result);
                    }
                    Resource_taocan rT = (from r in db.Resource_taocan where r.Id == mtaocan.ResourceTaocanId select r).FirstOrDefault <Resource_taocan>();
                    if (rT == null)
                    {
                        result.Status  = ChargeStatus.FAILED;
                        result.Message = "参数有误";
                        return(result);
                    }
                    if (rT.Sp_id != sp)
                    {
                        string tmpSPName = "";
                        if (rT.Sp_id == 1)
                        {
                            tmpSPName = "中国移动";
                        }
                        else if (rT.Sp_id == 2)
                        {
                            tmpSPName = "中国电信";
                        }
                        else if (rT.Sp_id == 3)
                        {
                            tmpSPName = "中国联通";
                        }
                        result.Status  = ChargeStatus.FAILED;
                        result.Message = string.Format("此二维码链接不能充值{0}的手机号码的流量,只能充值{1}的号码的流量", orderCharge.SPName, tmpSPName);
                        return(result);
                    }
                    order.ResourceTaocanId = mtaocan.ResourceTaocanId;
                    order.MarketOrderId    = orderCharge.ActivityOrderId;
                    mOrder.Used            = true;
                    mOrder.Sent            = true;
                }
                else if (activity.ScanType == 1 && orderCharge.ActivityOrderId > 0)
                {
                    result.Status  = ChargeStatus.FAILED;
                    result.Message = "参数有误";
                    return(result);
                }
                else if (activity.ScanType == 2 && orderCharge.ActivityOrderId <= 0)
                {
                    result.Status  = ChargeStatus.FAILED;
                    result.Message = "参数有误";
                    return(result);
                }

                OrderManagement orderMgr = new OrderManagement(CurrentLoginUser);
                order = orderMgr.GenerateOrder(order);
                ChargeBridge chargeBridge = new ChargeBridge();
                if (order.Id > 0)
                {
                    db.SaveChanges();
                    result = chargeBridge.Charge(order);
                    if (result.Status == ChargeStatus.FAILED)
                    {
                        //Rollback, the order cannot be used next time
                        mOrder.UsedTime = 0;
                        mOrder.Used     = false;
                        if (activity.ScanType == 1)
                        {
                            mOrder.Sent = false;
                        }

                        db.SaveChanges();
                    }
                    else
                    {
                        mOrder.UsedTime = DateTimeUtil.ConvertDateTimeToInt(DateTime.Now);
                    }
                    db.SaveChanges();
                }
            }
            catch (KMBitException kex)
            {
                logger.Warn(kex);
                result.Status  = ChargeStatus.FAILED;
                result.Message = kex.Message;
                if (mOrder != null)
                {
                    mOrder.Used = false;
                    db.SaveChanges();
                }
            }
            catch (Exception ex)
            {
                logger.Fatal(ex);
                result.Status  = ChargeStatus.FAILED;
                result.Message = "系统错误,稍后再试";
                if (mOrder != null)
                {
                    mOrder.Used = false;
                    db.SaveChanges();
                }
            }
            finally
            {
                if (db != null)
                {
                    db.Dispose();
                }
            }
            logger.Info("Finished MarketingCharge");
            return(result);
        }
Example #4
0
        public ChargeResult MarketingCharge(BMarketOrderCharge orderCharge)
        {
            logger.Info("MarketingCharge");
            ChargeResult result = new ChargeResult();
            if (orderCharge == null)
            {
                result.Status = ChargeStatus.FAILED;
                result.Message = "参数不正确";
                return result;
            }
            if (orderCharge.AgentId == 0 || orderCharge.CustomerId == 0 || orderCharge.ActivityId == 0)
            {
                result.Status = ChargeStatus.FAILED;
                result.Message = "参数不正确";
                return result;
            }
            if (string.IsNullOrEmpty(orderCharge.SPName))
            {
                result.Status = ChargeStatus.FAILED;
                result.Message = "参数不正确";
                return result;
            }
            if (string.IsNullOrEmpty(orderCharge.Phone))
            {
                result.Status = ChargeStatus.FAILED;
                result.Message = "参数不正确";
                return result;
            }
            int sp = 0;
            if (orderCharge.SPName.Contains("联通"))
            {
                sp = 3;
            }
            else if (orderCharge.SPName.Contains("移动"))
            {
                sp = 1;
            }
            else if (orderCharge.SPName.Contains("电信"))
            {
                sp = 2;
            }
            chargebitEntities db = new chargebitEntities();
            Marketing_Activity_Taocan mtaocan = null;
            Marketing_Orders mOrder = null;
            try
            {
                Marketing_Activities activity = (from a in db.Marketing_Activities where a.Id==orderCharge.ActivityId select a).FirstOrDefault<Marketing_Activities>();
                if(activity==null)
                {
                    result.Status = ChargeStatus.FAILED;
                    result.Message = "参数不正确";
                    return result;
                }
                if(activity.CustomerId!=orderCharge.CustomerId)
                {
                    result.Status = ChargeStatus.FAILED;
                    result.Message = "参数不正确";
                    return result;
                }
                if (activity.AgentId != orderCharge.AgentId)
                {
                    result.Status = ChargeStatus.FAILED;
                    result.Message = "参数不正确";
                    return result;
                }
                //非直接扫码活动,必须传入特定的marketing order id
                if(activity.ScanType!=1 && orderCharge.ActivityOrderId==0)
                {
                    result.Status = ChargeStatus.FAILED;
                    result.Message = "参数不正确";
                    return result;
                }
                ChargeOrder order = new ChargeOrder()
                {
                    AgencyId = orderCharge.AgentId,
                    ChargeType = 1,
                    City = orderCharge.City,
                    CreatedTime = DateTimeUtil.ConvertDateTimeToInt(DateTime.Now),
                    IsMarket = true,
                    MacAddress = orderCharge.OpenId,
                    MobileNumber = orderCharge.Phone,
                    MobileSP = orderCharge.SPName,
                    Payed = true,
                    Province = orderCharge.Province,

                };

                //direct scan
                if (activity.ScanType==1 && orderCharge.ActivityOrderId<=0)
                {
                    //判断是否还有可用marketing order

                    List<Marketing_Activity_Taocan> rTaocans = (from mt in db.Marketing_Activity_Taocan
                                                                join t in db.Resource_taocan on mt.ResourceTaocanId equals t.Id
                                                                where mt.ActivityId == orderCharge.ActivityId && t.Sp_id == sp
                                                                select mt).ToList<Marketing_Activity_Taocan>();

                    if (rTaocans.Count==0)
                    {
                        result.Status = ChargeStatus.FAILED;
                        result.Message = "本次活动" + orderCharge.SPName + "不能扫码充值";
                        return result;
                    }

                    mtaocan = rTaocans[0];
                    mOrder = (from o in db.Marketing_Orders where o.ActivityId== orderCharge.ActivityId && o.Sent==false && o.Used==false && o.ActivityTaocanId== mtaocan.Id select o).FirstOrDefault<Marketing_Orders>();
                    if(mOrder==null)
                    {
                        result.Status = ChargeStatus.FAILED;
                        result.Message = "本次活动的流量充值额度已经全部被扫完,尽请期待下次活动";
                        return result;
                    }
                    if(mOrder.Used)
                    {
                        result.Status = ChargeStatus.FAILED;
                        result.Message = "本次活动的流量充值额度已经全部被扫完,尽请期待下次活动";
                        return result;
                    }
                    mOrder.Used = true;
                    mOrder.Sent = true;
                    //db.SaveChanges();
                    order.MarketOrderId = mOrder.Id;
                    order.ResourceTaocanId = mtaocan.ResourceTaocanId;
                }//weichat push
                else if(activity.ScanType==2 && orderCharge.ActivityOrderId>0)
                {
                    mOrder = (from o in db.Marketing_Orders where o.Id==orderCharge.ActivityOrderId select o).FirstOrDefault<Marketing_Orders>();
                    if (mOrder == null)
                    {
                        result.Status = ChargeStatus.FAILED;
                        result.Message = "参数有误";
                        return result;
                    }
                    if(mOrder.Used)
                    {
                        result.Status = ChargeStatus.FAILED;
                        result.Message = "本次活动的流量充值额度已经全部被扫完,尽请期待下次活动";
                        return result;
                    }
                    mtaocan = (from mt in db.Marketing_Activity_Taocan where mt.Id==mOrder.ActivityTaocanId select mt).FirstOrDefault<Marketing_Activity_Taocan>();
                    if(mtaocan == null)
                    {
                        result.Status = ChargeStatus.FAILED;
                        result.Message = "参数有误";
                        return result;
                    }
                    Resource_taocan rT = (from r in db.Resource_taocan where r.Id == mtaocan.ResourceTaocanId select r).FirstOrDefault<Resource_taocan>();
                    if(rT==null)
                    {
                        result.Status = ChargeStatus.FAILED;
                        result.Message = "参数有误";
                        return result;
                    }
                    if(rT.Sp_id!=sp)
                    {
                        string tmpSPName = "";
                        if(rT.Sp_id==1)
                        {
                            tmpSPName = "中国移动";
                        }else if(rT.Sp_id==2)
                        {
                            tmpSPName = "中国电信";
                        }
                        else if (rT.Sp_id == 3)
                        {
                            tmpSPName = "中国联通";
                        }
                        result.Status = ChargeStatus.FAILED;
                        result.Message = string.Format("此二维码链接不能充值{0}的手机号码的流量,只能充值{1}的号码的流量",orderCharge.SPName,tmpSPName);
                        return result;
                    }
                    order.ResourceTaocanId = mtaocan.ResourceTaocanId;
                    order.MarketOrderId = orderCharge.ActivityOrderId;
                    mOrder.Used = true;
                    mOrder.Sent = true;
                }else if(activity.ScanType==1 && orderCharge.ActivityOrderId>0)
                {
                    result.Status = ChargeStatus.FAILED;
                    result.Message = "参数有误";
                    return result;
                }
                else if(activity.ScanType==2 && orderCharge.ActivityOrderId<=0)
                {
                    result.Status = ChargeStatus.FAILED;
                    result.Message = "参数有误";
                    return result;
                }

                OrderManagement orderMgr = new OrderManagement(CurrentLoginUser);
                order=orderMgr.GenerateOrder(order);
                ChargeBridge chargeBridge = new ChargeBridge();
                if(order.Id>0)
                {
                    db.SaveChanges();
                    result=chargeBridge.Charge(order);
                    if(result.Status== ChargeStatus.FAILED)
                    {
                        //Rollback, the order cannot be used next time
                        mOrder.UsedTime = 0;
                        mOrder.Used = false;
                        if(activity.ScanType==1)
                        {
                            mOrder.Sent = false;
                        }

                        db.SaveChanges();
                    }else
                    {
                        mOrder.UsedTime = DateTimeUtil.ConvertDateTimeToInt(DateTime.Now);
                    }
                    db.SaveChanges();
                }
            }
            catch (KMBitException kex)
            {
                logger.Warn(kex);
                result.Status = ChargeStatus.FAILED;
                result.Message = kex.Message;
                if(mOrder!=null)
                {
                    mOrder.Used = false;
                    db.SaveChanges();
                }
            }
            catch (Exception ex)
            {
                logger.Fatal(ex);
                result.Status = ChargeStatus.FAILED;
                result.Message = "系统错误,稍后再试";
                if (mOrder != null)
                {
                    mOrder.Used = false;
                    db.SaveChanges();
                }
            }
            finally
            {
                if(db!=null)
                {
                    db.Dispose();
                }
            }
            logger.Info("Finished MarketingCharge");
            return result;
        }