7 changed files with 183 additions and 107 deletions
-
143app/AdminSettled/Common/SettledPay.php
-
4app/AdminSettled/Controllers/AgentController.php
-
4app/AdminSettled/Controllers/GuideController.php
-
28app/AdminSettled/Controllers/IsPayController.php
-
107app/AdminSettled/Controllers/SupplierController.php
-
2app/AdminSettled/routes.php
-
2app/Models/Guide.php
@ -0,0 +1,143 @@ |
|||
<?php |
|||
|
|||
namespace App\AdminSettled\Common; |
|||
|
|||
use App\Models\AdminSetting; |
|||
use App\Models\Agent; |
|||
use App\Models\Guide; |
|||
use App\Models\SettledOrder; |
|||
use App\Models\Supplier; |
|||
use EasyWeChat\Factory; |
|||
|
|||
/** |
|||
* 入驻支付 |
|||
* Class SettledPay |
|||
* @package App\AdminSettled\Common |
|||
*/ |
|||
class SettledPay |
|||
{ |
|||
/** |
|||
* 获取支付回调JS |
|||
* @param $model |
|||
* @return string |
|||
* @throws \EasyWeChat\Kernel\Exceptions\InvalidArgumentException |
|||
* @throws \EasyWeChat\Kernel\Exceptions\InvalidConfigException |
|||
* @throws \GuzzleHttp\Exception\GuzzleException |
|||
*/ |
|||
public function PayJs($model): string |
|||
{ |
|||
if ($model instanceof Supplier) { |
|||
$type = 'supplier'; |
|||
} else if ($model instanceof Agent) { |
|||
$type = 'agent'; |
|||
} else if ($model instanceof Guide) { |
|||
$type = 'guide'; |
|||
} else { |
|||
return "Dcat.swal.error('无效的商家类型', null);"; |
|||
} |
|||
|
|||
$cost = AdminSetting::val("settled_{$type}_cost"); //入驻费
|
|||
$pay = $this->payConfig($model, $cost, ['supplier' => 1, 'agent' => 2, 'guide' => 3][$type]); |
|||
|
|||
if (empty($pay['code_url'])) { |
|||
if (isset($pay['result_code'], $pay['err_code_des']) && $pay['result_code'] != 'SUCCESS') { |
|||
$msg = $pay['err_code_des']; |
|||
} else { |
|||
$msg = $pay['return_msg'] ?? '获取支付信息失败'; |
|||
} |
|||
$js = "Dcat.swal.info('支付:$msg', null);"; |
|||
} else { |
|||
$ajax_url = admin_url('is_pay'); |
|||
$js = <<<JS |
|||
Dcat.swal.info( |
|||
'<div style="margin-top:1rem;"><div id="qrcode"></div><p style="text-align:center;">入驻费:¥{$cost}元</p></div>', |
|||
'<b style="color:red">请微信扫码支付,请勿关闭页面</b>', |
|||
{ |
|||
type: null, |
|||
imageWidth: 240, |
|||
imageHeight: 240, |
|||
animation: false, |
|||
// confirmButtonText: '我已完成支付,刷新',
|
|||
showConfirmButton: false, |
|||
allowOutsideClick: false, |
|||
allowEscapeKey: false, |
|||
onOpen: function () { |
|||
$('#qrcode').qrcode({text:'{$pay["code_url"]}', width:240, height:240}); |
|||
if (window.timer) { |
|||
clearInterval(window.timer); |
|||
} |
|||
window.timer = setInterval(function () { |
|||
$.ajax({ |
|||
url: '$ajax_url', |
|||
data: { |
|||
username: '{$model->username}', |
|||
type: '{$type}', |
|||
}, |
|||
success: function (res) { |
|||
if (res == 1) { |
|||
clearInterval(window.timer); |
|||
Dcat.swal.success('支付成功,请联系平台审核!', null, { |
|||
onClose: function () { |
|||
window.location.reload(); |
|||
} |
|||
}).then(() => { |
|||
window.location.reload(); |
|||
}); |
|||
} |
|||
} |
|||
}); |
|||
}, 1000); |
|||
} |
|||
}); |
|||
JS; |
|||
} |
|||
return $js; |
|||
} |
|||
|
|||
/** |
|||
* 获取支付配置 |
|||
* @param $model |
|||
* @param $cost |
|||
* @param $user_type |
|||
* @return array|\EasyWeChat\Kernel\Support\Collection|object|\Psr\Http\Message\ResponseInterface|string |
|||
* @throws \EasyWeChat\Kernel\Exceptions\InvalidArgumentException |
|||
* @throws \EasyWeChat\Kernel\Exceptions\InvalidConfigException |
|||
* @throws \GuzzleHttp\Exception\GuzzleException |
|||
*/ |
|||
private function PayConfig($model, $cost, $user_type) |
|||
{ |
|||
$setting = AdminSetting::val(['payee_appid', 'payee_mchid', 'payee_mchkey']); |
|||
$config = [ |
|||
'app_id' => $setting['payee_appid'], |
|||
'mch_id' => $setting['payee_mchid'], |
|||
'key' => $setting['payee_mchkey'], |
|||
'notify_url' => route('wxpay_settled_notify'), |
|||
]; |
|||
$app = Factory::payment($config); |
|||
|
|||
//生成订单号
|
|||
list($micro, $sec) = explode(' ', microtime()); |
|||
$micro = str_pad(floor($micro * 1000000), 6, 0, STR_PAD_LEFT); |
|||
$order_no = date('ymdHis', $sec) . $micro . mt_rand(1000, 9999); |
|||
|
|||
//保存订单记录
|
|||
SettledOrder::insertOrIgnore([ |
|||
'order_no' => $order_no, |
|||
'user_type' => $user_type, |
|||
'username' => $model->username, |
|||
'money' => $cost, |
|||
'status' => 0, |
|||
'created_at' => now(), |
|||
'updated_at' => now(), |
|||
]); |
|||
|
|||
return $app->order->unify([ |
|||
'product_id' => $model->id, |
|||
'attach' => $model->username, |
|||
'body' => mb_strcut($model->company_name . ' 入驻易游平台', 0, 127), |
|||
'out_trade_no' => $order_no, |
|||
'total_fee' => round($cost * 100), //支付金额单位为分
|
|||
'trade_type' => 'NATIVE', // 请对应换成你的支付方式对应的值类型
|
|||
]); |
|||
} |
|||
} |
|||
@ -0,0 +1,28 @@ |
|||
<?php |
|||
|
|||
namespace App\AdminSettled\Controllers; |
|||
use App\Http\Controllers\Controller; |
|||
use App\Models\SettledOrder; |
|||
|
|||
/** |
|||
* ajax回调,判断是否已经支付 |
|||
* Class IsPayController |
|||
* @package App\AdminSettled\Controllers |
|||
*/ |
|||
class IsPayController extends Controller |
|||
{ |
|||
//ajax回调,判断是否已支付
|
|||
public function index(): int |
|||
{ |
|||
$username = request()->input('username'); |
|||
$type = request()->input('type'); |
|||
|
|||
$user_type = ['supplier' => 1, 'agent' => 2, 'guide' => 3][$type] ?? die('错误的type'); |
|||
|
|||
$order = SettledOrder::where(['username' => $username, 'user_type' => $user_type])->first(); |
|||
if (!$order) { |
|||
return 0; |
|||
} |
|||
return (int)$order->status; |
|||
} |
|||
} |
|||
Write
Preview
Loading…
Cancel
Save
Reference in new issue