Пример #1
0
        public static void Main(string[] args)
        {
            try
            {
                LogHelp.WriteLog("begin::团购定时任务");
                //判断已经结束的团购
                OrderBC bc      = new OrderBC();
                var     entitys = bc.GetGroupBuyConfig();
                foreach (var item in entitys)
                {
                    var needCount = bc.GetGroupBuyConfigByClassId(item.ClassId).NeedCount;
                    LogHelp.WriteLog("needCount:::" + needCount.ToString());
                    var group = bc.GetGroupBuyByClassId(item.ClassId);
                    if (group != null)
                    {
                        if (needCount != group.NowCount)//人数不满足,退款
                        {
                            LogHelp.WriteLog("人数不满足,退款");
                            //找到付款订单
                            var members = bc.GetGroupBuyMember(group.GroupBuyId);
                            if (members != null && members.Count > 0)
                            {
                                foreach (var i in members)
                                {
                                    var order = bc.GetOrderByOpenIdandClassId(i.openId, group.ClassId);
                                    //根据订单退款
                                    AppSetting  setting = new AppSetting();
                                    WxPayClient client  = new WxPayClient();
                                    WxPayData   data    = new WxPayData();


                                    string RefundNumber = string.Format("{0}{1}", order.OrderNo.ToString(), DateTime.Now.ToString("fff"));
                                    LogHelp.WriteLog("RefundNumber:::" + RefundNumber);


                                    RefundOrderRequest req = new RefundOrderRequest();
                                    data.SetValue("out_trade_no", order.WXPayOutTradeNumber);
                                    data.SetValue("total_fee", 1);                                 //订单总金额
                                    data.SetValue("refund_fee", 1);                                //退款金额

                                    data.SetValue("out_refund_no", WxPayApi.GenerateOutTradeNo()); //随机生成商户退款单号
                                    //data.SetValue("total_fee", Convert.ToInt32(order.PayPrice * 100));//订单总金额
                                    //data.SetValue("refund_fee",  Convert.ToInt32(order.PayPrice * 100));//退款金额

                                    var resp = client.Refund(data);

                                    //WxPayData jsApiParam = new WxPayData();
                                    //jsApiParam.SetValue("appId", resp.AppId);
                                    //jsApiParam.SetValue("timeStamp", WxPayApi.GenerateTimeStamp());
                                    //jsApiParam.SetValue("nonceStr", WxPayApi.GenerateNonceStr());
                                    //jsApiParam.SetValue("package", "prepay_id=" + resp.PrepayId);
                                    //jsApiParam.SetValue("signType", "MD5");
                                    //jsApiParam.SetValue("paySign", jsApiParam.MakeSign());
                                }
                            }
                        }
                        bc.UpdateGroupBuyStatus(group.GroupBuyId, 2);
                    }
                }
                LogHelp.WriteLog("end::团购定时任务");
            }
            catch (Exception ex)
            {
                LogHelp.WriteLog("end::团购定时任务出错" + ex.Message);
            }

            //
        }
Пример #2
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());
        }