Files
OMS/app/erpapi/lib/invoice/response/params/abstract.php
2025-12-28 23:13:25 +08:00

63 lines
2.2 KiB
PHP
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
<?php
/**
* Copyright © ShopeX http://www.shopex.cn. All rights reserved.
* See LICENSE file for license details.
*/
abstract class erpapi_invoice_response_params_abstract
{
/**
* 检查
* @param mixed $params 参数
* @param mixed $method method
* @return mixed 返回验证结果
*/
public function check($params,$method)
{
$check_params = $this->{$method}();
if (!$check_params || !is_array($check_params)) return array('rsp'=>'succ');
foreach ($check_params as $col => $valid) {
if ($valid['required']=='true' && !$params[$col]) {
$msg = $valid['errmsg'] ? $valid['errmsg'] : "{$col} required";
return array('rsp'=>'fail', 'msg'=>$msg);
}
switch ($valid['type']) {
case 'date':
if ($params[$col] && !preg_match('/^\d{4}\-\d{2}\-\d{2} \d{2}:\d{2}:\d{2}$/', $params[$col])) {
$msg = $valid['errmsg'] ? $valid['errmsg'] : '日期格式有误';
return array('rsp'=>'fail', 'msg'=>$msg);
}
break;
case 'string':
if (!is_string($params[$col])) {
$msg = $valid['errmsg'] ? $valid['errmsg'] : "{$col} must be string";
return array('rsp'=>'fail', 'msg'=>$msg);
}
break;
case 'enum':
if (!in_array($params[$col],$valid['value'])) {
$msg = $valid['errmsg'] ? $valid['errmsg'] : "{$col}: only ".implode('|', $valid['value']).' can be choise';
return array('rsp'=>'fail', 'msg'=>$msg);
}
break;
case 'array':
if (!is_array($params[$col]) || !$params[$col]) {
$msg = $valid['errmsg'] ? $valid['errmsg'] : "{$col} must be array";
return array('rsp'=>'fail', 'msg'=>$msg);
}
break;
default:
# code...
break;
}
}
return array('rsp'=>'succ','msg'=>'');
}
}