kernel
parent
5aca2d4119
commit
c23990f7d3
|
|
@ -2,9 +2,7 @@
|
||||||
|
|
||||||
namespace App\Console\Commands;
|
namespace App\Console\Commands;
|
||||||
|
|
||||||
use App\Enums\PayWay;
|
|
||||||
use App\Models\Order;
|
use App\Models\Order;
|
||||||
use App\Models\OrderProfit;
|
|
||||||
use App\Services\DistributeService;
|
use App\Services\DistributeService;
|
||||||
use Illuminate\Console\Command;
|
use Illuminate\Console\Command;
|
||||||
use Illuminate\Support\Facades\DB;
|
use Illuminate\Support\Facades\DB;
|
||||||
|
|
@ -16,7 +14,7 @@ class OrderProfitCommand extends Command
|
||||||
*
|
*
|
||||||
* @var string
|
* @var string
|
||||||
*/
|
*/
|
||||||
protected $signature = 'order:profit';
|
protected $signature = 'order-profit:send';
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* The console command description.
|
* The console command description.
|
||||||
|
|
@ -47,43 +45,29 @@ class OrderProfitCommand extends Command
|
||||||
|
|
||||||
// 售后过期天数 7
|
// 售后过期天数 7
|
||||||
$saleDays = app_settings('app.sale_after_expire_days');
|
$saleDays = app_settings('app.sale_after_expire_days');
|
||||||
while (true) {
|
$orders = Order::query()
|
||||||
$page = 0;
|
// 订单已完成
|
||||||
|
->where('status', Order::STATUS_COMPLETED)
|
||||||
|
// 没有售后订单
|
||||||
|
->whereDoesntHave('afterSales')
|
||||||
|
// 售后期过了
|
||||||
|
->where('completed_at', '<', now()->subDays($saleDays))
|
||||||
|
// 未支付提成
|
||||||
|
->whereNull('profit_paid')
|
||||||
|
->limit(10)
|
||||||
|
->get();
|
||||||
|
|
||||||
$orders = Order::query()
|
foreach ($orders as $order) {
|
||||||
// 订单已完成
|
try {
|
||||||
->where('status', Order::STATUS_COMPLETED)
|
DB::beginTransaction();
|
||||||
// 没有售后订单
|
$service->wechatShare($order);
|
||||||
->whereDoesntHave('afterSales')
|
// 分账成功, 更新订单状态
|
||||||
// 售后期过了
|
$order->update(['profit_paid' => $now]);
|
||||||
->where('completed_at', '<', now()->subDays($saleDays))
|
DB::commit();
|
||||||
// 未支付提成
|
} catch (\Exception $e) {
|
||||||
->whereNull('profit_paid')
|
DB::rollBack();
|
||||||
->limit(10)
|
report($e);
|
||||||
->get();
|
$this->error($e->getMessage());
|
||||||
|
|
||||||
foreach ($orders as $order) {
|
|
||||||
try {
|
|
||||||
DB::beginTransaction();
|
|
||||||
$service->wechatShare($order);
|
|
||||||
// 分账成功, 更新订单状态
|
|
||||||
$order->update(['profit_paid' => $now]);
|
|
||||||
DB::commit();
|
|
||||||
} catch (\Exception $e) {
|
|
||||||
DB::rollBack();
|
|
||||||
report($e);
|
|
||||||
$this->error($e->getMessage());
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
$page++;
|
|
||||||
|
|
||||||
if ($page === 0) {
|
|
||||||
sleep(60);
|
|
||||||
} elseif ($page === 1) {
|
|
||||||
sleep(30);
|
|
||||||
} else {
|
|
||||||
sleep(15);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -24,6 +24,7 @@ class Kernel extends ConsoleKernel
|
||||||
*/
|
*/
|
||||||
protected function schedule(Schedule $schedule)
|
protected function schedule(Schedule $schedule)
|
||||||
{
|
{
|
||||||
|
$schedule->command('order-profit:send')->daily();
|
||||||
$schedule->command('order-profit:check')->daily();
|
$schedule->command('order-profit:check')->daily();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue