ソースを参照

糊盒工资计算

unknown 1 週間 前
コミット
322237f6d1

+ 2 - 2
application/api/controller/GluSalaryCalculation.php

@@ -36,7 +36,7 @@ class GluSalaryCalculation extends Api
             ->find();
 
         if ($runningTask) {
-            $this->success('该月份的糊盒工资计算任务正在执行中,请稍后查看结果', null, [
+            $this->success('该月份的糊盒工资计算任务正在执行中,请稍后查看结果', [
                 'task_id' => $runningTask['id'],
                 'month' => $month,
                 'status' => $runningTask['status'],
@@ -70,7 +70,7 @@ class GluSalaryCalculation extends Api
                     'update_time' => date('Y-m-d H:i:s'),
                 ]);
 
-            $this->success('糊盒工资计算任务已提交到队列,请稍后查看结果', null, [
+            $this->success('糊盒工资计算任务已提交到队列,请稍后查看结果', [
                 'task_id' => $taskId,
                 'job_id' => $jobId,
                 'month' => $month,

+ 4 - 4
application/job/GluSalaryCalculationJob.php

@@ -20,7 +20,7 @@ class GluSalaryCalculationJob
         $taskId = $data['task_id'] ?? 0;
 
         try {
-            Log::info('开始执行糊盒工资计算队列任务', $data);
+            Log::info('开始执行糊盒工资计算队列任务: ' . json_encode($data, JSON_UNESCAPED_UNICODE));
             $this->updateTaskStatus($taskId, 'processing', [
                 'start_time' => date('Y-m-d H:i:s'),
                 'retry_count' => $job->attempts(),
@@ -35,7 +35,7 @@ class GluSalaryCalculationJob
                     'end_time' => date('Y-m-d H:i:s'),
                     'result' => json_encode($result, JSON_UNESCAPED_UNICODE),
                 ]);
-                Log::info('糊盒工资计算任务执行成功', $result);
+                Log::info('糊盒工资计算任务执行成功: ' . json_encode($result, JSON_UNESCAPED_UNICODE));
                 return;
             }
 
@@ -48,12 +48,12 @@ class GluSalaryCalculationJob
                     'error' => $message,
                     'retry_count' => $job->attempts(),
                 ]);
-                Log::error('糊盒工资计算任务失败', ['data' => $data, 'error' => $message]);
+                Log::error('糊盒工资计算任务失败: ' . json_encode(['data' => $data, 'error' => $message], JSON_UNESCAPED_UNICODE));
                 return;
             }
 
             $job->release($this->getRetryDelay($job->attempts()));
-            Log::warning('糊盒工资计算任务重试', ['attempts' => $job->attempts(), 'error' => $message]);
+            Log::warning('糊盒工资计算任务重试: ' . json_encode(['attempts' => $job->attempts(), 'error' => $message], JSON_UNESCAPED_UNICODE));
         } catch (\Exception $e) {
             Log::error('糊盒工资计算队列任务异常: ' . $e->getMessage());
             $maxRetry = config('queue.queues.salary_calculation.retry') ?? 2;

+ 61 - 13
application/service/GluSalaryCalculationService.php

@@ -41,7 +41,7 @@ class GluSalaryCalculationService
                 }
 
                 foreach ($wageList as $wageItem) {
-                    $pieceData[] = $this->buildSalarySummaryRow([
+                    $pieceData[] = $this->buildPieceSalarySummaryRow([
                         'sczl_gdbh' => $v['工单编号'],
                         'sczl_gxmc' => $v['工序名称'],
                         'sczl_rq' => $v['日期'],
@@ -71,18 +71,14 @@ class GluSalaryCalculationService
 
             $timekeepInsert = [];
             foreach ($timekeepData as $item) {
-                $remark = $item['remark'] ?? '';
-                if (!empty($item['type'])) {
-                    $remark = $remark !== '' ? $item['type'] . ',' . $remark : $item['type'];
-                }
-                $timekeepInsert[] = $this->buildSalarySummaryRow([
+                $timekeepInsert[] = $this->buildTimekeepSalarySummaryRow([
                     'sczl_rq' => $item['sczl_rq'] . ' 00:00:00',
                     'bh' => $item['bh'],
                     'name' => $item['姓名'],
                     'time_salary' => $item['salary'],
                     'time_price' => $item['price'],
                     'time_duration' => $item['duration'],
-                    'remark' => $remark,
+                    'remark' => $item['remark'] ?? '',
                     'sys_id' => $params['sys_id'] ?? '',
                 ]);
             }
@@ -148,6 +144,17 @@ class GluSalaryCalculationService
         return stripos((string)$jtbh, 'SG') !== false;
     }
 
+    /**
+     * 员工编号是否参与工资计算(仅纯数字编号)
+     * @param mixed $bh
+     * @return bool
+     */
+    protected function isValidEmployeeBh($bh)
+    {
+        $bh = trim((string)$bh);
+        return $bh !== '' && $bh !== '0000' && ctype_digit($bh);
+    }
+
     /**
      * 普通机台计件工资
      * @param array $report
@@ -161,7 +168,7 @@ class GluSalaryCalculationService
 
         for ($i = 1; $i <= 30; $i++) {
             $bh = trim($classResult['bh' . $i] ?? '');
-            if ($bh === '' || $bh === '0000') {
+            if (!$this->isValidEmployeeBh($bh)) {
                 continue;
             }
 
@@ -187,7 +194,7 @@ class GluSalaryCalculationService
         $employees = [];
         for ($i = 1; $i <= 30; $i++) {
             $bh = trim($classResult['bh' . $i] ?? '');
-            if ($bh === '' || $bh === '0000') {
+            if (!$this->isValidEmployeeBh($bh)) {
                 continue;
             }
             $employees[] = [
@@ -333,7 +340,7 @@ class GluSalaryCalculationService
         foreach ($list as $row) {
             for ($i = 1; $i <= 30; $i++) {
                 $bh = isset($row['bh' . $i]) ? trim($row['bh' . $i]) : '';
-                if ($bh !== '' && $bh !== '0000') {
+                if ($this->isValidEmployeeBh($bh)) {
                     $employeeIds[$bh] = true;
                 }
             }
@@ -355,7 +362,7 @@ class GluSalaryCalculationService
             $employees = [];
             for ($i = 1; $i <= 30; $i++) {
                 $bh = isset($row['bh' . $i]) ? trim($row['bh' . $i]) : '';
-                if ($bh !== '' && $bh !== '0000') {
+                if ($this->isValidEmployeeBh($bh)) {
                     $employees[] = $bh;
                 }
             }
@@ -426,7 +433,7 @@ class GluSalaryCalculationService
         foreach ($list as $row) {
             for ($i = 1; $i <= 6; $i++) {
                 $bh = isset($row['wgjs_bh' . $i]) ? trim($row['wgjs_bh' . $i]) : '';
-                if ($bh !== '') {
+                if ($this->isValidEmployeeBh($bh)) {
                     $employeeIds[$bh] = true;
                 }
             }
@@ -450,7 +457,7 @@ class GluSalaryCalculationService
 
             for ($i = 1; $i <= 6; $i++) {
                 $bh = isset($row['wgjs_bh' . $i]) ? trim($row['wgjs_bh' . $i]) : '';
-                if ($bh === '') {
+                if (!$this->isValidEmployeeBh($bh)) {
                     continue;
                 }
 
@@ -514,6 +521,47 @@ class GluSalaryCalculationService
         return $data;
     }
 
+    /**
+     * 构建计件工资汇总行(仅填 price、salary,计时字段为 0)
+     * @param array $fields
+     * @return array
+     */
+    protected function buildPieceSalarySummaryRow(array $fields = [])
+    {
+        return $this->buildSalarySummaryRow(array_merge([
+            'time_salary' => 0,
+            'time_price' => 0,
+            'time_duration' => 0,
+            'remark' => '',
+        ], $fields));
+    }
+
+    /**
+     * 构建计时工资汇总行(仅填 time_price、time_salary、time_duration、remark,计件字段为 0)
+     * @param array $fields
+     * @return array
+     */
+    protected function buildTimekeepSalarySummaryRow(array $fields = [])
+    {
+        return $this->buildSalarySummaryRow(array_merge([
+            'sczl_gdbh' => '',
+            'sczl_gxmc' => '',
+            'sczl_dedh' => '',
+            'sczl_cl' => 0,
+            '工价系数' => '',
+            '保养工时' => '',
+            '装版工时' => '',
+            '异常工时' => '',
+            '设备运行工时' => '',
+            'sczl_jtbh' => '',
+            'cpdh' => '',
+            'cpmc' => '',
+            'rate' => '',
+            'salary' => 0,
+            'price' => 0,
+        ], $fields));
+    }
+
     /**
      * 构建工资汇总统一字段结构
      * @param array $fields