其余文件
This commit is contained in:
151
app/admin/validate/distribution/DistributionLevelValidate.php
Normal file
151
app/admin/validate/distribution/DistributionLevelValidate.php
Normal file
@ -0,0 +1,151 @@
|
||||
<?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\admin\validate\distribution;
|
||||
|
||||
use app\common\basics\Validate;
|
||||
use app\common\model\distribution\DistributionLevel;
|
||||
|
||||
class DistributionLevelValidate extends Validate
|
||||
{
|
||||
protected $rule = [
|
||||
'name' => 'require|checkName',
|
||||
'weights' => 'require|integer|gt:1|checkWeights',
|
||||
'first_ratio' => 'require|between:0,100',
|
||||
'second_ratio' => 'require|between:0,100',
|
||||
'update_relation' => 'require|in:1,2',
|
||||
'update_condition' => 'require|array|checkCondition',
|
||||
'singleConsumptionAmount' => 'gt:0',
|
||||
'cumulativeConsumptionAmount' => 'gt:0',
|
||||
'cumulativeConsumptionTimes' => 'integer|gt:0',
|
||||
'returnedCommission' => 'gt:0',
|
||||
'id' => 'require'
|
||||
];
|
||||
|
||||
|
||||
protected $message = [
|
||||
'name.require' => '请填写等级名称',
|
||||
'weights.require' => '请输入级别',
|
||||
'weights.integer' => '级别须为整型',
|
||||
'weights.gt' => '级别须大于1',
|
||||
'first_ratio.require' => '请输入一级佣金比例',
|
||||
'first_ratio.between' => '一级佣金比例须在0-100之间',
|
||||
'second_ratio.require' => '请输入二级佣金比例',
|
||||
'second_ratio.between' => '二级佣金比例须在0-100之间',
|
||||
'update_relation.require' => '请选择升级关系',
|
||||
'update_relation.in' => '升级关系状态值错误',
|
||||
'update_condition.require' => '请选择升级条件',
|
||||
'update_condition.array' => '升级条件数据格式错误',
|
||||
'singleConsumptionAmount.gt' => '单笔消费金额须大于0',
|
||||
'cumulativeConsumptionAmount.gt' => '累计消费金额须大于0',
|
||||
'cumulativeConsumptionTimes.gt' => '累计消费次数须大于0',
|
||||
'cumulativeConsumptionTimes.integer' => '累计消费次数须为整数',
|
||||
'returnedCommission.gt' => '已结算佣金收入须大于0',
|
||||
'id.require' => '参数缺失',
|
||||
];
|
||||
|
||||
/**
|
||||
* @notes 添加分销等级
|
||||
* @return DistributionLevelValidate
|
||||
* @author Tab
|
||||
* @date 2021/9/1 14:45
|
||||
*/
|
||||
public function sceneAdd()
|
||||
{
|
||||
return $this->only(['name', 'weights', 'self_ratio', 'first_ratio', 'second_ratio', 'update_condition', 'update_relation', 'singleConsumptionAmount', 'cumulativeConsumptionAmount', 'cumulativeConsumptionTimes', 'returnedCommission']);
|
||||
}
|
||||
|
||||
/**
|
||||
* @notes 编辑分销等级
|
||||
* @return DistributionLevelValidate
|
||||
* @author Tab
|
||||
* @date 2021/9/1 15:49
|
||||
*/
|
||||
public function sceneEdit()
|
||||
{
|
||||
return $this->only(['id', 'name', 'weights', 'first_ratio', 'second_ratio'])
|
||||
->remove('weights', 'gt');
|
||||
}
|
||||
|
||||
/**
|
||||
* @notes 校验等级名称
|
||||
* @param $value
|
||||
* @param $rule
|
||||
* @param $data
|
||||
* @return bool|string
|
||||
* @author Tab
|
||||
* @date 2021/9/1 14:42
|
||||
*/
|
||||
public function checkName($value, $rule, $data)
|
||||
{
|
||||
$where = [['name', '=', $value]];
|
||||
if(isset($data['id'])) {
|
||||
// 编辑的场景
|
||||
$where[] = ['id', '<>', $data['id']];
|
||||
}
|
||||
$level = DistributionLevel::where($where)->findOrEmpty();
|
||||
if(!$level->isEmpty()) {
|
||||
return '等级名称已存在';
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* @notes 校验等级级别
|
||||
* @param $value
|
||||
* @param $rule
|
||||
* @param $data
|
||||
* @return bool|string
|
||||
* @author Tab
|
||||
* @date 2021/9/1 14:42
|
||||
*/
|
||||
public function checkWeights($value, $rule, $data)
|
||||
{
|
||||
$where = [['weights', '=', $value]];
|
||||
if(isset($data['id'])) {
|
||||
// 编辑的场景
|
||||
$where[] = ['id', '<>', $data['id']];
|
||||
}
|
||||
$level = DistributionLevel::where($where)->findOrEmpty();
|
||||
if(!$level->isEmpty()) {
|
||||
return '等级级别已存在';
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* @notes 校验升级条件
|
||||
* @param $value
|
||||
* @return bool|string
|
||||
* @author Tab
|
||||
* @date 2021/9/1 14:43
|
||||
*/
|
||||
public function checkCondition($value, $rule, $data)
|
||||
{
|
||||
if(!count($value)) {
|
||||
return '请选择升级条件';
|
||||
}
|
||||
foreach($value as $v) {
|
||||
if(!isset($data[$v]) || empty($data[$v])) {
|
||||
return '升级条件数据未填写';
|
||||
}
|
||||
}
|
||||
return true;
|
||||
}
|
||||
}
|
||||
101
app/admin/validate/distribution/MemberValidate.php
Normal file
101
app/admin/validate/distribution/MemberValidate.php
Normal 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\admin\validate\distribution;
|
||||
|
||||
use think\Validate;
|
||||
use app\common\model\user\User;
|
||||
|
||||
class MemberValidate extends Validate
|
||||
{
|
||||
protected $rule = [
|
||||
// 添加分销会员
|
||||
'sn' => 'require|max:10',
|
||||
'remarks' => 'max:100',
|
||||
// 更新上级
|
||||
'user_id' => 'require',
|
||||
'change_type' => 'require',
|
||||
'referrer_sn' => 'requireIf:change_type,appoint|checkReferrer',
|
||||
// 冻结、解冻资格/ 审核分销会员
|
||||
'id' => 'require',
|
||||
'type' => 'require',
|
||||
];
|
||||
|
||||
|
||||
protected $message = [
|
||||
'sn.require' => '请输入会员编号',
|
||||
'sn.max' => '会员编号不能超过10个字符',
|
||||
'remarks.max' => '备注不能超过100个字符',
|
||||
'user_id.require' => '会员id不能为空',
|
||||
'change_type.require' => '调整方式不能为空',
|
||||
'referrer_sn.requireIf' => '指定上级不能为空',
|
||||
'id.require' => '请输入会员id',
|
||||
'type.require' => '请输入类型',
|
||||
];
|
||||
|
||||
public function sceneAdd()
|
||||
{
|
||||
return $this->only(['sn', 'remarks']);
|
||||
}
|
||||
|
||||
public function sceneUpdateLeader()
|
||||
{
|
||||
return $this->only(['user_id', 'change_type', 'referrer_sn']);
|
||||
}
|
||||
|
||||
public function sceneFreeze()
|
||||
{
|
||||
return $this->only(['id', 'type']);
|
||||
}
|
||||
|
||||
public function sceneAudit()
|
||||
{
|
||||
return $this->only(['id', 'type']);
|
||||
}
|
||||
|
||||
public function checkReferrer($value, $rule, $data)
|
||||
{
|
||||
if (empty($value) && $data['change_type'] == 'clear'){
|
||||
return true;
|
||||
}
|
||||
|
||||
$referrer = User::where('sn', $value)->findOrEmpty();
|
||||
|
||||
if ($referrer->isEmpty()){
|
||||
return '推荐人不存在';
|
||||
}
|
||||
|
||||
$referrer = $referrer->toArray();
|
||||
|
||||
if ($referrer['id'] == $data['user_id']){
|
||||
return '上级推荐人不能是自己';
|
||||
}
|
||||
|
||||
if ($referrer['is_distribution'] == 0){
|
||||
return '对方不是分销会员';
|
||||
}
|
||||
|
||||
$ancestor_relation = explode(',', $referrer['ancestor_relation']);
|
||||
if (!empty($ancestor_relation) && in_array($data['user_id'], $ancestor_relation)) {
|
||||
return '推荐人不能是自己的任意下级';
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user