添加钱包模块、美化前端

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

@ -1,314 +1,327 @@
<template> <template>
<!------总容器------> <!------总容器------>
<div class="wrapper"> <div class="wrapper">
<header> <header>
<i class="fa fa-angle-left" @click="back"></i> <i class="fa fa-angle-left" @click="back"></i>
<p>修改地址</p> <p>修改地址</p>
</header> </header>
<div class="shangbiao"> <div class="shangbiao">
<img src="../assets/elmlogo.jpg"> <img src="../assets/elmlogo.jpg">
</div> </div>
<!------自动识别------> <!------自动识别------>
<div class="identify"> <div class="identify">
<input type="text" placeholder=" 粘贴地址,智能识别填写" v-model="addressInfo"> <input type="text" placeholder=" 粘贴地址,智能识别填写" v-model="addressInfo">
<button @click="fill"> <button @click="fill">
<p>AI识别</p> <p>AI识别</p>
</button> </button>
</div> </div>
<!------列表------> <!------列表------>
<ul class="form"> <ul class="form">
<li> <li>
<div class="title"> <div class="title">
收货人 收货人
</div> </div>
<div class="content"> <div class="content">
<input type="text" placeholder=" 收货人姓名" v-model="deliveryAddress.contactName"> <input type="text" placeholder=" 收货人姓名" v-model="deliveryAddress.contactName">
</div> </div>
</li> </li>
<li> <li>
<div class="gender" style="font-size: 3.5vw"> <div class="gender" style="font-size: 3.5vw">
<input type="radio" name="sex" checked style="width: 8vw;height: 4.2vw;">先生 <input type="radio" name="sex" checked style="width: 8vw;height: 4.2vw;">先生
<input type="radio" name="sex" style="width: 8vw;height: 4.2vw;">女士 <input type="radio" name="sex" style="width: 8vw;height: 4.2vw;">女士
</div> </div>
</li> </li>
<li> <li>
<div class="title"> <div class="title">
手机号 手机号
</div> </div>
<div class="content"> <div class="content">
<input type="text" placeholder=" 填写收获人手机号码" v-model="deliveryAddress.contactTel"> <input type="text" placeholder=" 填写收获人手机号码" v-model="deliveryAddress.contactTel">
</div> </div>
</li> </li>
<li> <li>
<div class="title"> <div class="title">
地址 地址
</div> </div>
<div class="content"> <div class="content">
<input type="text" placeholder=" 填写详细地址,精确到门牌号" v-model="deliveryAddress.address"> <input type="text" placeholder=" 填写详细地址,精确到门牌号" v-model="deliveryAddress.address">
</div> </div>
</li> </li>
</ul> </ul>
<!------确认修改------> <!------确认修改------>
<div class="ok"> <div class="ok">
<button @click="addUserAddress"> <button @click="addUserAddress">
<p>保存修改</p> <p>保存修改</p>
</button> </button>
</div> </div>
</div> </div>
</template> </template>
<script> <script>
import Footer from '../components/Footer.vue'; import Footer from '../components/Footer.vue';
export default { export default {
name: 'AddUserAddress', name: 'AddUserAddress',
data() { data() {
return { return {
businessId: this.$route.query.businessId, businessId: this.$route.query.businessId,
user: {}, user: {},
addressInfo: '', addressInfo: '',
deliveryAddress: { deliveryAddress: {
contactName: '', contactName: '',
contactSex: 1, contactSex: 1,
contactTel: '', contactTel: '',
address: '' address: ''
}, },
nameVisible: false, nameVisible: false,
phoneVisible: false, phoneVisible: false,
phoneError: false, phoneError: false,
addrVisible: false addrVisible: false
} }
}, },
created() { created() {
this.user = this.$getSessionStorage('user'); this.user = this.$getSessionStorage('user');
}, },
components: { components: {
Footer Footer
}, },
methods: { methods: {
back() { back() {
this.$router.go(-1); this.$router.go(-1);
}, },
addUserAddress() { addUserAddress() {
if (this.deliveryAddress.contactName == '') { if (this.deliveryAddress.contactName == '') {
this.nameVisible = true; this.nameVisible = true;
setTimeout(() => { setTimeout(() => {
this.nameVisible = false; this.nameVisible = false;
}, 2000); }, 2000);
return; return;
} }
if (this.deliveryAddress.contactTel == '') { if (this.deliveryAddress.contactTel == '') {
this.phoneVisible = true; this.phoneVisible = true;
setTimeout(() => { setTimeout(() => {
this.phoneVisible = false; this.phoneVisible = false;
}, 2000); }, 2000);
return; return;
} else { } else {
const contactTelString = this.deliveryAddress.contactTel.toString(); const contactTelString = this.deliveryAddress.contactTel.toString();
if (contactTelString.length === 11 && !isNaN(contactTelString) && contactTelString.startsWith('1')) { if (contactTelString.length === 11 && !isNaN(contactTelString) && contactTelString.startsWith('1')) {
// 111 // 111
} else { } else {
this.phoneError = true; this.phoneError = true;
setTimeout(() => { setTimeout(() => {
this.phoneError = false; this.phoneError = false;
}, 2000); }, 2000);
return; return;
} }
} }
if (this.deliveryAddress.address == '') { if (this.deliveryAddress.address == '') {
this.addrVisible = true; this.addrVisible = true;
setTimeout(() => { setTimeout(() => {
this.addrVisible = false; this.addrVisible = false;
}, 2000); }, 2000);
return; return;
} }
let url=`DeliveryAddressController/saveDeliveryAddress/${this.deliveryAddress.contactName}/${this.deliveryAddress.contactSex}/${this.deliveryAddress.contactTel}/${this.deliveryAddress.address}/${this.user.userId}` let url =
this.$axios.post(url).then(response => { `DeliveryAddressController/saveDeliveryAddress/${this.deliveryAddress.contactName}/${this.deliveryAddress.contactSex}/${this.deliveryAddress.contactTel}/${this.deliveryAddress.address}/${this.user.userId}`
if (response.data.result > 0) { this.$axios.post(url).then(response => {
this.$router.push({ if (response.data.result > 0) {
path: '/userAddress', this.$router.push({
query: { path: '/userAddress',
businessId: this.businessId query: {
} businessId: this.businessId
}); }
} else { });
alert('新增地址失败!'); } else {
} alert('新增地址失败!');
}).catch(error => { }
console.error(error); }).catch(error => {
}); console.error(error);
}, });
fill() { },
this.$axios.get('DeliveryAddressController/AddressInfo',{ fill() {
params:{ this.$axios.get('DeliveryAddressController/AddressInfo', {
addressInfo: this.addressInfo params: {
} addressInfo: this.addressInfo
}).then(response => { }
this.deliveryAddress.contactName = response.data[0]; }).then(response => {
this.deliveryAddress.contactTel = response.data[1]; this.deliveryAddress.contactName = response.data[0];
this.deliveryAddress.address = response.data[2]; this.deliveryAddress.contactTel = response.data[1];
}).catch(error => { this.deliveryAddress.address = response.data[2];
console.error(error); }).catch(error => {
}); console.error(error);
} });
} }
} }
}
</script> </script>
<style scoped> <style scoped>
/****************** 总容器 ******************/ /****************** 总容器 ******************/
.wrapper { .wrapper {
width: 100vw; width: 100vw;
position: absolute; position: absolute;
} }
/******head部分********/ /******head部分********/
.wrapper header { .wrapper header {
width: 100%; width: 100%;
height: 12vw; height: 12vw;
background-color: #01B0F2; background-color: #01B0F2;
font-size: 4.8vw; font-size: 5.5vw;
color: #fff; color: #fff;
z-index: 10;
display: flex;
justify-content: center;
align-items: center;
position: fixed;
left: 0;
top: 0;
transition: all 0.3s ease;
}
z-index: 10; .wrapper header i {
margin-right: 3vw;
font-size: 7vw;
user-select: none;
cursor: pointer;
}
display: flex; .wrapper header p {
justify-content: flex-start; margin-left: 3vw;
align-items: center; }
position: fixed;
left: 0;
top: 0;
}
.wrapper header i {
margin: 0vw 0vw 0vw 3vw;
font-size: 6vw;
user-select: none;
cursor: pointer;
}
.wrapper header p {
margin: 0vw 0vw 0vw 33.5vw;
}
.wrapper .shangbiao {
width:100vw;
height: 20vw;
margin-top: 20vw;
display: flex;
justify-content: center;
}
.wrapper .shangbiao img{
width: 30vw;
height: 25vw;
}
/*******自动识别********/
.wrapper .identify {
width: 100vw;
height: 18vw;
margin-top: 2vw;
display: flex;
align-items: center;
justify-content: center;
}
.wrapper .identify input {
width: 70%;
height: 8vw;
font-size: 4vw;
background-color: #d4ebfe;
border-radius: 2.5vw;
outline: none;
border-style: dotted;
}
.wrapper .identify button{
width: 14vw;
height: 8vw;
border-radius: 3vw;
margin-left: 3vw;
}
.wrapper .identify button p{
font-size: 3.5vw;
}
/******列表******/ .wrapper .shangbiao {
.wrapper .form{ width: 100vw;
width: 100vw; height: 20vw;
margin-top: 2vw; margin-top: 14vw;
} display: flex;
justify-content: center;
box-shadow: 0px 4px 6px rgba(0, 0, 0, 0.1);
}
.wrapper .form li {
box-sizing: border-box;
padding: 4vw 3vw 0 3vw;
display: flex; .wrapper .shangbiao img {
align-items: center; width: 30vw;
} height: 25vw;
}
.wrapper .form li .title { /*******自动识别********/
flex: 0 0 18vw; .wrapper .identify {
font-size: 4vw; width: 100vw;
font-weight: 450; height: 18vw;
color: #666;
margin-left: 5vw;
}
.wrapper .form li .content { margin-top: 2vw;
flex: 1; display: flex;
} align-items: center;
justify-content: center;
}
.wrapper .form li .content input { .wrapper .identify input {
outline: none; width: 80%;
width: 90%; height: 10vw;
height: 7vw; font-size: 4.5vw;
font-size: 3.5vw; background-color: #d4ebfe;
} border-radius: 5vw;
outline: none;
border: none;
padding: 0 2vw;
box-shadow: 0px 2px 4px rgba(0, 0, 0, 0.1);
}
.wrapper .form li .gender { .wrapper .identify button {
width: 100vw; width: 16vw;
height: 6vw; height: 10vw;
display: flex; border-radius: 5vw;
justify-content: center; margin-left: 3vw;
} background-color: #01B0F2;
border: none;
outline: none;
cursor: pointer;
transition: all 0.3s ease;
}
.wrapper .identify button p {
font-size: 4vw;
color: #fff;
}
.wrapper .identify button:hover {
transform: scale(1.1);
}
/*******确认修改********/ /******列表******/
.wrapper .ok{ .wrapper .form {
height: 20vw; width: 100vw;
width: 100vw; margin-top: 2vw;
display: flex; }
align-items: center;
justify-content: center;
}
.wrapper .ok button{ .wrapper .form li {
width: 35vw; box-sizing: border-box;
height: 8vw; padding: 3vw 3vw 0 3vw;
border-radius: 3vw; display: flex;
margin-left: 3vw; align-items: center;
background-color: #4ba0fa; }
border: none;
margin-top: 8vw;
}
.wrapper .ok p{ .wrapper .form li .title {
font-size: 4vw; flex: 0 0 20vw;
color: #fff; font-size: 4.5vw;
font-weight: 800; font-weight: 500;
} color: #333;
margin-left: 3vw;
}
.wrapper .form li .content {
flex: 1;
}
.wrapper .form li .content input {
outline: none;
width: 90%;
height: 7vw;
font-size: 4vw;
border: none;
border-bottom: 1px solid #ccc;
}
.wrapper .form li .gender {
width: 100vw;
height: 6vw;
display: flex;
justify-content: center;
}
.wrapper .ok {
height: 20vw;
width: 100vw;
display: flex;
align-items: center;
justify-content: center;
}
.wrapper .ok button {
width: 35vw;
height: 10vw;
border-radius: 5vw;
background-color: #4ba0fa;
border: none;
margin-top: 6vw;
font-size: 4.5vw;
font-weight: 600;
color: #fff;
}
.wrapper .ok button:hover {
background-color: #3687d8;
}
</style> </style>

File diff suppressed because it is too large Load Diff

View File

@ -1,204 +1,236 @@
<template> <template>
<div class="wrapper"> <div class="wrapper">
<!-- header部分 --> <!-- header部分 -->
<header> <header>
<i class="fa fa-angle-left" @click="back"></i> <i class="fa fa-angle-left" @click="back"></i>
<p>商家列表</p> <p>商家列表</p>
</header> </header>
<!-- 商家列表部分 --> <!-- 商家列表部分 -->
<ul class="business"> <ul class="business">
<li v-for="item in businessArr" @click="toBusinessInfo(item.businessId)"> <li v-for="item in businessArr" @click="toBusinessInfo(item.businessId)">
<div class="border"> <div class="border">
<div class="business-img"> <div class="business-img">
<img :src="item.businessImg"> <img :src="item.businessImg">
<div class="business-img-quantity" v-show="item.quantity>0">{{item.quantity}}</div> <div class="business-img-quantity" v-show="item.quantity>0">{{item.quantity}}</div>
</div> </div>
<div class="business-info"> <div class="business-info">
<h3>{{item.businessName}}</h3> <h3>{{item.businessName}}</h3>
<p>&#165;{{item.starPrice}}起送 | &#165;{{item.deliveryPrice}}配送</p> <p>&#165;{{item.starPrice}}起送 | &#165;{{item.deliveryPrice}}配送</p>
<p>{{item.businessExplain}}</p> <p>{{item.businessExplain}}</p>
</div> </div>
</div> </div>
</li> </li>
</ul> </ul>
<Footer></Footer> <Footer></Footer>
</div> </div>
</template> </template>
<script> <script>
import Footer from '../components/Footer.vue'; import Footer from '../components/Footer.vue';
export default { export default {
name: 'BusinessList', name: 'BusinessList',
data() { data() {
return { return {
orderTypeId: this.$route.query.orderTypeId, orderTypeId: this.$route.query.orderTypeId,
businessArr: [], businessArr: [],
user: {} user: {}
} }
}, },
created() { created() {
this.user = this.$getSessionStorage('user'); this.user = this.$getSessionStorage('user');
//orderTypeId //orderTypeId
let url=`BusinessController/listBusinessByOrderTypeId/${this.orderTypeId}` let url = `BusinessController/listBusinessByOrderTypeId/${this.orderTypeId}`
this.$axios.get(url).then(response => { this.$axios.get(url).then(response => {
this.businessArr = response.data.result; this.businessArr = response.data.result;
console.log(response.data.message); console.log(response.data.message);
// //
if (this.user != null) { if (this.user != null) {
this.listCart(); this.listCart();
} }
}).catch(error => { }).catch(error => {
console.error(error); console.error(error);
}); });
}, },
components: { components: {
Footer Footer
}, },
methods: { methods: {
back() { back() {
this.$router.go(-1); this.$router.go(-1);
}, },
listCart() { listCart() {
let url=`CartController/listCart/${this.user.userId}` let url = `CartController/listCart/${this.user.userId}`
this.$axios.get(url).then(response => { this.$axios.get(url).then(response => {
let cartArr = response.data.result; let cartArr = response.data.result;
// //
for (let businessItem of this.businessArr) { for (let businessItem of this.businessArr) {
businessItem.quantity = 0; businessItem.quantity = 0;
for (let cartItem of cartArr) { for (let cartItem of cartArr) {
if (cartItem.businessId == businessItem.businessId) { if (cartItem.businessId == businessItem.businessId) {
businessItem.quantity += cartItem.quantity; businessItem.quantity += cartItem.quantity;
} }
} }
} }
this.businessArr.sort(); this.businessArr.sort();
}).catch(error => { }).catch(error => {
console.error(error); console.error(error);
}); });
}, },
toBusinessInfo(businessId) { toBusinessInfo(businessId) {
this.$router.push({ this.$router.push({
path: '/businessInfo', path: '/businessInfo',
query: { query: {
businessId: businessId businessId: businessId
} }
}); });
} }
} }
} }
</script> </script>
<style scoped> <style scoped>
/****************总容器***************/ /****************总容器***************/
.wrapper { .wrapper {
width: 100%; width: 100%;
height: 100%; height: 100%;
} }
/****************header部分***************/ /****************header部分***************/
.wrapper header { .wrapper header {
width: 100%; width: 100%;
height: 12vw; height: 12vw;
background-color: #01B0F2; background-color: #01B0F2;
font-size: 4.8vw; font-size: 4.8vw;
color: #fff; color: #fff;
z-index: 10; z-index: 10;
display: flex; display: flex;
justify-content: flex-start; justify-content: flex-start;
align-items: center; align-items: center;
position: fixed; position: fixed;
left: 0; left: 0;
top: 0; top: 0;
} }
.wrapper header i { .wrapper header i {
margin: 0vw 0vw 0vw 3vw; margin: 0vw 0vw 0vw 3vw;
font-size: 6vw; font-size: 6vw;
user-select: none; user-select: none;
cursor: pointer; cursor: pointer;
} }
.wrapper header p { .wrapper header p {
margin: 0vw 0vw 0vw 33.5vw; margin: 0vw 0vw 0vw 33.5vw;
} }
/****************商家列表部分***************/ /****************商家列表部分***************/
.wrapper .business { .wrapper .business {
width: 100%; width: 100%;
margin-top: 12vw; margin-top: 12vw;
padding-bottom: 14vw; padding-bottom: 14vw;
} }
.wrapper .business li { .wrapper .business li {
width: 100%; width: 100%;
padding: 2vw 2vw 0vw 2vw; padding: 2vw 2vw 0vw 2vw;
background-color: #F4F8Fb; background-color: #F4F8Fb;
box-sizing: border-box; box-sizing: border-box;
} }
.wrapper .business li .border { .wrapper .business li .border {
width: 100%; width: 100%;
box-sizing: border-box; box-sizing: border-box;
padding: 2vw; padding: 2vw;
user-select: none; user-select: none;
background-color: #fff; background-color: #fff;
cursor: pointer; cursor: pointer;
border-radius: 2vw; 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;
}
display: flex; .wrapper .business li:hover .border {
align-items: center; background-color: #E0F2FE;
} transform: scale(1.05);
}
.wrapper .business li .border .business-img { .wrapper .business li:active .border {
position: relative; border: 2px solid #FF5722;
} transform: scale(0.95);
}
.wrapper .business li .border .business-img img { @keyframes fadeIn {
width: 20vw; from {
height: 20vw; opacity: 0;
border-radius: 2vw; }
}
.wrapper .business li .border .business-img .business-img-quantity { to {
width: 5vw; opacity: 1;
height: 5vw; }
background-color: red; }
color: #fff;
font-size: 3.6vw;
border-radius: 2.5vw;
display: flex; .wrapper .business li .border .business-img {
justify-content: center; position: relative;
align-items: center; }
position: absolute; .wrapper .business li .border .business-img img {
right: -1.5vw; width: 20vw;
top: -1.5vw; height: 20vw;
} border-radius: 2vw;
transition: transform 0.3s;
}
.wrapper .business li .border .business-info { .wrapper .business li .border:hover .business-img img {
margin-left: 3vw; transform: scale(1.1);
} }
.wrapper .business li .border .business-info h3 { .wrapper .business li .border:active .business-img img {
font-size: 3.8vw; transform: scale(0.9);
color: #555; }
}
.wrapper .business li .border .business-info p { .wrapper .business li .border .business-img .business-img-quantity {
font-size: 3vw; width: 5vw;
color: #888; height: 5vw;
margin-top: 2vw; background-color: red;
} color: #fff;
font-size: 3.6vw;
border-radius: 2.5vw;
display: flex;
justify-content: center;
align-items: center;
position: absolute;
right: -1.5vw;
top: -1.5vw;
}
.wrapper .business li .border .business-info {
margin-left: 3vw;
}
.wrapper .business li .border .business-info h3 {
font-size: 3.8vw;
color: #555;
}
.wrapper .business li .border .business-info p {
font-size: 3vw;
color: #888;
margin-top: 2vw;
}
</style> </style>

View File

@ -1,271 +1,272 @@
<template> <template>
<div class="wrapper"> <div class="wrapper">
<!-- header部分 --> <!-- header部分 -->
<header> <header>
<i class="fa fa-angle-left" @click="back"></i> <i class="fa fa-angle-left" @click="back"></i>
<p>消费券选择</p> <p>消费券选择</p>
</header> </header>
<!-- 地址列表部分 --> <!-- 地址列表部分 -->
<ul class="addresslist"> <ul class="addresslist">
<li v-for="item in CouponList"> <li v-for="item in CouponList" v-show="this.totalPrice>=item.limitNum">
<!-- <div class="addresslist-left" @click="setDeliveryAddress(item)"> <!-- <div class="addresslist-left" @click="setDeliveryAddress(item)">
<h3>{{item.contactName}}{{getSexText(item.contactSex)}} {{item.contactTel}} <h3>{{item.contactName}}{{getSexText(item.contactSex)}} {{item.contactTel}}
</h3> </h3>
<p>{{item.address}}</p> <p>{{item.address}}</p>
</div> </div>
<div class="addresslist-right"> <div class="addresslist-right">
<i class="fa fa-edit" @click="editUserAddress(item.daId)"></i> <i class="fa fa-edit" @click="editUserAddress(item.daId)"></i>
<i class="fa fa-remove" @click="removeUserAddress(item.daId)"></i> <i class="fa fa-remove" @click="removeUserAddress(item.daId)"></i>
</div> --> </div> -->
<div class="Coupon-Intro" @click="useThisCoupon(item)"> <div class="Coupon-Intro" @click="useThisCoupon(item)">
<p class="Coupon-Name">{{item.limitNum}}{{item.minusNum}}优惠券</p> <p class="Coupon-Name">{{item.limitNum}}{{item.minusNum}}优惠券</p>
<p class="Coupon-Outdate">有效日期{{item.outDate}}</p> <p class="Coupon-Outdate">有效日期{{item.outDate}}</p>
</div> </div>
</li> </li>
<li> <li>
<div class="Coupon-Intro" @click="notUseCoupon()"> <div class="Coupon-Intro" @click="notUseCoupon()">
<p class="Coupon-Name">不使用消费券</p> <p class="Coupon-Name">不使用消费券</p>
<p class="Coupon-Outdate">-</p> <p class="Coupon-Outdate">-</p>
</div> </div>
</li> </li>
</ul> </ul>
<!-- 新增地址部分 --> <!-- 新增地址部分 -->
<!-- <div class="addbtn" @click="toAddUserAddress"> <!-- <div class="addbtn" @click="toAddUserAddress">
<i class="fa fa-plus-circle"></i> <i class="fa fa-plus-circle"></i>
<p>新增收货地址</p> <p>新增收货地址</p>
</div> --> </div> -->
<!-- 底部菜单部分 --> <!-- 底部菜单部分 -->
<Footer></Footer> <Footer></Footer>
</div> </div>
</template> </template>
<script> <script>
import Footer from '../components/Footer.vue'; import Footer from '../components/Footer.vue';
export default { export default {
name: 'UserAddress', name: 'UserAddress',
data() { data() {
return { return {
businessId: this.$route.query.businessId, businessId: this.$route.query.businessId,
user: {}, user: {},
deliveryAddressArr: [], deliveryAddressArr: [],
CouponList:[], CouponList:[],
} totalPrice:this.$route.query.totalPrice,
}, }
created() { },
this.user = this.$getSessionStorage('user'); created() {
this.user = this.$getSessionStorage('user');
this.listDeliveryAddressByUserId(); this.listDeliveryAddressByUserId();
this.getCouponByUserId(this.user.userId); this.getCouponByUserId(this.user.userId);
}, },
components: { components: {
Footer Footer
}, },
methods: { methods: {
back() { back() {
this.$router.go(-1); this.$router.go(-1);
}, },
getSexText(sex) { getSexText(sex) {
return sex === 1 ? '先生' : '女士'; return sex === 1 ? '先生' : '女士';
}, },
listDeliveryAddressByUserId() { listDeliveryAddressByUserId() {
// //
let url=`DeliveryAddressController/listDeliveryAddressByUserId/${this.user.userId}` let url=`DeliveryAddressController/listDeliveryAddressByUserId/${this.user.userId}`
this.$axios.get(url).then(response => { this.$axios.get(url).then(response => {
this.deliveryAddressArr = response.data.result; this.deliveryAddressArr = response.data.result;
}).catch(error => { }).catch(error => {
console.error(error); console.error(error);
}); });
}, },
setDeliveryAddress(deliveryAddress) { setDeliveryAddress(deliveryAddress) {
//localStorage //localStorage
this.$setLocalStorage(this.user.userId, deliveryAddress); this.$setLocalStorage(this.user.userId, deliveryAddress);
this.$router.push({ this.$router.push({
path: '/orders', path: '/orders',
query: { query: {
businessId: this.businessId businessId: this.businessId
} }
}); });
}, },
toAddUserAddress() { toAddUserAddress() {
this.$router.push({ this.$router.push({
path: '/addUserAddress', path: '/addUserAddress',
query: { query: {
businessId: this.businessId businessId: this.businessId
} }
}); });
}, },
editUserAddress(daId) { editUserAddress(daId) {
this.$router.push({ this.$router.push({
path: '/editUserAddress', path: '/editUserAddress',
query: { query: {
businessId: this.businessId, businessId: this.businessId,
daId: daId daId: daId
} }
}); });
}, },
removeUserAddress(daId) { removeUserAddress(daId) {
if (!confirm('确认要删除此送货地址吗?')) { if (!confirm('确认要删除此送货地址吗?')) {
return; return;
} }
let url=`DeliveryAddressController/removeDeliveryAddress/${daId}` let url=`DeliveryAddressController/removeDeliveryAddress/${daId}`
this.$axios.delete(url).then(response => { this.$axios.delete(url).then(response => {
if (response.data.result > 0) { if (response.data.result > 0) {
let deliveryAddress = this.$getLocalStorage(this.user.userId); let deliveryAddress = this.$getLocalStorage(this.user.userId);
if (deliveryAddress != null && deliveryAddress.daId == daId) { if (deliveryAddress != null && deliveryAddress.daId == daId) {
this.$removeLocalStorage(this.user.userId); this.$removeLocalStorage(this.user.userId);
} }
this.listDeliveryAddressByUserId(); this.listDeliveryAddressByUserId();
} else { } else {
alert('删除地址失败!'); alert('删除地址失败!');
} }
}).catch(error => { }).catch(error => {
console.error(error); console.error(error);
}); });
}, },
getCouponByUserId(userId) getCouponByUserId(userId)
{ {
this.$axios.get(`CouponController/getCouponByUserId/${userId}`).then(response =>{ this.$axios.get(`CouponController/getCouponByUserId/${userId}`).then(response =>{
this.CouponList=response.data.result; this.CouponList=response.data.result;
}) })
}, },
useThisCoupon(Coupon) useThisCoupon(Coupon)
{ {
this.$setLocalStorage(this.$route.query.businessId,Coupon); this.$setLocalStorage(this.$route.query.businessId,Coupon);
this.$router.push({ this.$router.push({
path: '/orders', path: '/orders',
query: { query: {
businessId: this.businessId businessId: this.businessId
} }
}); });
}, },
notUseCoupon() notUseCoupon()
{ {
this.$setLocalStorage(this.$route.query.businessId,null) this.$setLocalStorage(this.$route.query.businessId,null)
this.$router.push({ this.$router.push({
path: '/orders', path: '/orders',
query: { query: {
businessId: this.businessId businessId: this.businessId
} }
}); });
} }
} }
} }
</script> </script>
<style scoped> <style scoped>
/*************** 总容器 ***************/ /*************** 总容器 ***************/
.wrapper { .wrapper {
width: 100%; width: 100%;
height: 100%; height: 100%;
background-color: #F5F5F5; background-color: #F5F5F5;
} }
/*************** header ***************/ /*************** header ***************/
.wrapper header { .wrapper header {
width: 100%; width: 100%;
height: 12vw; height: 12vw;
background-color: #01B0F2; background-color: #01B0F2;
font-size: 4.8vw; font-size: 4.8vw;
color: #fff; color: #fff;
z-index: 10; z-index: 10;
display: flex; display: flex;
justify-content: flex-start; justify-content: flex-start;
align-items: center; align-items: center;
position: fixed; position: fixed;
left: 0; left: 0;
top: 0; top: 0;
} }
.wrapper header i { .wrapper header i {
margin: 0vw 0vw 0vw 3vw; margin: 0vw 0vw 0vw 3vw;
font-size: 6vw; font-size: 6vw;
user-select: none; user-select: none;
cursor: pointer; cursor: pointer;
} }
.wrapper header p { .wrapper header p {
margin: 0vw 0vw 0vw 33.5vw; margin: 0vw 0vw 0vw 33.5vw;
} }
/*************** addresslist ***************/ /*************** addresslist ***************/
.wrapper .addresslist { .wrapper .addresslist {
width: 100%; width: 100%;
padding-top: 12vw; padding-top: 12vw;
background-color: #fff; background-color: #fff;
} }
.wrapper .addresslist li { .wrapper .addresslist li {
width: 100%; width: 100%;
box-sizing: border-box; box-sizing: border-box;
border-bottom: solid 1px #DDD; border-bottom: solid 1px #DDD;
padding: 3vw; padding: 3vw;
display: flex; display: flex;
} }
.wrapper .addresslist li .addresslist-left { .wrapper .addresslist li .addresslist-left {
flex: 5; flex: 5;
/*左边这块区域是可以点击的*/ /*左边这块区域是可以点击的*/
user-select: none; user-select: none;
cursor: pointer; cursor: pointer;
} }
.wrapper .addresslist li .addresslist-left h3 { .wrapper .addresslist li .addresslist-left h3 {
font-size: 4.6vw; font-size: 4.6vw;
font-weight: 300; font-weight: 300;
color: #666; color: #666;
} }
.wrapper .addresslist li .addresslist-left p { .wrapper .addresslist li .addresslist-left p {
font-size: 4vw; font-size: 4vw;
color: #666; color: #666;
} }
.wrapper .addresslist li .addresslist-right { .wrapper .addresslist li .addresslist-right {
flex: 1; flex: 1;
font-size: 5.6vw; font-size: 5.6vw;
color: #999; color: #999;
cursor: pointer; cursor: pointer;
display: flex; display: flex;
justify-content: space-around; justify-content: space-around;
align-items: center; align-items: center;
} }
/*************** 新增地址部分 ***************/ /*************** 新增地址部分 ***************/
.wrapper .addbtn { .wrapper .addbtn {
width: 100%; width: 100%;
height: 14vw; height: 14vw;
border-top: solid 1px #DDD; border-top: solid 1px #DDD;
border-bottom: solid 1px #DDD; border-bottom: solid 1px #DDD;
background-color: #fff; background-color: #fff;
margin-top: 4vw; margin-top: 4vw;
display: flex; display: flex;
justify-content: center; justify-content: center;
align-items: center; align-items: center;
font-size: 4.5vw; font-size: 4.5vw;
color: #01B0F2; color: #01B0F2;
user-select: none; user-select: none;
cursor: pointer; cursor: pointer;
} }
p { p {
margin-left: 2vw; margin-left: 2vw;
} }
.wrapper .Coupon-Intro{ .wrapper .Coupon-Intro{
cursor: pointer; cursor: pointer;
width: 100%; width: 100%;
height: 16vw; height: 16vw;
box-sizing: border-box; box-sizing: border-box;
padding: 3vw; padding: 3vw;
color: #666; color: #666;
display: flex; display: flex;
justify-content: space-between; justify-content: space-between;
align-items: center; align-items: center;
font-size: 3.5vw; font-size: 3.5vw;
} }
</style> </style>

View File

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

View File

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

View File

@ -1,181 +1,247 @@
<template> <template>
<div class="wrapper"> <div class="wrapper">
<!-- header部分 --> <!-- header部分 -->
<header> <header>
<i class="fa fa-angle-left" @click="back"></i> <i class="fa fa-angle-left" @click="back"></i>
<p>我的钱包</p> <p>我的钱包</p>
</header> </header>
</div>
<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> </template>
<script> <script>
export default { export default {
name: 'Wallet', name: 'walletDetails',
data() { data() {
return { return {
isShouzhi: true, isShouzhi: true,
availablePointArr: [], availablePointArr: [],
outDatePointArr: [], balance: [],
user: {} user: {}
}; };
}, },
computed: { computed: {
sum() { sum() {
return this.availablePointArr.reduce((accumulator, currentValue) => accumulator + currentValue.pointNum, return this.availablePointArr.reduce((accumulator, currentValue) => accumulator + currentValue.pointNum,
0); 0);
} }
}, },
created() { created() {
this.user = this.$getSessionStorage('user');
}, this.$axios.get(`WalletController/listWallets`, {
methods: { params: {
back() { userId: this.user.userId
this.$router.go(-1); },
}, headers: {
toggleTab(tab) { Authorization: this.user.password
this.isShouzhi = tab === 'shouzhi'; }
}, }).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() {
this.$router.go(-1);
},
toggleTab(tab) {
this.isShouzhi = tab === 'shouzhi';
},
},
};
</script> </script>
<style scoped> <style scoped>
.wrapper { .wrapper {
width: 100%; width: 100%;
height: 100%; height: 100%;
background-color: #F4F8Fb; background-color: #F4F8Fb;
} }
/****************** header ******************/ /****************** header ******************/
.wrapper header { .wrapper header {
width: 100%; width: 100%;
height: 12vw; height: 12vw;
background-color: #01B0F2; background-color: #01B0F2;
font-size: 4.8vw; font-size: 4.8vw;
color: #fff; color: #fff;
z-index: 10; z-index: 10;
display: flex; display: flex;
justify-content: flex-start; justify-content: flex-start;
align-items: center; align-items: center;
position: fixed; position: fixed;
left: 0; left: 0;
top: 0; top: 0;
} }
.wrapper header i { .wrapper header i {
margin: 0vw 0vw 0vw 3vw; margin: 0vw 0vw 0vw 3vw;
font-size: 6vw; font-size: 6vw;
user-select: none; user-select: none;
cursor: pointer; cursor: pointer;
} }
.wrapper header p { .wrapper header p {
margin: 0vw 0vw 0vw 32vw; margin: 0vw 0vw 0vw 32vw;
} }
.wrapper .points-total { .wrapper .wallet-total {
padding-top: 20vw; padding-top: 20vw;
} }
.wrapper .points-total .num { .wrapper .wallet-total .num {
display: flex; display: flex;
justify-content: center; justify-content: center;
align-items: center; align-items: center;
margin-bottom: 1vw; margin-bottom: 1vw;
} }
.wrapper .points-total .num p { .wrapper .wallet-total .num p {
font-size: 6vw; font-size: 6.5vw;
} padding-left: 2vw;
}
.wrapper .points-total .num img { .wrapper .wallet-total .num img {
width: 8vw; width: 12vw;
height: 8vw; height: 12vw;
} }
.wrapper .points-total .text { .wrapper .wallet-total .text {
display: flex; display: flex;
justify-content: center; justify-content: center;
align-items: center; align-items: center;
font-size: 2.8vw; font-size: 2.8vw;
} }
.wrapper .points-detail { .wrapper .wallet-detail {
padding-top: 6vw; padding-top: 6vw;
} }
.wrapper .points-detail .top { .wrapper .wallet-detail .top {
display: flex; display: flex;
justify-content: space-around; justify-content: space-around;
align-items: center; align-items: center;
font-size: 3.5vw; font-size: 3.5vw;
padding-bottom: 2vw; padding-bottom: 2vw;
} }
.wrapper .points-detail .top p { .wrapper .wallet-detail .top p {
font-weight: normal; font-weight: normal;
user-select: none; user-select: none;
cursor: pointer; cursor: pointer;
} }
.wrapper .points-detail .top p.active { .wrapper .wallet-detail .top p.active {
font-weight: bold; font-weight: bold;
user-select: none; user-select: none;
cursor: pointer; cursor: pointer;
} }
.wrapper .points-detail .border { .wrapper .wallet-detail .border {
width: 100%; width: 100%;
padding: 2vw 2vw 0vw 2vw; padding: 2vw 2vw 0vw 2vw;
box-sizing: border-box; box-sizing: border-box;
} }
.wrapper .points-detail .border .get-pay { .wrapper .wallet-detail .border .get-pay {
width: 100%; width: 100%;
background-color: #fff; background-color: #fff;
border-radius: 2vw; border-radius: 2vw;
} }
.wrapper .points-detail .border .get-pay .li1 { .wrapper .wallet-detail .border .get-pay .li1 {
padding: 2vw 0vw; padding: 2vw 0vw;
} }
.wrapper .points-detail .border .get-pay .details { .wrapper .wallet-detail .border .get-pay .details {
display: flex; display: flex;
margin: 0vw 2vw; padding: 0vw 2vw 1vw 2vw;
} }
.wrapper .points-detail .border .get-pay .details li { .wrapper .wallet-detail .border .get-pay .details .x{
width: 34%; width: 37%;
font-size: 2.8vw; font-size: 2.8vw;
display: flex; display: flex;
justify-content: center; justify-content: center;
align-items: center; align-items: center;
} }
.wrapper .points-detail .border .duihuan { .wrapper .wallet-detail .border .get-pay .details .y{
width: 100%; width: 21%;
background-color: #fff; font-size: 2.8vw;
border-radius: 2vw; display: flex;
} justify-content: center;
align-items: center;
.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%;
font-size: 2.8vw;
display: flex;
justify-content: center;
align-items: center;
}
</style> </style>

View File

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

View File

@ -41,5 +41,7 @@
<file url="file://$PROJECT_DIR$/src/main/resources" charset="UTF-8" /> <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/java" charset="UTF-8" />
<file url="file://$PROJECT_DIR$/user_server_10100/src/main/resources" 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> </component>
</project> </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; package com.neusoft.service.impl;
import com.neusoft.mapper.CartMapper; import com.neusoft.mapper.CartMapper;
import com.neusoft.po.Cart; import com.neusoft.po.Cart;
import com.neusoft.service.CartService;
import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service; import org.springframework.stereotype.Service;
import java.util.List; import java.util.List;
@Service @Service
public class CartServiceImpl implements CartService { public class CartServiceImpl extends AbstractCartService {
@Autowired @Autowired
private CartMapper cartMapper; private CartMapper cartMapper;
@Override @Override
public List<Cart> listCart(Cart cart) { protected List<Cart> listCartInternal(Cart cart) {
return cartMapper.listCart(cart); return cartMapper.listCart(cart);
} }
@Override @Override
public int saveCart(Cart cart) { protected int saveCartInternal(Cart cart) {
return cartMapper.saveCart(cart); return cartMapper.saveCart(cart);
} }
@Override @Override
public int updateCart(Cart cart) { protected int updateCartInternal(Cart cart) {
return cartMapper.updateCart(cart); return cartMapper.updateCart(cart);
} }
@Override @Override
public int removeCart(Cart cart) { protected int removeCartInternal(Cart cart) {
return cartMapper.removeCart(cart); return cartMapper.removeCart(cart);
} }
} }

View File

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

View File

@ -73,6 +73,11 @@ spring:
predicates: predicates:
- Path=/CollectController/*/** - Path=/CollectController/*/**
- id: walletServer
uri: lb://wallet-server
predicates:
- Path=/WalletController/*/**
eureka: eureka:
client: client:
service-url: 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.beans.factory.annotation.Autowired;
import org.springframework.cloud.context.config.annotation.RefreshScope; import org.springframework.cloud.context.config.annotation.RefreshScope;
import org.springframework.web.bind.annotation.*; import org.springframework.web.bind.annotation.*;
import com.neusoft.controller.CommonResultFactory;
import java.util.List; import java.util.List;
@ -16,6 +17,12 @@ public class OrdersController {
@Autowired @Autowired
private OrdersService ordersService; private OrdersService ordersService;
private final CommonResultFactory commonResultFactory;
public OrdersController(CommonResultFactory commonResultFactory) {
this.commonResultFactory = commonResultFactory;
}
@PostMapping("/createOrders/{userId}/{businessId}/{daId}/{orderTotal}") @PostMapping("/createOrders/{userId}/{businessId}/{daId}/{orderTotal}")
public CommonResult<Integer> createOrders( public CommonResult<Integer> createOrders(
@PathVariable("userId") String userId, @PathVariable("userId") String userId,
@ -29,26 +36,26 @@ public class OrdersController {
param.setDaId(daId); param.setDaId(daId);
param.setOrderTotal(orderTotal); param.setOrderTotal(orderTotal);
int orderId=ordersService.createOrders(param); int orderId=ordersService.createOrders(param);
return new CommonResult<>(200,"success",orderId); return commonResultFactory.createSuccessResult(orderId);
} }
@GetMapping("/getOrdersById/{orderId}") @GetMapping("/getOrdersById/{orderId}")
public CommonResult<Orders> getOrdersById(@PathVariable("orderId") Integer orderId) throws Exception { public CommonResult<Orders> getOrdersById(@PathVariable("orderId") Integer orderId) throws Exception {
Orders orders=ordersService.getOrdersById(orderId); Orders orders=ordersService.getOrdersById(orderId);
return new CommonResult<>(200,"success",orders); return commonResultFactory.createSuccessResult(orders);
} }
@GetMapping("/listOrdersByUserId/{userId}") @GetMapping("/listOrdersByUserId/{userId}")
public CommonResult<List<Orders>> listOrdersByUserId(@PathVariable("userId") String userId) throws Exception { public CommonResult<List<Orders>> listOrdersByUserId(@PathVariable("userId") String userId) throws Exception {
List<Orders> list=ordersService.listOrdersByUserId(userId); List<Orders> list=ordersService.listOrdersByUserId(userId);
return new CommonResult<>(200,"success",list); return commonResultFactory.createSuccessResult(list);
} }
@PutMapping("/Orders/{orderId}") @PutMapping("/Orders/{orderId}")
public CommonResult<Integer>payOrdersById(@PathVariable("orderId") Integer orderId)throws Exception public CommonResult<Integer>payOrdersById(@PathVariable("orderId") Integer orderId)throws Exception
{ {
int result=ordersService.payOrdersById(orderId, null, null, null); 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 @Autowired
private OrdersService ordersService; private OrdersService ordersService;
private final CommonResultFactory commonResultFactory;
public OrdersController(CommonResultFactory commonResultFactory) {
this.commonResultFactory = commonResultFactory;
}
@PostMapping("/createOrders/{userId}/{businessId}/{daId}/{orderTotal}") @PostMapping("/createOrders/{userId}/{businessId}/{daId}/{orderTotal}")
public CommonResult<Integer> createOrders( public CommonResult<Integer> createOrders(
@PathVariable("userId") String userId, @PathVariable("userId") String userId,
@ -29,21 +35,29 @@ public class OrdersController {
param.setDaId(daId); param.setDaId(daId);
param.setOrderTotal(orderTotal); param.setOrderTotal(orderTotal);
int orderId=ordersService.createOrders(param); int orderId=ordersService.createOrders(param);
return new CommonResult<>(200,"success",orderId); return commonResultFactory.createSuccessResult(orderId);
} }
@GetMapping("/getOrdersById/{orderId}") @GetMapping("/getOrdersById/{orderId}")
public CommonResult<Orders> getOrdersById(@PathVariable("orderId") Integer orderId) throws Exception { public CommonResult<Orders> getOrdersById(@PathVariable("orderId") Integer orderId) throws Exception {
Orders orders=ordersService.getOrdersById(orderId); Orders orders=ordersService.getOrdersById(orderId);
return new CommonResult<>(200,"success",orders); return commonResultFactory.createSuccessResult(orders);
} }
@GetMapping("/listOrdersByUserId/{userId}") @GetMapping("/listOrdersByUserId/{userId}")
public CommonResult<List<Orders>> listOrdersByUserId(@PathVariable("userId") String userId) throws Exception { public CommonResult<List<Orders>> listOrdersByUserId(@PathVariable("userId") String userId) throws Exception {
List<Orders> list=ordersService.listOrdersByUserId(userId); 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") // @PutMapping("/Orders")
// public int payOrdersById(OrderState orderState, @RequestHeader("Authorization") String token) throws Exception { // public int payOrdersById(OrderState orderState, @RequestHeader("Authorization") String token) throws Exception {
// return ordersService.payOrdersById(orderState.getOrderId(), orderState.getUserId(), orderState.getOrderTotal(), orderState.getReduction(),token); // return ordersService.payOrdersById(orderState.getOrderId(), orderState.getUserId(), orderState.getOrderTotal(), orderState.getReduction(),token);

View File

@ -27,6 +27,7 @@
<module>point_server_10900</module> <module>point_server_10900</module>
<module>coupon_server_10950</module> <module>coupon_server_10950</module>
<module>collect_server_10800</module> <module>collect_server_10800</module>
<module>wallet_server_11000</module>
</modules> </modules>
<packaging>pom</packaging> <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;