Commit 9fb73e35 authored by wanjilong's avatar wanjilong

add: 梳理报错信息及文案

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