Exemple #1
0
        public string DelCard(string etnum, int id = 0)
        {
            string    tnum      = LokFuEncode.LokFuAPIDecode(etnum, DllName);
            FastOrder FastOrder = Entity.FastOrder.FirstOrDefault(n => n.TNum == tnum);

            if (FastOrder == null)
            {
                return("0");
            }
            Users Users = Entity.Users.FirstOrDefault(n => n.Id == FastOrder.UId);

            if (Users == null)
            {
                return("0");
            }
            UsersPayCard UsersPayCard = Entity.UsersPayCard.FirstOrDefault(n => n.UId == FastOrder.UId && n.Id == id);

            if (UsersPayCard == null)
            {
                return("0");
            }
            UsersPayCard.State = 0;
            Entity.SaveChanges();
            return("1");
        }
Exemple #2
0
        public ActionResult Index(string etnum)
        {
            if (etnum.IsNullOrEmpty())
            {
                ViewBag.ErrorMsg = "Some Error[00]";
                return(View("Error"));
            }
            string    tnum      = LokFuEncode.LokFuAPIDecode(etnum, DllName);
            FastOrder FastOrder = Entity.FastOrder.FirstOrDefault(n => n.TNum == tnum);

            if (FastOrder == null)
            {
                ViewBag.ErrorMsg = "Some Error[02]";
                return(View("Error"));
            }
            ViewBag.FastOrder = FastOrder;

            Users Users = Entity.Users.FirstOrDefault(n => n.Id == FastOrder.UId);

            ViewBag.Users = Users;

            IList <UsersPayCard> UsersPayCardList = Entity.UsersPayCard.Where(n => n.UId == Users.Id && n.State == 1).ToList();

            ViewBag.UsersPayCardList = UsersPayCardList;

            ViewBag.etnum = etnum;

            return(View());
        }
        public ActionResult Index(string etnum)
        {
            if (etnum.IsNullOrEmpty())
            {
                ViewBag.ErrorMsg = "Some Error[00]";
                return(View("Error"));
            }
            string    tnum      = LokFuEncode.LokFuAPIDecode(etnum, DllName);
            FastOrder FastOrder = Entity.FastOrder.FirstOrDefault(n => n.TNum == tnum);

            if (FastOrder == null)
            {
                ViewBag.ErrorMsg = "Some Error[02]";
                return(View("Error"));
            }
            FastPayWay FastPayWay = Entity.FastPayWay.FirstOrDefault(n => n.Id == FastOrder.PayWay);

            if (FastOrder == null)
            {
                ViewBag.ErrorMsg = "Some Error[03]";
                return(View("Error"));
            }
            if (FastPayWay.DllName != DllName)
            {
                ViewBag.ErrorMsg = "Some Error[04]";
                return(View("Error"));
            }
            string[] PayConfigArr = FastPayWay.QueryArray.Split(',');
            if (PayConfigArr.Length != 3)
            {
                ViewBag.ErrorMsg = "Some Error[05]";
                return(View("Error"));
            }
            FastUserPay FastUserPay = Entity.FastUserPay.FirstOrDefault(n => n.PayWay == FastOrder.PayWay && n.UId == FastOrder.UId && n.MerState == 1);

            if (FastUserPay == null)
            {
                ViewBag.ErrorMsg = "商户通道异常";
                return(View("Error"));
            }

            string paywaycode = PayConfigArr[2];                                   //绑定通道
            string OrderMoney = (FastOrder.Amoney * 100).ToString("F0");           //金额,以分为单
            string ReturnUrl  = PayPath + "/PayCenter/HFJSPay/FastResult.html";    //支付成功跳转页
            string BackUrl    = NoticePath + "/PayCenter/HFJSPay/FastNotice.html"; //后台通过地址

            string Data = "{\"txnamt\":\"" + OrderMoney + "\",\"merid\":\"" + FastUserPay.MerId + "\",\"paywaycode\":\"" + paywaycode + "\",\"orderid\":\"" + FastOrder.TNum + "\",\"backurl\":\"" + BackUrl + "\",\"fronturl\":\"" + ReturnUrl + "\"}";

            string DataBase64 = LokFuEncode.Base64Encode(Data, "utf-8");
            string Sign       = (DataBase64 + FastUserPay.MerKey).GetMD5();

            string GoUrl = "https://api.zhifujiekou.com/apis/fastorderspay?";

            GoUrl += "req=" + HttpUtility.UrlEncode(DataBase64);
            GoUrl += "&sign=" + Sign;

            Response.Redirect(GoUrl);

            return(View("Null"));
        }
        public ActionResult StateChange(FastOrder FastOrder)
        {
            if (!(FastOrder.UserState == 1 || FastOrder.UserState == 2))
            {
                ViewBag.ErrorMsg = "请输入正确的状态";
                return(View("Error"));
            }
            var baseFastOrder = this.Entity.FastOrder.FirstOrDefault(o => o.TNum == FastOrder.TNum);

            if (!baseFastOrder.IsStateChange())
            {
                ViewBag.ErrorMsg = "用户结算状态未符合规则";
                return(View("Error"));
            }
            baseFastOrder.UserState = FastOrder.UserState;
            baseFastOrder.Remark    = FastOrder.Remark;
            var FastOrderOP = new FastOrderOP()
            {
                AddTime   = DateTime.Now,
                AdminId   = this.AdminUser.Id,
                AdminName = this.AdminUser.TrueName,
                State     = baseFastOrder.UserState,
                TNum      = baseFastOrder.TNum,
                Remark    = baseFastOrder.Remark,
            };

            this.Entity.FastOrderOP.AddObject(FastOrderOP);
            this.Entity.SaveChanges();
            ViewBag.Msg = "设置成功";
            return(View("Succeed"));
        }
        public ActionResult MyOrder(FastOrder FastOrder)
        {
            if (!IsLokFu)
            {
                ViewBag.ErrorMsg = "请在钱包中打开链接!";
                return(View("Error"));
            }
            if (BasicUsers == null)//用户令牌不存在
            {
                ViewBag.ErrorMsg = "您未登录或已在其它手机登录!";
                return(View("Error"));
            }
            if (BasicUsers.State != 1)//用户被锁定
            {
                ViewBag.ErrorMsg = "您的帐户被锁定!";
                return(View("Error"));
            }
            if (BasicUsers.CardStae != 2)//未实名认证
            {
                ViewBag.ErrorMsg = "您未实名认证!";
                return(View("Error"));
            }
            FastOrder FO = Entity.FastOrder.FirstOrDefault(n => n.UId == BasicUsers.Id && n.TNum == FastOrder.TNum);

            if (FO == null)
            {
                ViewBag.ErrorMsg = "订单不存在!";
                return(View("Error"));
            }
            ViewBag.FastOrder = FO;
            return(View());
        }
        /// <summary>
        /// 统计
        /// </summary>
        /// <returns></returns>
        public ActionResult IndexStats(FastOrder FastOrder, EFPagingInfo <FastOrder> p, bool?IsShowSupAgent)
        {
            //条件:已支付,正常
            //总金额
            //笔数
            //手续费
            //分润
            if (IsShowSupAgent == null)
            {
                IsShowSupAgent = false;
            }
            p = this.Condition(FastOrder, p, IsShowSupAgent.Value);
            var Iquery = this.Entity.FastOrder.AsQueryable();

            foreach (var item in p.SqlWhere)
            {
                Iquery = Iquery.Where(item);
            }
            //var Iquery = this.Entity.FastOrder.Where(o => o.State == 1 && o.PayState == 1);
            ViewBag.SumAmoney      = Iquery.Sum(o => (decimal?)o.Amoney) ?? 0m;
            ViewBag.SumPoundage    = Iquery.Sum(o => (decimal?)o.Poundage) ?? 0m;
            ViewBag.SumAgentPayGet = Iquery.Sum(o => (decimal?)o.AgentPayGet) ?? 0m;
            ViewBag.Count          = Iquery.Count();
            return(this.View());
        }
Exemple #7
0
 public ActionResult Info(FastOrder FastOrder)
 {
     if (!FastOrder.Id.IsNullOrEmpty())
     {
         FastOrder = Entity.FastOrder.FirstOrDefault(n => n.Id == FastOrder.Id);
     }
     else if (!FastOrder.TNum.IsNullOrEmpty())
     {
         FastOrder = Entity.FastOrder.FirstOrDefault(n => n.TNum == FastOrder.TNum);
     }
     if (FastOrder == null)
     {
         ViewBag.ErrorMsg = "查询的交易不存在";
         return(View("Error"));
     }
     if (!IsBelongToAgent(FastOrder.Agent))
     {
         ViewBag.ErrorMsg = AgentLanguage.Surmount;
         return(View("Error"));
     }
     ViewBag.FastOrder = FastOrder;
     ViewBag.Users     = Entity.Users.FirstOrNew(n => n.Id == FastOrder.UId);
     ViewBag.SysAgent  = Entity.SysAgent.FirstOrNew(n => n.Id == FastOrder.Agent);
     return(View("Edit"));
 }
Exemple #8
0
        public ActionResult IndexOrderProfitLog(string tnum)
        {
            FastOrder FastOrder = Entity.FastOrder.FirstOrDefault(n => n.TNum == tnum);

            if (FastOrder == null)
            {
                ViewBag.ErrorMsg = "查询的交易不存在";
                return(View("Error"));
            }
            var query = this.Entity.OrderProfitLog.Where(o => o.TNum == tnum);

            if (FastOrder.Agent == this.BasicAgent.Id)
            {
                query = query.Where(o => (o.Agent == this.BasicAgent.Id || o.LogType == 1));
            }
            else
            {
                query = query.Where(o => o.Agent == this.BasicAgent.Id);
            }
            var OrderProfitLog = query.OrderByDescending(o => o.Id).ToList();

            ViewBag.OrderProfitLog = OrderProfitLog;

            var UIds         = OrderProfitLog.Select(o => o.UId).ToList();
            var UserNameList = this.Entity.Users.Where(o => UIds.Contains(o.Id)).ToDictionary(o => o.Id, o => o.TrueName);

            ViewBag.UserNameList = UserNameList;

            var Agents     = OrderProfitLog.Select(o => o.Agent).ToList();
            var AgentsList = this.Entity.SysAgent.Where(o => Agents.Contains(o.Id)).ToDictionary(o => o.Id, o => o.Name);

            ViewBag.SysAgentList = AgentsList;

            return(View());
        }
Exemple #9
0
        public ActionResult Index(FastOrder FastOrder, EFPagingInfo <FastOrder> p, bool?IsShowSupAgent, int?LowerLevel, int IsFirst = 0)
        {
            if (IsShowSupAgent == null)
            {
                IsShowSupAgent = false;
            }
            LowerLevel = LowerLevel == null ? 0 : LowerLevel;
            p          = this.Condition(FastOrder, p, IsShowSupAgent.Value, LowerLevel.Value);
            IPageOfItems <FastOrder> FastOrderList = null;

            if (IsFirst == 0)
            {
                FastOrder.STime = DateTime.Now.AddDays(-1).Date;
                FastOrder.ETime = DateTime.Now;
                FastOrderList   = new PageOfItems <FastOrder>(new List <FastOrder>(), 0, 10, 0, new Hashtable());
            }
            else
            {
                FastOrderList = Entity.Selects <FastOrder>(p);
            }
            ViewBag.FastOrderList = FastOrderList;
            ViewBag.FastOrder     = FastOrder;
            //副表信息
            List <int> UId = FastOrderList.Select(o => o.UId).Distinct().ToList();

            ViewBag.UsersList = Entity.Users.Where(n => n.State == 1 && UId.Contains(n.Id)).ToList();

            //其他信息
            ViewBag.IsShowSupAgent = IsShowSupAgent;//是否显示下级
            ViewBag.LowerLevel     = LowerLevel;

            //权限相关
            ViewBag.Edit = this.checkPower("Edit");
            return(View());
        }
Exemple #10
0
 public override int GetHashCode()
 {
     unchecked
     {
         var hashCode = _totalBalance.GetHashCode();
         hashCode = (hashCode * 397) ^ AutoSleep.GetHashCode();
         hashCode = (hashCode * 397) ^ SleepThreshold.GetHashCode();
         hashCode = (hashCode * 397) ^ (Login != null ? Login.GetHashCode() : 0);
         hashCode = (hashCode * 397) ^ (Password != null ? Password.GetHashCode() : 0);
         hashCode = (hashCode * 397) ^ (Role != null ? Role.GetHashCode() : 0);
         hashCode = (hashCode * 397) ^ LicenseExpDate.GetHashCode();
         hashCode = (hashCode * 397) ^ (Status != null ? Status.GetHashCode() : 0);
         hashCode = (hashCode * 397) ^ (ConnectionID != null ? ConnectionID.GetHashCode() : 0);
         hashCode = (hashCode * 397) ^ (Sleep != null ? Sleep.GetHashCode() : 0);
         hashCode = (hashCode * 397) ^ Alerts.GetHashCode();
         hashCode = (hashCode * 397) ^ AllTrades.GetHashCode();
         hashCode = (hashCode * 397) ^ AllTradesPro.GetHashCode();
         hashCode = (hashCode * 397) ^ Chart.GetHashCode();
         hashCode = (hashCode * 397) ^ Counter.GetHashCode();
         hashCode = (hashCode * 397) ^ L2.GetHashCode();
         hashCode = (hashCode * 397) ^ Logbook.GetHashCode();
         hashCode = (hashCode * 397) ^ Trading.GetHashCode();
         hashCode = (hashCode * 397) ^ FastOrder.GetHashCode();
         hashCode = (hashCode * 397) ^ (Email != null ? Email.GetHashCode() : 0);
         hashCode = (hashCode * 397) ^ SleepThreshold.GetHashCode();
         hashCode = (hashCode * 397) ^ ProfitControl.GetHashCode();
         hashCode = (hashCode * 397) ^ ProfitLimit.GetHashCode();
         hashCode = (hashCode * 397) ^ ProfitLossLimit.GetHashCode();
         return(hashCode);
     }
 }
Exemple #11
0
        static void Main(string[] args)
        {
            User user1 = new User();


            SolarEngine solar = new SolarEngine(1);                                                                                               //СОЗДАЕМ ДВИГАТЕЛЬ

            Vehicle <SolarEngine> car1 = new Vehicle <SolarEngine>("BMW", "Машина без поворотников", 9999999, 1500000, "Синий", "Машина", solar); //СОЗДАЕМ МАШИНУ НА СОЛНЕЧНОЙ ЭНЕРГИИ

            Food    cucumber = new Food("Огурец", "Овощь", 10, 210, 150, null);                                                                   //СОЗДАЕМ ОГУРЕЦ
            Food    tomato   = new Food("Помидор", "Овощь", 15, 100, 20, null);                                                                   //СОЗДАЕМ ПОМИДОР
            Food    banana   = new Food("Банан", "Фрукт", 40, 50, 30, null);                                                                      //СОЗДАЕМ БАНАН
            Clothes tshirt   = new Clothes("Футболка Kelvin Don", "Хлопчатобумажная футболка с принтом ", 5000, 100, "Белый", "Футболка");        //СОЗДАЕМ ФУТБОЛКУ
            Clothes coat     = new Clothes("Пальто Lious Makarti", "100% Синтетика", 9999, 500, "Черный", "Пальто");                              //СОЗДАЕМ ПАЛЬТО

            PickPointDelivery deliv = new PickPointDelivery("Пункт выдачи по адресу ...");                                                        //СОЗДАЕМ ДОСТАВКУ В ПУНКТ ВЫДАЧИ

            Order <PickPointDelivery> order = new Order <PickPointDelivery>(deliv);                                                               //СОЗДАЕМ ОБЫЧНЫЙ ЗАКАЗ

            order.AddProduct(car1);
            order.AddProduct(cucumber);
            order.AddProduct(tomato);
            order.AddProduct(banana);               //ДОБАВЛЯЕМ ПРОДУКТЫ
            order.AddProduct(tshirt);
            order.AddProduct(coat);

            Console.ReadLine();

            Console.WriteLine(order[4].GetName() + " стоит " + order[4].GetCost());             //ПОЛУЧАЕМ ПРЕДМЕТ ПО ИНДЕКСУ И ВЫВОДИМ ЕГО ИНФОРМАЦИЮ НА ЭКРАН (НАЗВАНИЕ И СТОИМОСТЬ)

            Console.ReadLine();

            GasEngine gas = new GasEngine(1);                                                                                              //СОЗДАЕМ ДВИГАТЕЛЬ

            Vehicle <GasEngine> supercar = new Vehicle <GasEngine>("LAMBORGHINI", "Суперкар", 19999999, 1200000, "Желтый", "Машина", gas); //СОЗДАЕМ МАШИНУ НА БЕНЗИНЕ

            Clothes supercoat = new Clothes("Пальто Golden Шик", "100% из шерсти", 199999, 500, "Фиальковый", "Пальто");                   //СОЗДАЕМ ПАЛЬТО

            HomeDelivery sDeliv = new HomeDelivery("Красная площидь 1");                                                                   //СОЗДАЕМ ДОСТАВКУ НА ДОМ

            FastOrder <HomeDelivery> sOrder = new FastOrder <HomeDelivery>(sDeliv);                                                        //СОЗДАЕМ  БЫСТРЫЙ ЗАКАЗ

            sOrder.AddProduct(supercoat);
            sOrder.AddProduct(supercar);

            Console.ReadLine();

            Console.WriteLine("Номер первого заказа: " + order.GetOrderNumber());
            Console.WriteLine("Номер второго заказа: " + sOrder.GetOrderNumber());

            Console.ReadLine();

            Console.WriteLine($"{order.ArrivingDay} первый заказ приедет по адресу {order.Delivery.GetAdress()} ({order.Delivery.DeliveryType})");
            Console.WriteLine($"{sOrder.ArrivingDay} второй заказ приедет по адресу {sOrder.Delivery.GetAdress()} ({sOrder.Delivery.DeliveryType})");

            Console.ReadLine();
        }
        public static void ToName(this List <OrdersViewModel2> orders)
        {
            orders.ForEach(o =>
            {
                #region 直通车订单
                if (o.toway == 2)
                {
                    o.otypename = Utils.GetFastOrderModel().FirstOrNew(n => n.Id == o.otype).Name;

                    var temp = new FastOrder()
                    {
                        State     = o.state,
                        PayState  = o.paystate,
                        UserState = o.userstate,
                        OType     = o.otype
                    };
                    o.statename = temp.GeStateName();
                    o.colour    = temp.GeStateColour();
                }
                #endregion

                #region 交易订单
                if (o.toway == 1)
                {
                    if (o.otype != 4)
                    {
                        IList <OrdersModel> OML = Utils.GetOrdersModel();
                        OrdersModel OrdersModel = OML.FirstOrNew(n => n.Id == o.otype);
                        o.otypename             = OrdersModel.Name;
                    }
                    else
                    {
                        o.otypename = "转账";
                    }

                    var temp = new Orders()
                    {
                        TState      = o.state,
                        TDState     = o.tdstate,
                        TType       = o.otype,
                        InState     = o.instate,
                        IdCardState = o.idcardstate,
                        PayState    = o.paystate,
                    };
                    o.statename = temp.GetState();
                    o.colour    = temp.GeStateColour();
                }
                #endregion
            });
        }
        /// <summary>
        /// 统计
        /// </summary>
        /// <returns></returns>
        public ActionResult IndexStats(FastOrder FastOrder, EFPagingInfo <FastOrder> p)
        {
            p.PageSize = 9999999;
            string STimeStr = string.Empty;
            string ETimeStr = string.Empty;
            string TNumStr  = string.Empty;

            if (FastOrder.STime == null || FastOrder.STime == DateTime.MinValue)
            {
                FastOrder.STime = DateTime.Now.AddDays(-1);
            }
            if (FastOrder.ETime == null || FastOrder.ETime == DateTime.MinValue)
            {
                FastOrder.ETime = DateTime.Now;
            }

            TimeSpan TS   = FastOrder.ETime.Subtract(FastOrder.STime);
            int      Days = TS.Days;

            if (Days > 31)
            {
                return(null);
            }
            STimeStr = " AND L.AddTime >= '" + FastOrder.STime.ToString("yyyy-MM-dd HH:mm:ss") + "'";
            ETimeStr = " AND L.AddTime <= '" + FastOrder.ETime.ToString("yyyy-MM-dd HH:mm:ss") + "'";
            if (!FastOrder.TNum.IsNullOrEmpty())
            {
                TNumStr = " AND L.TNum = " + FastOrder.TNum.ToString();
            }
            int           s        = ((p.PageIndex == 0 ? 1 : p.PageIndex) - 1) * p.PageSize;
            int           e        = (p.PageIndex + 1) * p.PageSize;
            var           DataList = new List <FastShareProfitModel>();
            StringBuilder sql      = new StringBuilder();

            sql.Append(" select * From ( ");
            sql.Append(" select O.Id,row_number() OVER (ORDER BY O.Id DESC) AS RowNumber,O.TNum,O.OType,O.UserState,O.Amoney,ISNULL(L.UId,0) UId,ISNULL(L.LogType,0) LogType,ISNULL(Sum(L.Profit), 0) Profit,L.AddTime  ");
            sql.Append(" From FastOrder(nolock) O Left Join OrderProfitLog(nolock) L ON O.TNum=L.TNum AND L.IsDel=0 ");
            sql.Append(" Where O.IsDel=0 " + STimeStr + ETimeStr + TNumStr);
            sql.Append(" Group By O.Id,O.TNum,L.UId,O.Amoney,O.OType,O.UserState,L.LogType,L.AddTime ");
            sql.Append(" ) AS D Where RowNumber BETWEEN " + s.ToString() + " AND " + e.ToString() + " Order By Id desc");
            DataList          = Entity.ExecuteStoreQuery <FastShareProfitModel>(sql.ToString(), null).ToList();
            ViewBag.SumAmoney = DataList.Sum(o => o.Amoney);
            ViewBag.SumProfit = DataList.Sum(o => o.Profit);
            ViewBag.Count     = DataList.Count;
            return(this.View());
        }
        public ActionResult Index(FastOrder FastOrder, EFPagingInfo <FastOrder> p, bool?IsShowSupAgent, int IsFirst = 0)
        {
            if (IsShowSupAgent == null)
            {
                IsShowSupAgent = false;
            }
            p = this.Condition(FastOrder, p, IsShowSupAgent.Value);
            IPageOfItems <FastOrder> FastOrderList = null;

            if (IsFirst == 0)
            {
                FastOrderList = new PageOfItems <FastOrder>(new List <FastOrder>(), 0, 10, 0, new Hashtable());
            }
            else
            {
                FastOrderList = Entity.Selects <FastOrder>(p);
            }
            ViewBag.FastOrderList = FastOrderList;
            ViewBag.FastOrder     = FastOrder;
            //副表信息
            List <int> UId = FastOrderList.Select(o => o.UId).Distinct().ToList();

            ViewBag.UsersList = Entity.Users.Where(n => n.State == 1 && UId.Contains(n.Id)).ToList();

            //其他信息
            var FastPayWayList        = Entity.FastPayWay.ToList();
            var AllowFastPayWayIdList = FastPayWayList.Where(o => AllowFastPayWay.Contains(o.DllName)).Select(o => o.Id).ToList();

            ViewBag.FastPayWayList        = FastPayWayList;
            ViewBag.AllowFastPayWayIdList = AllowFastPayWayIdList;
            ViewBag.SysAgentList          = Entity.SysAgent.Where(n => n.State == 1).ToList();
            ViewBag.IsShowSupAgent        = IsShowSupAgent;//是否显示下级

            //权限相关
            ViewBag.Edit             = this.checkPower("Edit");
            ViewBag.IndexStats       = this.checkPower("IndexStats");
            ViewBag.ExcelExport      = this.checkPower("ExcelExport");
            ViewBag.SysAgentClearing = this.checkPower("SysAgentClearing");
            ViewBag.StateChange      = this.checkPower("StateChange");
            ViewBag.Resubmit         = this.checkPower("Resubmit");
            ViewBag.ExcelInport      = this.checkPower("ExcelInport");
            ViewBag.Download         = this.checkPower("Download");
            ViewBag.OrdersRepair     = this.checkPower("OrdersRepair");
            return(View());
        }
        public ActionResult Success(string code)
        {
            string    TNum      = LokFuEncode.Base64Decode(code);
            FastOrder FastOrder = Entity.FastOrder.FirstOrDefault(n => n.TNum == TNum);

            if (FastOrder == null)
            {
                ViewBag.ErrorMsg = "订单不存在!";
                return(View("Error"));
            }
            if (FastOrder.PayState != 1)
            {
                ViewBag.ErrorMsg = "订单未支付!";
                return(View("Error"));
            }
            ViewBag.FastOrder = FastOrder;
            return(View());
        }
 public ActionResult Info(FastOrder FastOrder)
 {
     if (!FastOrder.Id.IsNullOrEmpty())
     {
         FastOrder = Entity.FastOrder.FirstOrDefault(n => n.Id == FastOrder.Id);
     }
     else if (!FastOrder.TNum.IsNullOrEmpty())
     {
         FastOrder = Entity.FastOrder.FirstOrDefault(n => n.TNum == FastOrder.TNum);
     }
     if (FastOrder == null)
     {
         ViewBag.ErrorMsg = "数据不存在";
         return(View("Error"));
     }
     ViewBag.FastOrder  = FastOrder;
     ViewBag.Users      = Entity.Users.FirstOrNew(n => n.Id == FastOrder.UId);
     ViewBag.SysAgent   = Entity.SysAgent.FirstOrNew(n => n.Id == FastOrder.Agent);
     ViewBag.FastPayWay = Entity.FastPayWay.FirstOrNew(o => o.Id == FastOrder.PayWay);
     return(View("Edit"));
 }
        /// <summary>
        /// 一户一码模式绑卡类交易入口
        /// </summary>
        /// <param name="Id"></param>
        /// <param name="sign"></param>
        public void Pay(int Id, string sign)
        {
            if (Id.IsNullOrEmpty() || sign.IsNullOrEmpty())
            {
                Response.Write("Some Error[00]");
                return;
            }
            if (((Id * 100 + 99) + "Pay").GetMD5().Substring(8, 8) != sign)
            {
                Response.Write("Some Error[01]");
                return;
            }
            FastOrder FastOrder = Entity.FastOrder.FirstOrDefault(n => n.Id == Id);

            if (FastOrder == null)
            {
                Response.Write("Some Error[02]");
                return;
            }
            FastPayWay FastPayWay = Entity.FastPayWay.FirstOrDefault(n => n.Id == FastOrder.PayWay);

            if (FastPayWay == null)
            {
                Response.Write("Some Error[03]");
                return;
            }
            if (FastPayWay.DllName == "HFPay" || FastPayWay.DllName == "HFJSPay")
            {
                //不需要绑卡,去支付
                Response.Redirect("/paycenter/" + FastPayWay.DllName.ToLower() + "/index.html?etnum=" + HttpUtility.UrlEncode(LokFuEncode.LokFuAPIEncode(FastOrder.TNum, FastPayWay.DllName)));
            }
            else
            {
                //跳出绑卡
                Response.Redirect("/paycenter/cardpay/index.html?etnum=" + HttpUtility.UrlEncode(LokFuEncode.LokFuAPIEncode(FastOrder.TNum, "CardPay")));
            }
        }
Exemple #18
0
        public void GoPay(string etnum, int BankId)
        {
            if (etnum.IsNullOrEmpty() || BankId.IsNullOrEmpty())
            {
                Response.Write("Some Error[00]");
                return;
            }
            string    tnum      = LokFuEncode.LokFuAPIDecode(etnum, DllName);
            FastOrder FastOrder = Entity.FastOrder.FirstOrDefault(n => n.TNum == tnum);

            if (FastOrder == null)
            {
                Response.Write("Some Error[02]");
                return;
            }
            FastPayWay FastPayWay = Entity.FastPayWay.FirstOrDefault(n => n.Id == FastOrder.PayWay);

            if (FastOrder == null)
            {
                Response.Write("Some Error[03]");
                return;
            }
            Response.Redirect("/paycenter/" + FastPayWay.DllName.ToLower() + "/gopay.html?etnum=" + HttpUtility.UrlEncode(LokFuEncode.LokFuAPIEncode(FastOrder.TNum + "|" + BankId, FastPayWay.DllName)));
        }
        public void Post()
        {
            string Data = DataObj.GetData();

            if (Data.IsNullOrEmpty())
            {
                DataObj.OutError("1000");
                return;
            }
            JObject json = new JObject();

            try
            {
                json = (JObject)JsonConvert.DeserializeObject(Data);
            }
            catch (Exception Ex)
            {
                Log.Write("[FastOrders]:", "【Data】" + Data, Ex);
            }
            if (json == null)
            {
                DataObj.OutError("1000");
                return;
            }
            FastOrder FastOrder = new FastOrder();

            FastOrder = JsonToObject.ConvertJsonToModel(FastOrder, json);

            //var ford = this.Entity.FastOrder.FirstOrDefault(o => o.TNum == "20170606_01_0000024928");
            //if (ford != null)
            //{
            //    FastOrderExtensions.PushMsg(ford, this.Entity);
            //}

            //var Ord = new Orders()
            //{
            //    Id = 5555,
            //    TState =1,
            //    TType = 8,
            //    TNum = "20170625111111111111",
            //    Amoney = 50,
            //    Poundage = 8,
            //    AddTime = DateTime.Now,
            //    ComeWay = 1,
            //    UId = 566,
            //    PayState = 1,
            //    IdCardState = 0,
            //};
            //Ord.SendMsg(this.Entity);

            //System.Threading.Thread.Sleep(1000 * 60 * 1);

            Users baseUsers = Entity.Users.FirstOrDefault(n => n.Token == FastOrder.Token);

            if (baseUsers == null)//用户令牌不存在
            {
                DataObj.OutError("2004");
                return;
            }
            if (baseUsers.State != 1)//用户被锁定
            {
                DataObj.OutError("2003");
                return;
            }

            EFPagingInfo <FastOrder> p = new EFPagingInfo <FastOrder>();

            if (!FastOrder.Pg.IsNullOrEmpty())
            {
                p.PageIndex = FastOrder.Pg;
            }
            if (!FastOrder.Pgs.IsNullOrEmpty())
            {
                p.PageSize = FastOrder.Pgs;
            }

            p.SqlWhere.Add(f => f.UId == baseUsers.Id);
            //搜索
            if (!FastOrder.OType.IsNullOrEmpty())
            {
                p.SqlWhere.Add(f => f.OType == FastOrder.OType);
            }
            if (!FastOrder.State.IsNullOrEmpty())
            {
                switch (FastOrder.State)
                {
                case 1:
                    p.SqlWhere.Add(f => f.State == 1 && f.PayState == 0);
                    break;

                case 2:
                    p.SqlWhere.Add(f => f.State == 1 && f.PayState == 1);
                    break;

                case 3:
                    p.SqlWhere.Add(f => f.State == 1 && f.PayState == 1 && f.UserState == 0);
                    break;

                case 4:
                    p.SqlWhere.Add(f => f.State == 1 && f.PayState == 1 && f.UserState == 1);
                    break;
                }
            }
            if (!FastOrder.STime.IsNullOrEmpty())
            {
                p.SqlWhere.Add(f => f.AddTime >= FastOrder.STime);
            }
            if (!FastOrder.ETime.IsNullOrEmpty())
            {
                FastOrder.ETime = FastOrder.ETime.AddHours(24);
                p.SqlWhere.Add(f => f.AddTime <= FastOrder.ETime);
            }

            p.OrderByList.Add("Id", "DESC");
            IPageOfItems <FastOrder> List = Entity.Selects <FastOrder>(p);

            //处理转帐订单
            foreach (var pp in List)
            {
                if (pp.State == 1)
                {
                    if (pp.PayState == 1)
                    {
                        if (pp.UserState == 1)
                        {
                            pp.State = 3;
                        }
                        else
                        {
                            pp.State = 2;
                        }
                    }
                    else
                    {
                        pp.State = 1;
                    }
                }
                else
                {
                    pp.State = 0;
                }
            }

            IList <FastOrder> iList = List.ToList();
            StringBuilder     sb    = new StringBuilder("");

            sb.Append("{");
            sb.Append(List.PageToString());
            sb.Append(",");
            sb.Append(iList.EntityToString());
            sb.Append("}");
            DataObj.Data = sb.ToString();
            DataObj.Code = "0000";
            DataObj.OutString();
        }
        public ActionResult FastResult()
        {
            string Resp    = Request.QueryString["resp"];
            string Sign    = Request.QueryString["sign"];
            string SignStr = Resp;

            Resp = LokFuEncode.Base64Decode(Resp, "utf-8");
            JObject json = new JObject();

            try
            {
                json = (JObject)JsonConvert.DeserializeObject(Resp);
            }
            catch (Exception Ex)
            {
                ViewBag.ErrorMsg = Ex.ToString();
                return(View("Error"));
            }
            if (json == null)
            {
                ViewBag.ErrorMsg = "数据处理出错";
                return(View("Error"));
            }

            string resultcode = json["resultcode"].ToString(); //交易结果码
            string resultmsg  = json["resultmsg"].ToString();  //交易结果信息
            string queryid    = json["queryid"].ToString();    //交易流水号
            string txnamt     = json["txnamt"].ToString();     //交易金额
            string merid      = json["merid"].ToString();      //商户号
            string orderid    = json["orderid"].ToString();    //交易单号

            FastOrder FastOrder = Entity.FastOrder.FirstOrDefault(n => n.TNum == orderid);

            if (FastOrder == null)
            {
                ViewBag.ErrorMsg = "交易不存在!";
                return(View("Error"));
            }
            if (FastOrder.State != 1)
            {
                ViewBag.ErrorMsg = "交易异常!";
                return(View("Error"));
            }
            FastUserPay FastUserPay = Entity.FastUserPay.FirstOrDefault(o => o.UId == FastOrder.UId && o.PayWay == FastOrder.PayWay);
            string      MerId       = FastUserPay.MerId;
            string      MerKey      = FastUserPay.MerKey;

            if (MerId.IsNullOrEmpty() || MerKey.IsNullOrEmpty())
            {
                ViewBag.ErrorMsg = "支付通道配置异常!";
                return(View("Error"));
            }
            string MD5Str = SignStr + MerKey;
            string sign   = MD5Str.GetMD5();
            //================================================
            //这里记录日志
            PayLog PayLog = new PayLog();

            PayLog.PId     = (int)FastOrder.PayWay;
            PayLog.OId     = FastOrder.TNum;
            PayLog.TId     = FastOrder.Trade;
            PayLog.Amount  = decimal.Parse(txnamt) / 100;
            PayLog.Way     = "Result";
            PayLog.AddTime = DateTime.Now;
            PayLog.Data    = Request.Form.ToString();
            PayLog.State   = 1;
            Entity.PayLog.AddObject(PayLog);
            Entity.SaveChanges();
            //================================================
            if (Sign != sign)
            {
                ViewBag.ErrorMsg = "签名错误!";
                return(View("Error"));
            }
            if (MerId != merid)
            {
                ViewBag.ErrorMsg = "商户号不一置!";
                return(View("Error"));
            }
            if (resultcode != "0000" && resultcode != "1002" && resultcode != "1003")
            {
                ViewBag.ErrorMsg = "支付失败![" + resultcode + "]" + resultmsg;
                return(View("Error"));
            }
            int factmoney = int.Parse(txnamt);

            if (((int)(FastOrder.Amoney * 100)) != factmoney)
            {
                ViewBag.ErrorMsg = "支付金额与交易金额不符!";
                return(View("Error"));
            }
            FastOrder.Trade = queryid;
            Entity.SaveChanges();
            FastOrder = FastOrder.PaySuccess(Entity);
            if (FastOrder.PayState == 1)
            {
                if (resultcode == "0000")
                {
                    FastOrder.UserState = 1;
                    FastOrder.UserTime  = DateTime.Now;
                }
                if (resultcode == "1002")
                {
                    FastOrder.UserState = 3;
                    FastOrder.UserTime  = DateTime.Now;
                }
                if (resultcode == "1003")
                {
                    FastOrder.UserState = 2;
                    FastOrder.UserTime  = DateTime.Now;
                }
                Entity.SaveChanges();
            }
            ViewBag.FastOrder = FastOrder;
            return(View("FastSuccess"));
        }
        public void FastNotice()
        {
            string Resp    = Request.Form["resp"];
            string Sign    = Request.Form["sign"];
            string SignStr = Resp;

            Resp = LokFuEncode.Base64Decode(Resp, "utf-8");
            JObject json = new JObject();

            try
            {
                json = (JObject)JsonConvert.DeserializeObject(Resp);
            }
            catch (Exception Ex)
            {
                Response.Write(Ex.ToString());
                return;
            }
            if (json == null)
            {
                Response.Write("Json Null");
                return;
            }
            string resultcode = json["resultcode"].ToString(); //交易结果码
            string resultmsg  = json["resultmsg"].ToString();  //交易结果信息
            string queryid    = json["queryid"].ToString();    //交易流水号
            string txnamt     = json["txnamt"].ToString();     //交易金额\
            string merid      = json["merid"].ToString();      //交易金额
            string orderid    = json["orderid"].ToString();    //交易金额

            FastOrder FastOrder = Entity.FastOrder.FirstOrDefault(n => n.TNum == orderid);

            if (FastOrder == null)
            {
                Response.Write("E1");
                return;
            }
            if (FastOrder.State != 1)
            {
                Response.Write("E2");
                return;
            }
            if (FastOrder.PayState == 1)
            {
                if (resultcode == "0000")
                {
                    FastOrder.UserState = 1;
                    FastOrder.UserTime  = DateTime.Now;
                }
                if (resultcode == "1002")
                {
                    FastOrder.UserState = 3;
                    FastOrder.UserTime  = DateTime.Now;
                }
                if (resultcode == "1003")
                {
                    FastOrder.UserState = 2;
                    FastOrder.UserTime  = DateTime.Now;
                }
                Entity.SaveChanges();
                Response.Write("0000");
                return;
            }
            FastUserPay FastUserPay = Entity.FastUserPay.FirstOrDefault(o => o.UId == FastOrder.UId && o.PayWay == FastOrder.PayWay);
            string      MerId       = FastUserPay.MerId;
            string      MerKey      = FastUserPay.MerKey;

            if (MerId.IsNullOrEmpty() || MerKey.IsNullOrEmpty())
            {
                Response.Write("E53");
                return;
            }
            string MD5Str = SignStr + MerKey;
            string sign   = MD5Str.GetMD5();
            //================================================
            //这里记录日志
            PayLog PayLog = new PayLog();

            PayLog.PId     = (int)FastOrder.PayWay;
            PayLog.OId     = FastOrder.TNum;
            PayLog.TId     = FastOrder.Trade;
            PayLog.Amount  = decimal.Parse(txnamt) / 100;
            PayLog.Way     = "POST";
            PayLog.AddTime = DateTime.Now;
            PayLog.Data    = Request.Form.ToString();
            PayLog.State   = 1;
            Entity.PayLog.AddObject(PayLog);
            Entity.SaveChanges();
            //================================================
            if (Sign != sign)
            {
                Response.Write("E4");
                return;
            }
            if (MerId != merid)
            {
                Response.Write("E5");
                return;
            }
            //0000 交易成功【已支付,结算到子商户结算卡】
            //1001 未支付
            //1002 交易处理中【已支付,未结算到结算卡】
            //1003交易成功结算失败
            //1004 交易失败
            if (resultcode != "0000" && resultcode != "1002" && resultcode != "1003")
            {
                Response.Write("E6");
                return;
            }
            int factmoney = int.Parse(txnamt);

            if (((int)(FastOrder.Amoney * 100)) != factmoney)
            {
                Response.Write("E7");
                return;
            }
            FastOrder.Trade = queryid;
            Entity.SaveChanges();
            FastOrder = FastOrder.PaySuccess(Entity);
            if (FastOrder.PayState == 1)
            {
                if (resultcode == "0000")
                {
                    FastOrder.UserState = 1;
                    FastOrder.UserTime  = DateTime.Now;
                }
                if (resultcode == "1002")
                {
                    FastOrder.UserState = 3;
                    FastOrder.UserTime  = DateTime.Now;
                }
                if (resultcode == "1003")
                {
                    FastOrder.UserState = 2;
                    FastOrder.UserTime  = DateTime.Now;
                }
                Entity.SaveChanges();
            }
            Response.Write("0000");
        }
        public void Post()
        {
            string Data = DataObj.GetData();

            if (Data.IsNullOrEmpty())
            {
                DataObj.OutError("1000");
                return;
            }
            JObject json = new JObject();

            try
            {
                json = (JObject)JsonConvert.DeserializeObject(Data);
            }
            catch (Exception Ex)
            {
                Log.Write("[FastOrderQueryController]:", "【Data】" + Data, Ex);
                json = null;
            }
            if (json == null)
            {
                DataObj.OutError("1000");
                return;
            }

            FastOrder InFastOrder = new FastOrder();

            InFastOrder = JsonToObject.ConvertJsonToModel(InFastOrder, json);
            if (InFastOrder.TNum.IsNullOrEmpty() || InFastOrder.Token.IsNullOrEmpty())
            {
                DataObj.OutError("1000");
                return;
            }

            Users baseUsers = Entity.Users.FirstOrDefault(n => n.Token == InFastOrder.Token);

            if (baseUsers == null)//用户令牌不存在
            {
                DataObj.OutError("2004");
                return;
            }
            if (baseUsers.State != 1)//用户被锁定
            {
                DataObj.OutError("2003");
                return;
            }
            if (baseUsers.CardStae != 2)//未实名认证
            {
                DataObj.OutError("2006");
                return;
            }

            FastOrder FastOrder = Entity.FastOrder.FirstOrDefault(n => n.TNum == InFastOrder.TNum && n.UId == baseUsers.Id);

            if (FastOrder == null)
            {
                DataObj.OutError("1000");
                return;
            }
            if (FastOrder.State == 1 && FastOrder.PayState == 0)
            {
                FastPayWay FastPayWay = Entity.FastPayWay.FirstOrNew(n => n.Id == FastOrder.PayWay);
                if (FastPayWay == null)
                {
                    DataObj.OutError("2079");
                    return;
                }
                string[] PayConfigArr = FastPayWay.QueryArray.Split(new char[] { ',' });//接口信息
                if (FastPayWay.DllName == "HFPay")
                {
                    #region 结算中心
                    if (PayConfigArr.Length == 3)
                    {
                        string HF_Url     = "https://api.zhifujiekou.com/api/query";
                        string MerId      = PayConfigArr[0];
                        string MerKey     = PayConfigArr[1];
                        string orderId    = FastOrder.TNum;//商户流水号
                        string PostJson   = "{\"merid\":\"" + MerId + "\",\"orderid\":\"" + orderId + "\"}";
                        string DataBase64 = LokFuEncode.Base64Encode(PostJson, "utf-8");
                        string Sign       = (DataBase64 + MerKey).GetMD5();
                        DataBase64 = HttpUtility.UrlEncode(DataBase64);
                        string  PostData = string.Format("req={0}&sign={1}", DataBase64, Sign);
                        string  Ret      = Utils.PostRequest(HF_Url, PostData, "utf-8");
                        JObject JS       = new JObject();
                        try
                        {
                            JS = (JObject)JsonConvert.DeserializeObject(Ret);
                        }
                        catch (Exception)
                        {
                            JS = null;
                        }
                        if (JS != null)
                        {
                            if (JS["resp"] != null)
                            {
                                string resp = JS["resp"].ToString();
                                Ret = LokFuEncode.Base64Decode(resp, "utf-8");
                                try
                                {
                                    JS = (JObject)JsonConvert.DeserializeObject(Ret);
                                }
                                catch (Exception)
                                {
                                    JS = null;
                                }
                                if (JS != null)
                                {
                                    string respcode = JS["respcode"].ToString();
                                    if (respcode == "00")
                                    {
                                        string resultcode = JS["resultcode"].ToString();
                                        if (resultcode == "0000" || resultcode == "1002" || resultcode == "1004")
                                        {
                                            string queryid = JS["queryid"].ToString();
                                            FastOrder.Trade = queryid;
                                            Entity.SaveChanges();
                                            string txnamt    = JS["txnamt"].ToString();
                                            int    factmoney = int.Parse(txnamt);
                                            if (((int)(FastOrder.Amoney * 100)) == factmoney)
                                            {
                                                FastOrder = FastOrder.PaySuccess(Entity);
                                            }
                                        }
                                    }
                                    //================================================
                                    //这里记录日志
                                    PayLog PayLog = new PayLog();
                                    PayLog.PId     = (int)FastOrder.PayWay;
                                    PayLog.OId     = FastOrder.TNum;
                                    PayLog.TId     = FastOrder.Trade;
                                    PayLog.Amount  = FastOrder.Amoney;
                                    PayLog.Way     = "Query";
                                    PayLog.AddTime = DateTime.Now;
                                    PayLog.Data    = Ret;
                                    PayLog.State   = 1;
                                    Entity.PayLog.AddObject(PayLog);
                                    Entity.SaveChanges();
                                    //================================================
                                }
                            }
                        }
                    }
                    #endregion
                }
                if (FastPayWay.DllName == "HFJSPay")
                {
                    #region 结算中心
                    if (PayConfigArr.Length == 3)
                    {
                        FastUserPay          FastUserPay          = Entity.FastUserPay.FirstOrDefault(n => n.PayWay == FastOrder.PayWay && n.UId == baseUsers.Id && n.MerState == 1);
                        fastordersqueryModel fastordersqueryModel = new fastordersqueryModel()
                        {
                            merid   = FastUserPay.MerId,
                            orderid = "",
                            queryid = FastOrder.TNum
                        };
                        fastordersqueryResult fastordersqueryResult = HFJSTools.fastordersquery(fastordersqueryModel, FastUserPay.MerKey);
                        //================================================
                        //记录通知信息
                        PayLog PayLog = new PayLog();
                        PayLog.PId     = FastOrder.PayWay.Value;
                        PayLog.OId     = FastOrder.TNum;
                        PayLog.TId     = fastordersqueryResult.queryid;
                        PayLog.Amount  = FastOrder.Amoney;
                        PayLog.Way     = "Query";
                        PayLog.AddTime = DateTime.Now;
                        PayLog.Data    = HFJSTools.MyObjectToJson(fastordersqueryResult);
                        PayLog.State   = 1;
                        Entity.PayLog.AddObject(PayLog);
                        Entity.SaveChanges();
                        //================================================
                        if (fastordersqueryResult.respcode == "00")
                        {
                            if (fastordersqueryResult.resultcode == "0000" || fastordersqueryResult.resultcode == "1002")
                            {
                                FastOrder.Trade = fastordersqueryResult.queryid;
                                Entity.SaveChanges();
                                FastOrder = FastOrder.PaySuccess(Entity);
                                if (FastOrder.PayState == 1)
                                {
                                    if (fastordersqueryResult.resultcode == "0000")
                                    {
                                        FastOrder.UserState = 1;
                                    }
                                    if (fastordersqueryResult.resultcode == "1002")
                                    {
                                        FastOrder.UserState = 3;
                                    }
                                    FastOrder.UserTime = DateTime.Now;
                                    Entity.SaveChanges();
                                }
                            }
                            else if (fastordersqueryResult.resultcode == "1004")
                            {
                                FastOrder.State = 0;
                                Entity.SaveChanges();
                            }
                            else
                            {
                            }
                            Entity.SaveChanges();
                        }
                        else
                        {
                            string resp_desc = fastordersqueryResult.respmsg;
                            Utils.WriteLog("HFJS[Query][" + FastOrder.TNum + "]:" + resp_desc, "JobHFJS");
                        }
                    }
                    #endregion
                }
            }
            if (FastOrder.State == 1)
            {
                if (FastOrder.PayState == 1)
                {
                    if (FastOrder.UserState == 1)
                    {
                        FastOrder.State = 3;
                    }
                    else
                    {
                        FastOrder.State = 2;
                    }
                }
                else
                {
                    FastOrder.State = 1;
                }
            }
            else
            {
                FastOrder.State = 0;
            }
            FastOrder.Cols = "TNum,PayId,Amoney,Poundage,State";
            DataObj.Data   = FastOrder.OutJson();
            DataObj.Code   = "0000";
            DataObj.OutString();
        }
Exemple #23
0
        //opening windows
        public void OpenWindow(object param)
        {
            var parameter = param.ToString().Split('/');

            switch (parameter[0])
            {
            case "watchlist":
                var view = new Watchlist();
                view.DataContext = new WatchlistViewModel(parameter[1], view);
                view.Show();
                break;

            case "clients":
                if (CheckIfWindowIsOpened(typeof(Clients)))
                {
                    break;
                }
                //_clientsViewModel.Timer.Start();
                new Clients {
                    DataContext = ClientsViewModel
                }.Show();
                break;

            case "newOrder":
                if (CheckIfWindowIsOpened(typeof(NewOrder)))
                {
                    break;
                }
                new NewOrder {
                    DataContext = new NewOrderViewModel()
                }.Show();
                break;

            case "newStoporder":
                if (CheckIfWindowIsOpened(typeof(NewStopOrder)))
                {
                    break;
                }
                new NewStopOrder {
                    DataContext = new NewStopOrderViewModel()
                }.Show();
                break;

            case "trades":
                if (CheckIfWindowIsOpened(typeof(ClientTrades)))
                {
                    break;
                }
                new ClientTrades {
                    DataContext = ClientTradesViewModel
                }.Show();
                break;

            case "orders":
                if (CheckIfWindowIsOpened(typeof(ClientOrders)))
                {
                    break;
                }
                new ClientOrders {
                    DataContext = ClientOrdersViewModel
                }.Show();
                break;

            case "stoporders":
                if (CheckIfWindowIsOpened(typeof(ClientStoporders)))
                {
                    break;
                }
                new ClientStoporders {
                    DataContext = ClientOrdersViewModel
                }.Show();
                break;

            case "allTradesCounterFile":
                new AllTradesCounterWindow {
                    DataContext = new AllTradesCounterFromFile()
                }.Show();
                break;

            case "unitedPortfolio":
                new UnitedPortfolio {
                    DataContext = new UnitedPortfolioViewModel()
                }.Show();
                break;

            case "admin":
                if (CheckIfWindowIsOpened(typeof(AdminWindow)))
                {
                    break;
                }
                //new AdminWindow { DataContext = new AdminViewModel(Hub, DialogCoordinator.Instance) }.Show();
                new AdminWindow {
                    DataContext = AdminViewModel
                }.Show();
                break;

            case "news":
                if (CheckIfWindowIsOpened(typeof(Views.News)))
                {
                    break;
                }
                new Views.News {
                    DataContext = NewsViewModel
                }.Show();
                break;

            case "cart":
                if (CheckIfWindowIsOpened(typeof(Cart)))
                {
                    break;
                }
                new Cart {
                    DataContext = CartViewModel
                }.Show();
                break;

            case "fastOrder":
                var window = new FastOrder();
                window.DataContext = new FastOrderViewModel(null, null, window);
                window.Show();
                break;

            case "alerts":
                new Alerts(AlertsViewModel).Show();
                break;

            case "balance":
                new BalanceReport {
                    DataContext = BalanceReportViewModel
                }.Show();
                break;

            case "calendar":
                new CalendarMainWindow().Show();
                break;
            }
        }
        public void Post()
        {
            string Data = DataObj.GetData();

            if (Data.IsNullOrEmpty())
            {
                DataObj.OutError("1000");
                return;
            }
            JObject json = new JObject();

            try
            {
                json = (JObject)JsonConvert.DeserializeObject(Data);
            }
            catch (Exception Ex)
            {
                Log.Write("[FastOrdersInfo]:", "【Data】" + Data, Ex);
            }
            if (json == null)
            {
                DataObj.OutError("1000");
                return;
            }
            FastOrder FastOrder = new FastOrder();

            FastOrder = JsonToObject.ConvertJsonToModel(FastOrder, json);

            Users baseUsers = Entity.Users.FirstOrDefault(n => n.Token == FastOrder.Token);

            if (baseUsers == null)//用户令牌不存在
            {
                DataObj.OutError("2004");
                return;
            }
            if (baseUsers.State != 1)//用户被锁定
            {
                DataObj.OutError("2003");
                return;
            }

            FastOrder FO = Entity.FastOrder.FirstOrDefault(n => n.TNum == FastOrder.TNum && n.UId == baseUsers.Id);

            if (FO == null)
            {
                DataObj.OutError("1000");
                return;
            }
            FO.StateName = FO.GeStateName();
            FO.Colour    = FO.GeStateColour();
            #region 旧版本要使用来控制颜色
            if (FO.State == 1)
            {
                if (FO.PayState == 1)
                {
                    if (FO.UserState == 1)
                    {
                        FO.State = 3;
                    }
                    else
                    {
                        FO.State = 2;
                    }
                }
                else
                {
                    FO.State = 1;
                }
            }
            else
            {
                FO.State = 0;
            }
            #endregion
            DataObj.Data = FO.OutJson();
            DataObj.Code = "0000";
            DataObj.OutString();
        }
        /// <summary>
        /// 订单分润/分润退款
        /// </summary>
        /// <param name="O"></param>
        /// <param name="Entity"></param>
        /// <param name="Type">1分润入帐 2分润退款</param>
        /// <returns></returns>
        public static FastOrder PayAgent(this FastOrder O, LokFuEntity Entity, int Type)
        {
            FastConfig FastConfig = Entity.FastConfig.FirstOrNew();

            if (FastConfig.AgentWay != 1)
            {
                return(O);
            }
            if (O.Agent.IsNullOrEmpty())
            {//代理商没有情况下
                return(O);
            }
            //if (O.AgentPayGet.IsNullOrEmpty())
            //{
            //    //没有佣金
            //    //直接标识为已结算
            //    O.AgentState = 1;
            //    O.AgentTime = DateTime.Now;
            //    Entity.SaveChanges();
            //    return O;
            //}
            if (Type != 1)//类型不对
            {
                return(O);
            }
            Users OrderUser = Entity.Users.FirstOrDefault(n => n.Id == O.UId);//读取订单用户

            if (Type == 1)
            {
                string TypeString = "收付直通车";
                #region 结算
                if (O.AgentState != 0)
                {//已结算,不能重复结算
                    return(O);
                }
                O.AgentState = 1;
                O.AgentTime  = DateTime.Now;
                Entity.SaveChanges();
                //获取各级代理商
                SysAgent SysAgent = new SysAgent();
                SysAgent.Id = O.Agent;
                IList <SysAgent> SysAgentList = SysAgent.GetAgentsById(Entity);
                decimal          AIdPayGet    = (decimal)O.AgentPayGet; //
                decimal          sumpayget    = 0;
                int tier = 1;
                foreach (var p in SysAgentList)
                {
                    if (p.State == 1)
                    {
                        decimal PayGet = SysAgent.GetSplit(p.Tier, Entity);
                        AIdPayGet = O.Amoney * PayGet; //当前级总佣金,需获取是否有下级拆分他的佣金
                        AIdPayGet = AIdPayGet.Floor();
                        decimal AIdPayGetNext = 0;     //定义下一级佣金
                        if (tier < SysAgentList.Count)
                        {
                            //不是最后一级,需计算下级拆分金额
                            SysAgent SysAgentNext = SysAgentList.Skip(tier).Take(1).FirstOrDefault();
                            if (SysAgentNext != null)
                            {
                                if (SysAgentNext.State == 1)
                                {//下级状态有效时才计算,如关闭了则不正计算下级
                                    decimal PayGetNext = SysAgent.GetSplit(SysAgentNext.Tier, Entity);
                                    AIdPayGetNext = O.Amoney * PayGetNext;
                                    AIdPayGetNext = AIdPayGetNext.Floor();
                                }
                            }
                        }
                        decimal AIdPayGetMy = AIdPayGet - AIdPayGetNext; //当前级所能得到真实佣金

                        decimal UsersGetAll = 0;                         //定义所有用户佣金
                        //最后一级代理商 处理用户分润
                        #region 最后一级代理商 处理用户分润
                        if (tier == SysAgentList.Count)
                        {
                            //获取各级分润配置
                            SysSet SysSet   = Entity.SysSet.FirstOrNew();
                            int    MaxLevel = SysSet.GlobaPromoteMaxLevel;
                            //有用户分润,开始执行用户分润
                            Users Users = new Users();
                            Users.Id = O.UId;
                            //获取用户各级关系,最大级不超过用户配置级数。返回数据包含当前用户,当前用户级数标识Tier为0
                            IList <Users> UsersList = Users.GetUsersById(Entity, MaxLevel);
                            int           UsersTier = 1;
                            foreach (var U in UsersList.Where(n => n.Tier > 0 && n.State == 1))
                            {
                                //UsersGetAll
                                //UserPromoteGet UserPromoteGet = UserPromoteGetList.FirstOrDefault(n => n.PromoteLevel == U.Tier);
                                //if (UserPromoteGet != null)
                                //{
                                decimal PromoteGet = Users.GetUsersSplit(Entity, U.Tier);
                                decimal UsersGet   = O.Amoney * PromoteGet;
                                UsersGet = UsersGet.Floor();
                                if (UsersTier == 1)
                                {
                                    UsersGetAll = UsersGet;
                                }
                                //UsersGetSum += UsersGet;

                                if (UsersTier < UsersList.Count)
                                {
                                    //不是最后一级,需计算下级拆分金额
                                    byte  nexttier  = (byte)(U.Tier + 1);
                                    Users UsersNext = UsersList.FirstOrDefault(o => o.Tier == nexttier);
                                    if (UsersNext != null)
                                    {
                                        if (UsersNext.State == 1)
                                        {    //下级状态有效时才计算,如关闭了则不正计算下级
                                            decimal PayGetNext     = Users.GetUsersSplit(Entity, UsersNext.Tier);
                                            decimal UserPayGetNext = O.Amoney * PayGetNext;
                                            UserPayGetNext = UserPayGetNext.Floor();
                                            //减掉下级用户的金额
                                            UsersGet = UsersGet - UserPayGetNext;
                                        }
                                    }
                                }
                                if (UsersGet > 0)
                                {
                                    //帐户变动记录
                                    string Remark = string.Format("{0}[{1}]", TypeString, O.TNum);
                                    string SP_Ret = Entity.SP_UsersMoney(U.Id, O.TNum, UsersGet, 8, Remark, 0);
                                    if (SP_Ret != "3")
                                    {
                                        Utils.WriteLog(string.Format("U{0},O{1},T{2}:{3}【{4}】", U.Id, O.TNum, 8, UsersGet, SP_Ret), "SP_UsersMoney");
                                    }
                                    //记录清分记录
                                    OrderProfitLog OPL = new OrderProfitLog();
                                    OPL.AddTime   = DateTime.Now;
                                    OPL.UId       = U.Id;
                                    OPL.Agent     = 0;
                                    OPL.TNum      = O.TNum;
                                    OPL.LogType   = 1;
                                    OPL.Tier      = U.Tier;
                                    OPL.Profit    = UsersGet;
                                    OPL.Amoney    = O.Amoney;
                                    OPL.OrderType = 21;
                                    OPL.UserName  = OrderUser.UserName;
                                    Entity.OrderProfitLog.AddObject(OPL);
                                    //=====增加统计记录=====
                                    ShareTotal ShareTotal = Entity.ShareTotal.FirstOrDefault(n => n.UId == U.Id && n.Tier == U.Tier);
                                    if (ShareTotal == null)
                                    {
                                        ShareTotal          = new ShareTotal();
                                        ShareTotal.UId      = U.Id;
                                        ShareTotal.AddTime  = DateTime.Now;
                                        ShareTotal.ShareNum = 0;
                                        ShareTotal.Amount   = O.Amoney;
                                        ShareTotal.Profit   = UsersGet;
                                        ShareTotal.Tier     = U.Tier;
                                        Entity.ShareTotal.AddObject(ShareTotal);
                                    }
                                    else
                                    {
                                        ShareTotal.Amount += O.Amoney;
                                        ShareTotal.Profit += UsersGet;
                                    }
                                    sumpayget = sumpayget + UsersGet;
                                }
                                UsersTier++;
                                // }
                            }
                        }
                        #endregion
                        //20160704 Lin 增加统计用户拆分多少,最后一级代理金额减掉这部分金额即可。
                        //解决用户分剩下钱规系统逻辑问题
                        AIdPayGetMy = AIdPayGetMy - UsersGetAll;

                        #region 最后一级代理商 处理同级分润
                        if (tier == SysAgentList.Count)
                        {
                            if (!p.SameAgent.IsNullOrEmpty() && AIdPayGet > 0)
                            {
                                SysMoneySet SysMoneySet = Entity.SysMoneySet.FirstOrNew();
                                decimal     SameMoney   = AIdPayGet * SysMoneySet.SameAgent;
                                SameMoney = SameMoney.Floor();
                                SysAgent SameSysAgent = Entity.SysAgent.FirstOrNew(o => o.Id == p.SameAgent);
                                if (SameSysAgent.State == 1 && !SameSysAgent.MyUId.IsNullOrEmpty())
                                {
                                    //帐户变动记录
                                    string Remark = string.Format("{0}[{1}]", "直通车同级分润", O.TNum);
                                    string SP_Ret = Entity.SP_UsersMoney(SameSysAgent.MyUId, O.TNum, SameMoney, 8, Remark, 0);
                                    if (SP_Ret != "3")
                                    {
                                        Utils.WriteLog(string.Format("U{0},O{1},T{2}:{3}【{4}】", SameSysAgent.MyUId, O.TNum, 8, SameMoney, SP_Ret), "SP_UsersMoney");
                                    }
                                    //记录清分记录
                                    OrderProfitLog OPL = new OrderProfitLog();
                                    OPL.AddTime   = DateTime.Now;
                                    OPL.UId       = SameSysAgent.MyUId;
                                    OPL.Agent     = SameSysAgent.Id;
                                    OPL.TNum      = O.TNum;
                                    OPL.LogType   = 3;
                                    OPL.Tier      = p.Tier;
                                    OPL.Profit    = SameMoney;
                                    OPL.Amoney    = O.Amoney;
                                    OPL.OrderType = 21;
                                    OPL.UserName  = OrderUser.UserName;
                                    Entity.OrderProfitLog.AddObject(OPL);
                                    O.SameGet = SameMoney;
                                }
                            }
                        }
                        #endregion

                        if (!p.MyUId.IsNullOrEmpty() && AIdPayGetMy > 0)//某一级未绑定钱包,钱留给系统^-^
                        {
                            //获取钱包信息
                            //为了减少系统开销,这里不读取用户信息——By Lin
                            //Users Users = Entity.Users.FirstOrDefault(n => n.Id == p.MyUId);
                            if (p.MyUId > 0)
                            {
                                //帐户变动记录
                                string Remark = string.Format("{0}[{1}]", TypeString, O.TNum);
                                string SP_Ret = Entity.SP_UsersMoney(p.MyUId, O.TNum, AIdPayGetMy, 8, Remark, 0);
                                if (SP_Ret != "3")
                                {
                                    Utils.WriteLog(string.Format("U{0},O{1},T{2}:{3}【{4}】", p.MyUId, O.TNum, 8, AIdPayGetMy, SP_Ret), "SP_UsersMoney");
                                }
                                //记录清分记录
                                OrderProfitLog OPL = new OrderProfitLog();
                                OPL.AddTime   = DateTime.Now;
                                OPL.UId       = p.MyUId;
                                OPL.Agent     = p.Id;
                                OPL.TNum      = O.TNum;
                                OPL.LogType   = 2;
                                OPL.Tier      = p.Tier;
                                OPL.Profit    = AIdPayGetMy;
                                OPL.Amoney    = O.Amoney;
                                OPL.OrderType = 21;
                                OPL.UserName  = OrderUser.UserName;
                                Entity.OrderProfitLog.AddObject(OPL);
                                sumpayget = sumpayget + AIdPayGetMy;
                            }
                        }
                    }
                    tier++;
                }

                Entity.SaveChanges();
                //统计所有分润
                //decimal Profit = 0;
                //if (Entity.OrderProfitLog.Count(n => n.TNum == O.TNum) > 0)
                //{
                //    Profit = Entity.OrderProfitLog.Where(n => n.TNum == O.TNum).Sum(n => n.Profit);//是否会为空的情况
                //}
                O.AgentPayGet = sumpayget;//记录总佣金支出,以便总系统计算利润
                O.AgentState  = 1;
                Entity.SaveChanges();
                #endregion
            }
            if (Type == 2)
            {
                //没有退款,分润也不需要写
            }
            return(O);
        }
Exemple #26
0
        public ActionResult AddCard(string etnum, string Card = "", string Mobile = "", string code = "")
        {
            string    tnum      = LokFuEncode.LokFuAPIDecode(etnum, DllName);
            FastOrder FastOrder = Entity.FastOrder.FirstOrDefault(n => n.TNum == tnum);

            if (FastOrder == null)
            {
                ViewBag.ErrorMsg = "订单有误!";
                return(View("Error"));
            }
            Users Users = Entity.Users.FirstOrDefault(n => n.Id == FastOrder.UId);

            if (Users == null)
            {
                ViewBag.ErrorMsg = "商户信息有误!";
                return(View("Error"));
            }

            ViewBag.FastOrder = FastOrder;
            ViewBag.Users     = Users;
            ViewBag.etnum     = etnum;

            if (!Card.IsNullOrEmpty() && !Mobile.IsNullOrEmpty() && !code.IsNullOrEmpty())
            {
                if (Card.Length > 20)
                {
                    ViewBag.ErrorMsg = "卡号长度超限!";
                    return(View("Error"));
                }
                if (Mobile.Length > 20)
                {
                    ViewBag.ErrorMsg = "手机号码长度超限!";
                    return(View("Error"));
                }
                if (code.ToUpper() != Session.GetCheckCode())
                {
                    ViewBag.ErrorMsg = "验证码错误!";
                    return(View("Error"));
                }
                Session.ClearCheckCode();
                //绑卡前验证是否有鉴权权限
                UsersPayCard UsersPayCard = Entity.UsersPayCard.FirstOrDefault(n => n.Card == Card && n.Mobile == Mobile && n.UId == FastOrder.UId);
                if (UsersPayCard == null)//不存在则绑卡
                {
                    UserBlackList UserBlackList = Entity.UserBlackList.FirstOrDefault(UBL => UBL.CardNumber == Card && UBL.State == 3);
                    if (UserBlackList != null)
                    {
                        ViewBag.ErrorMsg = "暂不支持该银行卡绑卡";
                        return(View("Error"));
                    }

                    string HaoFu_Auth_MerId  = ConfigurationManager.AppSettings["HaoFu_Auth_MerId"].ToString();
                    string HaoFu_Auth_MerKey = ConfigurationManager.AppSettings["HaoFu_Auth_MerKey"].ToString();
                    string HaoFu_Auth_Url    = ConfigurationManager.AppSettings["HaoFu_Auth_Url"].ToString();

                    string data       = "{\"action\":\"authuser\",\"merid\":\"" + HaoFu_Auth_MerId + "\",\"orderid\":\"" + FastOrder.TNum + "\",\"bankaccount\":\"" + Card + "\",\"accountname\":\"" + Users.TrueName + "\",\"identitycode\":\"" + Users.CardId + "\",\"mobile\":\"" + Mobile + "\"}";
                    string DataBase64 = LokFuEncode.Base64Encode(data, "utf-8");
                    string Sign       = (DataBase64 + HaoFu_Auth_MerKey).GetMD5();

                    DataBase64 = HttpUtility.UrlEncode(DataBase64, Encoding.UTF8);
                    string postdata = "req=" + DataBase64 + "&sign=" + Sign;

                    string CONTENT = Utils.PostRequest(HaoFu_Auth_Url, postdata, "utf-8");

                    JObject JS = new JObject();
                    try
                    {
                        JS = (JObject)JsonConvert.DeserializeObject(CONTENT);
                    }
                    catch (Exception)
                    {
                        ViewBag.ErrorMsg = "请求银联鉴权失败!【00】";
                        return(View("Error"));
                    }
                    string resp = JS["resp"].ToString();
                    CONTENT = LokFuEncode.Base64Decode(resp, "utf-8");
                    try
                    {
                        JS = (JObject)JsonConvert.DeserializeObject(CONTENT);
                    }
                    catch (Exception)
                    {
                        ViewBag.ErrorMsg = "请求银联鉴权失败!【01】";
                        return(View("Error"));
                    }
                    string ret_code = JS["respcode"].ToString();

                    if (ret_code == "0000")
                    {
                        string BankNumLeft = Card.Substring(0, 6);
                        //获取卡Bin
                        BasicCardBin BasicCardBin = Entity.BasicCardBin.FirstOrDefault(n => n.BIN == BankNumLeft);
                        string       bankName     = "银联卡";
                        byte         CardType     = 0;
                        if (BasicCardBin != null)
                        {
                            bankName = BasicCardBin.BankName;
                            CardType = (byte)BasicCardBin.CardType;
                        }
                        else
                        {
                        }
                        UsersPayCard         = new UsersPayCard();
                        UsersPayCard.UId     = FastOrder.UId;
                        UsersPayCard.Type    = CardType;
                        UsersPayCard.Bank    = bankName;
                        UsersPayCard.Name    = Users.TrueName;
                        UsersPayCard.Card    = Card;
                        UsersPayCard.Mobile  = Mobile;
                        UsersPayCard.State   = 1;
                        UsersPayCard.AddTime = DateTime.Now;
                        Entity.UsersPayCard.AddObject(UsersPayCard);
                        Entity.SaveChanges();
                        Response.Redirect("GoPay.html?BankId=" + UsersPayCard.Id + "&etnum=" + HttpUtility.UrlEncode(etnum));
                    }
                    else
                    {
                        string ret_msg = JS["respmsg"].ToString();
                        ViewBag.ErrorMsg = "银行卡认证失败!";
                        return(View("Error"));
                    }
                }
                else
                {
                    if (UsersPayCard.State == 0)
                    {
                        UsersPayCard.State = 1;
                        Entity.SaveChanges();
                    }
                    Response.Redirect("GoPay.html?BankId=" + UsersPayCard.Id + "&etnum=" + HttpUtility.UrlEncode(etnum));
                }
            }
            return(View());
        }
        public ActionResult Index(string etnum)
        {
            if (etnum.IsNullOrEmpty())
            {
                ViewBag.ErrorMsg = "Some Error[00]";
                return(View("Error"));
            }
            string    tnum      = LokFuEncode.LokFuAPIDecode(etnum, DllName);
            FastOrder FastOrder = Entity.FastOrder.FirstOrDefault(n => n.TNum == tnum);

            if (FastOrder == null)
            {
                ViewBag.ErrorMsg = "Some Error[02]";
                return(View("Error"));
            }
            FastPayWay FastPayWay = Entity.FastPayWay.FirstOrDefault(n => n.Id == FastOrder.PayWay);

            if (FastPayWay == null)
            {
                ViewBag.ErrorMsg = "Some Error[03]";
                return(View("Error"));
            }
            if (FastPayWay.DllName != DllName)
            {
                ViewBag.ErrorMsg = "Some Error[04]";
                return(View("Error"));
            }
            string[] PayConfigArr = FastPayWay.QueryArray.Split(',');
            if (PayConfigArr.Length != 3)
            {
                ViewBag.ErrorMsg = "Some Error[05]";
                return(View("Error"));
            }
            FastUser FastUser = Entity.FastUser.FirstOrNew(n => n.UId == FastOrder.UId);

            string merId  = PayConfigArr[0];                             //商户号
            string merKey = PayConfigArr[1];                             //商户密钥
            string PayWay = PayConfigArr[2];                             //绑定通道

            string orderId    = FastOrder.TNum;                          //商户流水号
            string OrderMoney = (FastOrder.Amoney * 100).ToString("F0"); //金额,以分为单

            string TrueName = FastUser.TrueName;
            string CardId   = FastUser.CardId;

            //填写参数
            string ReturnUrl = PayPath + "/PayCenter/HFPay/FastResult.html";    //支付成功跳转页
            string BackUrl   = NoticePath + "/PayCenter/HFPay/FastNotice.html"; //后台通过地址


            if (TrueName.IsNullOrEmpty() || CardId.IsNullOrEmpty())
            {
                ViewBag.ErrorMsg = "TrueName IsNull";
                return(View("Error"));
            }
            if (FastPayWay.Id == 8)
            {
                PayWay = "3855";
            }
            //if (FastPayWay.Id == 13)
            //{
            //    PayWay = "3852";
            //}

            string Data = "{\"action\":\"goAndPay\",\"txnamt\":\"" + OrderMoney + "\",\"merid\":\"" + merId + "\",\"payway\":\"" + PayWay + "\",\"orderid\":\"" + orderId + "\",\"backurl\":\"" + BackUrl + "\",\"fronturl\":\"" + ReturnUrl + "\",\"accname\":\"" + TrueName + "\",\"accno\":\"" + CardId + "\"}";

            string DataBase64 = LokFuEncode.Base64Encode(Data, "utf-8");
            string Sign       = (DataBase64 + merKey).GetMD5();

            string GoUrl = "https://api.zhifujiekou.com/apis/gateway?";

            GoUrl += "req=" + HttpUtility.UrlEncode(DataBase64);
            GoUrl += "&sign=" + Sign;

            Response.Redirect(GoUrl);

            return(View("Null"));
        }
        public void FastNotice()
        {
            string Resp    = Request.Form["resp"];
            string Sign    = Request.Form["sign"];
            string SignStr = Resp;

            Resp = LokFuEncode.Base64Decode(Resp, "utf-8");
            JObject json = new JObject();

            try
            {
                json = (JObject)JsonConvert.DeserializeObject(Resp);
            }
            catch (Exception Ex)
            {
                Response.Write(Ex.ToString());
                return;
            }
            if (json == null)
            {
                Response.Write("Json Null");
                return;
            }
            string resultcode = json["resultcode"].ToString(); //交易结果码
            string resultmsg  = json["resultmsg"].ToString();  //交易结果信息
            string queryid    = json["queryid"].ToString();    //交易流水号
            string txnamt     = json["txnamt"].ToString();     //交易金额\
            string merid      = json["merid"].ToString();      //交易金额
            string orderid    = json["orderid"].ToString();    //交易金额

            FastOrder FastOrder = Entity.FastOrder.FirstOrDefault(n => n.TNum == orderid);

            if (FastOrder == null)
            {
                Response.Write("E1");
                return;
            }
            if (FastOrder.PayState == 1)
            {
                Response.Write("P1");
                return;
            }
            FastPayWay FastPayWay = Entity.FastPayWay.FirstOrDefault(n => n.Id == FastOrder.PayWay);

            if (FastPayWay == null)
            {
                Response.Write("E3");
                return;
            }
            if (FastPayWay.State != 1)
            {
                Response.Write("E4");
                return;
            }
            if (FastPayWay.DllName != "HFPay")
            {
                Response.Write("E5");
                return;
            }
            string[] PayConfigArr = FastPayWay.QueryArray.Split(',');
            if (PayConfigArr.Length != 3)
            {
                Response.Write("E53");
                return;
            }
            string MerId  = PayConfigArr[0];
            string MerKey = PayConfigArr[1];

            string MD5Str = SignStr + MerKey;
            string sign   = MD5Str.GetMD5();
            //================================================
            //这里记录日志
            PayLog PayLog = new PayLog();

            PayLog.PId     = (int)FastOrder.PayWay;
            PayLog.OId     = FastOrder.TNum;
            PayLog.TId     = FastOrder.Trade;
            PayLog.Amount  = decimal.Parse(txnamt) / 100;
            PayLog.Way     = "POST";
            PayLog.AddTime = DateTime.Now;
            PayLog.Data    = Request.Form.ToString();
            PayLog.State   = 1;
            Entity.PayLog.AddObject(PayLog);
            Entity.SaveChanges();
            //================================================
            if (Sign != sign)
            {
                Response.Write("E4");
                return;
            }
            if (MerId != merid)
            {
                Response.Write("E5");
                return;
            }
            if (resultcode != "0000" && resultcode != "1002")
            {
                Response.Write("E6");
                return;
            }
            int factmoney = int.Parse(txnamt);

            if (((int)(FastOrder.Amoney * 100)) != factmoney)
            {
                Response.Write("E7");
                return;
            }
            FastOrder.Trade = queryid;
            Entity.SaveChanges();

            FastOrder         = FastOrder.PaySuccess(Entity);
            ViewBag.FastOrder = FastOrder;

            Response.Write("0000");
        }
Exemple #29
0
        public void Post()
        {
            string Data = DataObj.GetData();

            if (Data.IsNullOrEmpty())
            {
                DataObj.OutError("1000");
                return;
            }
            JObject json = new JObject();

            try
            {
                json = (JObject)JsonConvert.DeserializeObject(Data);
            }
            catch (Exception Ex)
            {
                Log.Write("[FastOrderController]:", "【Data】" + Data, Ex);
                json = null;
            }
            if (json == null)
            {
                DataObj.OutError("1000");
                return;
            }

            FastOrder InFastOrder = new FastOrder();

            InFastOrder = JsonToObject.ConvertJsonToModel(InFastOrder, json);

            UserTrack UserTrack = new UserTrack();

            UserTrack = JsonToObject.ConvertJsonToModel(UserTrack, json);

            if (InFastOrder.Id == 99999)
            {
                DataObj.Msg = "当前通道维护中,建议您开通收款到银行卡功能,享受更多收款通道";
                DataObj.OutError("1000");
                return;
            }

            if (InFastOrder.CashType.IsNullOrEmpty())
            {
                InFastOrder.CashType = "D0";
                //DataObj.OutError("1000");
                //return;
            }
            decimal Amount = InFastOrder.Amoney;
            byte    payway = InFastOrder.OType;

            if (Amount <= 0)
            {
                DataObj.OutError("1000");
                return;
            }
            if (payway != 1 && payway != 2 && payway != 3)
            {
                DataObj.Msg = "你当前版本不支持该交易,请等待新版本发布及升级!";
                DataObj.OutError("1000");
                return;
            }

            Users Users = Entity.Users.FirstOrDefault(n => n.Token == InFastOrder.Token);

            #region 用户
            if (Users == null)//用户令牌不存在
            {
                DataObj.OutError("2004");
                return;
            }
            if (Users.State != 1)//用户被锁定
            {
                DataObj.OutError("2003");
                return;
            }
            if (Users.CardStae != 2)//未实名认证
            {
                DataObj.OutError("2006");
                return;
            }
            if (Amount.IsNullOrEmpty() || payway.IsNullOrEmpty())
            {
                DataObj.OutError("1000");
                return;
            }
            #endregion

            FastUser FastUser = Entity.FastUser.FirstOrDefault(o => o.UId == Users.Id);
            if (FastUser == null)
            {
                DataObj.OutError("2070");
                return;
            }
            #region 取通道
            IList <FastPayWay> FastPayWayList = null;
            if (InFastOrder.Id.IsNullOrEmpty())
            {
                //这是旧逻辑,有一些旧版还在用
                if (payway == 1)
                {
                    FastPayWayList = Entity.FastPayWay.Where(n => n.State == 1 && n.SNum2 < Amount && n.ENum2 >= Amount && n.HasAliPay == 1).OrderBy(n => n.Sort).ToList();
                }
                else if (payway == 2)
                {
                    FastPayWayList = Entity.FastPayWay.Where(n => n.State == 1 && n.SNum < Amount && n.ENum >= Amount && n.HasWeiXin == 1).OrderBy(n => n.Sort).ToList();
                }
                else if (payway == 3)
                {
                    FastPayWayList = Entity.FastPayWay.Where(n => n.State == 1 && n.BankSNum < Amount && n.BankENum >= Amount && n.HasBank == 1).OrderBy(n => n.Sort).ToList();
                }
                else
                {
                    DataObj.OutError("1000");
                    return;
                }
            }
            else
            {
                var query = Entity.FastPayWay.Where(n => n.Id == InFastOrder.Id && n.State == 1);
                if (payway == 1)
                {
                    query = query.Where(o => o.HasAliPay == 1 && o.SNum2 <= Amount && o.ENum2 >= Amount);
                }
                else if (payway == 2)
                {
                    query = query.Where(o => o.HasWeiXin == 1 && o.SNum <= Amount && o.ENum >= Amount);
                }
                else if (payway == 3)
                {
                    query = query.Where(o => o.HasBank == 1 && o.BankSNum <= Amount && o.BankENum >= Amount);
                }
                FastPayWayList = query.ToList();
            }
            #endregion
            if (FastPayWayList.Count < 1)
            {
                DataObj.OutError("2079");
                return;
            }
            #region 通道验证及商户进件信息验证
            FastPayWay         FastPayWay  = null;
            FastUserPay        FastUserPay = null;
            IList <FastPayWay> PayWayList  = new List <FastPayWay>();
            foreach (var p in FastPayWayList)
            {
                if (p.TimeType == 1)//限制时间,模式1
                {
                    DateTime STime    = p.STime;
                    DateTime ETime    = p.ETime;
                    DateTime NowSTime = DateTime.Parse(DateTime.Now.ToString("yyyy-MM-dd") + " " + STime.ToString("HH:mm:ss"));
                    DateTime NowETime = DateTime.Parse(DateTime.Now.ToString("yyyy-MM-dd") + " " + ETime.ToString("HH:mm:ss"));
                    if (NowSTime <= DateTime.Now && DateTime.Now <= NowETime)
                    {
                        //当前时间允许交易
                        PayWayList.Add(p);
                    }
                }
                else
                {
                    PayWayList.Add(p);
                }
            }
            if (PayWayList.Count < 1)
            {
                DataObj.OutError("2071");
                return;
            }
            foreach (var p in PayWayList)
            {
                FastUserPay temp = Entity.FastUserPay.FirstOrDefault(n => n.UId == Users.Id && n.PayWay == p.Id && n.MerState == 1 && n.CardState == 1 && n.BusiState == 1);
                if (temp != null)
                {
                    FastPayWay  = p;
                    FastUserPay = temp;
                    break;
                }
            }
            if (FastUserPay == null)
            {
                DataObj.OutError("2072");
                return;
            }
            if (FastPayWay == null)
            {
                DataObj.OutError("2073");
                return;
            }
            #endregion
            string[] PayConfigArr = FastPayWay.QueryArray.Split(',');
            #region 验证配置
            if (FastPayWay.DllName == "HFPay")
            {
                if (PayConfigArr.Length != 3)
                {
                    DataObj.OutError("2074");
                    return;
                }
            }
            if (FastPayWay.DllName == "HFJSPay")
            {
                if (PayConfigArr.Length != 3)
                {
                    DataObj.OutError("2074");
                    return;
                }
            }
            #endregion

            decimal UserCost  = 0;//用户
            decimal BankCost  = 0;
            decimal BankMin   = 0;
            decimal BankMax   = 0;
            decimal AgentCost = 0; //代理
            if (payway == 1)
            {                      //支付宝
                UserCost  = FastUserPay.UserCost2;
                BankCost  = FastPayWay.BankCost2;
                BankMin   = FastPayWay.MinCost2;
                BankMax   = FastPayWay.MaxCost2;
                AgentCost = FastPayWay.Cost2;
            }
            if (payway == 2)//微信
            {
                UserCost  = FastUserPay.UserCost;
                BankCost  = FastPayWay.BankCost;
                BankMin   = FastPayWay.MinCost;
                BankMax   = FastPayWay.MaxCost;
                AgentCost = FastPayWay.Cost;
            }
            if (payway == 3)//银联
            {
                UserCost  = FastUserPay.UserCost3;
                BankCost  = FastPayWay.BankCost3;
                BankMin   = FastPayWay.MinCost3;
                BankMax   = FastPayWay.MaxCost3;
                AgentCost = FastPayWay.Cost3;
            }
            #region 创建交易
            //=======================生成订单===========================
            SysAgent         SysAgent     = Entity.SysAgent.FirstOrNew(n => n.Id == Users.Agent);
            IList <SysAgent> SysAgentList = SysAgent.GetAgentsById(Entity);
            SysAgent         TopAgent     = SysAgentList.FirstOrNew();

            FastOrder FastOrder = new FastOrder();
            FastOrder.ComeWay = 1;
            FastOrder.UId     = Users.Id;
            FastOrder.Agent   = SysAgent.Id;

            FastOrder.PayId = string.Empty;

            FastOrder.OType    = payway;
            FastOrder.PayWay   = FastPayWay.Id;
            FastOrder.CashType = InFastOrder.CashType;
            FastOrder.Amoney   = Amount;

            //用户手续费
            decimal Poundage = Amount * UserCost + FastUserPay.UserCash;
            Poundage           = Poundage.Ceiling();
            FastOrder.Poundage = Poundage;
            //用户最终金额
            FastOrder.PayMoney = FastOrder.Amoney - FastOrder.Poundage;

            if (FastOrder.PayMoney < 0)
            {
                DataObj.OutError("2076");
                return;
            }
            FastOrder.UserRate  = UserCost;
            FastOrder.AgentRate = AgentCost;
            FastOrder.SysRate   = BankCost;
            FastOrder.UserCash  = FastUserPay.UserCash;
            FastOrder.SysCash   = FastPayWay.Cash;
            FastOrder.SameGet   = 0;
            //计算手续费差
            SysMoneySet SysMoneySet = Entity.SysMoneySet.FirstOrNew();
            decimal     PaySplit    = 0;//代理商费率
            PaySplit = SysAgent.GetSplit(TopAgent.Tier, Entity);
            decimal PayGet = Amount * PaySplit;
            PayGet = PayGet.Floor();
            //一级代理利润
            decimal AgentPayGet = PayGet;
            AgentPayGet           = AgentPayGet.Floor();
            FastOrder.AgentPayGet = 0;
            string  AgentPath = "|";
            string  Split     = "|";
            decimal MyGet     = PayGet;
            foreach (var p in SysAgentList)
            {
                PaySplit   = SysAgent.GetSplit(p.Tier, Entity);
                AgentPath += p.Id + "|";
                MyGet      = Amount * PaySplit;//各级代理分润
                MyGet      = MyGet.Floor();
                Split     += MyGet.ToString("F2") + "|";
            }
            FastOrder.AgentPath = AgentPath;
            FastOrder.Split     = Split;

            decimal BankMoney = Amount * BankCost;
            if (BankMoney < BankMin)
            {
                BankMoney = BankMin;
            }
            if (BankMoney > BankMax)
            {
                BankMoney = BankMax;
            }
            BankMoney = BankMoney.Floor();
            //用户手续费(含代付手续费)-代付分润-银行手续费-银行代付成本
            decimal HFGet = Poundage - AgentPayGet - BankMoney - FastPayWay.Cash;
            FastOrder.HFGet = HFGet;

            FastOrder.State   = 1;
            FastOrder.AddTime = DateTime.Now;

            FastOrder.PayState   = 0;
            FastOrder.AgentState = 0;
            FastOrder.UserState  = 0;

            FastOrder.CardName = FastUserPay.CardName;
            FastOrder.Bank     = FastUserPay.Bank;
            FastOrder.Card     = FastUserPay.Card;
            FastOrder.Bin      = FastUserPay.Bin;

            Entity.FastOrder.AddObject(FastOrder);
            Entity.SaveChanges();
            Entity.Refresh(RefreshMode.StoreWins, FastOrder);
            #endregion

            //=======================================
            UserTrack.ENo      = DataObj.ENo;
            UserTrack.OPType   = "到银行卡交易";
            UserTrack.UserName = FastOrder.TNum;
            UserTrack.UId      = FastOrder.UId;
            UserTrack.SeavGPSLog(Entity);
            //=======================================

            //=======================分润记录===========================
            MyGet = PayGet;
            int tier = 1;
            foreach (var p in SysAgentList)
            {
                PaySplit = SysAgent.GetSplit(p.Tier, Entity);
                MyGet    = Amount * PaySplit;//各级代理分润
                MyGet    = MyGet.Floor();
                FastSplit FastSplit = new FastSplit();
                FastSplit.Tnum    = FastOrder.TNum;
                FastSplit.Profit  = MyGet;
                FastSplit.AgentId = p.Id;
                FastSplit.Tier    = p.Tier;
                FastSplit.AddTime = DateTime.Now;
                Entity.FastSplit.AddObject(FastSplit);
                tier++;
            }
            Entity.SaveChanges();
            //=======================请求接口开始===========================
            if (FastOrder.OType == 1 || FastOrder.OType == 2)
            {
                if (FastPayWay.DllName == "HFPay")
                {
                    string NoticeUrl = NoticePath + "/PayCenter/HFPay/FastNotice.html";//后台通过地址
                    #region 微信&支付宝
                    string Action = "";
                    if (FastOrder.OType == 1)
                    {
                        Action = "AliSao";
                    }
                    else if (FastOrder.OType == 2)
                    {
                        Action = "WxSao";
                    }
                    //提交结算中心
                    string merId  = PayConfigArr[0]; //商户号
                    string merKey = PayConfigArr[1]; //商户密钥
                    string PayWay = PayConfigArr[2]; //绑定通道

                    decimal money      = FastOrder.Amoney * 100;
                    string  OrderMoney = money.ToString("F0");//金额,以分为单

                    string PostJson = "{\"action\":\"" + Action + "\",\"txnamt\":\"" + OrderMoney + "\",\"merid\":\"" + merId + "\",\"payway\":\"" + PayWay + "\",\"orderid\":\"" + FastOrder.TNum + "\",\"backurl\":\"" + NoticeUrl + "\"}";

                    string DataBase64 = LokFuEncode.Base64Encode(PostJson, "utf-8");
                    string Sign       = (DataBase64 + merKey).GetMD5();

                    DataBase64 = HttpUtility.UrlEncode(DataBase64);
                    string PostData = string.Format("req={0}&sign={1}", DataBase64, Sign);

                    string HF_Url = "https://api.zhifujiekou.com/api/mpgateway";

                    string Ret = Utils.PostRequest(HF_Url, PostData, "utf-8");

                    JObject JS = new JObject();
                    try
                    {
                        JS = (JObject)JsonConvert.DeserializeObject(Ret);
                    }
                    catch (Exception)
                    {
                        FastOrder.State  = 0;
                        FastOrder.Remark = "数据请求出错";
                        Entity.SaveChanges();
                        JS = null;
                    }
                    if (JS != null)
                    {
                        string resp = JS["resp"].ToString();
                        Ret = LokFuEncode.Base64Decode(resp, "utf-8");
                        try
                        {
                            JS = (JObject)JsonConvert.DeserializeObject(Ret);
                        }
                        catch (Exception Ex)
                        {
                            FastOrder.State  = 0;
                            FastOrder.Remark = "JSON加载出错";
                            Entity.SaveChanges();
                            JS = null;
                        }
                        if (JS != null)
                        {
                            string respcode = JS["respcode"].ToString();
                            if (respcode != "00")
                            {
                                string respmsg = JS["respmsg"].ToString();
                                FastOrder.State  = 0;
                                FastOrder.Remark = respmsg;
                                Entity.SaveChanges();
                            }
                            else
                            {
                                if (JS["formaction"] == null)
                                {
                                    FastOrder.State  = 0;
                                    FastOrder.Remark = "接口没有返回二维码";
                                    Entity.SaveChanges();
                                }
                                else
                                {
                                    string BankNum = JS["queryid"].ToString();
                                    string qr_code = JS["formaction"].ToString();
                                    FastOrder.PayId = qr_code;
                                    FastOrder.Trade = BankNum;
                                    Entity.SaveChanges();
                                }
                            }
                        }
                    }
                    #endregion
                }
            }
            else if (FastOrder.OType == 3)
            {
                if (FastPayWay.DllName == "HFPay" || FastPayWay.DllName == "HFJSPay")
                {
                    #region
                    //银联不用请求第三方,直接生成链接
                    FastOrder.PayId = PayPath + "/paycenter/pay-" + FastOrder.Id + ".html?sign=" + ((FastOrder.Id * 100 + 99) + "Pay").GetMD5().Substring(8, 8);
                    Entity.SaveChanges();
                    #endregion
                }
            }
            if (FastOrder.State == 1)
            {
                if (FastOrder.PayState == 1)
                {
                    if (FastOrder.UserState == 1)
                    {
                        FastOrder.State = 3;
                    }
                    else
                    {
                        FastOrder.State = 2;
                    }
                }
                else
                {
                    FastOrder.State = 1;
                }
            }
            else
            {
                FastOrder.State = 0;
                DataObj.OutError("1005");
                return;
            }
            FastOrder.Cols = "TNum,PayId,Amoney,Poundage,State";

            DataObj.Data = FastOrder.OutJson();
            DataObj.Code = "0000";
            DataObj.OutString();
        }
        private void ContextMenuAction(object param)
        {
            if (SelectedItem == null)
            {
                return;
            }
            var str = param.ToString().Split('/');

            switch (str[0])
            {
            case "add":
                AddToWatchlist();
                break;

            case "Logbook":
            {
                var view = new LogBook();
                view.DataContext = new LogBookViewModel(SelectedItem.Board, SelectedItem.Seccode, view);
                view.Show();
                break;
            }

            case "Level2":
            {
                var view = new Level2();
                view.DataContext = new Level2ViewModel(SelectedItem.Board, SelectedItem.Seccode, view);
                view.Show();
                break;
            }

            case "AllTrades":
            {
                var view = new AllTradesSimple();
                view.DataContext = new AllTradesSimpleViewModel(SelectedItem.Board, SelectedItem.Seccode, view);
                view.Show();
                break;
            }

            case "AllTradesPro":
            {
                var view = new AllTrades();
                view.DataContext = new AllTradesViewModel(SelectedItem.Board, SelectedItem.Seccode, view);
                view.Show();
                break;
            }

            case "TradesCounter":
            {
                new AllTradesCounterWindow {
                    DataContext = new AllTradesCounterViewModel(SelectedItem.Board, SelectedItem.Seccode)
                }.Show();
                break;
            }

            case "Chart":
            {
                var view = new SciChartWindow();
                view.DataContext = new SciChartViewModel(SelectedItem.Board, SelectedItem.Seccode, view);
                view.Show();
                break;
            }

            case "NewOrder":
            {
                new NewOrder
                {
                    DataContext = new NewOrderViewModel
                    {
                        Board   = SelectedItem.Board,
                        Seccode = SelectedItem.Seccode
                    }
                }.Show();
                break;
            }

            case "NewStoporder":
            {
                new NewStopOrder
                {
                    DataContext = new NewStopOrderViewModel
                    {
                        Board   = SelectedItem.Board,
                        Seccode = SelectedItem.Seccode
                    }
                }.Show();
                break;
            }

            case "Cart":
                Application.Current.Dispatcher.Invoke(
                    () => ((MainWindowViewModel)Application.Current.MainWindow.DataContext).CartViewModel.Orders
                    .Add(new CartItem
                {
                    Board   = SelectedItem.Board,
                    Seccode = SelectedItem.Seccode,
                    Client  = SelectClient(SelectedItem.Board)[0],
                    Union   = SelectClient(SelectedItem.Board)[1],
                    Mkt     = true
                }));
                break;

            case "Spread":
            {
                new Spread
                {
                    DataContext = new SpreadViewModel(SelectedItem.Board, SelectedItem.Seccode)
                }.Show();
                break;
            }

            case "FastOrder":
            {
                var view = new FastOrder();
                view.DataContext = new FastOrderViewModel(SelectedItem.Board, SelectedItem.Seccode, view);
                view.Show();
                break;
            }
            }
        }