Blame view

domain/device/CreateBatchRepository.php 5.28 KB
931eed21   xu   1. A授权接口开发
1
2
3
4
<?php

namespace domain\device;

a0935a2c   xu   1. F 数据统计添加多个统计维度
5
use yii\db\Expression;
ff8327f6   xu   1. F 删除冗余代码
6
use yii\db\Query;
931eed21   xu   1. A授权接口开发
7
use domain\device\models\CreateBatch as CreateBatchModel;
ff8327f6   xu   1. F 删除冗余代码
8
9
use domain\device\models\Device as DeviceModel;
use domain\device\models\DeviceStats;
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

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
     * @param $keyword
b60f5eda   xu   1. 删除部分冗余代码
30
     * @return array
931eed21   xu   1. A授权接口开发
31
32
     */
    static function getSerialNoComponent($type, $keyword)
b60f5eda   xu   1. 删除部分冗余代码
33
    {
931eed21   xu   1. A授权接口开发
34
35
36
        if ('manufacture' == $type) {
            $q = new Query();
            $q->select(['concat(id, "_", manufacture_no) as uid', 'id','manufacture_no', 'name']);
b9c38308   xu   1. A OTA版本和APP版本录...
37
            $q->from('manufacture');
931eed21   xu   1. A授权接口开发
38
            $q->where('id >1');
b60f5eda   xu   1. 删除部分冗余代码
39

b9c38308   xu   1. A OTA版本和APP版本录...
40
            $list = $q->all();
931eed21   xu   1. A授权接口开发
41
42
43
44
45

            return $list;
        } elseif('project' == $type) {
            $q = new Query();
            $q->select(['concat(id,"_", project_no) as uid', 'id','project_no', 'name']);
b9c38308   xu   1. A OTA版本和APP版本录...
46
            $q->from('project');
931eed21   xu   1. A授权接口开发
47
            $q->where('id >1');
b60f5eda   xu   1. 删除部分冗余代码
48

b9c38308   xu   1. A OTA版本和APP版本录...
49
            $list = $q->all();
931eed21   xu   1. A授权接口开发
50
51
52
53
54

            return $list;
        } elseif ('model' == $type) {
            $q = new Query();
            $q->select(['concat(id,"_", model_no) as uid','id','model_no', 'name']);
b9c38308   xu   1. A OTA版本和APP版本录...
55
            $q->from('model');
931eed21   xu   1. A授权接口开发
56
            $q->where('id >1');
b60f5eda   xu   1. 删除部分冗余代码
57
            $list = $q->all();
931eed21   xu   1. A授权接口开发
58
59
60
61
62

            return $list;
        } elseif ('production' == $type) {
            $q = new Query();
            $q->select(['concat(id,"_", production_no) as uid','id','production_no', 'name']);
b9c38308   xu   1. A OTA版本和APP版本录...
63
            $q->from('production');
931eed21   xu   1. A授权接口开发
64
            $q->where('id >1');
b60f5eda   xu   1. 删除部分冗余代码
65
            $list = $q->all();
931eed21   xu   1. A授权接口开发
66
67
68
69
70
71
72
73

            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)
    {
        $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 数据统计添加多个统计维度
82
        $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 del_num');
ff8327f6   xu   1. F 删除冗余代码
83

a0935a2c   xu   1. F 数据统计添加多个统计维度
84
        $delNumExpress = new Expression("(select count(*) from ".DeviceModel::tableName(). "as dd where dd.is_delete = 1 and dd.batch_id = a.id) as del_num");
54761512   xu   1. A 添加删除序列号列表
85

a0935a2c   xu   1. F 数据统计添加多个统计维度
86
87
88
        $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', $hasAuthNumExpress, $noAuthNumExpress, $delNumExpress]);
ff8327f6   xu   1. F 删除冗余代码
89
90
91
        $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');
a0935a2c   xu   1. F 数据统计添加多个统计维度
92
93
94
95
96
        $batchModelFind->leftJoin(ProductionModel::tableName(). ' prod', 'prod.id = a.production_id');
        $batchModelFind->where($where);
        $batchModelFind->asArray();
        if ($offset) {
            $batchModelFind->offset($offset);
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
        }
        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($batchId)
    {
        $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');
a0935a2c   xu   1. F 数据统计添加多个统计维度
137
        $batchModelFind->leftJoin(ProductionModel::tableName(). ' prod', 'prod.id = a.production_id');
ff8327f6   xu   1. F 删除冗余代码
138
139
140
141
142
143
144
        $batchModelFind->where(['a.id' => $batchId]);
        $batchModelFind->asArray();
        $info = $batchModelFind->one();

        return $info;
    }
}
a0935a2c   xu   1. F 数据统计添加多个统计维度

ff8327f6   xu   1. F 删除冗余代码

d1ded260   xu   1. F 版本管理列表增加显示项目和型号

931eed21   xu   1. A授权接口开发