Commit 9fb73e35 authored by wanjilong's avatar wanjilong

add: 梳理报错信息及文案

parent ac188e65
......@@ -13,5 +13,7 @@ class FundsException extends BaseException
protected $cus = [
0 => '系统异常请联系管理员',
1 => '缺少渠道平台账户配置,请联系管理员!',
2 => 'Funds日志已经存在,请勿重复操作!',
3 => '营销账户不存在,请联系管理员!',
];
}
......@@ -18,23 +18,24 @@ class PayException extends BaseException
4 => '请确认订单信息及用户是否一致。',
5 => '订单缺少过期时间,请联系管理员',
6 => '订单过期,不允许支付',
7 => '支付订单创建失败,请管理员关注',
8 => '订单已经支付,请勿重复支付',
9 => '获取商户账户ID失败,请联系管理员',
10 => '回调失败,支付订单不存在',
11 => '回调失败,支付金额错误',
12 => '订单服务优惠信息错误',
13 => '订单明细保存失败',
10 => '未支付订单不允许核销,请管理员关注',
11 => '商家仅允许核销自己的订单,请管理员关注',
12 => '支付订单预结算失败,结算资金不能负数,请核对配置',
14 => '订单缺少商品信息,请联系管理员',
15 => '订单存在过期商品,不能支付',
18 => '订单不存在,请重试',
7 => '支付订单创建失败,请重试',
8 => '支付子订单创建失败,请重试',
9 => '订单优惠信息保存失败,请重试',
10 => '营销补贴锁定失败,请重试',
11 => '订单已支付,请勿重复支付',
12 => '支付订单不存在,请管理员关注',
13 => '支付回调金额不符,请管理员关注',
14 => '支付清分失败,结算资金为负',
15 => '支付回调资金入账失败,请管理员关注',
16 => '支付回调营销扣款失败,请管理员关注',
17 => '保存清分记录失败,请管理员关注',
18 => '保存清分明细记录失败,请管理员关注',
19 => '支付子单不存在,请管理员关注',
20 => '待核销子单处理中,请勿重复提交',
21 => '保存核销单失败,请重试',
22 => '保存核销子单失败,请重试',
23 => '保存核销结算失败,请重试',
24 => '更新子单结算状态失败,请管理员关注',
100=>'支付渠道错误,暂不支持该渠道',
101=>'该订单已经支付,请稍后刷新',
......
......@@ -16,11 +16,13 @@ class RefundException extends BaseException
2 => '订单未支付或不存在,请核对。',
3 => '不存在满足条件的退款订单。',
4 => '退单保存失败,请联系管理员。',
5 => '订单退款回调处理失败,请核对。',
6 => 'pingxx退单缺少matadata!',
7 => 'pingxx未支付订单不允许退款。',
8 => 'pingxx订单可能存在多次成功支付,需人工确认处理。',
5 => '退单子单保存失败,请联系管理员。',
6 => '支付子单状态更新失败,请联系管理员。',
7 => '退单保存失败,请联系管理员。',
8 => '退单更新失败,请联系管理员。',
9 => '保存退款结算信息失败,请重试',
10 => 'pingxx未支付订单不允许退款。',
11 => 'pingxx订单可能存在多次成功支付,需人工确认处理。',
];
}
......@@ -70,11 +70,18 @@ class OrderController extends Base
public function write_offAction() {
$params = $this->params;
$life_account_id = $params['life_account_id'];
$order_item_id = $params['order_item_id'];
$order_id = $params['order_id'];
if(!empty($params['order_item_id'])) {
if(!is_array($params['order_item_id'])) {
$params['order_item_id'] = explode(',', $params['order_item_id']);
}
} else {
$params['order_item_id'] = [];
}
$refundSrv = new PayService();
$ret = $refundSrv->write_off($order_item_id, $life_account_id);
$ret = $refundSrv->write_off($order_id, $params['order_item_id']);
$this->success(['result'=>$ret]);
}
......
......@@ -4,6 +4,7 @@
namespace App\Services\marketing;
use App\Exception\custom\FundsException;
use App\Models\order\mysql\MarketingAccount;
use App\Models\order\mysql\MarketingAccountLog;
use App\Models\order\mysql\MarketingAccountMap;
......@@ -23,7 +24,6 @@ class AccountService
$coupon = self::formatData($list);
$cnt = true;
foreach ($coupon as $id=>$amount) {
$marketing_account_id = self::map($id);
......@@ -182,6 +182,10 @@ class AccountService
}
}
if(empty(self::$maps[$third_id])) {
throw new FundsException(['cus'=>3]);
}
return self::$maps[$third_id];
}
......
......@@ -25,6 +25,11 @@ class FundsService
throw new FundsException(['cus' => 1]);
}
$log = PlatformFundsLog::getMaster('*', ['trade_id'=>$data['trade_id']]);
if($log) {
throw new FundsException(['cus' => 2]);
}
$cnt = PlatformFunds::update([
'total_amount[+]'=>$data['amount'],
'total_tip[+]'=>$data['tip'],
......@@ -58,6 +63,11 @@ class FundsService
throw new FundsException(['cus'=>1]);
}
$log = PlatformFundsLog::getMaster('*', ['trade_id'=>$data['trade_id']]);
if($log) {
throw new FundsException(['cus' => 2]);
}
$cnt = true;
$cnt = $cnt && PlatformFunds::update([
'total_amount[-]'=>$data['amount'],
......@@ -66,8 +76,8 @@ class FundsService
$cnt = $cnt && PlatformFundsLog::insert([
'platform_funds_id'=>$info['platform_funds_id'],
'trade_id'=>$data['order_id'],
'third_order_id'=>$data['third_id'],
'trade_id'=>$data['trade_id'],
'third_order_id'=>$data['third_order_id'],
'fund_type'=>2,
'amount'=>$data['amount'],
'tip'=>$data['tip'],
......
......@@ -102,6 +102,7 @@ class PayService
$ids = $this->get_idgen_id($order["user_id"], 1 + count($data['order_item_list']));
$pay_order_id = array_shift($ids);
try{
PayOrder::beginTransaction();
$pay = PayOrder::getMaster('*', ['order_id'=>$order['order_id']]);
if(!empty($pay)) {
......@@ -137,6 +138,9 @@ class PayService
$cnt = true;
$cnt = $cnt && PayOrder::insert($new_pay, ['rowCount'=>true]);
if($cnt == false) {
throw new PayException(['cus'=>7]);
}
$order_items = $coupon_items = [];
foreach ($data['order_item_list'] as $r) {
......@@ -162,6 +166,9 @@ class PayService
//新增订单子单
$cnt = $cnt && PayOrderItem::insert($order_items, ['rowCount'=>true]);
if($cnt == false) {
throw new PayException(['cus'=>8]);
}
if(!empty($data['order_share_coupon'])) {
foreach ($data['order_share_coupon'] as $r) {
......@@ -179,19 +186,28 @@ class PayService
//新增订单优惠信息
$cnt = $cnt && PayCouponItem::insert($coupon_items, ['rowCount'=>true]);
if($cnt == false) {
throw new PayException(['cus'=>9]);
}
//营销资金冻结
$cnt = $cnt && AccountService::frozen($data['order_share_coupon'], $order['order_id']);
if($cnt == false) {
throw new PayException(['cus'=>10]);
}
}
if($cnt == true) {
$pay = $new_pay;
PayOrder::commit();
} else {
}catch (BaseException $e) {
PayOrder::rollback();
throw new PayException(['cus' => 7]);
throw $e;
}catch (\Exception $e) {
PayOrder::rollback();
throw new BaseException(['msg'=>$e->getMessage(), 'code'=>2031]);
}
return $pay;
}
......@@ -210,7 +226,7 @@ class PayService
// 创建支付订单、营销冻结
$pay_order = $this->make_pay_order($data, $params['pay_method_id']);
if ($pay_order['pay_order_status'] == 2) {
throw new PayException(['cus' => 8]);
throw new PayException(['cus' => 11]);
}
// 支付金额0,系统支付
......@@ -290,10 +306,10 @@ class PayService
$pay_order_id = $object['order_no'];
$pay_order = PayOrder::get('*', ['pay_order_id' => $pay_order_id]);
if (empty($pay_order)) {
throw new PayException(['cus' => 7]);
throw new PayException(['cus' => 12]);
}
if($pay_order['pay_amount'] != $object['amount']) {
throw new PayException(['cus' => 8]);
throw new PayException(['cus' => 13]);
}
// 修改状态,锁定业务
......@@ -358,7 +374,7 @@ class PayService
$pay_order = PayOrder::get('*', ['order_id'=>$order_id]);
if(empty($pay_order)) {
throw new PayException(['cus' => 18]);
throw new PayException(['cus' => 12]);
}
$data = [
......@@ -413,72 +429,85 @@ class PayService
* @throws BaseException
* @throws \App\Exception\custom\CodeSpecialException
*/
public function write_off($order_id, $life_account_id, $order_item_ids = [] )
public function write_off($order_id, $order_item_ids = [] )
{
try{
PayOrderItem::beginTransaction();
$pay_order = PayOrder::getMaster('*', ['order_id'=>$order_id]);
if(empty($pay_order) || $pay_order['life_account_id'] != $life_account_id) {
throw new PayException(['cus'=>14]);
if(empty($pay_order)) {
throw new PayException(['cus'=>12]);
}
$list = PayOrderItem::getMaster('*', ['pay_order_id' => $pay_order['pay_order_id']]);
$list = PayOrderItem::selectMaster('*', ['pay_order_id' => $pay_order['pay_order_id']]);
if(empty($list)) {
throw new PayException(['cus'=>15]);
throw new PayException(['cus'=>19]);
}
$item_ids = [];
$exists = $item_ids = [];
foreach ($list as $item) {
if(!empty($order_item_ids) && !in_array($item['order_item_id'], $order_item_ids)) {
continue; //部分核销,且不再核销子单列表,不处理
}
if(in_array($item['refund_order_status'], [1, 2])) {
continue; //退款中、已退款不允许再次申请
}
if($item['can_notify_account'] == 1) {
$exists[] = $item['order_item_id'];
continue; //已结算不允许再次核销
}
if(!empty($order_item_ids) && !in_array($item['order_item_id'], $order_item_ids)) {
continue; //部分核销,且不再核销子单列表,不处理
}
$item_ids[] = $item['order_item_id'];
}
if(empty($item_ids)) {
throw new PayException(['cus'=>16]);
throw new PayException(['cus'=>20]);
}
$ids = $this->gen_pay_order_id($life_account_id, count($list) + 5);
$write_off_order_id = array_shift($ids);
$ids = $this->get_idgen_id($pay_order['user_id'], count($list) + 5);
$writeOff_order_id = array_shift($ids);
//统计平台、团长、商户金额
$cnt = true;
$cnt = $cnt && WriteOffOrder::insert([
'write_off_order_id'=>$write_off_order_id,
'writeoff_order_id'=>$writeOff_order_id,
'user_id'=>$pay_order['user_id'],
'order_id'=>$pay_order['order_id'],
'write_off_status'=>0,
'writeoff_status'=>0,
], ['rowCount' => true]);
if($cnt == false) {
throw new PayException(['cus'=>21]);
}
$items = [];
foreach ($item_ids as $_id) {
$items[] = [
'writeoff_order_item_id'=>array_shift($ids),
'writeoff_order_id'=>$write_off_order_id,
'writeoff_order_id'=>$writeOff_order_id,
'order_item_id'=>$_id,
];
}
$cnt = $cnt && WriteOffOrderItem::insert($items, ['rowCount' => true]);
if($cnt == false) {
throw new PayException(['cus'=>22]);
}
$cnt = $cnt && $this->write_off_clear_record($writeOff_order_id, $pay_order, $item_ids);
if($cnt == false) {
throw new PayException(['cus'=>23]);
}
$cnt = $cnt && $this->write_off_clear_record($write_off_order_id, $pay_order, $item_ids);
$cnt = $cnt && PayOrderItem::update([
PayOrderItem::update([
'notify_account_status' => 0,
'can_notify_account' => 1,
'can_notify_account_time' => date('Y-m-d H:i:s'),
], ['order_item_id' => $item_ids, 'can_notify_account'=>0, 'refund_order_status'=>0]);
if($cnt == false) {
throw new PayException(['cus'=>17]);
$err = PayOrderItem::getMaster('*', ['order_item_id' => $item_ids, 'can_notify_account'=>0, 'refund_order_status'=>0]);
if($err) {
throw new PayException(['cus'=>24]);
}
PayOrderItem::commit();
}catch (PayException $e) {
PayOrderItem::rollback();
......@@ -489,12 +518,13 @@ class PayService
throw new BaseException(['msg'=>$e->getMessage(), 'code'=>$e->getCode()]);
}
$this->sync_account_wallet($write_off_order_id);
$this->sync_account_wallet($writeOff_order_id);
return [
'write_off_order_id'=>$write_off_order_id,
'writeoff_order_id'=>$writeOff_order_id,
'order_id'=>$order_id,
'order_item_id' => $item_ids
'order_item_id' => $item_ids,
'exists' => $exists,
];
}
......@@ -505,16 +535,16 @@ class PayService
public function sync_account_wallet($writeOff_order_id) {
$p_cnt = $u_cnt = $m_cnt = true;
/*
//修改状态为执行中
$cnt = WriteOffOrder::update([
'notify_account_status'=>1,
], ['write_off_order_id'=>$writeOff_order_id, 'write_off_status' => 2, 'notify_account_status'=>0]);
], ['writeoff_order_id'=>$writeOff_order_id, 'writeoff_status' => 2, 'notify_account_status'=>0]);
if(!$cnt) {//乐观锁,不满足条件不处理
return true;
}
*/
//平台收入入账
$p = WriteOffPlatformRecord::selectMaster('*',
['writeoff_order_id'=>$writeOff_order_id, 'notify_account_status[<]'=>2]);
......@@ -538,7 +568,7 @@ class PayService
'source_name' => 1,
'amount' => $u['payment'],
'third_order_id' => $u['writeoff_personal_id'],
'third_order_id_type' => 406,
'third_order_id_type' => 105,
'third_order_desc' => '',
];
}
......@@ -555,7 +585,7 @@ class PayService
}
}
//商家收益 407
//商家收益
$m = WriteOffMerchantRecord::selectMaster('*',
['writeoff_order_id'=>$writeOff_order_id, 'notify_account_status[<]'=>2]);
if($m) {
......@@ -565,7 +595,7 @@ class PayService
'shop_id'=>$m['shop_id'],
'source_name'=>$m['source_name'],
'service_name'=>$m['service_name'],
'write_off_order_id'=>$m['write_off_order_id'],
'writeoff_order_id'=>$m['writeoff_order_id'],
'third_order_title'=>$m['title'],
'third_order_desc'=>$m['desc'],
'third_order_type'=>$m['business_from'],
......@@ -612,11 +642,11 @@ class PayService
$d = $m = $p = [];
foreach ($clear_items as $r) {
if($r['pay_sub_type'] == 404) { // 团长佣金收入
if($r['pay_sub_type'] == 105) { // 团长佣金收入
if(!isset($d[$r['account_id']])) {
$d[$r['account_id']] = [
'writeoff_merchant_id'=>array_shift($this->gen_ids),
'writeOff_order_id'=>$writeOff_order_id,
'writeoff_personal_id'=>array_shift($this->gen_ids),
'writeoff_order_id'=>$writeOff_order_id,
'pay_order_id'=>$r['pay_order_id'],
'order_id'=>$r['order_id'],
'user_id'=>$r['account_id'],
......@@ -625,11 +655,11 @@ class PayService
}
$d[$r['account_id']]['payment'] += $r['pay_amount'];
} elseif ($r['pay_sub_type'] == 405 || $r['pay_sub_type'] == 408) { // 平台抽成
} elseif ($r['pay_sub_type'] == 101 || $r['pay_sub_type'] == 108) { // 平台抽成
if(!isset($p[$r['account_id']])) {
$p[$r['account_id']] = [
'refund_platform_id'=>array_shift($this->gen_ids),
'refund_order_id'=>$writeOff_order_id,
'writeoff_platform_id'=>array_shift($this->gen_ids),
'writeoff_order_id'=>$writeOff_order_id,
'pay_order_id'=>$r['pay_order_id'],
'order_id'=>$r['order_id'],
'account_id'=>$r['account_id'],
......@@ -638,14 +668,15 @@ class PayService
}
$p[$r['account_id']]['payment'] += $r['pay_amount'];
} elseif ($r['pay_sub_type'] == 407) { // 商品交易
$key = $r['life_account_id'] . '_' . $r['shop_id'];
} elseif ($r['pay_sub_type'] == 102) { // 商品交易
$key = $r['account_id'];
if(!isset($m[$key])) {
$m[$key] = [
'writeoff_merchant_id'=>array_shift($this->gen_ids),
'writeoff_order_id'=>$writeOff_order_id,
'pay_order_id'=>$r['pay_order_id'],
'order_id'=>$r['order_id'],
'account_id'=>$r['account_id'],
'life_account_id'=>$pay_order['life_account_id'],
'shop_id'=>$pay_order['shop_id'],
'source_name'=>$pay_order['source_name'],
......@@ -720,7 +751,7 @@ class PayService
'platform_tip'=>$platform['amount'],
'merchant_cash'=>$merchant_cash,
]));
throw new PayException(['cus'=>12]);
throw new PayException(['cus'=>14]);
}
$this->make_merchant_clearing($merchant_cash, $platform); //商户收益
......@@ -736,13 +767,22 @@ class PayService
'amount'=>$this->pay_order['pay_amount'],
'tip'=>$wx_tip,
], 1);
if($cnt == false) {
throw new PayException(['cus'=>15]);
}
//营销扣款
$cnt = $cnt && AccountService::pay($coupon_items, $this->pay_order['order_id']);
if($cnt == false) {
throw new PayException(['cus'=>16]);
}
$cnt = $cnt && PayOrderClearing::insert($this->clear_list, ['rowCount' => true]);
if($cnt == false) {
throw new PayException(['cus'=>17]);
}
$cnt = $cnt && PayOrderClearingItem::insert($this->clear_items_list, ['rowCount' => true]);
if ($cnt == false) {
throw new PayException(['cus' => 0]);
if($cnt == false) {
throw new PayException(['cus'=>18]);
}
PayOrderClearing::commit();
} catch (\Exception $e) {
......@@ -777,7 +817,7 @@ class PayService
$account['account_type'] = 4; //三方手续费 + 平台总帐
$account['pay_type'] = 2; //支付
$account['pay_sub_type'] = 406; //第三方渠道手续费
$account['pay_sub_type'] = 107; //第三方渠道手续费
$this->clear_list[] = [
'pay_order_clearing_id' => array_shift($this->gen_ids),
......@@ -807,7 +847,7 @@ class PayService
$account['account_type'] = 3; //平台(平台收入+平台补贴)
$account['pay_type'] = 2; //支付
$account['pay_sub_type'] = 405; //平台抽成
$account['pay_sub_type'] = 101; //平台抽成
$total_amount = $this->pay_order['pay_amount']; //订单支付总价格
$cleared_amount = 0; //已经结算记录
......@@ -822,7 +862,7 @@ class PayService
'account_type' => 3,
'pay_amount' => $account['amount'],
'pay_type' => 2,
'pay_sub_type' => 405,
'pay_sub_type' => 101,
];
foreach ($this->order_items as $r) {
......@@ -839,7 +879,7 @@ class PayService
'pay_amount' => $current_tip,
'clear_payment' => 0, //商品结算价格
'pay_type' => 2,
'pay_sub_type' => 405,
'pay_sub_type' => 101,
'remark' => '',
];
......@@ -911,7 +951,7 @@ class PayService
'account_type' => 1,
'pay_amount' => 0,
'pay_type' => 1,
'pay_sub_type' => 404,
'pay_sub_type' => 105,
];
}
$maps[$u['user_id']]['pay_amount'] += $u['amount'];
......@@ -927,7 +967,7 @@ class PayService
'pay_amount' => $u['amount'],
'clear_payment' => 0, //商品结算价格
'pay_type' => 1, //收入
'pay_sub_type' => 404, //团长佣金收入
'pay_sub_type' => 105, //团长佣金收入
'remark' => '',
];
$total_tip += $u['amount'];
......@@ -953,12 +993,12 @@ class PayService
$merchant['account_id'] = $m['account_id']; //商户
$merchant['account_type'] = 2; //商户
$merchant['pay_type'] = 1; //收入
$merchant['pay_sub_type'] = 407; //商品交易102
$merchant['pay_sub_type'] = 102; //商品交易102
$merchant['amount'] = 0;
$platform['account_type'] = 3;
$platform['pay_type'] = 1;
$platform['pay_sub_type'] = 408; //平台抽成(结算价);
$platform['pay_sub_type'] = 108; //平台抽成(结算价);
$platform['amount'] = 0;
$m_clearing_id = array_shift($this->gen_ids); //商家清分ID
......@@ -1009,8 +1049,6 @@ class PayService
'remark' => '',
];
$pay_amount = $clear_payment;
} else{}
$this->clear_items_list[] = [
......@@ -1027,7 +1065,9 @@ class PayService
'pay_sub_type' => $merchant['pay_sub_type'],
'remark' => $remark,
];
$merchant['amount'] += $clear_payment;
//收集金额用于分拆计算
$cleared_amount += $r['payment'];
$cleared_tip += $current_tip;
}
......
......@@ -53,6 +53,7 @@ class RefundService
try{
$payer = Channel::getChannel($data['pay_order']['pay_channel']);
$ret = $payer->refund($data, $mata_data);
//$ret['data'] = 'ok';
if(!empty($ret["data"])) {
$edit = ['request_pingxx_success_time'=>date('Y-m-d H:i:s')];
RefundOrder::update($edit, ['refund_order_id'=>$data['refund_order']['refund_order_id']]);
......@@ -119,6 +120,7 @@ class RefundService
// 修改状态,锁定业务
$refund_order_id = $object['metadata']['refund_order_id'];
try{
RefundOrder::beginTransaction();
$refund = RefundOrder::getMaster('*', ['refund_order_id'=>$refund_order_id]);
......@@ -137,27 +139,40 @@ class RefundService
'amount'=>$refund['refund_amount'],
'tip'=>$refund['refund_wx_tip'],
], 1);
if($cnt == false) {
throw new RefundException(['cus'=>7]);
}
$edit = [
'refund_order_status'=>2, //pingxx回调成功,
'pingxx_callback_success_time'=>date('Y-m-d H:i:s'), //回调成功时间
];
$cnt = $cnt && RefundOrder::update($edit, ['refund_order_id'=>$refund_order_id, 'refund_order_status'=>1]);
if($cnt == false) {
throw new RefundException(['cus'=>8]);
}
$cnt = $cnt && PayOrderItem::update(['refund_order_status'=>2], [
'order_item_id'=>$object['metadata']['order_item_id']
]);
if($cnt == false) {
throw new RefundException(['cus'=>6]);
}
$cnt = $cnt && $this->refund_clear_record($refund, $object['metadata']['order_item_id']);
if($cnt == false) {
throw new RefundException(['cus'=>9]);
}
if($cnt) {
RefundOrder::commit();
return ['refund_order_id'=>$refund_order_id];
} else {
}catch (BaseException $e) {
RefundOrder::rollback();
throw $e;
}catch (\Exception $e) {
RefundOrder::rollback();
throw new RefundException(['cus' => 16]);
throw new BaseException(['msg'=>$e->getMessage(), 'code'=>2031]);
}
}
......@@ -175,7 +190,7 @@ class RefundService
$d = $m = $p = [];
foreach ($clear_items as $r) {
if($r['pay_sub_type'] == 404) { // 团长佣金收入
if($r['pay_sub_type'] == 105) { // 团长佣金收入
if(!isset($d[$r['account_id']])) {
$d[$r['account_id']] = [
'refund_personal_id'=>array_shift($ids),
......@@ -188,7 +203,7 @@ class RefundService
}
$d[$r['account_id']]['payment'] += $r['pay_amount'];
} elseif ($r['pay_sub_type'] == 405 || $r['pay_sub_type'] == 408) { // 平台抽成
} elseif ($r['pay_sub_type'] == 101 || $r['pay_sub_type'] == 108) { // 平台抽成
if(!isset($p[$r['account_id']])) {
$p[$r['account_id']] = [
'refund_platform_id'=>array_shift($ids),
......@@ -201,7 +216,7 @@ class RefundService
}
$p[$r['account_id']]['payment'] += $r['pay_amount'];
} elseif ($r['pay_sub_type'] == 407) { // 商品交易
} elseif ($r['pay_sub_type'] == 102) { // 商品交易
if(!isset($m[$r['account_id']])) {
$m[$r['account_id']] = [
'refund_merchant_id'=>array_shift($ids),
......@@ -252,20 +267,23 @@ class RefundService
throw new RefundException(['cus' => 2]);
}
$items = $exists = [];
$pay_order_items = PayOrderItem::selectMaster('*', ['pay_order_id'=>$pay_order['pay_order_id']]);
foreach ($pay_order_items as $item) {
if(!empty($order_item_ids) && !in_array($item['order_item_id'], $order_item_ids)) {
continue; //部分退款,且不再退款子单列表,不处理
}
if($item['can_notify_account'] == 1) {
continue; //已结算不允许退款
}
if(in_array($item['refund_order_status'], [1, 2])) {
$exists[] = $item['order_item_id'];
continue; //退款中、已退款不允许再次申请
}
if(!empty($order_item_ids) && !in_array($item['order_item_id'], $order_item_ids)) {
continue; //部分退款,且不再退款子单列表,不处理
}
$items[] = $item;
$refund_payment += $item['payment'];
}
......@@ -292,7 +310,7 @@ class RefundService
$wx_clear = PayOrderClearing::getMaster('*', [
'order_id'=>$pay_order['order_id'],
'pay_order_id'=>$pay_order['pay_order_id'],
'pay_sub_type'=>406 //三方渠道手续费
'pay_sub_type'=>106 //三方渠道手续费
]
);
$wx_total_tip = 0;
......@@ -326,25 +344,35 @@ class RefundService
$cnt = true;
$cnt = $cnt && RefundOrder::insert($refund, ['rowCount'=>true]);
$cnt = $cnt && RefundOrderItem::insert($refund_items, ['rowCount'=>true]);
$cnt = $cnt && PayOrderItem::update(['refund_order_status'=>1], ['order_item_id'=>array_column($items, 'order_item_id')]);
if($cnt == false) {
throw new RefundException(['cus' => 4]);
}
RefundOrder::commit();
$cnt = $cnt && RefundOrderItem::insert($refund_items, ['rowCount'=>true]);
if($cnt == false) {
throw new RefundException(['cus' => 5]);
}
}catch (\Exception $e) {
RefundOrder::rollback();
throw new BaseException(['msg'=>$e->getMessage(), 'code'=>$e->getCode()]);
$cnt = $cnt && PayOrderItem::update(['refund_order_status'=>1], ['order_item_id'=>array_column($items, 'order_item_id')]);
if($cnt == false) {
throw new RefundException(['cus' => 6]);
}
RefundOrder::commit();
return [
'refund_order'=>$refund,
'pay_order'=>$pay_order,
'order_item_id'=>array_column($items, 'order_item_id'),
'exists'=>$exists,
];
}catch (\Exception $e) {
RefundOrder::rollback();
throw new BaseException(['msg'=>$e->getMessage(), 'code'=>$e->getCode()]);
}
}
private function get_idgen_id($number, $count = 1)
......
......@@ -7,11 +7,10 @@ update pay_order set pay_discount = 0;
-- 核销/确认收货表
CREATE TABLE `write_off_order` (
`write_off_order_id` varchar(20) CHARACTER SET utf8 COLLATE utf8_general_ci NOT NULL DEFAULT '' COMMENT 'ID',
`writeoff_order_id` varchar(20) CHARACTER SET utf8 COLLATE utf8_general_ci NOT NULL DEFAULT '' COMMENT 'ID',
`user_id` bigint unsigned NOT NULL DEFAULT '0' COMMENT 'buyerId',
`order_id` varchar(30) CHARACTER SET utf8 COLLATE utf8_general_ci NOT NULL DEFAULT '' COMMENT '订单id',
`write_off_status` tinyint unsigned NOT NULL DEFAULT '0' COMMENT '核销状态,0 未核销, 1待确认 , 2 已核销',
`write_off_amount` int unsigned NOT NULL DEFAULT '0' COMMENT '核销金额,单位分',
`writeoff_status` tinyint unsigned NOT NULL DEFAULT '0' COMMENT '核销状态,0 未核销, 1待确认 , 2 已核销',
`notify_account_status` tinyint NOT NULL DEFAULT '0' COMMENT '通知账户系统状态,0未通知,1已通知',
`notify_account_success_time` timestamp NULL DEFAULT NULL COMMENT '通知账户系统成功时间',
`create_time` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP COMMENT '添加时间',
......
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