PayConfigValidate.php 4.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134
  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\adminapi\validate\settings\pay;
  20. use app\common\enum\PayEnum;
  21. use app\common\model\PayConfig;
  22. use app\common\validate\BaseValidate;
  23. class PayConfigValidate extends BaseValidate
  24. {
  25. protected $rule = [
  26. 'id' => 'require|checkId',
  27. 'name' => 'require|checkName',
  28. 'icon' => 'require',
  29. 'sort' => 'require|number|max:5',
  30. ];
  31. protected $message = [
  32. 'id.require' => 'id不能为空',
  33. 'name.require' => '支付名称不能为空',
  34. 'icon.require' => '支付图标不能为空',
  35. 'sort.require' => '排序不能为空',
  36. 'sort,number' => '排序必须是纯数字',
  37. 'sort.max' => '排序最大不能超过五位数',
  38. ];
  39. public function sceneGet()
  40. {
  41. return $this->only(['id'])
  42. ->remove('id','checkId');
  43. }
  44. /**
  45. * @notes 检查ID是否存在
  46. * @param $value
  47. * @param $rule
  48. * @param $data
  49. * @return bool|string
  50. * @throws \think\db\exception\DataNotFoundException
  51. * @throws \think\db\exception\DbException
  52. * @throws \think\db\exception\ModelNotFoundException
  53. * @author ljj
  54. * @date 2021/7/27 6:01 下午
  55. */
  56. public function checkId($value,$rule,$data)
  57. {
  58. $result = PayConfig::where('id',$value)->find();
  59. if (empty($result)) {
  60. return '支付方式不存在';
  61. }
  62. if ($result['pay_way'] == PayEnum::WECHAT_PAY) {
  63. if (empty($data['interface_version'])) {
  64. return '微信支付接口版本不能为空';
  65. }
  66. if (empty($data['merchant_type'])) {
  67. return '商户类型不能为空';
  68. }
  69. if(! in_array($data['interface_version'], [ 'v2', 'v3' ])) {
  70. return '微信支付接口版本 必须为v2或v3';
  71. }
  72. if (! in_array($data['merchant_type'], [ 'ordinary_merchant', 'partner_sub_merchant' ])) {
  73. return '商户类型 错误';
  74. }
  75. if ($data['interface_version'] == 'v2' && $data['merchant_type'] == 'partner_sub_merchant') {
  76. return 'v2版本暂不支持子商户';
  77. }
  78. if (empty($data['mch_id'])) {
  79. return '微信支付商户号不能为空';
  80. }
  81. if (empty($data['pay_sign_key'])) {
  82. return '商户API密钥不能为空';
  83. }
  84. if (empty($data['apiclient_cert'])) {
  85. return '微信支付证书不能为空';
  86. }
  87. if (empty($data['apiclient_key'])) {
  88. return '微信支付证书密钥不能为空';
  89. }
  90. }
  91. if ($result['pay_way'] == PayEnum::ALI_PAY) {
  92. if (empty($data['mode'])) {
  93. return '模式不能为空';
  94. }
  95. // if (empty($data['merchant_type'])) {
  96. // return '商户类型不能为空';
  97. // }
  98. if (empty($data['app_id'])) {
  99. return '应用ID不能为空';
  100. }
  101. if (empty($data['private_key'])) {
  102. return '应用私钥不能为空';
  103. }
  104. if (empty($data['ali_public_key'])) {
  105. return '支付宝公钥不能为空';
  106. }
  107. }
  108. return true;
  109. }
  110. /**
  111. * @notes 检查支付名称是否已存在
  112. * @param $value
  113. * @param $rule
  114. * @param $data
  115. * @author ljj
  116. * @date 2021/7/27 5:50 下午
  117. */
  118. public function checkName($value,$rule,$data)
  119. {
  120. $result = PayConfig::where('name', $value)->where('id','<>', $data['id'])->findOrEmpty();
  121. if (!$result->isEmpty()) {
  122. return '支付名称已存在';
  123. }
  124. return true;
  125. }
  126. }