1.代客下单会员余额支付
This commit is contained in:
@@ -2,7 +2,7 @@ package com.chaozhanggui.system.cashierservice.bean;
|
|||||||
|
|
||||||
public enum TableStateEnum {
|
public enum TableStateEnum {
|
||||||
IDLE("idle"),
|
IDLE("idle"),
|
||||||
CLOSED("closed"), PAYING("paying"), PENDING("pending");
|
CLOSED("closed"), PAYING("paying"), PENDING("pending"), USING("using");
|
||||||
private String state = "closed";
|
private String state = "closed";
|
||||||
|
|
||||||
TableStateEnum(String state) {
|
TableStateEnum(String state) {
|
||||||
|
|||||||
@@ -198,6 +198,26 @@ public class PayController {
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 会员支付
|
||||||
|
* @param token
|
||||||
|
* @param loginName
|
||||||
|
* @param clientType
|
||||||
|
* @param orderId
|
||||||
|
* @return
|
||||||
|
*/
|
||||||
|
@GetMapping("vipPay")
|
||||||
|
@LimitSubmit(key = "vipPay:%s")
|
||||||
|
public Result vipPay(@RequestHeader("token") String token,
|
||||||
|
@RequestHeader("loginName") String loginName,
|
||||||
|
@RequestHeader("clientType") String clientType,
|
||||||
|
@RequestParam("orderId") String orderId,
|
||||||
|
@RequestParam("vipUserId") Integer vipUserId){
|
||||||
|
return payService.vipPay(orderId,token, vipUserId);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|||||||
@@ -102,6 +102,8 @@ public class TbOrderInfo implements Serializable {
|
|||||||
|
|
||||||
private Integer staffId;
|
private Integer staffId;
|
||||||
|
|
||||||
|
private String useType;
|
||||||
|
|
||||||
private static final long serialVersionUID = 1L;
|
private static final long serialVersionUID = 1L;
|
||||||
public TbOrderInfo(){
|
public TbOrderInfo(){
|
||||||
super();
|
super();
|
||||||
@@ -166,4 +168,4 @@ public class TbOrderInfo implements Serializable {
|
|||||||
this.payType=payType;
|
this.payType=payType;
|
||||||
this.tableName=tableName;
|
this.tableName=tableName;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -0,0 +1,7 @@
|
|||||||
|
package com.chaozhanggui.system.cashierservice.mybatis;
|
||||||
|
|
||||||
|
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
|
||||||
|
import com.chaozhanggui.system.cashierservice.entity.TbShopUserFlow;
|
||||||
|
|
||||||
|
public interface MpShopUserFlowMapper extends BaseMapper<TbShopUserFlow> {
|
||||||
|
}
|
||||||
@@ -0,0 +1,13 @@
|
|||||||
|
package com.chaozhanggui.system.cashierservice.mybatis;
|
||||||
|
|
||||||
|
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
|
||||||
|
import com.chaozhanggui.system.cashierservice.entity.TbShopUser;
|
||||||
|
import org.apache.ibatis.annotations.Param;
|
||||||
|
import org.apache.ibatis.annotations.Update;
|
||||||
|
|
||||||
|
import java.math.BigDecimal;
|
||||||
|
|
||||||
|
public interface MpShopUserMapper extends BaseMapper<TbShopUser> {
|
||||||
|
@Update("update tb_shop_user set amount=amount-#{orderAmount}, consume_amount=consume_amount+#{orderAmount} where id=#{vipUserId} and amount >= 0")
|
||||||
|
long decrBalance(@Param("vipUserId") Integer vipUserId, @Param("orderAmount") BigDecimal orderAmount);
|
||||||
|
}
|
||||||
@@ -591,6 +591,9 @@ public class OrderService {
|
|||||||
orderInfo.setMasterId(masterId);
|
orderInfo.setMasterId(masterId);
|
||||||
orderInfo.setRemark(orderVo.getRemark());
|
orderInfo.setRemark(orderVo.getRemark());
|
||||||
orderInfo.setUserId(orderVo.getUserId());
|
orderInfo.setUserId(orderVo.getUserId());
|
||||||
|
if (StrUtil.isNotBlank(orderVo.getTableId())) {
|
||||||
|
orderInfo.setTableId(orderVo.getTableId());
|
||||||
|
}
|
||||||
if (Objects.nonNull(tbToken)){
|
if (Objects.nonNull(tbToken)){
|
||||||
orderInfo.setTokenId(tbToken.getId());
|
orderInfo.setTokenId(tbToken.getId());
|
||||||
}
|
}
|
||||||
@@ -661,6 +664,9 @@ public class OrderService {
|
|||||||
redisUtil.deleteByKey("SHOP:CODE:USER:" + clientType + ":" + orderVo.getShopId() + ":" + day + orderVo.getUserId());
|
redisUtil.deleteByKey("SHOP:CODE:USER:" + clientType + ":" + orderVo.getShopId() + ":" + day + orderVo.getUserId());
|
||||||
// 代课下单
|
// 代课下单
|
||||||
if (!StrUtil.isBlank(orderVo.getTableId())) {
|
if (!StrUtil.isBlank(orderVo.getTableId())) {
|
||||||
|
mpShopTableMapper.update(null, new LambdaUpdateWrapper<TbShopTable>()
|
||||||
|
.eq(TbShopTable::getQrcode, orderInfo.getTableId())
|
||||||
|
.set(TbShopTable::getStatus, TableStateEnum.USING.getState()));
|
||||||
producer.printMechine(String.valueOf(orderInfo.getId()));
|
producer.printMechine(String.valueOf(orderInfo.getId()));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,8 +1,10 @@
|
|||||||
package com.chaozhanggui.system.cashierservice.service;
|
package com.chaozhanggui.system.cashierservice.service;
|
||||||
|
|
||||||
|
import cn.hutool.core.date.DateUtil;
|
||||||
import cn.hutool.core.util.ObjectUtil;
|
import cn.hutool.core.util.ObjectUtil;
|
||||||
import cn.hutool.json.JSONUtil;
|
import cn.hutool.json.JSONUtil;
|
||||||
import com.alibaba.fastjson.JSONObject;
|
import com.alibaba.fastjson.JSONObject;
|
||||||
|
import com.baomidou.mybatisplus.core.conditions.update.LambdaUpdateWrapper;
|
||||||
import com.chaozhanggui.system.cashierservice.dao.*;
|
import com.chaozhanggui.system.cashierservice.dao.*;
|
||||||
import com.chaozhanggui.system.cashierservice.entity.*;
|
import com.chaozhanggui.system.cashierservice.entity.*;
|
||||||
import com.chaozhanggui.system.cashierservice.entity.dto.ReturnGroupOrderDto;
|
import com.chaozhanggui.system.cashierservice.entity.dto.ReturnGroupOrderDto;
|
||||||
@@ -11,6 +13,8 @@ import com.chaozhanggui.system.cashierservice.exception.MsgException;
|
|||||||
import com.chaozhanggui.system.cashierservice.model.ReturnOrderReq;
|
import com.chaozhanggui.system.cashierservice.model.ReturnOrderReq;
|
||||||
import com.chaozhanggui.system.cashierservice.model.ScanPayReq;
|
import com.chaozhanggui.system.cashierservice.model.ScanPayReq;
|
||||||
import com.chaozhanggui.system.cashierservice.model.TradeQueryReq;
|
import com.chaozhanggui.system.cashierservice.model.TradeQueryReq;
|
||||||
|
import com.chaozhanggui.system.cashierservice.mybatis.MpShopUserFlowMapper;
|
||||||
|
import com.chaozhanggui.system.cashierservice.mybatis.MpShopUserMapper;
|
||||||
import com.chaozhanggui.system.cashierservice.rabbit.RabbitProducer;
|
import com.chaozhanggui.system.cashierservice.rabbit.RabbitProducer;
|
||||||
import com.chaozhanggui.system.cashierservice.sign.CodeEnum;
|
import com.chaozhanggui.system.cashierservice.sign.CodeEnum;
|
||||||
import com.chaozhanggui.system.cashierservice.sign.Result;
|
import com.chaozhanggui.system.cashierservice.sign.Result;
|
||||||
@@ -118,6 +122,10 @@ public class PayService {
|
|||||||
|
|
||||||
@Autowired
|
@Autowired
|
||||||
TbPlussShopStaffMapper tbPlussShopStaffMapper;
|
TbPlussShopStaffMapper tbPlussShopStaffMapper;
|
||||||
|
@Autowired
|
||||||
|
private MpShopUserMapper mpShopUserMapper;
|
||||||
|
@Autowired
|
||||||
|
private MpShopUserFlowMapper mpShopUserFlowMapper;
|
||||||
|
|
||||||
|
|
||||||
public static void main(String[] args) {
|
public static void main(String[] args) {
|
||||||
@@ -710,6 +718,82 @@ public class PayService {
|
|||||||
return Result.success(CodeEnum.SUCCESS);
|
return Result.success(CodeEnum.SUCCESS);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public Result vipPay(String orderId, String token, Integer vipUserId) {
|
||||||
|
if (ObjectUtil.isEmpty(orderId)) {
|
||||||
|
return Result.fail(CodeEnum.PARAM);
|
||||||
|
}
|
||||||
|
|
||||||
|
TbOrderInfo orderInfo = tbOrderInfoMapper.selectByPrimaryKey(Integer.valueOf(orderId));
|
||||||
|
|
||||||
|
if (ObjectUtil.isEmpty(orderInfo)) {
|
||||||
|
return Result.fail(CodeEnum.ORDERNOEXIST);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!"unpaid".equals(orderInfo.getStatus())) {
|
||||||
|
return Result.fail(CodeEnum.ORDERSTATUSERROR);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
int count = tbShopPayTypeMapper.countSelectByShopIdAndPayType(orderInfo.getShopId(), "cash");
|
||||||
|
if (count < 1) {
|
||||||
|
return Result.fail(CodeEnum.PAYTYPENOEXIST);
|
||||||
|
}
|
||||||
|
|
||||||
|
// 扣减会员余额
|
||||||
|
TbShopUser shopUser = mpShopUserMapper.selectOne(new LambdaUpdateWrapper<TbShopUser>()
|
||||||
|
.eq(TbShopUser::getStatus, 1)
|
||||||
|
.eq(TbShopUser::getId, vipUserId));
|
||||||
|
|
||||||
|
if (shopUser == null) {
|
||||||
|
return Result.fail("用户不存在或已被禁用");
|
||||||
|
}
|
||||||
|
|
||||||
|
long flag = mpShopUserMapper.decrBalance(vipUserId, orderInfo.getOrderAmount());
|
||||||
|
if (flag < 1) {
|
||||||
|
return Result.fail("余额不足或扣除余额失败");
|
||||||
|
}
|
||||||
|
|
||||||
|
TbShopUserFlow userFlow = new TbShopUserFlow();
|
||||||
|
userFlow.setAmount(orderInfo.getOrderAmount());
|
||||||
|
userFlow.setBalance(shopUser.getAmount());
|
||||||
|
userFlow.setShopUserId(shopUser.getId());
|
||||||
|
userFlow.setBizCode("vipCardCash");
|
||||||
|
userFlow.setBizName("代客下单会员余额支付");
|
||||||
|
userFlow.setCreateTime(DateUtil.date());
|
||||||
|
userFlow.setType("-");
|
||||||
|
mpShopUserFlowMapper.insert(userFlow);
|
||||||
|
|
||||||
|
|
||||||
|
orderInfo.setPayAmount(orderInfo.getOrderAmount());
|
||||||
|
orderInfo.setPayType("cash");
|
||||||
|
orderInfo.setStatus("closed");
|
||||||
|
orderInfo.setPayOrderNo("cash".concat(SnowFlakeUtil.generateOrderNo()));
|
||||||
|
tbOrderInfoMapper.updateByPrimaryKeySelective(orderInfo);
|
||||||
|
//更新购物车状态
|
||||||
|
int cartCount = tbCashierCartMapper.updateByOrderId(orderId, "final");
|
||||||
|
|
||||||
|
tbOrderDetailMapper.updateStatusByOrderIdAndStatus(Integer.valueOf(orderId), "closed");
|
||||||
|
log.info("更新购物车:{}", cartCount);
|
||||||
|
|
||||||
|
JSONObject jsonObject = new JSONObject();
|
||||||
|
jsonObject.put("token", token);
|
||||||
|
jsonObject.put("type", "create");
|
||||||
|
jsonObject.put("orderId", orderId);
|
||||||
|
|
||||||
|
producer.putOrderCollect(jsonObject.toJSONString());
|
||||||
|
|
||||||
|
|
||||||
|
producer.printMechine(orderId);
|
||||||
|
|
||||||
|
// 发送库存记录mq消息
|
||||||
|
JSONObject mqData = new JSONObject();
|
||||||
|
mqData.put("orderId", orderId);
|
||||||
|
mqData.put("type", "pc");
|
||||||
|
producer.sendStockSaleMsg(mqData);
|
||||||
|
|
||||||
|
return Result.success(CodeEnum.SUCCESS);
|
||||||
|
}
|
||||||
|
|
||||||
@Transactional(rollbackFor = Exception.class)
|
@Transactional(rollbackFor = Exception.class)
|
||||||
public Result cashPay(String orderId, String token,BigDecimal payAmount,BigDecimal discountAmount) {
|
public Result cashPay(String orderId, String token,BigDecimal payAmount,BigDecimal discountAmount) {
|
||||||
if (ObjectUtil.isEmpty(orderId)) {
|
if (ObjectUtil.isEmpty(orderId)) {
|
||||||
|
|||||||
@@ -47,6 +47,7 @@
|
|||||||
<result column="master_id" jdbcType="VARCHAR" property="masterId"/>
|
<result column="master_id" jdbcType="VARCHAR" property="masterId"/>
|
||||||
<result column="table_name" jdbcType="VARCHAR" property="tableName"/>
|
<result column="table_name" jdbcType="VARCHAR" property="tableName"/>
|
||||||
<result column="out_number" jdbcType="VARCHAR" property="outNumber"/>
|
<result column="out_number" jdbcType="VARCHAR" property="outNumber"/>
|
||||||
|
<result column="use_type" jdbcType="VARCHAR" property="useType"/>
|
||||||
|
|
||||||
|
|
||||||
</resultMap>
|
</resultMap>
|
||||||
@@ -56,7 +57,7 @@
|
|||||||
discount_amount, table_id, small_change, send_type, order_type, product_type, status,
|
discount_amount, table_id, small_change, send_type, order_type, product_type, status,
|
||||||
billing_id, merchant_id, shop_id, is_vip, member_id, user_id, product_score, deduct_score,
|
billing_id, merchant_id, shop_id, is_vip, member_id, user_id, product_score, deduct_score,
|
||||||
user_coupon_id, user_coupon_amount, refund_able, paid_time, is_effect, is_group,
|
user_coupon_id, user_coupon_amount, refund_able, paid_time, is_effect, is_group,
|
||||||
updated_at, `system_time`, created_at, is_accepted, pay_order_no,trade_day,`source`,remark,master_id,`table_name`,out_number
|
updated_at, `system_time`, created_at, is_accepted, pay_order_no,trade_day,`source`,remark,master_id,`table_name`,out_number, use_type
|
||||||
</sql>
|
</sql>
|
||||||
<select id="selectByPrimaryKey" parameterType="java.lang.Integer" resultMap="BaseResultMap">
|
<select id="selectByPrimaryKey" parameterType="java.lang.Integer" resultMap="BaseResultMap">
|
||||||
select
|
select
|
||||||
|
|||||||
Reference in New Issue
Block a user