123456789101112131415161718192021222324252627282930313233343536373839404142 |
- <?php
- namespace app\common\validate;
- use think\Validate;
- use think\Db;
- class GGoods extends Validate{
- protected $rule = [
- 'title|商品名称' => 'require|length:1,20|checkUnique',
- 'price|商品价格' => 'require',
- 'stock|库存' => 'require',
- 'cate_id|商品分类' => 'require|gt:0',
- 'img|商品图片' => 'require',
- 'imgs|宣传图' => 'require',
- 'content|详情' => 'require',
- ];
- protected $message = [
- 'cate_id.require'=>'商品分类不能为空',
- 'cate_id.gt'=>'商品分类不能为空'
- ];
- protected function checkUnique($value, $rule, $data=[]){
- if(isset($data['id']) && $data['id'] > 0){
- $ret = Db::name('g_goods')
- ->where('del',0)
- ->where('title',$data['title'])
- ->where('org_id',$data['org_id'])
- ->where('id','<>',$data['id'])
- ->find();
- }else{
- $ret = Db::name('g_goods')
- ->where('del',0)
- ->where('title',$data['title'])
- ->where('org_id',$data['org_id'])
- ->find();
- }
- return $ret?'名称已被使用':true;
- }
- }
|