Exemplo n.º 1
0
        /// <summary>
        /// 调用出金接口
        /// </summary>
        /// <param name="type">要调用的出金接口,0表示通联,1表示融宝</param>
        /// <param name="money"></param>
        /// <returns></returns>
        public static RequestResult CachOut(string type, TRealAccounts account, TAgents agent, TAccountMoney money)
        {
            PayEntity entity = new PayEntity();
            if (account != null)
            {
                entity.Phone = account.Phone;
                entity.Name = account.Name;
                entity.IDCardNO = account.IDCardNo;
            }
            else
            {
                entity.IDCardNO = agent.IdCardNo;
                entity.Phone = agent.TelePhone;
                entity.Name = agent.SavingsName;
            }

            RequestResult result = new RequestResult();

            if (money.BankName == null)
            {
                result.IsSuccess = false;
                result.ErrMsg = "银行名不能为空!";
                return result;
            }

            switch (type)
            {
                case "0":
                    result = allinpayMethod(entity.Name, money.AccountNo, "PERSONAL", (money.CreateMoney * 100).ToString(), money.BankName + money.BranchName, "");
                    break;
                case "1":
                    string dateTime = DateTime.Now.ToString("yyMMddhhmmss");
                    if (money.BranchName == null)
                    {
                        result.IsSuccess = false;
                        result.ErrMsg = "支行名不能为空!";
                        break;
                    }
                    int index = money.BranchName.IndexOf("分行");
                    if (index == -1)
                    {
                        result.IsSuccess = false;
                        result.ErrMsg = "分行必须填写!";
                        break;
                    }
                    string fen = money.BranchName.Substring(0, index + 2);
                    result = goldMoney(dateTime, money.CreateMoney.Value.ToString("N"), dateTime,
                              money.AccountNo, entity.Name, money.BankName,
                              fen, money.BranchName, money.ProvincialName,
                              money.CityName, entity.Phone, "身份证",
                              entity.IDCardNO, money.MoneyOrderNum, "", "私", "CNY", dateTime);
                    break;
                default:
                    break;
            }
            return result;
        }
Exemplo n.º 2
0
        public ActionResult DoCash()
        {
            try
            {
                string reqPrice = Request["price"];
                //string Branch = Request["Branch"];
                if (string.IsNullOrEmpty(reqPrice))
                {
                    return Json("出金金额不能为空!");
                }
                double price = Convert.ToDouble(reqPrice);
                if (price <= 0)
                {
                    return Json("出金金额必须大于0!");
                }

                int agentids = Converter.ToInt(Session["agentid"], 0);
                //string SavingsAccount = Request["SavingsAccount"];
                //int CityID = Converter.ToInt(Request["CityID"],0);
                //string BankName = Request["BankName"];

                APIDataDataContext db = DBFactory.DB;
                var user = (from c in db.TAgents where c.ID == agentids select c).FirstOrDefault();
                if (price > user.AccountMoney)
                {
                    return Json("可用余额不足!");
                }

                TAccountMoney tam = new TAccountMoney();
                tam.MoneyOrderNum = DateTime.Now.ToString("yyyyMMddHHmmssfff");
                tam.AgentId = agentids;
                tam.TypeId = 3;
                tam.OriginalMoney = user.AccountMoney;
                tam.CreateMoney = price;
                tam.NowMoney = user.AccountMoney - price;
                tam.CreateTime = DateTime.Now;
                tam.UpDateTime = DateTime.Now;
                tam.Status = 1;
                tam.BankState = 0;
                tam.PlatformState = 0;
                tam.Examine = 0;
                tam.CounterFee = 0;
                //tam.BankName = BankName;
                //tam.BranchName = Branch;
                //tam.AccountNo = SavingsAccount;
                //tam.CityId = CityID;
                //var city = (from c in db.TCities where c.ID == CityID select c).FirstOrDefault();
                //if (city != null)
                //{
                //    tam.CityName = city.CityName;
                //    var citys = (from c in db.TCities where c.CityCode == city.ParentCode select c).FirstOrDefault();
                //    if (citys != null)
                //    {
                //        tam.ProvincialName = citys.CityName;
                //    }
                //}
                //else
                //{
                //    tam.CityName = "";
                //    tam.ProvincialName = "";
                //}
                db.TAccountMoney.InsertOnSubmit(tam);
                //user.AccountMoney = user.AccountMoney - price;
                //user.MoneyUpDateTime = DateTime.Now;
                db.SubmitChanges();
                return Json("true");
            }
            catch
            {
                return Json("出金时出现错误!");
            }
        }
Exemplo n.º 3
0
        public ActionResult EditPositionPassword()
        {
            var password = Request["password"];

            var orderid = Converter.ToInt(Request["orderid"], 0);
            var types = Request["types"];//0保存 1删除 2平仓
            var OrderNum = Request["OrderNum"];
            var ProductID = Request["ProductID"];
            var TRealAccountsID = Converter.ToInt(Request["TRealAccountID"], 0);
            var Deal = Request["Deal"];
            var OrderCount = Request["OrderCount"];
            var OpenPrice = Request["OpenPrice"];
            var Loss = Request["Loss"];
            var OpenTime = Request["OpenTime"];
            var Profit = Request["Profit"];
            var NowPrice = Request["NowPrice"];
            var Deposit = Request["Deposit"];
            var UpdateTime = Request["UpdateTime"];

            APIDataDataContext db = APIDataContextProxy.APIDB;
            TOperationLog OLog = new TOperationLog();

            var user2 = (from c in db.TRealAccounts where c.ID == TRealAccountsID && c.PassWord == password select c).FirstOrDefault();

            if (user2 == null)
            {
                return Json(new { code = "0", msg = "客户密码不正确!" });
            }
            try
            {
                if (orderid > 0)
                {
                    var order = (from c in db.TOrders where c.ID == orderid select c).FirstOrDefault();
                    OLog.BeforeValue = ObjectToJson.ModelToJson(order);

                    OLog.UserID = Convert.ToInt32(Session["ID"]);
                    OLog.UserType = 2;//0 用户 1 会员 2 员工
                    OLog.CreateDate = DateTime.Now;

                    if (order != null)
                    {
                        if (types == "1")
                        {
                            #region 删除订单
                            db.TOrders.DeleteOnSubmit(order);
                            db.SubmitChanges();
                            OLog.UpdateValue = "";
                            //写入操作日志
                            OLog.PageName = "删除在手订单";
                            Converter.InsertOperationLog(OLog);
                            return Json(new { code = "1", msg = "提交成功!" });
                            #endregion

                        }
                        else if (types == "0")
                        {
                            #region 修改保存
                            order.ProductID = Converter.ToInt(ProductID, 0);
                            order.TRealAccountsID = Converter.ToInt(TRealAccountsID, 0);
                            order.Deal = Deal == "1" ? true : false;
                            order.OrderCount = Converter.ToInt(OrderCount, 0);
                            order.OpenPrice = Converter.ToFloat(OpenPrice, 0);
                            order.Loss = Converter.ToFloat(Loss, 0);
                            order.OpenTime = Convert.ToDateTime(OpenTime);
                            order.Profit = Converter.ToFloat(Profit, 0);
                            order.NowPrice = Converter.ToFloat(NowPrice, 0);
                            order.Deposit = Converter.ToFloat(Deposit, 0);
                            order.UpdateTime = Convert.ToDateTime(UpdateTime);
                            db.SubmitChanges();
                            OLog.UpdateValue = ObjectToJson.ModelToJson(order);
                            //写入操作日志
                            OLog.PageName = "修改在手订单";
                            Converter.InsertOperationLog(OLog);
                            return Json(new { code = "1", msg = "提交成功!" });
                            #endregion
                        }
                        else
                        {
                            #region 平仓
                            int OrderId = orderid;
                            var item = (from c in db.TOrders
                                        where c.ID == OrderId
                                        && c.OrderState == 1
                                        && c.OrderType == 1
                                        select c).FirstOrDefault();
                            if (item != null)
                            {
                                var product = (from c in db.TProducts
                                               join b in db.TLastClose on c.ProductCode equals b.ProductCode
                                               where c.ID == item.ProductID
                                               orderby c.ID
                                               select new
                                               {
                                                   c,
                                                   b.LastClose,
                                                   b.LastUpdateTime
                                               }).FirstOrDefault();
                                if (product != null)
                                {
                                    var Scale = Converter.ToFloat(product.c.Scale, 2);
                                    var nowdate = product.LastUpdateTime;
                                    #region 加工费
                                    double closedeposit = 0.0;   //加工费
                                    if (product.c.DepositType == 1)//固定
                                    {
                                        closedeposit = Converter.ToFloat(product.c.CloseDeposit, 0) * Converter.ToFloat(product.c.ContractNumber, 0) * Converter.ToFloat(item.OrderCount, 0);
                                    }
                                    else if (product.c.DepositType == 2)//浮动
                                    {
                                        if (item.Deal == false)
                                            closedeposit = 0.01 * Converter.ToFloat(product.c.CloseDeposit, 0) * (Converter.ToFloat(product.LastClose, 0)) * Converter.ToFloat(product.c.ContractNumber, 0) * Converter.ToFloat(item.OrderCount, 0);
                                        else
                                            closedeposit = 0.01 * Converter.ToFloat(product.c.CloseDeposit, 0) * (Converter.ToFloat(product.LastClose, 0) + Converter.ToFloat(product.c.Fixedly, 0)) * Converter.ToFloat(product.c.ContractNumber, 0) * Converter.ToFloat(item.OrderCount, 0);
                                    }
                                    closedeposit = Converter.ToFloat(closedeposit.ToString("F" + Scale), 0);
                                    #endregion
                                    item.Deposit = Converter.ToFloat((Converter.ToFloat(item.Deposit, 0) + closedeposit).ToString("F" + Scale), 0);
                                    double LastClose = 0.0;       //市场价 收盘价
                                    double Spread = 0.0;        //点数
                                    //计算盈亏
                                    if (item.Deal == false)//卖出
                                    {
                                        LastClose = Converter.ToFloat(product.LastClose, 0) + Converter.ToFloat(product.c.Fixedly, 0);
                                        Spread = Converter.ToFloat(item.OpenPrice, 0) - LastClose;
                                    }
                                    else if (item.Deal == true)//买入
                                    {
                                        LastClose = Converter.ToFloat(product.LastClose, 0);
                                        Spread = LastClose - Converter.ToFloat(item.OpenPrice, 0);
                                    }
                                    item.Spread = Converter.ToFloat(Spread.ToString("F" + Scale), 0);
                                    item.ProfitAndLoss = Converter.ToFloat((Converter.ToFloat(Spread * item.OrderCount, 0) * Converter.ToFloat(product.c.ContractNumber, 0)).ToString("F" + Scale), 0);
                                    item.NowPrice = Converter.ToFloat(LastClose.ToString("F" + Scale), 0);
                                    item.NetProfit = Converter.ToFloat((Converter.ToFloat(item.ProfitAndLoss, 0) - Converter.ToFloat(item.Deposit, 0) - Converter.ToFloat(item.Interest, 0)).ToString("F" + Scale), 0);
                                    item.UpdateTime = nowdate;
                                    item.OrderState = 2;
                                    item.OrderType = 2;
                                    item.CloseType = "授权平仓";
                                    var user = (from c in db.TRealAccounts where c.ID == item.TRealAccountsID select c).FirstOrDefault();

                                    try
                                    {
                                        var agent = (from c in db.TAgents
                                                     join b in db.TAgentGroup on c.GroupID equals b.ID
                                                     where c.ID == user.AgendID
                                                     select new
                                                     {
                                                         c.ID,
                                                         c.DirectAgentID,
                                                         c.Depth,
                                                         c.HeadRate1,
                                                         c.ProcessRate1,
                                                         c.InterestRate1,
                                                         c.HeadRate2,
                                                         c.ProcessRate2,
                                                         c.InterestRate2,
                                                         c.HeadRate3,
                                                         c.ProcessRate3,
                                                         c.InterestRate3,
                                                         c.HeadRate4,
                                                         c.ProcessRate4,
                                                         c.InterestRate4,
                                                         c.HeadRate5,
                                                         c.ProcessRate5,
                                                         c.InterestRate5,
                                                         GID = b.ID,
                                                         b.GroupName,
                                                         b.ProcessRate,
                                                         b.HeadRate,
                                                         b.InterestRate,
                                                         b.NextRate
                                                     }).FirstOrDefault();

                                        #region 分成
                                        if (agent != null)
                                        {
                                            //查询客户所属会员的分成
                                            double HeadRate = Convert.ToDouble(Converter.ToFloat(agent.HeadRate, 0).ToString("F4")) * 0.01;
                                            double ProcessRate = Convert.ToDouble(Converter.ToFloat(agent.ProcessRate, 0).ToString("F4")) * 0.01;
                                            double InterestRate = Convert.ToDouble(Converter.ToFloat(agent.InterestRate, 0).ToString("F4")) * 0.01;
                                            //计算分成
                                            double HeadInfo = Convert.ToDouble((Converter.ToFloat(item.ProfitAndLoss, 0) * HeadRate * -1).ToString("F4"));
                                            double ProcessInfo = Convert.ToDouble((Converter.ToFloat(item.Deposit, 0) * ProcessRate).ToString("F4"));
                                            double InterestInfo = Convert.ToDouble((Converter.ToFloat(item.Interest, 0) * InterestRate).ToString("F4"));

                                            TAgentRate tar = new TAgentRate();
                                            tar.HeadRate = HeadInfo.ToString();
                                            tar.ProcessRate = ProcessInfo.ToString();
                                            tar.InterestRate = InterestInfo.ToString();
                                            tar.AllRate = (HeadInfo + ProcessInfo + InterestInfo).ToString();
                                            tar.NextHeadRate = "0";
                                            tar.NextProcessRate = "0";
                                            tar.NextInterestRate = "0";
                                            tar.NextAllRate = "0";
                                            tar.Date = DateTime.Now;
                                            tar.TAgentId = agent.ID;
                                            tar.TOrderId = item.ID;

                                            IList<TAgentRate> tarlist = new List<TAgentRate>();
                                            int depth = agent.Depth;//深度
                                            if (depth > 6)
                                                depth = 6;
                                            var ag = (from c in db.TAgents where c.ID == agent.ID select c).FirstOrDefault();
                                            var age = ag;
                                            for (int i = 1; i < depth; i++)
                                            {
                                                if (i == 1)
                                                {
                                                    //会员的分成
                                                    HeadRate = Convert.ToDouble(Converter.ToFloat(age.HeadRate1, 0).ToString("F4")) * 0.01;
                                                    ProcessRate = Convert.ToDouble(Converter.ToFloat(age.ProcessRate1, 0).ToString("F4")) * 0.01;
                                                    InterestRate = Convert.ToDouble(Converter.ToFloat(age.ProcessRate1, 0).ToString("F4")) * 0.01;
                                                    //计算分成
                                                    var HeadInfo_ = Convert.ToDouble((Converter.ToFloat(item.ProfitAndLoss, 0) * HeadRate * -1).ToString("F4"));
                                                    var ProcessInfo_ = Convert.ToDouble((Converter.ToFloat(item.Deposit, 0) * ProcessRate).ToString("F4"));
                                                    var InterestInfo_ = Convert.ToDouble((Converter.ToFloat(item.Interest, 0) * InterestRate).ToString("F4"));

                                                    TAgentRate tars = new TAgentRate();
                                                    tars.HeadRate = "0";
                                                    tars.ProcessRate = "0";
                                                    tars.InterestRate = "0";
                                                    tars.AllRate = "0";
                                                    tars.NextHeadRate = HeadInfo_.ToString();
                                                    tars.NextProcessRate = ProcessInfo_.ToString();
                                                    tars.NextInterestRate = InterestInfo_.ToString();
                                                    tars.NextAllRate = (HeadInfo_ + ProcessInfo_ + InterestInfo_).ToString();
                                                    tars.Date = DateTime.Now;
                                                    tars.TAgentId = ag.DirectAgentID;
                                                    tars.TOrderId = item.ID;
                                                    tarlist.Add(tars);
                                                    tar.HeadRate = (Convert.ToDouble(tar.HeadRate) - HeadInfo_).ToString("F4");
                                                    tar.ProcessRate = (Convert.ToDouble(tar.ProcessRate) - ProcessInfo_).ToString("F4");
                                                    tar.InterestRate = (Convert.ToDouble(tar.InterestRate) - InterestInfo_).ToString("F4");
                                                    tar.AllRate = (Convert.ToDouble(tar.AllRate) - (HeadInfo_ + ProcessInfo_ + InterestInfo_)).ToString("F4");
                                                }
                                                else if (i == 2)
                                                {
                                                    //会员的分成
                                                    HeadRate = Convert.ToDouble(Converter.ToFloat(age.HeadRate2, 0).ToString("F4")) * 0.01;
                                                    ProcessRate = Convert.ToDouble(Converter.ToFloat(age.ProcessRate2, 0).ToString("F4")) * 0.01;
                                                    InterestRate = Convert.ToDouble(Converter.ToFloat(age.ProcessRate2, 0).ToString("F4")) * 0.01;
                                                    //计算分成
                                                    var HeadInfo_ = Convert.ToDouble((Converter.ToFloat(item.ProfitAndLoss, 0) * HeadRate * -1).ToString("F4"));
                                                    var ProcessInfo_ = Convert.ToDouble((Converter.ToFloat(item.Deposit, 0) * ProcessRate).ToString("F4"));
                                                    var InterestInfo_ = Convert.ToDouble((Converter.ToFloat(item.Interest, 0) * InterestRate).ToString("F4"));

                                                    TAgentRate tars = new TAgentRate();
                                                    tars.HeadRate = "0";
                                                    tars.ProcessRate = "0";
                                                    tars.InterestRate = "0";
                                                    tars.AllRate = "0";
                                                    tars.NextHeadRate = HeadInfo_.ToString();
                                                    tars.NextProcessRate = ProcessInfo_.ToString();
                                                    tars.NextInterestRate = InterestInfo_.ToString();
                                                    tars.NextAllRate = (HeadInfo_ + ProcessInfo_ + InterestInfo_).ToString();
                                                    tars.Date = DateTime.Now;
                                                    tars.TAgentId = ag.DirectAgentID;
                                                    tars.TOrderId = item.ID;
                                                    tarlist.Add(tars);
                                                    tar.HeadRate = (Convert.ToDouble(tar.HeadRate) - HeadInfo_).ToString("F4");
                                                    tar.ProcessRate = (Convert.ToDouble(tar.ProcessRate) - ProcessInfo_).ToString("F4");
                                                    tar.InterestRate = (Convert.ToDouble(tar.InterestRate) - InterestInfo_).ToString("F4");
                                                    tar.AllRate = (Convert.ToDouble(tar.AllRate) - (HeadInfo_ + ProcessInfo_ + InterestInfo_)).ToString("F4");
                                                }
                                                else if (i == 3)
                                                {
                                                    //会员的分成
                                                    HeadRate = Convert.ToDouble(Converter.ToFloat(age.HeadRate3, 0).ToString("F4")) * 0.01;
                                                    ProcessRate = Convert.ToDouble(Converter.ToFloat(age.ProcessRate3, 0).ToString("F4")) * 0.01;
                                                    InterestRate = Convert.ToDouble(Converter.ToFloat(age.ProcessRate3, 0).ToString("F4")) * 0.01;
                                                    //计算分成
                                                    var HeadInfo_ = Convert.ToDouble((Converter.ToFloat(item.ProfitAndLoss, 0) * HeadRate * -1).ToString("F4"));
                                                    var ProcessInfo_ = Convert.ToDouble((Converter.ToFloat(item.Deposit, 0) * ProcessRate).ToString("F4"));
                                                    var InterestInfo_ = Convert.ToDouble((Converter.ToFloat(item.Interest, 0) * InterestRate).ToString("F4"));

                                                    TAgentRate tars = new TAgentRate();
                                                    tars.HeadRate = "0";
                                                    tars.ProcessRate = "0";
                                                    tars.InterestRate = "0";
                                                    tars.AllRate = "0";
                                                    tars.NextHeadRate = HeadInfo_.ToString();
                                                    tars.NextProcessRate = ProcessInfo_.ToString();
                                                    tars.NextInterestRate = InterestInfo_.ToString();
                                                    tars.NextAllRate = (HeadInfo_ + ProcessInfo_ + InterestInfo_).ToString();
                                                    tars.Date = DateTime.Now;
                                                    tars.TAgentId = ag.DirectAgentID;
                                                    tars.TOrderId = item.ID;
                                                    tarlist.Add(tars);
                                                    tar.HeadRate = (Convert.ToDouble(tar.HeadRate) - HeadInfo_).ToString("F4");
                                                    tar.ProcessRate = (Convert.ToDouble(tar.ProcessRate) - ProcessInfo_).ToString("F4");
                                                    tar.InterestRate = (Convert.ToDouble(tar.InterestRate) - InterestInfo_).ToString("F4");
                                                    tar.AllRate = (Convert.ToDouble(tar.AllRate) - (HeadInfo_ + ProcessInfo_ + InterestInfo_)).ToString("F4");
                                                }
                                                else if (i == 4)
                                                {
                                                    //会员的分成
                                                    HeadRate = Convert.ToDouble(Converter.ToFloat(age.HeadRate4, 0).ToString("F4")) * 0.01;
                                                    ProcessRate = Convert.ToDouble(Converter.ToFloat(age.ProcessRate4, 0).ToString("F4")) * 0.01;
                                                    InterestRate = Convert.ToDouble(Converter.ToFloat(age.ProcessRate4, 0).ToString("F4")) * 0.01;
                                                    //计算分成
                                                    var HeadInfo_ = Convert.ToDouble((Converter.ToFloat(item.ProfitAndLoss, 0) * HeadRate * -1).ToString("F4"));
                                                    var ProcessInfo_ = Convert.ToDouble((Converter.ToFloat(item.Deposit, 0) * ProcessRate).ToString("F4"));
                                                    var InterestInfo_ = Convert.ToDouble((Converter.ToFloat(item.Interest, 0) * InterestRate).ToString("F4"));

                                                    TAgentRate tars = new TAgentRate();
                                                    tars.HeadRate = "0";
                                                    tars.ProcessRate = "0";
                                                    tars.InterestRate = "0";
                                                    tars.AllRate = "0";
                                                    tars.NextHeadRate = HeadInfo_.ToString();
                                                    tars.NextProcessRate = ProcessInfo_.ToString();
                                                    tars.NextInterestRate = InterestInfo_.ToString();
                                                    tars.NextAllRate = (HeadInfo_ + ProcessInfo_ + InterestInfo_).ToString();
                                                    tars.Date = DateTime.Now;
                                                    tars.TAgentId = ag.DirectAgentID;
                                                    tars.TOrderId = item.ID;
                                                    tarlist.Add(tars);
                                                    tar.HeadRate = (Convert.ToDouble(tar.HeadRate) - HeadInfo_).ToString("F4");
                                                    tar.ProcessRate = (Convert.ToDouble(tar.ProcessRate) - ProcessInfo_).ToString("F4");
                                                    tar.InterestRate = (Convert.ToDouble(tar.InterestRate) - InterestInfo_).ToString("F4");
                                                    tar.AllRate = (Convert.ToDouble(tar.AllRate) - (HeadInfo_ + ProcessInfo_ + InterestInfo_)).ToString("F4");
                                                }
                                                else if (i == 5)
                                                {
                                                    //会员的分成
                                                    HeadRate = Convert.ToDouble(Converter.ToFloat(age.HeadRate5, 0).ToString("F4")) * 0.01;
                                                    ProcessRate = Convert.ToDouble(Converter.ToFloat(age.ProcessRate5, 0).ToString("F4")) * 0.01;
                                                    InterestRate = Convert.ToDouble(Converter.ToFloat(age.ProcessRate5, 0).ToString("F4")) * 0.01;
                                                    //计算分成
                                                    var HeadInfo_ = Convert.ToDouble((Converter.ToFloat(item.ProfitAndLoss, 0) * HeadRate * -1).ToString("F4"));
                                                    var ProcessInfo_ = Convert.ToDouble((Converter.ToFloat(item.Deposit, 0) * ProcessRate).ToString("F4"));
                                                    var InterestInfo_ = Convert.ToDouble((Converter.ToFloat(item.Interest, 0) * InterestRate).ToString("F4"));

                                                    TAgentRate tars = new TAgentRate();
                                                    tars.HeadRate = "0";
                                                    tars.ProcessRate = "0";
                                                    tars.InterestRate = "0";
                                                    tars.AllRate = "0";
                                                    tars.NextHeadRate = HeadInfo_.ToString();
                                                    tars.NextProcessRate = ProcessInfo_.ToString();
                                                    tars.NextInterestRate = InterestInfo_.ToString();
                                                    tars.NextAllRate = (HeadInfo_ + ProcessInfo_ + InterestInfo_).ToString();
                                                    tars.Date = DateTime.Now;
                                                    tars.TAgentId = ag.DirectAgentID;
                                                    tars.TOrderId = item.ID;
                                                    tarlist.Add(tars);
                                                    tar.HeadRate = (Convert.ToDouble(tar.HeadRate) - HeadInfo_).ToString("F4");
                                                    tar.ProcessRate = (Convert.ToDouble(tar.ProcessRate) - ProcessInfo_).ToString("F4");
                                                    tar.InterestRate = (Convert.ToDouble(tar.InterestRate) - InterestInfo_).ToString("F4");
                                                    tar.AllRate = (Convert.ToDouble(tar.AllRate) - (HeadInfo_ + ProcessInfo_ + InterestInfo_)).ToString("F4");
                                                }
                                                ag = (from c in db.TAgents where c.ID == ag.DirectAgentID select c).FirstOrDefault();
                                            }
                                            tarlist.Add(tar);
                                            db.TAgentRate.InsertAllOnSubmit(tarlist);
                                            db.SubmitChanges();

                                            //AgentRate ar = new AgentRate();
                                            //ar.Id = agent.ID;
                                            //ar.DirectAgentID = Converter.ToInt(agent.DirectAgentID, 0);
                                            //ar.Groupid = agent.GID;
                                            //ar.Num = 0;
                                            //ar.HeadInfo = HeadInfo;
                                            //ar.ProcessInfo = ProcessInfo;
                                            //ar.InterestInfo = InterestInfo;
                                            //ar.NextheadInfo = HeadInfo;
                                            //ar.NextprocessInfo = ProcessInfo;
                                            //ar.NextinterestInfo = InterestInfo;
                                            //if (ar.DirectAgentID > 0)
                                            //{
                                            //    Converter.GetAgent(ar, ar, item.ID);
                                            //}
                                            //ar.HeadInfo = ar.NextheadInfo;
                                            //ar.ProcessInfo = ar.NextprocessInfo;
                                            //ar.InterestInfo = ar.NextinterestInfo;
                                            //ar.NextheadInfo = 0;
                                            //ar.NextprocessInfo = 0;
                                            //ar.NextinterestInfo = 0;

                                            //APIDataDataContext db2 = ConnectionHelper.Db;
                                            //{
                                            //    TAgentRate tar = new TAgentRate();
                                            //    tar.HeadRate = ar.HeadInfo.ToString();
                                            //    tar.ProcessRate = ar.ProcessInfo.ToString();
                                            //    tar.InterestRate = ar.InterestInfo.ToString();
                                            //    tar.AllRate = (ar.HeadInfo + ar.ProcessInfo + ar.InterestInfo).ToString();
                                            //    tar.NextHeadRate = ar.NextheadInfo.ToString();
                                            //    tar.NextProcessRate = ar.NextprocessInfo.ToString();
                                            //    tar.NextInterestRate = ar.NextinterestInfo.ToString();
                                            //    tar.NextAllRate = (ar.NextheadInfo + ar.NextprocessInfo + ar.NextinterestInfo).ToString();
                                            //    tar.Date = DateTime.Now;
                                            //    tar.TAgentId = agent.ID;
                                            //    tar.TOrderId = item.ID;
                                            //    db2.TAgentRate.InsertOnSubmit(tar);
                                            //    db2.SubmitChanges();
                                            //}
                                        }
                                        #endregion
                                    }
                                    catch
                                    {
                                    }

                                    #region 资金记录
                                    TAccountMoney tam = new TAccountMoney();
                                    tam.MoneyOrderNum = DateTime.Now.ToString("yyyyMMddHHmmssfff");
                                    tam.RealAccountId = Converter.ToInt(item.TRealAccountsID, 0);
                                    tam.TypeId = 4;
                                    tam.OriginalMoney = user.AccountMoney;
                                    tam.CreateMoney = item.ProfitAndLoss;
                                    tam.NowMoney = user.AccountMoney + item.ProfitAndLoss;
                                    if (tam.NowMoney < 0)
                                    {
                                        tam.NowMoney = 0;
                                    }
                                    tam.CreateTime = nowdate;
                                    tam.UpDateTime = nowdate;
                                    tam.Status = 2;
                                    tam.TOrderId = item.ID;
                                    db.TAccountMoney.InsertOnSubmit(tam);

                                    TAccountMoney tams = new TAccountMoney();
                                    tams.MoneyOrderNum = DateTime.Now.ToString("yyyyMMddHHmmssfff");
                                    tams.RealAccountId = Converter.ToInt(item.TRealAccountsID, 0);
                                    tams.TypeId = 5;
                                    tams.OriginalMoney = tam.NowMoney;
                                    tams.CreateMoney = item.Deposit;
                                    tams.NowMoney = tam.NowMoney - item.Deposit;
                                    if (tams.NowMoney < 0)
                                    {
                                        tams.NowMoney = 0;
                                    }
                                    tams.CreateTime = nowdate;
                                    tams.UpDateTime = nowdate;
                                    tams.Status = 2;
                                    tams.TOrderId = item.ID;
                                    db.TAccountMoney.InsertOnSubmit(tams);

                                    #endregion
                                    user.AccountMoney = user.AccountMoney + item.ProfitAndLoss - item.Deposit;
                                    if (user.AccountMoney < 0)
                                    {
                                        user.AccountMoney = 0;
                                    }
                                    db.SubmitChanges();
                                    OLog.UpdateValue = ObjectToJson.ModelToJson(order);
                                    //写入操作日志
                                    OLog.PageName = "平仓";
                                    Converter.InsertOperationLog(OLog);
                                    return Json(new { code = "1", msg = "提交成功!" });
                                }
                                else
                                {
                                    return Json(new { code = "0", msg = "订单id不正确!" });
                                }
                            }
                            else
                            {
                                return Json(new { code = "0", msg = "订单id不正确!" });
                            }
                            #endregion
                        }
                    }
                    else
                    {
                        return Json(new { code = "0", msg = "提交失败请稍后在试!" });
                    }
                }
                else
                {
                    //添加
                    #region 添加
                    TOrders to = new TOrders();
                    to.OrderNum = DateTime.Now.ToString("yyyyMMddHHmmssfff");
                    to.ProductID = Converter.ToInt(ProductID, 0);
                    to.TRealAccountsID = TRealAccountsID;
                    to.Deal = Deal == "1" ? true : false;
                    to.OrderCount = Converter.ToInt(OrderCount, 0);
                    to.OpenPrice = Converter.ToFloat(OpenPrice, 0);
                    to.Profit = Converter.ToFloat(Profit, 0);
                    to.Loss = Converter.ToFloat(Loss, 0);
                    to.NowPrice = Converter.ToFloat(NowPrice, 0);
                    to.Deposit = Converter.ToFloat(Deposit, 0);
                    to.Interest = 0;
                    double nowbaozhengjin = 0;
                    var product = (from c in db.TProducts where c.ID == Converter.ToInt(ProductID, 0) select c).FirstOrDefault();
                    int OccupyFundsType = product.OccupyFundsType.Value;    //保证金方式(每单必须有的保证金) 1固定(每笔统一价) 2浮动(按照交易金额的百分比来算)
                    double OccupyFunds = Converter.ToFloat(product.OccupyFunds, 0);         //保证金   固定(固定值*手数)   浮动(开仓价*固定值*手数)
                    if (OccupyFundsType == 1)
                        nowbaozhengjin = OccupyFunds * product.ContractNumber.Value * Converter.ToInt(OrderCount, 0);
                    else
                        nowbaozhengjin = 0.01 * OccupyFunds * product.ContractNumber.Value * Converter.ToFloat(NowPrice, 0) * Converter.ToInt(OrderCount, 0);
                    to.OccupyFunds = nowbaozhengjin;
                    to.OpenTime = Convert.ToDateTime(OpenTime);
                    to.UpdateTime = DateTime.Now;
                    try
                    {
                        to.OperatorIP = GetUserIp;
                    }
                    catch
                    {
                        return Json(new { code = "0", msg = "服务器内部错误!" });
                    }
                    to.OrderState = 1;
                    to.OrderType = 1;
                    to.EntrustType = 0;
                    db.TOrders.InsertOnSubmit(to);
                    db.SubmitChanges();
                    return Json(new { code = "1", msg = "提交成功!" });
                    #endregion
                }
            }
            catch
            {
                return Json(new { code = "0", msg = "服务器内部错误!" });
            }
        }
Exemplo n.º 4
0
        public ActionResult PostCommission()
        {
            APIDataDataContext db = APIDataContextProxy.APIDB;
            int id = 0;  //Id
            string name = ""; //登陆名
            string Type = "";  //type
            string msg = "";  //提示信息
            bool fruit = false;  //结果
            TOperationLog OLog = new TOperationLog();
            OLog.PageName = "会员资金审核";
            try
            {
                var agentid = Request["agentid"];
                var createdate = Request["createdate"];

                var Yjtc = Convert.ToDouble(Converter.ToFloat(Request["Yjtc"], 0).ToString("f4"));
                var Yjjgf = Convert.ToDouble(Converter.ToFloat(Request["Yjjgf"], 0).ToString("f4"));
                var Yjcx = Convert.ToDouble(Converter.ToFloat(Request["Yjcx"], 0).ToString("f4"));
                var Yjxj = Convert.ToDouble(Converter.ToFloat(Request["Yjxj"], 0).ToString("f4"));

                var allrate = Convert.ToDouble(Converter.ToFloat(Request["allrate"], 0).ToString("f4"));

                TAgentCommission tac = new TAgentCommission();
                tac.agentid = Convert.ToInt32(agentid);
                tac.createdate = Convert.ToDateTime(createdate);
                db.TAgentCommission.InsertOnSubmit(tac);

                var ag = (from c in db.TAgents where c.ID == Convert.ToInt32(agentid) select c).FirstOrDefault();

                #region 资金记录

                TAccountMoney tam = new TAccountMoney();
                tam.MoneyOrderNum = DateTime.Now.ToString("yyyyMMddHHmmssfff");
                tam.AgentId = ag.ID;
                tam.TypeId = 4;
                tam.OriginalMoney = ag.AccountMoney;
                tam.CreateMoney = Yjtc;
                tam.NowMoney = ag.AccountMoney + Yjtc;
                if (tam.NowMoney < 0)
                {
                    tam.NowMoney = 0;
                }
                tam.CreateTime = Convert.ToDateTime(createdate);
                tam.UpDateTime = Convert.ToDateTime(createdate);
                tam.Status = 2;
                tam.TOrderId = 0;
                db.TAccountMoney.InsertOnSubmit(tam);

                TAccountMoney tams = new TAccountMoney();
                tams.MoneyOrderNum = DateTime.Now.ToString("yyyyMMddHHmmssfff");
                tams.AgentId = ag.ID;
                tams.TypeId = 5;
                tams.OriginalMoney = tam.NowMoney;
                tams.CreateMoney = Yjjgf;
                tams.NowMoney = tam.NowMoney + Yjjgf;
                if (tams.NowMoney < 0)
                {
                    tams.NowMoney = 0;
                }
                tams.CreateTime = Convert.ToDateTime(createdate);
                tams.UpDateTime = Convert.ToDateTime(createdate);
                tams.Status = 2;
                tams.TOrderId = 0;
                db.TAccountMoney.InsertOnSubmit(tams);

                TAccountMoney tams1 = new TAccountMoney();
                tams1.MoneyOrderNum = DateTime.Now.ToString("yyyyMMddHHmmssfff");
                tams1.AgentId = ag.ID;
                tams1.TypeId = 6;
                tams1.OriginalMoney = tams.NowMoney;
                tams1.CreateMoney = Yjcx;
                tams1.NowMoney = tams.NowMoney + Yjcx;
                if (tams1.NowMoney < 0)
                {
                    tams1.NowMoney = 0;
                }
                tams1.CreateTime = Convert.ToDateTime(createdate);
                tams1.UpDateTime = Convert.ToDateTime(createdate);
                tams1.Status = 2;
                tams1.TOrderId = 0;
                db.TAccountMoney.InsertOnSubmit(tams1);

                TAccountMoney tams2 = new TAccountMoney();
                tams2.MoneyOrderNum = DateTime.Now.ToString("yyyyMMddHHmmssfff");
                tams2.AgentId = ag.ID;
                tams2.TypeId = 7;
                tams2.OriginalMoney = tams1.NowMoney;
                tams2.CreateMoney = Yjxj;
                tams2.NowMoney = tams1.NowMoney + Yjxj;
                if (tams2.NowMoney < 0)
                {
                    tams2.NowMoney = 0;
                }
                tams2.CreateTime = Convert.ToDateTime(createdate);
                tams2.UpDateTime = Convert.ToDateTime(createdate);
                tams2.Status = 2;
                tams2.TOrderId = 0;
                db.TAccountMoney.InsertOnSubmit(tams2);

                #endregion

                ag.AccountMoney = ag.AccountMoney + Yjtc + Yjjgf + Yjcx + Yjxj;

                db.SubmitChanges();

                var total = allrate + Yjxj;
                StringBuilder sb = new StringBuilder();

                sb.Append("{")
                    .AppendFormat(
                        "\"会员金额\":\"{0}\",\"分红\":\"{1}\",\"加工费\":\"{2}\",\"仓息\":\"{3}\",\"本级汇总\":\"{4}\",\"下级汇总\":\"{5}\",\"总计\":\"{6}\"" +
                        "", ag.AccountMoney, Yjtc, Yjjgf, Yjcx, allrate, Yjxj, total).Append("}");

                OLog.UpdateValue = sb.ToString();
                OLog.BeforeValue = "";
                //写入操作日志
                OLog.UserID = Convert.ToInt32(Session["ID"]);
                OLog.UserType = 2;//0 用户 1 会员 2 员工
                OLog.CreateDate = DateTime.Now;
                Converter.InsertOperationLog(OLog);
                //存入日志
                id = Convert.ToInt32(Session["ID"]); //id
                Type = Session["Type"].ToString();  //类型
                msg = "修改会员账户金额";
                fruit = true;
                Converter.InsertLog(id, name, Type, msg, fruit);

                return Content("true");
            }
            catch
            {

                //存入日志
                id = Convert.ToInt32(Session["ID"]); //id
                Type = Session["Type"].ToString();  //类型
                msg = "修改会员账户金额";
                fruit = false;
                Converter.InsertLog(id, name, Type, msg, fruit);

                return Content("false");
            }
        }
Exemplo n.º 5
0
        /// <summary>
        /// 调整资金
        /// </summary>
        /// <param name="type">0表示客户,1表示会员</param>
        /// <param name="createMoney">调整金额</param>
        /// <param name="id">客户或会员的ID</param>
        /// <param name="typeid">存款或取款</param>
        /// <returns></returns>
        public ActionResult MoneyChange(int type, double createMoney, int id, int typeid)
        {
            APIDataDataContext db = APIDataContextProxy.APIDB;
            {
                try
                {
                    TRealAccounts realAccount = new TRealAccounts();
                    TAgents agent = new TAgents();
                    TOperationLog OLog = new TOperationLog();
                    OLog.BeforeValue = "";
                    TAccountMoney accountMoney = new TAccountMoney() { CreateMoney = createMoney, TypeId = typeid, CreateTime = DateTime.Now, Status = 2, BankState=1,PlatformState=1,Examine=1 };
                    if (type == 0)
                    {
                        realAccount = db.TRealAccounts.Where(t => t.ID == id).FirstOrDefault();
                        accountMoney.OriginalMoney = realAccount.AccountMoney;
                        accountMoney.NowMoney = realAccount.AccountMoney + (typeid == 1 ? createMoney : (-1) * createMoney);
                        accountMoney.RealAccountId = id;
                        realAccount.AccountMoney = accountMoney.NowMoney;
                        if (typeid == 3 && realAccount.AccountMoney < 0)
                        {
                            return Json("余额不足!");
                        }
                    }
                    else
                    {
                        agent = db.TAgents.Where(t => t.ID == id).FirstOrDefault();
                        accountMoney.OriginalMoney = agent.AccountMoney;
                        accountMoney.NowMoney = agent.AccountMoney + (typeid == 1 ? createMoney : (-1) * createMoney);
                        accountMoney.AgentId = id;
                        agent.AccountMoney = (double)accountMoney.NowMoney;
                        if (typeid == 3 && agent.AccountMoney < 0)
                        {
                            return Json("余额不足!");
                        }
                    }
                    db.TAccountMoney.InsertOnSubmit(accountMoney);
                    db.SubmitChanges();
                    OLog.UpdateValue = ObjectToJson.ModelToJson(accountMoney);

                    //写入操作日志
                    OLog.UserID = Convert.ToInt32(Session["ID"]);
                    OLog.UserType = 2;//0 用户 1 会员 2 员工
                    OLog.CreateDate = DateTime.Now;
                    OLog.PageName = "调整金额";
                    Converter.InsertOperationLog(OLog);
                    return Json(1);

                }
                catch
                {
                    return Json("服务器内部错误!");
                }
            }
        }
Exemplo n.º 6
0
        private bool CloseAllOrder(List<TOrders> orderList, APIDataDataContext db)
        {
            try
            {
                TOperationLog OLog = new TOperationLog();
                if (orderList.Count > 0)
                {

                    StringBuilder beforevalue=new StringBuilder();
                    beforevalue.Append("{\"IDlist\":[");
                    foreach (var item in orderList)
                    {
                        beforevalue.Append("{");
                        beforevalue.AppendFormat("\"id\":\"{0}\"", item.ID);
                        beforevalue.Append("},");
                        var product = (from c in db.TProducts
                                       join b in db.TLastClose on c.ProductCode equals b.ProductCode
                                       where c.ID == item.ProductID
                                       orderby c.ID
                                       select new
                                       {
                                           c,
                                           b.LastClose,
                                           b.LastUpdateTime
                                       }).FirstOrDefault();
                        if (product != null)
                        {
                            var Scale = Converter.ToFloat(product.c.Scale, 2);
                            var nowdate = product.LastUpdateTime;
                            #region 加工费
                            double closedeposit = 0.0;   //加工费
                            if (product.c.DepositType == 1)//固定
                            {
                                closedeposit = Converter.ToFloat(product.c.CloseDeposit, 0) * Converter.ToFloat(product.c.ContractNumber, 0) * Converter.ToFloat(item.OrderCount, 0);
                            }
                            else if (product.c.DepositType == 2)//浮动
                            {
                                if (item.Deal == false)
                                    closedeposit = 0.01 * Converter.ToFloat(product.c.CloseDeposit, 0) * (Converter.ToFloat(product.LastClose, 0)) * Converter.ToFloat(product.c.ContractNumber, 0) * Converter.ToFloat(item.OrderCount, 0);
                                else
                                    closedeposit = 0.01 * Converter.ToFloat(product.c.CloseDeposit, 0) * (Converter.ToFloat(product.LastClose, 0) + Converter.ToFloat(product.c.Fixedly, 0)) * Converter.ToFloat(product.c.ContractNumber, 0) * Converter.ToFloat(item.OrderCount, 0);
                            }
                            closedeposit = Converter.ToFloat(closedeposit.ToString("F" + Scale), 0);
                            #endregion
                            item.Deposit = Converter.ToFloat((Converter.ToFloat(item.Deposit, 0) + closedeposit).ToString("F" + Scale), 0);
                            //double LastClose = 0.0;       //市场价 收盘价
                            //double Spread = 0.0;        //点数
                            //计算盈亏
                            //if (item.Deal == false)//卖出
                            //{
                            //    LastClose = Converter.ToFloat(product.LastClose, 0) + Converter.ToFloat(product.c.Fixedly, 0);
                            //    Spread = Converter.ToFloat(item.OpenPrice, 0) - LastClose;
                            //}
                            //else if (item.Deal == true && item.Profit > 0)//买入
                            //{
                            //    LastClose = Converter.ToFloat(product.LastClose, 0);
                            //    Spread = LastClose - Converter.ToFloat(item.OpenPrice, 0);
                            //}
                            //item.Spread = Converter.ToFloat(Spread.ToString("F" + Scale), 0);
                            //item.ProfitAndLoss = Converter.ToFloat((Converter.ToFloat(Spread * item.OrderCount, 0) * Converter.ToFloat(product.c.ContractNumber, 0)).ToString("F" + Scale), 0);
                            //item.NowPrice = Converter.ToFloat(LastClose.ToString("F" + Scale), 0);
                            //item.NetProfit = Converter.ToFloat((Converter.ToFloat(item.ProfitAndLoss, 0) - Converter.ToFloat(item.Deposit, 0) - Converter.ToFloat(item.Interest, 0)).ToString("F" + Scale), 0);
                            item.CloseType = "清算/交割";
                            item.UpdateTime = nowdate;
                            item.OrderState = 2;
                            item.OrderType = 2;

                            var user = (from c in db.TRealAccounts where c.ID == item.TRealAccountsID select c).FirstOrDefault();
                            if (user==null)
                            {
                                db.TOrders.DeleteOnSubmit(item);
                            }
                            else
                            {
                            #region 资金记录
                            TAccountMoney tam = new TAccountMoney();
                            tam.MoneyOrderNum = DateTime.Now.ToString("yyyyMMddHHmmssfff");
                            tam.RealAccountId = Converter.ToInt(item.TRealAccountsID, 0);
                            tam.TypeId = 4;
                            tam.OriginalMoney = user.AccountMoney;
                            tam.CreateMoney = item.ProfitAndLoss;
                            tam.NowMoney = user.AccountMoney + item.ProfitAndLoss;
                            if (tam.NowMoney<0)
                            {
                                tam.NowMoney = 0;
                            }
                            tam.CreateTime = nowdate;
                            tam.UpDateTime = nowdate;
                            tam.Status = 2;
                            tam.TOrderId = item.ID;
                            db.TAccountMoney.InsertOnSubmit(tam);

                            TAccountMoney tams = new TAccountMoney();
                            tams.MoneyOrderNum = DateTime.Now.ToString("yyyyMMddHHmmssfff");
                            tams.RealAccountId = Converter.ToInt(item.TRealAccountsID, 0);
                            tams.TypeId = 5;
                            tams.OriginalMoney = tam.NowMoney;
                            tams.CreateMoney = item.Deposit;
                            tams.NowMoney = tam.NowMoney - item.Deposit;
                            if (tams.NowMoney<0)
                            {
                                tams.NowMoney = 0;
                            }
                            tams.CreateTime = nowdate;
                            tams.UpDateTime = nowdate;
                            tams.Status = 2;
                            tams.TOrderId = item.ID;
                            db.TAccountMoney.InsertOnSubmit(tams);

                            #endregion
                            user.AccountMoney = user.AccountMoney+item.ProfitAndLoss-item.Deposit;
                            if (user.AccountMoney<0)
                            {
                                user.AccountMoney = 0;
                            }
                            }
                            db.SubmitChanges();

                        }
                        else
                        {
                        }
                    }
                    //移除最后一个‘,’
                    beforevalue.Remove(beforevalue.Length - 1, 1);
                    beforevalue.Append("]}");
                    OLog.BeforeValue = beforevalue.ToString();
                    OLog.UpdateValue = "";
                    //写入操作日志
                    OLog.UserID = Convert.ToInt32(Session["ID"]);
                    OLog.UserType = 2;//0 用户 1 会员 2 员工
                    OLog.CreateDate = DateTime.Now;
                    OLog.PageName = "财务清算";
                    Converter.InsertOperationLog(OLog);
                    return true;
                }
                else
                {
                    return false;
                }
            }
            catch
            {
                return false;
            }
        }
Exemplo n.º 7
0
        /// <summary>
        /// 平仓操作
        /// 10050 订单id不正确!
        /// 10051 订单id不正确!
        /// 10052 服务器错误!
        /// </summary>
        /// <returns></returns>
        public string CloseOrder()
        {
            try
            {
                int OrderId = Converter.ToInt(Request["OrderId"], 0);               //订单id
                double ClosePrice = Convert.ToDouble(Request["ClosePrice"]);        //关闭价格
                APIDataDataContext db = APIDataContextProxy.APIDB;
                var item = (from c in db.TOrders
                            where c.ID == OrderId
                            && c.OrderState == 1
                            && c.OrderType == 1
                            select c).FirstOrDefault();

                if (item != null)
                {
                    var product = (from c in db.TProducts
                                   join b in db.TLastClose on c.ProductCode equals b.ProductCode
                                   where c.ID == item.ProductID
                                   orderby c.ID
                                   select new
                                   {
                                       c,
                                       b.LastClose,
                                       b.LastUpdateTime
                                   }).FirstOrDefault();
                    if (product != null)
                    {
                        var OffsetLow = userGroup.OffsetLow;
                        var MinWareTime = userGroup.MinWareTime;

                        #region 允许交易
                        var AllowTrade = userGroup.AllowTrade;                       //允许交易
                        if (AllowTrade == false)
                        {
                            return ErrMsg(10039, "对不起您所在的用户组现在不允许交易!");
                        }
                        TRealAccounts tra = (from c in db.TRealAccounts where c.ID == userid select c).FirstOrDefault();
                        var traAllowTrade = tra.AllowTrade;
                        if (traAllowTrade == false)
                        {
                            return ErrMsg(10039, "对不起您现在不允许交易!");
                        }
                        #endregion
                        if (MinWareTime > 0)
                        {
                            DateTime nowdt = DateTime.Now;
                            try
                            {
                                if ((nowdt - item.OpenTime.Value).TotalSeconds < MinWareTime)
                                {
                                    return ErrMsg(10050, "持仓最少时间为" + MinWareTime + "秒!");
                                }
                            }
                            catch { }
                        }

                        var lastcloseprice = 0.0;
                        if (item.Deal.Value)
                        {
                            lastcloseprice = product.LastClose.Value;
                            if (lastcloseprice - ClosePrice > OffsetLow || ClosePrice - lastcloseprice > OffsetLow)
                            {
                                return ErrMsg(10050, "价格已经改变请重新开仓!");
                            }
                        }
                        else
                        {
                            lastcloseprice = product.c.Fixedly.Value + product.LastClose.Value;
                            if (lastcloseprice - ClosePrice > OffsetLow || ClosePrice - lastcloseprice > OffsetLow)
                            {
                                return ErrMsg(10050, "价格已经改变请重新开仓!");
                            }
                        }
                        ClosePrice = lastcloseprice;
                        var Scale = Converter.ToFloat(product.c.Scale, 2);
                        var nowdate = product.LastUpdateTime;
                        #region 加工费
                        double closedeposit = 0.0;   //加工费
                        if (product.c.DepositType == 1)//固定(设定的值*合约数*手数)
                        {
                            closedeposit = Converter.ToFloat(product.c.CloseDeposit) * Converter.ToFloat(product.c.ContractNumber) * Converter.ToFloat(item.OrderCount);
                        }
                        else if (product.c.DepositType == 2)//浮动(设定的比率*现价*合约数*手数)
                        {
                            if (item.Deal == false)
                                closedeposit = 0.01 * Converter.ToFloat(product.c.CloseDeposit) * (Converter.ToFloat(product.LastClose)) * Converter.ToFloat(product.c.ContractNumber) * Converter.ToFloat(item.OrderCount);
                            else
                                closedeposit = 0.01 * Converter.ToFloat(product.c.CloseDeposit) * (Converter.ToFloat(product.LastClose) + Converter.ToFloat(product.c.Fixedly)) * Converter.ToFloat(product.c.ContractNumber) * Converter.ToFloat(item.OrderCount);
                        }
                        closedeposit = Converter.ToFloat(closedeposit.ToString("F" + Scale));
                        #endregion
                        item.Deposit = Converter.ToFloat((Converter.ToFloat(item.Deposit) + closedeposit).ToString("F" + Scale));//修改加工费
                        double LastClose = 0.0;       //市场价 收盘价
                        double Spread = 0.0;        //点数
                        //计算盈亏
                        if (item.Deal == false)//卖出
                        {
                            LastClose = Converter.ToFloat(product.LastClose) + Converter.ToFloat(product.c.Fixedly);
                            Spread = Converter.ToFloat(item.OpenPrice) - LastClose;
                        }
                        else if (item.Deal == true)//买入
                        {
                            LastClose = Converter.ToFloat(product.LastClose);
                            Spread = LastClose - Converter.ToFloat(item.OpenPrice);
                        }
                        item.Spread = Converter.ToFloat(Spread.ToString("F" + Scale));
                        item.ProfitAndLoss = Converter.ToFloat((Converter.ToFloat(Spread * item.OrderCount) * Converter.ToFloat(product.c.ContractNumber)).ToString("F" + Scale));
                        item.NowPrice = Converter.ToFloat(LastClose.ToString("F" + Scale));
                        item.NetProfit = Converter.ToFloat((Converter.ToFloat(item.ProfitAndLoss) - Converter.ToFloat(item.Deposit) - Converter.ToFloat(item.Interest)).ToString("F" + Scale));
                        item.UpdateTime = nowdate;
                        item.OrderState = 2;
                        item.OrderType = 2;
                        item.CloseType = "人工平仓";

                        var user = (from c in db.TRealAccounts where c.ID == item.TRealAccountsID select c).FirstOrDefault();

                        try
                        {
                            var agent = (from c in db.TAgents
                                         join b in db.TAgentGroup on c.GroupID equals b.ID
                                         where c.ID == user.AgendID
                                         select new
                                         {
                                             c.ID,
                                             c.DirectAgentID,
                                             c.Depth,
                                             c.HeadRate1,
                                             c.ProcessRate1,
                                             c.InterestRate1,
                                             c.HeadRate2,
                                             c.ProcessRate2,
                                             c.InterestRate2,
                                             c.HeadRate3,
                                             c.ProcessRate3,
                                             c.InterestRate3,
                                             c.HeadRate4,
                                             c.ProcessRate4,
                                             c.InterestRate4,
                                             c.HeadRate5,
                                             c.ProcessRate5,
                                             c.InterestRate5,
                                             GID = b.ID,
                                             b.GroupName,
                                             b.ProcessRate,
                                             b.HeadRate,
                                             b.InterestRate,
                                             b.NextRate
                                         }).FirstOrDefault();

                            #region 分成
                            if (agent != null)
                            {
                                //查询客户所属会员的分成
                                double HeadRate = Convert.ToDouble(Converter.ToFloat(agent.HeadRate, 0).ToString("F4")) * 0.01;//直属会员浮动盈亏比率
                                double ProcessRate = Convert.ToDouble(Converter.ToFloat(agent.ProcessRate, 0).ToString("F4")) * 0.01;//加工费比率
                                double InterestRate = Convert.ToDouble(Converter.ToFloat(agent.InterestRate, 0).ToString("F4")) * 0.01;//仓息比率
                                //计算分成
                                double HeadInfo = Convert.ToDouble((Converter.ToFloat(item.ProfitAndLoss, 0) * HeadRate * -1).ToString("F4"));//盈利与客户相反:客户赚钱,会员亏钱
                                double ProcessInfo = Convert.ToDouble((Converter.ToFloat(item.Deposit, 0) * ProcessRate).ToString("F4"));//加工费
                                double InterestInfo = Convert.ToDouble((Converter.ToFloat(item.Interest, 0) * InterestRate).ToString("F4"));//仓息

                                //会员分红相关,跟每笔订单相关
                                TAgentRate tar = new TAgentRate();
                                tar.HeadRate = HeadInfo.ToString();
                                tar.ProcessRate = ProcessInfo.ToString();
                                tar.InterestRate = InterestInfo.ToString();
                                tar.AllRate = (HeadInfo + ProcessInfo + InterestInfo).ToString();
                                tar.NextHeadRate = "0";
                                tar.NextProcessRate = "0";
                                tar.NextInterestRate = "0";
                                tar.NextAllRate = "0";
                                tar.Date = DateTime.Now;
                                tar.TAgentId = agent.ID;
                                tar.TOrderId = item.ID;

                                IList<TAgentRate> tarlist = new List<TAgentRate>();
                                int depth = agent.Depth;//深度
                                if (depth > 6)
                                    depth = 6;
                                var ag = (from c in db.TAgents where c.ID == agent.ID select c).FirstOrDefault();
                                var age = ag;
                                for (int i = 1; i < depth; i++)
                                {
                                    if (i == 1)//直属会员的上1级
                                    {
                                        //会员的分成
                                        HeadRate = Convert.ToDouble(Converter.ToFloat(age.HeadRate1, 0).ToString("F4")) * 0.01;
                                        ProcessRate = Convert.ToDouble(Converter.ToFloat(age.ProcessRate1, 0).ToString("F4")) * 0.01;
                                        InterestRate = Convert.ToDouble(Converter.ToFloat(age.ProcessRate1, 0).ToString("F4")) * 0.01;
                                        //计算分成
                                        var HeadInfo_ = Convert.ToDouble((Converter.ToFloat(item.ProfitAndLoss, 0) * HeadRate * -1).ToString("F4"));
                                        var ProcessInfo_ = Convert.ToDouble((Converter.ToFloat(item.Deposit, 0) * ProcessRate).ToString("F4"));
                                        var InterestInfo_ = Convert.ToDouble((Converter.ToFloat(item.Interest, 0) * InterestRate).ToString("F4"));

                                        TAgentRate tars = new TAgentRate();
                                        tars.HeadRate = "0";
                                        tars.ProcessRate = "0";
                                        tars.InterestRate = "0";
                                        tars.AllRate = "0";
                                        tars.NextHeadRate = HeadInfo_.ToString();
                                        tars.NextProcessRate = ProcessInfo_.ToString();
                                        tars.NextInterestRate = InterestInfo_.ToString();
                                        tars.NextAllRate = (HeadInfo_ + ProcessInfo_ + InterestInfo_).ToString();
                                        tars.Date = DateTime.Now;
                                        tars.TAgentId = ag.DirectAgentID;
                                        tars.TOrderId = item.ID;
                                        tarlist.Add(tars);
                                        tar.HeadRate = (Convert.ToDouble(tar.HeadRate) - HeadInfo_).ToString("F4");
                                        tar.ProcessRate = (Convert.ToDouble(tar.ProcessRate) - ProcessInfo_).ToString("F4");
                                        tar.InterestRate = (Convert.ToDouble(tar.InterestRate) - InterestInfo_).ToString("F4");
                                        tar.AllRate = (Convert.ToDouble(tar.AllRate) - (HeadInfo_ + ProcessInfo_ + InterestInfo_)).ToString("F4");
                                    }
                                    else if (i == 2)//指数会员的上2级
                                    {
                                        //会员的分成
                                        HeadRate = Convert.ToDouble(Converter.ToFloat(age.HeadRate2, 0).ToString("F4")) * 0.01;
                                        ProcessRate = Convert.ToDouble(Converter.ToFloat(age.ProcessRate2, 0).ToString("F4")) * 0.01;
                                        InterestRate = Convert.ToDouble(Converter.ToFloat(age.ProcessRate2, 0).ToString("F4")) * 0.01;
                                        //计算分成
                                        var HeadInfo_ = Convert.ToDouble((Converter.ToFloat(item.ProfitAndLoss, 0) * HeadRate * -1).ToString("F4"));
                                        var ProcessInfo_ = Convert.ToDouble((Converter.ToFloat(item.Deposit, 0) * ProcessRate).ToString("F4"));
                                        var InterestInfo_ = Convert.ToDouble((Converter.ToFloat(item.Interest, 0) * InterestRate).ToString("F4"));

                                        TAgentRate tars = new TAgentRate();
                                        tars.HeadRate = "0";
                                        tars.ProcessRate = "0";
                                        tars.InterestRate = "0";
                                        tars.AllRate = "0";
                                        tars.NextHeadRate = HeadInfo_.ToString();
                                        tars.NextProcessRate = ProcessInfo_.ToString();
                                        tars.NextInterestRate = InterestInfo_.ToString();
                                        tars.NextAllRate = (HeadInfo_ + ProcessInfo_ + InterestInfo_).ToString();
                                        tars.Date = DateTime.Now;
                                        tars.TAgentId = ag.DirectAgentID;
                                        tars.TOrderId = item.ID;
                                        tarlist.Add(tars);
                                        tar.HeadRate = (Convert.ToDouble(tar.HeadRate) - HeadInfo_).ToString("F4");
                                        tar.ProcessRate = (Convert.ToDouble(tar.ProcessRate) - ProcessInfo_).ToString("F4");
                                        tar.InterestRate = (Convert.ToDouble(tar.InterestRate) - InterestInfo_).ToString("F4");
                                        tar.AllRate = (Convert.ToDouble(tar.AllRate) - (HeadInfo_ + ProcessInfo_ + InterestInfo_)).ToString("F4");
                                    }
                                    else if (i == 3)//指数会员的上3级
                                    {
                                        //会员的分成
                                        HeadRate = Convert.ToDouble(Converter.ToFloat(age.HeadRate3, 0).ToString("F4")) * 0.01;
                                        ProcessRate = Convert.ToDouble(Converter.ToFloat(age.ProcessRate3, 0).ToString("F4")) * 0.01;
                                        InterestRate = Convert.ToDouble(Converter.ToFloat(age.ProcessRate3, 0).ToString("F4")) * 0.01;
                                        //计算分成
                                        var HeadInfo_ = Convert.ToDouble((Converter.ToFloat(item.ProfitAndLoss, 0) * HeadRate * -1).ToString("F4"));
                                        var ProcessInfo_ = Convert.ToDouble((Converter.ToFloat(item.Deposit, 0) * ProcessRate).ToString("F4"));
                                        var InterestInfo_ = Convert.ToDouble((Converter.ToFloat(item.Interest, 0) * InterestRate).ToString("F4"));

                                        TAgentRate tars = new TAgentRate();
                                        tars.HeadRate = "0";
                                        tars.ProcessRate = "0";
                                        tars.InterestRate = "0";
                                        tars.AllRate = "0";
                                        tars.NextHeadRate = HeadInfo_.ToString();
                                        tars.NextProcessRate = ProcessInfo_.ToString();
                                        tars.NextInterestRate = InterestInfo_.ToString();
                                        tars.NextAllRate = (HeadInfo_ + ProcessInfo_ + InterestInfo_).ToString();
                                        tars.Date = DateTime.Now;
                                        tars.TAgentId = ag.DirectAgentID;
                                        tars.TOrderId = item.ID;
                                        tarlist.Add(tars);
                                        tar.HeadRate = (Convert.ToDouble(tar.HeadRate) - HeadInfo_).ToString("F4");
                                        tar.ProcessRate = (Convert.ToDouble(tar.ProcessRate) - ProcessInfo_).ToString("F4");
                                        tar.InterestRate = (Convert.ToDouble(tar.InterestRate) - InterestInfo_).ToString("F4");
                                        tar.AllRate = (Convert.ToDouble(tar.AllRate) - (HeadInfo_ + ProcessInfo_ + InterestInfo_)).ToString("F4");
                                    }
                                    else if (i == 4)//指数会员的上4级
                                    {
                                        //会员的分成
                                        HeadRate = Convert.ToDouble(Converter.ToFloat(age.HeadRate4, 0).ToString("F4")) * 0.01;
                                        ProcessRate = Convert.ToDouble(Converter.ToFloat(age.ProcessRate4, 0).ToString("F4")) * 0.01;
                                        InterestRate = Convert.ToDouble(Converter.ToFloat(age.ProcessRate4, 0).ToString("F4")) * 0.01;
                                        //计算分成
                                        var HeadInfo_ = Convert.ToDouble((Converter.ToFloat(item.ProfitAndLoss, 0) * HeadRate * -1).ToString("F4"));
                                        var ProcessInfo_ = Convert.ToDouble((Converter.ToFloat(item.Deposit, 0) * ProcessRate).ToString("F4"));
                                        var InterestInfo_ = Convert.ToDouble((Converter.ToFloat(item.Interest, 0) * InterestRate).ToString("F4"));

                                        TAgentRate tars = new TAgentRate();
                                        tars.HeadRate = "0";
                                        tars.ProcessRate = "0";
                                        tars.InterestRate = "0";
                                        tars.AllRate = "0";
                                        tars.NextHeadRate = HeadInfo_.ToString();
                                        tars.NextProcessRate = ProcessInfo_.ToString();
                                        tars.NextInterestRate = InterestInfo_.ToString();
                                        tars.NextAllRate = (HeadInfo_ + ProcessInfo_ + InterestInfo_).ToString();
                                        tars.Date = DateTime.Now;
                                        tars.TAgentId = ag.DirectAgentID;
                                        tars.TOrderId = item.ID;
                                        tarlist.Add(tars);
                                        tar.HeadRate = (Convert.ToDouble(tar.HeadRate) - HeadInfo_).ToString("F4");
                                        tar.ProcessRate = (Convert.ToDouble(tar.ProcessRate) - ProcessInfo_).ToString("F4");
                                        tar.InterestRate = (Convert.ToDouble(tar.InterestRate) - InterestInfo_).ToString("F4");
                                        tar.AllRate = (Convert.ToDouble(tar.AllRate) - (HeadInfo_ + ProcessInfo_ + InterestInfo_)).ToString("F4");
                                    }
                                    else if (i == 5)//指数会员的上5级
                                    {
                                        //会员的分成
                                        HeadRate = Convert.ToDouble(Converter.ToFloat(age.HeadRate5, 0).ToString("F4")) * 0.01;
                                        ProcessRate = Convert.ToDouble(Converter.ToFloat(age.ProcessRate5, 0).ToString("F4")) * 0.01;
                                        InterestRate = Convert.ToDouble(Converter.ToFloat(age.ProcessRate5, 0).ToString("F4")) * 0.01;
                                        //计算分成
                                        var HeadInfo_ = Convert.ToDouble((Converter.ToFloat(item.ProfitAndLoss, 0) * HeadRate * -1).ToString("F4"));
                                        var ProcessInfo_ = Convert.ToDouble((Converter.ToFloat(item.Deposit, 0) * ProcessRate).ToString("F4"));
                                        var InterestInfo_ = Convert.ToDouble((Converter.ToFloat(item.Interest, 0) * InterestRate).ToString("F4"));

                                        TAgentRate tars = new TAgentRate();
                                        tars.HeadRate = "0";
                                        tars.ProcessRate = "0";
                                        tars.InterestRate = "0";
                                        tars.AllRate = "0";
                                        tars.NextHeadRate = HeadInfo_.ToString();
                                        tars.NextProcessRate = ProcessInfo_.ToString();
                                        tars.NextInterestRate = InterestInfo_.ToString();
                                        tars.NextAllRate = (HeadInfo_ + ProcessInfo_ + InterestInfo_).ToString();
                                        tars.Date = DateTime.Now;
                                        tars.TAgentId = ag.DirectAgentID;
                                        tars.TOrderId = item.ID;
                                        tarlist.Add(tars);
                                        tar.HeadRate = (Convert.ToDouble(tar.HeadRate) - HeadInfo_).ToString("F4");
                                        tar.ProcessRate = (Convert.ToDouble(tar.ProcessRate) - ProcessInfo_).ToString("F4");
                                        tar.InterestRate = (Convert.ToDouble(tar.InterestRate) - InterestInfo_).ToString("F4");
                                        tar.AllRate = (Convert.ToDouble(tar.AllRate) - (HeadInfo_ + ProcessInfo_ + InterestInfo_)).ToString("F4");
                                    }
                                    ag = (from c in db.TAgents where c.ID == ag.DirectAgentID select c).FirstOrDefault();
                                }
                                tarlist.Add(tar);
                                db.TAgentRate.InsertAllOnSubmit(tarlist);
                                db.SubmitChanges();

                                //AgentRate ar = new AgentRate();
                                //ar.Id = agent.ID;
                                //ar.DirectAgentID = Converter.ToInt(agent.DirectAgentID, 0);
                                //ar.Groupid = agent.GID;
                                //ar.Num = 0;
                                //ar.HeadInfo = HeadInfo;
                                //ar.ProcessInfo = ProcessInfo;
                                //ar.InterestInfo = InterestInfo;
                                //ar.NextheadInfo = HeadInfo;
                                //ar.NextprocessInfo = ProcessInfo;
                                //ar.NextinterestInfo = InterestInfo;
                                //if (ar.DirectAgentID > 0)
                                //{
                                //    Converter.GetAgent(ar, ar, item.ID);
                                //}
                                //ar.HeadInfo = ar.NextheadInfo;
                                //ar.ProcessInfo = ar.NextprocessInfo;
                                //ar.InterestInfo = ar.NextinterestInfo;
                                //ar.NextheadInfo = 0;
                                //ar.NextprocessInfo = 0;
                                //ar.NextinterestInfo = 0;

                                //APIDataDataContext db2 = APIDataContextProxy.APIDB;
                                //{
                                //    TAgentRate tar = new TAgentRate();
                                //    tar.HeadRate = ar.HeadInfo.ToString();
                                //    tar.ProcessRate = ar.ProcessInfo.ToString();
                                //    tar.InterestRate = ar.InterestInfo.ToString();
                                //    tar.AllRate = (ar.HeadInfo + ar.ProcessInfo + ar.InterestInfo).ToString();
                                //    tar.NextHeadRate = ar.NextheadInfo.ToString();
                                //    tar.NextProcessRate = ar.NextprocessInfo.ToString();
                                //    tar.NextInterestRate = ar.NextinterestInfo.ToString();
                                //    tar.NextAllRate = (ar.NextheadInfo + ar.NextprocessInfo + ar.NextinterestInfo).ToString();
                                //    tar.Date = DateTime.Now;
                                //    tar.TAgentId = agent.ID;
                                //    tar.TOrderId = item.ID;
                                //    db2.TAgentRate.InsertOnSubmit(tar);
                                //    db2.SubmitChanges();
                                //}
                            }
                            #endregion
                        }
                        catch
                        {
                        }

                        #region 资金记录
                        TAccountMoney tam = new TAccountMoney();
                        tam.MoneyOrderNum = DateTime.Now.ToString("yyyyMMddHHmmssfff");
                        tam.RealAccountId = Converter.ToInt(item.TRealAccountsID);
                        tam.TypeId = 4;
                        tam.OriginalMoney = user.AccountMoney;
                        tam.CreateMoney = item.ProfitAndLoss;
                        tam.NowMoney = user.AccountMoney + item.ProfitAndLoss;
                        if (tam.NowMoney < 0)
                        {
                            tam.NowMoney = 0;
                        }
                        tam.CreateTime = nowdate;
                        tam.UpDateTime = nowdate;
                        tam.Status = 2;
                        tam.TOrderId = item.ID;
                        db.TAccountMoney.InsertOnSubmit(tam);

                        TAccountMoney tams = new TAccountMoney();
                        tams.MoneyOrderNum = DateTime.Now.ToString("yyyyMMddHHmmssfff");
                        tams.RealAccountId = Converter.ToInt(item.TRealAccountsID, 0);
                        tams.TypeId = 5;
                        tams.OriginalMoney = tam.NowMoney;
                        tams.CreateMoney = item.Deposit;
                        tams.NowMoney = tam.NowMoney - item.Deposit;
                        if (tams.NowMoney < 0)
                        {
                            tams.NowMoney = 0;
                        }
                        tams.CreateTime = nowdate;
                        tams.UpDateTime = nowdate;
                        tams.Status = 2;
                        tams.TOrderId = item.ID;
                        db.TAccountMoney.InsertOnSubmit(tams);

                        #endregion
                        user.AccountMoney = user.AccountMoney + item.ProfitAndLoss - item.Deposit;
                        if (user.AccountMoney < 0)
                        {
                            user.AccountMoney = 0;
                        }
                        db.SubmitChanges();

                        JObject jb = new JObject();
                        jb["success"] = "TRUE";
                        jb["content"] = OrderId;
                        return jb.ToString();
                    }
                    else
                    {
                        return ErrMsg(10050, "订单id不正确!");
                    }
                }
                else
                {
                    return ErrMsg(10051, "订单id不正确!");
                }
            }
            catch
            {
                return ErrMsg(10052, "服务器错误!");
            }
        }
Exemplo n.º 8
0
        //注册
        public string Regist()
        {
            APIDataDataContext db = APIDataContextProxy.APIDB;
            string Name = SoftwareAPI.Utils.Converter.ToString(Request["Name"], "");
            string Sexs = SoftwareAPI.Utils.Converter.ToString(Request["Sex"], "");
            int AccountType = SoftwareAPI.Utils.Converter.ToInt(Request["AccountType"], 0);//帐号类型 0模拟 1 实盘
            string Phone = SoftwareAPI.Utils.Converter.ToString(Request["Phone"], "");//手机
            string Email = SoftwareAPI.Utils.Converter.ToString(Request["Email"], "");//邮箱
            int CityID = SoftwareAPI.Utils.Converter.ToInt(Request["CityID"], 0);//地区;
            string Address = SoftwareAPI.Utils.Converter.ToString(Request["Address"], "");//地址;
            int AgendID = SoftwareAPI.Utils.Converter.ToInt(Request["AgendID"], 0);//所属会员;
            string PassWord = SoftwareAPI.Utils.Converter.ToString(Request["PassWord"], "");//密码
            string Account = "";//生成
            bool Sex = false;
            sysPreference = db.TSysPreference.FirstOrDefault();
            if (AccountType == 0 && sysPreference.AllowDemo == false)
            {
                JObject jo = new JObject();
                jo["success"] = 10003;
                jo["token"] = "";
                jo["msg"] = "该平台禁止模拟账户注册!";
                return jo.ToString();
            }
            if (Sexs.ToLower() == "true")
            {
                Sex = true;
            }
            string IP = GetUserIp;//密码
            var user = (from c in db.TRealAccounts where c.Email.ToUpper() == Email.ToUpper() || c.Phone.ToUpper() == Phone.ToUpper() select c).FirstOrDefault();
            if (string.IsNullOrEmpty(Name) || string.IsNullOrEmpty(Phone) || string.IsNullOrEmpty(Email) || string.IsNullOrEmpty(PassWord))
            {
                JObject jo = new JObject();
                jo["success"] = 10003;
                jo["token"] = "";
                jo["msg"] = "请输入完整!";
                return jo.ToString();
            }
            if (user != null)
            {
                JObject jo = new JObject();
                jo["success"] = 10004;
                jo["token"] = "";
                jo["msg"] = "该用户已经注册过了!";
                return jo.ToString();
            }
            else
            {
                //查询平台设置
                var sys = (from c in db.TSysPreference select c).FirstOrDefault();
                string beforename = "";//帐号前缀
                if (AccountType == 1)//真实帐号
                {
                    beforename = sys.LCPrefix;
                }
                else //模拟帐号
                {
                    beforename = sys.DCPrefix;
                }
                Account = beforename + DateTime.Now.ToString("yyyyMMddHHmmss");
                var group = (from c in db.TUserGroup orderby c.IsDefault descending select c).FirstOrDefault();
                //添加新用户
                user = new TRealAccounts();
                //Account
                user.Name = Name;
                user.Sex = Sex;
                user.Account = Account;
                user.AccountType = AccountType;
                user.Phone = Phone;
                user.Email = Email;
                user.CityID = CityID;
                user.Address = Address;
                if (AgendID == 0)
                    user.AgendID = (from c in db.TAgents orderby c.Depth ascending select c.ID ).FirstOrDefault();
                else
                    user.AgendID = AgendID;

                user.PassWord = PassWord;
                user.AccountMoney = 0;
                if (AccountType != 1)
                {
                    try
                    {
                        if (sysPreference.DefaultDemoFin > 0)
                        {
                            user.AccountMoney = sysPreference.DefaultDemoFin;
                            user.AccountBeginMoney = sysPreference.DefaultDemoFin;//赠金
                            TAccountMoney tam = new TAccountMoney();
                            tam.MoneyOrderNum = DateTime.Now.ToString("yyyyMMddHHmmssfff");
                            tam.RealAccountId = Converter.ToInt(user.ID);
                            tam.TypeId = 2;
                            tam.OriginalMoney = user.AccountMoney;
                            tam.CreateMoney = sysPreference.DefaultDemoFin;
                            tam.NowMoney = sysPreference.DefaultDemoFin;
                            if (tam.NowMoney < 0)
                            {
                                tam.NowMoney = 0;
                            }
                            tam.CreateTime = DateTime.Now;
                            tam.UpDateTime = DateTime.Now;
                            tam.Status = 2;
                            tam.TOrderId = 0;
                            db.TAccountMoney.InsertOnSubmit(tam);

                        }
                    }
                    catch { }

                }
                //user.AccountType = AccountType;
                user.LastLoginIP = IP;
                user.LastLoginTime = DateTime.Now;
                try
                {
                    user.GroupID = group.ID;
                }
                catch
                {
                    user.GroupID = 0;
                }
                db.TRealAccounts.InsertOnSubmit(user);
                db.SubmitChanges();

                user.Account = beforename + user.ID.ToString("000000");
                db.SubmitChanges();
                //Account = beforename + DateTime.Now.ToString("yyyyMMddHHmmss");
                //查询accesstoken 是否有
                Access access = (from c in db.Access where c.userid == user.ID select c).FirstOrDefault();
                string token = "";
                if (access != null)// 数据库有accesstoken
                {
                    token = access.access_token;
                }
                else
                {
                    access = new Access();
                    access.userid = user.ID;
                    string access_token = FormsAuthentication.HashPasswordForStoringInConfigFile(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss"), "MD5");
                    access.access_token = access_token;
                    access.expires_in = 0;
                    access.scope = "0";
                    access.datetime = DateTime.Now;
                    access.platform_name = sys.FullName;
                    access.deviceid = 0;
                    db.Access.InsertOnSubmit(access);
                    db.SubmitChanges();
                }

                JObject job = new JObject();
                job["token"] = access.access_token;
                job["Account"] = user.Account;
                job["MinVolume"] = group.MinVolume;
                job["MaxVolume"] = group.MaxVolume;
                job["EntrustDeadLine"] = group.EntrustDeadLine;

                JObject jo = new JObject();
                jo["success"] = "TRUE";
                jo["content"] = job;
                jo["msg"] = "登陆成功!";
                return jo.ToString();
            }
        }