Esempio n. 1
0
 public ApiMessage GetAgentReports()
 {
     this.IniRequest();
     DateTime sDate = DateTime.MinValue;
     DateTime eDate = DateTime.MinValue;
     if (!string.IsNullOrEmpty(request["startTime"]))
     {
         DateTime.TryParse(request["startTime"], out sDate);
     }
     if (!string.IsNullOrEmpty(request["endTime"]))
     {
         DateTime.TryParse(request["endTime"], out eDate);
     }
     long sintDate = sDate != DateTime.MinValue ? DateTimeUtil.ConvertDateTimeToInt(sDate) : 0;
     long eintDate = eDate != DateTime.MinValue ? DateTimeUtil.ConvertDateTimeToInt(eDate) : 0;
     ApiMessage message = new ApiMessage();
     OrderManagement orderMgt = new OrderManagement(User.Identity.Name);
     List<ReportTemplate> reportList = orderMgt.SearchAgentReport(0, sintDate, eintDate);
     message.Status = "OK";
     message.Item = reportList;
     return message;
 }
Esempio n. 2
0
        public APIChargeResult Charge(int agentId,int routeId,string mobile,string spname,string province,string city,string callBackUrl,string client_order_id)
        {
            if(string.IsNullOrEmpty(mobile))
            {
                throw new KMBitException("手机号码不能为空");
            }
            if (string.IsNullOrEmpty(spname))
            {
                throw new KMBitException("手机号归属运行商不能为空");
            }
            if (string.IsNullOrEmpty(province))
            {
                throw new KMBitException("手机号归属省份不能为空");
            }
            //if (string.IsNullOrEmpty(city))
            //{
            //    throw new KMBitException("手机号归属城市不能为空");
            //}
            ChargeResult result = null;
            ChargeBridge cb = new ChargeBridge();
            ChargeOrder order = new ChargeOrder()
            {
                ClientOrderId = client_order_id,
                Payed = false,
                OperateUserId = 0,
                AgencyId = agentId,
                Id = 0,
                Province = province,
                City = city!=null? city:"",
                MobileNumber = mobile,
                MobileSP=spname,
                OutOrderId = "",
                ResourceId = 0,
                ResourceTaocanId = 0,
                RouteId = routeId,
                CreatedTime = DateTimeUtil.ConvertDateTimeToInt(DateTime.Now),
                CallbackUrl = callBackUrl
            };
            chargebitEntities db = null;
            OrderManagement orderMgt = new OrderManagement();
            try
            {
                db = new chargebitEntities();
                Users agent = (from u in db.Users where u.Id == agentId select u).FirstOrDefault<Users>();
                if(agent==null)
                {
                    throw new KMBitException(string.Format("编号为{0}的代理商不存在",agentId));
                }
                if(!agent.Enabled)
                {
                    throw new KMBitException(string.Format("代理商{0}已经被关闭禁用",agent.Name));
                }
                //verify mobile sp
                Agent_route route = (from r in db.Agent_route where r.Id == routeId && r.User_id == agentId select r).FirstOrDefault<Agent_route>();
                if(route==null)
                {
                    throw new KMBitException(string.Format("代理商 {1} 编号为{0}的路由不存在", routeId,agent.Name));
                }
                if(!route.Enabled)
                {
                    throw new KMBitException(string.Format("代理商 {1} 编号为{0}的路由已经被关闭", routeId, agent.Name));
                }
                Resource_taocan taocan = (from t in db.Resource_taocan where t.Id==route.Resource_taocan_id select t).FirstOrDefault<Resource_taocan>();
                int spId = (from sp in db.Sp where sp.Name.Contains(spname.Trim()) select sp.Id).FirstOrDefault<int>();
                if(spId==0)
                {
                    throw new KMBitException("手机运营商的值必须是-中国移动,中国联通或者中国电信");
                }
                int provinceId = (from area in db.Area where area.Name.Contains(province) select area.Id).FirstOrDefault<int>();
                if(provinceId==0)
                {
                    throw new KMBitException("手机号码归属省份值不正确,例如 河南,海南,江苏,请以此种格式传入");
                }
                if(taocan.NumberProvinceId>0 && provinceId>0)
                {
                    if(provinceId!=taocan.NumberProvinceId)
                    {
                        throw new KMBitException(string.Format("当前路由不能充{0}-{1}的手机号码",spname,province));
                    }
                }
                order = orderMgt.GenerateOrder(order);
                //result = cb.Charge(order);
                if(order.Id>0)
                {
                    result = new ChargeResult();
                    result.Status = ChargeStatus.SUCCEED;
                    result.Message = "充值信息已提交到充值系统";
                }
            }
            catch(KMBitException kex)
            {
                throw kex;
            }
            catch (Exception ex)
            {
                logger.Error(ex);
                result = new ChargeResult();
                result.Status = ChargeStatus.FAILED;
                result.Message = "未知错误,请联系平台管理员";
            }

            APIChargeResult apiResult = new APIChargeResult();
            //apiResult.Message = result.Message;
            apiResult.OrderId = order.Id;
            switch (result.Status)
            {
                case ChargeStatus.SUCCEED:
                    apiResult.Status = ChargeStatus.SUCCEED.ToString();
                    apiResult.Message = result.Message;
                    break;
                case ChargeStatus.FAILED:
                    apiResult.Status = ChargeStatus.FAILED.ToString();
                    break;
                case ChargeStatus.ONPROGRESS:
                    apiResult.Status = ChargeStatus.SUCCEED.ToString();
                    break;
                case ChargeStatus.PENDIND:
                    apiResult.Status = ChargeStatus.SUCCEED.ToString();
                    break;
            }

            return apiResult;
        }
Esempio n. 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);
        }
Esempio n. 4
0
        public JsonResult PreCharge(WeChatChargeModel model)
        {
            logger.Info("WeChatController.PreCharge......................................................");
            ApiMessage message = new ApiMessage();
            ChargeOrder order = null;
            if (ModelState.IsValid)
            {
                try
                {
                    if (string.IsNullOrEmpty(model.OpenId))
                    {
                        message.Status = "ERROR";
                        message.Message = "请从公众号菜单打开此页面";
                        return Json(message, JsonRequestBehavior.AllowGet);
                    }
                    //ChargeBridge cb = new ChargeBridge();
                    order = new ChargeOrder()
                    {
                        ChargeType = 0,
                        AgencyId = 0,
                        Id = 0,
                        Province = model.Province,
                        City = model.City,
                        MobileSP = model.SPName,
                        MobileNumber = model.Mobile,
                        OutOrderId = "",
                        ResourceId = 0,
                        ResourceTaocanId = model.ResourceTaocanId,
                        RouteId = 0,
                        CreatedTime = DateTimeUtil.ConvertDateTimeToInt(DateTime.Now),
                        Payed = false,
                        OpenId = model.OpenId,
                        OpenAccountType = 1
                    };
                    //
                    OrderManagement orderMgt = new OrderManagement();
                    ResourceManagement resourceMgr = new ResourceManagement(0);

                    string msg = string.Empty;
                    if (orderMgt.IsThisMonthCharged(order.MobileNumber, order.ResourceTaocanId, out msg))
                    {
                        message.Status = "ERROR";
                        message.Message = msg;
                        return Json(message, JsonRequestBehavior.AllowGet);
                    }

                    order = orderMgt.GenerateOrder(order);
                    int total = 0;
                    List<BResourceTaocan> taocans = resourceMgr.FindResourceTaocans(order.ResourceTaocanId, 0, 0, out total);
                    if (taocans == null || taocans.Count == 0)
                    {
                        message.Message = "当前套餐不可用";
                        message.Status = "ERROR";
                        return Json(message, JsonRequestBehavior.AllowGet);
                    }
                    logger.Info(string.Format("Order is generated, Id - {0}, mobile - {1}", order.Id, order.MobileNumber));
                    BResourceTaocan taocan = taocans[0];
                    message.Status = "OK";
                    message.Message = "预充值订单已经生成";
                    message.Item = null;
                    //
                    string ip = Request.ServerVariables["REMOTE_ADDR"];
                    if (ip != null && ip.IndexOf("::") > -1)
                    {
                        ip = "127.0.0.1";
                    }
                    string prepayId = WeChatPaymentWrapper.GetPrepayId(PersistentValueManager.config, Session["wechat_openid"] != null ? Session["wechat_openid"].ToString() : "", order.PaymentId.ToString(), "TEST WECHATPAY", ip, (int)taocan.Taocan.Sale_price * 100, TradeType.JSAPI);
                    logger.Info(string.Format("Prepay Id - {0}", prepayId));
                    WeChatOrder weOrder = new WeChatOrder();
                    weOrder.Order = new ChargeOrder { Id = order.Id, Payed = order.Payed, PaymentId = order.PaymentId, MobileNumber = order.MobileNumber, MobileSP = order.MobileSP, Province = order.Province };
                    weOrder.PrepayId = prepayId;
                    weOrder.PaySign = "";
                    message.Item = weOrder;

                    AccessToken token = PersistentValueManager.GetWeChatAccessToken();
                    JSAPITicket ticket = PersistentValueManager.GetWeChatJsApiTicket();
                    SortedDictionary<string, string> parameters = new SortedDictionary<string, string>();
                    parameters.Add("appId", PersistentValueManager.config.APPID);
                    parameters.Add("timeStamp", model.timestamp);
                    parameters.Add("nonceStr", model.nancestr);
                    parameters.Add("package", "prepay_id=" + prepayId);
                    parameters.Add("signType", "MD5");

                    logger.Info(string.Format("timeStamp:{0}", model.timestamp));
                    logger.Info(string.Format("nonceStr:{0}", model.nancestr));
                    logger.Info(string.Format("package:{0}", "prepay_id=" + prepayId));

                    string querystr = null;
                    foreach (KeyValuePair<string, string> para in parameters)
                    {
                        if (querystr == null)
                        {
                            querystr = para.Key + "=" + para.Value;
                        }
                        else
                        {
                            querystr += "&" + para.Key + "=" + para.Value;
                        }
                    }
                    querystr += "&key=" + PersistentValueManager.config.ShopSecret;
                    logger.Info(querystr);
                    string sign = UrlSignUtil.GetMD5(querystr);
                    model.paySign = sign.ToUpper();
                    model.prepay_id = prepayId;
                    logger.Info(string.Format("paySign:{0}", sign.ToUpper()));
                    message.Item = model;
                }
                catch (KMBitException kex)
                {
                    logger.Error(kex);
                    message.Message = kex.Message;
                    message.Status = "ERROR";
                }
                catch (Exception ex)
                {
                    message.Message = "未知错误,请联系我们";
                    message.Status = "ERROR";
                    logger.Fatal(ex);
                }
                finally
                {

                }
            }

            logger.Info("Done.");
            return Json(message, JsonRequestBehavior.AllowGet);
        }
Esempio n. 5
0
        public ActionResult Charge(ChargeModel model)
        {
            if (ModelState.IsValid)
            {
                //ChargeBridge cb = new ChargeBridge();
                ChargeOrder order = new ChargeOrder()
                { ChargeType = 0, AgencyId = 0, Id = 0, Province = model.Province, City = model.City, MobileSP = model.SPName, MobileNumber = model.Mobile, OutOrderId = "", ResourceId = 0, ResourceTaocanId = model.ResourceTaocanId, RouteId = 0, CreatedTime = DateTimeUtil.ConvertDateTimeToInt(DateTime.Now) };
                //
                OrderManagement orderMgt = new OrderManagement();
                ResourceManagement resourceMgr = new ResourceManagement(0);
                try
                {
                    order = orderMgt.GenerateOrder(order);
                }
                catch(KMBitException kex)
                {
                    ViewBag.Message = kex.Message;
                    return View();
                }
                catch(Exception ex)
                {
                    ViewBag.Message = "未知错误请联系系统管理员";
                    return View();
                }

                int total = 0;
                List<BResourceTaocan> taocans = resourceMgr.FindResourceTaocans(order.ResourceTaocanId, 0, 0, out total);
                if (taocans == null || taocans.Count == 0)
                {
                    ViewBag.Message = "当前套餐不可用";
                    return View();
                }
                BResourceTaocan taocan = taocans[0];
                //Redirct to the payment page.
                //TBD
                //After the payment is done then process below steps
                AlipayConfig config = new AlipayConfig(System.IO.Path.Combine(Request.PhysicalApplicationPath, "Config\\AliPayConfig.xml"));
                Submit submit = new Submit(config);

                SortedDictionary<string, string> sParaTemp = new SortedDictionary<string, string>();
                sParaTemp.Add("partner", config.Partner);
                sParaTemp.Add("seller_email", "*****@*****.**");
                sParaTemp.Add("_input_charset", config.Input_charset.ToLower());
                sParaTemp.Add("service", "create_direct_pay_by_user");
                sParaTemp.Add("payment_type", "1");
                sParaTemp.Add("notify_url", config.Notify_Url);
                sParaTemp.Add("return_url", config.Return_Url);
                sParaTemp.Add("out_trade_no", order.PaymentId.ToString());
                sParaTemp.Add("subject", string.Format("{0}M", taocan.Taocan.Quantity));
                sParaTemp.Add("total_fee", taocan.Taocan.Sale_price.ToString("0.00"));
                sParaTemp.Add("body", string.Format("{0}M", taocan.Taocan.Quantity));
                sParaTemp.Add("show_url", "");
                sParaTemp.Add("seller_id",config.Partner);
                //sParaTemp.Add("anti_phishing_key", "");
                //sParaTemp.Add("exter_invoke_ip", "");

                //建立请求
                string sHtmlText = submit.BuildRequest(sParaTemp, "get", "确认");
                //Response.Write("ok");
                Response.Clear();
                Response.Charset = "utf-8";
                Response.Write(sHtmlText);

                //ChargeResult result = cb.Charge(order);
                //ViewBag.Message = result.Message;
            }

            return View();
        }
Esempio n. 6
0
        // GET: PayBack此方法仅供直冲用户支付宝支付完成回调以及支付宝充值账户回调
        public ActionResult AlipayBack()
        {
            SortedDictionary<string, string> sPara = GetRequestGet();
            ChargeResult result = new ChargeResult() { Status= ChargeStatus.FAILED };
            if (sPara.Count > 0)//判断是否有带返回参数
            {
                AlipayConfig config = new AlipayConfig(System.IO.Path.Combine(Request.PhysicalApplicationPath, "Config\\AliPayConfig.xml"));
                Notify aliNotify = new Notify(config);
                bool verifyResult = aliNotify.Verify(sPara, Request.QueryString["notify_id"], Request.QueryString["sign"]);

                if (verifyResult)//验证成功
                {
                    //本地系统支付号
                    string out_trade_no = Request.QueryString["out_trade_no"];
                    int paymentId = 0;
                    int.TryParse(out_trade_no, out paymentId);

                    //支付宝交易号
                    string trade_no = Request.QueryString["trade_no"];

                    //买家支付宝账户
                    string buyerAccount = Request.QueryString["buyer_email"];
                    //交易状态
                    string trade_status = Request.QueryString["trade_status"];
                    if (Request.QueryString["trade_status"] == "TRADE_FINISHED" || Request.QueryString["trade_status"] == "TRADE_SUCCESS")
                    {
                        //判断该笔订单是否在商户网站中已经做过处理
                        //如果没有做过处理,根据订单号(out_trade_no)在商户网站的订单系统中查到该笔订单的详细,并执行商户的业务程序
                        //如果有做过处理,不执行商户的业务程序
                        OrderManagement orderMgr = new OrderManagement(0);
                        PaymentManagement payMgr = new PaymentManagement(0);
                        if(paymentId>0)
                        {
                            try
                            {
                                BPaymentHistory payment = null;
                                int total = 0;
                                List<BPaymentHistory> payments = payMgr.FindPayments(paymentId,0, 0,out total);
                                if(payments!=null && payments.Count==1)
                                {
                                    payment = payments[0];
                                    if(payment.PayType==0)//直冲用户支付
                                    {
                                        result = orderMgr.ProcessOrderAfterPaid(paymentId, trade_no, buyerAccount);
                                        result.Status = ChargeStatus.SUCCEED;
                                        result.Message = "支付成功,已经提交到充值系统,请耐心等待...";
                                        return Redirect("/Product/Charge?message=" + result.Message);
                                    }
                                    else if(payment.PayType==1)//代理商用户充值账户
                                    {
                                        payMgr.UpdateAccountMoneyAfterPayment(payment);
                                        return Redirect("/Agent/ChargeAccount?message=" + result.Message);
                                    }

                                }else
                                {
                                    result.Status = ChargeStatus.FAILED;
                                    result.Message = string.Format("支付号{0}在本系统中不存在",paymentId);
                                }

                            }
                            catch(KMBitException e)
                            {
                                result.Message = e.Message;
                                result.Status = ChargeStatus.FAILED;
                            }
                            catch(Exception ex)
                            {
                                result.Message = ex.Message;
                                result.Status = ChargeStatus.FAILED;
                            }
                        }
                    }
                    else
                    {
                        result.Message = string.Format("支付宝支付失败:{0}",Request.QueryString["trade_status"]);
                        result.Status = ChargeStatus.FAILED;

                        //需要删除本地系统内的支付记录或者充值订单记录TBD
                    }
                }
                else//验证失败
                {
                    result.Message = "支付宝返回数据验证失败,请不要串改支付宝返回的数据";
                    result.Status = ChargeStatus.FAILED;
                    //需要删除本地系统内的支付记录或者充值订单记录TBD
                }
            }
            else
            {
                result.Message = "支付宝没有返回任何数据,充值失败";
                result.Status = ChargeStatus.FAILED;
            }
            return Redirect("/Product/Charge?message=" + result.Message);
        }
Esempio n. 7
0
        public HttpResponseMessage WeChatPayBack()
        {
            var resp = new HttpResponseMessage(HttpStatusCode.OK);
            string returnXML = null;
            logger.Info("PaymentController.WeChatPayBack is being called by Wechat payment notify service.........................");
            Stream stream = Request.InputStream;
            if(stream!=null)
            {
                StreamReader rs = null;
                try
                {
                    rs = new StreamReader(stream);
                    string result = rs.ReadToEnd();
                    if (!string.IsNullOrEmpty(result))
                    {
                        logger.Info("Below is the data posted by wechat payment service");
                        logger.Info(result);
                        string paraValues = WeChatPaymentWrapper.ParsePaymentNotifySignParas(result);
                        logger.Info(string.Format("{0} needs to be signed",paraValues));
                        BaseResponse baseresponse = WeChatPaymentWrapper.ParsePaymentNotify(result);
                        PaymentNotifyResponse response = null;
                        if (baseresponse != null)
                        {
                            response = (PaymentNotifyResponse)baseresponse;
                        }
                        logger.Info(string.Format("Signature sent by wechat is {0}", response.sign));
                        WeChatPayConfig config = PersistentValueManager.config;
                        paraValues += "&key=" + config.ShopSecret;
                        string sign = UrlSignUtil.GetMD5(paraValues).ToUpper();
                        logger.Info(string.Format("Signature caculated by localsystem is {0}", sign));
                        if (sign!= response.sign)
                        {
                            logger.Error("Two signatures are different, the request was not sent by wechat payment system.");
                            returnXML = "<xml><return_code>FAIL</return_code><return_msg>签名不正确</return_msg></xml>";
                            resp.Content = new StringContent(returnXML, System.Text.Encoding.UTF8, "text/plain");
                        }
                        logger.Info("Sign verification passed");
                        OrderManagement orderMgr = new OrderManagement(0);
                        PaymentManagement payMgr = new PaymentManagement(0);
                        int paymentId = 0;
                        int.TryParse(response.out_trade_no,out paymentId);
                        if(paymentId>0)
                        {
                            logger.Info("Going to process payment id"+paymentId);
                            ChargeResult cResult = null;
                            try
                            {
                                BPaymentHistory payment = null;
                                int total = 0;
                                List<BPaymentHistory> payments = payMgr.FindUnProcessedOnLinePayments(paymentId, 0, 0, out total);
                                if (payments != null && payments.Count == 1)
                                {
                                    payment = payments[0];
                                    if (payment.PayType == 0)//直冲用户支付
                                    {
                                        logger.Info("OpenId:"+response.openid);
                                        logger.Info("OpenTradeNo:" + response.transaction_id);
                                        cResult = orderMgr.ProcessOrderAfterPaid(paymentId, response.transaction_id, response.openid);
                                        logger.Info(cResult.Status.ToString());
                                        logger.Info(cResult.Message);
                                        if(cResult.Status== ChargeStatus.SUCCEED)
                                        {
                                            logger.Info("The payment status has been successfully synced to local system.");
                                            returnXML = "<xml><return_code>SUCCESS</return_code><return_msg>OK</return_msg></xml>";
                                            resp.Content = new StringContent(returnXML, System.Text.Encoding.UTF8, "text/plain");
                                            return resp;
                                        }
                                        else
                                        {
                                            logger.Error(cResult.Message);
                                            returnXML = "<xml><return_code>FAIL</return_code><return_msg>unexpected error</return_msg></xml>";
                                            resp.Content = new StringContent(returnXML, System.Text.Encoding.UTF8, "text/plain");
                                            return resp;
                                        }
                                    }
                                }
                                else
                                {
                                    logger.Warn("Didn't find payment by id:"+paymentId);
                                    returnXML = "<xml><return_code>FAIL</return_code><return_msg>out_trade_no is wrong</return_msg></xml>";
                                    resp.Content = new StringContent(returnXML, System.Text.Encoding.UTF8, "text/plain");
                                }

                            }
                            catch (KMBitException e)
                            {
                                returnXML = "<xml><return_code>FAIL</return_code><return_msg>unexpected error</return_msg></xml>";
                                resp.Content = new StringContent(returnXML, System.Text.Encoding.UTF8, "text/plain");
                                logger.Error(e);
                            }
                            catch (Exception ex)
                            {
                                returnXML = "<xml><return_code>FAIL</return_code><return_msg>unexpected error</return_msg></xml>";
                                resp.Content = new StringContent(returnXML, System.Text.Encoding.UTF8, "text/plain");
                                logger.Fatal(ex);
                            }
                        }
                    }

                }
                catch(Exception ex)
                {
                    logger.Error(ex);
                }

            }
            logger.Info("Done...................");
            return resp;
        }
Esempio n. 8
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;
        }
Esempio n. 9
0
        public ApiMessage ExportOrders()
        {
            this.IniRequest();
            ApiMessage message = new ApiMessage();
            int orderId = 0;
            int agencyId = 0;
            int resourceId = 0;
            int resourceTaocanId = 0;
            int status = 0;
            string mobileNumber = null;
            DateTime sDate = DateTime.MinValue;
            DateTime eDate = DateTime.MinValue;
            if (request["OrderId"]!=null)
            {
                int.TryParse(request["OrderId"].ToString(),out orderId);
            }
            if (request["AgencyId"] != null)
            {
                int.TryParse(request["AgencyId"].ToString(), out agencyId);
            }
            if(request["Status"]!=null)
            {
                int.TryParse(request["Status"],out status);
            }
            if (request["ResourceId"] != null)
            {
                int.TryParse(request["ResourceId"].ToString(), out resourceId);
            }
            if (request["ResourceTaocanId"] != null)
            {
                int.TryParse(request["ResourceTaocanId"].ToString(), out resourceTaocanId);
            }
            mobileNumber = request["MobileNumber"];
            if (!string.IsNullOrEmpty(request["StartTime"]))
            {
                DateTime.TryParse(request["StartTime"], out sDate);
            }
            if (!string.IsNullOrEmpty(request["EndTime"]))
            {
                DateTime.TryParse(request["EndTime"], out eDate);
            }
            int total = 0;
            long sintDate = sDate != DateTime.MinValue ? DateTimeUtil.ConvertDateTimeToInt(sDate) : 0;
            long eintDate = eDate != DateTime.MinValue ? DateTimeUtil.ConvertDateTimeToInt(eDate) : 0;
            OrderManagement orderMgr = new OrderManagement(User.Identity.Name);
            List<BOrder> orders = orderMgr.FindOrders(orderId,
                                                      agencyId,
                                                      resourceId,
                                                      resourceTaocanId,
                                                      0,
                                                      null, mobileNumber,
                                                      new int[] { status},
                                                      sintDate,
                                                      eintDate,
                                                      out total,
                                                      0,
                                                      0, false);

            message.Status = "OK";

            string path = request.PhysicalApplicationPath;
            string fileName = orderMgr.CurrentLoginUser.User.Id +"_"+ DateTime.Now.ToString("yyyyMMddHHmm")+".csv";
            string fullPath = System.IO.Path.Combine(path+"\\Temp",fileName);
            FileStream fs = null;
            StreamWriter sw = null;
            try
            {
                fs = new FileStream(fullPath, FileMode.Create);
                sw = new StreamWriter(fs,Encoding.UTF8);
                sw.WriteLine("编号,资源,代理商,手机号,省份,城市,平台成本价,平台售价,代理商代理价,代理商售价,时间,状态");
                foreach (BOrder order in orders)
                {
                    StringBuilder builder = new StringBuilder();
                    builder.Append(order.Id.ToString() + ",");
                    builder.Append(order.ReseouceName + ",");
                    builder.Append((order.AgentName != null ? order.AgentName.ToString() : "") + ",");
                    builder.Append(order.MobilePhone + ",");
                    builder.Append((order.MobileProvince != null ? order.MobileProvince : "") + ",");
                    builder.Append((order.MobileCity != null ? order.MobileCity : "") + ",");
                    builder.Append(order.PlatformCostPrice.ToString("0.00") + ",");
                    builder.Append(order.PlatformSalePrice.ToString("0.00") + ",");
                    builder.Append(order.PurchasePrice.ToString("0.00") + ",");
                    builder.Append(order.SalePrice.ToString("0.00") + ",");
                    builder.Append(DateTimeUtil.ConvertToDateTime(order.CreatedTime).ToString("yyyy-MM-dd HH:mm") + ",");
                    builder.Append(order.StatusText != null ? order.StatusText : "");
                    sw.WriteLine(builder.ToString());
                }
            }
            catch(Exception ex)
            {
                logger.Fatal(ex);
            }
            finally
            {
                if(sw!=null)
                {
                    sw.Close();
                }
                if (fs != null)
                {
                    fs.Close();
                }
            }
            message.Item = "http://"+request.Url.Authority+"/Temp/"+ fileName;
            return message;
        }
Esempio n. 10
0
        public ActionResult Charge(AgentChargeModel model)
        {
            if (ModelState.IsValid)
            {
                try
                {
                    ChargeBridge cb = new ChargeBridge();
                    ChargeOrder order = new ChargeOrder() { Payed = false, OperateUserId = 0, AgencyId = User.Identity.GetUserId<int>(), Id = 0, Province = model.Province, City = model.City, MobileSP =model.SPName, MobileNumber = model.Mobile, OutOrderId = "", ResourceId = 0, ResourceTaocanId = model.ResourceTaocanId, RouteId = model.RouteId, CreatedTime = DateTimeUtil.ConvertDateTimeToInt(DateTime.Now) };

                    OrderManagement orderMgt = new OrderManagement();
                    order = orderMgt.GenerateOrder(order);
                    //ChargeResult result = cb.Charge(order);
                    ViewBag.Message = "成功提交到充值系统,等待充值,可以到流量充值查询里查看充值状态...";                    
                }
                catch (KMBitException ex)
                {
                    ViewBag.Message = ex.Message;
                }finally
                {
                    model = new AgentChargeModel();
                }
            }

            return View(model);
        }
Esempio n. 11
0
 public ActionResult ChargeOrders(OrderSearchModel searchModel)
 {
     OrderManagement orderMgt = new OrderManagement(User.Identity.GetUserId<int>());  
     int pageSize = 30;
     DateTime sDate = DateTime.MinValue;
     DateTime eDate = DateTime.MinValue;
     if (!string.IsNullOrEmpty(searchModel.StartTime))
     {
         DateTime.TryParse(searchModel.StartTime, out sDate);
     }
     if (!string.IsNullOrEmpty(searchModel.EndTime))
     {
         DateTime.TryParse(searchModel.EndTime, out eDate);
     }
     long sintDate = sDate != DateTime.MinValue ? DateTimeUtil.ConvertDateTimeToInt(sDate) : 0;
     long eintDate = eDate != DateTime.MinValue ? DateTimeUtil.ConvertDateTimeToInt(eDate) : 0;
     int page = 1;
     if (Request["page"] != null)
     {
         int.TryParse(Request["page"], out page);
     }
     searchModel.Page = page;
     searchModel.AgencyId = User.Identity.GetUserId<int>();
     List<BOrder> orders = orderMgt.FindOrders(searchModel.OrderId != null ? (int)searchModel.OrderId : 0,
                                               searchModel.AgencyId != null ? (int)searchModel.AgencyId : 0,
                                               searchModel.ResourceId != null ? (int)searchModel.ResourceId : 0,
                                               searchModel.ResourceTaocanId != null ? (int)searchModel.ResourceTaocanId : 0,
                                               searchModel.RuoteId != null ? (int)searchModel.RuoteId : 0,
                                               searchModel.SPName, searchModel.MobileNumber,
                                               searchModel.Status,
                                               sintDate,
                                               eintDate,
                                               out total,
                                               pageSize,
                                               searchModel.Page, true);
     PageItemsResult<BOrder> result = new PageItemsResult<BOrder>() { CurrentPage = searchModel.Page, Items = orders, PageSize = pageSize, TotalRecords = total, EnablePaging = true };
     KMBit.Grids.KMGrid<BOrder> grid = new Grids.KMGrid<BOrder>(result);
     BigOrderSearchModel model = new BigOrderSearchModel() { SearchModel = searchModel, OrderGrid = grid };  
     List<BResourceTaocan> taocans = new List<BResourceTaocan>();
     agentMgt = new AgentManagement(orderMgt.CurrentLoginUser);
     List<BAgentRoute> routes = agentMgt.FindTaocans(0);
     taocans = (from r in routes select r.Taocan).ToList<BResourceTaocan>();
     ViewBag.Taocans = new SelectList((from t in taocans select new { Id = t.Taocan.Id, Name = t.Taocan2.Name }), "Id", "Name");
     ViewBag.StatusList = new SelectList((from s in StaticDictionary.GetChargeStatusList() select new { Id = s.Id, Name = s.Value }), "Id", "Name");
     return View(model);
 }
Esempio n. 12
0
        public ActionResult OrderDetail(int orderId)
        {
            OrderManagement orderMgt = new OrderManagement(User.Identity.GetUserId<int>());            
            List<BOrder> orders = orderMgt.FindOrders(orderId, 0, 0, 0, 0, null, null, null, 0, 0, out total);
            if (orders == null || orders.Count == 0)
            {
                ViewBag.Message = string.Format("编号为:{0}的充值记录不存在", orderId);
                return View("Error");
            }

            if(orders[0].AgentId!=orderMgt.CurrentLoginUser.User.Id)
            {
                ViewBag.Message = string.Format("编号为:{0}的充值记录为其他代理商的充值信息,不能查看", orderId);
                return View("Error");
            }

            return View(orders[0]);
        }
Esempio n. 13
0
 public ActionResult OrderDetail(int orderId)
 {
     OrderManagement orderMgt = new OrderManagement(User.Identity.GetUserId<int>());
     if (!orderMgt.CurrentLoginUser.Permission.CHARGE_HISTORY)
     {
         ViewBag.Message = "没有权限查看流量充值记录";
         return View("Error");
     }
     List<BOrder> orders = orderMgt.FindOrders(orderId, 0, 0, 0, 0, null, null, null, 0, 0, out total);
     if(orders==null || orders.Count==0)
     {
         ViewBag.Message = string.Format("编号为:{0}的充值记录不存在",orderId);
         return View("Error");
     }
     return View(orders[0]);
 }
Esempio n. 14
0
        public ActionResult Charge(ChargeModel model)
        {
            BaseManagement baseMgt = new BaseManagement(User.Identity.GetUserId<int>());
            if (!baseMgt.CurrentLoginUser.Permission.CHARGE_BYTE)
            {
                ViewBag.Message = "没有权限充值流量";
                return View("Error");
            }
           
            if (ModelState.IsValid)
            {
                ChargeBridge cb = new ChargeBridge();
                ChargeOrder order = new ChargeOrder() { ChargeType=2, Payed=true, OperateUserId=User.Identity.GetUserId<int>(), AgencyId = 0, Id = 0, Province=model.Province,City=model.City, MobileSP = model.SPName, MobileNumber = model.Mobile, OutOrderId = "", ResourceId = 0, ResourceTaocanId = model.ResourceTaocanId, RouteId = 0, CreatedTime = DateTimeUtil.ConvertDateTimeToInt(DateTime.Now) };
              
                OrderManagement orderMgt = new OrderManagement();
                try
                {
                    order = orderMgt.GenerateOrder(order);
                    ViewBag.Message = "成功提交到充值系统,等待充值,可以到流量充值查询里查看充值状态...";
                }
                catch(KMBitException kex)
                {
                    ViewBag.Message = kex.Message;
                }
                catch(Exception ex)
                {
                    ViewBag.Message = ex.Message;
                }
                           
                //ChargeResult result = cb.Charge(order);
                
            }

            return View();
        }
Esempio n. 15
0
        public ActionResult ChargeOrders(OrderSearchModel searchModel)
        {
            OrderManagement orderMgt = new OrderManagement(User.Identity.GetUserId<int>());
            agentAdminMgt = new AgentAdminMenagement(orderMgt.CurrentLoginUser);
            resourceMgt = new ResourceManagement(orderMgt.CurrentLoginUser);
            if (!orderMgt.CurrentLoginUser.Permission.CHARGE_HISTORY)
            {
                ViewBag.Message = "没有权限查看流量充值记录";
                return View("Error");
            }
            int pageSize = 40;
            DateTime sDate = DateTime.MinValue;
            DateTime eDate = DateTime.MinValue;
            if(!string.IsNullOrEmpty(searchModel.StartTime))
            {
                DateTime.TryParse(searchModel.StartTime, out sDate);
            }
            if (!string.IsNullOrEmpty(searchModel.EndTime))
            {
                DateTime.TryParse(searchModel.EndTime, out eDate);
            }
            long sintDate = sDate!=DateTime.MinValue?DateTimeUtil.ConvertDateTimeToInt(sDate):0;
            long eintDate= eDate != DateTime.MinValue ? DateTimeUtil.ConvertDateTimeToInt(eDate) : 0;
            int page = 1;
            if(Request["page"]!=null)
            {
                int.TryParse(Request["page"],out page);
            }
            searchModel.Page = page;
            List<BOrder> orders = orderMgt.FindOrders(searchModel.OrderId!=null?(int)searchModel.OrderId:0, 
                                                      searchModel.AgencyId!=null?(int)searchModel.AgencyId:0, 
                                                      searchModel.ResourceId!=null?(int)searchModel.ResourceId:0, 
                                                      searchModel.ResourceTaocanId!=null?(int)searchModel.ResourceTaocanId:0, 
                                                      searchModel.RuoteId!=null?(int)searchModel.RuoteId:0, 
                                                      searchModel.SPName, searchModel.MobileNumber,
                                                      searchModel.Status,
                                                      sintDate,
                                                      eintDate,
                                                      out total,
                                                      pageSize,
                                                      searchModel.Page, true);
            PageItemsResult<BOrder> result = new PageItemsResult<BOrder>() { CurrentPage = searchModel.Page, Items = orders, PageSize = pageSize, TotalRecords = total,EnablePaging=true };
            KMBit.Grids.KMGrid<BOrder> grid = new Grids.KMGrid<BOrder>(result);
            BigOrderSearchModel model = new BigOrderSearchModel() { SearchModel = searchModel, OrderGrid = grid };

            List<KMBit.Beans.BUser> agencies = agentAdminMgt.FindAgencies(0, null, null, 0, 0, out total, 0, 0, false,null);
            List<BResource> resources = new List<BResource>();
            if(searchModel.AgencyId!=null)
            {
                resources = agentAdminMgt.FindAgentResources((int)searchModel.AgencyId);
            }else
            {
                resources = resourceMgt.FindResources(0,null,0,out total);
            }
            ViewBag.Agencies = new SelectList((from a in agencies select a.User).ToList<Users>(),"Id","Name");
            ViewBag.Resources = new SelectList((from r in resources select r.Resource).ToList<Resource>(), "Id", "Name");

            List<BResourceTaocan> taocans = new List<BResourceTaocan>();
            if(searchModel.ResourceId!=null)
            {
                if(searchModel.AgencyId==null)
                {
                    taocans = resourceMgt.FindResourceTaocans((int)searchModel.ResourceId, 0, false);
                }
                else
                {
                    taocans = agentAdminMgt.FindAgencyResourceTaocans((int)searchModel.AgencyId, (int)searchModel.ResourceId);
                }                
            }
            ViewBag.Taocans = new SelectList((from t in taocans select new { Id=t.Taocan.Id,Name=t.Taocan2.Name}), "Id", "Name");
            ViewBag.StatusList = new SelectList((from s in StaticDictionary.GetChargeStatusList() select new { Id=s.Id,Name=s.Value}),"Id","Name");
            return View(model);
        }