Commit 402c0e72 authored by 顾文旭's avatar 顾文旭

add id get

parent fbc30077
...@@ -4,6 +4,7 @@ ...@@ -4,6 +4,7 @@
namespace App\Services\pay; namespace App\Services\pay;
use Api\PhpServices\Idgen\Idgen; use Api\PhpServices\Idgen\Idgen;
use Api\PhpUtils\Http\Request;
use Api\PhpUtils\Log\FileLog; use Api\PhpUtils\Log\FileLog;
use App\Models\Dictionary; use App\Models\Dictionary;
use App\Models\order\mysql\PayOrder; use App\Models\order\mysql\PayOrder;
...@@ -35,7 +36,7 @@ class PayService ...@@ -35,7 +36,7 @@ class PayService
public function do_pay($order_id, $user_id, $pingxx_id, $pay_method_id = 105, $extra = []) public function do_pay($order_id, $user_id, $pingxx_id, $pay_method_id = 105, $extra = [])
{ {
if(empty($order_id)) { if (empty($order_id)) {
throw new PayException(['cus' => 1]); throw new PayException(['cus' => 1]);
} }
// 获取订单信息 // 获取订单信息
...@@ -54,52 +55,52 @@ class PayService ...@@ -54,52 +55,52 @@ class PayService
} }
$pay_expiration_time = strtotime($order_info['pay_expiration_time']); $pay_expiration_time = strtotime($order_info['pay_expiration_time']);
if($pay_expiration_time < time()) { if ($pay_expiration_time < time()) {
throw new PayException(['cus' => 16]); throw new PayException(['cus' => 16]);
} }
if(empty($data['result']['order_item_list'])) { if (empty($data['result']['order_item_list'])) {
throw new PayException(['cus' => 14]); throw new PayException(['cus' => 14]);
} }
$metadata = [ $metadata = [
'app_id'=>'merchant-c', 'app_id' => 'merchant-c',
'pingxx_id'=>PingxxService::getInstance($pingxx_id)->getAppId(), 'pingxx_id' => PingxxService::getInstance($pingxx_id)->getAppId(),
'environ'=>Application::app()->environ(), 'environ' => Application::app()->environ(),
'order_id'=>$order_id, 'order_id' => $order_id,
'goods'=>[], 'goods' => [],
'marketing'=>[], 'marketing' => [],
'order_item_id'=>[], 'order_item_id' => [],
]; ];
$min_expire_time = $now = time(); $min_expire_time = $now = time();
foreach ($data['result']['order_item_list'] as $item) { foreach ($data['result']['order_item_list'] as $item) {
if(strtotime($item['expiration_time']) < $min_expire_time) { if (strtotime($item['expiration_time']) < $min_expire_time) {
$min_expire_time = strtotime($item['expiration_time']); $min_expire_time = strtotime($item['expiration_time']);
} }
if(empty($metadata['goods'][$item['goods_sku_id']])) { if (empty($metadata['goods'][$item['goods_sku_id']])) {
$metadata['goods'][$item['goods_sku_id']] = 0; $metadata['goods'][$item['goods_sku_id']] = 0;
} }
$metadata['goods'][$item['goods_sku_id']] += $item['goods_num']; $metadata['goods'][$item['goods_sku_id']] += $item['goods_num'];
if(!empty($item['marketing_id'])) { if (!empty($item['marketing_id'])) {
$metadata['marketing'][$item['goods_sku_id']] = $item['marketing_id']; $metadata['marketing'][$item['goods_sku_id']] = $item['marketing_id'];
} }
array_push($metadata['order_item_id'], $item['order_item_id']); array_push($metadata['order_item_id'], $item['order_item_id']);
} }
if($now > $min_expire_time) { if ($now > $min_expire_time) {
throw new PayException(['cus' => 15]); throw new PayException(['cus' => 15]);
} }
//订单过期时间必须满足 70s+ //订单过期时间必须满足 70s+
if($pay_expiration_time - $now < 70 ) { if ($pay_expiration_time - $now < 70) {
$pay_expiration_time = $now + 70; $pay_expiration_time = $now + 70;
} }
$pay_order_id = $this->gen_pay_order_id($user_id); $pay_order_id = $this->gen_id_by_blend('pay_order_id');
$new_pay_order = [ $new_pay_order = [
'pay_order_id' => $pay_order_id, 'pay_order_id' => $pay_order_id,
'user_id' => $order_info['user_id'], 'user_id' => $order_info['user_id'],
...@@ -125,7 +126,7 @@ class PayService ...@@ -125,7 +126,7 @@ class PayService
} }
//不支持修改订单过期时间,再次调用支付服务 //不支持修改订单过期时间,再次调用支付服务
if(strtotime($pay_order['expire_time']) < time()) { if (strtotime($pay_order['expire_time']) < time()) {
throw new PayException(['cus' => 16]); throw new PayException(['cus' => 16]);
} }
...@@ -134,14 +135,14 @@ class PayService ...@@ -134,14 +135,14 @@ class PayService
} }
// 已经创建,需要查询返回 // 已经创建,需要查询返回
if(!empty($pay_order['third_order_id'])) { if (!empty($pay_order['third_order_id'])) {
$ret = PingxxService::getInstance($pingxx_id)->getOrder($pay_order['third_order_id']); $ret = PingxxService::getInstance($pingxx_id)->getOrder($pay_order['third_order_id']);
} else { } else {
$ret = PingxxService::getInstance($pingxx_id)->createOrder($pay_order, $metadata); $ret = PingxxService::getInstance($pingxx_id)->createOrder($pay_order, $metadata);
} }
if (!empty($ret['error'])) { if (!empty($ret['error'])) {
throw new BaseException(['msg'=>$ret['error']['message'], 'code'=>'2301']); throw new BaseException(['msg' => $ret['error']['message'], 'code' => '2301']);
} }
if ($ret["status"] == 'paid' || $ret['status'] == 'refunded') { if ($ret["status"] == 'paid' || $ret['status'] == 'refunded') {
...@@ -173,16 +174,16 @@ class PayService ...@@ -173,16 +174,16 @@ class PayService
} }
//存在一个继续支付单订单 //存在一个继续支付单订单
if($pay_order_id != $pay_order['pay_order_id']) { if ($pay_order_id != $pay_order['pay_order_id']) {
$ret['exist'] = true; $ret['exist'] = true;
} }
$channel_exist = false; $channel_exist = false;
$channel = $this->getChannel($pay_method_id); $channel = $this->getChannel($pay_method_id);
if(!empty($ret['charges']['data'])) { if (!empty($ret['charges']['data'])) {
//是否存在 //是否存在
foreach ($ret['charges']['data'] as $ch) { foreach ($ret['charges']['data'] as $ch) {
if($ch['channel'] == $channel) { if ($ch['channel'] == $channel) {
$channel_exist = true; $channel_exist = true;
} }
} }
...@@ -190,18 +191,18 @@ class PayService ...@@ -190,18 +191,18 @@ class PayService
} }
//判断是否做过pay操作 charge //判断是否做过pay操作 charge
if($channel_exist == false) { if ($channel_exist == false) {
// 创建支付单 // 创建支付单
$payment = [ $payment = [
'charge_order_no'=> $pay_order['pay_order_id'], 'charge_order_no' => $pay_order['pay_order_id'],
'charge_amount'=> $pay_order['pay_amount'], 'charge_amount' => $pay_order['pay_amount'],
'channel'=> $channel, 'channel' => $channel,
'extra'=> $extra, 'extra' => $extra,
]; ];
$pay = PingxxService::getInstance($pingxx_id)->pay($ret['id'], $payment); $pay = PingxxService::getInstance($pingxx_id)->pay($ret['id'], $payment);
if (!empty($pay['error'])) { if (!empty($pay['error'])) {
throw new BaseException(['msg'=>$pay['error']['message'], 'code'=>'2002']); throw new BaseException(['msg' => $pay['error']['message'], 'code' => '2002']);
} }
return $pay; return $pay;
...@@ -218,20 +219,20 @@ class PayService ...@@ -218,20 +219,20 @@ class PayService
public function call_back($data) public function call_back($data)
{ {
if (!in_array($data['type'], ['order.succeeded', 'charge.succeeded'])) { if (!in_array($data['type'], ['order.succeeded', 'charge.succeeded'])) {
return ['error'=>'支付回调类型不正确']; return ['error' => '支付回调类型不正确'];
} }
if (empty($data['data']['object'])) { if (empty($data['data']['object'])) {
return ['error'=>'支付回调格式不正确']; return ['error' => '支付回调格式不正确'];
} }
$object = $data['data']['object']; $object = $data['data']['object'];
if(empty($object['metadata']['app_id']) || $object['metadata']['app_id'] != "merchant-c") { if (empty($object['metadata']['app_id']) || $object['metadata']['app_id'] != "merchant-c") {
//非支付中心发出的订单,需要忽略 //非支付中心发出的订单,需要忽略
return ['error'=>'非merchant渠道订单,不做处理。']; return ['error' => '非merchant渠道订单,不做处理。'];
} }
if($data['type'] == 'charge.succeeded') { if ($data['type'] == 'charge.succeeded') {
$pay_order_id = $object['order_no']; $pay_order_id = $object['order_no'];
$paid = $object['paid']; $paid = $object['paid'];
$amount = $object['amount']; $amount = $object['amount'];
...@@ -241,15 +242,15 @@ class PayService ...@@ -241,15 +242,15 @@ class PayService
$amount = $object['actual_amount']; $amount = $object['actual_amount'];
} }
if($paid != true) { if ($paid != true) {
return ['error'=>'支付状态不正确,不做处理。']; return ['error' => '支付状态不正确,不做处理。'];
} }
$pay_order = PayOrder::get('*', ['pay_order_id' => $pay_order_id]); $pay_order = PayOrder::get('*', ['pay_order_id' => $pay_order_id]);
if (empty($pay_order)) { if (empty($pay_order)) {
throw new PayException(['cus' => 7]); throw new PayException(['cus' => 7]);
} }
if($pay_order['pay_amount'] != $amount) { if ($pay_order['pay_amount'] != $amount) {
throw new PayException(['cus' => 8]); throw new PayException(['cus' => 8]);
} }
...@@ -265,7 +266,7 @@ class PayService ...@@ -265,7 +266,7 @@ class PayService
$cnt = PayOrder::update($edit, $where); $cnt = PayOrder::update($edit, $where);
//保持幂等返回成功 //保持幂等返回成功
if($cnt == 0) { if ($cnt == 0) {
return ['pay_order_id' => $pay_order_id]; return ['pay_order_id' => $pay_order_id];
} }
...@@ -281,14 +282,14 @@ class PayService ...@@ -281,14 +282,14 @@ class PayService
$this->make_order_clearing($ret['result']); $this->make_order_clearing($ret['result']);
//收集第一商品名称 //收集第一商品名称
if($this->order_items) { if ($this->order_items) {
$title = $this->order_items[0]['goods_name'] ?? '商品名称'; $title = $this->order_items[0]['goods_name'] ?? '商品名称';
} else { } else {
$title = ''; $title = '';
} }
try{ try {
//通知消息 //通知消息
$app_id = 'wx65e9ba99c333444f'; $app_id = 'wx65e9ba99c333444f';
$template_id = 'EzOH2ZpfW-eUdFf9gzjZTAv-Z9PFmKHNsQ0VOGvvN7c'; $template_id = 'EzOH2ZpfW-eUdFf9gzjZTAv-Z9PFmKHNsQ0VOGvvN7c';
...@@ -301,12 +302,12 @@ class PayService ...@@ -301,12 +302,12 @@ class PayService
date('Y-m-d'), date('Y-m-d'),
]; ];
if(isset($ret['result']['order_info']['business_from']) && $ret['result']['order_info']['business_from'] != 2) { if (isset($ret['result']['order_info']['business_from']) && $ret['result']['order_info']['business_from'] != 2) {
//接龙业务不发送消息 //接龙业务不发送消息
Msg::send($pay_order['user_id'], $app_id, $template_id, $page_url, $type, $query); Msg::send($pay_order['user_id'], $app_id, $template_id, $page_url, $type, $query);
} }
}catch (\Throwable $e) { } catch (\Throwable $e) {
; ;
} }
...@@ -320,48 +321,49 @@ class PayService ...@@ -320,48 +321,49 @@ class PayService
* @throws PayException * @throws PayException
* 返回订单状态及订单渠道列表 * 返回订单状态及订单渠道列表
*/ */
public function pay_charges($order_id) { public function pay_charges($order_id)
{
$pay_order = PayOrder::get('*', ['order_id'=>$order_id]); $pay_order = PayOrder::get('*', ['order_id' => $order_id]);
if(empty($pay_order)) { if (empty($pay_order)) {
throw new PayException(['cus' => 18]); throw new PayException(['cus' => 18]);
} }
$data = [ $data = [
'status'=>'created', 'status' => 'created',
'max_expire_time'=>$pay_order['expire_time'], 'max_expire_time' => $pay_order['expire_time'],
'list'=>[] 'list' => []
]; ];
$max_expire_time = strtotime($pay_order['expire_time']); $max_expire_time = strtotime($pay_order['expire_time']);
if($max_expire_time < time()) { if ($max_expire_time < time()) {
$data["status"] = 'canceled'; $data["status"] = 'canceled';
} }
if(empty($pay_order['third_order_id'])) { if (empty($pay_order['third_order_id'])) {
return $data; return $data;
} }
//paid、refunded、canceled、created //paid、refunded、canceled、created
$ret = PingxxService::getInstance($pay_order['pingxx_id'])->getOrder($pay_order['third_order_id']); $ret = PingxxService::getInstance($pay_order['pingxx_id'])->getOrder($pay_order['third_order_id']);
if (!empty($ret['error'])) { if (!empty($ret['error'])) {
throw new BaseException(['msg'=>$ret['error']['message'], 'code'=>'2301']); throw new BaseException(['msg' => $ret['error']['message'], 'code' => '2301']);
} }
$data["status"] = $ret["status"]; $data["status"] = $ret["status"];
if(!empty($ret['charges']['data'])) { if (!empty($ret['charges']['data'])) {
//是否存在 //是否存在
foreach ($ret['charges']['data'] as $ch) { foreach ($ret['charges']['data'] as $ch) {
$data["list"][] = [ $data["list"][] = [
'paid'=>$ch['paid'], 'paid' => $ch['paid'],
'refunded'=>$ch['refunded'], 'refunded' => $ch['refunded'],
'channel'=>$ch['channel'], 'channel' => $ch['channel'],
'time_expire'=>$ch['time_expire'], 'time_expire' => $ch['time_expire'],
]; ];
if($max_expire_time < $ch['time_expire']) { if ($max_expire_time < $ch['time_expire']) {
$max_expire_time = $ch['time_expire']; $max_expire_time = $ch['time_expire'];
} }
} }
...@@ -381,37 +383,37 @@ class PayService ...@@ -381,37 +383,37 @@ class PayService
{ {
$cnt = 0; $cnt = 0;
//锁定状态 //锁定状态
try{ try {
PayOrderItem::beginTransaction(); PayOrderItem::beginTransaction();
$item = PayOrderItem::getMaster('*', ['order_item_id' => $order_item_id]); $item = PayOrderItem::getMaster('*', ['order_item_id' => $order_item_id]);
if(empty($item)) { if (empty($item)) {
throw new PayException(['cus'=>10]); throw new PayException(['cus' => 10]);
} }
if($item['refund_order_status'] != 0) { if ($item['refund_order_status'] != 0) {
throw new PayException(['cus'=>9]); throw new PayException(['cus' => 9]);
} }
$pay_order = PayOrder::getMaster('*', ['pay_order_id'=>$item['pay_order_id']]); $pay_order = PayOrder::getMaster('*', ['pay_order_id' => $item['pay_order_id']]);
if(empty($pay_order) || $pay_order['life_account_id'] != $life_account_id) { if (empty($pay_order) || $pay_order['life_account_id'] != $life_account_id) {
throw new PayException(['cus'=>11]); throw new PayException(['cus' => 11]);
} }
$cnt = PayOrderItem::update([ $cnt = PayOrderItem::update([
'notify_account_status' => 0, 'notify_account_status' => 0,
'can_notify_account' => 1, 'can_notify_account' => 1,
'can_notify_account_time' => date('Y-m-d H:i:s'), 'can_notify_account_time' => date('Y-m-d H:i:s'),
], ['order_item_id' => $order_item_id, 'can_notify_account'=>0, 'refund_order_status'=>0]); ], ['order_item_id' => $order_item_id, 'can_notify_account' => 0, 'refund_order_status' => 0]);
PayOrderItem::commit(); PayOrderItem::commit();
}catch (\Exception $e) { } catch (\Exception $e) {
PayOrderItem::rollback(); PayOrderItem::rollback();
throw new BaseException(['msg'=>$e->getMessage(), 'code'=>$e->getCode()]); throw new BaseException(['msg' => $e->getMessage(), 'code' => $e->getCode()]);
} }
if($cnt == 0) {//幂等直接返回 if ($cnt == 0) {//幂等直接返回
return ['order_item_id' => $order_item_id]; return ['order_item_id' => $order_item_id];
} }
...@@ -425,13 +427,14 @@ class PayService ...@@ -425,13 +427,14 @@ class PayService
* @throws \App\Exception\custom\CodeSpecialException * @throws \App\Exception\custom\CodeSpecialException
* 同步钱包处理 * 同步钱包处理
*/ */
public function sync_account_wallet($order_item_id) { public function sync_account_wallet($order_item_id)
{
$cnt = PayOrderItem::update([ $cnt = PayOrderItem::update([
'notify_account_status' => 1, 'notify_account_status' => 1,
], ['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) {//乐观锁,不满足条件不处理
return true; return true;
} }
...@@ -442,12 +445,12 @@ class PayService ...@@ -442,12 +445,12 @@ class PayService
$wallet_list = []; $wallet_list = [];
foreach ($clearing_items as $row) { foreach ($clearing_items as $row) {
if($row['pay_amount'] <= 0) { if ($row['pay_amount'] <= 0) {
continue; continue;
} }
//处理商家结算价格的兼容 //处理商家结算价格的兼容
if($row['clear_payment'] > 0 && $row['pay_sub_type'] == 102) { if ($row['clear_payment'] > 0 && $row['pay_sub_type'] == 102) {
$pay_amount = $row['clear_payment']; $pay_amount = $row['clear_payment'];
} else { } else {
$pay_amount = $row['pay_amount']; $pay_amount = $row['pay_amount'];
...@@ -464,9 +467,9 @@ class PayService ...@@ -464,9 +467,9 @@ class PayService
]; ];
} }
try{ try {
if($wallet_list) { //同步成功,返回结果 if ($wallet_list) { //同步成功,返回结果
WalletService::send(['list'=>$wallet_list]); WalletService::send(['list' => $wallet_list]);
} }
PayOrderItem::update([ PayOrderItem::update([
'notify_account_status' => 2, 'notify_account_status' => 2,
...@@ -503,7 +506,7 @@ class PayService ...@@ -503,7 +506,7 @@ class PayService
$pay_order_items = []; $pay_order_items = [];
foreach ($this->order_items as $r) { foreach ($this->order_items as $r) {
$pay_order_items[] = [ $pay_order_items[] = [
'pay_order_item_id' => $this->gen_pay_order_item_id(), 'pay_order_item_id' => $this->gen_id_by_blend('pay_order_item_id'),
'pay_order_id' => $this->pay_order['pay_order_id'], 'pay_order_id' => $this->pay_order['pay_order_id'],
'order_id' => $this->pay_order['order_id'], 'order_id' => $this->pay_order['order_id'],
'order_item_id' => $r['order_item_id'], 'order_item_id' => $r['order_item_id'],
...@@ -518,10 +521,10 @@ class PayService ...@@ -518,10 +521,10 @@ class PayService
$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) { if ($wx_tip < 0 || $distribution_tip < 0 || $platform_tip < 0 || $merchant_cash < 0) {
FileLog::error('pay-service: 支付预结算失败,结算资金为负', FileLog::error('pay-service: 支付预结算失败,结算资金为负',
json_encode([$this->order_info['payment'], $wx_tip, $distribution_tip, $platform_tip, $merchant_cash])); json_encode([$this->order_info['payment'], $wx_tip, $distribution_tip, $platform_tip, $merchant_cash]));
throw new PayException(['cus'=>12]); throw new PayException(['cus' => 12]);
} }
$this->make_merchant_clearing($merchant_cash); //商户收益 $this->make_merchant_clearing($merchant_cash); //商户收益
...@@ -546,11 +549,11 @@ class PayService ...@@ -546,11 +549,11 @@ class PayService
foreach ($this->order_items as $r) { foreach ($this->order_items as $r) {
// 收集直接到账信息 // 收集直接到账信息
//rule_refund 退款规则:1到期自动退款,2购买后不允许退款,3到期后不退款 //rule_refund 退款规则:1到期自动退款,2购买后不允许退款,3到期后不退款
if($r['rule_refund'] == 2 ) { //分销商品一定是不可退 if ($r['rule_refund'] == 2) { //分销商品一定是不可退
PayOrderItem::update([ PayOrderItem::update([
'can_notify_account'=>1, 'can_notify_account' => 1,
'can_notify_account_time'=>date('Y-m-d H:i:s') 'can_notify_account_time' => date('Y-m-d H:i:s')
], ['order_item_id'=>$r['order_item_id']]); ], ['order_item_id' => $r['order_item_id']]);
} }
} }
} }
...@@ -562,11 +565,11 @@ class PayService ...@@ -562,11 +565,11 @@ 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') ?? '1111'; $wx_account_id = config('pay', 'pay.wechat_account_id') ?? '1111';
$float_tip = $wx_rate * $this->order_info['payment'] / 10000; $float_tip = $wx_rate * $this->order_info['payment'] / 10000;
if($float_tip >= 1 ) { if ($float_tip >= 1) {
$total_tip = round($float_tip); $total_tip = round($float_tip);
} else { } else {
$total_tip = 0; $total_tip = 0;
...@@ -635,33 +638,33 @@ class PayService ...@@ -635,33 +638,33 @@ class PayService
$total_tip = 0; $total_tip = 0;
foreach ($this->order_items as $r) { foreach ($this->order_items as $r) {
//仅处理分销业务 //仅处理分销业务
if(empty($r['distributor_user_id']) || $r['marketing_type'] != 1) { if (empty($r['distributor_user_id']) || $r['marketing_type'] != 1) {
continue; continue;
} }
$r['distributor_commission_value'] = intval($r['distributor_commission_value']); $r['distributor_commission_value'] = intval($r['distributor_commission_value']);
$r['parent_commission_value'] = intval($r['parent_commission_value']); $r['parent_commission_value'] = intval($r['parent_commission_value']);
$_one = $_two = 0; $_one = $_two = 0;
if($r['commission_mode'] == 1) { if ($r['commission_mode'] == 1) {
$_one = floor($r['distributor_commission_value'] * $this->order_info['total_price'] / 10000); $_one = floor($r['distributor_commission_value'] * $this->order_info['total_price'] / 10000);
$_two = floor($r['parent_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) { } elseif ($r['commission_mode'] == 2) {
$_one = $r['distributor_commission_value']; $_one = $r['distributor_commission_value'];
$_two = $r['parent_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'=>$_one 'amount' => $_one
]; ];
if(!empty($r['parent_user_id'])) { if (!empty($r['parent_user_id'])) {
$users[1] = [ $users[1] = [
'user_id'=>$r['parent_user_id'], 'user_id' => $r['parent_user_id'],
'value'=>$r['parent_commission_value'], 'value' => $r['parent_commission_value'],
'amount'=>$_two 'amount' => $_two
]; ];
} }
...@@ -671,7 +674,7 @@ class PayService ...@@ -671,7 +674,7 @@ class PayService
} }
$this->clear_items_list[] = [ $this->clear_items_list[] = [
'pay_order_clearing_item_id' => $this->gen_pay_order_clearing_item_id(), 'pay_order_clearing_item_id' => $this->gen_id_by_blend('pay_order_clearing_item_id'),
'pay_order_clearing_id' => '', 'pay_order_clearing_id' => '',
'pay_order_id' => $this->pay_order['pay_order_id'], 'pay_order_id' => $this->pay_order['pay_order_id'],
'order_id' => $this->pay_order['order_id'], 'order_id' => $this->pay_order['order_id'],
...@@ -701,14 +704,14 @@ class PayService ...@@ -701,14 +704,14 @@ class PayService
private function make_merchant_clearing($merchant_cash) private function make_merchant_clearing($merchant_cash)
{ {
$ret = $this->get_life_account($this->order_info['life_account_id']); $ret = $this->get_life_account($this->order_info['life_account_id']);
if(empty($ret['result']['life_account_admin_id'])) { if (empty($ret['result']['life_account_admin_id'])) {
$log_string = json_encode([ $log_string = json_encode([
'life_account_id'=>$this->order_info['life_account_id'], 'life_account_id' => $this->order_info['life_account_id'],
'ret'=>$ret, 'ret' => $ret,
], JSON_UNESCAPED_UNICODE); ], JSON_UNESCAPED_UNICODE);
FileLog::error('pay-service:', '获取生活号管理员失败', $log_string); FileLog::error('pay-service:', '获取生活号管理员失败', $log_string);
throw new PayException(['cus'=>13]); throw new PayException(['cus' => 13]);
} }
$account = [ $account = [
...@@ -732,7 +735,7 @@ class PayService ...@@ -732,7 +735,7 @@ class PayService
$cleared_amount = 0; //已经结算记录 $cleared_amount = 0; //已经结算记录
$cleared_tip = 0; //已经结算记录 $cleared_tip = 0; //已经结算记录
$pay_order_clearing_id = $this->gen_pay_order_clearing_id(); $pay_order_clearing_id = $this->gen_id_by_blend('pay_order_clearing_id');
$this->clear_list[] = [ $this->clear_list[] = [
'pay_order_clearing_id' => $pay_order_clearing_id, 'pay_order_clearing_id' => $pay_order_clearing_id,
'pay_order_id' => $this->pay_order['pay_order_id'], 'pay_order_id' => $this->pay_order['pay_order_id'],
...@@ -752,16 +755,16 @@ class PayService ...@@ -752,16 +755,16 @@ class PayService
foreach ($this->order_items as $r) { foreach ($this->order_items as $r) {
$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_id_by_blend('pay_order_clearing_item_id');
//商家资金需要显示商品名称 //商家资金需要显示商品名称
if($account['pay_sub_type'] == 102) { if ($account['pay_sub_type'] == 102) {
$remark = $r['goods_name'] ?? ''; $remark = $r['goods_name'] ?? '';
if(mb_strlen($remark) > 100) { if (mb_strlen($remark) > 100) {
$remark = mb_substr($remark, 0, 100) . '...'; $remark = mb_substr($remark, 0, 100) . '...';
} }
if(!empty($r['clear_price'])) { if (!empty($r['clear_price'])) {
$clear_payment = $r['goods_num'] * $r['clear_price']; $clear_payment = $r['goods_num'] * $r['clear_price'];
} else { } else {
$clear_payment = 0; $clear_payment = 0;
...@@ -793,44 +796,62 @@ class PayService ...@@ -793,44 +796,62 @@ class PayService
} }
} }
private function gen_pay_order_id($user_id) // private function gen_pay_order_id($user_id)
{ // {
$number = substr($user_id, -2); // $number = substr($user_id, -2);
$ids = $this->get_idgen_id($number, 1); // $ids = $this->get_idgen_id($number, 1);
return array_pop($ids); // return array_pop($ids);
} // }
private function gen_pay_order_item_id() // private function gen_pay_order_item_id()
// {
// $number = substr($this->order_info['user_id'], -2);
// $ids = $this->get_idgen_id($number, 1);
// return array_pop($ids);
// }
private function gen_id_by_blend($type)
{ {
$number = substr($this->order_info['user_id'], -2); $params = [
$ids = $this->get_idgen_id($number, 1); 'type' => 'bp_' . $type,
return array_pop($ids); ];
} $url = config('interface', 'bp.id.blend');
if (empty($url)) {
private function gen_pay_order_clearing_id() FileLog::error("interface", sprintf("%s 接口配置不存在", 'bp.id.blend'));
{ }
$number = substr($this->order_info['user_id'], -2); $res = (new Request())->post($url, $params);
$ids = $this->get_idgen_id($number, 1); if (!empty($res) && !empty($res['response']) && $res['response']['code'] == 0) {
return array_pop($ids); return $res['response']['reason'];
} } else {
FileLog::error("interface", sprintf("%s 接口调用失败", 'bp.id.blend'));
private function gen_pay_order_clearing_item_id() return -1;
{ }
$number = substr($this->order_info['user_id'], -2);
$ids = $this->get_idgen_id($number, 1);
return array_pop($ids);
} }
private function get_idgen_id($number, $count = 1) // private function gen_pay_order_clearing_id()
{ // {
$number = intval($number); // $number = substr($this->order_info['user_id'], -2);
$res = Idgen::get(appConfig('idgen.partner'), appConfig('idgen.key'), [], [[ // $ids = $this->get_idgen_id($number, 1);
"type" => "55c768", // return array_pop($ids);
'number' => $number, // }
"count" => $count]]); //
$id = $res['id_datetime']['55c768'] ?? []; // private function gen_pay_order_clearing_item_id()
return $id; // {
} // $number = substr($this->order_info['user_id'], -2);
// $ids = $this->get_idgen_id($number, 1);
// return array_pop($ids);
// }
// private function get_idgen_id($number, $count = 1)
// {
// $number = intval($number);
// $res = Idgen::get(appConfig('idgen.partner'), appConfig('idgen.key'), [], [[
// "type" => "55c768",
// 'number' => $number,
// "count" => $count]]);
// $id = $res['id_datetime']['55c768'] ?? [];
// return $id;
// }
private function get_life_account($life_account_id) private function get_life_account($life_account_id)
{ {
...@@ -842,25 +863,27 @@ class PayService ...@@ -842,25 +863,27 @@ class PayService
return Sdk::call($url, $params); return Sdk::call($url, $params);
} }
private function getChannel($pay_method_id) { private function getChannel($pay_method_id)
{
$maps = [ $maps = [
105=>"wx", //微信 App 支付 105 => "wx", //微信 App 支付
106=>"alipay", //支付宝 106 => "alipay", //支付宝
107=>"wx_pub", //微信 JSAPI 支付 107 => "wx_pub", //微信 JSAPI 支付
108=>"wx_pub_qr", //微信 Native 支付 108 => "wx_pub_qr", //微信 Native 支付
109=>"wx_wap", //微信 H5 支付 109 => "wx_wap", //微信 H5 支付
110=>"wx_lite", //微信小程序支付 110 => "wx_lite", //微信小程序支付
]; ];
if(!empty($maps[$pay_method_id])) { if (!empty($maps[$pay_method_id])) {
return $maps[$pay_method_id]; return $maps[$pay_method_id];
} else { } else {
return $maps[105]; return $maps[105];
} }
} }
private function getNextTime($times = 0) { private function getNextTime($times = 0)
{
return time() + pow(3, $times + 1); return time() + pow(3, $times + 1);
} }
} }
\ 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