コード例 #1
0
        /// <summary>
        /// 支付完成
        /// </summary>
        /// <returns></returns>
        public ActionResult rechargesucc(string openId, string orderNo)
        {
            OrderBC bc     = new OrderBC();
            var     result = bc.GetOrderByOrderNo(orderNo);

            //支付成功,1.更新订单状态;2.更新课程热度;3.增加用户积分;4.删除购物车
            UpdateOrderStatus(orderNo, 2);//1

            var goods = bc.GetOrderGoodsListByOrderId(result.OrderId);

            if (goods != null && goods.Count > 0)
            {
                foreach (var item in goods)
                {
                    new ClassBC().UpdateClassHot(item.ClassId);             //2
                    new ShopCarBC().EnableShopCar(openId, item.ClassId, 2); //4
                }
            }

            var point = bc.GetPointsByOpenid(openId);//3

            if (point == null)
            {
                PointsEntity points = new PointsEntity()
                {
                    OpenId = openId,
                    Points = result.PayPrice,
                };
                bc.AddPoint(points, openId);
                PointsLogEntity log = new PointsLogEntity()
                {
                    OrderId = result.OrderId,
                    LogType = "1",
                    Points  = result.PayPrice,
                    OpenId  = openId,
                };
                bc.AddPointLog(log, openId);
            }
            else
            {
                bc.UpdatePonits(openId, result.PayPrice);
                PointsLogEntity log = new PointsLogEntity()
                {
                    OrderId = result.OrderId,
                    LogType = "1",
                    Points  = result.PayPrice,
                    OpenId  = openId,
                };
                bc.AddPointLog(log, openId);
            }



            //根据订单来源,变更不同推广状态
            switch (result.OrderSource)
            {
            case "1":    //单独购买
                break;

            case "2":    //砍价
                foreach (var item in goods)
                {
                    var barginEntity = bc.GetBargainByOpenIdAndClassId(item.ClassId, openId);
                    bc.UpdateBargainStatus(barginEntity.BargainId, 2);
                }
                break;

            case "3":                          //团购
                UpdateOrderStatus(orderNo, 3); //1

                foreach (var item in goods)
                {
                    var gbEntity = bc.GetGroupBuyByClassId(item.ClassId);
                    if (gbEntity != null)    //该商品已有团购,更新团购人数
                    {
                        bc.UpdateGroupBuyCount(gbEntity.GroupBuyId);
                    }
                    else    //该商品没有团购,新增团购数据
                    {
                        GroupBuyEntity buy = new GroupBuyEntity()
                        {
                            ClassId  = item.ClassId,
                            NowCount = 1,
                        };
                        bc.AddGroupBuy(buy, openId);
                    }
                    gbEntity = bc.GetGroupBuyByClassId(item.ClassId);
                    //记录团购成员表
                    GroupBuyMemberEntity member = new GroupBuyMemberEntity()
                    {
                        GroupBuyId = gbEntity.GroupBuyId,
                        GroupPrice = item.Price,
                        openId     = openId
                    };
                    bc.AddGroupBuyMember(member, openId);

                    var nowCountEntity = bc.GetGroupBuyByClassId(item.ClassId);
                    var nowCount       = nowCountEntity.NowCount;
                    var needCount      = bc.GetGroupBuyConfigByClassId(item.ClassId).NeedCount;

                    if (nowCount == needCount)    //团购人数已满,变更团购状态为已完成(2)
                    {
                        bc.UpdateGroupBuyStatus(nowCountEntity.GroupBuyId, 2);
                        //更新成员表中所有成员的订单状态
                        var members = bc.GetGroupBuyMember(nowCountEntity.GroupBuyId);
                        foreach (var i in members)
                        {
                            var order = bc.GetOrderByOpenIdandClassId(i.openId, item.ClassId);
                            UpdateOrderStatus(order.OrderNo, 2);    //1
                        }
                    }
                }

                break;

            case "4":    //助力

                break;
            }


            ViewBag.OrderNo = orderNo;
            ViewBag.OpenId  = openId;
            ViewBag.Price   = result.PayPrice;

            return(View());
        }