防止充值金额重复到账

QuickEdition(No-js-Encryption)
Max 7 years ago
parent 5eee24df84
commit 3dc8e6001a

@ -72,6 +72,54 @@ abstract class AbstractPayment
return 0;
}
public function postPaymentMaliopay($pid, $method)
{
$p = Paylist::where('tradeno', $pid)->first();
if ($p->status == 1) {
return json_encode(['errcode' => 0]);
}
$p->status = 1;
$p->save();
$user = User::find($p->userid);
$user->money += $p->total;
$user->save();
$codeq = new Code();
$codeq->code = $method;
$codeq->isused = 1;
$codeq->type = -1;
$codeq->number = $p->total;
$codeq->usedatetime = date('Y-m-d H:i:s');
$codeq->userid = $user->id;
$codeq->tradeno = $pid;
if (!$codeq->save()) {
return 0; // failed
}
if ($user->ref_by >= 1) {
$gift_user = User::where('id', '=', $user->ref_by)->first();
$gift_user->money += ($codeq->number * (Config::get('code_payback') / 100));
$gift_user->save();
$Payback = new Payback();
$Payback->total = $codeq->number;
$Payback->userid = $user->id;
$Payback->ref_by = $user->ref_by;
$Payback->ref_get = $codeq->number * (Config::get('code_payback') / 100);
$Payback->datetime = time();
$Payback->save();
}
if (Config::get('enable_donate') == 'true') {
if ($user->is_hide == 1) {
Telegram::Send('一位不愿透露姓名的大老爷给我们捐了 ' . $codeq->number . ' 元!');
} else {
Telegram::Send($user->user_name . ' 大老爷给我们捐了 ' . $codeq->number . ' 元!');
}
}
return 0;
}
public static function generateGuid()
{
mt_srand((double)microtime() * 10000);

@ -135,11 +135,11 @@ class MalioPay extends AbstractPayment
switch ($payment_system) {
case ('bitpayx'):
$bitpayx = new BitPayX(Config::get('bitpay_secret'));
if (!$bitpayx->bitpayAppSecret || $bitpayx->bitpayAppSecret === '') {
if (!Config::get('bitpay_secret') || Config::get('bitpay_secret') === '') {
$return = [];
$return['status'] = 400;
echo json_encode($return);
return;
return $return;
}
$inputString = file_get_contents('php://input', 'r');
$inputStripped = str_replace(array("\r", "\n", "\t", "\v"), '', $inputString);
@ -157,7 +157,7 @@ class MalioPay extends AbstractPayment
$resultVerify = $bitpayx->verify($str_to_sign, $inputJSON['token']);
$isPaid = $data !== null && $data['status'] !== null && $data['status'] === 'PAID';
if ($resultVerify && $isPaid) {
$bitpayx->postPayment($data['merchant_order_id'], '在线支付 ' . $data['merchant_order_id']);
$bitpayx->postPaymentMaliopay($data['merchant_order_id'], '在线支付 ' . $data['merchant_order_id']);
// echo 'SUCCESS';
$return = [];
$return['status'] = 200;
@ -168,7 +168,7 @@ class MalioPay extends AbstractPayment
$return['status'] = 400;
echo json_encode($return);
}
return 'bitpayx';
return $return;
case ('tomatopay'):
$type = $args['type'];
$settings = Config::get("tomatopay")[$type];
@ -195,7 +195,7 @@ class MalioPay extends AbstractPayment
$p = Paylist::where('tradeno', '=', $order_data['out_trade_no'])->first();
$money = $p->total;
if ($p->status != 1) {
$this->postPayment($order_data['out_trade_no'], "在线支付");
$this->postPaymentMaliopay($order_data['out_trade_no'], "在线支付");
echo 'SUCCESS';
} else {
echo 'ERROR';
@ -221,7 +221,7 @@ class MalioPay extends AbstractPayment
$aliResponse = $aliRequest->send();
$pid = $aliResponse->data('out_trade_no');
if ($aliResponse->isPaid()) {
$this->postPayment($pid, '支付宝');
$this->postPaymentMaliopay($pid, '支付宝');
die('success'); //The response should be 'success' only
}
return 'f2fpay';

@ -0,0 +1,3 @@
/* 给 code 表增加 tradeno 字段,防止重复到账 */
ALTER TABLE `code` ADD COLUMN `tradeno` varchar(255) NULL;
ALTER TABLE `code` ADD UNIQUE (`tradeno`);

@ -2,6 +2,13 @@
ALTER TABLE `user` ADD `uuid` text;
ALTER TABLE `user` ADD `phone` bigint(20) AFTER `email`;
/* 给 user 表 email 字段增加唯一属性,防止重复注册 */
ALTER TABLE `user` ADD UNIQUE (`email`);
/* 给 code 表增加 tradeno 字段,防止重复到账 */
ALTER TABLE `code` ADD COLUMN `tradeno` varchar(255) NULL;
ALTER TABLE `code` ADD UNIQUE (`tradeno`);
/* 增加 短信验证码 表 */
CREATE TABLE IF NOT EXISTS `sms_verify` (
`id` bigint(20) unsigned NOT NULL AUTO_INCREMENT,

Loading…
Cancel
Save