- 新增种菜应收对账完整CRUD:21字段对账数据表 - 字段:日期、种菜订单编号、财务售价/运费/佣金/空包费/打款金额、 京喜差价、扣款、正确店铺、负责人、创建人、所属利润中心、 负责平台、ID、店铺、财务备注、支付宝订单、账单项目、 收入金额、差异数据 - 表单分4组:基本信息、财务数据、店铺与人员、收款与差异 - 修改Business\Pages支持无tabs页面加载内容 - 路由:zhongcai-reconciliations 路由组
184 lines
5.8 KiB
PHP
184 lines
5.8 KiB
PHP
<?php
|
||
|
||
namespace App\Http\Controllers\Business;
|
||
|
||
use App\Models\Banking\MarketingAccountBill;
|
||
use App\Models\Banking\MarketingTaobaoAlipayBill;
|
||
use App\Models\Banking\MarketingPinduoduoBill;
|
||
use App\Models\StoreReceivables\StoreZhongcaiReconciliation;
|
||
use App\Utilities\SidebarPermissions;
|
||
use Illuminate\Routing\Controller;
|
||
|
||
class Pages extends Controller
|
||
{
|
||
|
||
/**
|
||
* 支持的营销账户平台列表
|
||
*/
|
||
protected const MARKETING_PLATFORMS = [
|
||
'taobao-alipay', 'taobao-wechat', 'pinduoduo',
|
||
'jd-wallet', 'douyin', 'dewu', 'vipshop',
|
||
];
|
||
public function home()
|
||
{
|
||
$section = collect(SidebarPermissions::navigationFor(user()))->first();
|
||
|
||
abort_if(empty($section), 403, '当前账号没有已授权的侧边栏功能。');
|
||
|
||
$page = collect($section['pages'] ?? [])->first();
|
||
$parameters = ['section' => $section['slug']];
|
||
|
||
if ($page) {
|
||
$parameters['page'] = $page['slug'];
|
||
|
||
if (! empty($page['tabs'])) {
|
||
$parameters['tab'] = $page['tabs'][0]['slug'];
|
||
}
|
||
}
|
||
|
||
return redirect()->route('business.pages.show', $parameters);
|
||
}
|
||
|
||
public function show(string $section, ?string $page = null, ?string $tab = null)
|
||
{
|
||
$sectionConfig = collect(SidebarPermissions::navigationFor(user()))->firstWhere('slug', $section);
|
||
|
||
abort_if(empty($sectionConfig), 403, '当前账号没有该页面权限。');
|
||
|
||
$pages = collect($sectionConfig['pages'] ?? []);
|
||
|
||
if ($pages->isEmpty()) {
|
||
abort_if($page !== null || $tab !== null, 404);
|
||
|
||
return view('business.pages.show', [
|
||
'section' => $sectionConfig,
|
||
'page' => null,
|
||
'tabs' => collect(),
|
||
'activeTab' => null,
|
||
]);
|
||
}
|
||
|
||
if ($page === null) {
|
||
return $this->redirectToPage($sectionConfig, $pages->first());
|
||
}
|
||
|
||
$pageConfig = $pages->firstWhere('slug', $page);
|
||
|
||
abort_if(empty($pageConfig), 404);
|
||
|
||
$tabs = collect($pageConfig['tabs'] ?? []);
|
||
|
||
if ($tabs->isEmpty()) {
|
||
abort_if($tab !== null, 404);
|
||
|
||
$content = $this->resolveContent($page, null);
|
||
|
||
return view('business.pages.show', [
|
||
'section' => $sectionConfig,
|
||
'page' => $pageConfig,
|
||
'tabs' => $tabs,
|
||
'activeTab' => null,
|
||
'content' => $content,
|
||
]);
|
||
}
|
||
|
||
if ($tab === null) {
|
||
return $this->redirectToPage($sectionConfig, $pageConfig);
|
||
}
|
||
|
||
$activeTab = $tabs->firstWhere('slug', $tab);
|
||
|
||
abort_if(empty($activeTab), 404);
|
||
|
||
$content = $this->resolveContent($page, $tab);
|
||
|
||
return view('business.pages.show', [
|
||
'section' => $sectionConfig,
|
||
'page' => $pageConfig,
|
||
'tabs' => $tabs,
|
||
'activeTab' => $activeTab,
|
||
'content' => $content,
|
||
]);
|
||
}
|
||
|
||
/**
|
||
* 根据页面和标签加载对应的业务内容数据
|
||
*/
|
||
protected function resolveContent(string $page, ?string $tab): ?array
|
||
{
|
||
return match ($page) {
|
||
'marketing-account-bills' => $this->contentForMarketingAccountBills($tab),
|
||
'zhongcai-reconciliation' => $this->contentForZhongcaiReconciliation(),
|
||
default => null,
|
||
};
|
||
}
|
||
|
||
/**
|
||
* 种菜应收对账 - 加载对账数据(21字段)
|
||
*/
|
||
protected function contentForZhongcaiReconciliation(): ?array
|
||
{
|
||
return [
|
||
'view' => 'store_receivables.zhongcai_reconciliations.partials.embedded-table',
|
||
'records' => StoreZhongcaiReconciliation::orderBy('bill_date', 'desc')
|
||
->orderBy('id', 'desc')
|
||
->paginate(setting('default.list_limit', 25)),
|
||
];
|
||
}
|
||
|
||
/**
|
||
* 营销账户账单 - 加载指定平台的数据
|
||
* 淘系支付宝、拼多多使用独立的流水账单表,其他平台使用通用汇总账单表
|
||
*/
|
||
protected function contentForMarketingAccountBills(string $tab): ?array
|
||
{
|
||
if (!in_array($tab, self::MARKETING_PLATFORMS, true)) {
|
||
return null;
|
||
}
|
||
|
||
// 淘系支付宝 - 使用独立的流水账单表(8字段)
|
||
if ($tab === 'taobao-alipay') {
|
||
return [
|
||
'view' => 'banking.marketing_taobao_alipay_bills.partials.embedded-table',
|
||
'bills' => MarketingTaobaoAlipayBill::orderBy('transaction_date', 'desc')
|
||
->orderBy('id', 'desc')
|
||
->paginate(setting('default.list_limit', 25)),
|
||
];
|
||
}
|
||
|
||
// 拼多多 - 使用独立的流水账单表(7字段)
|
||
if ($tab === 'pinduoduo') {
|
||
return [
|
||
'view' => 'banking.marketing_pinduoduo_bills.partials.embedded-table',
|
||
'bills' => MarketingPinduoduoBill::orderBy('transaction_time', 'desc')
|
||
->orderBy('id', 'desc')
|
||
->paginate(setting('default.list_limit', 25)),
|
||
];
|
||
}
|
||
|
||
// 其他平台 - 使用通用汇总账单表(15字段)
|
||
return [
|
||
'view' => 'banking.marketing_account_bills.partials.embedded-table',
|
||
'platform' => $tab,
|
||
'accounts' => MarketingAccountBill::platform($tab)
|
||
->orderBy('bill_date', 'desc')
|
||
->orderBy('id', 'desc')
|
||
->paginate(setting('default.list_limit', 25)),
|
||
];
|
||
}
|
||
|
||
protected function redirectToPage(array $section, array $page)
|
||
{
|
||
$parameters = [
|
||
'section' => $section['slug'],
|
||
'page' => $page['slug'],
|
||
];
|
||
|
||
if (! empty($page['tabs'])) {
|
||
$parameters['tab'] = $page['tabs'][0]['slug'];
|
||
}
|
||
|
||
return redirect()->route('business.pages.show', $parameters);
|
||
}
|
||
}
|