6
0
Fork 0
jiqu-library-server/app/Console/Commands/OrderProfitCommand.php

76 lines
1.8 KiB
PHP

<?php
namespace App\Console\Commands;
use App\Models\Order;
use App\Services\DistributeService;
use Illuminate\Console\Command;
use Illuminate\Support\Facades\DB;
class OrderProfitCommand extends Command
{
/**
* The name and signature of the console command.
*
* @var string
*/
protected $signature = 'order-profit:send';
/**
* The console command description.
*
* @var string
*/
protected $description = '售后期结束的订单, 发放提成部分';
/**
* Create a new command instance.
*
* @return void
*/
public function __construct()
{
parent::__construct();
}
/**
* Execute the console command.
*
* @return int
*/
public function handle()
{
$service = new DistributeService();
$now = now();
// 售后过期天数 7
$saleDays = app_settings('app.sale_after_expire_days');
$orders = Order::query()
// 订单已完成
->where('status', Order::STATUS_COMPLETED)
// 没有售后订单
->whereDoesntHave('afterSales')
// 售后期过了
->where('completed_at', '<', now()->subDays($saleDays))
// 未支付提成
->whereNull('profit_paid')
// 微信分账订单
->where('wx_share->status', 'Y')
->limit(10)
->get();
foreach ($orders as $order) {
try {
DB::beginTransaction();
$service->wechatShare($order);
DB::commit();
} catch (\Exception $e) {
logger('app/Console/Commands/OrderProfitCommand error');
DB::rollBack();
report($e);
$this->error($e->getMessage());
}
}
}
}