|
|
@@ -6,6 +6,7 @@ use App\Model\EmployeeIndex;
|
|
|
use App\Model\FreightFee;
|
|
|
use App\Model\GiveOut;
|
|
|
use App\Model\ItemReport;
|
|
|
+use App\Model\ItemReportMan;
|
|
|
use App\Model\ItemReportRoad;
|
|
|
use App\Model\RevenueCost;
|
|
|
use App\Model\RevenueCostTotal;
|
|
|
@@ -915,6 +916,40 @@ class StatisticsService extends Service
|
|
|
return $data;
|
|
|
}
|
|
|
|
|
|
+ public function statisticsMan($data, $user)
|
|
|
+ {
|
|
|
+ $model = $this->statisticsManCommon($data, $user);
|
|
|
+ $list = $this->limit($model,'',$data);
|
|
|
+ $list = $this->statisticsManFillData($list, $user,$data);
|
|
|
+
|
|
|
+ $list['count'] = $this->countTotal($list['data'], $user['header_default']);
|
|
|
+
|
|
|
+ return [true, $list];
|
|
|
+ }
|
|
|
+
|
|
|
+ public function statisticsManCommon($data,$user, $field = []){
|
|
|
+ $model = ItemReportMan::select('*')
|
|
|
+ ->orderby('id', 'desc');
|
|
|
+
|
|
|
+ if(! empty($data['order_time'])){
|
|
|
+ $time = strtotime($data['order_time'] . "-01");
|
|
|
+ $model->where('time', $time);
|
|
|
+ }
|
|
|
+
|
|
|
+ return $model;
|
|
|
+ }
|
|
|
+
|
|
|
+ public function statisticsManFillData($data, $user, $ergs){
|
|
|
+ if(empty($data['data'])) return $data;
|
|
|
+
|
|
|
+ foreach ($data['data'] as $key => $value) {
|
|
|
+ $time = $value['time'] ? date('Y-m',$value['time']) : '';
|
|
|
+ $data['data'][$key]['time'] = $time;
|
|
|
+ }
|
|
|
+
|
|
|
+ return $data;
|
|
|
+ }
|
|
|
+
|
|
|
public function getChannelReport($data)
|
|
|
{
|
|
|
if(empty($data['order_time'])) return [false, '年月不能为空'];
|
|
|
@@ -1102,4 +1137,405 @@ class StatisticsService extends Service
|
|
|
|
|
|
return $finalResult;
|
|
|
}
|
|
|
+
|
|
|
+ private function getAmountFieldManNames()
|
|
|
+ {
|
|
|
+ return [
|
|
|
+ 'receipt_amount', 'receipt_not_amount', 'cost', 'profit', 'profit_not',
|
|
|
+ 'settle_amount', 'gl_amount', 'gl_not_amount', 'wl_amount', 'wl_not_amount',
|
|
|
+ 'ht_amount', 'zk_amount', 'cx_amount', 'tg_amount', 'cl_amount',
|
|
|
+ 'kq_amount', 'zp_amount', 'gg_amount', 'kd_amount', 'xsqt_amount',
|
|
|
+ 'ry_amount', 'sb_amount', 'sj_amount', 'sj_not_amount', 'sx_amount',
|
|
|
+ 'sx_not_amount', 'other_ck_amount', 'cg_amount'
|
|
|
+ ];
|
|
|
+ }
|
|
|
+
|
|
|
+ private function injectAmountMan($data)
|
|
|
+ {
|
|
|
+ $result = [];
|
|
|
+ // 参与 total 计算的费用字段 (排除收入、成本和利润)
|
|
|
+ $expenseFields = [
|
|
|
+ 'settle_amount', 'gl_amount', 'gl_not_amount', 'wl_amount', 'wl_not_amount',
|
|
|
+ 'ht_amount', 'zk_amount', 'cx_amount', 'tg_amount', 'cl_amount',
|
|
|
+ 'kq_amount', 'zp_amount', 'gg_amount', 'kd_amount', 'xsqt_amount',
|
|
|
+ 'ry_amount', 'sb_amount', 'sj_amount', 'sj_not_amount', 'sx_amount',
|
|
|
+ 'sx_not_amount', 'other_ck_amount', 'cg_amount'
|
|
|
+ ];
|
|
|
+
|
|
|
+ // 第一步:格式化并插入占位符
|
|
|
+ foreach ($this->getAmountFieldManNames() as $key) {
|
|
|
+ $val = $data[$key] ?? 0;
|
|
|
+
|
|
|
+ if ($key === 'sj_amount') {
|
|
|
+ $result['amount1'] = '0.00'; // 占位
|
|
|
+ $result['sj_amount'] = number_format((float)$val, 2, '.', '');
|
|
|
+ $result['amount2'] = '0.00'; // 占位
|
|
|
+ } else {
|
|
|
+ $result[$key] = number_format((float)$val, 2, '.', '');
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ // 第二步:计算费用总额
|
|
|
+ $total = 0;
|
|
|
+ foreach ($expenseFields as $field) {
|
|
|
+ $total += (float)($data[$field] ?? 0);
|
|
|
+ }
|
|
|
+ $result['total'] = number_format($total, 2, '.', '');
|
|
|
+
|
|
|
+ return $result;
|
|
|
+ }
|
|
|
+
|
|
|
+ public function getChannelReportMan1($data)
|
|
|
+ {
|
|
|
+ if(empty($data['order_time'])) return [false, '年月不能为空'];
|
|
|
+ $yearMonth = $data['order_time']; // 格式如 2026-02
|
|
|
+
|
|
|
+ [$year, $month] = explode('-', $yearMonth);
|
|
|
+ $year = (int)$year;
|
|
|
+ $month = (int)$month;
|
|
|
+
|
|
|
+ // 当前选择月的第一天戳
|
|
|
+ $currentMonthTs = mktime(0, 0, 0, $month, 1, $year);
|
|
|
+ // 去年7月1日的时间戳 (例如输入2026-02,则起始为2025-07-01)
|
|
|
+ $startTs = mktime(0, 0, 0, 7, 1, $year - 1);
|
|
|
+
|
|
|
+ // 从业务员报表获取数据
|
|
|
+ $records = DB::table('item_report_man')
|
|
|
+ ->whereBetween('time', [$startTs, $currentMonthTs])
|
|
|
+ ->get();
|
|
|
+
|
|
|
+ $channels = [];
|
|
|
+ $allFields = $this->getAmountFieldManNames();
|
|
|
+
|
|
|
+ foreach ($records as $record) {
|
|
|
+ // 以渠道财务分组
|
|
|
+ $channel = $record->channel_finance ?: '未知渠道';
|
|
|
+
|
|
|
+ if (!isset($channels[$channel])) {
|
|
|
+ $channels[$channel] = [
|
|
|
+ 'monthly' => array_fill_keys($allFields, 0),
|
|
|
+ 'cumulative' => array_fill_keys($allFields, 0),
|
|
|
+ ];
|
|
|
+ }
|
|
|
+
|
|
|
+ $isCurrentMonth = ((int)$record->time === $currentMonthTs);
|
|
|
+
|
|
|
+ foreach ($allFields as $field) {
|
|
|
+ $val = (float)($record->$field ?? 0);
|
|
|
+ // 累计去年7月至今
|
|
|
+ $channels[$channel]['cumulative'][$field] += $val;
|
|
|
+ // 仅当月
|
|
|
+ if ($isCurrentMonth) {
|
|
|
+ $channels[$channel]['monthly'][$field] += $val;
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ $finalResult = [];
|
|
|
+ foreach ($channels as $channelName => $values) {
|
|
|
+ $finalResult[] = [
|
|
|
+ 'channel' => $channelName,
|
|
|
+ 'monthly' => $this->injectAmountMan($values['monthly']),
|
|
|
+ 'cumulative' => $this->injectAmountMan($values['cumulative']),
|
|
|
+ ];
|
|
|
+ }
|
|
|
+
|
|
|
+ return $finalResult;
|
|
|
+ }
|
|
|
+
|
|
|
+ public function getChannelReportMan2($data)
|
|
|
+ {
|
|
|
+ if (empty($data['order_time'])) return [false, '年月不能为空'];
|
|
|
+ $yearMonth = $data['order_time'];
|
|
|
+
|
|
|
+ [$year, $month] = explode('-', $yearMonth);
|
|
|
+ $year = (int)$year;
|
|
|
+ $month = (int)$month;
|
|
|
+
|
|
|
+ // 1. 计算时间范围
|
|
|
+ $currentMonthTs = mktime(0, 0, 0, $month, 1, $year);
|
|
|
+ // 财年规则:如果当前月 >= 7月,起始是当年7月;否则是去年7月
|
|
|
+ $startYear = ($month >= 7) ? $year : $year - 1;
|
|
|
+ $startTs = mktime(0, 0, 0, 7, 1, $startYear);
|
|
|
+
|
|
|
+ // 2. 一次性获取所有相关记录
|
|
|
+ $records = DB::table('item_report_man')
|
|
|
+ ->whereBetween('time', [$startTs, $currentMonthTs])
|
|
|
+ ->get();
|
|
|
+
|
|
|
+ // 3. 定义金额字段(按 B5-B27 的顺序排列,方便后面直接填充 row)
|
|
|
+ $rowFieldMapping = [
|
|
|
+ 5 => 'receipt_amount', 6 => 'cost', 7 => 'profit',
|
|
|
+ 8 => 'settle_amount', 9 => 'gl_amount', 10 => 'wl_amount',
|
|
|
+ 11 => 'ht_amount', 12 => 'zk_amount', 13 => 'cx_amount',
|
|
|
+ 14 => 'tg_amount', 15 => 'cl_amount', 16 => 'kq_amount',
|
|
|
+ 17 => 'zp_amount', 18 => 'gg_amount', 19 => 'kd_amount',
|
|
|
+ 20 => 'xsqt_amount', 21 => 'ry_amount', 22 => 'sb_amount',
|
|
|
+ 23 => '退货亏损', 24 => 'cg_amount', 25 => 'sj_amount',
|
|
|
+ 26 => 'sx_amount', 27 => 'other_ck_amount'
|
|
|
+ ];
|
|
|
+
|
|
|
+ // 4. 初始化列容器(C到Z)
|
|
|
+ $columns = [];
|
|
|
+ $columnKeys = range('C', 'Z');
|
|
|
+ foreach ($columnKeys as $col) {
|
|
|
+ $columns[$col] = array_fill(5, 28, 0); // 5-32行,初始化为0
|
|
|
+ }
|
|
|
+
|
|
|
+ // 5. 遍历分拣数据
|
|
|
+ foreach ($records as $record) {
|
|
|
+ $empId = (int)$record->employee_id_1;
|
|
|
+ $finance = $record->channel_finance;
|
|
|
+ $isCurrent = ((int)$record->time === $currentMonthTs);
|
|
|
+
|
|
|
+ foreach ($rowFieldMapping as $rowIdx => $field) {
|
|
|
+ $val = (float)($record->$field ?? 0);
|
|
|
+
|
|
|
+ // 规则分拣 (C, D, G, H, K, L, O, Q, R, U, W)
|
|
|
+ // C: 2+社区
|
|
|
+ if ($empId === 2 && $finance === '社区') {
|
|
|
+ if ($isCurrent) $columns['C'][$rowIdx] += $val;
|
|
|
+ $columns['F'][$rowIdx] += $val; // 累计
|
|
|
+ }
|
|
|
+ // D: (2+通路) + (5+通路)
|
|
|
+ if (($empId === 2 || $empId === 5) && $finance === '通路') {
|
|
|
+ if ($isCurrent) $columns['D'][$rowIdx] += $val;
|
|
|
+ $columns['F'][$rowIdx] += $val; // 累计到F
|
|
|
+ }
|
|
|
+ // G: 3+通路
|
|
|
+ if ($empId === 3 && $finance === '通路') {
|
|
|
+ if ($isCurrent) $columns['G'][$rowIdx] += $val;
|
|
|
+ $columns['J'][$rowIdx] += $val;
|
|
|
+ }
|
|
|
+ // H: 3+联华加盟
|
|
|
+ if ($empId === 3 && $finance === '联华加盟') {
|
|
|
+ if ($isCurrent) $columns['H'][$rowIdx] += $val;
|
|
|
+ $columns['J'][$rowIdx] += $val;
|
|
|
+ }
|
|
|
+ // K: 23+通路
|
|
|
+ if ($empId === 23 && $finance === '通路') {
|
|
|
+ if ($isCurrent) $columns['K'][$rowIdx] += $val;
|
|
|
+ $columns['N'][$rowIdx] += $val;
|
|
|
+ }
|
|
|
+ // L: 23+智鲸
|
|
|
+ if ($empId === 23 && $finance === '智鲸') {
|
|
|
+ if ($isCurrent) $columns['L'][$rowIdx] += $val;
|
|
|
+ $columns['N'][$rowIdx] += $val;
|
|
|
+ }
|
|
|
+ // O: (7,8,54) + (通路,大卖场)
|
|
|
+ if (in_array($empId, [7, 8, 54]) && in_array($finance, ['通路', '大卖场'])) {
|
|
|
+ if ($isCurrent) $columns['O'][$rowIdx] += $val;
|
|
|
+ $columns['P'][$rowIdx] += $val;
|
|
|
+ }
|
|
|
+ // Q: 48+通路
|
|
|
+ if ($empId === 48 && $finance === '通路') {
|
|
|
+ if ($isCurrent) $columns['Q'][$rowIdx] += $val;
|
|
|
+ $columns['T'][$rowIdx] += $val;
|
|
|
+ }
|
|
|
+ // R: 48+大卖场
|
|
|
+ if ($empId === 48 && $finance === '大卖场') {
|
|
|
+ if ($isCurrent) $columns['R'][$rowIdx] += $val;
|
|
|
+ $columns['T'][$rowIdx] += $val;
|
|
|
+ }
|
|
|
+ // U: 行政
|
|
|
+ if ($finance === '行政') {
|
|
|
+ if ($isCurrent) $columns['U'][$rowIdx] += $val;
|
|
|
+ $columns['V'][$rowIdx] += $val;
|
|
|
+ }
|
|
|
+ // W: 鲍总
|
|
|
+ if ($finance === '鲍总') {
|
|
|
+ if ($isCurrent) $columns['W'][$rowIdx] += $val;
|
|
|
+ $columns['X'][$rowIdx] += $val;
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ // 6. 计算横向合计列
|
|
|
+ for ($i = 5; $i <= 27; $i++) {
|
|
|
+ $columns['E'][$i] = $columns['C'][$i] + $columns['D'][$i]; // 张+霍当月合计
|
|
|
+ $columns['I'][$i] = $columns['G'][$i] + $columns['H'][$i]; // 金小勇当月合计
|
|
|
+ $columns['M'][$i] = $columns['K'][$i] + $columns['L'][$i]; // 沈强当月合计
|
|
|
+ $columns['S'][$i] = $columns['Q'][$i] + $columns['R'][$i]; // 叶南汝当月合计
|
|
|
+
|
|
|
+ // Y: 当月总计 (所有当月列累加)
|
|
|
+ $columns['Y'][$i] = $columns['C'][$i] + $columns['D'][$i] + $columns['G'][$i] +
|
|
|
+ $columns['H'][$i] + $columns['K'][$i] + $columns['L'][$i] +
|
|
|
+ $columns['O'][$i] + $columns['Q'][$i] + $columns['R'][$i] +
|
|
|
+ $columns['U'][$i] + $columns['W'][$i];
|
|
|
+
|
|
|
+ // Z: 年累计总计 (所有累计列累加)
|
|
|
+ $columns['Z'][$i] = $columns['F'][$i] + $columns['J'][$i] + $columns['N'][$i] +
|
|
|
+ $columns['P'][$i] + $columns['T'][$i] + $columns['V'][$i] + $columns['X'][$i];
|
|
|
+ }
|
|
|
+
|
|
|
+ // 7. 组装最终供 Excel 填充的数组 (5行到32行)
|
|
|
+ $finalData = [];
|
|
|
+ for ($row = 5; $row <= 32; $row++) {
|
|
|
+ $rowData = [];
|
|
|
+ // 从 C 到 Z 循环取数据
|
|
|
+ foreach (range('C', 'Z') as $colLetter) {
|
|
|
+ $val = $columns[$colLetter][$row] ?? 0;
|
|
|
+ // 28-32行填空字符串,其他格式化
|
|
|
+ if ($row > 27 && $row < 32) {
|
|
|
+ $rowData[] = '';
|
|
|
+ } elseif ($row == 32) {
|
|
|
+ // 如果需要算小计可以在这里加,目前先填空字符串
|
|
|
+ $rowData[] = '';
|
|
|
+ } else {
|
|
|
+ $rowData[] = $val == 0 ? '0.00' : number_format($val, 2, '.', '');
|
|
|
+ }
|
|
|
+ }
|
|
|
+ $finalData[] = $rowData;
|
|
|
+ }
|
|
|
+
|
|
|
+ return $finalData;
|
|
|
+ }
|
|
|
+
|
|
|
+ public function getChannelReportMan($data)
|
|
|
+ {
|
|
|
+ if (empty($data['order_time'])) return [false, '年月不能为空'];
|
|
|
+ $yearMonth = $data['order_time'];
|
|
|
+
|
|
|
+ [$year, $month] = explode('-', $yearMonth);
|
|
|
+ $year = (int)$year;
|
|
|
+ $month = (int)$month;
|
|
|
+
|
|
|
+ // 1. 计算时间范围:7月财年规则
|
|
|
+ $currentMonthTs = mktime(0, 0, 0, $month, 1, $year);
|
|
|
+ $startYear = ($month >= 7) ? $year : $year - 1;
|
|
|
+ $startTs = mktime(0, 0, 0, 7, 1, $startYear);
|
|
|
+
|
|
|
+ // 2. 一次性获取数据
|
|
|
+ $records = DB::table('item_report_man')
|
|
|
+ ->whereBetween('time', [$startTs, $currentMonthTs])
|
|
|
+ ->get();
|
|
|
+
|
|
|
+ // 3. 字段映射 (注意 23 行,若数据库无字段则设为 null 会自动补 0)
|
|
|
+ $rowFieldMapping = [
|
|
|
+ 5 => 'receipt_amount', 6 => 'cost', 7 => 'profit',
|
|
|
+ 8 => 'settle_amount', 9 => 'gl_amount', 10 => 'wl_amount',
|
|
|
+ 11 => 'ht_amount', 12 => 'zk_amount', 13 => 'cx_amount',
|
|
|
+ 14 => 'tg_amount', 15 => 'cl_amount', 16 => 'kq_amount',
|
|
|
+ 17 => 'zp_amount', 18 => 'gg_amount', 19 => 'kd_amount',
|
|
|
+ 20 => 'xsqt_amount', 21 => 'ry_amount', 22 => 'sb_amount',
|
|
|
+ 23 => null, // 退货亏损 (不良仓),暂无字段映射,填充0
|
|
|
+ 24 => 'cg_amount', 25 => 'sj_amount',
|
|
|
+ 26 => 'sx_amount', 27 => 'other_ck_amount'
|
|
|
+ ];
|
|
|
+
|
|
|
+ // 4. 初始化列容器 (C 到 Z)
|
|
|
+ $columns = [];
|
|
|
+ $columnKeys = range('C', 'Z');
|
|
|
+ foreach ($columnKeys as $col) {
|
|
|
+ $columns[$col] = array_fill(5, 28, 0); // 覆盖 5-32 行
|
|
|
+ }
|
|
|
+
|
|
|
+ // 5. 数据分拣累加
|
|
|
+ foreach ($records as $record) {
|
|
|
+ $empId = (int)$record->employee_id_1;
|
|
|
+ $finance = $record->channel_finance;
|
|
|
+ $isCurrent = ((int)$record->time === $currentMonthTs);
|
|
|
+
|
|
|
+ foreach ($rowFieldMapping as $rowIdx => $field) {
|
|
|
+ $val = $field ? (float)($record->$field ?? 0) : 0;
|
|
|
+
|
|
|
+ // 分拣规则
|
|
|
+ // 张春勇、霍尚琳
|
|
|
+ if ($empId === 2 && $finance === '社区') {
|
|
|
+ if ($isCurrent) $columns['C'][$rowIdx] += $val;
|
|
|
+ $columns['F'][$rowIdx] += $val;
|
|
|
+ }
|
|
|
+ if (($empId === 2 || $empId === 5) && $finance === '通路') {
|
|
|
+ if ($isCurrent) $columns['D'][$rowIdx] += $val;
|
|
|
+ $columns['F'][$rowIdx] += $val;
|
|
|
+ }
|
|
|
+ // 金小勇
|
|
|
+ if ($empId === 3 && $finance === '通路') {
|
|
|
+ if ($isCurrent) $columns['G'][$rowIdx] += $val;
|
|
|
+ $columns['J'][$rowIdx] += $val;
|
|
|
+ }
|
|
|
+ if ($empId === 3 && $finance === '联华加盟') {
|
|
|
+ if ($isCurrent) $columns['H'][$rowIdx] += $val;
|
|
|
+ $columns['J'][$rowIdx] += $val;
|
|
|
+ }
|
|
|
+ // 沈强
|
|
|
+ if ($empId === 23 && $finance === '通路') {
|
|
|
+ if ($isCurrent) $columns['K'][$rowIdx] += $val;
|
|
|
+ $columns['N'][$rowIdx] += $val;
|
|
|
+ }
|
|
|
+ if ($empId === 23 && $finance === '智鲸') {
|
|
|
+ if ($isCurrent) $columns['L'][$rowIdx] += $val;
|
|
|
+ $columns['N'][$rowIdx] += $val;
|
|
|
+ }
|
|
|
+ // 王利英等组合 (O/P列)
|
|
|
+ if (in_array($empId, [7, 8, 54]) && in_array($finance, ['通路', '大卖场'])) {
|
|
|
+ if ($isCurrent) $columns['O'][$rowIdx] += $val;
|
|
|
+ $columns['P'][$rowIdx] += $val;
|
|
|
+ }
|
|
|
+ // 叶南汝
|
|
|
+ if ($empId === 48 && $finance === '通路') {
|
|
|
+ if ($isCurrent) $columns['Q'][$rowIdx] += $val;
|
|
|
+ $columns['T'][$rowIdx] += $val;
|
|
|
+ }
|
|
|
+ if ($empId === 48 && $finance === '大卖场') {
|
|
|
+ if ($isCurrent) $columns['R'][$rowIdx] += $val;
|
|
|
+ $columns['T'][$rowIdx] += $val;
|
|
|
+ }
|
|
|
+ // 行政
|
|
|
+ if ($finance === '行政') {
|
|
|
+ if ($isCurrent) $columns['U'][$rowIdx] += $val;
|
|
|
+ $columns['V'][$rowIdx] += $val;
|
|
|
+ }
|
|
|
+ // 鲍总
|
|
|
+ if ($finance === '鲍总') {
|
|
|
+ if ($isCurrent) $columns['W'][$rowIdx] += $val;
|
|
|
+ $columns['X'][$rowIdx] += $val;
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ // 6. 计算合计列与纵向小计
|
|
|
+ for ($i = 5; $i <= 27; $i++) {
|
|
|
+ // 合计列
|
|
|
+ $columns['E'][$i] = $columns['C'][$i] + $columns['D'][$i];
|
|
|
+ $columns['I'][$i] = $columns['G'][$i] + $columns['H'][$i];
|
|
|
+ $columns['M'][$i] = $columns['K'][$i] + $columns['L'][$i];
|
|
|
+ $columns['S'][$i] = $columns['Q'][$i] + $columns['R'][$i];
|
|
|
+
|
|
|
+ // Y/Z 总计
|
|
|
+ $columns['Y'][$i] = $columns['C'][$i] + $columns['D'][$i] + $columns['G'][$i] + $columns['H'][$i] +
|
|
|
+ $columns['K'][$i] + $columns['L'][$i] + $columns['O'][$i] + $columns['Q'][$i] +
|
|
|
+ $columns['R'][$i] + $columns['U'][$i] + $columns['W'][$i];
|
|
|
+
|
|
|
+ $columns['Z'][$i] = $columns['F'][$i] + $columns['J'][$i] + $columns['N'][$i] + $columns['P'][$i] +
|
|
|
+ $columns['T'][$i] + $columns['V'][$i] + $columns['X'][$i];
|
|
|
+ }
|
|
|
+
|
|
|
+ // 纵向小计 (第 32 行 = 8 到 31 行累加)
|
|
|
+ foreach ($columnKeys as $col) {
|
|
|
+ $subTotal = 0;
|
|
|
+ for ($r = 8; $r <= 31; $r++) {
|
|
|
+ $subTotal += (float)($columns[$col][$r] ?? 0);
|
|
|
+ }
|
|
|
+ $columns[$col][32] = $subTotal;
|
|
|
+ }
|
|
|
+
|
|
|
+ // 7. 最终格式化
|
|
|
+ $finalData = [];
|
|
|
+ for ($row = 5; $row <= 32; $row++) {
|
|
|
+ $rowData = [];
|
|
|
+ foreach ($columnKeys as $colLetter) {
|
|
|
+ $val = $columns[$colLetter][$row] ?? 0;
|
|
|
+
|
|
|
+ if ($row >= 28 && $row <= 31) {
|
|
|
+ $rowData[] = ''; // 预留行填空
|
|
|
+ } else {
|
|
|
+ $rowData[] = ($val == 0) ? '0.00' : number_format($val, 2, '.', '');
|
|
|
+ }
|
|
|
+ }
|
|
|
+ $finalData[] = $rowData;
|
|
|
+ }
|
|
|
+
|
|
|
+ return $finalData;
|
|
|
+ }
|
|
|
}
|