Initial commit,修正

This commit is contained in:
2025-07-13 19:37:38 +08:00
parent 38ce288e27
commit 65bbd06981
12384 changed files with 3985464 additions and 8 deletions
+15
View File
@@ -0,0 +1,15 @@
namespace: common\tests
actor_suffix: Tester
paths:
tests: tests
output: tests/_output
data: tests/_data
support: tests/_support
bootstrap: _bootstrap.php
settings:
colors: true
memory_limit: 1024M
modules:
config:
Yii2:
configFile: 'config/codeception-local.php'
+44
View File
@@ -0,0 +1,44 @@
<?php
/**
* @Author: fm453
* @Date: 2018-11-21 04:18:24
* @Last Modified by: fm453
* @Last Modified time: 2019-10-07 17:16:03
* @Email: fm453@lukegzs.com
*/
namespace common\components;
use Yii;
use yii\data\Pagination;
use yii\widgets\ActiveForm;
class Attachment extends ActiveForm
{
/*处理分页*/
private $pagination;
/**
* 获取$pagination,提供给外部代码调用
* @return mixed
*/
public function getPagination()
{
return $this->pagination;
}
public function getData($model,$where,$orderby)
{
// 预查询,此时还没有执行。where()条件查询、orderBy()排序等都应该放在这里
$query = $model->find()->where($where)->orderBy($orderby);
// 获取能够查询到的数据条目数量(这就是条件查询等语句要放在上一行代码的原因),但是还没有执行查询
$count = $query->count();
// 构造分页对象
$this->pagination = new Pagination(['totalCount'=>$count,'defaultPageSize' => 12]);
// 使用分页对象填充limit语句,并获得数据(此时才真正执行数据库查询)
return $query->offset($this->pagination->offset)
->limit($this->pagination->limit)
->asArray()
->all();
}
}
+68
View File
@@ -0,0 +1,68 @@
<?php
/**
* Description:操作日志记录
*/
namespace common\components;
use common\models\Logs;
use Yii;
class DoLogs {
public static function record(){
$username = '';
$uid = 0;
if(isset(Yii::$app->user->identity)){
$username = Yii::$app->user->identity->username;
$uid = Yii::$app->user->identity->id;
}
$usertypes = array(
'app-backend' => '1',
'app-frontend' => '2',
);
$usertype = $usertypes[Yii::$app->id];
$request = Yii::$app->getRequest();
$nowFile = $request -> getScriptFile();
$r = isset($_GET['r']) ? $_GET['r'] : 'null/null';
$r = explode('/',$r);
$m = '';
$m = $r[0];
$v = '';
$c = '';
$c = $r[1];
//$a = __METHOD__; //当前方法
$a = '';
$ip = Yii::$app->request->userIP;
$domain=$_SERVER['HTTP_HOST'];
$data = '';
Yii::$app->db->createCommand()->insert(
'c_logs', [
'username' => $username,
'uid' => $uid,
'usertype' => $usertype,
'file' => $nowFile,
'm' => $m,
'v' => $v,
'c' => $c,
'a' => $a,
'ip'=>$ip,
'domain' => $domain,
'data'=>$data,
'create_time' => time(),
])->execute();
}
//历史访客数
public static function getHistoryVisNum(){
$res = Logs::find()->count();
return $res;
}
//最近一个月访问量
public static function getMonthHistoryVisNum(){
$LastMonth = strtotime("-1 month");
$res = Logs::find()->where(['>','create_time',$LastMonth])->count();
return $res;
}
}
+67
View File
@@ -0,0 +1,67 @@
<?php
/**
* @Author: fm453
* @Date: 2021-09-08 00:25:51
* @Last Modified by: fm453
* @Last Modified time: 2021-09-09 02:03:09
* @Email: fm453@lukegzs.com
*/
namespace common\components;
use Yii;
class HiCookie {
//添加Cookie
public static function set($name,$value,$httpOnly=true,$expire=null)
{
$cookie = new \yii\web\Cookie();
$cookie->name = $name; //cookie的名称
$expire = $expire>0 ? $expire : '180'; //默认180s
$cookie->expire = time() + $expire; //存活的时间
$cookie->httpOnly = $httpOnly; //无法通过js读取cookie
$cookie->value = $value; //cookie的值
\Yii::$app->response->getCookies()->add($cookie);
}
//读取Cookie
public static function get($name)
{
if(\Yii::$app->request->cookies->has($name)){
return \Yii::$app->request->cookies->getValue($name);
}
return false;
}
public static function getObj($name)
{
if(\Yii::$app->request->cookies->has($name)){
return \Yii::$app->request->cookies->get($name);
}
return false;
}
//删除Cookie /*注意删除用的是response而不是request*/
public static function delete($name)
{
$cookie = $this->getObj($name);
//移除一个Cookie对象
if($cookie){
\Yii::$app->response->getCookies()->remove($cookie);
}
}
public static function deleteAll()
{
//移除所有Cookie,目前好像不太好使
\Yii::$app->response->getCookies()->removeAll();
}
//读取Cookie的总数
public static function count()
{
return \Yii::$app->request->cookies->count();
}
}
+4
View File
@@ -0,0 +1,4 @@
codeception-local.php
main-local.php
params-local.php
test-local.php
+3
View File
@@ -0,0 +1,3 @@
<?php
Yii::setAlias('@common', dirname(__DIR__));
Yii::setAlias('@console', dirname(dirname(__DIR__)) . '/console');
+61
View File
@@ -0,0 +1,61 @@
<?php
# @Author: fm453
# @Date: 1970-01-01T08:00:00+08:00
# @Email: fm453@hiluker.com
# @Last modified by: fm453
# @Last modified time: 2021-09-14T23:27:42+08:00
return [
'aliases' => [
'@bower' => '@vendor/bower-asset',
'@npm' => '@vendor/npm-asset',
],
'vendorPath' => dirname(dirname(__DIR__)) . '/vendor',
'components' => [
'cache' => [
'class' => 'yii\caching\FileCache',
],
'mailer' => [
'class' => 'yii\symfonymailer\Mailer',
'viewPath' => '@common/mail',
// send all mails to a file by default. You have to set
// 'useFileTransport' to false and configure a transport
// for the mailer to send real emails.
'useFileTransport' => false,
'transport' => [
// 'class' => 'Swift_SmtpTransport', //使用的类
'scheme' => 'smtps',
'host' => 'smtp.qq.com', //邮箱服务一地址
'username' => '393213759@qq.com',//邮箱地址,发送的邮箱
'password' => 'oqqkcnstydagbigd', //QQ邮箱授权码
'port' => '465', //服务器端口
'encryption' => 'ssl', //加密方式
],
'messageConfig'=>[
'charset'=>'UTF-8',
'from'=>['393213759@qq.com'=>'admin']
],
],
/**
* 语言包配置(归于components下),
* 将"源语言"翻译成"目标语言". 注意"源语言"默认配置为 'sourceLanguage' => 'en-US'
* 使用: \Yii::t('common', 'title'); 将common/messages下的common.php中的title转为对应的中文
*/
'i18n' => [
'translations' => [
'*' => [
'class' => 'yii\i18n\PhpMessageSource',
'basePath' => '@common/messages',
//'sourceLanguage' => 'en-US',
'fileMap' => [
'common' => 'common.php',
'frontend' => 'frontend.php',
'backend' => 'backend.php',
'errorcode' => 'errorcode.php',
],
],
],
],
],
];
+23
View File
@@ -0,0 +1,23 @@
<?php
return [
//目前已经添加的一些数据模型
'dataModules' => [
'realty' => '房地产',
'page' => '页面',
'goods' => '商品',
'price' => '价格',
'stock' => '库存',
'order' => '订单',
'shopcart' => '购物车',
'article' => '文章',
'users' => '用户',
'comment' => '评论',
'emarketing' => '营销',
'attachment' => '附件',
'ads' => '广告',
'chat' => '聊天室',
'setting' => '设置记录',
'metadata' => '元数据',
'alimsg' => '阿里云短信',
],
];
+8
View File
@@ -0,0 +1,8 @@
<?php
return [
'adminEmail' => 'admin@lukegzs.com',
'supportEmail' => '393213759@qq.com', //对应main-local的配置
'noticeEmail' => '393213759@qq.com', //邮件通知用的邮箱(注意必须和main配置的邮件服务器一致)
'user.passwordResetTokenExpire' => 3600,
'user.passwordMinLength' => 8,
];
+11
View File
@@ -0,0 +1,11 @@
<?php
return [
'id' => 'app-common-tests',
'basePath' => dirname(__DIR__),
'components' => [
'user' => [
'class' => 'yii\web\User',
'identityClass' => 'common\models\User',
],
],
];
+9
View File
@@ -0,0 +1,9 @@
<?php
namespace common\fixtures;
use yii\test\ActiveFixture;
class UserFixture extends ActiveFixture
{
public $modelClass = 'common\models\User';
}
+15
View File
@@ -0,0 +1,15 @@
<?php
use yii\helpers\Html;
/* @var $this yii\web\View */
/* @var $user common\models\User */
$verifyLink = Yii::$app->urlManager->createAbsoluteUrl(['site/verify-email', 'token' => $user->verification_token]);
?>
<div class="verify-email">
<p>Hello <?= Html::encode($user->username) ?>,</p>
<p>Follow the link below to verify your email:</p>
<p><?= Html::a(Html::encode($verifyLink), $verifyLink) ?></p>
</div>
+12
View File
@@ -0,0 +1,12 @@
<?php
/* @var $this yii\web\View */
/* @var $user common\models\User */
$verifyLink = Yii::$app->urlManager->createAbsoluteUrl(['site/verify-email', 'token' => $user->verification_token]);
?>
Hello <?= $user->username ?>,
Follow the link below to verify your email:
<?= $verifyLink ?>
+22
View File
@@ -0,0 +1,22 @@
<?php
use yii\helpers\Html;
/* @var $this \yii\web\View view component instance */
/* @var $message \yii\mail\MessageInterface the message being composed */
/* @var $content string main view render result */
?>
<?php $this->beginPage() ?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=<?= Yii::$app->charset ?>" />
<title><?= Html::encode($this->title) ?></title>
<?php $this->head() ?>
</head>
<body>
<?php $this->beginBody() ?>
<?= $content ?>
<?php $this->endBody() ?>
</body>
</html>
<?php $this->endPage() ?>
+14
View File
@@ -0,0 +1,14 @@
<?php
use yii\helpers\Html;
/** @var \yii\web\View $this view component instance */
/** @var \yii\mail\MessageInterface $message the message being composed */
/** @var string $content main view render result */
?>
<?php $this->beginPage() ?>
<?php $this->beginBody() ?>
<?= $content ?>
<?php $this->endBody() ?>
<?php $this->endPage() ?>
+15
View File
@@ -0,0 +1,15 @@
<?php
use yii\helpers\Html;
/* @var $this yii\web\View */
/* @var $user common\models\User */
$resetLink = Yii::$app->urlManager->createAbsoluteUrl(['site/reset-password', 'token' => $user->password_reset_token]);
?>
<div class="password-reset">
<p>Hello <?= Html::encode($user->username) ?>,</p>
<p>Follow the link below to reset your password:</p>
<p><?= Html::a(Html::encode($resetLink), $resetLink) ?></p>
</div>
+12
View File
@@ -0,0 +1,12 @@
<?php
/* @var $this yii\web\View */
/* @var $user common\models\User */
$resetLink = Yii::$app->urlManager->createAbsoluteUrl(['site/reset-password', 'token' => $user->password_reset_token]);
?>
Hello <?= $user->username ?>,
Follow the link below to reset your password:
<?= $resetLink ?>
+12
View File
@@ -0,0 +1,12 @@
<?php
return [
/* 系统信息 开始 */
'Project Name' => 'DACMS',
'Short Company Name' => '嗨路客',
'Full Company Name' => '海南嗨路客电子商务有限公司',
'English Company Name' => 'Hi Luker',
'Company Create Time' => '2013',
'System Name' => 'DACMS控制面板',
'System' => '系统',
/* 系统信息 结束 */
];
+157
View File
@@ -0,0 +1,157 @@
<?php
return [
/* 系统信息 开始 */
'Project Name' => 'Hi',
'Short Company Name' => '嗨路客',
'Full Company Name' => '海南嗨路客电子商务有限公司',
'English Company Name' => 'Hi Luker',
'Company Create Time' => '2013',
'System Name' => '控制面板',
'System' => '系统',
/* 系统信息 结束 */
/* 按钮 开始 */
'Profile' => '个人资料',
'Settings' => '设置',
'Logout' => '退出系统',
'Login' => '登录',
'Create' => '创建',
'Update' => '更新',
'Delete' => '删除',
'View' => '查看',
'List' => '列表',
'Submit' => '提交',
'Show' => '显示',
'Hide' => '隐藏',
'Update Status' => '修改状态',
'Back' => '返回',
'Refresh' => '刷新',
'Cancel' => '取消',
'Recovery' => '恢复',
'Set Password' => '修改密码',
'Reset Password' => '重置密码',
/* 按钮 结束 */
/* 提示 开始 */
//以下是提示文字
'Username' => '登陆名',
'Avatar' => '头像',
'Password' => '登录密码',
'Remember Me' => '记住密码',
'Email' => '邮箱',
'Mobile' => '手机',
'Role' => '用户组',
'Verify Code' => '验证码',
'Status' => '状态',
'Search' => '查询',
'Switching Sidebar' => '切换侧边栏',
'System Error!' => '系统出错啦',
'System Error' => '系统错误',
'Sytem Unknown Error' => '崩溃...系统也不知道哪里错了',
'More Controllers' => '更多操作',
'Go back' => '返回上一页',
//以下是提示句子
'Incorrect username or password.' => '用户名或密码不正确。',
'Not find data' => '暂无数据!',
'{start}-{end} a total of {total}'=>'第<b>{start}-{end}</b>条,共<b>{total}</b>条数据',
'The requested page does not exist' => '请求的页面不存在',
'Are you sure to delete {param}?' => '确定删除 {param} 吗?',
'Are you sure you want to delete this item?' => '确定要删除当前记录?',
'Delete the item {param} successful!' => '{param}记录删除成功!',
'Delete the item {param} failed!' => '{param}记录删除失败!',
'Delete the item {param} failed because of {relations}!' => '删除失败,请先删除当前{param}以下关联信息:{relations}。',
'Are you sure you want to change status to {param}?' => '确定要修改当前状态为 {param} 吗?',
'User name will be used as the login account' => '用户名将作为管理员登录账号使用。',
'Password must be the same.' => '两次密码不一致。',
'Old password is incorrect.' => '原密码错误。',
"Are you sure to reset {param}'s password?" => '确定要重置 {param} 的密码吗?',
'Reset password successful!' => '密码重置成功!',
'Reset password failed!' => '密码重置失败!',
'Update status successful!' => '状态修改成功!',
'Update status failed!' => '状态修改失败!',
'Add Sensitive Word:' => '增加敏感词:',
'Recommend {param} successful!' => '{param}推荐成功!',
'Role delete successful!' => '角色删除成功!',
'Role delete failed! Please checked it.' => '角色删除失败!请检查系统是否存在该角色的管理员。',
'You don\'t have permission to access this action.Please contract administrator to know about permission managment.' => '没有访问权限!请联系管理员了解权限管理。',
'You\'re not allow to access this action.' => '没有访问权限!',
'Input \'0\' means unlimited of this item.' => '输入0表示无限制',
'Unknown operation.' => '未知操作。',
'<a href="{profile}">{admin}</a> view the {label} record:<a href="{url}">{item}</a>.' => '<a href="{profile}">{admin}</a> 查看了{label} <a href="{url}">{item}</a>。',
'<a href="{profile}">{admin}</a> created a new {label} record:<a href="{url}">{item}</a>.' => '<a href="{profile}">{admin}</a> 创建了{label} <a href="{url}">{item}</a>。',
'<a href="{profile}">{admin}</a> updated the {label} record:{attributes} of <a href="{url}">{item}</a>.' => '<a href="{profile}">{admin}</a> 修改了{label} <a href="{url}">{item}</a> 的以下信息:{attributes}。',
'<a href="{profile}">{admin}</a> deleted the {label} record:{item}.' => '<a href="{profile}">{admin}</a> 删除了{label} {item}。',
'<a href="{profile}">{admin}</a> reset the <a href="{url}">{item}</a> password to {password}.' => '<a href="{profile}">{admin}</a> 把 <a href="{url}">{item}</a> 的密码重置为了 {password}。',
'<a href="{profile}">{admin}</a> update the {label} <a href="{url}">{item}</a> <a href="{subitem_url}">{subitem}</a> status to {status}.' => '<a href="{profile}">{admin}</a> 把{label} <a href="{url}">{item}</a> 的 <a href="{subitem_url}">{subitem}</a> 状态修改为了 {status}。',
'<a href="{profile}">{admin}</a> deleted the {label} <a href="{url}">{title}</a> comment record:{item}.' => '<a href="{profile}">{admin}</a> 删除了{label} <a href="{url}">{title}</a> 的评论 {item}。',
'<a href="{profile}">{admin}</a> login system.' => '<a href="{profile}">{admin}</a> 登录了系统。',
'<a href="{profile}">{admin}</a> logout system.' => '<a href="{profile}">{admin}</a> 退出了系统。',
'<a href="{profile}">{admin}</a> recommended {num} {unit}<a href="{url}">{item}</a>.' => '<a href="{profile}">{admin}</a> 推荐了{num}{unit} <a href="{url}">{item}</a>。',
'<a href="{profile}">{admin}</a> operated an order refund,code is <a href="{url}">{item}</a>,amount is {refund_amount}, refund massage is {msg}.' => '<a href="{profile}">{admin}</a> 操作了一笔订单退款,订单编号:<a href="{url}">{item}</a>,退款金额:{refund_amount}元,操作信息:{msg}。',
/* 提示 结束 */
/* 标题 开始 */
'Console' => '控制台',
/* 标题 结束 */
/* 系统导航栏 开始 */
'See all' => '查看全部',
'Notifications' => '通知',
'Messages' => '消息',
'New Comments' => '新的评论',
'New Orders' => '新的订单',
'New Users' => '新注册用户',
/* 系统导航栏 结束 */
/* 通用文字 开始 */
//跟状态相关的文字
'Normal' => '正常',
'Forbidden' => '禁用',
'Read Only' => '只读',
'Writable' => '可写',
'Yes' => '是',
'No' => '不是',
'Unlimited' => '不限',
'Dashboard' => '控制面板',
'Administrator' => '管理员',
'Role' => '角色',
'Role Management' => '角色管理',
'Role Defined' => '角色定义',
'Store Manager Name' => '网点负责人',
'General Employee' => '普通员工',
//跟性别相关的文字
'Sex' => '性别',
'Male' => '男',
'Famale' => '女',
//其他
'All' => '全部',
'Unknown' => '未知',
'User Defined' => '自定义',
'Moment Ago' => '刚刚',
'' => '',
/* 通用文字 结束 */
/* Controller名 */
'Addition' => '选件',
'Admin' => '管理员',
'Article' => '文档',
/* 字段名 */
'Recommend Count' => '推荐数',
'Lon And Lat' => '经纬度',
/* 控制面板 */
'New Orders' => '今日订单',
'Login Users' => '登录用户',
'New Registers' => '新增注册',
'This Week' => '本周',
'Last Week' => '上周',
'This Month' => '本月',
'Last Month' => '上月',
];
+45
View File
@@ -0,0 +1,45 @@
<?php
return [
//登陆处理相关453000
'45300001' => '未找到该用户',
'45300002' => '密码错误',
'45300003' => '用户账号已被冻结',
'45300004' => '登陆失败',
'4530009999' => '未知的错误',
//服务器证书管理相关453001
'45300101' => '非法访问1(来路IP或域名不在白名单中)',
'45300102' => '非法访问2',
'45300103' => '未设置有效的证书路径',
'45300104' => '未查询到服务器证书',
'45300105' => '无效的服务器证书',
//站点访问相关453002
'45300201' => '请登陆后再操作',
'45300202' => '连接成功',
'45300203' => '授权码code不正确',
'45300204' => 'AccessToken无效',
'45300205' => '未指定有效的appid',
'45300206' => '非法访问(无效的appid与accesstoken)',
//数据设置相关453003
'45300301' => '保存失败',
'45300302' => '未获取到data数据',
'45300303' => '未获取到param数据',
'45300304' => '未获取到self数据',
'45300305' => '未获取到form数据',
'45300306' => '未获取到order数据',
'45300307' => '未获取到addon数据',
'45300308' => '未获取到attr数据',
'4530039999' => '未传入有效的ac({ac})',
//短信接口相关453004
'45300401' => '部分发送失败',
'45300402' => '全部发送失败',
'45300403' => 'POST数据非法,config配置项不应为空且必须为包含了accessKeyId、accessKeySecret、sign键的数组',
'45300404' => 'POST数据非法,option配置项必须为数组',
'45300405' => 'POST数据非法,tmpl配置项不应为空且必须为符合阿里大鱼短信模板编号的文本形式',
'45300406' => 'POST数据非法,phone配置项不应为空且必须为数组',
'45300407' => 'POST数据非法,content配置项必须为数组',
];
+82
View File
@@ -0,0 +1,82 @@
<?php
return [
/* 系统信息 开始 */
'Project Name' => 'DACMS',
'Site Name' => 'HiLuker Api',
'Short Company Name' => '嗨路客',
'Full Company Name' => '海南嗨路客电子商务有限公司',
'English Company Name' => 'Hi Luker',
'Company Create Time' => '2013',
'System Name' => '数据接口站',
'System' => '系统',
/* 系统信息 结束 */
/* 标题 开始 */
'Console' => '控制台',
/* 标题 结束 */
/* 系统导航栏 开始 */
'Home' => '首页',
'About' => '关于我们',
'Contact' => '联系我们',
'Sign Up' => '注册',
'Login' => '登陆',
'Logout' => '退出',
'Api' => '我的接口',
'Ali SMS' => '云短信',
/* 系统导航栏 结束 */
/* 按钮 开始 */
'Profile' => '个人资料',
'Settings' => '设置',
'Logout' => '退出系统',
'Signup' => '注册',
'Login' => '登录',
'Create' => '创建',
'Update' => '更新',
'Delete' => '删除',
'View' => '查看',
'List' => '列表',
'Submit' => '提交',
'Show' => '显示',
'Hide' => '隐藏',
'Back' => '返回',
'Refresh' => '刷新',
'Cancel' => '取消',
'Recovery' => '恢复',
'Set Password' => '修改密码',
'Reset Password' => '重置密码',
/* 按钮 结束 */
/* 具体页面文字 开始 */
//联系我们
'Page:Contact Tips' => '您可通过填写下面的表单,与我们取得联系。' ,
//If you have business inquiries or other questions, please fill out the following form to contact us. Thank you.
'Page:Signup Tips' => '您可通过填写下面的表单,与我们取得联系。' ,
//Please fill out the following fields to signup:
/* 具体页面文字 结束 */
/* 提示 开始 */
//以下是提示句子
'The site is now offline. Please view later…' => '站点已关闭,请稍后再访问!',
/* 提示 结束 */
/* 默认用语 开始 */
'Default Realty s_sn_title' => '房产模型实例',
'Default Realty f_sn_title' => '楼盘实例',
'Default Realty o_sn_title' => '楼盘户型设置集',
'Default Page s_sn_title' => '页面模型',
'Default Page f_sn_title' => '页面实例',
'Default Page o_sn_title' => '页面内容集',
'Default Metadata s_sn_title' => '元数据模型',
'Default Metadata f_sn_title' => '元数据实例',
'Default Metadata o_sn_title' => '元数据内容集',
'Default Setting s_sn_title' => '客户端设置实例',
'Default Setting f_sn_title' => '客户端系统设置实例',
'Default Setting o_sn_title' => '客户端系统设置集',
/* 默认用语 结束 */
];
+75
View File
@@ -0,0 +1,75 @@
<?php
/**
* @Author: fm453
* @Date: 2019-01-20 12:21:10
* @Last Modified by: fm453
* @Last Modified time: 2019-01-20 12:21:19
* @Email: fm453@lukegzs.com
*/
namespace common\models;
use Yii;
use yii\base\NotSupportedException;
use yii\behaviors\TimestampBehavior;
use yii\db\ActiveRecord;
use yii\web\IdentityInterface;
class CAccess extends ActiveRecord
{
/**
* @inheritdoc
*/
public static function tableName()
{
return '{{%c_access}}';
}
/**
* @inheritdoc
*/
public function behaviors()
{
return [
TimestampBehavior::className(),
];
}
/**
* @inheritdoc
*/
public static function findIdentity($id)
{
return static::findOne(['id' => $id]);
}
/**
* @inheritdoc
*/
public static function findIdentityByAccessToken($token,$type=null)
{
return static::findOne(['accesstoken' => $token]);
}
/**
* Finds user by username
*
* @param string $username
* @return static|null
*/
public static function findByUsername($username)
{
return static::findOne(['username' => $username]);
}
/**
* @inheritdoc
*/
public function getId()
{
return $this->getPrimaryKey();
}
}
+79
View File
@@ -0,0 +1,79 @@
<?php
/**
* @Author: fm453
* @Date: 2018-11-22 02:10:33
* @Last Modified by: fm453
* @Last Modified time: 2019-10-07 17:20:58
* @Email: fm453@lukegzs.com
*/
namespace common\models;
use Yii;
/**
* This is the model class for table "c_attachment".
*
* @property int $id
* @property int $pid 平台ID
* @property int $mid 关联会员ID
* @property int $uid 关联管理员ID
* @property int $type 附件类型
* @property string $title 附件标题
* @property string $route 附件路径
* @property int $filesize 附件大小(byte)
* @property string $options 额外参数
* @property int $status_code 状态代码
* @property int $deleted 是否删除
* @property int $update_at 数据更新时间
* @property int $create_at 数据创建时间
*/
class CAttachment extends \yii\db\ActiveRecord
{
/**
* @inheritdoc
*/
public static function tableName()
{
return 'c_attachment';
}
/**
* @inheritdoc
*/
public function rules()
{
return [
[['siteid','pid', 'mid', 'uid', 'type', 'filesize', 'update_at', 'create_at'], 'required'],
[['siteid','pid', 'mid', 'uid', 'type', 'filesize', 'status_code', 'update_at', 'create_at'], 'integer'],
[['options'], 'string'],
[['title', 'route'], 'string', 'max' => 255],
[['deleted'], 'string', 'max' => 1],
];
}
/**
* @inheritdoc
*/
public function attributeLabels()
{
return [
'id' => Yii::t('app', 'ID'),
'siteid' => Yii::t('app', '站点ID'),
'pid' => Yii::t('app', '平台ID'),
'mid' => Yii::t('app', '关联会员ID'),
'uid' => Yii::t('app', '关联管理员ID'),
'type' => Yii::t('app', '附件类型'),
'title' => Yii::t('app', '附件标题'),
'route' => Yii::t('app', '附件路径'),
'filesize' => Yii::t('app', '附件大小(byte)'),
'options' => Yii::t('app', '额外参数'),
'status_code' => Yii::t('app', '状态代码'),
'deleted' => Yii::t('app', '是否删除'),
'update_at' => Yii::t('app', '数据更新时间'),
'create_at' => Yii::t('app', '数据创建时间'),
];
}
}
+48
View File
@@ -0,0 +1,48 @@
<?php
namespace common\models;
use Yii;
/**
* This is the model class for table "log".
*
* @property string $username
* @property string $ip
* @property string $data
* @property string $create_time
*/
class CLog extends \yii\db\ActiveRecord
{
/**
* @inheritdoc
*/
public static function tableName()
{
return '{{%c_log}}';
}
/**
* @inheritdoc
*/
public function rules()
{
return [
[['username', 'create_time'], 'string', 'max' => 32],
[['ip', 'data'], 'string', 'max' => 64],
];
}
/**
* @inheritdoc
*/
public function attributeLabels()
{
return [
'username' => 'Username',
'ip' => 'Ip',
'data' => 'Data',
'create_time' => 'Create Time',
];
}
}
+25
View File
@@ -0,0 +1,25 @@
<?php
/**
* @Author: fm453
* @Date: 2019-01-20 12:21:10
* @Last Modified by: fm453
* @Last Modified time: 2019-10-04 16:27:55
* @Email: fm453@lukegzs.com
*/
namespace common\models;
use Yii;
use yii\db\ActiveRecord;
class CSms extends ActiveRecord
{
/**
* @inheritdoc
*/
public static function tableName()
{
return '{{%c_sms}}';
}
}
+25
View File
@@ -0,0 +1,25 @@
<?php
/**
* @Author: fm453
* @Date: 2019-01-20 12:21:10
* @Last Modified by: fm453
* @Last Modified time: 2019-10-04 16:27:18
* @Email: fm453@lukegzs.com
*/
namespace common\models;
use Yii;
use yii\db\ActiveRecord;
class CVcode extends ActiveRecord
{
/**
* @inheritdoc
*/
public static function tableName()
{
return '{{%c_vcode}}';
}
}
+201
View File
@@ -0,0 +1,201 @@
<?php
/**
* @Author: fm453
* @Date: 2021-09-11 00:36:07
* @Last Modified by: fm453
* @Last Modified time: 2021-09-11 07:20:34
* @Email: fm453@lukegzs.com
*/
namespace common\models;
use Yii;
use yii\base\NotSupportedException;
use yii\behaviors\TimestampBehavior;
use yii\db\ActiveRecord;
use yii\web\IdentityInterface;
/**
* Fans model
*
* @property integer $id
* @property string $username
* @property string $password_hash
* @property string $password_reset_token
* @property string $email
* @property string $auth_key
* @property integer $status
* @property integer $created_at
* @property integer $updated_at
* @property string $password write-only password
*/
class Fans extends ActiveRecord implements IdentityInterface
{
const STATUS_DELETED = 0;
const STATUS_ACTIVE = 10;
/**
* @inheritdoc
*/
public static function tableName()
{
return '{{%c_fans}}';
}
/**
* @inheritdoc
*/
public function behaviors()
{
return [
TimestampBehavior::className(),
];
}
/**
* @inheritdoc
*/
public function rules()
{
return [
['status', 'default', 'value' => self::STATUS_ACTIVE],
['status', 'in', 'range' => [self::STATUS_ACTIVE, self::STATUS_DELETED]],
[['email','mobile'], 'unique'],
//去除首尾空白
[['mobile','email','from'], 'filter', 'filter' => 'trim'],
];
}
/**
* @inheritdoc
*/
public static function findIdentity($id)
{
return static::findOne(['id' => $id, 'status' => self::STATUS_ACTIVE]);
}
/**
* @inheritdoc
*/
public static function findIdentityByAccessToken($token, $type = null)
{
throw new NotSupportedException('"findIdentityByAccessToken" is not implemented.');
}
/**
* Finds user by username
*
* @param string $username
* @return static|null
*/
public static function findByUsername($username)
{
return static::findOne(['mobile' => $username, 'status' => self::STATUS_ACTIVE]);
}
/**
* Finds user by password reset token
*
* @param string $token password reset token
* @return static|null
*/
public static function findByPasswordResetToken($token)
{
if (!static::isPasswordResetTokenValid($token)) {
return null;
}
return static::findOne([
'password_reset_token' => $token,
'status' => self::STATUS_ACTIVE,
]);
}
/**
* Finds out if password reset token is valid
*
* @param string $token password reset token
* @return bool
*/
public static function isPasswordResetTokenValid($token)
{
if (empty($token)) {
return false;
}
$timestamp = (int) substr($token, strrpos($token, '_') + 1);
$expire = Yii::$app->params['user.passwordResetTokenExpire'];
return $timestamp + $expire >= time();
}
/**
* @inheritdoc
*/
public function getId()
{
return $this->getPrimaryKey();
}
/**
* @inheritdoc
*/
public function getAuthKey()
{
return $this->auth_key;
}
/**
* @inheritdoc
*/
public function validateAuthKey($authKey)
{
return $this->getAuthKey() === $authKey;
}
/**
* Validates password
*
* @param string $password password to validate
* @return bool if password provided is valid for current user
*/
public function validatePassword($password)
{
return Yii::$app->security->validatePassword($password, $this->password_hash);
}
/**
* Generates password hash from password and sets it to the model
*
* @param string $password
*/
public function setPassword($password)
{
$this->password_hash = Yii::$app->security->generatePasswordHash($password);
}
/**
* Generates "remember me" authentication key
*/
public function generateAuthKey()
{
$this->auth_key = Yii::$app->security->generateRandomString();
}
/**
* Generates new password reset token
*/
public function generatePasswordResetToken()
{
$this->password_reset_token = Yii::$app->security->generateRandomString() . '_' . time();
}
/**
* Removes password reset token
*/
public function removePasswordResetToken()
{
$this->password_reset_token = null;
}
}
+52
View File
@@ -0,0 +1,52 @@
<?php
namespace common\models;
use Yii;
/**
* This is the model class for table "c_logs".
*
* @property string $username
* @property string $ip
* @property string $data
* @property string $create_time
*/
class Logs extends \yii\db\ActiveRecord
{
/**
* @inheritdoc
*/
public static function tableName()
{
return '{{%c_logs}}';
}
/**
* @inheritdoc
*/
public function rules()
{
return [
[['username', 'create_time'], 'string', 'max' => 32],
[['ip'], 'string', 'max' => 64],
[['uid'], 'string', 'max' => 11],
[['usertype'], 'string', 'max' => 1],
[['file','m','v','c','a','domain'], 'string', 'max' => 255],
];
}
/**
* @inheritdoc
*/
public function attributeLabels()
{
return [
'username' => Yii::t('common' ,'Username'),
'usertype' => Yii::t('common' ,'Usertype'),
'ip' => Yii::t('common' ,'Ip'),
'data' => Yii::t('common' ,'Do Data'),
'create_time' => Yii::t('common' ,'Create Time'),
];
}
}
+240
View File
@@ -0,0 +1,240 @@
<?php
/**
* @Author: fm453
* @Date: 2021-09-10 18:26:06
* @Last Modified by: fm453
* @Last Modified time: 2021-09-11 00:25:31
* @Email: fm453@lukegzs.com
*/
namespace common\models;
use Yii;
use yii\base\NotSupportedException;
use yii\behaviors\TimestampBehavior;
use yii\db\ActiveRecord;
use yii\web\IdentityInterface;
/**
* Member model
*
* @property integer $id
* @property string $username
* @property string $password_hash
* @property string $password_reset_token
* @property string $email
* @property string $auth_key
* @property integer $status
* @property integer $created_at
* @property integer $updated_at
* @property string $password write-only password
*/
class Member extends ActiveRecord implements IdentityInterface
{
const STATUS_DELETED = 0;
const STATUS_ACTIVE = 1;
const STATUS_MAX = 1;
/**
* @inheritdoc
*/
public static function tableName()
{
return '{{%c_member}}';
}
/**
* @inheritdoc
*/
public function behaviors()
{
return [
TimestampBehavior::className(),
];
}
/**
* @inheritdoc
*/
public function rules()
{
return [
[['username','mobile'], 'required'],
[['status', 'created_at', 'updated_at'], 'integer'],
['status', 'default', 'value' => self::STATUS_ACTIVE],
['status', 'in', 'range' => [self::STATUS_MAX, self::STATUS_DELETED]],
[['password_hash', 'password_reset_token', 'email'], 'string', 'max' => 255],
[['username','auth_key'], 'string', 'max' => 32],
[['mobile'], 'string', 'max' => 20],
[['email','mobile'], 'unique'], //手机号或邮箱用于登陆,username不登陆
//去除首尾空白
[['username', 'mobile', 'email'], 'filter', 'filter' => 'trim'],
];
}
/**
* @inheritdoc
*/
public function attributeLabels()
{
return [
'id' => 'ID',
'username' => Yii::t('common' ,'Username'),
'auth_key' => Yii::t('common' ,'Password'),
'password_hash' => 'Password Hash',
'password_reset_token' => 'Password Reset Token',
'email' => Yii::t('common' ,'Email'),
'mobile' => Yii::t('common' ,'Mobile'),
'status' => 'Status',
'created_at' => 'Created At',
'updated_at' => 'Updated At',
];
}
/**
* @inheritdoc
*/
public static function findIdentity($id)
{
return static::findOne(['id' => $id, 'status' => self::STATUS_ACTIVE]);
}
public static function findById($id)
{
return static::findOne(['id' => $id]);
}
/**
* @inheritdoc
*/
public static function findIdentityByAccessToken($token, $type = null)
{
throw new NotSupportedException('"findIdentityByAccessToken" is not implemented.');
}
/**
* Finds user by username
*
* @param string $username
* @return static|null
*/
public static function findByUsername($username)
{
return static::findOne(['username' => $username, 'status' => self::STATUS_ACTIVE]);
}
public static function findByMobile($mobile)
{
return static::findOne(['mobile' => $mobile, 'status' => self::STATUS_ACTIVE]);
}
/**
* Finds user by password reset token
*
* @param string $token password reset token
* @return static|null
*/
public static function findByPasswordResetToken($token)
{
if (!static::isPasswordResetTokenValid($token)) {
return null;
}
return static::findOne([
'password_reset_token' => $token,
'status' => self::STATUS_ACTIVE,
]);
}
/**
* Finds out if password reset token is valid
*
* @param string $token password reset token
* @return bool
*/
public static function isPasswordResetTokenValid($token)
{
if (empty($token)) {
return false;
}
$timestamp = (int) substr($token, strrpos($token, '_') + 1);
$expire = Yii::$app->params['user.passwordResetTokenExpire'];
return $timestamp + $expire >= time();
}
/**
* @inheritdoc
*/
public function getId()
{
return $this->getPrimaryKey();
}
/**
* @inheritdoc
*/
public function getAuthKey()
{
return $this->auth_key;
}
/**
* @inheritdoc
*/
public function validateAuthKey($authKey)
{
return $this->getAuthKey() === $authKey;
}
/**
* Validates password
*
* @param string $password password to validate
* @return bool if password provided is valid for current user
*/
public function validatePassword($password)
{
return Yii::$app->security->validatePassword($password, $this->password_hash);
}
/**
* Generates password hash from password and sets it to the model
*
* @param string $password
*/
public function setPassword($password)
{
$this->password_hash = Yii::$app->security->generatePasswordHash($password);
}
/**
* Generates "remember me" authentication key
*/
public function generateAuthKey()
{
$this->auth_key = Yii::$app->security->generateRandomString();
}
/**
* Generates new password reset token
*/
public function generatePasswordResetToken()
{
$this->password_reset_token = Yii::$app->security->generateRandomString() . '_' . time();
}
/**
* Removes password reset token
*/
public function removePasswordResetToken()
{
$this->password_reset_token = null;
}
// //获取所有用户
// public function get_all_user(){
// $where='';
// $user = Yii::$app->db->createCommand('select * from '. tableName(). $where)->queryAll();
// return $user;
// }
}
+242
View File
@@ -0,0 +1,242 @@
<?php
namespace common\models;
use Yii;
use yii\base\NotSupportedException;
use yii\behaviors\TimestampBehavior;
use yii\db\ActiveRecord;
use yii\web\IdentityInterface;
/**
* User model
*
* @property integer $id
* @property string $username
* @property string $password_hash
* @property string $password_reset_token
* @property string $verification_token
* @property string $email
* @property string $auth_key
* @property integer $status
* @property integer $created_at
* @property integer $updated_at
* @property string $password write-only password
*/
class User extends ActiveRecord implements IdentityInterface
{
const STATUS_DELETED = 0;
const STATUS_INACTIVE = 9;
const STATUS_ACTIVE = 10;
/**
* @inheritdoc
*/
public static function tableName()
{
return '{{%c_user}}';
}
/**
* @inheritdoc
*/
public function behaviors()
{
return [
TimestampBehavior::className(),
];
}
public static function status()
{
return [
0 => ['title'=>'剔除','css'=>'default'],
1 => ['title'=>'未知','css'=>'default'],
9 => ['title'=>'停用','css'=>'warning'],
10 => ['title'=>'启用','css'=>'success']
];
}
/**
* @inheritdoc
*/
public function rules()
{
return [
[['username','email'], 'required'],
[['status', 'created_at', 'updated_at'], 'integer'],
['status', 'default', 'value' => self::STATUS_INACTIVE],
['status', 'in', 'range' => [self::STATUS_ACTIVE, self::STATUS_INACTIVE, self::STATUS_DELETED]],
[['password_hash', 'password_reset_token', 'email'], 'string', 'max' => 255],
[['username','auth_key'], 'string', 'max' => 32],
[['username', 'email','mobile'], 'unique'],
//去除首尾空白
[['username', 'mobile', 'email'], 'filter', 'filter' => 'trim'],
];
}
public function attributeLabels() {
return [
'id' => 'ID',
'username' => Yii::t('common' ,'Username'),
'avatar' => Yii::t('common' ,'Avatar'),
'auth_key' => Yii::t('common' ,'Password'),
'password_hash' => 'Password Hash',
'email' => Yii::t('common' ,'Email'),
'mobile' => Yii::t('common' ,'Mobile'),
'status' => Yii::t('common' ,'Status'),
'created_at' => 'Created At',
'updated_at' => 'Updated At',
'role' => Yii::t('common' ,'Role'),
];
}
/**
* @inheritdoc
*/
public static function findIdentity($id)
{
return static::findOne(['id' => $id, 'status' => self::STATUS_ACTIVE]);
}
/**
* @inheritdoc
*/
public static function findIdentityByAccessToken($token, $type = null)
{
throw new NotSupportedException('"findIdentityByAccessToken" is not implemented.');
}
/**
* Finds user by username
*
* @param string $username
* @return static|null
*/
public static function findByUsername($username)
{
return static::findOne(['username' => $username, 'status' => self::STATUS_ACTIVE]);
}
/**
* Finds user by password reset token
*
* @param string $token password reset token
* @return static|null
*/
public static function findByPasswordResetToken($token)
{
if (!static::isPasswordResetTokenValid($token)) {
return null;
}
return static::findOne([
'password_reset_token' => $token,
'status' => self::STATUS_ACTIVE,
]);
}
/**
* Finds user by verification email token
*
* @param string $token verify email token
* @return static|null
*/
public static function findByVerificationToken($token) {
return static::findOne([
'verification_token' => $token,
'status' => self::STATUS_INACTIVE
]);
}
/**
* Finds out if password reset token is valid
*
* @param string $token password reset token
* @return bool
*/
public static function isPasswordResetTokenValid($token)
{
if (empty($token)) {
return false;
}
$timestamp = (int) substr($token, strrpos($token, '_') + 1);
$expire = Yii::$app->params['user.passwordResetTokenExpire'];
return $timestamp + $expire >= time();
}
/**
* @inheritdoc
*/
public function getId()
{
return $this->getPrimaryKey();
}
/**
* @inheritdoc
*/
public function getAuthKey()
{
return $this->auth_key;
}
/**
* @inheritdoc
*/
public function validateAuthKey($authKey)
{
return $this->getAuthKey() === $authKey;
}
/**
* Validates password
*
* @param string $password password to validate
* @return bool if password provided is valid for current user
*/
public function validatePassword($password)
{
return Yii::$app->security->validatePassword($password, $this->password_hash);
}
/**
* Generates password hash from password and sets it to the model
*
* @param string $password
*/
public function setPassword($password)
{
$this->password_hash = Yii::$app->security->generatePasswordHash($password);
}
/**
* Generates "remember me" authentication key
*/
public function generateAuthKey()
{
$this->auth_key = Yii::$app->security->generateRandomString();
}
/**
* Generates new password reset token
*/
public function generatePasswordResetToken()
{
$this->password_reset_token = Yii::$app->security->generateRandomString() . '_' . time();
}
public function generateEmailVerificationToken()
{
$this->verification_token = Yii::$app->security->generateRandomString() . '_' . time();
}
/**
* Removes password reset token
*/
public function removePasswordResetToken()
{
$this->password_reset_token = null;
}
}
+47
View File
@@ -0,0 +1,47 @@
<?php
namespace common\models\base;
use Yii;
use yii\db\ActiveRecord;
/**
* 重写数据基类
* @author
*
*/
class BaseModel extends ActiveRecord
{
/**
* 获取列表(分页)
* @param unknown $query
* @param number $curPage
* @param number $pageSize
* @param string $search
* @return multitype:number multitype: |unknown
*/
public function getPages($query,$curPage = 1,$pageSize = 10 ,$search = null)
{
if($search)
$query = $query->andFilterWhere($search);
$data['count'] = $query->count();
if(!$data['count'])
return ['count'=>0,'curPage'=>$curPage,'pageSize'=>$pageSize,'start'=>0,'end'=>0,'data'=>[]];
$curPage = (ceil($data['count']/$pageSize)<$curPage)?ceil($data['count']/$pageSize):$curPage;
$data['curPage'] = $curPage;
//每页显示条数
$data['pageSize'] = $pageSize;
//起始页
$data['start'] = ($curPage-1)*$pageSize+1;
//末页
$data['end'] = (ceil($data['count']/$pageSize) == $curPage)?$data['count']:($curPage-1)*$pageSize+$pageSize;
//数据
$data['data'] = $query->offset(($curPage-1)*$pageSize)->limit($pageSize)->asArray()->all();
return $data;
}
}
+9
View File
@@ -0,0 +1,9 @@
<?php
defined('YII_DEBUG') or define('YII_DEBUG', true);
defined('YII_ENV') or define('YII_ENV', 'test');
defined('YII_APP_BASE_PATH') or define('YII_APP_BASE_PATH', __DIR__.'/../../');
require_once __DIR__ . '/../../vendor/autoload.php';
require_once __DIR__ . '/../../vendor/yiisoft/yii2/Yii.php';
require __DIR__ . '/../config/bootstrap.php';
+14
View File
@@ -0,0 +1,14 @@
<?php
return [
[
'username' => 'bayer.hudson',
'auth_key' => 'HP187Mvq7Mmm3CTU80dLkGmni_FUH_lR',
//password_0
'password_hash' => '$2y$13$EjaPFBnZOQsHdGuHI.xvhuDp1fHpo8hKRSk6yshqa9c5EG8s3C3lO',
'password_reset_token' => 'ExzkCOaYc1L8IOBs4wdTGGbgNiG3Wz1I_1402312317',
'created_at' => '1402312317',
'updated_at' => '1402312317',
'email' => 'nicole.paucek@schultz.info',
],
];
+2
View File
@@ -0,0 +1,2 @@
*
!.gitignore
+1
View File
@@ -0,0 +1 @@
_generated
+25
View File
@@ -0,0 +1,25 @@
<?php
namespace common\tests;
/**
* Inherited Methods
* @method void wantToTest($text)
* @method void wantTo($text)
* @method void execute($callable)
* @method void expectTo($prediction)
* @method void expect($prediction)
* @method void amGoingTo($argumentation)
* @method void am($role)
* @method void lookForwardTo($achieveValue)
* @method void comment($description)
* @method \Codeception\Lib\Friend haveFriend($name, $actorClass = NULL)
*
* @SuppressWarnings(PHPMD)
*/
class UnitTester extends \Codeception\Actor
{
use _generated\UnitTesterActions;
/**
* Define custom actions here
*/
}
+7
View File
@@ -0,0 +1,7 @@
suite_namespace: common\tests\unit
actor: UnitTester
bootstrap: false
modules:
enabled:
- Yii2:
part: fixtures
+67
View File
@@ -0,0 +1,67 @@
<?php
namespace common\tests\unit\models;
use Yii;
use common\models\LoginForm;
use common\fixtures\UserFixture;
/**
* Login form test
*/
class LoginFormTest extends \Codeception\Test\Unit
{
/**
* @var \common\tests\UnitTester
*/
protected $tester;
/**
* @return array
*/
public function _fixtures()
{
return [
'user' => [
'class' => UserFixture::className(),
'dataFile' => codecept_data_dir() . 'user.php'
]
];
}
public function testLoginNoUser()
{
$model = new LoginForm([
'username' => 'not_existing_username',
'password' => 'not_existing_password',
]);
expect('model should not login user', $model->login())->false();
expect('user should not be logged in', Yii::$app->user->isGuest)->true();
}
public function testLoginWrongPassword()
{
$model = new LoginForm([
'username' => 'bayer.hudson',
'password' => 'wrong_password',
]);
expect('model should not login user', $model->login())->false();
expect('error message should be set', $model->errors)->hasKey('password');
expect('user should not be logged in', Yii::$app->user->isGuest)->true();
}
public function testLoginCorrect()
{
$model = new LoginForm([
'username' => 'bayer.hudson',
'password' => 'password_0',
]);
expect('model should login user', $model->login())->true();
expect('error message should not be set', $model->errors)->hasntKey('password');
expect('user should be logged in', Yii::$app->user->isGuest)->false();
}
}
+76
View File
@@ -0,0 +1,76 @@
<?php
namespace common\widgets;
use Yii;
use yii\bootstrap5\Widget as Widget;
/**
* Alert widget renders a message from session flash. All flash messages are displayed
* in the sequence they were assigned using setFlash. You can set message as following:
*
* ```php
* Yii::$app->session->setFlash('error', 'This is the message');
* Yii::$app->session->setFlash('success', 'This is the message');
* Yii::$app->session->setFlash('info', 'This is the message');
* ```
*
* Multiple messages could be set as follows:
*
* ```php
* Yii::$app->session->setFlash('error', ['Error 1', 'Error 2']);
* ```
*
* @author Kartik Visweswaran <kartikv2@gmail.com>
* @author Alexander Makarov <sam@rmcreative.ru>
*/
class Alert extends Widget
{
/**
* @var array the alert types configuration for the flash messages.
* This array is setup as $key => $value, where:
* - key: the name of the session flash variable
* - value: the bootstrap alert type (i.e. danger, success, info, warning)
*/
public $alertTypes = [
'error' => 'alert-danger',
'danger' => 'alert-danger',
'success' => 'alert-success',
'info' => 'alert-info',
'warning' => 'alert-warning'
];
/**
* @var array the options for rendering the close button tag.
* Array will be passed to [[\yii\bootstrap\Alert::closeButton]].
*/
public $closeButton = [];
/**
* {@inheritdoc}
*/
public function run()
{
$session = Yii::$app->session;
$flashes = $session->getAllFlashes();
$appendClass = isset($this->options['class']) ? ' ' . $this->options['class'] : '';
foreach ($flashes as $type => $flash) {
if (!isset($this->alertTypes[$type])) {
continue;
}
foreach ((array) $flash as $i => $message) {
echo \yii\bootstrap\Alert::widget([
'body' => $message,
'closeButton' => $this->closeButton,
'options' => array_merge($this->options, [
'id' => $this->getId() . '-' . $type . '-' . $i,
'class' => $this->alertTypes[$type] . $appendClass,
]),
]);
}
$session->removeFlash($type);
}
}
}