|
1
|
|
|
<?php |
|
2
|
|
|
/* |
|
3
|
|
|
* This file is part of EC-CUBE |
|
4
|
|
|
* |
|
5
|
|
|
* Copyright(c) 2000-2015 LOCKON CO.,LTD. All Rights Reserved. |
|
6
|
|
|
* |
|
7
|
|
|
* http://www.lockon.co.jp/ |
|
8
|
|
|
* |
|
9
|
|
|
* This program is free software; you can redistribute it and/or |
|
10
|
|
|
* modify it under the terms of the GNU General Public License |
|
11
|
|
|
* as published by the Free Software Foundation; either version 2 |
|
12
|
|
|
* of the License, or (at your option) any later version. |
|
13
|
|
|
* |
|
14
|
|
|
* This program is distributed in the hope that it will be useful, |
|
15
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of |
|
16
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
|
17
|
|
|
* GNU General Public License for more details. |
|
18
|
|
|
* |
|
19
|
|
|
* You should have received a copy of the GNU General Public License |
|
20
|
|
|
* along with this program; if not, write to the Free Software |
|
21
|
|
|
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. |
|
22
|
|
|
*/ |
|
23
|
|
|
|
|
24
|
|
|
|
|
25
|
|
|
namespace Eccube\Controller\Admin\Order; |
|
26
|
|
|
|
|
27
|
|
|
use Eccube\Application; |
|
28
|
|
|
use Eccube\Common\Constant; |
|
29
|
|
|
use Eccube\Controller\AbstractController; |
|
30
|
|
|
use Eccube\Entity\Master\CsvType; |
|
31
|
|
|
use Eccube\Event\EccubeEvents; |
|
32
|
|
|
use Eccube\Event\EventArgs; |
|
33
|
|
|
use Symfony\Component\HttpFoundation\Request; |
|
34
|
|
|
use Symfony\Component\HttpFoundation\StreamedResponse; |
|
35
|
|
|
|
|
36
|
|
|
class OrderController extends AbstractController |
|
|
|
|
|
|
37
|
|
|
{ |
|
38
|
|
|
|
|
39
|
10 |
|
public function index(Application $app, Request $request, $page_no = null) |
|
|
|
|
|
|
40
|
|
|
{ |
|
41
|
|
|
|
|
42
|
8 |
|
$session = $request->getSession(); |
|
43
|
|
|
|
|
44
|
8 |
|
$builder = $app['form.factory'] |
|
45
|
8 |
|
->createBuilder('admin_search_order'); |
|
46
|
|
|
|
|
47
|
8 |
|
$event = new EventArgs( |
|
48
|
|
|
array( |
|
49
|
8 |
|
'builder' => $builder, |
|
50
|
8 |
|
), |
|
51
|
|
|
$request |
|
52
|
8 |
|
); |
|
53
|
8 |
|
$app['eccube.event.dispatcher']->dispatch(EccubeEvents::ADMIN_ORDER_INDEX_INITIALIZE, $event); |
|
54
|
|
|
|
|
55
|
8 |
|
$searchForm = $builder->getForm(); |
|
56
|
|
|
|
|
57
|
8 |
|
$pagination = array(); |
|
58
|
|
|
|
|
59
|
8 |
|
$disps = $app['eccube.repository.master.disp']->findAll(); |
|
60
|
8 |
|
$pageMaxis = $app['eccube.repository.master.page_max']->findAll(); |
|
61
|
8 |
|
$page_count = $app['config']['default_page_count']; |
|
62
|
10 |
|
$page_status = null; |
|
63
|
8 |
|
$active = false; |
|
64
|
|
|
|
|
65
|
10 |
|
if ('POST' === $request->getMethod()) { |
|
|
|
|
|
|
66
|
|
|
|
|
67
|
6 |
|
$searchForm->handleRequest($request); |
|
68
|
|
|
|
|
69
|
6 |
View Code Duplication |
if ($searchForm->isValid()) { |
|
|
|
|
|
|
70
|
6 |
|
$searchData = $searchForm->getData(); |
|
71
|
|
|
|
|
72
|
|
|
// paginator |
|
73
|
6 |
|
$qb = $app['eccube.repository.order']->getQueryBuilderBySearchDataForAdmin($searchData); |
|
74
|
|
|
|
|
75
|
6 |
|
$event = new EventArgs( |
|
76
|
|
|
array( |
|
77
|
6 |
|
'form' => $searchForm, |
|
78
|
6 |
|
'qb' => $qb, |
|
79
|
6 |
|
), |
|
80
|
|
|
$request |
|
81
|
6 |
|
); |
|
82
|
6 |
|
$app['eccube.event.dispatcher']->dispatch(EccubeEvents::ADMIN_ORDER_INDEX_SEARCH, $event); |
|
83
|
|
|
|
|
84
|
6 |
|
$page_no = 1; |
|
85
|
6 |
|
$pagination = $app['paginator']()->paginate( |
|
86
|
6 |
|
$qb, |
|
87
|
6 |
|
$page_no, |
|
88
|
|
|
$page_count |
|
89
|
6 |
|
); |
|
90
|
|
|
|
|
91
|
|
|
// sessionのデータ保持 |
|
92
|
6 |
|
$session->set('eccube.admin.order.search', $searchData); |
|
93
|
6 |
|
$session->set('eccube.admin.order.search.page_no', $page_no); |
|
94
|
6 |
|
} |
|
95
|
6 |
|
} else { |
|
96
|
4 |
|
if (is_null($page_no) && $request->get('resume') != Constant::ENABLED) { |
|
97
|
|
|
// sessionを削除 |
|
98
|
2 |
|
$session->remove('eccube.admin.order.search'); |
|
99
|
2 |
|
$session->remove('eccube.admin.order.search.page_no'); |
|
100
|
2 |
|
} else { |
|
101
|
|
|
// pagingなどの処理 |
|
102
|
2 |
|
$searchData = $session->get('eccube.admin.order.search'); |
|
103
|
2 |
|
if (is_null($page_no)) { |
|
104
|
|
|
$page_no = intval($session->get('eccube.admin.order.search.page_no')); |
|
105
|
|
|
} else { |
|
106
|
2 |
|
$session->set('eccube.admin.order.search.page_no', $page_no); |
|
107
|
|
|
} |
|
108
|
|
|
|
|
109
|
2 |
|
if (!is_null($searchData)) { |
|
|
|
|
|
|
110
|
|
|
|
|
111
|
|
|
// 公開ステータス |
|
112
|
2 |
|
$status = $request->get('status'); |
|
113
|
2 |
|
if (!empty($status)) { |
|
114
|
|
|
if ($status != $app['config']['admin_product_stock_status']) { |
|
115
|
|
|
$searchData['status']->clear(); |
|
116
|
|
|
$searchData['status']->add($status); |
|
117
|
|
|
} else { |
|
118
|
|
|
$searchData['stock_status'] = $app['config']['disabled']; |
|
119
|
|
|
} |
|
120
|
|
|
$page_status = $status; |
|
121
|
|
|
} |
|
122
|
|
|
// 表示件数 |
|
123
|
2 |
|
$pcount = $request->get('page_count'); |
|
124
|
|
|
|
|
125
|
2 |
|
$page_count = empty($pcount) ? $page_count : $pcount; |
|
126
|
|
|
|
|
127
|
2 |
|
$qb = $app['eccube.repository.order']->getQueryBuilderBySearchDataForAdmin($searchData); |
|
128
|
|
|
|
|
129
|
2 |
|
$event = new EventArgs( |
|
130
|
|
|
array( |
|
131
|
2 |
|
'form' => $searchForm, |
|
132
|
2 |
|
'qb' => $qb, |
|
133
|
2 |
|
), |
|
134
|
|
|
$request |
|
135
|
2 |
|
); |
|
136
|
2 |
|
$app['eccube.event.dispatcher']->dispatch(EccubeEvents::ADMIN_ORDER_INDEX_SEARCH, $event); |
|
137
|
|
|
|
|
138
|
2 |
|
$pagination = $app['paginator']()->paginate( |
|
139
|
2 |
|
$qb, |
|
140
|
2 |
|
$page_no, |
|
141
|
|
|
$page_count |
|
142
|
2 |
|
); |
|
143
|
|
|
|
|
144
|
|
|
// セッションから検索条件を復元 |
|
145
|
2 |
|
if (!empty($searchData['status'])) { |
|
146
|
2 |
|
$searchData['status'] = $app['eccube.repository.master.order_status']->find($searchData['status']); |
|
147
|
2 |
|
} |
|
148
|
2 |
View Code Duplication |
if (count($searchData['sex']) > 0) { |
|
|
|
|
|
|
149
|
2 |
|
$sex_ids = array(); |
|
150
|
2 |
|
foreach ($searchData['sex'] as $Sex) { |
|
151
|
2 |
|
$sex_ids[] = $Sex->getId(); |
|
152
|
2 |
|
} |
|
153
|
2 |
|
$searchData['sex'] = $app['eccube.repository.master.sex']->findBy(array('id' => $sex_ids)); |
|
154
|
2 |
|
} |
|
155
|
2 |
View Code Duplication |
if (count($searchData['payment']) > 0) { |
|
|
|
|
|
|
156
|
2 |
|
$payment_ids = array(); |
|
157
|
2 |
|
foreach ($searchData['payment'] as $Payment) { |
|
158
|
2 |
|
$payment_ids[] = $Payment->getId(); |
|
159
|
2 |
|
} |
|
160
|
2 |
|
$searchData['payment'] = $app['eccube.repository.payment']->findBy(array('id' => $payment_ids)); |
|
161
|
2 |
|
} |
|
162
|
2 |
|
$searchForm->setData($searchData); |
|
163
|
2 |
|
} |
|
164
|
|
|
} |
|
165
|
|
|
} |
|
166
|
|
|
|
|
167
|
8 |
|
return $app->render('Order/index.twig', array( |
|
168
|
8 |
|
'searchForm' => $searchForm->createView(), |
|
169
|
8 |
|
'pagination' => $pagination, |
|
170
|
8 |
|
'disps' => $disps, |
|
171
|
8 |
|
'pageMaxis' => $pageMaxis, |
|
172
|
8 |
|
'page_no' => $page_no, |
|
173
|
8 |
|
'page_status' => $page_status, |
|
174
|
8 |
|
'page_count' => $page_count, |
|
175
|
8 |
|
'active' => $active, |
|
176
|
8 |
|
)); |
|
177
|
|
|
|
|
178
|
|
|
} |
|
179
|
|
|
|
|
180
|
2 |
|
public function delete(Application $app, Request $request, $id) |
|
|
|
|
|
|
181
|
|
|
{ |
|
182
|
2 |
|
$this->isTokenValid($app); |
|
183
|
2 |
|
$session = $request->getSession(); |
|
184
|
2 |
|
$page_no = intval($session->get('eccube.admin.order.search.page_no')); |
|
185
|
2 |
|
$page_no = $page_no ? $page_no : Constant::ENABLED; |
|
186
|
|
|
|
|
187
|
2 |
|
$Order = $app['orm.em']->getRepository('Eccube\Entity\Order') |
|
188
|
2 |
|
->find($id); |
|
189
|
|
|
|
|
190
|
2 |
|
if (!$Order) { |
|
191
|
|
|
$app->deleteMessage(); |
|
192
|
|
|
return $app->redirect($app->url('admin_order_page', array('page_no' => $page_no)).'?resume='.Constant::ENABLED); |
|
|
|
|
|
|
193
|
|
|
} |
|
194
|
|
|
|
|
195
|
2 |
|
$Order->setDelFlg(Constant::ENABLED); |
|
196
|
|
|
|
|
197
|
2 |
|
$app['orm.em']->persist($Order); |
|
198
|
2 |
|
$app['orm.em']->flush(); |
|
199
|
|
|
|
|
200
|
2 |
|
$Customer = $Order->getCustomer(); |
|
201
|
2 |
|
if ($Customer) { |
|
202
|
|
|
// 会員の場合、購入回数、購入金額などを更新 |
|
203
|
2 |
|
$app['eccube.repository.customer']->updateBuyData($app, $Customer, $Order->getOrderStatus()->getId()); |
|
204
|
2 |
|
} |
|
205
|
|
|
|
|
206
|
2 |
|
$event = new EventArgs( |
|
207
|
|
|
array( |
|
208
|
2 |
|
'Order' => $Order, |
|
209
|
2 |
|
'Customer' => $Customer, |
|
210
|
2 |
|
), |
|
211
|
|
|
$request |
|
212
|
2 |
|
); |
|
213
|
2 |
|
$app['eccube.event.dispatcher']->dispatch(EccubeEvents::ADMIN_ORDER_DELETE_COMPLETE, $event); |
|
214
|
|
|
|
|
215
|
2 |
|
$app->addSuccess('admin.order.delete.complete', 'admin'); |
|
216
|
|
|
|
|
217
|
2 |
|
return $app->redirect($app->url('admin_order_page', array('page_no' => $page_no)).'?resume='.Constant::ENABLED); |
|
218
|
|
|
} |
|
219
|
|
|
|
|
220
|
|
|
|
|
221
|
|
|
/** |
|
222
|
|
|
* 受注CSVの出力. |
|
223
|
|
|
* |
|
224
|
|
|
* @param Application $app |
|
225
|
|
|
* @param Request $request |
|
|
|
|
|
|
226
|
|
|
* @return StreamedResponse |
|
227
|
|
|
*/ |
|
228
|
1 |
|
public function exportOrder(Application $app, Request $request) |
|
229
|
|
|
{ |
|
230
|
|
|
|
|
231
|
|
|
// タイムアウトを無効にする. |
|
232
|
1 |
|
set_time_limit(0); |
|
233
|
|
|
|
|
234
|
|
|
// sql loggerを無効にする. |
|
235
|
1 |
|
$em = $app['orm.em']; |
|
236
|
1 |
|
$em->getConfiguration()->setSQLLogger(null); |
|
237
|
|
|
|
|
238
|
1 |
|
$response = new StreamedResponse(); |
|
239
|
|
|
$response->setCallback(function () use ($app, $request) { |
|
240
|
|
|
|
|
241
|
|
|
// CSV種別を元に初期化. |
|
242
|
1 |
|
$app['eccube.service.csv.export']->initCsvType(CsvType::CSV_TYPE_ORDER); |
|
243
|
|
|
|
|
244
|
|
|
// ヘッダ行の出力. |
|
245
|
1 |
|
$app['eccube.service.csv.export']->exportHeader(); |
|
246
|
|
|
|
|
247
|
|
|
// 受注データ検索用のクエリビルダを取得. |
|
248
|
1 |
|
$qb = $app['eccube.service.csv.export'] |
|
249
|
1 |
|
->getOrderQueryBuilder($request); |
|
250
|
|
|
|
|
251
|
|
|
// データ行の出力. |
|
252
|
1 |
|
$app['eccube.service.csv.export']->setExportQueryBuilder($qb); |
|
253
|
|
View Code Duplication |
$app['eccube.service.csv.export']->exportData(function ($entity, $csvService) { |
|
|
|
|
|
|
254
|
|
|
|
|
255
|
1 |
|
$Csvs = $csvService->getCsvs(); |
|
256
|
|
|
|
|
257
|
1 |
|
$Order = $entity; |
|
258
|
1 |
|
$OrderDetails = $Order->getOrderDetails(); |
|
259
|
|
|
|
|
260
|
1 |
|
foreach ($OrderDetails as $OrderDetail) { |
|
261
|
1 |
|
$row = array(); |
|
262
|
|
|
|
|
263
|
|
|
// CSV出力項目と合致するデータを取得. |
|
264
|
1 |
|
foreach ($Csvs as $Csv) { |
|
265
|
|
|
// 受注データを検索. |
|
266
|
1 |
|
$data = $csvService->getData($Csv, $Order); |
|
267
|
1 |
|
if (is_null($data)) { |
|
268
|
|
|
// 受注データにない場合は, 受注明細を検索. |
|
269
|
1 |
|
$data = $csvService->getData($Csv, $OrderDetail); |
|
270
|
1 |
|
} |
|
271
|
1 |
|
$row[] = $data; |
|
272
|
|
|
|
|
|
|
|
|
|
273
|
1 |
|
} |
|
274
|
|
|
|
|
275
|
|
|
//$row[] = number_format(memory_get_usage(true)); |
|
|
|
|
|
|
276
|
|
|
// 出力. |
|
277
|
1 |
|
$csvService->fputcsv($row); |
|
278
|
1 |
|
} |
|
279
|
1 |
|
}); |
|
280
|
1 |
|
}); |
|
281
|
|
|
|
|
282
|
1 |
|
$now = new \DateTime(); |
|
283
|
1 |
|
$filename = 'order_' . $now->format('YmdHis') . '.csv'; |
|
|
|
|
|
|
284
|
1 |
|
$response->headers->set('Content-Type', 'application/octet-stream'); |
|
285
|
1 |
|
$response->headers->set('Content-Disposition', 'attachment; filename=' . $filename); |
|
|
|
|
|
|
286
|
1 |
|
$response->send(); |
|
287
|
|
|
|
|
288
|
1 |
|
return $response; |
|
289
|
|
|
} |
|
290
|
|
|
|
|
291
|
|
|
/** |
|
292
|
|
|
* 配送CSVの出力. |
|
293
|
|
|
* |
|
294
|
|
|
* @param Application $app |
|
295
|
|
|
* @param Request $request |
|
|
|
|
|
|
296
|
|
|
* @return StreamedResponse |
|
297
|
|
|
*/ |
|
298
|
3 |
|
public function exportShipping(Application $app, Request $request) |
|
299
|
|
|
{ |
|
300
|
|
|
// タイムアウトを無効にする. |
|
301
|
1 |
|
set_time_limit(0); |
|
302
|
|
|
|
|
303
|
|
|
// sql loggerを無効にする. |
|
304
|
1 |
|
$em = $app['orm.em']; |
|
305
|
1 |
|
$em->getConfiguration()->setSQLLogger(null); |
|
306
|
|
|
|
|
307
|
1 |
|
$response = new StreamedResponse(); |
|
308
|
|
|
$response->setCallback(function () use ($app, $request) { |
|
309
|
|
|
|
|
310
|
|
|
// CSV種別を元に初期化. |
|
311
|
1 |
|
$app['eccube.service.csv.export']->initCsvType(CsvType::CSV_TYPE_SHIPPING); |
|
312
|
|
|
|
|
313
|
|
|
// ヘッダ行の出力. |
|
314
|
1 |
|
$app['eccube.service.csv.export']->exportHeader(); |
|
315
|
|
|
|
|
316
|
|
|
// 受注データ検索用のクエリビルダを取得. |
|
317
|
1 |
|
$qb = $app['eccube.service.csv.export'] |
|
318
|
1 |
|
->getOrderQueryBuilder($request); |
|
319
|
|
|
|
|
320
|
|
|
// データ行の出力. |
|
321
|
1 |
|
$app['eccube.service.csv.export']->setExportQueryBuilder($qb); |
|
322
|
3 |
|
$app['eccube.service.csv.export']->exportData(function ($entity, $csvService) { |
|
323
|
|
|
|
|
324
|
1 |
|
$Csvs = $csvService->getCsvs(); |
|
325
|
|
|
|
|
326
|
|
|
/** @var $Order \Eccube\Entity\Order */ |
|
327
|
1 |
|
$Order = $entity; |
|
328
|
|
|
/** @var $Shippings \Eccube\Entity\Shipping[] */ |
|
329
|
1 |
|
$Shippings = $Order->getShippings(); |
|
330
|
|
|
|
|
331
|
1 |
|
foreach ($Shippings as $Shipping) { |
|
332
|
|
|
/** @var $ShipmentItems \Eccube\Entity\ShipmentItem */ |
|
333
|
1 |
|
$ShipmentItems = $Shipping->getShipmentItems(); |
|
334
|
1 |
|
foreach ($ShipmentItems as $ShipmentItem) { |
|
335
|
1 |
|
$row = array(); |
|
336
|
|
|
|
|
337
|
|
|
// CSV出力項目と合致するデータを取得. |
|
338
|
3 |
|
foreach ($Csvs as $Csv) { |
|
339
|
|
|
// 受注データを検索. |
|
340
|
1 |
|
$data = $csvService->getData($Csv, $Order); |
|
341
|
1 |
|
if (is_null($data)) { |
|
342
|
|
|
// 配送情報を検索. |
|
343
|
1 |
|
$data = $csvService->getData($Csv, $Shipping); |
|
344
|
1 |
|
} |
|
345
|
1 |
|
if (is_null($data)) { |
|
346
|
|
|
// 配送商品を検索. |
|
347
|
1 |
|
$data = $csvService->getData($Csv, $ShipmentItem); |
|
348
|
1 |
|
} |
|
349
|
1 |
|
$row[] = $data; |
|
350
|
1 |
|
} |
|
351
|
|
|
//$row[] = number_format(memory_get_usage(true)); |
|
|
|
|
|
|
352
|
|
|
// 出力. |
|
353
|
1 |
|
$csvService->fputcsv($row); |
|
354
|
1 |
|
} |
|
355
|
1 |
|
} |
|
356
|
1 |
|
}); |
|
357
|
1 |
|
}); |
|
358
|
|
|
|
|
359
|
1 |
|
$now = new \DateTime(); |
|
360
|
1 |
|
$filename = 'shipping_' . $now->format('YmdHis') . '.csv'; |
|
|
|
|
|
|
361
|
1 |
|
$response->headers->set('Content-Type', 'application/octet-stream'); |
|
362
|
1 |
|
$response->headers->set('Content-Disposition', 'attachment; filename=' . $filename); |
|
|
|
|
|
|
363
|
1 |
|
$response->send(); |
|
364
|
|
|
|
|
365
|
1 |
|
return $response; |
|
366
|
|
|
} |
|
367
|
|
|
} |
|
368
|
|
|
|