1
|
|
|
<?php |
2
|
|
|
/* |
3
|
|
|
* This file is part of EC-CUBE |
4
|
|
|
* |
5
|
|
|
* Copyright(c) 2000-2017 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
|
|
|
namespace Eccube\Service\PurchaseFlow\Processor; |
25
|
|
|
|
26
|
|
|
use Doctrine\ORM\EntityManager; |
27
|
|
|
use Eccube\Annotation\Inject; |
28
|
|
|
use Eccube\Entity\BaseInfo; |
29
|
|
|
use Eccube\Entity\ItemHolderInterface; |
30
|
|
|
use Eccube\Entity\Master\OrderItemType; |
31
|
|
|
use Eccube\Entity\Master\TaxDisplayType; |
32
|
|
|
use Eccube\Entity\Master\TaxType; |
33
|
|
|
use Eccube\Entity\Order; |
34
|
|
|
use Eccube\Entity\OrderItem; |
35
|
|
|
use Eccube\Entity\Shipping; |
36
|
|
|
use Eccube\Service\PurchaseFlow\ItemHolderProcessor; |
37
|
|
|
use Eccube\Service\PurchaseFlow\ProcessResult; |
38
|
|
|
use Eccube\Service\PurchaseFlow\PurchaseContext; |
39
|
|
|
|
40
|
|
|
/** |
41
|
|
|
* 利用ポイントに応じてポイントを減算する. |
42
|
|
|
*/ |
43
|
|
|
class SubstractPointProcessor implements ItemHolderProcessor |
44
|
|
|
{ |
45
|
|
|
/** |
46
|
|
|
* @var BaseInfo |
47
|
|
|
*/ |
48
|
|
|
protected $BaseInfo; |
49
|
|
|
|
50
|
|
|
/** |
|
|
|
|
51
|
|
|
* SubstractPointProcessor constructor. |
52
|
|
|
* |
53
|
|
|
* @param $app |
|
|
|
|
54
|
|
|
*/ |
55
|
|
|
public function __construct(BaseInfo $BaseInfo) |
56
|
|
|
{ |
57
|
|
|
$this->BaseInfo = $BaseInfo; |
58
|
|
|
} |
59
|
|
|
|
60
|
|
|
/** |
61
|
|
|
* @param ItemHolderInterface $itemHolder |
62
|
|
|
* @param PurchaseContext $context |
63
|
|
|
* |
64
|
|
|
* @return ProcessResult |
65
|
|
|
*/ |
66
|
|
|
public function process(ItemHolderInterface $itemHolder, PurchaseContext $context) |
67
|
|
|
{ |
68
|
|
|
/** @var Order $Order */ |
69
|
|
|
$Order = $itemHolder; |
70
|
|
|
if ($Order->getUsePoint() > 0) { |
71
|
|
|
$Order->setAddPoint($this->substract($Order->getAddPoint(), $Order->getUsePoint(), $this->BaseInfo->getBasicPointRate())); |
72
|
|
|
} |
73
|
|
|
return ProcessResult::success(); |
|
|
|
|
74
|
|
|
} |
75
|
|
|
|
76
|
|
|
/** |
77
|
|
|
* Substract point. |
78
|
|
|
* |
79
|
|
|
* @param integer $totalPoint 合計ポイント |
80
|
|
|
* @param integer $usePoint 利用ポイント |
81
|
|
|
* @param integer $pointRate ポイント付与率(%) |
82
|
|
|
* @return integer Point after substraction |
83
|
|
|
*/ |
84
|
|
|
protected function substract($totalPoint, $usePoint, $pointRate) |
85
|
|
|
{ |
86
|
|
|
$add_point = $totalPoint - intval($usePoint * ($pointRate / 100)); |
87
|
|
|
return $add_point < 0 ? 0 : $add_point; |
|
|
|
|
88
|
|
|
} |
89
|
|
|
} |
90
|
|
|
|