You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
 
simple-yewu/common/models/InvalidT.php

235 lines
6.7 KiB

<?php
namespace common\models;
use Yii;
/**
* This is the model class for table "invalid_t".
*
* @property integer $id
* @property string $name
* @property integer $parent_id
* @property string $created_at
* @property string $updated_at
*/
class InvalidT extends \common\models\Base
{
/**
* @inheritdoc
*/
public static function tableName()
{
return 'invalid_t';
}
/**
* @inheritdoc
*/
public function rules()
{
return [
[['name'], 'required'],
[['parent_id','difc','paixu_id'], 'integer'],
[['created_at', 'updated_at'], 'safe'],
[['name'], 'string', 'max' => 60],
];
}
/**
* @inheritdoc
*/
public function attributeLabels()
{
return [
'id' => 'ID',
'name' => 'Name',
'parent_id' => 'Parent ID',
'created_at' => 'Created At',
'updated_at' => 'Updated At',
];
}
public function getInvalids()
{
return $this->hasMany(InvalidT::className(),['parent_id'=>'id']);
}
public function getParent()
{
return $this->hasOne(InvalidT::className(),['id'=>'parent_id']);
}
public function hasChild($id)
{
$items = InvalidT::getTree($this->id);
foreach($items as $item) {
if($item->id == $id)
return true;
}
return false;
}
static public function getTree($parent_id=0,$level=0)
{
$items = InvalidT::find()
->where('parent_id='.$parent_id)
->all();
$data = array();
foreach($items as $item) {
$tmp_str = '';
if($level > 1)
$tmp_str .= str_repeat('  ',$level-1);
if($level > 0)
$tmp_str .= str_repeat('  ',1);
$tmp_str .= $item->name;
$item->name = $tmp_str;
$data[] = $item;
$tmp_data = array_merge($data,InvalidT::getTree($item->id,$level+1));
$data = $tmp_data;
}
return $data;
}
// static public function getTreeCleanOrder($parent_id=0,$level=0)
// {
// $items = InvalidT::find()
// ->where('parent_id='.$parent_id)
// ->orderBy('paixu_id desc')
// ->all();
// $data = array();
// foreach($items as $item) {
// $tmp_str = '';
// if($level > 1)
// $tmp_str .= str_repeat('  ',$level-1);
// if($level > 0)
// $tmp_str .= str_repeat('  ',1);
// $tmp_str .= $item->name;
// $item->name = $tmp_str;
// $data[] = $item;
// $tmp_data = array_merge($data,InvalidT::getTreeCleanOrder($item->id,$level+1));
// $data = $tmp_data;
// }
// return $data;
// }
static public function getTreeXinbao($parent_id=0,$level=0)
{
$items = InvalidT::find()
->where('parent_id='.$parent_id)
->andWhere('id <37')
->all();
$data = array();
foreach($items as $item) {
$tmp_str = '';
if($level > 1)
$tmp_str .= str_repeat('  ',$level-1);
if($level > 0)
$tmp_str .= str_repeat('  ',1);
$tmp_str .= $item->name;
$item->name = $tmp_str;
$data[] = $item;
$tmp_data = array_merge($data,InvalidT::getTree($item->id,$level+1));
$data = $tmp_data;
}
return $data;
}
static public function getTreeXinbaoNew($parent_id=0,$level=0)
{
$items = InvalidT::find()
->where('parent_id='.$parent_id)
->andWhere('difc=3')
// ->andWhere('id <37')
->all();
// dd($items);
$data = array();
foreach($items as $item) {
$tmp_str = '';
if($level > 1)
$tmp_str .= str_repeat('  ',$level-1);
if($level > 0)
$tmp_str .= str_repeat('  ',1);
$tmp_str .= $item->name;
$item->name = $tmp_str;
$data[] = $item;
$tmp_data = array_merge($data,InvalidT::getTree($item->id,$level+1));
$data = $tmp_data;
}
return $data;
}
static public function getTreeXubao($parent_id=0,$level=0)
{
$items = InvalidT::find()
->where('parent_id='.$parent_id)
->andWhere('difc=2')
->all();
$data = array();
foreach($items as $item) {
$tmp_str = '';
if($level > 1)
$tmp_str .= str_repeat('  ',$level-1);
if($level > 0)
$tmp_str .= str_repeat('  ',1);
$tmp_str .= $item->name;
$item->name = $tmp_str;
$data[] = $item;
$tmp_data = array_merge($data,InvalidT::getTree($item->id,$level+1));
$data = $tmp_data;
}
return $data;
}
static public function getTreeClean($parent_id=0,$level=0)
{
$items = InvalidT::find()
->where('parent_id='.$parent_id)
->andWhere('difc=4')
->orderBy('paixu_id desc')
->all();
$data = array();
foreach($items as $item) {
$tmp_str = '';
if($level > 1)
$tmp_str .= str_repeat('  ',$level-1);
if($level > 0)
$tmp_str .= str_repeat('  ',1);
$tmp_str .= $item->name;
$item->name = $tmp_str;
$data[] = $item;
$tmp_data = array_merge($data,InvalidT::getTree($item->id,$level+1));
$data = $tmp_data;
}
return $data;
}
static public function getTrees($parent_id=0,$level=0)
{
$query=InvalidT::find();
$items = $query
// ->where('parent_id='.$parent_id)
->where('id in(9,10,11,12,13,14,15,16,24)')
->all();
// echo $query->createCommand()->rawSql;
$data = array();
foreach($items as $item) {
$tmp_str = '';
if($level > 1)
$tmp_str .= str_repeat('  ',$level-1);
if($level > 0)
$tmp_str .= str_repeat('  ',1);
$tmp_str .= $item->name;
$item->name = $tmp_str;
$data[] = $item;
// $tmp_data = array_merge($data,InvalidT::getTree($item->id,$level+1));
// $data = $tmp_data;
}
return $data;
}
public function getPath()
{
$path = '';
if($this->parent_id > 0) {
$info = $this->parent;
$path .= $info->getPath();
}
return $path.'/'.$this->name;
}
}