Пример #1
0
        public string Execute(Hashtable params_ht)
        {
            Hashtable res = params_ht;

            if (res["UID"] == null || res["UID"].ToString().Trim().Length <= 0 ||
                res["PayWay"] == null || res["PayWay"].ToString().Trim().Length <= 0 ||
                res["OrderNum"] == null || res["OrderNum"].ToString().Trim().Length <= 0 ||
                res["OpenID"] == null || res["OpenID"].ToString().Trim().Length <= 0)
            {
                return(SiteHelper.GetJsonFromHashTable(null, "faild", "参数不完整"));
            }
            else
            {
                uid    = res["UID"].ToString().Trim();
                openID = res["OpenID"].ToString().Trim();
                ip     = HttpContext.Current.Request.UserHostAddress;
                int.TryParse(res["PayWay"].ToString().Trim(), out payway);
                string            ordernum      = res["OrderNum"].ToString().Trim();
                string            couponID      = "";
                OrdersManager     om            = new OrdersManager();
                UserCouponManager couponManager = new UserCouponManager();
                Hashtable         order_ht      = om.GetOrderInfoByNum(ordernum);
                if (order_ht == null)
                {
                    return(SiteHelper.GetJsonFromHashTable(null, "faild", "未找到订单数据,支付失败"));
                }
                int     payState   = int.Parse(SiteHelper.GetHashTableValueByKey(order_ht, "PayState"));
                int     orderState = int.Parse(SiteHelper.GetHashTableValueByKey(order_ht, "OrderState"));
                decimal payMoney   = decimal.Parse(SiteHelper.GetHashTableValueByKey(order_ht, "PayMoney"));
                decimal totalMoney = decimal.Parse(SiteHelper.GetHashTableValueByKey(order_ht, "TotalMoney"));

                if (OrderState.UnPay.GetHashCode() != orderState)
                {
                    return(SiteHelper.GetJsonFromHashTable(null, "faild", "订单支付失败"));
                }
                if (payMoney <= 0)
                {
                    return(SiteHelper.GetJsonFromHashTable(null, "faild", "未产生支付费用,无需进行支付操作"));
                }

                if (res["CouponID"] != null && res["CouponID"].ToString().Trim().Length > 0)
                {
                    couponID = res["CouponID"].ToString().Trim();
                    Hashtable coupon_ht = couponManager.GetDataByID(couponID);
                    if (coupon_ht == null || coupon_ht.Keys.Count == 0)
                    {
                        return(SiteHelper.GetJsonFromHashTable(null, "faild", "使用骑行券失败,支付失败"));
                    }
                    string  orderid     = SiteHelper.GetHashTableValueByKey(coupon_ht, "OrderID");
                    string  begintime   = SiteHelper.GetHashTableValueByKey(coupon_ht, "BeginTime");
                    string  endtime     = SiteHelper.GetHashTableValueByKey(coupon_ht, "EndTime");
                    string  userid      = SiteHelper.GetHashTableValueByKey(coupon_ht, "UserID");
                    decimal couponMoney = 0.00m;
                    decimal.TryParse(SiteHelper.GetHashTableValueByKey(coupon_ht, "Money"), out couponMoney);
                    if (userid != uid)
                    {
                        return(SiteHelper.GetJsonFromHashTable(null, "faild", "使用骑行券失败,支付失败"));
                    }
                    if (!string.IsNullOrEmpty(orderid))
                    {
                        return(SiteHelper.GetJsonFromHashTable(null, "faild", "使用骑行券失败,支付失败"));
                    }
                    if (DateTime.Parse(begintime) > DateTime.Now || DateTime.Parse(endtime) < DateTime.Now)
                    {
                        return(SiteHelper.GetJsonFromHashTable(null, "faild", "使用骑行券失败,支付失败"));
                    }
                    if (couponMoney > totalMoney)
                    {
                        return(SiteHelper.GetJsonFromHashTable(null, "faild", "使用骑行券失败,支付失败"));
                    }

                    Hashtable update_order_ht = new Hashtable();
                    update_order_ht["CouponID"]    = couponID;
                    update_order_ht["CouponMoney"] = couponMoney;
                    update_order_ht["PayMoney"]    = totalMoney - couponMoney;
                    bool rrr = om.AddOrEditOrdersInfo(update_order_ht, SiteHelper.GetHashTableValueByKey(order_ht, "ID"));
                }

                webRoot         = SiteHelper.GetWebRoot();
                weixinNotifyUrl = string.Format("{0}{1}", webRoot, "/api/weapp/pay/wxpay/order_notify_url.aspx");
                alipayNotifyUrl = string.Format("{0}{1}", webRoot, "/api/weapp/pay/alipay/order_notify_url.aspx");

                string result = "";
                switch (payway)
                {
                case 1:
                    result = AliPay(uid, ordernum);
                    break;

                case 2:
                    result = WxPay(uid, ordernum);
                    break;

                case 3:
                    result = BalancePay(uid, ordernum);
                    break;

                default:
                    break;
                }
                return(result);
            }
        }
Пример #2
0
        public string Execute(Hashtable params_ht)
        {
            Hashtable res = params_ht;

            if (res["UID"] == null || res["UID"].ToString().Trim().Length <= 0 ||
                res["PayWay"] == null || res["PayWay"].ToString().Trim().Length <= 0 ||
                res["OrderNum"] == null || res["OrderNum"].ToString().Trim().Length <= 0)
            {
                return(SiteHelper.GetJsonFromHashTable(null, "faild", "参数不完整"));
            }
            else
            {
                uid = res["UID"].ToString().Trim();
                int.TryParse(res["PayWay"].ToString().Trim(), out payway);
                cacheKey += uid;
                string ordernum                    = res["OrderNum"].ToString().Trim();
                string couponID                    = "";
                UserFinancialManager ufm           = new UserFinancialManager();
                UserInfoManager      uim           = new UserInfoManager();
                OrdersManager        om            = new OrdersManager();
                UserCouponManager    couponManager = new UserCouponManager();
                Hashtable            order_ht      = om.GetOrderInfoByNum(ordernum);
                if (order_ht == null)
                {
                    return(SiteHelper.GetJsonFromHashTable(null, "faild", "未找到订单数据,支付失败"));
                }
                int     payState   = int.Parse(SiteHelper.GetHashTableValueByKey(order_ht, "PayState"));
                int     orderState = int.Parse(SiteHelper.GetHashTableValueByKey(order_ht, "OrderState"));
                decimal payMoney   = decimal.Parse(SiteHelper.GetHashTableValueByKey(order_ht, "PayMoney"));
                decimal totalMoney = decimal.Parse(SiteHelper.GetHashTableValueByKey(order_ht, "TotalMoney"));

                if (OrderState.UnPay.GetHashCode() != orderState)
                {
                    return(SiteHelper.GetJsonFromHashTable(null, "faild", "订单支付失败"));
                }
                if (totalMoney <= 0)
                {
                    return(SiteHelper.GetJsonFromHashTable(null, "faild", "未产生支付费用,无需进行支付操作"));
                }

                #region 检测前一笔未确认支付交易是否成功,成功则禁止重复支付

                Hashtable financial_ht = ufm.GetLatestUserFinancialInfo(uid, UserFinancialState.NewSubmit, UserFinancialChangesType.Consumption);
                if (financial_ht != null && financial_ht.Keys.Count > 0)
                {
                    string order_num    = SiteHelper.GetHashTableValueByKey(financial_ht, "OrderNum");
                    string order_payid  = SiteHelper.GetHashTableValueByKey(financial_ht, "OrderPayID");
                    string operator_way = SiteHelper.GetHashTableValueByKey(financial_ht, "OperatorWay");
                    if (operator_way == UserFinancialOperatorWay.WeixinPay.GetHashCode().ToString())
                    {
                        WxOrderQuery     orderQuery  = new WxOrderQuery();
                        OrderQueryResult queryResult = orderQuery.Query(order_payid);
                        if (queryResult.trade_state == TradeStateEnum.SUCCESS)
                        {
                            Hashtable hashuf = new Hashtable();
                            hashuf["ID"]       = SiteHelper.GetHashTableValueByKey(financial_ht, "ID");
                            hashuf["OrderNum"] = SiteHelper.GetHashTableValueByKey(financial_ht, "OrderNum");
                            hashuf["UserID"]   = SiteHelper.GetHashTableValueByKey(financial_ht, "UserID");
                            hashuf["State"]    = UserFinancialState.Effect.GetHashCode();
                            hashuf["TradeNo"]  = queryResult.transaction_id;
                            hashuf["TotalFee"] = queryResult.total_fee;
                            hashuf["PayWay"]   = UserFinancialOperatorWay.WeixinPay;
                            decimal changesAmount = 0.00m;
                            decimal.TryParse(SiteHelper.GetHashTableValueByKey(financial_ht, "ChangesAmount"), out changesAmount);
                            bool isSuccess = false;
                            if (Math.Abs(changesAmount) == queryResult.total_fee)
                            {
                                isSuccess = uim.OrderPayCallback(hashuf);
                            }
                            if (isSuccess && ordernum == order_num)
                            {
                                return(SiteHelper.GetJsonFromHashTable(null, "faild", "您当前订单已成功支付"));
                            }
                        }
                    }
                    else if (operator_way == UserFinancialOperatorWay.Alipay.GetHashCode().ToString())
                    {
                        AlipayOrderQuery orderQuery  = new AlipayOrderQuery();
                        OrderQueryResult queryResult = orderQuery.Query(order_payid);
                        if (queryResult.trade_state == TradeStateEnum.SUCCESS)
                        {
                            Hashtable hashuf = new Hashtable();
                            hashuf["ID"]       = SiteHelper.GetHashTableValueByKey(financial_ht, "ID");
                            hashuf["OrderNum"] = SiteHelper.GetHashTableValueByKey(financial_ht, "OrderNum");
                            hashuf["UserID"]   = SiteHelper.GetHashTableValueByKey(financial_ht, "UserID");
                            hashuf["State"]    = UserFinancialState.Effect.GetHashCode();
                            hashuf["TradeNo"]  = queryResult.transaction_id;
                            hashuf["TotalFee"] = queryResult.total_fee;
                            hashuf["PayWay"]   = UserFinancialOperatorWay.Alipay;
                            decimal changesAmount = 0.00m;
                            decimal.TryParse(SiteHelper.GetHashTableValueByKey(financial_ht, "ChangesAmount"), out changesAmount);
                            bool isSuccess = false;
                            if (Math.Abs(changesAmount) == queryResult.total_fee)
                            {
                                isSuccess = uim.OrderPayCallback(hashuf);
                            }
                            if (isSuccess && ordernum == order_num)
                            {
                                return(SiteHelper.GetJsonFromHashTable(null, "faild", "您当前订单已成功支付"));
                            }
                        }
                    }
                }

                #endregion

                if (res["CouponID"] != null && res["CouponID"].ToString().Trim().Length > 0)
                {
                    couponID = res["CouponID"].ToString().Trim();
                    Hashtable coupon_ht = couponManager.GetDataByID(couponID);
                    if (coupon_ht == null || coupon_ht.Keys.Count == 0)
                    {
                        return(SiteHelper.GetJsonFromHashTable(null, "faild", "使用骑行券失败,支付失败"));
                    }
                    string  orderid     = SiteHelper.GetHashTableValueByKey(coupon_ht, "OrderID");
                    string  begintime   = SiteHelper.GetHashTableValueByKey(coupon_ht, "BeginTime");
                    string  endtime     = SiteHelper.GetHashTableValueByKey(coupon_ht, "EndTime");
                    string  userid      = SiteHelper.GetHashTableValueByKey(coupon_ht, "UserID");
                    decimal couponMoney = 0.00m;
                    decimal.TryParse(SiteHelper.GetHashTableValueByKey(coupon_ht, "Money"), out couponMoney);
                    if (userid != uid)
                    {
                        return(SiteHelper.GetJsonFromHashTable(null, "faild", "使用骑行券失败,支付失败"));
                    }
                    if (!string.IsNullOrEmpty(orderid))
                    {
                        return(SiteHelper.GetJsonFromHashTable(null, "faild", "使用骑行券失败,支付失败"));
                    }
                    if (DateTime.Parse(begintime) > DateTime.Now || DateTime.Parse(endtime) < DateTime.Now)
                    {
                        return(SiteHelper.GetJsonFromHashTable(null, "faild", "使用骑行券失败,支付失败"));
                    }
                    if (couponMoney > totalMoney)
                    {
                        return(SiteHelper.GetJsonFromHashTable(null, "faild", "使用骑行券失败,支付失败"));
                    }

                    Hashtable update_order_ht = new Hashtable();
                    update_order_ht["CouponID"]    = couponID;
                    update_order_ht["CouponMoney"] = couponMoney;
                    update_order_ht["PayMoney"]    = totalMoney - couponMoney;
                    bool rrr = om.AddOrEditOrdersInfo(update_order_ht, SiteHelper.GetHashTableValueByKey(order_ht, "ID"));
                }

                webRoot         = SiteHelper.GetWebRoot();
                weixinNotifyUrl = string.Format("{0}{1}", webRoot, "/api/app/pay/wxpay/order_notify_url.aspx");
                alipayNotifyUrl = string.Format("{0}{1}", webRoot, "/api/app/pay/alipay/order_notify_url.aspx");

                string result = "";
                ICache cache  = null;
                switch (payway)
                {
                case 1:
                    cache = CacheFactory.GetCache();
                    if (!string.IsNullOrEmpty(cache.Get <string>(cacheKey)))
                    {
                        cache.Dispose();
                        Logger.Error("订单支付宝支付5秒内," + uid);
                        return(SiteHelper.GetJsonFromHashTable(null, "faild", "5秒内请勿重复点击"));
                    }
                    cache.Dispose();
                    result = AliPay(uid, ordernum);
                    break;

                case 2:
                    cache = CacheFactory.GetCache();
                    if (!string.IsNullOrEmpty(cache.Get <string>(cacheKey)))
                    {
                        cache.Dispose();
                        Logger.Error("订单微信支付5秒内," + uid);
                        return(SiteHelper.GetJsonFromHashTable(null, "faild", "5秒内请勿重复点击"));
                    }
                    cache.Dispose();
                    result = WxPay(uid, ordernum);
                    break;

                case 3:
                    result = BalancePay(uid, ordernum);
                    break;

                default:
                    break;
                }
                return(result);
            }
        }