GluSalaryCalculationService.php 22 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649
  1. <?php
  2. namespace app\service;
  3. /**
  4. * 糊盒工资计算服务
  5. */
  6. class GluSalaryCalculationService
  7. {
  8. /**
  9. * 执行糊盒工资计算
  10. * @param array $params
  11. * @return array
  12. */
  13. public function execute(array $params)
  14. {
  15. try {
  16. if (empty($params['month']) || empty($params['startDay']) || empty($params['endDay'])) {
  17. return ['success' => false, 'message' => '参数错误'];
  18. }
  19. $where = ['a.sczl_rq' => ['between', [$params['startDay'] . ' 00:00:00', $params['endDay'] . ' 23:59:59']]];
  20. $filds = "a.sczl_gdbh as 工单编号,a.sczl_gxmc as 工序名称,a.sczl_cl as 产量,a.sczl_rq as 日期,
  21. a.sczl_dedh as 定额代号,d.日定额 as 日定额,a.工价系数,a.保养工时,a.装版工时,a.异常工时,a.设备运行工时,a.role,a.sczl_jtbh,b.Gd_cpdh,b.Gd_cpmc,a.price";
  22. $list = db('设备_糊盒报工资料')
  23. ->alias('a')
  24. ->join('工单_基本资料 b', 'a.sczl_gdbh = b.Gd_gdbh ', 'left')
  25. ->join('dic_lzde d', 'a.sczl_dedh = d.sys_bh', 'left')
  26. ->field($filds)
  27. ->where($where)
  28. ->group('a.Uid')
  29. ->select();
  30. $pieceData = [];
  31. foreach ($list as $v) {
  32. $result = $this->salaryCalculationClass($v['role']);
  33. if ($this->isManualMachine($v['sczl_jtbh'])) {
  34. $wageList = $this->calculateManualPieceWages($v, $result);
  35. } else {
  36. $wageList = $this->calculateRegularPieceWages($v, $result);
  37. }
  38. foreach ($wageList as $wageItem) {
  39. $pieceData[] = $this->buildPieceSalarySummaryRow([
  40. 'sczl_gdbh' => $v['工单编号'],
  41. 'sczl_gxmc' => $v['工序名称'],
  42. 'sczl_rq' => $v['日期'],
  43. 'sczl_cl' => $v['产量'],
  44. 'sczl_dedh' => $v['定额代号'],
  45. '工价系数' => $v['工价系数'],
  46. '保养工时' => $v['保养工时'],
  47. '装版工时' => $v['装版工时'],
  48. '异常工时' => $v['异常工时'],
  49. '设备运行工时' => $v['设备运行工时'],
  50. 'sczl_jtbh' => $v['sczl_jtbh'],
  51. 'cpdh' => $v['Gd_cpdh'],
  52. 'cpmc' => $v['Gd_cpmc'],
  53. 'bh' => $wageItem['bh'],
  54. 'rate' => $wageItem['rate'],
  55. 'name' => $wageItem['name'],
  56. 'salary' => $wageItem['wage'],
  57. 'price' => $v['price'],
  58. 'sys_id' => $params['sys_id'] ?? '',
  59. ]);
  60. }
  61. }
  62. $teamres = $this->teamTimekeepCalculation($params['month']);
  63. $timekeepres = $this->calculateTimekeepSalary($params['month']);
  64. $timekeepData = $this->mergeTimekeepSalaryData($teamres, $timekeepres);
  65. $timekeepInsert = [];
  66. foreach ($timekeepData as $item) {
  67. $timekeepInsert[] = $this->buildTimekeepSalarySummaryRow([
  68. 'sczl_rq' => $item['sczl_rq'] . ' 00:00:00',
  69. 'bh' => $item['bh'],
  70. 'name' => $item['姓名'],
  71. 'time_salary' => $item['salary'],
  72. 'time_price' => $item['price'],
  73. 'time_duration' => $item['duration'],
  74. 'remark' => $item['remark'] ?? '',
  75. 'sys_id' => $params['sys_id'] ?? '',
  76. ]);
  77. }
  78. $insertData = array_merge($pieceData, $timekeepInsert);
  79. if (empty($insertData)) {
  80. return ['success' => false, 'message' => '无可保存的工资数据'];
  81. }
  82. db('糊盒工资汇总')->where('sczl_rq', 'like', $params['month'] . '%')->delete();
  83. $sql = db('糊盒工资汇总')->fetchSql(true)->insertAll($insertData);
  84. $res = db()->query($sql);
  85. if ($res === false) {
  86. return ['success' => false, 'message' => '工资数据保存失败'];
  87. }
  88. return [
  89. 'success' => true,
  90. 'message' => '成功',
  91. 'piece_count' => count($pieceData),
  92. 'timekeep_count' => count($timekeepInsert),
  93. 'total_count' => count($insertData),
  94. ];
  95. } catch (\Exception $e) {
  96. return ['success' => false, 'message' => '糊盒工资计算失败: ' . $e->getMessage()];
  97. }
  98. }
  99. protected function salaryCalculationClass($role)
  100. {
  101. // 构建查询对象
  102. $query = db('糊盒报工班组')->alias('a')->where('a.id', $role);
  103. // 构建字段列表
  104. $fieldParts = [];
  105. // 添加 bh 和 rate 字段
  106. for ($i = 1; $i <= 30; $i++) {
  107. $fieldParts[] = "a.bh{$i}";
  108. $fieldParts[] = "a.rate{$i}";
  109. }
  110. // 添加 JOIN 和员工姓名字段
  111. for ($i = 1; $i <= 30; $i++) {
  112. $table = 'b' . $i;
  113. $fieldParts[] = "{$table}.员工姓名 as 员工姓名{$i}";
  114. $query->join("人事_基本资料 {$table}", "a.bh{$i} = {$table}.员工编号", 'left');
  115. }
  116. // 设置字段
  117. $query->field(implode(',', $fieldParts));
  118. return $query->find();
  119. }
  120. /**
  121. * 判断是否手工机台
  122. * @param string $jtbh
  123. * @return bool
  124. */
  125. protected function isManualMachine($jtbh)
  126. {
  127. return stripos((string)$jtbh, 'SG') !== false;
  128. }
  129. /**
  130. * 判断是否皮壳机台(机台编号含 PK)
  131. * @param string $jtbh
  132. * @return bool
  133. */
  134. protected function isShellMachine($jtbh)
  135. {
  136. return stripos((string)$jtbh, 'PK') !== false;
  137. }
  138. /**
  139. * 皮壳机机长工资系数
  140. * @param float $wage
  141. * @param string $jtbh
  142. * @param int $slotIndex 班组序号,1 为机长
  143. * @return float
  144. */
  145. protected function applyShellCaptainWageBonus($wage, $jtbh, $slotIndex)
  146. {
  147. if ((int)$slotIndex === 1 && $this->isShellMachine($jtbh)) {
  148. return floatval(number_format((float)$wage * 1.1, 2, '.', ''));
  149. }
  150. return $wage;
  151. }
  152. /**
  153. * 员工编号是否参与工资计算(仅纯数字编号)
  154. * @param mixed $bh
  155. * @return bool
  156. */
  157. protected function isValidEmployeeBh($bh)
  158. {
  159. $bh = trim((string)$bh);
  160. return $bh !== '' && $bh !== '0000' && ctype_digit($bh);
  161. }
  162. /**
  163. * 普通机台计件工资
  164. * @param array $report
  165. * @param array $classResult
  166. * @return array
  167. */
  168. protected function calculateRegularPieceWages(array $report, array $classResult)
  169. {
  170. $wageList = [];
  171. $salary = (float)$report['产量'] * (float)$report['price'];
  172. $jtbh = $report['sczl_jtbh'] ?? '';
  173. for ($i = 1; $i <= 30; $i++) {
  174. $bh = trim($classResult['bh' . $i] ?? '');
  175. if (!$this->isValidEmployeeBh($bh)) {
  176. continue;
  177. }
  178. $wage = floatval(number_format($salary * (float)$classResult['rate' . $i], 2, '.', ''));
  179. $wage = $this->applyShellCaptainWageBonus($wage, $jtbh, $i);
  180. $wageList[] = [
  181. 'bh' => $bh,
  182. 'name' => $classResult['员工姓名' . $i] ?? '',
  183. 'rate' => $classResult['rate' . $i] ?? '',
  184. 'wage' => $wage,
  185. ];
  186. }
  187. return $wageList;
  188. }
  189. /**
  190. * 手工机台计件超产工资
  191. * @param array $report
  192. * @param array $classResult
  193. * @return array
  194. */
  195. protected function calculateManualPieceWages(array $report, array $classResult)
  196. {
  197. $employees = [];
  198. $jtbh = $report['sczl_jtbh'] ?? '';
  199. for ($i = 1; $i <= 30; $i++) {
  200. $bh = trim($classResult['bh' . $i] ?? '');
  201. if (!$this->isValidEmployeeBh($bh)) {
  202. continue;
  203. }
  204. $employees[] = [
  205. 'bh' => $bh,
  206. 'name' => $classResult['员工姓名' . $i] ?? '',
  207. 'rate' => $classResult['rate' . $i] ?? '',
  208. 'slot' => $i,
  209. ];
  210. }
  211. if (empty($employees)) {
  212. return [];
  213. }
  214. $hireDates = db('人事_基本资料')
  215. ->whereIn('员工编号', array_column($employees, 'bh'))
  216. ->column('聘用日期', '员工编号');
  217. $totalOutput = (float)$report['产量'];
  218. $dailyQuota = (float)$report['日定额'];
  219. if ($dailyQuota <= 0) {
  220. $dailyQuota = (float)$report['定额代号'];
  221. }
  222. $unitPrice = (float)$report['price'];
  223. $reportDate = $report['日期'];
  224. $totalCount = count($employees);
  225. $countGt3 = 0;
  226. $count8to15 = 0;
  227. $countGt15 = 0;
  228. $allPiece = true;
  229. foreach ($employees as &$employee) {
  230. $workDays = $this->getEmployeeTenureDays($employee['bh'], $reportDate, $hireDates);
  231. $employee['work_days'] = $workDays;
  232. if ($workDays > 3) {
  233. $countGt3++;
  234. }
  235. if ($workDays >= 8 && $workDays <= 15) {
  236. $count8to15++;
  237. }
  238. if ($workDays > 15) {
  239. $countGt15++;
  240. }
  241. if ($workDays <= 7) {
  242. $allPiece = false;
  243. }
  244. }
  245. unset($employee);
  246. $wageList = [];
  247. if ($allPiece) {
  248. $overPerPerson = $totalCount > 0
  249. ? max(0, ($totalOutput - $dailyQuota * $totalCount) * $unitPrice / $totalCount)
  250. : 0;
  251. foreach ($employees as $employee) {
  252. $wage = floatval(number_format($overPerPerson, 2, '.', ''));
  253. $wage = $this->applyShellCaptainWageBonus($wage, $jtbh, $employee['slot']);
  254. $wageList[] = [
  255. 'bh' => $employee['bh'],
  256. 'name' => $employee['name'],
  257. 'rate' => $employee['rate'],
  258. 'wage' => $wage,
  259. ];
  260. }
  261. return $wageList;
  262. }
  263. $value1 = $countGt3 > 0
  264. ? max(0, ($totalOutput - $dailyQuota * $countGt3) * $unitPrice)
  265. : 0;
  266. $halfShare = $countGt3 > 0 ? $value1 / $countGt3 / 2 : 0;
  267. $value2 = max(0, $value1 - $halfShare * $count8to15);
  268. $gt15Share = $countGt15 > 0 ? $value2 / $countGt15 : 0;
  269. foreach ($employees as $employee) {
  270. $workDays = $employee['work_days'];
  271. if ($workDays <= 7) {
  272. $wage = 0;
  273. } elseif ($workDays >= 8 && $workDays <= 15) {
  274. $wage = $halfShare;
  275. } elseif ($workDays > 15) {
  276. $wage = $gt15Share;
  277. } else {
  278. $wage = 0;
  279. }
  280. $wageList[] = [
  281. 'bh' => $employee['bh'],
  282. 'name' => $employee['name'],
  283. 'rate' => $employee['rate'],
  284. 'wage' => $this->applyShellCaptainWageBonus(
  285. floatval(number_format($wage, 2, '.', '')),
  286. $jtbh,
  287. $employee['slot']
  288. ),
  289. ];
  290. }
  291. return $wageList;
  292. }
  293. /**
  294. * 计算员工上班天数
  295. * @param string $bh
  296. * @param string $reportDate
  297. * @param array $hireDates
  298. * @return int
  299. */
  300. protected function getEmployeeTenureDays($bh, $reportDate, array $hireDates)
  301. {
  302. if (empty($hireDates[$bh])) {
  303. return 0;
  304. }
  305. $hireTime = strtotime(date('Y-m-d', strtotime($hireDates[$bh])));
  306. $reportTime = strtotime(date('Y-m-d', strtotime($reportDate)));
  307. if ($hireTime === false || $reportTime === false || $reportTime < $hireTime) {
  308. return 0;
  309. }
  310. return (int)floor(($reportTime - $hireTime) / 86400) + 1;
  311. }
  312. /**
  313. * 班组计时工资计算
  314. * @param string $month 月份
  315. * @return array 班组计时工资数据
  316. */
  317. protected function teamTimekeepCalculation($month)
  318. {
  319. $bhFields = [];
  320. for ($i = 1; $i <= 30; $i++) {
  321. $bhFields[] = 'bh' . $i;
  322. }
  323. $list = db('糊盒班组计时')
  324. ->field(array_merge(['sczl_rq', 'type', 'duration', 'price', 'remark'], $bhFields))
  325. ->where('sczl_rq', 'like', $month . '%')
  326. ->select();
  327. if (empty($list)) {
  328. return [];
  329. }
  330. $employeeIds = [];
  331. foreach ($list as $row) {
  332. for ($i = 1; $i <= 30; $i++) {
  333. $bh = isset($row['bh' . $i]) ? trim($row['bh' . $i]) : '';
  334. if ($this->isValidEmployeeBh($bh)) {
  335. $employeeIds[$bh] = true;
  336. }
  337. }
  338. }
  339. $employeeNames = [];
  340. if (!empty($employeeIds)) {
  341. $employees = db('人事_基本资料')
  342. ->whereIn('员工编号', array_keys($employeeIds))
  343. ->field('员工编号, rtrim(员工姓名) as 姓名')
  344. ->select();
  345. foreach ($employees as $employee) {
  346. $employeeNames[$employee['员工编号']] = $employee['姓名'];
  347. }
  348. }
  349. $data = [];
  350. foreach ($list as $row) {
  351. $employees = [];
  352. for ($i = 1; $i <= 30; $i++) {
  353. $bh = isset($row['bh' . $i]) ? trim($row['bh' . $i]) : '';
  354. if ($this->isValidEmployeeBh($bh)) {
  355. $employees[] = $bh;
  356. }
  357. }
  358. if (empty($employees)) {
  359. continue;
  360. }
  361. $employeeCount = count($employees);
  362. $salaryPerEmployee = ((float)$row['duration'] * (float)$row['price']) / $employeeCount;
  363. $ymd = date('Ymd', strtotime($row['sczl_rq']));
  364. foreach ($employees as $bh) {
  365. $name = $employeeNames[$bh] ?? '';
  366. $key = $ymd . '-' . $bh . '-' . $name . '-' . $row['price'];
  367. $durationPerEmployee = (float)$row['duration'] / $employeeCount;
  368. if (isset($data[$key])) {
  369. $data[$key]['duration'] = floatval(number_format((float)$data[$key]['duration'] + $durationPerEmployee, 2, '.', ''));
  370. $data[$key]['salary'] = floatval(number_format($data[$key]['salary'] + $salaryPerEmployee, 2, '.', ''));
  371. if ($row['type'] !== '' && strpos($data[$key]['type'], $row['type']) === false) {
  372. $data[$key]['type'] = trim($data[$key]['type'] . ',' . $row['type'], ',');
  373. }
  374. if ($row['remark'] !== '' && strpos($data[$key]['remark'], $row['remark']) === false) {
  375. $data[$key]['remark'] = trim($data[$key]['remark'] . ',' . $row['remark'], ',');
  376. }
  377. continue;
  378. }
  379. $data[$key] = [
  380. 'sczl_rq' => date('Y-m-d', strtotime($row['sczl_rq'])),
  381. 'type' => $row['type'],
  382. 'duration' => floatval(number_format($durationPerEmployee, 2, '.', '')),
  383. 'price' => $row['price'],
  384. 'remark' => $row['remark'],
  385. 'bh' => $bh,
  386. '姓名' => $name,
  387. 'salary' => floatval(number_format($salaryPerEmployee, 2, '.', '')),
  388. ];
  389. }
  390. }
  391. return $data;
  392. }
  393. /**
  394. * 计算糊盒计时工资
  395. * @param string $month 月份
  396. * @return array 糊盒计时工资数据
  397. */
  398. protected function calculateTimekeepSalary($month)
  399. {
  400. $list = db('糊盒报工机时')
  401. ->field(['wgjs_rq', 'wgjs_bh1', 'wgjs_js1', 'wgjs_yy1', 'wgjs_je1',
  402. 'wgjs_bh2', 'wgjs_js2', 'wgjs_yy2', 'wgjs_je2',
  403. 'wgjs_bh3', 'wgjs_js3', 'wgjs_yy3', 'wgjs_je3',
  404. 'wgjs_bh4', 'wgjs_js4', 'wgjs_yy4', 'wgjs_je4',
  405. 'wgjs_bh5', 'wgjs_js5', 'wgjs_yy5', 'wgjs_je5',
  406. 'wgjs_bh6', 'wgjs_js6', 'wgjs_yy6', 'wgjs_je6'])
  407. ->where('wgjs_rq', 'like', $month . '%')
  408. ->select();
  409. if (empty($list)) {
  410. return [];
  411. }
  412. $employeeIds = [];
  413. foreach ($list as $row) {
  414. for ($i = 1; $i <= 6; $i++) {
  415. $bh = isset($row['wgjs_bh' . $i]) ? trim($row['wgjs_bh' . $i]) : '';
  416. if ($this->isValidEmployeeBh($bh)) {
  417. $employeeIds[$bh] = true;
  418. }
  419. }
  420. }
  421. $employeeNames = [];
  422. if (!empty($employeeIds)) {
  423. $employees = db('人事_基本资料')
  424. ->whereIn('员工编号', array_keys($employeeIds))
  425. ->field('员工编号, rtrim(员工姓名) as 姓名')
  426. ->select();
  427. foreach ($employees as $employee) {
  428. $employeeNames[$employee['员工编号']] = $employee['姓名'];
  429. }
  430. }
  431. $data = [];
  432. foreach ($list as $row) {
  433. $ymd = date('Ymd', strtotime($row['wgjs_rq']));
  434. $sczl_rq = date('Y-m-d', strtotime($row['wgjs_rq']));
  435. for ($i = 1; $i <= 6; $i++) {
  436. $bh = isset($row['wgjs_bh' . $i]) ? trim($row['wgjs_bh' . $i]) : '';
  437. if (!$this->isValidEmployeeBh($bh)) {
  438. continue;
  439. }
  440. $duration = isset($row['wgjs_js' . $i]) ? (float)$row['wgjs_js' . $i] : 0;
  441. $type = isset($row['wgjs_yy' . $i]) ? trim($row['wgjs_yy' . $i]) : '';
  442. $salary = isset($row['wgjs_je' . $i]) ? (float)$row['wgjs_je' . $i] : 0;
  443. $price = '';
  444. $name = $employeeNames[$bh] ?? '';
  445. $key = $ymd . '-' . $bh . '-' . $name . '-' . $price;
  446. if (isset($data[$key])) {
  447. $data[$key]['duration'] = floatval(number_format((float)$data[$key]['duration'] + $duration, 2, '.', ''));
  448. $data[$key]['salary'] = floatval(number_format((float)$data[$key]['salary'] + $salary, 2, '.', ''));
  449. if ($type !== '' && strpos($data[$key]['type'], $type) === false) {
  450. $data[$key]['type'] = trim($data[$key]['type'] . ',' . $type, ',');
  451. }
  452. continue;
  453. }
  454. $data[$key] = [
  455. 'sczl_rq' => $sczl_rq,
  456. 'type' => $type,
  457. 'duration' => floatval(number_format($duration, 2, '.', '')),
  458. 'price' => '',
  459. 'remark' => '',
  460. 'bh' => $bh,
  461. '姓名' => $name,
  462. 'salary' => floatval(number_format($salary, 2, '.', '')),
  463. ];
  464. }
  465. }
  466. return $data;
  467. }
  468. /**
  469. * 合并计时工资数据
  470. * @param array $data1
  471. * @param array $data2
  472. * @return array
  473. */
  474. protected function mergeTimekeepSalaryData(array $data1, array $data2)
  475. {
  476. $data = $data1;
  477. foreach ($data2 as $key => $item) {
  478. if (!isset($data[$key])) {
  479. $data[$key] = $item;
  480. continue;
  481. }
  482. $data[$key]['duration'] = floatval(number_format((float)$data[$key]['duration'] + (float)$item['duration'], 2, '.', ''));
  483. $data[$key]['salary'] = floatval(number_format((float)$data[$key]['salary'] + (float)$item['salary'], 2, '.', ''));
  484. if (!empty($item['type']) && strpos($data[$key]['type'], $item['type']) === false) {
  485. $data[$key]['type'] = trim($data[$key]['type'] . ',' . $item['type'], ',');
  486. }
  487. if (!empty($item['remark']) && strpos($data[$key]['remark'], $item['remark']) === false) {
  488. $data[$key]['remark'] = trim($data[$key]['remark'] . ',' . $item['remark'], ',');
  489. }
  490. }
  491. return $data;
  492. }
  493. /**
  494. * 构建计件工资汇总行(仅填 price、salary,计时字段为 0)
  495. * @param array $fields
  496. * @return array
  497. */
  498. protected function buildPieceSalarySummaryRow(array $fields = [])
  499. {
  500. return $this->buildSalarySummaryRow(array_merge([
  501. 'time_salary' => 0,
  502. 'time_price' => 0,
  503. 'time_duration' => 0,
  504. 'remark' => '',
  505. ], $fields));
  506. }
  507. /**
  508. * 构建计时工资汇总行(仅填 time_price、time_salary、time_duration、remark,计件字段为 0)
  509. * @param array $fields
  510. * @return array
  511. */
  512. protected function buildTimekeepSalarySummaryRow(array $fields = [])
  513. {
  514. return $this->buildSalarySummaryRow(array_merge([
  515. 'sczl_gdbh' => '',
  516. 'sczl_gxmc' => '',
  517. 'sczl_dedh' => '',
  518. 'sczl_cl' => 0,
  519. '工价系数' => '',
  520. '保养工时' => '',
  521. '装版工时' => '',
  522. '异常工时' => '',
  523. '设备运行工时' => '',
  524. 'sczl_jtbh' => '',
  525. 'cpdh' => '',
  526. 'cpmc' => '',
  527. 'rate' => '',
  528. 'salary' => 0,
  529. 'price' => 0,
  530. ], $fields));
  531. }
  532. /**
  533. * 构建工资汇总统一字段结构
  534. * @param array $fields
  535. * @return array
  536. */
  537. protected function buildSalarySummaryRow(array $fields = [])
  538. {
  539. $defaults = [
  540. 'sczl_gdbh' => '',
  541. 'sczl_gxmc' => '',
  542. 'sczl_rq' => '',
  543. 'sczl_dedh' => '',
  544. 'sczl_cl' => 0,
  545. '工价系数' => '',
  546. '保养工时' => '',
  547. '装版工时' => '',
  548. '异常工时' => '',
  549. '设备运行工时' => '',
  550. 'sczl_jtbh' => '',
  551. 'cpdh' => '',
  552. 'cpmc' => '',
  553. 'bh' => '',
  554. 'rate' => '',
  555. 'name' => '',
  556. 'salary' => 0,
  557. 'time_salary' => 0,
  558. 'price' => 0,
  559. 'time_price' => 0,
  560. 'time_duration' => 0,
  561. 'remark' => '',
  562. 'sys_id' => '',
  563. 'sys_rq' => date('Y-m-d H:i:s'),
  564. ];
  565. $row = array_merge($defaults, $fields);
  566. $decimalFields = ['sczl_cl', 'salary', 'time_salary', 'price', 'time_price', 'time_duration'];
  567. foreach ($decimalFields as $field) {
  568. if (!isset($row[$field]) || $row[$field] === '' || $row[$field] === null) {
  569. $row[$field] = 0;
  570. } else {
  571. $row[$field] = is_numeric($row[$field]) ? (float)$row[$field] : 0;
  572. }
  573. }
  574. return $row;
  575. }
  576. }