ZskkModel.php 2.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172
  1. <?php
  2. namespace app\common\model;
  3. use app\common\library\BlurUtils;
  4. use app\common\library\Gm;
  5. use think\facade\Config;
  6. abstract class ZskkModel extends ZskkBaseModel
  7. {
  8. public function encryptWhere($where): array {
  9. if(!$where) {
  10. return $where;
  11. }
  12. foreach($where as &$_where) {
  13. $key = $this->getWhereKey($_where);
  14. if(in_array($key, $this->decrypts)) {
  15. $_where[2] = $this->encrypt($_where[2], $key);
  16. }
  17. }
  18. return $where;
  19. }
  20. public function getTable(): string {
  21. return parse_name(basename(str_replace('\\', '/', get_class($this)))).'.';
  22. }
  23. private function getWhereKey($where): string {
  24. $key = $where[0];
  25. $table = $this->getTable();
  26. $_key = str_replace($table, '', $key);
  27. return $_key;
  28. }
  29. protected function decrypt($val, $name) {
  30. return Gm::decrypt($this->getGmKey(), $val);
  31. }
  32. protected function blur($val, $name) {
  33. if($this->notNeedBlur($name)) {
  34. return $val;
  35. }
  36. $fun = '';
  37. if(isset($this->blur_funs[$name])) {
  38. $fun = $this->blur_funs[$name];
  39. }
  40. switch ($fun)
  41. {
  42. case 'blur1':
  43. $return = mb_substr($val, 0, 1) . str_repeat('*', mb_strlen($val) - 1);;
  44. break;
  45. case 'blur2':
  46. $return = substr_replace($val, str_repeat('*', 8), 6, 8);
  47. break;
  48. case 'blur3':
  49. $return = substr_replace($val, str_repeat('*', ceil(strlen($val)/2)), ceil(strlen($val)/4), ceil(strlen($val)/2));;
  50. break;
  51. default:
  52. $return = $val;
  53. }
  54. return $return;
  55. }
  56. protected function encrypt($val, $name) {
  57. return Gm::encrypt($this->getGmKey(), $val);
  58. }
  59. protected function getGmKey(): string {
  60. return Config::get('gm.key');
  61. }
  62. protected function notNeedBlur($name): bool {
  63. return BlurUtils::isNotNeedBlur();
  64. }
  65. }