-
Notifications
You must be signed in to change notification settings - Fork 4
/
PurchaseController.java
240 lines (205 loc) · 8.77 KB
/
PurchaseController.java
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
package com.mogotco.controller;
import java.io.IOException;
import java.net.URLEncoder;
import java.util.List;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;
import com.mogotco.dto.CouponDTO;
import com.mogotco.dto.MentorDTO;
import com.mogotco.dto.MentoringDTO;
import com.mogotco.dto.MentoringOptionDTO;
import com.mogotco.dto.MentoringmemberDTO;
import com.mogotco.dto.PurchaseDTO;
import com.mogotco.dto.PurchaseDetailDTO;
import com.mogotco.dto.UserCouponDTO;
import com.mogotco.dto.UserDTO;
import com.mogotco.service.MentorService;
import com.mogotco.service.MentoringOptionService;
import com.mogotco.service.MentoringService;
import com.mogotco.service.MentoringmemberService;
import com.mogotco.service.PurchaseDetailService;
import com.mogotco.service.PurchaseService;
import com.mogotco.service.UserCouponService;
import com.mogotco.service.UserService;
@Controller
@RequestMapping("/purchase")
public class PurchaseController {
String purchase = "purchase/";
//service
@Autowired
PurchaseService service;
@Autowired
PurchaseDetailService service1;
@Autowired
MentoringService service2;
@Autowired
MentoringmemberService service3;
@Autowired
MentoringOptionService service4;
@Autowired
UserService service5;
@Autowired
UserCouponService ucservice;
@Autowired
MentorService mservice;
// 아이디값 유무 판단
@RequestMapping("/idcheck")
public void idcheck(PurchaseDTO purchase, HttpServletRequest request, HttpServletResponse response) {
// current session이 없으면 없는채로 두는 것
HttpSession session = request.getSession(false);
// session정보가 없을 때
if (session == null) {
try {
// session이 없을 때 controller주소로 감
response.sendRedirect("/mogotco/user/login");
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
} else {
try {// session이 있을 때 controller주소로 감
//한국어 encode해줘야 함
String mentoring_mtitle = request.getParameter("mentoring_mtitle");
String encodeMentoring_mtitle = URLEncoder.encode(mentoring_mtitle, "UTF-8");
String mentoring_mplace = request.getParameter("mentoring_mplace");
String encodeMentoring_mplace = URLEncoder.encode(mentoring_mplace, "UTF-8");
response.sendRedirect("/mogotco/purchase?mentoring_mentoringid=" +request.getParameter("mentoring_mentoringid")+"&mentoringoption_mentoringtime="+request.getParameter("mentoringoption_mentoringtime")
+ "&mentoring_mtitle="+encodeMentoring_mtitle + "&mentoring_mentoringdate="+request.getParameter("mentoring_mentoringdate") + "&mentoring_mplace="+encodeMentoring_mplace
+ "&mentoring_mentoringprice="+request.getParameter("mentoring_mentoringprice") + "&mentor_userid="+request.getParameter("mentor_userid"));
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
}
//구매페이지
@RequestMapping("")
public String purchase(Model model, HttpSession session, PurchaseDTO pur) {
//mentoringid제외한 것
int i = 0;
String nonface = "nonface";
if(pur.getMentoring_mplace().length() == 0) {
pur.setMentoring_mplace(nonface);
}
model.addAttribute("pur", pur);
model.addAttribute("zero", i);
//mentoringoptionid
MentoringOptionDTO mto = null;
try {
mto = service4.viewmentoringoptionid(pur.getMentoring_mentoringid(), pur.getMentoringoption_mentoringtime());
model.addAttribute("mto", mto);
model.addAttribute("center", purchase+"purchase");
} catch (Exception e) {
// TODO Auto-generated catch block
e.printStackTrace();
model.addAttribute("center", purchase+"error");
}
return "main";
}
//구매상세페이지
@RequestMapping("/purchasedetail")
public String purchasedetail(Model model, String id) {
List<PurchaseDetailDTO> detail = null;
PurchaseDetailDTO detailmember = null;
UserDTO myuser = null;
MentorDTO mentor = null;
try {
//멘토링 정보를 불러오고
detail = service1.wholedetail(id);
//향상 for문에 first라는 개별 객체에 넣어줌
for(PurchaseDetailDTO first : detail) {
//멘토링 멤버수를 뽑기위해 mentoringoptionid를 불러오고
Integer mentoringoptionid = first.getMentoringoptionid();
//뽑은 멤버수 정보를
detailmember = service1.groupcount(mentoringoptionid);
//다시 first객체에 setting해준다.
first.setMentoringmembercnt(detailmember.getMentoringmembercnt());
}
myuser = service5.get(id);
mentor = mservice.mentorAll(id);
model.addAttribute("userid", id);
model.addAttribute("list", detail);
model.addAttribute("us", myuser);
model.addAttribute("ms", mentor);
model.addAttribute("center", purchase+"purchasedetail");
} catch (Exception e) {
// TODO Auto-generated catch block
e.printStackTrace();
model.addAttribute("center", purchase+"error");
}
return "main";
}
//구매완료페이지
@RequestMapping("/purchasefinish")
public String purchasefinish(Model model, HttpSession session, PurchaseDTO pur, int willusepoint, int mentoringprice, int willusecoupon) {
//결제완료 버튼을 눌렀을 때
try {
//구매 내용을 등록하고
service.register(pur);
//구매한 mentoring정보를 불러옴(url을 불러오기위한 것)
MentoringDTO mentoring = service2.get(pur.getMentoring_mentoringid());
//멘토링 멤버번호를 생성(멘토링 멤버 추가)
MentoringmemberDTO mentoringmember = new MentoringmemberDTO(0, pur.getMentoringoption_mentoringoptionid(), pur.getUserid());
service3.register(mentoringmember);
//구매이력을 바로 생성
int r = pur.getPurchaseid();
PurchaseDetailDTO detail = new PurchaseDetailDTO(0,pur.getMentoringoption_mentoringoptionid(), r, 0, "x", pur.getPurdate(),
pur.getPurprice(), pur.getPurpay(), pur.getPurcard(),pur.getMentoring_mtitle(), pur.getMentor_userid(), pur.getUser_mentorname(),
pur.getMentoring_mentoringdate(), pur.getMentoringoption_mentoringtime(),
mentoring.getMentorurl(), pur.getMentoring_mplace(), 0, mentoring.getMcaring(), mentoring.getMentorid(), 0, mentoring.getMentor_mentorimg(), null, null, 0);//membercount부분은 member부분에서 저장되기 때문에 굳이 detail에서 넣어줄 이유가 없음
service1.register(detail);
//해당 mentoringoption을 불러옴
MentoringOptionDTO beforementoringoption = service4.get(pur.getMentoringoption_mentoringoptionid());
//재고수정
MentoringOptionDTO aftermentoringoption = new MentoringOptionDTO(pur.getMentoringoption_mentoringoptionid(),
pur.getMentoring_mentoringid(), pur.getMentoringoption_mentoringtime(), beforementoringoption.getMoptionstock()-1);
service4.modify(aftermentoringoption);
//coupon 삭제
//지금 로그인한 회원의 쿠폰 목록정보
if(willusecoupon != 0) {
UserCouponDTO beforecoupon = null;
beforecoupon = ucservice.userCouponfind(pur.getUserid(), willusecoupon);
//delete
ucservice.remove(beforecoupon.getUsercouponid());
}
//point값 수정
//지금 로그인된 회원 정보
UserDTO beforeuser = null;
beforeuser = service5.get(pur.getUserid());
//수정 point
int modipoint = 0;
if(pur.getPurprice() >=30000) {
modipoint = beforeuser.getUserpoint() - willusepoint + (mentoringprice*3/100);
}else {
modipoint = beforeuser.getUserpoint() - willusepoint + mentoringprice/100;
}
//수정할 회원 정보
UserDTO afteruser = new UserDTO(beforeuser.getUserid(), beforeuser.getUserpwd(), beforeuser.getUsername(), beforeuser.getUseraddr(), beforeuser.getUsertel(), beforeuser.getUseremail(),
beforeuser.getUserdate(), beforeuser.getWithdraw(), beforeuser.getUserbirth(), modipoint, beforeuser.getNaverid(), beforeuser.getKakaoid(), beforeuser.getGoogleid(), beforeuser.getUsergen(),
beforeuser.getAddrnum(), beforeuser.getAddrdetail(), beforeuser.getAddrextra(), beforeuser.getSnsinsta(), beforeuser.getSnsgit(), beforeuser.getUserimg(),beforeuser.getMentor_mentorok());
//수정
service5.modify(afteruser);
//구매 정보 뽑음
PurchaseDTO finish = null;
finish=service.purchasefinishpage(r);
String nonface = "nonface";
if(finish.getMentoring_mplace().length() == 0) {
finish.setMentoring_mplace(nonface);
}
//model객체에 담음
model.addAttribute("list", finish);
//화면
model.addAttribute("center", purchase+"purchasefinish");
} catch (Exception e) {
// TODO Auto-generated catch block
e.printStackTrace();
model.addAttribute("center", purchase+"error");
}
return "main";
}
}