예제 #1
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();
        }
예제 #2
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);
        }
예제 #3
0
        public ApiMessage GetAgencyResourceTaocans()
        {
            this.IniRequest();
            ApiMessage message = new ApiMessage();
            AgentAdminMenagement agentMgtMgr = new AgentAdminMenagement(User.Identity.Name);
            int agencyId = 0;
            int resourceId = 0;
            int.TryParse(request["agencyId"], out agencyId);
            int.TryParse(request["resourceId"], out resourceId);
            if(agencyId==0 && resourceId==0)
            {
                message.Status = "ERROR";
                message.Item = null;
                message.Message = "代理商编号和资源编号都不能为空";
                return message;
            }
            List<BResourceTaocan> taocans = new List<BResourceTaocan>();
            if(resourceId>0 && agencyId>0)
            {
                taocans = agentMgtMgr.FindAgencyResourceTaocans(agencyId, resourceId);
            }else if(resourceId>0 && agencyId<=0)
            {
                ResourceManagement resourceMgr = new ResourceManagement(agentMgtMgr.CurrentLoginUser);
                taocans = resourceMgr.FindResourceTaocans(resourceId, 0, false);
            }

            message.Status = "OK";
            message.Item = taocans;
            return message;
        }
예제 #4
0
 public ActionResult ViewResourceTaoCan(int? resourceId)
 {
     int id = resourceId??0;            
     resourceMgt = new ResourceManagement(User.Identity.GetUserId<int>());
     List<BResource> resources = resourceMgt.FindResources(id, null, 0,out total);
     if (resources == null || resources.Count == 0)
     {               
         return View("Error");
     }
     int pageSize = 50;
     int requestPage = 1;
     int.TryParse(Request["page"], out requestPage);
     requestPage = requestPage == 0 ? 1 : requestPage;
     List<BResourceTaocan> resourceTaocans = resourceMgt.FindResourceTaocans(0, id, 0, out total, requestPage, pageSize,false);
     PageItemsResult<BResourceTaocan> result = new PageItemsResult<BResourceTaocan>() { CurrentPage = requestPage, Items = resourceTaocans, PageSize = resourceTaocans.Count, TotalRecords = total };
     result.EnablePaging = false;
     KMBit.Grids.KMGrid<BResourceTaocan> grid = new Grids.KMGrid<BResourceTaocan>(result);
     ViewBag.Resource = resources[0];
     return View(grid);
 }
예제 #5
0
        public ActionResult UpdateResourceTaocan(ResourceTaocanModel model)
        {
            bool ret = false;
            resourceMgt = new ResourceManagement(User.Identity.GetUserId<int>());
            List<BResource> resources = resourceMgt.FindResources(model.ResoucedId, null, 0, out total);
            if (resources == null || resources.Count == 0)
            {
                ViewBag.Message = "资源信息丢失";
                return View("Error");
            }
            BResource resource = resources[0];

            if (ModelState.IsValid)
            {
                KMBit.DAL.Resource_taocan taocan = null;
                if(model.Id>0)
                {
                    int total = 0;
                    List<BResourceTaocan> ts = resourceMgt.FindResourceTaocans(model.Id, 0, 0, out total);
                    if (total == 1)
                    {
                        taocan = ts[0].Taocan;
                    }
                }else
                {
                    taocan = new DAL.Resource_taocan();
                    taocan.CreatedBy = User.Identity.GetUserId<int>();
                    taocan.Created_time = DateTimeUtil.ConvertDateTimeToInt(DateTime.Now);
                    taocan.Quantity = model.Quantity;
                    taocan.Resource_id = model.ResoucedId;
                }
                taocan.Serial = model.Serial;
                taocan.Area_id = model.Province != null ? (int)model.Province : 0;
                taocan.City_id = model.City!=null ?(int)model.City:0;
                taocan.NumberProvinceId = model.NumberProvince != null ? (int)model.NumberProvince : 0;
                taocan.NumberCityId = model.NumberCity != null ? (int)model.NumberCity : 0;
                taocan.Enabled = model.Enabled;
                taocan.Purchase_price = model.PurchasePrice;
                taocan.EnableDiscount = model.EnabledDiscount;
                taocan.Resource_Discount = model.Discount;
                taocan.Sale_price = model.SalePrice;
                taocan.Sp_id = model.SP != null ? (int)model.SP : 0;               
                taocan.UpdatedBy = User.Identity.GetUserId<int>();
                taocan.Updated_time = DateTimeUtil.ConvertDateTimeToInt(DateTime.Now);
                try
                {
                    if (model.Id <= 0)
                    {
                        ret = resourceMgt.CreateResourceTaocan(taocan);
                    }
                    else
                    {
                        ret = resourceMgt.UpdateResourceTaocan(taocan);
                    }
                }
                catch(KMBitException kex)
                {
                    KMLogger.GetLogger().Error(kex);
                    ViewBag.Message = kex.Message;
                    return View("Error");
                }                
                catch(Exception ex)
                {
                    KMLogger.GetLogger().Fatal(ex);
                    ViewBag.Message = "未知错误,请联系系统管理员";
                    return View("Error");
                }
                if (ret)
                {
                    return Redirect("/Admin/ViewResourceTaoCan?resourceId=" + model.ResoucedId);
                }
                else
                {
                    ViewBag.Message = "未知错误,请联系系统管理员";
                    return View("Error");
                }
            }else
            {
                var errors = ModelState
                .Where(x => x.Value.Errors.Count > 0)
                .Select(x => new { x.Key, x.Value.Errors })
                .ToArray();
                ViewBag.Message = "资源套餐创建失败";
                return View("Error");
            }
            List<KMBit.DAL.Area> provinces = null;
            List<KMBit.DAL.Sp> sps = null;
            provinces = resourceMgt.GetAreas(0);
            sps = resourceMgt.GetSps();
            ViewBag.Resource = resource;
            ViewBag.Provinces = new SelectList(provinces, "Id", "Name");
            ViewBag.Cities = new SelectList(resourceMgt.GetAreas(model.Province != null ? (int)model.Province : 0), "Id", "Name");
            ViewBag.SPs = new SelectList(sps, "Id", "Name");

            return View("CreateResourceTaocan",model);
        }
예제 #6
0
 public ActionResult UpdateResourceTaocan(int taocanId)
 {           
     if(taocanId<=0)
     {
         ViewBag.Message = "套餐信息丢失";
         return View("Error");
     }
     resourceMgt = new ResourceManagement(User.Identity.GetUserId<int>());
     List<BResourceTaocan> resourceTaocans = resourceMgt.FindResourceTaocans(taocanId, 0, 0, out total, 1, 1);
     if(total==0)
     {
         ViewBag.Message = "编号为"+taocanId+"的套餐不存在";
         return View("Error");
     }
     BResourceTaocan bTaocan = resourceTaocans[0];
     ResourceTaocanModel model = new ResourceTaocanModel()
     {
         Id = bTaocan.Taocan.Id,
         Serial = bTaocan.Taocan.Serial,
         Province = bTaocan.Taocan.Area_id,
         City = bTaocan.Taocan.City_id,
         NumberProvince=bTaocan.Taocan.NumberProvinceId,
         NumberCity=bTaocan.Taocan.NumberCityId,
         Enabled = bTaocan.Taocan.Enabled,
         PurchasePrice = bTaocan.Taocan.Purchase_price,
         Quantity = bTaocan.Taocan.Quantity,
         ResoucedId = bTaocan.Taocan.Resource_id,
         SalePrice = bTaocan.Taocan.Sale_price,
         SP = bTaocan.Taocan.Sp_id,
         Discount = bTaocan.Taocan.Resource_Discount,
         EnabledDiscount = bTaocan.Taocan.EnableDiscount,
         
     };
   
     List<KMBit.DAL.Area> provinces = null;
     List<KMBit.DAL.Sp> sps = null;
     provinces = resourceMgt.GetAreas(0);
     sps = resourceMgt.GetSps();
     ViewBag.Provinces = new SelectList(provinces, "Id", "Name");
     if (model.City > 0)
     {
         ViewBag.Cities = new SelectList(resourceMgt.GetAreas((int)model.Province), "Id", "Name");
     }
     else
     {
         ViewBag.Cities = new SelectList(new List<KMBit.DAL.Area>(), "Id", "Name");
     }
     if(model.NumberCity>0)
     {
         ViewBag.NCities = new SelectList(resourceMgt.GetAreas((int)model.NumberProvince), "Id", "Name");
     }else
     {
         ViewBag.NCities = new SelectList(new List<KMBit.DAL.Area>(), "Id", "Name");
     }
     ViewBag.SPs = new SelectList(sps, "Id", "Name");
     ViewBag.Resource = bTaocan.Resource;
     return View("CreateResourceTaocan",model);
 }
예제 #7
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);
        }