123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151 |
- <?php
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
- 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' => '参数缺失',
- ];
-
-
-
- public function sceneAdd()
- {
- return $this->only(['name', 'weights', 'self_ratio', 'first_ratio', 'second_ratio', 'update_condition', 'update_relation', 'singleConsumptionAmount', 'cumulativeConsumptionAmount', 'cumulativeConsumptionTimes', 'returnedCommission']);
- }
-
-
-
- public function sceneEdit()
- {
- return $this->only(['id', 'name', 'weights', 'first_ratio', 'second_ratio'])
- ->remove('weights', 'gt');
- }
-
-
-
- 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;
- }
-
-
-
- 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;
- }
-
-
-
- public function checkCondition($value, $rule, $data)
- {
- if(!count($value)) {
- return '请选择升级条件';
- }
- foreach($value as $v) {
- if(!isset($data[$v]) || empty($data[$v])) {
- return '升级条件数据未填写';
- }
- }
- return true;
- }
- }
|