66 lines
2.5 KiB
PHP
66 lines
2.5 KiB
PHP
|
<?php
|
||
|
|
||
|
namespace app\action;
|
||
|
|
||
|
use Exception;
|
||
|
use libs\db\Db;
|
||
|
|
||
|
/**
|
||
|
* ERP采购入库查询对接接口
|
||
|
* Class SetSupplier
|
||
|
* @package app\action
|
||
|
*/
|
||
|
class SetPurchaseInboundResult
|
||
|
{
|
||
|
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 '';
|
||
|
}
|
||
|
}
|