Model.php
2.35 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
<?php
namespace common\models;
use yii\db\ActiveRecord;
use common\helpers\SqlHelper;
use common\helpers\Utils;
use domain\device\models\Device;
/**
* 型号
* This is the model class for table "{{%model}}".
*/
class Model extends ActiveRecord
{
/**
* @inheritdoc
*/
public static function tableName()
{
return '{{%model}}';
}
/* @inheritdoc */
public function init()
{
parent::init();
$this->attachEvents();
}
/* @inheritdoc */
public function attachEvents()
{
$this->on(static::EVENT_BEFORE_INSERT, [$this, 'onBeforeInsert']);
}
/**
* 记录插入前的回调处理
*/
public function onBeforeInsert()
{
$this->uuid = Utils::genUUID();
}
public function getModelList($offset,$limit,$map)
{
$sql = "select m.id,m.model,d.device_name,b.chinese_name,t.name as cat_name from model as m left join device as d on m.device_cat_id=d.device_cat_id and m.id=d.model_id left join brand as b on b.id=m.brand_id
left join device_cat as t on t.id=m.device_cat_id ";
if(sizeof($map) > 0){
$sql = $sql." where ".SqlHelper::parseSql($map);
}
$sql = $sql." order by m.id desc limit {$offset},$limit ";
return self::findBySql($sql)->asArray()->all();
}
/**
* 获取总数
* @return mixed
*/
public function getModelListCount($map)
{
$sql = "select count(m.id) as cnt from model as m left join device as d on m.device_cat_id=d.device_cat_id and m.id=d.model_id left join brand as b on b.id=m.brand_id
left join device_cat as t on t.id=m.device_cat_id ";
if(sizeof($map) > 0){
$sql = $sql." where ".SqlHelper::parseSql($map);
}
$model = self::findBySql($sql);
return $model->asArray()->one()['cnt'];
}
static public function checkLimitModel($modelName)
{
if(empty($modelName)){
return '';
}
$modelNameArr = explode('-',$modelName);
$speedArr = array(Device::HIGH_FLAG,Device::MEDIUM_FLAG,Device::LOW_FLAG,Device::NONE_FLAG);
if($modelNameArr[0] == 'JIWORK' &&
(isset($modelNameArr[1]) && in_array($modelNameArr[1],$speedArr)) &&
isset($modelNameArr[2])
){
return true;
}else{
return false;
}
}
}