Exemplo n.º 1
0
        /// <summary>
        /// 发起退款请求
        /// </summary>
        /// <param name="out_order_no">订单号必填</param>
        /// <param name="create_time">否,当仅上送out_order_no需上送,若不上送,默认当天</param>
        /// <param name="num8">退款金额</param>
        /// <returns></returns>
        private bool RefundRequest(string out_order_no, string create_time, double num8)
        {
            string refund_request_no = Guid.NewGuid().ToString("N").ToString();
            string refundResult      = HeMaPay.Refund(out_order_no.ToString(), refund_request_no, num8, create_time);

            if (string.IsNullOrWhiteSpace(refundResult))
            {
                return(RefundDB(refund_request_no, out_order_no, refundResult, "0"));
            }
            else
            {
                JObject retRefundObj = JObject.Parse(refundResult);
                if (retRefundObj["code"].ToString().Equals("200"))
                {
                    JObject retRefundDetailObj = JObject.Parse(retRefundObj["data"].ToString());
                    if (retRefundDetailObj["sub_code"].ToString().Equals("REFUND_SUCCESS"))
                    {
                        return(RefundDB(refund_request_no, out_order_no, refundResult, "1"));
                    }
                    else
                    {
                        return(RefundDB(refund_request_no, out_order_no, refundResult, "0"));
                    }
                }
                else
                {
                    return(RefundDB(refund_request_no, out_order_no, refundResult, "0"));
                }
            }
        }
Exemplo n.º 2
0
        private void RefundFailedTask()
        {
            DbUtil    dbUtil     = new DbUtil();
            DataTable dataTable2 = dbUtil.ExecuteQuery("SELECT * FROM he_ma_pay_refund_failed");

            if (dataTable2 != null)
            {
                for (int i = 0; i < dataTable2.Rows.Count; i++)
                {
                    DataRow dataRow      = dataTable2.Rows[i];
                    string  out_order_no = dataRow["out_order_no"].ToString();
                    string  total_amount = dataRow["total_amount"].ToString();
                    string  create_time  = dataRow["create_time"].ToString();

                    // 发起退款请求
                    string refundResult = HeMaPay.Refund(out_order_no, Guid.NewGuid().ToString("N").ToString(), double.Parse(total_amount), create_time);
                    if (!string.IsNullOrWhiteSpace(refundResult))
                    {
                        JObject retRefundObj2 = JObject.Parse(refundResult);
                        if (retRefundObj2["code"].ToString().Equals("200"))
                        {
                            JObject retRefundDetailObj2 = JObject.Parse(retRefundObj2["data"].ToString());
                            if (retRefundDetailObj2["sub_code"].ToString().Equals("REFUND_SUCCESS"))
                            {
                                // 退款成功修改数据
                                refundOK(out_order_no, refundResult);
                            }
                        }
                    }
                }
            }
        }
Exemplo n.º 3
0
        private void CloseOrder(string out_order_no, string queryResult, JObject retQueryObj, JObject retQueryDetailObj)
        {
            string retCancel = HeMaPay.Close(out_order_no);

            if (!string.IsNullOrWhiteSpace(retCancel))
            {
                JObject retCancelObj       = JObject.Parse(retCancel);
                JObject retCancelDetailObj = JObject.Parse(retCancelObj["data"].ToString());

                if ("CLOSE_FAILED".Equals(retCancelDetailObj["sub_code"].ToString().Trim()))
                {
                    string pay_way = retQueryDetailObj["pay_way_code"].ToString().Trim();
                    if (pay_way.Equals(PayWay.ALIPAY.ToString()))
                    {
                        // 写数据入库 支付宝未扫码不能完成关闭订单
                        closeDB(out_order_no, retCancel, queryResult);
                    }
                    else
                    {
                        closeDB(out_order_no, retCancel, queryResult, "0");
                    }
                }
                else if ("CLOSE_SUCCESS".Equals(retCancelDetailObj["sub_code"].ToString().Trim()))
                {
                    // 写数据入库
                    closeDB(out_order_no, retCancel, queryResult);
                }
                else
                {
                    // 写数据入库
                    closeDB(out_order_no, retCancel, queryResult, "0");
                }
            }
        }
Exemplo n.º 4
0
        /// <summary>
        /// 退款
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void button3_Click(object sender, EventArgs e)
        {
            string refund_request_no = Guid.NewGuid().ToString();

            this.textBox_refund_request_no.Text = refund_request_no;
            string out_order_no      = this.textBox1.Text;
            string amount            = this.textBox2.Text;
            string order_create_time = strToTime(this.textBox3.Text);

            if (string.IsNullOrWhiteSpace(out_order_no) || string.IsNullOrWhiteSpace(amount) || string.IsNullOrWhiteSpace(order_create_time))
            {
                WMMessageBox.Show(this, "请选择退款错误的数据!");
                return;
            }
            double refund_fee   = double.Parse(amount);
            string refundResult = HeMaPay.Refund(out_order_no, refund_request_no, refund_fee, order_create_time);

            if (string.IsNullOrWhiteSpace(refundResult))
            {
                RefundDB(out_order_no, refundResult, "0");
                WMMessageBox.Show(this, "退款失败,请稍后再试!");
                return;
            }
            else
            {
                JObject retRefundObj = JObject.Parse(refundResult);
                if (retRefundObj["code"].ToString().Equals("200"))
                {
                    JObject retRefundDetailObj = JObject.Parse(retRefundObj["data"].ToString());
                    if (retRefundDetailObj["sub_code"].ToString().Equals("REFUND_SUCCESS"))
                    {
                        refundOK(out_order_no, refundResult);
                        cleanData();
                        initDGV();
                        WMMessageBox.Show(this, "退款成功!");
                        return;
                    }
                    else
                    {
                        RefundDB(out_order_no, refundResult, "0");
                        showCauseOfError(retRefundDetailObj);
                        WMMessageBox.Show(this, "退款失败!");
                        return;
                    }
                }
                else
                {
                    RefundDB(out_order_no, refundResult, "0");
                    showCauseOfError(retRefundObj);
                    WMMessageBox.Show(this, "退款失败!");
                    return;
                }
            }
        }
Exemplo n.º 5
0
        private void timer1_Tick(object sender, EventArgs e)
        {
            this.pay_time_out = this.pay_time_out - 1;
            this.label5.Text  = $"缴费倒计时{this.pay_time_out}秒";

            // 支付超时超时
            if (this.pay_time_out == 0)
            {
                this.timer1.Stop();
                this.timer1.Enabled = false;

                string queryResult = HeMaPay.Query(out_order_no.ToString(), create_time);
                if (string.IsNullOrWhiteSpace(queryResult))
                {
                    this.Close();
                    this.mainForm.Close();
                }
                else
                {
                    JObject retQueryObj       = JObject.Parse(queryResult);
                    JObject retQueryDetailObj = JObject.Parse(retQueryObj["data"].ToString());
                    if (retQueryObj["code"].ToString().Equals("200") && retQueryDetailObj["sub_code"].ToString().Equals("SUCCESS"))
                    {
                        this.Close();
                        this.mainForm.PaySucceed(queryResult, retQueryObj, retQueryDetailObj, out_order_no.ToString(), this.create_time);
                    }
                    else
                    {
                        CloseOrder(out_order_no.ToString(), queryResult, retQueryObj, retQueryDetailObj);
                        this.Close();
                        this.mainForm.Close();
                    }
                }
            }
            else
            {
                if (this.pay_time_out % this.pay_poll_time == 0)
                {
                    string  queryResult       = HeMaPay.Query(out_order_no.ToString(), create_time);
                    JObject retQueryObj       = JObject.Parse(queryResult);
                    JObject retQueryDetailObj = JObject.Parse(retQueryObj["data"].ToString());
                    if (retQueryObj["code"].ToString().Equals("200") && retQueryDetailObj["sub_code"].ToString().Equals("SUCCESS"))
                    {
                        this.Close();
                        this.timer1.Stop();
                        this.timer1.Enabled = false;
                        this.mainForm.PaySucceed(queryResult, retQueryObj, retQueryDetailObj, out_order_no.ToString(), this.create_time);
                        return;
                    }
                }
            }
        }
Exemplo n.º 6
0
        private void CloseForm()
        {
            string queryResult = HeMaPay.Query(out_order_no.ToString(), create_time);

            if (string.IsNullOrWhiteSpace(queryResult))
            {
                this.Close();
                this.mainForm.Close();
            }
            else
            {
                JObject retQueryObj       = JObject.Parse(queryResult);
                JObject retQueryDetailObj = JObject.Parse(retQueryObj["data"].ToString());
                if (retQueryObj["code"].ToString().Equals("200") && retQueryDetailObj["sub_code"].ToString().Equals("SUCCESS"))
                {
                    this.Close();
                    this.mainForm.PaySucceed(queryResult, retQueryObj, retQueryDetailObj, out_order_no.ToString(), this.create_time);
                }
                else
                {
                    CloseOrder(out_order_no.ToString(), queryResult, retQueryObj, retQueryDetailObj);
                }
            }
        }
Exemplo n.º 7
0
        private void showPayForm(object sender, EventArgs e, string amount = null)
        {
            this.resetTimeOut();
            if (!this.payWaySelect)
            {
                WMMessageBox.Show(this, "请选择支付方式!");
                return;
            }
            if (string.IsNullOrWhiteSpace(amount))
            {
                // 计算支付金额以及购买量
                calculateFee(((Button)sender).Text.Trim());
            }
            else
            {
                calculateFee(amount);
            }

            // 验证
            double num3 = ConvertUtils.ToDouble(this.limitPursuitTB.Text);
            double num4 = ConvertUtils.ToDouble(this.payNumTBText.Trim());

            if (num4 < 0.0)
            {
                WMMessageBox.Show(this, "购买量不得小于0!");
                return;
            }
            if (num4 > num3 && num3 != 0.0)
            {
                WMMessageBox.Show(this, "超出该用户类型限购量!");
                return;
            }
            ConsumeCardEntity consumeCardEntity = null;

            int num5 = isValidCard(false);

            if (num5 == 2)
            {
                consumeCardEntity = this.parseCard(false);
                if (consumeCardEntity == null)
                {
                    return;
                }
            }
            if (consumeCardEntity == null)
            {
                return;
            }
            if (consumeCardEntity != null)
            {
                if (consumeCardEntity != null && consumeCardEntity.DeviceHead.DeviceIdFlag == 0U)
                {
                    WMMessageBox.Show(this, "此卡未开户,不能写入数据!");
                    return;
                }
                if (consumeCardEntity != null && consumeCardEntity.DeviceHead.ConsumeFlag == 0U)
                {
                    WMMessageBox.Show(this, "此卡未刷卡,不能写入数据!");
                    return;
                }
            }

            PayForm payForm = new PayForm();

            payForm.setMainForm(this);
            payForm.setWelcomeForm(this.welcomeForm);

            string time      = DateTime.Now.ToLocalTime().ToString();
            string timestamp = DateTime.Parse(time).ToString("yyyyMMddHHmmss");
            string body      = $"购买热量:{this.payNumTBText}kWh";
            string ip        = HeMaPay.GetLocalIp();
            DbUtil db        = new DbUtil();

            db.AddParameter("pay", this.payWay.ToString());
            db.AddParameter("total_amount", this.dueNumTBText);
            db.AddParameter("body", body);
            db.AddParameter("create_time", timestamp);
            db.AddParameter("create_ip", ip);
            long out_order_no = db.ExecuteNonQueryAndReturnLastInsertRowId("INSERT INTO he_ma_pay(pay, total_amount, body, create_time, create_ip) values (@pay, @total_amount, @body, @create_time, @create_ip)");

            string payRequest = HeMaPay.Percreate(this.payWay, out_order_no.ToString(), this.dueNumTBText, body, timestamp, ip);

            if (!string.IsNullOrWhiteSpace(payRequest))
            {
                JObject retPayObJ = JObject.Parse(payRequest.ToString());
                if (retPayObJ["code"].ToString().Equals("200"))
                {
                    JObject data = JObject.Parse(retPayObJ["data"].ToString());
                    if (data["sub_code"].ToString().Equals("SUCCESS"))
                    {
                        // 下单成功, 数据入库
                        updatePayResult(db, out_order_no, payRequest, 0);

                        string qr_code = data["qr_code"].ToString().Trim();

                        string way = "";
                        if (payWay == PayWay.WECHAT)
                        {
                            way = "微信";
                        }
                        else if (payWay == PayWay.ALIPAY)
                        {
                            way = "支付宝";
                        }

                        this.timer1.Stop();
                        this.timer1.Enabled = false;

                        /****
                         * dueNum 金额
                         * payNum 购买量
                         * */
                        payForm.setInit(this.dueNumTBText, this.payNumTBText, qr_code, out_order_no, way, timestamp);
                        payForm.ShowDialog(this);
                    }
                    else
                    {
                        WMMessageBox.Show(this, data["sub_msg"].ToString() + "!");
                        return;
                    }
                }
                else
                {
                    WMMessageBox.Show(this, "下单失败!");
                    return;
                }
            }
            else
            {
                WMMessageBox.Show(this, "网络异常,请稍后再试!");
                return;
            }
        }