engineering/app/adminapi/validate/quotation/QuotationValidate.php
2024-03-21 14:16:47 +08:00

170 lines
4.9 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
// +----------------------------------------------------------------------
// | likeadmin快速开发前后端分离管理后台PHP版
// +----------------------------------------------------------------------
// | 欢迎阅读学习系统程序代码,建议反馈是我们前进的动力
// | 开源版本可自由商用可去除界面版权logo
// | gitee下载https://gitee.com/likeshop_gitee/likeadmin
// | github下载https://github.com/likeshop-github/likeadmin
// | 访问官网https://www.likeadmin.cn
// | likeadmin团队 版权所有 拥有最终解释权
// +----------------------------------------------------------------------
// | author: likeadminTeam
// +----------------------------------------------------------------------
namespace app\adminapi\validate\quotation;
use app\common\model\custom\Custom;
use app\common\model\dict\DictData;
use app\common\model\material\Material;
use app\common\model\quotation\QuotationDetail;
use app\common\validate\BaseValidate;
/**
* 报价单验证器
* Class QuotationValidate
* @package app\adminapi\validate\quotation
*/
class QuotationValidate extends BaseValidate
{
/**
* 设置校验规则
* @var string[]
*/
protected $rule = [
'id' => 'require',
'custom_id' => 'require|checkCustom',
'quotation_date' => 'dateFormat:Y-m-d',
'invoice_type' => 'checkInvoiceType',
'freight' => 'require|float|egt:0',
'other_fee' => 'require|float|egt:0',
'annex' => 'checkAnnex',
'quotation_detail' => 'require|checkQuotationDetail',
];
protected $message = [
'id.require' => '缺少必要参数',
'custom_id.require' => '请选择客户',
'quotation_date.dateFormat' => '报价日期格式错误',
'freight.require' => '运费不能为空',
'freight.float' => '运费值必须是数字',
'freight.egt' => '运费值必须大于等于0',
'other_fee.require' => '其它费用不能为空',
'other_fee.float' => '其它费用值必须是数字',
'other_fee.egt' => '其它费用值必须大于等于0',
'quotation_detail.require' => '报价明细不能为空',
];
/**
* @notes 添加场景
* @return QuotationValidate
* @author likeadmin
* @date 2023/11/27 17:23
*/
public function sceneAdd()
{
return $this->remove('id', true);
}
/**
* @notes 编辑场景
* @return QuotationValidate
* @author likeadmin
* @date 2023/11/27 17:23
*/
public function sceneEdit()
{
}
/**
* @notes 删除场景
* @return QuotationValidate
* @author likeadmin
* @date 2023/11/27 17:23
*/
public function sceneDelete()
{
return $this->only(['id'])->remove('id', 'checkData');
}
/**
* @notes 详情场景
* @return QuotationValidate
* @author likeadmin
* @date 2023/11/27 17:23
*/
public function sceneDetail()
{
return $this->only(['id']);
}
public function checkCustom($value): bool|string
{
$custom = Custom::where('id', $value)->findOrEmpty();
if ($custom->isEmpty()) {
return '客户不存在';
}
return true;
}
public function checkInvoiceType($value): bool|string
{
$dictData = DictData::where('type_value', 'invoice_type')->column('value');
if (!in_array($value, $dictData)) {
return '发票类型无效';
}
return true;
}
public function checkQuotationDetail($value): bool|string
{
if (!empty($value) && !is_array($value)) {
return '报价明细数据格式错误';
}
foreach ($value as $k => $v) {
if (!empty($v['id'])) {
$quotation_detail = QuotationDetail::where('id', $v['id'])->findOrEmpty();
if ($quotation_detail->isEmpty()) return '报价明细列表第' . ($k + 1) . '行报价明细数据不存在';
}
if (empty($v['product_id'])) {
return '请选择产品';
} else {
$product = Material::where('id', $v['product_id'])->findOrEmpty();
if ($product->isEmpty()) {
return '产品信息不存在';
}
}
if (empty($v['num'])) {
return '报价明细列表第' . ($k + 1) . '行数量不能为空';
} else {
if (!is_numeric($v['num']) || $v['num'] < 0) {
return '报价明细列表第' . ($k + 1) . '行数量必须是大于0的数字';
}
}
if (empty($v['tax_rate'])) {
return '报价明细列表第' . ($k + 1) . '行税率不能为空';
} else {
$tax_rate_dict_data = DictData::where('type_value', 'tax_rate')->column('value');
if (!in_array($v['tax_rate'], $tax_rate_dict_data)) {
return '报价明细列表第' . ($k + 1) . '行税率无效';
}
}
if (empty($v['tax_inclusive_price'])) {
return '报价明细列表第' . ($k + 1) . '行含税单价不能为空';
} else {
if (!is_numeric($v['tax_inclusive_price']) || $v['tax_inclusive_price'] < 0) {
return '报价明细列表第' . ($k + 1) . '行含税单价必须是大于0的数字';
}
}
}
return true;
}
}