931eed21
xu
1. A授权接口开发
|
1
2
3
4
|
<?php
namespace domain\device;
|
a0935a2c
xu
1. F 数据统计添加多个统计维度
|
5
|
use domain\device\models\CreateBatch;
|
ff8327f6
xu
1. F 删除冗余代码
|
6
|
use yii\db\Expression;
|
931eed21
xu
1. A授权接口开发
|
7
|
use yii\db\Query;
|
ff8327f6
xu
1. F 删除冗余代码
|
8
9
|
use domain\device\models\CreateBatch as CreateBatchModel;
use domain\device\models\Device as DeviceModel;
|
ff8327f6
xu
1. F 删除冗余代码
|
10
11
12
13
|
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;
|
a0935a2c
xu
1. F 数据统计添加多个统计维度
|
14
|
use domain\device\models\DeviceAuthFail as DeviceAuthFailModel;
|
ff8327f6
xu
1. F 删除冗余代码
|
15
|
|
931eed21
xu
1. A授权接口开发
|
16
17
18
19
20
21
22
23
24
25
26
27
28
29
|
class CreateBatchRepository
{
/**
* @param $condition
* @return null|static
*/
static function findOne($condition)
{
return CreateBatchModel::findOne($condition);
}
/**
* @param $type
|
b60f5eda
xu
1. 删除部分冗余代码
|
30
|
* @param $keyword
|
931eed21
xu
1. A授权接口开发
|
31
32
|
* @return array
*/
|
b60f5eda
xu
1. 删除部分冗余代码
|
33
|
static function getSerialNoComponent($type, $keyword)
|
931eed21
xu
1. A授权接口开发
|
34
35
36
|
{
if ('manufacture' == $type) {
$q = new Query();
|
b9c38308
xu
1. A OTA版本和APP版本录...
|
37
|
$q->select(['concat(id, "_", manufacture_no) as uid', 'id','manufacture_no', 'name']);
|
931eed21
xu
1. A授权接口开发
|
38
|
$q->from('manufacture');
|
b60f5eda
xu
1. 删除部分冗余代码
|
39
|
$q->where('id >1');
|
b9c38308
xu
1. A OTA版本和APP版本录...
|
40
|
|
931eed21
xu
1. A授权接口开发
|
41
42
43
44
45
|
$list = $q->all();
return $list;
} elseif('project' == $type) {
$q = new Query();
|
b9c38308
xu
1. A OTA版本和APP版本录...
|
46
|
$q->select(['concat(id,"_", project_no) as uid', 'id','project_no', 'name']);
|
931eed21
xu
1. A授权接口开发
|
47
|
$q->from('project');
|
b60f5eda
xu
1. 删除部分冗余代码
|
48
|
$q->where('id >1');
|
b9c38308
xu
1. A OTA版本和APP版本录...
|
49
|
|
931eed21
xu
1. A授权接口开发
|
50
51
52
53
54
|
$list = $q->all();
return $list;
} elseif ('model' == $type) {
$q = new Query();
|
b9c38308
xu
1. A OTA版本和APP版本录...
|
55
|
$q->select(['concat(id,"_", model_no) as uid','id','model_no', 'name']);
|
931eed21
xu
1. A授权接口开发
|
56
|
$q->from('model');
|
b60f5eda
xu
1. 删除部分冗余代码
|
57
|
$q->where('id >1');
|
931eed21
xu
1. A授权接口开发
|
58
59
60
61
62
|
$list = $q->all();
return $list;
} elseif ('production' == $type) {
$q = new Query();
|
b9c38308
xu
1. A OTA版本和APP版本录...
|
63
|
$q->select(['concat(id,"_", production_no) as uid','id','production_no', 'name']);
|
931eed21
xu
1. A授权接口开发
|
64
|
$q->from('production');
|
b60f5eda
xu
1. 删除部分冗余代码
|
65
|
$q->where('id >1');
|
931eed21
xu
1. A授权接口开发
|
66
67
68
69
70
71
72
73
|
$list = $q->all();
return $list;
} else {
return [];
}
}
|
ff8327f6
xu
1. F 删除冗余代码
|
74
75
76
77
78
79
80
81
|
/**
* @param $where
* @param $offset
* @param $limit
* @return array|\yii\db\ActiveRecord[]
*/
static function getPageList($where, $offset = 0, $limit = 0)
{
|
a0935a2c
xu
1. F 数据统计添加多个统计维度
|
82
|
$totalNumExpress = new Expression("(select count(*) from ".DeviceModel::tableName(). "as dd where dd.batch_id = a.id and dd.is_delete = 0) as total_num");
|
ff8327f6
xu
1. F 删除冗余代码
|
83
|
$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');
|
a0935a2c
xu
1. F 数据统计添加多个统计维度
|
84
|
$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');
|
54761512
xu
1. A 添加删除序列号列表
|
85
|
$delNumExpress = new Expression("(select count(*) from ".DeviceModel::tableName(). "as dd where dd.is_delete = 1 and dd.batch_id = a.id) as del_num");
|
a0935a2c
xu
1. F 数据统计添加多个统计维度
|
86
87
88
|
$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");
|
ff8327f6
xu
1. F 删除冗余代码
|
89
90
91
|
$batchModelFind = CreateBatchModel::find();
$batchModelFind->alias('a');
|
a0935a2c
xu
1. F 数据统计添加多个统计维度
|
92
93
94
95
96
|
$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
]);
|
ff8327f6
xu
1. F 删除冗余代码
|
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
|
$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
*/
|
a0935a2c
xu
1. F 数据统计添加多个统计维度
|
137
|
static function getBatchInfo($where)
|
ff8327f6
xu
1. F 删除冗余代码
|
138
139
140
141
142
143
144
145
|
{
$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');
|
a0935a2c
xu
1. F 数据统计添加多个统计维度
|
146
|
$batchModelFind->where($where);
|
ff8327f6
xu
1. F 删除冗余代码
|
147
148
149
150
151
|
$batchModelFind->asArray();
$info = $batchModelFind->one();
return $info;
}
|
d1ded260
xu
1. F 版本管理列表增加显示项目和型号
|
152
|
}
|
931eed21
xu
1. A授权接口开发
|
|
|