GoodsCommentValidate.php 2.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889
  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\adminapi\validate\goods;
  20. use app\common\model\GoodsComment;
  21. use app\common\validate\BaseValidate;
  22. class GoodsCommentValidate extends BaseValidate
  23. {
  24. protected $rule = [
  25. 'id' => 'require|array|checkId',
  26. 'status' => 'require|in:0,1,2',
  27. ];
  28. public function sceneReply()
  29. {
  30. return $this->only(['id']);
  31. }
  32. public function sceneDel()
  33. {
  34. return $this->only(['id']);
  35. }
  36. public function sceneStatus()
  37. {
  38. return $this->only(['id','status'])
  39. ->append('id','checkStatus');
  40. }
  41. /**
  42. * @notes 检查商品评价ID是否存在
  43. * @param $value
  44. * @param $rule
  45. * @param $data
  46. * @return bool|string
  47. * @author ljj
  48. * @date 2021/8/12 5:20 下午
  49. */
  50. public function checkId($value,$rule,$data)
  51. {
  52. foreach ($value as $val) {
  53. $result = GoodsComment::findOrEmpty($val);
  54. if ($result->isEmpty()) {
  55. return '存在非法ID';
  56. }
  57. }
  58. return true;
  59. }
  60. /**
  61. * @notes 检验评价审核状态
  62. * @param $value
  63. * @param $rule
  64. * @param $data
  65. * @return bool|string
  66. * @author ljj
  67. * @date 2021/9/9 2:44 下午
  68. */
  69. public function checkStatus($value,$rule,$data)
  70. {
  71. foreach ($value as $val) {
  72. $result = GoodsComment::findOrEmpty($val);
  73. if ($result['status'] > 0) {
  74. return '存在已审核评价,请重新提交';
  75. }
  76. }
  77. return true;
  78. }
  79. }