Esempio n. 1
0
        public ActionResult UnionDonations(ChariGameViewModel cgvm)
        {
            ViewData[SessionKey.VwUserMenu] = "uniondonation";
            LoveChange old_lc = _uow.LoveChangeService.Get(o => o.UnionOrder == cgvm.DonationId && o.Amount == cgvm.DonationAmount);
            UserInfo   usr    = base.CurrentUser;

            if (old_lc == null)
            {
                ModelState.AddModelError("NotExistDonation", "无法帮定捐赠单");
                var list = _uow.LoveChangeService.GetQueryList(o => o.UserId == usr.Id).OrderByDescending(o => o.CreateTime);
                cgvm.PageList = new Common.Helper.PageList <LoveChange>(list, cgvm.PageIndex, cgvm.PageCount);
                return(View(cgvm));
            }
            if (old_lc.UserId != null)
            {
                ModelState.AddModelError("BindedDonation", "此捐赠单已经绑定");
                var list = _uow.LoveChangeService.GetQueryList(o => o.UserId == usr.Id).OrderByDescending(o => o.CreateTime);
                cgvm.PageList = new Common.Helper.PageList <LoveChange>(list, cgvm.PageIndex, cgvm.PageCount);
                return(View(cgvm));
            }

            old_lc.UserId = usr.Id;
            if (string.IsNullOrWhiteSpace(old_lc.TrueName))
            {
                old_lc.TrueName = usr.TrueName;
            }
            _uow.Commit();
            base.RenderTip(null);
            return(RedirectToAction("UnionDonations"));
        }
Esempio n. 2
0
        /// <summary>
        /// Verifies donation order entered by user for drawing
        /// </summary>
        /// <param name="cdvm"></param>
        /// <returns></returns>
        public ActionResult GameVerify(ChariDrawViewModel cdvm)
        {
            LoveChange lc = _uow.LoveChangeService.Get(o => o.Amount == cdvm.DonAmount && o.UnionOrder == cdvm.DonatioinId);

            if (lc != null)
            {
                Session[SessionKey.DonationId]  = cdvm.DonatioinId;
                Session[SessionKey.DonationAmt] = cdvm.DonAmount;
                return(RedirectToAction("DonationPanel"));
            }
            Response.Close();
            Response.End();

            return(null);
        }
Esempio n. 3
0
        public ActionResult DonationPanel()
        {
            string  donId  = Session[SessionKey.DonationId].ToString();
            decimal donAmt = 0;

            _log.Info(string.Format("SessionKey.DonationId : {0} , SessionKey.DonationAmt : {1}", donId, Session[SessionKey.DonationAmt]));
            if (!string.IsNullOrWhiteSpace(donId) && decimal.TryParse(Session[SessionKey.DonationAmt].ToString(), out donAmt))
            {
                LoveChange lc = _uow.LoveChangeService.Get(o => o.UnionOrder == donId && o.Amount == donAmt);
                if (lc != null)
                {
                    ChariGameViewModel cgvm = new ChariGameViewModel();
                    cgvm.DonationId     = donId;
                    cgvm.DonationAmount = donAmt;
                    ViewBag.DonPlayed   = lc.IsGame;
                    _log.Info("love change query ok");
                    return(View(cgvm));
                }
            }

            return(RedirectToAction("LoginPanel"));
        }
Esempio n. 4
0
        /// <summary>
        /// Verifies order redirected from UPOP
        /// </summary>
        /// <returns></returns>
        public ActionResult VerifyUPOPOrder()
        {
            if (Session[SessionKey.UPOPChari] != null && Session[SessionKey.ID] != null && Session[SessionKey.DonationAmt] != null)
            {
                //redirected from UPOP
                if (Session[SessionKey.UPOPChari].ToString() == "Verified")
                {
                    string  oId = Session[SessionKey.ID].ToString();
                    decimal amt = decimal.Parse(Session[SessionKey.DonationAmt].ToString());
                    if (_uow.LoveChangeService.Get(o => o.UnionOrder == oId && o.Amount == amt) == null)
                    {
                        LoveChange lc = new LoveChange();
                        lc.UnionOrder = oId;
                        lc.Amount     = amt;
                        lc.CreateTime = DateTime.Now;
                        lc.IsGame     = false;
                        lc.IsSuccess  = true;
                        if (base.CurrentUser != null)
                        {
                            lc.UserId = base.CurrentUser.Id;
                        }
                        lc.State = (int)OrderState.Paid;
                        _uow.LoveChangeService.Add(lc);
                        _uow.Commit();
                        _log.Info(string.Format("ChinaUnion: {0}_{1}", lc.UnionOrder, lc.Amount));
                    }
                    Session[SessionKey.UPOPChari]   = "Verified";
                    Session[SessionKey.DonationId]  = oId;
                    Session[SessionKey.DonationAmt] = amt;
                    _log.Info("upop order verified, redirect to donation panel");
                    return(RedirectToAction("DonationPanel", new { t = (DateTime.Now - new DateTime(1900, 1, 1)).Ticks }));
                }
            }

            return(RedirectToAction("Error"));
        }
Esempio n. 5
0
        public string FlashGame(string var)
        {
            //Session[SessionKey.DrawId] = 1;
            //Session[SessionKey.PrizeId] = 1;
            //Session[SessionKey.User] = _uow.UserInfoService.Get(o => o.Id == 8);
            //return "{ \"type\" : \"checkLogin\", \"status\" : 1, \"massage\" : \"xx\", \"angle\" : 60, \"url\" : \"win\" }";

            //check if request generated from ChariDraw page
            if (Session["ChariGame"] == null)
            {
                return("{ \"type\" : \"checkLogin\", \"status\" : 0, \"massage\" : \"已超时,请重新刷新。\", \"url\" : \"exp\" }");
            }
            if (Session["ChariGame"].ToString() == DataEncryption.HashString("chari.game"))
            {
                //直接输入捐赠号
                UserInfo usr         = (UserInfo)Session[SessionKey.User];
                string   DonationId  = (string)Session[SessionKey.DonationId];
                decimal  DonationAmt = 0;
                if (Session[SessionKey.DonationAmt] != null)
                {
                    DonationAmt = (decimal)Session[SessionKey.DonationAmt];
                }

                #region User Logged In
                if (usr != null)
                {
                    //user logged in
                    UserInfo dbusr = _uow.UserInfoService.Get(o => o.Id == usr.Id);
                    if (dbusr != null && usr.Password == dbusr.Password && usr.UserName == dbusr.UserName)
                    {
                        //user valid, get user's donations
                        //List<LoveChange> donations = _uow.LoveChangeService.GetQueryList(o => o.UserId == dbusr.Id  && o.IsGame != true).OrderBy(o => o.CreateTime).ToList();
                        var donation = _uow.LoveChangeService.GetQueryList(o => o.UserId == dbusr.Id && o.IsGame != true).OrderBy(o => o.CreateTime).FirstOrDefault();

                        //int dtype = (int)OrderType.Donation;
                        //List<Order> orderList = _uow.OrderService.GetQueryList(o => o.UserId == dbusr.Id && o.IsGame != true && o.OrderType == dtype && o.Status == 10).OrderBy(o => o.PayTime).ToList();
                        var donationOrder = _uow.OrderService.GetQueryList(t => t.UserId == dbusr.Id &&
                                                                           t.IsGame == false &&
                                                                           t.OrderType == (int)OrderType.Donation &&
                                                                           t.Status >= (int)OrderState.Paid).OrderBy(t => t.PayTime).FirstOrDefault();

                        #region 愛心零錢 UnionPay
                        //if (donations.Count > 0)
                        if (donation != null)
                        {
                            //愛心零錢 available for drawings, select earliest and create drawing entry
                            Drawings NewDraw = new Drawings();
                            NewDraw.Source  = (int)GameSource.ChangeOfCare;
                            NewDraw.UserId  = dbusr.Id;
                            NewDraw.OrderNo = donation.UnionOrder;

                            //get available prizes
                            List <Prize> przList = _uow.PrizeService.SelectPrizeList(true);
                            if (przList.Count > 0)
                            {
                                //prize available, calculate winning result
                                bool DrawResult = DataEncryption.GetDrawingResult();
                                NewDraw.IsWinner = DrawResult;

                                if (DrawResult)
                                {
                                    //user won a prize, selects a random prize from the list
                                    Prize wPrize = _uow.PrizeService.SelectWinningPrize(przList);
                                    NewDraw.PrizeId = wPrize.Id;
                                    //increase used prize count
                                    wPrize.UsedCount  += 1;
                                    NewDraw.CreateTime = DateTime.Now;
                                    donation.GameTime  = NewDraw.CreateTime;
                                    donation.IsGame    = true;
                                    _uow.DrawingsService.Add(NewDraw);
                                    _uow.Commit();

                                    int ang = wPrize.Angle + 720;
                                    return("{ \"type\" : \"checkLogin\", \"status\" : 1, \"massage\" : \"" + wPrize.Name + "\", \"angle\" : " + ang.ToString() + ", \"url\" : \"usr\" }");
                                }
                                else
                                {
                                    //user did not win
                                    NewDraw.CreateTime   = DateTime.Now;
                                    donation.GameTime    = NewDraw.CreateTime;
                                    NewDraw.IsConfirrmed = true;
                                    donation.IsGame      = true;
                                    _uow.DrawingsService.Add(NewDraw);
                                    _uow.Commit();
                                    return("{ \"type\" : \"checkLogin\", \"status\" : 2, \"massage\" : \"感谢您对慈善事业的大力支持,谢谢参与。\", \"angle\" : 1050, \"url\" : \"usr\" }");
                                }
                            }
                            else
                            {
                                //no prize available, user set to not win
                                NewDraw.CreateTime   = DateTime.Now;
                                donation.GameTime    = NewDraw.CreateTime;
                                NewDraw.IsConfirrmed = true;
                                donation.IsGame      = true;
                                _uow.DrawingsService.Add(NewDraw);
                                _uow.Commit();
                                return("{ \"type\" : \"checkLogin\", \"status\" : 2, \"massage\" : \"感谢您对慈善事业的大力支持,谢谢参与。\", \"angle\" : 1050, \"url\" : \"usr\" }");
                            }
                        }
                        #endregion
                        #region 愛心捐贈 ichari
                        else if (donationOrder != null)
                        {
                            //愛心捐贈 available for drawings, select earliest and create drawing entry
                            Drawings NewDraw = new Drawings();
                            NewDraw.Source  = (int)GameSource.IchariDonation;
                            NewDraw.UserId  = dbusr.Id;
                            NewDraw.OrderNo = donationOrder.TradeNo;

                            //get available prizes
                            List <Prize> przList = _uow.PrizeService.SelectRandomPrizeList(11, true);
                            if (przList.Count > 0)
                            {
                                //prize available, calculate winning result
                                bool DrawResult = DataEncryption.GetDrawingResult();
                                NewDraw.IsWinner = DrawResult;
                                if (DrawResult)
                                {
                                    //user won a prize, selects a random prize from the list
                                    Prize wPrize = _uow.PrizeService.SelectWinningPrize(przList);
                                    //end prize selection
                                    NewDraw.PrizeId = wPrize.Id;
                                    //increase used prize count
                                    wPrize.UsedCount  += 1;
                                    NewDraw.CreateTime = DateTime.Now;
                                    _uow.DrawingsService.Add(NewDraw);
                                    //更新捐赠订单
                                    donationOrder.UpdateTime = NewDraw.CreateTime;
                                    donationOrder.IsGame     = true;

                                    _uow.Commit();

                                    int ang = wPrize.Angle + 720;
                                    return("{ \"type\" : \"checkLogin\", \"status\" : 1, \"massage\" : \"" + wPrize.Name + "\", \"angle\" : " + ang.ToString() + ", \"url\" : \"usr\" }");
                                }
                                else
                                {
                                    //user did not win
                                    NewDraw.CreateTime   = DateTime.Now;
                                    NewDraw.IsConfirrmed = true;
                                    //更新捐赠订单
                                    donationOrder.UpdateTime = NewDraw.CreateTime;
                                    donationOrder.IsGame     = true;
                                    _uow.DrawingsService.Add(NewDraw);

                                    _uow.Commit();

                                    return("{ \"type\" : \"checkLogin\", \"status\" : 2, \"massage\" : \"感谢您对慈善事业的大力支持,谢谢参与。\", \"angle\" : 1050, \"url\" : \"usr\" }");
                                }
                            }
                            else
                            {
                                //no prize available, user set to not win
                                NewDraw.CreateTime       = DateTime.Now;
                                donationOrder.UpdateTime = NewDraw.CreateTime;
                                NewDraw.IsConfirrmed     = true;
                                donationOrder.IsGame     = true;
                                _uow.DrawingsService.Add(NewDraw);
                                _uow.Commit();
                                return("{ \"type\" : \"checkLogin\", \"status\" : 2, \"massage\" : \"感谢您对慈善事业的大力支持,谢谢参与。\", \"angle\" : 1050, \"url\" : \"usr\" }");
                            }
                        }
                        #endregion
                        else
                        {
                            _log.Info("user is logon,but not exist donation order");
                            //no donations available for drawing
                            return("{ \"type\" : \"checkLogin\", \"status\" : 0, \"massage\" : \"对不起,您已经没有抽奖机会了\" }");
                        }
                    }
                }
                #endregion
                #region Donation Entered or from UPOP
                else if (!string.IsNullOrWhiteSpace(DonationId) && DonationAmt > 0)
                {
                    //donation entered
                    LoveChange lc = _uow.LoveChangeService.Get(o => o.UnionOrder == DonationId & o.Amount == DonationAmt);
                    if (lc != null && lc.Amount == DonationAmt && lc.UnionOrder == DonationId)
                    {
                        //donation valid,
                        if (lc.IsGame != true)
                        {
                            //check if prize available, create drawing entry
                            Drawings NewDraw = new Drawings();
                            NewDraw.OrderNo = DonationId;
                            NewDraw.Source  = (int)GameSource.ChangeOfCare;
                            List <Prize> przList = _uow.PrizeService.SelectRandomPrizeList(11, true);
                            if (przList.Count > 0)
                            {
                                //prize available, get drawing result
                                bool drawResult = DataEncryption.GetDrawingResult();
                                NewDraw.IsWinner = drawResult;
                                if (drawResult)
                                {
                                    //user won, randomly selects a prize
                                    Prize wPrize = _uow.PrizeService.SelectWinningPrize(przList);
                                    NewDraw.PrizeId = wPrize.Id;
                                    //increase used count
                                    wPrize.UsedCount  += 1;
                                    NewDraw.CreateTime = DateTime.Now;
                                    lc.GameTime        = NewDraw.CreateTime;
                                    lc.IsGame          = true;
                                    _uow.DrawingsService.Add(NewDraw);
                                    _uow.Commit();
                                    Session[SessionKey.DrawId] = _uow.DrawingsService.Get(o => o.PrizeId == NewDraw.PrizeId && o.OrderNo == NewDraw.OrderNo).Id;


                                    int ang = wPrize.Angle + 720;
                                    return("{ \"type\" : \"checkLogin\", \"status\" : 1, \"massage\" : \"" + wPrize.Name + "\", \"angle\" : " + ang.ToString() + ", \"url\" : \"win\" }");
                                }
                                else
                                {
                                    //user did not win
                                    NewDraw.CreateTime   = DateTime.Now;
                                    lc.GameTime          = NewDraw.CreateTime;
                                    NewDraw.IsConfirrmed = true;
                                    lc.IsGame            = true;
                                    _uow.DrawingsService.Add(NewDraw);
                                    _uow.Commit();
                                    return("{ \"type\" : \"checkLogin\", \"status\" : 2, \"massage\" : \"感谢您对慈善事业的大力支持,谢谢参与。\", \"angle\" : 1050, \"url\" : \"lose\" }");
                                }
                            }
                            else
                            {
                                //prize not available, user set to lost
                                NewDraw.CreateTime   = DateTime.Now;
                                lc.GameTime          = NewDraw.CreateTime;
                                NewDraw.IsConfirrmed = true;
                                lc.IsGame            = true;
                                _uow.DrawingsService.Add(NewDraw);
                                _uow.Commit();
                                return("{ \"type\" : \"checkLogin\", \"status\" : 2, \"massage\" : \"感谢您对慈善事业的大力支持,谢谢参与。\", \"angle\" : 1050, \"url\" : \"lose\" }");
                            }
                        }
                        else
                        {
                            //game played
                            return("{ \"type\" : \"checkLogin\", \"status\" : 0, \"massage\" : \"此捐赠单已抽奖,请登录查询中奖记录。\" }");
                        }
                    }
                    else
                    {
                        //donation invalid
                        return("{ \"type\" : \"checkLogin\", \"status\" : 0, \"massage\" : \"请重新确认您的捐赠单号。(或凭证号)。\" }");
                    }
                }
                #endregion
                else
                {
                    //user not logged in and no donation entered, disable flash
                    return("{ \"type\" : \"checkLogin\", \"status\" : 0, \"massage\" : \"《请登陆用户》 或 《填写捐赠单》\", \"url\" : \"login\" }");
                }
            }

            return("");
        }