Browse Source

收货地址

PLF 5 năm trước cách đây
mục cha
commit
1fd9cfe2c1

+ 68 - 6
src/main/java/com/caimei/controller/user/PersonalController.java

@@ -1,10 +1,8 @@
 package com.caimei.controller.user;
 
-import com.caimei.entity.Club;
-import com.caimei.entity.CmOperationUser;
-import com.caimei.entity.CmUserBalanceRecord;
-import com.caimei.entity.WxJsonModel;
+import com.caimei.entity.*;
 import com.caimei.service.user.PersonalService;
+import com.github.pagehelper.PageHelper;
 import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.stereotype.Controller;
 import org.springframework.web.bind.annotation.RequestMapping;
@@ -48,13 +46,77 @@ public class PersonalController {
     }
 
     /**
-     * 收货地址管理
+     * 地址管理:省市区
      */
     @ResponseBody
     @RequestMapping("/address")
-    public void address() {
+    public List<Province> address() {
+        List<Province> list = personalService.address();
+        return list;
+    }
 
+    /**
+     * 省
+     */
+    @ResponseBody
+    @RequestMapping("/province")
+    public List<Province> getProvince() {
+        List<Province> provinceList = personalService.getProvince();
+        return provinceList;
+    }
 
+    /**
+     * 市
+     */
+    @ResponseBody
+    @RequestMapping("/city")
+    public List<City> getCity(Long provinceid) {
+        List<City> cityList = personalService.getCity(provinceid);
+        return cityList;
+    }
+
+    /**
+     * 区
+     */
+    @ResponseBody
+    @RequestMapping("/town")
+    public List<Town> getTown(Integer cityid) {
+        List<Town> townList = personalService.getTown(cityid);
+        return townList;
+    }
+
+    /**
+     * 查询用户所有地址
+     *
+     * @param userID
+     * @return
+     */
+    @ResponseBody
+    @RequestMapping("/findAddress")
+    public Page<Address> findAddress(Integer userID, Integer index, Integer pageSize) {
+        if (index == null) index = 1;
+        if (pageSize == null) pageSize = 10;
+        PageHelper.startPage(index, pageSize);
+        List<Address> addressList = personalService.findAddress(userID);
+        Page<Address> page = new Page<>(addressList);
+        return page;
+    }
+
+    /**
+     * 保存或编辑地址
+     *
+     * @return
+     */
+    @ResponseBody
+    @RequestMapping("/save")
+    public WxJsonModel saveAddress(Address address) {
+        WxJsonModel res = WxJsonModel.newInstance();
+        try {
+            personalService.saveAddress(address);
+        } catch (Exception e) {
+            return res.error("保存失败");
+        }
+        return res.success("保存成功", "");
     }
 
 }

+ 114 - 0
src/main/java/com/caimei/entity/Address.java

@@ -0,0 +1,114 @@
+package com.caimei.entity;
+
+import java.io.Serializable;
+
+public class Address implements Serializable {
+    private Integer addressID; //用户地址ID
+    private Integer userID; //用户ID
+    private String shouHuoRen; //收货人
+    private Integer townID; //区ID
+    private String addressDetail; //地址
+    private String postalCode; //邮编
+    private String phone; //电话
+    private String mobile; //手机
+    private String defaultFlag; //是否默认收货地址(0 不是默认,1 默认)
+    private String town;//村镇名
+    private String city;//城市名称
+    private String province;//省份名称
+
+    public Integer getAddressID() {
+        return addressID;
+    }
+
+    public void setAddressID(Integer addressID) {
+        this.addressID = addressID;
+    }
+
+    public Integer getUserID() {
+        return userID;
+    }
+
+    public void setUserID(Integer userID) {
+        this.userID = userID;
+    }
+
+    public String getShouHuoRen() {
+        return shouHuoRen;
+    }
+
+    public void setShouHuoRen(String shouHuoRen) {
+        this.shouHuoRen = shouHuoRen;
+    }
+
+    public Integer getTownID() {
+        return townID;
+    }
+
+    public void setTownID(Integer townID) {
+        this.townID = townID;
+    }
+
+    public String getAddressDetail() {
+        return addressDetail;
+    }
+
+    public void setAddressDetail(String addressDetail) {
+        this.addressDetail = addressDetail;
+    }
+
+    public String getPostalCode() {
+        return postalCode;
+    }
+
+    public void setPostalCode(String postalCode) {
+        this.postalCode = postalCode;
+    }
+
+    public String getPhone() {
+        return phone;
+    }
+
+    public void setPhone(String phone) {
+        this.phone = phone;
+    }
+
+    public String getMobile() {
+        return mobile;
+    }
+
+    public void setMobile(String mobile) {
+        this.mobile = mobile;
+    }
+
+    public String getDefaultFlag() {
+        return defaultFlag;
+    }
+
+    public void setDefaultFlag(String defaultFlag) {
+        this.defaultFlag = defaultFlag;
+    }
+
+    public String getTown() {
+        return town;
+    }
+
+    public void setTown(String town) {
+        this.town = town;
+    }
+
+    public String getCity() {
+        return city;
+    }
+
+    public void setCity(String city) {
+        this.city = city;
+    }
+
+    public String getProvince() {
+        return province;
+    }
+
+    public void setProvince(String province) {
+        this.province = province;
+    }
+}

+ 53 - 0
src/main/java/com/caimei/entity/City.java

@@ -0,0 +1,53 @@
+package com.caimei.entity;
+
+
+import java.io.Serializable;
+import java.util.List;
+
+public class City implements Serializable {
+    private Integer cityid; //市ID
+    private Integer provinceid; //所属省ID
+    private String name;        //市名
+    private String validflag;   //是否有效(0 无效,1 有效)
+    private List<Town> towns;   //下面的区
+
+    public Integer getCityid() {
+        return cityid;
+    }
+
+    public void setCityid(Integer cityid) {
+        this.cityid = cityid;
+    }
+
+    public Integer getProvinceid() {
+        return provinceid;
+    }
+
+    public void setProvinceid(Integer provinceid) {
+        this.provinceid = provinceid;
+    }
+
+    public String getName() {
+        return name;
+    }
+
+    public void setName(String name) {
+        this.name = name;
+    }
+
+    public String getValidflag() {
+        return validflag;
+    }
+
+    public void setValidflag(String validflag) {
+        this.validflag = validflag;
+    }
+
+    public List<Town> getTowns() {
+        return towns;
+    }
+
+    public void setTowns(List<Town> towns) {
+        this.towns = towns;
+    }
+}

+ 139 - 0
src/main/java/com/caimei/entity/Page.java

@@ -0,0 +1,139 @@
+package com.caimei.entity;
+
+import java.io.Serializable;
+import java.util.Collection;
+import java.util.List;
+
+public class Page<T> implements Serializable{
+	private static final long serialVersionUID = 1L;
+	private int index;//当前页码
+	private int pageSize;//每页大小
+	private int totalRecord;//总记录数
+	private int totalPage;//总页数?
+    private boolean hasNextPage;//是否有后一页
+    private boolean hasPreviousPage;//是否有前一页
+	List<T> results;//查询结果
+	
+	public Page(List<T> list){
+		if(list instanceof com.github.pagehelper.Page){
+			com.github.pagehelper.Page<T> page = (com.github.pagehelper.Page<T>)list;
+			this.index = page.getPageNum();
+			this.pageSize = page.getPageSize();
+			this.totalRecord = (int) page.getTotal();
+			this.totalPage = page.getPages();
+			setHasPreviousAndNext();
+			this.results = page;
+		}else if(list instanceof Collection){
+			this.index = 1;
+            this.pageSize = list.size();
+            this.totalRecord = list.size();
+            this.totalPage = 1;
+            this.results = list;
+		}
+	}
+	
+	public Page(int index, int pageSize, int totalRecord, List<T> results) {
+		super();
+		this.index = index;
+		this.pageSize = pageSize;
+		this.totalRecord = totalRecord;
+		this.totalPage = totalRecord % pageSize == 0 ? totalRecord/pageSize : totalRecord/pageSize+1;
+		this.results = results;
+		if(this.index<2){
+			hasPreviousPage=false;
+		}else{
+			hasPreviousPage=true;
+		}
+		if(this.index<totalPage){
+			hasNextPage = true;
+		}else{
+			hasNextPage = false;
+		}
+	}
+	
+	public Page(int index, int maxSize, int totalRecord, int totalPage,
+			List<T> results) {
+		super();
+		this.index = index;
+		this.pageSize = maxSize;
+		this.totalRecord = totalRecord;
+		this.totalPage = totalPage;
+		this.results = results;
+		if(this.index<2){
+			hasPreviousPage=false;
+		}else{
+			hasPreviousPage=true;
+		}
+		if(this.index<totalPage){
+			hasNextPage = true;
+		}else{
+			hasNextPage = false;
+		}
+	}
+	public void setHasPreviousAndNext(){
+		if(this.index<2){
+			hasPreviousPage=false;
+		}else{
+			hasPreviousPage=true;
+		}
+		if(this.index<totalPage){
+			hasNextPage = true;
+		}else{
+			hasNextPage = false;
+		}
+	}
+	
+	public Page() {
+		super();
+	}
+	public int getIndex() {
+		return index;
+	}
+	public void setIndex(int index) {
+		this.index = index;
+	}
+	public int getPageSize() {
+		return pageSize;
+	}
+	public void setPageSize(int maxSize) {
+		this.pageSize = maxSize;
+	}
+	public int getTotalRecord() {
+		return totalRecord;
+	}
+	public void setTotalRecord(int totalRecord) {
+		this.totalRecord = totalRecord;
+	}
+	public int getTotalPage() {
+		return totalPage;
+	}
+	public void setTotalPage(int totalPage) {
+		this.totalPage = totalPage;
+	}
+	public List<T> getResults() {
+		return results;
+	}
+	public void setResults(List<T> results) {
+		this.results = results;
+	}
+	
+	
+	public boolean isHasNextPage() {
+		return hasNextPage;
+	}
+	public void setHasNextPage(boolean hasNextPage) {
+		this.hasNextPage = hasNextPage;
+	}
+	public boolean isHasPreviousPage() {
+		return hasPreviousPage;
+	}
+	public void setHasPreviousPage(boolean hasPreviousPage) {
+		this.hasPreviousPage = hasPreviousPage;
+	}
+	public int countTotalPage(){
+		int total = totalRecord % pageSize == 0 ? totalRecord/pageSize : totalRecord/pageSize+1;
+		this.setTotalPage(total);
+	    return total;
+	}
+	
+}

+ 62 - 0
src/main/java/com/caimei/entity/Province.java

@@ -0,0 +1,62 @@
+package com.caimei.entity;
+
+
+import java.io.Serializable;
+import java.util.List;
+
+public class Province implements Serializable {
+    private Long provinceid;
+    private String name;        //名称
+    private String validflag;   //是否可用,1可用
+    private Float deliveryfee;  //运费
+    private Float freemintotalprice;  //最低包邮金额
+    private List<City> citys;    //下面的市
+
+    public Long getProvinceid() {
+        return provinceid;
+    }
+
+    public void setProvinceid(Long provinceid) {
+        this.provinceid = provinceid;
+    }
+
+    public String getName() {
+        return name;
+    }
+
+    public void setName(String name) {
+        this.name = name;
+    }
+
+    public String getValidflag() {
+        return validflag;
+    }
+
+    public void setValidflag(String validflag) {
+        this.validflag = validflag;
+    }
+
+    public Float getDeliveryfee() {
+        return deliveryfee;
+    }
+
+    public void setDeliveryfee(Float deliveryfee) {
+        this.deliveryfee = deliveryfee;
+    }
+
+    public Float getFreemintotalprice() {
+        return freemintotalprice;
+    }
+
+    public void setFreemintotalprice(Float freemintotalprice) {
+        this.freemintotalprice = freemintotalprice;
+    }
+
+    public List<City> getCitys() {
+        return citys;
+    }
+
+    public void setCitys(List<City> citys) {
+        this.citys = citys;
+    }
+}

+ 58 - 0
src/main/java/com/caimei/entity/Town.java

@@ -0,0 +1,58 @@
+package com.caimei.entity;
+
+public class Town {
+    private Integer townid; //
+    private Integer cityid;  //所在城市Id
+    private String name;  //名称
+    private String zip;     //邮编
+    private String telzip;  //电话区号
+    private String validflag;   //是否可用,1可用
+
+    public Integer getTownid() {
+        return townid;
+    }
+
+    public void setTownid(Integer townid) {
+        this.townid = townid;
+    }
+
+    public Integer getCityid() {
+        return cityid;
+    }
+
+    public void setCityid(Integer cityid) {
+        this.cityid = cityid;
+    }
+
+    public String getName() {
+        return name;
+    }
+
+    public void setName(String name) {
+        this.name = name;
+    }
+
+    public String getZip() {
+        return zip;
+    }
+
+    public void setZip(String zip) {
+        this.zip = zip;
+    }
+
+    public String getTelzip() {
+        return telzip;
+    }
+
+    public void setTelzip(String telzip) {
+        this.telzip = telzip;
+    }
+
+    public String getValidflag() {
+        return validflag;
+    }
+
+    public void setValidflag(String validflag) {
+        this.validflag = validflag;
+    }
+}

+ 15 - 3
src/main/java/com/caimei/mapper/user/PersonalMapper.java

@@ -1,8 +1,6 @@
 package com.caimei.mapper.user;
 
-import com.caimei.entity.Club;
-import com.caimei.entity.CmOperationUser;
-import com.caimei.entity.CmUserBalanceRecord;
+import com.caimei.entity.*;
 import org.apache.ibatis.annotations.Mapper;
 
 import java.util.List;
@@ -13,4 +11,18 @@ public interface PersonalMapper {
     Club myCentre(CmOperationUser operationUser);
 
     List<CmUserBalanceRecord> touchBalance(CmUserBalanceRecord balanceRecord);
+
+    List<Province> findAllProvince();
+
+    List<City> findAllCity(Long provinceid);
+
+    List<Town> findAllTown(Integer cityid);
+
+    List<Address> findAddress(Integer userID);
+
+    Address findCantonal(Integer townID);
+
+    void saveAddress(Address address);
+
+    void updateAddress(Address address);
 }

+ 13 - 3
src/main/java/com/caimei/service/user/PersonalService.java

@@ -1,8 +1,6 @@
 package com.caimei.service.user;
 
-import com.caimei.entity.Club;
-import com.caimei.entity.CmOperationUser;
-import com.caimei.entity.CmUserBalanceRecord;
+import com.caimei.entity.*;
 
 import java.util.List;
 
@@ -10,4 +8,16 @@ public interface PersonalService {
     Club myCentre(CmOperationUser operationUser);
 
     List<CmUserBalanceRecord> touchBalance(int year, int month, CmUserBalanceRecord balanceRecord);
+
+    List<Province> address();
+
+    List<Address> findAddress(Integer userID);
+
+    List<Province> getProvince();
+
+    List<City> getCity(Long provinceid);
+
+    List<Town> getTown(Integer cityid);
+
+    void saveAddress(Address address);
 }

+ 56 - 3
src/main/java/com/caimei/service/user/impl/PersonalServiceImpl.java

@@ -1,8 +1,6 @@
 package com.caimei.service.user.impl;
 
-import com.caimei.entity.Club;
-import com.caimei.entity.CmOperationUser;
-import com.caimei.entity.CmUserBalanceRecord;
+import com.caimei.entity.*;
 import com.caimei.mapper.user.PersonalMapper;
 import com.caimei.service.user.PersonalService;
 import org.springframework.beans.factory.annotation.Autowired;
@@ -37,4 +35,59 @@ public class PersonalServiceImpl implements PersonalService {
         List<CmUserBalanceRecord> list = personalMapper.touchBalance(balanceRecord);
         return list;
     }
+
+    @Override
+    public List<Province> address() {
+        List<Province> list = personalMapper.findAllProvince();
+        for (Province province : list) {
+            List<City> cityList = personalMapper.findAllCity(province.getProvinceid());
+            province.setCitys(cityList);
+            if (cityList != null && cityList.size() > 0) {
+                for (City city : cityList) {
+                    List<Town> townList = personalMapper.findAllTown(city.getCityid());
+                    city.setTowns(townList);
+                }
+            }
+        }
+        return list;
+    }
+
+    @Override
+    public List<Address> findAddress(Integer userID) {
+        List<Address> addressList = personalMapper.findAddress(userID);
+        for (Address address : addressList) {
+            Address cantonal = personalMapper.findCantonal(address.getTownID());
+            address.setProvince(cantonal.getProvince());
+            address.setCity(cantonal.getCity());
+            address.setTown(cantonal.getTown());
+        }
+        return addressList;
+    }
+
+    @Override
+    public List<Province> getProvince() {
+        List<Province> list = personalMapper.findAllProvince();
+        return list;
+    }
+
+    @Override
+    public List<City> getCity(Long provinceid) {
+        return personalMapper.findAllCity(provinceid);
+    }
+
+    @Override
+    public List<Town> getTown(Integer cityid) {
+        return personalMapper.findAllTown(cityid);
+    }
+
+    @Override
+    public void saveAddress(Address address) {
+        if (address.getAddressID() == null) {
+            personalMapper.saveAddress(address);
+        } else {
+            personalMapper.updateAddress(address);
+        }
+    }
+
+
 }

+ 2 - 2
src/main/resources/dev/application-dev.yml

@@ -41,5 +41,5 @@ logging:
   level: debug
 
 miniprogram:
-  AppId: wxffa5730591e05c04
-  AppSecret: 9c88bcbd2797877c7e3322b1eaa88966
+  AppId: wxd3cadbba8bf55f47
+  AppSecret: 811a6ab8105e0bdf24cd78f6e6f009a7

+ 72 - 0
src/main/resources/mapper/PersonalMapper.xml

@@ -42,4 +42,76 @@
         ORDER BY cubr.addDate DESC
     </select>
 
+    <select id="findAllProvince" resultType="com.caimei.entity.Province">
+        SELECT * FROM province WHERE validFlag = '1'
+    </select>
+
+    <select id="findAllCity" resultType="com.caimei.entity.City">
+        SELECT * FROM city WHERE provinceID = #{provinceID} AND validFlag = '1'
+    </select>
+
+    <select id="findAllTown" resultType="com.caimei.entity.Town">
+        SELECT * FROM town WHERE cityID = #{cityID} AND validFlag = '1'
+    </select>
+
+    <select id="findAddress" resultType="com.caimei.entity.Address">
+        SELECT
+          addressID,
+          userID,
+          shouHuoRen,
+          townID,
+          address AS addressDetail,
+          postalCode,
+          phone,
+          mobile,
+          defaultFlag
+        FROM
+          address
+        WHERE
+          userID = #{userID}
+        ORDER BY
+          defaultFlag DESC,
+          addressID DESC
+    </select>
+
+    <select id="findCantonal" resultType="com.caimei.entity.Address">
+        SELECT
+          p.name AS province,
+          c.name AS city,
+          t.name AS town
+        FROM
+          town t
+          LEFT JOIN city c ON t.cityID = c.cityID
+          LEFT JOIN province p ON p.provinceID = c.provinceID
+        WHERE
+          t.townID = #{townID}
+          AND t.validFlag = '1'
+          AND c.validFlag = '1'
+          AND p.validFlag = '1'
+    </select>
+
+    <insert id="saveAddress" parameterType="com.caimei.entity.Address">
+        INSERT INTO address (
+          userID, shouHuoRen, townID, address,
+          mobile, defaultFlag
+        )
+        VALUES
+          (
+            #{userID},#{shouHuoRen},#{townID},
+            #{addressDetail},#{mobile},#{defaultFlag}
+          )
+    </insert>
+
+    <update id="updateAddress" parameterType="com.caimei.entity.Address">
+        UPDATE
+          address
+        SET
+          shouHuoRen =#{shouHuoRen},
+          townID = #{townID},
+          address = #{addressDetail},
+          mobile = #{mobile},
+          defaultFlag = #{defaultFlag}
+        WHERE
+          addressID = #{addressID}
+    </update>
 </mapper>

+ 3 - 2
src/main/resources/prod/application-prod.yml

@@ -42,5 +42,6 @@ logging:
   file: /mnt/newdatadrive/data/runtime/tomcat-instance/caimei-brand-alliance/catalina.out
   level: debug
 
-miniprogramAppId:
-miniprogramAppSecret:
+miniprogram:
+  AppId: wxd3cadbba8bf55f47
+  AppSecret: 811a6ab8105e0bdf24cd78f6e6f009a7

+ 3 - 2
src/main/resources/test/application-test.yml

@@ -41,5 +41,6 @@ logging:
   file: /mnt/newdatadrive/data/runtime/tomcat-instance/caimei-brand-alliance/catalina.out
   level: debug
 
-miniprogramAppId:
-miniprogramAppSecret:
+miniprogram:
+  AppId: wxd3cadbba8bf55f47
+  AppSecret: 811a6ab8105e0bdf24cd78f6e6f009a7