个人中心地址

zhc4dev
wangjiadong 2 years ago
parent 5a213bff3a
commit 695dc61bd6
  1. 57
      ant-design-vue-jeecg/src/views/shopping/components/addrView.vue
  2. 6
      jeecg-boot/jeecg-boot-module-system/src/main/java/org/jeecg/modules/demo/customerreceivingaddress/mapper/CustomerReceivingAddressMapper.java
  3. 4
      jeecg-boot/jeecg-boot-module-system/src/main/java/org/jeecg/modules/demo/customerreceivingaddress/service/ICustomerReceivingAddressService.java
  4. 10
      jeecg-boot/jeecg-boot-module-system/src/main/java/org/jeecg/modules/demo/customerreceivingaddress/service/impl/CustomerReceivingAddressServiceImpl.java
  5. 67
      jeecg-boot/jeecg-boot-module-system/src/main/java/org/jeecg/modules/system/controller/ApeopersionController.java

@ -108,6 +108,7 @@
import { httpAction, getAction } from '@/api/manage' import { httpAction, getAction } from '@/api/manage'
import { deleteAction } from '@/api/manage' import { deleteAction } from '@/api/manage'
import {mapGetters} from 'vuex'
export default { export default {
name: "addrView", name: "addrView",
@ -178,7 +179,9 @@
url: { url: {
getaddress: "/getuserpersion/getaddress", getaddress: "/getuserpersion/getaddress",
deleteadd: "/getuserpersion/deleteadd", deleteadd: "/getuserpersion/deleteadd",
sdqx: "/getuserpersion/sdqx" sdqx: "/getuserpersion/sdqx",
addadressress: "/getuserpersion/addadressress",
updateadressress: "/getuserpersion/updateadressress"
}, },
}; };
}, },
@ -188,6 +191,7 @@
}, },
methods: { methods: {
...mapGetters(["nickname", "avatar","userInfo"]),
reload() { reload() {
this.isReload = false this.isReload = false
this.$nextTick(() => { this.$nextTick(() => {
@ -198,8 +202,6 @@
getAction(this.url.getaddress).then((res) => { getAction(this.url.getaddress).then((res) => {
if(res.success) { if(res.success) {
this.addrList1= res.result; this.addrList1= res.result;
console.log("===================")
console.log(res.result)
} else { } else {
} }
}); });
@ -238,20 +240,61 @@
if(this.form.flag){// if(this.form.flag){//
this.changeDefault() this.changeDefault()
this.addrList.unshift(this.form) this.addrList.unshift(this.form)
//
getAction(this.url.addadressress,{form : JSON.stringify(this.form)}).then((res) => {
if(res.success) {
this.$router.go(0)
} else {
}
});
}else{// }else{//
this.addrList.push(this.form) this.addrList.push(this.form)
console.log(this.userInfo())
//
getAction(this.url.addadressress,{form : JSON.stringify(this.form)}).then((res) => {
if(res.success) {
this.$router.go(0)
} else {
}
});
} }
}else if(this.flag == 'edit'){// }else if(this.flag == 'edit'){
//
// //
let itemIndex3 = this.addrList.findIndex(item =>item.id == this.form.id) let itemIndex3 = this.addrList.findIndex(item =>item.id == this.form.id)
if(this.form.flag){// if(this.form.flag){//
this.changeDefault() this.changeDefault()
this.form.flag = true this.form.flag = true
this.addrList[itemIndex3] = this.form this.addrList[itemIndex3] = this.form
console.log("this.addrList2") /* console.log("this.addrList2")
console.log(this.addrList) console.log(this.addrList)*/
console.log(this.form)
getAction(this.url.updateadressress,{form : JSON.stringify(this.form)}).then((res) => {
if(res.success) {
this.$router.go(0)
} else {
}
});
}else{ }else{
this.addrList[itemIndex3] = this.form this.addrList[itemIndex3] = this.form
getAction(this.url.updateadressress,{form : JSON.stringify(this.form)}).then((res) => {
if(res.success) {
this.$router.go(0)
} else {
}
});
console.log(this.form)
} }
} }
// //
@ -285,7 +328,7 @@
console.log(id) console.log(id)
deleteAction(this.url.deleteadd,{id,id}).then((res) => { deleteAction(this.url.deleteadd,{id,id}).then((res) => {
if(res.success) { if(res.success) {
this.loadData(1); this.$router.go(0)
} else { } else {
} }
}); });

@ -45,4 +45,10 @@ public interface CustomerReceivingAddressMapper extends BaseMapper<CustomerRecei
@Update("update customer_receiving_address set sort ='0' where id = #{id} ") @Update("update customer_receiving_address set sort ='0' where id = #{id} ")
void updates(String id); void updates(String id);
@Select("SELECT * FROM customer_receiving_address WHERE create_by=#{username} ORDER BY sort DESC LIMIT 1")
CustomerReceivingAddress getcreatbuyuser(String username);
@Select("select * from customer_receiving_address where create_by =#{username} and sort ='0'")
CustomerReceivingAddress getneedyls(String username);
} }

@ -28,4 +28,8 @@ public interface ICustomerReceivingAddressService extends IService<CustomerRecei
void updatec(String id, Integer sort); void updatec(String id, Integer sort);
void updates(String id); void updates(String id);
CustomerReceivingAddress getcreatbuyuser(String username);
CustomerReceivingAddress getneedyls(String username);
} }

@ -78,4 +78,14 @@ public class CustomerReceivingAddressServiceImpl extends ServiceImpl<CustomerRec
public void updates(String id) { public void updates(String id) {
customerReceivingAddressMapper.updates(id); customerReceivingAddressMapper.updates(id);
} }
@Override
public CustomerReceivingAddress getcreatbuyuser(String username) {
return customerReceivingAddressMapper.getcreatbuyuser(username);
}
@Override
public CustomerReceivingAddress getneedyls(String username) {
return customerReceivingAddressMapper.getneedyls(username);
}
} }

@ -208,6 +208,7 @@ public class ApeopersionController {
return null; return null;
} }
//这个功能是个人中心的地址管设置默认地址
@RequestMapping(value = "/sdqx", method = RequestMethod.GET) @RequestMapping(value = "/sdqx", method = RequestMethod.GET)
public Result<?> sdqx(@RequestParam(name="id",required=true) String id) { public Result<?> sdqx(@RequestParam(name="id",required=true) String id) {
//根据id查询需要设置成默认收货地址的收货地址 //根据id查询需要设置成默认收货地址的收货地址
@ -224,9 +225,75 @@ public class ApeopersionController {
customerReceivingAddressService.updatec(cusm.getId(),sort); customerReceivingAddressService.updatec(cusm.getId(),sort);
customerReceivingAddressService.updates(id); customerReceivingAddressService.updates(id);
} }
return Result.OK("成功!");
}
//这个功能是个人中心的地址添加收货地址,不是默认收货地址
@RequestMapping(value = "/addadressress", method = RequestMethod.GET)
public Result<?> addadressress(@RequestParam(name = "form", required = true) String form) {
System.out.println(form);
//这里方便获取当前登陆信息
LoginUser loginUser = (LoginUser) SecurityUtils.getSubject().getPrincipal();
//这里获取当前登陆的用户名
String Username = loginUser.getUsername();
//将前台传过来的json数据包转化成map
Map map = JSON.parseObject(form,Map.class);
//获取flag的数据
String flag = map.get("flag").toString();
//通过flag判断是否是需要的设置成默认地址
if (flag.equals("false")){
//寻找之前的排序的最后一个
CustomerReceivingAddress cus = customerReceivingAddressService.getcreatbuyuser(Username);
CustomerReceivingAddress cus2 =new CustomerReceivingAddress();
cus2.setUserId(loginUser.getId());
cus2.setCityId((String)map.get("addr"));
cus2.setUsernamme((String)map.get("name"));
cus2.setAddress((String)map.get("detailed"));
cus2.setMobile((String)map.get("phone"));
cus2.setSort(cus.getSort()+1);
customerReceivingAddressService.save(cus2);
} else if (flag.equals("true")){
//寻找之前的排序的最后一个
CustomerReceivingAddress cus = customerReceivingAddressService.getcreatbuyuser(Username);
//开始寻找之前的默认地址
CustomerReceivingAddress cusm = customerReceivingAddressService.getneedyls(Username);
//开始组装需要的新的默认地址
CustomerReceivingAddress cus2 =new CustomerReceivingAddress();
cus2.setUserId(loginUser.getId());
cus2.setCityId((String)map.get("addr"));
cus2.setUsernamme((String)map.get("name"));
cus2.setAddress((String)map.get("detailed"));
cus2.setMobile((String)map.get("phone"));
cus2.setSort(0);
//将新的数据写入数据库
customerReceivingAddressService.save(cus2);
//将老的默认收货地址放在排序的最后一个
cusm.setSort(cus.getSort()+1);
customerReceivingAddressService.updateById(cusm);
}
return Result.OK("成功!"); return Result.OK("成功!");
} }
//这个功能是个人中心的地址添加收货地址,不是默认收货地址
@RequestMapping(value = "/updateadressress", method = RequestMethod.GET)
public Result<?> updateadressress(@RequestParam(name = "form", required = true) String form) {
//将前台传过来的json数据包转化成map
Map map = JSON.parseObject(form,Map.class);
//查询需要的对象
CustomerReceivingAddress needc = customerReceivingAddressService.getById((String)map.get("id"));
needc.setMobile((String)map.get("phone"));
needc.setUsernamme((String)map.get("name"));
needc.setAddress((String)map.get("detailed"));
needc.setCityId((String)map.get("addr"));
customerReceivingAddressService.updateById(needc);
return Result.OK("成功!");
}
} }

Loading…
Cancel
Save