12345678910111213141516171819202122232425262728293031323334353637383940 |
- <?php
- namespace app\common\validate;
- use think\Db;
- use think\Validate;
- class Dinner extends Validate{
- protected $rule = [
- 'title|名称' => 'require',
- 'cate_id|分类' => 'require',
- 'day|售卖日期' => 'require|date|checkUnique',
- ];
- protected $message = [
- ];
- protected $scene = [
- ];
- protected function checkUnique($value,$rule,$data=[])
- {
- $info = Db::name('dinner')
- ->where('title',$data['title'])
- ->where('del',0)
- ->where('day',$data['day'])
- ->where('cate_id',$data['cate_id'])
- ->find();
- if($data['id'] <= 0 && $info){
- return '名称已被使用';
- }
- if($info && $data['id'] > 0 && $info['id'] != $data['id']){
- return '名称已被使用';
- }
- return true;
- }
- }
|