| | |
| | | |
| | | import javax.servlet.http.HttpServletRequest; |
| | | import javax.servlet.http.HttpServletResponse; |
| | | import java.util.HashMap; |
| | | import java.util.Map; |
| | | |
| | | /** |
| | |
| | | @Override |
| | | @Transactional(rollbackFor = Exception.class) |
| | | public void alipayCallback(HttpServletRequest request, HttpServletResponse response) { |
| | | Map<String, String> map = new HashMap<>(); |
| | | try { |
| | | String resString = XmlUtils.parseRequest(request); |
| | | String respString = "error"; |
| | | if (!resString.isEmpty()) { |
| | | Map<String, String> map = XmlUtils.toMap(resString.getBytes(), "utf-8"); |
| | | map = XmlUtils.toMap(resString.getBytes(), "utf-8"); |
| | | String sign_type = map.get("sign_type"); |
| | | String reSign = map.get("sign"); |
| | | if (map.containsKey("sign")) { |
| | | OrderResponse order = orderService.getByOrderNum(map.get("out_trade_no")); |
| | | PayTypeEnum status = PayTypeEnum.find(order.getOrder().getPayType()); |
| | | if (SignUtil.verifySign(reSign, sign_type, map, properties, status)) { |
| | | log.error("验证签名错误!:{}", map.toString()); |
| | | log.error("汇旺财支付验证签名错误!:{}", map.toString()); |
| | | } else { |
| | | if ("0".equals(map.get("status"))) { |
| | | if ("0".equals(map.get("result_code"))) { |
| | |
| | | } |
| | | response.getWriter().write(respString); |
| | | } catch (Exception e) { |
| | | log.error("汇旺财支付回调失败:{}", map.toString()); |
| | | throw new BadRequestException("操作失败,原因:" + e.getMessage()); |
| | | } |
| | | } |
| | |
| | | @Override |
| | | @Transactional(rollbackFor = Exception.class) |
| | | public void returnNotify(HttpServletRequest request, HttpServletResponse response) { |
| | | Map<String, String> map = new HashMap<>(); |
| | | try { |
| | | String resString = XmlUtils.parseRequest(request); |
| | | String respString = "error"; |
| | | if (!resString.isEmpty()) { |
| | | Map<String, String> map = XmlUtils.toMap(resString.getBytes(), "utf-8"); |
| | | map = XmlUtils.toMap(resString.getBytes(), "utf-8"); |
| | | String sign_type = map.get("sign_type"); |
| | | String reSign = map.get("sign"); |
| | | if (map.containsKey("sign")) { |
| | | OrderReturn order = returnService.getByReturnNum(map.get("out_refund_no")); |
| | | PayTypeEnum status = PayTypeEnum.find(order.getPayType()); |
| | | if (SignUtil.verifySign(reSign, sign_type, map, properties, status)) { |
| | | log.error("验证签名错误!:{}", map.toString()); |
| | | log.error("汇旺财退款验证签名错误!:{}", map.toString()); |
| | | } else { |
| | | if ("0".equals(map.get("status"))) { |
| | | if ("0".equals(map.get("result_code"))) { |
| | |
| | | } |
| | | response.getWriter().write(respString); |
| | | } catch (Exception e) { |
| | | log.error("汇旺财退款回调失败:{}", map.toString()); |
| | | System.out.println("操作失败,原因:" + e.getMessage()); |
| | | } |
| | | } |
| | |
| | | @ApiModelProperty(value = "类型") |
| | | private String type; |
| | | |
| | | @ApiModelProperty(value = "审核状态") |
| | | private Integer status; |
| | | |
| | | @ApiModelProperty(value = "页码", example = "1") |
| | | private Integer page = 1; |
| | | |
| | | @ApiModelProperty(value = "每页数据量", example = "10") |
| | | private Integer size = 10; |
| | | |
| | | } |
| | |
| | | @ApiModelProperty(value = "类型") |
| | | private String type; |
| | | |
| | | @ApiModelProperty(value = "审核状态") |
| | | private Integer status; |
| | | |
| | | @ApiModelProperty(value = "页码", example = "1") |
| | | private Integer page = 1; |
| | | |
| | | @ApiModelProperty(value = "每页数据量", example = "10") |
| | | private Integer size = 10; |
| | | |
| | | } |
| | |
| | | @ApiModelProperty(value = "配送费详情Id") |
| | | private String deliveryFeeId; |
| | | |
| | | @ApiModelProperty(value = "预计送达时间") |
| | | private String orderTime; |
| | | |
| | | public void copy(RiderOrderRecord source){ |
| | | BeanUtil.copyProperties(source,this, CopyOptions.create().setIgnoreNullValue(true)); |
| | | } |
| | |
| | | import lombok.Setter; |
| | | |
| | | import java.io.Serializable; |
| | | import java.util.List; |
| | | |
| | | /** |
| | | * @description / |
| | |
| | | |
| | | private String message; |
| | | |
| | | private RiderSourceInfo data; |
| | | private List<RiderSourceInfo> data; |
| | | |
| | | } |
| | |
| | | IPage<RiderOrderRecord> findAll(@Param("criteria") RiderOrderRecordQueryCriteria criteria, Page<Object> page); |
| | | |
| | | List<RiderOrderRecord> findAll(@Param("criteria") RiderOrderRecordQueryCriteria criteria); |
| | | |
| | | RiderOrderRecord selectRiderInfo(@Param("orderNum") String orderNum); |
| | | } |
| | |
| | | return ResponseEntity.ok(R.success(result)); |
| | | } |
| | | |
| | | @GetMapping("riderOperationOrder") |
| | | @PostMapping("riderOperationOrder") |
| | | @ApiOperation("骑手上报到店/取货配送") |
| | | // @PreAuthorize("@el.check('riderOrderRecord:list')") |
| | | public ResponseEntity<?> riderOperationOrder(OrderRiderOperationVo orderRiderOperation) { |
| | | public ResponseEntity<?> riderOperationOrder(@RequestBody OrderRiderOperationVo orderRiderOperation) { |
| | | // 订单号不能为空 |
| | | if (orderRiderOperation.getOrderNum() == null || orderRiderOperation.getOrderNum().equals("")) { |
| | | return ResponseEntity.ok(R.fail(Constants.HTTP_CODE_FAIL, "订单号不能为空")); |
| | |
| | | |
| | | import com.oying.modules.rider.domain.RiderOrderRecord; |
| | | import com.oying.modules.rider.domain.dto.RiderOrderRecordQueryCriteria; |
| | | |
| | | import java.text.ParseException; |
| | | import java.util.List; |
| | | import java.io.IOException; |
| | | import javax.servlet.http.HttpServletResponse; |
| | |
| | | */ |
| | | void download(List<RiderOrderRecord> all, HttpServletResponse response) throws IOException; |
| | | |
| | | |
| | | /** |
| | | * 骑手接单 |
| | | * @param orderNum |
| | |
| | | */ |
| | | R riderOperationOrder(OrderRiderOperationVo orderRiderOperation); |
| | | |
| | | /** |
| | | * 骑手完成订单状态 |
| | | * @param orderNum |
| | | * @throws IOException / |
| | | */ |
| | | R riderCompleteOrder(String orderNum); |
| | | |
| | | /** |
| | | * 骑手完成订单修改接口 |
| | | * @param orderNum |
| | | * @param |
| | | * @throws IOException / |
| | | */ |
| | | void updateRiderOrderInfo(String orderNum) ; |
| | | } |
| | |
| | | @Transactional(rollbackFor = Exception.class) |
| | | public void syncRiderSourceInfo(String sourcePlatform) { |
| | | Long riderId = SecurityUtils.getCurrentUserId(); |
| | | // 添加请求参数 |
| | | List<String> phoneList = new ArrayList<>(); |
| | | phoneList.add(SecurityUtils.getCurrentUsername()); |
| | | // 查询其他平台的数据 |
| | | RiderSourceInfoHttp riderSourceInfoHttp = RiderSourceHttpUtils.getRiderSourceInfoHttp(SecurityUtils.getCurrentUsername(), sourcePlatform); |
| | | RiderSourceInfoHttp riderSourceInfoHttp = RiderSourceHttpUtils.getRiderSourceInfoHttp(phoneList, sourcePlatform); |
| | | // 请求成功 |
| | | if (riderSourceInfoHttp.getCode().equals(Constants.HTTP_CODE_SUCCESS)) { |
| | | // 检查是否存在该平台的骑手信息 |
| | | QueryWrapper<RiderInfo> riderInfoQueryWrapper = new QueryWrapper<>(); |
| | | riderInfoQueryWrapper.eq(RiderInfo.COL_RIDER_ID, riderId); |
| | | RiderInfo riderInfo = riderInfoMapper.selectOne(riderInfoQueryWrapper); |
| | | // 获取骑手信息等于空 |
| | | if (null != riderSourceInfoHttp.getData()) { |
| | | RiderSourceInfo infoHttpData = riderSourceInfoHttp.getData(); |
| | | // 检查是否存在该平台的骑手信息 |
| | | QueryWrapper<RiderInfo> riderInfoQueryWrapper = new QueryWrapper<>(); |
| | | riderInfoQueryWrapper.eq(RiderInfo.COL_RIDER_ID, riderId); |
| | | RiderInfo riderInfo = riderInfoMapper.selectOne(riderInfoQueryWrapper); |
| | | if (!riderSourceInfoHttp.getData().isEmpty()) { |
| | | // 单个骑手信息同步只取第一条数据 |
| | | RiderSourceInfo infoHttpData = riderSourceInfoHttp.getData().get(0); |
| | | // 如果存在该平台的骑手信息 |
| | | if (null == riderInfo) { |
| | | // 如果不存在,则创建新的骑手三方信息 |
| | |
| | | import cn.hutool.core.lang.UUID; |
| | | import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper; |
| | | import com.oying.exception.BadRequestException; |
| | | import com.oying.modules.pc.store.domain.Store; |
| | | import com.oying.modules.pc.store.service.StoreService; |
| | | import com.oying.modules.rider.domain.RiderIncomeDetail; |
| | | import com.oying.modules.rider.domain.RiderInfo; |
| | |
| | | import org.springframework.transaction.annotation.Transactional; |
| | | |
| | | import java.sql.Timestamp; |
| | | import java.time.LocalDateTime; |
| | | import java.time.format.DateTimeFormatter; |
| | | import java.util.List; |
| | | import java.util.Map; |
| | | import java.io.IOException; |
| | |
| | | |
| | | @Override |
| | | @Transactional(rollbackFor = Exception.class) |
| | | public void updateRiderOrderInfo(String orderNum) { |
| | | // 查询骑手订单信息 |
| | | RiderOrderRecord riderOrderRecord = riderOrderRecordMapper.selectRiderInfo(orderNum); |
| | | // 当前为接单 设置为待取货状态 1-待取货 2-配送中 3-已完成 4-商家取消 5-骑手取消 6-客户取消 7-系统取消 |
| | | RiderOrderRecord riderOrderRecordUpdate = new RiderOrderRecord(); |
| | | riderOrderRecordUpdate.setRecordId(riderOrderRecord.getRecordId()); |
| | | riderOrderRecordUpdate.setOrderNum(orderNum); |
| | | riderOrderRecordUpdate.setOrderStatus(Constants.ORDER_STATUS_FINISH); |
| | | // 判断是否超时 当前时间和预计送达时间做比较// 获取当前时间 |
| | | Timestamp now = new Timestamp(System.currentTimeMillis()); |
| | | // 获取订单的预计送达时间(假设 orderResponse.getOrder().getOrderTime() 返回的是 Timestamp 类型) |
| | | DateTimeFormatter formatter = DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss"); |
| | | LocalDateTime orderLocalTime = LocalDateTime.parse(riderOrderRecord.getOrderTime(), formatter); |
| | | Timestamp orderTime = Timestamp.valueOf(orderLocalTime); |
| | | // 判断是否超时 |
| | | String isOvertime = Constants.IS_OVERTIME_YES; |
| | | if (now.after(orderTime)) { |
| | | isOvertime = Constants.IS_OVERTIME_YES; |
| | | } |
| | | // 设置到订单记录中 |
| | | riderOrderRecordUpdate.setIsOvertime(isOvertime); |
| | | // 完成时间 |
| | | Timestamp finishTime = new Timestamp(System.currentTimeMillis()); |
| | | riderOrderRecordUpdate.setFinishTime(finishTime); |
| | | // 接单时间-完成时间 计算出相隔秒数 |
| | | Timestamp acceptTime = riderOrderRecord.getAcceptTime(); |
| | | // 计算两个时间之间的秒数差 |
| | | long durationInSeconds = (finishTime.getTime() - acceptTime.getTime()) / 1000; |
| | | riderOrderRecordUpdate.setDeliveryDuration(durationInSeconds); |
| | | // 更新订单状态 |
| | | riderOrderRecordMapper.updateById(riderOrderRecordUpdate); |
| | | } |
| | | |
| | | @Override |
| | | @Transactional(rollbackFor = Exception.class) |
| | | public R riderGrabOrder(String orderNum) { |
| | | Long riderId = SecurityUtils.getCurrentUserId(); |
| | | // 查询骑手信息 |
| | |
| | | } |
| | | // 查询当前订单 检查订单是否已经被其他骑手抢到或取消 直接返回 |
| | | OrderResponse orderResponse = orderService.getByOrderNum(orderNum); |
| | | if (orderResponse == null || orderResponse.getOrder() == null) { |
| | | return R.fail(400, "订单信息不存在,请稍后重试"); |
| | | } |
| | | int orderStatus = orderResponse.getOrder().getOrderStatus(); |
| | | // 2商家已接单 4商家已备货 这两个状态可以接单 |
| | | if (orderResponse == null || orderResponse.getOrder().getOrderStatus() != 2 || orderResponse.getOrder().getOrderStatus() != 4) { |
| | | return R.fail(400, "订单已经被其他骑手接单或顾客取消,请稍后重试"); |
| | | if (orderStatus != 2 && orderStatus != 4) { |
| | | return R.fail(400, "订单已经被其他骑手接单或取消,请稍后重试"); |
| | | } |
| | | // 商家备货状态 查看是否存在骑手信息 |
| | | if (orderStatus == 4 && orderResponse.getOrder().getRiderId() != null) { |
| | | return R.fail(400, "订单已经被其他骑手接单,请稍后重试"); |
| | | } |
| | | // 订单没有被接单或取消的情况下,进行接单操作 |
| | | // 1.新增骑手接单记录 |
| | |
| | | riderOrderRecord.setMerchantId(orderResponse.getOrder().getStoreId()); |
| | | riderOrderRecord.setMerchantName(orderResponse.getOrder().getStoreName()); |
| | | riderOrderRecord.setMerchantAddress(orderResponse.getOrder().getStoreAddress()); |
| | | riderOrderRecord.setReceiverAddress(orderResponse.getAddress().getDetail()); |
| | | // 收货地址 拼接地址 |
| | | String receiverAddress = orderResponse.getAddress().getCity() |
| | | + orderResponse.getAddress().getDistrict() |
| | | + orderResponse.getAddress().getStreet() |
| | | + orderResponse.getAddress().getShortAddress() |
| | | + orderResponse.getAddress().getDetail(); |
| | | riderOrderRecord.setReceiverAddress(receiverAddress); |
| | | // 当前为接单 设置为待取货状态 0-已接单 1-已到店 2-配送中 3-已完成 4-商家取消 5-骑手取消 6-客户取消 7-系统取消 |
| | | riderOrderRecord.setOrderStatus(Constants.ORDER_STATUS_OK); |
| | | riderOrderRecord.setAcceptTime(new Timestamp(System.currentTimeMillis())); |
| | |
| | | // 配送费详情Id |
| | | // riderOrderRecord.setDeliveryFeeId(orderResponse.getOrder().getDeliveryFeeId()); |
| | | riderOrderRecord.setOrderIncome(orderResponse.getOrder().getSendPrice()); |
| | | riderOrderRecord.setOrderTime(orderResponse.getOrder().getOrderTime()); |
| | | create(riderOrderRecord); |
| | | } |
| | | |
| | |
| | | Order order = orderResponse.getOrder(); |
| | | // 添加订单操作记录 订单完成 |
| | | orderService.operationLog(orderResponse, OrderStatusEnum.SEVEN, orderResponse.getOrder().getRiderName()); |
| | | // 修改骑手端的订单状态 |
| | | updateRiderOrderStatus(orderNum, Constants.ORDER_STATUS_FINISH); |
| | | // 修改骑手端的订单状态 // 修改完成时间 |
| | | updateRiderOrderInfo(orderNum); |
| | | // 返回参数 |
| | | orderResponse.getOrder().setOrderStatus(OrderStatusEnum.SEVEN.getKey()); |
| | | // 查询骑手钱包信息 |
| | |
| | | riderIncomeDetail.setDeliveryTime(new Timestamp(System.currentTimeMillis())); |
| | | riderIncomeDetail.setOrderStatus(Constants.ORDER_STATUS_FINISH); |
| | | riderIncomeDetail.setStartAddress(orderResponse.getOrder().getStoreAddress()); |
| | | riderIncomeDetail.setEndAddress(orderResponse.getAddress().getDetail()); |
| | | // 收货地址 拼接地址 |
| | | String receiverAddress = orderResponse.getAddress().getCity() |
| | | + orderResponse.getAddress().getDistrict() |
| | | + orderResponse.getAddress().getStreet() |
| | | + orderResponse.getAddress().getShortAddress() |
| | | + orderResponse.getAddress().getDetail(); |
| | | riderIncomeDetail.setEndAddress(receiverAddress); |
| | | riderIncomeDetailService.save(riderIncomeDetail); |
| | | return R.success(orderResponse); |
| | | } |
| | |
| | | * 超时状态 1-是 0-否 |
| | | */ |
| | | String IS_OVERTIME_NO = "0"; |
| | | String IS_OVERTIME = "1"; |
| | | String IS_OVERTIME_YES = "1"; |
| | | |
| | | /** |
| | | * 订单来源: 1-平台派单 2-骑手抢单 3-商家直派 4-其他 |
| | |
| | | import org.slf4j.LoggerFactory; |
| | | |
| | | import java.util.HashMap; |
| | | import java.util.List; |
| | | import java.util.Map; |
| | | |
| | | |
| | | /** |
| | |
| | | * @return: riderSourceInfoHttp |
| | | * @author: pxb |
| | | */ |
| | | public static RiderSourceInfoHttp getRiderSourceInfoHttp(String phone, String sourcePlatform) { |
| | | HashMap<String, Object> paramMap = new HashMap<>(2); |
| | | paramMap.put("phone", phone); |
| | | paramMap.put("sourcePlatform", sourcePlatform); |
| | | public static RiderSourceInfoHttp getRiderSourceInfoHttp(List<String> phones, String sourcePlatform) { |
| | | HashMap<String, Object> param = new HashMap<>(2); |
| | | param.put("phones", phones); |
| | | param.put("sourcePlatform", sourcePlatform); |
| | | // String url = ""; |
| | | // 转化成对象 |
| | | RiderSourceInfoHttp riderSourceInfoHttp = new RiderSourceInfoHttp(); |
| | | // try { |
| | | // String result = httpPostRequest(paramMap, url); |
| | | // String result = httpPostRequest(param, url); |
| | | // // 转换数据 |
| | | // riderSourceInfoHttp = riderConvertUtils(result); |
| | | // } catch (Exception e) { |
| | |
| | | riderSourceInfo.setPhone("18706999997"); |
| | | riderSourceInfo.setCardName("张三"); |
| | | riderSourceInfo.setEnabled(Constants.SOURCE_ENABLED_ON); |
| | | riderSourceInfoHttp.setData(riderSourceInfo); |
| | | riderSourceInfoHttp.getData().add(riderSourceInfo); |
| | | return riderSourceInfoHttp; |
| | | } |
| | | |
| | |
| | | package com.oying.modules.sh.domain; |
| | | |
| | | import com.baomidou.mybatisplus.annotation.TableField; |
| | | import com.oying.base.BaseEntity; |
| | | import cn.hutool.core.bean.BeanUtil; |
| | | import io.swagger.annotations.ApiModelProperty; |
| | |
| | | @ApiModelProperty(value = "标签(家、公司等)") |
| | | private String tag; |
| | | |
| | | @TableField(exist = false) |
| | | @ApiModelProperty(value = "距离") |
| | | private BigDecimal distance; |
| | | |
| | | public void copy(UserAddress source){ |
| | | BeanUtil.copyProperties(source,this, CopyOptions.create().setIgnoreNullValue(true)); |
| | | } |
| | |
| | | package com.oying.modules.sh.domain.dto; |
| | | |
| | | import lombok.Data; |
| | | |
| | | import java.sql.Timestamp; |
| | | import java.util.List; |
| | | import io.swagger.annotations.ApiModelProperty; |
| | |
| | | @ApiModelProperty(value = "用户id") |
| | | private Long userId; |
| | | |
| | | @ApiModelProperty(value = "经度") |
| | | private double longitude; |
| | | |
| | | @ApiModelProperty(value = "纬度") |
| | | private double latitude; |
| | | |
| | | @ApiModelProperty(value = "半径(米)") |
| | | private Integer radius; |
| | | |
| | | @ApiModelProperty(value = "标签(家、公司等)") |
| | | private String tag; |
| | | |
| | |
| | | package com.oying.modules.sh.domain.vo; |
| | | |
| | | import com.oying.modules.pc.store.domain.Store; |
| | | import com.oying.modules.sh.domain.UserAddress; |
| | | import io.swagger.annotations.ApiModelProperty; |
| | | import lombok.Getter; |
| | |
| | | @Setter |
| | | public class OrderInfo { |
| | | |
| | | @ApiModelProperty(value = "门店信息") |
| | | private Store store; |
| | | @ApiModelProperty(value = "商品信息列") |
| | | private List<ProductInfo> products; |
| | | @ApiModelProperty(value = "用户地址信息") |
| | |
| | | List<UserAddress> findAll(@Param("criteria") UserAddressQueryCriteria criteria); |
| | | |
| | | void isDefault(Long userId); |
| | | |
| | | UserAddress getById(Long addressId, Long userId, Double longitude, Double latitude); |
| | | } |
| | |
| | | return new ResponseEntity<>(R.success(), HttpStatus.OK); |
| | | } |
| | | |
| | | @Log("关闭订单") |
| | | @ApiOperation("关闭订单") |
| | | @PostMapping(value = "/closeOrder") |
| | | public ResponseEntity<Object> closeOrder(@RequestParam String orderNum) { |
| | | orderService.closeOrder(orderNum); |
| | | @Log("用户取消订单") |
| | | @ApiOperation("用户取消订单") |
| | | @PostMapping(value = "/cancel") |
| | | public ResponseEntity<Object> cancel(@RequestParam String orderNum) { |
| | | orderService.cancel(orderNum); |
| | | return new ResponseEntity<>(R.success(), HttpStatus.OK); |
| | | } |
| | | |
| | |
| | | */ |
| | | void download(List<Order> all, HttpServletResponse response) throws IOException; |
| | | |
| | | void closeOrder(String orderNum); |
| | | void cancel(String orderNum); |
| | | |
| | | void statusOrder(StatusOrder statusOrder); |
| | | } |
| | |
| | | |
| | | import com.oying.modules.sh.domain.UserAddress; |
| | | import com.oying.modules.sh.domain.dto.UserAddressQueryCriteria; |
| | | |
| | | import java.util.List; |
| | | import java.io.IOException; |
| | | import javax.servlet.http.HttpServletResponse; |
| | | |
| | | import com.baomidou.mybatisplus.extension.plugins.pagination.Page; |
| | | import com.baomidou.mybatisplus.extension.service.IService; |
| | | import com.oying.utils.PageResult; |
| | |
| | | */ |
| | | void download(List<UserAddress> all, HttpServletResponse response) throws IOException; |
| | | |
| | | List<UserAddress> queryUserAddress(); |
| | | List<UserAddress> queryUserAddress(double longitude, double latitude); |
| | | |
| | | UserAddress getById(Long addressId, Double longitude, Double latitude); |
| | | } |
| | |
| | | @Transactional(rollbackFor = Exception.class) |
| | | public void create(OrderResponse response, OrderStatusEnum statusEnum, String cardName) { |
| | | String userType = ConstantsKey.BUYER; |
| | | String username = null; |
| | | switch (statusEnum) { |
| | | case ZERO: |
| | | case ONE: |
| | |
| | | userType = ConstantsKey.BUYER; |
| | | break; |
| | | case TWO: |
| | | username = response.getOrder().getUsername(); |
| | | case FOUR: |
| | | userType = ConstantsKey.MERCHANT; |
| | | break; |
| | |
| | | break; |
| | | default: |
| | | } |
| | | String username = SecurityUtils.getCurrentUsername(); |
| | | if (username == null) { |
| | | username = SecurityUtils.getCurrentUsername(); |
| | | } |
| | | Timestamp time = new Timestamp(System.currentTimeMillis()); |
| | | OrderOperationLog resources = new OrderOperationLog(); |
| | | resources.setOrderNum(response.getOrder().getOrderNum()); |
| | |
| | | import com.oying.modules.pc.product.domain.enums.ProductStatusEnum; |
| | | import com.oying.modules.pc.product.service.ProductService; |
| | | import com.oying.modules.pc.store.domain.Store; |
| | | import com.oying.modules.pc.store.domain.enums.StoreStatusEnum; |
| | | import com.oying.modules.pc.store.service.StoreService; |
| | | import com.oying.modules.sh.domain.*; |
| | | import com.oying.modules.sh.domain.request.GeneratorOrder; |
| | |
| | | default: |
| | | throw new BadRequestException("支付类型暂未开放"); |
| | | } |
| | | String orderNum = redisUtils.generateOrderSn(GenerateEnum.ORDER.getKey()); |
| | | // 总金额 |
| | | BigDecimal amount = BigDecimal.ZERO; |
| | | GeneratorOrder generator = new GeneratorOrder(); |
| | | generator.setProducts(submit.getProducts()); |
| | | generator.setStoreId(submit.getStoreId()); |
| | | OrderInfo info = generatorOrder(generator); |
| | | Store store = info.getStore(); |
| | | UserAddress address = userAddressService.getById(submit.getAddressId(), store.getLongitude(), store.getLatitude()); |
| | | if (address == null) { |
| | | throw new BadRequestException("没找到用户地址"); |
| | | } |
| | | if (!(address.getDistance().compareTo(BigDecimal.valueOf(store.getRadius())) <= 0)) { |
| | | throw new BadRequestException("超出配送范围"); |
| | | } |
| | | String orderNum = redisUtils.generateOrderSn(GenerateEnum.ORDER.getKey()); |
| | | // 总金额 |
| | | BigDecimal amount = BigDecimal.ZERO; |
| | | // 商品快照 |
| | | List<OrderProductSnapshot> snapshots = new ArrayList<>(); |
| | | for (ProductInfo productInfo : info.getProducts()) { |
| | |
| | | String openid = SecurityUtils.getCurrentOpenid(); |
| | | if (openid == null || openid.isEmpty()) { |
| | | throw new BadRequestException("OPENID错误"); |
| | | } |
| | | |
| | | // 门店信息 |
| | | Store store = storeService.getById(submit.getStoreId()); |
| | | if (amount.compareTo(store.getDeliveryMinimum()) >= 0) { |
| | | throw new BadRequestException("起送金额:" + store.getDeliveryMinimum()); |
| | | } |
| | | // 订单信息 |
| | | Order order = new Order(); |
| | |
| | | order.setPayMessage(PayStateEnum.SUCCESS.getValue()); |
| | | order.setPayTime(DateUtil.localDateTimeFormat(now.toLocalDateTime(), DateUtil.SDF_YMDHMS)); |
| | | } |
| | | UserAddress address = userAddressService.getById(submit.getAddressId()); |
| | | |
| | | OrderAddressSnapshot addressSnapshot = getOrderAddressSnapshot(orderNum, address); |
| | | |
| | | |
| | |
| | | @Override |
| | | @Transactional(rollbackFor = Exception.class) |
| | | public synchronized OrderInfo generatorOrder(GeneratorOrder criteria) { |
| | | // 门店信息 |
| | | Store store = storeService.getById(criteria.getStoreId()); |
| | | if (!store.getBusinessStatus().equals(StoreStatusEnum.OPEN.getValue())) { |
| | | throw new BadRequestException("停止营业"); |
| | | } |
| | | List<ProductInfo> products = new ArrayList<>(); |
| | | BigDecimal amount = BigDecimal.ZERO; |
| | | for (ProductOrder productOrder : criteria.getProducts()) { |
| | |
| | | products.add(info); |
| | | amount = BigDecimalUtils.add(amount, BigDecimalUtils.multiply(product.getPrice(), productOrder.getCount())); |
| | | } |
| | | if (!(amount.compareTo(store.getDeliveryMinimum()) >= 0)) { |
| | | throw new BadRequestException("起送金额:" + store.getDeliveryMinimum()); |
| | | } |
| | | OrderInfo info = new OrderInfo(); |
| | | info.setStore(store); |
| | | info.setProducts(products); |
| | | info.setAmount(amount); |
| | | info.setPayAmount(amount); |
| | | info.setPromotionAmount(BigDecimal.ZERO); |
| | | info.setUserAddresses(userAddressService.queryUserAddress()); |
| | | info.setUserAddresses(userAddressService.queryUserAddress(store.getLongitude(), store.getLatitude())); |
| | | return info; |
| | | } |
| | | |
| | |
| | | |
| | | @Override |
| | | @Transactional(rollbackFor = Exception.class) |
| | | public void closeOrder(String orderNum) { |
| | | public void cancel(String orderNum) { |
| | | OrderResponse response = getByOrderNum(orderNum); |
| | | Order order = response.getOrder(); |
| | | if (order == null) { |
| | |
| | | map.put("消息", order.getPayMessage()); |
| | | map.put("支付类型", order.getPayType()); |
| | | map.put("支付时间", order.getPayTime()); |
| | | map.put("订单失效时间RFC3339", order.getExpireTime()); |
| | | map.put("订单失效时间", order.getExpireTime()); |
| | | map.put("openid", order.getOpenid()); |
| | | map.put("APPID", order.getAppId()); |
| | | map.put("创建人", order.getCreateBy()); |
| | |
| | | } |
| | | |
| | | @Override |
| | | public List<UserAddress> queryUserAddress() { |
| | | public List<UserAddress> queryUserAddress(double longitude, double latitude) { |
| | | UserAddressQueryCriteria criteria = new UserAddressQueryCriteria(); |
| | | criteria.setUserId(SecurityUtils.getCurrentUserId()); |
| | | criteria.setLongitude(longitude); |
| | | criteria.setLatitude(latitude); |
| | | return queryAll(criteria); |
| | | } |
| | | |
| | | @Override |
| | | public UserAddress getById(Long addressId, Double longitude, Double latitude) { |
| | | return userAddressMapper.getById(addressId, SecurityUtils.getCurrentUserId(), longitude, latitude); |
| | | } |
| | | |
| | | @Override |
| | | @Transactional(rollbackFor = Exception.class) |
| | | public void create(UserAddress resources) { |
| | | if (resources.getIsDefault()) { |
| | |
| | | <if test="criteria.type != null and criteria.type != ''"> |
| | | and type = #{criteria.type} |
| | | </if> |
| | | <if test="criteria.status != null"> |
| | | and status = #{criteria.status} |
| | | </if> |
| | | </where> |
| | | order by audit_id desc |
| | | </select> |
| | |
| | | <if test="criteria.type != null and criteria.type != ''"> |
| | | and type = #{criteria.type} |
| | | </if> |
| | | <if test="criteria.status != null"> |
| | | and status = #{criteria.status} |
| | | </if> |
| | | </where> |
| | | order by audit_id desc |
| | | </select> |
| | |
| | | <result column="merchant_latitude" property="merchantLatitude"/> |
| | | <result column="user_id" property="userId"/> |
| | | <result column="delivery_fee_id" property="deliveryFeeId"/> |
| | | <result column="order_time" property="orderTime"/> |
| | | </resultMap> |
| | | |
| | | <sql id="Base_Column_List"> |
| | | record_id, order_id, order_num, merchant_id, merchant_name, merchant_address, |
| | | receiver_address, order_status, accept_time, accept_num, finish_time, delivery_duration, |
| | | is_overtime, order_source, order_income, create_by, create_time, update_by, update_time, |
| | | rider_id, phone, rider_name, user_id, user_longitude, user_latitude, merchant_longitude, merchant_latitude,delivery_fee_id |
| | | record_id, |
| | | order_id, |
| | | order_num, |
| | | merchant_id, |
| | | merchant_name, |
| | | merchant_address, |
| | | receiver_address, |
| | | order_status, |
| | | accept_time, |
| | | accept_num, |
| | | finish_time, |
| | | delivery_duration, |
| | | is_overtime, |
| | | order_source, |
| | | order_income, |
| | | create_by, |
| | | create_time, |
| | | update_by, |
| | | update_time, |
| | | rider_id, |
| | | phone, |
| | | rider_name, |
| | | user_id, |
| | | user_longitude, |
| | | user_latitude, |
| | | merchant_longitude, |
| | | merchant_latitude, |
| | | delivery_fee_id, |
| | | order_time |
| | | </sql> |
| | | <select id="findAll" resultMap="BaseResultMap"> |
| | | select |
| | |
| | | and merchant_id = #{criteria.merchantId} |
| | | </if> |
| | | <if test="criteria.merchantName != null"> |
| | | and merchant_name like concat('%',#{criteria.merchantName},'%') |
| | | and merchant_name like concat('%', #{criteria.merchantName}, '%') |
| | | </if> |
| | | <if test="criteria.merchantAddress != null"> |
| | | and merchant_address like concat('%',#{criteria.merchantAddress},'%') |
| | | and merchant_address like concat('%', #{criteria.merchantAddress}, '%') |
| | | </if> |
| | | <if test="criteria.receiverAddress != null"> |
| | | and receiver_address like concat('%',#{criteria.receiverAddress},'%') |
| | | and receiver_address like concat('%', #{criteria.receiverAddress}, '%') |
| | | </if> |
| | | <if test="criteria.orderStatus != null"> |
| | | and order_status = #{criteria.orderStatus} |
| | |
| | | </where> |
| | | order by create_time desc |
| | | </select> |
| | | |
| | | <select id="selectRiderInfo" resultMap="BaseResultMap"> |
| | | select record_id recordId ,accept_time as acceptTime, order_time as orderTime |
| | | from qs_rider_order_record where order_num = #{orderNum} |
| | | </select> |
| | | </mapper> |
| | |
| | | <result column="latitude" property="latitude"/> |
| | | <result column="is_default" property="isDefault"/> |
| | | <result column="tag" property="tag"/> |
| | | <result column="distance" property="distance"/> |
| | | <result column="create_by" property="createBy"/> |
| | | <result column="create_time" property="createTime"/> |
| | | <result column="update_by" property="updateBy"/> |
| | |
| | | <select id="findAll" resultMap="BaseResultMap"> |
| | | select |
| | | <include refid="Base_Column_List"/> |
| | | <if test="criteria.longitude != null and criteria.latitude != null and criteria.longitude != '' and criteria.latitude != ''"> |
| | | , ROUND(ST_Distance_Sphere(POINT(#{criteria.longitude}, #{criteria.latitude}), POINT(longitude, |
| | | latitude)), 2) distance |
| | | </if> |
| | | from sh_user_address |
| | | <where> |
| | | <if test="criteria.userId != null and criteria.userId != ''"> |
| | |
| | | <if test="criteria.phone != null and criteria.phone != ''"> |
| | | and receiver_phone like concat('%',#{criteria.phone},'%') |
| | | </if> |
| | | <if test="criteria.radius != null and criteria.radius != ''"> |
| | | and ST_Distance_Sphere(POINT(#{criteria.longitude}, #{criteria.latitude}), POINT(longitude, |
| | | latitude)) distance <= #{criteria.radius} |
| | | </if> |
| | | <if test="criteria.createTime != null and criteria.createTime.size() > 0"> |
| | | AND create_time BETWEEN #{criteria.createTime[0]} AND #{criteria.createTime[1]} |
| | | </if> |
| | | </where> |
| | | order by address_id desc |
| | | </select> |
| | | <select id="getById" resultMap="BaseResultMap"> |
| | | select |
| | | <include refid="Base_Column_List"/> |
| | | , ROUND(ST_Distance_Sphere(POINT(#{longitude}, #{latitude}), POINT(longitude, latitude)), 2) distance |
| | | from sh_user_address |
| | | where user_id = #{userId} and address_id = #{addressId} |
| | | </select> |
| | | </mapper> |