Commit d1fffc15 by xuwenhao

2.23修改下单默认就近站点

parent 8a531aa8
...@@ -107,6 +107,13 @@ ...@@ -107,6 +107,13 @@
<version>6.6.14</version> <version>6.6.14</version>
</dependency> </dependency>
<!--微信支付-->
<dependency>
<groupId>com.github.wechatpay-apiv3</groupId>
<artifactId>wechatpay-java</artifactId>
<version>0.2.12</version>
</dependency>
</dependencies> </dependencies>
......
...@@ -210,7 +210,11 @@ public class WaterOrderController extends BaseController ...@@ -210,7 +210,11 @@ public class WaterOrderController extends BaseController
@RepeatSubmit(message = "订单已提交,请勿重复操作!") @RepeatSubmit(message = "订单已提交,请勿重复操作!")
public AjaxResult add(@RequestBody WaterOrderVo waterOrderVo) public AjaxResult add(@RequestBody WaterOrderVo waterOrderVo)
{ {
return toAjax(waterOrderService.insertWaterOrder(waterOrderVo)); int i = waterOrderService.insertWaterOrder(waterOrderVo);
if (i == -1){
return AjaxResult.error("该地址超出配送范围,请重新选择地址!");
}
return toAjax(i);
} }
/** /**
......
...@@ -134,6 +134,12 @@ public class WaterOrder extends BaseEntity ...@@ -134,6 +134,12 @@ public class WaterOrder extends BaseEntity
@Excel(name = "详细地址") @Excel(name = "详细地址")
private String address; private String address;
/** 收货地址经度 */
private double lon;
/** 收货地址纬度 */
private double lat;
/** 收货人手机号 */ /** 收货人手机号 */
@Excel(name = "收货人手机号") @Excel(name = "收货人手机号")
private Long mobile; private Long mobile;
......
...@@ -46,4 +46,10 @@ public class WaterUserAddress ...@@ -46,4 +46,10 @@ public class WaterUserAddress
/** 是否默认地址(1是,0否) */ /** 是否默认地址(1是,0否) */
private String isDefault; private String isDefault;
/** 经度 */
private double lon;
/** 纬度 */
private double lat;
} }
...@@ -6,8 +6,11 @@ import com.qianhe.common.utils.StringUtils; ...@@ -6,8 +6,11 @@ import com.qianhe.common.utils.StringUtils;
import com.qianhe.system.domain.*; import com.qianhe.system.domain.*;
import com.qianhe.system.mapper.*; import com.qianhe.system.mapper.*;
import com.qianhe.system.service.IWaterOrderService; import com.qianhe.system.service.IWaterOrderService;
import com.qianhe.system.utils.PositionUtil;
import com.qianhe.system.vo.WaterOrderVo; import com.qianhe.system.vo.WaterOrderVo;
import com.qianhe.system.vo.WaterStationVo;
import io.swagger.models.auth.In; import io.swagger.models.auth.In;
import org.gavaghan.geodesy.Ellipsoid;
import org.springframework.beans.BeanUtils; import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service; import org.springframework.stereotype.Service;
...@@ -16,6 +19,7 @@ import org.springframework.transaction.annotation.Transactional; ...@@ -16,6 +19,7 @@ import org.springframework.transaction.annotation.Transactional;
import java.math.BigDecimal; import java.math.BigDecimal;
import java.text.SimpleDateFormat; import java.text.SimpleDateFormat;
import java.util.*; import java.util.*;
import java.util.stream.Collectors;
/** /**
* 订单Service业务层处理 * 订单Service业务层处理
...@@ -36,6 +40,10 @@ public class WaterOrderServiceImpl implements IWaterOrderService ...@@ -36,6 +40,10 @@ public class WaterOrderServiceImpl implements IWaterOrderService
private WaterGoodsImgMapper waterGoodsImgMapper; private WaterGoodsImgMapper waterGoodsImgMapper;
@Autowired @Autowired
private WaterGoodsCartMapper waterGoodsCartMapper; private WaterGoodsCartMapper waterGoodsCartMapper;
@Autowired
private WaterUserAddressMapper waterUserAddressMapper;
@Autowired
private WaterStationMapper waterStationMapper;
/** /**
* 查询订单 * 查询订单
...@@ -110,6 +118,20 @@ public class WaterOrderServiceImpl implements IWaterOrderService ...@@ -110,6 +118,20 @@ public class WaterOrderServiceImpl implements IWaterOrderService
if (StringUtils.isNull(waterOrderVo.getUserAddressId())){ if (StringUtils.isNull(waterOrderVo.getUserAddressId())){
throw new ServiceException("未选择地址!"); throw new ServiceException("未选择地址!");
} }
//判断用户地址是否在配送范围之内
List<WaterStationVo> stations = getStation(waterOrderVo);
if (stations.size() <= 0){
return -1;
}
WaterStationVo station = stations.get(0);
waterOrderVo.setStationId(station.getId());
waterOrderVo.setStationName(station.getStationName());
waterOrderVo.setStationPhone(station.getPhoneNum());
waterOrderVo.setStationProvince(station.getProvince());
waterOrderVo.setStationCity(station.getCity());
waterOrderVo.setStationArea(station.getArea());
waterOrderVo.setStationAddress(station.getStationAddress());
waterOrderVo.setCreateUser(waterOrderVo.getUserId().toString()); waterOrderVo.setCreateUser(waterOrderVo.getUserId().toString());
waterOrderVo.setCreateTime(DateUtils.getNowDate()); waterOrderVo.setCreateTime(DateUtils.getNowDate());
waterOrderVo.setOrderNum(getOrerNum()); waterOrderVo.setOrderNum(getOrerNum());
...@@ -132,6 +154,33 @@ public class WaterOrderServiceImpl implements IWaterOrderService ...@@ -132,6 +154,33 @@ public class WaterOrderServiceImpl implements IWaterOrderService
} }
/** /**
* 获取与用户收货地址最近的站点信息
*/
public List<WaterStationVo> getStation(WaterOrderVo waterOrderVo){
//查询用户地址详细信息
WaterUserAddress waterUserAddress = waterUserAddressMapper.selectWaterUserAddressById(waterOrderVo.getUserAddressId());
//查询所有站点信息
List<WaterStation> waterStationList = waterStationMapper.selectWaterStationList(new WaterStation());
//获取距离用户收货地址最近的站点
List<WaterStationVo> waterStationVoList = new ArrayList<>();
for (WaterStation waterStation : waterStationList) {
//计算距离
double distance = PositionUtil.getDistance(waterUserAddress.getLon(), waterUserAddress.getLat(), waterStation.getStationLonTen(), waterStation.getStationLatTen(), Ellipsoid.WGS84);
//换算成千米
double distance1 = distance / 1000;
if (distance1 <= 5){
WaterStationVo waterStationVo = new WaterStationVo();
BeanUtils.copyProperties(waterStation,waterStationVo);
waterStationVo.setDistance(distance1);
waterStationVoList.add(waterStationVo);
}
}
//根据距离升序排序
List<WaterStationVo> collect = waterStationVoList.stream().sorted(Comparator.comparing(WaterStationVo::getDistance)).collect(Collectors.toList());
return collect;
}
/**
* 生成订单编号 * 生成订单编号
* @return * @return
*/ */
......
...@@ -110,6 +110,12 @@ public class WaterOrderVo { ...@@ -110,6 +110,12 @@ public class WaterOrderVo {
/** 详细地址 */ /** 详细地址 */
private String address; private String address;
/** 收货地址经度 */
private double lon;
/** 收货地址纬度 */
private double lat;
/** 收货人手机号 */ /** 收货人手机号 */
private Long mobile; private Long mobile;
......
...@@ -131,16 +131,28 @@ xss: ...@@ -131,16 +131,28 @@ xss:
# 匹配链接 # 匹配链接
urlPatterns: /system/*,/monitor/*,/tool/* urlPatterns: /system/*,/monitor/*,/tool/*
# 订水端小程序 # 订水端小程序(含微信支付)
wx: wx:
#测试 #测试
# appId: wxcabea5c944c4327c # appId: wxcabea5c944c4327c
# appSecret: bd486fd54bd1ea5e9b198911d765ce6a # appSecret: bd486fd54bd1ea5e9b198911d765ce6a
# access-token-uri: https://api.weixin.qq.com/cgi-bin/token?grant_type=client_credential&appid=${wx.appId}&secret=${wx.appSecret} # access-token-uri: https://api.weixin.qq.com/cgi-bin/token?grant_type=client_credential&appid=${wx.appId}&secret=${wx.appSecret}
#正式 #正式
appId: wx75635671bf9fe9bb #微信小程序qppid
appSecret: 5ac4f25af14d7cfb3e62870fa1719459 appId: wx3c0181d9800dfbf2
access-token-uri: https://api.weixin.qq.com/cgi-bin/token?grant_type=client_credential&appid=${wx.appId}&secret=${wx.appSecret} #小程序密钥
appSecret: d1382ba5e014038ee38eda00d737ac43
access-token-uri: https://api.weixin.qq.com/cgi-bin/token?grant_type=client_credential&appid=${sswx.appId}&secret=${sswx.appSecret}
#商户号
mchId: xxx
#证书序列号
mch-serial-no: xxx
#api密钥
api-key: xxx
#回调接口地址
notify-url: xxx
#证书地址
key-path: xxx
# 送水端小程序 # 送水端小程序
sswx: sswx:
...@@ -149,6 +161,6 @@ sswx: ...@@ -149,6 +161,6 @@ sswx:
# appSecret: 27ebe3778435c719cc1b97f260b7e026 # appSecret: 27ebe3778435c719cc1b97f260b7e026
# access-token-uri: https://api.weixin.qq.com/cgi-bin/token?grant_type=client_credential&appid=${sswx.appId}&secret=${sswx.appSecret} # access-token-uri: https://api.weixin.qq.com/cgi-bin/token?grant_type=client_credential&appid=${sswx.appId}&secret=${sswx.appSecret}
#正式 #正式
appId: wx3c0181d9800dfbf2 appId: wx75635671bf9fe9bb
appSecret: d1382ba5e014038ee38eda00d737ac43 appSecret: 5ac4f25af14d7cfb3e62870fa1719459
access-token-uri: https://api.weixin.qq.com/cgi-bin/token?grant_type=client_credential&appid=${sswx.appId}&secret=${sswx.appSecret} access-token-uri: https://api.weixin.qq.com/cgi-bin/token?grant_type=client_credential&appid=${wx.appId}&secret=${wx.appSecret}
...@@ -35,6 +35,8 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" ...@@ -35,6 +35,8 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
<result property="city" column="city" /> <result property="city" column="city" />
<result property="area" column="area" /> <result property="area" column="area" />
<result property="address" column="address" /> <result property="address" column="address" />
<result property="lon" column="lon" />
<result property="lat" column="lat" />
<result property="mobile" column="mobile" /> <result property="mobile" column="mobile" />
<result property="delieverTime" column="deliever_time" /> <result property="delieverTime" column="deliever_time" />
<result property="delieverName" column="deliever_name" /> <result property="delieverName" column="deliever_name" />
...@@ -51,7 +53,7 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" ...@@ -51,7 +53,7 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
</resultMap> </resultMap>
<sql id="selectWaterOrderVo"> <sql id="selectWaterOrderVo">
select id, order_num, user_id, user_name, user_phone, user_province, user_city, user_area, user_address, station_id, station_name, station_phone, station_province, station_city, station_area, station_address, order_goods_type, order_state, complete_state, confirm_state, pay_state, pay_type, pay_num, cancel_result, user_address_id, name, province, city, area, address, mobile, deliever_time, deliever_name, deliever_mobile, create_time, create_user, deliever_over, take_time, finish_time, remark, goods_val, order_type, return_order_result from water_order select id, order_num, user_id, user_name, user_phone, user_province, user_city, user_area, user_address, station_id, station_name, station_phone, station_province, station_city, station_area, station_address, order_goods_type, order_state, complete_state, confirm_state, pay_state, pay_type, pay_num, cancel_result, user_address_id, name, province, city, area, address, lon, lat, mobile, deliever_time, deliever_name, deliever_mobile, create_time, create_user, deliever_over, take_time, finish_time, remark, goods_val, order_type, return_order_result from water_order
</sql> </sql>
<select id="selectWaterOrderList" parameterType="com.qianhe.system.vo.WaterOrderVo" resultMap="WaterOrderResult"> <select id="selectWaterOrderList" parameterType="com.qianhe.system.vo.WaterOrderVo" resultMap="WaterOrderResult">
...@@ -141,7 +143,7 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" ...@@ -141,7 +143,7 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
<if test="payState != null">pay_state,</if> <if test="payState != null">pay_state,</if>
<if test="payType != null">pay_type,</if> <if test="payType != null">pay_type,</if>
<if test="payNum != null">pay_num,</if> <if test="payNum != null">pay_num,</if>
<if test="userAddressId != null">user_address_id,name,province,city,area,address,mobile,</if> <if test="userAddressId != null">user_address_id,name,province,city,area,address,lon,lat,mobile,</if>
<if test="delieverTime != null">deliever_time,</if> <if test="delieverTime != null">deliever_time,</if>
<if test="delieverName != null">deliever_name,</if> <if test="delieverName != null">deliever_name,</if>
<if test="delieverMobile != null">deliever_mobile,</if> <if test="delieverMobile != null">deliever_mobile,</if>
...@@ -187,6 +189,8 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" ...@@ -187,6 +189,8 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
(select city from water_user_address where id = #{userAddressId}), (select city from water_user_address where id = #{userAddressId}),
(select area from water_user_address where id = #{userAddressId}), (select area from water_user_address where id = #{userAddressId}),
(select user_address from water_user_address where id = #{userAddressId}), (select user_address from water_user_address where id = #{userAddressId}),
(select lon from water_user_address where id = #{userAddressId}),
(select lat from water_user_address where id = #{userAddressId}),
(select phone from water_user_address where id = #{userAddressId}), (select phone from water_user_address where id = #{userAddressId}),
</if> </if>
<if test="delieverTime != null">#{delieverTime},</if> <if test="delieverTime != null">#{delieverTime},</if>
...@@ -240,6 +244,8 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" ...@@ -240,6 +244,8 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
city = (select city from water_user_address where id = #{userAddressId}), city = (select city from water_user_address where id = #{userAddressId}),
area = (select area from water_user_address where id = #{userAddressId}), area = (select area from water_user_address where id = #{userAddressId}),
address = (select user_address from water_user_address where id = #{userAddressId}), address = (select user_address from water_user_address where id = #{userAddressId}),
lon = (select lon from water_user_address where id = #{userAddressId}),
lat = (select lat from water_user_address where id = #{userAddressId}),
mobile = (select phone from water_user_address where id = #{userAddressId}), mobile = (select phone from water_user_address where id = #{userAddressId}),
</if> </if>
<if test="delieverTime != null">deliever_time = #{delieverTime},</if> <if test="delieverTime != null">deliever_time = #{delieverTime},</if>
......
...@@ -14,10 +14,12 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" ...@@ -14,10 +14,12 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
<result property="name" column="name" /> <result property="name" column="name" />
<result property="phone" column="phone" /> <result property="phone" column="phone" />
<result property="isDefault" column="is_default" /> <result property="isDefault" column="is_default" />
<result property="lon" column="lon" />
<result property="lat" column="lat" />
</resultMap> </resultMap>
<sql id="selectWaterUserAddressVo"> <sql id="selectWaterUserAddressVo">
select id, water_user_id, user_address, province, city, area, name, phone, is_default from water_user_address select id, water_user_id, user_address, province, city, area, name, phone, is_default, lon, lat from water_user_address
</sql> </sql>
<select id="selectWaterUserAddressList" parameterType="WaterUserAddress" resultMap="WaterUserAddressResult"> <select id="selectWaterUserAddressList" parameterType="WaterUserAddress" resultMap="WaterUserAddressResult">
...@@ -56,6 +58,8 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" ...@@ -56,6 +58,8 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
<if test="name != null">name,</if> <if test="name != null">name,</if>
<if test="phone != null">phone,</if> <if test="phone != null">phone,</if>
<if test="isDefault != null">is_default,</if> <if test="isDefault != null">is_default,</if>
<if test="lon != null">lon,</if>
<if test="lat != null">lat,</if>
</trim> </trim>
<trim prefix="values (" suffix=")" suffixOverrides=","> <trim prefix="values (" suffix=")" suffixOverrides=",">
<if test="waterUserId != null">#{waterUserId},</if> <if test="waterUserId != null">#{waterUserId},</if>
...@@ -66,6 +70,8 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" ...@@ -66,6 +70,8 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
<if test="name != null">#{name},</if> <if test="name != null">#{name},</if>
<if test="phone != null">#{phone},</if> <if test="phone != null">#{phone},</if>
<if test="isDefault != null">#{isDefault},</if> <if test="isDefault != null">#{isDefault},</if>
<if test="lon != null">#{lon},</if>
<if test="lat != null">#{lat},</if>
</trim> </trim>
</insert> </insert>
...@@ -80,6 +86,8 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" ...@@ -80,6 +86,8 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
<if test="name != null">name = #{name},</if> <if test="name != null">name = #{name},</if>
<if test="phone != null">phone = #{phone},</if> <if test="phone != null">phone = #{phone},</if>
<if test="isDefault != null">is_default = #{isDefault},</if> <if test="isDefault != null">is_default = #{isDefault},</if>
<if test="lon != null">lon = #{lon},</if>
<if test="lat != null">lat = #{lat},</if>
</trim> </trim>
where id = #{id} where id = #{id}
</update> </update>
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment