门店信息

This commit is contained in:
liu
2026-08-10 10:09:51 +08:00
parent df7631c7a9
commit cba0e7d1bb
5 changed files with 171 additions and 18 deletions
File diff suppressed because one or more lines are too long
+35 -11
View File
@@ -4,33 +4,57 @@ namespace App\Http\Controllers\Mini;
use Illuminate\Http\JsonResponse;
use Illuminate\Http\Request;
use Modules\AnnoRoute\Attribute\GetRoute;
use Modules\AnnoRoute\Attribute\PutRoute;
use Modules\AnnoRoute\Attribute\RequestAttribute;
/**
* 小程序门店设置(回款周期自配置,影响对账单应结算日期
* 小程序门店设置(门店信息查看与维护:联系人 / 联系电话 / 地址
*/
#[RequestAttribute('/mini', 'mini', authGuard: 'users')]
class StoreController extends BaseMiniController
{
/** 修改回款周期(≥0,无上限 */
#[PutRoute('/store/paymentCycle', authorize: true)]
public function paymentCycle(Request $request): JsonResponse
/** 门店详情(编辑回显;门店名称 / 编码 / 回款周期为只读,由后台维护 */
#[GetRoute('/store/info', authorize: true)]
public function info(Request $request): JsonResponse
{
$user = $this->currentUser($request);
$store = $this->ensureStoreBound($user);
return $this->success([
'id' => $store->id,
'name' => $store->name,
'code' => $store->code,
'contact' => $store->contact,
'phone' => $store->phone,
'address' => $store->address,
'payment_cycle_days' => $store->payment_cycle_days,
]);
}
/** 修改门店信息(仅联系人 / 联系电话 / 地址,白名单更新) */
#[PutRoute('/store/info', authorize: true)]
public function updateInfo(Request $request): JsonResponse
{
$data = $request->validate([
'payment_cycle_days' => 'required|integer|min:0',
'contact' => 'nullable|string|max:50',
'phone' => 'nullable|string|max:20',
'address' => 'nullable|string|max:255',
], [
'payment_cycle_days.required' => '回款周期不能为空',
'payment_cycle_days.integer' => '回款周期必须为整数',
'payment_cycle_days.min' => '回款周期不能小于 0',
'contact.max' => '联系人最长 50 个字符',
'phone.max' => '联系电话最长 20 个字符',
'address.max' => '地址最长 255 个字符',
]);
$user = $this->currentUser($request);
$store = $this->ensureStoreBound($user);
$store->payment_cycle_days = (int) $data['payment_cycle_days'];
$store->save();
$store->update($data);
return $this->success(['payment_cycle_days' => $store->payment_cycle_days], '回款周期已更新');
return $this->success([
'contact' => $store->contact,
'phone' => $store->phone,
'address' => $store->address,
], '门店信息已更新');
}
}
+110
View File
@@ -0,0 +1,110 @@
<?php
namespace Tests\Feature;
use App\Models\StoreModel;
use App\Models\UserModel;
/**
* 小程序门店设置:详情回显、联系人/电话/地址维护、
* 名称/编码/回款周期等字段不可通过小程序端修改
*/
class MiniStoreTest extends ProcurementTestCase
{
/** 门店详情:返回当前绑定门店信息(含只读回款周期) */
public function test_info_returns_bound_store(): void
{
$store = StoreModel::factory()->paymentCycle(7)->create([
'contact' => '张三',
'phone' => '13800138000',
'address' => '幸福路 1 号',
]);
$this->actingAsMiniUser(UserModel::factory()->forStore($store->id)->create());
$this->getJson('/mini/store/info')
->assertOk()
->assertJsonPath('success', true)
->assertJsonPath('data.id', $store->id)
->assertJsonPath('data.contact', '张三')
->assertJsonPath('data.phone', '13800138000')
->assertJsonPath('data.address', '幸福路 1 号')
->assertJsonPath('data.payment_cycle_days', 7);
}
/** 修改门店信息:联系人 / 电话 / 地址 */
public function test_update_info(): void
{
$store = StoreModel::factory()->create();
$this->actingAsMiniUser(UserModel::factory()->forStore($store->id)->create());
$this->putJson('/mini/store/info', [
'contact' => '李四',
'phone' => '13900139000',
'address' => '建设路 88 号',
])
->assertOk()
->assertJsonPath('success', true)
->assertJsonPath('data.contact', '李四')
->assertJsonPath('data.phone', '13900139000')
->assertJsonPath('data.address', '建设路 88 号');
$fresh = $store->fresh();
$this->assertSame('李四', $fresh->contact);
$this->assertSame('13900139000', $fresh->phone);
$this->assertSame('建设路 88 号', $fresh->address);
}
/** 白名单更新:名称 / 编码 / 回款周期等字段提交后被忽略 */
public function test_update_info_ignores_readonly_fields(): void
{
$store = StoreModel::factory()->paymentCycle(5)->create([
'name' => '原门店',
'code' => 'ST100',
]);
$this->actingAsMiniUser(UserModel::factory()->forStore($store->id)->create());
$this->putJson('/mini/store/info', [
'contact' => '王五',
'name' => '改名门店',
'code' => 'HACK',
'payment_cycle_days' => 99,
])
->assertOk()
->assertJsonPath('success', true);
$fresh = $store->fresh();
$this->assertSame('王五', $fresh->contact);
$this->assertSame('原门店', $fresh->name);
$this->assertSame('ST100', $fresh->code);
$this->assertSame(5, $fresh->payment_cycle_days);
}
/** 未绑定门店 → 拒绝访问 */
public function test_requires_bound_store(): void
{
$this->actingAsMiniUser(UserModel::factory()->create());
$this->getJson('/mini/store/info')
->assertOk()
->assertJsonPath('success', false)
->assertJsonPath('msg', '尚未绑定门店,请联系客服处理');
$this->putJson('/mini/store/info', ['contact' => '路人'])
->assertOk()
->assertJsonPath('success', false);
}
/** 字段长度校验:联系人超过 50 字符 → 校验失败 */
public function test_update_info_validates_length(): void
{
$store = StoreModel::factory()->create();
$this->actingAsMiniUser(UserModel::factory()->forStore($store->id)->create());
$this->putJson('/mini/store/info', ['contact' => str_repeat('长', 51)])
->assertOk()
->assertJsonPath('success', false)
->assertJsonPath('msg', '联系人最长 50 个字符');
$this->assertSame($store->contact, $store->fresh()->contact, '校验失败不应落库');
}
}
+23 -5
View File
@@ -486,19 +486,37 @@ items 每项:
## 7. 门店设置
### 7.1 修改回款周期
### 7.1 门店详情
`PUT /mini/store/paymentCycle`(需登录 + 门店)
`GET /mini/store/info`(需登录 + 门店)
用于门店信息编辑页回显。响应(`data`):
| 字段 | 类型 | 说明 |
|------|------|------|
| id | int | 门店 ID |
| name | string | 门店名称(只读,后台维护) |
| code | string | 门店编码(只读) |
| contact | string | 联系人 |
| phone | string | 联系电话 |
| address | string | 地址 |
| payment_cycle_days | int | 回款周期天数(只读,后台维护) |
### 7.2 修改门店信息
`PUT /mini/store/info`(需登录 + 门店)
请求参数:
| 参数 | 类型 | 必填 | 说明 |
|------|------|------|------|
| payment_cycle_days | int | | 回款周期天数(≥0,无上限;0 = 当天结算 |
| contact | string | | 联系人(≤50 字符 |
| phone | string | 否 | 联系电话(≤20 字符) |
| address | string | 否 | 地址(≤255 字符) |
响应(`data`):`{ "payment_cycle_days": 1 }`,提示「回款周期已更新」。
响应(`data`):`{ "contact": "张三", "phone": "13800138000", "address": "幸福路 1 号" }`,提示「门店信息已更新」。
> 该值影响后续生成对账单的 `settlement_date`(周期结束 + 回款周期天)。
> 仅支持修改联系人 / 电话 / 地址(白名单更新,提交其他字段将被忽略);门店名称、编码、回款周期由后台维护。回款周期影响后续生成对账单的 `settlement_date`(周期结束 + 回款周期天)。
---
+2 -1
View File
@@ -364,7 +364,8 @@ return app(ExportService::class)->download('settlement', $settlement, $format);
| `/mini/statement/generate` | POST | `{period_start, period_end}``StatementGenerateService`——拉周期内订单明细,**快照当前 payment_cycle_dayssettlement_date = period_end + cycle 天**statement_no = ST… |
| `/mini/statement/{id}` | GET | 详情(含单品对账状态标识) |
| `/mini/statement/{id}/export` | GET | `?format=xlsx\|pdf``ExportService::download('statement', ...)`blob |
| `/mini/store/paymentCycle` | PUT | `{payment_cycle_days}`(≥0,无上限 |
| `/mini/store/info` | GET | 门店详情(编辑回显;name/code/payment_cycle_days 只读 |
| `/mini/store/info` | PUT | 修改门店信息:仅 `{contact, phone, address}` 白名单更新;回款周期由后台维护 |
| `/mini/notice` | GET | 本人通知 + 全员广播(`user_id in [0, 当前id]`),分页 + `unread_count` |
| `/mini/notice/{id}/read` | PUT | 标记已读 + read_at |