init
This commit is contained in:
135
commands/AssignController.php
Normal file
135
commands/AssignController.php
Normal file
@@ -0,0 +1,135 @@
|
||||
<?php
|
||||
|
||||
/**
|
||||
* @link http://www.yiiframework.com/
|
||||
* @copyright Copyright (c) 2008 Yii Software LLC
|
||||
* @license http://www.yiiframework.com/license/
|
||||
*/
|
||||
|
||||
namespace app\commands;
|
||||
|
||||
use yii\console\Controller;
|
||||
use yii\console\ExitCode;
|
||||
|
||||
/**
|
||||
* This command echoes the first argument that you have entered.
|
||||
*
|
||||
* This command is provided as an example for you to learn how to create console commands.
|
||||
*
|
||||
* @author Qiang Xue <qiang.xue@gmail.com>
|
||||
* @since 2.0
|
||||
*/
|
||||
class AssignController extends Controller {
|
||||
|
||||
public $pharse = [
|
||||
1 => "Phân cảnh",
|
||||
2 => "Vẽ background",
|
||||
3 => "Vẽ động",
|
||||
4 => "Đọc thoại",
|
||||
5 => "Sạch xen",
|
||||
6 => "Kỹ thuật"
|
||||
];
|
||||
|
||||
/**
|
||||
* This command echoes what you have entered as the message.
|
||||
* @param string $message the message to be echoed.
|
||||
* @return int Exit code
|
||||
*/
|
||||
public function actionIndex() {
|
||||
$config = \app\models\Config::findOne(['config_key' => 'auto_assign'])->config;
|
||||
$time = \app\models\Config::findOne(['config_key' => 'time_auto_assign'])->config * 60;
|
||||
if ($config === '1') {
|
||||
$query = \app\models\Projects::find();
|
||||
$query->andFilterWhere(["OR", ['p1' => 0], ['p2' => 0], ['p3' => 0], ['p4' => 0], ['p5' => 0], ['p6' => 0]]);
|
||||
$projects = $query->all();
|
||||
foreach ($projects as $k => $project) {
|
||||
if ($project->p1 == 0) {
|
||||
$this->assign($time, $project, 1);
|
||||
} else {
|
||||
if ($project->p2 == 0) {
|
||||
$this->assign($time, $project, 2);
|
||||
} else {
|
||||
if ($project->p5 == 0) {
|
||||
$this->assign($time, $project, 5);
|
||||
} elseif ($project->p6 == 0) {
|
||||
$this->assign($time, $project, 6);
|
||||
}
|
||||
}
|
||||
if ($project->p3 == 0) {
|
||||
$this->assign($time, $project, 3);
|
||||
}
|
||||
if ($project->p4 == 0) {
|
||||
$this->assign($time, $project, 4);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
return;
|
||||
}
|
||||
|
||||
public function assign($time, $project, $pid) {
|
||||
$project_id = $project->id;
|
||||
$role = '';
|
||||
if ($pid == 1) {
|
||||
$role = 'hoa_sy_phan_canh';
|
||||
}
|
||||
if (in_array($pid, [2, 3, 4])) {
|
||||
if ($pid == 2) {
|
||||
$role = 'hoa_sy_to_mau';
|
||||
}
|
||||
if ($pid == 3) {
|
||||
$role = 'hoa_sy_ve_dong';
|
||||
}
|
||||
if ($pid == 4) {
|
||||
$role = 'doc_thoai';
|
||||
}
|
||||
$timeConfig = time() - $time;
|
||||
$check = \app\models\Results::find()->andWhere(['project_id' => $project_id, 'p_id' => 1, 'status' => 1])->andWhere(["<", "modified_at", $timeConfig])->count();
|
||||
if ($check == 0) {
|
||||
return;
|
||||
}
|
||||
}
|
||||
if ($pid == 5) {
|
||||
$role = 'hoa_sy_sach_xen';
|
||||
$timeConfig = time() - $time;
|
||||
$check = \app\models\Results::find()->andWhere(['project_id' => $project_id, 'p_id' => 2, 'status' => 1])->andWhere(["<", "modified_at", $timeConfig])->count();
|
||||
if ($check == 0) {
|
||||
return;
|
||||
}
|
||||
}
|
||||
if ($pid == 6) {
|
||||
$role = 'ky_thuat';
|
||||
$timeConfig = time() - $time;
|
||||
$check = \app\models\Results::find()->andWhere(['project_id' => $project_id, 'p_id' => 5, 'status' => 1])->andWhere(["<", "modified_at", $timeConfig])->count();
|
||||
if ($check == 0) {
|
||||
return;
|
||||
}
|
||||
}
|
||||
$authors = \app\models\AuthAssignment::find()->andWhere(['item_name' => $role])->all();
|
||||
foreach ($authors as $k => $v) {
|
||||
$currentProjects = \app\models\Results::find()->andWhere(['u_id' => $v->user_id, 'content' => null])->count();
|
||||
if (\app\models\User::findOne($v->user_id)->quota > $currentProjects) {
|
||||
\app\models\Projects::updateAll(['p' . $pid => $v->user_id], ['id' => $project_id]);
|
||||
$model = new \app\models\Results();
|
||||
$check = $model->create(['project_id' => $project_id, 'p_id' => $pid, 'u_id' => $v->user_id]);
|
||||
if ($check) {
|
||||
$notification = new \app\models\Notification();
|
||||
$content = "<b>Hệ thống</b> đã tự động giao quy trình " . $this->pharse[$pid] . " cho bạn trong dự án <b>" . $project->name . "</b>";
|
||||
$notif_id = $notification->create([
|
||||
'content' => $content,
|
||||
'from_user' => 0,
|
||||
'to_user' => $v->user_id,
|
||||
'url' => \yii\helpers\Url::to(['/projects/view', 'id' => $project_id, 'p' => $pid]),
|
||||
'time' => time()
|
||||
]);
|
||||
if ($notif_id) {
|
||||
$notification->sendEmail($notif_id, $v->user_id, $content);
|
||||
}
|
||||
return true;
|
||||
}
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
}
|
||||
34
commands/HelloController.php
Normal file
34
commands/HelloController.php
Normal file
@@ -0,0 +1,34 @@
|
||||
<?php
|
||||
/**
|
||||
* @link http://www.yiiframework.com/
|
||||
* @copyright Copyright (c) 2008 Yii Software LLC
|
||||
* @license http://www.yiiframework.com/license/
|
||||
*/
|
||||
|
||||
namespace app\commands;
|
||||
|
||||
use yii\console\Controller;
|
||||
use yii\console\ExitCode;
|
||||
|
||||
/**
|
||||
* This command echoes the first argument that you have entered.
|
||||
*
|
||||
* This command is provided as an example for you to learn how to create console commands.
|
||||
*
|
||||
* @author Qiang Xue <qiang.xue@gmail.com>
|
||||
* @since 2.0
|
||||
*/
|
||||
class HelloController extends Controller
|
||||
{
|
||||
/**
|
||||
* This command echoes what you have entered as the message.
|
||||
* @param string $message the message to be echoed.
|
||||
* @return int Exit code
|
||||
*/
|
||||
public function actionIndex($message = 'hello world')
|
||||
{
|
||||
echo $message . "\n";
|
||||
|
||||
return ExitCode::OK;
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user