CreateBatchRepository.php
7.13 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
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
<?php
namespace domain\device;
use domain\device\models\CreateBatch;
use yii\db\Expression;
use yii\db\Query;
use domain\device\models\CreateBatch as CreateBatchModel;
use domain\device\models\Device as DeviceModel;
use domain\manufacturer\models\Manufacturer as ManufacturerModel;
use domain\model\models\Model as ModelModel;
use domain\production\models\Production as ProductionModel;
use domain\project\models\Project as ProjectModel;
use domain\device\models\DeviceAuthFail as DeviceAuthFailModel;
class CreateBatchRepository
{
/**
* @param $condition
* @return null|static
*/
static function findOne($condition)
{
return CreateBatchModel::findOne($condition);
}
/**
* @param $type
* @param $keyword
* @return array
*/
static function getSerialNoComponent($type, $keyword)
{
if ('manufacture' == $type) {
$q = new Query();
$q->select(['concat(id, "_", manufacture_no) as uid', 'id','manufacture_no', 'name']);
$q->from('manufacture');
$q->where('id >0');
$list = $q->all();
return $list;
} elseif('project' == $type) {
$q = new Query();
$q->select(['concat(id,"_", project_no) as uid', 'id','project_no', 'name']);
$q->from('project');
$q->where('id >0');
$list = $q->all();
return $list;
} elseif ('model' == $type) {
$q = new Query();
$q->select(['concat(id,"_", model_no) as uid','id','model_no', 'name']);
$q->from('model');
$q->where('id >0');
$list = $q->all();
return $list;
} elseif ('production' == $type) {
$q = new Query();
$q->select(['concat(id,"_", production_no) as uid','id','production_no', 'name']);
$q->from('production');
$q->where('id >0');
$list = $q->all();
return $list;
} else {
return [];
}
}
/**
* @param $where
* @param $offset
* @param $limit
* @return array|\yii\db\ActiveRecord[]
*/
static function getPageList($where, $offset = 0, $limit = 0)
{
$totalNumExpress = new Expression("(select count(*) from ".DeviceModel::tableName(). "as dd where dd.batch_id = a.id and dd.is_delete = 0) as total_num");
$hasAuthNumExpress = new Expression("(select count(*) from ".DeviceModel::tableName(). "as dd where dd.status =".DeviceStatus::HAS_AUTH.' and dd.batch_id = a.id and dd.is_delete = 0) as has_auth_num');
$noAuthNumExpress = new Expression("(select count(*) from ".DeviceModel::tableName(). "as dd where dd.status =".DeviceStatus::NO_AUTH.' and dd.batch_id = a.id and dd.is_delete = 0) as no_auth_num');
$delNumExpress = new Expression("(select count(*) from ".DeviceModel::tableName(). "as dd where dd.is_delete = 1 and dd.batch_id = a.id) as del_num");
$outOfLimitExpress = new Expression("(select count(*) from ".DeviceAuthFailModel::tableName(). "as dd where concat(dd.manufacture_no, dd.project_no, dd.model_no, dd.production_no) = a.batch_no and dd.is_delete = 0) as out_of_num");
$sysFailNumExpress = new Expression("(select count(*) from ".DeviceModel::tableName(). "as dd where dd.status =".DeviceStatus::FAIL_AUTH." and dd.is_delete = 0 and dd.batch_id = a.id) as auth_fail_num");
$handleAuthFailNumExpress = new Expression("(select count(*) from ".DeviceModel::tableName(). "as dd where dd.batch_id = a.id and dd.has_re_auth = 1 and dd.is_delete = 0) as handle_auth_fail_num");
$batchModelFind = CreateBatchModel::find();
$batchModelFind->alias('a');
$batchModelFind->select([
'a.*',
'm.name as manufacture_name','pro.name as project_name','mo.name as model_name','prod.name as production_name',
$totalNumExpress, $hasAuthNumExpress, $noAuthNumExpress, $delNumExpress, $outOfLimitExpress, $sysFailNumExpress, $handleAuthFailNumExpress
]);
$batchModelFind->leftJoin(ManufacturerModel::tableName(). ' m', 'm.id = a.manufacture_id');
$batchModelFind->leftJoin(ProjectModel::tableName(). ' pro', 'pro.id = a.project_id');
$batchModelFind->leftJoin(ModelModel::tableName(). ' mo', 'mo.id = a.model_id');
$batchModelFind->leftJoin(ProductionModel::tableName(). ' prod', 'prod.id = a.production_id');
$batchModelFind->where($where);
$batchModelFind->asArray();
if ($offset) {
$batchModelFind->offset($offset);
}
if ($limit) {
$batchModelFind->limit($limit);
}
$batchModelFind->orderBy('created_at desc');
$all = $batchModelFind->all();
return $all;
}
/**
* @param $where
* @return int|string
*/
static function getPageCount($where)
{
$batchModelFind = CreateBatchModel::find();
$batchModelFind->alias('a');
$batchModelFind->leftJoin(ManufacturerModel::tableName(). ' m', 'm.id = a.manufacture_id');
$batchModelFind->leftJoin(ProjectModel::tableName(). ' pro', 'pro.id = a.project_id');
$batchModelFind->leftJoin(ModelModel::tableName(). ' mo', 'mo.id = a.model_id');
$batchModelFind->leftJoin(ProductionModel::tableName(). ' prod', 'prod.id = a.production_id');
$batchModelFind->where($where);
$count= $batchModelFind->count();
return $count;
}
/**
* @param $batchId
* @return array|null|\yii\db\ActiveRecord
*/
static function getBatchInfo($where)
{
$batchModelFind = CreateBatchModel::find();
$batchModelFind->alias('a');
$batchModelFind->select(['a.*','m.name as manufacture','pro.name as project','mo.name as model','prod.name as production']);
$batchModelFind->leftJoin(ManufacturerModel::tableName(). ' m', 'm.id = a.manufacture_id');
$batchModelFind->leftJoin(ProjectModel::tableName(). ' pro', 'pro.id = a.project_id');
$batchModelFind->leftJoin(ModelModel::tableName(). ' mo', 'mo.id = a.model_id');
$batchModelFind->leftJoin(ProductionModel::tableName(). ' prod', 'prod.id = a.production_id');
$batchModelFind->where($where);
$batchModelFind->asArray();
$info = $batchModelFind->one();
return $info;
}
/**
* @param $batchId
* @return array|null|\yii\db\ActiveRecord
*/
static function getBatchSelectList($where)
{
$batchModelFind = CreateBatchModel::find();
$batchModelFind->alias('a');
$batchModelFind->select(['a.*','m.name as manufacture','pro.name as project','mo.name as model','prod.name as production']);
$batchModelFind->leftJoin(ManufacturerModel::tableName(). ' m', 'm.id = a.manufacture_id');
$batchModelFind->leftJoin(ProjectModel::tableName(). ' pro', 'pro.id = a.project_id');
$batchModelFind->leftJoin(ModelModel::tableName(). ' mo', 'mo.id = a.model_id');
$batchModelFind->leftJoin(ProductionModel::tableName(). ' prod', 'prod.id = a.production_id');
$batchModelFind->where($where);
$batchModelFind->asArray();
$info = $batchModelFind->all();
return $info;
}
}