截流自动化的商城平台
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

SignDailyValidate.php 3.0KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121
  1. <?php
  2. namespace app\admin\validate\sign_daily;
  3. use app\common\basics\Validate;
  4. use app\common\model\sign_daily\SignDaily;
  5. /**
  6. * 签到验证
  7. * Class SignDailyValidate
  8. * @package app\admin\validate
  9. */
  10. class SignDailyValidate extends Validate
  11. {
  12. protected $rule = [
  13. 'integral' => 'requireIf:integral_status,1|integer|checkIntegral', //积分
  14. 'growth' => 'requireIf:growth_status,1|integer|checkGrowth', //成长值
  15. 'days' => 'require|integer|gt:0|checkDays', //连续签到天数
  16. 'instructions' => 'require'
  17. ];
  18. protected $message = [
  19. 'integral.requireIf' => '积分不能为空',
  20. 'integral.integer' => '积分必须为整数',
  21. 'growth.requireIf' => '成长值不能为空',
  22. 'growth.integer' => '成长值必须为整数',
  23. 'days.require' => '连续签到天数不能为空',
  24. 'days.integer' => '连续签到天数必须为整数',
  25. 'days.gt' => '连续签到天数必须大于0',
  26. 'instructions' => '签到规则说明不能为空'
  27. ];
  28. public function sceneAdd()
  29. {
  30. $this->only(['integral', 'days', 'growth'])
  31. ->remove('instructions');
  32. }
  33. public function sceneEdit()
  34. {
  35. $this->only(['integral', 'days', 'growth'])
  36. ->remove('instructions');
  37. }
  38. public function sceneSign()
  39. {
  40. $this->only(['integral', 'growth', 'instructions'])
  41. ->remove('days');
  42. }
  43. /**
  44. * @notes 验证积分
  45. * @param $value
  46. * @param $rule
  47. * @param $data
  48. * @return bool|string
  49. * @author 段誉
  50. * @date 2022/3/17 14:45
  51. */
  52. public function checkIntegral($value, $rule, $data)
  53. {
  54. if (isset($data['integral_status']) && $data['integral_status'] && $value <= 0) {
  55. return '积分必须大于0';
  56. }
  57. return true;
  58. }
  59. /**
  60. * @notes 验证成长值
  61. * @param $value
  62. * @param $rule
  63. * @param $data
  64. * @return bool|string
  65. * @author 段誉
  66. * @date 2022/3/17 14:45
  67. */
  68. public function checkGrowth($value, $rule, $data)
  69. {
  70. if (isset($data['growth_status']) && $data['growth_status'] && $value <= 0) {
  71. return '成长值必须大于0';
  72. }
  73. return true;
  74. }
  75. /**
  76. * @notes 判断连续签到天数是否存在
  77. * @param $value
  78. * @param $rule
  79. * @param $data
  80. * @return bool|string
  81. * @author 段誉
  82. * @date 2022/2/17 10:46
  83. */
  84. public function checkDays($value, $rule, $data)
  85. {
  86. if (!isset($data['integral_status']) && !isset($data['growth_status'])) {
  87. return '请选择积分奖励或成才值奖励';
  88. }
  89. if (isset($data['id'])) {
  90. $where[] = ['id', '<>', $data['id']];
  91. }
  92. $where[] = ['days', '=', $value];
  93. $where[] = ['del', '=', 0];
  94. $sign_daily = SignDaily::where($where)->findOrEmpty();
  95. if (!$sign_daily->isEmpty()) {
  96. return '该连续签到天数已存在';
  97. }
  98. return true;
  99. }
  100. }