添加钱包模块、美化前端

This commit is contained in:
EhusoeAsom 2024-04-23 14:59:38 +08:00
parent 1c54eaff29
commit 2681504445
39 changed files with 2463 additions and 1440 deletions

Binary file not shown.

After

Width:  |  Height:  |  Size: 4.5 KiB

View File

@ -66,8 +66,8 @@
</div>
</template>
<script>
import Footer from '../components/Footer.vue';
export default {
import Footer from '../components/Footer.vue';
export default {
name: 'AddUserAddress',
data() {
return {
@ -130,7 +130,8 @@
return;
}
let url=`DeliveryAddressController/saveDeliveryAddress/${this.deliveryAddress.contactName}/${this.deliveryAddress.contactSex}/${this.deliveryAddress.contactTel}/${this.deliveryAddress.address}/${this.user.userId}`
let url =
`DeliveryAddressController/saveDeliveryAddress/${this.deliveryAddress.contactName}/${this.deliveryAddress.contactSex}/${this.deliveryAddress.contactTel}/${this.deliveryAddress.address}/${this.user.userId}`
this.$axios.post(url).then(response => {
if (response.data.result > 0) {
this.$router.push({
@ -147,8 +148,8 @@
});
},
fill() {
this.$axios.get('DeliveryAddressController/AddressInfo',{
params:{
this.$axios.get('DeliveryAddressController/AddressInfo', {
params: {
addressInfo: this.addressInfo
}
}).then(response => {
@ -160,60 +161,61 @@
});
}
}
}
}
</script>
<style scoped>
/****************** 总容器 ******************/
.wrapper {
/****************** 总容器 ******************/
.wrapper {
width: 100vw;
position: absolute;
}
}
/******head部分********/
.wrapper header {
/******head部分********/
.wrapper header {
width: 100%;
height: 12vw;
background-color: #01B0F2;
font-size: 4.8vw;
font-size: 5.5vw;
color: #fff;
z-index: 10;
display: flex;
justify-content: flex-start;
justify-content: center;
align-items: center;
position: fixed;
left: 0;
top: 0;
}
transition: all 0.3s ease;
}
.wrapper header i {
margin: 0vw 0vw 0vw 3vw;
font-size: 6vw;
.wrapper header i {
margin-right: 3vw;
font-size: 7vw;
user-select: none;
cursor: pointer;
}
}
.wrapper header p {
margin: 0vw 0vw 0vw 33.5vw;
}
.wrapper header p {
margin-left: 3vw;
}
.wrapper .shangbiao {
width:100vw;
.wrapper .shangbiao {
width: 100vw;
height: 20vw;
margin-top: 20vw;
margin-top: 14vw;
display: flex;
justify-content: center;
}
box-shadow: 0px 4px 6px rgba(0, 0, 0, 0.1);
}
.wrapper .shangbiao img{
.wrapper .shangbiao img {
width: 30vw;
height: 25vw;
}
}
/*******自动识别********/
.wrapper .identify {
/*******自动识别********/
.wrapper .identify {
width: 100vw;
height: 18vw;
@ -221,94 +223,105 @@
display: flex;
align-items: center;
justify-content: center;
}
}
.wrapper .identify input {
width: 70%;
height: 8vw;
font-size: 4vw;
.wrapper .identify input {
width: 80%;
height: 10vw;
font-size: 4.5vw;
background-color: #d4ebfe;
border-radius: 2.5vw;
border-radius: 5vw;
outline: none;
border-style: dotted;
}
border: none;
padding: 0 2vw;
box-shadow: 0px 2px 4px rgba(0, 0, 0, 0.1);
}
.wrapper .identify button{
width: 14vw;
height: 8vw;
border-radius: 3vw;
.wrapper .identify button {
width: 16vw;
height: 10vw;
border-radius: 5vw;
margin-left: 3vw;
}
background-color: #01B0F2;
border: none;
outline: none;
cursor: pointer;
transition: all 0.3s ease;
}
.wrapper .identify button p{
font-size: 3.5vw;
}
.wrapper .identify button p {
font-size: 4vw;
color: #fff;
}
.wrapper .identify button:hover {
transform: scale(1.1);
}
/******列表******/
.wrapper .form{
/******列表******/
.wrapper .form {
width: 100vw;
margin-top: 2vw;
}
}
.wrapper .form li {
.wrapper .form li {
box-sizing: border-box;
padding: 4vw 3vw 0 3vw;
padding: 3vw 3vw 0 3vw;
display: flex;
align-items: center;
}
}
.wrapper .form li .title {
flex: 0 0 18vw;
font-size: 4vw;
font-weight: 450;
color: #666;
margin-left: 5vw;
}
.wrapper .form li .title {
flex: 0 0 20vw;
font-size: 4.5vw;
font-weight: 500;
color: #333;
margin-left: 3vw;
}
.wrapper .form li .content {
.wrapper .form li .content {
flex: 1;
}
}
.wrapper .form li .content input {
.wrapper .form li .content input {
outline: none;
width: 90%;
height: 7vw;
font-size: 3.5vw;
}
font-size: 4vw;
border: none;
border-bottom: 1px solid #ccc;
}
.wrapper .form li .gender {
.wrapper .form li .gender {
width: 100vw;
height: 6vw;
display: flex;
justify-content: center;
}
}
/*******确认修改********/
.wrapper .ok{
.wrapper .ok {
height: 20vw;
width: 100vw;
display: flex;
align-items: center;
justify-content: center;
}
}
.wrapper .ok button{
.wrapper .ok button {
width: 35vw;
height: 8vw;
border-radius: 3vw;
margin-left: 3vw;
height: 10vw;
border-radius: 5vw;
background-color: #4ba0fa;
border: none;
margin-top: 8vw;
}
.wrapper .ok p{
font-size: 4vw;
margin-top: 6vw;
font-size: 4.5vw;
font-weight: 600;
color: #fff;
font-weight: 800;
}
}
.wrapper .ok button:hover {
background-color: #3687d8;
}
</style>

View File

@ -8,14 +8,14 @@
<!-- 商家logo部分 -->
<div class="business-logo">
<img :src="business.businessImg" />
<img :src="business.businessImg"/>
</div>
<!-- 商家信息部分 -->
<div class="business-info">
<h1>{{business.businessName}}</h1>
<p>&#165;{{business.starPrice}}起送 &#165;{{business.deliveryPrice}}配送</p>
<p>{{business.businessExplain}}</p>
<h1>{{ business.businessName }}</h1>
<p>&#165;{{ business.starPrice }}起送 &#165;{{ business.deliveryPrice }}配送</p>
<p>{{ business.businessExplain }}</p>
</div>
<!-- 添加收藏按钮 -->
<div v-if="this.isCollected" @click="toggleCollect(business)" class="collect-button0">
@ -31,16 +31,16 @@
<div class="food-left">
<img :src="item.foodImg">
<div class="food-left-info">
<h3>{{item.foodName}}</h3>
<p>{{item.foodExplain}}</p>
<p>&#165;{{item.foodPrice}}</p>
<h3>{{ item.foodName }}</h3>
<p>{{ item.foodExplain }}</p>
<p>&#165;{{ item.foodPrice }}</p>
</div>
</div>
<div class="food-right">
<div>
<i class="fa fa-minus-circle" @click="minus(index)" v-show="item.quantity!=0"></i>
</div>
<p><span v-show="item.quantity!=0">{{item.quantity}}</span></p>
<p><span v-show="item.quantity!=0">{{ item.quantity }}</span></p>
<div>
<i class="fa fa-plus-circle" @click="add(index)"></i>
</div>
@ -56,19 +56,19 @@
:style="totalQuantity==0?'background-color:#505051;':'background-color:#01B0F2;'">
<i class="fa fa-shopping-cart"></i>
<div class="cart-left-icon-quantity" v-show="totalQuantity!=0">
{{totalQuantity}}
{{ totalQuantity }}
</div>
</div>
<div class="cart-left-info">
<p>&#165;{{totalPrice}}</p>
<p>另需配送费{{business.deliveryPrice}}</p>
<p>&#165;{{ totalPrice }}</p>
<p>另需配送费{{ business.deliveryPrice }}</p>
</div>
</div>
<div class="cart-right">
<!-- 不够起送费 -->
<div class="cart-right-item" v-show="totalSettle<business.starPrice"
style="background-color: #444;cursor: default;">
&#165;{{business.starPrice}}起送
&#165;{{ business.starPrice }}起送
</div>
<!-- 达到起送费 -->
<div class="cart-right-item" @click="toOrder" v-show="totalSettle>=business.starPrice">
@ -80,7 +80,7 @@
</template>
<script>
export default {
export default {
name: 'BusinessInfo',
data() {
return {
@ -98,7 +98,7 @@
created() {
this.user = this.$getSessionStorage('user');
//businessId
let url=`BusinessController/getBusinessById/${this.businessId}`
let url = `BusinessController/getBusinessById/${this.businessId}`
this.$axios.get(url).then(response => {
this.business = response.data.result;
this.foodArr = this.business.foodList;
@ -125,15 +125,15 @@
}).catch(error => {
console.error(error);
});
for(let i of this.collectList){
if(`${i.businessId}`===this.businessId){
this.isCollected=true
for (let i of this.collectList) {
if (`${i.businessId}` === this.businessId) {
this.isCollected = true
break
}
}
},
listCart() {
let url=`CartController/listCart/${this.user.userId}/${this.businessId}`
let url = `CartController/listCart/${this.user.userId}/${this.businessId}`
this.$axios.get(url).then(response => {
let cartArr = response.data.result;
//
@ -189,7 +189,7 @@
this.interval = 200;
},
savaCart(index) {
let url=`CartController/saveCart/${this.user.userId}/${this.businessId}/${this.foodArr[index].foodId}`
let url = `CartController/saveCart/${this.user.userId}/${this.businessId}/${this.foodArr[index].foodId}`
this.$axios.post(url).then(response => {
if (response.data.result == 1) {
//1
@ -203,7 +203,7 @@
});
},
updateCart(index, num) {
let url=`CartController/updateCart/${this.user.userId}/${this.businessId}/${this.foodArr[index].foodId}/${this.foodArr[index].quantity + num}`
let url = `CartController/updateCart/${this.user.userId}/${this.businessId}/${this.foodArr[index].foodId}/${this.foodArr[index].quantity + num}`
this.$axios.put(url).then(response => {
if (response.data.result == 1) {
//1-1
@ -217,7 +217,7 @@
});
},
removeCart(index) {
let url=`CartController/removeCart/${this.user.userId}/${this.businessId}/${this.foodArr[index].foodId}`
let url = `CartController/removeCart/${this.user.userId}/${this.businessId}/${this.foodArr[index].foodId}`
this.$axios.delete(url).then(response => {
if (response.data.result == 1) {
//0
@ -272,22 +272,24 @@
return this.totalPrice + this.business.deliveryPrice;
}
}
}
}
</script>
<style scoped>
/****************总容器***************/
.wrapper {
/****************总容器***************/
.wrapper {
width: 100%;
height: 100%;
}
}
/****************header部分***************/
.wrapper header {
/****************header部分***************/
.wrapper header {
width: 100%;
height: 12vw;
height: 14vw;
/* 增大header高度 */
background-color: #01B0F2;
font-size: 4.8vw;
font-size: 5vw;
/* 调整字体大小 */
color: #fff;
z-index: 10;
@ -299,168 +301,185 @@
position: fixed;
left: 0;
top: 0;
}
}
.wrapper header i {
margin: 0vw 0vw 0vw 3vw;
font-size: 6vw;
.wrapper header i {
margin: 0vw 0vw 0vw 4vw;
/* 调整返回按钮的间距 */
font-size: 7vw;
/* 调整返回按钮的大小 */
user-select: none;
cursor: pointer;
}
}
.wrapper header p {
margin: 0vw 0vw 0vw 33.5vw;
}
.wrapper header p {
margin: 0vw 0vw 0vw 35vw;
/* 调整标题的间距 */
}
/****************商家logo部分***************/
.wrapper .business-logo {
/****************商家logo部分***************/
.wrapper .business-logo {
width: 100%;
height: 35vw;
padding-top: 12vw;
height: 40vw;
/* 增大商家logo部分高度 */
padding-top: 14vw;
/* 调整商家logo上方间距 */
display: flex;
justify-content: center;
align-items: center;
}
}
.wrapper .business-logo img {
width: 40vw;
height: 30vw;
border-radius: 2vw;
}
.wrapper .business-logo img {
width: 45vw;
/* 增大商家logo图片尺寸 */
height: 35vw;
/* 调整商家logo图片尺寸 */
border-radius: 2.5vw;
/* 调整边框圆角 */
}
/****************商家信息部分***************/
.wrapper .business-info {
/****************商家信息部分***************/
.wrapper .business-info {
width: 100%;
height: 20vw;
height: 25vw;
/* 增大商家信息部分高度 */
display: flex;
flex-direction: column;
align-items: center;
justify-content: center;
}
}
.wrapper .business-info h1 {
font-size: 5vw;
.wrapper .business-info h1 {
font-size: 6vw;
/* 调整商家名称字体大小 */
}
}
.wrapper .business-info p {
font-size: 3vw;
.wrapper .business-info p {
font-size: 4vw;
/* 调整商家信息字体大小 */
color: #666;
margin-top: 1.2vw;
}
margin-top: 1.5vw;
/* 调整商家信息顶部间距 */
}
/****************收藏按钮***************/
.wrapper .collect-button0 {
position: fixed;
font-size: 3vw;
color: white;
background-color: gray;
align-items: center;
justify-content: center;
padding: 1vw;
right: 0;
top: 13vw;
}
.wrapper .collect-button1 {
position: fixed;
font-size: 3vw;
color: white;
background-color: #01B0F2;
align-items: center;
justify-content: center;
padding: 1vw;
right: 0;
top: 13vw;
}
/****************食品信息部分***************/
.wrapper .food {
/****************食品信息部分***************/
.wrapper .food {
width: 100%;
padding-bottom: 14vw;
}
padding-bottom: 16vw;
/* 增大底部填充 */
}
.wrapper .food li {
.wrapper .food li {
width: 100%;
box-sizing: border-box;
padding: 2.5vw;
padding: 3vw;
/* 调整内边距 */
user-select: none;
display: flex;
justify-content: space-between;
align-items: center;
}
.wrapper .food li .food-left {
transition: all 0.3s ease;
/* 添加过渡效果 */
}
.wrapper .food li:hover {
background-color: #f4f4f4;
/* 鼠标悬停时背景色变化 */
}
.wrapper .food li .food-left {
display: flex;
align-items: center;
}
}
.wrapper .food li .food-left img {
width: 20vw;
height: 20vw;
border-radius: 1vw;
}
.wrapper .food li .food-left img {
width: 22vw;
/* 增大食品图片尺寸 */
height: 22vw;
/* 增大食品图片尺寸 */
border-radius: 1.5vw;
/* 调整边框圆角 */
transition: all 0.3s ease;
/* 添加过渡效果 */
}
.wrapper .food li .food-left .food-left-info {
margin-left: 3vw;
.wrapper .food li .food-left img:hover {
transform: scale(1.05);
/* 鼠标悬停时放大图片 */
}
}
.wrapper .food li .food-left .food-left-info {
margin-left: 4vw;
/* 调整左侧信息的间距 */
.wrapper .food li .food-left .food-left-info h3 {
font-size: 3.8vw;
}
.wrapper .food li .food-left .food-left-info h3 {
font-size: 4vw;
/* 调整标题字体大小 */
color: #555;
}
}
.wrapper .food li .food-left .food-left-info p {
font-size: 3vw;
.wrapper .food li .food-left .food-left-info p {
font-size: 3.2vw;
/* 调整文本字体大小 */
color: #888;
margin-top: 2vw;
}
margin-top: 2.5vw;
/* 调整顶部间距 */
}
.wrapper .food li .food-right {
width: 16vw;
.wrapper .food li .food-right {
width: 18vw;
/* 增大右侧部分宽度 */
display: flex;
justify-content: space-between;
align-items: center;
}
}
.wrapper .food li .food-right .fa-minus-circle {
font-size: 5.5vw;
.wrapper .food li .food-right .fa-minus-circle,
.wrapper .food li .food-right .fa-plus-circle {
font-size: 6vw;
/* 调整按钮图标大小 */
color: #999;
cursor: pointer;
}
transition: all 0.3s ease;
/* 添加过渡效果 */
}
.wrapper .food li .food-right p {
font-size: 3.6vw;
color: #333;
}
.wrapper .food li .food-right .fa-plus-circle {
font-size: 5.5vw;
.wrapper .food li .food-right .fa-minus-circle:hover,
.wrapper .food li .food-right .fa-plus-circle:hover {
color: #01B0F2;
cursor: pointer;
}
/* 鼠标悬停时按钮颜色变化 */
}
/****************** 购物车部分 ******************/
.wrapper .cart {
.wrapper .food li .food-right p {
font-size: 4vw;
/* 调整数量文本字体大小 */
color: #333;
}
/****************** 购物车部分 ******************/
.wrapper .cart {
width: 100%;
height: 14vw;
position: fixed;
left: 0;
bottom: 0;
display: flex;
}
}
.wrapper .cart .cart-left {
.wrapper .cart .cart-left {
flex: 4;
background-color: #505051;
display: flex;
}
}
.wrapper .cart .cart-left .cart-left-icon {
.wrapper .cart .cart-left .cart-left-icon {
width: 16vw;
height: 16vw;
box-sizing: border-box;
@ -475,9 +494,9 @@
margin-top: -4vw;
margin-left: 3vw;
position: relative;
}
}
.wrapper .cart .cart-left .cart-left-icon-quantity {
.wrapper .cart .cart-left .cart-left-icon-quantity {
width: 5vw;
height: 5vw;
border-radius: 2.5vw;
@ -490,27 +509,27 @@
position: absolute;
right: -1.5vw;
top: -1.5vw;
}
}
.wrapper .cart .cart-left .cart-left-info p:first-child {
.wrapper .cart .cart-left .cart-left-info p:first-child {
font-size: 4.5vw;
color: #fff;
margin-top: 1vw;
}
}
.wrapper .cart .cart-left .cart-left-info p:last-child {
.wrapper .cart .cart-left .cart-left-info p:last-child {
font-size: 2.8vw;
color: #AAA;
}
}
.wrapper .cart .cart-right {
.wrapper .cart .cart-right {
flex: 1.4;
background-color: #505051;
padding: 2vw 2vw;
}
}
/*达到起送费时的样式*/
.wrapper .cart .cart-right .cart-right-item {
/*达到起送费时的样式*/
.wrapper .cart .cart-right .cart-right-item {
width: 100%;
height: 100%;
background-color: #01B0F2;
@ -523,10 +542,10 @@
justify-content: center;
align-items: center;
border-radius: 8vw;
}
}
/*不够起送费时的样式(只有背景色和鼠标样式的区别)*/
/*
/*不够起送费时的样式(只有背景色和鼠标样式的区别)*/
/*
.wrapper .cart .cart-right .cart-right-item{
width: 100%;
height: 100%;
@ -541,4 +560,31 @@
align-items: center;
}
*/
/****************收藏按钮***************/
.wrapper .collect-button0 {
position: fixed;
font-size: 4vw;
color: white;
background-color: gray;
align-items: center;
justify-content: center;
padding: 1vw;
right: 0;
top: 15vw;
border-radius: 10vw 0 0 10vw;
}
.wrapper .collect-button1 {
position: fixed;
font-size: 4vw;
color: white;
background-color: #01B0F2;
align-items: center;
justify-content: center;
padding: 1vw;
right: 0;
top: 15vw;
border-radius: 10vw 0 0 10vw;
}
</style>

View File

@ -31,9 +31,9 @@
</template>
<script>
import Footer from '../components/Footer.vue';
import Footer from '../components/Footer.vue';
export default {
export default {
name: 'BusinessList',
data() {
return {
@ -46,7 +46,7 @@
this.user = this.$getSessionStorage('user');
//orderTypeId
let url=`BusinessController/listBusinessByOrderTypeId/${this.orderTypeId}`
let url = `BusinessController/listBusinessByOrderTypeId/${this.orderTypeId}`
this.$axios.get(url).then(response => {
this.businessArr = response.data.result;
console.log(response.data.message);
@ -66,7 +66,7 @@
this.$router.go(-1);
},
listCart() {
let url=`CartController/listCart/${this.user.userId}`
let url = `CartController/listCart/${this.user.userId}`
this.$axios.get(url).then(response => {
let cartArr = response.data.result;
//
@ -93,18 +93,18 @@
});
}
}
}
}
</script>
<style scoped>
/****************总容器***************/
.wrapper {
/****************总容器***************/
.wrapper {
width: 100%;
height: 100%;
}
}
/****************header部分***************/
.wrapper header {
/****************header部分***************/
.wrapper header {
width: 100%;
height: 12vw;
background-color: #01B0F2;
@ -120,34 +120,34 @@
position: fixed;
left: 0;
top: 0;
}
}
.wrapper header i {
.wrapper header i {
margin: 0vw 0vw 0vw 3vw;
font-size: 6vw;
user-select: none;
cursor: pointer;
}
}
.wrapper header p {
.wrapper header p {
margin: 0vw 0vw 0vw 33.5vw;
}
}
/****************商家列表部分***************/
.wrapper .business {
/****************商家列表部分***************/
.wrapper .business {
width: 100%;
margin-top: 12vw;
padding-bottom: 14vw;
}
}
.wrapper .business li {
.wrapper .business li {
width: 100%;
padding: 2vw 2vw 0vw 2vw;
background-color: #F4F8Fb;
box-sizing: border-box;
}
}
.wrapper .business li .border {
.wrapper .business li .border {
width: 100%;
box-sizing: border-box;
padding: 2vw;
@ -155,22 +155,54 @@
background-color: #fff;
cursor: pointer;
border-radius: 2vw;
display: flex;
align-items: center;
animation: fadeIn 1.0s ease forwards;
opacity: 0;
/* 初始透明度为0 */
transition: background-color 0.3s, transform 0.3s;
}
.wrapper .business li:hover .border {
background-color: #E0F2FE;
transform: scale(1.05);
}
.wrapper .business li:active .border {
border: 2px solid #FF5722;
transform: scale(0.95);
}
@keyframes fadeIn {
from {
opacity: 0;
}
.wrapper .business li .border .business-img {
to {
opacity: 1;
}
}
.wrapper .business li .border .business-img {
position: relative;
}
}
.wrapper .business li .border .business-img img {
.wrapper .business li .border .business-img img {
width: 20vw;
height: 20vw;
border-radius: 2vw;
}
transition: transform 0.3s;
}
.wrapper .business li .border .business-img .business-img-quantity {
.wrapper .business li .border:hover .business-img img {
transform: scale(1.1);
}
.wrapper .business li .border:active .business-img img {
transform: scale(0.9);
}
.wrapper .business li .border .business-img .business-img-quantity {
width: 5vw;
height: 5vw;
background-color: red;
@ -185,20 +217,20 @@
position: absolute;
right: -1.5vw;
top: -1.5vw;
}
}
.wrapper .business li .border .business-info {
.wrapper .business li .border .business-info {
margin-left: 3vw;
}
}
.wrapper .business li .border .business-info h3 {
.wrapper .business li .border .business-info h3 {
font-size: 3.8vw;
color: #555;
}
}
.wrapper .business li .border .business-info p {
.wrapper .business li .border .business-info p {
font-size: 3vw;
color: #888;
margin-top: 2vw;
}
}
</style>

View File

@ -7,8 +7,8 @@
</header>
<!-- 地址列表部分 -->
<ul class="addresslist">
<li v-for="item in CouponList">
<!-- <div class="addresslist-left" @click="setDeliveryAddress(item)">
<li v-for="item in CouponList" v-show="this.totalPrice>=item.limitNum">
<!-- <div class="addresslist-left" @click="setDeliveryAddress(item)">
<h3>{{item.contactName}}{{getSexText(item.contactSex)}} {{item.contactTel}}
</h3>
<p>{{item.address}}</p>
@ -40,9 +40,9 @@
</div>
</template>
<script>
import Footer from '../components/Footer.vue';
import Footer from '../components/Footer.vue';
export default {
export default {
name: 'UserAddress',
data() {
return {
@ -50,6 +50,7 @@
user: {},
deliveryAddressArr: [],
CouponList:[],
totalPrice:this.$route.query.totalPrice,
}
},
created() {
@ -151,18 +152,18 @@
});
}
}
}
}
</script>
<style scoped>
/*************** 总容器 ***************/
.wrapper {
/*************** 总容器 ***************/
.wrapper {
width: 100%;
height: 100%;
background-color: #F5F5F5;
}
}
/*************** header ***************/
.wrapper header {
/*************** header ***************/
.wrapper header {
width: 100%;
height: 12vw;
background-color: #01B0F2;
@ -178,54 +179,54 @@
position: fixed;
left: 0;
top: 0;
}
}
.wrapper header i {
.wrapper header i {
margin: 0vw 0vw 0vw 3vw;
font-size: 6vw;
user-select: none;
cursor: pointer;
}
}
.wrapper header p {
.wrapper header p {
margin: 0vw 0vw 0vw 33.5vw;
}
}
/*************** addresslist ***************/
.wrapper .addresslist {
/*************** addresslist ***************/
.wrapper .addresslist {
width: 100%;
padding-top: 12vw;
background-color: #fff;
}
}
.wrapper .addresslist li {
.wrapper .addresslist li {
width: 100%;
box-sizing: border-box;
border-bottom: solid 1px #DDD;
padding: 3vw;
display: flex;
}
}
.wrapper .addresslist li .addresslist-left {
.wrapper .addresslist li .addresslist-left {
flex: 5;
/*左边这块区域是可以点击的*/
user-select: none;
cursor: pointer;
}
}
.wrapper .addresslist li .addresslist-left h3 {
.wrapper .addresslist li .addresslist-left h3 {
font-size: 4.6vw;
font-weight: 300;
color: #666;
}
}
.wrapper .addresslist li .addresslist-left p {
.wrapper .addresslist li .addresslist-left p {
font-size: 4vw;
color: #666;
}
}
.wrapper .addresslist li .addresslist-right {
.wrapper .addresslist li .addresslist-right {
flex: 1;
font-size: 5.6vw;
color: #999;
@ -233,10 +234,10 @@
display: flex;
justify-content: space-around;
align-items: center;
}
}
/*************** 新增地址部分 ***************/
.wrapper .addbtn {
/*************** 新增地址部分 ***************/
.wrapper .addbtn {
width: 100%;
height: 14vw;
border-top: solid 1px #DDD;
@ -250,13 +251,13 @@
color: #01B0F2;
user-select: none;
cursor: pointer;
}
}
p {
p {
margin-left: 2vw;
}
}
.wrapper .Coupon-Intro{
.wrapper .Coupon-Intro{
cursor: pointer;
width: 100%;
height: 16vw;
@ -267,5 +268,5 @@
justify-content: space-between;
align-items: center;
font-size: 3.5vw;
}
}
</style>

View File

@ -44,7 +44,7 @@
<!-- 合计部分 -->
<div class="total">
<div class="total-left">
&#165;{{ totalPrice }}
&#165;{{ finalPrice }}
</div>
<div class="box">
<div class="total-right" @click="toPayment">
@ -66,10 +66,14 @@ export default {
cartArr: [],
deliveryaddress: {},
availablePointArr: [],
couponUsed: {}
couponUsed: {},
}
},
created() {
// finalPrice
// finalPrice=totalPrice;
this.user = this.$getSessionStorage('user');
this.deliveryaddress = this.$getLocalStorage(this.user.userId);
this.couponUsed = this.$getLocalStorage(this.businessId);
@ -96,13 +100,25 @@ export default {
totalPrice += cartItem.food.foodPrice * cartItem.quantity;
}
totalPrice += this.business.deliveryPrice;
//
// if (this.couponUsed != null) {
// totalPrice -= this.couponUsed.minusNum;
// }
return totalPrice;
},
finalPrice() {
let totalPrice = 0;
for (let cartItem of this.cartArr) {
totalPrice += cartItem.food.foodPrice * cartItem.quantity;
}
totalPrice += this.business.deliveryPrice;
//
if (this.couponUsed != null) {
totalPrice -= this.couponUsed.minusNum;
}
return totalPrice;
}
},
methods: {
back() {
@ -126,25 +142,30 @@ export default {
}
//
let url = `OrdersController/createOrders/${this.user.userId}/${this.businessId}/${this.deliveryaddress.daId}/${this.totalPrice}`
let finalPrice = this.totalPrice;
if (this.couponUsed != null) {
finalPrice -= this.couponUsed.minusNum;
}
let url =
`OrdersController/createOrders/${this.user.userId}/${this.businessId}/${this.deliveryaddress.daId}/${this.finalPrice}`
this.$axios.post(url).then(response => {
let orderId = response.data.result;
if (orderId > 0) {
//
if (this.couponUsed != null) {
this.$axios.delete(`CouponController/deleteCouponByCouponId/${this.couponUsed.couponId}`);
this.$axios.delete(
`CouponController/deleteCouponByCouponId/${this.couponUsed.couponId}`);
}
this.$router.push({
path: '/payment',
query: {
orderId: orderId,
userId: this.user.userId,
reduction: this.couponUsed===null?0:this.couponUsed.minusNum
reduction: this.couponUsed === null ? 0 : this.couponUsed.minusNum
}
});
this.$removeSessionStorage(this.businessId);
this.$setLocalStorage(this.businessId,null);
console.log("this.$removeSessionStorage(this.businessId)");
} else {
alert('创建订单失败!');
}
@ -153,11 +174,11 @@ export default {
});
},
toCouponSelect() {
this.$router.push(
{
this.$router.push({
path: '/CouponSelect',
query: {
businessId: this.businessId
businessId: this.businessId,
totalPrice: this.totalPrice
}
});
},

View File

@ -9,29 +9,29 @@
<h3>订单信息</h3>
<div class="order-info">
<p>
{{orders.business.businessName}}
{{ orders.business.businessName }}
<i class="fa fa-caret-down" @click="detailetShow"></i>
</p>
<p>&#165;{{orders.orderTotal}}</p>
<p>&#165;{{ orders.orderTotal }}</p>
</div>
<!-- 订单明细部分 -->
<ul class="order-detailet" v-show="isShowDetailet">
<li v-for="item in orders.list">
<p>{{item.food.foodName}} x {{item.quantity}}</p>
<p>&#165;{{item.food.foodPrice*item.quantity}}</p>
<p>{{ item.food.foodName }} x {{ item.quantity }}</p>
<p>&#165;{{ item.food.foodPrice * item.quantity }}</p>
</li>
<li>
<p>配送费</p>
<p>&#165;{{orders.business.deliveryPrice}}</p>
<p>&#165;{{ orders.business.deliveryPrice }}</p>
</li>
<li>
<p>消费券减免</p>
<p>-&#165;{{reduction}}</p>
<p>-&#165;{{ reduction }}</p>
</li>
<!-- 积分系统新增显示 -->
<li>
<p>获得积分</p>
<p>{{orders.orderTotal*10}}</p>
<p>{{ orders.orderTotal * 10 }}</p>
</li>
</ul>
<!-- 支付方式部分 -->
@ -50,12 +50,16 @@
<h2 v-show="paySuccess" style="color: #0097FF;text-align: center;">
支付成功
</h2>
<h2 v-show="noMoney" style="color: red;text-align: center;">
钱包余额不足
</h2>
<!-- 底部菜单部分 -->
<Footer></Footer>
</div>
</template>
<script>
import Footer from '../components/Footer.vue';
export default {
name: 'Payment',
data() {
@ -68,11 +72,12 @@ export default {
},
isShowDetailet: false,
paySuccess: false,
isPayed: false
isPayed: false,
noMoney: false
}
},
created() {
let url=`OrdersController/getOrdersById/${this.orderId}`
let url = `OrdersController/getOrdersById/${this.orderId}`
this.$axios.get(url).then(response => {
this.orders = response.data.result;
}).catch(error => {
@ -94,66 +99,57 @@ export default {
window.onpopstate = null;
},
computed: {
pointGot(){
let res=this.orders.orderTotal+this.reduction;
pointGot() {
let res = this.orders.orderTotal + this.reduction;
return Math.floor(res);
}
},
methods: {
back() {
this.$router.go(-1);
},
detailetShow() {
this.isShowDetailet = !this.isShowDetailet;
},
pay() {
// this.$axios.put('OrdersController/Orders', this.$qs.stringify({
// orderId: this.orderId,
// userId: this.userId,
// orderTotal: this.orders.orderTotal,
// reduction: this.reduction
// }),{
// headers: {
// Authorization:this.$getSessionStorage('user').password
// }
// }).then(response => {
// let orderId = response.data;
// if (orderId > 0) {
// this.paySuccess=true;
// this.isPayed=true;
// setTimeout(() => {
// this.$router.push({
// path: '/orderList'
// });
// }, 500);
// } else {
// alert('');
// }
// }).catch(error => {
// console.error(error);
// });
let url0 = `WalletController/expense/${this.userId}/${this.orders.orderTotal}`;
let url = `OrdersController/Orders/${this.orderId}`;
console.log("Kicked");
let url=`OrdersController/Orders/${this.orderId}`
this.$axios.post(url0)
.then(response => {
if (response.data.result === 1) {
// url0 1 url
this.$axios.put(url)
.then(
response =>
{
console.log(response);
console.log("支付成功");
let url=`PointController/addPointByPointId/${this.userId}/${this.orders.orderDate}/${this.orders.orderTotal*10}`
.then(response => {
let url =
`PointController/addPointByPointId/${this.userId}/${this.orders.orderDate}/${this.orders.orderTotal * 10}`;
console.log(url);
this.$axios.post(url).then(response =>
{
this.$axios.post(url)
.then(response => {
console.log(response.data);
});
this.$router.push({path:'/orderList'});
}
)
.catch(error =>
{
this.paySuccess = true;
this.isPayed = true;
setTimeout(() => {
this.$router.push({
path: '/orderList'
})
}, 500);
})
.catch(error => {
console.error(error);
});
} else {
// url0 1
this.noMoney = true
setTimeout(() => {
this.noMoney = false
}, 1000);
}
);
})
.catch(error => {
console.error(error);
});
}
},
components: {

View File

@ -5,17 +5,71 @@
<i class="fa fa-angle-left" @click="back"></i>
<p>我的钱包</p>
</header>
<div class="wallet-total">
<div class="num">
<img src="../assets/钱包.png">
<p style="color: black;">{{balance}}</p>
</div>
<div class="text">
<p></p>
</div>
</div>
<div class="wallet-detail">
<div class="top">
<p :class="{ active: isShouzhi }" @click="toggleTab('shouzhi')">钱包流水</p>
</div>
<div class="border">
<ul class="get-pay" v-show="isShouzhi">
<li class="li1">
<ul class="details">
<li class="x">
<h4>交易时间</h4>
</li>
<li class="y">
<h4>交易额</h4>
</li>
<li class="y">
<h4>余额</h4>
</li>
<li class="y">
<h4>交易类型</h4>
</li>
</ul>
</li>
<li class="li1">
<ul class="details" v-for="item in availablePointArr">
<li class="x">
<h4>{{item.transactionTime}}</h4>
</li>
<li class="y">
<p>{{ item.transactionNum }}</p>
</li>
<li class="y">
<p>{{ item.balance }}</p>
</li>
<li class="y">
<p style="color: green;">{{ item.transactionType }}</p>
</li>
</ul>
</li>
</ul>
</div>
</div>
</div>
</template>
<script>
export default {
name: 'Wallet',
export default {
name: 'walletDetails',
data() {
return {
isShouzhi: true,
availablePointArr: [],
outDatePointArr: [],
balance: [],
user: {}
};
},
@ -26,7 +80,33 @@
}
},
created() {
this.user = this.$getSessionStorage('user');
this.$axios.get(`WalletController/listWallets`, {
params: {
userId: this.user.userId
},
headers: {
Authorization: this.user.password
}
}).then(response => {
//
let result = response.data.result;
this.availablePointArr = result;
console.log(response);
// console.log(this.user.userId+" "+this.user.password);
}).catch(error => {
console.error(error);
});
let url = `WalletController/getWalletBalance/${this.user.userId}`
this.$axios.get(url).then(response => {
let result = response.data.result;
this.balance = result;
console.log("balance:\n" + result)
}).catch(error => {
console.error(error);
});
},
methods: {
back() {
@ -36,18 +116,18 @@
this.isShouzhi = tab === 'shouzhi';
},
},
};
};
</script>
<style scoped>
.wrapper {
.wrapper {
width: 100%;
height: 100%;
background-color: #F4F8Fb;
}
}
/****************** header ******************/
.wrapper header {
/****************** header ******************/
.wrapper header {
width: 100%;
height: 12vw;
background-color: #01B0F2;
@ -63,119 +143,105 @@
position: fixed;
left: 0;
top: 0;
}
}
.wrapper header i {
.wrapper header i {
margin: 0vw 0vw 0vw 3vw;
font-size: 6vw;
user-select: none;
cursor: pointer;
}
}
.wrapper header p {
.wrapper header p {
margin: 0vw 0vw 0vw 32vw;
}
}
.wrapper .points-total {
.wrapper .wallet-total {
padding-top: 20vw;
}
}
.wrapper .points-total .num {
.wrapper .wallet-total .num {
display: flex;
justify-content: center;
align-items: center;
margin-bottom: 1vw;
}
}
.wrapper .points-total .num p {
font-size: 6vw;
}
.wrapper .wallet-total .num p {
font-size: 6.5vw;
padding-left: 2vw;
}
.wrapper .points-total .num img {
width: 8vw;
height: 8vw;
}
.wrapper .wallet-total .num img {
width: 12vw;
height: 12vw;
}
.wrapper .points-total .text {
.wrapper .wallet-total .text {
display: flex;
justify-content: center;
align-items: center;
font-size: 2.8vw;
}
}
.wrapper .points-detail {
.wrapper .wallet-detail {
padding-top: 6vw;
}
}
.wrapper .points-detail .top {
.wrapper .wallet-detail .top {
display: flex;
justify-content: space-around;
align-items: center;
font-size: 3.5vw;
padding-bottom: 2vw;
}
}
.wrapper .points-detail .top p {
.wrapper .wallet-detail .top p {
font-weight: normal;
user-select: none;
cursor: pointer;
}
}
.wrapper .points-detail .top p.active {
.wrapper .wallet-detail .top p.active {
font-weight: bold;
user-select: none;
cursor: pointer;
}
}
.wrapper .points-detail .border {
.wrapper .wallet-detail .border {
width: 100%;
padding: 2vw 2vw 0vw 2vw;
box-sizing: border-box;
}
}
.wrapper .points-detail .border .get-pay {
.wrapper .wallet-detail .border .get-pay {
width: 100%;
background-color: #fff;
border-radius: 2vw;
}
}
.wrapper .points-detail .border .get-pay .li1 {
.wrapper .wallet-detail .border .get-pay .li1 {
padding: 2vw 0vw;
}
}
.wrapper .points-detail .border .get-pay .details {
.wrapper .wallet-detail .border .get-pay .details {
display: flex;
margin: 0vw 2vw;
}
padding: 0vw 2vw 1vw 2vw;
}
.wrapper .points-detail .border .get-pay .details li {
width: 34%;
.wrapper .wallet-detail .border .get-pay .details .x{
width: 37%;
font-size: 2.8vw;
display: flex;
justify-content: center;
align-items: center;
}
}
.wrapper .points-detail .border .duihuan {
width: 100%;
background-color: #fff;
border-radius: 2vw;
}
.wrapper .points-detail .border .duihuan .li1 {
padding: 2vw 0vw;
}
.wrapper .points-detail .border .duihuan .details {
display: flex;
margin: 0vw 2vw;
}
.wrapper .points-detail .border .duihuan .details li {
width: 34%;
.wrapper .wallet-detail .border .get-pay .details .y{
width: 21%;
font-size: 2.8vw;
display: flex;
justify-content: center;
align-items: center;
}
}
</style>

View File

@ -25,7 +25,11 @@
<module name="deliveryaddress_server_10500" />
<module name="search_server_11600" />
<module name="business_server_10300" />
<module name="wallet_server_11000" />
</profile>
</annotationProcessing>
<bytecodeTargetLevel>
<module name="wallet_server_10800" target="1.8" />
</bytecodeTargetLevel>
</component>
</project>

View File

@ -41,5 +41,7 @@
<file url="file://$PROJECT_DIR$/src/main/resources" charset="UTF-8" />
<file url="file://$PROJECT_DIR$/user_server_10100/src/main/java" charset="UTF-8" />
<file url="file://$PROJECT_DIR$/user_server_10100/src/main/resources" charset="UTF-8" />
<file url="file://$PROJECT_DIR$/wallet_server_11000/src/main/java" charset="UTF-8" />
<file url="file://$PROJECT_DIR$/wallet_server_11000/src/main/resources" charset="UTF-8" />
</component>
</project>

View File

@ -0,0 +1,16 @@
<component name="ProjectRunConfigurationManager">
<configuration default="false" name="wallet_server_11000" type="SpringBootApplicationConfigurationType" factoryName="Spring Boot">
<option name="FRAME_DEACTIVATION_UPDATE_POLICY" value="UpdateClassesAndResources" />
<module name="wallet_server_11000" />
<option name="SPRING_BOOT_MAIN_CLASS" value="com.neusoft.MyApplication" />
<extension name="coverage">
<pattern>
<option name="PATTERN" value="com.neusoft.*" />
<option name="ENABLED" value="true" />
</pattern>
</extension>
<method v="2">
<option name="Make" enabled="true" />
</method>
</configuration>
</component>

View File

@ -0,0 +1,37 @@
package com.neusoft.service.impl;
import com.neusoft.po.Cart;
import com.neusoft.service.CartService;
import java.util.List;
public abstract class AbstractCartService implements CartService {
protected abstract List<Cart> listCartInternal(Cart cart);
protected abstract int saveCartInternal(Cart cart);
protected abstract int updateCartInternal(Cart cart);
protected abstract int removeCartInternal(Cart cart);
@Override
public List<Cart> listCart(Cart cart) {
return listCartInternal(cart);
}
@Override
public int saveCart(Cart cart) {
return saveCartInternal(cart);
}
@Override
public int updateCart(Cart cart) {
return updateCartInternal(cart);
}
@Override
public int removeCart(Cart cart) {
return removeCartInternal(cart);
}
}

View File

@ -1,36 +1,38 @@
//模板方法模式
/*模板方法模式可以将一些共同的行为放在一个抽象类中,然后由具体的子类实现具体的行为。创建一个抽象的 AbstractCartService 类,其中包含通用的方法实现,然后 CartServiceImpl 类继承这个抽象类并实现具体的方法。*/
package com.neusoft.service.impl;
import com.neusoft.mapper.CartMapper;
import com.neusoft.po.Cart;
import com.neusoft.service.CartService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import java.util.List;
@Service
public class CartServiceImpl implements CartService {
public class CartServiceImpl extends AbstractCartService {
@Autowired
private CartMapper cartMapper;
@Override
public List<Cart> listCart(Cart cart) {
protected List<Cart> listCartInternal(Cart cart) {
return cartMapper.listCart(cart);
}
@Override
public int saveCart(Cart cart) {
protected int saveCartInternal(Cart cart) {
return cartMapper.saveCart(cart);
}
@Override
public int updateCart(Cart cart) {
protected int updateCartInternal(Cart cart) {
return cartMapper.updateCart(cart);
}
@Override
public int removeCart(Cart cart) {
protected int removeCartInternal(Cart cart) {
return cartMapper.removeCart(cart);
}
}

View File

@ -73,6 +73,11 @@ spring:
predicates:
- Path=/CollectController/*/**
- id: walletServer
uri: lb://wallet-server
predicates:
- Path=/WalletController/*/**
eureka:
client:
service-url:

View File

@ -73,6 +73,11 @@ spring:
predicates:
- Path=/CollectController/*/**
- id: walletServer
uri: lb://wallet-server
predicates:
- Path=/WalletController/*/**
eureka:
client:
service-url:

View File

@ -0,0 +1,12 @@
package com.neusoft.controller;
import com.neusoft.po.CommonResult;
import org.springframework.stereotype.Component;
@Component
public class CommonResultFactory {
public <T> CommonResult<T> createSuccessResult(T data) {
return new CommonResult<>(200, "success", data);
}
}

View File

@ -6,6 +6,7 @@ import com.neusoft.service.OrdersService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.cloud.context.config.annotation.RefreshScope;
import org.springframework.web.bind.annotation.*;
import com.neusoft.controller.CommonResultFactory;
import java.util.List;
@ -16,6 +17,12 @@ public class OrdersController {
@Autowired
private OrdersService ordersService;
private final CommonResultFactory commonResultFactory;
public OrdersController(CommonResultFactory commonResultFactory) {
this.commonResultFactory = commonResultFactory;
}
@PostMapping("/createOrders/{userId}/{businessId}/{daId}/{orderTotal}")
public CommonResult<Integer> createOrders(
@PathVariable("userId") String userId,
@ -29,26 +36,26 @@ public class OrdersController {
param.setDaId(daId);
param.setOrderTotal(orderTotal);
int orderId=ordersService.createOrders(param);
return new CommonResult<>(200,"success",orderId);
return commonResultFactory.createSuccessResult(orderId);
}
@GetMapping("/getOrdersById/{orderId}")
public CommonResult<Orders> getOrdersById(@PathVariable("orderId") Integer orderId) throws Exception {
Orders orders=ordersService.getOrdersById(orderId);
return new CommonResult<>(200,"success",orders);
return commonResultFactory.createSuccessResult(orders);
}
@GetMapping("/listOrdersByUserId/{userId}")
public CommonResult<List<Orders>> listOrdersByUserId(@PathVariable("userId") String userId) throws Exception {
List<Orders> list=ordersService.listOrdersByUserId(userId);
return new CommonResult<>(200,"success",list);
return commonResultFactory.createSuccessResult(list);
}
@PutMapping("/Orders/{orderId}")
public CommonResult<Integer>payOrdersById(@PathVariable("orderId") Integer orderId)throws Exception
{
int result=ordersService.payOrdersById(orderId, null, null, null);
return new CommonResult<>(200,"success",result);
return commonResultFactory.createSuccessResult(result);
}

View File

@ -0,0 +1,12 @@
package com.neusoft.controller;
import com.neusoft.po.CommonResult;
import org.springframework.stereotype.Component;
@Component
public class CommonResultFactory {
public <T> CommonResult<T> createSuccessResult(T data) {
return new CommonResult<>(200, "success", data);
}
}

View File

@ -16,6 +16,12 @@ public class OrdersController {
@Autowired
private OrdersService ordersService;
private final CommonResultFactory commonResultFactory;
public OrdersController(CommonResultFactory commonResultFactory) {
this.commonResultFactory = commonResultFactory;
}
@PostMapping("/createOrders/{userId}/{businessId}/{daId}/{orderTotal}")
public CommonResult<Integer> createOrders(
@PathVariable("userId") String userId,
@ -29,21 +35,29 @@ public class OrdersController {
param.setDaId(daId);
param.setOrderTotal(orderTotal);
int orderId=ordersService.createOrders(param);
return new CommonResult<>(200,"success",orderId);
return commonResultFactory.createSuccessResult(orderId);
}
@GetMapping("/getOrdersById/{orderId}")
public CommonResult<Orders> getOrdersById(@PathVariable("orderId") Integer orderId) throws Exception {
Orders orders=ordersService.getOrdersById(orderId);
return new CommonResult<>(200,"success",orders);
return commonResultFactory.createSuccessResult(orders);
}
@GetMapping("/listOrdersByUserId/{userId}")
public CommonResult<List<Orders>> listOrdersByUserId(@PathVariable("userId") String userId) throws Exception {
List<Orders> list=ordersService.listOrdersByUserId(userId);
return new CommonResult<>(200,"success",list);
return commonResultFactory.createSuccessResult(list);
}
@PutMapping("/Orders/{orderId}")
public CommonResult<Integer>payOrdersById(@PathVariable("orderId") Integer orderId)throws Exception
{
int result=ordersService.payOrdersById(orderId, null, null, null);
return commonResultFactory.createSuccessResult(result);
}
// @PutMapping("/Orders")
// public int payOrdersById(OrderState orderState, @RequestHeader("Authorization") String token) throws Exception {
// return ordersService.payOrdersById(orderState.getOrderId(), orderState.getUserId(), orderState.getOrderTotal(), orderState.getReduction(),token);

View File

@ -27,6 +27,7 @@
<module>point_server_10900</module>
<module>coupon_server_10950</module>
<module>collect_server_10800</module>
<module>wallet_server_11000</module>
</modules>
<packaging>pom</packaging>

View File

@ -0,0 +1,65 @@
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 https://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<parent>
<groupId>com.neusoft</groupId>
<artifactId>springcloud_elm</artifactId>
<version>1.0-SNAPSHOT</version>
</parent>
<artifactId>wallet_server_11000</artifactId>
<properties>
<maven.compiler.source>8</maven.compiler.source>
<maven.compiler.target>8</maven.compiler.target>
</properties>
<dependencies>
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-bus</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-stream-binder-rabbit</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-actuator</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-starter-config</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-starter-netflix-eureka-client</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
</dependency>
<dependency>
<groupId>org.mybatis.spring.boot</groupId>
<artifactId>mybatis-spring-boot-starter</artifactId>
<version>2.0.1</version>
</dependency>
<dependency>
<groupId>mysql</groupId>
<artifactId>mysql-connector-java</artifactId>
<version>8.0.20</version>
<scope>runtime</scope>
</dependency>
<!-- 热部署 gav -->
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-devtools</artifactId>
<scope>runtime</scope>
<optional>true</optional>
</dependency>
<dependency>
<groupId>com.neusoft</groupId>
<artifactId>business_server_10300</artifactId>
<version>1.0-SNAPSHOT</version>
</dependency>
</dependencies>
</project>

View File

@ -0,0 +1,11 @@
package com.neusoft;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
@SpringBootApplication
public class MyApplication {
public static void main(String[] args){
SpringApplication.run(MyApplication.class,args);
}
}

View File

@ -0,0 +1,41 @@
package com.neusoft.controller;
import com.neusoft.po.CommonResult;
import com.neusoft.po.Wallet;
import com.neusoft.service.WalletService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import java.util.List;
@RestController
@RequestMapping("/WalletController")
public class WalletController {
@Autowired
private WalletService walletService;
@GetMapping("/listWallets")
public CommonResult<List<Wallet>> listWallets(@RequestParam("userId") String userId, @RequestHeader("Authorization") String token) throws Exception {
return new CommonResult<>(200, "success", walletService.listWallets(userId, token));
}
@PostMapping("/deposit/{userId}/{amount}")
public CommonResult<Integer> deposit(@PathVariable("userId") String userId, @PathVariable("amount") double amount) {
return new CommonResult<>(200, "success", walletService.deposit(userId, amount));
}
@PostMapping("/withdraw/{userId}/{amount}")
public CommonResult<Integer> withdraw(@PathVariable("userId") String userId, @PathVariable("amount") double amount) {
return new CommonResult<>(200, "success", walletService.withdraw(userId, amount));
}
@PostMapping("/expense/{userId}/{amount}")
public CommonResult<Integer> transfer(@PathVariable("userId") String userId,@PathVariable("amount") double amount) {
return new CommonResult<>(200, "success", walletService.expense(userId, amount));
}
@GetMapping("/getWalletBalance/{userId}")
public CommonResult<Double> getWalletBalance(@PathVariable("userId") String userId) {
return new CommonResult<>(200, "success", walletService.getWalletBalance(userId));
}
}

View File

@ -0,0 +1,29 @@
package com.neusoft.mapper;
import com.neusoft.po.Point;
import org.apache.ibatis.annotations.Delete;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Options;
import org.apache.ibatis.annotations.Select;
import org.apache.ibatis.annotations.Update;
import java.util.List;
@Mapper
public interface PointMapper {
@Select("select * from point where userId=#{userId}")
public List<Point> listPointsByUserId(String userId);
@Update("update point set pointNum=#{pointNum} where pointId=#{pointId}")
public void setPointByPointId(Point point);
@Delete("delete from point where pointId=#{pointId}")
public void deletePointByPointId(String pointId);
@Select("insert into point(userId,pointDate,pointNum,outDate) values(#{userId},#{pointDate},#{pointNum},#{outDate})")
@Options(useGeneratedKeys=true,keyProperty="pointId",keyColumn="pointId")
public void addPointByPointId(Point point);
}

View File

@ -0,0 +1,18 @@
package com.neusoft.mapper;
import com.neusoft.po.User;
import org.apache.ibatis.annotations.Insert;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Select;
@Mapper
public interface UserMapper {
@Select("select * from user where userId=#{userId} and password=#{password}")
public User getUserByIdByPass(User user);
@Select("select count(*) from user where userId=#{userId}")
public int getUserById(String userId);
@Insert("insert into user values(#{userId},#{password},#{userName},#{userSex},null,1)")
public int saveUser(User user);
}

View File

@ -0,0 +1,20 @@
package com.neusoft.mapper;
import com.neusoft.po.Wallet;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Options;
import org.apache.ibatis.annotations.Select;
import java.util.List;
@Mapper
public interface WalletMapper {
@Select("select * from wallet where userId=#{userId}")
public List<Wallet> listWalletsByUserId(String userId);
@Select("insert into wallet(userId,balance,transactionNum,transactionTime,transactionType) values(#{userId},#{balance},#{transactionNum},#{transactionTime},#{transactionType})")
@Options(useGeneratedKeys=true,keyProperty="walletId",keyColumn="walletId")
public void addWalletByWallet(Wallet wallet);
}

View File

@ -0,0 +1,41 @@
package com.neusoft.po;
import java.io.Serializable;
public class CommonResult<T> implements Serializable {
private Integer code;
private String message;
private T result;
public CommonResult() {}
public CommonResult(Integer code, String message, T result) {
this.code = code;
this.message = message;
this.result = result;
}
public Integer getCode() {
return code;
}
public void setCode(Integer code) {
this.code = code;
}
public String getMessage() {
return message;
}
public void setMessage(String message) {
this.message = message;
}
public T getResult() {
return result;
}
public void setResult(T result) {
this.result = result;
}
}

View File

@ -0,0 +1,63 @@
package com.neusoft.po;
public class Point {
private String pointId;
private String userId;
private String pointDate;
private Integer pointNum;
private String outDate;
public Point()
{
}
public Point(String pointId,String userId,String pointDate,Integer pointNum,String outDate)
{
this.pointId=pointId;
this.userId=userId;
this.pointDate=pointDate;
this.pointNum=pointNum;
this.outDate=outDate;
}
public String getPointId()
{
return this.pointId;
}
public String getUserId()
{
return this.userId;
}
public String getPointDate()
{
return this.pointDate;
}
public Integer getPointNum()
{
return this.pointNum;
}
public void setPointId(String pointId)
{
this.pointId=pointId;
}
public void setUserId(String userId)
{
this.userId=userId;
}
public void setPointDate(String pointDate)
{
this.pointDate=pointDate;
}
public void setPointNum(Integer pointNum)
{
this.pointNum=pointNum;
}
public String getOutDate() {
return outDate;
}
public void setOutDate(String outDate) {
this.outDate = outDate;
}
}

View File

@ -0,0 +1,18 @@
package com.neusoft.po;
public enum TransactionType {
DEPOSIT("Deposit"),
WITHDRAWAL("Withdrawal"),
EXPENSE("Expense"),
CREATE("Create");
private final String type;
TransactionType(String type) {
this.type = type;
}
public String getType() {
return type;
}
}

View File

@ -0,0 +1,59 @@
package com.neusoft.po;
public class User {
private String userId;
private String password;
private String userName;
private Integer userSex;
private String userImg;
private Integer delTag;
public String getUserId() {
return userId;
}
public void setUserId(String userId) {
this.userId = userId;
}
public String getPassword() {
return password;
}
public void setPassword(String password) {
this.password = password;
}
public String getUserName() {
return userName;
}
public void setUserName(String userName) {
this.userName = userName;
}
public Integer getUserSex() {
return userSex;
}
public void setUserSex(Integer userSex) {
this.userSex = userSex;
}
public String getUserImg() {
return userImg;
}
public void setUserImg(String userImg) {
this.userImg = userImg;
}
public Integer getDelTag() {
return delTag;
}
public void setDelTag(Integer delTag) {
this.delTag = delTag;
}
}

View File

@ -0,0 +1,71 @@
package com.neusoft.po;
import java.util.Date;
public class Wallet {
private Integer walletId;
private String userId;
private double balance;
private double transactionNum;
private String transactionTime;
private TransactionType transactionType;
public Wallet(Integer walletId,String userId,double balance,double transactionNum,String transactionTime,TransactionType transactionType)
{
this.walletId=walletId;
this.userId=userId;
this.balance=balance;
this.transactionNum=transactionNum;
this.transactionTime=transactionTime;
this.transactionType=transactionType;
}
public Integer getWalletId() {
return walletId;
}
public void setWalletId(Integer walletId) {
this.walletId = walletId;
}
public String getUserId() {
return userId;
}
public void setUserId(String userId) {
this.userId = userId;
}
public double getBalance() {
return balance;
}
public void setBalance(double balance) {
this.balance = balance;
}
public String getTransactionTime() {
return transactionTime;
}
public void setTransactionTime(String transactionTime) {
this.transactionTime = transactionTime;
}
public TransactionType getTransactionType() {
return transactionType;
}
public void setTransactionType(TransactionType transactionType) {
this.transactionType = transactionType;
}
public double getTransactionNum() {
return transactionNum;
}
public void setTransactionNum(double transactionNum) {
this.transactionNum = transactionNum;
}
}

View File

@ -0,0 +1,19 @@
package com.neusoft.service;
import java.text.ParseException;
import java.util.List;
import com.neusoft.po.Wallet;
public interface WalletService {
public List<Wallet> listWallets(String userId, String token) throws ParseException;
public int deposit(String userId, double amount);
public int withdraw(String userId, double amount);
public int expense(String userId, double amount);
public double getWalletBalance(String userId);
}

View File

@ -0,0 +1,152 @@
package com.neusoft.service.impl;
import com.neusoft.mapper.UserMapper;
import com.neusoft.mapper.WalletMapper;
import com.neusoft.po.TransactionType;
import com.neusoft.po.User;
import com.neusoft.po.Wallet;
import com.neusoft.service.WalletService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.Collections;
import java.util.Comparator;
import java.util.Date;
import java.util.List;
@Service
public class WalletServiceImpl implements WalletService {
@Autowired
private WalletMapper walletMapper;
@Autowired
private UserMapper userMapper0;
@Override
public List<Wallet> listWallets(String userId, String token) throws ParseException {
User user = new User();
user.setUserId(userId);
user.setPassword(token);
if (userMapper0.getUserByIdByPass(user) == null)
return null;
List<Wallet> list = new ArrayList<>();
list = walletMapper.listWalletsByUserId(userId);
return list;
}
@Override
public int deposit(String userId, double amount) {
try {
// 获取用户当前余额
double balance = getWalletBalance(userId);
balance = balance += amount;
SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
// 创建 Wallet 对象
Wallet wallet = new Wallet(null, userId, balance, amount, sdf.format(new Date()), TransactionType.DEPOSIT);
// 调用 Mapper 方法插入数据
walletMapper.addWalletByWallet(wallet);
// 插入成功返回 1
return 1;
} catch (Exception e) {
// 插入失败记录异常并返回 0
e.printStackTrace();
return 0;
}
}
@Override
public int withdraw(String userId, double amount) {
try {
// 获取用户当前余额
double balance = getWalletBalance(userId);
// 如果余额不足直接返回 0
if (balance < amount) {
return 0;
}
// 更新余额
balance -= amount;
SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
// 创建 Wallet 对象并插入数据
Wallet wallet = new Wallet(null, userId, balance, amount, sdf.format(new Date()), TransactionType.WITHDRAWAL);
walletMapper.addWalletByWallet(wallet);
// 插入成功返回 1
return 1;
} catch (Exception e) {
// 记录异常并返回 0
e.printStackTrace();
return 0;
}
}
@Override
public int expense(String userId, double amount) {
try {
// 获取用户当前余额
double balance = getWalletBalance(userId);
// 如果余额不足直接返回 0
if (balance < amount) {
return 0;
}
// 更新余额
balance -= amount;
SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
// 创建 Wallet 对象并插入数据
Wallet wallet = new Wallet(null, userId, balance, amount, sdf.format(new Date()), TransactionType.EXPENSE);
walletMapper.addWalletByWallet(wallet);
// 插入成功返回 1
return 1;
} catch (Exception e) {
// 记录异常并返回 0
e.printStackTrace();
return 0;
}
}
@Override
public double getWalletBalance(String userId) {
try {
// 查询用户所有钱包记录
List<Wallet> wallets = walletMapper.listWalletsByUserId(userId);
// 如果用户没有钱包记录则余额为0
double balance = 0.0;
SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
if (wallets.isEmpty()) {
// 创建 Wallet 对象
Wallet wallet = new Wallet(null, userId, balance, 0.0, sdf.format(new Date()), TransactionType.CREATE);
// 调用 Mapper 方法插入数据
walletMapper.addWalletByWallet(wallet);
}
if (!wallets.isEmpty()) {
// 找到具有最大钱包ID的记录
Wallet maxWallet = Collections.max(wallets, Comparator.comparing(w -> w.getWalletId()));
// 获取最大钱包的余额
balance = maxWallet.getBalance();
}
return balance;
} catch (Exception e) {
// 发生异常时记录并返回0
e.printStackTrace();
return 0.0;
}
}
}

View File

@ -0,0 +1,19 @@
spring:
cloud:
config:
name: wallet_server_11000
profile: dev
label: master
discovery:
enabled: true
service-id: config-server
eureka:
client:
service-url:
defaultZone: http://eurekaServer13000:13000/eureka/,http://eurekaServer13001:13001/eureka/
instance:
prefer-ip-address: true #使用ip地址向eureka server进行注册
instance-id: ${spring.cloud.client.ip-address}:${server.port} #设置eureka控制台中显示的注册信息
lease-renewal-interval-in-seconds: 5
lease-expiration-duration-in-seconds: 15

View File

@ -0,0 +1,5 @@
Manifest-Version: 1.0
Built-By: ₩ᄁチ¦ᄌタ¥ヘモ
Build-Jdk: 1.8.0_371
Created-By: Maven Integration for Eclipse

View File

@ -0,0 +1,7 @@
#Generated by Maven Integration for Eclipse
#Sun Apr 21 15:15:43 CST 2024
version=1.0-SNAPSHOT
groupId=com.neusoft
m2e.projectName=wallet_server_10800
m2e.projectLocation=D\:\\OneDrive - tju.edu.cn\\my homework\\\u9AD8\u7EA7\u5B9E\u8DF5\\elm_springcloud-main\\springcloud_elm\\wallet_server_10800
artifactId=wallet_server_10800

View File

@ -0,0 +1,65 @@
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 https://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<parent>
<groupId>com.neusoft</groupId>
<artifactId>springcloud_elm</artifactId>
<version>1.0-SNAPSHOT</version>
</parent>
<artifactId>wallet_server_10800</artifactId>
<properties>
<maven.compiler.source>8</maven.compiler.source>
<maven.compiler.target>8</maven.compiler.target>
</properties>
<dependencies>
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-bus</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-stream-binder-rabbit</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-actuator</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-starter-config</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-starter-netflix-eureka-client</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
</dependency>
<dependency>
<groupId>org.mybatis.spring.boot</groupId>
<artifactId>mybatis-spring-boot-starter</artifactId>
<version>2.0.1</version>
</dependency>
<dependency>
<groupId>mysql</groupId>
<artifactId>mysql-connector-java</artifactId>
<version>8.0.20</version>
<scope>runtime</scope>
</dependency>
<!-- 热部署 gav -->
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-devtools</artifactId>
<scope>runtime</scope>
<optional>true</optional>
</dependency>
<dependency>
<groupId>com.neusoft</groupId>
<artifactId>business_server_10300</artifactId>
<version>1.0-SNAPSHOT</version>
</dependency>
</dependencies>
</project>

View File

@ -0,0 +1,19 @@
spring:
cloud:
config:
name: wallet_server_11000
profile: dev
label: master
discovery:
enabled: true
service-id: config-server
eureka:
client:
service-url:
defaultZone: http://eurekaServer13000:13000/eureka/,http://eurekaServer13001:13001/eureka/
instance:
prefer-ip-address: true #使用ip地址向eureka server进行注册
instance-id: ${spring.cloud.client.ip-address}:${server.port} #设置eureka控制台中显示的注册信息
lease-renewal-interval-in-seconds: 5
lease-expiration-duration-in-seconds: 15

9
wallet.sql Normal file
View File

@ -0,0 +1,9 @@
CREATE TABLE Wallet (
walletId INT PRIMARY KEY AUTO_INCREMENT,
userId VARCHAR(20),
balance DOUBLE,
transactionNum DOUBLE,
transactionTime DATETIME,
transactionType VARCHAR(50),
FOREIGN KEY (userId) REFERENCES user(userId)
) ENGINE=InnoDB DEFAULT CHARSET=utf8;