erp/app/api/validate/OpurchaseGoodsOfferValidate.php

51 lines
1.4 KiB
PHP

<?php
namespace app\api\validate;
use app\common\model\opurchase\OpurchaseGoodsOffer;
use app\common\validate\BaseValidate;
class OpurchaseGoodsOfferValidate extends BaseValidate
{
protected $rule = [
'data' => 'require|checkData',
'delivery_name' => 'require',
'delivery_id' => 'require',
];
protected $message = [
'data.require' => '参数缺失',
'delivery_name.require' => '快递名称/送货人姓名',
'delivery_id.require' => '快递单号/手机号',
];
public function sceneOffer(): OpurchaseGoodsOfferValidate
{
return $this->only(['data']);
}
public function sceneExpress()
{
return $this->only(['delivery_name','delivery_id']);
}
public function checkData($value){
if(!is_array($value)) return '参数数据格式错误';
foreach($value as $k => $v){
if(!isset($v['id']) || $v['id'] == ''){
return '第'.($k+1).'行缺少数据主键';
}else{
$data = OpurchaseGoodsOffer::where('id',$v['id'])->where('is_adopt',0)->findOrEmpty();
if($data->isEmpty()) return '第'.($k+1).'行数据信息不存在';
}
if(!isset($v['price']) || $v['price'] == '') {
return '第'.($k+1).'行缺少价格';
}
if(!isset($v['nums']) || $v['nums'] == '') {
return '第'.($k+1).'行缺少数量';
}
if($data['nums']<$v['nums']){
return '第'.($k+1).'行数量不能大于采购数量';
}
}
return true;
}
}