其余文件
This commit is contained in:
70
app/admin/validate/goods/BrandValidate.php
Normal file
70
app/admin/validate/goods/BrandValidate.php
Normal file
@ -0,0 +1,70 @@
|
||||
<?php
|
||||
// +----------------------------------------------------------------------
|
||||
// | likeshop开源商城系统
|
||||
// +----------------------------------------------------------------------
|
||||
// | 欢迎阅读学习系统程序代码,建议反馈是我们前进的动力
|
||||
// | gitee下载:https://gitee.com/likeshop_gitee
|
||||
// | github下载:https://github.com/likeshop-github
|
||||
// | 访问官网:https://www.likeshop.cn
|
||||
// | 访问社区:https://home.likeshop.cn
|
||||
// | 访问手册:http://doc.likeshop.cn
|
||||
// | 微信公众号:likeshop技术社区
|
||||
// | likeshop系列产品在gitee、github等公开渠道开源版本可免费商用,未经许可不能去除前后端官方版权标识
|
||||
// | likeshop系列产品收费版本务必购买商业授权,购买去版权授权后,方可去除前后端官方版权标识
|
||||
// | 禁止对系统程序代码以任何目的,任何形式的再发布
|
||||
// | likeshop团队版权所有并拥有最终解释权
|
||||
// +----------------------------------------------------------------------
|
||||
// | author: likeshop.cn.team
|
||||
// +----------------------------------------------------------------------
|
||||
|
||||
namespace app\admin\validate\goods;
|
||||
|
||||
|
||||
use app\common\basics\Validate;
|
||||
use app\common\model\goods\Goods;
|
||||
|
||||
|
||||
/**
|
||||
* 商品品牌
|
||||
* Class GoodsBrandValidate
|
||||
* @package app\admin\validate
|
||||
*/
|
||||
class BrandValidate extends Validate
|
||||
{
|
||||
|
||||
protected $rule = [
|
||||
'id' => 'require',
|
||||
'name' => 'require|unique:goodsBrand,name&del',
|
||||
'initial' => 'require',
|
||||
'image' => 'require'
|
||||
];
|
||||
|
||||
protected $message = [
|
||||
'id.require' => '参数缺失',
|
||||
'name.require' => '参数缺失',
|
||||
'name.unique' => '该名称已被使用',
|
||||
'initial.unique' => '请选择品牌首字母',
|
||||
'image.require' => '请选择品牌图片',
|
||||
];
|
||||
|
||||
protected $scene = [
|
||||
'add' => ['name', 'initial', 'image'],
|
||||
'edit' => ['id','name', 'initial', 'image'],
|
||||
];
|
||||
|
||||
public function sceneDel()
|
||||
{
|
||||
return $this->only(['id'])
|
||||
->append('id','checkDel');
|
||||
}
|
||||
|
||||
|
||||
protected function checkDel($value,$rule,$data)
|
||||
{
|
||||
$check = Goods::where('brand_id', $value)->find();
|
||||
if ($check) {
|
||||
return '品牌已经关联商品,无法删除品牌';
|
||||
}
|
||||
return true;
|
||||
}
|
||||
}
|
||||
149
app/admin/validate/goods/CategoryValidate.php
Normal file
149
app/admin/validate/goods/CategoryValidate.php
Normal file
@ -0,0 +1,149 @@
|
||||
<?php
|
||||
// +----------------------------------------------------------------------
|
||||
// | likeshop开源商城系统
|
||||
// +----------------------------------------------------------------------
|
||||
// | 欢迎阅读学习系统程序代码,建议反馈是我们前进的动力
|
||||
// | gitee下载:https://gitee.com/likeshop_gitee
|
||||
// | github下载:https://github.com/likeshop-github
|
||||
// | 访问官网:https://www.likeshop.cn
|
||||
// | 访问社区:https://home.likeshop.cn
|
||||
// | 访问手册:http://doc.likeshop.cn
|
||||
// | 微信公众号:likeshop技术社区
|
||||
// | likeshop系列产品在gitee、github等公开渠道开源版本可免费商用,未经许可不能去除前后端官方版权标识
|
||||
// | likeshop系列产品收费版本务必购买商业授权,购买去版权授权后,方可去除前后端官方版权标识
|
||||
// | 禁止对系统程序代码以任何目的,任何形式的再发布
|
||||
// | likeshop团队版权所有并拥有最终解释权
|
||||
// +----------------------------------------------------------------------
|
||||
// | author: likeshop.cn.team
|
||||
// +----------------------------------------------------------------------
|
||||
|
||||
namespace app\admin\validate\goods;
|
||||
|
||||
use think\Validate;
|
||||
use app\common\model\goods\GoodsCategory as GoodsCategoryModel;
|
||||
use app\common\model\goods\Goods as GoodsModel;
|
||||
use app\admin\logic\goods\CategoryLogic;
|
||||
|
||||
class CategoryValidate extends Validate
|
||||
{
|
||||
protected $rule = [
|
||||
'id' => 'require|checkCategory',
|
||||
'name' => 'require|max: 30|checkName',
|
||||
'pid' => 'require|integer|addPid|editPid',
|
||||
];
|
||||
|
||||
protected $message = [
|
||||
'id.require' => 'id不能为空',
|
||||
'name.require' => '分类名称不能为空',
|
||||
'name.max' => '分类名称不能超过30个字符',
|
||||
'pid.require' => '请选择上级分类',
|
||||
'pid.integer' => '上级id必须为整型',
|
||||
];
|
||||
|
||||
/**
|
||||
* 添加场景
|
||||
*/
|
||||
public function sceneAdd()
|
||||
{
|
||||
return $this->remove('id', ['require', 'checkCategory'])
|
||||
->remove('pid','editPid');
|
||||
}
|
||||
|
||||
/**
|
||||
* 删除场景
|
||||
*/
|
||||
public function sceneDel()
|
||||
{
|
||||
return $this->only(['id']);
|
||||
}
|
||||
|
||||
/**
|
||||
* 编辑场景
|
||||
*/
|
||||
public function sceneEdit()
|
||||
{
|
||||
return $this->remove('id', 'checkCategory')
|
||||
->remove('pid', 'addPid');
|
||||
}
|
||||
|
||||
/*
|
||||
* 校验分类名称(同一个上级分类下不允许出现相同分类名称)
|
||||
*/
|
||||
protected function checkName($value,$rule,$data){
|
||||
$where[] = ['del','=',0];
|
||||
// 如果有id代表是编辑校验分类名称
|
||||
if(isset($data['id'])){
|
||||
$where[] = ['id','<>',$data['id']];
|
||||
}
|
||||
$where[] = ['name','=',$data['name']];
|
||||
$where[] = ['pid','=',$data['pid']];
|
||||
|
||||
$name = GoodsCategoryModel::where($where)->value('name');
|
||||
if($name){
|
||||
return '分类名称已存在';
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
/*
|
||||
* 添加时,校验上级
|
||||
*/
|
||||
protected function addPid($value, $rule, $data){
|
||||
// 顶级分类直接通过
|
||||
if($value == 0) return true;
|
||||
|
||||
$goods_category = GoodsCategoryModel::where([
|
||||
'id' => $value,
|
||||
'del' => 0
|
||||
])->find();
|
||||
|
||||
if($goods_category) return true;
|
||||
|
||||
return '上级分类不存在,请重新选择';
|
||||
}
|
||||
|
||||
/*
|
||||
* 验证分类
|
||||
*/
|
||||
protected function checkCategory($value, $rule, $data){
|
||||
$children = GoodsCategoryModel::where([
|
||||
'del' => 0,
|
||||
'pid' => $value
|
||||
])->find();
|
||||
if($children) {
|
||||
return '该分类下还有子分类不允许删除';
|
||||
}
|
||||
// 已经有商品绑定了该分类,不能删除
|
||||
$goods = GoodsModel::where([
|
||||
'del' => 0,
|
||||
'third_cate_id' => $value
|
||||
])->find();
|
||||
if($goods) {
|
||||
return '已有商品绑定此分类不允许删除';
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
/*
|
||||
* 编辑时,验证上级分类
|
||||
*/
|
||||
protected function editPid($value, $rule, $data){
|
||||
// 目标上级分类为顶部分类时,直接通过
|
||||
if($value == 0 ) return true;
|
||||
// 当前分类
|
||||
$category = GoodsCategoryModel::where(['id'=>$data['id'],'del'=>0])->find();
|
||||
// 目标上级分类
|
||||
$partner = GoodsCategoryModel::where(['id'=>$value,'del'=>0])->find();
|
||||
// 当前分类下的子分类
|
||||
$level = CategoryLogic::getCategoryLevel($category);
|
||||
|
||||
if($category['id'] == $partner['id']) return '上级分类不能是自己';
|
||||
// 限制分类不超过3级
|
||||
if($level == 3 && $partner) return '该分类下有完整的子分类,不可修改上级分类';
|
||||
if($partner['level'] == 2 && $level != 1) return '该分类下有子分类,请先调整该分类下的子分类';
|
||||
if($partner['level'] == 3) return '父级分类不能是第三级';
|
||||
|
||||
return true;
|
||||
}
|
||||
}
|
||||
50
app/admin/validate/goods/ColumnValidate.php
Normal file
50
app/admin/validate/goods/ColumnValidate.php
Normal file
@ -0,0 +1,50 @@
|
||||
<?php
|
||||
// +----------------------------------------------------------------------
|
||||
// | likeshop开源商城系统
|
||||
// +----------------------------------------------------------------------
|
||||
// | 欢迎阅读学习系统程序代码,建议反馈是我们前进的动力
|
||||
// | gitee下载:https://gitee.com/likeshop_gitee
|
||||
// | github下载:https://github.com/likeshop-github
|
||||
// | 访问官网:https://www.likeshop.cn
|
||||
// | 访问社区:https://home.likeshop.cn
|
||||
// | 访问手册:http://doc.likeshop.cn
|
||||
// | 微信公众号:likeshop技术社区
|
||||
// | likeshop系列产品在gitee、github等公开渠道开源版本可免费商用,未经许可不能去除前后端官方版权标识
|
||||
// | likeshop系列产品收费版本务必购买商业授权,购买去版权授权后,方可去除前后端官方版权标识
|
||||
// | 禁止对系统程序代码以任何目的,任何形式的再发布
|
||||
// | likeshop团队版权所有并拥有最终解释权
|
||||
// +----------------------------------------------------------------------
|
||||
// | author: likeshop.cn.team
|
||||
// +----------------------------------------------------------------------
|
||||
|
||||
namespace app\admin\validate\goods;
|
||||
|
||||
|
||||
use app\common\basics\Validate;
|
||||
|
||||
|
||||
/**
|
||||
* 商品栏目
|
||||
* Class GoodsColumnValidate
|
||||
* @package app\admin\validate
|
||||
*/
|
||||
class ColumnValidate extends Validate
|
||||
{
|
||||
|
||||
protected $rule = [
|
||||
'id' => 'require',
|
||||
'name' => 'require|unique:goodsColumn,name&del',
|
||||
];
|
||||
|
||||
protected $message = [
|
||||
'id.require' => '参数缺失',
|
||||
'name.require' => '参数缺失',
|
||||
'name.unique' => '该名称已被使用',
|
||||
];
|
||||
|
||||
protected $scene = [
|
||||
'add' => ['name'],
|
||||
'edit' => ['name'],
|
||||
'del' => ['id'],
|
||||
];
|
||||
}
|
||||
45
app/admin/validate/goods/GoodsValidate.php
Normal file
45
app/admin/validate/goods/GoodsValidate.php
Normal file
@ -0,0 +1,45 @@
|
||||
<?php
|
||||
namespace app\admin\validate\goods;
|
||||
|
||||
use think\Validate;
|
||||
|
||||
class GoodsValidate extends Validate
|
||||
{
|
||||
protected $rule = [
|
||||
'goods_id' => 'require|integer',
|
||||
'reason' => 'require|length:1,200',
|
||||
'sales_virtual' => 'integer|egt:0',
|
||||
'clicks_virtual' => 'integer|egt:0',
|
||||
'sort_weight' => 'integer|egt:0',
|
||||
'audit_status' => 'require|integer|in:1,2',
|
||||
'audit_remark' => 'require|length:1,200',
|
||||
'ids' => 'require',
|
||||
];
|
||||
|
||||
protected $message= [
|
||||
'goods_id.require' => '商品id不能为空',
|
||||
'goods_id.integer' => '商品id须为整型',
|
||||
'reason.require' => '违规原因不能为空',
|
||||
'reason.length' => '违规原因不能超过200个字符',
|
||||
'sales_virtual.integer' => '虚拟销量须为整型',
|
||||
'sales_virtual.egt' => '虚拟销量须大于或等于0',
|
||||
'clicks_virtual.integer' => '虚拟浏览量须为整型',
|
||||
'clicks_virtual.egt' => '虚拟浏览量须大于或等于0',
|
||||
'sort_weight.integer' => '排序权重须为整型',
|
||||
'sort_weight.egt' => '排序权重须大于或等于0',
|
||||
'audit_status.require' => '审核状态不能为空',
|
||||
'audit_status.integer' => '审核状态须为整型',
|
||||
'audit_status.in' => '审核状态错误',
|
||||
'audit_remark.require' => '审核说明不能为空',
|
||||
'audit_remark.length' => '审核说明长度不能超过200个字符',
|
||||
'ids.require' => '参数缺失',
|
||||
];
|
||||
|
||||
protected $scene = [
|
||||
're_audit' => ['goods_id', 'reason'],
|
||||
'set_info' => ['goods_id', 'sales_virtual', 'clicks_virtual','sort_weight'],
|
||||
'audit' => ['goods_id', 'audit_status', 'audit_remark'],
|
||||
'moreLower' => ['ids', 'reason'],
|
||||
'moreAudit' => ['ids', 'audit_remark']
|
||||
];
|
||||
}
|
||||
65
app/admin/validate/goods/UnitValidate.php
Normal file
65
app/admin/validate/goods/UnitValidate.php
Normal file
@ -0,0 +1,65 @@
|
||||
<?php
|
||||
// +----------------------------------------------------------------------
|
||||
// | likeshop开源商城系统
|
||||
// +----------------------------------------------------------------------
|
||||
// | 欢迎阅读学习系统程序代码,建议反馈是我们前进的动力
|
||||
// | gitee下载:https://gitee.com/likeshop_gitee
|
||||
// | github下载:https://github.com/likeshop-github
|
||||
// | 访问官网:https://www.likeshop.cn
|
||||
// | 访问社区:https://home.likeshop.cn
|
||||
// | 访问手册:http://doc.likeshop.cn
|
||||
// | 微信公众号:likeshop技术社区
|
||||
// | likeshop系列产品在gitee、github等公开渠道开源版本可免费商用,未经许可不能去除前后端官方版权标识
|
||||
// | likeshop系列产品收费版本务必购买商业授权,购买去版权授权后,方可去除前后端官方版权标识
|
||||
// | 禁止对系统程序代码以任何目的,任何形式的再发布
|
||||
// | likeshop团队版权所有并拥有最终解释权
|
||||
// +----------------------------------------------------------------------
|
||||
// | author: likeshop.cn.team
|
||||
// +----------------------------------------------------------------------
|
||||
|
||||
namespace app\admin\validate\goods;
|
||||
|
||||
|
||||
use app\common\basics\Validate;
|
||||
use app\common\model\goods\Goods;
|
||||
|
||||
/**
|
||||
* 商品单位验证
|
||||
* Class GoodsUnitValidate
|
||||
* @package app\admin\validate
|
||||
*/
|
||||
class UnitValidate extends Validate
|
||||
{
|
||||
|
||||
protected $rule = [
|
||||
'id' => 'require',
|
||||
'name' => 'require|unique:goodsUnit,name&del'
|
||||
];
|
||||
|
||||
protected $message = [
|
||||
'id.require' => '参数缺失',
|
||||
'name.unique' => '该名称已被使用',
|
||||
];
|
||||
|
||||
|
||||
protected $scene = [
|
||||
'add' => ['name'],
|
||||
'edit' => ['id','name'],
|
||||
];
|
||||
|
||||
public function sceneDel()
|
||||
{
|
||||
return $this->only(['id'])
|
||||
->append('id','CheckUnit');
|
||||
}
|
||||
|
||||
protected function CheckUnit($value, $rule, $data)
|
||||
{
|
||||
$check = Goods::where('unit_id', $value)->find();
|
||||
if ($check) {
|
||||
return '当前商品单位已使用,无法删除';
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user