Commit 402e8739 authored by shoei.kanno's avatar shoei.kanno

Merge branch '財布画面デザイン' into 'master'

財布機能追加

See merge request !58
parents b67d62f3 2a00476e
...@@ -48,8 +48,8 @@ public class EcsiteRestController { ...@@ -48,8 +48,8 @@ public class EcsiteRestController {
@Autowired @Autowired
WalletsService walletsService; WalletsService walletsService;
int totalPrice;
String sameId; String sameId;
int totalPrice;
//アカウント新規登録 //アカウント新規登録
@PostMapping("signUp") @PostMapping("signUp")
...@@ -117,17 +117,22 @@ public class EcsiteRestController { ...@@ -117,17 +117,22 @@ public class EcsiteRestController {
@GetMapping("buy") @GetMapping("buy")
public void buy(@AuthenticationPrincipal LoginUser userDetails, LinkedHashMap<String, Items> items, ArrayList <Items> cart, Wallets wallet){ public void buy(@AuthenticationPrincipal LoginUser userDetails, LinkedHashMap<String, Items> items, ArrayList <Items> cart, Wallets wallet){
if(walletsService.findOne(userDetails.getId()).getAmount() < totalPrice){
throw new BadRequestException();
}
items = (LinkedHashMap<String, Items>) session.getAttribute("cart"); items = (LinkedHashMap<String, Items>) session.getAttribute("cart");
items.forEach((key, value) -> { items.forEach((key, value) -> {
cart.add(value); cart.add(value);
}); });
User user = userDetails.getUser(); cart.forEach(item ->{
Integer userId = user.getId(); totalPrice += item.getPrice();
salesLogService.update(1, cart); });
Integer userId = (Integer) session.getAttribute("userId");
if(walletsService.findOne(userId).getAmount() < totalPrice){
throw new BadRequestException();
}
//支払い
walletsService.pay(userId, totalPrice);
salesLogService.update(userId, cart);
session.removeAttribute("cart"); session.removeAttribute("cart");
session.removeAttribute("cartValue"); session.removeAttribute("cartValue");
totalPrice = 0;
} }
} }
\ No newline at end of file
...@@ -30,6 +30,15 @@ public class WalletsService { ...@@ -30,6 +30,15 @@ public class WalletsService {
return walletsRepository.save(wallet); return walletsRepository.save(wallet);
} }
//チャージ処理
public Wallets charge(Integer id, Integer amount){
//対象の財布情報を取得
Wallets wallet = new Wallets();
wallet = this.findOne(id);
wallet.setAmount(wallet.getAmount() + amount);
return walletsRepository.save(wallet);
}
//支払い処理 //支払い処理
public Wallets pay(Integer id, Integer amount){ public Wallets pay(Integer id, Integer amount){
//対象の財布情報を取得 //対象の財布情報を取得
......
...@@ -15,11 +15,11 @@ import org.springframework.stereotype.Controller; ...@@ -15,11 +15,11 @@ import org.springframework.stereotype.Controller;
import org.springframework.ui.Model; import org.springframework.ui.Model;
import org.springframework.validation.annotation.Validated; import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.GetMapping; import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.ModelAttribute;
import org.springframework.web.bind.annotation.PathVariable; import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping; import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping; import org.springframework.web.bind.annotation.RequestMapping;
import com.example.domain.BadRequestException;
import com.example.domain.Items; import com.example.domain.Items;
import com.example.domain.SalesLog; import com.example.domain.SalesLog;
import com.example.domain.Shoes; import com.example.domain.Shoes;
...@@ -42,6 +42,11 @@ public class EcsiteController { ...@@ -42,6 +42,11 @@ public class EcsiteController {
@Autowired @Autowired
HttpSession session; HttpSession session;
@ModelAttribute
WalletsForm setUpForm() {
return new WalletsForm();
}
int totalPrice = 0; int totalPrice = 0;
//写真の表示用メソッド //写真の表示用メソッド
public String photoView(String Photo) { public String photoView(String Photo) {
...@@ -151,6 +156,7 @@ public class EcsiteController { ...@@ -151,6 +156,7 @@ public class EcsiteController {
public String Cart(Model model, @AuthenticationPrincipal LoginUser userDetails, LinkedHashMap<String, Items> items, ArrayList <Items> cart){ public String Cart(Model model, @AuthenticationPrincipal LoginUser userDetails, LinkedHashMap<String, Items> items, ArrayList <Items> cart){
User user = userDetails.getUser(); User user = userDetails.getUser();
model.addAttribute("user", user); model.addAttribute("user", user);
session.setAttribute("userId", user.getId());
items = (LinkedHashMap<String, Items>) session.getAttribute("cart"); items = (LinkedHashMap<String, Items>) session.getAttribute("cart");
if(items == null) { if(items == null) {
if(session.getAttribute("cartValue") == null) { if(session.getAttribute("cartValue") == null) {
...@@ -189,7 +195,7 @@ public class EcsiteController { ...@@ -189,7 +195,7 @@ public class EcsiteController {
//財布チャージ処理 //財布チャージ処理
@PostMapping("wallets/charge/{id}") @PostMapping("wallets/charge/{id}")
public String walletsCharge(@PathVariable Integer id, @Validated WalletsForm form){ public String walletsCharge(@PathVariable Integer id, @Validated WalletsForm form){
walletsService.pay(id, form.getAmount()); walletsService.charge(id, form.getAmount());
return "redirect:/top"; return "redirect:/limited/top";
} }
} }
...@@ -21,7 +21,7 @@ $('#ok-btn').on('click',function(){ ...@@ -21,7 +21,7 @@ $('#ok-btn').on('click',function(){
alert("購入が完了しました。"); alert("購入が完了しました。");
window.location.href = "/limited/top"; window.location.href = "/limited/top";
}) })
.faild(function(){ .fail(function(){
alert("ウォレットの残高が足りません。チャージしてください"); alert("ウォレットの残高が足りません。チャージしてください");
}) })
}); });
\ No newline at end of file
...@@ -98,7 +98,7 @@ $('.cartBtn').on('click', function(event){ ...@@ -98,7 +98,7 @@ $('.cartBtn').on('click', function(event){
contentType: 'application/json', contentType: 'application/json',
dataType: "json", dataType: "json",
data: JSON.stringify(data) data: JSON.stringify(data)
}); })
//[#modal-content]と[#modal-overlay]をフェードアウトした後に… //[#modal-content]と[#modal-overlay]をフェードアウトした後に…
$( "#modal-content,#modal-overlay" ).fadeOut( "slow" , function(){ $( "#modal-content,#modal-overlay" ).fadeOut( "slow" , function(){
//[#modal-overlay]を削除する //[#modal-overlay]を削除する
......
...@@ -69,7 +69,7 @@ ...@@ -69,7 +69,7 @@
<div class="container"> <div class="container">
<p id="online-shoe-store" class="wallets-p"><span id="online-shoe-store-span">Wallets</span></p> <p id="online-shoe-store" class="wallets-p"><span id="online-shoe-store-span">Wallets</span></p>
<p id="balance">Balance<span id="balanceSpan" th:text="'&yen;' + ${wallet.amount}">10000</span></p> <p id="balance">Balance<span id="balanceSpan" th:text="'&yen;' + ${wallet.amount}">10000</span></p>
<form id="wallets-form" method="post" th:action="@{/limited/wallets/charge/{id}(id=${user.id})}" th:object="${walletForm}"> <form id="wallets-form" method="post" th:action="@{/limited/wallets/charge/{id}(id=${user.id})}" th:object="${walletsForm}">
<div id="amount-form"> <div id="amount-form">
<label for="amount">Charge Money</label> <label for="amount">Charge Money</label>
<span id="en">&yen;</span><input type="number" id="amount" name="amount" required="required" th:field="*{amount}"/> <span id="en">&yen;</span><input type="number" id="amount" name="amount" required="required" th:field="*{amount}"/>
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment