|
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\Setting\Shop; |
|
26
|
|
|
|
|
27
|
|
|
use Doctrine\DBAL\Exception\ForeignKeyConstraintViolationException; |
|
28
|
|
|
use Doctrine\ORM\EntityManager; |
|
29
|
|
|
use Eccube\Annotation\Component; |
|
30
|
|
|
use Eccube\Annotation\Inject; |
|
31
|
|
|
use Eccube\Application; |
|
32
|
|
|
use Eccube\Controller\AbstractController; |
|
33
|
|
|
use Eccube\Entity\Payment; |
|
34
|
|
|
use Eccube\Event\EccubeEvents; |
|
35
|
|
|
use Eccube\Event\EventArgs; |
|
36
|
|
|
use Eccube\Form\Type\Admin\PaymentRegisterType; |
|
37
|
|
|
use Eccube\Repository\PaymentRepository; |
|
38
|
|
|
use Sensio\Bundle\FrameworkExtraBundle\Configuration\Method; |
|
39
|
|
|
use Sensio\Bundle\FrameworkExtraBundle\Configuration\Route; |
|
40
|
|
|
use Sensio\Bundle\FrameworkExtraBundle\Configuration\Template; |
|
41
|
|
|
use Symfony\Component\EventDispatcher\EventDispatcher; |
|
42
|
|
|
use Symfony\Component\Filesystem\Filesystem; |
|
43
|
|
|
use Symfony\Component\Form\FormFactory; |
|
44
|
|
|
use Symfony\Component\HttpFoundation\Request; |
|
45
|
|
|
use Symfony\Component\HttpKernel\Exception\BadRequestHttpException; |
|
46
|
|
|
use Symfony\Component\HttpKernel\Exception\UnsupportedMediaTypeHttpException; |
|
47
|
|
|
|
|
48
|
|
|
/** |
|
49
|
|
|
* @Component |
|
50
|
|
|
* @Route(service=PaymentController::class) |
|
51
|
|
|
*/ |
|
52
|
|
|
class PaymentController extends AbstractController |
|
53
|
|
|
{ |
|
54
|
|
|
/** |
|
55
|
|
|
* @Inject("orm.em") |
|
56
|
|
|
* @var EntityManager |
|
57
|
|
|
*/ |
|
58
|
|
|
protected $entityManager; |
|
59
|
|
|
|
|
60
|
|
|
/** |
|
61
|
|
|
* @Inject("config") |
|
62
|
|
|
* @var array |
|
63
|
|
|
*/ |
|
64
|
|
|
protected $appConfig; |
|
65
|
|
|
|
|
66
|
|
|
/** |
|
67
|
|
|
* @Inject("form.factory") |
|
68
|
|
|
* @var FormFactory |
|
69
|
|
|
*/ |
|
70
|
|
|
protected $formFactory; |
|
71
|
|
|
|
|
72
|
|
|
/** |
|
73
|
|
|
* @Inject("eccube.event.dispatcher") |
|
74
|
|
|
* @var EventDispatcher |
|
75
|
|
|
*/ |
|
76
|
|
|
protected $eventDispatcher; |
|
77
|
|
|
|
|
78
|
|
|
/** |
|
79
|
|
|
* @Inject(PaymentRepository::class) |
|
80
|
|
|
* @var PaymentRepository |
|
81
|
|
|
*/ |
|
82
|
|
|
protected $paymentRepository; |
|
83
|
|
|
|
|
84
|
|
|
/** |
|
|
|
|
|
|
85
|
|
|
* @Route("/{_admin}/setting/shop/payment", name="admin_setting_shop_payment") |
|
86
|
|
|
* @Template("Setting/Shop/payment.twig") |
|
87
|
|
|
*/ |
|
|
|
|
|
|
88
|
1 |
View Code Duplication |
public function index(Application $app, Request $request) |
|
|
|
|
|
|
89
|
|
|
{ |
|
90
|
1 |
|
$Payments = $this->paymentRepository |
|
91
|
1 |
|
->findBy( |
|
92
|
1 |
|
array(), |
|
93
|
1 |
|
array('rank' => 'DESC') |
|
94
|
|
|
); |
|
95
|
|
|
|
|
96
|
1 |
|
$event = new EventArgs( |
|
97
|
|
|
array( |
|
98
|
1 |
|
'Payments' => $Payments, |
|
99
|
|
|
), |
|
100
|
1 |
|
$request |
|
101
|
|
|
); |
|
102
|
1 |
|
$this->eventDispatcher->dispatch(EccubeEvents::ADMIN_SETTING_SHOP_PAYMENT_INDEX_COMPLETE, $event); |
|
103
|
|
|
|
|
104
|
|
|
return [ |
|
105
|
1 |
|
'Payments' => $Payments, |
|
106
|
|
|
]; |
|
107
|
|
|
} |
|
108
|
|
|
|
|
109
|
|
|
/** |
|
|
|
|
|
|
110
|
|
|
* @Route("/{_admin}/setting/shop/payment/new", name="admin_setting_shop_payment_new") |
|
111
|
|
|
* @Route("/{_admin}/setting/shop/payment/{id}/edit", requirements={"id" = "\d+"}, name="admin_setting_shop_payment_edit") |
|
112
|
|
|
* @Template("Setting/Shop/payment_edit.twig") |
|
113
|
|
|
*/ |
|
|
|
|
|
|
114
|
6 |
|
public function edit(Application $app, Request $request, Payment $Payment = null) |
|
115
|
|
|
{ |
|
116
|
6 |
|
if (is_null($Payment)) { |
|
117
|
|
|
// FIXME |
|
118
|
3 |
|
$Payment = $this->paymentRepository |
|
|
|
|
|
|
119
|
3 |
|
->findOrCreate(0); |
|
120
|
|
|
} |
|
121
|
|
|
|
|
122
|
6 |
|
$builder = $this->formFactory |
|
123
|
6 |
|
->createBuilder(PaymentRegisterType::class, $Payment); |
|
124
|
|
|
|
|
125
|
6 |
|
$event = new EventArgs( |
|
126
|
|
|
array( |
|
127
|
6 |
|
'builder' => $builder, |
|
128
|
6 |
|
'Payment' => $Payment, |
|
129
|
|
|
), |
|
130
|
6 |
|
$request |
|
131
|
|
|
); |
|
132
|
6 |
|
$this->eventDispatcher->dispatch(EccubeEvents::ADMIN_SETTING_SHOP_PAYMENT_EDIT_INITIALIZE, $event); |
|
133
|
|
|
|
|
134
|
6 |
|
$form = $builder->getForm(); |
|
135
|
6 |
|
$form->handleRequest($request); |
|
136
|
|
|
|
|
137
|
|
|
// 登録ボタン押下 |
|
138
|
6 |
|
if ($form->isSubmitted() && $form->isValid()) { |
|
139
|
2 |
|
$Payment = $form->getData(); |
|
140
|
|
|
|
|
141
|
|
|
// 手数料を設定できない場合には、手数料を0にする |
|
142
|
2 |
|
if ($Payment->getChargeFlg() == 2) { |
|
143
|
|
|
$Payment->setCharge(0); |
|
144
|
|
|
} |
|
145
|
|
|
|
|
146
|
|
|
// ファイルアップロード |
|
147
|
2 |
|
$file = $form['payment_image']->getData(); |
|
148
|
2 |
|
$fs = new Filesystem(); |
|
149
|
2 |
|
if ($file && $fs->exists($this->appConfig['image_temp_realdir'].'/'.$file)) { |
|
150
|
|
|
$fs->rename( |
|
151
|
|
|
$this->appConfig['image_temp_realdir'].'/'.$file, |
|
152
|
|
|
$this->appConfig['image_save_realdir'].'/'.$file |
|
153
|
|
|
); |
|
154
|
|
|
} |
|
155
|
|
|
|
|
156
|
2 |
|
$Payment->setVisible(true); |
|
157
|
2 |
|
$this->entityManager->persist($Payment); |
|
158
|
2 |
|
$this->entityManager->flush(); |
|
159
|
|
|
|
|
160
|
2 |
|
$event = new EventArgs( |
|
161
|
|
|
array( |
|
162
|
2 |
|
'form' => $form, |
|
163
|
2 |
|
'Payment' => $Payment, |
|
164
|
|
|
), |
|
165
|
2 |
|
$request |
|
166
|
|
|
); |
|
167
|
2 |
|
$this->eventDispatcher->dispatch(EccubeEvents::ADMIN_SETTING_SHOP_PAYMENT_EDIT_COMPLETE, $event); |
|
168
|
|
|
|
|
169
|
2 |
|
$app->addSuccess('admin.register.complete', 'admin'); |
|
170
|
|
|
|
|
171
|
2 |
|
return $app->redirect($app->url('admin_setting_shop_payment')); |
|
172
|
|
|
} |
|
173
|
|
|
|
|
174
|
|
|
return [ |
|
175
|
4 |
|
'form' => $form->createView(), |
|
176
|
4 |
|
'payment_id' => $Payment->getId(), |
|
177
|
4 |
|
'Payment' => $Payment, |
|
178
|
|
|
]; |
|
179
|
|
|
} |
|
180
|
|
|
|
|
181
|
|
|
/** |
|
|
|
|
|
|
182
|
|
|
* @Route("/{_admin}/setting/shop/payment/image/add", name="admin_payment_image_add") |
|
183
|
|
|
*/ |
|
|
|
|
|
|
184
|
2 |
|
public function imageAdd(Application $app, Request $request) |
|
185
|
|
|
{ |
|
186
|
2 |
|
if (!$request->isXmlHttpRequest()) { |
|
187
|
1 |
|
throw new BadRequestHttpException(); |
|
188
|
|
|
} |
|
189
|
|
|
|
|
190
|
1 |
|
$images = $request->files->get('payment_register'); |
|
191
|
1 |
|
$filename = null; |
|
192
|
1 |
|
if (isset($images['payment_image_file'])) { |
|
193
|
|
|
$image = $images['payment_image_file']; |
|
194
|
|
|
|
|
195
|
|
|
//ファイルフォーマット検証 |
|
196
|
|
|
$mimeType = $image->getMimeType(); |
|
197
|
|
|
if (0 !== strpos($mimeType, 'image')) { |
|
198
|
|
|
throw new UnsupportedMediaTypeHttpException(); |
|
199
|
|
|
} |
|
200
|
|
|
|
|
201
|
|
|
$extension = $image->guessExtension(); |
|
202
|
|
|
$filename = date('mdHis').uniqid('_').'.'.$extension; |
|
203
|
|
|
$image->move($this->appConfig['image_temp_realdir'], $filename); |
|
204
|
|
|
} |
|
205
|
1 |
|
$event = new EventArgs( |
|
206
|
|
|
array( |
|
207
|
1 |
|
'images' => $images, |
|
208
|
1 |
|
'filename' => $filename, |
|
209
|
|
|
), |
|
210
|
1 |
|
$request |
|
211
|
|
|
); |
|
212
|
1 |
|
$this->eventDispatcher->dispatch(EccubeEvents::ADMIN_SETTING_SHOP_PAYMENT_IMAGE_ADD_COMPLETE, $event); |
|
213
|
1 |
|
$filename = $event->getArgument('filename'); |
|
214
|
|
|
|
|
215
|
1 |
|
return $app->json(array('filename' => $filename), 200); |
|
216
|
|
|
} |
|
217
|
|
|
|
|
218
|
|
|
/** |
|
|
|
|
|
|
219
|
|
|
* @Method("DELETE") |
|
220
|
|
|
* @Route("/{_admin}/setting/shop/payment/{id}/delete", requirements={"id" = "\d+"}, name="admin_setting_shop_payment_delete") |
|
221
|
|
|
*/ |
|
|
|
|
|
|
222
|
1 |
|
public function delete(Application $app, Request $request, Payment $TargetPayment) |
|
223
|
|
|
{ |
|
224
|
1 |
|
$this->isTokenValid($app); |
|
225
|
|
|
|
|
226
|
1 |
|
$rank = 1; |
|
227
|
1 |
|
$Payments = $this->paymentRepository->findBy(array(), array('rank' => 'ASC')); |
|
228
|
1 |
|
foreach ($Payments as $Payment) { |
|
229
|
1 |
|
$Payment->setRank($rank++); |
|
230
|
|
|
} |
|
231
|
|
|
|
|
232
|
|
|
try { |
|
233
|
1 |
|
$this->paymentRepository->delete($TargetPayment); |
|
234
|
1 |
|
$this->entityManager->flush(); |
|
235
|
|
|
|
|
236
|
1 |
|
$event = new EventArgs( |
|
237
|
|
|
array( |
|
238
|
1 |
|
'Payment' => $TargetPayment, |
|
239
|
|
|
), |
|
240
|
1 |
|
$request |
|
241
|
|
|
); |
|
242
|
1 |
|
$this->eventDispatcher->dispatch(EccubeEvents::ADMIN_SETTING_SHOP_PAYMENT_DELETE_COMPLETE, $event); |
|
243
|
|
|
|
|
244
|
1 |
|
$app->addSuccess('admin.delete.complete', 'admin'); |
|
245
|
|
|
} catch(ForeignKeyConstraintViolationException $e) { |
|
246
|
|
|
$this->entityManager->rollback(); |
|
247
|
|
|
$app->addError('admin.payment.delete.error', 'admin'); |
|
248
|
|
|
} |
|
249
|
|
|
|
|
250
|
1 |
|
return $app->redirect($app->url('admin_setting_shop_payment')); |
|
251
|
|
|
} |
|
252
|
|
|
|
|
253
|
|
|
/** |
|
|
|
|
|
|
254
|
|
|
* @Method("PUT") |
|
255
|
|
|
* @Route("/{_admin}/setting/shop/payment/{id}/up", requirements={"id" = "\d+"}, name="admin_setting_shop_payment_up") |
|
256
|
|
|
*/ |
|
|
|
|
|
|
257
|
1 |
View Code Duplication |
public function up(Application $app, Payment $current) |
|
|
|
|
|
|
258
|
|
|
{ |
|
259
|
1 |
|
$this->isTokenValid($app); |
|
260
|
|
|
|
|
261
|
1 |
|
$currentRank = $current->getRank(); |
|
262
|
1 |
|
$targetRank = $currentRank + 1; |
|
263
|
|
|
|
|
264
|
1 |
|
$target = $this->paymentRepository->findOneBy(array('rank' => $targetRank)); |
|
265
|
|
|
|
|
266
|
1 |
|
$target->setRank($currentRank); |
|
267
|
1 |
|
$current->setRank($targetRank); |
|
268
|
|
|
|
|
269
|
1 |
|
$this->entityManager->flush(); |
|
270
|
|
|
|
|
271
|
1 |
|
$app->addSuccess('admin.rank.move.complete', 'admin'); |
|
272
|
|
|
|
|
273
|
1 |
|
return $app->redirect($app->url('admin_setting_shop_payment')); |
|
274
|
|
|
} |
|
275
|
|
|
|
|
276
|
|
|
/** |
|
|
|
|
|
|
277
|
|
|
* @Method("PUT") |
|
278
|
|
|
* @Route("/{_admin}/setting/shop/payment/{id}/down", requirements={"id" = "\d+"}, name="admin_setting_shop_payment_down") |
|
279
|
|
|
*/ |
|
|
|
|
|
|
280
|
1 |
View Code Duplication |
public function down(Application $app, Payment $current) |
|
|
|
|
|
|
281
|
|
|
{ |
|
282
|
1 |
|
$this->isTokenValid($app); |
|
283
|
|
|
|
|
284
|
1 |
|
$currentRank = $current->getRank(); |
|
285
|
1 |
|
$targetRank = $currentRank - 1; |
|
286
|
|
|
|
|
287
|
1 |
|
$target = $this->paymentRepository->findOneBy(array('rank' => $targetRank)); |
|
288
|
|
|
|
|
289
|
1 |
|
$target->setRank($currentRank); |
|
290
|
1 |
|
$current->setRank($targetRank); |
|
291
|
|
|
|
|
292
|
1 |
|
$this->entityManager->flush(); |
|
293
|
|
|
|
|
294
|
1 |
|
$app->addSuccess('admin.rank.move.complete', 'admin'); |
|
295
|
|
|
|
|
296
|
1 |
|
return $app->redirect($app->url('admin_setting_shop_payment')); |
|
297
|
|
|
} |
|
298
|
|
|
|
|
299
|
|
|
/** |
|
|
|
|
|
|
300
|
|
|
* @Method("PUT") |
|
301
|
|
|
* @Route("/{_admin}/setting/shop/payment/{id}/visible", requirements={"id" = "\d+"}, name="admin_setting_shop_payment_visible") |
|
302
|
|
|
*/ |
|
|
|
|
|
|
303
|
|
|
public function visible(Application $app, Payment $Payment) |
|
304
|
|
|
{ |
|
305
|
|
|
$this->isTokenValid($app); |
|
306
|
|
|
|
|
307
|
|
|
$Payment->setVisible(!$Payment->isVisible()); |
|
308
|
|
|
|
|
309
|
|
|
$this->entityManager->flush(); |
|
310
|
|
|
|
|
311
|
|
|
if ($Payment->isVisible()) { |
|
312
|
|
|
$app->addSuccess('admin.payment.visible.complete', 'admin'); |
|
313
|
|
|
} else { |
|
314
|
|
|
$app->addSuccess('admin.payment.invisible.complete', 'admin'); |
|
315
|
|
|
} |
|
316
|
|
|
|
|
317
|
|
|
return $app->redirect($app->url('admin_setting_shop_payment')); |
|
318
|
|
|
} |
|
319
|
|
|
} |
|
320
|
|
|
|