截流自动化的商城平台
Você não pode selecionar mais de 25 tópicos Os tópicos devem começar com uma letra ou um número, podem incluir traços ('-') e podem ter até 35 caracteres.

Validate.php 3.6KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107
  1. <?php
  2. // +----------------------------------------------------------------------
  3. // | likeshop开源商城系统
  4. // +----------------------------------------------------------------------
  5. // | 欢迎阅读学习系统程序代码,建议反馈是我们前进的动力
  6. // | gitee下载:https://gitee.com/likeshop_gitee
  7. // | github下载:https://github.com/likeshop-github
  8. // | 访问官网:https://www.likeshop.cn
  9. // | 访问社区:https://home.likeshop.cn
  10. // | 访问手册:http://doc.likeshop.cn
  11. // | 微信公众号:likeshop技术社区
  12. // | likeshop系列产品在gitee、github等公开渠道开源版本可免费商用,未经许可不能去除前后端官方版权标识
  13. // | likeshop系列产品收费版本务必购买商业授权,购买去版权授权后,方可去除前后端官方版权标识
  14. // | 禁止对系统程序代码以任何目的,任何形式的再发布
  15. // | likeshop团队版权所有并拥有最终解释权
  16. // +----------------------------------------------------------------------
  17. // | author: likeshop.cn.team
  18. // +----------------------------------------------------------------------
  19. namespace app\common\basics;
  20. use app\common\server\JsonServer;
  21. use think\response\Json;
  22. /**
  23. * 验证器基类
  24. * Class Validate
  25. * @Author FZR
  26. * @package app\common\basics
  27. */
  28. abstract class Validate extends \think\Validate
  29. {
  30. /**
  31. * 切面验证接收到的参数
  32. * @param null $scene (场景验证)
  33. * @param array $validate_data 验证参数,可追加和覆盖掉接收的参数
  34. * @author FZR
  35. * @return mixed|Json
  36. */
  37. public function goCheck($scene=null,$validate_data = [])
  38. {
  39. // 1.接收参数
  40. $params = request()->param();
  41. //合并验证参数
  42. $params = array_merge($params,$validate_data);
  43. // 2.验证参数
  44. if (!($scene ? $this->scene($scene)->check($params) : $this->check($params))) {
  45. $exception = is_array($this->error)
  46. ? implode(';', $this->error) : $this->error;
  47. JsonServer::throw($exception);
  48. }
  49. // 3.成功返回数据
  50. return $params;
  51. }
  52. /**
  53. * @notes 验证联系方式
  54. * @param $value
  55. * @param $rule
  56. * @param $data
  57. * @return string|bool
  58. * @author lbzy
  59. * @datetime 2024-10-28 18:00:59
  60. */
  61. function checkMobile($value, $rule, $data)
  62. {
  63. $checkList = $rule['check'] ?? [ 'land' ];
  64. $arr = [
  65. 'land' => [
  66. 'title' => '手机号',
  67. 'preg' => '/^1[3-9]\d{9}$/',
  68. ],
  69. 'hk' => [
  70. 'title' => '手机号',
  71. 'preg' => '/^(00|\+)?(852)[5|6|9]\d{7}$/',
  72. ],
  73. 'taiWan' => [
  74. 'title' => '手机号',
  75. 'preg' => '/^(00|\+)?(886)[0][9]\d{8}$/',
  76. ],
  77. 'aoMen' => [
  78. 'title' => '手机号',
  79. 'preg' => '/^(00|\+)?(853)?[6]\d{7}$/',
  80. ],
  81. 'landTel' => [
  82. 'title' => '电话',
  83. 'preg' => '/^(?:(?:\d{3}-?)?\d{8}|^(?:\d{4}-?)?\d{7,8})(?:-\d+)?$/',
  84. ],
  85. ];
  86. $result = false;
  87. foreach ($checkList as $key) {
  88. if (! isset($arr[$key])) {
  89. return '不存在的手机或电话地区';
  90. }
  91. if (preg_match($arr[$key]['preg'], $value)) {
  92. $result = true;
  93. break;
  94. }
  95. }
  96. return $result ? true : ($rule['msg'] ?? '联系方式错误');
  97. }
  98. }