其余文件

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,142 @@
<?php
namespace app\api\validate;
use app\common\basics\Validate;
use app\common\server\ConfigServer;
use think\facade\Db;
use app\common\model\after_sale\AfterSale;
use app\common\enum\OrderEnum;
class AfterSaleValidate extends Validate
{
protected $rule = [
'id' => 'require',
'order_id' => 'require|checkSettle|checkRefundAddress|checkAfterSale|checkAbleApply',
'reason' => 'require',
'item_id' => 'require',
'refund_type' => 'require',
'express_name' => 'require',
'invoice_no' => 'require|alphaNum',
];
protected $message = [
'id.require' => '参数错误',
'reason.require' => '请选择退款原因',
'order_id.require' => '参数错误',
'order_id.checkSettle' => '该订单无法申请售后',
'order_id.checkRefundAddress' => '该商家未设置售后地址',
'item_id.require' => '参数错误',
'refund_type.require' => '参数错误',
'express_name.require' => '请填写物流公司名称',
'invoice_no.require' => '请填写快递单号',
'invoice_no.alphaNum' => '请填写正确的快递单号',
];
protected $scene = [
'add' => ['item_id', 'order_id', 'reason', 'refund_type'],
'sceneInfo' => ['order_id', 'item_id'],
'goodsInfo' => ['item_id'],
'express' => ['id', 'express_name', 'invoice_no'],
'cancel' => ['id'],
'detail' => ['id'],
'again' => ['id', 'reason', 'refund_type'],
];
/**
* @notes 验证该订单是否已经申请售后
* @param $value
* @param $rule
* @param $data
* @author suny
* @date 2021/7/29 4:43 下午
*/
public function checkAfterSale($value, $rule, $data)
{
$condition = [
'order_id' => $value,
'item_id' => $data['item_id'],
'del' => 0
];
$after_sale = AfterSale::where($condition)->find();
if (!$after_sale) {
return true;
} else {
return '该订单已申请过售后,请勿重复申请';
}
}
/**
* @notes 判断该订单是否已经结算
* @param $value
* @param $rule
* @param $data
* @return bool
* @author suny
* @date 2021/7/13 6:26 下午
*/
public function checkSettle($value, $rule, $data)
{
$settle_id = Db::name('order')->where('id', $value)->value('settle_id');
if ($settle_id == 1) {
return false;
} else {
return true;
}
}
/**
* @notes 验证退货地址
* @param $value
* @param $rule
* @param $data
* @return bool
* @author suny
* @date 2021/7/13 6:27 下午
*/
public function checkRefundAddress($value, $rule, $data)
{
if ($data['refund_type'] == 1) {
$shop_id = Db::name('order')->where('id', $value)->value('shop_id');
$refund_address = Db::name('shop')->where('id', $shop_id)->value('refund_address');
if (empty($refund_address) || $refund_address == '') {
return false;
} else {
return true;
}
} else {
return true;
}
}
//验证订单是否在售后时间内
protected function checkAbleApply($value, $rule, $data)
{
$now = time();
$where = [];
$where[] = ['o.id', '=', $value];
$where[] = ['g.item_id', '=', $data['item_id']];
$where[] = ['o.order_status', 'in', [OrderEnum::ORDER_STATUS_GOODS, OrderEnum::ORDER_STATUS_COMPLETE]];
$order = Db::name('order')->alias('o')
->field('o.order_status,o.confirm_take_time,g.refund_status')
->join('order_goods g', 'o.id = g.order_id')
->where($where)
->find();
$refund_days = ConfigServer::get('transaction', 'order_after_sale_days', 7);
if ($refund_days == 0) {
return true;
}
if ($order['order_status'] == OrderEnum::ORDER_STATUS_COMPLETE) {
$check_time = intval($order['confirm_take_time'] + ($refund_days * 24 * 60 * 60));
if ($now > $check_time) {
return '不在售后时间内';
}
}
return true;
}
}

View File

@ -0,0 +1,232 @@
<?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\api\validate;
use app\common\model\bargain\BargainLaunch;
use think\facade\Db;
use app\common\basics\Validate;
/**
* Class BargainValidate
* @package app\api\validate
*/
class BargainValidate extends Validate
{
protected $rule = [
'id' => 'require',
'bargain_id' => 'require',
'item_id' => 'require|checkGoods',
'url' => 'require',
];
protected $message = [
'id.require' => '请选择砍价订单',
'bargain_id.require' => '请选择活动',
'item_id.require' => '请选择规格',
'url.require' => '缺少参数',
];
/**
* @notes 砍价商品详情验证场景
* @author suny
* @date 2021/7/13 6:27 下午
*/
public function sceneDetail()
{
$this->only(['bargain_id'])
->append('bargain_id', 'checkBargain');
}
/**
* @notes 发起砍价验证
* @author suny
* @date 2021/7/13 6:27 下午
*/
public function sceneSponsor()
{
$this->only(['bargain_id', 'item_id'])->append('bargain_id', 'checkBargain');
}
/**
* @notes 砍价详情验证
* @author suny
* @date 2021/7/13 6:27 下午
*/
public function sceneBargainDetail()
{
$this->only(['id']);
}
/**
* @notes 分享验证
* @author suny
* @date 2021/7/13 6:27 下午
*/
public function sceneShare()
{
$this->only(['id', 'url'])
->append('id', 'checkBargainLaunch');
}
/**
* @notes 助力验证
* @author suny
* @date 2021/7/13 6:27 下午
*/
public function sceneKnife()
{
$this->only(['id'])
->append('id', 'checkBnife');
}
/**
* @notes 验证活动是否开启
* @param $value
* @param $rule
* @param $data
* @return bool|string
* @throws \think\db\exception\DataNotFoundException
* @throws \think\db\exception\ModelNotFoundException
* @throws \think\exception\DbException
* @author suny
* @date 2021/7/13 6:28 下午
*/
protected function checkBargain($value, $rule, $data)
{
$now = time();
$bargain = Db::name('bargain')
->where([
['id', '=', $value],
['del', '=', 0],
['activity_start_time', '<', $now],
['activity_end_time', '>', $now],
['status', '=', 1]
])
->find();
if (empty($bargain)) {
return '该砍价活动已下架';
}
return true;
}
/**
* @notes 验证商品库存
* @param $value
* @param $rule
* @param $data
* @return bool|string
* @author suny
* @date 2021/7/13 6:28 下午
*/
protected function checkGoods($value, $rule, $data)
{
$stock = Db::name('goods_item')
->where(['id' => $value])
->value('stock');
if ($stock < 1) {
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 suny
* @date 2021/7/13 6:28 下午
*/
protected function checkBargainLaunch($value, $rule, $data)
{
$bargain_launch = new BargainLaunch();
$bargain_launch = $bargain_launch
->where(['id' => $value])
->find();
if ($bargain_launch['launch_end_time'] <= time() || $bargain_launch['status'] !== 0) {
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
* @throws \think\exception\DbException
* @author suny
* @date 2021/7/13 6:28 下午
*/
protected function checkBnife($value, $rule, $data)
{
$bargain_launch = new BargainLaunch();
$bargain_launch = $bargain_launch
->where(['id' => $value])
->find()->toarray();
if (0 != $bargain_launch['status']) {
return '该砍价已结束';
}
if ($bargain_launch['launch_end_time'] <= time()) {
return '该砍价已结束';
}
if ($bargain_launch['user_id'] === $data['user_id']) {
return '不能助力自己的砍价活动';
}
if ($bargain_launch['current_price'] < 0) {
return '该砍价活动已成功';
}
//当前活动是砍到低价,且已经低于等于活动低价时,砍价成功
if (1 == $bargain_launch['bargain_snap']['payment_where'] && $bargain_launch['current_price'] <= $bargain_launch['bargain_price']) {
return '该砍价活动已成功';
}
$bargain_knife = Db::name('bargain_knife')
->where(['launch_id' => $value, 'user_id' => $data['user_id']])
->find();
if ($bargain_knife) {
return '您已助力过了';
}
return true;
}
}

View File

@ -0,0 +1,61 @@
<?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\api\validate;
use app\common\basics\Validate;
use app\common\model\Cart;
class CartValidate extends Validate
{
protected $rule = [
'cart_id' => 'require|checkCart',
'goods_num' => 'require|integer|gt:0',
'item_id' => 'require',
'selected' => 'require|in:0,1',
];
protected $message = [
'item_id' => '请选择商品',
'goods_num.require' => '商品数量不能为0',
'goods_num.gt' => '商品数量需大于0',
'goods_num.integer' => '商品数量需为整数',
'cart_id.require' => '参数错误',
'selected.require' => '参数错误',
'selected.in' => '参数错误',
];
protected $scene = [
'add' => ['item_id', 'goods_num'],
'del' => ['cart_id'],
'selected' => ['cart_id', 'selected'],
'change' => ['cart_id', 'goods_num'],
];
protected function checkCart($value, $rule, $data)
{
$cart = Cart::where(['id' => $value, 'user_id' => $data['user_id']])->find();
if (!$cart) {
return '购物车不存在';
}
return true;
}
}

View File

@ -0,0 +1,75 @@
<?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\api\validate;
use app\common\basics\Validate;
use app\common\logic\SmsLogic;
use app\common\model\Client_;
use app\common\model\user\User;
class ChangeMobileValidate extends Validate
{
protected $rule = [
'mobile' => 'require|mobile',
'new_mobile' => 'require|mobile|checkMobile',
];
protected $message = [
'mobile.require' => '参数缺失',
'mobile.mobile' => '请填写正确的手机号',
'new_mobile.mobile' => '请填写正确的手机号',
'new_mobile.require' => '请填写手机号'
];
public function sceneBinding()
{
$this->only(['new_mobile']);
}
protected function checkMobile($value, $rule, $data)
{
//检查新手机号是否已存在
$user = User::where([
['mobile', '=', $value],
['id', '<>', $data['user_id']]
])->find();
if ($user) {
return '此手机号已被使用';
}
if (!isset($data['code'])) {
return '请填写验证码';
}
$mobile = $data['new_mobile'];
if (isset($data['action']) && 'change' == $data['action'] && $data['client'] != Client_::pc) {
$mobile = $data['mobile'];
}
$res = SmsLogic::check($data['message_key'], $mobile, $data['code']);
if (false === $res) {
return SmsLogic::getError();
}
return true;
}
}

View File

@ -0,0 +1,36 @@
<?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\api\validate;
use app\common\basics\Validate;
class changeUserInfo extends Validate{
protected $rule = [
'nickname' => 'require',
'sex' => 'require|in:0,1,2',
];
protected $message = [
'nickname.require' => '请输入昵称',
'sex.require' => '请选择性别',
'sex.in' => '性别设置错误',
];
public function scenePc(){
$this->only(['nickname','sex']);
}
}

View File

@ -0,0 +1,196 @@
<?php
namespace app\api\validate;
use app\common\basics\Validate;
use app\common\enum\GoodsEnum;
use app\common\enum\ShopEnum;
use app\common\model\community\CommunityArticle;
use app\common\model\goods\Goods;
use app\common\model\shop\Shop;
/**
* 种草社区文章验证
* Class CommunityArticleValidate
* @package app\api\validate
*/
class CommunityArticleValidate extends Validate
{
protected $rule = [
'id' => 'require|checkArticle',
'content' => 'require|min:10|max:999',
'image' => 'require|checkImage',
'goods' => 'checkGoods',
'shop' => 'checkShop',
];
protected $message = [
'id.require' => '参数缺失',
'content.require' => '写够10个字才可以发布和被精选哦',
'content.min' => '至少输入10个字符',
'content.max' => '至多输入999个字符',
'image.require' => '至少要添加1张图片哦',
];
/**
* @notes 添加场景
* @return CommunityArticleValidate
* @author 段誉
* @date 2022/5/7 9:46
*/
public function sceneAdd()
{
return $this->remove('id', true);
}
/**
* @notes 编辑场景
* @author 段誉
* @date 2022/5/7 9:47
*/
public function sceneEdit()
{
}
/**
* @notes 删除场景
* @author 段誉
* @date 2022/5/7 9:47
*/
public function sceneDel()
{
return $this->only(['id']);
}
/**
* @notes 校验文章
* @param $value
* @param $rule
* @param $data
* @return bool|string
* @author 段誉
* @date 2022/5/7 9:50
*/
protected function checkArticle($value, $rule, $data)
{
$article = CommunityArticle::findOrEmpty($value);
if ($article->isEmpty()) {
return '信息不存在';
}
if ($article['del'] == 1) {
return '已被删除';
}
return true;
}
/**
* @notes 校验图片数量
* @param $value
* @param $rule
* @param $data
* @return bool|string
* @author 段誉
* @date 2022/4/29 10:53
*/
protected function checkImage($value, $rule, $data)
{
if (count($value) > 9) {
return '最多上传9张图片';
}
return true;
}
/**
* @notes 校验所选商品
* @param $value
* @param $rule
* @param $data
* @return bool|string
* @author 段誉
* @date 2022/4/29 10:53
*/
protected function checkGoods($value, $rule, $data)
{
if (empty($value)) {
return true;
}
if (!empty($data['shop'])) {
return '不能同时选择宝贝/店铺';
}
if (count($value) > 5) {
return '最多只能选择5个商品';
}
$goods_id = array_unique($value);
$where = [
['del', '=', GoodsEnum::DEL_NORMAL], // 未删除
['status', '=', GoodsEnum::STATUS_SHELVES], // 上架中
['audit_status', '=', GoodsEnum::AUDIT_STATUS_OK], // 审核通过
['id', 'in', $goods_id]
];
$goods = Goods::where($where)->column('*', 'id');
foreach ($value as $item) {
if (!isset($goods[$item])) {
return '所选商品中包含已下架商品';
}
}
return true;
}
/**
* @notes 校验所选店铺
* @param $value
* @param $rule
* @param $data
* @return bool|string
* @author 段誉
* @date 2022/4/29 10:54
*/
protected function checkShop($value, $rule, $data)
{
if (empty($value)) {
return true;
}
if (!empty($data['goods'])) {
return '不能同时选择宝贝/店铺';
}
if (count($value) > 3) {
return '最多只能选择3个店铺';
}
$shop_id = array_unique($value);
$where = [
['is_freeze', '=', ShopEnum::SHOP_FREEZE_NORMAL], // 未冻结
['del', '=', 0], // 未删除
['is_run', '=', ShopEnum::SHOP_RUN_OPEN], // 未暂停营业
['id', 'in', $shop_id]
];
$shops = Shop::where($where)->column('*', 'id');
foreach ($value as $item) {
if (!isset($shops[$item])) {
return '所选店铺中包含暂停营业店铺';
}
}
return true;
}
}

View File

@ -0,0 +1,87 @@
<?php
namespace app\api\validate;
use app\common\basics\Validate;
use app\common\enum\CommunityArticleEnum;
use app\common\model\community\CommunityArticle;
use app\common\model\community\CommunityComment;
/**
* 种草社区评论验证
* Class CommunityCommentValidate
* @package app\api\validate
*/
class CommunityCommentValidate extends Validate
{
protected $rule = [
'article_id' => 'require|checkArticle',
'comment' => 'require|max:150',
'pid' => 'checkComment',
];
protected $message = [
'article_id.require' => '参数缺失',
'comment.require' => '请输入评论内容',
'comment.max' => '评论内容不可超过150字符',
];
public function sceneAdd()
{
return $this->only(['article_id', 'comment', 'pid']);
}
public function sceneLists()
{
return $this->only(['article_id']);
}
/**
* @notes 校验文章
* @param $value
* @param $rule
* @param $data
* @return bool|string
* @author 段誉
* @date 2022/5/7 11:19
*/
protected function checkArticle($value, $rule, $data)
{
$article = CommunityArticle::findOrEmpty($value);
if ($article->isEmpty()) {
return '种草内容不存在';
}
if ($article['del'] == 1) {
return '该种草内容已被删除';
}
return true;
}
/**
* @notes 校验评论
* @param $value
* @param $rule
* @param $data
* @return bool|string
* @author 段誉
* @date 2022/5/7 11:22
*/
protected function checkComment($value, $rule, $data)
{
if (empty($value)) {
return true;
}
$comment = CommunityComment::findOrEmpty($value);
if ($comment->isEmpty()) {
return '回复评论不存在';
}
return true;
}
}

View File

@ -0,0 +1,22 @@
<?php
namespace app\api\validate;
use think\Validate;
class CouponValidate extends Validate
{
protected $rule = [
'coupon_id' => 'require',
'user_id' => 'require'
];
protected $message = [
'coupon_id.require' => '优惠券ID不能为空',
'user_id.require' => '用户ID不能为空',
];
public function sceneGetCoupon()
{
return $this->only(['coupon_id', 'user_id']);
}
}

View File

@ -0,0 +1,117 @@
<?php
namespace app\api\validate;
use app\admin\logic\distribution\DistributionSettingLogic;
use app\admin\logic\setting\UserLogic;
use app\common\model\distribution\Distribution;
use app\common\server\ConfigServer;
use think\Validate;
use app\common\model\distribution\DistributionMemberApply;
use app\common\model\user\User;
class DistributionValidate extends Validate
{
protected $rule = [
'user_id' => 'require|apply',
'real_name' => 'require',
'mobile' => 'require|mobile',
'province' => 'require|number',
'city' => 'require|number',
'district' => 'require|number',
'reason' => 'require',
'code' => 'require|checkCode',
];
protected $message = [
'user_id.require' => '无法获取用户ID',
'real_name.require' => '请填写真实姓名',
'mobile.require' => '请填写手机号',
'mobile.mobile' => '请填写正确的手机号码',
'province.require' => '请填写省份',
'province.number' => '省份需为数字代号',
'city.require' => '请填写城市',
'city.number' => '城市须为数字代号',
'district.require' => '请填写县区',
'district.number' => '县区段为数字代号',
'reason.require' => '请填写申请原因',
'code.require' => '请填写邀请码',
];
/**
* 申请分销会员场景
*/
public function sceneApply()
{
return $this->only(['user_id','real_name','mobile','province','city','district','reason']);
}
/**
* 填写邀请码
*/
public function sceneCode()
{
return $this->only(['code']);
}
/**
* 判断当前用户是否有待审核的申请记录
*/
public function apply($value, $rule, $data)
{
$where = [
'user_id' => $value,
'status' => 0, // 审核中
];
$apply = DistributionMemberApply::where($where)->findOrEmpty();
if($apply->isEmpty()) {
return true;
}
return '正在审核中,请勿重复提交申请';
}
/**
* 邀请码验证
*/
public function checkCode($value, $rule, $data)
{
$config = UserLogic::getConfig();
// 总开关
$config['switch'] = ConfigServer::get('distribution', 'is_open');
if(!$config['switch']) {
return '系统已关闭分销功能,无法邀请粉丝';
}
if(!$config['is_open']) {
return '系统已关闭邀请功能';
}
$user = User::where(['id'=>$data['user_id'], 'del'=>0])->findOrEmpty();
if($user->isEmpty()) {
return '无法获取当前用户信息';
}
if(!empty($user['first_leader'])) {
return '已有邀请人';
}
$firstLader = User::field('id,is_distribution,level,ancestor_relation,user_delete')
->where('distribution_code', $value)
->findOrEmpty();
if($firstLader->isEmpty() || $firstLader->user_delete) {
return '无效的邀请码';
}
if($firstLader['id'] == $data['user_id']) {
return '不能填自己的邀请码';
}
// qualifications-邀请资格 【1-全部用户 2-指定等级用户】
$invite_appoint_user = ConfigServer::get('invite', 'invite_appoint_user', []);
if(in_array(2, $config['qualifications']) && !in_array($firstLader['level'],$invite_appoint_user)) {
return '邀请下级资格未达到要求';
}
// 如果当前用户id出现在邀请人的祖先链路中代表当前用户是已经是邀请人的上级或祖先级同时意味着邀请人是当前用户的后代级别
// 不能将自己的上级设置为自己的后代级用户
$ancestorArr = explode(',', $firstLader['ancestor_relation']);
if(!empty($ancestorArr) && in_array($data['user_id'], $ancestorArr)) {
return '不能填写自己下级的邀请码';
}
return true;
}
}

View File

@ -0,0 +1,25 @@
<?php
namespace app\api\validate;
use think\Validate;
class GoodsCommentValidate extends Validate
{
protected $rule = [
'order_goods_id' => 'require',
'goods_comment' =>'require',
'description_comment' =>'require',
'service_comment' =>'require',
'express_comment' =>'require',
];
protected $message = [
'order_goods_id.require' =>'请传入子订单id',
'shop_id.require' =>'请传入店铺id',
'goods_comment.require' =>'请进行商品评价',
'description_comment.require' =>'请进行描述相符评价',
'service_comment.require' =>'请进行服务态度评价',
'express_comment.require' =>'请进行配送服务评价',
];
}

View File

@ -0,0 +1,45 @@
<?php
namespace app\api\validate;
use app\common\basics\Validate;
use app\common\enum\IntegralGoodsEnum;
use app\common\model\integral\IntegralGoods;
/**
* 积分商品验证
* Class IntegralOrderValidate
* @package app\api\validate
*/
class IntegralGoodsValidate extends Validate
{
protected $rule = [
'id' => 'require|number|checkGoods',
];
protected $message = [
'id.require' => '参数缺失',
'id.number' => '参数类型错误',
];
// 验证商品
protected function checkGoods($value, $rule, $data)
{
$goods = IntegralGoods::where([
'id' => $value,
'del' => IntegralGoodsEnum::DEL_NORMAL,
])->findOrEmpty();
if ($goods->isEmpty()) {
return '积分商品不存在';
}
if ($goods['status'] != IntegralGoodsEnum::STATUS_SHELVES) {
return '商品已下架';
}
return true;
}
}

View File

@ -0,0 +1,122 @@
<?php
namespace app\api\validate;
use app\common\basics\Validate;
use app\common\enum\IntegralGoodsEnum;
use app\common\enum\IntegralOrderEnum;
use app\common\enum\PayEnum;
use app\common\model\integral\IntegralOrder;
/**
* 积分订单验证
* Class IntegralOrderValidate
* @package app\api\validate
*/
class IntegralOrderValidate extends Validate
{
protected $rule = [
'id' => 'require|number|checkOrder',
];
protected $message = [
'id.require' => '参数缺失',
'id.number' => '参数类型错误',
];
public function sceneDetail()
{
return $this->only(['id']);
}
public function sceneCancel()
{
return $this->only(['id'])->append('id', 'checkCancel');
}
public function sceneConfirm()
{
return $this->only(['id'])->append('id', 'checkConfirm');
}
public function sceneTraces()
{
return $this->only(['id']);
}
public function sceneDel()
{
return $this->only(['id'])->append('id','checkDel');
}
// 验证订单
protected function checkOrder($value, $rule, $data)
{
$condition = ['id' => $value, 'user_id' => $data['user_id']];
$order = IntegralOrder::where($condition)->findOrEmpty();
if ($order->isEmpty()) {
return '订单不存在';
}
if ($order['del'] == 1) {
return '订单已删除';
}
return true;
}
protected function checkConfirm($value, $rule, $data)
{
$order = IntegralOrder::findOrEmpty($value);
if ($order['order_status'] < IntegralOrderEnum::ORDER_STATUS_DELIVERY) {
return '订单未发货';
}
if ($order['order_status'] == IntegralOrderEnum::ORDER_STATUS_COMPLETE) {
return '订单已完成';
}
return true;
}
public function checkDel($value, $rule, $data)
{
$order = IntegralOrder::findOrEmpty($value);
// 订单状态为 已关闭 且 [未支付 或者 已退款才可以删除]
if ($order['order_status'] == IntegralOrderEnum::ORDER_STATUS_DOWN) {
if ($order['pay_status'] == PayEnum::UNPAID || $order['refund_status'] == 1) {
return true;
}
}
return '订单不可删除';
}
// 取消
public function checkCancel($value, $rule, $data)
{
$order = IntegralOrder::findOrEmpty($value);
$goods_snap = $order['goods_snap'];
// 商品类型为红包的不可取消
if ($goods_snap['type'] == IntegralGoodsEnum::TYPE_BALANCE) {
return '此订单不可取消';
}
if ($order['order_status'] >= IntegralOrderEnum::ORDER_STATUS_GOODS) {
return '此订单不可取消';
}
return true;
}
}

View File

@ -0,0 +1,82 @@
<?php
namespace app\api\validate;
use app\common\basics\Validate;
use app\common\enum\IntegralGoodsEnum;
use app\common\model\integral\IntegralGoods;
use app\common\model\user\UserAddress;
/**
* 积分订单下单验证
* Class IntegralOrderValidate
* @package app\api\validate
*/
class IntegralPlaceOrderValidate extends Validate
{
protected $rule = [
'num' => 'require|number|gt:0',
'id' => 'require|number|checkGoods',
'address_id' => 'require|checkAddress',
];
protected $message = [
'id.require' => '参数缺失',
'id.number' => '参数类型错误',
'num.require' => '请选择商品数量',
'num.number' => '商品数量参数类型错误',
'num.gt' => '请选择商品数量',
'address_id.require' => '请选择地址',
];
public function sceneSettlement()
{
return $this->only(['code','num']);
}
public function sceneSubmit()
{
return $this->only(['id', 'num', 'address_id'])
->append('id', 'checkGoods');
}
// 验证商品
protected function checkGoods($value, $rule, $data)
{
$goods = IntegralGoods::where([
'id' => $value,
'del' => IntegralGoodsEnum::DEL_NORMAL,
'status' => IntegralGoodsEnum::STATUS_SHELVES
])->findOrEmpty();
if ($goods->isEmpty()) {
return '积分商品不存在';
}
if ($goods['stock'] < intval($data['num'])) {
return '积分商品库存不足';
}
return true;
}
// 验证地址信息
protected function checkAddress($value, $rule, $data)
{
$condition = [
'id' => (int)$value,
'user_id' => $data['user_id'],
'del' => 0
];
$address = UserAddress::where($condition)->findOrEmpty();
if ($address->isEmpty()) {
return '收货地址信息不存在';
}
return true;
}
}

View File

@ -0,0 +1,70 @@
<?php
// +----------------------------------------------------------------------
// | likeshop开源商城系统
// +----------------------------------------------------------------------
// | 欢迎阅读学习系统程序代码,建议反馈是我们前进的动力
// | gitee下载https://gitee.com/likeshop_gitee
// | github下载https://github.com/likeshop-github
// | 访问官网https://www.likeshop.cn
// | 访问社区https://home.likeshop.cn
// | 访问手册http://doc.likeshop.cn
// | 微信公众号likeshop技术社区
// | likeshop系列产品在gitee、github等公开渠道开源版本可免费商用未经许可不能去除前后端官方版权标识
// | likeshop系列产品收费版本务必购买商业授权购买去版权授权后方可去除前后端官方版权标识
// | 禁止对系统程序代码以任何目的,任何形式的再发布
// | likeshop团队版权所有并拥有最终解释权
// +----------------------------------------------------------------------
// | author: likeshop.cn.team
// +----------------------------------------------------------------------
namespace app\api\validate;
use app\common\basics\Validate;
use app\common\logic\SmsLogic;
/**
* Class LoginPasswordValidate
* @package app\api\validate
*/
class LoginPasswordValidate extends Validate
{
protected $regex = ['password' => '^(?=.*[a-zA-Z0-9].*)(?=.*[a-zA-Z\\W].*)(?=.*[0-9\\W].*).{6,20}$'];
protected $rule = [
'mobile' => 'require|mobile',
'password' => 'require|confirm:password|regex:password',
// 'repassword' => 'require|confirm:password',
'code' => 'require|checkCode',
];
protected $message = [
'mobile.require' => '请输入手机号',
'password.require' => '请输入密码',
'password.regex' => '密码格式错误',
// 'repassword.require' => '请再次输入密码',
// 'repassword.confirm' => '两次密码输入不一致',
'code.require' => '请输入验证码',
'mobile.mobile' => '非有效手机号码'
];
/**
* @notes 验证码
* @param $value
* @param $rule
* @param $data
* @return array|bool|string
* @author suny
* @date 2021/7/13 6:29 下午
*/
public static function checkCode($value, $rule, $data)
{
$res = SmsLogic::check($data['message_key'], $data['mobile'], $value);
if (false === $res) {
return SmsLogic::getError();
}
return true;
}
}

View File

@ -0,0 +1,94 @@
<?php
namespace app\api\validate;
use app\common\basics\Validate;
use app\common\enum\NoticeEnum;
use app\common\model\user\User;
use app\common\logic\SmsLogic;
class LoginValidate extends Validate
{
protected $rule = [
'client' => 'require|in:1,2,3,4,5,6',
'mobile' => 'require|mobile',
'password' => 'require|checkPassword',
'code' => 'require|checkCode'
];
protected $message = [
'mobile.require' => '请输入手机号',
'mobile.mobile' => '请输入正确手机号',
'password.require' => '请输入密码',
'client.require' => '请输入客户端',
'client.in' => '无效的客户端',
'code.require' => '请输入验证码'
];
protected $scene = [
'smsLogin' => ['mobile', 'code','client'], // 短信验证码登录
'mpLogin' => ['mobile', 'password', 'client'], //手机号密码登录
];
public function checkPassword($value, $rule, $data) {
if($this->safe() === false) {
return '密码输入错误次数过多';
}
$user = User::where([
'mobile' => $data['mobile'],
'del' => 0
])->findOrEmpty();
if($user->isEmpty()) { // 账号错误
$this->safe(true); // 记录错误次数
return '账号不存在';
}
if($user['disable']) {
return '账号已禁用';
}
$password = create_password($value, $user['salt']);
if($password != $user['password']) {
$this->safe(true);
return '密码错误';
}
return true;
}
/**
* 连续30分钟内15次输错密码无法登录
*/
public function safe($flag = false)
{
$cache_name = 'login_error_count_'. request()->ip();
if($flag) {
$login_error_count = cache($cache_name);
$login_error_count++;
cache($cache_name, $login_error_count, 1800); // 1800秒 = 30分钟
}
$login_error_count = cache($cache_name);
if(!empty($login_error_count) && $login_error_count >= 15) {
return false;
}
return true;
}
/***
* 验证验证码
* @param $value
* @param $rule
* @param $data
* @return bool
*/
public static function checkCode($value, $rule, $data)
{
$message_key = NoticeEnum::GET_GODE_LOGIN_NOTICE;
$res = SmsLogic::check($message_key, $data['mobile'], $value);
if (false === $res) {
return SmsLogic::getError();
}
return true;
}
}

View File

@ -0,0 +1,71 @@
<?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\api\validate;
use app\common\basics\Validate;
use app\common\model\bargain\BargainLaunch;
use app\common\model\goods\Goods;
/**
* 二维码验证器
* Class MakeMnQrcode
* @package app\api\validate
*/
class MakeMnQrcode extends Validate
{
protected $rule = [
'url' => 'require',
'type' => 'require|in:0,1,2|checkId',
];
protected $message = [
'url.require' => 'url不能为空',
'type.require' => '类型不能为空',
'type.in' => '类型错误',
];
//验证商品、活动
public function checkId($value,$rule,$data){
$type = $data['type'] ?? 0;
if(0 != $type && empty($data['id'])){
return '缺少id';
}
if(1 == $type){
$goods = Goods::where(['id'=>$data['id']])
->find();
if(empty($goods)){
return '商品不存在';
}
}
if(2 == $type){
$bargain_launch = new BargainLaunch();
$bargain_launch = $bargain_launch
->where(['id'=>$data['id']])
->find();
if(empty($bargain_launch) || $bargain_launch['launch_end_time'] <= time()){
return '该砍价已结束';
}
}
return true;
}
}

View File

@ -0,0 +1,14 @@
<?php
namespace app\api\validate;
use think\Validate;
class OaLoginValidate extends Validate
{
protected $rule = [
'code' => 'require',
];
}

View File

@ -0,0 +1,161 @@
<?php
namespace app\api\validate;
use app\common\basics\Validate;
use app\common\enum\OrderEnum;
use app\common\enum\OrderInvoiceEnum;
use app\common\model\order\Order;
use app\common\model\order\OrderInvoice;
/**
* 订单发票验证
* Class OrderInvoiceValidate
* @package app\api\validate
*/
class OrderInvoiceValidate extends Validate
{
protected $rule = [
'id' => 'require|checkInvoice', // 发票id
'shop_id' => 'require', // 门店id
'order_id' => 'require|checkOrder', // 订单id
'type' => 'require', // 发票类型
'header_type' => 'require|checkHeaderType',// 抬头类型
'name' => 'require',// 抬头名称
'email' => 'require',// 邮箱
'duty_number' => 'requireIf:header_type,' . OrderInvoiceEnum::HEADER_TYPE_COMPANY,// 税号 (企业类型必填)
'address' => 'requireIf:type,' . OrderInvoiceEnum::TYPE_SPEC,// 企业地址(专票类型必填)
'mobile' => 'requireIf:type,' . OrderInvoiceEnum::TYPE_SPEC,// 企业电话(专票类型必填)
'bank' => 'requireIf:type,' . OrderInvoiceEnum::TYPE_SPEC,// 快狐银行(专票类型必填)
'bank_account' => 'requireIf:type,' . OrderInvoiceEnum::TYPE_SPEC,// 银行账号(专票类型必填)
];
protected $message = [
'id.require' => '参数缺失',
'shop_id.require' => '参数缺失',
'order_id.require' => '订单参数缺失',
'type.require' => '请选择发票类型',
'header_type.require' => '请选择抬头类型',
'name.require' => '请填写抬头名称',
'email.require' => '请填写邮箱',
'duty_number.requireIf' => '请填写税号',
'address.requireIf' => '请填写企业地址',
'mobile.requireIf' => '请填写企业电话',
'bank.requireIf' => '请填写开户银行',
'bank_account.requireIf' => '请填写银行账号',
];
public function sceneAdd()
{
return $this->remove('id', true)
->remove('shop_id', true);
}
public function sceneEdit()
{
return $this->remove('order_id', true)
->remove('shop_id', true)
->append('id', 'checkAbleEdit');
}
public function sceneDetail()
{
return $this->only(['id']);
}
public function sceneSetting()
{
return $this->only(['shop_id']);
}
/**
* @notes 校验发票
* @param $value
* @param $rule
* @param $data
* @return bool|string
* @author 段誉
* @date 2022/4/12 12:09
*/
protected function checkInvoice($value, $rule, $data)
{
$invoice = OrderInvoice::findOrEmpty($value);
if ($invoice->isEmpty()) {
return '发票信息不存在';
}
return true;
}
/**
* @notes 校验订单是否可添加发票
* @param $value
* @param $rule
* @param $data
* @return bool|string
* @author 段誉
* @date 2022/4/12 10:01
*/
protected function checkOrder($value, $rule, $data)
{
$order = Order::with(['invoice'])->findOrEmpty($value);
if ($order->isEmpty()) {
return '订单不存在';
}
if ($order['del'] == 1 || $order['order_status'] == OrderEnum::ORDER_STATUS_DOWN) {
return '此订单已不可申请发票';
}
if (!empty($order['invoice'])) {
return '此订单已有发票信息';
}
return true;
}
/**
* @notes 校验抬头类型
* @param $value
* @param $rule
* @param $data
* @return bool|string
* @author 段誉
* @date 2022/4/11 17:17
*/
protected function checkHeaderType($value, $rule, $data)
{
if ($value == OrderInvoiceEnum::HEADER_TYPE_PERSONAL && $data['type'] == OrderInvoiceEnum::TYPE_SPEC) {
return '专用发票抬头类型仅支持企业';
}
return true;
}
/**
* @notes 校验能否编辑
* @param $value
* @param $rule
* @param $data
* @return bool|string
* @author 段誉
* @date 2022/4/12 14:56
*/
protected function checkAbleEdit($value, $rule, $data)
{
$invoice = OrderInvoice::findOrEmpty($value);
if ($invoice['status'] == OrderInvoiceEnum::STATUS_YES) {
return '此发票已开票,无法编辑';
}
return true;
}
}

View File

@ -0,0 +1,47 @@
<?php
namespace app\api\validate;
use app\common\basics\Validate;
class OrderValidate extends Validate
{
protected $rule = [
'id' => 'require',
'cart_id' => 'require',
'goods' => 'require',
'address_id' => 'require|checkParam',
];
protected $message = [
'id' => '参数错误',
'cart_id' => '参数类型错误',
'goods' => '请选择商品',
'address_id' => '请选择收货地址',
];
protected $scene = [
'add' => ['address_id'],
'detail' => ['id'],
];
/**
* @notes 参数验证
* @param $value
* @param $arr
* @param $data
* @return bool|string
* @author suny
* @date 2021/7/13 6:29 下午
*/
public function checkParam($value, $arr, $data)
{
if (!isset($data['goods']) && !isset($data['cart_id'])) {
return '参数有误';
}
return true;
}
}

View File

@ -0,0 +1,63 @@
<?php
namespace app\api\validate;
use app\common\basics\Validate;
use app\common\enum\OrderInvoiceEnum;
/**
* 下单时订单发票验证
* Class OrderInvoiceValidate
* @package app\api\validate
*/
class PlaceOrderInvoiceValidate extends Validate
{
protected $rule = [
'type' => 'require', // 发票类型
'header_type' => 'require|checkHeaderType',// 抬头类型
'name' => 'require',// 抬头名称
'email' => 'require',// 邮箱
'duty_number' => 'requireIf:header_type,'. OrderInvoiceEnum::HEADER_TYPE_COMPANY,// 税号 (企业类型必填)
'address' => 'requireIf:type,'. OrderInvoiceEnum::TYPE_SPEC,// 企业地址(专票类型必填)
'mobile' => 'requireIf:type,'. OrderInvoiceEnum::TYPE_SPEC,// 企业电话(专票类型必填)
'bank' => 'requireIf:type,'. OrderInvoiceEnum::TYPE_SPEC,// 快狐银行(专票类型必填)
'bank_account' => 'requireIf:type,'. OrderInvoiceEnum::TYPE_SPEC,// 银行账号(专票类型必填)
];
protected $message = [
'type.require' => '请选择发票类型',
'header_type.require' => '请选择抬头类型',
'name.require' => '请填写抬头名称',
'email.require' => '请填写邮箱',
'duty_number.requireIf' => '请填写税号',
'address.requireIf' => '请填写企业地址',
'mobile.requireIf' => '请填写企业电话',
'bank.requireIf' => '请填写开户银行',
'bank_account.requireIf' => '请填写银行账号',
];
/**
* @notes 校验
* @param $value
* @param $rule
* @param $data
* @return bool|string
* @author 段誉
* @date 2022/4/11 17:17
*/
protected function checkHeaderType($value, $rule, $data)
{
if ($value == OrderInvoiceEnum::HEADER_TYPE_PERSONAL && $data['type'] == OrderInvoiceEnum::TYPE_SPEC) {
return '专用发票抬头类型仅支持企业';
}
return true;
}
}

View File

@ -0,0 +1,42 @@
<?php
namespace app\api\validate;
use think\Validate;
use app\common\server\ConfigServer;
use app\common\model\RechargeTemplate;
class RechargeValidate extends Validate
{
protected $rule = [
'id' => 'checkRecharge', // 充值模板id
'money' => 'checkRecharge',
];
protected $message = [
];
protected function checkRecharge($value,$rule,$data){
$open_racharge = ConfigServer::get('recharge','open_racharge',0);
if(!$open_racharge){
return '充值功能已关闭,无法充值';
}
if(empty($value) && $data['money']){
return '请输入充值金额';
}
if(isset($data['id'])){
$remplate = RechargeTemplate::where(['id'=>$value,'del'=>0])->findOrEmpty();
if($remplate->isEmpty()){
return '该充值模板不存在';
}
}else{
$min_money = ConfigServer::get('recharge', 'min_money',0);
if($data['money'] < $min_money){
return '最低充值金额为'.$min_money;
}
}
return true;
}
}

View File

@ -0,0 +1,53 @@
<?php
namespace app\api\validate;
use think\Validate;
use app\common\model\user\User;
use app\common\logic\SmsLogic;
class RegisterValidate extends Validate
{
protected $regex = ['password' => '^(?=.*[a-zA-Z0-9].*)(?=.*[a-zA-Z\\W].*)(?=.*[0-9\\W].*).{6,20}$'];
protected $rule = [
'mobile' => 'require|mobile|checkMobile',
'password' => 'require|regex:password',
'code' => 'requireIf:check_code,1|checkCode',
'client' => 'require|in:1,2,3,4,5,6'
];
protected $message = [
'mobile.require' => '请输入手机号',
'mobile.mobile' => '无效的手机号码',
'password.require' => '请输入密码',
'password.regex' => '密码格式错误',
'code.requireIf' => '请输入验证码',
'client.require' => '请输入客户端',
'client.in' => '无效的客户端',
];
public function checkCode($value, $rule, $data)
{
$res = SmsLogic::check($data['message_key'], $data['mobile'], $value);
if (false === $res) {
return SmsLogic::getError();
}
return true;
}
public function checkMobile($value, $data, $rule)
{
$where = [
'del' => 0,
'mobile' => $value
];
//检查手机号是否已存在
$user = User::where($where)->findOrEmpty();
if (!$user->isEmpty()) {
return '此手机号已被使用';
}
return true;
}
}

View File

@ -0,0 +1,19 @@
<?php
namespace app\api\validate;
use think\Validate;
class SetWechatUserValidate extends Validate
{
protected $rule = [
'nickname' => 'require',
'avatar' => 'require',
'sex' => 'require',
];
protected $message = [
'nickname.require' => '参数缺失',
'avatar.require' => '参数缺失',
'sex.require' => '参数缺失',
];
}

View File

@ -0,0 +1,57 @@
<?php
namespace app\api\validate;
use app\common\basics\Validate;
use app\common\enum\NoticeEnum;
use app\common\logic\SmsLogic;
class ShopApplyValidate extends Validate
{
protected $rule = [
'cid' => 'require|number',
'name' => 'require|chsAlphaNum',
'nickname' => 'require|chsAlphaNum',
'mobile' => 'require|mobile',
'account' => 'require|unique:shop_apply,name&del|alphaNum|min:2|max:20',
'password' => 'require|alphaDash|min:6|max:32',
'license' => 'require|array',
'code' => 'require|checkCode'
];
protected $message = [
'cid.require' => '请选择主营类目',
'cid.number' => 'cid参数必须为数字',
'name.require' => '请填写商家名称',
'nickname.require' => '请填写联系人姓名',
'mobile.require' => '请填写手机号码',
'mobile.mobile' => '请填写正确的手机号',
'account.require' => '请现在创建的账号',
'account.unique' => '该账号已存在',
'account.alphaNum' => '账号必须由数字或字母组成',
'account.min' => '账号长度不能少于2个字符',
'account.max' => '账号长度不能超过20个字符',
'password.require' => '请填写登录密码',
'license.require' => '请上传营业执照',
'license.array' => 'license参数需数组格式',
'code.require' => '请输入验证码'
];
protected $scene = [
'apply' => ['cid', 'name', 'nickname', 'mobile', 'account', 'password', 'license', 'code']
];
//验证手机验证码
protected function checkCode($value, $rule, $data)
{
$message_key = NoticeEnum::SHOP_APPLY_CHECK_CODE;
$res = SmsLogic::check($message_key, $data['mobile'], $value);
if (false === $res) {
return SmsLogic::getError();
}
return true;
}
}

View File

@ -0,0 +1,31 @@
<?php
namespace app\api\validate;
use app\common\basics\Validate;
use app\common\model\sign_daily\UserSign;
/**
* 签到验证
* Class Sign
* @package app\api\validate
*/
class SignValidate extends Validate
{
protected $rule = [
'user_id' => 'checkSign',
];
public function checkSign($value, $data, $rule)
{
$today = UserSign::where(['del' => 0, 'user_id' => $value])
->whereTime('sign_time', 'today')
->findOrEmpty();
if (!$today->isEmpty()) {
return '您今天已签到过了';
}
return true;
}
}

View File

@ -0,0 +1,82 @@
<?php
namespace app\api\validate;
use app\api\logic\LoginLogic;
use app\common\basics\Validate;
use app\common\enum\NoticeEnum;
use app\common\model\Client_;
use app\common\model\shop\Shop;
use app\common\model\SmsLog;
use app\common\model\user\User;
use app\common\server\sms\Driver;
use think\facade\Db;
class SmsSend extends Validate
{
protected $rule = [
'mobile' => 'require|mobile|checkSms',
'key' => 'checkMobile',
];
protected $message = [
'mobile.require' => '请输入手机号码',
'mobile.mobile' => '请输入正确的手机号码',
];
//限制验证码发送频率
protected function checkSms($value, $rule, $data)
{
$message_key = NoticeEnum::SMS_SCENE[$data['key']];
$send_time = SmsLog::where(['message_key' => $message_key, 'mobile' => $value, 'is_verify' => 0])
->order('id desc')
->value('send_time');
//一分钟内不能频繁发送
if ($send_time && $send_time + 60 > time()) {
return '验证码发送频繁,请稍后在发送';
}
return true;
}
//验证手机号
function checkMobile($value, $rule, $data)
{
if($data['client'] == Client_::pc && $data['key'] == 'BGSJHM'){
$data['new_mobile'] = $data['mobile'];
$mobile = Db::name('user')->where(['id' => $data['user_id']])->value('mobile');
$data['mobile'] = $mobile;
}
$user = User::where(['mobile' => $data['mobile'], 'del' => 0])->findOrEmpty();
switch ($value) {
case 'ZCYZ': //注册验证
case 'BDSJHM': //绑定手机号码
if (!$user->isEmpty()) {
return '该手机号码已存在';
}
break;
case 'YZMDL': //验证码登录
if ($user->isEmpty()) { //账号不存在, 给他注册
$post = request()->post();
$post['password'] = '';
LoginLogic::register($post);
}
break;
case 'ZHMM': //找回密码
case 'BGSJHM': //变更手机号码
case 'ZHZFMM': // 找回支付密码
if ($user->isEmpty()) {
return '手机号码不存在';
}
break;
case 'SJSQYZ': //商家入驻
$shop = Shop::where(['mobile' => $data['mobile'], 'del' => 0])->findOrEmpty();
if(!$shop->isEmpty()) {
return '该手机号码已存在!';
}
break;
default:
return '场景错误';
}
return true;
}
}

View File

@ -0,0 +1,62 @@
<?php
namespace app\api\validate;
use app\common\basics\Validate;
use app\common\model\goods\Goods;
use app\common\model\shop\Shop;
class TeamValidate extends Validate
{
protected $rule = [
'team_id' => 'require|number',
'goods_id' => 'require|number|checkShop',
'item_id' => 'require|number',
'count' => 'require|number',
];
protected $message = [
'team_id.require' => '缺少team_id',
'team_id.number' => 'team_id需为数字',
'goods_id.require' => '缺少goods_id',
'goods_id.number' => 'goods_id需为数字',
'item_id.require' => '缺少item_id',
'item_id.number' => 'item_id需为数字',
'count.require' => '缺少count',
'count.number' => 'count需为数字',
];
protected $scene = [
'check' => ['goods_id', 'item_id', 'count']
];
/**
* @notes 检查商品所属店铺的营业状态
* @param $goods_id
* @return bool|string
* @author Tab
* @date 2021/7/19 14:08
*/
public function checkShop($goods_id)
{
$shop_id = Goods::where('id', $goods_id)->value('shop_id');
$shop = Shop::field('expire_time,is_run,is_freeze')->where(['del' => 0, 'id' => $shop_id])->findOrEmpty();
if($shop->isEmpty()) {
return '该商品所属店铺不存在';
}
// 获取原始数据(不经获取器)
$shop = $shop->getData();
if(!empty($shop['expire_time']) && ($shop['expire_time'] <= time())) {
return '该商品所属店铺已到期';
}
if($shop['is_freeze']) {
return '该商品所属店铺已被冻结';
}
if(!$shop['is_run']) {
return '该商品所属店铺暂停营业中';
}
return true;
}
}

View File

@ -0,0 +1,83 @@
<?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\api\validate;
use think\Validate;
use app\common\model\Session as SessionModel;
use app\common\model\user\User;
class TokenValidate extends Validate
{
protected $rule = [
'token' => 'require|valid|user',
];
/**
* User: 意象信息科技 lr
* Desc: token验证
* @param $token
* @param $other
* @param $data
* @return bool|string
* @throws \think\db\exception\DataNotFoundException
* @throws \think\db\exception\ModelNotFoundException
* @throws \think\exception\DbException
*/
protected function valid($token, $other, $data)
{
$session = SessionModel::where(['token' => $token])->find();
if (empty($session)) {
return '会话失效,请重新登录';
}
if ($session['expire_time'] <= time()) {
return '登录超时,请重新登录';
}
return true;
}
/**
* User: 意象信息科技 lr
* Desc 用户验证
* @param $token
* @param $other
* @param $data
* @return string
* @throws \think\db\exception\DataNotFoundException
* @throws \think\db\exception\ModelNotFoundException
* @throws \think\exception\DbException
*/
protected function user($token, $other, $data)
{
$user_id = SessionModel::where(['token' => $token])
->value('user_id');
$user_info = User::where(['id' => $user_id, 'del' => 0])
->find();
if (empty($user_info)) {
return '用户不存在';
}
if ($user_info['disable'] == 1) {
return '用户被禁用';
}
return true;
}
}

View File

@ -0,0 +1,32 @@
<?php
namespace app\api\validate;
use think\Validate;
class UpdateUserValidate extends Validate
{
protected $rule = [
'field' => 'require|checkField',
'value' => 'require',
];
protected $message = [
'field.require' => '请填写要修改的字段',
'value.require' => '请填写要修改的值',
];
public function sceneSet()
{
$this->only(['field', 'value']);
}
protected function checkField($value, $rule, $data)
{
$allow_field = ['nickname', 'sex', 'avatar'];
if (in_array($value, $allow_field)) {
return true;
}
return '非法字段';
}
}

View File

@ -0,0 +1,56 @@
<?php
namespace app\api\validate;
use app\common\basics\Validate;
class UserAddressValidate extends Validate
{
protected $rule = [
'id' => 'require|integer',
'contact' => 'require',
'telephone' => [ 'require', 'checkMobile' => [ 'check' => [ 'land', 'hk' ] ] ],
'province_id' => 'require',
'city_id' => 'require',
'district_id' => 'require',
'address' => 'require',
'is_default' => 'require',
];
protected $message = [
'id.require' => 'id不能为空',
'id.integer' => 'id参数错误',
'contact.require' => '收货人不能为空',
'telephone.require' => '联系方式不能为空',
'telephone.mobile' => '非有效手机号',
'province_id.require' => '所选地区不能为空',
'city_id.require' => '请选择完整地址',
'district_id.require' => '请选择完整地址',
'address.require' => '详细地址不能为空',
'is_default.require' => '是否默认不能为空',
'province.require' => '省不能为空',
'city.require' => '市不能为空',
'district.require' => '区不能为空',
];
protected $scene = [
'add' => ['contact','telephone','province_id','city_id','district_id','is_default','address'],
'set'=>['id'],
'one'=>['id'],
'edit'=>['id','contact','telephone','province_id','city_id','district_id','is_default'],
'del'=>['id'],
];
/**
* 获取省市区id
*/
public function sceneHandleRegion()
{
return $this->only(['province','city','district'])
->append('province','require')
->append('city','require')
->append('district','require');
}
}

View File

@ -0,0 +1,37 @@
<?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\api\validate;
use app\common\basics\Validate;
class WechatLoginValidate extends Validate
{
protected $rule = [
'code' => 'require',
];
protected $message = [
'code.require' => 'code缺少',
];
public function sceneWechatAuth()
{
return $this->only(['code']);
}
}

View File

@ -0,0 +1,13 @@
<?php
namespace app\api\validate;
use think\Validate;
class WechatMobileValidate extends Validate
{
protected $rule = [
'code' => 'require',
'encrypted_data' => 'require',
'iv' => 'require',
];
}

View File

@ -0,0 +1,93 @@
<?php
namespace app\api\validate;
use app\common\basics\Validate;
use app\common\server\ConfigServer;
use app\common\model\user\User;
/**
* Class WithdrawValidate
* @package app\api\validate
*/
class WithdrawValidate extends Validate
{
protected $rule = [
'id' => 'require', //参数缺失
'type' => 'require|in:1,2,3,4,5',//提现类型
'money' => 'require|checkMoney',//提现佣金
'account' => 'requireIf:type,3|requireIf:type,4|requireIf:type,5',//账户类型
'real_name' => 'requireIf:type,3|requireIf:type,4|requireIf:type,5|chs',//真实姓名
'money_qr_code' => 'requireIf:type,3|requireIf:type,4',//收款码
'bank' => 'requireIf:type,5', // 提现银行
'subbank' => 'requireIf:type,5', // 银行支行
];
protected $message = [
'id.require' => '参数缺失',
'type.require' => '参数错误',
'type.in' => '提现类型错误',
'money.require' => '参数错误',
'account.requireIf' => '请填写账号',
'real_name.requireIf' => '请填写真实姓名',
'real_name.chs' => '请填写真实姓名',
'money_qr_code.requireIf' => '请上传收款码',
'bank.requireIf' => '请填写提现银行',
'subbank.requireIf' => '请填写银行支行',
];
/**
* @notes 申请提现
* @return WithdrawValidate
* @author suny
* @date 2021/7/13 6:30 下午
*/
public function sceneApply()
{
return $this->only(['type', 'money', 'account', 'real_name', 'money_qr_code', 'bank', 'subbank']);
}
/**
* @notes 申请详情
* @return WithdrawValidate
* @author suny
* @date 2021/7/13 6:30 下午
*/
public function sceneInfo()
{
return $this->only(['id']);
}
/**
* @notes 提现佣金验证
* @param $value
* @param $rule
* @param array $data
* @return bool|string
* @author suny
* @date 2021/7/13 6:30 下午
*/
protected function checkMoney($value, $rule, $data = [])
{
$able_withdraw = User::where('id', $data['user_id'])->value('earnings');
if ($value > $able_withdraw) {
return '可提现金额不足';
}
//1.最低提现金额
$min_withdraw = ConfigServer::get('withdraw', 'min_withdraw', 0);
if ($value < $min_withdraw) {
return '最低提现' . $min_withdraw . '元';
}
//2,最高提现金额
$max_withdraw = ConfigServer::get('withdraw', 'max_withdraw', 0);
if ($value > $max_withdraw) {
return '最高提现' . $max_withdraw . '元';
}
return true;
}
}