CaiWuXiTong/tests/Unit/EcommerceFinance/PlantingDingTalkFormTest.php
limeng b5244362a1 feat(种菜报销): 佣金人员可维护、自动放行检查、自动发通知、一键提交钉钉流程
- 报销佣金人员改为工作台维护(新增 / 移除 / 追加导入 / 导出),首次读取时自动导入以前上传的历史名单
- 去掉「去聚工单人工核对、勾选已核对」:改为放行检查(聚工单 20 分钟内同步过、额度已校验、
  规则不为空、自检全过、有可报销单),不通过不许导出 / 发通知 / 提交,并在页面列出原因
- 每天 11:20 汇总任务放行检查通过后自动发不予报销通知(@ 发起人,同一批不重发)
- 一键提交钉钉「种菜报销流程」(PROC-C5159B8D…):发起人李斯(按钉钉花名册查 userId),
  按钉钉表单实际结构自动填(收款费用明细 / 收款合计 / 收款人·开户行·账号=账号详见附件 /
  付款明细 / 报销类型=种菜核销),打款明细 xlsx 上传审批钉盘作附件;先可预览,
  缺必填 / 选项不匹配不许提交;同一账单日只提交一次,结果不确定记待核查
- 新配置 config/planting_reimbursement.php(凭据默认沿用快递入驻的财务系统钉钉应用,
  需补 PLANTING_DINGTALK_AGENT_ID)

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01UNTa9ohkCsVFACqjz3KMcG
2026-12-01 05:56:51 +00:00

92 lines
5.5 KiB
PHP
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

<?php
namespace Tests\Unit\EcommerceFinance;
use Modules\EcommerceFinance\Services\PlantingDingTalkForm as Form;
use PHPUnit\Framework\TestCase;
class PlantingDingTalkFormTest extends TestCase
{
/** 结构仿照钉钉表单接口返回(schemaContent.items)。 */
public static function schema(): array
{
$field = static fn (string $type, string $label, bool $required = true, array $extra = []): array => ['componentName' => $type, 'props' => ['label' => $label, 'required' => $required] + $extra];
return [
$field('TextNote', '说明'),
$field('DDSelectField', '报销类型', true, ['options' => [['key' => 'a', 'value' => '种菜核销'], ['key' => 'b', 'value' => '日常报销']]]),
['componentName' => 'TableField', 'props' => ['label' => '收款费用明细', 'required' => true], 'children' => [
$field('NumberField', '序号'),
$field('DepartmentField', '费用承担部门(利润中心)'),
$field('TextField', '店铺'),
$field('TextField', '用途'),
$field('MoneyField', '收款金额'),
$field('TextField', '备注', false),
]],
$field('MoneyField', '收款合计'),
$field('TextField', '收款人'),
$field('TextField', '开户行'),
$field('TextField', '账号'),
['componentName' => 'TableField', 'props' => ['label' => '付款明细', 'required' => false], 'children' => [
$field('TextField', '对应序号'),
$field('MoneyField', '付款金额'),
$field('DDSelectField', '付款方式', true, ['options' => ['{"key":"1","value":"银行卡"}', '{"key":"2","value":"支付宝"}']]),
$field('DDDateField', '打款时间', false),
]],
$field('DDAttachment', '附件'),
];
}
public static function summary(): array
{
return [
'bill_date' => '2026-11-11', 'purpose' => '11.11种菜报销', 'total' => '130.50',
'ding_lines' => [
['department' => '运营中心A', 'shop' => '欧意朗', 'purpose' => '11.11种菜报销', 'payment_method' => '银行卡', 'cents' => 10050],
['department' => '运营中心G', 'shop' => '其他', 'purpose' => '11.11种菜报销', 'payment_method' => '银行卡', 'cents' => 3000],
],
];
}
public function test_fills_form_by_labels_and_attachment(): void
{
$attachment = ['spaceId' => 'S1', 'fileName' => '种菜报销明细11.11.xlsx', 'fileSize' => '123', 'fileType' => 'xlsx', 'fileId' => 'F1'];
$result = (new Form())->build(self::schema(), self::summary(), $attachment, '种菜报销明细11.11.xlsx');
$this->assertSame([], $result['missing']);
$this->assertSame([], $result['invalid']);
$values = array_column($result['values'], 'value', 'name');
$this->assertSame('种菜核销', $values['报销类型']);
$this->assertSame('130.50', $values['收款合计']);
$this->assertSame('账号详见附件', $values['收款人']);
$this->assertSame('账号详见附件', $values['账号']);
$this->assertSame([
[['name' => '序号', 'value' => '1'], ['name' => '费用承担部门(利润中心)', 'value' => '运营中心A'], ['name' => '店铺', 'value' => '欧意朗'], ['name' => '用途', 'value' => '11.11种菜报销'], ['name' => '收款金额', 'value' => '100.50']],
[['name' => '序号', 'value' => '2'], ['name' => '费用承担部门(利润中心)', 'value' => '运营中心G'], ['name' => '店铺', 'value' => '其他'], ['name' => '用途', 'value' => '11.11种菜报销'], ['name' => '收款金额', 'value' => '30.00']],
], json_decode($values['收款费用明细'], true));
$this->assertSame([[['name' => '对应序号', 'value' => '1-2'], ['name' => '付款金额', 'value' => '130.50'], ['name' => '付款方式', 'value' => '银行卡']]], json_decode($values['付款明细'], true));
$this->assertSame([$attachment], json_decode($values['附件'], true));
$this->assertArrayNotHasKey('说明', $values);
// 预览时不带附件:不出附件值,但不算缺字段。
$preview = (new Form())->build(self::schema(), self::summary(), null, '种菜报销明细11.11.xlsx');
$this->assertSame([], $preview['missing']);
$this->assertArrayNotHasKey('附件', array_column($preview['values'], 'value', 'name'));
}
public function test_reports_required_fields_it_cannot_fill_and_bad_options(): void
{
$schema = self::schema();
$schema[] = ['componentName' => 'DDDateField', 'props' => ['label' => '报销日期', 'required' => true]];
$schema[1]['props']['options'] = [['key' => 'b', 'value' => '日常报销']];
array_pop($schema[2]['children']);
$schema[2]['children'][] = ['componentName' => 'TextField', 'props' => ['label' => '经办人', 'required' => true]];
$withoutAttachment = array_values(array_filter($schema, static fn (array $item): bool => $item['componentName'] !== 'DDAttachment'));
$result = (new Form())->build($withoutAttachment, self::summary(), null, 'x.xlsx');
$this->assertSame(['收款费用明细 → 经办人', '报销日期', '附件(表单里没有附件字段,无法附上打款明细)'], $result['missing']);
$this->assertSame(['报销类型(选项里没有「种菜核销」)'], $result['invalid']);
}
}