TeamValidate.php 3.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103
  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\validate\BaseValidate;
  21. class TeamValidate extends BaseValidate
  22. {
  23. protected $rule = [
  24. 'id' => 'require|number',
  25. 'action' => 'require|in:buy,settle',
  26. 'pay_way' => 'number|in:1,2,3',
  27. 'address_id' => 'number',
  28. 'coupon_id' => 'number',
  29. 'team_id' => 'require|number',
  30. 'goods' => 'require|array|checkGoods'
  31. ];
  32. protected $message = [
  33. 'id.require' => '缺少id参数',
  34. 'id.number' => 'id参数必须为数字',
  35. 'action.require' => '缺少action参数',
  36. 'action.in' => 'action参数不在合法范围',
  37. 'pay_way.number' => 'pay_way参数异常',
  38. 'pay_way.in' => 'pay_way参数不在合法范围',
  39. 'address_id.number' => 'address_id参数异常',
  40. 'coupon_id.number' => 'coupon_id参数异常',
  41. 'team_id.require' => '缺少team_id参数',
  42. 'team_id.number' => 'team_id参数异常',
  43. ];
  44. /**
  45. * @notes id验证场景
  46. * @return TeamValidate
  47. * @author 张无忌
  48. * @date 2021/8/3 15:25
  49. */
  50. public function sceneId()
  51. {
  52. return $this->only(['id']);
  53. }
  54. /**
  55. * @notes 开团场景验证
  56. * @return TeamValidate
  57. * @author 张无忌
  58. * @date 2021/8/3 16:28
  59. */
  60. public function sceneKaituan()
  61. {
  62. return $this->only([
  63. 'action', 'pay_way', 'address_id', 'goods'
  64. ]);
  65. }
  66. /**
  67. * @notes 验证商品参数
  68. * @param $value
  69. * @author 张无忌
  70. * @return bool|string
  71. * @date 2021/7/26 17:22
  72. */
  73. public function checkGoods($value)
  74. {
  75. if (empty($value)) {
  76. return '缺少goods相关参数';
  77. }
  78. if (empty($value['goods_id'])) {
  79. return '缺少goods_id参数';
  80. }
  81. if (empty($value['item_id'])) {
  82. return '缺少item_id参数';
  83. }
  84. if (empty($value['count'])) {
  85. return '缺少count参数';
  86. }
  87. return true;
  88. }
  89. }