- 报销金额公式:空包费改为加(任务付款+快递费+佣金+京喜差价−扣款+空包费) - 去掉「以旧换新超买家实付」「查不到标签待复查」两项校验 - 种菜额度不再上传看板:按《种菜明细报表生成逻辑》(业务交付包 2026-11-27)自算, 商品ID→ID负责人、职级、店铺信息直接只读查经营分析副本库(JSReportReplica.rpt), 金额取实付金额字段(同看板);单笔/每日/月度超额、未匹配负责人、职级为空、职级未配置、 额度规则未配置全部取消;额度数据取不到时整批待复查 - 额度规则 309 条(脉象导出)随代码初始化,工作台可新增/修改/删除/整体导入/导出 - 利润中心直接读工作平台店铺信息(rpt.fys_shopInfo),查不到改为待复查;去掉店铺信息、看板上传 - 种菜任务工单导入模板执行人统一填李斯 - 每日群汇总推送改到 11:20(部署脚本 cron) - 用看板 11 月 1–27 日 13,941 单对照:规则来源、日/月累计、风险类型逐单一致 Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01UNTa9ohkCsVFACqjz3KMcG
108 lines
5.5 KiB
PHP
108 lines
5.5 KiB
PHP
<?php
|
||
|
||
namespace App\Console\Commands;
|
||
|
||
use App\Models\Common\Company;
|
||
use Illuminate\Console\Command;
|
||
use Illuminate\Support\Facades\Cache;
|
||
use Modules\EcommerceFinance\Repositories\PlantingReimbursementRepository as Repository;
|
||
use Modules\EcommerceFinance\Services\PlantingReimbursementAuditor as Auditor;
|
||
use Modules\EcommerceFinance\Services\PlantingReimbursementRobot as Robot;
|
||
use Modules\EcommerceFinance\Services\PlantingReimbursementWorkbench as Workbench;
|
||
use Throwable;
|
||
|
||
/** 每天 11:20 生成当天种菜报销批次,把核对数、可报销合计、要取消的单和自检结果推到钉钉群并 @ 报销人。只读,不改聚工单。 */
|
||
class PlantingReimbursementDailyDigest extends Command
|
||
{
|
||
protected $signature = 'planting-reimbursement:daily-digest
|
||
{--date= : 报销日期 Y-m-d,默认今天}
|
||
{--dry-run : 只打印消息,不发送}
|
||
{--force : 忽略当天已推送标记}';
|
||
|
||
protected $description = '推送当天种菜报销批次汇总到钉钉群';
|
||
|
||
public function handle(Workbench $workbench, Robot $robot, Repository $repository): int
|
||
{
|
||
$date = trim((string) $this->option('date')) ?: Workbench::defaultDate();
|
||
try {
|
||
Workbench::parseDate($date);
|
||
} catch (Throwable $exception) {
|
||
$this->error($exception->getMessage());
|
||
|
||
return self::FAILURE;
|
||
}
|
||
|
||
$failed = false;
|
||
foreach (Company::enabled()->orderBy('id')->get() as $company) {
|
||
$company->makeCurrent();
|
||
if (! $robot->enabled()) {
|
||
$this->line("#{$company->id}: 未配置种菜报销群机器人,跳过");
|
||
continue;
|
||
}
|
||
$lock = "planting-reimbursement:digest:{$company->id}:{$date}";
|
||
if (! $this->option('dry-run') && ! $this->option('force') && ! Cache::add($lock, now()->toDateTimeString(), now()->addDay())) {
|
||
$this->line("#{$company->id}: {$date} 已推送过");
|
||
continue;
|
||
}
|
||
|
||
try {
|
||
[$title, $text] = $this->message($workbench, $repository, (int) $company->id, $date);
|
||
if ($this->option('dry-run')) {
|
||
$this->line($title . "\n" . $text);
|
||
continue;
|
||
}
|
||
$robot->sendDigest($title, $text);
|
||
$this->info("#{$company->id}: 已推送 {$date} 汇总");
|
||
} catch (Throwable $exception) {
|
||
Cache::forget($lock);
|
||
report($exception);
|
||
$this->error("#{$company->id}: 推送失败:" . $exception->getMessage());
|
||
$failed = true;
|
||
}
|
||
}
|
||
|
||
return $failed ? self::FAILURE : self::SUCCESS;
|
||
}
|
||
|
||
/** @return array{0:string,1:string} */
|
||
private function message(Workbench $workbench, Repository $repository, int $companyId, string $date): array
|
||
{
|
||
$sync = $repository->syncStatus();
|
||
$url = route('business.pages.show', ['company_id' => $companyId, 'section' => 'planting-data', 'page' => 'planting-reimbursement-workbench', 'date' => $date]);
|
||
$title = '种菜报销 ' . $date . ' 批次';
|
||
$lines = ['#### ' . $title];
|
||
|
||
$stale = $sync['code'] !== 'ready' || $sync['last_succeeded_at'] === null
|
||
|| now()->diffInMinutes(\Illuminate\Support\Carbon::parse($sync['last_succeeded_at']), true) > 20;
|
||
if ($stale) {
|
||
$lines[] = '> **聚工单数据不是最新的**(最后同步成功:' . ($sync['last_succeeded_at'] ? substr($sync['last_succeeded_at'], 0, 16) : '无') . '),先别按下面结果报销。';
|
||
}
|
||
if (! in_array($sync['code'], ['ready', 'failed'], true)) {
|
||
$lines[] = '- 聚工单镜像未就绪,暂时无法生成批次。';
|
||
$lines[] = '- [打开工作台](' . $url . ')';
|
||
|
||
return [$title, implode("\n", $lines)];
|
||
}
|
||
|
||
$result = $workbench->build($companyId, $date);
|
||
$s = $result['summary'];
|
||
$lines[] = '- 待处理(付款 ' . substr($result['window']['from'], 0, 10) . ' ~ ' . substr($result['window']['to'], 0, 10) . '):**' . $s['source']['count'] . ' 条 / ' . number_format((float) $s['source']['amount'], 2) . ' 元**,请先在聚工单核对';
|
||
$lines[] = '- 可报销:' . $s['counts'][Auditor::DECISION_PASS] . ' 条 / **' . number_format((float) $s['total'], 2) . ' 元**(三大天猫 ' . number_format((float) $s['group_amounts'][Auditor::GROUP_BIG_TMALL], 2) . ',其他 ' . number_format((float) $s['group_amounts'][Auditor::GROUP_OTHER], 2) . ')';
|
||
$lines[] = '- 取消工单:' . $s['counts'][Auditor::DECISION_CANCEL] . ' 条;待复查:' . $s['counts'][Auditor::DECISION_RECHECK] . ' 条';
|
||
$bad = array_column(array_filter($s['checks'], static fn (array $check): bool => ! $check['ok']), 'label');
|
||
$lines[] = '- 自检:' . ($bad === [] ? '全部通过' : '未通过 ' . implode('、', $bad));
|
||
if (($result['quota_error'] ?? '') !== '') {
|
||
$lines[] = '- **种菜额度没有校验**(' . $result['quota_error'] . '),相关工单都在待复查,先别报销';
|
||
}
|
||
if (($result['shop_source'] ?? '') === 'mirror') {
|
||
$lines[] = '- 工作平台店铺信息暂时读不到,利润中心用的是前一天同步的数据';
|
||
}
|
||
if (($result['roster_source'] ?? '') === 'none') {
|
||
$lines[] = '- 取不到在职名单,收款人在职未校验';
|
||
}
|
||
$lines[] = '- [打开工作台核对](' . $url . ')';
|
||
|
||
return [$title, implode("\n", $lines)];
|
||
}
|
||
}
|