ProductionController.php
5.85 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
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
<?php
namespace app\ht\modules\production\controllers;
use Yii;
use yii\data\Pagination;
use domain\production\Production;
use domain\production\ProductionRepository;
use app\ht\controllers\BaseController;
/**
* 生产日期管理
* Class ProductionController
* @package app\ht\modules\production\controllers
*/
class ProductionController extends BaseController
{
/**
* 生产日期管理
*/
public function actionIndex()
{
$params = $this->dataList(1);
/**
* 渲染模板
*/
return $this->render('index', $params);
}
/**
* 查询数据列表
*/
protected function dataList($type = '')
{
$request = Yii::$app->request;
$creatTime = $request->get('creatTime');
$endTime = $request->get('endTime');
$productionCreatTime = $request->get('productionCreatTime');
$productionEndTime = $request->get('productionEndTime');
$gets = [
'creatTime' => $creatTime,
'endTime' => $endTime,
'productionCreatTime' => $productionCreatTime,
'productionEndTime' => $productionEndTime,
];
$where = ['and'];
if ($creatTime) {
$creatTime = strtotime($creatTime);
$where[] = ['>=', 'p.created_at', $creatTime];
}
if ($endTime) {
$endTime = strtotime($endTime) + 86400;
$where[] = ['<=', 'p.created_at', $endTime];
}
if ($productionCreatTime) {
$productionCreatTime = strtotime($productionCreatTime);
$where[] = ['>=', 'p.name', $productionCreatTime];
}
if ($productionEndTime) {
$productionEndTime = strtotime($productionEndTime) + 86400;
$where[] = ['<=', 'p.name', $productionEndTime];
}
if ($type == 0) {
$pageList = ProductionRepository::getPageList($where, 0 , 0);
$pages = null;
} else {
$pageSize = 20;
$pages = new Pagination(['totalCount' => ProductionRepository::getPageCount($where), 'pageSize' => $pageSize]);
$pageList = ProductionRepository::getPageList($where, $pages->offset, $pages->limit);
}
/**
* 数据整理
*/
return [
'listdata' => $pageList,
'pages' => $pages,
'gets' => $gets
];
}
/**
* 创建生产日期
* @return string
*/
public function actionCreate()
{
return $this->render('create');
}
/**
* 创建生产日期
* @return string
*/
public function actionDoAdd()
{
$request = Yii::$app->request;
$name = $request->post("name"); // 生产日期
if (empty($name)) {
Yii::$app->session->setFlash('error', '生产日期不能为空');
return $this->render('create');
}
$result = Production::create($request->post());
if ($result === -1) {
Yii::$app->session->setFlash('error', '添加失败,生产日期' . $name . '已存在');
return $this->render('create');
}
if ($result) {
Yii::$app->session->setFlash('success', '添加成功');
} else {
Yii::$app->session->setFlash('error', '添加失败');
}
return $this->redirect('index');
}
/**
* 编辑生产日期
* @return string
*/
public function actionEdit()
{
$productionId = $this->request->get("pid");
$info = ProductionRepository::selectOne($productionId, true);
return $this->render('edit', ["info" => $info]);
}
/**
* 编辑生产日期
* @return string
*/
public function actionDoEdit()
{
$request = Yii::$app->request;
$name = $request->post("name");
$pid = $request->post("pid");
if (empty($pid)) {
Yii::$app->session->setFlash('error', '生产日期编号不能为空');
$params = $this->dataList(1);
return $this->render('index', $params);
}
$production = ProductionRepository::selectOne($pid,true);
if (empty($production)) {
Yii::$app->session->setFlash('error', '生产日期记录不存在');
$params = $this->dataList(1);
return $this->render('index', $params);
}
if (empty(trim($name))) {
Yii::$app->session->setFlash('error', '生产日期不能为空');
return $this->render('edit', ["info" => $production]);
}
$result = Production::update($pid, $request->post());
if ($result === -1) {
Yii::$app->session->setFlash('error', '修改的生产日期' . $name . '已存在');
return $this->render('edit', ["info" => $production]);
}
if ($result) {
Yii::$app->session->setFlash('success', '编辑成功');
} else {
Yii::$app->session->setFlash('error', '编辑失败');
}
$production = ProductionRepository::selectOne($pid,true);
return $this->render('edit', ["info" => $production]);
}
/**
* 删除生产日期
* @return string
* @throws \Exception
*/
public function actionDoDel()
{
$request = Yii::$app->request;
$itemId = $request->post("data_id");
$msg = array();
// 删除对应的生产日期
if (Production::delete($itemId)) {
$msg['status'] = 1;
$msg['msg'] = "操作成功";
} else {
$msg['status'] = 0;
$msg['msg'] = "操作失败";
}
return $this->renderJson($msg);
}
/**
* 导出厂商数据
* @return string
*/
public function actionExport()
{
$params = $this->dataList(0);
return $this->renderPartial('export', $params);
}
}