| @@ -47,8 +47,8 @@ public class WxOrderController extends BaseController { | |||||
| return new ResultData(order); | return new ResultData(order); | ||||
| }catch (MallinkException e) { | }catch (MallinkException e) { | ||||
| logger.error(e.getMessage()); | logger.error(e.getMessage()); | ||||
| return new ResultData(e.getErrorCode(), e.getMessage()); | |||||
| } | } | ||||
| return new ResultData(); | |||||
| } | } | ||||
| @ApiOperation("取消订单") | @ApiOperation("取消订单") | ||||
| @@ -72,9 +72,10 @@ public enum ErrorCode{ | |||||
| * 订单 | * 订单 | ||||
| */ | */ | ||||
| REMAIN_IS_EMPTY(3000, "库存不足"), | REMAIN_IS_EMPTY(3000, "库存不足"), | ||||
| ORDER_IS_FAIL(3001, "订单创建失败"), | |||||
| ORDER_IS_NOT_FIND(3002, "订单不存在"), | |||||
| ORDER_IS_NOT_PAY(3003, "订单已不能进行支付"), | |||||
| ORDER_IS_LIMITED(3001, "购买超限"), | |||||
| ORDER_IS_FAIL(3002, "订单创建失败"), | |||||
| ORDER_IS_NOT_FIND(3003, "订单不存在"), | |||||
| ORDER_IS_NOT_PAY(3004, "订单已不能进行支付"), | |||||
| /** | /** | ||||
| * 微信 | * 微信 | ||||
| @@ -72,6 +72,9 @@ public class WxOrder implements Serializable { | |||||
| /*更新时间**/ | /*更新时间**/ | ||||
| @io.swagger.annotations.ApiModelProperty(value="更新时间",name="updateDate") | @io.swagger.annotations.ApiModelProperty(value="更新时间",name="updateDate") | ||||
| private Date updateDate; | private Date updateDate; | ||||
| /*支付描述,订单支付时用**/ | |||||
| @io.swagger.annotations.ApiModelProperty(value="支付描述,订单支付时用",name="detail") | |||||
| private String detail; | |||||
| public Long getOrderNumber() { | public Long getOrderNumber() { | ||||
| return orderNumber; | return orderNumber; | ||||
| } | } | ||||
| @@ -132,6 +135,12 @@ public class WxOrder implements Serializable { | |||||
| public void setUpdateDate(Date _updateDate) { | public void setUpdateDate(Date _updateDate) { | ||||
| updateDate = _updateDate; | updateDate = _updateDate; | ||||
| } | } | ||||
| public String getDetail() { | |||||
| return detail; | |||||
| } | |||||
| public void setDetail(String _detail) { | |||||
| detail = _detail; | |||||
| } | |||||
| @@ -148,6 +157,7 @@ public class WxOrder implements Serializable { | |||||
| ,OrderStatus_ASC("`orderStatus` ASC"),OrderStatus_DESC("`orderStatus` DESC") | ,OrderStatus_ASC("`orderStatus` ASC"),OrderStatus_DESC("`orderStatus` DESC") | ||||
| ,CreateDate_ASC("`createDate` ASC"),CreateDate_DESC("`createDate` DESC") | ,CreateDate_ASC("`createDate` ASC"),CreateDate_DESC("`createDate` DESC") | ||||
| ,UpdateDate_ASC("`updateDate` ASC"),UpdateDate_DESC("`updateDate` DESC") | ,UpdateDate_ASC("`updateDate` ASC"),UpdateDate_DESC("`updateDate` DESC") | ||||
| ,Detail_ASC("`detail` ASC"),Detail_DESC("`detail` DESC") | |||||
| ; | ; | ||||
| private String value; | private String value; | ||||
| Field(String value){ | Field(String value){ | ||||
| @@ -87,22 +87,43 @@ public class WxOrderServiceImpl implements WxOrderService { | |||||
| Date curr = new Date(); | Date curr = new Date(); | ||||
| Date valid_date = null; | Date valid_date = null; | ||||
| // 检查 优惠券 库存 | |||||
| if (coupon.getRemainInventory() <= 0) { | |||||
| //解锁 | |||||
| redisLock.unlock(couponIdStr, timeStr); | |||||
| logger.error("此券库存为0, couponId: " + couponIdStr); | |||||
| throw new MallinkException(ErrorCode.REMAIN_IS_EMPTY); | |||||
| } | |||||
| // check 购买是否超限 | |||||
| try { | try { | ||||
| // 检查 优惠券 库存 | |||||
| if (coupon.getRemainInventory() <= 0) { | |||||
| WxCouponOrder query = new WxCouponOrder(); | |||||
| query.setCouponId(couponId); | |||||
| query.setCouponOrderStatus(EnumCouponOrderStatus.COUPON_ORDER_USE_WAIT.getCode()); | |||||
| List<WxCouponOrder> list = wxCouponOrderMapper.findList(query); | |||||
| if (list.size() >= coupon.getUseLimitQuantity()) { | |||||
| //解锁 | //解锁 | ||||
| redisLock.unlock(couponIdStr, timeStr); | redisLock.unlock(couponIdStr, timeStr); | ||||
| logger.error("此券库存为0, couponId: " + couponIdStr); | |||||
| throw new MallinkException(ErrorCode.REMAIN_IS_EMPTY); | |||||
| throw new MallinkException(ErrorCode.ORDER_IS_LIMITED); | |||||
| } | } | ||||
| }catch (Exception e) { | |||||
| //解锁 | |||||
| redisLock.unlock(couponIdStr, timeStr); | |||||
| logger.error("此券购买数量检查出问题了, couponId: " + couponIdStr); | |||||
| throw new MallinkException(ErrorCode.ORDER_IS_FAIL); | |||||
| } | |||||
| try { | |||||
| // 减库存 | // 减库存 | ||||
| coupon.setRemainInventory(coupon.getRemainInventory() - 1); | coupon.setRemainInventory(coupon.getRemainInventory() - 1); | ||||
| wxCouponMapper.updateByPrimaryKeySelective(coupon); | wxCouponMapper.updateByPrimaryKeySelective(coupon); | ||||
| //解锁 | |||||
| redisLock.unlock(couponIdStr, timeStr); | |||||
| } catch (RuntimeException e) { | } catch (RuntimeException e) { | ||||
| //解锁 | //解锁 | ||||
| redisLock.unlock(couponIdStr, timeStr); | redisLock.unlock(couponIdStr, timeStr); | ||||
| logger.error("此券减库存失败, couponId: " + couponIdStr); | logger.error("此券减库存失败, couponId: " + couponIdStr); | ||||
| throw new MallinkException(ErrorCode.ORDER_IS_FAIL); | throw new MallinkException(ErrorCode.ORDER_IS_FAIL); | ||||
| } | } | ||||
| @@ -118,6 +139,10 @@ public class WxOrderServiceImpl implements WxOrderService { | |||||
| WxOrder record = new WxOrder(); | WxOrder record = new WxOrder(); | ||||
| // body | |||||
| // tenant_id + merchant_id + title + subtitle | |||||
| try { | try { | ||||
| // 保存订单 | // 保存订单 | ||||
| record.setId(orderNumber); | record.setId(orderNumber); | ||||
| @@ -13,10 +13,11 @@ | |||||
| <result column="order_status" jdbcType="INTEGER" property="orderStatus" /> | <result column="order_status" jdbcType="INTEGER" property="orderStatus" /> | ||||
| <result column="create_date" jdbcType="TIMESTAMP" property="createDate" /> | <result column="create_date" jdbcType="TIMESTAMP" property="createDate" /> | ||||
| <result column="update_date" jdbcType="TIMESTAMP" property="updateDate" /> | <result column="update_date" jdbcType="TIMESTAMP" property="updateDate" /> | ||||
| <result column="detail" jdbcType="VARCHAR" property="detail" /> | |||||
| </resultMap> | </resultMap> | ||||
| <sql id="allColumns"> | <sql id="allColumns"> | ||||
| `id`,`order_number`,`tenant_id`,`c_user_id`,`b_user_id`,`payment_type`,`payment`,`payment_time`,`order_status`,`create_date`,`update_date` | |||||
| `id`,`order_number`,`tenant_id`,`c_user_id`,`b_user_id`,`payment_type`,`payment`,`payment_time`,`order_status`,`create_date`,`update_date`,`detail` | |||||
| </sql> | </sql> | ||||
| <sql id="dynamicWhereConditions"> | <sql id="dynamicWhereConditions"> | ||||
| @@ -75,6 +76,11 @@ | |||||
| <if test=" null != updateDate "> | <if test=" null != updateDate "> | ||||
| and `update_date` = #{updateDate} | and `update_date` = #{updateDate} | ||||
| </if> | |||||
| <if test=" null != detail "> | |||||
| and `detail` like concat('%', #{detail},'%') | |||||
| </if> | </if> | ||||
| <if test=" null != ids "> | <if test=" null != ids "> | ||||
| and id in | and id in | ||||