Beispiel #1
0
        /// <summary>
        /// 新增成功的订单信息
        /// </summary>
        /// <param name="recharge"></param>
        private static void AddRecharge(Recharge recharge)
        {
            if (recharge == null || String.IsNullOrWhiteSpace(recharge.id))
            {
                return;
            }
            Recharge recharge1 = GetInfo(recharge.id);

            String sql = "";

            if (recharge1 != null)
            {
                sql = String.Format("update recharge set `group` = '{0}', accounts='{1}', time='{2}', money = '{3}', agent = '{4}' where id = '{5}' ", recharge.group, recharge.accounts, recharge.time, recharge.money, recharge.agent, recharge.id);
                DBUtils.ExecuteNonQuery(sql);

                FileLogUtils.Info("AddRecharge", "历史订单已处理:" + recharge.ToJsonString());
            }
            else
            {
                sql = String.Format("insert into recharge(id,`group`,accounts,time,money,agent) values('{0}','{1}','{2}','{3}','{4}','{5}')", recharge.id, recharge.group, recharge.accounts, recharge.time, recharge.money, recharge.agent);
                DBUtils.ExecuteNonQuery(sql);

                FileLogUtils.Info("AddRecharge", "新订单生成成功:" + recharge.ToJsonString());
            }
        }
Beispiel #2
0
        /// <summary>
        /// 更新历史订单信息(主要用于更新支付状态)
        /// </summary>
        /// <param name="recharge"></param>
        public static void UpdateRechargeState(Recharge recharge)
        {
            lock (LockObj)
            {
                if (recharge == null || String.IsNullOrWhiteSpace(recharge.id))
                {
                    FileLogUtils.Info("UpdateRechargeState", "订单参数异常:" + recharge.ToJsonString());
                    return;
                }
                Recharge recharge1 = GetHistoryInfo(recharge.id);
                if (recharge1 == null)
                {
                    FileLogUtils.Info("UpdateRechargeState", "历史订单不存在:" + recharge.ToJsonString());
                    return;
                }

                String sql = "";
                if (String.IsNullOrEmpty(recharge1.pay_orderid) && recharge1.pay_orderid != recharge.pay_orderid)
                {
                    sql = String.Format("update recharge_history set pay_orderid = '{0}' where id = '{1}' ", recharge.pay_orderid, recharge1.id);
                    DBUtils.ExecuteNonQuery(sql);
                    FileLogUtils.Info("UpdateRechargeState", "支付平台流水号已记录:" + recharge.ToJsonString());
                }
                if (recharge1.payStatus == 1)
                {
                    FileLogUtils.Info("UpdateRechargeState", "历史订单已处理:" + recharge.ToJsonString());
                    return;
                }
                sql = String.Format("update recharge_history set payState = {0}, pay_money={1}, pay_orderid='{2}' where id = '{3}' ", recharge.payStatus, recharge.pay_money, recharge.pay_orderid, recharge1.id);
                DBUtils.ExecuteNonQuery(sql);
                FileLogUtils.Info("UpdateRechargeState", "历史订单状态已变更:" + recharge.ToJsonString());

                if (recharge.payStatus == 1)
                {
                    recharge1.payStatus   = 1;
                    recharge1.money       = recharge.pay_money.Value;
                    recharge1.pay_orderid = recharge.pay_orderid;
                    AddRecharge(recharge1);
                }
            }
        }
Beispiel #3
0
        /// <summary>
        ///
        /// </summary>
        /// <param name="param"></param>
        /// <returns></returns>
        public static Result1 getPostParam(RequestParam param, String sessionCode)
        {
            Result1 result = new Result1();

            try
            {
                Decimal doubleMoney = 0;
                if (!Decimal.TryParse(param.pay_amount, out doubleMoney))
                {
                    result.status  = "failed";
                    result.message = "支付金额出现异常,请稍候再试.";
                    return(result);
                }
                if (doubleMoney <= 0)
                {
                    result.status  = "failed";
                    result.message = "支付金额出现异常,请稍候再试.";
                    return(result);
                }

                if (String.IsNullOrEmpty(sessionCode) ||
                    String.IsNullOrEmpty(param.code) ||
                    sessionCode.ToUpper() != param.code.ToUpper())
                {
                    result.status  = "failed";
                    result.message = "验证码错误,请重新输入.";
                    return(result);
                }
                if (String.IsNullOrWhiteSpace(param.pay_orderid) ||
                    String.IsNullOrWhiteSpace(param.pay_amount) ||
                    String.IsNullOrWhiteSpace(param.group) ||
                    String.IsNullOrWhiteSpace(param.pay_bankcode) ||
                    String.IsNullOrWhiteSpace(param.code))
                {
                    result.status  = "failed";
                    result.message = "提交数据出现异常,请稍候再试.";
                    return(result);
                }

                PayType payType = ConfigUtils.PayTypes.FirstOrDefault(A => A.Key == param.pay_bankcode);
                if (payType == null)
                {
                    result.status  = "failed";
                    result.message = "不支持该支付类型,请重新提交.";
                    return(result);
                }

                UserAccount userAccount = AccountUntils.GetInfo(param.accounts);
                if (userAccount == null)
                {
                    result.status  = "failed";
                    result.message = "充值账号不存在,请重新提交.";
                    return(result);
                }
                //if (String.IsNullOrEmpty(userAccount.agent))
                //{
                //    result.status = "failed";
                //    result.message = "代理不存在,无法充值.";
                //    return result;
                //}
                if (String.IsNullOrEmpty(userAccount.agent))
                {
                    userAccount.agent = "";
                }

                //写入历史订单表
                Recharge recharge = new Recharge();
                recharge.id        = param.pay_orderid;
                recharge.group     = param.group;
                recharge.accounts  = param.accounts;
                recharge.agent     = userAccount.agent;
                recharge.money     = Double.Parse(doubleMoney.ToString());
                recharge.time      = TimeUntils.GetNow();
                recharge.payStatus = 0;
                recharge.payType   = param.pay_bankcode;

                //Post参数
                SortedDictionary <string, string> pay_params = new SortedDictionary <string, string>();
                pay_params.Add("pid", ConfigUtils.pid);
                pay_params.Add("type", recharge.payType);            //平台分配商户号
                pay_params.Add("out_trade_no", recharge.id);         //订单号
                pay_params.Add("notify_url", ConfigUtils.notifyurl); //服务端返回地址(POST返回数据)
                pay_params.Add("return_url", ConfigUtils.returnurl); //页面跳转返回地址(POST返回数据)
                pay_params.Add("name", "充值");
                pay_params.Add("money", doubleMoney.ToString("F2")); //支付金额
                pay_params.Add("sitename", ConfigUtils.sitename);

                String sign = CommonUntils.getSign(pay_params);
                pay_params.Add("sign", sign);
                pay_params.Add("sign_type", "MD5");
                pay_params.Add("remark", Base64.Encode(recharge.ToJsonString()));

                String postMessage = pay_params.ToJsonString();
                postMessage = Base64.Encode(postMessage);

                result.status  = "1";
                result.postUrl = "PayNet.aspx";
                result.message = postMessage;
                return(result);
            }
            catch (Exception ex)
            {
                FileLogUtils.Error("getPostParam", ex.StackTrace);
                result.status  = "failed";
                result.message = "服务器出现异常,请稍候再试.";
                return(result);
            }
        }