Commit d4916818 authored by wanjilong's avatar wanjilong

add: init pay_v2

parent dc61a339
......@@ -15,4 +15,6 @@ class Code
const REFUND = 102000;
const ORDER = 103000;
const SDK = 104000;
const FUNDS = 105000;
const P_ACCOUNT = 106000;
}
\ No newline at end of file
......@@ -6,28 +6,12 @@ namespace App\Exception\custom;
use App\Exception\BaseException;
class RefundException extends BaseException
class FundsException extends BaseException
{
protected $base_code = Code::REFUND;
protected $base_code = Code::FUNDS;
protected $cus = [
0 => '系统异常请联系管理员',
1 => '缺少退款订单ID!',
2 => '获取订单信息返回错误,请核对',
3 => '仅支持自己操作订单退款!',
4 => '目前仅支持支付后的订单退款,请核对',
5 => '已核销计算订单不支持退款!',
6 => '退款处理完成,请勿重复申请',
7 => '退款处理中请稍等',
8 => '退款消息类型匹配失败,请管理员关注!',
9 => 'pingxx退款消息格式错误,请管理员关注!',
10 => 'pingxx退单状态异常,请管理员关注!',
11 => 'pingxx退单缺少matadata!',
12 => 'pingxx未支付订单不允许退款。',
13 => 'pingxx订单可能存在多次成功支付,需人工确认处理。',
14 => '不存在满足条件的退款订单。',
15 => '订单未支付或不存在,请核对。',
16 => '订单退款回调处理失败,请核对。',
1 => '缺少渠道平台账户配置,请联系管理员!',
];
}
......@@ -13,24 +13,34 @@ class PayException extends BaseException
protected $cus = [
0 => '系统错误,请稍收重试',
1 => '请输入订单ID',
2 => '订单服务获取订单信息失败。',
3 => '请确认订单信息及用户是否一致。',
4 => '支付订单创建失败,请管理员关注',
5 => '该订单已经支付,请稍后刷新',
6 => '该订单已超时取消关闭,请重新下单购买',
7 => '支付回调订单不存在,请管理员关注',
8 => '支付订单金额与实际支付金额不等,请管理员关注',
9 => '退款中订单不允许核销,请管理员关注',
2 => '请输入用户ID',
3 => '订单服务获取订单信息失败。',
4 => '请确认订单信息及用户是否一致。',
5 => '订单缺少过期时间,请联系管理员',
6 => '订单过期,不允许支付',
7 => '支付订单创建失败,请管理员关注',
8 => '支付订单创建失败,请管理员关注',
9 => '订单已经支付,请勿重复支付',
10 => '回调失败,支付订单不存在',
11 => '回调失败,支付金额错误',
12 => '订单服务优惠信息错误',
13 => '订单明细保存失败',
10 => '未支付订单不允许核销,请管理员关注',
11 => '商家仅允许核销自己的订单,请管理员关注',
12 => '支付订单预结算失败,结算资金不能负数,请核对配置',
13 => '生活号获取管理员ID失败,请联系管理员',
14 => '订单缺少商品信息,请联系管理员',
15 => '订单存在过期商品,不能支付',
16 => '订单过期,不允许支付',
17 => '订单缺少过期时间,请联系管理员',
18 => '订单不存在,请重试',
100=>'支付渠道错误,暂不支持该渠道',
101=>'该订单已经支付,请稍后刷新',
102=>'该订单已超时取消关闭,请重新下单购买',
103=>'该订单已超时取消关闭,请重新下单购买',
104=>'请增加pingxx渠道手续费配置',
];
}
......@@ -6,9 +6,9 @@ namespace App\Exception\custom;
use App\Exception\BaseException;
class FundsException extends BaseException
class PlatformAccountException extends BaseException
{
protected $base_code = Code::FUNDS;
protected $base_code = Code::P_ACCOUNT;
protected $cus = [
0 => '系统异常请联系管理员',
......
......@@ -11,23 +11,16 @@ class RefundException extends BaseException
protected $base_code = Code::REFUND;
protected $cus = [
0 => '系统异常请联系管理员',
0 => '系统异常请联系管理员',
1 => '缺少退款订单ID!',
2 => '获取订单信息返回错误,请核对',
3 => '仅支持自己操作订单退款!',
4 => '目前仅支持支付后的订单退款,请核对',
5 => '已核销计算订单不支持退款!',
6 => '退款处理完成,请勿重复申请',
7 => '退款处理中请稍等',
8 => '退款消息类型匹配失败,请管理员关注!',
9 => 'pingxx退款消息格式错误,请管理员关注!',
10 => 'pingxx退单状态异常,请管理员关注!',
11 => 'pingxx退单缺少matadata!',
12 => 'pingxx未支付订单不允许退款。',
13 => 'pingxx订单可能存在多次成功支付,需人工确认处理。',
14 => '不存在满足条件的退款订单。',
15 => '订单未支付或不存在,请核对。',
16 => '订单退款回调处理失败,请核对。',
2 => '订单未支付或不存在,请核对。',
3 => '不存在满足条件的退款订单。',
4 => '退单保存失败,请联系管理员。',
5 => '订单退款回调处理失败,请核对。',
6 => 'pingxx退单缺少matadata!',
7 => 'pingxx未支付订单不允许退款。',
8 => 'pingxx订单可能存在多次成功支付,需人工确认处理。',
];
}
......@@ -6,5 +6,5 @@ use Api\PhpUtils\Mysql\MysqlBase;
class CallbackLog extends MysqlBase
{
const TABLE_NAME = 'callback_log';
const CONFIG_INDEX = 'pay';
const CONFIG_INDEX = 'pay_v2';
}
......@@ -4,34 +4,8 @@ namespace App\Models\order\mysql;
use Api\PhpUtils\Mysql\MysqlBase;
use App\Exception\custom\PayException;
class PayOrder extends MysqlBase
class MarketingAccount extends MysqlBase
{
const TABLE_NAME = 'pay_order';
const CONFIG_INDEX = 'pay';
/**
* @param $order_id
* @param $pay_order
* @return array
*/
public static function get_valid_order($order_id, $pay_order) {
self::beginTransaction();
try{
$order = self::getMaster('*', ['order_id'=>$order_id]);
if(empty($order)) {
$cnt = self::insert($pay_order, ['rowCount'=>true]);
if($cnt) {
$order = $pay_order;
}
}
self::commit();
}catch (\PDOException $e) {
self::rollback();
}
return $order;
}
const TABLE_NAME = 'marketing_account';
const CONFIG_INDEX = 'pay_v2';
}
......@@ -2,10 +2,9 @@
namespace App\Models\order\mysql;
use Api\PhpUtils\Mysql\MysqlBase;
use App\Exception\custom\PayException;
class MarketingAccount extends MysqlBase
class MarketingAccountLog extends MysqlBase
{
const TABLE_NAME = 'marketing_account';
const CONFIG_INDEX = 'pay';
const TABLE_NAME = 'marketing_account_log';
const CONFIG_INDEX = 'pay_v2';
}
......@@ -3,8 +3,8 @@ namespace App\Models\order\mysql;
use Api\PhpUtils\Mysql\MysqlBase;
class MarketingAccountLog extends MysqlBase
class MarketingAccountMap extends MysqlBase
{
const TABLE_NAME = 'marketing_account_log';
const CONFIG_INDEX = 'pay';
const TABLE_NAME = 'marketing_account_map';
const CONFIG_INDEX = 'pay_v2';
}
......@@ -4,34 +4,8 @@ namespace App\Models\order\mysql;
use Api\PhpUtils\Mysql\MysqlBase;
use App\Exception\custom\PayException;
class PayOrder extends MysqlBase
class PayCouponItem extends MysqlBase
{
const TABLE_NAME = 'pay_order';
const CONFIG_INDEX = 'pay';
/**
* @param $order_id
* @param $pay_order
* @return array
*/
public static function get_valid_order($order_id, $pay_order) {
self::beginTransaction();
try{
$order = self::getMaster('*', ['order_id'=>$order_id]);
if(empty($order)) {
$cnt = self::insert($pay_order, ['rowCount'=>true]);
if($cnt) {
$order = $pay_order;
}
}
self::commit();
}catch (\PDOException $e) {
self::rollback();
}
return $order;
}
const TABLE_NAME = 'pay_coupon_item';
const CONFIG_INDEX = 'pay_v2';
}
......@@ -7,7 +7,7 @@ use App\Exception\custom\PayException;
class PayOrder extends MysqlBase
{
const TABLE_NAME = 'pay_order';
const CONFIG_INDEX = 'pay';
const CONFIG_INDEX = 'pay_v2';
/**
* @param $order_id
......
......@@ -6,5 +6,5 @@ use Api\PhpUtils\Mysql\MysqlBase;
class PayOrderClearing extends MysqlBase
{
const TABLE_NAME = 'pay_order_clearing';
const CONFIG_INDEX = 'pay';
const CONFIG_INDEX = 'pay_v2';
}
......@@ -7,7 +7,7 @@ use App\Exception\BaseException;
class PayOrderClearingItem extends MysqlBase
{
const TABLE_NAME = 'pay_order_clearing_item';
const CONFIG_INDEX = 'pay';
const CONFIG_INDEX = 'pay_v2';
public static function marketSaleCount($accountId) {
......
......@@ -6,5 +6,5 @@ use Api\PhpUtils\Mysql\MysqlBase;
class PayOrderItem extends MysqlBase
{
const TABLE_NAME = 'pay_order_item';
const CONFIG_INDEX = 'pay';
const CONFIG_INDEX = 'pay_v2';
}
......@@ -4,34 +4,8 @@ namespace App\Models\order\mysql;
use Api\PhpUtils\Mysql\MysqlBase;
use App\Exception\custom\PayException;
class PayOrder extends MysqlBase
class PayOrderLog extends MysqlBase
{
const TABLE_NAME = 'pay_order';
const CONFIG_INDEX = 'pay';
/**
* @param $order_id
* @param $pay_order
* @return array
*/
public static function get_valid_order($order_id, $pay_order) {
self::beginTransaction();
try{
$order = self::getMaster('*', ['order_id'=>$order_id]);
if(empty($order)) {
$cnt = self::insert($pay_order, ['rowCount'=>true]);
if($cnt) {
$order = $pay_order;
}
}
self::commit();
}catch (\PDOException $e) {
self::rollback();
}
return $order;
}
const TABLE_NAME = 'pay_order_log';
const CONFIG_INDEX = 'pay_v2';
}
......@@ -3,8 +3,8 @@ namespace App\Models\order\mysql;
use Api\PhpUtils\Mysql\MysqlBase;
class PlatformFunds extends MysqlBase
class PlatformAccount extends MysqlBase
{
const TABLE_NAME = 'platform_funds_log';
const CONFIG_INDEX = 'pay';
const TABLE_NAME = 'platform_account';
const CONFIG_INDEX = 'pay_v2';
}
......@@ -3,8 +3,8 @@ namespace App\Models\order\mysql;
use Api\PhpUtils\Mysql\MysqlBase;
class PlatformAccount extends MysqlBase
class PlatformAccountLog extends MysqlBase
{
const TABLE_NAME = 'platform_account';
const CONFIG_INDEX = 'pay';
const TABLE_NAME = 'platform_account_log';
const CONFIG_INDEX = 'pay_v2';
}
......@@ -3,8 +3,8 @@ namespace App\Models\order\mysql;
use Api\PhpUtils\Mysql\MysqlBase;
class PlatformFunds extends MysqlBase
class PlatformConfig extends MysqlBase
{
const TABLE_NAME = 'platform_funds_log';
const CONFIG_INDEX = 'pay';
const TABLE_NAME = 'platform_config';
const CONFIG_INDEX = 'pay_v2';
}
......@@ -3,8 +3,8 @@ namespace App\Models\order\mysql;
use Api\PhpUtils\Mysql\MysqlBase;
class PlatformAccount extends MysqlBase
class PlatformFunds extends MysqlBase
{
const TABLE_NAME = 'platform_account';
const CONFIG_INDEX = 'pay';
const TABLE_NAME = 'platform_funds';
const CONFIG_INDEX = 'pay_v2';
}
......@@ -3,8 +3,8 @@ namespace App\Models\order\mysql;
use Api\PhpUtils\Mysql\MysqlBase;
class PlatformAccountLog extends MysqlBase
class PlatformFundsLog extends MysqlBase
{
const TABLE_NAME = 'platform_account_log';
const CONFIG_INDEX = 'pay';
const TABLE_NAME = 'platform_funds_log';
const CONFIG_INDEX = 'pay_v2';
}
......@@ -3,8 +3,8 @@ namespace App\Models\order\mysql;
use Api\PhpUtils\Mysql\MysqlBase;
class RefundPlatformRecord extends MysqlBase
class RefundMerchantRecord extends MysqlBase
{
const TABLE_NAME = 'refund_platform_record';
const CONFIG_INDEX = 'pay';
const TABLE_NAME = 'refund_merchant_record';
const CONFIG_INDEX = 'pay_v2';
}
......@@ -6,5 +6,5 @@ use Api\PhpUtils\Mysql\MysqlBase;
class RefundOrder extends MysqlBase
{
const TABLE_NAME = 'refund_order';
const CONFIG_INDEX = 'pay';
const CONFIG_INDEX = 'pay_v2';
}
......@@ -3,8 +3,8 @@ namespace App\Models\order\mysql;
use Api\PhpUtils\Mysql\MysqlBase;
class RefundOrder extends MysqlBase
class RefundOrderItem extends MysqlBase
{
const TABLE_NAME = 'refund_order';
const CONFIG_INDEX = 'pay';
const TABLE_NAME = 'refund_order_item';
const CONFIG_INDEX = 'pay_v2';
}
......@@ -3,8 +3,8 @@ namespace App\Models\order\mysql;
use Api\PhpUtils\Mysql\MysqlBase;
class RefundOrderItem extends MysqlBase
class RefundPersonalRecord extends MysqlBase
{
const TABLE_NAME = 'refund_order_item';
const CONFIG_INDEX = 'pay';
const TABLE_NAME = 'refund_personal_record';
const CONFIG_INDEX = 'pay_v2';
}
......@@ -3,8 +3,8 @@ namespace App\Models\order\mysql;
use Api\PhpUtils\Mysql\MysqlBase;
class RefundPersonalRecord extends MysqlBase
class RefundPlatformRecord extends MysqlBase
{
const TABLE_NAME = 'refund_personal_record';
const CONFIG_INDEX = 'pay';
const TABLE_NAME = 'refund_platform_record';
const CONFIG_INDEX = 'pay_v2';
}
......@@ -3,8 +3,8 @@ namespace App\Models\order\mysql;
use Api\PhpUtils\Mysql\MysqlBase;
class WriteOffOrder extends MysqlBase
class WriteOffMerchantRecord extends MysqlBase
{
const TABLE_NAME = 'writeoff_order';
const CONFIG_INDEX = 'pay';
const TABLE_NAME = 'writeoff_merchant_record';
const CONFIG_INDEX = 'pay_v2';
}
......@@ -3,8 +3,8 @@ namespace App\Models\order\mysql;
use Api\PhpUtils\Mysql\MysqlBase;
class RefundOrder extends MysqlBase
class WriteOffOrder extends MysqlBase
{
const TABLE_NAME = 'refund_order';
const CONFIG_INDEX = 'pay';
const TABLE_NAME = 'writeoff_order';
const CONFIG_INDEX = 'pay_v2';
}
......@@ -3,8 +3,8 @@ namespace App\Models\order\mysql;
use Api\PhpUtils\Mysql\MysqlBase;
class RefundOrder extends MysqlBase
class WriteOffOrderItem extends MysqlBase
{
const TABLE_NAME = 'refund_order';
const CONFIG_INDEX = 'pay';
const TABLE_NAME = 'writeoff_order_item';
const CONFIG_INDEX = 'pay_v2';
}
......@@ -3,8 +3,8 @@ namespace App\Models\order\mysql;
use Api\PhpUtils\Mysql\MysqlBase;
class WriteOffMerchantRecord extends MysqlBase
class WriteOffPersonalRecord extends MysqlBase
{
const TABLE_NAME = 'writeoff_merchant_record';
const CONFIG_INDEX = 'pay';
const TABLE_NAME = 'writeoff_personal_record';
const CONFIG_INDEX = 'pay_v2';
}
......@@ -3,8 +3,8 @@ namespace App\Models\order\mysql;
use Api\PhpUtils\Mysql\MysqlBase;
class WriteOffPersonalRecord extends MysqlBase
class WriteOffPlatformRecord extends MysqlBase
{
const TABLE_NAME = 'writeoff_personal_record';
const CONFIG_INDEX = 'pay';
const TABLE_NAME = 'writeoff_platform_record';
const CONFIG_INDEX = 'pay_v2';
}
<?php
use Api\PhpServices\Idgen\Idgen;
use App\Base\Base;
use App\Models\order\mysql\PayOrderItem;
......@@ -82,4 +83,16 @@ class TccController extends Base
$params['traceId'] = \Helpers\Tracer::getTraceId();
$this->success($params);
}
public function idsAction() {
$number = $this->params['number'] ?? '12';
$count = $this->params['count'] ?? 5;
$res = Idgen::get(appConfig('idgen.partner'), appConfig('idgen.key'), [], [[
"type" => "55c768",
'number' => $number,
"count" => $count]]);
$id = $res['id_datetime']['55c768'] ?? [];
$this->success(['ids'=>$id]);
}
}
......@@ -51,12 +51,17 @@ class Hook extends \Yaf\Plugin_Abstract {
return false;
}
// 优选选择 raw 方式, raw, $_POST 不能共存。
// raw, $_POST 不能共存。
if(!empty($_POST)) {
return false;
}
// application/json形式,仅处理$_POST, 不整合$_GET
switch ($request->getServer('CONTENT_TYPE')) {
switch (strtolower($request->getServer('CONTENT_TYPE'))) {
case "application/json":
case "application/json; charset=utf-8":
case "application/json;charset=utf-8":
$jsonPost = file_get_contents("php://input");
if(empty($jsonPost)) {
$_POST = [];
......
<?php
namespace App\Services\order;
namespace App\Services;
use App\Exception\custom\CodeSpecialException;
use Helpers\Sdk;
use App\Services\channel\Pingxx;
use App\Services\channel\Platform;
use App\Exception\custom\PayException;
class OrderService
class Channel
{
/**
* @param $orderId
* @param $userId
* 调用内部服务获取用户订单、子单、分润信息
*/
public static function getFullOrderData($order_id) {
public static function getChannel($pay_channel) {
$payer = null;
switch ($pay_channel) {
case '105':
case '106':
case '107':
case '108':
case '109':
case '110':
$payer = new Pingxx();
break;
case '1':
$payer = new Platform();
break;
$url = config('interface', 'order.order.pay_order');
if (!$url) {
throw new CodeSpecialException("failed" . __METHOD__ );
}
$params = ['order_id'=>$order_id];
return Sdk::call($url, $params);
if(empty($payer)) {
throw new PayException(['cus'=>100]);
}
public static function getOrderInfo($order_id, $user_id) {
//pay_order_info
$url = config('interface', 'order.order.pay_order_info');
if (!$url) {
throw new CodeSpecialException("failed" . __METHOD__ );
return $payer;
}
$params = ['order_id'=>$order_id, 'user_id'=>$user_id];
return Sdk::call($url, $params);
}
/**
* @param $order_item_id
* @param $user_id
* @return bool|mixed
* @throws CodeSpecialException
* 获取订单子单信息
*/
public static function getOrderItemData($order_item_id) {
//merchant.account.get_role_list
$url = config('interface', 'order.order.pay_order_item');
if (!$url) {
throw new CodeSpecialException("failed" . __METHOD__ );
}
$params = ['order_item_id'=>$order_item_id];
return Sdk::call($url, $params);
}
}
\ No newline at end of file
<?php
namespace App\Services\channel;
use Api\PhpUtils\Log\FileLog;
use App\Exception\custom\RefundException;
use App\Models\order\mysql\PlatformConfig;
use App\Services\pingxx\PingxxService;
use App\Exception\custom\PayException;
use App\Exception\BaseException;
class Pingxx {
/**
* @param $pay_order
* @param $mata_data
* 系统支付
*/
public function pay($pay_order, $mata_data, $extra = []) {
// 已经创建,需要查询返回
if(!empty($pay_order['third_order_id'])) {
$ret = PingxxService::getInstance()->getOrder($pay_order['third_order_id']);
} else {
$ret = PingxxService::getInstance()->createOrder($pay_order, $mata_data);
}
if (!empty($ret['error'])) {
throw new BaseException(['msg'=>$ret['error']['message'], 'code'=>'2301']);
}
if ($ret["status"] == 'paid' || $ret['status'] == 'refunded') {
throw new PayException(['cus' => 101]);
} elseif ($ret["status"] == 'canceled') {
throw new PayException(['cus' => 102]);
} elseif ($ret["status"] == 'created') {
;
} else {
throw new PayException(['cus' => 103]);
}
$channel_exist = false;
$channel = $this->getChannel($pay_order['pay_channel']);
if(!empty($ret['charges']['data'])) {
//是否存在
foreach ($ret['charges']['data'] as $ch) {
if($ch['channel'] == $channel) {
$channel_exist = true;
}
}
}
//判断是否做过pay操作 charge
if($channel_exist == false) {
// 创建支付单
$payment = [
'charge_order_no'=> $pay_order['pay_order_id'],
'charge_amount'=> $pay_order['pay_amount'],
'channel'=> $channel,
'extra'=> $extra,
];
$pay = PingxxService::getInstance()->pay($ret['id'], $payment);
if (!empty($pay['error'])) {
throw new BaseException(['msg'=>$pay['error']['message'], 'code'=>'2002']);
}
return $pay;
} else {
return $ret;
}
}
/**
* @param $pay_order
* @param $mata_data
* 系统退款
*/
public function refund($data, $mata_data) {
/*
https://www.pingxx.com/api/%E8%AE%A2%E5%8D%95%20Refunds%20%E9%80%80%E6%AC%BE%E6%A6%82%E8%BF%B0.html
订单退款 paid = true, status = canceled, amount_paid > 0 则表明可以退款
amount_paid 大于 actual_amount 需要最后一单全退。
具体见ping++ 文档
*/
$pay = PingxxService::getInstance()->getOrder($data['pay_order']['third_order_id']);
if(empty($pay['paid']) || $pay['paid'] != true) {
throw new RefundException(['cus' => 7]);
}
// 存在多次支付的场景需要人工介入处理, 修复订单支付金额,退款金额
if($pay['amount_paid'] > $pay['actual_amount']) {
FileLog::error('pay-service: 订单可能存在多次成功支付,需人工确认处理。', json_encode($pay, JSON_UNESCAPED_UNICODE));
throw new RefundException(['cus' => 8]);
}
// 构造退款数据
$refund = [
'id'=>$pay['id'], //pingxx订单ID
'charge'=>$pay['charge'], //pingxx 支付订单ID
'refund_mode' => 'to_source', //默认返回
'charge_amount'=>$data['refund_order']['refund_amount'],
'metadata' => $mata_data,
];
return PingxxService::getInstance()->sendRefund($refund);
}
private function getChannel($pay_method_id) {
$maps = [
1=>"syt", //系统余额支付
105=>"wx", //微信 App 支付
106=>"alipay", //支付宝
107=>"wx_pub", //微信 JSAPI 支付
108=>"wx_pub_qr", //微信 Native 支付
109=>"wx_wap", //微信 H5 支付
110=>"wx_lite", //微信小程序支付
];
if(!empty($maps[$pay_method_id])) {
return $maps[$pay_method_id];
} else {
return $maps[105];
}
}
/**
* @param $pay_order
* @return array
* @throws PayException
* 手续费计算
*/
public function clearChannelTips($pay_order) {
//PlatformConfig
$info = PlatformConfig::get('*', [
'account_type'=>2,
'channel'=>1,
'source_name'=>$pay_order['source_name'],
'service_name'=>$pay_order['service_name']
]);
if(empty($info)) {
throw new PayException(['cus'=>104]);
}
$float_tip = $info['rate'] * $pay_order['payment'] / 10000;
if($float_tip >= 1 ) {
$total_tip = round($float_tip);
return [
'account_id' => $info['account_id'],
'amount' => $total_tip,
];
} else {
return [];
}
}
public function clearPlatformTips($pay_order) {
//PlatformConfig
$info = PlatformConfig::get('*', [
'account_type'=>1,
'channel'=>1,
'source_name'=>$pay_order['source_name'],
'service_name'=>$pay_order['service_name']
]);
if(empty($info)) {
throw new PayException(['cus'=>104]);
}
$float_tip = $info['rate'] * $pay_order['total_price'] / 10000;
$total_tip = round($float_tip);
if($float_tip >= 1) {
return [
'account_id' => $info['account_id'],
'amount' => $total_tip,
];
} else {
return [];
}
}
public function getFundsInfo($pay_order) {
$info = PlatformConfig::get('*', [
'account_type'=>3,
'channel'=>1,
'source_name'=>$pay_order['source_name'],
'service_name'=>$pay_order['service_name']
]);
if(empty($info)) {
throw new PayException(['cus'=>104]);
}
return $info;
}
}
<?php
namespace App\Services\channel;
class Platform {
/**
* @param $pay_order
* @param $mata_data
* 系统支付
*/
public function pay($pay_order, $mata_data) {
//todo 保存数据
return [];
}
/**
* @param $pay_order
* @param $mata_data
* 系统退款
*/
public function refund($pay_order, $mata_data) {
}
}
\ No newline at end of file
<?php
namespace App\Services\wallet;
namespace App\Services\marketing;
use App\Exception\custom\CodeSpecialException;
use Helpers\Sdk;
use App\Models\order\mysql\MarketingAccount;
use App\Models\order\mysql\MarketingAccountLog;
use App\Models\order\mysql\MarketingAccountMap;
class WalletService
class AccountService
{
private static $maps = [];
/**
* @param $list
* @param $order_id
* @return bool
* 资金冻结
*/
public static function frozen($list, $order_id) {
$coupon = self::formatData($list);
$cnt = true;
foreach ($coupon as $id=>$amount) {
$marketing_account_id = self::map($id);
$cnt = $cnt && MarketingAccount::update([
'frozen_amount[+]'=>$amount,
'receivable_amount[-]'=>$amount,
], ['marketing_account_id'=>$marketing_account_id]);
$cnt = $cnt && MarketingAccountLog::insert([
'marketing_account_id'=>$marketing_account_id,
'third_id'=>$id,
'fund_type'=>1,
'trade_id'=>$order_id,
'amount'=>$amount,
], ['rowCount'=>true]);
}
return $cnt;
}
/**
* @param $params
* @return bool|mixed
* @throws CodeSpecialException
* 钱包记录同步
* @param $list
* @param $order_id
* @return bool
* 营销资金扣款
*/
public static function send($params) {
public static function pay($list, $order_id) {
$coupon = self::formatData($list);
$url = config('interface', 'wallet.account.transfer');
if (!$url) {
throw new CodeSpecialException("failed");
$cnt = true;
// 冻结优惠信息
foreach ($coupon as $id=>$amount) {
$marketing_account_id = self::map($id);
$cnt = $cnt && MarketingAccount::update([
'frozen_amount[-]'=>$amount,
], ['marketing_account_id'=>$marketing_account_id]);
$cnt = $cnt && MarketingAccountLog::insert([
'marketing_account_id'=>$marketing_account_id,
'third_id'=>$id,
'fund_type'=>2,
'trade_id'=>$order_id,
'amount'=>$amount,
], ['rowCount'=>true]);
}
return $cnt;
}
// 服务增加签名
$appid = \Yaf\Application::app()->getConfig()->get('wallet.appid');
$secret = \Yaf\Application::app()->getConfig()->get('wallet.secret');
/**
* @param $list
* @param $refund_order_id
* @return bool
* 退款营销可用增加
*/
public static function refund($list, $refund_order_id) {
$coupon = self::formatData($list);
$cnt = true;
$params['time'] = date('Y-m-d H:i:s');
$params['transfer_service_id'] = $appid;
$params['sign'] = self::sign($params, $secret);
foreach ($coupon as $id=>$amount) {
$marketing_account_id = self::map($id);
$cnt = $cnt && MarketingAccount::update([
'receivable_amount[+]'=>$amount,
], ['marketing_account_id'=>$marketing_account_id]);
$cnt = $cnt && MarketingAccountLog::insert([
'marketing_account_id'=>$marketing_account_id,
'third_id'=>$id,
'fund_type'=>3,
'trade_id'=>$refund_order_id,
'amount'=>$amount,
], ['rowCount'=>true]);
}
return $cnt;
}
/**
* @param $list
* @param $order_id
* @return bool
* 未支付取消,营销冻结释放
*/
public static function cancel($list, $order_id) {
$coupon = self::formatData($list);
$cnt = true;
return Sdk::call($url, $params);
foreach ($coupon as $id=>$amount) {
$marketing_account_id = self::map($id);
$cnt = $cnt && MarketingAccount::update([
'receivable_amount[+]'=>$amount,
], ['marketing_account_id'=>$marketing_account_id]);
$cnt = $cnt && MarketingAccountLog::insert([
'marketing_account_id'=>$marketing_account_id,
'third_id'=>$id,
'fund_type'=>4,
'trade_id'=>$order_id,
'amount'=>$amount,
], ['rowCount'=>true]);
}
return $cnt;
}
/**
* @param $data
* @param $marketing_account_id
* @return bool
* 营销充值
*/
public static function recharge($data, $marketing_account_id) {
$cnt = true;
$cnt = $cnt && MarketingAccount::update([
'receivable_amount[+]'=>$data['amount']
], ['marketing_account_id'=>$marketing_account_id]);
$cnt = $cnt && MarketingAccountLog::insert([
'marketing_account_id'=>$marketing_account_id,
'third_id'=>$data['third_id'],
'fund_type'=>5,
'trade_id'=>$data['trade_id'],
'amount'=>$data['amount'],
]);
return $cnt;
}
public static function transfer($data, $marketing_account_id) {
$cnt = true;
$cnt = $cnt && MarketingAccount::update([
'receivable_amount[-]'=>$data['amount']
], ['marketing_account_id'=>$marketing_account_id]);
$cnt = $cnt && MarketingAccountLog::insert([
'marketing_account_id'=>$marketing_account_id,
'third_id'=>$data['third_id'],
'fund_type'=>6,
'trade_id'=>$data['trade_id'],
'amount'=>$data['amount'],
]);
return $cnt;
}
public static function map($third_id, $source_name = 10, $service_name = 1) {
if(!isset(self::$maps[$third_id])) {
$info = MarketingAccountMap::get('*',
['third_id'=>$third_id, 'source_name'=>$source_name, 'service_name'=>$service_name]);
if($info) {
self::$maps[$third_id] = $info['marketing_account_id'];
} else {
self::$maps[$third_id] = '';
}
}
return self::$maps[$third_id];
}
private static function formatData($list) {
$coupon = [];
foreach ($list as $r) {
if(!isset($coupon[$r['capital_pool_id']])) {
$coupon[$r['capital_pool_id']] = 0;
}
$coupon[$r['capital_pool_id']] += $r['share_coupon_amount'];
}
private function sign($params, $secret) {
$sign = md5($params['time'] . $secret);
return $sign;
return $coupon;
}
}
\ No newline at end of file
This diff is collapsed.
This diff is collapsed.
......@@ -4,10 +4,10 @@
namespace App\Services\pay;
use App\Exception\custom\FundsException;
use App\Models\order\mysql\PlatformFunds;
use App\Models\order\mysql\PlatformFundsLog;
use App\Models\order\mysql\PlatformAccount;
use App\Models\order\mysql\PlatformAccountLog;
class FundsService
class PlatformAccountService
{
/**
* @param $data
......@@ -17,62 +17,27 @@ class FundsService
* @throws FundsException
* 渠道账户入账记录
*/
public static function credit($data, $channel = 1, $source_name = 10, $service_name = 1) {
public static function credit($data, $source_name = 10, $service_name = 1) {
$info = PlatformFunds::getMaster('*',
['channel'=>$channel, 'source_name'=>$source_name, 'service_name'=>$service_name]);
if(empty($info)) {
throw new FundsException(['cus'=>1]);
}
$cnt = PlatformFunds::update([
'total_amount[+]'=>$data['amount'],
'total_tip[+]'=>$data['tip'],
], ['platform_funds_id'=>$info['platform_funds_id']]);
$l_cnt = PlatformFundsLog::insert([
'platform_funds_id'=>$info['platform_funds_id'],
'trade_id'=>$data['order_id'],
'third_order_id'=>$data['third_id'],
'fund_type'=>1,
'amount'=>$data['amount'],
'tip'=>$data['tip'],
], ['rowCount' => true]);
return $l_cnt && $cnt;
}
/**
* @param $data
* @param int $channel
* @param int $source_name
* @param int $service_name
* @throws FundsException
* 渠道账户出账
*/
public static function payOut($data, $channel = 1, $source_name = 10, $service_name = 1) {
$info = PlatformFunds::getMaster('*',
['channel'=>$channel, 'source_name'=>$source_name, 'service_name'=>$service_name]);
$info = PlatformAccount::getMaster('*',
['source_name'=>$source_name, 'service_name'=>$service_name]);
if(empty($info)) {
throw new FundsException(['cus'=>1]);
}
$cnt = true;
$cnt = $cnt && PlatformFunds::update([
'total_amount[-]'=>$data['amount'],
'total_tip[-]'=>$data['tip'],
$cnt = $cnt && PlatformAccount::update([
'receivable_amount[+]'=>$data['amount']
], ['platform_funds_id'=>$info['platform_funds_id']]);
$cnt = $cnt && PlatformFundsLog::insert([
'platform_funds_id'=>$info['platform_funds_id'],
'trade_id'=>$data['order_id'],
'third_order_id'=>$data['third_id'],
'fund_type'=>2,
'amount'=>$data['amount'],
'tip'=>$data['tip'],
$cnt = $cnt && PlatformAccountLog::insert([
'platform_account_id'=>$info['platform_account_id'],
'trade_id'=>$data['trade_id'],
'fund_type'=>1,
'amount'=>$data['amount']
], ['rowCount' => true]);
return $cnt;
}
}
\ No newline at end of file
......@@ -7,7 +7,7 @@ use App\Exception\custom\CodeSpecialException;
use Helpers\Sdk;
class WalletService
class MerchantAccountService
{
/**
......@@ -16,12 +16,15 @@ class WalletService
* @throws CodeSpecialException
* 钱包记录同步
*/
public static function send($params) {
$url = config('interface', 'wallet.account.transfer');
public static function sync($params) {
/*
///account/billrecord/create
$url = config('interface', 'account.account.transfer');
if (!$url) {
throw new CodeSpecialException("failed");
}
*/
$url = 'http://account.dev.yidian-inc.com/account/billrecord/create';
// 服务增加签名
$appid = \Yaf\Application::app()->getConfig()->get('wallet.appid');
......
......@@ -38,4 +38,5 @@ class WalletService
$sign = md5($params['time'] . $secret);
return $sign;
}
}
\ No newline at end of file
<?php
var_dump($_POST);
$ids = ["21092214200312204001","21092214200312204002","21092214200312204003","21092214200312204004","21092214200312204005"];
$t = array_shift($ids);
var_dump($t);
\ 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