GoodsCommentValidate.php 3.1 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\shopapi\validate;
  20. use app\common\model\Goods;
  21. use app\common\model\Order;
  22. use app\common\model\OrderGoods;
  23. use app\common\validate\BaseValidate;
  24. class GoodsCommentValidate extends BaseValidate
  25. {
  26. protected $rule = [
  27. 'order_goods_id' => 'require|checkOrderGoodsId',
  28. 'goods_comment' => 'require|number|in:1,2,3,4,5',
  29. 'service_comment' => 'require|number|in:1,2,3,4,5',
  30. 'description_comment' => 'require|number|in:1,2,3,4,5',
  31. 'express_comment' => 'require|number|in:1,2,3,4,5',
  32. 'image' => 'array',
  33. 'goods_id' => 'require|checkGoodsId',
  34. ];
  35. public function sceneAdd()
  36. {
  37. return $this->only(['order_goods_id','goods_comment','service_comment','description_comment','express_comment']);
  38. }
  39. public function sceneCommentCategory()
  40. {
  41. return $this->only(['goods_id']);
  42. }
  43. public function sceneCommentGoodsInfo()
  44. {
  45. return $this->only(['order_goods_id']);
  46. }
  47. /**
  48. * @notes 检查订单商品是否存在
  49. * @param $value
  50. * @param $rule
  51. * @param $data
  52. * @return bool|string
  53. * @author ljj
  54. * @date 2021/8/6 6:11 下午
  55. */
  56. public function checkOrderGoodsId($value,$rule,$data)
  57. {
  58. $order_goods = OrderGoods::where('id', $value)->findOrEmpty();
  59. if ($order_goods->isEmpty()) {
  60. return '订单商品不存在';
  61. }
  62. if ($order_goods['is_comment'] == 1) {
  63. return '该商品已评价';
  64. }
  65. $order = Order::where('id', $order_goods['order_id'])->where('order_status', '=', 3)->findOrEmpty();
  66. if ($order->isEmpty()) {
  67. return '订单不存在或未完成';
  68. }
  69. return true;
  70. }
  71. /**
  72. * @notes 检查商品ID是否存在
  73. * @param $value
  74. * @param $rule
  75. * @param $data
  76. * @return bool|string
  77. * @author ljj
  78. * @date 2021/8/6 8:29 下午
  79. */
  80. public function checkGoodsId($value,$rule,$data)
  81. {
  82. $order_goods = Goods::where('id', $value)->findOrEmpty();
  83. if ($order_goods->isEmpty()) {
  84. return '商品不存在';
  85. }
  86. return true;
  87. }
  88. }