glhcp/server/app/shop/validate/goods/GoodsStatusValidate.php

101 lines
3.2 KiB
PHP
Raw Normal View History

2023-08-10 06:59:52 +00:00
<?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;
}
}