public ActionResult CreateAgentRoute(CreateAgentRouteModel model) { int agencyId = model.AgencyId; if (agentAdminMgt == null) agentAdminMgt = new AgentAdminMenagement(User.Identity.GetUserId<int>()); resourceMgt = new ResourceManagement(User.Identity.GetUserId<int>()); List<BUser> users = agentAdminMgt.FindAgencies((int)agencyId, null, null, 0, 0, out total); if (users == null || users.Count == 0) { ViewBag.Message = string.Format("编号为 {0} 的代理商存在"); return View("Error"); } BUser agency = users[0]; ViewBag.Agency = agency; if(ModelState.IsValid) { KMBit.DAL.Agent_route ruote; if(model.ResouceTaocans.Length>0) { foreach(int tId in model.ResouceTaocans) { ruote = new DAL.Agent_route() { CreatedBy = User.Identity.GetUserId<int>(), Create_time = DateTimeUtil.ConvertDateTimeToInt(DateTime.Now), Discount = model.Discount, Enabled = model.Enabled, Resource_Id = model.ResourceId, Resource_taocan_id = tId, User_id = model.AgencyId }; bool ret = agentAdminMgt.CreateRoute(ruote); } } return Redirect("/Admin/AgentRoutes?agencyId=" + model.AgencyId); } List<BResource> resources = resourceMgt.FindResources(0, null, 0, out total); ViewBag.Resources = new SelectList((from r in resources select r.Resource).ToList<KMBit.DAL.Resource>(), "Id", "Name"); List<BResourceTaocan> taocans = new List<BResourceTaocan>(); if(model.ResourceId>0) { taocans = resourceMgt.FindEnabledResourceTaocansForAgent(model.ResourceId,model.AgencyId); } ViewBag.ResourceTaocans1 = taocans; return View(model); }
public ApiMessage GetAgencyResources() { this.IniRequest(); ApiMessage message = new ApiMessage(); AgentAdminMenagement agentMgtMgr = new AgentAdminMenagement(User.Identity.Name); int agencyId = 0; int.TryParse(request["agencyId"],out agencyId); if(agencyId>0) { List<BResource> rs = agentMgtMgr.FindAgentResources(agencyId); message.Status = "OK"; message.Item = rs; }else { ResourceManagement resourceMgr = new ResourceManagement(agentMgtMgr.CurrentLoginUser); int total = 0; List<BResource> rs = resourceMgr.FindResources(0, null, 0, out total); message.Status = "OK"; message.Item = rs; } return message; }
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); }
public ActionResult CreateAgentRoute(int agencyId) { if (agentAdminMgt == null) agentAdminMgt = new AgentAdminMenagement(User.Identity.GetUserId<int>()); resourceMgt = new ResourceManagement(User.Identity.GetUserId<int>()); List<BUser> users = agentAdminMgt.FindAgencies((int)agencyId, null, null, 0, 0, out total); if (users == null || users.Count == 0) { ViewBag.Message = string.Format("编号为 {0} 的代理商存在"); return View("Error"); } BUser agency = users[0]; ViewBag.Agency = agency; CreateAgentRouteModel model = new CreateAgentRouteModel() { Enabled = true, AgencyId = agency.User.Id,Id=0 }; List<BResource> resources = resourceMgt.FindResources(0, null, 0, out total); ViewBag.Resources = new SelectList((from r in resources select r.Resource).ToList<KMBit.DAL.Resource>(), "Id", "Name"); List<BResourceTaocan> taocans = new List<BResourceTaocan>(); //taocans = resourceMgt.FindResourceTaocans(0, 1, 0, out total); //ViewBag.ResourceTaocans = new SelectList((from t in taocans select new { Id = t.Taocan.Id, Name = t.City.Name + " " + t.SP.Name + " " + t.Taocan.Quantity }).ToList(), "Id", "Name"); ViewBag.ResourceTaocans1 = taocans; return View("CreateAgentRoute",model); }
public ActionResult CreateResource() { resourceMgt = new ResourceManagement(User.Identity.GetUserId<int>()); List<KMBit.DAL.Area> provinces = resourceMgt.GetAreas(0); List<KMBit.DAL.Sp> sps = resourceMgt.GetSps(); //List<SelectListItem> selProvinces = (from p in provinces select new SelectListItem { Text=p.Name,Value=p.Id.ToString() }).ToList<SelectListItem>(); ViewBag.Provinces = new SelectList(provinces, "Id", "Name"); ViewBag.Cities = new SelectList(new List<KMBit.DAL.Area>(), "Id", "Name"); ViewBag.SPs = new SelectList(sps, "Id", "Name"); ResourceModel model = new ResourceModel() { Enabled = true, Id = 0 }; return View("CreateResource", model); }
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); }
public ActionResult Resources() { int pageSize = 20; int requestPage = 1; int.TryParse(Request["page"], out requestPage); requestPage = requestPage == 0 ? 1 : requestPage; resourceMgt = new ResourceManagement(User.Identity.GetUserId<int>()); if(!resourceMgt.CurrentLoginUser.Permission.VIEW_RESOURCE) { ViewBag.Message = "没有权限查看资源"; return View("Error"); } ViewBag.LoginUser = resourceMgt.CurrentLoginUser; var resources = resourceMgt.FindResources(0, null, 0,out total,requestPage,pageSize,true); PageItemsResult<BResource> result = new PageItemsResult<BResource>() { CurrentPage = requestPage, Items = resources, PageSize = pageSize, TotalRecords = total }; KMBit.Grids.KMGrid<BResource> grid = new Grids.KMGrid<BResource>(result); return View(grid); }
static void test() { ResourceManagement rmgt = new ResourceManagement(3); int total; List<BResource> resources = rmgt.FindResources(2,"xx",0,out total); }
public ActionResult ImportProduct(int resourceId) { if (resourceId <= 0) { ViewBag.Message = "落地资源编号不正确"; return View("Error"); } resourceMgt = new ResourceManagement(User.Identity.GetUserId<int>()); if (!resourceMgt.CurrentLoginUser.Permission.CONFIGURE_RESOURCE) { ViewBag.Message = "没有权限配置落地资源接口信息"; return View("Error"); } try { ChargeBridge bridge = new ChargeBridge(); bridge.ImportResourceProducts(resourceId,User.Identity.GetUserId<int>()); return Redirect("/Admin/ViewResourceTaoCan?resourceId=" + resourceId); } catch(KMBitException ex) { ViewBag.Message = ex.Message; return View("Error"); } }
public ActionResult UpdateResource(ResourceModel model) { resourceMgt = new ResourceManagement(User.Identity.GetUserId<int>()); List<KMBit.DAL.Area> provinces = null; List<KMBit.DAL.Sp> sps = null; if (ModelState.IsValid) { DAL.Resource resource = null; if (model.Id > 0) { List<BResource> resources = resourceMgt.FindResources((int)model.Id, null, 0, out total); if (resources == null) { ViewBag.Message = "试图编辑的资源不存在"; return View("Error"); } BResource bresouce = resources[0]; resource = bresouce.Resource; } else { resource = new DAL.Resource(); resource.Name = model.Name; resource.CreatedBy = User.Identity.GetUserId<int>(); resource.Created_time = DateTimeUtil.ConvertDateTimeToInt(DateTime.Now); } resource.Address = model.Address; resource.City_Id = model.City; resource.Contact = model.Contact; resource.Description = model.Description; resource.Email = model.Email; resource.Enabled = model.Enabled; resource.Province_Id = model.Province; resource.SP_Id = model.SP; resource.UpdatedBy = User.Identity.GetUserId<int>(); resource.Updated_time = DateTimeUtil.ConvertDateTimeToInt(DateTime.Now); try { bool result = false; if (resource.Id <= 0) { result = resourceMgt.CreateResource(resource); } else { result = resourceMgt.UpdateResource(resource); } if (result) { return RedirectToAction("Resources"); } } catch (KMBitException ex) { ViewBag.Exception = ex; } catch (Exception nex) { ViewBag.ErrMsg = nex.Message; } finally { } } else { string validationErrors = string.Join(",", ModelState.Values.Where(E => E.Errors.Count > 0) .SelectMany(E => E.Errors) .Select(E => E.ErrorMessage) .ToArray()); ViewBag.ErrMsg = validationErrors; } provinces = resourceMgt.GetAreas(0); sps = resourceMgt.GetSps(); ViewBag.Provinces = new SelectList(provinces, "Id", "Name"); ViewBag.Cities = new SelectList(resourceMgt.GetAreas(model.Province), "Id", "Name"); ViewBag.SPs = new SelectList(sps, "Id", "Name"); return View("CreateResource",model); }
public ActionResult ConfigureResource(ResourceConfigModel model) { if(ModelState.IsValid) { resourceMgt = new ResourceManagement(User.Identity.GetUserId<int>()); Resrouce_interface api = new Resrouce_interface() { Id = model.Id, Resource_id = model.ResoucedId, APIURL = model.ApiUrl, ProductApiUrl = model.ProductFetchUrl, CallBackUrl = model.CallBack, Interface_classname = model.InterfaceName, Interface_assemblyname = model.InterfaceAssemblyName, Username = model.UserName, Userpassword = model.Password, AppKey=model.AppKey, AppSecret=model.AppSecret, GetTokenUrl=model.GetTokenURL, QueryStatusUrl=model.QueryStatusURL }; if(resourceMgt.UpdateResrouceInterface(api)) { return RedirectToAction("Resources"); } } return View(); }
public ActionResult ConfigureResource(int resourceId) { if(resourceId<=0) { ViewBag.Message = "落地资源编号不正确"; return View("Error"); } ResourceConfigModel model = new ResourceConfigModel() { Id=0,ResoucedId=resourceId}; resourceMgt = new ResourceManagement(User.Identity.GetUserId<int>()); if(!resourceMgt.CurrentLoginUser.Permission.CONFIGURE_RESOURCE) { ViewBag.Message = "没有权限配置落地资源接口信息"; return View("Error"); } try { KMBit.DAL.Resrouce_interface api = resourceMgt.GetResrouceInterface(resourceId); if (api != null) { model.Id = api.Id; model.InterfaceName = api.Interface_classname; model.Password = KMAes.DecryptStringAES(api.Userpassword); model.UserName = api.Username; model.ResoucedId = api.Resource_id; model.ApiUrl = api.APIURL; model.CallBack = api.CallBackUrl; model.ProductFetchUrl = api.ProductApiUrl; model.AppSecret = api.AppSecret; model.AppKey = api.AppKey; model.GetTokenURL = api.GetTokenUrl; model.QueryStatusURL = api.QueryStatusUrl; model.InterfaceAssemblyName = api.Interface_assemblyname; } } catch (KMBitException ex) { ViewBag.Message = ex.Message; return View("Error"); } return View(model); }
public ActionResult EditResource(int resourceId) { resourceMgt = new ResourceManagement(User.Identity.GetUserId<int>()); if (resourceId <= 0) { ViewBag.Message = "资源编号不正确"; return View("Error"); } List<BResource> resources = resourceMgt.FindResources(resourceId, null, 0,out total); if (resources == null) { ViewBag.Message = "试图编辑的资源不存在"; return View("Error"); } BResource resouce = resources[0]; ResourceModel model = new ResourceModel() { Address = resouce.Resource.Address, City = (int)resouce.Resource.City_Id, Contact = resouce.Resource.Contact, Description = resouce.Resource.Description, Email = resouce.Resource.Email, Enabled = resouce.Resource.Enabled, Id = resouce.Resource.Id, Name = resouce.Resource.Name, Province = resouce.Resource.Province_Id, SP = resouce.Resource.SP_Id }; 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"); ViewBag.Cities = new SelectList(resourceMgt.GetAreas(model.Province), "Id", "Name"); ViewBag.SPs = new SelectList(sps, "Id", "Name"); return View("CreateResource", model); }
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; }
public ActionResult CreateResourceTaocan(int? resourceId) { if(resourceId==null) { ViewBag.Message = "资源信息丢失"; return View("Error"); } int id = (int)resourceId; ResourceTaocanModel mode = new ResourceTaocanModel() { ResoucedId=id,EnabledDiscount=true}; if (id <= 0) { ViewBag.Message = "资源信息丢失"; return View("Error"); } resourceMgt = new ResourceManagement(User.Identity.GetUserId<int>()); List<BResource> resources = resourceMgt.FindResources(id, null, 0, out total); if(resources == null || resources.Count==0) { ViewBag.Message = "资源信息丢失"; return View("Error"); } BResource resource = resources[0]; 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"); ViewBag.Cities = new SelectList(new List<KMBit.DAL.Area>(), "Id", "Name"); ViewBag.NCities = new SelectList(new List<KMBit.DAL.Area>(), "Id", "Name"); ViewBag.SPs = new SelectList(sps, "Id", "Name"); ViewBag.Resource = resource; mode.Enabled = true; mode.EnabledDiscount = true; return View(mode); }
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(); }
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); }
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); }
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); }