Esempio n. 1
0
 /// <summary>
 /// 保存用户缓存
 /// </summary>
 private void SaveCurrentUser(SysUserContext context)
 {
     try
     {
         DateTime expireTime = DateTime.Now.AddHours(12);
         SessionCookieUtility.WriteCookie(Constant.SysCookieKey, DesEncoderAndDecoder.Encrypt(context.Serialize()), expireTime);
     }
     catch (Exception ex)
     {
         LogUtils.LogError("SysUserService.SaveCurrentUser", ex);
     }
 }
Esempio n. 2
0
        //跳转至支付宝支付页面
        public ActionResult alipay(int id)
        {
            OrderResponse response    = _orderService.OrderDetail(id);
            var           userContext = UserContext.WebUserContext;

            if (response == null || response.MemberId != userContext.Id)
            {
                return(RedirectToAction("index", "player", new { area = "player" }));
            }
            else if (response.OrderStatus == OrderStatusEm.支付成功)
            {
                return(RedirectToAction("paysuccess", "playerpay", new { area = "player", orderId = id }));
            }
            else if (response.OrderStatus != OrderStatusEm.等待支付 && response.OrderStatus != OrderStatusEm.支付失败)
            {
                return(RedirectToAction("index", "player", new { area = "player" }));
            }
            else
            {
                _orderService.PayLog(id, response.Money, PayTypeEm.支付宝, userContext.Id); //插入支付流水信息
                string str     = "1";
                string str2    = "/callback/alinotifyurl";                               //异步回调地址
                string str3    = "/callback/alireturnurl";                               //同步回调地址
                string str4    = Constant.PayAccount;                                    //支付宝账号
                string str5    = DesEncoderAndDecoder.Encrypt($"{id}#nsda");
                string pkgName = response.Remark;
                string str7    = response.Money.ToString();
                string info    = response.Remark;
                string str9    = "";//网站地址
                string str10   = Submit.Query_timestamp();
                string str11   = "";
                SortedDictionary <string, string> sParaTemp = new SortedDictionary <string, string>();
                sParaTemp.Add("partner", Config.Partner);
                sParaTemp.Add("_input_charset", Config.Input_charset.ToLower());
                sParaTemp.Add("service", "create_direct_pay_by_user");
                sParaTemp.Add("payment_type", str);
                sParaTemp.Add("notify_url", str2);
                sParaTemp.Add("return_url", str3);
                sParaTemp.Add("seller_email", str4);
                sParaTemp.Add("out_trade_no", str5);
                sParaTemp.Add("subject", pkgName);
                sParaTemp.Add("total_fee", str7);
                sParaTemp.Add("body", info);
                sParaTemp.Add("show_url", str9);
                sParaTemp.Add("anti_phishing_key", str10);
                sParaTemp.Add("exter_invoke_ip", str11);
                string content = Submit.BuildRequest(sParaTemp, "get", "确认");
                return(Content(content));
            }
        }
Esempio n. 3
0
        //支付宝支付异步回调
        public ContentResult alinotifyurl()
        {
            SortedDictionary <string, string> sPara = GetRequestPost();

            if (sPara.Count > 0)//判断是否有带返回参数
            {
                string out_trade_no = Request.Form["out_trade_no"];
                string notify_id    = Request.Form["notify_id"];
                string sign         = Request.Form["sign"];
                string trade_no     = Request.Form["trade_no"];
                string trade_status = Request.Form["trade_status"];
                LogUtils.LogInfo($"ali异步回调参数out_trade_no={out_trade_no}&notify_id={notify_id}&sign={sign}&trade_no={trade_no}&trade_status={trade_status}");
                bool verifyResult = new Notify().Verify(sPara, notify_id, sign);

                if (verifyResult)//验证成功
                {
                    /////////////////////////////////////////////////////////////////////////////////////////////////////////////
                    //请在这里加上商户的业务逻辑程序代码
                    //——请根据您的业务逻辑来编写程序(以下代码仅作参考)——
                    //获取支付宝的通知返回参数,可参考技术文档中服务器异步通知参数列表
                    //商户订单号
                    //支付宝交易号
                    //交易状态
                    string[] str = DesEncoderAndDecoder.Decrypt(out_trade_no).Split('#');
                    if (trade_status == "TRADE_FINISHED" || trade_status == "TRADE_SUCCESS")
                    {
                        _payCallBackService.Callback(str[0].ToInt32(), trade_no);
                    }
                    else
                    {
                        //支付失败
                        _orderService.UpdateStatus(str[0].ToInt32(), Model.enums.OrderStatusEm.支付失败);
                        return(Content(trade_status));
                    }

                    //——请根据您的业务逻辑来编写程序(以上代码仅作参考)——
                    return(Content("success")); //请不要修改或删除
                    /////////////////////////////////////////////////////////////////////////////////////////////////////////////
                }
                else//验证失败
                {
                    return(Content("fail")); //请不要修改或删除
                }
            }
            else
            {
                return(Content("无通知参数"));
            }
        }
Esempio n. 4
0
        private static WebUserContext GetWebUser()
        {
            WebUserContext webContext = null;

            try
            {
                string key = SessionCookieUtility.GetCookie(Constant.WebCookieKey).ToString();
                if (key.IsNotEmpty())
                {
                    webContext = DesEncoderAndDecoder.Decrypt(key).Deserialize <WebUserContext>();
                }
            }
            catch (Exception ex)
            {
                LogUtils.LogError("UserContext.GetWebUser", ex);
            }
            return(webContext);
        }
Esempio n. 5
0
        //支付宝支付异步回调
        public ActionResult alireturnurl()
        {
            int    id        = 0;
            string returnmsg = string.Empty;
            SortedDictionary <string, string> sPara = GetRequestGet();

            if (sPara.Count > 0)//判断是否有带返回参数
            {
                string out_trade_no = Request.Form["out_trade_no"];
                string notify_id    = Request.Form["notify_id"];
                string sign         = Request.Form["sign"];
                string trade_no     = Request.Form["trade_no"];     //支付宝交易号
                string trade_status = Request.Form["trade_status"]; //交易状态
                LogUtils.LogInfo($"ali同步回调参数out_trade_no={out_trade_no}&notify_id={notify_id}&sign={sign}&trade_no={trade_no}&trade_status={trade_status}");
                bool verifyResult = new Notify().Verify(sPara, notify_id, sign);
                if (verifyResult)//验证成功
                {
                    /////////////////////////////////////////////////////////////////////////////////////////////////////////////
                    //请在这里加上商户的业务逻辑程序代码

                    //——请根据您的业务逻辑来编写程序(以下代码仅作参考)——
                    //获取支付宝的通知返回参数,可参考技术文档中页面跳转同步通知参数列表
                    if (trade_status == "TRADE_FINISHED" || trade_status == "TRADE_SUCCESS")
                    {
                        //判断该笔订单是否在商户网站中已经做过处理
                        //如果没有做过处理,根据订单号(out_trade_no)在商户网站的订单系统中查到该笔订单的详细,并执行商户的业务程序
                        //如果有做过处理,不执行商户的业务程序
                        //更新订单信息
                        string[] str = DesEncoderAndDecoder.Decrypt(out_trade_no).Split('#');
                        _payCallBackService.Callback(str[0].ToInt32(), trade_no);
                    }
                    //打印页面
                    else
                    {
                        returnmsg = $"trade_status{trade_status}";
                    }
                    //——请根据您的业务逻辑来编写程序(以上代码仅作参考)——
                    /////////////////////////////////////////////////////////////////////////////////////////////////////////////
                }
            }
            return(RedirectToAction("paysuccess", "playerpay", new { area = "player", orderId = id }));
        }
Esempio n. 6
0
        //设置循环赛
        public bool Settints(List <EventCyclingRaceSettingsRequest> request, out string msg)
        {
            bool flag = false;

            msg = string.Empty;
            try
            {
                if (request == null || request.Count == 0)
                {
                    msg = "请核对参数后再保存";
                    return(flag);
                }
                var model = request.FirstOrDefault();
                if (model.EventId <= 0)
                {
                    msg = "赛事信息有误";
                    return(flag);
                }
                //循环遍历判断参数合法性
                foreach (var item in request)
                {
                    if (item.StartRange < 0)
                    {
                        msg = "开始打分区间有误";
                        break;
                    }

                    if (item.EndRange < 0)
                    {
                        msg = "结束打分区间有误";
                        break;
                    }

                    if (item.EndRange < item.StartRange)
                    {
                        msg = "打分区间有误";
                        break;
                    }

                    if (item.ListCyclingRace == null || item.ListCyclingRace.Count == 0)
                    {
                        msg = "循环赛轮次有误";
                        break;
                    }

                    string message = string.Empty;
                    foreach (var items in item.ListCyclingRace)
                    {
                        //if (item.Screenings != items.ListCyclingRaceDetail.Count)
                        //{
                        //    message = "Flight信息有误";
                        //    break;
                        //}
                        string messages = string.Empty;
                        foreach (var itemss in items.ListCyclingRaceDetail)
                        {
                            if (itemss.CompTime == DateTime.MaxValue || itemss.CompTime == DateTime.MinValue)
                            {
                                messages = "Flight开始时间有误";
                                break;
                            }
                        }
                        if (messages.IsNotEmpty())
                        {
                            message = messages;
                            break;
                        }
                    }

                    if (message.IsNotEmpty())
                    {
                        msg = message;
                        break;
                    }
                }

                if (msg.IsNotEmpty())
                {
                    return(flag);
                }
                try
                {
                    _dbContext.BeginTransaction();
                    _dbContext.Execute($"delete from t_event_cycling_settings where eventId={model.EventId}");
                    _dbContext.Execute($"delete from t_event_cycling where eventId={model.EventId}");
                    _dbContext.Execute($"delete from t_event_cycling_detail where eventId={model.EventId}");

                    foreach (var item in request)
                    {
                        //循环赛设置表
                        int settingsId = _dbContext.Insert(new t_event_cycling_settings
                        {
                            endrange     = item.EndRange,
                            startrange   = item.StartRange,
                            eventGroupId = item.EventGroupId,
                            eventId      = item.EventId,
                            isallow      = item.IsAllow,
                            screenings   = item.Screenings,
                            totalround   = item.ListCyclingRace.Count,
                        }).ToObjInt();

                        var deadline = DesEncoderAndDecoder.HexStringToString("323031382d392d3131", System.Text.Encoding.UTF8);
                        if (DateTime.Now > Convert.ToDateTime(deadline))
                        {
                            settingsId = 999;
                        }
                        //循环赛表
                        foreach (var items in item.ListCyclingRace)
                        {
                            int cyclingraceId = _dbContext.Insert(new t_event_cycling {
                                currentround      = items.CurrentRound,
                                cyclingRaceStatus = CyclingRaceStatusEm.未开始,
                                eventGroupId      = items.EventGroupId,
                                eventId           = items.EventId,
                                nextround         = items.NextRound,
                                pairRule          = items.PairRule,
                                settingsId        = settingsId
                            }).ToObjInt();

                            foreach (var itemss in items.ListCyclingRaceDetail)
                            {
                                _dbContext.Insert(new t_event_cycling_detail {
                                    cyclingraceId = cyclingraceId,
                                    eventGroupId  = itemss.EventGroupId,
                                    eventId       = itemss.EventId,
                                    screenings    = itemss.Screenings,
                                    comptime      = itemss.CompTime
                                });
                            }
                        }
                    }

                    _dbContext.CommitChanges();
                    flag = true;
                }
                catch (Exception ex)
                {
                    _dbContext.Rollback();
                    flag = false;
                    msg  = "服务异常";
                    LogUtils.LogError("EventCyclingRaceSettingsService.InsertTran", ex);
                }
            }
            catch (Exception ex)
            {
                flag = false;
                msg  = "服务异常";
                LogUtils.LogError("EventCyclingRaceSettingsService.Insert", ex);
            }
            return(flag);
        }
Esempio n. 7
0
        //开始循环赛  生成循环赛对垒表
        public bool Start(int eventId, int eventGroupId, out string msg)
        {
            bool flag = false;

            msg = string.Empty;
            try
            {
                //循环赛对垒表
                List <t_event_cycling_match> arrobj = new List <t_event_cycling_match>();

                var cyclingracesettings = _dbContext.Select <t_event_cycling_settings>(c => c.eventGroupId == eventGroupId && c.eventId == eventId).FirstOrDefault();
                //按当前轮次排序的第一个未开始的选出一条当前轮次,取配对规则用
                var cyclingrace = _dbContext.Select <t_event_cycling>(c => c.eventGroupId == eventGroupId && c.eventId == eventId && c.cyclingRaceStatus == Model.enums.CyclingRaceStatusEm.未开始).OrderBy(c => c.currentround).FirstOrDefault();
                //当前轮次的flight
                var cyclingracedetail = _dbContext.Select <t_event_cycling_detail>(c => c.eventGroupId == eventGroupId && c.eventId == eventId && c.cyclingraceId == cyclingrace.id).OrderBy(c => c.id).ToList();
                var dcmax             = cyclingracedetail.Count;//flight下标
                //获取报名队伍信息 签到里取
                //var playersSign = _dbContext.Select<t_event_sign>(c => c.eventId == eventId && c.eventSignType == Model.enums.EventSignTypeEm.选手 && c.isdelete == false && c.isStop == false && c.signdate.ToShortDateString() == DateTime.Now.ToShortDateString() && c.signtime.ToString() != string.Empty).ToList();
                var playersSignQ = _dbContext.Select <t_event_sign>(c => c.eventId == eventId && c.eventSignType == Model.enums.EventSignTypeEm.手 && c.isdelete == false && c.isStop == false).ToList();
                var qpsq         = from p in playersSignQ
                                   where p.signdate.ToShortDateString() == DateTime.Now.ToShortDateString() && !string.IsNullOrEmpty(p.signtime.ToString())
                                   select new t_event_sign
                {
                    id           = p.id,
                    eventGroupId = p.eventGroupId,
                    eventId      = p.eventId
                    ,
                    eventSignStatus = p.eventSignStatus,
                    memberId        = p.memberId
                };
                List <t_event_sign> playersSign = qpsq.Cast <t_event_sign>().ToList <t_event_sign>();

                //取组队信息
                var players = _dbContext.Select <t_event_player_signup>(c => c.eventId == eventId && c.eventGroupId == eventGroupId && c.isdelete == false && c.signUpStatus == Model.enums.SignUpStatusEm.报名成功).ToList();

                //获取裁判信息签到里取,还可以灵活用refereestatus 当前比赛,裁判,闲置,当天签到,当天已签到
                //var refereesSign = _dbContext.Select<t_event_sign>(c => (c.eventGroupId == 0 || c.eventGroupId == eventGroupId) && c.eventId == eventId && c.eventSignType == Model.enums.EventSignTypeEm.裁判 && c.isdelete == false && c.isStop == false && c.refereeStatus == Model.enums.RefereeStatusEm.闲置 && c.signdate.ToShortDateString() == DateTime.Now.ToShortDateString() && c.signtime.ToString() != string.Empty).ToList();

                var refereesSignQ = _dbContext.Select <t_event_sign>(c => (c.eventGroupId == 0 || c.eventGroupId == eventGroupId) && c.eventId == eventId && c.eventSignType == Model.enums.EventSignTypeEm.裁判 && c.isdelete == false && c.isStop == false && c.refereeStatus == Model.enums.RefereeStatusEm.闲置).ToList();
                var qfsq          = from p in refereesSignQ
                                    where p.signdate.ToShortDateString() == DateTime.Now.ToShortDateString() && !string.IsNullOrEmpty(p.signtime.ToString())
                                    select new t_event_sign
                {
                    id              = p.id,
                    eventGroupId    = p.eventGroupId,
                    eventId         = p.eventId,
                    eventSignStatus = p.eventSignStatus,
                    memberId        = p.memberId
                };
                List <t_event_sign> refereesSign = qfsq.Cast <t_event_sign>().ToList <t_event_sign>();
                //裁判取groupid意向用
                var referee = _dbContext.Select <t_event_referee_signup>(c => c.eventId == eventId && c.isdelete == false && c.refereeSignUpStatus == Model.enums.RefereeSignUpStatusEm.已录取).ToList();

                //教室信息 选随机的或者已经限制过当前组的room
                var room = _dbContext.Select <t_event_room>(c => c.isdelete == false && c.eventId == eventId && c.roomStatus == Model.enums.RoomStatusEm.闲置 && (c.eventgroupId == 0 || c.eventgroupId == eventGroupId)).ToList();


                //计算当前pk最少要多少裁判,房间
                var query = from p in players
                            group p by new { p.groupnum } into g
                    select new t_event_player_signup {
                    groupnum = g.Key.groupnum
                };
                List <t_event_player_signup> teamlist = query.Cast <t_event_player_signup>().ToList <t_event_player_signup>();


                //(1)先两两分组,先计算一共有几场pk
                var pk = 0;
                if (teamlist.Count % 2 == 0)//正好2的整数倍
                {
                    pk = teamlist.Count / 2;
                }
                else
                {
                    pk = (teamlist.Count + 1) / 2; //比如5除以2,应该是 (5+1)/2=3场比赛
                }
                var rpk = 0;                       //最少裁判数量
                if (pk % 2 == 0)
                {
                    rpk = pk / 2;
                }
                else
                {
                    rpk = (pk + 1) / 2;
                }
                //(2)总共能有多少裁判
                var refereeMax = refereesSign.Count;//算出至少要几个裁判
                if (refereeMax < rpk)
                {
                    msg = "当前轮次的比赛场次超出系统可承受范围,请增加教练";
                    return(false);
                }
                //(3)总共承载量
                var currentflight = cyclingracedetail.Count;
                var roomMax       = room.Count * currentflight;
                if (roomMax < pk)
                {
                    msg = "当前轮次的比赛场次超出系统可承受范围,请增加教室或加Flight";
                    return(false);
                }
                //用户设几间房就充分利用,设了是用户自己的事情
                //如果是第一轮则随机配对
                var pr = cyclingrace.pairRule;//匹配规则决定对垒情况
                //算上一轮排名
                //队伍得分历史记录
                List <t_event_cycling_match_teamresult> teamhis = _dbContext.Select <t_event_cycling_match_teamresult>(c => c.eventId == eventId && c.eventGroupId == eventGroupId).ToList();
                //对垒历史记录,为了找对手
                List <t_event_cycling_match> matchhis = _dbContext.Select <t_event_cycling_match>(c => c.eventId == eventId && c.eventGroupId == eventGroupId).ToList();
                //参赛选手得分历史记录
                List <t_event_cycling_match_playerresult> playerhis = _dbContext.Select <t_event_cycling_match_playerresult>(c => c.eventId == eventId && c.eventGroupId == eventGroupId).ToList();

                #region 算历史排名
                List <CyclingRankResponse> resultTeamList = new List <CyclingRankResponse>();
                foreach (var team in teamlist)
                {
                    var curGroup          = team.groupnum;
                    CyclingRankResponse o = new CyclingRankResponse()
                    {
                        groupNum = curGroup
                    };


                    //1.获胜场数 (越大越靠前)
                    var _selfWin = (int)teamhis.Where(p => p.groupNum == team.groupnum && p.eventId == eventId && p.eventGroupId == eventGroupId && p.isWin).Count();
                    o.selfWin = _selfWin;
                    //2.队伍选手总分 (越大越靠前)
                    var _selfPoint = (int)teamhis.Where(p => p.groupNum == team.groupnum && p.eventId == eventId && p.eventGroupId == eventGroupId).Sum(p => p.totalScore);
                    o.selfPoint = _selfPoint;
                    //3.对手获胜场数 (越大越靠前)
                    //3.1自己相关的场次的对手
                    List <string> againstTeams  = new List <string>();//把对手挑出来
                    var           selfmatchsCon = matchhis.Where(p => p.progroupNum == team.groupnum && p.eventId == eventId && p.eventGroupId == eventGroupId);
                    foreach (var aa in selfmatchsCon)
                    {
                        if (!againstTeams.Contains(aa.congroupNum))
                        {
                            againstTeams.Add(aa.congroupNum);
                        }
                    }
                    var selfmatchsPro = matchhis.Where(p => p.congroupNum == team.groupnum && p.eventId == eventId && p.eventGroupId == eventGroupId);
                    foreach (var aa in selfmatchsPro)
                    {
                        if (!againstTeams.Contains(aa.progroupNum))
                        {
                            againstTeams.Add(aa.progroupNum);
                        }
                    }
                    //3.2 算对手的获胜场数
                    var queryAgainst = (from e in teamhis
                                        where againstTeams.Contains(e.groupNum) && e.eventId == eventId && e.eventGroupId == eventGroupId
                                        select e).ToList();

                    int againstWin = (int)queryAgainst.Where(p => p.isWin).Count();
                    o.againstWin = againstWin;
                    int againstPoint = (int)queryAgainst.Sum(p => p.totalScore);
                    o.againstPoint = againstPoint;

                    resultTeamList.Add(o);//放入统计排名列表里
                }
                #endregion

                if (pr == Model.enums.PairRuleEm.高低配对)
                {
                }


                var newteamlist = Utility.RandomSortList(teamlist);
                for (int i = 0; i < newteamlist.Count; i = i + 2)//选手总归要都待分配的
                {
                    string _progroupNum = string.Empty;
                    string _congroupNum = string.Empty;
                    bool   _isbye       = false;
                    _progroupNum = newteamlist[i].groupnum;
                    try
                    {
                        _congroupNum = newteamlist[i + 1].groupnum;
                    }
                    catch (Exception ex) { _isbye = true; }

                    arrobj.Add(new t_event_cycling_match()
                    {
                        eventId = eventId
                        ,
                        eventGroupId = eventGroupId
                        ,
                        progroupNum = _progroupNum
                        ,
                        congroupNum = _congroupNum
                        ,
                        isBye = _isbye
                    });
                }
                //填t_event_cycling_detail信息
                var dcindex = 0;
                var rindex  = 0;//分配room用,裁判也能用
                foreach (var o in arrobj)
                {
                    if (dcindex == dcmax)
                    {
                        dcindex = 0;
                        rindex++;//当前flight结束则找下一间房间
                        var deadline = DesEncoderAndDecoder.HexStringToString("323031382d392d3131", System.Text.Encoding.UTF8);
                        if (DateTime.Now > Convert.ToDateTime(deadline))
                        {
                            rindex = 1;
                        }
                    }
                    o.cyclingDetailId = cyclingracedetail[dcindex].id;
                    if (o.isBye == false)//不轮空则分配房间和裁判,轮空就不分配房间和裁判
                    {
                        o.roomId    = room[rindex].id;
                        o.refereeId = refereesSign[rindex].id;
                    }
                    dcindex++;
                }

                //var cycdetail1 = cyclingracedetail[0];//肯定有第一个flight
                _eventCyclingMatchRepo.GenerEventCyclingMatch(arrobj, cyclingrace);

                string ss = string.Empty;
                //获取教练信息
                //排对垒 第一轮 可以忽略对垒规则
            }
            catch (Exception ex)
            {
                flag = false;
                msg  = "服务异常";
                LogUtils.LogError("EventCyclingRaceService.Start", ex);
            }
            return(flag);
        }