其余文件

This commit is contained in:
2026-04-14 17:46:22 +08:00
parent 294b68fe37
commit 3691f4db22
1343 changed files with 189847 additions and 0 deletions

View File

@ -0,0 +1,67 @@
<?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;
use app\common\basics\Validate;
use app\common\model\shop\ShopAdmin;
/**
* 管理员密码
* Class AdminPasswordValidate
* @package app\admin\validate
*/
class AdminPasswordValidate extends Validate
{
protected $rule = [
'old_password' => 'require|verify',
'password' => 'require|length:6,16',
're_password' => 'confirm:password',
];
protected $message = [
'old_password.require' => '当前密码不能为空',
'old_password.verify' => '当前密码输入不正确',
'password.require' => '新密码不能为空',
'password.length' => '密码长度必须为6到16位之间',
're_password.confirm' => '两次密码输入不一致',
];
/**
* 密码验证
* @param $old_password
* @param $other
* @param $data
* @return bool
* @throws \think\db\exception\DataNotFoundException
* @throws \think\db\exception\ModelNotFoundException
* @throws \think\exception\DbException
*/
protected function verify($old_password, $other, $data)
{
$admin = ShopAdmin::find($data['admin_id']);
$password = generatePassword($old_password, $admin['salt']);
if ($password != $admin['password']) {
return false;
}
return true;
}
}

View File

@ -0,0 +1,96 @@
<?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;
use app\common\basics\Validate;
/**
* 管理员验证
* Class AdminValidate
* @package app\admin\validate
*/
class AdminValidate extends Validate
{
protected $rule = [
'account' => 'require|unique:shop_admin|length:1,32',
'password' => 'require|length:6,32|confirm:re_password|edit',
're_password' => 'confirm:password',
'name' => 'require|length:1,16',
'role_id' => 'require',
];
protected $message = [
'account.require' => '账号不能为空',
'account.unique' => '账号名已存在,请使用其他账号名',
'account.length' => '账号名的长度为1到32位之间',
'password.require' => '密码不能为空',
'password.length' => '密码长度必须为6到16位之间',
'password.confirm' => '两次密码输入不一致',
're_password.confirm' => '两次密码输入不一致',
'name.require' => '名称不能为空',
'name.length' => '账号名的长度为1到32位之间',
'role_id.require' => '请选择角色',
];
/**
* Notes: 场景 - 添加
* @author 段誉(2021/4/10 16:07)
*/
public function sceneAdd()
{
$this->remove('password',['edit']);
}
/**
* Notes: 场景 - 编辑
* @author 段誉(2021/4/10 16:07)
*/
public function sceneEdit()
{
$this->remove('password', ['require', 'password']);
}
/**
* Notes: 编辑的时候自定义验证方法
* @param $password
* @param $other
* @param $data
* @author 段誉(2021/4/10 16:06)
* @return bool|mixed
*/
protected function edit($password, $other, $data)
{
//不填写验证
if (empty($password) && empty($data['re_password'])) {
return true;
}
//填写的时候验证
$password_length = strlen($password);
if ($password_length < 6 || $password_length > 16) {
return $this->message['password.length'];
}
return true;
}
}

View File

@ -0,0 +1,29 @@
<?php
namespace app\shop\validate;
use app\common\basics\Validate;
class AlipayValidate extends Validate
{
protected $rule = [
'id' => 'require|number',
'account' => 'require',
'username' => 'require',
];
protected $message = [
'id.require' => '缺少ID字段',
'id.number' => 'ID必须为数字',
'account.require' => '请填写支付宝账号',
'username.require' => '请填写支付宝姓名',
];
protected $scene = [
'id' => [ 'id' ],
'add' => [ 'account', 'username' ],
'edit' => [ 'id', 'account', 'username' ],
];
}

View File

@ -0,0 +1,33 @@
<?php
namespace app\shop\validate;
use app\common\basics\Validate;
class BankValidate extends Validate
{
protected $rule = [
'id' => 'require|number',
'name' => 'require',
'branch' => 'require',
'nickname' => 'require',
'account' => 'require',
];
protected $message = [
'id.require' => '缺少ID字段',
'id.number' => 'ID必须为数字',
'name.require' => '请填写提现银行',
'branch.require' => '请填写银行支行',
'nickname.require' => '请填写开户名称',
'account.require' => '请填写银行账号',
];
protected $scene = [
'id' => ['id'],
'add' => ['name', 'branch', 'nickname', 'account'],
'edit' => ['id', 'name', 'branch', 'nickname', 'account']
];
}

View File

@ -0,0 +1,112 @@
<?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;
use app\api\controller\Bargain;
use app\common\basics\Validate;
use app\common\model\bargain\Bargain as BargainModel;
use app\common\model\goods\GoodsItem;
/**
* 砍价活动 数据校验
* Class BargainValidate
* @Author 张无忌
* @package app\admin\validate
*/
class BargainValidate extends Validate
{
protected $rule = [
'id' => 'require|checkStatus',
'goods_id' => 'require|number',
'time_limit' => 'require',
'activity_start_time' => 'require',
'activity_end_time' => 'require|endTime',
'payment_where' => 'require|in:1,2',
'knife_type' => 'require|in:1,2',
'status' => 'require|in:0,1',
'floor_price' => 'require|checkFloorPrice'
];
protected $message = [
'id' => 'ID不可为空',
'id.number' => 'ID必须为数字',
'goods_id.require' => '未选择砍价商品',
'goods_id.number' => '选择砍价商品异常',
'time_limit.require' => '请填写砍价活动有效期',
'time_limit.number' => '砍价活动有效期必须为数字',
'activity_start_time.require' => '请选择活动开始时间',
'activity_end_time.require' => '请选择活动结束时间',
'payment_where.require' => '请选择购买方式',
'payment_where.number' => '选择的购买方式异常',
'knife_type.require' => '请选择砍价金额方式',
'knife_type.number' => '选择的砍价方式异常',
'status.require' => '请选择砍价活动状态',
'status.in' => '砍价状态选择异常',
];
protected $scene = [
'add' => ['goods_id', 'time_limit', 'activity_start_time', 'activity_end_time', 'payment_where', 'knife_type', 'status', 'floor_price'],
'edit' => ['id', 'goods_id', 'time_limit', 'activity_start_time', 'activity_end_time', 'payment_where', 'knife_type', 'status', 'floor_price'],
];
public function checkFloorPrice($value, $rule, $data)
{
foreach ($value as $item) {
foreach ($item as $item_id => $floor_price) {
$goods_price = GoodsItem::where(['id' => $item_id])->value('price');
if($floor_price >= $goods_price){
return '活动底价必须低于商品价格';
}else{
return true;
}
}
}
}
/***
* 验证审核状态,如果是审核通过时进行编辑无需再次审核,如果是审核拒绝时编辑需要再次审核。
* @param $value
* @param $rule
* @param $data
*/
public function checkStatus($value, $rule, $data)
{
$bargain = BargainModel::where('id', $value)->find();
if ($bargain['status'] == 1) {
return '该活动正在进行中,无法编辑!';
} else {
return true;
}
}
public function endTime($value, $rule, $data)
{
if (strtotime($value) <= time()) {
return '结束时间不能少于当前时间';
}
if (strtotime($value) <= strtotime($data['activity_start_time'])) {
return '结束时间不能少于或等于开始时间';
}
return true;
}
}

View File

@ -0,0 +1,110 @@
<?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;
use app\common\basics\Validate;
use app\common\model\shop\ShopAdmin;
use think\facade\Cache;
/**
* 登录数据验证
* Class LoginValidate
* @package app\shop\validate
*/
class LoginValidate extends Validate
{
protected $rule = [
'account' => 'require',
'password' => 'require|password',
];
protected $message = [
'account.require' => '请填写登录账号',
'password.require' => '请填写登录密码',
'password.password' => '账号密码错误',
];
/**
* 账号密码验证码
* @param $password
* @param $other
* @param $data
* @return bool
* @throws \think\db\exception\DataNotFoundException
* @throws \think\db\exception\ModelNotFoundException
* @throws \think\exception\DbException
*/
protected function password($password, $other, $data)
{
if ($this->safe() === false) {
$this->message['password.password'] .= ':多次输入错误';
return false;
}
$adminModel = new ShopAdmin();
$admin_info = $adminModel->alias('a')
->field('a.*')
->join('shop s', 's.id = a.shop_id')
->where(['a.account' => $data['account'], 'a.del' => 0])
->find();
if (empty($admin_info)) {
$this->safe(true);
return '账号不存在';
}
if ($admin_info['disable']) {
return '账号被禁用';
}
$password = generatePassword($password, $admin_info['salt']);
if ($password != $admin_info['password']) {
$this->safe(true);
return false;
}
return true;
}
/**
* 连续30分钟内15次输错密码无法登录
* @param bool $add
* @return bool
*/
protected function safe($add = false)
{
$cache_name = 'shop_admin_login_error_count' . request()->ip();
if ($add) {
$admin_login_error_count = Cache::get($cache_name);
$admin_login_error_count++;
Cache::tag('shop_admin_login_error_count')->set($cache_name, $admin_login_error_count, 1800);
}
$count = Cache::get($cache_name);
if (!empty($count) && $count >= 15) {
return false;
}
return true;
}
}

View File

@ -0,0 +1,76 @@
<?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;
use app\common\basics\Validate;
use app\common\model\shop\ShopAdmin;
class RoleValidate extends Validate
{
protected $rule = [
'id' => 'adminExistRole',
'name' => 'require',
'auth_ids' => 'array'
];
protected $message = [
'name.require' => '角色名不能为空',
'auth_ids.auth' => '权限错误',
'id.adminExistRole' => '管理员列表存在该角色,无法删除',
];
protected function sceneAdd()
{
$this->remove('id', ['adminExistRole']);
}
protected function sceneEdit()
{
$this->remove('id', ['adminExistRole']);
}
public function sceneDel()
{
$this->remove('name', ['require'])
->remove('auth_ids', ['auth']);
}
/**
* 判断管理列表是否存在该角色
* @param $id
* @return bool
* @throws \think\db\exception\DataNotFoundException
* @throws \think\db\exception\ModelNotFoundException
* @throws \think\exception\DbException
*/
protected function adminExistRole($value, $rule, $data=[])
{
$result = ShopAdmin::where(['role_id' => $value, 'del' => 0])->find();
if ($result) {
return false;
}
return true;
}
}

View File

@ -0,0 +1,161 @@
<?php
namespace app\shop\validate;
use app\common\model\bargain\Bargain;
use app\common\model\team\TeamActivity;
use think\Validate;
use app\common\model\seckill\SeckillTime;
use app\common\model\seckill\SeckillGoods;
use app\common\model\goods\Goods;
use app\common\model\goods\GoodsItem;
class SeckillGoodsValidate extends Validate
{
protected $rule = [
'start_end' => 'require',
'seckill_id' => 'require|checkSeckill',
'item' => 'require|checkActivity'
];
protected $message = [
'start_end.require' => '请选择日期',
'seckill_id.require' => '请选择秒杀时段',
'item.require' => '请选择秒杀商品',
];
public function checkSeckill($value,$rule,$data){
$seckill = SeckillTime::where(['del'=>0,'id'=>$value])->findOrEmpty();
if($seckill->isEmpty()){
return '秒杀时间段已被调整,请重新选择时间段';
}
return true;
}
public function sceneAdd(){
$this->append('item','checkAddGoods');
}
public function sceneEdit(){
$this->append('item','checkEditGoods');
}
public function checkAddGoods($value,$rule,$data){
$goods_ids = array_unique(array_column($value,'goods_id'));
$goods = Goods::where(['del'=>0, 'shop_id'=>$data['shop_id']])->column('id');
$goods_item = GoodsItem::where(['goods_id'=>$goods_ids])->column('price,spec_value_str','id');
$seckill_goods = SeckillGoods::where(['seckill_id'=>$data['seckill_id'],'del'=>0])->column('item_id');
// 参与时期
$start_end_arr = explode('~', $data['start_end']);
$start_date = strtotime(trim($start_end_arr[0]));
$end_date = strtotime(trim($start_end_arr[1]));
// 同一日期同一时间段内不允许重复添加活动商品
foreach($value as $item) {
if(!in_array($item['goods_id'],$goods)){
return '商品ID:'.$item['goods_id'].'已下架';
}
$goods_price = $goods_item[$item['item_id']]['price'] ?? 0;
//验证商品价格
if($item['price'] > $goods_price){
return '商品规格:'.$goods_item[$item['item_id']]['spec_value_str'] .'的秒杀价格高于原价';
}
// 获取当前商品参与过哪些日期及哪些时段的秒杀
$joinDateTime = SeckillGoods::where(['del'=>0, 'goods_id'=>$item['goods_id']])
->field('seckill_id,goods_id,start_date,end_date')
->group('seckill_id,goods_id,start_date,end_date')
->select()
->toArray();
foreach($joinDateTime as $subItem) {
if($data['seckill_id'] == $subItem['seckill_id'] && $start_date < strtotime($subItem['start_date']) && $end_date < strtotime($subItem['start_date'])) {
// 时间段相同,新增日期不在已存在的日期范围,允许添加
continue;
}else if($data['seckill_id'] == $subItem['seckill_id'] && $start_date > strtotime($subItem['end_date']) && $end_date > strtotime($subItem['end_date'])) {
// 时间段相同,新增日期不在已存在的日期范围,允许添加
continue;
}else if($data['seckill_id'] != $subItem['seckill_id']) {
// 时间段不同,允许新增
continue;
}else{
return '商品已在活动中,请勿重新添加';
}
}
}
return true;
}
public function checkEditGoods($value,$rule,$data){
$goods_ids = array_unique(array_column($value,'goods_id'));
$seckill_ids = array_column($value,'id');
$seckill_goods = SeckillGoods::where(['goods_id'=>$goods_ids,'seckill_id'=>$data['seckill_id']])
->where('id','not in',$seckill_ids)
->find();
$goods = Goods::where(['del'=>0])->column('id');
$goods_item = GoodsItem::where(['goods_id'=>$goods_ids])->column('price,spec_value_str','id');
// 参与时期
$start_end_arr = explode('~', $data['start_end']);
$start_date = strtotime(trim($start_end_arr[0]));
$end_date = strtotime(trim($start_end_arr[1]));
// 同一日期同一时间段内不允许重复添加活动商品
foreach ($value as $item){
if(!in_array($item['goods_id'],$goods)){
return '商品ID:'.$item['goods_id'].'已下架';
}
$goods_price = $goods_item[$item['item_id']]['price'] ?? 0;
//验证商品价格
if($item['price'] > $goods_price){
return '商品规格:'.$goods_item[$item['item_id']]['spec_value_str'] .'的秒杀价格高于原价';
}
// 获取当前商品参与过哪些日期及哪些时段的秒杀
$joinDateTime = SeckillGoods::where([
['del', '=', 0],
['goods_id', '=', $item['goods_id']],
['id', 'not in', $seckill_ids]
])
->field('seckill_id,goods_id,start_date,end_date')
->group('seckill_id,goods_id,start_date,end_date')
->select()
->toArray();
foreach($joinDateTime as $subItem) {
if($data['seckill_id'] == $subItem['seckill_id'] && $start_date < strtotime($subItem['start_date']) && $end_date < strtotime($subItem['start_date'])) {
// 时间段相同,新增日期不在已存在的日期范围,允许添加
continue;
}else if($data['seckill_id'] == $subItem['seckill_id'] && $start_date > strtotime($subItem['end_date']) && $end_date > strtotime($subItem['end_date'])) {
// 时间段相同,新增日期不在已存在的日期范围,允许添加
continue;
}else if($data['seckill_id'] != $subItem['seckill_id']) {
// 时间段不同,允许新增
continue;
}else{
return '商品已在活动中,请勿重新添加';
}
}
}
return true;
}
public function checkActivity($item, $rule, $data)
{
foreach($item as $v) {
$team = TeamActivity::where(['del' => 0, 'goods_id' => $v['goods_id']])->select()->toArray();
if($team) {
return '商品正在参加拼团活动,不能再参与限时秒杀!';
}
$bargain = Bargain::where(['del' => 0, 'goods_id' => $v['goods_id']])->select()->toArray();
if($bargain) {
return '商品正在参加砍价活动,不能再参与限时秒杀!';
}
}
return true;
}
}

View File

@ -0,0 +1,34 @@
<?php
namespace app\shop\validate;
use app\common\basics\Validate;
class TeamValidate extends Validate
{
protected $rule = [
'id' => 'require',
'goods_id' => 'require',
'people_num' => 'require',
'effective_time' => 'require',
'activity_start_time' => 'require',
'activity_end_time' => 'require',
];
protected $message = [
'id.require' => '缺少id字段',
'goods_id.require' => '请选择商品',
'people_num.require' => '请填写成团人数',
'effective_time.require' => '请填写团失效时长',
'activity_start_time.require' => '请选择团开始时间',
'activity_end_time.require' => '请选择团结束时间',
];
protected $scene = [
'id' => ['id'],
'add' => ['goods_id', 'people_num', 'effective_time', 'activity_start_time', 'activity_end_time'],
'edit' => ['id', 'goods_id', 'people_num', 'effective_time', 'activity_start_time', 'activity_end_time'],
];
}

View File

@ -0,0 +1,46 @@
<?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\activity_area;
use think\facade\Db;
use app\common\model\activity_area\ActivityAreaGoods;
use app\common\basics\Validate;
class ActivityGoodsValidate extends Validate{
protected $rule = [
'activity_id' => 'require',
'goods_id' => 'require|checkGoods',
];
protected $message = [
'activity_id.require' => '请选择活动专区',
'goods_id.require' => '请先添加商品',
];
protected $scene = [
'add' => ['activity_id','goods_id'],
];
protected function checkGoods($value,$rule,$data){
$activity_goods = ActivityAreaGoods::where(['activity_area_id'=>$data['activity_id'],'goods_id'=>$value[0],'del'=>0])
->find();
if($activity_goods){
return '该商品已在该活动专区中,请勿重复添加';
}
return true;
}
}

View File

@ -0,0 +1,66 @@
<?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\activity_area;
use app\common\basics\Validate;
use think\facade\Db;
class AreaValidate extends Validate{
protected $rule = [
'id' => 'require|checkArea',
'name' => 'require|unique:activity_area,name^del',
'synopsis' => 'require',
// 'image' => 'require',
];
protected $message = [
'name.require' => '请输入专区名称',
'name.unique' => '专区名称重复',
'synopsis.require' => '请专区简介',
];
protected $scene = [
'add' => ['name','synopsis'],
'edit' => [['id','checkArea'],'name','synopsis'],
'del' => ['id']
];
// public function sceneEdit()
// {
// $this->remove('id','checkArea');
// }
//
// public function sceneDel()
// {
// $this->only(['id']);
// }
//验证活动专区
public function checkArea($value,$rule,$data){
$goods = Db::name('activity_area_goods')
->where(['del'=>0,'activity_area_id'=>$value])
->find();
if($goods){
return '该活动专区已被使用,无法删除';
}
return true;
}
}

View 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\coupon;
use think\Validate;
class CouponValidate extends Validate{
protected $rule = [
'name' => 'require|max:16', //优惠券名称
'send_time_start' => 'require|checkSendTime', //优惠券发放开始时间
'send_time_end' => 'require', //优惠券发放结束时间
'money' => 'require|gt:0', //优惠券面额
'send_total_type' => 'require|in:1,2', //发送总量类型1-不限制2-限制张数
'send_total' => 'requireIf:send_total_type,2|gt:0', //发送总量类型为2时该字段为限制的张数
'condition_type' => 'require|in:1,2', //使用条件类型1-无门槛2-订单满足金额
'condition_money' => 'requireIf:condition_type,2|gt:0', //使用条件类型为2时该字段为订单满足金额可使用
'use_time_type' => 'require|in:1,2,3', //用券时间类型1-固定时间2-领券当天起3-领券次日起
'use_time_start' => 'requireIf:use_time_type,1|checkUseTime',//用券时间类型为1时该字段为使用开始时间
'use_time_end' => 'requireIf:use_time_type,1', //用券时间类型为1时该字段为使用结束时间
'use_time' => 'requireIf:use_time_type,2', //用券时间类型为2时该字段为多少天内可用
'tomorrow_use_time' => 'requireIf:use_time_type,3', //用券时间类型为3时该字段为多少天内可用
'get_type' => 'require|in:1,2', //领取类型1-直接领取2-商家赠送
'get_num_type' => 'require|in:1,2,3', //领取次数类型1-不限制领取次数2-限制次数3-每天限制数量
'get_num' => 'requireIf:get_num_type,2', //领取次数类型为2时该字段为领取限制的数量
'use_goods_type' => 'require|in:1,2,3', //适用商品类型:1-全部商品2-部分商品可用3-部分商品不可用
];
protected $message = [
'name.require' => '请输入优惠券名称',
'name.max' => '优惠券名称长度最多16个字符',
'send_time_start.require' => '请选择优惠券开始发放时间',
'send_time_end.require' => '请选择优惠券结束发放时间',
'money.require' => '请输入优惠券面额',
'money.gt' => '优惠券面额必须大于零',
'send_total_type.require' => '请选择发放总量',
'send_total_type.in' => '发放总量类型错误',
'send_total.requireIf' => '请填写限制张数',
'send_total.gt' => '限制张数必须大于0',
'condition_type.require' => '请选择使用门槛',
'condition_type.in' => '使用门槛类型错误',
'condition_money.gt' => '使用门槛金额不可小于0',
'use_time_type.require' => '请选择用券时间',
'use_time_start.requireIf' => '请选择优惠券使用时间',
'use_time_end.requireIf' => '请选择优惠券使用时间',
'use_time.requireIf' => '请选择优惠券使用时间',
'tomorrow_use_time.requireIf' => '请选择优惠券使用时间',
'get_type.require' => '请选择领取方式',
'get_type.in' => '领取方式类型错误',
'get_num_type.require' => '请选择领取次数',
'get_num_type.in' => '领取次数类型错误',
'get_num.requireIf' => '请输入领取次数',
'day_get_num.requireIf' => '请输入领取次数',
'use_goods_type.require' => '请选择适用商品',
'use_goods_type.in' => '适用商品类型错误',
];
public function checkUseTime($value,$rule,$data){
if($value && strtotime($value) == strtotime($data['use_time_end'])){
return '用券时间开始时间和结束时间不能相同';
}
return true;
}
public function checkSendTime($value,$rule,$data){
if($value && strtotime($value) == strtotime($data['send_time_end'])){
return '发放开始时间和结束时间不能相同';
}
if (strtotime($data['send_time_end']) < strtotime($value)) {
return '发放结束时间不能小于发放开始时间';
}
return true;
}
}

View File

@ -0,0 +1,125 @@
<?php
namespace app\shop\validate\express_assistant;
use app\common\basics\Validate;
use app\common\enum\OrderEnum;
use app\common\enum\PayEnum;
use app\common\enum\TeamEnum;
use app\common\model\Express;
use app\common\model\face_sheet\FaceSheetSender;
use app\common\model\face_sheet\FaceSheetTemplate;
use app\common\model\order\Order;
use app\common\model\team\TeamJoin;
/**
* 电子面单打印
* Class FaceSheetOrderValidate
* @package app\shop\validate\kefu
*/
class FaceSheetOrderValidate extends Validate
{
protected $rule = [
'order_id' => 'require|checkOrder',
'template_id' => 'require|checkTemplate',
'sender_id' => 'require|checkSender',
];
protected $message = [
'order_ids.require' => '请选择要打印的订单',
'order_ids.array' => '订单参数须为数组格式',
'template_id.require' => '请选择电子模板',
'sender_id.require' => '请选择发件人',
];
/**
* @notes 校验订单是否可打印
* @param $value
* @param $rrule
* @param $data
* @return bool|string
* @author 段誉
* @date 2023/2/14 9:49
*/
public function checkOrder($value, $rrule, $data)
{
$order = Order::where(['shop_id' => $data['shop_id'], 'id' => $value])->findOrEmpty()->toArray();
if (empty($order)) {
return '不存在id为' . $value . '的订单';
}
if ($order['order_status'] != OrderEnum::ORDER_STATUS_DELIVERY) {
return '订单' . $order['order_sn'] . '不是待发货状态';
}
if ($order['pay_status'] == PayEnum::UNPAID) {
return '订单' . $order['order_sn'] . '未支付';
}
if ($order['delivery_type'] != OrderEnum::DELIVERY_TYPE_EXPRESS) {
return '订单' . $order['order_sn'] . '配送方式不是快递发货';
}
if ($order['refund_status'] > OrderEnum::REFUND_STATUS_NO_REFUND) {
return '订单' . $order['order_sn'] . '已发生退款';
}
if ($order['order_type'] == OrderEnum::TEAM_ORDER && !$this->checkTeamJoinOrder($order['id'])) {
return '拼团订单:' . $order['order_sn'] . '需要拼团成功后才能打印';
}
return true;
}
/**
* @notes 校验面单模板
* @param $templateId
* @return bool|string
* @author 段誉
* @date 2023/2/13 18:15
*/
public function checkTemplate($templateId, $rule, $data)
{
$template = FaceSheetTemplate::where(['shop_id' => $data['shop_id'], 'id' => $templateId])->findOrEmpty($templateId);
if ($template->isEmpty()) {
return '电子面单模板不存在';
}
if (Express::findOrEmpty($template['express_id'])->isEmpty()) {
return '电子面单模板中的快递公司不存在';
}
return true;
}
/**
* @notes 校验发件人模板
* @param $senderId
* @return bool|string
* @author 段誉
* @date 2023/2/13 18:16
*/
public function checkSender($senderId, $rule, $data)
{
$sender = FaceSheetSender::where(['shop_id' => $data['shop_id'], 'id' => $senderId])->findOrEmpty();
if ($sender->isEmpty()) {
return '发件人模板不存在';
}
return true;
}
/**
* @notes 校验拼团订单
* @param $orderId
* @return bool
* @author 段誉
* @date 2023/2/13 18:11
*/
public function checkTeamJoinOrder($orderId)
{
$teamJoin = TeamJoin::where(['order_id' => $orderId])->findOrEmpty();
if (!$teamJoin->isEmpty() && $teamJoin['status'] == TeamEnum::TEAM_STATUS_SUCCESS) {
// 拼团成功
return true;
}
return false;
}
}

View 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;
}
}

View 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;
}
}

View 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;
}
}

View 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;
}
}

View 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;
}
}

View 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;
}
}

View 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;
}
}

View File

@ -0,0 +1,68 @@
<?php
// +----------------------------------------------------------------------
// | likeshop100%开源免费商用商城系统
// +----------------------------------------------------------------------
// | 欢迎阅读学习系统程序代码,建议反馈是我们前进的动力
// | 开源版本可自由商用可去除界面版权logo
// | 商业版本务必购买商业授权,以免引起法律纠纷
// | 禁止对系统程序代码以任何目的,任何形式的再发布
// | 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团队 版权所有 拥有最终解释权
// +----------------------------------------------------------------------
// | author: likeshopTeam
// +----------------------------------------------------------------------
namespace app\shop\validate\kefu;
use app\common\basics\Validate;
use app\common\model\kefu\KefuLang;
/**
*
* Class KefuLangValidate
* @package app\admin\validate\kefu
*/
class KefuLangValidate extends Validate
{
protected $rule = [
'id' => 'require|checkLang',
'title' => 'require|unique:'.KefuLang::class.',title^shop_id',
'content' => 'require|unique:'.KefuLang::class.',content^shop_id',
'sort' => 'gt:0',
];
protected $message = [
'title.require' => '请输入标题',
'title.unique' => '标题已存在',
'content.require' => '请输入内容',
'content.unique' => '内容已存在',
'sort.gt' => '排序不能小于零',
];
public function sceneAdd()
{
$this->remove('id', true);
}
public function sceneDel()
{
$this->only(['id']);
}
public function checkLang($value,$rule,$data){
$lang = KefuLang::where(['id'=>$value,'shop_id'=>$data['shop_id']])->find();
if($lang){
return true;
}
return '话术不存在';
}
}

View File

@ -0,0 +1,98 @@
<?php
namespace app\shop\validate\kefu;
use app\common\basics\Validate;
use app\common\model\kefu\Kefu;
/**
* 客服验证逻辑
* Class KefuValidate
* @package app\admin\validate\content
*/
class KefuValidate extends Validate
{
protected $rule = [
'id' => 'require|number',
'admin_id' => 'require|number|checkIsKefu',
'avatar' => 'require',
'nickname' => 'require',
'disable' => 'require|in:0,1',
'sort' => 'gt:0'
];
protected $message = [
'id.require' => 'id不可为空',
'id.number' => 'id必须为数字',
'admin_id.require' => '请选择管理员',
'admin_id.number' => '管理员选择异常',
'avatar.require' => '请选择头像',
'nickname.require' => '请填写客服昵称',
'disable.require' => '请选择状态',
'disable.in' => '状态错误',
'sort.gt' => '排序需大于0',
];
public function sceneAdd()
{
$this->remove('id', true);
}
public function sceneEdit()
{
$this->remove('admin_id',true);
}
public function sceneDel()
{
$this->only(['id'])->append('id', 'checkIsDel');
}
/**
* @notes 选中管理员是否已为客服
* @param $value
* @param $rule
* @param array $data
* @return bool|string
* @author 段誉
* @date 2021/11/26 18:56
*/
protected function checkIsKefu($value, $rule, $data = [])
{
$check = Kefu::where([
'admin_id' => $value,
'shop_id' => $data['shop_id'],
'del' => 0
])->findOrEmpty();
if (!$check->isEmpty()) {
return "该管理员已是客服";
}
return true;
}
/**
* @notes 客服是否存在
* @param $value
* @param $rule
* @param array $data
* @return bool|string
* @author 段誉
* @date 2021/11/26 18:57
*/
protected function checkIsDel($value, $rule, $data = [])
{
$check = Kefu::where(['id' => $value, 'del' => 0])->findOrEmpty();
if ($check->isEmpty()) {
return "该客服数据错误";
}
return true;
}
}

View File

@ -0,0 +1,29 @@
<?php
namespace app\shop\validate\kefu;
use app\common\basics\Validate;
use app\common\logic\ChatLogic;
class LoginValidate extends Validate
{
protected $rule = [
'id' => 'require|number|checkConfig',
];
protected $message = [
'id.require' => 'id不可为空',
'id.number' => 'id必须为数字',
];
protected function checkConfig($value, $rule, $data = [])
{
if (false === ChatLogic::checkConfig($data['shop_id'])) {
return ChatLogic::getError() ?: '请联系管理员设置后台配置';
}
return true;
}
}

View File

@ -0,0 +1,90 @@
<?php
// +----------------------------------------------------------------------
// | likeshop100%开源免费商用商城系统
// +----------------------------------------------------------------------
// | 欢迎阅读学习系统程序代码,建议反馈是我们前进的动力
// | 开源版本可自由商用可去除界面版权logo
// | 商业版本务必购买商业授权,以免引起法律纠纷
// | 禁止对系统程序代码以任何目的,任何形式的再发布
// | 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团队 版权所有 拥有最终解释权
// +----------------------------------------------------------------------
// | author: likeshopTeam
// +----------------------------------------------------------------------
namespace app\shop\validate\live;
use app\common\basics\Validate;
use app\common\model\live\LiveGoods;
/**
* 直播商品验证器
* Class LiveGoodsValidate
* @package app\shop\validate\live
*/
class LiveGoodsValidate extends Validate
{
protected $rule = [
'id' => 'require|checkLiveGoods',
'name' => 'require|length:3,14',
'price_type' => 'require',
'url' => 'require',
'cover_img' => 'require',
];
protected $message = [
'id.require' => '参数缺失',
'name.require' => '请输入商品名称',
'name.length' => '商品名称长度在3~14个汉字',
'cover_img' => '请选择商品封面',
];
protected function sceneAdd()
{
return $this->remove(['id' => 'require']);
}
protected function sceneDel()
{
return $this->only(['id']);
}
protected function sceneDetail()
{
return $this->only(['id']);
}
/**
* @notes 校验直播商品
* @param $value
* @param $rule
* @param $data
* @return bool|string
* @author 段誉
* @date 2023/2/16 11:10
*/
protected function checkLiveGoods($value, $rule, $data)
{
$room = LiveGoods::where([
'id' => $value,
'shop_id' => $data['shop_id'],
'del' => 0
])->findOrEmpty();
if ($room->isEmpty()) {
return '直播商品不存在';
}
return true;
}
}

View File

@ -0,0 +1,141 @@
<?php
// +----------------------------------------------------------------------
// | likeshop100%开源免费商用商城系统
// +----------------------------------------------------------------------
// | 欢迎阅读学习系统程序代码,建议反馈是我们前进的动力
// | 开源版本可自由商用可去除界面版权logo
// | 商业版本务必购买商业授权,以免引起法律纠纷
// | 禁止对系统程序代码以任何目的,任何形式的再发布
// | 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团队 版权所有 拥有最终解释权
// +----------------------------------------------------------------------
// | author: likeshopTeam
// +----------------------------------------------------------------------
namespace app\shop\validate\live;
use app\common\basics\Validate;
use app\common\model\live\LiveRoom;
/**
* 直播间验证器
* Class LiveRoomValidate
* @package app\shop\validate\live
*/
class LiveRoomValidate extends Validate
{
protected $rule = [
'id' => 'require|checkLiveRoom',
'type' => 'require|in:0',
'name' => 'require|length:3,17',
'start_time' => 'require|checkStartTime',
'end_time' => 'require|checkEndTime',
'anchor_name' => 'require|length:2,15',
'anchor_wechat' => 'require',
'cover_img' => 'require',
'share_img' => 'require',
'feeds_img' => 'require',
];
protected $message = [
'id.require' => '参数缺失',
'type.require' => '请选择直播类型',
'type.in' => '直播类型错误',
'name.require' => '请输入直播间名字',
'name.length' => '直播间名字长度在3~17个汉字',
'start_time.require' => '请选择直播开始时间',
'end_time.require' => '请选择直播结束时间',
'anchor_name.require' => '请输入主播名称',
'anchor_name.length' => '主播名称长度在2~15个汉字',
'anchor_wechat.require' => '请输入主播微信号',
'cover_img' => '请直播间背景墙',
'share_img' => '请分享卡片封面',
'feeds_img' => '请直播卡片封面',
];
protected function sceneAdd()
{
return $this->remove(['id' => 'require']);
}
protected function sceneDel()
{
return $this->only(['id']);
}
/**
* @notes 校验开始时间
* @param $value
* @param $rule
* @param $data
* @return bool|string
* @author 段誉
* @date 2023/2/15 15:50
*/
protected function checkStartTime($value, $rule, $data)
{
$now = time();
$start = strtotime($value);
if (($start - $now) <= 600) {
return '开播时间需要在当前时间的10分钟后';
}
if (($start - $now) >= (180 * 86400)) {
return '开始时间不能在6个月后';
}
return true;
}
/**
* @notes 校验结束时间
* @param $value
* @param $rule
* @param $data
* @return bool|string
* @author 段誉
* @date 2023/2/15 15:51
*/
protected function checkEndTime($value, $rule, $data)
{
$end = strtotime($value);
$start = strtotime($data['start_time']);
if (($end - $start) <= (30 * 60)) {
return '开播时间和结束时间间隔不得短于30分钟';
}
if ($end - $start >= 86400) {
return '开播时间和结束时间间隔不得超过24小时';
}
return true;
}
/**
* @notes 校验直播间
* @param $value
* @param $rule
* @param $data
* @return bool|string
* @author 段誉
* @date 2023/2/16 11:10
*/
protected function checkLiveRoom($value, $rule, $data)
{
$room = LiveRoom::where([
'id' => $value,
'shop_id' => $data['shop_id'],
'del' => 0
])->findOrEmpty();
if ($room->isEmpty()) {
return '直播间信息不存在';
}
return true;
}
}

View File

@ -0,0 +1,48 @@
<?php
namespace app\shop\validate\order;
use app\common\basics\Validate;
class DeliveryBatchImportValidate extends Validate
{
protected $rule = [
'lists' => [ 'require', 'checkLists' ],
];
protected $message = [
'lists.require' => '上传文件不能为空',
];
function checkLists($lists, $rule, $data)
{
$nums = count($lists) - 1;
if ($nums < 1) {
return '导入的文件发货信息为空';
}
if ($nums > 2000) {
return '单次最多导入2000条发货信息';
}
foreach ($lists as $key => $info) {
if (empty(trim($info['A'])) || empty(trim($info['B'])) || empty(trim($info['C']))) {
return '发货信息:第' . ($key + 2) . '行存在未填写的发货信息';
}
if (mb_strlen($info['A']) > 255) {
return '发货信息:第' . ($key + 2) . '行发货信息 订单号 超过长度255';
}
if (mb_strlen($info['B']) > 255) {
return '发货信息:第' . ($key + 2) . '行发货信息超过长度255';
}
if (mb_strlen($info['C']) > 255) {
return '发货信息:第' . ($key + 2) . '行发货信息超过长度255';
}
}
return true;
}
}

View File

@ -0,0 +1,37 @@
<?php
namespace app\shop\validate\order;
use app\common\basics\Validate;
use app\common\model\order\OrderInvoice;
/**
* 订单发票验证
* Class OrderInvoiceValidate
* @package app\shop\validate\order
*/
class OrderInvoiceValidate extends Validate
{
protected $rule = [
'id' => 'require|checkInvoice',
'status' => 'require',
'invoice_number' => 'require',
];
protected $message = [
'id.require' => '缺少ID字段',
'status.require' => '请选择开票状态',
'invoice_number.require' => '请填写发票编号',
];
protected function checkInvoice($value, $rule, $data)
{
$invoice = OrderInvoice::findOrEmpty($value);
if ($invoice->isEmpty()) {
return '该发票记录不存在';
}
return true;
}
}

View File

@ -0,0 +1,36 @@
<?php
namespace app\shop\validate\order;
use app\common\basics\Validate;
use app\common\model\printer\Printer;
use app\common\model\printer\PrinterConfig;
class OrderPrintValidate extends Validate
{
protected $rule = [
'id' => 'require|checkPrint',
];
protected $message = [
'id.require' => '缺少ID字段',
];
protected function checkPrint($value, $rule, $data)
{
$config = PrinterConfig::where(['status' => 1, 'shop_id' => $data['shop_id']])->findOrEmpty();
if ($config->isEmpty()) {
return '请先到小票打印里面配置打印设置';
}
$printer = Printer::where(['config_id' => $config['id'], 'shop_id' => $data['shop_id']])->findOrEmpty();
if ($printer->isEmpty()) {
return '请先添加打印机';
}
return true;
}
}

View File

@ -0,0 +1,86 @@
<?php
namespace app\shop\validate\order;
use app\common\basics\Validate;
use app\common\enum\OrderEnum;
use app\common\enum\PayEnum;
use app\common\enum\TeamEnum;
use app\common\model\order\Order;
use app\common\model\team\TeamJoin;
/**
* 自提核销验证
* Class VerificationValidate
* @package app\shop\validate\order
*/
class VerificationValidate extends Validate
{
protected $rule = [
'order_id' => 'require|checkId',
];
protected $message = [
'order_id.require' => '参数缺失',
];
public function sceneVerification()
{
return $this->only(['order_id'])
->append('order_id', 'checkVerification');
}
/**
* @notes 校验订单
* @param $value
* @param $rule
* @param $data
* @return bool|string
* @author 段誉
* @date 2022/11/2 14:41
*/
public function checkId($value, $rule, $data)
{
$result = Order::where('id', $value)->findOrEmpty();
if ($result->isEmpty()) {
return '订单不存在';
}
return true;
}
/**
* @notes 校验订单是否可以提货核销
* @param $value
* @param $rule
* @param $data
* @return bool|string
* @author 段誉
* @date 2022/11/2 14:42
*/
public function checkVerification($value, $rule, $data)
{
$result = Order::where('id', $value)->findOrEmpty();
if ($result['pay_status'] != PayEnum::ISPAID) {
return '订单未支付,不允许核销';
}
if ($result['delivery_type'] != OrderEnum::DELIVERY_TYPE_SELF) {
return '非自提订单,不允许核销';
}
if ($result['verification_status'] == OrderEnum::WRITTEN_OFF) {
return '订单已核销';
}
if ($result['order_type'] == OrderEnum::TEAM_ORDER) {
$teamcheck = TeamJoin::where(['order_id' => $value, 'status' => TeamEnum::TEAM_STATUS_SUCCESS])->findOrEmpty();
if ($teamcheck->isEmpty()) {
return '拼团成功后才能核销';
}
}
return true;
}
}

View File

@ -0,0 +1,52 @@
<?php
namespace app\shop\validate\order;
use app\common\basics\Validate;
use app\common\model\order\Order;
/**
* 虚拟发货验证
* Class virtualDeliveryValidate
* @package app\shop\validate\order
*/
class VirtualDeliveryValidate extends Validate
{
protected $rule = [
'order_id' => 'require|checkOrder',
'delivery_content' => 'require',
];
protected $message = [
'order_id.require' => '缺少ID字段',
'delivery_content.require' => '请填写发货内容',
];
/**
* @notes 校验订单信息
* @param $value
* @param $rule
* @param $data
* @return bool|string
* @author 段誉
* @date 2022/4/7 18:26
*/
protected function checkOrder($value, $rule, $data)
{
$order = Order::findOrEmpty($value);
if ($order->isEmpty()) {
return '订单不存在';
}
if ($order['del'] == 1) {
return '订单已删除';
}
if ($order['shipping_status'] == 1) {
return '此订单已发货';
}
return true;
}
}

View File

@ -0,0 +1,47 @@
<?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\printer;
use app\common\basics\Validate;
/**
* 打印设置验证器
* Class ConfigValidate
* @package app\admin\validate\printer
*/
class ConfigValidate extends Validate
{
protected $rule = [
'id' => 'require',
'client_id' => 'require',
'client_secret' => 'require',
];
protected $message = [
'id.require' => '请选择打印机配置',
'client_id.require' => '请输入应用ID',
'client_secret.require' => '请输入应用秘钥',
];
}

View File

@ -0,0 +1,98 @@
<?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\printer;
use app\common\basics\Validate;
use app\common\model\printer\Printer;
use app\common\model\printer\PrinterConfig;
use think\facade\Db;
class PrinterValidate extends Validate
{
protected $rule = [
'id' => 'require',
'config_id' => 'require|checkType',
'name' => 'require',
'machine_code' => 'require|unique:printer,machine_code^del^config_id',
'private_key' => 'require',
'print_number' => 'require',
];
protected $message = [
'id.require' => '请选择打印机',
'config_id.require' => '请选择打印机类型',
'name.require' => '请输入打印机名称',
'machine_code.require' => '请输入终端号',
'machine_code.unique' => '终端号重复',
'private_key.require' => '请输入秘钥',
'print_number.require' => '请输入打印联数',
];
public function sceneAdd()
{
return $this->remove('id', true);
}
public function sceneDel()
{
return $this->only(['id']);
}
public function sceneConfig()
{
return $this->only(['id'])->append('id', 'checkPrinter');
}
// 验证类型
protected function checkType($value, $rule, $data)
{
$type = PrinterConfig::where(['id' => $value, 'shop_id' => $data['shop_id'], 'del' => 0])->findOrEmpty();
if ($type->isEmpty()) {
return '打印机配置错误';
}
if (empty($type['client_id']) || empty($type['client_secret'])) {
return '请先设置' . $type['name'] . '的配置';
}
return true;
}
// 验证打印机
protected function checkPrinter($value, $rule, $data)
{
$printer = Printer::where(['id' => $value, 'shop_id' => $data['shop_id']])->find();
if (!$printer || !$printer['machine_code']) {
return '打印机配置错误';
}
$type = PrinterConfig::where(['id' => $printer['config_id']])->find();
if (!$type) {
return '打印配置错误';
}
if (!$type['client_id'] || !$type['client_secret']) {
return '请先设置' . $type['name'] . '的配置';
}
return true;
}
}

View File

@ -0,0 +1,41 @@
<?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\printer;
use app\common\basics\Validate;
/**
* 小票模板验证器
* Class TemplateValidate
* @package app\admin\validate\printer
*/
class TemplateValidate extends Validate
{
protected $rule = [
'title' => 'require',
'qr_code_link' => 'require',
];
protected $message = [
'title.require' => '请输入小票标题',
'qr_code_link.require' => '请输入二维码链接',
];
}