コード例 #1
0
        public IHttpActionResult GetUseWalletList()
        {
            LogHelper.WriteLog("GetUseWalletList ");
            SimpleResult      result   = new SimpleResult();
            IUseWalletService _service = new UseWalletService();

            try
            {
                if (UserAuthorization)
                {
                    var list = _service.GetUseWalletList();
                    result.Resource = list;
                    result.Status   = Result.SUCCEED;
                }
                else
                {
                    result.Status   = ResultType;
                    result.Resource = ReAccessToken;
                    result.Msg      = TokenMessage;
                }
            }
            catch (Exception ex)
            {
                LogHelper.WriteLog("GetUseWalletList ", ex);
                result.Status = Result.FAILURE;
                result.Msg    = ex.Message;
            }
            LogHelper.WriteLog("GetUseWalletList result" + Json(result));
            return(Json(result));
        }
コード例 #2
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));
        }
コード例 #3
0
        public IHttpActionResult InsertUseWallet(UseWallet useWallet)
        {
            LogHelper.WriteLog("InsertUseWallet useWallet" + useWallet?.WalletCode);
            SimpleResult      result   = new SimpleResult();
            IUseWalletService _service = new UseWalletService();

            try
            {
                var list = _service.InsertUseWallet(useWallet);
                result.Resource = list;
                result.Status   = Result.SUCCEED;
            }
            catch (Exception ex)
            {
                LogHelper.WriteLog("InsertUseWallet useWallet" + useWallet.UserCode, ex);
                result.Status = Result.FAILURE;
                result.Msg    = ex.Message;
            }
            LogHelper.WriteLog("InsertUseWallet result" + Json(result));
            return(Json(result));
        }
コード例 #4
0
        public IHttpActionResult PayOrder([FromBody] PayOrderParam param)
        {
            SimpleResult result = new SimpleResult();
            IRecordsOfConsumptionService _service   = new RecordsOfConsumptionService();
            ICouponService      _couponService      = new CouponService();
            IUseWalletService   _useWalletService   = new UseWalletService();
            IStoreService       _stoeservice        = new StoreService();
            IProductInfoService _productInfoService = new ProductInfoService();

            try
            {
                if (UserAuthorization)
                {
                    LogHelper.WriteLog("PayOrder接口");
                    LogHelper.WriteLog("productCode  param.userCode" + param.paytype);
                    LogHelper.WriteLog("productCode param.money " + param.money);
                    LogHelper.WriteLog("productCode param.orderCode" + param.orderCode);
                    LogHelper.WriteLog("productCode param.peopleCount" + param.peopleCount);
                    LogHelper.WriteLog("productCode param.productCode" + param.productCode);
                    LogHelper.WriteLog("productCode param.storeId" + param.storeId);
                    LogHelper.WriteLog("productCode param.userCode " + param.userCode);
                    LogHelper.WriteLog("productCode param.couponCode " + param.couponCode);
                    var isExistProduct = _productInfoService.IsExistProduct(param.productCode);
                    if (!isExistProduct)
                    {
                        result.Status   = Result.SYSTEM_ERROR;
                        result.Msg      = "商品已失效或不存在";
                        result.Resource = null;
                    }
                    if (param.paytype == 0)
                    {
                        LogHelper.WriteLog("会员支付 " + param.paytype);

                        var isPay = true;
                        if (!string.IsNullOrEmpty(param.couponCode))
                        {
                            var n = _couponService.Exist(param.couponCode);
                            if (n == 1)
                            {
                                result.Status   = Result.SYSTEM_ERROR;
                                result.Msg      = "优惠卷不存在";
                                result.Resource = null;
                                isPay           = false;
                            }
                            else if (n == 2)
                            {
                                result.Status   = Result.SYSTEM_ERROR;
                                result.Msg      = "优惠卷已经被使用";
                                result.Resource = null;
                                isPay           = false;
                            }
                        }

                        if (isPay)
                        {
                            if (_useWalletService.ExistMoney(param.userCode, param.money))
                            {
                                var re = _service.PayOrder(param.productCode, param.userCode, param.peopleCount, param.dateTime, param.money, param.storeId, param.orderCode, param.couponCode);
                                result.Resource = "SUCCEED";
                                result.Status   = Result.SUCCEED;
                                LogHelper.WriteLog("result.Status " + Result.SUCCEED);
                            }
                            else
                            {
                                result.Status   = Result.SYSTEM_ERROR;
                                result.Msg      = "账号余额不足";
                                result.Resource = null;
                                LogHelper.WriteLog("result.Status " + Result.SYSTEM_ERROR);
                            }
                        }
                    }
                    else
                    {
                        var isPay = true;
                        if (!string.IsNullOrEmpty(param.couponCode))
                        {
                            var n = _couponService.Exist(param.couponCode);
                            if (n == 1)
                            {
                                result.Status   = Result.SYSTEM_ERROR;
                                result.Msg      = "优惠卷不存在";
                                result.Resource = null;
                                isPay           = false;
                            }
                            else if (n == 2)
                            {
                                result.Status   = Result.SYSTEM_ERROR;
                                result.Msg      = "优惠卷已经被使用";
                                result.Resource = null;
                                isPay           = false;
                            }
                        }
                        if (isPay)
                        {
                            using (var scope = new TransactionScope())//创建事务
                            {
                                LogHelper.WriteLog("微信支付 " + param.userCode);
                                IUserStoreService _userStoreservice = new UserStoreService();
                                var store        = _stoeservice.GetStore(param.storeId);
                                var couponser    = _couponService.GetCouponByCode(param.couponCode);
                                var userStoreser = _userStoreservice.GetUserStorebyUserCodestoreCode(param.userCode, param.storeId);
                                if (userStoreser != null)
                                {
                                    if (param.money != 0)
                                    {
                                        //生成微信预支付订单
                                        var wxprepay = Common.wxPayOrderSomething(userStoreser.OpenID, param.money.ToString(), couponser?.CouponTypeName, store);
                                        if (wxprepay != null)
                                        {
                                            var order = _service.WxPayOrder(param.productCode, param.userCode, param.peopleCount, param.dateTime, param.money, wxprepay.prepayid, param.storeId, param.orderCode, param.couponCode);
                                            if (!string.IsNullOrEmpty(param.couponCode))
                                            {
                                                _couponService.UsedUpdate(param.couponCode, param.userCode, order.OrderCode);
                                            }
                                            WxOrder wxorder = new WxOrder();
                                            wxorder.orderCode    = order.OrderCode;
                                            wxorder.wxJsApiParam = wxprepay.wxJsApiParam;
                                            wxorder.prepayid     = wxprepay.prepayid;
                                            wxorder.IsWxPay      = true;
                                            result.Resource      = wxorder;
                                            result.Status        = Result.SUCCEED;
                                        }
                                        else
                                        {
                                            result.Msg    = "微信下单失败,重新提交订单";
                                            result.Status = Result.SYSTEM_ERROR;
                                        }
                                    }
                                    else
                                    {
                                        var order = _service.WxPayNoMoneyOrder(param.productCode, param.userCode, param.peopleCount, param.dateTime, param.money, null, param.couponCode);
                                        _couponService.UsedUpdate(param.couponCode, param.userCode, order.OrderCode);
                                        LogHelper.WriteLog("更新的钱包和优惠券couponCode: " + param.couponCode);

                                        LogHelper.WriteLog("报表写入数据开始");
                                        IFinancialStatementsService _financialStatementsService = new FinancialStatementService();
                                        LogHelper.WriteLog("报表表数据更新");
                                        financialStatements fs = _financialStatementsService.getData(param.userCode, order, "微信");
                                        LogHelper.WriteLog("报表表数据更新完成");

                                        _financialStatementsService.Insert(fs);
                                        LogHelper.WriteLog("报表写入数据结束" + fs.Code);
                                        WxOrder wxorder = new WxOrder();
                                        wxorder.orderCode = order.OrderCode;
                                        result.Resource   = "SUCCEED";
                                        result.Status     = Result.SUCCEED;
                                    }
                                }
                                else
                                {
                                    result.Resource = "";
                                    result.Status   = Result.SYSTEM_ERROR;
                                }
                                scope.Complete();//这是最后提交事务
                            }
                        }
                    }
                }
                else
                {
                    result.Status   = ResultType;
                    result.Resource = ReAccessToken;
                    result.Msg      = TokenMessage;
                }
            }
            catch (Exception ex)
            {
                LogHelper.WriteLog("WxPayOrder PayOrder ", ex);
                result.Status = Result.FAILURE;
                result.Msg    = ex.Message;

                LogHelper.WriteLog("微信支付", ex);
            }
            LogHelper.WriteLog("PayOrder result" + Json(result));
            return(Json(result));
        }
コード例 #5
0
        public IHttpActionResult GetUserInfoByCode(string usercode, string store)
        {
            LogHelper.WriteLog("GetUserInfoByCode usercode" + usercode);
            LogHelper.WriteLog("GetUserInfoByCode store" + store);
            SimpleResult      result            = new SimpleResult();
            IUserInfo         _service          = new UserInfo();
            ICustomerServiceS _customerServiceS = new CustomerServiceS();
            IOrderService     _OrderService     = new OrderService();
            ICouponService    _CouponService    = new CouponService();
            UserInfoModel     userInfo          = new UserInfoModel();
            IUseWalletService _useWalletService = new UseWalletService();
            IUserTaskService  _userTaskService  = new UserTaskService();

            try
            {
                if (UserAuthorization)
                {
                    var user = _service.GetUserByCode(usercode);
                    userInfo.user = user;
                    var customerService = _customerServiceS.GetCustomerService(store);
                    userInfo.customerService = customerService;
                    var orders = _OrderService.GetOrderList(usercode);
                    userInfo.useWalletInfo = _useWalletService.GetUseWalletInfoByUserCode(usercode);
                    var conponList = _CouponService.GetUserCoupon(usercode);
                    userInfo.useCouponCount = conponList.Any()?conponList.Count:0;
                    if (orders != null)
                    {
                        userInfo.orders = orders.Where(p => p.PayTime != null && p.IsWriteOff == false).Count();
                    }
                    var coupons = _CouponService.GetCouponList(usercode);
                    if (coupons != null)
                    {
                        userInfo.coupons = coupons.Where(c => c.IsUsed == false).Count();
                    }
                    var userTask = _userTaskService.GetUserTaskList(user.Code);
                    if (userTask != null)
                    {
                        userInfo.userTask = userTask.Where(t => t.IsComplete == false).Count();
                    }
                    userInfo.openCard = new OpenCard();
                    var cardId = ConfigurationManager.AppSettings["cardId"].ToString();
                    userInfo.openCard.cardId = cardId;
                    userInfo.openCard.code   = userInfo.user?.ReferenceNumber;
                    result.Resource          = userInfo;
                    result.Status            = Result.SUCCEED;
                }
                else
                {
                    result.Status   = ResultType;
                    result.Resource = ReAccessToken;
                    result.Msg      = TokenMessage;
                }
            }
            catch (Exception ex)
            {
                LogHelper.WriteLog("GetUserInfoByCode usercode" + usercode + "store" + store, ex);
                result.Status = Result.FAILURE;
                result.Msg    = ex.Message;
            }
            LogHelper.WriteLog("GetUserInfoByCode result" + Json(result));
            return(Json(result));
        }
コード例 #6
0
        public IHttpActionResult  Recharge(string typeCode, string userCode, string storeCode, decimal?money = 0)
        {
            LogHelper.WriteLog("Recharge typeCode" + typeCode);
            LogHelper.WriteLog("Recharge userCode" + userCode);
            LogHelper.WriteLog("Recharge storeCode" + storeCode);
            LogHelper.WriteLog("Recharge money" + money);
            ICouponService         _couponService    = new CouponService();
            IUseWalletService      _useWalletService = new UseWalletService();
            IStoreService          _stoeservice      = new StoreService();
            SimpleResult           result            = new SimpleResult();
            IRechargeRecordService _service          = new RechargeRecordService();

            try
            {
                if (UserAuthorization)
                {
                    using (var scope = new TransactionScope())//创建事务
                    {
                        IUserStoreService    _userStoreservice = new UserStoreService();
                        IRechargeTypeService s   = new RechargeTypeService();
                        ITopupOrderServrce   tos = new TopupOrderServrce();
                        var store        = _stoeservice.GetStore(storeCode);
                        var userStoreser = _userStoreservice.GetUserStorebyUserCodestoreCode(userCode, storeCode);
                        if (userStoreser != null)
                        {//生成微信预支付订单
                            string  rechargeTypeName = "充值";
                            decimal?donationAmount   = 0;
                            if (typeCode == "0")
                            {
                                donationAmount = 0;
                            }
                            else
                            {
                                var type = s.GetRechargeTypeByCode(typeCode);
                                rechargeTypeName = type.RechargeTypeName;
                                donationAmount   = type?.DonationAmount;
                                money            = type?.Money;
                            }
                            var wxprepay = Common.wxPayOrderSomething(userStoreser.OpenID, money.ToString(), rechargeTypeName, store);
                            if (wxprepay != null)
                            {
                                //更新充值预订单
                                //给TopupOrder写数据
                                tos.InsertTopupOrder(userCode, wxprepay.prepayid, typeCode, money);

                                WxOrder wxorder = new WxOrder();
                                wxorder.orderCode    = null;
                                wxorder.wxJsApiParam = wxprepay.wxJsApiParam;
                                wxorder.prepayid     = wxprepay.prepayid;
                                result.Resource      = wxorder;
                                wxorder.IsWxPay      = true;
                                result.Status        = Result.SUCCEED;
                            }
                            else
                            {
                                result.Resource = "微信充值失败,重新充值";
                                result.Status   = Result.SYSTEM_ERROR;
                            }
                        }
                        scope.Complete();//这是最后提交事务
                    }
                }
                else
                {
                    result.Status   = ResultType;
                    result.Resource = ReAccessToken;
                    result.Msg      = TokenMessage;
                }
            }
            catch (Exception ex)
            {
                LogHelper.WriteLog("wxPrePay typeCode" + typeCode + " userCode" + userCode + " storeCode" + storeCode + " money" + money, ex);
                result.Status = Result.FAILURE;
                result.Msg    = ex.Message;
            }
            LogHelper.WriteLog("Recharge result" + Json(result));
            return(Json(result));
        }