浏览代码

修改云教室扣费相关功能

hgw 3 年之前
父节点
当前提交
9f611193ff

+ 2 - 0
mec-biz/src/main/java/com/ym/mec/biz/dal/dao/TenantAssetsInfoDao.java

@@ -20,5 +20,7 @@ public interface TenantAssetsInfoDao extends BaseMapper<TenantAssetsInfo> {
     int frozenAmount(BigDecimal frozenAmount);
 
     int recoverAmount(BigDecimal recoverAmount);
+
+    int deductAmount(BigDecimal deductAmount);
 }
 

+ 4 - 2
mec-biz/src/main/java/com/ym/mec/biz/service/TenantAssetsInfoService.java

@@ -14,8 +14,10 @@ import java.util.List;
  */
 public interface TenantAssetsInfoService extends IService<TenantAssetsInfo> {
 
-    void courseDeductAmountRules(List<CourseSchedule> dto);
+    void courseFrozenAmount(List<CourseSchedule> dto);
 
-    void courseRecoverAmountRules(Integer courseId);
+    void courseRecoverAmount(Integer courseId);
+
+    void courseDeductAmount(Integer courseId);
 }
 

+ 32 - 9
mec-biz/src/main/java/com/ym/mec/biz/service/impl/TenantAssetsInfoServiceImpl.java

@@ -48,22 +48,33 @@ public class TenantAssetsInfoServiceImpl extends ServiceImpl<TenantAssetsInfoDao
     private TenantCloudCourseRecordService tenantCloudCourseRecordService;
 
     /**
-     * 恢复/取消 冻结的金额
+     * 扣除冻结的金额
      *
      * @param courseId 课程id
      */
     @Override
     @Transactional(rollbackFor = Exception.class)
-    public void courseRecoverAmountRules(Integer courseId) {
-        TenantCloudCourseRecord lastRecord = tenantCloudCourseRecordService.queryLastRecord(courseId);
-        if (Objects.nonNull(lastRecord) && lastRecord.getDeductState() != 0) {
-            //只有冻结的
-            throw new BizException("该课程非线上课!");
+    public void courseDeductAmount(Integer courseId){
+        TenantCloudCourseRecord lastRecord = checkLastRecord(courseId);
+        //写入流水
+        lastRecord.setDeductState(1);
+        tenantCloudCourseRecordService.save(lastRecord);
+        if (baseMapper.deductAmount(lastRecord.getAmount()) != 1) {
+            throw new BizException("解除冻结金额失败!");
         }
+    }
+
+    /**
+     * 恢复/取消 冻结的金额
+     *
+     * @param courseId 课程id
+     */
+    @Override
+    @Transactional(rollbackFor = Exception.class)
+    public void courseRecoverAmount(Integer courseId) {
+        TenantCloudCourseRecord lastRecord = checkLastRecord(courseId);
         //写入流水
         lastRecord.setDeductState(2);
-        lastRecord.setCreatedBy(getUserId());
-        lastRecord.setCreatedTime(new Date());
         tenantCloudCourseRecordService.save(lastRecord);
         //解除冻结金额,恢复余额
         if (baseMapper.recoverAmount(lastRecord.getAmount()) != 1) {
@@ -71,6 +82,18 @@ public class TenantAssetsInfoServiceImpl extends ServiceImpl<TenantAssetsInfoDao
         }
     }
 
+    private TenantCloudCourseRecord checkLastRecord(Integer courseId) {
+        TenantCloudCourseRecord lastRecord = tenantCloudCourseRecordService.queryLastRecord(courseId);
+        //判断是否是冻结的状态
+        if (Objects.nonNull(lastRecord) && lastRecord.getDeductState() != 0) {
+            //只有冻结的才能取消冻结 或者 扣费
+            throw new BizException("该课程非线上课!");
+        }
+        lastRecord.setCreatedBy(getUserId());
+        lastRecord.setCreatedTime(new Date());
+        return lastRecord;
+    }
+
     /**
      * 排课扣费计算
      * 1.线上排课计算出的总价格不能超过账户余额(注意多人同时操作账户余额多扣问题)
@@ -78,7 +101,7 @@ public class TenantAssetsInfoServiceImpl extends ServiceImpl<TenantAssetsInfoDao
      */
     @Override
     @Transactional(rollbackFor = Exception.class)
-    public void courseDeductAmountRules(List<CourseSchedule> dto) {
+    public void courseFrozenAmount(List<CourseSchedule> dto) {
         Integer tenantId = TenantContextHolder.getTenantId();
 
         //校验课程 筛选出线上课

+ 5 - 0
mec-biz/src/main/resources/config/mybatis/TenantAssetsInfoMapper.xml

@@ -39,5 +39,10 @@
         where frozen_amount_  <![CDATA[ >= ]]> #{recoverAmount}
     </update>
 
+    <update id="deductAmount" parameterType="decimal">
+        update tenant_assets_info
+        set frozen_amount_ = frozen_amount_ - #{deductAmount}
+        where frozen_amount_  <![CDATA[ >= ]]> #{deductAmount}
+    </update>
 
 </mapper>