-
Notifications
You must be signed in to change notification settings - Fork 14
Expand file tree
/
Copy pathPaymentStatusController.php
More file actions
249 lines (220 loc) · 8.94 KB
/
Copy pathPaymentStatusController.php
File metadata and controls
249 lines (220 loc) · 8.94 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
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
<?php
/*
* This file is part of EC-CUBE
*
* Copyright(c) EC-CUBE CO.,LTD. All Rights Reserved.
*
* https://www.ec-cube.co.jp/
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/
namespace Plugin\SamplePayment\Controller\Admin;
use Eccube\Common\Constant;
use Eccube\Controller\AbstractController;
use Eccube\Entity\Order;
use Eccube\Repository\Master\PageMaxRepository;
use Eccube\Repository\OrderRepository;
use Eccube\Util\FormUtil;
use Knp\Component\Pager\PaginatorInterface;
use Plugin\SamplePayment\Form\Type\Admin\SearchPaymentType;
use Plugin\SamplePayment\Repository\PaymentStatusRepository;
use Sensio\Bundle\FrameworkExtraBundle\Configuration\Method;
use Sensio\Bundle\FrameworkExtraBundle\Configuration\Route;
use Sensio\Bundle\FrameworkExtraBundle\Configuration\Template;
use Symfony\Component\HttpFoundation\Request;
/**
* 決済状況管理
*/
class PaymentStatusController extends AbstractController
{
/**
* @var PaymentStatusRepository
*/
protected $paymentStatusRepository;
/**
* @var PageMaxRepository
*/
protected $pageMaxRepository;
/**
* @var OrderRepository
*/
protected $orderRepository;
/**
* @var array
*/
protected $bulkActions = [
['id' => 1, 'name' => '一括売上'],
['id' => 2, 'name' => '一括取消'],
['id' => 3, 'name' => '一括再オーソリ'],
];
/**
* PaymentController constructor.
*
* @param OrderStatusRepository $orderStatusRepository
*/
public function __construct(
PaymentStatusRepository $paymentStatusRepository,
PageMaxRepository $pageMaxRepository,
OrderRepository $orderRepository
) {
$this->paymentStatusRepository = $paymentStatusRepository;
$this->pageMaxRepository = $pageMaxRepository;
$this->orderRepository = $orderRepository;
}
/**
* 決済状況一覧画面
*
* @Route("/%eccube_admin_route%/sample_payment/payment_status", name="sample_payment_admin_payment_status")
* @Route("/%eccube_admin_route%/sample_payment/payment_status/{page_no}", requirements={"page_no" = "\d+"}, name="sample_payment_admin_payment_status_pageno")
* @Template("@SamplePayment/admin/payment_status.twig")
*/
public function index(Request $request, $page_no = null, PaginatorInterface $paginator)
{
$searchForm = $this->createForm(SearchPaymentType::class);
/**
* ページの表示件数は, 以下の順に優先される.
* - リクエストパラメータ
* - セッション
* - デフォルト値
* また, セッションに保存する際は mtb_page_maxと照合し, 一致した場合のみ保存する.
**/
$page_count = $this->session->get('sample_payment.admin.payment_status.search.page_count',
$this->eccubeConfig->get('eccube_default_page_count'));
$page_count_param = (int) $request->get('page_count');
$pageMaxis = $this->pageMaxRepository->findAll();
if ($page_count_param) {
foreach ($pageMaxis as $pageMax) {
if ($page_count_param == $pageMax->getName()) {
$page_count = $pageMax->getName();
$this->session->set('sample_payment.admin.payment_status.search.page_count', $page_count);
break;
}
}
}
if ('POST' === $request->getMethod()) {
$searchForm->handleRequest($request);
if ($searchForm->isValid()) {
/**
* 検索が実行された場合は, セッションに検索条件を保存する.
* ページ番号は最初のページ番号に初期化する.
*/
$page_no = 1;
$searchData = $searchForm->getData();
// 検索条件, ページ番号をセッションに保持.
$this->session->set('sample_payment.admin.payment_status.search', FormUtil::getViewData($searchForm));
$this->session->set('sample_payment.admin.payment_status.search.page_no', $page_no);
} else {
// 検索エラーの際は, 詳細検索枠を開いてエラー表示する.
return [
'searchForm' => $searchForm->createView(),
'pagination' => [],
'pageMaxis' => $pageMaxis,
'page_no' => $page_no,
'page_count' => $page_count,
'has_errors' => true,
];
}
} else {
if (null !== $page_no || $request->get('resume')) {
/*
* ページ送りの場合または、他画面から戻ってきた場合は, セッションから検索条件を復旧する.
*/
if ($page_no) {
// ページ送りで遷移した場合.
$this->session->set('sample_payment.admin.payment_status.search.page_no', (int) $page_no);
} else {
// 他画面から遷移した場合.
$page_no = $this->session->get('sample_payment.admin.payment_status.search.page_no', 1);
}
$viewData = $this->session->get('sample_payment.admin.payment_status.search', []);
$searchData = FormUtil::submitAndGetData($searchForm, $viewData);
} else {
/**
* 初期表示の場合.
*/
$page_no = 1;
$searchData = [];
// セッション中の検索条件, ページ番号を初期化.
$this->session->set('sample_payment.admin.payment_status.search', $searchData);
$this->session->set('sample_payment.admin.payment_status.search.page_no', $page_no);
}
}
$qb = $this->createQueryBuilder($searchData);
$pagination = $paginator->paginate(
$qb,
$page_no,
$page_count
);
return [
'searchForm' => $searchForm->createView(),
'pagination' => $pagination,
'pageMaxis' => $pageMaxis,
'page_no' => $page_no,
'page_count' => $page_count,
'has_errors' => false,
'bulkActions' => $this->bulkActions,
];
}
/**
* 一括処理.
*
* @Method("POST")
* @Route("/%eccube_admin_route%/sample_payment/payment_status/bulk_action/{id}", requirements={"id" = "\d+"}, name="sample_payment_admin_payment_status_bulk_action")
*/
public function bulkAction(Request $request, $id)
{
if (!isset($this->bulkActions[$id])) {
throw new BadRequestHttpException();
}
$this->isTokenValid();
/** @var Order[] $Orders */
$Orders = $this->orderRepository->findBy(['id' => $request->get('ids')]);
$count = 0;
foreach ($Orders as $Order) {
switch ($id) {
// 一括売上
case 1:
// 通信処理
// Order等の更新処理
break;
// 一括取消
case 2:
// 通信処理
// Order等の更新処理
break;
// 一括再オーソリ
case 3:
// 通信処理
// Order等の更新処理
break;
}
$this->entityManager->flush($Order);
$count++;
}
$this->addSuccess(trans('sample_payment.admin.payment_status.bulk_action.success', ['%count%' => $count]),
'admin');
return $this->redirectToRoute('sample_payment_admin_payment_status_pageno', ['resume' => Constant::ENABLED]);
}
private function createQueryBuilder(array $searchData)
{
$qb = $this->entityManager->createQueryBuilder();
$qb->select('o')
->from(Order::class, 'o')
->orderBy('o.order_date', 'DESC')
->addOrderBy('o.id', 'DESC');
if (!empty($searchData['Payments']) && count($searchData['Payments']) > 0) {
$qb->andWhere($qb->expr()->in('o.Payment', ':Payments'))
->setParameter('Payments', $searchData['Payments']);
}
if (!empty($searchData['OrderStatuses']) && count($searchData['OrderStatuses']) > 0) {
$qb->andWhere($qb->expr()->in('o.OrderStatus', ':OrderStatuses'))
->setParameter('OrderStatuses', $searchData['OrderStatuses']);
}
if (!empty($searchData['PaymentStatuses']) && count($searchData['PaymentStatuses']) > 0) {
$qb->andWhere($qb->expr()->in('o.SamplePaymentPaymentStatus', ':PaymentStatuses'))
->setParameter('PaymentStatuses', $searchData['PaymentStatuses']);
}
return $qb;
}
}