132 lines
5.3 KiB
PHP
132 lines
5.3 KiB
PHP
<?php
|
|
namespace addon\cardservice\event;
|
|
use think\facade\Db;
|
|
use addon\dividemoney\model\OrderPay;
|
|
use app\model\system\Pay as PayCommon;
|
|
use think\facade\Log;
|
|
|
|
class AliAuthNotify
|
|
{
|
|
public function handle($param = [])
|
|
{
|
|
$msg_method = $param['msg_method'] ?? '';
|
|
if ($msg_method) {
|
|
$biz_content = $param['biz_content'];
|
|
switch ($msg_method) {
|
|
case 'alipay.commerce.merchantcard.template.notify': //公域商品变更通知
|
|
if (isset($biz_content['change_type'])) {
|
|
$card_template_id = $biz_content['card_template_id'];
|
|
model('goods_card')->update(['change_type' => $biz_content['change_type']], ['card_template_id' => $card_template_id]);
|
|
}
|
|
break;
|
|
case 'alipay.commerce.merchantcard.order.notify': //订购状态通知接口
|
|
// $this->syncOrder($biz_content);
|
|
break;
|
|
case 'alipay.commerce.merchantcard.deductionorder.notify': //订单状态通知接口
|
|
// $this->orderNotify($biz_content);
|
|
break;
|
|
default:
|
|
}
|
|
}
|
|
}
|
|
|
|
|
|
/***
|
|
* 订单同步状态
|
|
* @param $data
|
|
*/
|
|
public function syncOrder($data)
|
|
{
|
|
// 支付宝交易号
|
|
$trade_no = $data['trade_no'];
|
|
$out_trade_no = $data['card_id']; //平台交易号
|
|
$third_order_no = $data['deduction_order_id'];
|
|
// 交易状态
|
|
$trade_status = $data['deduction_order_status'];
|
|
$user_id = $data['user_id'];
|
|
$card_template_id = $data['card_template_id'];
|
|
$where = [
|
|
'out_trade_no' => $out_trade_no,
|
|
'card_template_id' => $card_template_id
|
|
];
|
|
$orderInfo = (array)model('order')->getInfo([['out_trade_no', '=', $out_trade_no]], 'site_id,store_id,order_id,member_id,name,mobile,province_id,city_id,district_id,address,full_address,promotion_type,promotion_type_name');
|
|
$zmOrder = Db::name('zima_order')->where($where)->find();
|
|
if (empty($zmOrder)) {
|
|
$insdata = [
|
|
'productNo' => $data['productNo'],
|
|
'merchantPid' => $data['merchantPid'],
|
|
'site_id' => $orderInfo['site_id'],
|
|
'store_id' => $orderInfo['store_id'],
|
|
'userid' => $data['userId'],
|
|
'order_id' => $orderInfo['order_id'] ?? 0,
|
|
'uid' => $orderInfo['member_id'] ?? 0,
|
|
'trade_no' => $trade_no,
|
|
'out_trade_no' => $out_trade_no,
|
|
'third_order_no' => $third_order_no,
|
|
'verificationCodeStatus' => $data['verificationCodeStatus'] ?? '',
|
|
'orderSettleStatus' => $data['orderSettleStatus'],
|
|
'create_time' => strtotime($data['orderDate']),
|
|
'plan_time' => strtotime($data['planDeductionTime'] ?? ''),
|
|
'period' => $data['period'],
|
|
'order_status' => $trade_status,
|
|
'amount' => $data['deductionAmount']
|
|
];
|
|
Db::name('zima_order')->insert($insdata);
|
|
} else {
|
|
$updata = [
|
|
'order_status' => $trade_status,
|
|
'verificationCodeStatus' => $data['verificationCodeStatus'] ?? '',
|
|
'orderSettleStatus' => $data['orderSettleStatus'],
|
|
'settleTime' => $data['settleTime'] ?? 0,
|
|
'failTimes' => $data['failTimes'] ?? 0,
|
|
'failReason' => $data['failReason'] ?? '',
|
|
];
|
|
if ($trade_status == 'PAID') { //扣款成功
|
|
$updata['payChannel'] = $data['payChannel'];
|
|
$updata['settleDetails'] = json_encode($data['settleDetails']);
|
|
$updata['pay_time'] = strtotime($data['actualDeductionTime']);
|
|
event('CloudAliPayOrderPay', array_merge($zmOrder, $updata, $orderInfo));//订单支付成功
|
|
}
|
|
Db::name('zima_order')->where($where)->update($updata);
|
|
//核销支付中
|
|
try {
|
|
event('CloudAliPaySyncOrder', array_merge($zmOrder, $updata, $orderInfo));//订单同步事件
|
|
} catch (\Exception $exception) {
|
|
trace($exception, 'CloudAliPaySyncOrder同步事件' . json_encode($data));
|
|
}
|
|
}
|
|
$success = [
|
|
'success' => true,
|
|
'code' => 10000,
|
|
"msg" => 'Success',
|
|
];
|
|
ksort($success);
|
|
$json = [
|
|
'response' => $success,
|
|
'sign' => $this->aop->sign(json_encode($success), "RSA2")
|
|
];
|
|
echo json_encode($json);
|
|
}
|
|
|
|
|
|
/***
|
|
* 订单状态通知接口
|
|
* @param $data
|
|
* @return void
|
|
*/
|
|
public function orderNotify($data)
|
|
{
|
|
$card_id = $data['card_id'];
|
|
$order_id = $data['order_id'];
|
|
$create_time = $data['create_time'];
|
|
$card_template_id = $data['card_template_id'];
|
|
$card_status = $data['card_status'];
|
|
$card_name = $data['card_name'];
|
|
$card_type = $data['card_type'];
|
|
$total_count = $data['total_count'];
|
|
$remain_count = $data['remain_count'];
|
|
$merchant_app_id = $data['merchant_app_id'];
|
|
$user_id = $data['user_id'] ?: $data['open_id'];
|
|
}
|
|
}
|