更新代码
This commit is contained in:
114
app/Console/Commands/OrderDataCommand.php
Normal file
114
app/Console/Commands/OrderDataCommand.php
Normal file
@@ -0,0 +1,114 @@
|
||||
<?php
|
||||
|
||||
namespace App\Console\Commands;
|
||||
|
||||
use App\Models\SalesReport;
|
||||
use App\Models\Seller;
|
||||
use Carbon\Carbon;
|
||||
use Illuminate\Console\Command;
|
||||
use Illuminate\Support\Facades\DB;
|
||||
use RuLong\Order\Models\Order;
|
||||
use RuLong\Order\Models\OrderDetail;
|
||||
|
||||
class OrderDataCommand extends Command
|
||||
{
|
||||
/**
|
||||
* The name and signature of the console command.
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
protected $signature = 'rulong:OrderDataCommand';
|
||||
|
||||
/**
|
||||
* The console command description.
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
protected $description = 'Command description';
|
||||
|
||||
/**
|
||||
* Create a new command instance.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function __construct()
|
||||
{
|
||||
parent::__construct();
|
||||
}
|
||||
|
||||
/**
|
||||
* Execute the console command.
|
||||
*
|
||||
* @return mixed
|
||||
*/
|
||||
public function handle()
|
||||
{
|
||||
$sellerids = Seller::get();
|
||||
$starta = Carbon::yesterday()->toDateString();
|
||||
foreach ($sellerids as $key => $seller) {
|
||||
$seller_id = $seller->id;
|
||||
$start = date($starta, strtotime('-1 day'));
|
||||
$end = date($starta);
|
||||
$orderids[$key] = Order::when($seller_id, function ($q) use ($seller_id) {$q->where('seller_id', $seller_id);})
|
||||
->whereHas('logs', function ($query) use ($start, $end) {
|
||||
$query->where('state', 'DELIVERED|SIGNED')->when($start && $end, function ($query) use ($start, $end) {
|
||||
$query->whereBetween('created_at', [$start, date('Y-m-d', strtotime("+1 days", strtotime($end)))]);
|
||||
})
|
||||
->when($start && !$end, function ($query) use ($start) {
|
||||
$query->where('created_at', '>=', $start);
|
||||
})
|
||||
->when((!$start && $end), function ($query) use ($end) {
|
||||
$query->where('created_at', '<=', date('Y-m-d', strtotime("+1 days", strtotime($end))));
|
||||
});
|
||||
})->where('state', '<>',Order::ORDER_CLOSED)->pluck('id');
|
||||
if (!empty($orderids[$key])) {
|
||||
self::insertReport($orderids[$key], 'SIGNED', $starta, $seller_id);
|
||||
}
|
||||
|
||||
$orderDeliveredids[$key] = Order::when($seller_id, function ($q) use ($seller_id) {$q->where('seller_id', $seller_id);})
|
||||
->whereHas('logs', function ($query) use ($start, $end) {
|
||||
$query->where('state', 'PAID|DELIVERED')->when($start && $end, function ($query) use ($start, $end) {
|
||||
$query->whereBetween('created_at', [$start, date('Y-m-d', strtotime("+1 days", strtotime($end)))]);
|
||||
})
|
||||
->when($start && !$end, function ($query) use ($start) {
|
||||
$query->where('created_at', '>=', $start);
|
||||
})
|
||||
->when((!$start && $end), function ($query) use ($end) {
|
||||
$query->where('created_at', '<=', date('Y-m-d', strtotime("+1 days", strtotime($end))));
|
||||
});
|
||||
})->where('state', '<>',Order::ORDER_CLOSED)->pluck('id');
|
||||
if (!empty($orderids[$key])) {
|
||||
self::insertReport($orderDeliveredids[$key], 'DELIVERED', $starta, $seller_id);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
private static function insertReport($orderids, $type, $starta, $seller_id)
|
||||
{
|
||||
$detail = OrderDetail::select(DB::raw('sum(number) as number_sum, sum(score * number) as score_sum, sum(price * number) as price_sum, sum(seller_price * number) as seller_price_sum'))
|
||||
->whereIn('order_id', $orderids)->first();
|
||||
if (!empty($detail) && $detail->number_sum) {
|
||||
$order = Order::select(DB::raw('count(*) as order_total, sum(freight) as freight_sum, sum(seller_freight) as seller_freight_sum, sum(amount) as orders_price, sum(score) as orders_score,sum(seller_amount) as seller_amount_sum'))
|
||||
->whereIn('id', $orderids)->first();
|
||||
$report = SalesReport::where(['seller_id' => $seller_id, 'state' => $type, 'action_time' => $starta])->first();
|
||||
if (empty($report)) {
|
||||
SalesReport::create([
|
||||
'state' => $type,
|
||||
'action_time' => $starta,
|
||||
'goods_total' => $detail->number_sum,
|
||||
'goods_price_total' => $detail->price_sum,
|
||||
'goods_score_total' => $detail->score_sum,
|
||||
'orders_total' => $order->order_total,
|
||||
'orders_price' => $order->orders_price,
|
||||
'orders_score' => $order->orders_score,
|
||||
'orders_freight' => $order->freight_sum,
|
||||
'seller_id' => $seller_id,
|
||||
'seller_total' => $order->seller_amount_sum,
|
||||
'seller_freight' => $order->seller_freight_sum,
|
||||
]);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
59
app/Console/Commands/ProfitCommand.php
Normal file
59
app/Console/Commands/ProfitCommand.php
Normal file
@@ -0,0 +1,59 @@
|
||||
<?php
|
||||
|
||||
namespace App\Console\Commands;
|
||||
|
||||
use App\Jobs\ProfitJob;
|
||||
use App\Models\ProfitLog;
|
||||
use Carbon\Carbon;
|
||||
use Illuminate\Console\Command;
|
||||
use RuLong\Identity\Models\IdentityPoint;
|
||||
|
||||
class ProfitCommand extends Command
|
||||
{
|
||||
/**
|
||||
* The name and signature of the console command.
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
protected $signature = 'rulong:ProfitCommand';
|
||||
|
||||
/**
|
||||
* The console command description.
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
protected $description = 'Command description';
|
||||
|
||||
/**
|
||||
* Create a new command instance.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function __construct()
|
||||
{
|
||||
parent::__construct();
|
||||
}
|
||||
|
||||
/**
|
||||
* Execute the console command.
|
||||
*
|
||||
* @return mixed
|
||||
*/
|
||||
public function handle()
|
||||
{
|
||||
ProfitLog::getnow();
|
||||
|
||||
$info = ProfitLog::where('created_at', Carbon::yesterday()->toDateTimeString())->where('status', 0)->first();
|
||||
|
||||
if ($info) {
|
||||
if ($info->price > 0) {
|
||||
$users = IdentityPoint::where('created_at', '<', $info->end_at)->distinct()->pluck('user_id');
|
||||
foreach ($users as $key => $user_id) {
|
||||
ProfitJob::dispatch($user_id, $info);
|
||||
}
|
||||
}
|
||||
$info->status = 1;
|
||||
$info->save();
|
||||
}
|
||||
}
|
||||
}
|
||||
52
app/Console/Commands/WindupReportCommand.php
Normal file
52
app/Console/Commands/WindupReportCommand.php
Normal file
@@ -0,0 +1,52 @@
|
||||
<?php
|
||||
|
||||
namespace App\Console\Commands;
|
||||
|
||||
use App\Models\SalesReport;
|
||||
use App\Models\Seller;
|
||||
use App\Models\WindupReport;
|
||||
use Carbon\Carbon;
|
||||
use Illuminate\Console\Command;
|
||||
use Illuminate\Support\Facades\DB;
|
||||
use RuLong\Order\Models\Order;
|
||||
use RuLong\Order\Models\OrderDetail;
|
||||
|
||||
class WindupReportCommand extends Command
|
||||
{
|
||||
/**
|
||||
* The name and signature of the console command.
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
protected $signature = 'rulong:WindupReportCommand';
|
||||
|
||||
/**
|
||||
* The console command description.
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
protected $description = 'Command description';
|
||||
|
||||
/**
|
||||
* Create a new command instance.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function __construct()
|
||||
{
|
||||
parent::__construct();
|
||||
}
|
||||
|
||||
/**
|
||||
* Execute the console command.
|
||||
*
|
||||
* @return mixed
|
||||
*/
|
||||
public function handle()
|
||||
{
|
||||
$report = new WindupReport();
|
||||
$report->autoReport();
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
47
app/Console/Kernel.php
Normal file
47
app/Console/Kernel.php
Normal file
@@ -0,0 +1,47 @@
|
||||
<?php
|
||||
|
||||
namespace App\Console;
|
||||
|
||||
use Illuminate\Console\Scheduling\Schedule;
|
||||
use Illuminate\Foundation\Console\Kernel as ConsoleKernel;
|
||||
|
||||
class Kernel extends ConsoleKernel
|
||||
{
|
||||
/**
|
||||
* The Artisan commands provided by your application.
|
||||
*
|
||||
* @var array
|
||||
*/
|
||||
protected $commands = [
|
||||
//
|
||||
];
|
||||
|
||||
/**
|
||||
* Define the application's command schedule.
|
||||
*
|
||||
* @param \Illuminate\Console\Scheduling\Schedule $schedule
|
||||
* @return void
|
||||
*/
|
||||
protected function schedule(Schedule $schedule)
|
||||
{
|
||||
// $schedule->command('inspire')
|
||||
// ->hourly();
|
||||
$schedule->command('rulong:ProfitCommand')->dailyAt('22:00'); //总裁,总裁导师,创始总裁分红定时任务
|
||||
$schedule->command('rulong:OrderDataCommand')->dailyAt('1:00');//每日签收汇总、发货汇总记录生成
|
||||
$schedule->command('rulong:WindupReportCommand')->monthlyOn(1, '2:00');;//每个月1日生成上个月16日-月末的结算记录。
|
||||
$schedule->command('rulong:WindupReportCommand')->monthlyOn(16, '2:00');;//每个月16日生成1-15日结算记录。
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Register the commands for the application.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
protected function commands()
|
||||
{
|
||||
$this->load(__DIR__ . '/Commands');
|
||||
|
||||
require base_path('routes/console.php');
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user