|
|
@@ -1074,7 +1074,13 @@ class GluingReport extends Api
|
|
|
*/
|
|
|
protected function isEmptyReportPrice($price)
|
|
|
{
|
|
|
- return $price === null || $price === '';
|
|
|
+ if ($price === null || $price === '') {
|
|
|
+ return true;
|
|
|
+ }
|
|
|
+ if (is_string($price) && trim($price) === '') {
|
|
|
+ return true;
|
|
|
+ }
|
|
|
+ return is_numeric($price) && (float)$price == 0;
|
|
|
}
|
|
|
|
|
|
/**
|
|
|
@@ -1085,17 +1091,22 @@ class GluingReport extends Api
|
|
|
protected function resolveReportPrice(array $param)
|
|
|
{
|
|
|
$machine = trim($param['sczl_jtbh']);
|
|
|
- $gxmc = trim($param['sczl_gxmc']);
|
|
|
+ $gxmc = trim((string)($param['sczl_gxmc'] ?? $param['gxmc'] ?? ''));
|
|
|
$count = $this->extractManualProcessCountSilent($param);
|
|
|
+ $processText = $this->resolveManualProcessText($machine, $gxmc);
|
|
|
|
|
|
- $machinePrices = $this->collectMachinePriceValues($machine);
|
|
|
- if (!empty($machinePrices)) {
|
|
|
- return (float)$machinePrices[0];
|
|
|
+ if ($processText !== '') {
|
|
|
+ $manualPrice = $this->resolveManualProcessPriceSilent($processText, $count);
|
|
|
+ if ($manualPrice !== null) {
|
|
|
+ return $manualPrice;
|
|
|
+ }
|
|
|
}
|
|
|
|
|
|
- $manualPrice = $this->resolveManualProcessPriceSilent($gxmc, $count);
|
|
|
- if ($manualPrice !== null) {
|
|
|
- return $manualPrice;
|
|
|
+ if (!$this->isManualMachineId($machine)) {
|
|
|
+ $machinePrices = $this->collectMachinePriceValues($machine);
|
|
|
+ if (!empty($machinePrices)) {
|
|
|
+ return (float)$machinePrices[0];
|
|
|
+ }
|
|
|
}
|
|
|
|
|
|
$aiService = new Aicompute();
|
|
|
@@ -1124,6 +1135,45 @@ class GluingReport extends Api
|
|
|
return (float)$rates[0]['piece_price'];
|
|
|
}
|
|
|
|
|
|
+ /**
|
|
|
+ * 判断是否手工工序 machine_id
|
|
|
+ * @param string $machine
|
|
|
+ * @return bool
|
|
|
+ */
|
|
|
+ protected function isManualMachineId($machine)
|
|
|
+ {
|
|
|
+ static $manualIds = ['手工割围条', '手工打孔', '手工拆片', '手工贴片', '手工贴磁铁'];
|
|
|
+ return in_array(trim((string)$machine), $manualIds, true);
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 从机台编号/工序名称中识别手工工序文本
|
|
|
+ * @param string $machine
|
|
|
+ * @param string $gxmc
|
|
|
+ * @return string
|
|
|
+ */
|
|
|
+ protected function resolveManualProcessText($machine, $gxmc)
|
|
|
+ {
|
|
|
+ if ($this->isManualMachineId($machine)) {
|
|
|
+ return trim($machine);
|
|
|
+ }
|
|
|
+
|
|
|
+ $keywords = ['割围条', '打孔', '拆片', '贴磁铁', '贴片'];
|
|
|
+ foreach ([$gxmc, $machine] as $text) {
|
|
|
+ $text = trim((string)$text);
|
|
|
+ if ($text === '') {
|
|
|
+ continue;
|
|
|
+ }
|
|
|
+ foreach ($keywords as $keyword) {
|
|
|
+ if (strpos($text, $keyword) !== false) {
|
|
|
+ return $text;
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ return '';
|
|
|
+ }
|
|
|
+
|
|
|
/**
|
|
|
* 收集机台单价列表
|
|
|
* @param string $machine
|
|
|
@@ -1199,14 +1249,17 @@ class GluingReport extends Api
|
|
|
*/
|
|
|
protected function extractManualProcessCountSilent(array $params)
|
|
|
{
|
|
|
- if (!isset($params['count']) || $params['count'] === '') {
|
|
|
- return null;
|
|
|
- }
|
|
|
- if (!is_numeric($params['count']) || (int)$params['count'] != $params['count'] || (int)$params['count'] <= 0) {
|
|
|
- return null;
|
|
|
+ foreach (['count', '孔数', '拼数', 'hole_count', 'piece_count'] as $field) {
|
|
|
+ if (!isset($params[$field]) || $params[$field] === '') {
|
|
|
+ continue;
|
|
|
+ }
|
|
|
+ if (!is_numeric($params[$field]) || (int)$params[$field] != $params[$field] || (int)$params[$field] <= 0) {
|
|
|
+ continue;
|
|
|
+ }
|
|
|
+ return (int)$params[$field];
|
|
|
}
|
|
|
|
|
|
- return (int)$params['count'];
|
|
|
+ return null;
|
|
|
}
|
|
|
|
|
|
/**
|
|
|
@@ -1312,36 +1365,40 @@ class GluingReport extends Api
|
|
|
}
|
|
|
|
|
|
$machine = trim($params['machine']);
|
|
|
+ $gxmc = trim((string)($params['gxmc'] ?? $params['sczl_gxmc'] ?? ''));
|
|
|
+ $processText = $this->resolveManualProcessText($machine, $gxmc);
|
|
|
|
|
|
- // 1. 优先按机台编号查询
|
|
|
- $list = db('machine_price')
|
|
|
- ->where('machine_id', $machine)
|
|
|
- ->field('price1,price2,price3,price4,price5,price6,price7,price8,price9,price10')
|
|
|
- ->select();
|
|
|
+ if ($processText !== '') {
|
|
|
+ $price = $this->resolveManualProcessPriceByGxmc($processText, $params);
|
|
|
+ if ($price !== null) {
|
|
|
+ $this->success('获取成功', [$price]);
|
|
|
+ }
|
|
|
+ }
|
|
|
|
|
|
- $result = [];
|
|
|
- foreach ($list as $item) {
|
|
|
- foreach ($item as $value) {
|
|
|
- if ($value !== '' && $value !== null) {
|
|
|
- $result[] = $value;
|
|
|
+ if (!$this->isManualMachineId($machine)) {
|
|
|
+ $list = db('machine_price')
|
|
|
+ ->where('machine_id', $machine)
|
|
|
+ ->field('price1,price2,price3,price4,price5,price6,price7,price8,price9,price10')
|
|
|
+ ->select();
|
|
|
+
|
|
|
+ $result = [];
|
|
|
+ foreach ($list as $item) {
|
|
|
+ foreach ($item as $value) {
|
|
|
+ if ($value !== '' && $value !== null) {
|
|
|
+ $result[] = $value;
|
|
|
+ }
|
|
|
}
|
|
|
}
|
|
|
- }
|
|
|
- if (!empty($result)) {
|
|
|
- $this->success('获取成功', $result);
|
|
|
+ if (!empty($result)) {
|
|
|
+ $this->success('获取成功', $result);
|
|
|
+ }
|
|
|
}
|
|
|
|
|
|
- // 2. 机台编号查不到,按手工工序查询
|
|
|
- $gxmc = trim((string)($params['gxmc'] ?? ''));
|
|
|
- if ($gxmc === '') {
|
|
|
+ if ($processText === '') {
|
|
|
$this->error('未找到机台单价,请传入工序名称');
|
|
|
}
|
|
|
|
|
|
- $price = $this->resolveManualProcessPriceByGxmc($gxmc, $params);
|
|
|
- if ($price === null) {
|
|
|
- $this->error('未找到匹配的单价');
|
|
|
- }
|
|
|
- $this->success('获取成功', [$price]);
|
|
|
+ $this->error('未找到匹配的单价');
|
|
|
}
|
|
|
|
|
|
/**
|
|
|
@@ -1421,13 +1478,21 @@ class GluingReport extends Api
|
|
|
*/
|
|
|
protected function extractManualProcessCount(array $params)
|
|
|
{
|
|
|
- if (!isset($params['count']) || $params['count'] === '') {
|
|
|
- return null;
|
|
|
- }
|
|
|
- if (!is_numeric($params['count']) || (int)$params['count'] != $params['count'] || (int)$params['count'] <= 0) {
|
|
|
+ return $this->extractManualProcessCountSilent($params);
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 提取孔数/拼数(前端传入纯数字,缺失时报错)
|
|
|
+ * @param array $params
|
|
|
+ * @return int
|
|
|
+ */
|
|
|
+ protected function requireManualProcessCount(array $params)
|
|
|
+ {
|
|
|
+ $count = $this->extractManualProcessCountSilent($params);
|
|
|
+ if ($count === null) {
|
|
|
$this->error('孔数/拼数必须为大于0的整数');
|
|
|
}
|
|
|
- return (int)$params['count'];
|
|
|
+ return $count;
|
|
|
}
|
|
|
|
|
|
/**
|