初始版本

This commit is contained in:
贾祥聪
2025-08-19 14:16:51 +08:00
commit f937a1f9b9
4373 changed files with 359728 additions and 0 deletions

View File

@@ -0,0 +1,198 @@
<?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\shopapi\validate;
use app\common\model\city\City;
use app\common\model\goods\Goods;
use app\common\model\goods\GoodsCategory;
use app\common\model\skill\Skill;
use app\common\validate\BaseValidate;
class GoodsValidate extends BaseValidate
{
protected $rule = [
'id' => 'require|checkId',
'name' => 'require|max:64|checkGoodsName',
'category_id' => 'require|checkCategory',
'goods_image' => 'require|array|max:10',
'price' => 'require|float|egt:0',
'scribing_price' => 'float|egt:0',
'status' => 'require|in:0,1',
'duration' => 'require|float|egt:0',
'overtime_price'=> 'require|float|egt:0',
'overtime_duration'=> 'require|float|egt:0',
'commission_ratio' =>' require|float|egt:0',
'appoint_start_time' => 'require',
'appoint_end_time' => 'require',
'skill_id' => 'require|array|checkSkill',
// 'city_id' => 'require|array|checkCity',
];
protected $message = [
'id.require' => '参数错误',
'name.require' => '请输入服务名称',
'name.max' => '服务名称已超过限制字数',
'name.unique' => '服务名称重复',
'category_id.require' => '请选择服务分类',
'goods_image.require' => '请上传轮播图',
'goods_image.array' => '轮播图格式不正确',
'goods_image.max' => '轮播图数量不能大于10张',
'price.require' => '请输入价格',
'price.float' => '价格必须为浮点数',
'price.egt' => '价格必须大于或等于零',
'duration.require' => '请输入时长',
'overtime_price.require' => '请输入加时费用',
'overtime_price.float' => '加时费用必须为浮点数',
'overtime_price.egt' => '加时费用必须大于或等于零',
'overtime_duration.require' => '请输入加时时长',
'overtime_duration.float' => '加时时长必须为浮点数',
'overtime_duration.egt' => '加时时长必须大于或等于零',
'commission_ratio.require' => '请输入服务佣金',
'commission_ratio.float' => '服务佣金必须为浮点数',
'commission_ratio.egt' => '服务佣金必须大于或等于零',
'scribing_price.float' => '划线价必须为浮点数',
'scribing_price.egt' => '划线价必须大于或等于零',
'status.require' => '请选择服务状态',
'status.in' => '服务状态取值范围在[0,1]',
'ids.require' => '请选择服务',
'ids.array' => '参数格式错误',
'skill_id.require' => '请选择技能',
'city_id.require' => '请选择开通城市',
'appoint_start_time.require'=> '请输入预约开始时间',
'appoint_end_time.require'=> '请输入预约结束时间'
];
public function sceneAdd()
{
return $this->remove(['id'=>true,'ids'=>true]);
}
public function sceneDetail()
{
return $this->only(['id']);
}
public function sceneEdit()
{
return $this->remove(['ids'=>true]);
}
public function sceneDel()
{
return $this->only(['id'])
->append('id','checkDel');
}
public function sceneStatus()
{
return $this->only(['id','status']);
}
/**
* @notes 检验服务ID
* @param $value
* @param $rule
* @param $data
* @return bool|string
* @author ljj
* @date 2022/2/9 12:02 下午
*/
public function checkId($value,$rule,$data)
{
$result = Goods::where(['id'=>$value])->findOrEmpty();
if ($result->isEmpty()) {
return '服务不存在';
}
return true;
}
/**
* @notes 检验服务分类id
* @param $value
* @param $rule
* @param $data
* @return bool|string
* @author ljj
* @date 2022/2/9 12:06 下午
*/
public function checkCategory($value,$rule,$data)
{
$result = GoodsCategory::where(['id'=>$value])->findOrEmpty();
if ($result->isEmpty()) {
return '服务分类不存在,请重新选择';
}
return true;
}
/**
* @notes 检验服务能否被删除
* @param $value
* @param $rule
* @param $data
* @return bool|string
* @throws \think\db\exception\DataNotFoundException
* @throws \think\db\exception\DbException
* @throws \think\db\exception\ModelNotFoundException
* @author ljj
* @date 2022/4/1 3:37 下午
*/
public function checkDel($value,$rule,$data)
{
// $goods = Goods::column('name','id');
// foreach ($value as $val) {
// $result = Staff::whereRaw("FIND_IN_SET($val,goods_ids)")->select()->toArray();
// if ($result) {
// return '服务:'.$goods[$val].'已被师傅绑定,无法删除';
// }
// }
return true;
}
public function checkSkill($value,$rule,$data){
$lists = Skill::where(['id'=>$value])->select();
if(count($lists)!=count($value)){
return '技能数据错误';
}
return true;
}
public function checkGoodsName($value,$rule,$data)
{
$where[] = ['name','=',$value];
if(isset($data['id']) && $data['id']){
$where[] = ['id','<>',$data['id']];
}
if(isset($data['shop_id']) && $data['shop_id']){
$where[] = ['shop_id','<>',$data['shop_id']];
}
$goods = Goods::where($where)->findOrEmpty();
if($goods->isEmpty()){
return true;
}
return '服务名称已存在';
}
}