PayTemplate.php 3.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485
  1. <?php
  2. // +----------------------------------------------------------------------
  3. // | Niucloud-admin 企业快速开发的saas管理平台
  4. // +----------------------------------------------------------------------
  5. // | 官方网址:https://www.niucloud.com
  6. // +----------------------------------------------------------------------
  7. // | niucloud团队 版权所有 开源版本可自由商用
  8. // +----------------------------------------------------------------------
  9. // | Author: Niucloud Team
  10. // +----------------------------------------------------------------------
  11. namespace app\validate\pay;
  12. use app\dict\pay\PayDict;
  13. use think\facade\Lang;
  14. use think\Validate;
  15. /**
  16. * Class PayTemplate
  17. * @package app\validate\pay
  18. */
  19. class PayTemplate extends Validate
  20. {
  21. //用户名或密码的规范可能是从数据库中获取的
  22. protected $rule = [
  23. 'name' => 'require',
  24. //支付宝
  25. 'app_id' => 'requireIf:type,' . PayDict::ALIPAY,
  26. 'app_secret_cert' => 'requireIf:type,' . PayDict::ALIPAY,
  27. 'app_public_cert_path' => 'requireIf:type,' . PayDict::ALIPAY,
  28. 'alipay_public_cert_path' => 'requireIf:type,' . PayDict::ALIPAY,
  29. 'alipay_root_cert_path' => 'requireIf:type,' . PayDict::ALIPAY,
  30. //微信
  31. 'mch_id' => 'requireIf:type,' . PayDict::WECHATPAY,
  32. 'mch_secret_key' => 'requireIf:type,' . PayDict::WECHATPAY,
  33. 'mch_secret_cert' => 'requireIf:type,' . PayDict::WECHATPAY,
  34. 'mch_public_cert_path' => 'requireIf:type,' . PayDict::WECHATPAY,
  35. //支付方式
  36. 'type' => 'require|checkPayType',
  37. ];
  38. protected $message = [
  39. 'app_id.requireIf' => 'validate_pay.app_id_requireif',
  40. 'app_secret_cert.requireIf' => 'validate_pay.app_secret_cert_requireif',
  41. 'app_public_cert_path.requireIf' => 'validate_pay.app_public_cert_path_requireif',
  42. 'alipay_public_cert_path.requireIf' => 'validate_pay.alipay_public_cert_path_requireif',
  43. 'alipay_root_cert_path.requireIf' => 'validate_pay.alipay_root_cert_path_requireif',
  44. 'mch_id.requireIf' => 'validate_pay.mch_id_requireif',
  45. 'mch_secret_key.requireIf' => 'validate_pay.mch_secret_key_requireif',
  46. 'mch_secret_cert.requireIf' => 'validate_pay.mch_secret_cert_requireif',
  47. 'mch_public_cert_path.requireIf' => 'validate_pay.mch_public_cert_path_requireif',
  48. 'name.require' => 'validate_pay.name_require'
  49. ];
  50. protected $scene = [
  51. 'add' => [
  52. 'app_id', 'app_secret_cert', 'app_public_cert_path', 'alipay_public_cert_path', 'alipay_root_cert_path',
  53. 'mch_id', 'mch_secret_key', 'mch_secret_cert', 'mch_public_cert_path',
  54. 'type', 'name'
  55. ],
  56. 'edit' => [
  57. 'app_id', 'app_secret_cert', 'app_public_cert_path', 'alipay_public_cert_path', 'alipay_root_cert_path',
  58. 'mch_id', 'mch_secret_key', 'mch_secret_cert', 'mch_public_cert_path',
  59. 'name'
  60. ],
  61. ];
  62. /**
  63. * 自定义验证 支付类型
  64. * @param $value
  65. * @param $rule
  66. * @param array $data
  67. * @return Lang|true
  68. */
  69. protected function checkPayType($value, $rule, $data = [])
  70. {
  71. return isset(PayDict::getPayType()[$value]) ? true : get_lang('validate_pay.not_exit_pay_type');
  72. }
  73. }