public ActionResult Info(OrderCash OrderCash)
        {
            if (OrderCash.Id != 0)
            {
                OrderCash = Entity.OrderCash.FirstOrDefault(n => n.Id == OrderCash.Id);
            }
            ViewBag.OrderCash = OrderCash;
            Orders Orders = Entity.Orders.FirstOrDefault(n => n.TNum == OrderCash.OId);

            if (Orders == null)
            {
                ViewBag.ErrorMsg = "数据不存在";
                return(View("Error"));
            }
            ViewBag.Orders = Orders;
            Users Users = Entity.Users.FirstOrNew(n => n.Id == Orders.UId);

            if (Users == null)
            {
                ViewBag.ErrorMsg = "数据不存在";
                return(View("Error"));
            }
            ViewBag.Users    = Users;
            ViewBag.SysAgent = Entity.SysAgent.FirstOrNew(n => n.Id == Orders.Agent);
            ViewBag.SysAdmin = Entity.SysAdmin.FirstOrNew(n => n.Id == Orders.AId);
            ViewBag.FinAdmin = Entity.SysAdmin.FirstOrNew(n => n.Id == Orders.FId);
            return(View("Edit"));
        }
        public ActionResult Index(OrderCash OrderCash, EFPagingInfo <OrderCash> p, bool?IsShowSupAgent, int IsFirst = 0, int TimeType = 1)
        {
            if (IsShowSupAgent == null)
            {
                IsShowSupAgent = false;
            }
            p = this.Condition(OrderCash, p, IsShowSupAgent, IsFirst, TimeType);
            p.OrderByList.Add("Id", "DESC");
            IPageOfItems <OrderCash> OrderCashList = null;

            if (IsFirst == 0)
            {
                OrderCashList = new PageOfItems <OrderCash>(new List <OrderCash>(), 0, 10, 0, new Hashtable());
            }
            else
            {
                OrderCashList = Entity.Selects <OrderCash>(p);
            }
            ViewBag.OrderCashList = OrderCashList;
            ViewBag.OrderCash     = OrderCash;
            IList <OrderCash> List = OrderCashList.GroupBy(n => n.UId).Select(n => n.First()).ToList();
            List <int>        UId  = new List <int>();

            foreach (var pp in List)
            {
                UId.Add(pp.UId);
            }
            ViewBag.UsersList      = Entity.Users.Where(n => n.State == 1 && UId.Contains(n.Id)).ToList();
            ViewBag.SysAgentList   = Entity.SysAgent.Where(n => n.State == 1).ToList();
            ViewBag.IsShowSupAgent = IsShowSupAgent;
            ViewBag.Save           = this.checkPower("Save");
            ViewBag.TimeType       = TimeType;
            ViewBag.ExcelExport    = this.checkPower("ExcelExport");
            return(View());
        }
        public void CancelSave(OrderCash OrderCash)
        {
            OrderCash.Remark = OrderCash.Remark.IsNullOrEmpty() ? string.Empty : OrderCash.Remark;
            OrderCash baseOrderCash = Entity.OrderCash.FirstOrDefault(n => n.Id == OrderCash.Id);

            if (baseOrderCash.OrderState == 2 && ((baseOrderCash.PayState == 1 && baseOrderCash.FState == 0) || (baseOrderCash.PayState == 2 && baseOrderCash.FState == 1)))
            {
                baseOrderCash.PayState = 3;
                baseOrderCash.Remark   = OrderCash.Remark;
                Orders Orders = Entity.Orders.FirstOrDefault(n => n.TNum == baseOrderCash.OId);
                Orders.PayState = 3;
                Orders.Remark   = OrderCash.Remark;

                var OrderCashLog = new OrderCashLog()
                {
                    AddTime   = DateTime.Now,
                    AdminId   = this.AdminUser.Id,
                    AdminName = this.AdminUser.TrueName,
                    TNum      = baseOrderCash.OId,
                    Remark    = baseOrderCash.Remark,
                    LogType   = 2,
                };
                this.Entity.OrderCashLog.AddObject(OrderCashLog);

                Entity.SaveChanges();
                Orders.SendMsg(Entity);//发送消息类
            }
            BaseRedirect();
        }
        public ActionResult Edit(OrderCash OrderCash)
        {
            if (OrderCash.Id != 0)
            {
                OrderCash = Entity.OrderCash.FirstOrDefault(n => n.Id == OrderCash.Id);
            }
            if (OrderCash == null)
            {
                ViewBag.ErrorMsg = "数据不存在";
                return(View("Error"));
            }
            ViewBag.OrderCash = OrderCash;
            Orders Orders = Entity.Orders.FirstOrDefault(n => n.TNum == OrderCash.OId);

            if (Orders.PayState != 3 && Orders.PayState != 4)
            {
                ViewBag.ErrorMsg = "当前状态不能退款!";
                return(View("Error"));
            }
            if (Orders.TState != 2)
            {
                ViewBag.ErrorMsg = "交易不成功,不能退款!";
                return(View("Error"));
            }
            ViewBag.Orders   = Orders;
            ViewBag.Users    = Entity.Users.FirstOrNew(n => n.Id == Orders.UId);
            ViewBag.SysAgent = Entity.SysAgent.FirstOrNew(n => n.Id == Orders.Agent);
            ViewBag.SysAdmin = Entity.SysAdmin.FirstOrNew(n => n.Id == Orders.AId);
            ViewBag.FinAdmin = Entity.SysAdmin.FirstOrNew(n => n.Id == Orders.FId);
            if (Request.UrlReferrer != null)
            {
                Session["Url"] = Request.UrlReferrer.ToString();
            }
            return(View());
        }
        public void SaveEdit(OrderCash OrderCash)
        {
            OrderCash baseOrderCash = Entity.OrderCash.FirstOrDefault(n => n.Id == OrderCash.Id);
            Orders    Orders        = Entity.Orders.FirstOrDefault(n => n.TNum == baseOrderCash.OId);

            if (baseOrderCash.OrderState == 2 && baseOrderCash.PayState == 3)
            {
                baseOrderCash.PayState = 2;
                baseOrderCash.FState   = 1;
                baseOrderCash.FTime    = DateTime.Now;
                Orders.PayState        = 2;
                Entity.SaveChanges();
                //======分润======
                baseOrderCash      = baseOrderCash.PayAgent(Entity, 1);
                Orders.AgentPayGet = (decimal)baseOrderCash.AgentCashGet;

                var OrderCashLog = new OrderCashLog()
                {
                    AddTime   = DateTime.Now,
                    AdminId   = this.AdminUser.Id,
                    AdminName = this.AdminUser.TrueName,
                    TNum      = baseOrderCash.OId,
                    Remark    = string.Empty,
                    LogType   = 4,
                };
                this.Entity.OrderCashLog.AddObject(OrderCashLog);

                Entity.SaveChanges();
                Orders.SendMsg(Entity);//发送消息类
            }
            BaseRedirect();
        }
 public void ChangeStatus(OrderCash OrderCash, string InfoList, string Clomn, string Value)
 {
     //Clomn	FState
     //InfoList
     //206,205,192,191,190,189,188,187,186,47,39
     //value	1
     if (Clomn == "FState" && Value == "1")
     {
         string[] Arr = InfoList.Split(',');
         if (Arr.Length > 0)
         {
             List <int> ArrInt = new List <int>();
             foreach (string p in Arr)
             {
                 ArrInt.Add(Int32.Parse(p));
             }
             IList <OrderCash> List = Entity.OrderCash.Where(n => ArrInt.Contains(n.Id)).ToList();
             foreach (var p in List)
             {
                 Orders Orders = Entity.Orders.FirstOrDefault(n => n.TNum == p.OId);
                 if (BasicSet.CashPayWay == 1)//开启自动结算时执行
                 {
                     //自动出款
                     p.PayCash(Orders, Entity);//去付款
                     Thread.Sleep(1200);
                 }
                 else
                 {
                     p.PayState = 2;
                     p.FState   = 1;
                     p.FTime    = DateTime.Now;
                     //======分润======
                     OrderCash OC = p.PayAgent(Entity, 1);
                     Orders.AgentPayGet = (decimal)OC.AgentCashGet;
                     Orders.PayState    = 2;
                 }
                 Orders.SendMsg(Entity);//发送消息类
             }
             Entity.SaveChanges();
             Response.Write(List.Count);
         }
     }
     //if (string.IsNullOrEmpty(InfoList)) { InfoList = OrderCash.Id.ToString(); }
     //int Ret = Entity.ChangeEntity<OrderCash>(InfoList, Clomn, Value);
     //Entity.SaveChanges();
     //Response.Write(Ret);
 }
        public ActionResult Index(OrderCash OrderCash, EFPagingInfo <OrderCash> p, bool?IsShowSupAgent, int IsFirst = 0)
        {
            if (IsShowSupAgent == null)
            {
                IsShowSupAgent = false;
            }
            p = this.Condition(OrderCash, p, IsShowSupAgent);
            if (Request.QueryString["PageSize"].IsNullOrEmpty())
            {
                p.PageSize = 30;
            }
            p.OrderByList.Add("Id", "DESC");
            IPageOfItems <OrderCash> OrderCashList = null;

            if (IsFirst == 0)
            {
                OrderCashList = new PageOfItems <OrderCash>(new List <OrderCash>(), 0, 10, 0, new Hashtable());
            }
            else
            {
                OrderCashList = Entity.Selects <OrderCash>(p);
            }
            ViewBag.OrderCashList = OrderCashList;
            ViewBag.OrderCash     = OrderCash;
            IList <OrderCash> List = OrderCashList.GroupBy(n => n.UId).Select(n => n.First()).ToList();
            List <int>        UId  = new List <int>();

            foreach (var pp in List)
            {
                UId.Add(pp.UId);
            }
            ViewBag.UsersList      = Entity.Users.Where(n => n.State == 1 && UId.Contains(n.Id)).ToList();
            ViewBag.SysAgentList   = Entity.SysAgent.Where(n => n.State == 1).ToList();
            ViewBag.IsShowSupAgent = IsShowSupAgent;//是否显示下级

            bool PayCash = checkPower("PayCash");

            ViewBag.PayCash     = PayCash;
            ViewBag.Edit        = this.checkPower("Edit");
            ViewBag.Cancel      = this.checkPower("Cancel");
            ViewBag.Save        = this.checkPower("Save");
            ViewBag.Xls         = this.checkPower("Xls");
            ViewBag.XLSDoShanFu = this.checkPower("XLSDoShanFu");
            return(View());
        }
        public void Save(OrderCash OrderCash)
        {
            OrderCash baseOrderCash = Entity.OrderCash.FirstOrDefault(n => n.Id == OrderCash.Id);
            Orders    Orders        = Entity.Orders.FirstOrDefault(n => n.TNum == baseOrderCash.OId);
            var       OrderCashLog  = new OrderCashLog()
            {
                AddTime   = DateTime.Now,
                AdminId   = this.AdminUser.Id,
                AdminName = this.AdminUser.TrueName,
                TNum      = baseOrderCash.OId,
                Remark    = string.Empty,
                LogType   = 1,
            };

            this.Entity.OrderCashLog.AddObject(OrderCashLog);
            Entity.SaveChanges();
            if (BasicSet.CashPayWay == 1)//开启自动结算时执行
            {
                //自动出款
                baseOrderCash.PayCash(Orders, Entity);//去付款
            }
            else
            {
                if (baseOrderCash.OrderState == 2 && baseOrderCash.PayState == 1 && baseOrderCash.FState == 0)
                {
                    baseOrderCash.PayState = 2;
                    baseOrderCash.FState   = 1;
                    baseOrderCash.FTime    = DateTime.Now;
                    Orders.PayState        = 2;
                    Entity.SaveChanges();
                    //======分润======
                    baseOrderCash      = baseOrderCash.PayAgent(Entity, 1);
                    Orders.AgentPayGet = (decimal)baseOrderCash.AgentCashGet;
                    Entity.SaveChanges();
                }
            }
            Orders.SendMsg(Entity);//发送消息类
            BaseRedirect();
        }
        public ActionResult Info(OrderCash OrderCash)
        {
            ViewBag.BasicDescList = GetBasicDescList(BasicCodeEnum.Txtk);
            if (OrderCash.Id != 0)
            {
                OrderCash = Entity.OrderCash.FirstOrDefault(n => n.Id == OrderCash.Id);
            }
            ViewBag.OrderCash = OrderCash;
            Orders Orders = Entity.Orders.FirstOrDefault(n => n.TNum == OrderCash.OId);

            if (Orders == null)
            {
                ViewBag.ErrorMsg = "订单不存在!";
                return(View("Error"));
            }
            ViewBag.Orders   = Orders;
            ViewBag.Users    = Entity.Users.FirstOrNew(n => n.Id == Orders.UId);
            ViewBag.SysAgent = Entity.SysAgent.FirstOrNew(n => n.Id == Orders.Agent);
            ViewBag.SysAdmin = Entity.SysAdmin.FirstOrNew(n => n.Id == Orders.AId);
            ViewBag.FinAdmin = Entity.SysAdmin.FirstOrNew(n => n.Id == Orders.FId);
            return(View("Edit"));
        }
        /// <summary>
        /// 统计
        /// </summary>
        /// <returns></returns>
        public ActionResult IndexStats(OrderCash OrderCash, EFPagingInfo <OrderCash> p, bool?IsShowSupAgent, int IsFirst = 0, int TimeType = 1)
        {
            if (IsShowSupAgent == null)
            {
                IsShowSupAgent = false;
            }
            p = this.Condition(OrderCash, p, IsShowSupAgent, IsFirst, TimeType);
            var Iquery = this.Entity.OrderCash.AsQueryable();

            foreach (var item in p.SqlWhere)
            {
                Iquery = Iquery.Where(item);
            }
            var Count       = Iquery.Count();
            var SumAmoney   = Iquery.Sum(o => (decimal?)o.Amoney);
            var SumPaymoney = Iquery.Sum(o => (double?)o.UserRate);

            this.ViewBag.SumAmoney   = SumAmoney;
            this.ViewBag.SumPaymoney = SumPaymoney;
            this.ViewBag.Count       = Count;
            return(this.View());
        }
        public ActionResult Cancel(OrderCash OrderCash)
        {
            ViewBag.BasicDescList = GetBasicDescList(BasicCodeEnum.Txtk);
            if (OrderCash.Id != 0)
            {
                OrderCash = Entity.OrderCash.FirstOrDefault(n => n.Id == OrderCash.Id);
            }
            ViewBag.OrderCash = OrderCash;
            Orders Orders = Entity.Orders.FirstOrDefault(n => n.TNum == OrderCash.OId);

            if (Orders == null)
            {
                ViewBag.ErrorMsg = "订单不存在!";
                return(View("Error"));
            }
            if (Orders.PayState != 1 && Orders.PayState != 2)
            {
                ViewBag.ErrorMsg = "当前状态不能申请退款!";
                return(View("Error"));
            }
            if (Orders.TState != 2)
            {
                ViewBag.ErrorMsg = "交易不成功,不能退款!";
                return(View("Error"));
            }
            ViewBag.Orders   = Orders;
            ViewBag.Users    = Entity.Users.FirstOrNew(n => n.Id == Orders.UId);
            ViewBag.SysAgent = Entity.SysAgent.FirstOrNew(n => n.Id == Orders.Agent);
            ViewBag.SysAdmin = Entity.SysAdmin.FirstOrNew(n => n.Id == Orders.AId);
            ViewBag.FinAdmin = Entity.SysAdmin.FirstOrNew(n => n.Id == Orders.FId);
            if (Request.UrlReferrer != null)
            {
                Session["Url"] = Request.UrlReferrer.ToString();
            }
            return(View("Edit"));
        }
Пример #12
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("[Orders]:", "【Data】" + Data, Ex);
            }
            if (json == null)
            {
                DataObj.OutError("1000");
                return;
            }
            Orders Orders = new Orders();

            Orders = JsonToObject.ConvertJsonToModel(Orders, json);

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

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

            Orders = Entity.Orders.FirstOrDefault(n => n.TNum == Orders.TNum && (n.UId == baseUsers.Id || (n.RUId == baseUsers.Id && n.PayState == 1)));
            if (Orders == null)//不存在
            {
                DataObj.OutError("1001");
                return;
            }
            if (Orders.RUId == baseUsers.Id)
            {
                Orders.TType = 4;
            }
            Orders.DoRemark(Entity);

            Orders.StateTxt = Orders.GetState();

            String Out = Orders.ToStr();

            if (Orders.TType == 1)
            { //银联卡支付
                OrderRecharge OrderRecharge = Entity.OrderRecharge.FirstOrNew(n => n.OId == Orders.TNum);
                OrderRecharge.Cols = "Amoney,PayMoney,Poundage,PayType";
                Out = Out + "," + OrderRecharge.ToStr();
            }
            if (Orders.TType == 2)//提现不能取消
            {
                OrderCash OrderCash = Entity.OrderCash.FirstOrNew(n => n.OId == Orders.TNum);
                OrderCash.Cols = "Owner,Bank,CardNum,Deposit,Mobile,Province,City,District,Amoney,UserRate";
                Out            = Out + "," + OrderCash.ToStr();
            }
            if (Orders.TType == 3 || Orders.TType == 4)//付款
            {
                OrderTransfer OrderTransfer = Entity.OrderTransfer.FirstOrNew(n => n.OId == Orders.TNum);
                OrderTransfer.Cols = "UId,RUId,PayMoney,Poundage,Amoney";
                Out = Out + "," + OrderTransfer.ToStr();
            }
            if (Orders.TType == 5)//防租
            {
                OrderHouse OrderHouse = Entity.OrderHouse.FirstOrNew(n => n.OId == Orders.TNum);
                OrderHouse.Cols = "HouseOwner,Bank,CardNum,Deposit,Mobile,MonthRent,SecurityMoney,PayMonth,Poundage,Amoney";
                Out             = Out + "," + OrderHouse.ToStr();
            }
            if (Orders.TType == 6)
            { //升级
              //PayConfigOrder PayConfigOrder = Entity.PayConfigOrder.FirstOrNew(n => n.OId == Orders.TNum);
              //Out = Out + "," + PayConfigOrder.ToStr();
            }
            if (Orders.TType == 7 || Orders.TType == 8 || Orders.TType == 9)
            { //扫码
                OrderF2F OrderF2F = Entity.OrderF2F.FirstOrNew(n => n.OId == Orders.TNum);
                OrderF2F.Cols = "Amoney,PayMoney,Poundage";
                Out           = Out + "," + OrderF2F.ToStr();
            }
            if (Orders.TType == 10)
            { //代理
            }
            Out          = "{" + Out + "}";
            DataObj.Data = Out;
            DataObj.Code = "0000";
            DataObj.OutString();
        }
Пример #13
0
        public void Execute(IJobExecutionContext context)
        {
            string JobName = "OutMoney";
            string CanRun  = ConfigurationManager.AppSettings["Run" + JobName].ToString();

            if (CanRun == "true")
            {
                if (!IsRun)
                {
                    LokFuEntity Entity = new LokFuEntity();
                    IsRun = true;
                    try
                    {
                        Log.Write(JobName + "任务开始执行!");
                        //-------------------------------------------------------
                        #region 任务主体
                        #region 全局变量
                        SysSet BasicSet = Entity.SysSet.FirstOrDefault();

                        string NoticePath = ConfigurationManager.AppSettings["NoticePath"].ToString();
                        string NoticeUrl  = NoticePath + "/PayCenter/HFCash/Notice.html";
                        //提交结算中心
                        string merId  = ConfigurationManager.AppSettings["Cash_merId"].ToString();  //商户号
                        string merKey = ConfigurationManager.AppSettings["Cash_merKey"].ToString(); //商户密钥
                        #endregion
                        //0=无效,1=待执行,2=执行中,3=完成
                        IList <TaskCash> TaskCashList = Entity.TaskCash.Where(n => n.State == 1 || n.State == 2).OrderBy(n => n.Id).ToList();
                        //读取待执行
                        foreach (var P in TaskCashList)
                        {
                            //任务状态设置为执行中
                            if (P.State == 1)
                            {
                                P.State = 2;
                                P.STime = DateTime.Now;
                                Entity.SaveChanges();
                            }
                            IList <TaskCashInfo> TaskCashInfoList = Entity.TaskCashInfo.Where(n => (n.State == 1 || n.State == 2) && n.TId == P.Id).OrderBy(n => n.Id).ToList();
                            foreach (var p in TaskCashInfoList)
                            {
                                if (p.State == 1)
                                {
                                    p.State = 2;
                                    p.STime = DateTime.Now;
                                    Entity.SaveChanges();
                                }
                                OrderCash OC     = Entity.OrderCash.FirstOrDefault(n => n.OId == p.OId);
                                bool      CanPay = true;
                                if (OC == null)
                                {
                                    CanPay = false;
                                }
                                if (OC.FState == 1)//已付过款
                                {
                                    CanPay = false;
                                }
                                if (OC.OrderState != 2 || OC.PayState != 1)
                                {
                                    CanPay = false;
                                }
                                if (CanPay)//开启自动结算时执行
                                {
                                    if (BasicSet.CashPayWay == 0)
                                    {
                                        p.State  = 3;//标识成功
                                        p.OState = 2;
                                        p.NState = 1;
                                        p.Remark = "批量人工结算";
                                        p.ETime  = DateTime.Now;

                                        OC.PayState = 2;
                                        OC.FState   = 1;
                                        OC.FTime    = DateTime.Now;
                                        Orders O = Entity.Orders.FirstOrDefault(n => n.TNum == p.OId);
                                        if (O != null)
                                        {
                                            O.PayState   = 2;
                                            O.InternalRm = "批量人工结算";
                                        }
                                        Entity.SaveChanges();
                                        //======分润======
                                        OC = OC.PayAgent(Entity, 1);
                                        if (O != null)
                                        {
                                            O.AgentPayGet = (decimal)OC.AgentCashGet;
                                        }
                                        Entity.SaveChanges();
                                    }
                                    else if (BasicSet.CashPayWay == 1)
                                    {
                                        #region 提交接口
                                        string  orderId    = OC.OId;//商户流水号
                                        decimal PayMoney   = OC.Amoney - (decimal)OC.UserRate;
                                        decimal money      = PayMoney * 100;
                                        long    intmoney   = Int64.Parse(money.ToString("F0"));
                                        string  OrderMoney = intmoney.ToString();//金额,以分为单


                                        string UserCardId = Entity.Users.FirstOrNew(n => n.Id == OC.UId).CardId;
                                        string PostJson   = "{\"action\":\"QCash\",\"txnamt\":\"" + OrderMoney + "\",\"merid\":\"" + merId + "\",\"orderid\":\"" + orderId + "\",\"backurl\":\"" + NoticeUrl + "\",\"bin\":\"" + OC.Bin + "\",\"accno\":\"" + OC.CardNum + "\",\"accname\":\"" + OC.Owner + "\",\"cardno\":\"" + UserCardId + "\"}";

                                        //传送数据Base64
                                        string DataBase64 = LokFuEncode.Base64Encode(PostJson, "utf-8");

                                        //获得签名
                                        string Sign = (DataBase64 + merKey).GetMD5();

                                        //传送数据UrlEnCode
                                        DataBase64 = System.Web.HttpUtility.UrlEncode(DataBase64);

                                        //组装Post数据
                                        string PostData = string.Format("req={0}&sign={1}", DataBase64, Sign);

                                        string HFNFC_Url = "https://api.zhifujiekou.com/api/qcashgateway";

                                        //Post数据,获得结果
                                        string  Ret     = Utils.PostRequest(HFNFC_Url, PostData, "utf-8");
                                        string  runType = "PayOk";
                                        JObject JS      = new JObject();
                                        try
                                        {
                                            JS = (JObject)JsonConvert.DeserializeObject(Ret);
                                        }
                                        catch (Exception)
                                        {
                                            Utils.WriteLog("[" + OC.OId + "]" + Ret, "PayCashCenterErr");
                                            runType = "PayIng";
                                        }
                                        string Remark = "";
                                        if (runType == "PayOk")
                                        {
                                            if (JS != null)
                                            {
                                                string resp = JS["resp"].ToString();
                                                Ret = LokFuEncode.Base64Decode(resp, "utf-8");
                                                try
                                                {
                                                    JS = (JObject)JsonConvert.DeserializeObject(Ret);
                                                }
                                                catch (Exception)
                                                {
                                                    runType = "PayIng";
                                                }
                                                if (runType == "PayOk")
                                                {
                                                    if (JS != null)
                                                    {
                                                        string respcode = JS["respcode"].ToString();
                                                        if (respcode != "00")
                                                        {
                                                            if (respcode == "45")
                                                            {
                                                                //限额了,需要特别处理
                                                                runType = "PayErr";
                                                            }
                                                            else
                                                            {
                                                                runType = "PayIng";
                                                            }
                                                            Remark = JS["respmsg"].ToString();
                                                        }
                                                        else
                                                        {
                                                            string resultcode = JS["resultcode"].ToString();
                                                            if (resultcode == "0000")
                                                            {
                                                                runType = "PayOk";
                                                            }
                                                            else if (resultcode == "2002" || resultcode == "2003")
                                                            {
                                                                runType = "PayErr";
                                                                Remark  = JS["resultmsg"].ToString();
                                                            }
                                                            else
                                                            {
                                                                runType = "PayIng";
                                                                Remark  = JS["resultmsg"].ToString();
                                                            }
                                                        }
                                                    }
                                                    else
                                                    {
                                                        runType = "PayIng";
                                                    }
                                                }
                                            }
                                            else
                                            {
                                                runType = "PayIng";
                                            }
                                        }

                                        if (runType == "PayIng")
                                        {
                                            //处理中
                                            p.ETime = DateTime.Now;
                                            p.State = 5;//标识 未知状态
                                            Entity.SaveChanges();
                                        }
                                        if (runType == "PayErr")
                                        {
                                            OC.PayState = 3;
                                            OC.Remark   = Remark;
                                            p.State     = 4;//标识失败
                                            p.OState    = 2;
                                            p.NState    = 1;
                                            p.Remark    = Remark;
                                            p.ETime     = DateTime.Now;
                                            Orders O = Entity.Orders.FirstOrDefault(n => n.TNum == p.OId);
                                            if (O != null)
                                            {
                                                O.PayState = 3;
                                                O.Remark   = Remark;
                                            }
                                            Entity.SaveChanges();
                                        }
                                        if (runType == "PayOk")
                                        {
                                            OC.PayState = 2;
                                            OC.FState   = 1;
                                            OC.FTime    = DateTime.Now;
                                            p.State     = 3;//标识成功
                                            p.OState    = 2;
                                            p.NState    = 1;
                                            p.ETime     = DateTime.Now;
                                            Entity.SaveChanges();
                                            OC = OC.PayAgent(Entity, 1);//======分润======
                                            Orders O = Entity.Orders.FirstOrDefault(n => n.TNum == p.OId);
                                            if (O != null)
                                            {
                                                O.PayState    = 2;
                                                O.AgentPayGet = (decimal)OC.AgentCashGet;
                                                Entity.SaveChanges();
                                            }
                                        }
                                        Log.WriteLog("执行提现:" + p.OId, JobName);
                                        Thread.Sleep(1000);
                                        #endregion
                                    }
                                }
                                else
                                {
                                    p.Remark = "订单状态不符,需查单!";
                                    p.ETime  = DateTime.Now;
                                    p.State  = 5;//标识 未知状态
                                    Entity.SaveChanges();
                                }
                            }
                            //当前任务所有子项执行完成
                            int state1 = Entity.TaskCashInfo.Count(n => n.State == 1 && n.TId == P.Id);
                            int state2 = Entity.TaskCashInfo.Count(n => n.State == 2 && n.TId == P.Id);
                            int state3 = Entity.TaskCashInfo.Count(n => n.State == 3 && n.TId == P.Id);
                            int state4 = Entity.TaskCashInfo.Count(n => n.State == 4 && n.TId == P.Id);
                            int state5 = Entity.TaskCashInfo.Count(n => n.State == 5 && n.TId == P.Id);
                            if (state1 == 0 && state2 == 0)
                            {
                                P.State = 3;
                                P.ETime = DateTime.Now;
                            }
                            P.Success = state3 + state5;
                            P.Fail    = state4;
                            Entity.SaveChanges();
                            Log.WriteLog("TaskCashInfo任务执行完毕!共计" + TaskCashInfoList.Count + "笔交易", JobName);
                        }
                        Log.WriteLog("TaskCash任务执行完毕!共计" + TaskCashList.Count + "个任务", JobName);
                        #endregion
                        //-------------------------------------------------------
                        Log.Write(JobName + "任务执行结算!");
                    }
                    catch (Exception Ex)
                    {
                        Log.Write(JobName + "任务执行过程出错!", Ex);
                    }
                    IsRun = false;
                }
                else
                {
                    Log.Write(JobName + "任务还在执行中!");
                }
            }
        }
Пример #14
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("[Orders]:", "【Data】" + Data, Ex);
            }
            if (json == null)
            {
                DataObj.OutError("1000");
                return;
            }
            //System.Threading.Thread.Sleep(1000 * 150);
            Orders Orders = new Orders();

            Orders = JsonToObject.ConvertJsonToModel(Orders, json);

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

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

            Orders = Entity.Orders.FirstOrDefault(n => n.TNum == Orders.TNum && (n.UId == baseUsers.Id || (n.RUId == baseUsers.Id && n.PayState == 1)));
            if (Orders == null)//不存在
            {
                DataObj.OutError("1001");
                return;
            }
            if (Orders.RUId == baseUsers.Id)
            {
                Orders.TType = 4;
            }
            Orders.DoRemark(Entity);

            Orders.StateTxt = Orders.GetState();
            Orders.Cols    += ",Json,PicList,UserCardName,CardUpdateTime";
            Orders.DoRemark(Entity);
            Orders.Colour = Orders.GeStateColour();
            IList <OrdersModel> OML         = Utils.GetOrdersModel();
            OrdersModel         OrdersModel = OML.FirstOrNew(n => n.Id == Orders.TType);

            Orders.Otypename   = OrdersModel.Name;
            Orders.LagEntryDay = (byte)(Orders.TrunType.HasValue && Orders.TrunType.Value != 0 ? Orders.TrunType.Value : Orders.LagEntryDay);

            if (Orders.IdCardState > 1)
            {
                Orders.Remark = Orders.DDAuditRemark;
            }
            if (!Orders.UserCardPic.IsNullOrEmpty())
            {
                var UserCardPicList = Orders.UserCardPic.Split(',').ToList();
                for (int i = 0; i < UserCardPicList.Count; i++)
                {
                    var a = Utils.ImageUrl("Orders", UserCardPicList[i], AppImgPath);
                    UserCardPicList[i] = a;
                }
                JavaScriptSerializer JSS = new JavaScriptSerializer();
                string data = JSS.Serialize(UserCardPicList);
                JArray JO   = (JArray)JsonConvert.DeserializeObject(data);
                Orders.PicList = JO;
            }

            JObject JS = new JObject();

            if (Orders.TType == 1)
            { //银联卡支付
                OrderRecharge OrderRecharge = Entity.OrderRecharge.FirstOrNew(n => n.OId == Orders.TNum);
                OrderRecharge.Cols = "Amoney,PayMoney,Poundage,PayType";
                string JsStr = OrderRecharge.OutJson();
                try
                {
                    JS = (JObject)JsonConvert.DeserializeObject(JsStr);
                }
                catch (Exception Ex)
                {
                    Log.Write("[Order]:", "【JsStr】" + JsStr, Ex);
                }
                Orders.Json = JS;
            }
            if (Orders.TType == 2)//提现不能取消
            {
                OrderCash OrderCash = Entity.OrderCash.FirstOrNew(n => n.OId == Orders.TNum);
                OrderCash.Cols     = "Owner,Bank,CardNum,Deposit,Mobile,Province,City,District,Amoney,UserRate,TrunType,PayMoney";
                OrderCash.PayMoney = OrderCash.Amoney - (decimal)OrderCash.UserRate;
                string JsStr = OrderCash.OutJson();
                try
                {
                    JS = (JObject)JsonConvert.DeserializeObject(JsStr);
                }
                catch (Exception Ex)
                {
                    Log.Write("[Order]:", "【JsStr】" + JsStr, Ex);
                }
                Orders.Json = JS;
            }
            if (Orders.TType == 3 || Orders.TType == 4)//付款
            {
                OrderTransfer OrderTransfer = Entity.OrderTransfer.FirstOrNew(n => n.OId == Orders.TNum);
                Users         Users         = new Users();
                if (Orders.TType == 4)
                {
                    Users = Entity.Users.FirstOrNew(n => n.Id == OrderTransfer.UId);
                }
                if (Orders.TType == 3)
                {
                    Users = Entity.Users.FirstOrNew(n => n.Id == OrderTransfer.RUId);
                }
                OrderTransfer.Mobile     = Users.UserName;
                OrderTransfer.ToUserName = Users.TrueName;
                OrderTransfer.Cols       = "UId,RUId,PayMoney,Poundage,Amoney,Mobile,ToUserName";
                string JsStr = OrderTransfer.OutJson();
                try
                {
                    JS = (JObject)JsonConvert.DeserializeObject(JsStr);
                }
                catch (Exception Ex)
                {
                    Log.Write("[Order]:", "【JsStr】" + JsStr, Ex);
                }
                Orders.Json = JS;
            }
            if (Orders.TType == 5)//防租
            {
                OrderHouse OrderHouse = Entity.OrderHouse.FirstOrNew(n => n.OId == Orders.TNum);
                OrderHouse.Cols = "HouseOwner,Bank,CardNum,Deposit,Mobile,MonthRent,SecurityMoney,PayMonth,Poundage,Amoney";
                string JsStr = OrderHouse.OutJson();
                try
                {
                    JS = (JObject)JsonConvert.DeserializeObject(JsStr);
                }
                catch (Exception Ex)
                {
                    Log.Write("[Order]:", "【JsStr】" + JsStr, Ex);
                }
                Orders.Json = JS;
            }
            if (Orders.TType == 6)
            { //升级
                //PayConfigOrder PayConfigOrder = Entity.PayConfigOrder.FirstOrNew(n => n.OId == Orders.TNum);
                //Out = Out + "," + PayConfigOrder.ToStr();
                Orders.Poundage = 0;
            }
            if (Orders.TType == 7 || Orders.TType == 8 || Orders.TType == 9)
            { //扫码
                OrderF2F OrderF2F = Entity.OrderF2F.FirstOrNew(n => n.OId == Orders.TNum);
                OrderF2F.Cols = "Amoney,PayMoney,Poundage";
                string JsStr = OrderF2F.OutJson();
                try
                {
                    JS = (JObject)JsonConvert.DeserializeObject(JsStr);
                }
                catch (Exception Ex)
                {
                    Log.Write("[Order]:", "【JsStr】" + JsStr, Ex);
                }
                Orders.Json = JS;
            }
            if (Orders.TType == 10)
            { //代理
            }

            String Out = Orders.ToStr();

            Out          = "{" + Out + "}";
            DataObj.Data = Out;
            DataObj.Code = "0000";
            DataObj.OutString();
        }
        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("[OrderCash]:", "【Data】" + Data, Ex);
            }
            if (json == null)
            {
                DataObj.OutError("1000");
                return;
            }
            //System.Threading.Thread.Sleep(60000 * 60 * 24);
            OrderCash OrderCash = new OrderCash();

            OrderCash = JsonToObject.ConvertJsonToModel(OrderCash, json);

            UserTrack UserTrack = new UserTrack();

            UserTrack = JsonToObject.ConvertJsonToModel(UserTrack, json);

            if (OrderCash.TrunType.IsNullOrEmpty())
            {
                OrderCash.TrunType = 0;
            }
            if (OrderCash.TrunType != 0)
            {
                OrderCash.TrunType = 1;
            }

            string Tag = "Cash";

            if (OrderCash.TrunType == 0)
            {
                Tag = "CashT0";
            }
            if (OrderCash.TrunType == 1)
            {
                Tag = "CashT1";
            }
            SysControl SysControl = Entity.SysControl.FirstOrDefault(n => n.Tag == Tag);
            SysControl syscontrol = SysControl.ChkState();

            if (syscontrol.State != 1)
            {
                DataObj.OutError("1005");
                return;
            }

            if (OrderCash.PayPwd.IsNullOrEmpty())
            {
                DataObj.OutError("1000");
                return;
            }
            if (OrderCash.PayPwd.Length < 6)//6位及以上
            {
                DataObj.OutError("1000");
                return;
            }
            //获取用户信息
            Users baseUsers = Entity.Users.FirstOrDefault(n => n.Token == OrderCash.Token);

            if (baseUsers == null)//用户令牌不存在
            {
                DataObj.OutError("2004");
                return;
            }
            if (baseUsers.State != 1)//用户被锁定
            {
                DataObj.OutError("2003");
                return;
            }
            if (baseUsers.CardStae != 2)//未实名认证
            {
                DataObj.OutError("2006");
                return;
            }
            if (baseUsers.MiBao != 1)//未设置支付密码
            {
                DataObj.OutError("2008");
                return;
            }
            if (baseUsers.PayLock == 1)//密码错误太多次锁定
            {
                DataObj.OutError("2050");
                return;
            }
            if (baseUsers.StopPayState == 2)//禁止支付
            {
                DataObj.OutError("6060");
                return;
            }

            //获取系统配置
            SysSet SysSet = Entity.SysSet.FirstOrDefault();

            //这里是执行指纹解锁
            bool IfCheckOk = true;

            if (OrderCash.PayPwd.Substring(0, 3) == "HF_")
            {
                string PassWord = OrderCash.PayPwd;
                PassWord = PassWord.Replace("HF_", "");
                string Token = baseUsers.Token;
                Token = Token + "GoodPay";
                string Md5Token = Token.GetMD5().ToUpper();
                string Pass     = Md5Token.Substring(0, 4) + Md5Token.Substring(Md5Token.Length - 4, 4);
                if (Pass != PassWord)
                {
                    IfCheckOk = false;
                }
            }
            else if (baseUsers.PayPwd != OrderCash.PayPwd.GetPayMD5())
            {
                //原支付密码错误
                IfCheckOk = false;
            }
            if (!IfCheckOk)
            {
                //付密码错误
                baseUsers.PayErr++;
                if (baseUsers.PayErr >= SysSet.PayLock)
                {
                    baseUsers.PayLock = 1;
                }
                Entity.SaveChanges();
                Users Out = new Users();
                Out.PayErr   = SysSet.PayLock - baseUsers.PayErr;
                Out.Cols     = "PayErr";
                DataObj.Data = Out.OutJson();
                //DataObj.Code = "2010";
                DataObj.Code = "2002";
                if (Out.PayErr == 0)
                {
                    DataObj.Msg = "用户支付密码不正确,请明日再试或取回支付密码";
                }
                else
                {
                    DataObj.Msg = "用户支付密码不正确,您还可以尝试" + Out.PayErr + "次";
                }
                DataObj.OutString();
                return;
            }

            baseUsers.PayErr = 0;
            Entity.SaveChanges();

            //开始处理参数
            if (OrderCash.Amoney.IsNullOrEmpty())
            {
                DataObj.OutError("1000");
                return;
            }
            OrderCash.Amoney = OrderCash.Amoney.FormatMoney();
            //提现金额大于余额
            if (OrderCash.Amoney > baseUsers.Amount)
            {
                DataObj.OutError("6001");
                return;
            }
            //冻结金额小于0不能提现
            if (baseUsers.Frozen < 0)
            {
                DataObj.OutError("6001");
                return;
            }
            if (OrderCash.X.IsNullOrEmpty() || OrderCash.Y.IsNullOrEmpty())
            {
                DataObj.OutError("1000");
                return;
            }
            if (OrderCash.Owner.IsNullOrEmpty() || OrderCash.Bank.IsNullOrEmpty() || OrderCash.CardNum.IsNullOrEmpty() || OrderCash.Deposit.IsNullOrEmpty() || OrderCash.Mobile.IsNullOrEmpty())
            {
                DataObj.OutError("1000");
                return;
            }
            UserBlackList UserBlackList = Entity.UserBlackList.FirstOrDefault(UBL => UBL.CardNumber == OrderCash.CardNum && UBL.State == 3);

            if (UserBlackList != null)
            {
                //提示暂不支持该卡提现
                DataObj.OutError("2017");
                return;
            }
            //获取分支机构信息
            SysAgent SysAgent = new SysAgent();

            if (!baseUsers.Agent.IsNullOrEmpty())
            {
                SysAgent = Entity.SysAgent.FirstOrNew(n => n.Id == baseUsers.Agent);
            }
            if (SysAgent.Id.IsNullOrEmpty())
            {
                SysAgent.Cash0Times = 0;
                SysAgent.Cash1Times = 0;
            }

            decimal Peier = 0;

            if (OrderCash.TrunType == 0)
            {
                if (baseUsers.HasT0 != 1)
                {
                    //T0黑名单
                    DataObj.OutError("6020");
                    return;
                }

                //验证是否满足T0
                int     Day        = (DateTime.Now - baseUsers.AddTime).Days;
                int     OrderCount = Entity.Orders.Count(n => (n.TType == 2 || n.TType == 5) && n.PayState == 2 && n.UId == baseUsers.Id);
                decimal?OrderMoney = Entity.Orders.Where(n => (n.TType == 2 || n.TType == 5) && n.PayState == 2 && n.UId == baseUsers.Id).Sum(n => (decimal?)n.Amoney);
                if (OrderMoney.IsNullOrEmpty())
                {
                    OrderMoney = 0;
                }
                if (Day >= SysSet.CashDay && OrderCount >= SysSet.CashNum && OrderMoney >= SysSet.CashMoney)
                {
                }
                else
                {
                    DataObj.OutError("6020");
                    return;
                }
                //验证是否在快速提现时段内
                TaskTimeSet TaskTimeSet = Entity.TaskTimeSet.FirstOrDefault(n => n.STime <= DateTime.Now && n.ETime >= DateTime.Now && n.TId == 1);
                if (TaskTimeSet == null)
                {
                    DataObj.OutError("6018");
                    return;
                }
                Peier = TaskTimeSet.AllMoney - TaskTimeSet.UsedMoney;
            }

            OrderCash.UId = baseUsers.Id;
            if (OrderCash.TrunType == 0)//加急提现
            {
                if (baseUsers.T0Times < SysAgent.Cash0Times)
                {
                    //用户提现服务费
                    OrderCash.UserRate = 0;
                    //加急费用
                    OrderCash.Cash = 0;
                    //提现服务费
                    OrderCash.ECash = 0;
                }
                else
                {
                    //用户提现服务费=提现金额*加急费率+提现服务费
                    OrderCash.UserRate = (double)(OrderCash.Amoney * baseUsers.Cash0 + baseUsers.ECash0);
                    //提现服务费进位
                    OrderCash.UserRate = OrderCash.UserRate.Ceiling();
                    //加急费用
                    OrderCash.Cash = baseUsers.Cash0;
                    //提现服务费
                    OrderCash.ECash = baseUsers.ECash0;
                }
                //系统提现费成本
                OrderCash.CashRate = OrderCash.Amoney * SysSet.SysCash0 + SysSet.SysECash0;
                //系统手续费进位
                OrderCash.CashRate = OrderCash.CashRate.Ceiling();

                //这里是利润计算==========
                //代理商分润
                double GetAgent = OrderCash.UserRate - (double)(OrderCash.Amoney * SysSet.AgentCash0 + SysSet.AgentECash0);
                if (GetAgent < 0)
                {
                    GetAgent = 0;
                }
                //利润=收取用户手续费-系统支出手续费
                double GetAll = OrderCash.UserRate - (double)OrderCash.CashRate - GetAgent;
                //利润舍位
                GetAll = GetAll.Floor();
                //总利润
                OrderCash.AIdCashGet = (double)GetAll;
                //分支机构佣金设置为0,待分润计算后再写入
                OrderCash.AgentCashGet = GetAgent;
            }
            else
            {
                if (baseUsers.T1Times < SysAgent.Cash1Times)
                {
                    //用户提现服务费
                    OrderCash.UserRate = 0;
                    //加急费用
                    OrderCash.Cash = 0;
                    //提现服务费
                    OrderCash.ECash = 0;
                }
                else
                {
                    //用户提现服务费=提现金额*加急费率+提现服务费
                    OrderCash.UserRate = (double)(OrderCash.Amoney * baseUsers.Cash1 + baseUsers.ECash1);
                    //提现服务费进位
                    OrderCash.UserRate = OrderCash.UserRate.Ceiling();
                    //加急费用
                    OrderCash.Cash = baseUsers.Cash1;
                    //提现服务费
                    OrderCash.ECash = baseUsers.ECash1;
                }

                //系统提现费成本
                OrderCash.CashRate = OrderCash.Amoney * SysSet.SysCash1 + SysSet.SysECash1;
                //系统手续费进位
                OrderCash.CashRate = OrderCash.CashRate.Ceiling();

                //这里是利润计算==========
                //代理商分润
                double GetAgent = OrderCash.UserRate - (double)(OrderCash.Amoney * SysSet.AgentCash1 + SysSet.AgentECash1);
                if (GetAgent < 0)
                {
                    GetAgent = 0;
                }
                //利润=收取用户手续费-系统支出手续费
                double GetAll = OrderCash.UserRate - (double)OrderCash.CashRate - GetAgent;
                //利润舍位
                GetAll = GetAll.Floor();
                //总利润
                OrderCash.AIdCashGet = (double)GetAll;
                //分支机构佣金
                OrderCash.AgentCashGet = GetAgent;
            }
            decimal Money = OrderCash.Amoney - (decimal)OrderCash.UserRate;

            if (Money < 0)
            {
                DataObj.OutError("1006");
                return;
            }
            if (OrderCash.TrunType == 0)//T0时才验证
            {
                //付款金额

                //验证是否配额充足
                if (Peier < Money)
                {
                    DataObj.OutError("6019");
                    return;
                }
            }

            OrderCash.Agent      = SysAgent.Id;//分支机构Id
            OrderCash.AId        = baseUsers.AId;
            OrderCash.FId        = 0;
            OrderCash.OrderState = 1;
            OrderCash.PayState   = 1;
            OrderCash.AgentState = 0;
            OrderCash.FState     = 0;
            OrderCash.AddTime    = DateTime.Now;

            //写入前,判断交易金额限制
            if (OrderCash.Amoney < syscontrol.SNum || OrderCash.Amoney > syscontrol.ENum)
            {
                DataObj.OutError("1006");
                return;
            }
            //写入订单总表
            Orders Orders = new Orders();

            Orders.UId   = OrderCash.UId;
            Orders.TName = baseUsers.TrueName;

            Orders.PayType = 0;
            Orders.PayName = "提现";

            Orders.RUId     = 0;
            Orders.RName    = string.Empty;
            Orders.TType    = 2;
            Orders.TState   = 1;
            Orders.Amoney   = OrderCash.Amoney;
            Orders.Poundage = (decimal)OrderCash.UserRate;
            Orders.AddTime  = DateTime.Now;
            Orders.PayState = 1;//提现为余额支付的一种特殊形式。
            Orders.PayWay   = 4;
            Orders.PayTime  = DateTime.Now;

            Orders.Agent      = OrderCash.Agent;
            Orders.AgentState = 0;
            Orders.AId        = OrderCash.AId;
            Orders.FId        = 0;

            Orders.UserCardId = baseUsers.CardId;

            string OrderAddress = OrderCash.OrderAddress;

            if (OrderAddress.IsNullOrEmpty())
            {
                OrderAddress = Utils.GetAddressByGPS(OrderCash.X, OrderCash.Y);
            }
            Orders.OrderAddress = OrderAddress;
            Orders.X            = OrderCash.X;
            Orders.Y            = OrderCash.Y;

            Orders.TrunType = OrderCash.TrunType;

            Entity.Orders.AddObject(Orders);
            Entity.SaveChanges();
            Entity.Refresh(RefreshMode.StoreWins, Orders);

            OrderCash.OId = Orders.TNum;

            Entity.OrderCash.AddObject(OrderCash);
            Entity.SaveChanges();

            //帐户变动记录
            int     USERSID  = baseUsers.Id;
            string  TNUM     = OrderCash.OId;
            decimal PAYMONEY = Orders.Amoney;
            string  SP_Ret   = Entity.SP_UsersMoney(USERSID, TNUM, PAYMONEY, 3, "");

            if (SP_Ret != "3")
            {
                Utils.WriteLog(string.Format("U{0},O{1},T{2}:{3}【{4}】", USERSID, TNUM, 3, PAYMONEY, SP_Ret), "SP_UsersMoney");
                Orders.TState        = 0;
                Orders.PayState      = 0;
                OrderCash.OrderState = 0;
                OrderCash.PayState   = 0;
                Entity.SaveChanges();
                DataObj.OutError("8888");
                return;
            }

            if (OrderCash.TrunType == 0)//T0时减少配额
            {
                DateTime    Today       = DateTime.Parse(DateTime.Now.ToString("yyyy-MM-dd"));
                TaskTimeSet TaskTimeSet = Entity.TaskTimeSet.FirstOrDefault(n => n.ODate == Today);
                if (TaskTimeSet != null)
                {
                    TaskTimeSet.UsedMoney += Money;
                    Entity.SaveChanges();
                }
                baseUsers.T0Times = baseUsers.T0Times + 1;
            }
            else
            {
                baseUsers.T1Times = baseUsers.T1Times + 1;
            }
            if (SysSet.CashChecked == 1)
            {
                bool IsAuto = true;
                if (SysSet.EveryDayMaxCash > 0)//超出规定额度,变成人工审核。规定是0刚不执行
                {
                    DateTime Today      = DateTime.Parse(DateTime.Now.ToString("yyyy-MM-dd"));
                    var      todaymoney = this.Entity.OrderCash.Where(o => (o.OrderState == 2 || o.OrderState == 1) && o.AddTime > Today && (o.PayState == 1 || o.PayState == 2) && o.UId == baseUsers.Id).Sum(o => (decimal?)o.Amoney) ?? 0m;
                    if (todaymoney > SysSet.EveryDayMaxCash)//当天累加提现 > 规定额度
                    {
                        IsAuto = false;
                    }
                }
                if (IsAuto)
                {
                    //帐户变动记录
                    string SP_Ret2 = Entity.SP_UsersMoney(USERSID, TNUM, PAYMONEY, 4, "");
                    if (SP_Ret2 != "3")
                    {
                        Utils.WriteLog(string.Format("U{0},O{1},T{2}:{3}【{4}】", USERSID, TNUM, 4, PAYMONEY, SP_Ret2), "SP_UsersMoney");
                        DataObj.OutError("8888");
                        return;
                    }
                    else
                    {
                        //自动审核
                        Orders.TState        = 2;
                        OrderCash.OrderState = 2;
                        OrderCash.AuditTime  = DateTime.Now;
                        Entity.SaveChanges();
                    }
                    if (SysSet.CashPayWay == 1)      //开启自动结算时执行
                    {
                        if (OrderCash.TrunType == 0) //T0时自动出款
                        {
                            if (OrderCash.Amoney <= SysSet.QCash0)
                            {
                                Utils.WriteLog("[S]" + Orders.TNum, "CashAuto");
                                OrderCash.PayCash(Orders, Entity);//去付款
                                Utils.WriteLog("[E]" + Orders.TNum, "CashAuto");
                            }
                            else
                            {
                                Utils.WriteLog("结算金额超出自动出款金额" + OrderCash.OId + ":提现金额[" + OrderCash.Amoney + "]自动出款金额[" + SysSet.QCash0 + "]", "OrderCash");
                            }
                        }
                        //else
                        //{
                        //    Utils.WriteLog("T0时自动出款没开启" + OrderCash.OId, "OrderCash");
                        //}
                    }
                    else
                    {
                        Utils.WriteLog("自动结算没开启" + OrderCash.OId, "OrderCash");
                    }
                }
                else
                {
                    Utils.WriteLog("单卡超过限定金额" + OrderCash.OId, "OrderCash");
                }
            }
            else
            {
                Utils.WriteLog("自动审核没开启" + OrderCash.OId, "OrderCash");
            }
            Entity.Refresh(RefreshMode.StoreWins, Orders);
            //=======================================
            UserTrack.ENo        = DataObj.ENo;
            UserTrack.OPType     = Orders.PayName;
            UserTrack.UserName   = Orders.TNum;
            UserTrack.GPSAddress = Orders.OrderAddress;
            UserTrack.GPSX       = Orders.X;
            UserTrack.GPSY       = Orders.Y;
            Orders.SeavGPSLog(UserTrack, Entity);
            //=======================================

            Orders.SendMsg(Entity);//发送消息类

            if (Orders.PayState == 3 && Orders.Remark == "本银行卡今日提交超过限额!")
            {
                DataObj.OutError("1016");
                return;
            }
            //超过单日单卡(10W)到账限额
            DataObj.Data = Orders.OutJson();
            DataObj.Code = "0000";
            DataObj.OutString();
        }
Пример #16
0
        public void XLSDo(Orders Orders, EFPagingInfo <Orders> p, bool?IsShowSupAgent, int TimeType = 1)
        {
            if (IsShowSupAgent == null)
            {
                IsShowSupAgent = false;
            }
            p = this.Condition(Orders, p, IsShowSupAgent, TimeType);

            p.PageSize = 99999999;
            p.OrderByList.Add("Id", "DESC");
            IPageOfItems <Orders> OrdersList = Entity.Selects <Orders>(p);

            if (OrdersList.Count() > 0)
            {
                #region 导出
                string       file    = Server.MapPath("/template") + "\\finorders.xlsx";
                ExcelPackage package = new ExcelPackage(new FileInfo(file), true);
                var          sheet   = package.Workbook.Worksheets[1];
                var          cells   = sheet.Cells;
                int          Rows    = OrdersList.Count();
                //设置数据开始行
                int Befor = 2;
                sheet.InsertRow(Befor + 1, Rows - 1, Befor);
                int i = Befor;
                sheet.Row(i - 1).Height = 22;//设置行高
                int maxCol = 0;
                //获取机构及管理员
                IList <Orders> List = OrdersList.GroupBy(n => n.UId).Select(n => n.First()).ToList();
                List <int>     UId  = new List <int>();
                foreach (var pp in List)
                {
                    UId.Add(pp.UId);
                }
                IList <Users>     UsersList     = Entity.Users.Where(n => n.State == 1 && UId.Contains(n.Id)).ToList();
                IList <PayConfig> PayConfigList = Entity.PayConfig.Where(n => n.State == 1).ToList();
                IList <SysAgent>  SysAgentList  = Entity.SysAgent.ToList();
                foreach (var item in OrdersList)
                {
                    #region MyRegion
                    string AName = "--";
                    if (item.AId > 0)
                    {
                        SysAgent SA = SysAgentList.FirstOrNew(n => n.Id == item.Agent);
                        if (!SA.Name.IsNullOrEmpty())
                        {
                            AName = SA.Name;
                        }
                    }
                    string BName = "--";
                    Users  OU    = UsersList.FirstOrNew(n => n.Id == item.UId);
                    if (!OU.TrueName.IsNullOrEmpty())
                    {
                        BName = OU.TrueName;
                    }
                    PayConfig PayConfig = PayConfigList.FirstOrNew(n => n.Id == item.PayWay);
                    sheet.Row(i).Height = 22;//设置行高
                    //机构
                    cells["A" + i].Value = AName;
                    //交易号
                    cells["B" + i].Value = item.TNum;
                    //交易商户
                    cells["C" + i].Value = OU.NeekName + "[" + OU.TrueName + "]";
                    //交易类型
                    cells["D" + i].Value = item.GetTTName();
                    //交易内容
                    cells["E" + i].Value = item.GetPayNameWithTName();
                    //交易金额
                    cells["F" + i].Value = item.Amoney.ToString("f2");
                    //交易时间
                    cells["G" + i].Value = item.PayTime;
                    //入账时间
                    cells["H" + i].Value = (item.InTimed != null?Convert.ToDateTime(item.InTimed).ToString():"");
                    //支付方式
                    cells["I" + i].Value = PayConfig.Name;
                    //订单状态
                    cells["J" + i].Value = item.GetState();
                    string temp = string.Empty;
                    if (item.TType == 2 || item.TType == 5)
                    {
                        temp = "T+" + item.TrunType;
                    }
                    if (item.TType == 1 || item.TType == 7 || item.TType == 8 || item.TType == 9)
                    {
                        temp = "T+" + item.LagEntryDay;
                    }
                    //接收方式
                    cells["K" + i].Value = temp;
                    double  I = 0, K = 0, N = 0;
                    decimal J = 0, L = 0, M = 0;
                    string  Is = "";
                    #region MyRegion
                    if (item.TType == 1)
                    {                                                                                                                            //银联卡支付订单
                        OrderRecharge OrderRecharge = Entity.OrderRecharge.FirstOrNew(n => n.OId == item.TNum);
                        I = OrderRecharge.UserRate;                                                                                              //商户费率
                        J = OrderRecharge.Poundage;                                                                                              //手续费
                        K = OrderRecharge.SysRate;                                                                                               //第三方费率
                        L = ((decimal)OrderRecharge.SysRate * OrderRecharge.Amoney).Ceiling();                                                   //第三方手续费
                        N = OrderRecharge.AgentPayGet;                                                                                           //分支机构提成
                        M = OrderRecharge.Poundage - (decimal)OrderRecharge.SysRate * OrderRecharge.Amoney - (decimal)OrderRecharge.AgentPayGet; //利润
                    }
                    if (item.TType == 2)
                    { //提现订单
                        OrderCash OrderCash = Entity.OrderCash.FirstOrNew(n => n.OId == item.TNum);
                        I = 0;
                        if (!OrderCash.ECash.IsNullOrEmpty() && !OrderCash.Cash.IsNullOrEmpty())
                        {
                            Is = OrderCash.ECash.ToMoney() + "+" + (OrderCash.Cash * 100).ToString("F2") + "%";
                        }
                        else if (!OrderCash.ECash.IsNullOrEmpty())
                        {
                            Is = OrderCash.ECash.ToMoney();
                        }
                        else if (!OrderCash.Cash.IsNullOrEmpty())
                        {
                            Is = (OrderCash.Cash * 100).ToString("F2") + "%";
                        }
                        else
                        {
                            Is = "0";
                        }
                        J = (decimal)OrderCash.UserRate;                                                        //手续费
                        K = 0;                                                                                  //第三方费率
                        L = OrderCash.CashRate;                                                                 //第三方手续费
                        N = OrderCash.AgentCashGet;                                                             //分支机构提成
                        M = (decimal)OrderCash.UserRate - OrderCash.CashRate - (decimal)OrderCash.AgentCashGet; //利润
                    }
                    if (item.TType == 3)
                    {                                                                                               //转帐订单
                        OrderTransfer OrderTransfer = Entity.OrderTransfer.FirstOrNew(n => n.OId == item.TNum);
                        I = OrderTransfer.UserRate;                                                                 //商户费率
                        J = OrderTransfer.Poundage;                                                                 //手续费
                        K = OrderTransfer.SysRate;                                                                  //第三方费率
                        L = ((decimal)OrderTransfer.SysRate * OrderTransfer.Amoney).Ceiling();                      //第三方手续费
                        N = OrderTransfer.AgentPayGet;                                                              //分支机构提成
                        M = OrderTransfer.Amoney - OrderTransfer.PayMoney - L - (decimal)OrderTransfer.AgentPayGet; //利润
                    }
                    if (item.TType == 5)
                    {                                                                                      //付房租订单
                        OrderHouse OrderHouse = Entity.OrderHouse.FirstOrNew(n => n.OId == item.TNum);
                        I = OrderHouse.UserRate + (double)OrderHouse.CashRate;                             //商户费率
                        J = OrderHouse.Poundage;                                                           //手续费
                        K = OrderHouse.SysRate;                                                            //第三方费率
                        L = ((decimal)OrderHouse.SysRate * OrderHouse.Amoney).Ceiling();                   //第三方手续费
                        N = OrderHouse.AgentPayGet;                                                        //分支机构提成
                        M = OrderHouse.Amoney - OrderHouse.PayMoney - L - (decimal)OrderHouse.AgentPayGet; //利润
                    }
                    if (item.TType == 6)
                    {                                                                            //升级订单
                        PayConfigOrder PayConfigOrder = Entity.PayConfigOrder.FirstOrNew(n => n.OId == item.TNum);
                        I = 0;                                                                   //商户费率
                        J = PayConfigOrder.Poundage;                                             //手续费
                        K = PayConfigOrder.SysRate;                                              //第三方费率
                        L = ((decimal)PayConfigOrder.SysRate * PayConfigOrder.Amoney).Ceiling(); //第三方手续费
                        N = PayConfigOrder.AgentGet;                                             //分支机构提成
                        M = PayConfigOrder.Amoney - (decimal)PayConfigOrder.AgentGet;            //利润
                    }
                    if (item.TType == 7 || item.TType == 8 || item.TType == 9)
                    {                                                                                                        //当面付
                        OrderF2F OrderF2F = Entity.OrderF2F.FirstOrNew(n => n.OId == item.TNum);
                        I = OrderF2F.UserRate;                                                                               //商户费率
                        J = OrderF2F.Poundage;                                                                               //手续费
                        K = OrderF2F.SysRate;                                                                                //第三方费率
                        L = ((decimal)OrderF2F.SysRate * OrderF2F.Amoney).Ceiling();                                         //第三方手续费
                        N = OrderF2F.AgentPayGet;                                                                            //分支机构提成
                        M = OrderF2F.Poundage - (decimal)OrderF2F.SysRate * OrderF2F.Amoney - (decimal)OrderF2F.AgentPayGet; //利润
                    }
                    if (item.TType == 10)
                    {                                                         //升级订单
                        DaiLiOrder DaiLiOrder = Entity.DaiLiOrder.FirstOrNew(n => n.OId == item.TNum);
                        I = 0;                                                //商户费率
                        J = 0;                                                //手续费
                        K = 0;                                                //第三方费率
                        L = 0;                                                //第三方手续费
                        N = DaiLiOrder.AgentGet;                              //分支机构提成
                        M = DaiLiOrder.Amoney - (decimal)DaiLiOrder.AgentGet; //利润
                    }
                    #endregion
                    //用户费率9
                    if (item.TType == 2)
                    {
                        cells["L" + i].Value = Is;
                    }
                    else
                    {
                        cells["L" + i].Value = I;
                    }
                    //用户手续费10
                    cells["M" + i].Value = J;
                    //支出费率11 系统费率
                    cells["N" + i].Value = K;
                    //支出手续费12
                    cells["O" + i].Value = L;
                    //利润13
                    cells["P" + i].Value = M;
                    //结算金额14
                    cells["Q" + i].Value = N;
                    i++;
                    #endregion
                }
                sheet.Row(i).Height = 40;//设置行高
                //交易总额
                cells["F" + i].Formula = "SUM(F" + Befor + ":F" + (i - 1) + ")";
                //用户手续费10
                cells["M" + i].Formula = "SUM(M" + Befor + ":M" + (i - 1) + ")";
                //支出手续费12
                cells["O" + i].Formula = "SUM(O" + Befor + ":O" + (i - 1) + ")";
                //利润13
                cells["P" + i].Formula = "SUM(P" + Befor + ":P" + (i - 1) + ")";
                //结算金额14
                cells["Q" + i].Formula = "SUM(Q" + Befor + ":Q" + (i - 1) + ")";

                i--;
                maxCol = 17;
                //cells["B" + (i + 2)].Value = DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss");
                sheet.Cells[Befor, 1, i, maxCol].Style.Border.Left.Style   = ExcelBorderStyle.Thin;
                sheet.Cells[Befor, 1, i, maxCol].Style.Border.Right.Style  = ExcelBorderStyle.Thin;
                sheet.Cells[Befor, 1, i, maxCol].Style.Border.Top.Style    = ExcelBorderStyle.Thin;
                sheet.Cells[Befor, 1, i, maxCol].Style.Border.Bottom.Style = ExcelBorderStyle.Thin;
                sheet.Cells[Befor, 1, i, maxCol].Style.HorizontalAlignment = ExcelHorizontalAlignment.Center;//居中
                sheet.Cells[Befor, 7, i, 7].Style.Numberformat.Format      = "yyyy-mm-dd HH:mm:ss";
                sheet.Cells[Befor, 8, i, 8].Style.Numberformat.Format      = "yyyy-mm-dd HH:mm:ss";
                sheet.Cells[Befor, 12, i, 12].Style.Numberformat.Format    = "#0.00%";
                sheet.Cells[Befor, 14, i, 14].Style.Numberformat.Format    = "#0.00%";
                i++;
                sheet.Cells[Befor, 6, i, 6].Style.Numberformat.Format   = "\"¥\"#,##0.00_);[Red](\"¥\"#,##0.00)";
                sheet.Cells[Befor, 13, i, 13].Style.Numberformat.Format = "\"¥\"#,##0.00_);[Red](\"¥\"#,##0.00)";
                sheet.Cells[Befor, 15, i, 15].Style.Numberformat.Format = "\"¥\"#,##0.00_);[Red](\"¥\"#,##0.00)";
                sheet.Cells[Befor, 16, i, 16].Style.Numberformat.Format = "\"¥\"#,##0.00_);[Red](\"¥\"#,##0.00)";
                sheet.Cells[Befor, 17, i, 17].Style.Numberformat.Format = "\"¥\"#,##0.00_);[Red](\"¥\"#,##0.00)";
                Response.BinaryWrite(package.GetAsByteArray());
                //输出
                Response.ContentType = "application/vnd.openxmlformats-officedocument.spreadsheetml.sheet";
                Response.AddHeader("content-disposition", "attachment;  filename=" + DateTime.Now.ToString("yyyyMMddHHmmss") + new Random().Next(10, 99) + ".xlsx");
                #endregion
            }
            else
            {
                Response.Write("暂无符合条件数据");
            }
        }
 private EFPagingInfo <OrderCash> Condition(OrderCash OrderCash, EFPagingInfo <OrderCash> p, bool?IsShowSupAgent, int IsFirst = 0, int TimeType = 1)
 {
     if (IsShowSupAgent == null)
     {
         IsShowSupAgent = false;
     }
     p.SqlWhere.Add(f => f.OrderState == 2);
     p.SqlWhere.Add(f => f.PayState == 3 || f.PayState == 4);
     //if (!OrderCash.UId.IsNullOrEmpty()) { p.SqlWhere.Add(f => f.UId == OrderCash.UId); }
     if (!OrderCash.Owner.IsNullOrEmpty())
     {
         IList <Users> UList = Entity.Users.Where(n => n.TrueName.Contains(OrderCash.Owner) || n.NeekName.Contains(OrderCash.Owner) || n.UserName == OrderCash.Owner).ToList();
         List <int>    UIds  = new List <int>();
         foreach (var pp in UList)
         {
             UIds.Add(pp.Id);
         }
         p.SqlWhere.Add(f => UIds.Contains(f.UId));
     }
     if (!OrderCash.OId.IsNullOrEmpty())
     {
         p.SqlWhere.Add(f => f.OId == OrderCash.OId);
     }
     if (!OrderCash.Agent.IsNullOrEmpty())
     {
         //是否要显示下级
         if ((bool)IsShowSupAgent)
         {
             SysAgent         LowerLevelAgent = Entity.SysAgent.Where(s => s.Id == OrderCash.Agent).FirstOrNew();
             IList <SysAgent> SysAgentList    = LowerLevelAgent.GetSupAgent(Entity);
             IList <int>      UID             = new List <int>();
             foreach (var s in SysAgentList)
             {
                 UID.Add(s.Id);
             }
             p.SqlWhere.Add(f => UID.Contains(f.Agent));
         }
         else
         {
             p.SqlWhere.Add(f => f.Agent == OrderCash.Agent);
         }
     }
     if (!OrderCash.PayState.IsNullOrEmpty())
     {
         p.SqlWhere.Add(f => f.PayState == OrderCash.PayState);
     }
     if (!OrderCash.AId.IsNullOrEmpty())
     {
         p.SqlWhere.Add(f => f.AId == OrderCash.AId);
     }
     if (!OrderCash.FId.IsNullOrEmpty())
     {
         p.SqlWhere.Add(f => f.FId == OrderCash.FId);
     }
     if (TimeType == 1)
     {
         if (!OrderCash.AddTime.IsNullOrEmpty() && !OrderCash.FTime.IsNullOrEmpty())
         {
             // DateTime FTime = ((DateTime)OrderCash.FTime).AddDays(1);
             DateTime FTime = OrderCash.FTime.Value.AddMilliseconds(999);
             p.SqlWhere.Add(f => f.AddTime > OrderCash.AddTime && f.AddTime < FTime);
         }
     }
     else
     {
         if (!OrderCash.AddTime.IsNullOrEmpty() && !OrderCash.FTime.IsNullOrEmpty())
         {
             DateTime FTime = OrderCash.FTime.Value.AddMilliseconds(999);
             p.SqlWhere.Add(f => f.RefundTime > OrderCash.AddTime && f.RefundTime < FTime);
         }
     }
     return(p);
 }
        /// <summary>
        /// 导出
        /// </summary>
        /// <param name="ApplyJoin"></param>
        /// <param name="p"></param>
        /// <param name="STime"></param>
        /// <param name="ETime"></param>
        /// <param name="IsShowSupAgent"></param>
        /// <returns></returns>
        public FileResult ExcelExport(OrderCash OrderCash, EFPagingInfo <OrderCash> p, bool?IsShowSupAgent, int IsFirst = 0, int TimeType = 1)
        {
            if (IsShowSupAgent == null)
            {
                IsShowSupAgent = false;
            }
            p = this.Condition(OrderCash, p, IsShowSupAgent, IsFirst, TimeType);

            p.PageSize = 99999999;
            p.OrderByList.Add("Id", "DESC");
            IPageOfItems <OrderCash> OrderCashList = Entity.Selects <OrderCash>(p);

            DataTable table = new DataTable();
            DataRow   row   = null;

            // 创建 datatable
            table.Columns.Add(new DataColumn("订单号", typeof(string)));
            table.Columns.Add(new DataColumn("添加时间", typeof(string)));
            table.Columns.Add(new DataColumn("实名认证", typeof(string)));
            table.Columns.Add(new DataColumn("开户名", typeof(string)));
            table.Columns.Add(new DataColumn("手机号码", typeof(string)));
            table.Columns.Add(new DataColumn("银行", typeof(string)));
            table.Columns.Add(new DataColumn("银行账号", typeof(string)));
            table.Columns.Add(new DataColumn("提现方式", typeof(string)));
            table.Columns.Add(new DataColumn("提现金额", typeof(string)));
            table.Columns.Add(new DataColumn("手续费率", typeof(string)));
            table.Columns.Add(new DataColumn("退款状态", typeof(string)));
            table.Columns.Add(new DataColumn("退款时间", typeof(string)));
            table.Columns.Add(new DataColumn("交易备注", typeof(string)));
            List <int> UId = new List <int>();

            foreach (var pp in OrderCashList)
            {
                UId.Add(pp.UId);
            }
            IList <Users> UsersList = Entity.Users.Where(n => n.State == 1 && UId.Contains(n.Id)).ToList();

            // 填充数据
            foreach (var item in OrderCashList)
            {
                Users Users = UsersList.FirstOrNew(n => n.Id == item.UId);
                row     = table.NewRow();
                row[0]  = item.OId;
                row[1]  = item.AddTime.ToString();
                row[2]  = Users.TrueName;
                row[3]  = item.Owner;
                row[4]  = item.Mobile;
                row[5]  = item.Deposit;
                row[6]  = item.CardNum;
                row[7]  = "T+" + item.TrunType;
                row[8]  = item.Amoney.ToString("F2");
                row[9]  = item.UserRate.ToString("F2");
                row[10] = (item.PayState == 3?"申请中":"已退款");
                row[11] = (item.RefundTime != null ? Convert.ToDateTime(item.RefundTime).ToString("yyyy-MM-dd HH:mm") : "");
                row[12] = item.Remark;
                table.Rows.Add(row);
            }
            string Time = DateTime.Now.ToString("yyyyMMddHHmmss") + new Random().Next(10, 99);

            return(this.ExportExcelBase(table, "提现退款审核-" + Time));
        }
        public void XLSDo(OrderCash OrderCash, EFPagingInfo <OrderCash> p, bool?IsShowSupAgent)
        {
            if (IsShowSupAgent == null)
            {
                IsShowSupAgent = false;
            }
            p          = this.Condition(OrderCash, p, IsShowSupAgent);
            p.PageSize = 99999999;
            p.OrderByList.Add("Id", "ASC");
            IPageOfItems <OrderCash> OrderCashList = Entity.Selects <OrderCash>(p);

            if (OrderCashList.Count() > 0)
            {
                //当前银行名称
                //string thisBankName = Entity.BasicBank.FirstOrNew(n => n.Id == OrderCash.Id).Name;
                //当前导出缩合表,民生跨行,工行,民生同行
                int    BankIdMS   = 13; //民生ID
                int    BankIdGS   = 1;  //工商Id
                string BankNameMS = Entity.BasicBank.FirstOrNew(n => n.Id == BankIdMS).Name;
                string BankNameGS = Entity.BasicBank.FirstOrNew(n => n.Id == BankIdGS).Name;
                //加载对应银行模板
                string       tempname = "bank.xlsx";
                string       file     = Server.MapPath("/template") + "\\" + tempname;
                ExcelPackage package  = new ExcelPackage(new FileInfo(file), true);
                //民生
                IList <OrderCash> ListMS = OrderCashList.Where(n => n.Bank == BankNameMS).ToList();
                //工商
                IList <OrderCash> ListGS = OrderCashList.Where(n => n.Bank == BankNameGS).ToList();
                //其它
                IList <OrderCash> ListOT = OrderCashList.Where(n => n.Bank != BankNameMS && n.Bank != BankNameGS).ToList();
                //设置数据开始行
                int Befor  = 0;
                int maxCol = 0;//最大列数
                if (ListOT.Count > 0)
                {
                    //加载模板第一张表
                    var     sheet      = package.Workbook.Worksheets[1];
                    var     cells      = sheet.Cells;
                    decimal TotalMoney = 0; //计算总金额
                    int     Rows       = ListOT.Count();
                    Befor = 5;              //民生他行从5开始
                    sheet.InsertRow(Befor + 1, Rows - 1, Befor);
                    int i = Befor;
                    //sheet.Row(i - 1).Height = 18;//设置行高
                    foreach (var item in ListOT)
                    {
                        string zdlx = "2";
                        //sheet.Row(i).Height = 18;//设置行高
                        decimal Money = item.Amoney - (decimal)item.UserRate;
                        TotalMoney += Money;
                        //制单类型
                        cells["A" + i].Value = zdlx.ToString();
                        //企业自制凭证号
                        cells["B" + i].Value = item.Id.ToString().PadLeft(8, '0');
                        //客户号
                        cells["C" + i].Value = "2200488356";
                        //预约标志
                        cells["D" + i].Value = "0";
                        //付款账号
                        cells["E" + i].Value = "613111800";
                        //交易金额
                        cells["F" + i].Value = Money;
                        //收款账号
                        cells["G" + i].Value = item.CardNum;
                        //收款人姓名
                        cells["H" + i].Value = item.Owner;
                        //收款账户类型
                        cells["I" + i].Value = "1";
                        //子客户号
                        cells["J" + i].Value = "";
                        //子付款账号
                        cells["K" + i].Value = "";
                        //子付款账户名
                        cells["L" + i].Value = "";
                        //子付款账户开户行名
                        cells["M" + i].Value = "";
                        //用途
                        cells["N" + i].Value = "提现";
                        //汇路
                        cells["O" + i].Value = Money > 50000 ? "7" : "6";
                        //是否通知收款人
                        cells["P" + i].Value = "0";
                        //手机
                        cells["Q" + i].Value = item.Mobile;
                        //邮箱
                        cells["R" + i].Value = "";
                        //支付行号&支付行名称
                        cells["S" + i].Value = item.Bin + "&" + item.Deposit;
                        maxCol = 19;
                        i++;
                    }
                    i--;
                    //审核方式(文件类型)
                    cells["B1"].Value = "1";
                    //总金额
                    cells["B2"].Value = TotalMoney.ToString("F2");
                    //总交易数
                    cells["B3"].Value = Rows.ToString();
                    sheet.Cells[Befor, 6, i, 6].Style.Numberformat.Format = "\"¥\"#,##0.00_);[Red](\"¥\"#,##0.00)";
                    //cells["B" + (i + 2)].Value = DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss");
                    //sheet.Cells[Befor, 1, i, maxCol].Style.Border.Left.Style = ExcelBorderStyle.Thin;
                    //sheet.Cells[Befor, 1, i, maxCol].Style.Border.Right.Style = ExcelBorderStyle.Thin;
                    //sheet.Cells[Befor, 1, i, maxCol].Style.Border.Top.Style = ExcelBorderStyle.Thin;
                    //sheet.Cells[Befor, 1, i, maxCol].Style.Border.Bottom.Style = ExcelBorderStyle.Thin;
                    //sheet.Cells[Befor, 1, i, maxCol].Style.HorizontalAlignment = ExcelHorizontalAlignment.Center;//居中
                    //sheet.Cells[Befor, 5, i, 5].Style.Numberformat.Format = "yyyy-mm-dd HH:mm:ss";
                    //for (int j = i + 1; j <= i + 2; j++)
                    //{
                    //    sheet.Row(j).Height = 20;//设置行高
                    //}
                }
                if (ListMS.Count > 0)
                {
                    //加载模板第二张表
                    var     sheet      = package.Workbook.Worksheets[2];
                    var     cells      = sheet.Cells;
                    decimal TotalMoney = 0; //计算总金额
                    int     Rows       = ListMS.Count();
                    Befor = 9;              //民生本行从9开始
                    sheet.InsertRow(Befor + 1, Rows - 1, Befor);
                    int i = Befor;
                    foreach (var item in ListMS)
                    {
                        decimal Money = item.Amoney - (decimal)item.UserRate;
                        TotalMoney += Money;
                        //收款账号
                        cells["A" + i].Value = item.CardNum;
                        //交易金额
                        cells["B" + i].Value = Money.ToString("F2");
                        //收款人姓名
                        cells["C" + i].Value = item.Owner;
                        //用途
                        cells["D" + i].Value = "349";
                        maxCol = 4;
                        i++;
                    }
                    i--;
                    //总金额
                    cells["B6"].Value = TotalMoney.ToString();
                    //总交易数
                    cells["B7"].Value = Rows.ToString();
                }
                if (ListGS.Count > 0)
                {
                    //加载模板第三张表
                    var     sheet      = package.Workbook.Worksheets[3];
                    var     cells      = sheet.Cells;
                    decimal TotalMoney = 0; //计算总金额
                    int     Rows       = ListGS.Count();
                    Befor = 2;              //工行本行从2开始
                    sheet.InsertRow(Befor + 1, Rows - 1, Befor);
                    int i = Befor;
                    IList <BasicProvince> PList = Entity.BasicProvince.Where(n => n.State == 1).ToList();
                    IList <BasicCity>     CList = Entity.BasicCity.Where(n => n.State == 1).ToList();
                    foreach (var item in ListGS)
                    {
                        decimal Money = item.Amoney - (decimal)item.UserRate;
                        TotalMoney += Money;
                        //币种
                        cells["A" + i].Value = "RMB";
                        //日期
                        cells["B" + i].Value = DateTime.Now.ToString("yyyyMMdd");
                        //明细标志
                        cells["C" + i].Value = "";
                        //顺序号
                        cells["D" + i].Value = i - Befor + 1;
                        //付款账号开户行
                        cells["E" + i].Value = "工商银行";
                        //付款账号
                        cells["F" + i].Value = "4000051709100125887";
                        //付款账号名称
                        cells["G" + i].Value = "好付支付(深圳)有限公司";
                        //收款账号开户行
                        cells["H" + i].Value = "工商银行";
                        //收款账号省份
                        cells["I" + i].Value = PList.FirstOrNew(n => n.Id == item.Province).Name;
                        //收款账号地市
                        cells["J" + i].Value = CList.FirstOrNew(n => n.Id == item.City).Name;
                        //收款账号地区码
                        cells["K" + i].Value = "";
                        //收款账号
                        cells["L" + i].Value = item.CardNum;
                        //收款账号名称
                        cells["M" + i].Value = item.Owner;
                        //金额
                        cells["N" + i].Value = Money.ToString("F2");
                        //汇款用途
                        cells["O" + i].Value = "提现";
                        //备注信息
                        cells["P" + i].Value = "";
                        //汇款方式
                        cells["Q" + i].Value = 1;
                        //收款账户短信通知手机号码
                        cells["R" + i].Value = "";
                        //自定义序号
                        cells["S" + i].Value = item.Id;
                        maxCol = 19;
                        i++;
                    }
                    i--;
                }
                //无数据表删除
                if (ListGS.Count == 0)
                {
                    package.Workbook.Worksheets.Delete(package.Workbook.Worksheets[3]);
                }
                if (ListMS.Count == 0)
                {
                    package.Workbook.Worksheets.Delete(package.Workbook.Worksheets[2]);
                }
                if (ListOT.Count == 0)
                {
                    package.Workbook.Worksheets.Delete(package.Workbook.Worksheets[1]);
                }
                Response.BinaryWrite(package.GetAsByteArray());//输出
                Response.ContentType = "application/vnd.openxmlformats-officedocument.spreadsheetml.sheet";
                Response.AddHeader("content-disposition", "attachment;  filename=" + DateTime.Now.ToString("yyyyMMddHHmmss") + new Random().Next(10, 99) + ".xlsx");
            }
            else
            {
                Response.Write("暂无符合条件数据");
            }
        }
        public ActionResult Save(OrderCash OrderCash)
        {
            OrderCash baseOrderCash = Entity.OrderCash.FirstOrDefault(n => n.Id == OrderCash.Id);
            string    tnum          = "TK" + baseOrderCash.OId;

            if (!this.GetRuningState(tnum))
            {
                this.SetRuningState(tnum);
                try
                {
                    OrdersPayOnly OPO = new OrdersPayOnly();
                    OPO.TNum    = tnum;
                    OPO.AddTime = DateTime.Now;
                    Entity.OrdersPayOnly.AddObject(OPO);
                    Entity.SaveChanges();
                }
                catch (Exception)
                {
                    ViewBag.ErrorMsg = "重复入帐!";
                    return(View("Error"));
                }
                //return null;
                if (baseOrderCash.OrderState == 2 && baseOrderCash.PayState == 3)
                {
                    var OrderCashLog = new OrderCashLog()
                    {
                        AddTime   = DateTime.Now,
                        AdminId   = this.AdminUser.Id,
                        AdminName = this.AdminUser.TrueName,
                        TNum      = baseOrderCash.OId,
                        Remark    = string.Empty,
                        LogType   = 3,
                    };
                    this.Entity.OrderCashLog.AddObject(OrderCashLog);
                    baseOrderCash.RefundTime = DateTime.Now;
                    baseOrderCash.PayState   = 4;
                    Orders Orders = Entity.Orders.FirstOrDefault(n => n.TNum == baseOrderCash.OId);
                    Orders.PayState = 4;
                    //退款到余额
                    Users baseUsers = Entity.Users.FirstOrDefault(n => n.Id == baseOrderCash.UId);
                    //帐户变动记录
                    int     USERSID  = baseUsers.Id;
                    string  TNUM     = Orders.TNum;
                    decimal PAYMONEY = baseOrderCash.Amoney;
                    string  SP_Ret   = Entity.SP_UsersMoney(USERSID, TNUM, PAYMONEY, 6, "");
                    if (SP_Ret != "3")
                    {
                        Utils.WriteLog(string.Format("U{0},O{1},T{2}:{3}【{4}】", USERSID, TNUM, 6, PAYMONEY, SP_Ret), "SP_UsersMoney");
                    }
                    //======分润======
                    baseOrderCash      = baseOrderCash.PayAgent(Entity, 2);
                    Orders.AgentPayGet = (decimal)baseOrderCash.AgentCashGet;
                    Entity.SaveChanges();
                    Orders.SendMsg(Entity);//发送消息类
                    //T0时增加配额
                    if (baseOrderCash.TrunType == 0)
                    {
                        decimal     Money       = baseOrderCash.Amoney - (decimal)baseOrderCash.UserRate;
                        DateTime    Today       = DateTime.Parse(DateTime.Now.ToString("yyyy-MM-dd"));
                        TaskTimeSet TaskTimeSet = Entity.TaskTimeSet.FirstOrDefault(n => n.ODate == Today);
                        if (TaskTimeSet != null)
                        {
                            if (TaskTimeSet.UsedMoney >= Money)
                            {
                                TaskTimeSet.UsedMoney -= Money;
                            }
                            else
                            {
                                TaskTimeSet.UsedMoney = 0;
                            }
                            Entity.SaveChanges();
                        }
                    }
                }
                BaseRedirect();
            }
            return(null);
        }
        public void PayCash(OrderCash OrderCash, EFPagingInfo <OrderCash> p, bool?IsShowSupAgent)
        {
            if (IsShowSupAgent == null)
            {
                IsShowSupAgent = false;
            }
            p.PageSize = 99999999;
            p.SqlWhere.Add(f => f.OrderState == 2);
            p.SqlWhere.Add(f => f.PayState == 1 || f.PayState == 2);

            if (OrderCash.AddTime.IsNullOrEmpty())
            {
                OrderCash.AddTime = DateTime.Parse(DateTime.Now.ToString("yyyy-MM-dd"));
            }
            if (OrderCash.FTime.IsNullOrEmpty())
            {
                OrderCash.FTime = DateTime.Now;
            }
            if (!OrderCash.Owner.IsNullOrEmpty())
            {
                IList <Users> UList = Entity.Users.Where(n => n.TrueName.Contains(OrderCash.Owner) || n.NeekName.Contains(OrderCash.Owner) || n.UserName == OrderCash.Owner).ToList();
                List <int>    UIds  = new List <int>();
                foreach (var pp in UList)
                {
                    UIds.Add(pp.Id);
                }
                p.SqlWhere.Add(f => UIds.Contains(f.UId));
            }
            if (!OrderCash.Cash.IsNullOrEmpty())
            {
                p.SqlWhere.Add(f => f.Amoney >= OrderCash.Cash);
            }
            if (!OrderCash.ECash.IsNullOrEmpty())
            {
                p.SqlWhere.Add(f => f.Amoney <= OrderCash.ECash);
            }
            if (!OrderCash.OId.IsNullOrEmpty())
            {
                p.SqlWhere.Add(f => f.OId == OrderCash.OId);
            }
            if (!OrderCash.Agent.IsNullOrEmpty())
            {
                //是否要显示下级
                if ((bool)IsShowSupAgent)
                {
                    SysAgent         LowerLevelAgent = Entity.SysAgent.Where(s => s.Id == OrderCash.Agent).FirstOrNew();
                    IList <SysAgent> SysAgentList    = LowerLevelAgent.GetSupAgent(Entity);
                    IList <int>      UID             = new List <int>();
                    foreach (var s in SysAgentList)
                    {
                        UID.Add(s.Id);
                    }
                    p.SqlWhere.Add(f => UID.Contains(f.Agent));
                }
                else
                {
                    p.SqlWhere.Add(f => f.Agent == OrderCash.Agent);
                }
            }
            if (!OrderCash.FState.IsNullOrEmpty())
            {
                p.SqlWhere.Add(f => f.FState == (OrderCash.FState == 99 ? 0 : OrderCash.FState));
            }
            if (!OrderCash.TrunType.IsNullOrEmpty())
            {
                p.SqlWhere.Add(f => f.TrunType == (OrderCash.TrunType == 99 ? 0 : OrderCash.TrunType));
            }
            if (!OrderCash.AId.IsNullOrEmpty())
            {
                p.SqlWhere.Add(f => f.AId == OrderCash.AId);
            }
            if (!OrderCash.FId.IsNullOrEmpty())
            {
                p.SqlWhere.Add(f => f.FId == OrderCash.FId);
            }
            if (!OrderCash.AgentState.IsNullOrEmpty())
            {
                p.SqlWhere.Add(f => f.AgentState == OrderCash.AgentState);
            }
            if (!OrderCash.AddTime.IsNullOrEmpty() && !OrderCash.FTime.IsNullOrEmpty())
            {
                // DateTime FTime = ((DateTime)OrderCash.FTime).AddDays(1);
                DateTime FTime = OrderCash.FTime.Value;
                p.SqlWhere.Add(f => f.AddTime > OrderCash.AddTime && f.AddTime < FTime);
            }
            p.OrderByList.Add("Id", "ASC");
            IPageOfItems <OrderCash> OrderCashList = Entity.Selects <OrderCash>(p);

            TaskCash TaskCash = new TaskCash();

            TaskCash.State   = 0;
            TaskCash.AddTime = DateTime.Now;
            TaskCash.Total   = OrderCashList.Count();
            TaskCash.Success = 0;
            TaskCash.Fail    = 0;
            Entity.TaskCash.AddObject(TaskCash);
            Entity.SaveChanges();
            int suc  = 0;
            int fa   = 0;
            int same = 0;

            foreach (var O in OrderCashList)
            {
                if (O.PayState == 1 && O.OrderState == 2)
                {
                    TaskCashInfo TaskCashInfo = Entity.TaskCashInfo.FirstOrDefault(n => n.OId == O.OId);
                    if (TaskCashInfo == null)
                    {
                        TaskCashInfo         = new TaskCashInfo();
                        TaskCashInfo.OId     = O.OId;
                        TaskCashInfo.TId     = TaskCash.Id;
                        TaskCashInfo.State   = 0;
                        TaskCashInfo.OState  = 0;
                        TaskCashInfo.NState  = 0;
                        TaskCashInfo.AddTime = DateTime.Now;
                        Entity.TaskCashInfo.AddObject(TaskCashInfo);
                        suc++;
                    }
                    else
                    {
                        same++;
                    }
                }
                else
                {
                    fa++;
                }
            }
            TaskCash.Total = suc;
            Entity.SaveChanges();
            System.Web.HttpContext.Current.Response.AddHeader("content-type", "application/json");
            Response.Write("{\"id\":" + TaskCash.Id + ",\"same\":" + same + ",\"success\":" + suc + ",\"fail\":" + fa + "}");
        }
        /// <summary>
        /// 导出善付单
        /// </summary>
        /// <param name="OrderCash"></param>
        /// <param name="p"></param>
        /// <param name="IsShowSupAgent"></param>
        public void XLSDoShanFu(OrderCash OrderCash, EFPagingInfo <OrderCash> p, bool?IsShowSupAgent)
        {
            if (IsShowSupAgent == null)
            {
                IsShowSupAgent = false;
            }
            p = this.Condition(OrderCash, p, IsShowSupAgent);
            var Iquery = this.Entity.OrderCash.AsQueryable();

            foreach (var item in p.SqlWhere)
            {
                Iquery = Iquery.Where(item);
            }

            var OrderCashList = Iquery.Join(this.Entity.Users, o => o.UId, x => x.Id, (o, x) => new
            {
                Id       = o.Id,
                CardNum  = o.CardNum,
                CardId   = x.CardId,
                Owner    = o.Owner,
                Mobile   = o.Mobile,
                Amoney   = o.Amoney,
                UserRate = o.UserRate,
            }).OrderByDescending(o => o.Id).ToList();

            //加载对应银行模板
            string       tempname = "zx_demo.xlsx";
            string       file     = Server.MapPath("/template") + "\\" + tempname;
            ExcelPackage package  = new ExcelPackage(new FileInfo(file), true);

            if (OrderCashList.Count() > 0)
            {
                decimal adjust = 0.3M;//金额调节
                //加载模板第二张表
                var sheet = package.Workbook.Worksheets[1];
                var cells = sheet.Cells;
                int Rows  = OrderCashList.Count();
                int Befor = 2;
                int i     = Befor;
                sheet.InsertRow(Befor + 1, Rows - 1, Befor);
                foreach (var item in OrderCashList)
                {
                    decimal Money = (item.Amoney - (decimal)item.UserRate) + adjust;
                    //TotalMoney += Money;
                    //银行卡号
                    cells["A" + i].Value = item.CardNum;
                    //身份证号
                    cells["B" + i].Value = item.CardId;
                    //真实姓名
                    cells["C" + i].Value = item.Owner;
                    //银行卡绑定的手机号
                    cells["D" + i].Value = item.Mobile;
                    //银行卡背面的cvn2
                    cells["E" + i].Value = string.Empty;
                    //银行卡有效期
                    cells["F" + i].Value = string.Empty;
                    //交易金额
                    cells["G" + i].Value = Money.ToString("f2");
                    i++;
                }
                i--;

                Response.BinaryWrite(package.GetAsByteArray());//输出
                Response.ContentType = "application/vnd.openxmlformats-officedocument.spreadsheetml.sheet";
                Response.AddHeader("content-disposition", "attachment;  filename=" + OrderCash.AddTime.ToString("yyyyMMddHHmmss") + "至" + OrderCash.FTime.Value.ToString("yyyyMMddHHmmss") + ".xlsx");
            }
            else
            {
                Response.Write("暂无符合条件数据");
            }
        }
Пример #23
0
        public void Notice()
        {
            string merId  = ConfigurationManager.AppSettings["Cash_merId"].ToString();  //商户号
            string merKey = ConfigurationManager.AppSettings["Cash_merKey"].ToString(); //商户密钥
            string Resp   = Request.Form["resp"];
            string Sign   = Request.Form["sign"];
            string MD5Str = Resp + merKey;
            string sign   = MD5Str.GetMD5();

            if (Sign != sign)
            {
                Response.Write("E2");
                return;
            }
            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();    //交易金额
            //================================================
            PayLog PayLog = new PayLog();

            PayLog.PId     = 0;
            PayLog.OId     = orderid;
            PayLog.TId     = queryid;
            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 (merId != merid)
            {
                Response.Write("E1");
                return;
            }
            Orders Orders = Entity.Orders.FirstOrDefault(n => n.TNum == orderid);

            if (Orders == null)
            {
                Response.Write("E4");
                return;
            }
            if (resultcode == "0000")
            {
                if (Orders.TType == 2)
                {
                    OrderCash OrderCash = Entity.OrderCash.FirstOrDefault(n => n.OId == orderid);
                    if (OrderCash.FState == 0)
                    {
                        OrderCash.PayState = 2;
                        OrderCash.FState   = 1;
                        OrderCash.FTime    = DateTime.Now;
                        Orders.PayState    = 2;
                        if (OrderCash.AgentCashGet > 0)
                        {
                            Orders.RunSplit = 1;
                        }
                        Entity.SaveChanges();
                        Orders.SendMsg(Entity);//发送消息类
                    }
                }
                if (Orders.TType == 5)
                {
                    OrderHouse OrderHouse = Entity.OrderHouse.FirstOrDefault(n => n.OId == orderid);
                    if (OrderHouse.FState == 0)
                    {
                        OrderHouse.PayState = 2;
                        OrderHouse.FState   = 1;
                        OrderHouse.FTime    = DateTime.Now;
                        Orders.PayState     = 2;
                        if (OrderHouse.AIdPayGet > 0)
                        {
                            Orders.RunSplit = 1;
                        }
                        Entity.SaveChanges();
                        //======分润======
                        Orders.SendMsg(Entity);//发送消息类
                    }
                }
            }
            else if (resultcode == "2001")
            {
            }
            else
            {
                if (Orders.TType == 2)
                {
                    if (Orders.PayState != 4 && Orders.PayState != 3)
                    {
                        OrderCash OrderCash = Entity.OrderCash.FirstOrDefault(n => n.OId == orderid);

                        OrderCash.PayState = 3;
                        OrderCash.Remark   = resultmsg;
                        Orders.PayState    = 3;
                        Orders.Remark      = resultmsg;
                        Entity.SaveChanges();
                        Orders.SendMsg(Entity);//发送消息类
                    }
                }
                if (Orders.TType == 5)
                {
                    if (Orders.PayState != 4 && Orders.PayState != 3)
                    {
                        OrderHouse OrderHouse = Entity.OrderHouse.FirstOrDefault(n => n.OId == orderid);

                        OrderHouse.PayState = 3;
                        OrderHouse.Remark   = resultmsg;
                        Orders.PayState     = 3;
                        Orders.Remark       = resultmsg;
                        Entity.SaveChanges();
                        Orders.SendMsg(Entity);//发送消息类
                    }
                }
            }
            Response.Write("0000");
        }
Пример #24
0
        public void Execute(IJobExecutionContext context)
        {
            string JobName = "OrderProfit";
            string CanRun  = ConfigurationManager.AppSettings["Run" + JobName].ToString();

            if (CanRun == "true")
            {
                if (!IsRun)
                {
                    LokFuEntity Entity = new LokFuEntity();
                    IsRun = true;
                    try
                    {
                        Log.Write(JobName + "任务开始执行!");
                        //-------------------------------------------------------
                        #region 任务主体
                        IList <Orders> List = Entity.Orders.Where(n => n.RunSplit == 1).Take(50).ToList();
                        foreach (var p in List)
                        {
                            p.RunSplit = 2;
                        }
                        Entity.SaveChanges();
                        foreach (var O in List)
                        {
                            if (O.TType == 1)//银联卡支付
                            {
                                OrderRecharge OrderRecharge = Entity.OrderRecharge.FirstOrDefault(n => n.OId == O.TNum);
                                if (OrderRecharge != null)
                                {
                                    OrderRecharge = OrderRecharge.PayAgent(Entity, 1, O.FrozenState);
                                    O.AgentPayGet = (decimal)OrderRecharge.AgentPayGet;
                                    O.AgentState  = 1;
                                }
                            }
                            if (O.TType == 2)//提现
                            {
                                OrderCash OrderCash = Entity.OrderCash.FirstOrDefault(n => n.OId == O.TNum);
                                if (OrderCash != null)
                                {
                                    OrderCash     = OrderCash.PayAgent(Entity, 1);
                                    O.AgentPayGet = (decimal)OrderCash.AgentCashGet;
                                }
                            }
                            if (O.TType == 3)//转帐
                            {
                                OrderTransfer OrderTransfer = Entity.OrderTransfer.FirstOrDefault(n => n.OId == O.TNum);
                                if (OrderTransfer != null)
                                {
                                    OrderTransfer = OrderTransfer.PayAgent(Entity, 1);
                                    O.AgentPayGet = (decimal)OrderTransfer.AgentPayGet;
                                }
                            }
                            if (O.TType == 5)//房租
                            {
                                OrderHouse OrderHouse = Entity.OrderHouse.FirstOrDefault(n => n.OId == O.TNum);
                                if (OrderHouse != null)
                                {
                                    OrderHouse    = OrderHouse.PayAgent(Entity, 1);
                                    O.AgentPayGet = (decimal)OrderHouse.AgentPayGet;
                                }
                            }
                            if (O.TType == 6)//升级
                            {
                                VIPOrder VIPOrder = Entity.VIPOrder.FirstOrDefault(n => n.TNum == O.TNum);
                                if (VIPOrder != null)
                                {
                                    VIPOrder      = VIPOrder.PayAgent(Entity, 1);
                                    O.AgentPayGet = (decimal)VIPOrder.SplitMoney;
                                    O.AgentState  = 1;
                                }
                            }
                            if (O.TType == 7 || O.TType == 8 || O.TType == 9)//扫码 NFC
                            {
                                OrderF2F OrderF2F = Entity.OrderF2F.FirstOrDefault(n => n.OId == O.TNum);
                                if (OrderF2F != null)
                                {
                                    OrderF2F      = OrderF2F.PayAgent(Entity, 1, O.FrozenState);
                                    O.AgentPayGet = (decimal)OrderF2F.AgentPayGet;
                                }
                            }
                            if (O.TType == 10)//代理自助开通
                            {
                                DaiLiOrder DaiLiOrder = Entity.DaiLiOrder.FirstOrDefault(n => n.OId == O.TNum);
                                if (DaiLiOrder != null)
                                {
                                    DaiLiOrder    = DaiLiOrder.PayAgent(Entity, 1);
                                    O.AgentPayGet = (decimal)DaiLiOrder.AgentGet;
                                    O.AgentState  = 1;
                                }
                            }

                            O.RunSplit = 3;
                            Entity.SaveChanges();
                        }
                        #endregion
                        //-------------------------------------------------------
                        Log.Write(JobName + "任务执行结束![共计" + List.Count + "条]");
                    }
                    catch (Exception Ex)
                    {
                        Log.Write(JobName + "任务执行过程出错!", Ex);
                    }
                    IsRun = false;
                }
                else
                {
                    Log.Write(JobName + "任务还在执行中!");
                }
            }
        }
Пример #25
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("[Orders]:", "【Data】" + Data, Ex);
            }
            if (json == null)
            {
                DataObj.OutError("1000");
                return;
            }
            Orders Orders = new Orders();

            Orders = JsonToObject.ConvertJsonToModel(Orders, json);

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

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

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

            if (!Orders.Pg.IsNullOrEmpty())
            {
                p.PageIndex = Orders.Pg;
            }
            if (!Orders.Pgs.IsNullOrEmpty())
            {
                p.PageSize = Orders.Pgs;
            }
            if (!Orders.STime.IsNullOrEmpty())
            {
                p.SqlWhere.Add(f => f.AddTime >= Orders.STime);
            }
            if (!Orders.ETime.IsNullOrEmpty())
            {
                Orders.ETime = Orders.ETime.AddHours(24);
                p.SqlWhere.Add(f => f.AddTime <= Orders.ETime);
            }
            if (!Orders.IdCardState.IsNullOrEmpty())
            {//凭证状态
                if (Orders.IdCardState == 99)
                {
                    p.SqlWhere.Add(f => f.IdCardState == 0);
                }
                else if (Orders.IdCardState == 98)
                {
                    p.SqlWhere.Add(f => f.IdCardState == 1 || f.IdCardState == 2 || f.IdCardState == 4);
                }
                else
                {
                    p.SqlWhere.Add(f => f.IdCardState == Orders.IdCardState);
                }
            }

            bool IsOld = true;

            #region 版本比较 升级之后比较长时间后可以考滤删除版本判断代码
            //处理贴牌相关
            var SysAgent = this.Entity.SysAgent.FirstOrDefault(o => o.Id == baseUsers.Agent);
            if (SysAgent == null)
            {
                DataObj.OutError("1000");
                return;
            }
            var topSysAgent = SysAgent.GetTopAgent(this.Entity);

            if (!Equipment.SoftVer.IsNullOrEmpty())
            {
                Version v1 = new Version(Equipment.SoftVer);//当前版本
                Version v2 = new Version("1.0");

                if (Equipment.RqType.ToLower() == "apple")
                {
                    //苹果
                    if (topSysAgent.IsTeiPai == 0)//好付
                    {
                        v2 = new Version("8.0");
                    }
                    else//贴牌
                    {
                        v2 = new Version("6.0");
                    }
                }
                else if (Equipment.RqType.ToLower() == "android")
                {
                    //安卓
                    if (topSysAgent.IsTeiPai == 0)//好付
                    {
                        v2 = new Version("8.0.0");
                    }
                    else //贴牌
                    {
                        v2 = new Version("6.0");
                    }
                }
                if (v1 >= v2)
                {
                    IsOld = false;
                }
            }
            #endregion
            if (!IsOld)//新版
            {
                #region 4.0条件判断
                if (!(Orders.TType == 3 && Orders.TState == 3))
                {
                    p.SqlWhere.Add(o => o.UId == baseUsers.Id);
                }
                if (!Orders.TType.IsNullOrEmpty())
                {
                    p.SqlWhere.Add(f => f.TType == Orders.TType);//读取对应的类型
                    if (Orders.TType == 1)
                    {
                        if (!Orders.TState.IsNullOrEmpty())
                        {
                            switch (Orders.TState)
                            {
                            case 1:    //未付
                                p.SqlWhere.Add(f => f.TState == 1 && f.PayState == 0);
                                break;

                            case 2:    //已付
                                p.SqlWhere.Add(f => f.TState == 2 && f.PayState == 1);
                                break;

                            case 3:    //待传证照
                                p.SqlWhere.Add(f => f.PayState == 1 && f.IdCardState == 1);
                                break;

                            case 4:    //待审核/已传证照
                                p.SqlWhere.Add(f => f.PayState == 1 && f.IdCardState == 2);
                                break;

                            case 5:    //审核失败
                                p.SqlWhere.Add(f => f.PayState == 1 && f.IdCardState == 4);
                                break;

                            case 6:    //退单
                                p.SqlWhere.Add(f => f.TState == 4);
                                break;

                            case 7:    //待入帐
                                p.SqlWhere.Add(f => f.TState == 1 && f.PayState == 1 && f.InState == 0);
                                break;
                            }
                        }
                    }
                    if (Orders.TType == 2)
                    {
                        switch (Orders.TState)
                        {
                        case 1:    //处理中
                            p.SqlWhere.Add(f => f.TState == 1);
                            break;

                        case 2:    //已汇出
                            p.SqlWhere.Add(f => f.TState == 2 && f.PayState == 2);
                            break;

                        case 3:    //提现失败
                            p.SqlWhere.Add(f => f.TState == 3);
                            break;

                        case 4:    //出款中
                            p.SqlWhere.Add(f => f.TState == 2 && f.PayState == 1);
                            break;

                        case 5:    //退款
                            p.SqlWhere.Add(f => f.TState == 2 && f.PayState == 4);
                            break;

                        case 6:    //退款中
                            p.SqlWhere.Add(f => f.TState == 2 && f.PayState == 3);
                            break;
                        }
                    }
                    if (Orders.TType == 3)
                    {
                        switch (Orders.TState)
                        {
                        case 1:    //未付
                            p.SqlWhere.Add(f => f.TState == 1 && f.PayState == 0);
                            break;

                        case 2:    //已付
                            p.SqlWhere.Add(f => f.TState == 2 && f.PayState == 1);
                            break;

                        case 3:    //已收
                            p.SqlWhere.Add(f => f.TState == 2 && f.PayState == 1 && f.RUId == baseUsers.Id);
                            break;
                        }
                    }
                    if (Orders.TType == 6)
                    {
                        if (!Orders.TState.IsNullOrEmpty())
                        {
                            p.SqlWhere.Add(f => f.TState == Orders.TState);
                        }
                    }
                    if (Orders.TType == 7 || Orders.TType == 8)
                    {
                        if (!Orders.TState.IsNullOrEmpty())
                        {
                            if (Orders.TState == 99)
                            {
                                p.SqlWhere.Add(f => f.TState == 0);
                            }
                            if (Orders.TState == 1)
                            {
                                p.SqlWhere.Add(f => f.TState == 1 && f.PayState == 0);
                            }
                            if (Orders.TState == 2)
                            {
                                p.SqlWhere.Add(f => f.TState == 2 && f.PayState == 1);
                            }
                            if (Orders.TState == 3)//退单
                            {
                                p.SqlWhere.Add(f => f.TState == 4);
                            }
                            if (Orders.TState == 4)//待入帐
                            {
                                p.SqlWhere.Add(f => f.TState == 1 && f.PayState == 1 && f.InState == 0);
                            }
                            if (Orders.TState == 5)//待审核/已传证照
                            {
                                p.SqlWhere.Add(f => f.PayState == 1 && f.InState == 1 && f.IdCardState == 2);
                            }
                            if (Orders.TState == 6)//待传证照
                            {
                                p.SqlWhere.Add(f => f.PayState == 1 && f.InState == 1 && f.IdCardState == 1);
                            }
                            if (Orders.TState == 7)//审核失败
                            {
                                p.SqlWhere.Add(f => f.PayState == 1 && f.InState == 1 && f.IdCardState == 4);
                            }
                        }
                    }
                }
                else
                {
                    if (!Orders.TState.IsNullOrEmpty())
                    {
                        if (Orders.TState == 99)
                        {
                            p.SqlWhere.Add(f => f.TState == 0);
                        }
                        if (Orders.TState == 1)
                        {
                            p.SqlWhere.Add(f => f.PayState == 1);
                        }
                        if (Orders.TState == 2)
                        {
                            p.SqlWhere.Add(f => f.PayState == 0 && f.TState != 0);
                        }
                    }
                }
                #endregion
            }
            else
            {
                #region 4.0之前条件判断
                //搜索
                if (Orders.TType.IsNullOrEmpty())
                {//不限类型,读取收支交易,收款订单只显示已支付订单
                    p.SqlWhere.Add(f => f.UId == baseUsers.Id || (f.RUId == baseUsers.Id && f.PayState == 1) && f.TType != 2);
                }
                else
                {
                    if (Orders.TType == 4)
                    {
                        //已支付收款订单
                        p.SqlWhere.Add(f => f.TType == 3);
                        p.SqlWhere.Add(f => f.RUId == baseUsers.Id && f.PayState == 1);
                    }
                    else if (Orders.TType == 95)
                    { //转帐单
                        p.SqlWhere.Add(f => f.TType == 3);
                        p.SqlWhere.Add(f => (f.RUId == baseUsers.Id && f.PayState == 1) || f.UId == baseUsers.Id);
                    }
                    else if (Orders.TType == 96)   //收款订单
                    {
                        p.SqlWhere.Add(f => (f.TType == 3 && f.RUId == baseUsers.Id && f.PayState == 1) || (f.TType == 1 && f.UId == baseUsers.Id));
                    }
                    else
                    {
                        p.SqlWhere.Add(f => f.TType == Orders.TType);
                        p.SqlWhere.Add(f => f.UId == baseUsers.Id);
                    }
                }
                if (!Orders.TState.IsNullOrEmpty())  //交易状态
                {
                    p.SqlWhere.Add(f => f.TState == Orders.TState);
                }
                if (!Orders.PayState.IsNullOrEmpty()) //支付状态
                {
                    if (Orders.PayState == 99)
                    {
                        Orders.PayState = 0;
                    }
                    p.SqlWhere.Add(f => f.PayState == Orders.PayState);
                }
                #endregion
            }

            p.OrderByList.Add("Id", "DESC");
            IPageOfItems <Orders> List = Entity.Selects <Orders>(p);
            //处理转帐订单
            foreach (var pp in List)
            {
                pp.Cols = pp.Cols + ",Json,PicList,UserCardName,CardUpdateTime";
                if (baseUsers.Id == pp.RUId)
                {
                    pp.TType = 4;
                }
                JObject JS = new JObject();
                if (pp.TType == 1)
                { //银联卡支付
                    OrderRecharge OrderRecharge = Entity.OrderRecharge.FirstOrNew(n => n.OId == pp.TNum);
                    OrderRecharge.Cols = "Amoney,PayMoney,Poundage,PayType";
                    string JsStr = OrderRecharge.OutJson();
                    try
                    {
                        JS = (JObject)JsonConvert.DeserializeObject(JsStr);
                    }
                    catch (Exception Ex)
                    {
                        Log.Write("[Order]:", "【JsStr】" + JsStr, Ex);
                    }
                    pp.Json = JS;
                }
                if (pp.TType == 2)//提现不能取消
                {
                    OrderCash OrderCash = Entity.OrderCash.FirstOrNew(n => n.OId == pp.TNum);
                    OrderCash.Cols     = "Owner,Bank,CardNum,Deposit,Mobile,Province,City,District,Amoney,UserRate,TrunType,PayMoney";
                    OrderCash.PayMoney = OrderCash.Amoney - (decimal)OrderCash.UserRate;
                    string JsStr = OrderCash.OutJson();
                    try
                    {
                        JS = (JObject)JsonConvert.DeserializeObject(JsStr);
                    }
                    catch (Exception Ex)
                    {
                        Log.Write("[Order]:", "【JsStr】" + JsStr, Ex);
                    }
                    pp.Json = JS;
                }
                if (pp.TType == 3 || pp.TType == 4)//付款
                {
                    OrderTransfer OrderTransfer = Entity.OrderTransfer.FirstOrNew(n => n.OId == pp.TNum);
                    Users         Users         = new Users();
                    if (pp.TType == 4)
                    {
                        Users = Entity.Users.FirstOrNew(n => n.Id == OrderTransfer.UId);
                    }
                    if (pp.TType == 3)
                    {
                        Users = Entity.Users.FirstOrNew(n => n.Id == OrderTransfer.RUId);
                    }
                    OrderTransfer.Mobile     = Users.UserName;
                    OrderTransfer.ToUserName = Users.TrueName;
                    OrderTransfer.Cols       = "UId,RUId,PayMoney,Poundage,Amoney,Mobile,ToUserName";
                    string JsStr = OrderTransfer.OutJson();
                    try
                    {
                        JS = (JObject)JsonConvert.DeserializeObject(JsStr);
                    }
                    catch (Exception Ex)
                    {
                        Log.Write("[Order]:", "【JsStr】" + JsStr, Ex);
                    }
                    pp.Json = JS;
                }
                if (pp.TType == 5)//防租
                {
                    OrderHouse OrderHouse = Entity.OrderHouse.FirstOrNew(n => n.OId == pp.TNum);
                    OrderHouse.Cols = "HouseOwner,Bank,CardNum,Deposit,Mobile,MonthRent,SecurityMoney,PayMonth,Poundage,Amoney";
                    string JsStr = OrderHouse.OutJson();
                    try
                    {
                        JS = (JObject)JsonConvert.DeserializeObject(JsStr);
                    }
                    catch (Exception Ex)
                    {
                        Log.Write("[Order]:", "【JsStr】" + JsStr, Ex);
                    }
                    pp.Json = JS;
                }
                if (pp.TType == 6)
                { //升级
                    //PayConfigOrder PayConfigOrder = Entity.PayConfigOrder.FirstOrNew(n => n.OId == pp.TNum);
                    //Out = Out + "," + PayConfigOrder.ToStr();
                    pp.Poundage = 0;
                }
                if (pp.TType == 7 || pp.TType == 8 || pp.TType == 9)
                { //扫码
                    OrderF2F OrderF2F = Entity.OrderF2F.FirstOrNew(n => n.OId == pp.TNum);
                    OrderF2F.Cols = "Amoney,PayMoney,Poundage";
                    string JsStr = OrderF2F.OutJson();
                    try
                    {
                        JS = (JObject)JsonConvert.DeserializeObject(JsStr);
                    }
                    catch (Exception Ex)
                    {
                        Log.Write("[Order]:", "【JsStr】" + JsStr, Ex);
                    }
                    pp.Json = JS;
                }
                if (pp.TType == 10)
                {//代理
                }
                pp.DoRemark(Entity);
                pp.StateTxt = pp.GetState();
                if (pp.RUId == baseUsers.Id && pp.PayState == 1)
                {
                    pp.StateTxt = "已收";
                }
                if (pp.IdCardState > 1)
                {
                    pp.Remark = pp.DDAuditRemark;
                }
                if (!pp.Remark.IsNullOrEmpty())
                {
                    pp.Remark = pp.Remark.Replace("\t", "");
                }
                if (!pp.UserCardPic.IsNullOrEmpty())
                {
                    var UserCardPicList = pp.UserCardPic.Split(',').ToList();
                    for (int i = 0; i < UserCardPicList.Count; i++)
                    {
                        var a = Utils.ImageUrl("Orders", UserCardPicList[i], AppImgPath);
                        UserCardPicList[i] = a;
                    }
                    JavaScriptSerializer JSS = new JavaScriptSerializer();
                    string data = JSS.Serialize(UserCardPicList);
                    JArray JO   = (JArray)JsonConvert.DeserializeObject(data);
                    pp.PicList = JO;
                }
            }

            IList <OrdersModel> OML = Utils.GetOrdersModel();
            OML = OML.Where(n => n.Id != 10).ToList();
            foreach (var P in OML)
            {
                if (P.Id == 3)
                {
                    P.Id = 95;
                }
            }

            IList <Orders> iList = List.ToList();
            StringBuilder  sb    = new StringBuilder("");
            sb.Append("{");
            sb.Append(List.PageToString());
            sb.Append(",");
            sb.Append(iList.EntityToString());
            sb.Append(",");
            sb.Append(OML.EntityToString());

            sb.Append(",\"state\":{");
            sb.Append("\"0\":[{\"key\":\"交易关闭\",\"value\":\"99\"},{\"key\":\"已付\",\"value\":\"1\"},{\"key\":\"未付\",\"value\":\"2\"}],");
            sb.Append("\"1\":[{\"key\":\"未付\",\"value\":\"1\"},{\"key\":\"已付\",\"value\":\"2\"},{\"key\":\"待传证照\",\"value\":\"3\"},{\"key\":\"已传证照\",\"value\":\"4\"},{\"key\":\"审核失败\",\"value\":\"5\"},{\"key\":\"退单\",\"value\":\"6\"},{\"key\":\"待入账\",\"value\":\"7\"}],");
            sb.Append("\"2\":[{\"key\":\"处理中\",\"value\":\"1\"},{\"key\":\"已汇出\",\"value\":\"2\"},{\"key\":\"提现失败\",\"value\":\"3\"},{\"key\":\"出款中\",\"value\":\"4\"},{\"key\":\"已退款\",\"value\":\"5\"},{\"key\":\"退款中\",\"value\":\"6\"}],");
            sb.Append("\"3\":[{\"key\":\"未付\",\"value\":\"1\"},{\"key\":\"已付\",\"value\":\"2\"},{\"key\":\"已收\",\"value\":\"3\"}],");
            sb.Append("\"6\":[{\"key\":\"交易关闭\",\"value\":\"99\"},{\"key\":\"未付\",\"value\":\"1\"},{\"key\":\"已付\",\"value\":\"2\"}],");
            sb.Append("\"7\":[{\"key\":\"交易关闭\",\"value\":\"99\"},{\"key\":\"进行中\",\"value\":\"1\"},{\"key\":\"已付\",\"value\":\"2\"},{\"key\":\"退单\",\"value\":\"3\"},{\"key\":\"待入账\",\"value\":\"4\"},{\"key\":\"已传证照\",\"value\":\"5\"},{\"key\":\"待传证照\",\"value\":\"6\"},{\"key\":\"审核失败\",\"value\":\"7\"}],");
            sb.Append("\"8\":[{\"key\":\"交易关闭\",\"value\":\"99\"},{\"key\":\"进行中\",\"value\":\"1\"},{\"key\":\"已付\",\"value\":\"2\"},{\"key\":\"退单\",\"value\":\"3\"},{\"key\":\"待入账\",\"value\":\"4\"},{\"key\":\"已传证照\",\"value\":\"5\"},{\"key\":\"待传证照\",\"value\":\"6\"},{\"key\":\"审核失败\",\"value\":\"7\"}]");
            sb.Append("},");

            sb.Append("\"type\":[{\"key\":\"0\",\"value\":\"全部\"},{\"key\":\"1\",\"value\":\"银联卡支付\"},{\"key\":\"2\",\"value\":\"提现\"},{\"key\":\"3\",\"value\":\"转账\"},{\"key\":\"6\",\"value\":\"升级\"},{\"key\":\"7\",\"value\":\"支付宝\"},{\"key\":\"8\",\"value\":\"微信\"}]");

            sb.Append("}");
            DataObj.Data = sb.ToString();
            DataObj.Code = "0000";
            DataObj.OutString();
        }
 /// <summary>
 /// 条件
 /// </summary>
 private EFPagingInfo <OrderCash> Condition(OrderCash OrderCash, EFPagingInfo <OrderCash> p, bool?IsShowSupAgent)
 {
     p.SqlWhere.Add(f => f.OrderState == 2);
     p.SqlWhere.Add(f => f.PayState == 1 || f.PayState == 2);
     //if (OrderCash.AddTime.IsNullOrEmpty())
     //{
     //    OrderCash.AddTime = DateTime.Parse(DateTime.Now.ToString("yyyy-MM-dd"));
     //}
     //if (OrderCash.FTime.IsNullOrEmpty())
     //{
     //    //OrderCash.FTime = DateTime.Parse(DateTime.Now.ToString("yyyy-MM-dd"));
     //    OrderCash.FTime = DateTime.Now;
     //}
     //if (!OrderCash.UId.IsNullOrEmpty()) { p.SqlWhere.Add(f => f.UId == OrderCash.UId); }
     if (!OrderCash.Owner.IsNullOrEmpty())
     {
         IList <Users> UList = Entity.Users.Where(n => n.TrueName == OrderCash.Owner || n.NeekName == OrderCash.Owner || n.UserName == OrderCash.Owner).ToList();
         List <int>    UIds  = new List <int>();
         foreach (var pp in UList)
         {
             UIds.Add(pp.Id);
         }
         p.SqlWhere.Add(f => UIds.Contains(f.UId));
     }
     if (!OrderCash.Cash.IsNullOrEmpty())
     {
         p.SqlWhere.Add(f => f.Amoney >= OrderCash.Cash);
     }
     if (!OrderCash.ECash.IsNullOrEmpty())
     {
         p.SqlWhere.Add(f => f.Amoney <= OrderCash.ECash);
     }
     if (!OrderCash.OId.IsNullOrEmpty())
     {
         p.SqlWhere.Add(f => f.OId == OrderCash.OId);
     }
     if (!OrderCash.Agent.IsNullOrEmpty())
     {
         //是否要显示下级
         if ((bool)IsShowSupAgent)
         {
             SysAgent         LowerLevelAgent = Entity.SysAgent.Where(s => s.Id == OrderCash.Agent).FirstOrNew();
             IList <SysAgent> SysAgentList    = LowerLevelAgent.GetSupAgent(Entity);
             IList <int>      UID             = new List <int>();
             foreach (var s in SysAgentList)
             {
                 UID.Add(s.Id);
             }
             p.SqlWhere.Add(f => UID.Contains(f.Agent));
         }
         else
         {
             p.SqlWhere.Add(f => f.Agent == OrderCash.Agent);
         }
     }
     if (!OrderCash.FState.IsNullOrEmpty())
     {
         p.SqlWhere.Add(f => f.FState == (OrderCash.FState == 99 ? 0 : OrderCash.FState));
     }
     if (!OrderCash.TrunType.IsNullOrEmpty())
     {
         p.SqlWhere.Add(f => f.TrunType == (OrderCash.TrunType == 99 ? 0 : OrderCash.TrunType));
     }
     if (!OrderCash.AId.IsNullOrEmpty())
     {
         p.SqlWhere.Add(f => f.AId == OrderCash.AId);
     }
     if (!OrderCash.FId.IsNullOrEmpty())
     {
         p.SqlWhere.Add(f => f.FId == OrderCash.FId);
     }
     if (!OrderCash.AgentState.IsNullOrEmpty())
     {
         p.SqlWhere.Add(f => f.AgentState == OrderCash.AgentState);
     }
     if (!OrderCash.AddTime.IsNullOrEmpty() && !OrderCash.FTime.IsNullOrEmpty())
     {
         // DateTime FTime = ((DateTime)OrderCash.FTime).AddDays(1);
         DateTime FTime = OrderCash.FTime.Value;
         p.SqlWhere.Add(f => f.AddTime > OrderCash.AddTime && f.AddTime < FTime);
     }
     return(p);
 }