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