ApproveApply.php 2.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081
  1. <?php
  2. namespace app\common\validate;
  3. use app\common\constant\ApplyConstant;
  4. use think\Validate;
  5. /**
  6. * 申购信息验证
  7. */
  8. class ApproveApply extends Validate
  9. {
  10. /**
  11. * 验证规则
  12. */
  13. protected $rule = [
  14. 'reason' => 'require',
  15. 'type' => 'require|check_type',
  16. 'apply_goods' => 'requireIf:type,1',
  17. 'total_amount' => 'require|gt:0',
  18. 'pay_type' => 'require|check_pay_type',
  19. 'approve_user' => 'require',
  20. ];
  21. /**
  22. * 提示消息
  23. */
  24. protected $message = [
  25. ];
  26. /**
  27. * 验证场景
  28. */
  29. protected $scene = [
  30. 'create' => ['reason', 'type', 'apply_goods', 'total_amount', 'pay_type', 'approve_user'],
  31. 'update' => ['reason', 'type', 'apply_goods', 'total_amount', 'pay_type', 'approve_user'],
  32. 'edit' => ['reason', 'type', 'apply_goods', 'total_amount', 'pay_type'],
  33. ];
  34. /**
  35. * 构造函数
  36. * @access public
  37. * @param array $rules 验证规则
  38. * @param array $message 验证提示信息
  39. * @param array $field 验证字段描述信息
  40. */
  41. public function __construct(array $rules = [], $message = [], $field = [])
  42. {
  43. $this->field = [
  44. 'reason' => '申购事由',
  45. 'type' => '采购类型',
  46. 'apply_goods' => '申购物品',
  47. 'total_amount' => '总金额',
  48. 'pay_type' => '支付方式',
  49. 'approve_user' => '审批人',
  50. ];
  51. $this->message = array_merge($this->message, [
  52. 'type.check_type' => '请选择正确的采购类型',
  53. 'apply_goods.requireIf' => '请添加申购物品',
  54. 'pay_type.check_pay_type' => '请选择正确的支付方式',
  55. ]);
  56. parent::__construct($rules, $message, $field);
  57. }
  58. protected function check_type($value, $rule, $data)
  59. {
  60. $get_type_list = ApplyConstant::get_type_list();
  61. if (!array_key_exists($value, $get_type_list)) {
  62. return false;
  63. }
  64. return true;
  65. }
  66. protected function check_pay_type($value, $rule, $data)
  67. {
  68. $get_type_list = ApplyConstant::get_pay_type_list();
  69. if (!array_key_exists($value, $get_type_list)) {
  70. return false;
  71. }
  72. return true;
  73. }
  74. }