mirror of
https://gitee.com/technical-laohu/mpay.git
synced 2025-09-18 01:36:40 +08:00
优化代码结构
This commit is contained in:
parent
62989e4100
commit
fb2f8f2f2c
@ -20,70 +20,41 @@ class PayController
|
|||||||
'POST' => $request->post(),
|
'POST' => $request->post(),
|
||||||
default => []
|
default => []
|
||||||
};
|
};
|
||||||
if (!$req_data) {
|
if (!$req_data) return '参数错误';
|
||||||
return '参数错误';
|
// 验证签名
|
||||||
}
|
|
||||||
$key = User::where('pid', $req_data['pid'])->where('state', 1)->value('secret_key');
|
$key = User::where('pid', $req_data['pid'])->where('state', 1)->value('secret_key');
|
||||||
if (!$key) {
|
if (!$key) return '用户禁用或不存在';
|
||||||
return '用户禁用或不存在';
|
|
||||||
}
|
|
||||||
$sign_str = self::getSign($req_data, $key);
|
$sign_str = self::getSign($req_data, $key);
|
||||||
if ($req_data['sign'] === $sign_str) {
|
if ($req_data['sign'] !== $sign_str) return '签名错误';
|
||||||
// 检查商户订单
|
// 检查商户订单
|
||||||
$out_trade_no = Order::where('out_trade_no', $req_data['out_trade_no'])->value('out_trade_no');
|
$out_trade_no = Order::where('out_trade_no', $req_data['out_trade_no'])->value('out_trade_no');
|
||||||
if (!$out_trade_no) {
|
if ($out_trade_no) return '订单提交重复';
|
||||||
// 创建新订单
|
// 创建新订单
|
||||||
$order_id = Order::createOrder($req_data);
|
$order_id = Order::createOrder($req_data);
|
||||||
if ($order_id) {
|
if (!$order_id) return '创建订单失败';
|
||||||
return redirect("/Pay/console/{$order_id}");
|
return redirect("/Pay/console/{$order_id}");
|
||||||
} else {
|
|
||||||
return '创建订单失败';
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
return '订单提交重复';
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
return '签名错误';
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
// api提交订单
|
// api提交订单
|
||||||
public function mapi(Request $request)
|
public function mapi(Request $request)
|
||||||
{
|
{
|
||||||
if ($request->isPost()) {
|
if (!$request->isPost()) return '请使用POST方式提交';
|
||||||
$req_data = $request->post();
|
$req_data = $request->post();
|
||||||
if (!$req_data) {
|
if (!$req_data) $req_data = $request->get();
|
||||||
$req_data = $request->get();
|
if (!$req_data) return '参数错误';
|
||||||
if (!$req_data) {
|
// 验证签名
|
||||||
return '参数错误';
|
|
||||||
}
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
return '请使用POST方式提交';
|
|
||||||
}
|
|
||||||
$key = User::where('pid', $req_data['pid'])->where('state', 1)->value('secret_key');
|
$key = User::where('pid', $req_data['pid'])->where('state', 1)->value('secret_key');
|
||||||
if (!$key) {
|
if (!$key) return '用户禁用或不存在';
|
||||||
return '用户禁用或不存在';
|
|
||||||
}
|
|
||||||
$sign_str = self::getSign($req_data, $key);
|
$sign_str = self::getSign($req_data, $key);
|
||||||
if ($req_data['sign'] === $sign_str) {
|
if ($req_data['sign'] !== $sign_str) return '签名错误';
|
||||||
// 检查商户订单
|
// 检查商户订单
|
||||||
$out_trade_no = Order::where('out_trade_no', $req_data['out_trade_no'])->value('out_trade_no');
|
$out_trade_no = Order::where('out_trade_no', $req_data['out_trade_no'])->value('out_trade_no');
|
||||||
if (!$out_trade_no) {
|
if ($out_trade_no) return '订单提交重复';
|
||||||
// 创建新订单
|
// 创建新订单
|
||||||
$order_id = Order::createOrder($req_data);
|
$order_id = Order::createOrder($req_data);
|
||||||
if ($order_id) {
|
if (!$order_id) return '创建订单失败';
|
||||||
$payurl = $request->domain() . "/Pay/console/{$order_id}";
|
$payurl = $request->domain() . "/Pay/console/{$order_id}";
|
||||||
$info = ['code' => 1, 'msg' => '订单创建成功', 'trade_no' => $order_id, 'qrcode' => $payurl];
|
$info = ['code' => 1, 'msg' => '订单创建成功', 'trade_no' => $order_id, 'qrcode' => $payurl];
|
||||||
return json($info);
|
return json($info);
|
||||||
} else {
|
|
||||||
return '创建订单失败';
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
return '订单提交重复';
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
return '签名错误';
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
// 收银台
|
// 收银台
|
||||||
public function console($order_id = '')
|
public function console($order_id = '')
|
||||||
|
@ -13,11 +13,11 @@ class Order extends BaseModel
|
|||||||
// 订单有效期
|
// 订单有效期
|
||||||
private static $activity_time = 180;
|
private static $activity_time = 180;
|
||||||
// 新建订单
|
// 新建订单
|
||||||
public static function createOrder($data)
|
public static function createOrder($data): string|false
|
||||||
{
|
{
|
||||||
$my_time = time();
|
$my_time = time();
|
||||||
$channel = self::setChannel($data['pid'], $data['type']);
|
$channel = self::setChannel($data['pid'], $data['type']);
|
||||||
if(!$channel) return false;
|
if (!$channel) return false;
|
||||||
$new_order = [
|
$new_order = [
|
||||||
// 订单号
|
// 订单号
|
||||||
'order_id' => self::createOrderID('H'),
|
'order_id' => self::createOrderID('H'),
|
||||||
@ -140,7 +140,7 @@ class Order extends BaseModel
|
|||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if(!$channel_info) return [];
|
if (!$channel_info) return [];
|
||||||
// 选取收款通道
|
// 选取收款通道
|
||||||
$patt = PayAccount::find($channel_info->account_id);
|
$patt = PayAccount::find($channel_info->account_id);
|
||||||
$channel = ['aid' => $channel_info->account_id, 'cid' => $channel_info->id, 'patt' => $patt->getData('pattern')];
|
$channel = ['aid' => $channel_info->account_id, 'cid' => $channel_info->id, 'patt' => $patt->getData('pattern')];
|
||||||
|
Loading…
Reference in New Issue
Block a user