| | |
| | | package com.taoke.autopay.service.impl; |
| | | |
| | | import com.taoke.autopay.dao.KeyOrderMapper; |
| | | import com.taoke.autopay.dao.WxUserSettingsMapper; |
| | | import com.taoke.autopay.entity.KeyOrder; |
| | | import com.taoke.autopay.entity.OrderCountTypeEnum; |
| | | import com.taoke.autopay.entity.OrderDistributeCountInfo; |
| | | import com.taoke.autopay.entity.WxUserSettings; |
| | | import com.taoke.autopay.exception.KeyOrderException; |
| | | import com.taoke.autopay.exception.WxOrderCountException; |
| | | import com.taoke.autopay.factory.OrderFactory; |
| | | import com.taoke.autopay.service.KeyOrderService; |
| | | import com.taoke.autopay.service.WxUserOrderCountService; |
| | | import com.taoke.autopay.service.WxUserSettingService; |
| | | import com.taoke.autopay.utils.StringUtil; |
| | | import com.taoke.autopay.utils.TimeUtil; |
| | | import com.taoke.autopay.vo.SubmitKeyInfo; |
| | | import org.springframework.stereotype.Service; |
| | | import org.springframework.transaction.annotation.Transactional; |
| | | |
| | | import javax.annotation.Resource; |
| | | import java.math.BigDecimal; |
| | | import java.util.*; |
| | | |
| | | /** |
| | |
| | | @Resource |
| | | private KeyOrderMapper keyOrderMapper; |
| | | |
| | | @Resource |
| | | private WxUserSettingService wxUserSettingService; |
| | | |
| | | @Resource |
| | | private WxUserOrderCountService wxUserOrderCountService; |
| | | |
| | | |
| | | @Override |
| | | public KeyOrder selectById(String id) { |
| | | return keyOrderMapper.selectById(id); |
| | | } |
| | | |
| | | @Transactional(rollbackFor = Exception.class) |
| | | @Override |
| | | public KeyOrder addKeyOrder(String key) throws KeyOrderException { |
| | | String id = OrderFactory.createId(key); |
| | | public KeyOrder addKeyOrder(SubmitKeyInfo keyInfo, Long uid, String day) throws KeyOrderException, WxOrderCountException { |
| | | // 判断提交次数是否过量 |
| | | if (uid != null) { |
| | | WxUserSettings settings = wxUserSettingService.selectByUid(uid); |
| | | wxUserOrderCountService.addOrderCount(uid, OrderCountTypeEnum.SUBMIT_TOKEN_COUNT, day, 1, settings.getTotalOrderCountPerDay()); |
| | | } |
| | | String id = OrderFactory.createId(keyInfo.getKey()); |
| | | KeyOrder order = keyOrderMapper.selectById(id); |
| | | if (order != null) { |
| | | throw new KeyOrderException("请勿重复提交口令"); |
| | | } |
| | | order = new KeyOrder(); |
| | | order.setId(id); |
| | | order.setKey(key); |
| | | order.setKey(keyInfo.getKey()); |
| | | if(!StringUtil.isNullOrEmpty(keyInfo.getMoney())){ |
| | | order.setOrderMoney(new BigDecimal(keyInfo.getMoney())); |
| | | } |
| | | order.setUid(uid); |
| | | order.setState(KeyOrder.STATE_NOT_PROCESS); |
| | | order.setStateDesc("尚未处理"); |
| | | order.setCreateTime(new Date()); |
| | | keyOrderMapper.insertSelective(order); |
| | | |
| | | |
| | | return order; |
| | | } |
| | | |
| | |
| | | |
| | | @Transactional(rollbackFor = Exception.class) |
| | | @Override |
| | | public void paySuccess(String id, String stateDesc,String day) throws WxOrderCountException { |
| | | KeyOrder old = keyOrderMapper.selectByPrimaryKeyForUpdate(id); |
| | | if(old==null){ |
| | | return; |
| | | } |
| | | if(old.getState() == KeyOrder.STATE_PAY){ |
| | | return; |
| | | } |
| | | if(old.getUid()!=null) { |
| | | wxUserOrderCountService.addOrderCount(old.getUid(),OrderCountTypeEnum.DY_ORDER_PAY,day,1,null); |
| | | } |
| | | KeyOrder orderUpdate = new KeyOrder(); |
| | | orderUpdate.setId(id); |
| | | orderUpdate.setState(KeyOrder.STATE_PAY); |
| | | orderUpdate.setStateDesc(stateDesc); |
| | | if(old.getPayTime()==null){ |
| | | orderUpdate.setPayTime(new Date()); |
| | | } |
| | | update(orderUpdate); |
| | | } |
| | | |
| | | @Transactional(rollbackFor = Exception.class) |
| | | @Override |
| | | public void setOrderInfo(String id, String orderNo, int orderState) throws KeyOrderException { |
| | | KeyOrder old = keyOrderMapper.selectByPrimaryKeyForUpdate(id); |
| | | if (old == null) { |