初始化仓库
This commit is contained in:
66
app/adminapi/validate/user/AdjustUserMoney.php
Normal file
66
app/adminapi/validate/user/AdjustUserMoney.php
Normal file
@ -0,0 +1,66 @@
|
||||
<?php
|
||||
// +----------------------------------------------------------------------
|
||||
// | likeadmin快速开发前后端分离管理后台(PHP版)
|
||||
// +----------------------------------------------------------------------
|
||||
// | 欢迎阅读学习系统程序代码,建议反馈是我们前进的动力
|
||||
// | 开源版本可自由商用,可去除界面版权logo
|
||||
// | gitee下载:https://gitee.com/likeshop_gitee/likeadmin
|
||||
// | github下载:https://github.com/likeshop-github/likeadmin
|
||||
// | 访问官网:https://www.likeadmin.cn
|
||||
// | likeadmin团队 版权所有 拥有最终解释权
|
||||
// +----------------------------------------------------------------------
|
||||
// | author: likeadminTeam
|
||||
// +----------------------------------------------------------------------
|
||||
|
||||
namespace app\adminapi\validate\user;
|
||||
|
||||
use app\common\enum\user\AccountLogEnum;
|
||||
use app\common\model\user\User;
|
||||
use app\common\validate\BaseValidate;
|
||||
|
||||
/**
|
||||
* 调整用户钱包验证器
|
||||
* Class AdjustUserMoney
|
||||
* @package app\adminapi\validate\user
|
||||
*/
|
||||
class AdjustUserMoney extends BaseValidate
|
||||
{
|
||||
|
||||
protected $rule = [
|
||||
'user_id' => 'require',
|
||||
'action' => 'require|in:' . AccountLogEnum::INC . ',' .AccountLogEnum::DEC,
|
||||
'num' => 'require|gt:0|checkMoney',
|
||||
'remark' => 'max:128',
|
||||
];
|
||||
|
||||
protected $message = [
|
||||
'id.require' => '请选择用户',
|
||||
'action.require' => '请选择调整类型',
|
||||
'action.in' => '调整类型错误',
|
||||
'num.require' => '请输入调整数量',
|
||||
'num.gt' => '调整余额必须大于零',
|
||||
'remark' => '备注不可超过128个符号',
|
||||
];
|
||||
|
||||
|
||||
protected function checkMoney($vaule, $rule, $data)
|
||||
{
|
||||
$user = User::find($data['user_id']);
|
||||
if (empty($user)) {
|
||||
return '用户不存在';
|
||||
}
|
||||
|
||||
if (1 == $data['action']) {
|
||||
return true;
|
||||
}
|
||||
|
||||
$surplusMoeny = $user->user_money - $vaule;
|
||||
if ($surplusMoeny < 0) {
|
||||
return '用户可用余额仅剩' . $user->user_money;
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
128
app/adminapi/validate/user/UserValidate.php
Normal file
128
app/adminapi/validate/user/UserValidate.php
Normal file
@ -0,0 +1,128 @@
|
||||
<?php
|
||||
// +----------------------------------------------------------------------
|
||||
// | likeadmin快速开发前后端分离管理后台(PHP版)
|
||||
// +----------------------------------------------------------------------
|
||||
// | 欢迎阅读学习系统程序代码,建议反馈是我们前进的动力
|
||||
// | 开源版本可自由商用,可去除界面版权logo
|
||||
// | gitee下载:https://gitee.com/likeshop_gitee/likeadmin
|
||||
// | github下载:https://github.com/likeshop-github/likeadmin
|
||||
// | 访问官网:https://www.likeadmin.cn
|
||||
// | likeadmin团队 版权所有 拥有最终解释权
|
||||
// +----------------------------------------------------------------------
|
||||
// | author: likeadminTeam
|
||||
// +----------------------------------------------------------------------
|
||||
namespace app\adminapi\validate\user;
|
||||
|
||||
|
||||
use app\common\model\user\User;
|
||||
use app\common\validate\BaseValidate;
|
||||
|
||||
/**
|
||||
* 用户验证
|
||||
* Class UserValidate
|
||||
* @package app\adminapi\validate\user
|
||||
*/
|
||||
class UserValidate extends BaseValidate
|
||||
{
|
||||
|
||||
protected $rule = [
|
||||
'id' => 'require|checkUser',
|
||||
'field' => 'require|checkField',
|
||||
'value' => 'require',
|
||||
];
|
||||
|
||||
protected $message = [
|
||||
'id.require' => '请选择用户',
|
||||
'field.require' => '请选择操作',
|
||||
'value.require' => '请输入内容',
|
||||
];
|
||||
|
||||
|
||||
/**
|
||||
* @notes 详情场景
|
||||
* @return UserValidate
|
||||
* @author 段誉
|
||||
* @date 2022/9/22 16:35
|
||||
*/
|
||||
public function sceneDetail()
|
||||
{
|
||||
return $this->only(['id']);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @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 段誉
|
||||
* @date 2022/9/22 17:03
|
||||
*/
|
||||
public function checkUser($value, $rule, $data)
|
||||
{
|
||||
$userIds = is_array($value) ? $value : [$value];
|
||||
|
||||
foreach ($userIds as $item) {
|
||||
if (!User::find($item)) {
|
||||
return '用户不存在!';
|
||||
}
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @notes 校验是否可更新信息
|
||||
* @param $value
|
||||
* @param $rule
|
||||
* @param $data
|
||||
* @return bool|string
|
||||
* @author 段誉
|
||||
* @date 2022/9/22 16:37
|
||||
*/
|
||||
public function checkField($value, $rule, $data)
|
||||
{
|
||||
$allowField = ['account', 'sex', 'mobile', 'real_name'];
|
||||
|
||||
if (!in_array($value, $allowField)) {
|
||||
return '用户信息不允许更新';
|
||||
}
|
||||
|
||||
switch ($value) {
|
||||
case 'account':
|
||||
//验证手机号码是否存在
|
||||
$account = User::where([
|
||||
['id', '<>', $data['id']],
|
||||
['account', '=', $data['value']]
|
||||
])->findOrEmpty();
|
||||
|
||||
if (!$account->isEmpty()) {
|
||||
return '账号已被使用';
|
||||
}
|
||||
break;
|
||||
|
||||
case 'mobile':
|
||||
if (false == $this->validate($data['value'], 'mobile', $data)) {
|
||||
return '手机号码格式错误';
|
||||
}
|
||||
|
||||
//验证手机号码是否存在
|
||||
$mobile = User::where([
|
||||
['id', '<>', $data['id']],
|
||||
['mobile', '=', $data['value']]
|
||||
])->findOrEmpty();
|
||||
|
||||
if (!$mobile->isEmpty()) {
|
||||
return '手机号码已存在';
|
||||
}
|
||||
break;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user