PayConfigValidate.php 4.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131
  1. <?php
  2. // +----------------------------------------------------------------------
  3. // | likeadmin快速开发前后端分离管理后台(PHP版)
  4. // +----------------------------------------------------------------------
  5. // | 欢迎阅读学习系统程序代码,建议反馈是我们前进的动力
  6. // | 开源版本可自由商用,可去除界面版权logo
  7. // | gitee下载:https://gitee.com/likeshop_gitee/likeadmin
  8. // | github下载:https://github.com/likeshop-github/likeadmin
  9. // | 访问官网:https://www.likeadmin.cn
  10. // | likeadmin团队 版权所有 拥有最终解释权
  11. // +----------------------------------------------------------------------
  12. // | author: likeadminTeam
  13. // +----------------------------------------------------------------------
  14. namespace app\adminapi\validate\setting;
  15. use app\common\enum\PayEnum;
  16. use app\common\model\pay\PayConfig;
  17. use app\common\validate\BaseValidate;
  18. class PayConfigValidate extends BaseValidate
  19. {
  20. protected $rule = [
  21. 'id' => 'require',
  22. 'name' => 'require|checkName',
  23. 'icon' => 'require',
  24. 'sort' => 'require|number|max:5',
  25. 'config' => 'checkConfig',
  26. ];
  27. protected $message = [
  28. 'id.require' => 'id不能为空',
  29. 'name.require' => '支付名称不能为空',
  30. 'icon.require' => '支付图标不能为空',
  31. 'sort.require' => '排序不能为空',
  32. 'sort,number' => '排序必须是纯数字',
  33. 'sort.max' => '排序最大不能超过五位数',
  34. 'config.require' => '支付参数缺失',
  35. ];
  36. public function sceneGet()
  37. {
  38. return $this->only(['id']);
  39. }
  40. /**
  41. * @notes 校验支付配置记录
  42. * @param $value
  43. * @param $rule
  44. * @param $data
  45. * @return bool|string
  46. * @throws \think\db\exception\DataNotFoundException
  47. * @throws \think\db\exception\DbException
  48. * @throws \think\db\exception\ModelNotFoundException
  49. * @author 段誉
  50. * @date 2023/2/23 16:19
  51. */
  52. public function checkConfig($config, $rule, $data)
  53. {
  54. $result = PayConfig::where('id', $data['id'])->find();
  55. if (empty($result)) {
  56. return '支付方式不存在';
  57. }
  58. if ($result['pay_way'] != PayEnum::BALANCE_PAY && !isset($config)) {
  59. return '支付配置不能为空';
  60. }
  61. if ($result['pay_way'] == PayEnum::WECHAT_PAY) {
  62. if (empty($config['interface_version'])) {
  63. return '微信支付接口版本不能为空';
  64. }
  65. if (empty($config['merchant_type'])) {
  66. return '商户类型不能为空';
  67. }
  68. if (empty($config['mch_id'])) {
  69. return '微信支付商户号不能为空';
  70. }
  71. if (empty($config['pay_sign_key'])) {
  72. return '商户API密钥不能为空';
  73. }
  74. if (empty($config['apiclient_cert'])) {
  75. return '微信支付证书不能为空';
  76. }
  77. if (empty($config['apiclient_key'])) {
  78. return '微信支付证书密钥不能为空';
  79. }
  80. }
  81. if ($result['pay_way'] == PayEnum::ALI_PAY) {
  82. if (empty($config['mode'])) {
  83. return '模式不能为空';
  84. }
  85. if (empty($config['merchant_type'])) {
  86. return '商户类型不能为空';
  87. }
  88. if (empty($config['app_id'])) {
  89. return '应用ID不能为空';
  90. }
  91. if (empty($config['private_key'])) {
  92. return '应用私钥不能为空';
  93. }
  94. if (empty($config['ali_public_key'])) {
  95. return '支付宝公钥不能为空';
  96. }
  97. }
  98. return true;
  99. }
  100. /**
  101. * @notes 校验支付名
  102. * @param $value
  103. * @param $rule
  104. * @param $data
  105. * @return bool|string
  106. * @author 段誉
  107. * @date 2023/2/23 16:19
  108. */
  109. public function checkName($value, $rule, $data)
  110. {
  111. $result = PayConfig::where('name', $value)
  112. ->where('id', '<>', $data['id'])
  113. ->findOrEmpty();
  114. if (!$result->isEmpty()) {
  115. return '支付名称已存在';
  116. }
  117. return true;
  118. }
  119. }