__('Status 1'), '0' => __('Status 0'), ]; } public function getStatusTextAttr($value, $data) { $value = $value !== '' && $value !== null ? $value : (isset($data['status']) ? $data['status'] : ''); $list = $this->getStatusList(); return isset($list[(string)$value]) ? $list[(string)$value] : ''; } /** * 与手机端登录一致:md5(md5(明文)) */ public static function hashPassword(string $plain): string { return md5(md5($plain)); } /** * 邮箱、手机号仅保留单个值(去掉逗号等多值写法) */ public static function normalizeSingleContact(string $value): string { $value = trim($value); if ($value === '') { return ''; } $value = str_replace([',', ';', ';', '|', '|', "\n", "\r", "\t"], ',', $value); $parts = preg_split('/\s*,\s*/', $value, -1, PREG_SPLIT_NO_EMPTY); if (!$parts) { return $value; } return trim((string)$parts[0]); } protected static function init() { self::beforeWrite(function ($model) { $data = $model->getData(); foreach (['phone', 'email'] as $field) { if (!array_key_exists($field, $data)) { continue; } $model->setAttr($field, self::normalizeSingleContact((string)$data[$field])); } if (array_key_exists('account', $data)) { $model->setAttr('account', trim((string)$data['account'])); } }); } }