Commit 2b05019f by caiyt

修复订单整个流程遇到的问题

parent 6d3c274f
......@@ -89,7 +89,7 @@ public class AppController extends BaseController {
}
@RequestMapping("/refundOrder")
public AjaxResult refundOrder(String orderId){
public AjaxResult refundOrder(Long orderId){
return AjaxResult.success(orderService.refundOrder(orderId));
}
......
......@@ -13,7 +13,6 @@ import com.soss.system.domain.Order;
import com.soss.system.domain.vo.customer.CustomerQueryVo;
import com.soss.system.domain.vo.customer.CustomerResultVo;
import com.soss.system.service.ICustomerService;
import com.soss.system.service.impl.CustomerServiceImpl;
import io.jsonwebtoken.lang.Assert;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
......@@ -32,20 +31,23 @@ import java.util.Objects;
*/
@RestController
@RequestMapping("/system/customer")
public class CustomerController extends BaseController
{
public class CustomerController extends BaseController {
@Autowired
private ICustomerService customerService;
@Autowired
private TokenService tokenService;
@GetMapping("/allow")
public AjaxResult allow(HttpServletRequest request, String allow) {
@PostMapping("/allow")
@ApiOperation("用户授权")
public AjaxResult allow(HttpServletRequest request, @RequestBody Customer customer) {
TokenService bean = SpringUtils.getBean(TokenService.class);
LoginUser loginUser = bean.getLoginUser(request);
return AjaxResult.success(SpringUtils.getBean(CustomerServiceImpl.class).allow(loginUser.getOpenId(), allow));
if (loginUser == null) {
throw new ServiceException("请先登录");
}
customer.setId(loginUser.getOpenId());
customerService.updateSendMsgFlag(customer);
return AjaxResult.success();
}
@GetMapping("/detail")
......
......@@ -56,7 +56,7 @@ public class MachineApiController {
}
@GetMapping("/testOrder")
public void testOrder(String orderId){
public void testOrder(Long orderId){
machineApiService.testOrder(orderId);
}
@GetMapping("/testOrderUpdate")
......
......@@ -60,7 +60,7 @@ public class OrderController extends BaseController {
* 获取订单详细信息
*/
@GetMapping(value = "/{id}")
public AjaxResult getInfo(@PathVariable("id") String id) {
public AjaxResult getInfo(@PathVariable("id") Long id) {
return AjaxResult.success(orderService.selectOrderById(id));
}
......@@ -77,6 +77,9 @@ public class OrderController extends BaseController {
@PostMapping
public AjaxResult add(HttpServletRequest request, @RequestBody Order order) {
LoginUser loginUser = tokenService.getLoginUser(request);
if (loginUser == null) {
throw new ServiceException("请先登录");
}
if (order.getLng() == null || order.getLng().compareTo(BigDecimal.ZERO) == 0
|| order.getLat() == null || order.getLat().compareTo(BigDecimal.ZERO) == 0) {
......@@ -91,10 +94,16 @@ public class OrderController extends BaseController {
if (HttpStatus.SUCCESS != (int) result.get(result.CODE_TAG)) {
return result;
}
try {
orderService.checkShopInfo(order);
if (order.getCouponId() != null) {
List<CouponVo> couponVos = couponUserService.listCustAvailableCoupon(loginUser.getOpenId(), order.getCouponId());
} catch (ServiceException e) {
return AjaxResult.error(e.getMessage());
}
Integer couponUserId = order.getCouponId();
if (couponUserId != null) {
List<CouponVo> couponVos = couponUserService.listCustAvailableCoupon(loginUser.getOpenId(), couponUserId);
if (CollectionUtils.isEmpty(couponVos)) {
return AjaxResult.error("未查询到匹配的优惠券信息");
}
......@@ -106,21 +115,14 @@ public class OrderController extends BaseController {
}
order.setCouponAmount(couponVo.getCouponAmount().negate());
order.setPaidAmount(order.getAmount().add(order.getCouponAmount()));
order.getOrderDetails().forEach(orderDetail -> {
orderDetail.setCouponAmount(couponVo.getCouponAmountMap().get(orderDetail.getSkuId()).negate());
orderDetail.setRealAmount(orderDetail.getAmountShould().add(orderDetail.getCouponAmount()));
});
couponUserService.useCoupon(couponVo.getId());
}
} catch (ServiceException e) {
return AjaxResult.error(e.getMessage());
order.setCouponId(couponVo.getCouponId());
}
AjaxResult ajaxResult = orderService.insertOrder(loginUser, order);
AjaxResult ajaxResult = orderService.insertOrder(loginUser, order, couponUserId);
if (HttpStatus.SUCCESS != (int) ajaxResult.get(AjaxResult.CODE_TAG)) {
return ajaxResult;
}
int amount = order.getAmount().movePointRight(2).intValue();
int amount = order.getPaidAmount().movePointRight(2).intValue();
Map payInfo = weixinService.pay(request, "hooloo", order.getOrderNo(), order.getUserId(), amount);
if (payInfo != null) {
payInfo.put("orderId", order.getId());
......@@ -131,7 +133,7 @@ public class OrderController extends BaseController {
}
@RequestMapping("/payOrder")
public AjaxResult cancel(HttpServletRequest request, String orderId) {
public AjaxResult cancel(HttpServletRequest request, Long orderId) {
Order order = orderService.selectOrderById(orderId);
order.setOrderNo(orderService.getOrderNo(order.getSource()));
orderService.updateOrder(order);
......@@ -156,7 +158,7 @@ public class OrderController extends BaseController {
}
@RequestMapping("/cancel")
public AjaxResult cancel(String orderId) {
public AjaxResult cancel(Long orderId) {
return toAjax(orderService.cancel(orderId));
}
......
package com.soss.web.controller.coffee;
import java.util.List;
import com.soss.common.core.controller.BaseController;
import com.soss.common.core.domain.AjaxResult;
import com.soss.system.domain.OrderOperationLog;
import com.soss.system.service.IOrderOperationLogService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.soss.common.core.controller.BaseController;
import com.soss.common.core.domain.AjaxResult;
import java.util.List;
/**
* 订单日志Controller
......@@ -29,7 +29,7 @@ public class OrderLogController extends BaseController
*/
@GetMapping("/list")
public AjaxResult list(String orderId)
public AjaxResult list(Long orderId)
{
OrderOperationLog orderOperationLog = new OrderOperationLog();
orderOperationLog.setOrderId(orderId);
......
......@@ -7,6 +7,8 @@ import com.soss.common.core.domain.model.LoginUser;
import com.soss.common.core.page.TableDataInfo;
import com.soss.common.enums.BusinessType;
import com.soss.common.enums.RefundState;
import com.soss.common.exception.ServiceException;
import com.soss.common.utils.StringUtils;
import com.soss.framework.web.service.TokenService;
import com.soss.framework.web.service.WeixinServiceImpl;
import com.soss.system.domain.Order;
......@@ -46,20 +48,29 @@ public class OrderRefundController extends BaseController
*/
@PreAuthorize("@ss.hasPermi('system:refund:list')")
@GetMapping("/list")
public TableDataInfo list(OrderQuery orderQuery)
{
public TableDataInfo list(OrderQuery orderQuery) {
startPage();
List<OrderRefund> list = orderRefundService.selectOrderRefundList(orderQuery);
return getDataTable(list);
}
/**
* 查询订单退款列表
*/
@GetMapping("/list/{orderId}")
public AjaxResult listByOrderId(@PathVariable Long orderId) {
OrderRefund or = new OrderRefund();
or.setOrderId(orderId);
List<OrderRefund> list = orderRefundService.selectOrderRefundList(or);
return AjaxResult.success(list);
}
/**
* 获取订单退款详细信息
*/
@PreAuthorize("@ss.hasPermi('system:refund:query')")
@GetMapping(value = "/{id}")
public AjaxResult getInfo(@PathVariable("id") String id)
{
public AjaxResult getInfo(@PathVariable("id") String id) {
return AjaxResult.success(orderRefundService.selectOrderRefundById(id));
}
......@@ -70,8 +81,13 @@ public class OrderRefundController extends BaseController
@PostMapping
public AjaxResult add(HttpServletRequest request, @RequestBody OrderRefund orderRefund) {
Assert.notNull(orderRefund.getRefundAmount(), "退款金额还未传递");
Assert.notEmpty(orderRefund.getOrderDetailIds(), "退款订单明细ID还未传递");
LoginUser loginUser = tokenService.getLoginUser(request);
if (loginUser == null) {
throw new ServiceException("请先登录");
}
if (StringUtils.isEmpty(loginUser.getOpenId())) {
Assert.notEmpty(orderRefund.getOrderDetailIds(), "退款订单明细ID还未传递");
}
orderRefund.setCreateUserName(loginUser.getUsername());
AjaxResult ajaxResult = orderRefundService.insertOrderRefund(orderRefund);
......@@ -92,7 +108,7 @@ public class OrderRefundController extends BaseController
@PostMapping("/refund")
public void refund(){
Order order = orderService.selectOrderById("98");
Order order = orderService.selectOrderById(98L);
int totalFee = order.getAmount().movePointRight(2).intValue();
weixinService.refund(order.getOrderNo(),order.getOrderNo()+"1",totalFee,totalFee);
......
package com.soss.web.controller.coffee;
import java.util.List;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import com.soss.common.core.domain.BaseEntity;
import com.soss.common.core.domain.model.LoginUser;
import com.soss.framework.web.service.TokenService;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.soss.common.annotation.Log;
import com.soss.common.core.controller.BaseController;
import com.soss.common.core.domain.AjaxResult;
import com.soss.common.core.domain.BaseEntity;
import com.soss.common.core.domain.model.LoginUser;
import com.soss.common.core.page.TableDataInfo;
import com.soss.common.enums.BusinessType;
import com.soss.common.exception.ServiceException;
import com.soss.common.utils.poi.ExcelUtil;
import com.soss.framework.web.service.TokenService;
import com.soss.system.domain.WechatMessage;
import com.soss.system.service.IWechatMessageService;
import com.soss.common.utils.poi.ExcelUtil;
import com.soss.common.core.page.TableDataInfo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.util.List;
/**
* 小程序信息发送Controller
......@@ -49,6 +43,9 @@ public class WechatMessageController extends BaseController
{
WechatMessage wechatMessage = new WechatMessage();
LoginUser loginUser = tokenService.getLoginUser(request);
if (loginUser == null) {
throw new ServiceException("请先登录");
}
wechatMessage.setUserId(loginUser.getOpenId());
startPage();
......
......@@ -36,7 +36,7 @@ public class MachineSericeImpl {
jsonObjects.add(jsonObject);
Long skuId = detail.getSkuId();
String num = detail.getNum();
String amount = detail.getViewAmount().stripTrailingZeros().toString();
String amount = detail.getOriAmount().stripTrailingZeros().toString();
String realAmount = detail.getRealAmount().stripTrailingZeros().toString();
jsonObject.put("skuID",skuId);
jsonObject.put("skuCount",num);
......
......@@ -185,17 +185,6 @@ public class WeixinServiceImpl {
return new String(cipher.doFinal(encData), "UTF-8");
}
public Map orderQuery() {
Map<String, Object> map = new HashMap<>();
......@@ -475,7 +464,7 @@ public class WeixinServiceImpl {
try {
wxPayRefundNotifyResult = wxPayService.parseRefundNotifyResult(xmlData);
} catch (WxPayException e) {
log.error("退款失败,失败信息:{}", e);
log.error("退款失败", e);
return WxPayNotifyResponse.fail("退款失败");
}
//判断你返回状态信息是否正确
......
......@@ -7,6 +7,7 @@ import lombok.Data;
import org.apache.commons.lang3.builder.ToStringBuilder;
import org.apache.commons.lang3.builder.ToStringStyle;
import java.time.LocalDateTime;
import java.util.Date;
import java.util.List;
......@@ -54,14 +55,27 @@ public class Customer extends BaseEntity
private List<Order> cancelOrder;
private String allow;
@ApiModelProperty("用户授权发送消息1:0-未授权 1-授权")
private Boolean sendMsgFlag1;
@ApiModelProperty("用户授权发送消息2:0-未授权 1-授权")
private Boolean sendMsgFlag2;
@ApiModelProperty("用户授权发送消息3:0-未授权 1-授权")
private Boolean sendMsgFlag3;
@ApiModelProperty("记住标识:true-记住选择")
private Boolean rememberFlag;
@ApiModelProperty("用户授权有效期,空则永久有效")
private LocalDateTime flagExpireDate;
private List<Order> refundOrder;
private List<Order> normalOrder;
@Override
public String toString() {
return new ToStringBuilder(this,ToStringStyle.MULTI_LINE_STYLE)
return new ToStringBuilder(this, ToStringStyle.MULTI_LINE_STYLE)
.append("id", getId())
.append("userName", getUserName())
.append("phone", getPhone())
......
......@@ -7,7 +7,6 @@ import lombok.Data;
import org.apache.commons.lang3.builder.ToStringBuilder;
import org.apache.commons.lang3.builder.ToStringStyle;
import java.io.Serializable;
import java.math.BigDecimal;
import java.util.Date;
......@@ -18,12 +17,12 @@ import java.util.Date;
* @date 2022-04-28
*/
@Data
public class OrderDetail implements Serializable {
public class OrderDetail {
/**
* 主键
*/
private String id;
private Long id;
/**
* 订单ID
......@@ -56,9 +55,14 @@ public class OrderDetail implements Serializable {
private String num;
/**
* 展示金额
* 单价
*/
private BigDecimal viewAmount;
private BigDecimal unitPrice;
/**
* 原价总额
*/
private BigDecimal oriAmount;
/**
* 应付金额
......@@ -133,7 +137,7 @@ public class OrderDetail implements Serializable {
.append("goodsName", getGoodsName())
.append("machineId", getMachineId())
.append("num", getNum())
.append("viewAmount", getViewAmount())
.append("oriPrice", getOriAmount())
.append("amountShould", getAmountShould())
.append("couponAmount", getCouponAmount())
.append("realAmount", getRealAmount())
......
package com.soss.system.domain;
import java.util.Date;
import com.fasterxml.jackson.annotation.JsonFormat;
import org.apache.commons.lang3.builder.ToStringBuilder;
import org.apache.commons.lang3.builder.ToStringStyle;
import com.soss.common.annotation.Excel;
import com.soss.common.core.domain.BaseEntity;
import lombok.Data;
import org.apache.commons.lang3.builder.ToStringBuilder;
import org.apache.commons.lang3.builder.ToStringStyle;
import java.util.Date;
/**
* 【请填写功能名称】对象 order_operation_log
......@@ -14,6 +15,7 @@ import com.soss.common.core.domain.BaseEntity;
* @author zxq
* @date 2022-05-17
*/
@Data
public class OrderOperationLog extends BaseEntity
{
private static final long serialVersionUID = 1L;
......@@ -44,71 +46,7 @@ public class OrderOperationLog extends BaseEntity
/** $column.columnComment */
@Excel(name = "${comment}", readConverterExp = "$column.readConverterExp()")
private String orderId;
public void setId(String id)
{
this.id = id;
}
public String getId()
{
return id;
}
public void setStatus(String status)
{
this.status = status;
}
public String getStatus()
{
return status;
}
public void setOperation(String operation)
{
this.operation = operation;
}
public String getOperation()
{
return operation;
}
public void setCreateAt(Date createAt)
{
this.createAt = createAt;
}
public Date getCreateAt()
{
return createAt;
}
public void setOperationUser(String operationUser)
{
this.operationUser = operationUser;
}
public String getOperationUser()
{
return operationUser;
}
public void setContent(String content)
{
this.content = content;
}
public String getContent()
{
return content;
}
public void setOrderId(String orderId)
{
this.orderId = orderId;
}
public String getOrderId()
{
return orderId;
}
private Long orderId;
@Override
public String toString() {
......
......@@ -28,7 +28,7 @@ public class OrderRefund extends BaseEntity
/** 订单ID */
@Excel(name = "订单ID")
private String orderId;
private Long orderId;
/** 退款金额 */
@Excel(name = "退款金额")
......@@ -67,6 +67,9 @@ public class OrderRefund extends BaseEntity
@ApiModelProperty("退款明细id集合")
private List<Long> orderDetailIds;
@ApiModelProperty("退款订单明细")
private List<OrderDetail> orderDetails;
@Override
public String toString() {
return new ToStringBuilder(this, ToStringStyle.MULTI_LINE_STYLE)
......
......@@ -64,7 +64,7 @@ public interface CouponUserMapper {
* @param nowTime
* @return
*/
List<CouponVo> listCustAvailableCoupon(@Param("custId") String custId, @Param("couponId") Integer couponId, @Param("nowTime") LocalDateTime nowTime);
List<CouponVo> listCustAvailableCoupon(@Param("custId") String custId, @Param("couponUserId") Integer couponUserId, @Param("nowTime") LocalDateTime nowTime);
/**
* 查询用户优惠券列表
......
package com.soss.system.mapper;
import java.util.List;
import com.soss.system.domain.Customer;
import com.soss.system.domain.vo.customer.CustomerQueryVo;
import com.soss.system.domain.vo.customer.CustomerResultVo;
import java.util.List;
/**
* 用户信息Mapper接口
*
......@@ -46,6 +47,11 @@ public interface CustomerMapper
public int updateCustomer(Customer customer);
/**
* 修改用户授权信息
*/
int updateSendMsgFlag(Customer customer);
/**
* 删除用户信息
*
* @param id 用户信息主键
......
package com.soss.system.mapper;
import com.soss.system.domain.OrderDetail;
import org.apache.ibatis.annotations.Param;
import java.util.Date;
import java.util.List;
......@@ -26,7 +27,7 @@ public interface OrderDetailMapper {
* @param ids
* @return
*/
List<OrderDetail> listDetailByIds(List<Long> ids);
List<OrderDetail> listDetailByIds(@Param("ids") List<Long> ids);
/**
* 查询订单详情列表
......@@ -66,9 +67,9 @@ public interface OrderDetailMapper {
* @param ids 需要删除的数据主键集合
* @return 结果
*/
public int deleteOrderDetailByIds(String[] ids);
int deleteOrderDetailByIds(String[] ids);
void bindRefund(Long refundId, List<Long> ids);
void bindRefund(@Param("refundId") Long refundId, @Param("ids") List<Long> ids);
void updateRefundState(Long refundId, Date refundTime);
void updateRefundState(@Param("refundId") Long refundId, @Param("refundTime") Date refundTime);
}
......@@ -21,7 +21,7 @@ public interface OrderMapper {
* @param id 订单主键
* @return 订单
*/
public Order selectOrderById(String id);
public Order selectOrderById(Long id);
/**
* 查询订单列表
......@@ -53,7 +53,7 @@ public interface OrderMapper {
* @param id 订单主键
* @return 结果
*/
public int deleteOrderById(String id);
public int deleteOrderById(Long id);
/**
* 批量删除订单
......
......@@ -46,7 +46,7 @@ public class OrderSchedule {
OrderOperationLog operationLog =new OrderOperationLog();
operationLog.setOperationUser("系统");
operationLog.setStatus("已取消");
operationLog.setOrderId(String.valueOf(order.getId()));
operationLog.setOrderId(order.getId());
operationLog.setContent("超时自动取消");
operationLog.setCreateAt(new Date());
operationLog.setOperation("取消订单");
......
......@@ -23,13 +23,11 @@ public interface ICouponUserService {
int getCustAvailableCouponCnt(String custId);
List<CouponVo> listCustAvailableCoupon(String custId, Integer couponId);
List<CouponVo> listCustAvailableCoupon(String custId, Integer couponUserId);
List<CouponVo> listCustCoupons(String custId, Boolean effectiveFlag);
List<CouponUserVo> selectCouponUserList(CouponUser couponUser);
void resovleCouponFitable(List<CouponVo> couponVos, Order order);
void useCoupon(Integer id);
}
package com.soss.system.service;
import java.util.List;
import java.util.Map;
import com.soss.system.domain.Customer;
import com.soss.system.domain.Order;
import com.soss.system.domain.vo.customer.CustomerQueryVo;
import com.soss.system.domain.vo.customer.CustomerResultVo;
import java.util.List;
import java.util.Map;
/**
* 用户信息Service接口
*
......@@ -51,6 +51,8 @@ public interface ICustomerService
*/
public int updateCustomer(Customer customer);
int updateSendMsgFlag(Customer customer);
void updateCustBirthday(Customer customer);
/**
......@@ -69,7 +71,5 @@ public interface ICustomerService
*/
public int deleteCustomerById(Long id);
Integer allow(String openId, String allow);
Map<String, Object> getCustSimpleOrderStat(String custId);
}
......@@ -21,7 +21,7 @@ public interface IOrderService
* @param id 订单主键
* @return 订单
*/
public Order selectOrderById(String id);
Order selectOrderById(Long id);
/**
* 查询订单列表
......@@ -37,9 +37,10 @@ public interface IOrderService
*
* @param request
* @param order 订单
* @param couponUserId
* @return 结果
*/
public AjaxResult insertOrder(LoginUser request, Order order);
public AjaxResult insertOrder(LoginUser request, Order order, Integer couponUserId);
void checkShopInfo(Order order);
......@@ -51,25 +52,9 @@ public interface IOrderService
*/
public int updateOrder(Order order);
/**
* 批量删除订单
*
* @param ids 需要删除的订单主键集合
* @return 结果
*/
public int deleteOrderByIds(String[] ids);
/**
* 删除订单信息
*
* @param id 订单主键
* @return 结果
*/
public int deleteOrderById(String id);
AjaxResult check(Order order);
List<Order> getMyOrder(String openId);
int cancel(String orderId);
int cancel(Long orderId);
}
......@@ -2,7 +2,6 @@ package com.soss.system.service.impl;
import com.soss.common.enums.CouponCategoryType;
import com.soss.common.enums.CouponState;
import com.soss.common.enums.CouponUserState;
import com.soss.common.enums.CouponUserType;
import com.soss.common.exception.ServiceException;
import com.soss.common.utils.DateUtils;
......@@ -23,6 +22,7 @@ import org.springframework.util.CollectionUtils;
import java.math.BigDecimal;
import java.time.LocalDateTime;
import java.util.*;
import java.util.function.Function;
import java.util.stream.Collectors;
/**
......@@ -127,12 +127,12 @@ public class CouponUserServiceImpl implements ICouponUserService {
* 查询用户可用优惠券列表
*
* @param custId
* @param couponId
* @param couponUserId
* @return
*/
@Override
public List<CouponVo> listCustAvailableCoupon(String custId, Integer couponId) {
List<CouponVo> couponVos = couponUserMapper.listCustAvailableCoupon(custId, couponId, LocalDateTime.now());
public List<CouponVo> listCustAvailableCoupon(String custId, Integer couponUserId) {
List<CouponVo> couponVos = couponUserMapper.listCustAvailableCoupon(custId, couponUserId, LocalDateTime.now());
transferTabIds(couponVos);
return couponVos;
}
......@@ -175,12 +175,6 @@ public class CouponUserServiceImpl implements ICouponUserService {
checkGoodsFitable(couponVos, order.getOrderDetails());
}
@Override
public void useCoupon(Integer id) {
CouponUser couponUser = new CouponUser(id, CouponUserState.USED.getState());
couponUserMapper.updateCouponUser(couponUser);
}
private void checkGoodsFitable(List<CouponVo> couponVos, List<OrderDetail> orderDetails) {
Assert.notEmpty(orderDetails, "商品明细还未传递");
List<Long> skuIds = orderDetails.stream().map(OrderDetail::getSkuId).collect(Collectors.toList());
......@@ -192,10 +186,17 @@ public class CouponUserServiceImpl implements ICouponUserService {
List<Goods> goods = goodsMapper.selectGoodsByIds(goodsIds);
Assert.notEmpty(goods, "未查询到匹配的商品信息[id=" + goodsIds + "]");
// sku的ID和价格字典
Map<Long, BigDecimal> skuIdPriceMap = goodsSkus.stream().collect(Collectors.toMap(GoodsSku::getId, GoodsSku::getDiscount));
Map<Long, GoodsSku> skuMap = goodsSkus.stream().collect(Collectors.toMap(GoodsSku::getId, Function.identity()));
// 订单明细设置
orderDetails.forEach(orderDetail -> {
GoodsSku sku = skuMap.get(orderDetail.getSkuId());
BigDecimal skuNum = new BigDecimal(orderDetail.getNum());
orderDetail.setOriAmount(skuNum.multiply(sku.getPrice()));
orderDetail.setUnitPrice(sku.getDiscount());
orderDetail.setAmountShould(skuNum.multiply(sku.getDiscount()));
});
// 订单总额
BigDecimal orderTotalAmount = orderDetails.stream().map(orderDetail ->
new BigDecimal(orderDetail.getNum()).multiply(skuIdPriceMap.get(orderDetail.getSkuId()))).reduce(BigDecimal.ZERO, BigDecimal::add);
BigDecimal orderTotalAmount = orderDetails.stream().map(OrderDetail::getAmountShould).reduce(BigDecimal.ZERO, BigDecimal::add);
couponVos.stream().filter(couponVo -> StringUtils.isEmpty(couponVo.getNotFitableDesc())).forEach(couponVo -> {
/** 可用饮品范围的判断 */
List<Long> fitCouponGoodsIdList = goods.stream().filter(good ->
......@@ -218,9 +219,7 @@ public class CouponUserServiceImpl implements ICouponUserService {
couponVo.setCouponAmount(couponVo.getPriceDiscount().min(orderTotalAmount));
} else {
List<OrderDetail> fitOrderDetails = orderDetails.stream().filter(orderDetail -> fitCouponGoodsIdList.contains(orderDetail.getGoodsId())).collect(Collectors.toList());
Map<Long, BigDecimal> fitSkuMap = fitOrderDetails.stream().collect(Collectors.toMap(OrderDetail::getSkuId, orderDetail ->
new BigDecimal(orderDetail.getNum()).multiply(skuIdPriceMap.get(orderDetail.getSkuId()))));
BigDecimal fitGoodsAmount = fitSkuMap.values().stream().reduce(BigDecimal.ZERO, BigDecimal::add);
BigDecimal fitGoodsAmount = fitOrderDetails.stream().map(OrderDetail::getAmountShould).reduce(BigDecimal.ZERO, BigDecimal::add);
if (couponVo.getPriceLimit() != null && couponVo.getPriceLimit().compareTo(BigDecimal.ZERO) != 0 && couponVo.getPriceLimit().compareTo(fitGoodsAmount) > 0) {
if (couponVo.getType().equals(CouponCategoryType.DISCOUNT.getType())) { // 折扣
couponVo.setNotFitableDesc("未达到满减要求");
......@@ -229,35 +228,40 @@ public class CouponUserServiceImpl implements ICouponUserService {
}
}
this.wrapperCouponAmount(couponVo, fitOrderDetails, fitSkuMap, fitGoodsAmount);
this.wrapperCouponAmount(couponVo, fitOrderDetails, fitGoodsAmount);
Map<Long, BigDecimal> couponAmountMap = couponVo.getCouponAmountMap();
orderDetails.forEach(orderDetail -> {
BigDecimal couponAmount = couponAmountMap.get(orderDetail.getSkuId());
orderDetail.setCouponAmount(couponAmount == null ? BigDecimal.ZERO : couponAmount.negate());
orderDetail.setRealAmount(orderDetail.getAmountShould().add(orderDetail.getCouponAmount()));
});
}
});
}
private void wrapperCouponAmount(CouponVo couponVo, List<OrderDetail> fitOrderDetails, Map<Long, BigDecimal> fitSkuMap, BigDecimal fitGoodsAmount) {
private void wrapperCouponAmount(CouponVo couponVo, List<OrderDetail> fitOrderDetails, BigDecimal fitGoodsAmount) {
Map<Long, BigDecimal> couponAmountMap = new HashMap<>();
if (couponVo.getOrderLimit() != null && couponVo.getOrderLimit()) { // 单杯
BigDecimal discountAmount = fitSkuMap.values().stream().max(BigDecimal::compareTo).get();
Long couponSkuId = fitOrderDetails.stream().filter(orderDetail -> fitSkuMap.get(orderDetail.getSkuId()).compareTo(BigDecimal.ZERO) == 0).findFirst().get().getSkuId();
OrderDetail orderDetail = fitOrderDetails.stream().max(Comparator.comparing(OrderDetail::getUnitPrice)).get();
BigDecimal discountAmount = orderDetail.getUnitPrice();
if (couponVo.getType().equals(CouponCategoryType.DISCOUNT.getType())) { // 折扣
couponVo.setCouponAmount(discountAmount.subtract(this.getDiscountAmount(discountAmount, couponVo.getPriceDiscount())));
} else { // 免单
discountAmount = this.getDiscountAmount(discountAmount, couponVo.getPriceDiscount());
}/* else { // 免单
}*/
couponVo.setCouponAmount(discountAmount);
}
couponAmountMap.put(couponSkuId, discountAmount);
couponAmountMap.put(orderDetail.getSkuId(), couponVo.getCouponAmount());
} else { // 整单
if (couponVo.getType().equals(CouponCategoryType.DISCOUNT.getType())) { // 折扣
couponVo.setCouponAmount(this.getDiscountAmount(fitGoodsAmount, couponVo.getPriceDiscount()));
fitOrderDetails.forEach(orderDetail -> orderDetail.setCouponAmount(this.getDiscountAmount(fitSkuMap.get(orderDetail.getSkuId()), couponVo.getPriceDiscount())));
fitOrderDetails.forEach(orderDetail -> orderDetail.setCouponAmount(this.getDiscountAmount(orderDetail.getAmountShould(), couponVo.getPriceDiscount())));
// 订单明细优惠总和
BigDecimal detailCouponSum = fitOrderDetails.stream().map(OrderDetail::getCouponAmount).reduce(BigDecimal.ZERO, BigDecimal::add);
// 如果订单明细优惠总额大于订单总优惠金额,则将订单明细最后一条记录的优惠金额去掉差额
if (detailCouponSum.compareTo(couponVo.getCouponAmount()) > 0) {
if (detailCouponSum.compareTo(couponVo.getCouponAmount()) != 0) {
OrderDetail orderDetail = fitOrderDetails.get(fitOrderDetails.size() - 1);
orderDetail.setCouponAmount(orderDetail.getCouponAmount().add(couponVo.getCouponAmount().subtract(detailCouponSum)));
}
fitOrderDetails.forEach(orderDetail -> orderDetail.setCouponAmount(fitSkuMap.get(orderDetail.getSkuId()).subtract(orderDetail.getCouponAmount())));
couponVo.setCouponAmount(fitGoodsAmount.subtract(couponVo.getCouponAmount()));
} else { // 免单
couponVo.setCouponAmount(fitGoodsAmount);
}
......@@ -299,6 +303,11 @@ public class CouponUserServiceImpl implements ICouponUserService {
}
private BigDecimal getDiscountAmount(BigDecimal amount, BigDecimal priceDiscount) {
return amount.multiply(priceDiscount.divide(BigDecimal.TEN, 4, BigDecimal.ROUND_HALF_UP)).setScale(2, BigDecimal.ROUND_HALF_UP).min(amount);
// 打折后的价格
BigDecimal priceAfterDiscount = amount.multiply(priceDiscount.divide(BigDecimal.TEN, 4, BigDecimal.ROUND_HALF_UP)).setScale(2, BigDecimal.ROUND_HALF_UP);
// 跟原价比取最小值
priceAfterDiscount = priceAfterDiscount.min(amount);
// 获取优惠金额
return amount.subtract(priceAfterDiscount);
}
}
......@@ -11,9 +11,11 @@ import com.soss.system.mapper.CustomerMapper;
import com.soss.system.mapper.OrderMapper;
import com.soss.system.mapper.ShopMapper;
import com.soss.system.service.ICustomerService;
import org.apache.commons.lang3.BooleanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import java.time.LocalDateTime;
import java.util.Arrays;
import java.util.List;
import java.util.Map;
......@@ -51,17 +53,16 @@ public class CustomerServiceImpl implements ICustomerService
{
Order order = new Order();
order.setUserId(id);
List<String> normalStatus = Arrays.asList(OrderStatusConstant.PaidCancel,OrderStatusConstant.Unpaid,OrderStatusConstant.Paid,OrderStatusConstant.production,OrderStatusConstant.productionCompleted,OrderStatusConstant.Taking,OrderStatusConstant.completed);
List<String> cancelStatus = Arrays.asList(OrderStatusConstant.PaidCancel,OrderStatusConstant.UnpaidCancel,OrderStatusConstant.productionCancel,OrderStatusConstant.productionCompletedCancel);
List<String> refundStatus = Arrays.asList(OrderStatusConstant.refunding,OrderStatusConstant.refundFailed,OrderStatusConstant.PartialRefund,OrderStatusConstant.refund);
List<Order> orders = null;
List<String> statusList;
if("1".equals(status)){
orders = orderMapper.selectOrderByUserId(id,normalStatus);
statusList = Arrays.asList(OrderStatusConstant.PaidCancel, OrderStatusConstant.Unpaid, OrderStatusConstant.Paid, OrderStatusConstant.production, OrderStatusConstant.productionCompleted, OrderStatusConstant.Taking, OrderStatusConstant.completed);
}else if("2".equals(status)){
orders = orderMapper.selectOrderByUserId(id,cancelStatus);
statusList = Arrays.asList(OrderStatusConstant.PaidCancel, OrderStatusConstant.UnpaidCancel, OrderStatusConstant.productionCancel, OrderStatusConstant.productionCompletedCancel);
}else{
orders = orderMapper.selectOrderByUserId(id,refundStatus);
statusList = Arrays.asList(OrderStatusConstant.refunding, OrderStatusConstant.refundFailed, OrderStatusConstant.PartialRefund, OrderStatusConstant.refund);
}
orders = orderMapper.selectOrderByUserId(id, statusList);
for (Order order1 : orders) {
order1.setShop(shopMapper.selectShopById(order1.getShopId()));
}
......@@ -106,6 +107,18 @@ public class CustomerServiceImpl implements ICustomerService
return customerMapper.updateCustomer(customer);
}
/**
* 修改用户授权信息
*/
@Override
public int updateSendMsgFlag(Customer customer) {
if (!BooleanUtils.isTrue(customer.getRememberFlag())) {
LocalDateTime date = DateUtils.addDaysAndGetEnd(LocalDateTime.now(), 6);
customer.setFlagExpireDate(date);
}
return customerMapper.updateSendMsgFlag(customer);
}
@Override
public void updateCustBirthday(Customer customer) {
Customer cust = customerMapper.selectCustomerById(customer.getId());
......@@ -139,14 +152,6 @@ public class CustomerServiceImpl implements ICustomerService
}
@Override
public Integer allow(String openId, String allow) {
Customer customer = new Customer();
customer.setId(openId);
customer.setAllow("1");
return customerMapper.updateCustomer(customer);
}
@Override
public Map<String, Object> getCustSimpleOrderStat(String custId) {
return orderMapper.getCustOrderSimpleStat(custId);
}
......
......@@ -135,7 +135,7 @@ public class MachineApiServiceImpl {
public String updateOrder(JSONObject jsonObject) {
Long orderID = jsonObject.getLong("orderId");
String status = jsonObject.getString("status");
Order order1 = orderService.selectById(String.valueOf(orderID));
Order order1 = orderService.selectById(orderID);
if(order1==null){
throw new ServiceException("该订单不存在");
}
......@@ -152,10 +152,10 @@ public class MachineApiServiceImpl {
}
public void testOrder(String orderId) {
public void testOrder(Long orderId) {
try{
if(StringUtils.isEmpty(orderId)){
orderId = "8";
if(orderId == null){
orderId = 8L;
}
Order order = orderService.selectById(orderId);
OrderDetail orderDetail =new OrderDetail();
......@@ -194,7 +194,7 @@ public class MachineApiServiceImpl {
jsonObject.put("goodsId", detail.getGoodsId());
jsonObject.put("goodsName",detail.getGoodsName());
jsonObject.put("num",Integer.parseInt(detail.getNum()));
jsonObject.put("amount",detail.getViewAmount());
jsonObject.put("amount",detail.getOriAmount());
jsonObject.put("specRuleDetail",detail.getSpecRuleDetail());
jsonObject.put("specRuleIds",detail.getSpecRuleIds());
jsonObject.put("skuId", detail.getSkuId());
......
......@@ -60,7 +60,7 @@ public class OrderOperationLogServiceImpl implements IOrderOperationLogService
public int insertOrderOperationLog(Order order)
{
OrderOperationLog operationLog = new OrderOperationLog();
operationLog.setOrderId(String.valueOf(order.getId()));
operationLog.setOrderId(order.getId());
operationLog.setCreateAt(new Date());
String state = order.getState();
......@@ -162,7 +162,7 @@ public class OrderOperationLogServiceImpl implements IOrderOperationLogService
public void insertOrderOperationLog(OrderRefund orderRefund) {
Order order = orderRefund.getOrder();
OrderOperationLog operationLog = new OrderOperationLog();
operationLog.setOrderId(String.valueOf(order.getId()));
operationLog.setOrderId(order.getId());
operationLog.setCreateAt(new Date());
if(StringUtils.isEmpty(orderRefund.getDesc())){
operationLog.setStatus("已退款");
......@@ -182,7 +182,7 @@ public class OrderOperationLogServiceImpl implements IOrderOperationLogService
public void insertOrderOperationLog(Order order, ResultVo resultVo) {
OrderOperationLog operationLog = new OrderOperationLog();
operationLog.setOrderId(String.valueOf(order.getId()));
operationLog.setOrderId(order.getId());
operationLog.setCreateAt(new Date());
String state = order.getState();
operationLog.setOperation("同步消息");
......
package com.soss.system.service.impl;
import com.alibaba.fastjson.JSONObject;
import com.soss.common.core.domain.AjaxResult;
import com.soss.common.enums.RefundState;
import com.soss.common.exception.ServiceException;
......@@ -10,11 +9,9 @@ import com.soss.system.constants.OrderStatusConstant;
import com.soss.system.domain.Order;
import com.soss.system.domain.OrderDetail;
import com.soss.system.domain.OrderRefund;
import com.soss.system.domain.OrderSnapshot;
import com.soss.system.domain.vo.OrderQuery;
import com.soss.system.mapper.OrderDetailMapper;
import com.soss.system.mapper.OrderRefundMapper;
import com.soss.system.mapper.OrderSnapshotMapper;
import com.soss.system.service.IOrderRefundService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
......@@ -25,6 +22,7 @@ import java.math.BigDecimal;
import java.util.Arrays;
import java.util.Date;
import java.util.List;
import java.util.Objects;
import java.util.stream.Collectors;
/**
......@@ -41,9 +39,6 @@ public class OrderRefundServiceImpl implements IOrderRefundService
private OrderRefundMapper orderRefundMapper;
@Autowired
private OrderServiceImpl orderService;
@Autowired
private OrderSnapshotMapper orderSnapshotMapper;
@Autowired
private OrderDetailMapper orderDetailMapper;
......@@ -54,15 +49,19 @@ public class OrderRefundServiceImpl implements IOrderRefundService
* @return 订单退款
*/
@Override
public OrderRefund selectOrderRefundById(String id)
{
public OrderRefund selectOrderRefundById(String id) {
OrderRefund orderRefund = orderRefundMapper.selectOrderRefundById(id);
this.wrapperOrderInfo(orderRefund);
return orderRefund;
}
private void wrapperOrderInfo(OrderRefund orderRefund) {
Order order = orderService.selectOrderById(orderRefund.getOrderId());
OrderSnapshot orderSnapshot = orderSnapshotMapper.selectOrderSnapshotByOrderId(order.getId());
List<OrderDetail> orderDetails = JSONObject.parseArray(orderSnapshot.getSnapshot(), OrderDetail.class);
OrderDetail detail = new OrderDetail();
detail.setRefundId(orderRefund.getId());
List<OrderDetail> orderDetails = orderDetailMapper.selectOrderDetailList(detail);
order.setOrderDetails(orderDetails);
orderRefund.setOrder(order);
return orderRefund;
}
/**
......@@ -72,18 +71,15 @@ public class OrderRefundServiceImpl implements IOrderRefundService
* @return 订单退款
*/
@Override
public List<OrderRefund> selectOrderRefundList(OrderRefund orderRefund)
{
public List<OrderRefund> selectOrderRefundList(OrderRefund orderRefund) {
List<OrderRefund> orderRefunds = orderRefundMapper.selectOrderRefundList(orderRefund);
for (OrderRefund refund : orderRefunds) {
Order order = orderService.selectOrderById(refund.getOrderId());
OrderSnapshot orderSnapshot = orderSnapshotMapper.selectOrderSnapshotByOrderId(order.getId());
List<OrderDetail> orderDetails = JSONObject.parseArray(orderSnapshot.getSnapshot(), OrderDetail.class);
order.setOrderDetails(orderDetails);
refund.setOrder(order);
OrderDetail detail = new OrderDetail();
detail.setRefundId(refund.getId());
List<OrderDetail> orderDetails = orderDetailMapper.selectOrderDetailList(detail);
refund.setOrderDetails(orderDetails);
}
return orderRefunds;
}
/**
......@@ -114,16 +110,33 @@ public class OrderRefundServiceImpl implements IOrderRefundService
} else {
return AjaxResult.error("该订单状态不允许退款");
}
BigDecimal orderDetailAmount;
if (!CollectionUtils.isEmpty(orderRefund.getOrderDetailIds())) {
List<OrderDetail> orderDetails = orderDetailMapper.listDetailByIds(orderRefund.getOrderDetailIds());
List<String> illegalGoodNames = orderDetails.stream().filter(orderDetail -> orderDetail.getRefundTime() != null).map(OrderDetail::getGoodsName).collect(Collectors.toList());
List<String> illegalGoodNames = orderDetails.stream().filter(orderDetail -> !Objects.equals(orderDetail.getOrderId(), order.getId()))
.map(OrderDetail::getGoodsName).collect(Collectors.toList());
if (!CollectionUtils.isEmpty(illegalGoodNames)) {
return AjaxResult.error("商品" + illegalGoodNames + "已退过款");
return AjaxResult.error("商品" + illegalGoodNames + "和订单不匹配");
}
BigDecimal orderDetailAmount = orderDetails.stream().map(OrderDetail::getRealAmount).reduce(BigDecimal.ZERO, BigDecimal::add);
illegalGoodNames = orderDetails.stream().filter(orderDetail -> orderDetail.getRefundId() != null)
.map(OrderDetail::getGoodsName).collect(Collectors.toList());
if (!CollectionUtils.isEmpty(illegalGoodNames)) {
return AjaxResult.error("商品" + illegalGoodNames + "已发起过退款");
}
orderDetailAmount = orderDetails.stream().map(OrderDetail::getRealAmount).reduce(BigDecimal.ZERO, BigDecimal::add);
if (orderDetailAmount.compareTo(orderRefund.getRefundAmount()) != 0) {
log.warn("退款金额[{}]与商品明细总额[{}]不符", orderRefund.getRefundAmount(), orderDetailAmount);
return AjaxResult.error("退款金额与商品明细总额不符");
}
} else {
OrderDetail detail = new OrderDetail();
detail.setOrderId(order.getId());
List<OrderDetail> orderDetails = orderDetailMapper.selectOrderDetailList(detail);
orderDetailAmount = orderDetails.stream().map(OrderDetail::getRealAmount).reduce(BigDecimal.ZERO, BigDecimal::add);
List<Long> orderDetailIds = orderDetails.stream().map(OrderDetail::getId).collect(Collectors.toList());
orderRefund.setOrderDetailIds(orderDetailIds);
}
orderRefund.setCreatedAt(new Date());
orderRefund.setUpdatedAt(new Date());
......@@ -142,19 +155,7 @@ public class OrderRefundServiceImpl implements IOrderRefundService
orderRefund.setOrder(order);
return AjaxResult.success(orderRefund);
}
public void cancel(Order order) {
if(OrderStatusConstant.Unpaid.equals(order.getState())){
order.setState(OrderStatusConstant.UnpaidCancel);
order.setUpdatedAt(new Date());
orderService.updateOrder(order);
}else if(OrderStatusConstant.Paid.equals(order.getState())){
order.setState(OrderStatusConstant.PaidCancel);
order.setUpdatedAt(new Date());
orderService.updateOrder(order);
}else{
throw new ServiceException("该订单不允许退款");
}
}
/**
* 修改订单退款
*
......@@ -208,11 +209,7 @@ public class OrderRefundServiceImpl implements IOrderRefundService
public List<OrderRefund> selectOrderRefundList(OrderQuery orderQuery) {
List<OrderRefund> orderRefunds = orderRefundMapper.selectList(orderQuery);
for (OrderRefund refund : orderRefunds) {
Order order = orderService.selectOrderById(refund.getOrderId());
OrderSnapshot orderSnapshot = orderSnapshotMapper.selectOrderSnapshotByOrderId(order.getId());
List<OrderDetail> orderDetails = JSONObject.parseArray(orderSnapshot.getSnapshot(), OrderDetail.class);
order.setOrderDetails(orderDetails);
refund.setOrder(order);
this.wrapperOrderInfo(refund);
}
return orderRefunds;
}
......
......@@ -4,6 +4,7 @@ import com.alibaba.fastjson.JSONArray;
import com.alibaba.fastjson.JSONObject;
import com.soss.common.core.domain.AjaxResult;
import com.soss.common.core.domain.model.LoginUser;
import com.soss.common.enums.CouponUserState;
import com.soss.common.enums.MachineState;
import com.soss.common.exception.ServiceException;
import com.soss.common.utils.StringUtils;
......@@ -55,6 +56,8 @@ public class OrderServiceImpl implements IOrderService {
@Autowired
private ShopMapper shopMapper;
@Autowired
private CouponUserMapper couponUserMapper;
@Autowired
private OrderOperationLogServiceImpl orderOperationLogService;
@Autowired
private OrderSnapshotServiceImpl orderSnapshotService;
......@@ -81,7 +84,7 @@ public class OrderServiceImpl implements IOrderService {
* @return 订单
*/
@Override
public Order selectOrderById(String id) {
public Order selectOrderById(Long id) {
Order order = orderMapper.selectOrderById(id);
order.setShop(shopMapper.selectShopById(order.getShopId()));
OrderSnapshot orderSnapshot = orderSnapshotService.selectOrderSnapshotByOrderId(order.getId());
......@@ -91,7 +94,7 @@ public class OrderServiceImpl implements IOrderService {
return order;
}
public Order selectById(String id) {
public Order selectById(Long id) {
return orderMapper.selectOrderById(id);
}
......@@ -121,11 +124,17 @@ public class OrderServiceImpl implements IOrderService {
*
* @param loginUser
* @param order 订单
* @param couponUserId
* @return 结果
*/
@Override
@Transactional
public AjaxResult insertOrder(LoginUser loginUser, Order order) {
public AjaxResult insertOrder(LoginUser loginUser, Order order, Integer couponUserId) {
if (couponUserId != null) {
CouponUser couponUser = new CouponUser(couponUserId, CouponUserState.USED.getState());
couponUserMapper.updateCouponUser(couponUser);
}
order.setState(OrderStatusConstant.Unpaid);
order.setUserId(loginUser.getOpenId());
order.setUserName(loginUser.getUsername());
......@@ -329,9 +338,6 @@ public class OrderServiceImpl implements IOrderService {
wechatMessageService.insertWechatMessage(order.getUserId(), order.getId(), "制作完成,您的订单已经制作完成,现在可以去取餐啦!");
if (BooleanUtils.isTrue(order.getSendMsgFlag2())) {
sendMessageUtils.sendWxMsg(order);
}
Customer customer = customerMapper.selectCustomerById(order.getUserId());
if (!"1".equals(customer.getAllow())) {
sendSmsUtil.sendSms(order.getUserPhone(), "SMS_243650242", null);
}
}
......@@ -375,28 +381,6 @@ public class OrderServiceImpl implements IOrderService {
}
}
/**
* 批量删除订单
*
* @param ids 需要删除的订单主键
* @return 结果
*/
@Override
public int deleteOrderByIds(String[] ids) {
return orderMapper.deleteOrderByIds(ids);
}
/**
* 删除订单信息
*
* @param id 订单主键
* @return 结果
*/
@Override
public int deleteOrderById(String id) {
return orderMapper.deleteOrderById(id);
}
@Override
public AjaxResult check(Order order) {
//验证订单状态
......@@ -442,7 +426,7 @@ public class OrderServiceImpl implements IOrderService {
@Override
@Transactional
public int cancel(String orderId) {
public int cancel(Long orderId) {
Order order = orderMapper.selectOrderById(orderId);
if (OrderStatusConstant.Unpaid.equals(order.getState())) {
order.setState("8");
......@@ -544,7 +528,7 @@ public class OrderServiceImpl implements IOrderService {
}
public String refundOrder(String orderId) {
public String refundOrder(Long orderId) {
Order order = orderMapper.selectOrderById(orderId);
List<String> status = Arrays.asList("2", "3");
if (status.contains(order.getState())) {
......@@ -586,9 +570,7 @@ public class OrderServiceImpl implements IOrderService {
OrderDetail orderDetail = new OrderDetail();
orderDetail.setOrderId(order1.getId());
List<OrderDetail> orderDetails = orderDetailMapper.selectOrderDetailList(orderDetail);
if (CollectionUtils.isEmpty(orderDetails)) {
} else {
if (!CollectionUtils.isEmpty(orderDetails)) {
list.addAll(orderDetails);
}
}
......
package com.soss.system.service.impl;
import java.util.ArrayList;
import java.util.List;
import java.util.stream.Collectors;
import javax.validation.Validator;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.util.CollectionUtils;
import com.soss.common.annotation.DataScope;
import com.soss.common.constant.UserConstants;
import com.soss.common.core.domain.entity.SysRole;
......@@ -19,16 +9,24 @@ import com.soss.common.utils.SecurityUtils;
import com.soss.common.utils.StringUtils;
import com.soss.common.utils.bean.BeanValidators;
import com.soss.common.utils.spring.SpringUtils;
import com.soss.system.domain.SysPost;
import com.soss.system.domain.SysUserPost;
import com.soss.system.domain.SysUserRole;
import com.soss.system.mapper.SysPostMapper;
import com.soss.system.mapper.SysRoleMapper;
import com.soss.system.mapper.SysUserMapper;
import com.soss.system.mapper.SysUserPostMapper;
import com.soss.system.mapper.SysUserRoleMapper;
import com.soss.system.service.ISysConfigService;
import com.soss.system.service.ISysUserService;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.util.CollectionUtils;
import javax.validation.Validator;
import java.util.ArrayList;
import java.util.List;
import java.util.stream.Collectors;
/**
* 用户 业务层处理
......@@ -275,9 +273,9 @@ public class SysUserServiceImpl implements ISysUserService
*/
@Override
@Transactional
public int updateUser(SysUser user)
{
if(user.getRoles() ==null||user.getRoles().isEmpty()){
public int updateUser(SysUser user) {
// if(user.getRoles() ==null||user.getRoles().isEmpty()){
if (user.getRoleIds() == null || user.getRoleIds().length == 0) {
return userMapper.updateUser(user);
}
Long userId = user.getUserId();
......@@ -376,7 +374,7 @@ public class SysUserServiceImpl implements ISysUserService
if (StringUtils.isNotNull(roles))
{
// 新增用户与角色管理
List<SysUserRole> list = new ArrayList<SysUserRole>();
List<SysUserRole> list = new ArrayList<>();
for (Long roleId : roles)
{
SysUserRole ur = new SysUserRole();
......
......@@ -48,7 +48,7 @@ public class WechatMessageServiceImpl implements IWechatMessageService
for (WechatMessage message : wechatMessages) {
String[] split = message.getMessage().split(",");
message.setTitle(split[0]);
message.setTitle(split[1]);
message.setMessage(split[1]);
}
return wechatMessages;
}
......
......@@ -69,8 +69,8 @@
left join coupon_rule cr on c.rule_id = cr.id
where cu.cust_id = #{custId} and cr.use_start_time &lt; #{nowTime} and cu.expired_time > #{nowTime}
and cu.state = ${@com.soss.common.enums.CouponUserState @EFFECTIVE.getState}
<if test="couponId != null">
and c.id = #{couponId}
<if test="couponUserId != null">
and cu.id = #{couponUserId}
</if>
</sql>
......
<?xml version="1.0" encoding="UTF-8" ?>
<!DOCTYPE mapper
PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
"http://mybatis.org/dtd/mybatis-3-mapper.dtd">
PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
"http://mybatis.org/dtd/mybatis-3-mapper.dtd">
<mapper namespace="com.soss.system.mapper.CustomerMapper">
<resultMap type="Customer" id="CustomerResult">
......@@ -13,10 +13,14 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
<result property="sex" column="sex"/>
<result property="birthday" column="birthday"/>
<result property="soucre" column="soucre"/>
<result property="sendMsgFlag1" column="send_msg_flag1"/>
<result property="sendMsgFlag2" column="send_msg_flag2"/>
<result property="sendMsgFlag3" column="send_msg_flag3"/>
<result property="flagExpireDate" column="flag_expire_date"/>
</resultMap>
<sql id="selectCustomerVo">
select id, user_name, phone, create_time, head_sculpture_path, sex, birthday, soucre from customer
select * from customer
</sql>
<select id="selectCustomerList" parameterType="Customer" resultMap="CustomerResult">
......@@ -45,6 +49,10 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
<if test="sex != null">sex,</if>
<if test="birthday != null">birthday,</if>
<if test="soucre != null">soucre,</if>
<if test="sendMsgFlag1 != null">send_msg_flag1,</if>
<if test="sendMsgFlag2 != null">send_msg_flag2,</if>
<if test="sendMsgFlag3 != null">send_msg_flag3,</if>
<if test="flagExpireDate != null">flag_expire_date,</if>
</trim>
<trim prefix="values (" suffix=")" suffixOverrides=",">
<if test="id != null">#{id},</if>
......@@ -55,6 +63,10 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
<if test="sex != null">#{sex},</if>
<if test="birthday != null">#{birthday},</if>
<if test="soucre != null">#{soucre},</if>
<if test="sendMsgFlag1 != null">#{sendMsgFlag1},</if>
<if test="sendMsgFlag2 != null">#{sendMsgFlag2},</if>
<if test="sendMsgFlag3 != null">#{sendMsgFlag3},</if>
<if test="flagExpireDate != null">#{flagExpireDate},</if>
</trim>
</insert>
......@@ -68,10 +80,20 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
<if test="birthday != null">birthday = #{birthday},</if>
<if test="soucre != null">soucre = #{soucre},</if>
<if test="allow != null">allow = #{soucre},</if>
<if test="sendMsgFlag1 != null">send_msg_flag1 = #{sendMsgFlag1},</if>
<if test="sendMsgFlag2 != null">send_msg_flag2 = #{sendMsgFlag2},</if>
<if test="sendMsgFlag3 != null">send_msg_flag3 = #{sendMsgFlag3},</if>
<if test="flagExpireDate != null">flag_expire_date = #{flagExpireDate},</if>
</trim>
where id = #{id}
</update>
<update id="updateSendMsgFlag">
update customer set send_msg_flag1 = #{sendMsgFlag1}, send_msg_flag2 = #{sendMsgFlag2},
send_msg_flag3 = #{sendMsgFlag3}, flag_expire_date = #{flagExpireDate}
where id = #{id}
</update>
<delete id="deleteCustomerById" parameterType="Long">
delete from customer where id = #{id}
</delete>
......
......@@ -20,7 +20,7 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
</sql>
<select id="selectSkuListForOrder" resultMap="GoodsSkuResult">
select id, goods_id, discount from goods_sku where id in
select id, goods_id, price, discount from goods_sku where id in
<foreach collection="ids" item="id" separator="," open="(" close=")">#{id}</foreach>
</select>
......
......@@ -11,7 +11,8 @@
<result property="goodsName" column="goods_name"/>
<result property="machineId" column="machine_id"/>
<result property="num" column="num"/>
<result property="viewAmount" column="view_amount"/>
<result property="unitPrice" column="unit_price"/>
<result property="oriAmount" column="ori_amount"/>
<result property="amountShould" column="amount_should"/>
<result property="couponAmount" column="coupon_amount"/>
<result property="realAmount" column="real_amount"/>
......@@ -37,7 +38,8 @@
<if test="goodsName != null and goodsName != ''">and goods_name like concat('%', #{goodsName}, '%')</if>
<if test="machineId != null and machineId != ''">and machine_id = #{machineId}</if>
<if test="num != null and num != ''">and num = #{num}</if>
<if test="viewAmount != null ">and view_amount = #{viewAmount}</if>
<if test="oriAmount != null ">and ori_amount = #{oriAmount}</if>
<if test="unitPrice != null ">and unit_price = #{unitPrice}</if>
<if test="amountShould != null ">and amount_should = #{amountShould}</if>
<if test="couponAmount != null ">and coupon_amount = #{couponAmount}</if>
<if test="realAmount != null ">and real_amount = #{realAmount}</if>
......@@ -71,7 +73,8 @@
<if test="goodsName != null and goodsName != ''">goods_name,</if>
<if test="machineId != null and machineId != ''">machine_id,</if>
<if test="num != null and num != ''">num,</if>
<if test="viewAmount != null">view_amount,</if>
<if test="unitPrice != null">unit_price,</if>
<if test="oriAmount != null">ori_amount,</if>
<if test="amountShould != null">amount_should,</if>
<if test="couponAmount != null">coupon_amount,</if>
<if test="realAmount != null">real_amount,</if>
......@@ -90,7 +93,8 @@
<if test="goodsName != null and goodsName != ''">#{goodsName},</if>
<if test="machineId != null and machineId != ''">#{machineId},</if>
<if test="num != null and num != ''">#{num},</if>
<if test="viewAmount != null">#{viewAmount},</if>
<if test="unitPrice != null">#{unitPrice},</if>
<if test="oriAmount != null">#{oriAmount},</if>
<if test="amountShould != null">#{amountShould},</if>
<if test="couponAmount != null">#{couponAmount},</if>
<if test="realAmount != null">#{realAmount},</if>
......@@ -113,7 +117,8 @@
<if test="goodsName != null and goodsName != ''">goods_name = #{goodsName},</if>
<if test="machineId != null and machineId != ''">machine_id = #{machineId},</if>
<if test="num != null and num != ''">num = #{num},</if>
<if test="viewAmount != null">view_amount = #{viewAmount},</if>
<if test="unitPrice != null">unit_price = #{unitPrice},</if>
<if test="oriAmount != null">ori_amount = #{oriAmount},</if>
<if test="amountShould != null">amount_should = #{amountShould},</if>
<if test="couponAmount != null">coupon_amount = #{couponAmount},</if>
<if test="realAmount != null">real_amount = #{realAmount},</if>
......
......@@ -67,7 +67,7 @@
</where>
</select>
<select id="selectOrderById" parameterType="String" resultMap="OrderResult">
<select id="selectOrderById" parameterType="Long" resultMap="OrderResult">
<include refid="selectOrderVo"/>
where id = #{id}
</select>
......@@ -116,6 +116,8 @@
<if test="pickCode != null and pickCode != ''">#{pickCode},</if>
<if test="shopId != null and shopId != ''">#{shopId},</if>
<if test="machineId != null and machineId != ''">#{machineId},</if>
<if test="lng != null">#{lng},</if>
<if test="lat != null">#{lat},</if>
<if test="source != null and source != ''">#{source},</if>
<if test="state != null and state != ''">#{state},</if>
<if test="sendMsgFlag1 != null">#{sendMsgFlag1},</if>
......
......@@ -24,9 +24,9 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
<select id="selectOrderRefundList" parameterType="OrderRefund" resultMap="OrderRefundResult">
<include refid="selectOrderRefundVo"/>
<where>
<if test="orderId != null and orderId != ''"> and order_id = #{orderId}</if>
<if test="orderId != null"> and order_id = #{orderId}</if>
<if test="refundAmount != null "> and refund_amount = #{refundAmount}</if>
<if test="state != null and state != ''"> and state = #{state}</if>
<if test="state != null"> and state = #{state}</if>
<if test="desc != null and desc != ''"> and `desc` = #{desc}</if>
<if test="createdAt != null "> and created_at = #{createdAt}</if>
<if test="updatedAt != null "> and updated_at = #{updatedAt}</if>
......@@ -43,9 +43,9 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
<insert id="insertOrderRefund" parameterType="OrderRefund" useGeneratedKeys="true" keyProperty="id">
insert into order_refund
<trim prefix="(" suffix=")" suffixOverrides=",">
<if test="orderId != null and orderId != ''">order_id,</if>
<if test="orderId != null">order_id,</if>
<if test="refundAmount != null">refund_amount,</if>
<if test="state != null and state != ''">state,</if>
<if test="state != null">state,</if>
<if test="desc != null">`desc`,</if>
<if test="createdAt != null">created_at,</if>
<if test="updatedAt != null">updated_at,</if>
......@@ -54,9 +54,9 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
<if test="createUserName != null">create_user_name,</if>
</trim>
<trim prefix="values (" suffix=")" suffixOverrides=",">
<if test="orderId != null and orderId != ''">#{orderId},</if>
<if test="orderId != null">#{orderId},</if>
<if test="refundAmount != null">#{refundAmount},</if>
<if test="state != null and state != ''">#{state},</if>
<if test="state != null">#{state},</if>
<if test="desc != null">#{desc},</if>
<if test="createdAt != null">#{createdAt},</if>
<if test="updatedAt != null">#{updatedAt},</if>
......@@ -69,7 +69,7 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
<update id="updateOrderRefund" parameterType="OrderRefund">
update order_refund
<trim prefix="SET" suffixOverrides=",">
<if test="orderId != null and orderId != ''">order_id = #{orderId},</if>
<if test="orderId != null">order_id = #{orderId},</if>
<if test="refundAmount != null">refund_amount = #{refundAmount},</if>
<if test="state != null and state != ''">state = #{state},</if>
<if test="desc != null">`desc` = #{desc},</if>
......
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