| @@ -8,4 +8,6 @@ ALTER TABLE `wx_merchant` | |||||
| ADD COLUMN `mark` smallint(1) COMMENT '记号' AFTER `action_desc`; | ADD COLUMN `mark` smallint(1) COMMENT '记号' AFTER `action_desc`; | ||||
| ALTER TABLE `wx_merchant` | ALTER TABLE `wx_merchant` | ||||
| ADD COLUMN `entry_amount` int(11) COMMENT '入账金额' AFTER `credit_locked`; | |||||
| ADD COLUMN `entry_amount` int(11) DEFAULT 0 COMMENT '入账金额' AFTER `credit_locked`; | |||||
| UPDATE wx_merchant SET entry_amount = 0 ; | |||||
| @@ -203,6 +203,8 @@ public enum ErrorCode{ | |||||
| ORDER_USER_NOT_MATCH(2013, "订单用户不匹配"), | ORDER_USER_NOT_MATCH(2013, "订单用户不匹配"), | ||||
| ORDER_COUPON_CHANNEL_NOT_MATCH(2014, "订单渠道不匹配"), | ORDER_COUPON_CHANNEL_NOT_MATCH(2014, "订单渠道不匹配"), | ||||
| ORDER_COUPON_NOT_MATCH(2015, "订单券不匹配"), | ORDER_COUPON_NOT_MATCH(2015, "订单券不匹配"), | ||||
| ORDER_RECORDED_AMOUNT(2016, "已入账"), | |||||
| ORDER_RECORDED_AMOUNT_ERROR(2017, "入账失败"), | |||||
| /** | /** | ||||
| * 卡券 | * 卡券 | ||||
| @@ -62,6 +62,9 @@ public class TtOrder extends TenantEntity { | |||||
| @io.swagger.annotations.ApiModelProperty(value="是否入账",name="isRecorded") | @io.swagger.annotations.ApiModelProperty(value="是否入账",name="isRecorded") | ||||
| private Integer isRecorded; | private Integer isRecorded; | ||||
| @io.swagger.annotations.ApiModelProperty(value="入账时间",name="recordedDate") | |||||
| private Date recordedDate; | |||||
| public String getPaymentStr() { | public String getPaymentStr() { | ||||
| return payment != null ? new BigDecimal(payment).divide(new BigDecimal(100)).toPlainString() : paymentStr; | return payment != null ? new BigDecimal(payment).divide(new BigDecimal(100)).toPlainString() : paymentStr; | ||||
| @@ -21,7 +21,9 @@ public interface TtOrderMapper extends CommonMapper<TtOrder, Long> { | |||||
| Integer findListCount(TtOrder orderQ); | Integer findListCount(TtOrder orderQ); | ||||
| int updateExpire(@Param("expireDate")Date expireDate,@Param("orderStatus") Integer orderStatus); | |||||
| // int updateExpire(@Param("expireDate")Date expireDate,@Param("orderStatus") Integer orderStatus); | |||||
| List<Long> findExpireIdList(@Param("expireDate")Date expireDate,@Param("orderStatus") Integer orderStatus); | |||||
| List<Long> findBeforeIdList(@Param("beforeDate")Date beforeDate,@Param("orderStatus") Integer orderStatus,@Param("isRecorded") Integer isRecorded); | |||||
| int updateIsRecorded(@Param("id")Long id, @Param("isRecorded")Integer isRecorded); | |||||
| } | } | ||||
| @@ -55,4 +55,6 @@ public interface WxMerchantMapper extends CommonMapper<WxMerchant, Long> { | |||||
| WxMerchant getMerchantByEncode(@Param("encode")String encode); | WxMerchant getMerchantByEncode(@Param("encode")String encode); | ||||
| List<WxMerchant> findFollowList(WxMerchant record); | List<WxMerchant> findFollowList(WxMerchant record); | ||||
| int recordedAmount(WxMerchant record); | |||||
| } | } | ||||
| @@ -40,4 +40,12 @@ public interface TtOrderService { | |||||
| boolean isByMember(Long memberId, Long id); | boolean isByMember(Long memberId, Long id); | ||||
| List<Long> findExpireIdList(Date expireDate); | List<Long> findExpireIdList(Date expireDate); | ||||
| List<Long> findRecordedIdList(Date recordedDate); | |||||
| /** | |||||
| * 入账 | |||||
| * @return | |||||
| */ | |||||
| ResultData recordedAmount(Long orderId); | |||||
| } | } | ||||
| @@ -297,29 +297,31 @@ public class TtOrderServiceImpl implements TtOrderService { | |||||
| OrderQueryResult orderQueryResult = DouYinPayHelper.orderQuery(appInfo.getAppId(), payAccount.getApiKey(), order.getId().toString(), null); | OrderQueryResult orderQueryResult = DouYinPayHelper.orderQuery(appInfo.getAppId(), payAccount.getApiKey(), order.getId().toString(), null); | ||||
| if(orderQueryResult == null){ | if(orderQueryResult == null){ | ||||
| msg = "查询-单号不存在"; | msg = "查询-单号不存在"; | ||||
| } | |||||
| String trade_state = orderQueryResult.getOrderStatus(); | |||||
| if ("PROCESSING".equals(trade_state)) {//处理中 | |||||
| msg = "查询-处理中"; | |||||
| }else if ("SUCCESS".equals(trade_state)) {//成功 | |||||
| TtOrder orderSuc = new TtOrder(); | |||||
| orderSuc.setId(order.getId()); | |||||
| orderSuc.setOrderStatus(EnumTtOrderStatus.ORDER_STATUS_PAYMENT_SUCCESS.getCode()); | |||||
| orderSuc.setWay(orderQueryResult.getWay()); | |||||
| orderSuc.setPaymentTime(orderQueryResult.getPayTime()); | |||||
| orderSuc.setUpdateDate(new Date()); | |||||
| ttOrderMapper.updateById(orderSuc); | |||||
| ttcouponMapper.addSellCount(order.getProductId()); | |||||
| redisLock.unlock(lockKey, timeStr); | |||||
| return new ResultData(); | |||||
| }else if ("FAIL".equals(trade_state)) {//失败 | |||||
| msg = "查询-支付失败"; | |||||
| }else if ("TIMEOUT".equals(trade_state)) {//超时 | |||||
| msg = "查询-支付超时"; | |||||
| }else{ | }else{ | ||||
| msg = "查询-单号异常"; | |||||
| String trade_state = orderQueryResult.getOrderStatus(); | |||||
| if ("PROCESSING".equals(trade_state)) {//处理中 | |||||
| msg = "查询-处理中"; | |||||
| }else if ("SUCCESS".equals(trade_state)) {//成功 | |||||
| TtOrder orderSuc = new TtOrder(); | |||||
| orderSuc.setId(order.getId()); | |||||
| orderSuc.setOrderStatus(EnumTtOrderStatus.ORDER_STATUS_PAYMENT_SUCCESS.getCode()); | |||||
| orderSuc.setWay(orderQueryResult.getWay()); | |||||
| orderSuc.setPaymentTime(orderQueryResult.getPayTime()); | |||||
| orderSuc.setUpdateDate(new Date()); | |||||
| ttOrderMapper.updateById(orderSuc); | |||||
| ttcouponMapper.addSellCount(order.getProductId()); | |||||
| redisLock.unlock(lockKey, timeStr); | |||||
| return new ResultData(); | |||||
| }else if ("FAIL".equals(trade_state)) {//失败 | |||||
| msg = "查询-支付失败"; | |||||
| }else if ("TIMEOUT".equals(trade_state)) {//超时 | |||||
| msg = "查询-支付超时"; | |||||
| }else{ | |||||
| msg = "查询-单号异常"; | |||||
| } | |||||
| } | } | ||||
| if(isExpire){ | if(isExpire){ | ||||
| TtOrder orderSuc = new TtOrder(); | TtOrder orderSuc = new TtOrder(); | ||||
| orderSuc.setId(order.getId()); | orderSuc.setId(order.getId()); | ||||
| @@ -386,7 +388,42 @@ public class TtOrderServiceImpl implements TtOrderService { | |||||
| @Override | @Override | ||||
| public List<Long> findExpireIdList(Date expireDate) { | public List<Long> findExpireIdList(Date expireDate) { | ||||
| return ttOrderMapper.findExpireIdList(expireDate,EnumTtOrderStatus.ORDER_STATUS_PENDING_PAYMENT.getCode()); | |||||
| return ttOrderMapper.findBeforeIdList(expireDate,EnumTtOrderStatus.ORDER_STATUS_PENDING_PAYMENT.getCode(),null); | |||||
| } | |||||
| @Override | |||||
| public List<Long> findRecordedIdList(Date recordedDate) { | |||||
| return ttOrderMapper.findBeforeIdList(recordedDate,EnumTtOrderStatus.ORDER_STATUS_PAYMENT_SUCCESS.getCode(),EnumYesOrNo.NO.getCode()); | |||||
| } | |||||
| @Override | |||||
| @Transactional(propagation = Propagation.REQUIRED, readOnly = false, rollbackFor = {Exception.class}) | |||||
| public ResultData recordedAmount(Long orderId) { | |||||
| TtOrder order = ttOrderMapper.selectById(orderId); | |||||
| if (null == order) { | |||||
| logger.error("pay order, order not allow, orderId: " + orderId); | |||||
| return new ResultData(ErrorCode.ORDER_IS_NOT_FIND); | |||||
| } | |||||
| if(order.getOrderStatus() == EnumTtOrderStatus.ORDER_STATUS_PAYMENT_SUCCESS.getCode()){ | |||||
| if(order.getIsRecorded() == null || !order.getIsRecorded().equals(EnumYesOrNo.YES.getCode())){ | |||||
| WxMerchant merchant = new WxMerchant(); | |||||
| merchant.setId(order.getMerchantId()); | |||||
| merchant.setEntryAmount(order.getPayment()); | |||||
| merchant.setCashOutNumber(order.getPayment()); | |||||
| int i = wxMerchantMapper.recordedAmount(merchant); | |||||
| if(i == 1){ | |||||
| ttOrderMapper.updateIsRecorded(order.getId(),EnumYesOrNo.YES.getCode()); | |||||
| return new ResultData(); | |||||
| }else{ | |||||
| throw new MallinkException(ErrorCode.ORDER_RECORDED_AMOUNT_ERROR); | |||||
| } | |||||
| }else{ | |||||
| return new ResultData(ErrorCode.ORDER_RECORDED_AMOUNT); | |||||
| } | |||||
| }else{ | |||||
| return new ResultData(ErrorCode.PAY_ORDER_NOT_PAY,"订单不是支付状态"); | |||||
| } | |||||
| } | } | ||||
| } | } | ||||
| @@ -21,6 +21,8 @@ | |||||
| <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="is_recorded" jdbcType="INTEGER" property="isRecorded"/> | <result column="is_recorded" jdbcType="INTEGER" property="isRecorded"/> | ||||
| <result column="recorded_date" jdbcType="TIMESTAMP" property="recordedDate"/> | |||||
| <result column="nick_name" jdbcType="VARCHAR" property="nickName"/> | <result column="nick_name" jdbcType="VARCHAR" property="nickName"/> | ||||
| <result column="phone" jdbcType="VARCHAR" property="phone"/> | <result column="phone" jdbcType="VARCHAR" property="phone"/> | ||||
| @@ -30,7 +32,7 @@ | |||||
| <sql id="allColumns"> | <sql id="allColumns"> | ||||
| o.`id`,o.`tenant_id`,o.`parent_tenant_id`,o.`c_user_id`,o.`product_id`,o.`type`,o.`way`,o.`payment_type`,o.`payment`, | o.`id`,o.`tenant_id`,o.`parent_tenant_id`,o.`c_user_id`,o.`product_id`,o.`type`,o.`way`,o.`payment_type`,o.`payment`, | ||||
| o.`payment_time`,o.`order_status`,o.`create_date`,o.`update_date`,o.`is_recorded`, | |||||
| o.`payment_time`,o.`order_status`,o.`create_date`,o.`update_date`,o.`is_recorded`,o.`recorded_date`, | |||||
| u.`nick_name`,u.`phone`, | u.`nick_name`,u.`phone`, | ||||
| o.`product_title`,o.`product_pic`,o.`product_sale_price`, | o.`product_title`,o.`product_pic`,o.`product_sale_price`, | ||||
| m.`name` author,m.`img_url` author_pic | m.`name` author,m.`img_url` author_pic | ||||
| @@ -81,6 +83,10 @@ | |||||
| and o.`order_status` = #{orderStatus} | and o.`order_status` = #{orderStatus} | ||||
| </if> | </if> | ||||
| <if test=" null != isRecorded "> | |||||
| and o.`is_recorded` = #{isRecorded} | |||||
| </if> | |||||
| <if test=" null != nickName "> | <if test=" null != nickName "> | ||||
| and u.`nick_name` like concat('%', #{nickName},'%') | and u.`nick_name` like concat('%', #{nickName},'%') | ||||
| </if> | </if> | ||||
| @@ -163,6 +169,10 @@ | |||||
| and o.`product_id` = #{productId} | and o.`product_id` = #{productId} | ||||
| </if> | </if> | ||||
| <if test=" null != productTitle "> | |||||
| and o.`product_title` like concat('%', #{productTitle},'%') | |||||
| </if> | |||||
| <if test=" null != type "> | <if test=" null != type "> | ||||
| and o.`type` = #{type} | and o.`type` = #{type} | ||||
| </if> | </if> | ||||
| @@ -241,15 +251,17 @@ | |||||
| </if> | </if> | ||||
| </select> | </select> | ||||
| <update id="updateExpire" parameterType="java.util.HashMap"> | |||||
| update tt_order set order_status = #{orderStatus},update_date = now() | |||||
| where orderStatus=0 and create_date < #{expireDate} | |||||
| </update> | |||||
| <select id="findExpireIdList" parameterType="java.util.HashMap" resultType="Long"> | <select id="findExpireIdList" parameterType="java.util.HashMap" resultType="Long"> | ||||
| select id | select id | ||||
| from tt_order | from tt_order | ||||
| where orderStatus=#{orderStatus} and create_date < #{expireDate} | |||||
| where order_status=#{orderStatus} and create_date <= #{beforeDate} | |||||
| <if test=" null != isRecorded "> | |||||
| and `is_recorded` = #{isRecorded} | |||||
| </if> | |||||
| </select> | </select> | ||||
| <update id="updateIsRecorded" parameterType="java.util.HashMap"> | |||||
| update tt_order set `is_recorded` = #{isRecorded},recorded_date = now() where id = #{id} | |||||
| </update> | |||||
| </mapper> | </mapper> | ||||
| @@ -688,4 +688,11 @@ | |||||
| update wx_merchant set cash_out_count = 0 where id = #{id} | update wx_merchant set cash_out_count = 0 where id = #{id} | ||||
| </update> | </update> | ||||
| <update id="recordedAmount" parameterType="com.iformall.domain.po.WxMerchant"> | |||||
| update wx_merchant set | |||||
| entry_amount = ifnull(entry_amount,0)+#{entryAmount}, | |||||
| cash_out_number = ifnull(cash_out_number,0)+#{cashOutNumber} | |||||
| where id = #{id} | |||||
| </update> | |||||
| </mapper> | </mapper> | ||||
| @@ -1,15 +1,14 @@ | |||||
| package com.iformall.schedule; | package com.iformall.schedule; | ||||
| import com.iformall.domain.po.WxAppinfo; | import com.iformall.domain.po.WxAppinfo; | ||||
| import com.iformall.domain.po.WxMerchant; | |||||
| import com.iformall.domain.po.WxPayAccount; | import com.iformall.domain.po.WxPayAccount; | ||||
| import com.iformall.domain.po.base.TenantEntity; | import com.iformall.domain.po.base.TenantEntity; | ||||
| import com.iformall.enums.*; | import com.iformall.enums.*; | ||||
| import com.iformall.mapper.*; | |||||
| import com.iformall.service.WxAppinfoService; | import com.iformall.service.WxAppinfoService; | ||||
| import com.iformall.service.WxPayAccountService; | import com.iformall.service.WxPayAccountService; | ||||
| import com.iformall.service.tt.TtOrderService; | import com.iformall.service.tt.TtOrderService; | ||||
| import com.iformall.utils.Constant; | import com.iformall.utils.Constant; | ||||
| import com.iformall.utils.DateUtils; | |||||
| import org.slf4j.Logger; | import org.slf4j.Logger; | ||||
| import org.slf4j.LoggerFactory; | import org.slf4j.LoggerFactory; | ||||
| import org.springframework.beans.factory.annotation.Autowired; | import org.springframework.beans.factory.annotation.Autowired; | ||||
| @@ -31,10 +30,8 @@ public class TtOrderExpiringSchedule { | |||||
| private WxPayAccountService payAccountService; | private WxPayAccountService payAccountService; | ||||
| @Autowired | @Autowired | ||||
| TtOrderService ttOrderService; | |||||
| private TtOrderService ttOrderService; | |||||
| @Autowired | |||||
| WxMerchantMapper wxMerchantMapper; | |||||
| private TenantEntity getTenantInfo() { | private TenantEntity getTenantInfo() { | ||||
| TenantEntity tenantEntity = new TenantEntity() ; | TenantEntity tenantEntity = new TenantEntity() ; | ||||
| @@ -44,20 +41,20 @@ public class TtOrderExpiringSchedule { | |||||
| @Scheduled(cron = "0 */10 * * * *?") // 每10分钟检查一次 | @Scheduled(cron = "0 */10 * * * *?") // 每10分钟检查一次 | ||||
| public void orderExpireSchedule() { | public void orderExpireSchedule() { | ||||
| WxAppinfo cAppInfo = wxAppinfoService.getCAppInfo(getTenantInfo(), EnumPayWay.PAY_WAY_TT); | |||||
| if(cAppInfo == null){ | |||||
| return; | |||||
| } | |||||
| WxPayAccount payAccout = payAccountService.getById(cAppInfo.getId()); | |||||
| if(payAccout == null){ | |||||
| return; | |||||
| } | |||||
| Date now = new Date(); | Date now = new Date(); | ||||
| Date expireDate = new Date(now.getTime() - Constant.PRESS_TIME_OUT ); | Date expireDate = new Date(now.getTime() - Constant.PRESS_TIME_OUT ); | ||||
| List<Long> idList = ttOrderService.findExpireIdList(expireDate); | List<Long> idList = ttOrderService.findExpireIdList(expireDate); | ||||
| if(idList != null && idList.size() > 0){ | if(idList != null && idList.size() > 0){ | ||||
| WxAppinfo cAppInfo = wxAppinfoService.getCAppInfo(getTenantInfo(), EnumPayWay.PAY_WAY_TT); | |||||
| if(cAppInfo == null){ | |||||
| return; | |||||
| } | |||||
| WxPayAccount payAccout = payAccountService.getById(cAppInfo.getId()); | |||||
| if(payAccout == null){ | |||||
| return; | |||||
| } | |||||
| for (Long orderId:idList) { | for (Long orderId:idList) { | ||||
| try { | try { | ||||
| ttOrderService.updateOrderStatus(orderId,cAppInfo,payAccout); | ttOrderService.updateOrderStatus(orderId,cAppInfo,payAccout); | ||||
| @@ -72,7 +69,17 @@ public class TtOrderExpiringSchedule { | |||||
| @Scheduled(cron = "0 0 4 * * ?") //每天四点入账 | @Scheduled(cron = "0 0 4 * * ?") //每天四点入账 | ||||
| public void orderRecordedSchedule() { | public void orderRecordedSchedule() { | ||||
| Date dateZero = DateUtils.getDateZero(new Date()); | |||||
| List<Long> idList = ttOrderService.findRecordedIdList(dateZero); | |||||
| if(idList != null && idList.size() > 0){ | |||||
| for (Long orderId:idList) { | |||||
| try { | |||||
| ttOrderService.recordedAmount(orderId); | |||||
| } catch (Exception e) { | |||||
| e.printStackTrace(); | |||||
| } | |||||
| } | |||||
| } | |||||
| } | } | ||||
| } | } | ||||