| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100 |
- <?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\openapi\validate;
- use app\common\model\UserLevel;
- use app\shopapi\validate\DistributionValidate;
- /**
- * 用户等级验证器
- * Class UserValidate
- * @package app\openapi\validate
- */
- class UserLevelValidate extends BaseOpenValidate
- {
- protected $rule = [
- 'name' => 'require|checkName',
- 'discount'=>'require|float|egt:0',
- 'rank'=>'require|integer|egt:0',
- 'offline_user_level_id'=>'require',
- 'remark'=>'requireif:remark,""',
- 'condition'=>'requireif:condition,""',
- ];
-
- protected $message = [
- 'name.require' => '等级名称不能为空',
- // 'name.max' => '等级名称不能超过50个字符',
- 'discount.require' => '等级折扣必传',
- 'rank.require' => '等级权重必传',
- 'rank.egt' => '等级权重大于等于0',
- 'discount.egt' => '等级折扣大于等于0',
- 'offline_user_level_id.require' => '线下会员等级id必传',
- ];
-
- protected $scene = [
- 'getUserLevelLists' => ['level_name'],
- 'addUserLevel' => ['offline_user_level_id','name','discount','rank','remark','condition'],
- 'updateUserLevelInfo' => ['offline_user_level_id','name','discount','rank','remark','condition'],
- 'delUserLevel' => ['name']
- ];
- /**
- * @notes 检查等级名称是否存在
- * @param $value
- * @param $rule
- * @param $data
- * @return bool|string
- * @author ljj
- * @date 2021/8/10 2:00 下午
- */
- public function checkName($value,$rule,$data)
- {
- if($value == 0) return true;
- $user_level = UserLevel::where('name', $value)->findOrEmpty();
- if ($user_level->isEmpty()) {
- return true;
- }else{
- return '已存在该会员等级名称';
- }
- }
- /**
- * @notes
- * @return DistributionValidate
- * @author Tab
- * @date 2021/7/17 10:18
- */
- public function sceneUpdateUserLevelInfo()
- {
- return $this->remove('name', 'checkName');
- }
- /**
- * @notes
- * @return DistributionValidate
- * @author Tab
- * @date 2021/7/17 10:18
- */
- public function sceneDelUserLevel()
- {
- return $this->remove('name', 'checkName')->remove('discount', 'require')
- ->remove('rank', 'require')->remove('offline_user_level_id', 'require');
- }
- }
|