123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172 |
- <?php
- namespace app\common\model;
- use app\common\library\BlurUtils;
- use app\common\library\Gm;
- use think\facade\Config;
- abstract class ZskkModel extends ZskkBaseModel
- {
- public function encryptWhere($where): array {
- if(!$where) {
- return $where;
- }
- foreach($where as &$_where) {
- $key = $this->getWhereKey($_where);
- if(in_array($key, $this->decrypts)) {
- $_where[2] = $this->encrypt($_where[2], $key);
- }
- }
- return $where;
- }
- public function getTable(): string {
- return parse_name(basename(str_replace('\\', '/', get_class($this)))).'.';
- }
- private function getWhereKey($where): string {
- $key = $where[0];
- $table = $this->getTable();
- $_key = str_replace($table, '', $key);
- return $_key;
- }
- protected function decrypt($val, $name) {
- return Gm::decrypt($this->getGmKey(), $val);
- }
- protected function blur($val, $name) {
- if($this->notNeedBlur($name)) {
- return $val;
- }
- $fun = '';
- if(isset($this->blur_funs[$name])) {
- $fun = $this->blur_funs[$name];
- }
- switch ($fun)
- {
- case 'blur1':
- $return = mb_substr($val, 0, 1) . str_repeat('*', mb_strlen($val) - 1);;
- break;
- case 'blur2':
- $return = substr_replace($val, str_repeat('*', 8), 6, 8);
- break;
- case 'blur3':
- $return = substr_replace($val, str_repeat('*', ceil(strlen($val)/2)), ceil(strlen($val)/4), ceil(strlen($val)/2));;
- break;
- default:
- $return = $val;
- }
- return $return;
- }
- protected function encrypt($val, $name) {
- return Gm::encrypt($this->getGmKey(), $val);
- }
- protected function getGmKey(): string {
- return Config::get('gm.key');
- }
- protected function notNeedBlur($name): bool {
- return BlurUtils::isNotNeedBlur();
- }
-
- }
|