Commit 2ff3fb7c authored by Jiwon Yoon's avatar Jiwon Yoon
Browse files

Merge branch 'ourMaster' into jiwon

parents 8ae10e44 581c62c4
...@@ -53,6 +53,13 @@ function ListCard(props) { ...@@ -53,6 +53,13 @@ function ListCard(props) {
<Col sm={3} xs={5} className='p-1'><li>주문날짜 :</li></Col> <Col sm={3} xs={5} className='p-1'><li>주문날짜 :</li></Col>
<Col sm={8} xs={6} className='p-1'><strong>{e.createdAt.substring(0, 10)}</strong></Col> <Col sm={8} xs={6} className='p-1'><strong>{e.createdAt.substring(0, 10)}</strong></Col>
<Col sm={3} xs={5} className='p-1'><li>결제정보 :</li></Col>
<Col sm={8} xs={6} className='p-1'><strong>{e.paymentWay}</strong>{e.paymentWay == 'Remittance' ? (
<>
<br /><strong>{e.paymentInfo.bank} / ~ {e.paymentInfo.deadline}</strong>
</>
) : ''}</Col>
</Row> </Row>
</Col> </Col>
</Card.Text> </Card.Text>
...@@ -69,7 +76,7 @@ function ListCard(props) { ...@@ -69,7 +76,7 @@ function ListCard(props) {
<Card> <Card>
<Row className="mx-1"> <Row className="mx-1">
<Col xs={2} sm={2} className="text-center my-auto"> <Col xs={2} sm={2} className="text-center my-auto">
<input className="" type="checkbox" name={String(e._id)} onChange={props.checkedCart} /> <input type="checkbox" name={String(e._id)} onChange={props.checkedCart} checked={e.checked} />
</Col> </Col>
<Col className="text-center"> <Col className="text-center">
<Card.Img className="img-fluid" variant="top" src={e.productId.main_imgUrl && `/images/${e.productId.main_imgUrl}`} style={{ width: '20rem' }} /> <Card.Img className="img-fluid" variant="top" src={e.productId.main_imgUrl && `/images/${e.productId.main_imgUrl}`} style={{ width: '20rem' }} />
...@@ -83,7 +90,7 @@ function ListCard(props) { ...@@ -83,7 +90,7 @@ function ListCard(props) {
<Card.Text >수량</Card.Text> <Card.Text >수량</Card.Text>
<div> <div>
<input type="image" name={String(e._id)} alt="마이너스" src="https://img.icons8.com/ios-glyphs/20/000000/minus-math.png" className="align-middle" onClick={props.minusNum} /> <input type="image" name={String(e._id)} alt="마이너스" src="https://img.icons8.com/ios-glyphs/20/000000/minus-math.png" className="align-middle" onClick={props.minusNum} />
<input type="number" style={{ width: '30px' }} className="text-center align-middle mx-1" placeholder={e.count} value={e.count} readOnly></input> <input type="number" style={{ width: '35px' }} className="text-center align-middle mx-1" placeholder={e.count} value={e.count} readOnly></input>
<input type="image" name={String(e._id)} alt="플러스" src="https://img.icons8.com/ios-glyphs/20/000000/plus-math.png" className="align-middle" onClick={props.plusNum} /> <input type="image" name={String(e._id)} alt="플러스" src="https://img.icons8.com/ios-glyphs/20/000000/plus-math.png" className="align-middle" onClick={props.plusNum} />
</div> </div>
</Card.Body> </Card.Body>
......
...@@ -166,7 +166,7 @@ function Account() { ...@@ -166,7 +166,7 @@ function Account() {
</Row> </Row>
<Row className="px-3"> <Row className="px-3">
<Card.Body className="p-2 text-center"> <Card.Body className="p-2 text-center">
<h4><Link to="/"> <h4><Link to="/" style={{ textDecoration: "none" }}>
<strong title="홈으로"> <strong title="홈으로">
<Image src="/icon/mypagetiger.svg" width={"30rem"} roundedCircle className="img-thumbnail" > <Image src="/icon/mypagetiger.svg" width={"30rem"} roundedCircle className="img-thumbnail" >
</Image>KU# </Image>KU#
......
...@@ -79,6 +79,7 @@ function Payment({ match, location }) { ...@@ -79,6 +79,7 @@ function Payment({ match, location }) {
function handleReceiverInfo(e) { function handleReceiverInfo(e) {
const { name, value } = e.target const { name, value } = e.target
console.log(name,value)
setOrder({ ...order, receiverInfo: { ...order.receiverInfo, [name]: value } }) setOrder({ ...order, receiverInfo: { ...order.receiverInfo, [name]: value } })
} }
...@@ -129,25 +130,27 @@ function Payment({ match, location }) { ...@@ -129,25 +130,27 @@ function Payment({ match, location }) {
<Row className="justify-content-md-center"> <Row className="justify-content-md-center">
<Col md={6} className="border m-5 p-5"> <Col md={6} className="border m-5 p-5">
<Form> <Form>
<Form.Group controlId="exampleForm.ControlSelect1"> <Form.Group controlId="bank">
<Form.Label>입금은행</Form.Label> <Form.Label>입금은행</Form.Label>
<Form.Control as="select" placeholder="입금은행을 선택하세요."> <Form.Control as="select" name="bank" onChange={handleReceiverInfo}>
<option>농협 / 352-0559-2528-83 / 김수빈</option> <option value=''>입금은행을 선택하세요.</option>
<option>우리은행 / 0000-000-000000 / 이재연</option> <option value="농협">농협 / 352-0559-2528-83 / 김수빈</option>
<option>국민은행 / 111111-11-111111 / 윤대기</option> <option value="우리은행">우리은행 / 0000-000-000000 / 이재연</option>
<option value="국민은행">국민은행 / 111111-11-111111 / 윤대기</option>
</Form.Control> </Form.Control>
</Form.Group> </Form.Group>
<Form.Group controlId="formName"> <Form.Group controlId="depositor">
<Form.Label>입금자</Form.Label> <Form.Label>입금자</Form.Label>
<Form.Control type="email" placeholder="윤지원" /> <Form.Control type="text" name="depositor" onChange={handleReceiverInfo} />
</Form.Group> </Form.Group>
<Form.Group controlId="formDay"> <Form.Group controlId="deadline">
<Form.Label>입금예정일</Form.Label> <Form.Label>입금예정일</Form.Label>
<Form.Control type="date" /> <Form.Control type="date" name="deadline" onChange={handleReceiverInfo} />
</Form.Group> </Form.Group>
</Form> </Form>
</Col> </Col>
</Row>) </Row>)
setCompleteState("Remittance")
setPaymentWay(bankList) setPaymentWay(bankList)
} }
} }
...@@ -167,61 +170,69 @@ function Payment({ match, location }) { ...@@ -167,61 +170,69 @@ function Payment({ match, location }) {
order.products.map((el) => { order.products.map((el) => {
cartIds.push(el._id) cartIds.push(el._id)
}) })
try { // try {
setError('') // setError('')
const response = await axios.post(`/api/order/addorder`, { // const response = await axios.post(`/api/order/addorder`, {
userId: user, // userId: user,
...order, // ...order,
total: finalPrice + 2500 // paymentWay: completeState,
}) // total: finalPrice + 2500
const response2 = await axios.post(`/api/cart/deletecart2`, { // })
userId: user, // const response2 = await axios.post(`/api/cart/deletecart2`, {
cartId: cartIds // userId: user,
}) // cartId: cartIds
const response3 = await axios.post(`/api/product/pluspurchase`, { // })
products: order.products // const response3 = await axios.post(`/api/product/pluspurchase`, {
}) // products: order.products
if (completeState === "kakaopay") { // })
let itemNames = "" // if (completeState === "kakaopay") {
if (cart.length > 1) { // let itemNames = ""
itemNames = cart[0].productId.pro_name + '' + String(cart.length - 1) + '' // if (cart.length > 1) {
} else { // itemNames = cart[0].productId.pro_name + ' 외 ' + String(cart.length - 1) + '개'
itemNames = cart[0].productId.pro_name // } else {
} // itemNames = cart[0].productId.pro_name
setError('') // }
const response = await fetch('/api/kakaopay/test/single', { // setError('')
method: "POST", // const response = await fetch('/api/kakaopay/test/single', {
headers: { // method: "POST",
'Content-type': 'application/json' // headers: {
}, // 'Content-type': 'application/json'
body: JSON.stringify({ // },
cid: 'TC0ONETIME', // body: JSON.stringify({
partner_order_id: 'partner_order_id', // cid: 'TC0ONETIME',
partner_user_id: user, // partner_order_id: 'partner_order_id',
item_name: itemNames, // partner_user_id: user,
quantity: cart.length, // item_name: itemNames,
total_amount: finalPrice + 2500, // quantity: cart.length,
vat_amount: 200, // total_amount: finalPrice + 2500,
tax_free_amount: 0, // vat_amount: 200,
approval_url: 'http://localhost:3000/paymentcompleted', // tax_free_amount: 0,
fail_url: 'http://localhost:3000/shoppingcart', // approval_url: 'http://localhost:3000/paymentcompleted',
cancel_url: 'http://localhost:3000/shoppingcart', // fail_url: 'http://localhost:3000/shoppingcart',
}) // cancel_url: 'http://localhost:3000/shoppingcart',
}) // })
const data = await response.json() // })
window.location.href = data.redirect_url // const data = await response.json()
} else { // window.location.href = data.redirect_url
alert("주문이 완료되었습니다.") // } else {
history.push('/paymentcompleted') // alert("주문이 완료되었습니다.")
} // history.push('/paymentcompleted')
} catch (error) { // }
catchErrors(error, setError) // } catch (error) {
alert("주문에 실패하셨습니다. 다시 확인해주세요.") // catchErrors(error, setError)
} // alert("주문에 실패하셨습니다. 다시 확인해주세요.")
// window.location.reload()
// }
}
if (error) {
alert(`${error}`)
setError('')
} }
return ( return (
<Container className="mb-5"> <Container className="mb-5">
{console.log("order=",order)}
<h3 className="my-5 font-weight-bold text-center">주문/결제</h3> <h3 className="my-5 font-weight-bold text-center">주문/결제</h3>
<div> <div>
<h5 className="font-weight-bold py-3 border-top border-bottom text-center" style={{ background: '#F7F3F3' }}>주문자 정보</h5> <h5 className="font-weight-bold py-3 border-top border-bottom text-center" style={{ background: '#F7F3F3' }}>주문자 정보</h5>
...@@ -249,15 +260,15 @@ function Payment({ match, location }) { ...@@ -249,15 +260,15 @@ function Payment({ match, location }) {
<Row className="justify-content-center"> <Row className="justify-content-center">
<Col md={8}> <Col md={8}>
<Form> <Form>
<Form.Group> <Form.Group controlId="recipientName">
<Form.Label>이름</Form.Label> <Form.Label>이름</Form.Label>
<Form.Control type="text" name="name" onChange={handleReceiverInfo}></Form.Control> <Form.Control type="text" name="name" onChange={handleReceiverInfo}></Form.Control>
</Form.Group> </Form.Group>
<Form.Group> <Form.Group controlId="recipientTel">
<Form.Label>휴대전화</Form.Label> <Form.Label>휴대전화</Form.Label>
<Form.Control type="text" name="tel" onChange={handleReceiverInfo}></Form.Control> <Form.Control type="text" name="tel" onChange={handleReceiverInfo}></Form.Control>
</Form.Group> </Form.Group>
<Form.Group controlId="formBasicAdd"> <Form.Group controlId="recipientAdd">
<Form.Label>주소</Form.Label> <Form.Label>주소</Form.Label>
<Form.Row> <Form.Row>
<Col xs={4} sm={4}> <Col xs={4} sm={4}>
......
...@@ -26,6 +26,7 @@ function Product({ location }) { ...@@ -26,6 +26,7 @@ function Product({ location }) {
}, [product]) }, [product])
useEffect(() => { useEffect(() => {
window.scrollTo(0,0)
setProduct(location.state) setProduct(location.state)
}, [location.state]) }, [location.state])
......
...@@ -17,6 +17,10 @@ function ShoppingCart() { ...@@ -17,6 +17,10 @@ function ShoppingCart() {
getCart() getCart()
}, [user]) }, [user])
useEffect(() => {
price()
}, [cart])
function plusNum(e) { function plusNum(e) {
const addCount = cart.map((el) => { const addCount = cart.map((el) => {
if (el._id === e.target.name) { if (el._id === e.target.name) {
...@@ -27,6 +31,7 @@ function ShoppingCart() { ...@@ -27,6 +31,7 @@ function ShoppingCart() {
}) })
setCart(addCount) setCart(addCount)
} }
function minusNum(e) { function minusNum(e) {
const addCount = cart.map((el) => { const addCount = cart.map((el) => {
if (el._id === e.target.name) { if (el._id === e.target.name) {
...@@ -38,8 +43,17 @@ function ShoppingCart() { ...@@ -38,8 +43,17 @@ function ShoppingCart() {
setCart(addCount) setCart(addCount)
} }
function checkedCart(e) { function price() {
let price = 0 let price = 0
const list = cart.filter((el) => el.checked === true)
list.map((el) => {
price = el.count * el.productId.price + price
})
setFinalPrice(price)
setFinalCart(list)
}
function checkedCart(e) {
const cartCheck = cart.map((el) => { const cartCheck = cart.map((el) => {
if (el._id === e.target.name) { if (el._id === e.target.name) {
return { ...el, checked: !el.checked } return { ...el, checked: !el.checked }
...@@ -47,13 +61,7 @@ function ShoppingCart() { ...@@ -47,13 +61,7 @@ function ShoppingCart() {
return { ...el } return { ...el }
} }
}) })
const list = cartCheck.filter((el) => el.checked === true)
list.map((el) => {
price = el.count * el.productId.price + price
})
setFinalPrice(price)
setCart(cartCheck) setCart(cartCheck)
setFinalCart(list)
} }
async function deleteCart(e) { async function deleteCart(e) {
...@@ -74,7 +82,7 @@ function ShoppingCart() { ...@@ -74,7 +82,7 @@ function ShoppingCart() {
setError('') setError('')
const response = await axios.get(`/api/cart/showcart/${user}`) const response = await axios.get(`/api/cart/showcart/${user}`)
const addChecked = response.data.map((el) => { const addChecked = response.data.map((el) => {
return { ...el, checked: false } return { ...el, checked: true }
}) })
setCart(addChecked) setCart(addChecked)
} catch (error) { } catch (error) {
......
...@@ -4,10 +4,27 @@ import User from "../schemas/User.js"; ...@@ -4,10 +4,27 @@ import User from "../schemas/User.js";
import Product from "../schemas/Product.js"; import Product from "../schemas/Product.js";
const addorder = async (req, res) => { const addorder = async (req, res) => {
const { userId, products, receiverInfo, total } = req.body const { userId, products, receiverInfo, paymentWay, total } = req.body
console.log("pay=",paymentWay)
console.log(receiverInfo.bank , receiverInfo.depositor , receiverInfo.deadline)
try { try {
const newOrder = await new Order({ userId, products, receiverInfo, total }).save() if (!/^[0-9]{2,3}-[0-9]{3,4}-[0-9]{4}/.test(receiverInfo.tel)) {
res.status(200).send('Order DB에 저장 완료') return res.status(422).send('유효한 휴대전화번호가 아닙니다. 정확히 입력해주세요.')
} else if (paymentWay) {
if (paymentWay == 'Remittance') {
if (!(receiverInfo.bank && receiverInfo.depositor && receiverInfo.deadline)) {
return res.status(422).send('선택하신 결제 수단에 관한 모든 정보를 입력해주시기 바랍니다.')
}
const paymentInfo = { bank: receiverInfo.bank, depositor: receiverInfo.depositor, deadline: receiverInfo.deadline }
const newOrder = await new Order({ userId, products, receiverInfo, paymentWay, paymentInfo, total }).save()
res.status(200).send('Order DB에 저장 완료')
} else {
const newOrder = await new Order({ userId, products, receiverInfo, paymentWay, total }).save()
res.status(200).send('Order DB에 저장 완료')
}
} else {
return res.status(422).send('결제수단을 선택해주시기 바랍니다.')
}
} catch (error) { } catch (error) {
console.log(error) console.log(error)
res.status(500).send('Order DB에 저장 실패') res.status(500).send('Order DB에 저장 실패')
......
...@@ -32,12 +32,15 @@ const userById = async (req, res, next, id) => { ...@@ -32,12 +32,15 @@ const userById = async (req, res, next, id) => {
const signup = async (req, res) => { const signup = async (req, res) => {
const { name, number1, number2, id, password, tel, email } = req.body const { name, number1, number2, id, password, tel, email } = req.body
try { try {
if (!isLength(password, { min: 8, max: 15 })) {
return res.status(422).send('비밀번호는 8-15자리로 입력해주세요.')
}
const user = await User.findOne({ id }) const user = await User.findOne({ id })
if (user) { if (user) {
return res.status(422).send(`${id}가 이미 사용중입니다.`) return res.status(422).send(`${id}가 이미 사용중입니다.`)
} else if (!isLength(password, { min: 8, max: 15 })) {
return res.status(422).send('비밀번호는 8-15자리로 입력해주세요.')
} else if (number1.match('[^0-9]') || number2.match('[^0-9]')) {
return res.status(422).send('주민등록번호는 숫자로 입력해주세요.')
} else if (!/^[0-9]{2,3}-[0-9]{3,4}-[0-9]{4}/.test(tel)) {
return res.status(422).send('유효한 휴대전화번호가 아닙니다. 정확히 입력해주세요.')
} }
const hash = await bcrypt.hash(password, 10) const hash = await bcrypt.hash(password, 10)
const newUser = await new User({ const newUser = await new User({
...@@ -50,7 +53,7 @@ const signup = async (req, res) => { ...@@ -50,7 +53,7 @@ const signup = async (req, res) => {
email email
}).save() }).save()
await new Cart({ userId: newUser._id }).save() await new Cart({ userId: newUser._id }).save()
res.json(newUser) res.status(200).json('회원가입 성공')
} catch (error) { } catch (error) {
console.log(error) console.log(error)
res.status(500).send('죄송합니다. 다시 입력해 주십시오.') res.status(500).send('죄송합니다. 다시 입력해 주십시오.')
......
...@@ -52,8 +52,22 @@ const OrderSchema = new mongoose.Schema({ ...@@ -52,8 +52,22 @@ const OrderSchema = new mongoose.Schema({
type: String, type: String,
required: true required: true
} }
} },
, paymentWay: {
type: String,
required: true
},
paymentInfo: {
bank: {
type: String
},
depositor: {
type: String
},
deadline: {
type: String
}
},
total: { total: {
type: Number, type: Number,
required: true required: true
......
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