UserLevelValidate.php 3.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100
  1. <?php
  2. // +----------------------------------------------------------------------
  3. // | likeshop100%开源免费商用商城系统
  4. // +----------------------------------------------------------------------
  5. // | 欢迎阅读学习系统程序代码,建议反馈是我们前进的动力
  6. // | 开源版本可自由商用,可去除界面版权logo
  7. // | 商业版本务必购买商业授权,以免引起法律纠纷
  8. // | 禁止对系统程序代码以任何目的,任何形式的再发布
  9. // | gitee下载:https://gitee.com/likeshop_gitee
  10. // | github下载:https://github.com/likeshop-github
  11. // | 访问官网:https://www.likeshop.cn
  12. // | 访问社区:https://home.likeshop.cn
  13. // | 访问手册:http://doc.likeshop.cn
  14. // | 微信公众号:likeshop技术社区
  15. // | likeshop团队 版权所有 拥有最终解释权
  16. // +----------------------------------------------------------------------
  17. // | author: likeshopTeam
  18. // +----------------------------------------------------------------------
  19. namespace app\openapi\validate;
  20. use app\common\model\UserLevel;
  21. use app\shopapi\validate\DistributionValidate;
  22. /**
  23. * 用户等级验证器
  24. * Class UserValidate
  25. * @package app\openapi\validate
  26. */
  27. class UserLevelValidate extends BaseOpenValidate
  28. {
  29. protected $rule = [
  30. 'name' => 'require|checkName',
  31. 'discount'=>'require|float|egt:0',
  32. 'rank'=>'require|integer|egt:0',
  33. 'offline_user_level_id'=>'require',
  34. 'remark'=>'requireif:remark,""',
  35. 'condition'=>'requireif:condition,""',
  36. ];
  37. protected $message = [
  38. 'name.require' => '等级名称不能为空',
  39. // 'name.max' => '等级名称不能超过50个字符',
  40. 'discount.require' => '等级折扣必传',
  41. 'rank.require' => '等级权重必传',
  42. 'rank.egt' => '等级权重大于等于0',
  43. 'discount.egt' => '等级折扣大于等于0',
  44. 'offline_user_level_id.require' => '线下会员等级id必传',
  45. ];
  46. protected $scene = [
  47. 'getUserLevelLists' => ['level_name'],
  48. 'addUserLevel' => ['offline_user_level_id','name','discount','rank','remark','condition'],
  49. 'updateUserLevelInfo' => ['offline_user_level_id','name','discount','rank','remark','condition'],
  50. 'delUserLevel' => ['name']
  51. ];
  52. /**
  53. * @notes 检查等级名称是否存在
  54. * @param $value
  55. * @param $rule
  56. * @param $data
  57. * @return bool|string
  58. * @author ljj
  59. * @date 2021/8/10 2:00 下午
  60. */
  61. public function checkName($value,$rule,$data)
  62. {
  63. if($value == 0) return true;
  64. $user_level = UserLevel::where('name', $value)->findOrEmpty();
  65. if ($user_level->isEmpty()) {
  66. return true;
  67. }else{
  68. return '已存在该会员等级名称';
  69. }
  70. }
  71. /**
  72. * @notes
  73. * @return DistributionValidate
  74. * @author Tab
  75. * @date 2021/7/17 10:18
  76. */
  77. public function sceneUpdateUserLevelInfo()
  78. {
  79. return $this->remove('name', 'checkName');
  80. }
  81. /**
  82. * @notes
  83. * @return DistributionValidate
  84. * @author Tab
  85. * @date 2021/7/17 10:18
  86. */
  87. public function sceneDelUserLevel()
  88. {
  89. return $this->remove('name', 'checkName')->remove('discount', 'require')
  90. ->remove('rank', 'require')->remove('offline_user_level_id', 'require');
  91. }
  92. }