Commit ac188e65 authored by wanjilong's avatar wanjilong

add: 订单支付、支付回调

parent d4916818
...@@ -14,7 +14,7 @@ class Code ...@@ -14,7 +14,7 @@ class Code
const PAY = 101000; const PAY = 101000;
const REFUND = 102000; const REFUND = 102000;
const ORDER = 103000; const ORDER = 103000;
const SDK = 104000; const SDK = 104000;
const FUNDS = 105000; const FUNDS = 105000;
const P_ACCOUNT = 106000; const P_ACCOUNT = 106000;
} }
\ No newline at end of file
...@@ -19,8 +19,8 @@ class PayException extends BaseException ...@@ -19,8 +19,8 @@ class PayException extends BaseException
5 => '订单缺少过期时间,请联系管理员', 5 => '订单缺少过期时间,请联系管理员',
6 => '订单过期,不允许支付', 6 => '订单过期,不允许支付',
7 => '支付订单创建失败,请管理员关注', 7 => '支付订单创建失败,请管理员关注',
8 => '支付订单创建失败,请管理员关注', 8 => '订单已经支付,请勿重复支付',
9 => '订单已经支付,请勿重复支付', 9 => '获取商户账户ID失败,请联系管理员',
10 => '回调失败,支付订单不存在', 10 => '回调失败,支付订单不存在',
11 => '回调失败,支付金额错误', 11 => '回调失败,支付金额错误',
...@@ -30,7 +30,7 @@ class PayException extends BaseException ...@@ -30,7 +30,7 @@ class PayException extends BaseException
10 => '未支付订单不允许核销,请管理员关注', 10 => '未支付订单不允许核销,请管理员关注',
11 => '商家仅允许核销自己的订单,请管理员关注', 11 => '商家仅允许核销自己的订单,请管理员关注',
12 => '支付订单预结算失败,结算资金不能负数,请核对配置', 12 => '支付订单预结算失败,结算资金不能负数,请核对配置',
13 => '生活号获取管理员ID失败,请联系管理员',
14 => '订单缺少商品信息,请联系管理员', 14 => '订单缺少商品信息,请联系管理员',
15 => '订单存在过期商品,不能支付', 15 => '订单存在过期商品,不能支付',
......
...@@ -6,5 +6,5 @@ use Api\PhpUtils\Mysql\MysqlBase; ...@@ -6,5 +6,5 @@ use Api\PhpUtils\Mysql\MysqlBase;
class CallbackLog extends MysqlBase class CallbackLog extends MysqlBase
{ {
const TABLE_NAME = 'callback_log'; const TABLE_NAME = 'callback_log';
const CONFIG_INDEX = 'pay_v2'; const CONFIG_INDEX = 'pay';
} }
...@@ -7,5 +7,5 @@ use App\Exception\custom\PayException; ...@@ -7,5 +7,5 @@ use App\Exception\custom\PayException;
class MarketingAccount extends MysqlBase class MarketingAccount extends MysqlBase
{ {
const TABLE_NAME = 'marketing_account'; const TABLE_NAME = 'marketing_account';
const CONFIG_INDEX = 'pay_v2'; const CONFIG_INDEX = 'pay';
} }
...@@ -6,5 +6,5 @@ use Api\PhpUtils\Mysql\MysqlBase; ...@@ -6,5 +6,5 @@ use Api\PhpUtils\Mysql\MysqlBase;
class MarketingAccountLog extends MysqlBase class MarketingAccountLog extends MysqlBase
{ {
const TABLE_NAME = 'marketing_account_log'; const TABLE_NAME = 'marketing_account_log';
const CONFIG_INDEX = 'pay_v2'; const CONFIG_INDEX = 'pay';
} }
...@@ -6,5 +6,5 @@ use Api\PhpUtils\Mysql\MysqlBase; ...@@ -6,5 +6,5 @@ use Api\PhpUtils\Mysql\MysqlBase;
class MarketingAccountMap extends MysqlBase class MarketingAccountMap extends MysqlBase
{ {
const TABLE_NAME = 'marketing_account_map'; const TABLE_NAME = 'marketing_account_map';
const CONFIG_INDEX = 'pay_v2'; const CONFIG_INDEX = 'pay';
} }
...@@ -7,5 +7,5 @@ use App\Exception\custom\PayException; ...@@ -7,5 +7,5 @@ use App\Exception\custom\PayException;
class PayCouponItem extends MysqlBase class PayCouponItem extends MysqlBase
{ {
const TABLE_NAME = 'pay_coupon_item'; const TABLE_NAME = 'pay_coupon_item';
const CONFIG_INDEX = 'pay_v2'; const CONFIG_INDEX = 'pay';
} }
...@@ -7,7 +7,7 @@ use App\Exception\custom\PayException; ...@@ -7,7 +7,7 @@ use App\Exception\custom\PayException;
class PayOrder extends MysqlBase class PayOrder extends MysqlBase
{ {
const TABLE_NAME = 'pay_order'; const TABLE_NAME = 'pay_order';
const CONFIG_INDEX = 'pay_v2'; const CONFIG_INDEX = 'pay';
/** /**
* @param $order_id * @param $order_id
......
...@@ -6,5 +6,5 @@ use Api\PhpUtils\Mysql\MysqlBase; ...@@ -6,5 +6,5 @@ use Api\PhpUtils\Mysql\MysqlBase;
class PayOrderClearing extends MysqlBase class PayOrderClearing extends MysqlBase
{ {
const TABLE_NAME = 'pay_order_clearing'; const TABLE_NAME = 'pay_order_clearing';
const CONFIG_INDEX = 'pay_v2'; const CONFIG_INDEX = 'pay';
} }
...@@ -7,7 +7,7 @@ use App\Exception\BaseException; ...@@ -7,7 +7,7 @@ use App\Exception\BaseException;
class PayOrderClearingItem extends MysqlBase class PayOrderClearingItem extends MysqlBase
{ {
const TABLE_NAME = 'pay_order_clearing_item'; const TABLE_NAME = 'pay_order_clearing_item';
const CONFIG_INDEX = 'pay_v2'; const CONFIG_INDEX = 'pay';
public static function marketSaleCount($accountId) { public static function marketSaleCount($accountId) {
......
...@@ -6,5 +6,5 @@ use Api\PhpUtils\Mysql\MysqlBase; ...@@ -6,5 +6,5 @@ use Api\PhpUtils\Mysql\MysqlBase;
class PayOrderItem extends MysqlBase class PayOrderItem extends MysqlBase
{ {
const TABLE_NAME = 'pay_order_item'; const TABLE_NAME = 'pay_order_item';
const CONFIG_INDEX = 'pay_v2'; const CONFIG_INDEX = 'pay';
} }
...@@ -7,5 +7,5 @@ use App\Exception\custom\PayException; ...@@ -7,5 +7,5 @@ use App\Exception\custom\PayException;
class PayOrderLog extends MysqlBase class PayOrderLog extends MysqlBase
{ {
const TABLE_NAME = 'pay_order_log'; const TABLE_NAME = 'pay_order_log';
const CONFIG_INDEX = 'pay_v2'; const CONFIG_INDEX = 'pay';
} }
...@@ -6,5 +6,5 @@ use Api\PhpUtils\Mysql\MysqlBase; ...@@ -6,5 +6,5 @@ use Api\PhpUtils\Mysql\MysqlBase;
class PlatformAccount extends MysqlBase class PlatformAccount extends MysqlBase
{ {
const TABLE_NAME = 'platform_account'; const TABLE_NAME = 'platform_account';
const CONFIG_INDEX = 'pay_v2'; const CONFIG_INDEX = 'pay';
} }
...@@ -6,5 +6,5 @@ use Api\PhpUtils\Mysql\MysqlBase; ...@@ -6,5 +6,5 @@ use Api\PhpUtils\Mysql\MysqlBase;
class PlatformAccountLog extends MysqlBase class PlatformAccountLog extends MysqlBase
{ {
const TABLE_NAME = 'platform_account_log'; const TABLE_NAME = 'platform_account_log';
const CONFIG_INDEX = 'pay_v2'; const CONFIG_INDEX = 'pay';
} }
...@@ -6,5 +6,5 @@ use Api\PhpUtils\Mysql\MysqlBase; ...@@ -6,5 +6,5 @@ use Api\PhpUtils\Mysql\MysqlBase;
class PlatformConfig extends MysqlBase class PlatformConfig extends MysqlBase
{ {
const TABLE_NAME = 'platform_config'; const TABLE_NAME = 'platform_config';
const CONFIG_INDEX = 'pay_v2'; const CONFIG_INDEX = 'pay';
} }
...@@ -6,5 +6,5 @@ use Api\PhpUtils\Mysql\MysqlBase; ...@@ -6,5 +6,5 @@ use Api\PhpUtils\Mysql\MysqlBase;
class PlatformFunds extends MysqlBase class PlatformFunds extends MysqlBase
{ {
const TABLE_NAME = 'platform_funds'; const TABLE_NAME = 'platform_funds';
const CONFIG_INDEX = 'pay_v2'; const CONFIG_INDEX = 'pay';
} }
...@@ -6,5 +6,5 @@ use Api\PhpUtils\Mysql\MysqlBase; ...@@ -6,5 +6,5 @@ use Api\PhpUtils\Mysql\MysqlBase;
class PlatformFundsLog extends MysqlBase class PlatformFundsLog extends MysqlBase
{ {
const TABLE_NAME = 'platform_funds_log'; const TABLE_NAME = 'platform_funds_log';
const CONFIG_INDEX = 'pay_v2'; const CONFIG_INDEX = 'pay';
} }
...@@ -6,5 +6,5 @@ use Api\PhpUtils\Mysql\MysqlBase; ...@@ -6,5 +6,5 @@ use Api\PhpUtils\Mysql\MysqlBase;
class RefundMerchantRecord extends MysqlBase class RefundMerchantRecord extends MysqlBase
{ {
const TABLE_NAME = 'refund_merchant_record'; const TABLE_NAME = 'refund_merchant_record';
const CONFIG_INDEX = 'pay_v2'; const CONFIG_INDEX = 'pay';
} }
...@@ -6,5 +6,5 @@ use Api\PhpUtils\Mysql\MysqlBase; ...@@ -6,5 +6,5 @@ use Api\PhpUtils\Mysql\MysqlBase;
class RefundOrder extends MysqlBase class RefundOrder extends MysqlBase
{ {
const TABLE_NAME = 'refund_order'; const TABLE_NAME = 'refund_order';
const CONFIG_INDEX = 'pay_v2'; const CONFIG_INDEX = 'pay';
} }
...@@ -6,5 +6,5 @@ use Api\PhpUtils\Mysql\MysqlBase; ...@@ -6,5 +6,5 @@ use Api\PhpUtils\Mysql\MysqlBase;
class RefundOrderItem extends MysqlBase class RefundOrderItem extends MysqlBase
{ {
const TABLE_NAME = 'refund_order_item'; const TABLE_NAME = 'refund_order_item';
const CONFIG_INDEX = 'pay_v2'; const CONFIG_INDEX = 'pay';
} }
...@@ -6,5 +6,5 @@ use Api\PhpUtils\Mysql\MysqlBase; ...@@ -6,5 +6,5 @@ use Api\PhpUtils\Mysql\MysqlBase;
class RefundPersonalRecord extends MysqlBase class RefundPersonalRecord extends MysqlBase
{ {
const TABLE_NAME = 'refund_personal_record'; const TABLE_NAME = 'refund_personal_record';
const CONFIG_INDEX = 'pay_v2'; const CONFIG_INDEX = 'pay';
} }
...@@ -6,5 +6,5 @@ use Api\PhpUtils\Mysql\MysqlBase; ...@@ -6,5 +6,5 @@ use Api\PhpUtils\Mysql\MysqlBase;
class RefundPlatformRecord extends MysqlBase class RefundPlatformRecord extends MysqlBase
{ {
const TABLE_NAME = 'refund_platform_record'; const TABLE_NAME = 'refund_platform_record';
const CONFIG_INDEX = 'pay_v2'; const CONFIG_INDEX = 'pay';
} }
...@@ -6,5 +6,5 @@ use Api\PhpUtils\Mysql\MysqlBase; ...@@ -6,5 +6,5 @@ use Api\PhpUtils\Mysql\MysqlBase;
class WriteOffMerchantRecord extends MysqlBase class WriteOffMerchantRecord extends MysqlBase
{ {
const TABLE_NAME = 'writeoff_merchant_record'; const TABLE_NAME = 'writeoff_merchant_record';
const CONFIG_INDEX = 'pay_v2'; const CONFIG_INDEX = 'pay';
} }
...@@ -6,5 +6,5 @@ use Api\PhpUtils\Mysql\MysqlBase; ...@@ -6,5 +6,5 @@ use Api\PhpUtils\Mysql\MysqlBase;
class WriteOffOrder extends MysqlBase class WriteOffOrder extends MysqlBase
{ {
const TABLE_NAME = 'writeoff_order'; const TABLE_NAME = 'writeoff_order';
const CONFIG_INDEX = 'pay_v2'; const CONFIG_INDEX = 'pay';
} }
...@@ -6,5 +6,5 @@ use Api\PhpUtils\Mysql\MysqlBase; ...@@ -6,5 +6,5 @@ use Api\PhpUtils\Mysql\MysqlBase;
class WriteOffOrderItem extends MysqlBase class WriteOffOrderItem extends MysqlBase
{ {
const TABLE_NAME = 'writeoff_order_item'; const TABLE_NAME = 'writeoff_order_item';
const CONFIG_INDEX = 'pay_v2'; const CONFIG_INDEX = 'pay';
} }
...@@ -6,5 +6,5 @@ use Api\PhpUtils\Mysql\MysqlBase; ...@@ -6,5 +6,5 @@ use Api\PhpUtils\Mysql\MysqlBase;
class WriteOffPersonalRecord extends MysqlBase class WriteOffPersonalRecord extends MysqlBase
{ {
const TABLE_NAME = 'writeoff_personal_record'; const TABLE_NAME = 'writeoff_personal_record';
const CONFIG_INDEX = 'pay_v2'; const CONFIG_INDEX = 'pay';
} }
...@@ -6,5 +6,5 @@ use Api\PhpUtils\Mysql\MysqlBase; ...@@ -6,5 +6,5 @@ use Api\PhpUtils\Mysql\MysqlBase;
class WriteOffPlatformRecord extends MysqlBase class WriteOffPlatformRecord extends MysqlBase
{ {
const TABLE_NAME = 'writeoff_platform_record'; const TABLE_NAME = 'writeoff_platform_record';
const CONFIG_INDEX = 'pay_v2'; const CONFIG_INDEX = 'pay';
} }
...@@ -16,10 +16,6 @@ class OrderController extends Base ...@@ -16,10 +16,6 @@ class OrderController extends Base
public function payAction() public function payAction()
{ {
$params = $this->params; $params = $this->params;
$user_id = $params['user_id'];
$order_id = $params['order_id'];
$pay_method_id = $params['pay_method_id'] ?? 106;
$extra = []; $extra = [];
if(!empty($params['extra'])) { if(!empty($params['extra'])) {
if(is_string($params['extra'])) { if(is_string($params['extra'])) {
...@@ -30,7 +26,7 @@ class OrderController extends Base ...@@ -30,7 +26,7 @@ class OrderController extends Base
} }
$paySrv = new PayService(); $paySrv = new PayService();
$ret = $paySrv->do_pay($order_id, $user_id, $pay_method_id, $extra); $ret = $paySrv->do_pay($params, $extra);
//兼容C端客户端支付,调整返回结构,ping++ 返回 order,原生:微信、支付宝返回charge //兼容C端客户端支付,调整返回结构,ping++ 返回 order,原生:微信、支付宝返回charge
$result = []; $result = [];
......
...@@ -11,13 +11,7 @@ use App\Exception\BaseException; ...@@ -11,13 +11,7 @@ use App\Exception\BaseException;
class Pingxx { class Pingxx {
/** public function makeOrder($pay_order, $mata_data) {
* @param $pay_order
* @param $mata_data
* 系统支付
*/
public function pay($pay_order, $mata_data, $extra = []) {
// 已经创建,需要查询返回
if(!empty($pay_order['third_order_id'])) { if(!empty($pay_order['third_order_id'])) {
$ret = PingxxService::getInstance()->getOrder($pay_order['third_order_id']); $ret = PingxxService::getInstance()->getOrder($pay_order['third_order_id']);
} else { } else {
...@@ -39,12 +33,21 @@ class Pingxx { ...@@ -39,12 +33,21 @@ class Pingxx {
} else { } else {
throw new PayException(['cus' => 103]); throw new PayException(['cus' => 103]);
} }
return $ret;
}
/**
* @param $pay_order
* @param $mata_data
* 系统支付
*/
public function pay($pay_order, $object, $extra = []) {
$channel_exist = false; $channel_exist = false;
$channel = $this->getChannel($pay_order['pay_channel']); $channel = $this->pay2Channel($pay_order['pay_channel']);
if(!empty($ret['charges']['data'])) { if(!empty($object['charges']['data'])) {
//是否存在 //是否存在
foreach ($ret['charges']['data'] as $ch) { foreach ($object['charges']['data'] as $ch) {
if($ch['channel'] == $channel) { if($ch['channel'] == $channel) {
$channel_exist = true; $channel_exist = true;
} }
...@@ -61,7 +64,7 @@ class Pingxx { ...@@ -61,7 +64,7 @@ class Pingxx {
'extra'=> $extra, 'extra'=> $extra,
]; ];
$pay = PingxxService::getInstance()->pay($ret['id'], $payment); $pay = PingxxService::getInstance()->pay($object['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']);
} }
...@@ -69,7 +72,7 @@ class Pingxx { ...@@ -69,7 +72,7 @@ class Pingxx {
return $pay; return $pay;
} else { } else {
return $ret; return $object;
} }
} }
...@@ -110,7 +113,7 @@ class Pingxx { ...@@ -110,7 +113,7 @@ class Pingxx {
return PingxxService::getInstance()->sendRefund($refund); return PingxxService::getInstance()->sendRefund($refund);
} }
private function getChannel($pay_method_id) { private function pay2Channel($pay_method_id) {
$maps = [ $maps = [
1=>"syt", //系统余额支付 1=>"syt", //系统余额支付
...@@ -149,7 +152,7 @@ class Pingxx { ...@@ -149,7 +152,7 @@ class Pingxx {
throw new PayException(['cus'=>104]); throw new PayException(['cus'=>104]);
} }
$float_tip = $info['rate'] * $pay_order['payment'] / 10000; $float_tip = $info['rate'] * $pay_order['pay_amount'] / 10000;
if($float_tip >= 1 ) { if($float_tip >= 1 ) {
$total_tip = round($float_tip); $total_tip = round($float_tip);
...@@ -178,15 +181,10 @@ class Pingxx { ...@@ -178,15 +181,10 @@ class Pingxx {
$float_tip = $info['rate'] * $pay_order['total_price'] / 10000; $float_tip = $info['rate'] * $pay_order['total_price'] / 10000;
$total_tip = round($float_tip); $total_tip = round($float_tip);
if($float_tip >= 1) { return [
return [ 'account_id' => $info['account_id'],
'account_id' => $info['account_id'], 'amount' => $total_tip,
'amount' => $total_tip, ];
];
} else {
return [];
}
} }
public function getFundsInfo($pay_order) { public function getFundsInfo($pay_order) {
......
...@@ -22,7 +22,7 @@ class FundsService ...@@ -22,7 +22,7 @@ class FundsService
$info = PlatformFunds::getMaster('*', $info = PlatformFunds::getMaster('*',
['channel'=>$channel, 'source_name'=>$source_name, 'service_name'=>$service_name]); ['channel'=>$channel, 'source_name'=>$source_name, 'service_name'=>$service_name]);
if(empty($info)) { if(empty($info)) {
throw new FundsException(['cus'=>1]); throw new FundsException(['cus' => 1]);
} }
$cnt = PlatformFunds::update([ $cnt = PlatformFunds::update([
...@@ -32,8 +32,8 @@ class FundsService ...@@ -32,8 +32,8 @@ class FundsService
$l_cnt = PlatformFundsLog::insert([ $l_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'=>1, 'fund_type'=>1,
'amount'=>$data['amount'], 'amount'=>$data['amount'],
'tip'=>$data['tip'], 'tip'=>$data['tip'],
......
...@@ -52,11 +52,11 @@ class PayService ...@@ -52,11 +52,11 @@ class PayService
*/ */
private function pay_validate($params) { private function pay_validate($params) {
if($params['order_id']) { if(empty($params['order_id'])) {
throw new PayException(['cus' => 1]); throw new PayException(['cus' => 1]);
} }
if($params['user_id']) { if(empty($params['user_id'])) {
throw new PayException(['cus' => 2]); throw new PayException(['cus' => 2]);
} }
...@@ -103,7 +103,7 @@ class PayService ...@@ -103,7 +103,7 @@ class PayService
$pay_order_id = array_shift($ids); $pay_order_id = array_shift($ids);
PayOrder::beginTransaction(); PayOrder::beginTransaction();
$pay = self::getMaster('*', ['order_id'=>$order['order_id']]); $pay = PayOrder::getMaster('*', ['order_id'=>$order['order_id']]);
if(!empty($pay)) { if(!empty($pay)) {
//更新支付渠道 //更新支付渠道
if($pay['pay_order_status'] == 0) { if($pay['pay_order_status'] == 0) {
...@@ -124,7 +124,7 @@ class PayService ...@@ -124,7 +124,7 @@ class PayService
'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'],
'discount_fee' => $order['discount_fee'], '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' => '',
...@@ -146,6 +146,15 @@ class PayService ...@@ -146,6 +146,15 @@ class PayService
'order_id'=>$r['order_id'], 'order_id'=>$r['order_id'],
'order_item_id'=>$r['order_item_id'], 'order_item_id'=>$r['order_item_id'],
'user_id'=>$r['user_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'], 'payment'=>$r['payment'],
'share_coupon'=>$r['share_coupon'], 'share_coupon'=>$r['share_coupon'],
]; ];
...@@ -234,11 +243,13 @@ class PayService ...@@ -234,11 +243,13 @@ class PayService
try{ try{
$payer = Channel::getChannel($params['pay_method_id']); $payer = Channel::getChannel($params['pay_method_id']);
$ret = $payer->pay($pay_order, $meta_data, $extra); $ret = $payer->makeOrder($pay_order, $meta_data);
PayOrder::update(['pay_order_status'=>1], PayOrder::update(['pay_order_status'=>1, 'third_order_id'=>$ret['id']],
['pay_order_id'=>$pay_order['pay_order_id'], 'pay_order_status'=>0]); ['pay_order_id'=>$pay_order['pay_order_id'], 'pay_order_status'=>0]);
$response = $payer->pay($pay_order, $ret, $extra);
}catch (BaseException $e) { }catch (BaseException $e) {
throw $e; throw $e;
...@@ -246,7 +257,7 @@ class PayService ...@@ -246,7 +257,7 @@ class PayService
throw new BaseException(['msg'=>$e->getMessage(), 'code'=>'2301']); throw new BaseException(['msg'=>$e->getMessage(), 'code'=>'2301']);
} }
return $ret; return $response;
} }
/** /**
...@@ -694,7 +705,7 @@ class PayService ...@@ -694,7 +705,7 @@ class PayService
$wx_tip = $this->make_tip_clearing($payer); //渠道手续费 $wx_tip = $this->make_tip_clearing($payer); //渠道手续费
$distribution_tip = $this->make_distribution_clearing(); //团长收益 $distribution_tip = $this->make_distribution_clearing(); //团长收益
$platform = $this->make_platform_clearing(); //平台收益 $platform = $this->make_platform_clearing($payer); //平台收益
$merchant_cash = $this->pay_order['pay_amount'] + $this->pay_order['pay_discount'] - $wx_tip - $distribution_tip - $platform['amount']; $merchant_cash = $this->pay_order['pay_amount'] + $this->pay_order['pay_discount'] - $wx_tip - $distribution_tip - $platform['amount'];
...@@ -712,7 +723,7 @@ class PayService ...@@ -712,7 +723,7 @@ class PayService
throw new PayException(['cus'=>12]); throw new PayException(['cus'=>12]);
} }
$this->make_merchant_clearing($merchant_cash); //商户收益 $this->make_merchant_clearing($merchant_cash, $platform); //商户收益
try { try {
$cnt = true; $cnt = true;
...@@ -720,7 +731,7 @@ class PayService ...@@ -720,7 +731,7 @@ class PayService
//总账资金记账 //总账资金记账
$cnt = $cnt && FundsService::credit([ $cnt = $cnt && FundsService::credit([
'trade_id'=>$this->pay_order['order_id'], 'trade_id'=>$this->pay_order['pay_order_id'],
'third_order_id'=>$this->pay_order['third_order_id'], 'third_order_id'=>$this->pay_order['third_order_id'],
'amount'=>$this->pay_order['pay_amount'], 'amount'=>$this->pay_order['pay_amount'],
'tip'=>$wx_tip, 'tip'=>$wx_tip,
...@@ -728,18 +739,15 @@ class PayService ...@@ -728,18 +739,15 @@ class PayService
//营销扣款 //营销扣款
$cnt = $cnt && AccountService::pay($coupon_items, $this->pay_order['order_id']); $cnt = $cnt && AccountService::pay($coupon_items, $this->pay_order['order_id']);
$cnt = $cnt && PayOrderClearing::insert($this->clear_list, ['rowCount' => true]); $cnt = $cnt && PayOrderClearing::insert($this->clear_list, ['rowCount' => true]);
$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' => 0]);
} }
PayOrderClearing::commit(); PayOrderClearing::commit();
} catch (\Exception $e) { } catch (\Exception $e) {
PayOrderClearing::rollback(); PayOrderClearing::rollback();
throw new PayException(['cut' => 5]); throw $e;
} }
//如果是不可退款商品,则需进入结算队列 //如果是不可退款商品,则需进入结算队列
...@@ -792,7 +800,7 @@ class PayService ...@@ -792,7 +800,7 @@ class PayService
*/ */
private function make_platform_clearing($payer) private function make_platform_clearing($payer)
{ {
$account = $payer->clearPlatformTips($this->order_info); $account = $payer->clearPlatformTips($this->pay_order);
if(empty($account)) { if(empty($account)) {
return 0; return 0;
} }
...@@ -926,7 +934,9 @@ class PayService ...@@ -926,7 +934,9 @@ class PayService
} }
} }
array_push($this->clear_list, array_values($maps)); if($maps) {
array_push($this->clear_list, array_values($maps));
}
return $total_tip; return $total_tip;
} }
...@@ -938,9 +948,9 @@ class PayService ...@@ -938,9 +948,9 @@ class PayService
*/ */
private function make_merchant_clearing($merchant_cash, $platform) private function make_merchant_clearing($merchant_cash, $platform)
{ {
$m = $this->get_merchant_account($this->pay_order['life_account_id'], $this->pay_order['life_account_id']); $m = $this->get_merchant_account($this->pay_order);
$merchant['account_id'] = $m['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'] = 407; //商品交易102
...@@ -970,18 +980,20 @@ class PayService ...@@ -970,18 +980,20 @@ class PayService
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'];
$platform_amount = $current_tip - $clear_payment;
} else { } else {
$clear_payment = 0; $clear_payment = $current_tip;
$platform_amount = 0;
} }
$pay_amount = $current_tip; if($platform_amount < 0) {
if($current_tip < $clear_payment) {
throw new PayException(['cus'=>12]); //结算价不能大于商家分成部分 throw new PayException(['cus'=>12]); //结算价不能大于商家分成部分
}
}elseif($clear_payment < $current_tip) { if($platform_amount > 0) {
//结算价剩余部分返回平台 //结算价剩余部分返回平台
$p_tip = $current_tip - $clear_payment; $platform['amount'] += $platform_amount;
$platform['pay_amount'] += $p_tip;
$this->clear_items_list[] = [ $this->clear_items_list[] = [
'pay_order_clearing_item_id' => array_shift($this->gen_ids), 'pay_order_clearing_item_id' => array_shift($this->gen_ids),
'pay_order_clearing_id' => $p_clearing_id, 'pay_order_clearing_id' => $p_clearing_id,
...@@ -990,7 +1002,7 @@ class PayService ...@@ -990,7 +1002,7 @@ class PayService
'order_item_id' => $r['order_item_id'], 'order_item_id' => $r['order_item_id'],
'account_id' => $platform['account_id'], 'account_id' => $platform['account_id'],
'account_type' => $platform['account_type'], 'account_type' => $platform['account_type'],
'pay_amount' => $p_tip, 'pay_amount' => $platform_amount,
'clear_payment' => 0, //商品结算价格 'clear_payment' => 0, //商品结算价格
'pay_type' => $platform['pay_type'], 'pay_type' => $platform['pay_type'],
'pay_sub_type' => $platform['pay_sub_type'], 'pay_sub_type' => $platform['pay_sub_type'],
...@@ -1009,8 +1021,8 @@ class PayService ...@@ -1009,8 +1021,8 @@ class PayService
'order_item_id' => $r['order_item_id'], 'order_item_id' => $r['order_item_id'],
'account_id' => $merchant['account_id'], 'account_id' => $merchant['account_id'],
'account_type' => $merchant['account_type'], 'account_type' => $merchant['account_type'],
'pay_amount' => $pay_amount, 'pay_amount' => $clear_payment, //商品结算价格
'clear_payment' => $clear_payment, //商品结算价格 'clear_payment' => 0,
'pay_type' => $merchant['pay_type'], 'pay_type' => $merchant['pay_type'],
'pay_sub_type' => $merchant['pay_sub_type'], 'pay_sub_type' => $merchant['pay_sub_type'],
'remark' => $remark, 'remark' => $remark,
...@@ -1061,16 +1073,26 @@ class PayService ...@@ -1061,16 +1073,26 @@ class PayService
return $this->gen_ids; return $this->gen_ids;
} }
private function get_merchant_account($life_account_id, $shop_id) private function get_merchant_account($params)
{ {
/*
///account/account/get_account
$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__);
} }
$params = ['life_account_id' => $life_account_id]; */
$account = Sdk::call($url, $params); $url = "http://account.dev.yidian-inc.com/account/account/get_account";
$ret = Sdk::call($url, [
return $account; 'life_account_id'=>$params['life_account_id'],
'shop_id'=>$params['shop_id'],
'source_name'=>$params['source_name'],
'service_name'=>$params['service_name'],
]);
if(empty($ret['result'])) {
throw new PayException(['cus'=>9]);
}
return $ret['result'];
} }
private function getNextTime($times = 0) { private function getNextTime($times = 0) {
......
...@@ -62,7 +62,7 @@ class FileLog ...@@ -62,7 +62,7 @@ class FileLog
$exception_info = ''; $exception_info = '';
} }
$log .= ' [exception info: ]' . $exception_info; $log .= ' [exception info: ]' . $exception_info;
$log .= ' [debug_backtrace info: ]' . print_r(debug_backtrace(), 1); //$log .= ' [debug_backtrace info: ]' . print_r(debug_backtrace(), 1);
error_log($log); error_log($log);
if (empty($mail_to)) { if (empty($mail_to)) {
$mail_to = 'bp-server@yidian-inc.com'; $mail_to = 'bp-server@yidian-inc.com';
......
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