支付回调
This commit is contained in:
parent
f12b537d71
commit
cf384e724e
@ -28,12 +28,9 @@ class PayController extends BaseApiController
|
|||||||
{
|
{
|
||||||
$app = new PayService(1);
|
$app = new PayService(1);
|
||||||
$result = $app->wechat->callback(Request()->post());
|
$result = $app->wechat->callback(Request()->post());
|
||||||
Cache::set('log'.time(),$result);
|
|
||||||
Cache::set('logJ'.time(),json_encode($result));
|
|
||||||
if ($result && $result->event_type == 'TRANSACTION.SUCCESS') {
|
if ($result && $result->event_type == 'TRANSACTION.SUCCESS') {
|
||||||
$ciphertext = $result->resource['ciphertext'];
|
$ciphertext = $result->resource['ciphertext'];
|
||||||
if ($ciphertext['trade_state'] === 'SUCCESS') {
|
if ($ciphertext['trade_state'] === 'SUCCESS') {
|
||||||
$extra['transaction_id'] = $ciphertext['transaction_id'];
|
|
||||||
$attach = $ciphertext['attach'];
|
$attach = $ciphertext['attach'];
|
||||||
switch ($attach) {
|
switch ($attach) {
|
||||||
case 'wechat_common':
|
case 'wechat_common':
|
||||||
|
@ -130,7 +130,7 @@ class OrderController extends BaseApiController
|
|||||||
case PayEnum::WECHAT_PAY:
|
case PayEnum::WECHAT_PAY:
|
||||||
//微信支付
|
//微信支付
|
||||||
$redirectUrl = $params['redirect'] ?? '/pages/payment/payment';
|
$redirectUrl = $params['redirect'] ?? '/pages/payment/payment';
|
||||||
$result = PaymentLogic::pay($pay_type, 'StoreOrder', $order, $this->userInfo['terminal'], $redirectUrl);
|
$result = PaymentLogic::pay($pay_type, 'wechat_common', $order, $this->userInfo['terminal'], $redirectUrl);
|
||||||
if (PaymentLogic::hasError()) {
|
if (PaymentLogic::hasError()) {
|
||||||
return $this->fail(PaymentLogic::getError(), $params);
|
return $this->fail(PaymentLogic::getError(), $params);
|
||||||
}
|
}
|
||||||
|
@ -53,6 +53,14 @@ class OrderEnum
|
|||||||
*/
|
*/
|
||||||
const IS_OK = 1;
|
const IS_OK = 1;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 回调订单相关
|
||||||
|
* @PAY 支付
|
||||||
|
* @IBACK 退款
|
||||||
|
*/
|
||||||
|
const PAY = 1;
|
||||||
|
const BACK = 0;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 账户类型
|
* 账户类型
|
||||||
* @USER 用户
|
* @USER 用户
|
||||||
|
@ -4,6 +4,7 @@ namespace app\common\logic;
|
|||||||
|
|
||||||
use app\common\enum\OrderEnum;
|
use app\common\enum\OrderEnum;
|
||||||
use app\common\enum\PayEnum;
|
use app\common\enum\PayEnum;
|
||||||
|
use app\common\model\pay\PayNotify;
|
||||||
use app\common\model\store_finance_flow\StoreFinanceFlow;
|
use app\common\model\store_finance_flow\StoreFinanceFlow;
|
||||||
use app\common\model\store_order\StoreOrder;
|
use app\common\model\store_order\StoreOrder;
|
||||||
use app\common\model\user\User;
|
use app\common\model\user\User;
|
||||||
@ -97,7 +98,7 @@ class PayNotifyLogic extends BaseLogic
|
|||||||
} else {
|
} else {
|
||||||
PushService::push('store_merchant_' . $order['id'], $order['id'], ['type' => 'store_merchant', 'msg' => '您有一笔新的订单']);
|
PushService::push('store_merchant_' . $order['id'], $order['id'], ['type' => 'store_merchant', 'msg' => '您有一笔新的订单']);
|
||||||
Redis::send('push-platform-print', ['order_id' => $order['id']], 60);
|
Redis::send('push-platform-print', ['order_id' => $order['id']], 60);
|
||||||
Db::name('order_middle')->insert(['c_order_id' => $order['id']]);
|
// Db::name('order_middle')->insert(['c_order_id' => $order['id']]);
|
||||||
}
|
}
|
||||||
if (!empty($extra['payer']['openid']) && $order->pay_type != 9) {
|
if (!empty($extra['payer']['openid']) && $order->pay_type != 9) {
|
||||||
Redis::send('push-delivery', ['order_sn' => $order['order_id'], 'openid' => $extra['payer']['openid']], 5);
|
Redis::send('push-delivery', ['order_sn' => $order['order_id'], 'openid' => $extra['payer']['openid']], 5);
|
||||||
@ -105,6 +106,31 @@ class PayNotifyLogic extends BaseLogic
|
|||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
public static function store_order($orderSn, $extra = [])
|
||||||
|
{
|
||||||
|
$order = StoreOrder::where('order_id', $orderSn)->findOrEmpty();
|
||||||
|
if ($order->isEmpty() || $order->paid == PayEnum::ISPAID) {
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
if ($order->pay_type != 10) {
|
||||||
|
$order->pay_price = bcdiv($extra['amount']['payer_total'], 100, 2);
|
||||||
|
$order->paid = 1;
|
||||||
|
$order->pay_time = time();
|
||||||
|
$order->status = 1;
|
||||||
|
$order->save();
|
||||||
|
} else {
|
||||||
|
$extra['transaction_id'] = time();
|
||||||
|
}
|
||||||
|
if ($order->pay_type == 9) {
|
||||||
|
$order->status = 2;
|
||||||
|
}
|
||||||
|
self::afterPay($order);
|
||||||
|
|
||||||
|
return true;
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 现金支付
|
* 现金支付
|
||||||
*/
|
*/
|
||||||
@ -179,4 +205,25 @@ class PayNotifyLogic extends BaseLogic
|
|||||||
$financeLogic->save();
|
$financeLogic->save();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 回调日志
|
||||||
|
* @param $order
|
||||||
|
* @param $extra
|
||||||
|
* @return void
|
||||||
|
*/
|
||||||
|
public static function notifyLog($order,$extra)
|
||||||
|
{
|
||||||
|
$data = [
|
||||||
|
'pay_type'=>'wechat',
|
||||||
|
'type'=>OrderEnum::PAY,
|
||||||
|
'amount'=>$extra['amount']['payer_total'],//分
|
||||||
|
'order_sn'=>$order,
|
||||||
|
'out_trade_no'=>$extra['transaction_id'],
|
||||||
|
'attach'=>$extra['attach'],
|
||||||
|
'create_time'=>date('Y-m-d H:i:s',time()),
|
||||||
|
];
|
||||||
|
PayNotify::create($data);
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
10
app/common/model/pay/PayNotify.php
Normal file
10
app/common/model/pay/PayNotify.php
Normal file
@ -0,0 +1,10 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
namespace app\common\model\pay;
|
||||||
|
|
||||||
|
use app\common\model\BaseModel;
|
||||||
|
|
||||||
|
class PayNotify extends BaseModel
|
||||||
|
{
|
||||||
|
protected $name = 'pay_notify_log';
|
||||||
|
}
|
Loading…
x
Reference in New Issue
Block a user