Ejemplo n.º 1
0
        public IHttpActionResult GetUseWalletInfoByUserCode(string userCode)
        {
            LogHelper.WriteLog("GetUseWalletInfoByUserCode userCode" + userCode);

            SimpleResult           result   = new SimpleResult();
            IUseWalletService      _service = new UseWalletService();
            ITopupOrderServrce     tos      = new TopupOrderServrce();
            IRechargeRecordService _RechargeRecordService = new RechargeRecordService();
            IStoreService          _Storeservice          = new StoreService();
            IUserStoreService      _userStoreService      = new UserStoreService();

            try
            {
                if (UserAuthorization)
                {
                    //查看没有给微信支付核对的订单继续核对
                    var topupOrder = tos.GetTopupOrderbyuserCode(userCode);
                    var userSotre  = _userStoreService.GetUserStorebyUserCode(userCode);
                    var store      = _Storeservice.GetStore(userSotre.MembershipCardStore);

                    if (store != null)
                    {
                        foreach (var item in topupOrder)
                        {
                            if (!string.IsNullOrEmpty(item.WallePrCode) && item.PayDatetime == null)
                            {
                                var PayTime = Common.wxPayOrderQuery(item.WallePrCode, store.appid.Trim(), store.mchid);
                                if (!string.IsNullOrEmpty(PayTime))
                                {
                                    LogHelper.WriteLog("GetUseWalletInfoByUserCode PayTime" + PayTime);
                                    DateTime dt = DateTime.ParseExact(PayTime, "yyyyMMddHHmmss", System.Globalization.CultureInfo.CurrentCulture);
                                    item.PayDatetime = dt;
                                    tos.UpdateTopupOrder(item.WallePrCode, item.PayDatetime);
                                    _RechargeRecordService.Recharge(item.RechargeTypeCode, item.UserCode, item.RecordsMoney, store.StoreCode);
                                }
                            }
                        }
                    }
                    var list = _service.GetUseWalletInfoByUserCode(userCode);
                    result.Resource = list;
                    result.Status   = Result.SUCCEED;
                }
                else
                {
                    result.Status   = ResultType;
                    result.Resource = ReAccessToken;
                    result.Msg      = TokenMessage;
                }
            }
            catch (Exception ex)
            {
                LogHelper.WriteLog("GetUseWalletInfoByUserCode userCode" + userCode, ex);
                result.Status = Result.FAILURE;
                result.Msg    = ex.Message;
            }
            LogHelper.WriteLog("GetUseWalletInfoByUserCode result" + Json(result));
            return(Json(result));
        }
Ejemplo n.º 2
0
        public IHttpActionResult wxPrePay(string prepayid, string storeCode)
        {
            LogHelper.WriteLog("wxPrePay prepayid" + prepayid);
            LogHelper.WriteLog("wxPrePay storeCode" + storeCode);

            SimpleResult           result            = new SimpleResult();
            IRechargeRecordService _service          = new RechargeRecordService();
            ITopupOrderServrce     tos               = new TopupOrderServrce();
            IStoreService          _Storeservice     = new StoreService();
            IUserStoreService      _userStoreService = new UserStoreService();

            try
            {
                if (UserAuthorization)
                {
                    using (var scope = new TransactionScope())//创建事务
                    {
                        var opupOrder = tos.GetTopupOrderbyWallePrCode(prepayid);
                        if (opupOrder != null)
                        {
                            var userSotre = _userStoreService.GetUserStorebyUserCode(opupOrder.UserCode);
                            var store     = _Storeservice.GetStore(userSotre.MembershipCardStore);
                            if (store != null)
                            {
                                if (!string.IsNullOrEmpty(prepayid))
                                {
                                    if (ConfigurationManager.AppSettings["isWxpay"] != null && ConfigurationManager.AppSettings["isWxpay"].ToString() == "true")
                                    {
                                        var PayTime = Common.wxPayOrderQuery(prepayid, store.appid.Trim(), store.mchid);
                                        if (!string.IsNullOrEmpty(PayTime))
                                        {
                                            LogHelper.WriteLog("wxPrePay PayTime" + PayTime);
                                            DateTime dt      = DateTime.ParseExact(PayTime, "yyyyMMddHHmmss", System.Globalization.CultureInfo.CurrentCulture);
                                            var      payTime = dt;
                                            //更新TopupOrder 的支付时间
                                            tos.UpdateTopupOrder(prepayid, payTime);
                                            var tosmodel = tos.GetTopupOrderbyWallePrCode(prepayid);
                                            var list     = _service.Recharge(tosmodel.RechargeTypeCode, tosmodel.UserCode, tosmodel.RecordsMoney, storeCode);
                                            result.Resource = list;
                                            result.Status   = Result.SUCCEED;
                                        }
                                    }
                                    else
                                    {
                                        var payTime = DateTime.Now;
                                        //更新TopupOrder 的支付时间
                                        tos.UpdateTopupOrder(prepayid, payTime);
                                        var tosmodel = tos.GetTopupOrderbyWallePrCode(prepayid);
                                        var list     = _service.Recharge(tosmodel.RechargeTypeCode, tosmodel.UserCode, tosmodel.RecordsMoney, storeCode);
                                        result.Resource = list;
                                        result.Status   = Result.SUCCEED;
                                    }
                                }
                            }
                        }
                        scope.Complete();//这是最后提交事务
                    }
                }
                else
                {
                    result.Status   = ResultType;
                    result.Resource = ReAccessToken;
                    result.Msg      = TokenMessage;
                }
            }
            catch (Exception ex)
            {
                LogHelper.WriteLog("wxPrePay prepayid" + prepayid + " storeCode" + storeCode, ex);
                result.Status = Result.FAILURE;
                result.Msg    = ex.Message;
            }
            LogHelper.WriteLog("wxPrePay result" + Json(result));
            return(Json(result));
        }