1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253 |
- <?php
- namespace app\common\validate;
- use think\Db;
- use think\Validate;
- class ShopDay extends Validate
- {
- /**
- * 定义验证规则
- * 格式:'字段名' => ['规则1','规则2'...]
- *
- * @var array
- */
- protected $rule = [
- 'day|排餐日期' => 'require',
- 'cate|排餐类型' => 'require|checkCate',
- 'goods|商品' => 'require',
- 'start|时间段' => 'require',
- 'end|时间段' => 'require',
- ];
- /**
- * 定义错误信息
- * 格式:'字段名.规则名' => '错误信息'
- *
- * @var array
- */
- protected $message = [
- 'start.require'=>'未选择时间',
- 'end.require'=>'未选择时间',
- ];
- protected function checkCate($value, $rule, $data=[]){
- if(isset($data['id']) && $data['id'] > 0){
- $ret = Db::name('shop_day')
- ->where('day',$data['day'])
- ->where('cate',$data['cate'])
- ->where('org_id',$data['org_id'])
- ->where('id','<>',$data['id'])
- ->find();
- }else{
- $ret = Db::name('shop_day')
- ->where('day',$data['day'])
- ->where('cate',$data['cate'])
- ->where('org_id',$data['org_id'])
- ->find();
- }
- return $ret?'同一日期同一类型不能重复':true;
- }
- }
|