From 4e5dce1d2505b519f2f901139df7381cfc3da0f7 Mon Sep 17 00:00:00 2001 From: mzeros Date: Tue, 1 Oct 2024 01:02:05 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BF=AE=E5=A4=8D=E5=A4=9A=E6=B8=A0=E9=81=93?= =?UTF-8?q?=E5=88=87=E6=8D=A2=E6=B8=A0=E9=81=93=E5=BC=82=E5=B8=B8=E9=97=AE?= =?UTF-8?q?=E9=A2=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/gateway/controller/api/Core.php | 358 ++++++++++++++-------------- app/gateway/controller/v4/Core.php | 21 +- 2 files changed, 189 insertions(+), 190 deletions(-) diff --git a/app/gateway/controller/api/Core.php b/app/gateway/controller/api/Core.php index eba169b..de7c499 100644 --- a/app/gateway/controller/api/Core.php +++ b/app/gateway/controller/api/Core.php @@ -293,28 +293,18 @@ class Core extends Controller # 发送通知 protected function notify($order_id, $request, $status = false, $die = true) - { - $orderService = OrderService::instance(); - $order = $orderService->get($order_id); + { + $orderService = OrderService::instance(); + $order = $orderService->get($order_id); if (!$order) { - $oldOrder = OrderLastHistoryService::instance()->get($order_id); - if(!$oldOrder){ - $oldOrder = OrderTwoHistoryService::instance()->get($order_id); - } - if(!$oldOrder){ - $oldOrder = OrderHistoryService::instance()->get($order_id); - } - - - if ($oldOrder) { + $oldorder = OrderHistoryService::instance()->get($order_id); + if ($oldorder) { $channelService = ChannelService::instance(); - $oldupdate = $channelService->call('notify', $oldOrder['cid'], $request, false, $oldOrder); - $merchant = MerchantService::instance()->get($oldOrder['mid']); - if ($oldupdate['status'] == 3 && $oldOrder['status'] == 2 && isset($merchant['callback_repeat']) && $merchant['callback_repeat'] > 2) { -// # TODO 暂时写死渠道,后续需修改为可以自主选择 - - if ($oldOrder['cid'] == '2') { + $oldupdate = $channelService->call('notify', $oldorder['cid'], $request, false, $oldorder); + $merchant = MerchantService::instance()->get($oldorder['mid']); + if ($oldupdate['status'] == 3 && $oldorder['status'] == 2 && isset($merchant['callback_repeat']) && $merchant['callback_repeat'] > 2) { + if ($oldorder['cid'] == '2') { OrderHistoryService::instance()->db()->where(array('order_id' => $order_id))->update(['status' => '3', 'buy_back' => '1']); if (isset($oldupdate['yes']) && $oldupdate['yes']) { echo $oldupdate['yes']; @@ -324,43 +314,42 @@ class Core extends Controller die; } } - } - } - if ($order) { - $up = $nup = false; - if ($order['status'] != 2 && $order['status'] != 3 && $order['status'] != 5 && $order['status'] != -6) { - $up = true; - } + if ($order) { + $up = $nup = false; + if ($order['status'] != 2 && $order['status'] != 3 && $order['status'] != 5 && $order['status'] != -6) { + $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']) { $this->no(-104); } +// var_dump($order);die; + #识别是否重复回调 // $repeated // if ($order['']) - if (!$status && $request) { - $channelService = ChannelService::instance(); - $update = $channelService->call('notify', $order['cid'], $request, false, $order); - $merchant = MerchantService::instance()->get($order['mid']); - if (isset($order['param']) && $order['param']) { - $order['param'] = json_decode($order['param'], true); - } else { - $order['param'] = false; - } + if (!$status && $request) { + + $channelService = ChannelService::instance(); + $update = $channelService->call('notify', $order['cid'], $request, false, $order); + $merchant = MerchantService::instance()->get($order['mid']); + if (isset($order['param']) && $order['param']) { + $order['param'] = json_decode($order['param'], true); + } else { + $order['param'] = false; + } #渠道返销 if ($update['status'] == 3 && $order['status'] == 2 && isset($merchant['callback_repeat']) && $merchant['callback_repeat'] >= 2) { // # TODO 暂时写死渠道,后续需修改为可以自主选择 if ($order['cid'] == '2') { - - $order->db()->where(array('order_id' => $order_id))->update(['status' => '3', 'buy_back' => '1']); if (isset($update['yes']) && $update['yes']) { echo $update['yes']; @@ -370,167 +359,174 @@ class Core extends Controller die; } } +// echo '123';die; + if (isset($order['merchant_callback_at']) && $order['merchant_callback_at']) { + echo 'fail'; die; } $where[] = [ 'order_id', 'like', $order_id ]; - $is_lj_order = Db::name('merchant_order_lj')->where($where)->find(); - if ($is_lj_order) { - $is_lj_status = false; - } else { - $is_lj_status = true; - } +// $is_lj_order = Db::name('merchant_order_lj')->where($where)->find(); +// if ($is_lj_order) { +// $is_lj_status = false; +// } else { +// $is_lj_status = true; +// } if ($update['status'] == 3 && isset($merchant['stop']) && $merchant['stop'] > 2) { - # 是否暂停 - $num = $order['num'] + 1; - $order_id = $order['order_id'] . '_' . $num; - # 该渠道下单失败,重新下单,并暂停,等待手动启动 - # 记录失败的订单信息 - $orderAutoService = OrderAutoService::instance(); + # 是否暂停 + $num = $order['num'] + 1; + $order_id = $order['order_id'] . '_' . $num; + # 该渠道下单失败,重新下单,并暂停,等待手动启动 + # 记录失败的订单信息 + $orderAutoService = OrderAutoService::instance(); - $estate = $orderAutoService->up($order); - if ($estate) { - $orderAutoService->upChannelMsg($order['order_id'], $update['status'], $update['data'], $order['num']); + $estate = $orderAutoService->up($order); + if ($estate) { + $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 (isset($update['yes']) && $update['yes']) { - echo $update['yes'];die; - } - echo 'success';die; - } else { - return true; - } - } elseif ($update['status'] == 3 && isset($merchant['callback_fc']) && $merchant['callback_fc'] > $order['num']) { + if ($die) { + if (isset($update['yes']) && $update['yes']) { + echo $update['yes'];die; + } + echo 'success';die; + } else { + return true; + } + } elseif ($update['status'] == 3 && isset($merchant['callback_fc']) && $merchant['callback_fc'] > $order['num']) { - $num = $order['num'] + 1; - # 该渠道下单失败,开始复充 - # 记录失败的订单信息 - $orderAutoService = OrderAutoService::instance(); - $estate = $orderAutoService->up($order); - if ($estate) { - $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']); - } - } + $num = $order['num'] + 1; + # 该渠道下单失败,开始复充 + # 记录失败的订单信息 + $orderAutoService = OrderAutoService::instance(); + $estate = $orderAutoService->up($order); + if ($estate) { + $orderAutoService->upChannelMsg($order['order_id'], $update['status'], $update['data'], $order['num']); - # 商户后续操作 - 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); - } - } - } + # 修改状态 + $orderService->upStatus($order['order_id'], -4, '', $merchant['callback_fc_time'], $num); + } - 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; - } - } + 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 && !$order['apply_refund']) { + # 该渠道下单失败,重新开始找另外一个渠道 + $num = $order['num'] + 1; + $new_order_id = $order['order_id'] . '_' . $num; + // + $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'], $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) { diff --git a/app/gateway/controller/v4/Core.php b/app/gateway/controller/v4/Core.php index 12aa0ee..d1e007a 100644 --- a/app/gateway/controller/v4/Core.php +++ b/app/gateway/controller/v4/Core.php @@ -385,12 +385,12 @@ class Core extends Controller 'order_id', 'like', $order_id ]; - $is_lj_order = Db::name('merchant_order_lj')->where($where)->find(); - if ($is_lj_order) { - $is_lj_status = false; - } else { - $is_lj_status = true; - } +// $is_lj_order = Db::name('merchant_order_lj')->where($where)->find(); +// if ($is_lj_order) { +// $is_lj_status = false; +// } else { +// $is_lj_status = true; +// } if ($update['status'] == 3 && isset($merchant['stop']) && $merchant['stop'] > 2) { @@ -439,8 +439,11 @@ class Core extends Controller } else { 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(); $use = $orderAutoService->get($order['order_id']); $this->use_product[] = $order['pid']; @@ -456,8 +459,8 @@ class Core extends Controller 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); + $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;