其余文件
This commit is contained in:
103
app/shop/validate/goods/GoodsCategoryValidate.php
Normal file
103
app/shop/validate/goods/GoodsCategoryValidate.php
Normal file
@ -0,0 +1,103 @@
|
||||
<?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\shop\validate\goods;
|
||||
|
||||
use think\Validate;
|
||||
use app\common\model\shop\ShopGoodsCategory as ShopGoodsCategoryModel;
|
||||
use app\common\model\goods\Goods as GoodsModel;
|
||||
|
||||
class GoodsCategoryValidate extends Validate
|
||||
{
|
||||
protected $rule = [
|
||||
'id' => 'require|checkCategory',
|
||||
'name' => 'require|max: 30|checkName',
|
||||
'sort' => 'integer|egt:0',
|
||||
];
|
||||
|
||||
protected $message = [
|
||||
'id.require' => 'id不能为空',
|
||||
'name.require' => '分类名称不能为空',
|
||||
'name.max' => '分类名称不能超过30个字符',
|
||||
'pid.require' => '请选择上级分类',
|
||||
'pid.integer' => '上级id必须为整型',
|
||||
'sort.integer' => '排序值须为整数',
|
||||
'sort.egt' => '排序值须大于或等于0',
|
||||
];
|
||||
|
||||
/**
|
||||
* 添加场景
|
||||
*/
|
||||
public function sceneAdd()
|
||||
{
|
||||
return $this->remove('id', ['require', 'checkCategory']);
|
||||
}
|
||||
|
||||
/**
|
||||
* 删除场景
|
||||
*/
|
||||
public function sceneDel()
|
||||
{
|
||||
return $this->only(['id']);
|
||||
}
|
||||
|
||||
/**
|
||||
* 编辑场景
|
||||
*/
|
||||
public function sceneEdit()
|
||||
{
|
||||
return $this->remove('id', 'checkCategory');
|
||||
}
|
||||
|
||||
/*
|
||||
* 校验分类名称
|
||||
*/
|
||||
protected function checkName($value,$rule,$data){
|
||||
$where[] = ['del','=',0];
|
||||
$where[] = ['shop_id', '=', $data['shop_id']];
|
||||
// 如果有id代表是编辑校验分类名称
|
||||
if(isset($data['id'])){
|
||||
$where[] = ['id','<>',$data['id']];
|
||||
}
|
||||
$where[] = ['name','=',$data['name']];
|
||||
|
||||
$name = ShopGoodsCategoryModel::where($where)->value('name');
|
||||
if($name){
|
||||
return '分类名称已存在';
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
/*
|
||||
* 验证分类
|
||||
*/
|
||||
protected function checkCategory($value, $rule, $data){
|
||||
// 已经有商品绑定了该分类,不能删除
|
||||
$goods = GoodsModel::where([
|
||||
'del' => 0,
|
||||
'shop_cate_id' => $value
|
||||
])->find();
|
||||
if($goods) {
|
||||
return '已有商品绑定此分类不允许删除';
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
}
|
||||
58
app/shop/validate/goods/GoodsMoreSpec.php
Normal file
58
app/shop/validate/goods/GoodsMoreSpec.php
Normal file
@ -0,0 +1,58 @@
|
||||
<?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\shop\validate\goods;
|
||||
|
||||
use app\common\basics\Validate;
|
||||
|
||||
class GoodsMoreSpec extends Validate
|
||||
{
|
||||
protected $rule = [
|
||||
'spec_name' => 'require|array|specNameRepetition',
|
||||
'spec_values' => 'require|array|specValueRepetition',
|
||||
];
|
||||
|
||||
protected $message = [];
|
||||
|
||||
/**
|
||||
* 检测规格名称是否重复
|
||||
* @param $value
|
||||
* @param $rule
|
||||
* @param $data
|
||||
* @return bool|string
|
||||
*/
|
||||
public function specNameRepetition($value, $rule, $data)
|
||||
{
|
||||
if (count($value) != count(array_unique($value))) {
|
||||
return '规格名称重复';
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
public function specValueRepetition($value, $rule, $data)
|
||||
{
|
||||
foreach ($value as $k => $v) {
|
||||
$row = explode(',', $v);
|
||||
if (count($row) != count(array_unique($row))) {
|
||||
return '同一规格项的规格值不能重复';
|
||||
}
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
}
|
||||
85
app/shop/validate/goods/GoodsMoreSpecLists.php
Normal file
85
app/shop/validate/goods/GoodsMoreSpecLists.php
Normal file
@ -0,0 +1,85 @@
|
||||
<?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\shop\validate\goods;
|
||||
|
||||
use app\common\basics\Validate;
|
||||
use app\common\enum\FreightEnum;
|
||||
use app\common\model\Freight;
|
||||
|
||||
|
||||
class GoodsMoreSpecLists extends Validate
|
||||
{
|
||||
protected $rule = [
|
||||
'market_price' => [ ],
|
||||
'price' => 'require|egt:0.01|checkExpress',
|
||||
'chengben_price' => [],
|
||||
'stock' => 'require|integer|egt:0',
|
||||
'weight' => [],
|
||||
'volume' => [],
|
||||
];
|
||||
|
||||
protected $message = [
|
||||
'market_price.require' => '请输入市场价',
|
||||
'market_price.egt' => '市场价必须大于或等于0.01',
|
||||
'price.require' => '请输入价格',
|
||||
'price.egt' => '价格必须大于或等于0.01',
|
||||
'chengben_price.require' => '请输入成本价',
|
||||
'chengben_price.egt' => '成本价必须大于或等于0.01',
|
||||
'stock.require' => '请输入库存',
|
||||
'stock.integer' => '库存必须为整数',
|
||||
'stock.egt' => '库存必须大于或等于0',
|
||||
'weight.require' => '请输入重量',
|
||||
'weight.egt' => '重量必须大于或等于0',
|
||||
'volume.require' => '请输入体积',
|
||||
'volume.egt' => '体积必须大于或等于0',
|
||||
];
|
||||
|
||||
function checkExpress($value, $rule, $data)
|
||||
{
|
||||
$express_type = input('express_type');
|
||||
|
||||
// 运费模版
|
||||
if ($express_type != 3) {
|
||||
return true;
|
||||
}
|
||||
|
||||
$freight = Freight::where('id', input('express_template_id/d'))->findOrEmpty();
|
||||
|
||||
if (empty($freight['id'])) {
|
||||
return '运费模板不存在';
|
||||
}
|
||||
|
||||
switch ($freight['charge_way']) {
|
||||
case FreightEnum::CHARGE_WAY_WEIGHT:
|
||||
if (empty($data['weight']) || $data['weight'] <= 0) {
|
||||
return '当前运费模板是按重量计算运费,规格:' . $data['spec_value_str'] .' 的重量必须大于0';
|
||||
}
|
||||
break;
|
||||
case FreightEnum::CHARGE_WAY_VOLUME:
|
||||
if (empty($data['volume']) || $data['volume'] <= 0) {
|
||||
return '当前运费模板是按体积计算运费,规格:' . $data['spec_value_str'] .' 的体积必须大于0';
|
||||
}
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
}
|
||||
92
app/shop/validate/goods/GoodsOneSpec.php
Normal file
92
app/shop/validate/goods/GoodsOneSpec.php
Normal file
@ -0,0 +1,92 @@
|
||||
<?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\shop\validate\goods;
|
||||
|
||||
use app\common\basics\Validate;
|
||||
use app\common\enum\FreightEnum;
|
||||
use app\common\model\Freight;
|
||||
|
||||
/**
|
||||
* 单个规格验证
|
||||
* Class GoodsOneSpec
|
||||
* @package app\shop\validate\goods
|
||||
*/
|
||||
class GoodsOneSpec extends Validate
|
||||
{
|
||||
protected $rule = [
|
||||
'one_market_price' => [],
|
||||
'one_price' => 'require|egt:0.01|checkExpress',
|
||||
'one_stock' => 'require|integer|egt:0',
|
||||
'one_weight' => [],
|
||||
'one_volume' => [],
|
||||
'one_chengben_price' => [],
|
||||
];
|
||||
|
||||
protected $message = [
|
||||
'one_market_price.require' => '请输入价格',
|
||||
'one_market_price.egt' => '价格必须大于或等于0.01',
|
||||
'one_price.require' => '请输入价格',
|
||||
'one_price.egt' => '价格必须大于或等于0.01',
|
||||
'one_chengben_price.require'=> '请输入成本价',
|
||||
'one_chengben_price.egt' => '成本价必须大于或等于0.01',
|
||||
'one_stock.require' => '请输入库存',
|
||||
'one_stock.integer' => '库存必须为整型',
|
||||
'one_stock.egt' => '库存必须大于或等于0',
|
||||
'one_weight.require' => '请输入重量',
|
||||
'one_weight.egt' => '重量必须为大于或等于0',
|
||||
'one_volume.require' => '请输入体积',
|
||||
'one_volume.egt' => '体积必须为大于或等于0',
|
||||
];
|
||||
|
||||
|
||||
|
||||
function checkExpress($value, $rule, $data)
|
||||
{
|
||||
$express_type = input('express_type');
|
||||
|
||||
// 运费模版
|
||||
if ($express_type != 3) {
|
||||
return true;
|
||||
}
|
||||
|
||||
$freight = Freight::where('id', input('express_template_id/d'))->findOrEmpty();
|
||||
|
||||
if (empty($freight['id'])) {
|
||||
return '运费模板不存在';
|
||||
}
|
||||
|
||||
switch ($freight['charge_way']) {
|
||||
case FreightEnum::CHARGE_WAY_WEIGHT:
|
||||
if (empty($data['one_weight']) || $data['one_weight'] <= 0) {
|
||||
return '当前运费模板是按重量计算运费,请输入重量';
|
||||
}
|
||||
break;
|
||||
case FreightEnum::CHARGE_WAY_VOLUME:
|
||||
if (empty($data['one_volume']) || $data['one_volume'] <= 0) {
|
||||
return '当前运费模板是按体积计算运费,请输入体积';
|
||||
}
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
}
|
||||
101
app/shop/validate/goods/GoodsStatusValidate.php
Normal file
101
app/shop/validate/goods/GoodsStatusValidate.php
Normal file
@ -0,0 +1,101 @@
|
||||
<?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\shop\validate\goods;
|
||||
|
||||
use app\common\basics\Validate;
|
||||
use app\common\model\bargain\Bargain;
|
||||
use app\common\model\goods\Goods;
|
||||
use app\common\model\seckill\SeckillGoods;
|
||||
use app\common\model\team\TeamActivity;
|
||||
|
||||
|
||||
/**
|
||||
* 商品状态验证
|
||||
* Class GoodsStatusValidate
|
||||
* @package app\shop\validate\goods
|
||||
*/
|
||||
class GoodsStatusValidate extends Validate
|
||||
{
|
||||
protected $rule = [
|
||||
'ids' => 'require|checkIds',
|
||||
'status' => 'require|in:0,1',
|
||||
];
|
||||
|
||||
protected $message = [
|
||||
'ids.require' => '请选择商品',
|
||||
'status.require' => '参数缺失',
|
||||
'status.in' => '状态错误',
|
||||
];
|
||||
|
||||
|
||||
//活动商品不可编辑
|
||||
protected function checkIds($value, $rule, $data)
|
||||
{
|
||||
if (!is_array($value)) {
|
||||
return '参数错误';
|
||||
}
|
||||
|
||||
foreach ($value as $item) {
|
||||
$result = $this->checkGoods($item, $data['shop_id']);
|
||||
if (true !== $result) {
|
||||
return $result;
|
||||
}
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
// 验证商品
|
||||
protected function checkGoods($goods_id, $shop_id)
|
||||
{
|
||||
$goods = Goods::where(['del' => 0, 'id' => $goods_id, 'shop_id' => $shop_id])->findOrEmpty();
|
||||
if ($goods->isEmpty()) {
|
||||
return '包含不存在商品';
|
||||
}
|
||||
|
||||
$condition = [
|
||||
'del' => 0,
|
||||
'goods_id' => $goods_id,
|
||||
'shop_id' => $shop_id
|
||||
];
|
||||
|
||||
// 砍价
|
||||
$bargain = Bargain::where($condition)->findOrEmpty();
|
||||
if (!$bargain->isEmpty()) {
|
||||
return '所选商品中包含砍价活动商品, 无法修改';
|
||||
}
|
||||
|
||||
// 秒杀
|
||||
$seckillGoods = SeckillGoods::where($condition)->findOrEmpty();
|
||||
if (!$seckillGoods->isEmpty()) {
|
||||
return '所选商品中包含秒杀活动商品, 无法修改';
|
||||
}
|
||||
|
||||
// 拼团
|
||||
$teamGoods = TeamActivity::where($condition)->findOrEmpty();
|
||||
if (!$teamGoods->isEmpty()) {
|
||||
return '所选商品中包含拼团活动商品, 无法修改';
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
222
app/shop/validate/goods/GoodsValidate.php
Normal file
222
app/shop/validate/goods/GoodsValidate.php
Normal file
@ -0,0 +1,222 @@
|
||||
<?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\shop\validate\goods;
|
||||
|
||||
use app\common\basics\Validate;
|
||||
use app\common\enum\GoodsEnum;
|
||||
use app\common\enum\ShopEnum;
|
||||
use app\common\model\goods\GoodsBrand;
|
||||
use app\common\model\goods\GoodsUnit;
|
||||
use app\common\model\goods\Supplier;
|
||||
use app\common\model\goods\Goods;
|
||||
use app\common\model\bargain\Bargain;
|
||||
use app\common\model\seckill\SeckillGoods;
|
||||
use app\common\model\shop\Shop;
|
||||
use app\common\model\team\TeamActivity;
|
||||
use think\Db;
|
||||
|
||||
|
||||
/**
|
||||
* 商品-验证
|
||||
* Class GoodsValidate
|
||||
* @package app\admin\validate
|
||||
*/
|
||||
class GoodsValidate extends Validate
|
||||
{
|
||||
protected $rule = [
|
||||
// 商品类型 0-实物商品 1-虚拟商品
|
||||
'type' => 'require|in:0,1',
|
||||
'goods_id' => 'require|checkActivityGoods',
|
||||
'name' => 'require|min:3|max:64|checkName',
|
||||
'first_cate_id' => 'require',
|
||||
'image' => 'require',
|
||||
'goods_image' => 'require|length:1,10',
|
||||
'spec_type' => 'require',
|
||||
|
||||
// 配送方式 1-快递配送 2-虚拟发货
|
||||
'delivery_type' => 'require|checkDeliveryType',
|
||||
// 买家付款后 1-自动大货 2-手动发货
|
||||
'after_pay' => 'requireIf:type,1',
|
||||
// 发货后 1-自动完成订单 2-需要买家确认收货
|
||||
'after_delivery' => 'requireIf:type,1',
|
||||
'delivery_content' => 'requireIf:type,1',
|
||||
|
||||
// 快递类型 1-包邮;2-统一运费;3-运费模板
|
||||
'express_type' => 'requireIf:type,0',
|
||||
'express_money' => 'requireIf:express_type,2|checkExpressMoney',
|
||||
'express_template_id' => 'requireIf:express_type,3',
|
||||
'status' => 'require',
|
||||
'stock_warn' => 'integer|egt:0',
|
||||
'code' => 'checkCode',
|
||||
'sort' => 'egt:0',
|
||||
];
|
||||
|
||||
protected $message = [
|
||||
'type.require' => '请选择商品类型',
|
||||
'type.in' => '商品类型参数错误',
|
||||
'name.require' => '请输入商品名称',
|
||||
'name.min' => '商品名称长度至少3个字符',
|
||||
'name.max' => '商品名称长度最多64个字符',
|
||||
'name.unique' => '商品名称已存在,请重新输入',
|
||||
'first_cate_id.require' => '至少选择一个分类',
|
||||
'image.require' => '请上传商品主图',
|
||||
'goods_image.require' => '请上传商品轮播图',
|
||||
'goods_image.length' => '商品轮播图最多只能上传10张',
|
||||
'spec_type.require' => '请选择规格类型',
|
||||
|
||||
'delivery_type.require' => '请选择配送方式',
|
||||
'after_pay.requireIf' => '请选择买家付款后发货方式',
|
||||
'after_delivery.requireIf' => '请选择发货后是否自动完成订单',
|
||||
'delivery_content.requireIf' => '请填写发货内容',
|
||||
|
||||
'express_type.require' => '请选择快递运费类型',
|
||||
'express_money.requireIf' => '请输入统一运费',
|
||||
'express_template_id.requireIf' => '请选择快递运费模板',
|
||||
'status.require' => '请选择销售状态',
|
||||
'stock_warn.integer' => '库存预警须为整数',
|
||||
'stock_warn.egt' => '库存预警须大于或等于0',
|
||||
'sort.egt' => '排序值不能小于0',
|
||||
];
|
||||
|
||||
public function sceneAdd()
|
||||
{
|
||||
$this->remove('goods_id', 'require');
|
||||
}
|
||||
|
||||
public function sceneDel()
|
||||
{
|
||||
$this->only(['goods_id']);
|
||||
}
|
||||
|
||||
/**
|
||||
* 校验商品名称
|
||||
*/
|
||||
public function checkName($value, $rule, $data)
|
||||
{
|
||||
$where = [
|
||||
['del', '=', 0],
|
||||
['name', '=', $value],
|
||||
['shop_id', '=', $data['shop_id']]
|
||||
];
|
||||
if($data['goods_id']) { // 编辑
|
||||
$where[] = ['id', '<>', $data['goods_id']];
|
||||
}
|
||||
$goods = Goods::where($where)->findOrEmpty();
|
||||
if(!$goods->isEmpty()) {
|
||||
return '商品名称已存在,请更换其他名称';
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
//活动商品不可编辑
|
||||
public function checkActivityGoods($value, $rule, $data)
|
||||
{
|
||||
$condition = [
|
||||
'goods_id' => $value,
|
||||
'del' => 0,
|
||||
'shop_id' => $data['shop_id']
|
||||
];
|
||||
|
||||
// 砍价
|
||||
$bargain = Bargain::where($condition)->findOrEmpty();
|
||||
if(!$bargain->isEmpty()) {
|
||||
return '商品正在参与砍价活动, 无法修改';
|
||||
}
|
||||
|
||||
// 秒杀
|
||||
$seckillGoods = SeckillGoods::where($condition)->findOrEmpty();
|
||||
if (!$seckillGoods->isEmpty()) {
|
||||
return '商品正在参与秒杀活动, 无法修改';
|
||||
}
|
||||
|
||||
// 拼团
|
||||
$teamGoods = TeamActivity::where($condition)->findOrEmpty();
|
||||
if(!$teamGoods->isEmpty()){
|
||||
return '商品正在参加拼团活动, 无法修改';
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* @notes 校验商品编码唯一性
|
||||
*/
|
||||
public function checkCode($value, $rule, $data)
|
||||
{
|
||||
$where = [
|
||||
['code', '=', $data['code']],
|
||||
['del', '=', 0],
|
||||
];
|
||||
if($data['goods_id']) {
|
||||
$where[] = ['id', '<>', $data['goods_id']];
|
||||
}
|
||||
$goods = Goods::where($where)->select()->toArray();
|
||||
if($goods) {
|
||||
return '商品编码已存在';
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
public function checkExpressMoney($value, $rule, $data)
|
||||
{
|
||||
if ($data['express_type'] == 2 && $value < 0) {
|
||||
return '统一运费不能小于0';
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* @notes 校验配送方式
|
||||
* @param $value
|
||||
* @param $rule
|
||||
* @param $data
|
||||
* @return string|void
|
||||
* @author 段誉
|
||||
* @date 2022/4/7 12:04
|
||||
*/
|
||||
public function checkDeliveryType($value, $rule, $data)
|
||||
{
|
||||
// 虚拟商品
|
||||
if ($data['type'] == GoodsEnum::TYPE_VIRTUAL && !in_array(GoodsEnum::DELIVERY_VIRTUAL, $value)) {
|
||||
return '虚拟商品配送方式需选择虚拟发货';
|
||||
}
|
||||
|
||||
// 实物商品
|
||||
if ($data['type'] == GoodsEnum::TYPE_ACTUAL) {
|
||||
if (!in_array(GoodsEnum::DELIVERY_EXPRESS, $value) && !in_array(GoodsEnum::DELIVERY_SELF, $value)) {
|
||||
return '实物商品配送方式需选择快递发货或线下自提';
|
||||
}
|
||||
|
||||
$shop = Shop::findOrEmpty($data['shop_id']);
|
||||
|
||||
// 选择快递配送 但商家不支持快递配送
|
||||
if (in_array(GoodsEnum::DELIVERY_EXPRESS, $value) && !in_array(ShopEnum::DELIVERY_EXPRESS, $shop['delivery_type'])) {
|
||||
return '请先到商家设置开启快递配送方式';
|
||||
}
|
||||
|
||||
// 选择自提 但商家不支持自提
|
||||
if (in_array(GoodsEnum::DELIVERY_SELF, $value) && !in_array(ShopEnum::DELIVERY_SELF, $shop['delivery_type'])) {
|
||||
return '请先到商家设置开启线下自提方式';
|
||||
}
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
}
|
||||
74
app/shop/validate/goods/SupplierValidate.php
Normal file
74
app/shop/validate/goods/SupplierValidate.php
Normal file
@ -0,0 +1,74 @@
|
||||
<?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\shop\validate\goods;
|
||||
|
||||
|
||||
use app\common\basics\Validate;
|
||||
use app\common\model\goods\Goods;
|
||||
|
||||
|
||||
/**
|
||||
* 供货商
|
||||
* Class SupplierValidate
|
||||
* @package app\admin\validate
|
||||
*/
|
||||
class SupplierValidate extends Validate
|
||||
{
|
||||
|
||||
protected $rule = [
|
||||
'id' => 'require',
|
||||
'name' => 'require|unique:supplier,name&del',
|
||||
'contact' => 'require',
|
||||
'mobile' => 'require|mobile',
|
||||
'address' => 'require',
|
||||
];
|
||||
|
||||
protected $message = [
|
||||
'id.require' => '参数缺失',
|
||||
'name.require' => '参数缺失',
|
||||
'name.unique' => '该名称已被使用',
|
||||
'contact.require' => '请填写联系人',
|
||||
'mobile.require' => '请填写联系电话',
|
||||
'mobile.mobile' => '请填写正确联系电话',
|
||||
'address.require' => '请填写联系地址',
|
||||
];
|
||||
|
||||
protected $scene = [
|
||||
'add' => ['name', 'contact', 'mobile', 'address'],
|
||||
'edit' => ['name', 'contact', 'mobile', 'address'],
|
||||
];
|
||||
|
||||
public function sceneDel()
|
||||
{
|
||||
return $this->only(['id'])
|
||||
->append('id','checkDel');
|
||||
}
|
||||
|
||||
|
||||
protected function checkDel($value,$rule,$data)
|
||||
{
|
||||
$check = Goods::where('supplier_id', $value)->find();
|
||||
if ($check) {
|
||||
return '供货商已经关联商品,无法删除';
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user