SCTMES_V5/mes_in_sct/app/action/SetMaterialOutboundResult.php

66 lines
2.5 KiB
PHP
Raw Normal View History

2025-06-14 18:55:09 +08:00
<?php
namespace app\action;
use Exception;
use libs\db\Db;
/**
* ERP材料出库查询对接接口
* Class SetSupplier
* @package app\action
*/
class SetMaterialOutboundResult
{
public function execute($post)
{
// 验证数据
$param = check_valid($post['action'], [
['listData', 'array', '材料出库查询数据集'],
], $post['param']);
try {
$listData = $param['listData'];
// 检索是否存在必要字段
foreach ($listData as $index => $item) {
$idx = $index + 1;
$check_feilds = [
['name' => 'source_herder_num', 'feild_type' => 'string', 'required' => true, 'len' => 100],
['name' => 'source_line_num', 'feild_type' => 'string', 'required' => true, 'len' => 100],
['name' => 'result', 'feild_type' => 'string', 'required' => false, 'len' => 100],
['name' => 'messsage', 'feild_type' => 'string', 'required' => false, 'len' => 100],
];
foreach ($check_feilds as $val) {
if (!isset($item[$val['name']])) {
throw new Exception("材料出库查询数据集第[{$idx}]位置数据对象不存在字段[{$val['name']}]", 4001);
}
if ($val['required']) {
if ($val['feild_type'] == 'string') {
// 判断是否是一个字符串
if (!is_string($item[$val['name']])) {
throw new Exception("材料出库查询数据集第[{$idx}]位置数据对象[{$val['name']}]的值不是字符串类型,请检查!", 4001);
}
// 判断长度
if (strlen($item[$val['name']]) > $val['len']) {
throw new Exception("材料出库查询数据集第[{$idx}]位置数据对象[{$val['name']}]的值不符合规定的长度[{$val['len']}],请检查!", 4001);
}
}
if (empty($item[$val['name']])) {
throw new Exception("材料出库查询数据集第[{$idx}]位置数据对象字段[{$val['name']}]的值不能为空", 4001);
}
}
}
}
} catch (Exception $e) {
throw new Exception($e->getMessage(), $e->getCode() ? $e->getCode() : 4001);
}
return '';
}
}