6
0
Fork 0

order 没有提成 支付时 不分账

base
panliang 2023-10-23 14:08:19 +08:00
parent 048c18784a
commit aafeb15dd2
4 changed files with 27 additions and 23 deletions

View File

@ -24,7 +24,6 @@ class Kernel extends ConsoleKernel
*/
protected function schedule(Schedule $schedule)
{
$schedule->call(fn () => logger('schedule running'))->everyMinute();
$schedule->command('order-profit:send')->daily();
$schedule->command('order-profit:check')->daily();
}

View File

@ -35,24 +35,8 @@ class OrderDistribute
try {
DB::beginTransaction();
$service = new DistributeService();
$profits = $service->storeByOrder($order);
$service->storeByOrder($order);
DB::commit();
// 如果没有提成记录
if ($profits->count() <= 0 && in_array($order->pay_way, [PayWay::WxpayApp, PayWay::WxpayH5, PayWay::WxpayJsApi, PayWay::WxpayMiniProgram])) {
// 解冻资金
$sn = serial_number();
$result = (new WxpayService())->finishShare($order->out_trade_no, $sn);
if (data_get($result, 'return_code') != 'SUCCESS') {
logger()->error('微信分账-解冻资金失败', $result);
}
else if (data_get($result, 'result_code') != 'SUCCESS') {
logger()->error('微信分账-解冻资金失败', $result);
} else {
$attributes = ['finish_sn' => $sn, 'status' => 'N'];
$order->update(['wx_share' => $order->wx_share ? array_merge($order->wx_share, $attributes) : $attributes]);
}
}
} catch (Exception $e) {
logger('添加提成记录失败');
logger()->error($e);

View File

@ -23,7 +23,7 @@ use App\Models\ShippingAddress;
use App\Models\SocialiteUser;
use App\Models\Store\{Store, Desk, DeviceRecord};
use App\Models\UserCoupon;
use App\Models\{User, OrderPre, Tag};
use App\Models\{Agent, User, OrderPre, Tag};
use App\Services\Payment\WxpayService;
use Illuminate\Database\Eloquent\Builder;
use Illuminate\Database\QueryException;
@ -1240,12 +1240,22 @@ class OrderService
throw new BizException('支付方式 非法');
}
// 是否开启分账
$share = 'Y';
$user = $order->user;
$agentIds = User::whereIn('id', $user->userInfo->parent_ids)->pluck('agent_id');
$ratio = Agent::whereIn('id', $agentIds)->sum('ratio');
// 没有提成
if ($ratio == 0) {
$share = 'N';
}
$params = [
'body' => app_settings('app.app_name').'-商城订单',
'out_trade_no' => $payLog->pay_sn,
'total_fee' => $order->total_amount,
'trade_type' => $tradeType->value,
'profit_sharing' => 'Y',
'profit_sharing' => $share,
];
if ($tradeType === WxpayTradeType::JSAPI) {
@ -1269,7 +1279,8 @@ class OrderService
});
// 更新订单冻结状态
$order->update(['wx_share' => $order->wx_share ? array_merge($order->wx_share, ['status' => 'Y']) : ['status' => 'Y']]);
$attributes = ['status' => $share];
$order->update(['wx_share' => $order->wx_share ? array_merge($order->wx_share, $attributes) : $attributes]);
} elseif ($payLog->isAlipay()) {
$params = [
'subject' => app_settings('app.app_name').'-商城订单',

View File

@ -3,6 +3,8 @@
namespace Tests\Feature;
use App\Enums\PayWay;
use App\Models\Agent;
use App\Models\User;
use App\Services\DistributeService;
use App\Services\Payment\WxpayService;
use Illuminate\Support\Facades\DB;
@ -18,8 +20,16 @@ class ExampleTest extends TestCase
*/
public function test_example()
{
$result = ['status' => 'N', 'sn' => '21322132'];
dump($result ? array_merge($result, ['status' => 'Y']) : ['status' => 'Y']);
$share = 'Y';
$user = User::find(4);
$agentIds = User::whereIn('id', $user->userInfo->parent_ids)->pluck('agent_id');
dump($user->userInfo->parent_ids);
$ratio = Agent::whereIn('id', $agentIds)->sum('ratio');
// 没有提成
if ($ratio == 0) {
$share = 'N';
}
dump($share);
$this->assertTrue(true);
}
}