order 没有提成 支付时 不分账
parent
048c18784a
commit
aafeb15dd2
|
|
@ -24,7 +24,6 @@ class Kernel extends ConsoleKernel
|
||||||
*/
|
*/
|
||||||
protected function schedule(Schedule $schedule)
|
protected function schedule(Schedule $schedule)
|
||||||
{
|
{
|
||||||
$schedule->call(fn () => logger('schedule running'))->everyMinute();
|
|
||||||
$schedule->command('order-profit:send')->daily();
|
$schedule->command('order-profit:send')->daily();
|
||||||
$schedule->command('order-profit:check')->daily();
|
$schedule->command('order-profit:check')->daily();
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -35,24 +35,8 @@ class OrderDistribute
|
||||||
try {
|
try {
|
||||||
DB::beginTransaction();
|
DB::beginTransaction();
|
||||||
$service = new DistributeService();
|
$service = new DistributeService();
|
||||||
$profits = $service->storeByOrder($order);
|
$service->storeByOrder($order);
|
||||||
DB::commit();
|
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) {
|
} catch (Exception $e) {
|
||||||
logger('添加提成记录失败');
|
logger('添加提成记录失败');
|
||||||
logger()->error($e);
|
logger()->error($e);
|
||||||
|
|
|
||||||
|
|
@ -23,7 +23,7 @@ use App\Models\ShippingAddress;
|
||||||
use App\Models\SocialiteUser;
|
use App\Models\SocialiteUser;
|
||||||
use App\Models\Store\{Store, Desk, DeviceRecord};
|
use App\Models\Store\{Store, Desk, DeviceRecord};
|
||||||
use App\Models\UserCoupon;
|
use App\Models\UserCoupon;
|
||||||
use App\Models\{User, OrderPre, Tag};
|
use App\Models\{Agent, User, OrderPre, Tag};
|
||||||
use App\Services\Payment\WxpayService;
|
use App\Services\Payment\WxpayService;
|
||||||
use Illuminate\Database\Eloquent\Builder;
|
use Illuminate\Database\Eloquent\Builder;
|
||||||
use Illuminate\Database\QueryException;
|
use Illuminate\Database\QueryException;
|
||||||
|
|
@ -1240,12 +1240,22 @@ class OrderService
|
||||||
throw new BizException('支付方式 非法');
|
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 = [
|
$params = [
|
||||||
'body' => app_settings('app.app_name').'-商城订单',
|
'body' => app_settings('app.app_name').'-商城订单',
|
||||||
'out_trade_no' => $payLog->pay_sn,
|
'out_trade_no' => $payLog->pay_sn,
|
||||||
'total_fee' => $order->total_amount,
|
'total_fee' => $order->total_amount,
|
||||||
'trade_type' => $tradeType->value,
|
'trade_type' => $tradeType->value,
|
||||||
'profit_sharing' => 'Y',
|
'profit_sharing' => $share,
|
||||||
];
|
];
|
||||||
|
|
||||||
if ($tradeType === WxpayTradeType::JSAPI) {
|
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()) {
|
} elseif ($payLog->isAlipay()) {
|
||||||
$params = [
|
$params = [
|
||||||
'subject' => app_settings('app.app_name').'-商城订单',
|
'subject' => app_settings('app.app_name').'-商城订单',
|
||||||
|
|
|
||||||
|
|
@ -3,6 +3,8 @@
|
||||||
namespace Tests\Feature;
|
namespace Tests\Feature;
|
||||||
|
|
||||||
use App\Enums\PayWay;
|
use App\Enums\PayWay;
|
||||||
|
use App\Models\Agent;
|
||||||
|
use App\Models\User;
|
||||||
use App\Services\DistributeService;
|
use App\Services\DistributeService;
|
||||||
use App\Services\Payment\WxpayService;
|
use App\Services\Payment\WxpayService;
|
||||||
use Illuminate\Support\Facades\DB;
|
use Illuminate\Support\Facades\DB;
|
||||||
|
|
@ -18,8 +20,16 @@ class ExampleTest extends TestCase
|
||||||
*/
|
*/
|
||||||
public function test_example()
|
public function test_example()
|
||||||
{
|
{
|
||||||
$result = ['status' => 'N', 'sn' => '21322132'];
|
$share = 'Y';
|
||||||
dump($result ? array_merge($result, ['status' => 'Y']) : ['status' => '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);
|
$this->assertTrue(true);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue