40 lines
2.0 KiB
PHP
40 lines
2.0 KiB
PHP
<?php
|
||
|
||
namespace App\Console\Commands;
|
||
|
||
use Illuminate\Console\Command;
|
||
use Illuminate\Support\Facades\DB;
|
||
|
||
class JstCount extends Command
|
||
{
|
||
protected $signature = 'jst:count';
|
||
protected $description = '发货数据本地表统计';
|
||
|
||
public function handle(): int
|
||
{
|
||
$c = DB::connection((string) config('jushuitan.connection', 'jushuitan_local'));
|
||
$t = fn () => $c->table('jst_oms_shipping');
|
||
$this->line('明细行数 total='.$t()->count());
|
||
$this->line('包裹数(distinct source_id)='.$t()->distinct()->count('source_id'));
|
||
$this->line('自动发货仓行(source>=1e9)='.$t()->where('source_id', '>=', 1000000000)->count());
|
||
$this->line('补差残留='.$t()->where('product_name', 'like', '%补收差价%')->count());
|
||
$this->line('快递单号非空='.$t()->whereNotNull('express_no')->where('express_no', '<>', '')->count());
|
||
$this->line('件数pkg_count非空='.$t()->whereNotNull('pkg_count')->where('pkg_count', '<>', '')->count());
|
||
// 多件包裹数(pkg_count 不是 1/1)
|
||
$multi = $t()->where('pkg_count', 'not like', '1/1')->where('pkg_count', 'like', '1/%')->distinct()->count('source_id');
|
||
$this->line('多件包裹数(件数≠1/1)='.$multi);
|
||
// 一个多件包裹样例
|
||
$sample = $t()->where('pkg_count', 'like', '1/%')->where('pkg_count', '<>', '1/1')->orderByDesc('source_id')->first();
|
||
if ($sample) {
|
||
$rows = $t()->where('source_id', $sample->source_id)->get(['barcode', 'product_name', 'qty', 'pkg_count', 'actual_weight', 'freight', 'volume_cm3']);
|
||
$this->line('--- 样例多件包裹 source_id='.$sample->source_id.' 快递单号='.$sample->express_no.' ---');
|
||
foreach ($rows as $r) {
|
||
$this->line(sprintf(' 条码=%s 名称=%s 数量=%s 件数=%s 实称=%s 运费=%s 体积=%s',
|
||
$r->barcode, mb_substr((string) $r->product_name, 0, 12), $r->qty, $r->pkg_count, $r->actual_weight, $r->freight, $r->volume_cm3));
|
||
}
|
||
}
|
||
|
||
return self::SUCCESS;
|
||
}
|
||
}
|