添加会员支付
This commit is contained in:
@@ -210,9 +210,12 @@ public class LoginContoller {
|
||||
* @param id
|
||||
* @return
|
||||
*/
|
||||
@RequestMapping("createCardNo")
|
||||
public Result createCardNo(@RequestHeader("openId") String openId, @RequestHeader("token") String token, @RequestHeader("id") String id) {
|
||||
return loginService.createCardNo(id, openId);
|
||||
@GetMapping("createCardNo")
|
||||
public Result createCardNo(@RequestHeader("openId") String openId, @RequestHeader("token") String token, @RequestHeader("id") String id,
|
||||
|
||||
@RequestParam("shopId") String shopId
|
||||
) {
|
||||
return loginService.createCardNo(id, openId,shopId);
|
||||
}
|
||||
|
||||
@GetMapping("/wx/userInfo")
|
||||
|
||||
@@ -46,6 +46,17 @@ public class PayController {
|
||||
}
|
||||
|
||||
|
||||
//
|
||||
// public Result memberAccountPay(@RequestHeader("openId") String openId,
|
||||
// @RequestParam("orderId") String orderId,
|
||||
// @RequestParam("userId") Integer userId,
|
||||
// @RequestParam("shopId") String shopId,
|
||||
// @RequestParam("pwd") String pwd
|
||||
// ){
|
||||
//
|
||||
// }
|
||||
|
||||
|
||||
/**
|
||||
* 修改订单状态
|
||||
* @param map
|
||||
|
||||
@@ -1,7 +1,12 @@
|
||||
package com.chaozhanggui.system.cashierservice.dao;
|
||||
|
||||
import com.chaozhanggui.system.cashierservice.entity.TbShopPayType;
|
||||
import org.apache.ibatis.annotations.Mapper;
|
||||
import org.apache.ibatis.annotations.Param;
|
||||
import org.springframework.stereotype.Component;
|
||||
|
||||
@Component
|
||||
@Mapper
|
||||
public interface TbShopPayTypeMapper {
|
||||
int deleteByPrimaryKey(Integer id);
|
||||
|
||||
@@ -14,4 +19,6 @@ public interface TbShopPayTypeMapper {
|
||||
int updateByPrimaryKeySelective(TbShopPayType record);
|
||||
|
||||
int updateByPrimaryKey(TbShopPayType record);
|
||||
|
||||
int countSelectByShopIdAndPayType(@Param("shopId") String shopId, @Param("payType") String payType );
|
||||
}
|
||||
@@ -42,6 +42,13 @@ public class TbShopUser implements Serializable {
|
||||
|
||||
private String code;
|
||||
|
||||
|
||||
private String dynamicCode;
|
||||
|
||||
private String isPwd;
|
||||
|
||||
private String pwd;
|
||||
|
||||
private Byte isAttention;
|
||||
|
||||
private Integer attentionAt;
|
||||
@@ -214,6 +221,30 @@ public class TbShopUser implements Serializable {
|
||||
this.code = code == null ? null : code.trim();
|
||||
}
|
||||
|
||||
public String getDynamicCode() {
|
||||
return dynamicCode;
|
||||
}
|
||||
|
||||
public void setDynamicCode(String dynamicCode) {
|
||||
this.dynamicCode = dynamicCode;
|
||||
}
|
||||
|
||||
public String getIsPwd() {
|
||||
return isPwd;
|
||||
}
|
||||
|
||||
public void setIsPwd(String isPwd) {
|
||||
this.isPwd = isPwd;
|
||||
}
|
||||
|
||||
public String getPwd() {
|
||||
return pwd;
|
||||
}
|
||||
|
||||
public void setPwd(String pwd) {
|
||||
this.pwd = pwd;
|
||||
}
|
||||
|
||||
public Byte getIsAttention() {
|
||||
return isAttention;
|
||||
}
|
||||
|
||||
@@ -122,6 +122,7 @@ public class LoginService {
|
||||
tbShopUser.setShopId(tbShopInfo.getId().toString());
|
||||
tbShopUser.setUserId(userInfo.getId().toString());
|
||||
tbShopUser.setMiniOpenId(openId);
|
||||
tbShopUser.setIsPwd("1");
|
||||
tbShopUser.setCreatedAt(System.currentTimeMillis());
|
||||
tbShopUser.setUpdatedAt(System.currentTimeMillis());
|
||||
tbShopUserMapper.insert(tbShopUser);
|
||||
@@ -250,12 +251,11 @@ public class LoginService {
|
||||
return Result.fail("登录失败");
|
||||
}
|
||||
|
||||
public Result createCardNo(String id, String openId) {
|
||||
public Result createCardNo(String id, String openId,String shopId) {
|
||||
if (ObjectUtil.isEmpty(id) || ObjectUtil.isEmpty(openId)) {
|
||||
return Result.fail("head 信息不允许为空");
|
||||
}
|
||||
|
||||
|
||||
TbUserInfo userInfo = tbUserInfoMapper.selectByPrimaryKey(Integer.valueOf(id));
|
||||
if (userInfo == null || ObjectUtil.isEmpty(userInfo)) {
|
||||
userInfo = tbUserInfoMapper.selectByOpenId(openId);
|
||||
@@ -265,12 +265,22 @@ public class LoginService {
|
||||
return Result.fail("用户信息不存在");
|
||||
}
|
||||
|
||||
String cardNo = RandomUtil.randomNumbers(10);
|
||||
userInfo.setCardNo(cardNo);
|
||||
userInfo.setUpdatedAt(System.currentTimeMillis());
|
||||
tbUserInfoMapper.updateByPrimaryKeySelective(userInfo);
|
||||
|
||||
return Result.success(CodeEnum.SUCCESS, cardNo);
|
||||
TbShopUser tbShopUser= tbShopUserMapper.selectByUserIdAndShopId(userInfo.getId().toString(),shopId);
|
||||
if(ObjectUtil.isEmpty(tbShopUser)||tbShopUser==null){
|
||||
return Result.fail("用户信息错误");
|
||||
}
|
||||
|
||||
String dynamicCode = RandomUtil.randomNumbers(8);
|
||||
dynamicCode= StringUtils.rightPad(tbShopUser.getId(),6,"0").concat(dynamicCode);
|
||||
|
||||
tbShopUser.setDynamicCode(dynamicCode);
|
||||
tbShopUser.setUpdatedAt(System.currentTimeMillis());
|
||||
tbShopUserMapper.updateByPrimaryKeySelective(tbShopUser);
|
||||
|
||||
|
||||
|
||||
return Result.success(CodeEnum.SUCCESS, dynamicCode);
|
||||
}
|
||||
|
||||
|
||||
|
||||
@@ -15,6 +15,7 @@ import com.chaozhanggui.system.cashierservice.sign.Result;
|
||||
import com.chaozhanggui.system.cashierservice.socket.AppWebSocketServer;
|
||||
import com.chaozhanggui.system.cashierservice.util.BeanUtil;
|
||||
import com.chaozhanggui.system.cashierservice.util.MD5Util;
|
||||
import com.chaozhanggui.system.cashierservice.util.N;
|
||||
import com.chaozhanggui.system.cashierservice.util.SnowFlakeUtil;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
@@ -54,6 +55,11 @@ public class PayService {
|
||||
TbOrderDetailMapper tbOrderDetailMapper;
|
||||
|
||||
|
||||
|
||||
@Autowired
|
||||
TbShopPayTypeMapper tbShopPayTypeMapper;
|
||||
|
||||
|
||||
@Value("${ysk.url}")
|
||||
private String url;
|
||||
|
||||
@@ -182,6 +188,100 @@ public class PayService {
|
||||
|
||||
|
||||
|
||||
@Transactional(rollbackFor = Exception.class)
|
||||
public Result accountPay(String orderId, String userId, String shopId,String pwd) {
|
||||
if (ObjectUtil.isEmpty(orderId) || ObjectUtil.isEmpty(userId)||ObjectUtil.isEmpty(shopId)||ObjectUtil.isEmpty(pwd)) {
|
||||
return Result.fail("参数错误");
|
||||
}
|
||||
|
||||
TbOrderInfo orderInfo = tbOrderInfoMapper.selectByPrimaryKey(Integer.valueOf(orderId));
|
||||
if (ObjectUtil.isEmpty(orderInfo)) {
|
||||
return Result.fail("订单信息不存在");
|
||||
}
|
||||
|
||||
|
||||
if (!"unpaid".equals(orderInfo.getStatus())) {
|
||||
return Result.fail("订单状态异常");
|
||||
}
|
||||
|
||||
|
||||
int count = tbShopPayTypeMapper.countSelectByShopIdAndPayType(orderInfo.getShopId(), "deposit");
|
||||
if (count < 1) {
|
||||
return Result.fail("当前店铺未开通储值卡支付");
|
||||
}
|
||||
|
||||
TbShopUser user = tbShopUserMapper.selectByUserIdAndShopId(userId,shopId);
|
||||
|
||||
if (ObjectUtil.isEmpty(user) || !"1".equals(user.getIsVip().toString())) {
|
||||
return Result.fail("此用户非会员用户");
|
||||
}
|
||||
|
||||
|
||||
if("1".equals(user.getIsPwd())){
|
||||
return Result.fail("会员支付密码为初始化密码");
|
||||
}
|
||||
|
||||
if(!MD5Util.encrypt(pwd).equals(user.getPwd())){
|
||||
return Result.fail("会员支付密码错误");
|
||||
}
|
||||
|
||||
if (N.gt(orderInfo.getPayAmount(), user.getAmount())) {
|
||||
return Result.fail("会员卡余额不足");
|
||||
}
|
||||
|
||||
user.setAmount(user.getAmount().subtract(orderInfo.getOrderAmount()));
|
||||
user.setConsumeAmount(user.getConsumeAmount().add(orderInfo.getPayAmount()));
|
||||
user.setConsumeNumber(user.getConsumeNumber() + 1);
|
||||
user.setUpdatedAt(System.currentTimeMillis());
|
||||
tbShopUserMapper.updateByPrimaryKeySelective(user);
|
||||
|
||||
|
||||
TbShopUserFlow flow = new TbShopUserFlow();
|
||||
flow.setShopUserId(Integer.valueOf(user.getId()));
|
||||
flow.setBizCode("accountPay");
|
||||
flow.setBizName("会员储值卡支付");
|
||||
flow.setAmount(orderInfo.getOrderAmount());
|
||||
flow.setBalance(user.getAmount());
|
||||
flow.setCreateTime(new Date());
|
||||
tbShopUserFlowMapper.insert(flow);
|
||||
|
||||
|
||||
orderInfo.setPayAmount(orderInfo.getOrderAmount());
|
||||
orderInfo.setMemberId(userId);
|
||||
orderInfo.setPayType("deposit");
|
||||
orderInfo.setStatus("closed");
|
||||
orderInfo.setPayOrderNo("deposit".concat(SnowFlakeUtil.generateOrderNo()));
|
||||
tbOrderInfoMapper.updateByPrimaryKeySelective(orderInfo);
|
||||
|
||||
|
||||
int cartCount= tbCashierCartMapper.updateStatusByOrderId(orderId.toString(),"final");
|
||||
|
||||
log.info("更新购物车:{}",cartCount);
|
||||
|
||||
//更新子单状态
|
||||
tbOrderDetailMapper.updateStatusByOrderIdAndStatus(Integer.valueOf(orderId),"closed");
|
||||
|
||||
//修改主单状态
|
||||
orderInfo.setStatus("closed");
|
||||
orderInfo.setPayType("deposit");
|
||||
orderInfo.setPayOrderNo(user.getDynamicCode());
|
||||
orderInfo.setPayAmount(orderInfo.getOrderAmount());
|
||||
tbOrderInfoMapper.updateByPrimaryKeySelective(orderInfo);
|
||||
|
||||
|
||||
JSONObject jsonObject=new JSONObject();
|
||||
jsonObject.put("token",0);
|
||||
jsonObject.put("type","wxcreate");
|
||||
jsonObject.put("orderId",orderInfo.getId().toString());
|
||||
|
||||
producer.putOrderCollect(jsonObject.toJSONString());
|
||||
|
||||
producer.printMechine(orderInfo.getId() + "");
|
||||
|
||||
return Result.success(CodeEnum.SUCCESS);
|
||||
}
|
||||
|
||||
|
||||
@Transactional(rollbackFor = Exception.class)
|
||||
public Result modifyOrderStatus(Integer orderId) throws IOException {
|
||||
TbOrderInfo orderInfo= tbOrderInfoMapper.selectByPrimaryKey(Integer.valueOf(orderId));
|
||||
@@ -289,10 +389,6 @@ public class PayService {
|
||||
return Result.fail("对应的用户信息不存在");
|
||||
}
|
||||
|
||||
if(ObjectUtil.isEmpty(tbShopUser.getIsVip())||!"1".equals(tbShopUser.getIsVip().toString())){
|
||||
return Result.fail("非会员用户不允许充值");
|
||||
}
|
||||
|
||||
|
||||
TbShopInfo shopInfo= tbShopInfoMapper.selectByPrimaryKey(Integer.valueOf(shopId));
|
||||
if(ObjectUtil.isEmpty(shopInfo)){
|
||||
@@ -311,7 +407,7 @@ public class PayService {
|
||||
TbMemberIn memberIn=new TbMemberIn();
|
||||
memberIn.setAmount(payAmount);
|
||||
memberIn.setUserId(Integer.valueOf(tbShopUser.getUserId()));
|
||||
memberIn.setCode(tbShopUser.getCode());
|
||||
memberIn.setCode(tbShopUser.getDynamicCode());
|
||||
memberIn.setShopId(shopInfo.getId());
|
||||
memberIn.setStatus("7");
|
||||
memberIn.setMerchantId(Integer.valueOf(shopInfo.getMerchantId()));
|
||||
@@ -414,6 +510,7 @@ public class PayService {
|
||||
}
|
||||
|
||||
//修改客户资金
|
||||
tbShopUser.setIsVip(Byte.parseByte("1"));
|
||||
tbShopUser.setAmount(tbShopUser.getAmount().add(memberIn.getAmount()));
|
||||
tbShopUser.setUpdatedAt(System.currentTimeMillis());
|
||||
tbShopUserMapper.updateByPrimaryKeySelective(tbShopUser);
|
||||
|
||||
@@ -185,4 +185,9 @@
|
||||
updated_at = #{updatedAt,jdbcType=BIGINT}
|
||||
where id = #{id,jdbcType=INTEGER}
|
||||
</update>
|
||||
|
||||
<select id="countSelectByShopIdAndPayType" resultType="int">
|
||||
|
||||
select count(id) from tb_shop_pay_type where shop_id=#{shopId} and is_display=1 and pay_type=#{payType}
|
||||
</select>
|
||||
</mapper>
|
||||
@@ -301,6 +301,19 @@
|
||||
<if test="code != null">
|
||||
code = #{code,jdbcType=VARCHAR},
|
||||
</if>
|
||||
|
||||
<if test="dynamicCode != null">
|
||||
dynamic_code = #{dynamicCode,jdbcType=VARCHAR},
|
||||
</if>
|
||||
|
||||
|
||||
<if test="isPwd != null">
|
||||
is_pwd = #{isPwd,jdbcType=VARCHAR},
|
||||
</if>
|
||||
|
||||
<if test="pwd != null">
|
||||
pwd = #{pwd,jdbcType=VARCHAR},
|
||||
</if>
|
||||
<if test="isAttention != null">
|
||||
is_attention = #{isAttention,jdbcType=TINYINT},
|
||||
</if>
|
||||
|
||||
Reference in New Issue
Block a user