修复多渠道切换渠道异常问题
This commit is contained in:
parent
3f874513ad
commit
4e5dce1d25
@ -293,28 +293,18 @@ class Core extends Controller
|
|||||||
|
|
||||||
# 发送通知
|
# 发送通知
|
||||||
protected function notify($order_id, $request, $status = false, $die = true)
|
protected function notify($order_id, $request, $status = false, $die = true)
|
||||||
{
|
{
|
||||||
$orderService = OrderService::instance();
|
$orderService = OrderService::instance();
|
||||||
$order = $orderService->get($order_id);
|
$order = $orderService->get($order_id);
|
||||||
|
|
||||||
if (!$order) {
|
if (!$order) {
|
||||||
$oldOrder = OrderLastHistoryService::instance()->get($order_id);
|
$oldorder = OrderHistoryService::instance()->get($order_id);
|
||||||
if(!$oldOrder){
|
if ($oldorder) {
|
||||||
$oldOrder = OrderTwoHistoryService::instance()->get($order_id);
|
|
||||||
}
|
|
||||||
if(!$oldOrder){
|
|
||||||
$oldOrder = OrderHistoryService::instance()->get($order_id);
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
if ($oldOrder) {
|
|
||||||
$channelService = ChannelService::instance();
|
$channelService = ChannelService::instance();
|
||||||
$oldupdate = $channelService->call('notify', $oldOrder['cid'], $request, false, $oldOrder);
|
$oldupdate = $channelService->call('notify', $oldorder['cid'], $request, false, $oldorder);
|
||||||
$merchant = MerchantService::instance()->get($oldOrder['mid']);
|
$merchant = MerchantService::instance()->get($oldorder['mid']);
|
||||||
if ($oldupdate['status'] == 3 && $oldOrder['status'] == 2 && isset($merchant['callback_repeat']) && $merchant['callback_repeat'] > 2) {
|
if ($oldupdate['status'] == 3 && $oldorder['status'] == 2 && isset($merchant['callback_repeat']) && $merchant['callback_repeat'] > 2) {
|
||||||
// # TODO 暂时写死渠道,后续需修改为可以自主选择
|
if ($oldorder['cid'] == '2') {
|
||||||
|
|
||||||
if ($oldOrder['cid'] == '2') {
|
|
||||||
OrderHistoryService::instance()->db()->where(array('order_id' => $order_id))->update(['status' => '3', 'buy_back' => '1']);
|
OrderHistoryService::instance()->db()->where(array('order_id' => $order_id))->update(['status' => '3', 'buy_back' => '1']);
|
||||||
if (isset($oldupdate['yes']) && $oldupdate['yes']) {
|
if (isset($oldupdate['yes']) && $oldupdate['yes']) {
|
||||||
echo $oldupdate['yes'];
|
echo $oldupdate['yes'];
|
||||||
@ -324,43 +314,42 @@ class Core extends Controller
|
|||||||
die;
|
die;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
if ($order) {
|
if ($order) {
|
||||||
$up = $nup = false;
|
$up = $nup = false;
|
||||||
if ($order['status'] != 2 && $order['status'] != 3 && $order['status'] != 5 && $order['status'] != -6) {
|
if ($order['status'] != 2 && $order['status'] != 3 && $order['status'] != 5 && $order['status'] != -6) {
|
||||||
$up = true;
|
$up = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
if(isset($order['channel_order_id']) && $order['channel_order_id'] && isset($request['channel_order_id']) && $request['channel_order_id'] && $order['channel_order_id'] != $request['channel_order_id']) {
|
if(isset($order['channel_order_id']) && $order['channel_order_id'] && isset($request['channel_order_id']) && $request['channel_order_id'] && $order['channel_order_id'] != $request['channel_order_id']) {
|
||||||
$this->no(-104);
|
$this->no(-104);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// var_dump($order);die;
|
||||||
|
|
||||||
#识别是否重复回调
|
#识别是否重复回调
|
||||||
// $repeated
|
// $repeated
|
||||||
// if ($order[''])
|
// if ($order[''])
|
||||||
|
|
||||||
if (!$status && $request) {
|
if (!$status && $request) {
|
||||||
$channelService = ChannelService::instance();
|
|
||||||
$update = $channelService->call('notify', $order['cid'], $request, false, $order);
|
$channelService = ChannelService::instance();
|
||||||
$merchant = MerchantService::instance()->get($order['mid']);
|
$update = $channelService->call('notify', $order['cid'], $request, false, $order);
|
||||||
if (isset($order['param']) && $order['param']) {
|
$merchant = MerchantService::instance()->get($order['mid']);
|
||||||
$order['param'] = json_decode($order['param'], true);
|
if (isset($order['param']) && $order['param']) {
|
||||||
} else {
|
$order['param'] = json_decode($order['param'], true);
|
||||||
$order['param'] = false;
|
} else {
|
||||||
}
|
$order['param'] = false;
|
||||||
|
}
|
||||||
|
|
||||||
#渠道返销
|
#渠道返销
|
||||||
if ($update['status'] == 3 && $order['status'] == 2 && isset($merchant['callback_repeat']) && $merchant['callback_repeat'] >= 2) {
|
if ($update['status'] == 3 && $order['status'] == 2 && isset($merchant['callback_repeat']) && $merchant['callback_repeat'] >= 2) {
|
||||||
// # TODO 暂时写死渠道,后续需修改为可以自主选择
|
// # TODO 暂时写死渠道,后续需修改为可以自主选择
|
||||||
|
|
||||||
if ($order['cid'] == '2') {
|
if ($order['cid'] == '2') {
|
||||||
|
|
||||||
|
|
||||||
$order->db()->where(array('order_id' => $order_id))->update(['status' => '3', 'buy_back' => '1']);
|
$order->db()->where(array('order_id' => $order_id))->update(['status' => '3', 'buy_back' => '1']);
|
||||||
if (isset($update['yes']) && $update['yes']) {
|
if (isset($update['yes']) && $update['yes']) {
|
||||||
echo $update['yes'];
|
echo $update['yes'];
|
||||||
@ -370,167 +359,174 @@ class Core extends Controller
|
|||||||
die;
|
die;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
// echo '123';die;
|
||||||
|
|
||||||
|
|
||||||
if (isset($order['merchant_callback_at']) && $order['merchant_callback_at']) {
|
if (isset($order['merchant_callback_at']) && $order['merchant_callback_at']) {
|
||||||
|
echo 'fail';
|
||||||
die;
|
die;
|
||||||
}
|
}
|
||||||
$where[] = [
|
$where[] = [
|
||||||
'order_id', 'like', $order_id
|
'order_id', 'like', $order_id
|
||||||
];
|
];
|
||||||
|
|
||||||
$is_lj_order = Db::name('merchant_order_lj')->where($where)->find();
|
// $is_lj_order = Db::name('merchant_order_lj')->where($where)->find();
|
||||||
if ($is_lj_order) {
|
// if ($is_lj_order) {
|
||||||
$is_lj_status = false;
|
// $is_lj_status = false;
|
||||||
} else {
|
// } else {
|
||||||
$is_lj_status = true;
|
// $is_lj_status = true;
|
||||||
}
|
// }
|
||||||
|
|
||||||
|
|
||||||
if ($update['status'] == 3 && isset($merchant['stop']) && $merchant['stop'] > 2) {
|
if ($update['status'] == 3 && isset($merchant['stop']) && $merchant['stop'] > 2) {
|
||||||
# 是否暂停
|
# 是否暂停
|
||||||
$num = $order['num'] + 1;
|
$num = $order['num'] + 1;
|
||||||
$order_id = $order['order_id'] . '_' . $num;
|
$order_id = $order['order_id'] . '_' . $num;
|
||||||
# 该渠道下单失败,重新下单,并暂停,等待手动启动
|
# 该渠道下单失败,重新下单,并暂停,等待手动启动
|
||||||
# 记录失败的订单信息
|
# 记录失败的订单信息
|
||||||
$orderAutoService = OrderAutoService::instance();
|
$orderAutoService = OrderAutoService::instance();
|
||||||
|
|
||||||
$estate = $orderAutoService->up($order);
|
$estate = $orderAutoService->up($order);
|
||||||
if ($estate) {
|
if ($estate) {
|
||||||
$orderAutoService->upChannelMsg($order['order_id'], $update['status'], $update['data'], $order['num']);
|
$orderAutoService->upChannelMsg($order['order_id'], $update['status'], $update['data'], $order['num']);
|
||||||
|
|
||||||
# 修改状态
|
# 修改状态
|
||||||
$orderService->upStatus($order['order_id'], -5, '', false, $num);
|
$orderService->upStatus($order['order_id'], -5, '', false, $num);
|
||||||
}
|
}
|
||||||
|
|
||||||
if ($die) {
|
if ($die) {
|
||||||
if (isset($update['yes']) && $update['yes']) {
|
if (isset($update['yes']) && $update['yes']) {
|
||||||
echo $update['yes'];die;
|
echo $update['yes'];die;
|
||||||
}
|
}
|
||||||
echo 'success';die;
|
echo 'success';die;
|
||||||
} else {
|
} else {
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
} elseif ($update['status'] == 3 && isset($merchant['callback_fc']) && $merchant['callback_fc'] > $order['num']) {
|
} elseif ($update['status'] == 3 && isset($merchant['callback_fc']) && $merchant['callback_fc'] > $order['num']) {
|
||||||
|
|
||||||
$num = $order['num'] + 1;
|
$num = $order['num'] + 1;
|
||||||
# 该渠道下单失败,开始复充
|
# 该渠道下单失败,开始复充
|
||||||
# 记录失败的订单信息
|
# 记录失败的订单信息
|
||||||
$orderAutoService = OrderAutoService::instance();
|
$orderAutoService = OrderAutoService::instance();
|
||||||
$estate = $orderAutoService->up($order);
|
$estate = $orderAutoService->up($order);
|
||||||
if ($estate) {
|
if ($estate) {
|
||||||
$orderAutoService->upChannelMsg($order['order_id'], $update['status'], $update['data'], $order['num']);
|
$orderAutoService->upChannelMsg($order['order_id'], $update['status'], $update['data'], $order['num']);
|
||||||
|
|
||||||
# 修改状态
|
|
||||||
$orderService->upStatus($order['order_id'], -4, '', $merchant['callback_fc_time'], $num);
|
|
||||||
}
|
|
||||||
|
|
||||||
if ($die) {
|
|
||||||
if (isset($update['yes']) && $update['yes']) {
|
|
||||||
echo $update['yes'];die;
|
|
||||||
}
|
|
||||||
echo 'success';die;
|
|
||||||
} else {
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
} elseif ($update['status'] == 3 && $merchant['callback_auto'] == 2 && $is_lj_status) {
|
|
||||||
# 该渠道下单失败,重新开始找另外一个渠道
|
|
||||||
$orderAutoService = OrderAutoService::instance();
|
|
||||||
$use = $orderAutoService->get($order['order_id']);
|
|
||||||
$this->use_product[] = $order['pid'];
|
|
||||||
foreach ($use as $k => $v) {
|
|
||||||
$this->use_product[] = $v['pid'];
|
|
||||||
}
|
|
||||||
$isp = false;
|
|
||||||
if (isset($order['isp']) && $order['isp'] && $order['isp'] > 0) {
|
|
||||||
$isp_config = \app\merchant\service\PercentService::instance()->getIsp();
|
|
||||||
$isp = $isp_config[$order['isp']];
|
|
||||||
}
|
|
||||||
$new_product = $this->getProduct($order['mid'], $order['product_key'], $this->use_product, $order['cash'], $isp);
|
|
||||||
if ($new_product && $order['param']) {
|
|
||||||
# 记录失败的订单信息
|
|
||||||
$orderAutoService->up($order);
|
|
||||||
$orderAutoService->upChannelMsg($order_id, $update['status'], $update['data']);
|
|
||||||
$channelService->use($order['mid'], $new_product, $order['param'], false, $order_id, $this->use_product);
|
|
||||||
if ($die) {
|
|
||||||
if (isset($update['yes']) && $update['yes']) {
|
|
||||||
echo $update['yes'];die;
|
|
||||||
}
|
|
||||||
echo 'success';die;
|
|
||||||
} else {
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
if ($update && $up) {
|
|
||||||
$nup = true;
|
|
||||||
$orderService->upChannelMsg($order['id'], $update['status'], $update['data']);
|
|
||||||
}
|
|
||||||
} elseif ($status) {
|
|
||||||
$update['status'] = $status;
|
|
||||||
$update['data'] = $request;
|
|
||||||
}
|
|
||||||
|
|
||||||
if ($update && $order['merchant_callback_error'] != 1) {
|
|
||||||
//$update['order'] = $order;
|
|
||||||
$update['project_id'] = false;
|
|
||||||
if (isset($order['project_id'])) {
|
|
||||||
$update['project_id'] = $order['project_id'];
|
|
||||||
}
|
|
||||||
if (isset($order['card_id'])) {
|
|
||||||
$update['card_id'] = $order['card_id'];
|
|
||||||
}
|
|
||||||
$update['account'] = $order['account'];
|
|
||||||
$update['cash'] = $order['cash'];
|
|
||||||
$update['merchant_order_id'] = $order['merchant_order_id'];
|
|
||||||
$update['order_id'] = $order_id;
|
|
||||||
$update['notify_num'] = $order['merchant_callback_num'];
|
|
||||||
if (isset($order['isp']) && $order['isp']) {
|
|
||||||
$update['isp'] = $order['isp'];
|
|
||||||
}
|
|
||||||
if ($order['param'] && isset($order['param']['notify']) && $order['param']['notify']) {
|
|
||||||
$update['notify'] = $order['param']['notify'];
|
|
||||||
}
|
|
||||||
if ($order['mid'] == 33 && $order['cid'] == 10026) {
|
|
||||||
if (isset($update['s_nubmer'])) {
|
|
||||||
unset($update['s_nubmer']);
|
|
||||||
}
|
|
||||||
if (isset($update['msg'])) {
|
|
||||||
unset($update['msg']);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
# 商户后续操作
|
# 修改状态
|
||||||
if ($up) {
|
$orderService->upStatus($order['order_id'], -4, '', $merchant['callback_fc_time'], $num);
|
||||||
if (isset($order['error_account_oper']) && $order['error_account_oper'] == 1) {
|
}
|
||||||
# 需要进行扣费
|
|
||||||
MerchantService::instance()->up($order['id'], $order['mid'], $order['pid'], $order['product_key'], $update);
|
|
||||||
} else {
|
|
||||||
# 直接发送
|
|
||||||
MerchantService::instance()->notify($order['id'], $order['mid'], $order['pid'], $order['product_key'], $update);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
if ($update) {
|
if ($die) {
|
||||||
if ($up && $nup) {
|
if (isset($update['yes']) && $update['yes']) {
|
||||||
$orderService->upChannelMsg($order['id'], $update['status'], $update['data']);
|
echo $update['yes'];die;
|
||||||
}
|
}
|
||||||
if ($die) {
|
echo 'success';die;
|
||||||
if (isset($update['yes']) && $update['yes']) {
|
} else {
|
||||||
echo $update['yes'];die;
|
return true;
|
||||||
}
|
}
|
||||||
echo 'success';die;
|
} elseif ($update['status'] == 3 && $merchant['callback_auto'] == 2 && !$order['apply_refund']) {
|
||||||
} else {
|
# 该渠道下单失败,重新开始找另外一个渠道
|
||||||
return true;
|
$num = $order['num'] + 1;
|
||||||
}
|
$new_order_id = $order['order_id'] . '_' . $num;
|
||||||
}
|
//
|
||||||
}
|
$orderAutoService = OrderAutoService::instance();
|
||||||
if ($die) {
|
$use = $orderAutoService->get($order['order_id']);
|
||||||
echo 'fail';die;
|
$this->use_product[] = $order['pid'];
|
||||||
} else {
|
foreach ($use as $k => $v) {
|
||||||
return false;
|
$this->use_product[] = $v['pid'];
|
||||||
}
|
}
|
||||||
}
|
$isp = false;
|
||||||
|
if (isset($order['isp']) && $order['isp'] && $order['isp'] > 0) {
|
||||||
|
$isp_config = \app\merchant\service\PercentService::instance()->getIsp();
|
||||||
|
$isp = $isp_config[$order['isp']];
|
||||||
|
}
|
||||||
|
$new_product = $this->getProduct($order['mid'], $order['product_key'], $this->use_product, $order['cash'], $isp);
|
||||||
|
if ($new_product && $order['param']) {
|
||||||
|
# 记录失败的订单信息
|
||||||
|
$orderAutoService->up($order);
|
||||||
|
$orderAutoService->upChannelMsg($order_id, $update['status'], $update['data'], $order['num']);
|
||||||
|
$channelService->use($order['mid'], $new_product, $order['param'], false, $new_order_id, $this->use_product);
|
||||||
|
if ($die) {
|
||||||
|
if (isset($update['yes']) && $update['yes']) {
|
||||||
|
echo $update['yes'];die;
|
||||||
|
}
|
||||||
|
echo 'success';die;
|
||||||
|
} else {
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if ($update && $up) {
|
||||||
|
$nup = true;
|
||||||
|
$orderService->upChannelMsg($order['id'], $update['status'], $update['data']);
|
||||||
|
}
|
||||||
|
} elseif ($status) {
|
||||||
|
$update['status'] = $status;
|
||||||
|
$update['data'] = $request;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
if ($update && $order['merchant_callback_error'] != 1) {
|
||||||
|
//$update['order'] = $order;
|
||||||
|
$update['project_id'] = false;
|
||||||
|
if (isset($order['project_id'])) {
|
||||||
|
$update['project_id'] = $order['project_id'];
|
||||||
|
}
|
||||||
|
if (isset($order['card_id'])) {
|
||||||
|
$update['card_id'] = $order['card_id'];
|
||||||
|
}
|
||||||
|
$update['account'] = $order['account'];
|
||||||
|
$update['cash'] = $order['cash'];
|
||||||
|
$update['merchant_order_id'] = $order['merchant_order_id'];
|
||||||
|
$update['order_id'] = $order_id;
|
||||||
|
$update['notify_num'] = $order['merchant_callback_num'];
|
||||||
|
if (isset($order['isp']) && $order['isp']) {
|
||||||
|
$update['isp'] = $order['isp'];
|
||||||
|
}
|
||||||
|
if ($order['param'] && isset($order['param']['notify']) && $order['param']['notify']) {
|
||||||
|
$update['notify'] = $order['param']['notify'];
|
||||||
|
}
|
||||||
|
if ($order['mid'] == 33 && $order['cid'] == 10026) {
|
||||||
|
if (isset($update['s_nubmer'])) {
|
||||||
|
unset($update['s_nubmer']);
|
||||||
|
}
|
||||||
|
if (isset($update['msg'])) {
|
||||||
|
unset($update['msg']);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
# 商户后续操作
|
||||||
|
if ($up) {
|
||||||
|
if (isset($order['error_account_oper']) && $order['error_account_oper'] == 1) {
|
||||||
|
# 需要进行扣费
|
||||||
|
MerchantService::instance()->up($order['id'], $order['mid'], $order['pid'], $order['product_key'], $update);
|
||||||
|
} else {
|
||||||
|
# 直接发送
|
||||||
|
MerchantService::instance()->notify($order['id'], $order['mid'], $order['pid'], $order['product_key'], $update);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if ($update) {
|
||||||
|
if ($up && $nup) {
|
||||||
|
$orderService->upChannelMsg($order['id'], $update['status'], $update['data']);
|
||||||
|
}
|
||||||
|
if ($die) {
|
||||||
|
if (isset($update['yes']) && $update['yes']) {
|
||||||
|
echo $update['yes'];die;
|
||||||
|
}
|
||||||
|
echo 'success';die;
|
||||||
|
} else {
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if ($die) {
|
||||||
|
echo 'fail';die;
|
||||||
|
} else {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
private function getProduct($mid, $product, $use_product, $cash, $isp = false)
|
private function getProduct($mid, $product, $use_product, $cash, $isp = false)
|
||||||
{
|
{
|
||||||
|
@ -385,12 +385,12 @@ class Core extends Controller
|
|||||||
'order_id', 'like', $order_id
|
'order_id', 'like', $order_id
|
||||||
];
|
];
|
||||||
|
|
||||||
$is_lj_order = Db::name('merchant_order_lj')->where($where)->find();
|
// $is_lj_order = Db::name('merchant_order_lj')->where($where)->find();
|
||||||
if ($is_lj_order) {
|
// if ($is_lj_order) {
|
||||||
$is_lj_status = false;
|
// $is_lj_status = false;
|
||||||
} else {
|
// } else {
|
||||||
$is_lj_status = true;
|
// $is_lj_status = true;
|
||||||
}
|
// }
|
||||||
|
|
||||||
|
|
||||||
if ($update['status'] == 3 && isset($merchant['stop']) && $merchant['stop'] > 2) {
|
if ($update['status'] == 3 && isset($merchant['stop']) && $merchant['stop'] > 2) {
|
||||||
@ -439,8 +439,11 @@ class Core extends Controller
|
|||||||
} else {
|
} else {
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
} elseif ($update['status'] == 3 && $merchant['callback_auto'] == 2 && $is_lj_status) {
|
} elseif ($update['status'] == 3 && $merchant['callback_auto'] == 2 && !$order['apply_refund']) {
|
||||||
# 该渠道下单失败,重新开始找另外一个渠道
|
# 该渠道下单失败,重新开始找另外一个渠道
|
||||||
|
$num = $order['num'] + 1;
|
||||||
|
$new_order_id = $order['order_id'] . '_' . $num;
|
||||||
|
//
|
||||||
$orderAutoService = OrderAutoService::instance();
|
$orderAutoService = OrderAutoService::instance();
|
||||||
$use = $orderAutoService->get($order['order_id']);
|
$use = $orderAutoService->get($order['order_id']);
|
||||||
$this->use_product[] = $order['pid'];
|
$this->use_product[] = $order['pid'];
|
||||||
@ -456,8 +459,8 @@ class Core extends Controller
|
|||||||
if ($new_product && $order['param']) {
|
if ($new_product && $order['param']) {
|
||||||
# 记录失败的订单信息
|
# 记录失败的订单信息
|
||||||
$orderAutoService->up($order);
|
$orderAutoService->up($order);
|
||||||
$orderAutoService->upChannelMsg($order_id, $update['status'], $update['data']);
|
$orderAutoService->upChannelMsg($order_id, $update['status'], $update['data'], $order['num']);
|
||||||
$channelService->use($order['mid'], $new_product, $order['param'], false, $order_id, $this->use_product);
|
$channelService->use($order['mid'], $new_product, $order['param'], false, $new_order_id, $this->use_product);
|
||||||
if ($die) {
|
if ($die) {
|
||||||
if (isset($update['yes']) && $update['yes']) {
|
if (isset($update['yes']) && $update['yes']) {
|
||||||
echo $update['yes'];die;
|
echo $update['yes'];die;
|
||||||
|
Loading…
x
Reference in New Issue
Block a user