Commit 78b6760a authored by wanjilong's avatar wanjilong

add: 调整ping++返回

parent c42e12a3
...@@ -23,5 +23,6 @@ class PayException extends BaseException ...@@ -23,5 +23,6 @@ class PayException extends BaseException
11 => '该订单已超时关闭,请重新下单', 11 => '该订单已超时关闭,请重新下单',
12 => '订单不存在,请核对', 12 => '订单不存在,请核对',
13 => '生活号获取管理员ID失败,请联系管理员', 13 => '生活号获取管理员ID失败,请联系管理员',
14 => '支付订单预结算失败,结算资金不能负数,请核对配置',
]; ];
} }
...@@ -17,13 +17,21 @@ class PayOrder extends MysqlBase ...@@ -17,13 +17,21 @@ class PayOrder extends MysqlBase
public static function get_valid_order($order_id, $pay_order) { public static function get_valid_order($order_id, $pay_order) {
self::beginTransaction(); self::beginTransaction();
$_date = date('Y-m-d H:i:s'); try{
$order = self::getMaster('*', ['order_id'=>$order_id, 'expire_time[>]'=>$_date]); $_date = date('Y-m-d H:i:s');
if(empty($order)) { $order = self::getMaster('*', ['order_id'=>$order_id, 'expire_time[>]'=>$_date]);
self::insert($pay_order, ['rowCount'=>true]); if(empty($order)) {
$order = $pay_order; $cnt = self::insert($pay_order, ['rowCount'=>true]);
if($cnt) {
$order = $pay_order;
}
}
self::commit();
}catch (\PDOException $e) {
self::rollback();
} }
self::commit();
return $order; return $order;
} }
} }
...@@ -16,7 +16,6 @@ use App\Services\order\OrderService; ...@@ -16,7 +16,6 @@ use App\Services\order\OrderService;
use App\Services\pingxx\PingxxService; use App\Services\pingxx\PingxxService;
use App\Services\wallet\WalletService; use App\Services\wallet\WalletService;
use Helpers\Strategy; use Helpers\Strategy;
use Helpers\Logger;
use Helpers\Sdk; use Helpers\Sdk;
use App\Exception\custom\PayException; use App\Exception\custom\PayException;
...@@ -31,7 +30,6 @@ class PayService ...@@ -31,7 +30,6 @@ class PayService
private $pay_order = []; private $pay_order = [];
private $clear_list = []; private $clear_list = [];
private $clear_items_list = []; private $clear_items_list = [];
private $wallet_list = [];
public function do_pay($order_id, $user_id) public function do_pay($order_id, $user_id)
{ {
...@@ -88,7 +86,7 @@ class PayService ...@@ -88,7 +86,7 @@ class PayService
// 支持幂等,存在有效订单需要可以重复支付 // 支持幂等,存在有效订单需要可以重复支付
$ret = PingxxService::getInstance()->createOrder($order, $metadata); $ret = PingxxService::getInstance()->createOrder($order, $metadata);
if (!empty($ret['error'])) { if (!empty($ret['error'])) {
throw new \ErrorException($ret['error']['message'], '2001'); throw new \Exception($ret['error']['message'], '2001');
} }
if ($ret["status"] == 'paid' || $ret['status'] == 'refunded') { if ($ret["status"] == 'paid' || $ret['status'] == 'refunded') {
...@@ -117,6 +115,11 @@ class PayService ...@@ -117,6 +115,11 @@ class PayService
throw new PayException(['cus' => 0]); throw new PayException(['cus' => 0]);
} }
//存在一个继续支付单订单
if($pay_order_id != $order['pay_order_id']) {
$ret['exist'] = true;
}
return $ret; return $ret;
} }
...@@ -218,6 +221,8 @@ class PayService ...@@ -218,6 +221,8 @@ class PayService
return ['order_item_id' => $order_item_id]; return ['order_item_id' => $order_item_id];
} }
$this->sync_account_wallet($order_item_id);
return ['order_item_id' => $order_item_id]; return ['order_item_id' => $order_item_id];
} }
...@@ -230,7 +235,6 @@ class PayService ...@@ -230,7 +235,6 @@ class PayService
$cnt = PayOrderItem::update([ $cnt = PayOrderItem::update([
'notify_account_status' => 1, 'notify_account_status' => 1,
'notify_account_success_time' => date('Y-m-d H:i:s')
], ['order_item_id' => $order_item_id, 'can_notify_account' => 1, 'notify_account_status'=>0]); ], ['order_item_id' => $order_item_id, 'can_notify_account' => 1, 'notify_account_status'=>0]);
if($cnt ==0) {//乐观锁,不满足条件不处理 if($cnt ==0) {//乐观锁,不满足条件不处理
...@@ -254,29 +258,25 @@ class PayService ...@@ -254,29 +258,25 @@ class PayService
'amount' => $row['pay_amount'], 'amount' => $row['pay_amount'],
'third_order_id' => $row['pay_order_clearing_item_id'], 'third_order_id' => $row['pay_order_clearing_item_id'],
'third_order_id_type' => $row['pay_sub_type'], 'third_order_id_type' => $row['pay_sub_type'],
'third_order_desc' => '', 'third_order_desc' => $row['remark'],
]; ];
} }
if ($wallet_list) { try{
$ret = WalletService::send($wallet_list); if($wallet_list) { //同步成功,返回结果
if($ret) {//同步成功,返回结果 WalletService::send($wallet_list);
PayOrderItem::update([
'notify_account_status' => 2,
'notify_account_success_time' => date('Y-m-d H:i:s')
], ['order_item_id' => $order_item_id, 'can_notify_account' => 1]);
} else {
//补偿处理
PayOrderItem::update([
'notify_account_status' => 0,
], ['order_item_id' => $order_item_id, 'can_notify_account' => 1]);
} }
} else { //没有需要同步的,显示处理
PayOrderItem::update([ PayOrderItem::update([
'notify_account_status' => 2, 'notify_account_status' => 2,
'notify_account_success_time' => date('Y-m-d H:i:s') 'notify_account_success_time' => date('Y-m-d H:i:s')
], ['order_item_id' => $order_item_id, 'can_notify_account' => 1]); ], ['order_item_id' => $order_item_id, 'can_notify_account' => 1]);
} catch (\Exception $e) {
FileLog::error('wallet: 钱包同步失败' . $e->getMessage(), json_encode($wallet_list));
//补偿处理
PayOrderItem::update([
'notify_account_status' => 0,
], ['order_item_id' => $order_item_id, 'can_notify_account' => 1]);
} }
} }
...@@ -291,7 +291,6 @@ class PayService ...@@ -291,7 +291,6 @@ class PayService
$this->clear_list = []; $this->clear_list = [];
$this->clear_items_list = []; $this->clear_items_list = [];
$this->wallet_list = [];
$pay_order_items = []; $pay_order_items = [];
foreach ($this->order_items as $r) { foreach ($this->order_items as $r) {
...@@ -308,6 +307,14 @@ class PayService ...@@ -308,6 +307,14 @@ class PayService
$distribution_tip = $this->make_distribution_clearing(); //团长收益 $distribution_tip = $this->make_distribution_clearing(); //团长收益
$platform_tip = $this->make_platform_clearing(); //平台收益 $platform_tip = $this->make_platform_clearing(); //平台收益
$merchant_cash = $this->order_info['payment'] - $wx_tip - $distribution_tip - $platform_tip; $merchant_cash = $this->order_info['payment'] - $wx_tip - $distribution_tip - $platform_tip;
//核对各项资金的合理性
if($wx_tip <0 || $distribution_tip <0 || $platform_tip < 0 || $merchant_cash < 0) {
FileLog::error('pay: 支付预结算失败,结算资金为负',
json_encode([$this->order_info['payment'], $wx_tip, $distribution_tip, $platform_tip, $merchant_cash]));
throw new PayException(['cus'=>14]);
}
$this->make_merchant_clearing($merchant_cash); //商户收益 $this->make_merchant_clearing($merchant_cash); //商户收益
try { try {
...@@ -346,7 +353,7 @@ class PayService ...@@ -346,7 +353,7 @@ class PayService
private function make_tip_clearing() private function make_tip_clearing()
{ {
$wx_rate = config('pay','pay.wechat_rate') ?? 60; //微信利率 60 / 10000 $wx_rate = config('pay','pay.wechat_rate') ?? 60; //微信利率 60 / 10000
$wx_account_id = config('pay','pay.wechat_account_id') ?? ''; $wx_account_id = config('pay','pay.wechat_account_id') ?? '1111';
$total_tip = round($wx_rate * $this->order_info['payment'] / 10000); $total_tip = round($wx_rate * $this->order_info['payment'] / 10000);
if (empty($total_tip)) { if (empty($total_tip)) {
...@@ -398,7 +405,7 @@ class PayService ...@@ -398,7 +405,7 @@ class PayService
/** /**
* @return mixed * @return mixed
* 计算分销信息, 分销没有总帐,仅有单条四舍五入的计算 * 计算分销信息, 分销没有总帐,仅有单条floor的计算
*/ */
private function make_distribution_clearing() private function make_distribution_clearing()
{ {
...@@ -412,28 +419,33 @@ class PayService ...@@ -412,28 +419,33 @@ class PayService
$total_tip = 0; $total_tip = 0;
foreach ($this->order_items as $r) { foreach ($this->order_items as $r) {
if($r['marketing_type'] != 1) { //仅处理分销业务
if(empty($r['distributor_user_id']) || $r['marketing_type'] != 1) {
continue; continue;
} }
$_one = $_two = 0;
if($r['commission_mode'] == 1) {
$_one = floor($r['distributor_commission_value'] * $this->order_info['total_price'] / 10000);
$_two = floor($r['parent_commission_value'] * $this->order_info['total_price'] / 10000);
} elseif($r['commission_mode'] == 2) {
$_one = $r['distributor_commission_value'];
$_two = $r['parent_commission_value'];
}
$users[0] = [ $users[0] = [
'user_id'=>$r['distributor_user_id'], 'user_id'=>$r['distributor_user_id'],
'value'=>$r['distributor_commission_value'], 'value'=>$r['distributor_commission_value'],
'amount'=>0 'amount'=>$_one
];
$users[1] = [
'user_id'=>$r['parent_user_id'],
'value'=>$r['parent_commission_value'],
'amount'=>0
]; ];
if($r['commission_mode'] == 1) { if(!empty($r['parent_user_id'])) {
$users[0]['amount'] = round($users[0]['value'] * $this->order_info['total_price'] / 10000); $users[1] = [
$users[1]['amount'] = round($users[1]['value'] * $this->order_info['total_price'] / 10000); 'user_id'=>$r['parent_user_id'],
'value'=>$r['parent_commission_value'],
} elseif($r['commission_mode'] == 2) { 'amount'=>$_two
$users[0]['amount'] = $users[0]['value']; ];
$users[1]['amount'] = $users[1]['value'];
} }
foreach ($users as $u) { foreach ($users as $u) {
...@@ -480,7 +492,6 @@ class PayService ...@@ -480,7 +492,6 @@ class PayService
throw new PayException(['cus'=>13]); throw new PayException(['cus'=>13]);
} }
$account = [ $account = [
'account_id' => $ret['result']['life_account_admin_id'], 'account_id' => $ret['result']['life_account_admin_id'],
'amount' => $merchant_cash, 'amount' => $merchant_cash,
...@@ -523,6 +534,14 @@ class PayService ...@@ -523,6 +534,14 @@ class PayService
$current_tip = Strategy::getTip($r['payment'], $total_amount, $cleared_amount, $total_tip, $cleared_tip); $current_tip = Strategy::getTip($r['payment'], $total_amount, $cleared_amount, $total_tip, $cleared_tip);
$id = $this->gen_pay_order_clearing_item_id(); $id = $this->gen_pay_order_clearing_item_id();
//商家资金需要显示商品名称
if($account['pay_sub_type'] == 102) {
$remark = $r['goods_name'] ?? '';
$remark = mb_strlen($remark) > 100 ? mb_substr($remark, 0, 100) . '...' : '';
} else {
$remark = '';
}
$this->clear_items_list[] = [ $this->clear_items_list[] = [
'pay_order_clearing_item_id' => $id, 'pay_order_clearing_item_id' => $id,
'pay_order_clearing_id' => $pay_order_clearing_id, 'pay_order_clearing_id' => $pay_order_clearing_id,
...@@ -534,6 +553,7 @@ class PayService ...@@ -534,6 +553,7 @@ class PayService
'pay_amount' => $current_tip, 'pay_amount' => $current_tip,
'pay_type' => $account['pay_type'], 'pay_type' => $account['pay_type'],
'pay_sub_type' => $account['pay_sub_type'], 'pay_sub_type' => $account['pay_sub_type'],
'remark' => $remark,
'need_recorded' => $account['need_recorded'], 'need_recorded' => $account['need_recorded'],
]; ];
...@@ -582,7 +602,6 @@ class PayService ...@@ -582,7 +602,6 @@ class PayService
private function get_life_account($life_account_id) private function get_life_account($life_account_id)
{ {
$url = config('interface', 'merchant.lifeaccount.get_life_account_by_id'); $url = config('interface', 'merchant.lifeaccount.get_life_account_by_id');
if (!$url) { if (!$url) {
throw new CodeSpecialException("failed" . __METHOD__); throw new CodeSpecialException("failed" . __METHOD__);
......
...@@ -7,7 +7,6 @@ use Api\PhpUtils\Log\FileLog; ...@@ -7,7 +7,6 @@ use Api\PhpUtils\Log\FileLog;
use Pingpp\Order; use Pingpp\Order;
use Pingpp\Pingpp; use Pingpp\Pingpp;
use Pingpp\OrderRefund; use Pingpp\OrderRefund;
use Helpers\Logger;
use Api\PhpUtils\Common\IP; use Api\PhpUtils\Common\IP;
...@@ -62,14 +61,16 @@ class PingxxService ...@@ -62,14 +61,16 @@ class PingxxService
} catch (\Pingpp\Error\Base $e) { } catch (\Pingpp\Error\Base $e) {
// 捕获报错信息
if ($e->getHttpStatus() != null) { if ($e->getHttpStatus() != null) {
$msg = $e->getHttpBody(); return json_encode($e->getHttpBody(), true);
} else { } else {
$msg = $e->getMessage(); return [
'error'=>['message'=>$e->getMessage()],
'type'=>'http error',
];
} }
exit($msg);
throw new \Exception($msg, '2001');
} }
} }
...@@ -88,11 +89,15 @@ class PingxxService ...@@ -88,11 +89,15 @@ class PingxxService
return $respose; return $respose;
} catch (\Pingpp\Error\Base $e) { } catch (\Pingpp\Error\Base $e) {
// 捕获报错信息
if ($e->getHttpStatus() != null) { if ($e->getHttpStatus() != null) {
header('Status: ' . $e->getHttpStatus()); return json_encode($e->getHttpBody(), true);
echo $e->getHttpBody();
} else { } else {
echo $e->getMessage(); return [
'error'=>['message'=>$e->getMessage()],
'type'=>'http error',
];
} }
} }
} }
...@@ -130,11 +135,24 @@ class PingxxService ...@@ -130,11 +135,24 @@ class PingxxService
} catch (\Pingpp\Error\Base $e) { } catch (\Pingpp\Error\Base $e) {
// 捕获报错信息 // 捕获报错信息
if ($e->getHttpStatus() != null) { if ($e->getHttpStatus() != null) {
echo $e->getHttpStatus() . PHP_EOL; return json_decode($e->getHttpBody(), true);
echo $e->getHttpBody() . PHP_EOL;
} else { } else {
echo $e->getMessage() . PHP_EOL; return [
'error'=>['message'=>$e->getMessage()],
'type'=>'http error',
];
}
/**
{
"error": {
"type": "invalid_request_error",
"message": "缺少请求参数: merchant_order_no",
"param": "merchant_order_no",
"code": "request_param_error"
}
} }
*/
} }
} }
...@@ -153,11 +171,15 @@ class PingxxService ...@@ -153,11 +171,15 @@ class PingxxService
return $respose; return $respose;
} catch (\Pingpp\Error\Base $e) { } catch (\Pingpp\Error\Base $e) {
// 捕获报错信息
if ($e->getHttpStatus() != null) { if ($e->getHttpStatus() != null) {
header('Status: ' . $e->getHttpStatus()); return json_encode($e->getHttpBody(), true);
echo $e->getHttpBody();
} else { } else {
echo $e->getMessage(); return [
'error'=>['message'=>$e->getMessage()],
'type'=>'http error',
];
} }
} }
} }
......
...@@ -228,7 +228,6 @@ class RefundService ...@@ -228,7 +228,6 @@ class RefundService
}catch (\PDOException $e) { }catch (\PDOException $e) {
RefundOrder::rollback(); RefundOrder::rollback();
Logger::error($e->getMessage(), $edit);
throw $e; throw $e;
} }
......
...@@ -18,7 +18,6 @@ class WalletService ...@@ -18,7 +18,6 @@ class WalletService
*/ */
public static function send($params) { public static function send($params) {
return true;
$url = config('interface', 'wallet.wallet.recharge'); $url = config('interface', 'wallet.wallet.recharge');
if (!$url) { if (!$url) {
throw new CodeSpecialException("failed"); throw new CodeSpecialException("failed");
...@@ -26,5 +25,4 @@ class WalletService ...@@ -26,5 +25,4 @@ class WalletService
return Sdk::call($url, $params); return Sdk::call($url, $params);
} }
} }
\ No newline at end of file
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment