Browse Source

Merge branch 'master' of http://git.ds-bay.com/project/kmall-pt-general

zcb 4 years ago
parent
commit
ae18754c67

+ 31 - 0
kmall-admin/src/main/java/com/kmall/admin/controller/GoodsController.java

@@ -699,4 +699,35 @@ public class GoodsController {
 
 
 
+    /**
+     * 同步海关编号和商品税率
+     * @return
+     */
+    @PostMapping("/syncGoodsRate")
+    public R syncGoodsRate(){
+        // 先同步海关商品编码,再同步税率
+        try {
+            goodsService.syncOmsHsCode();
+        }catch (Exception e){
+            e.printStackTrace();
+            return R.error("同步海关商品编码失败,请联系管理员");
+        }
+        try {
+            goodsService.syncGoodsRate();
+        }catch (Exception e){
+            e.printStackTrace();
+            return R.error("同步商品税率失败,请联系管理员");
+        }
+        return R.ok();
+    }
+
+
+
+
+
+
+
+
+
+
 }

+ 1 - 1
kmall-admin/src/main/java/com/kmall/admin/service/impl/GoodsServiceImpl.java

@@ -1877,7 +1877,7 @@ public class GoodsServiceImpl implements GoodsService {
                     BigDecimal actualPaymentAmount = goods.getActualPaymentAmount(); //随便拿一个门店的当前时间的价格,如果有活动价会使用活动价
 //                    BigDecimal calculateTax = CalculateTax.calculateTax(goodsEntity, actualPaymentAmount);// 税费
 //                    BigDecimal goodsRate = calculateTax.divide(actualPaymentAmount, 4, BigDecimal.ROUND_HALF_UP);
-                    BigDecimal goodsRate =CalculateTax.calculateGoodsRate(goodsEntity, actualPaymentAmount);
+                    BigDecimal goodsRate =CalculateTax.calculateGoodsRate(goodsEntity);
                     goodsEntity.setGoodsRate(goodsRate);
                     goodsDao.update(goodsEntity);
                 }

+ 5 - 33
kmall-admin/src/main/java/com/kmall/admin/utils/CalculateTax.java

@@ -218,54 +218,26 @@ public class CalculateTax {
      * @param
      * @return
      */
-    public static final BigDecimal calculateGoodsRate(GoodsEntity goodsEntity, BigDecimal actualPaymentAmount) {
-        // 该商品消费税
-        BigDecimal grandConsumerTax = BigDecimal.ZERO;
-        // 该商品增值税
-        BigDecimal grandValueAddTax = BigDecimal.ZERO;
-
-
-        String hsCode = goodsEntity.getHsCode();// 海关商品编码
-        String hsCodeName = goodsEntity.getHsCodeName();// 海关商品编码名称
-
+    public static final BigDecimal calculateGoodsRate(GoodsEntity goodsEntity) {
         // 消费税税率
         final BigDecimal impConsumTaxRate = goodsEntity.getImpConsumTaxRate();
         // 增值税税率
         final BigDecimal valueAddedTaxRate = goodsEntity.getValueAddedTaxRate();
 
-        try {
-            // 计算某类产品的消费税
-            final BigDecimal subConsumerTax = calculateConsumerTax(actualPaymentAmount, impConsumTaxRate, hsCodeName, goodsEntity, actualPaymentAmount);
-            // 计算某类产品的增值税
-            final BigDecimal subValueAddTax = calculateValueAddTax(actualPaymentAmount, valueAddedTaxRate, subConsumerTax);
-
-            // 计算总的消费税
-            grandConsumerTax = grandConsumerTax.add(subConsumerTax);
-            // 计算总的增值税
-            grandValueAddTax = grandValueAddTax.add(subValueAddTax);
-        } catch (final RuntimeException e) {
-            if (logger.isErrorEnabled()) logger.error("计算税费出错!请检查产品的分类数据,以及产品类别的税率数据!", e);
-            throw new IllegalStateException("计算税费出错!请检查产品的分类数据,以及产品类别的税率数据!", e);
-        }
 
         // 如果增值税为0,免税
-        if (BigDecimal.ZERO.compareTo(grandValueAddTax)==0){
-            return grandValueAddTax;
+        if (BigDecimal.ZERO.compareTo(valueAddedTaxRate)==0){
+            return valueAddedTaxRate;
         }
         // 如果有消费税 23.06%=(0.13+0.15)/(1-0.15)*0.7
-        if (BigDecimal.ZERO.compareTo(grandConsumerTax)!=0){
+        if (BigDecimal.ZERO.compareTo(impConsumTaxRate)!=0){
            return valueAddedTaxRate.add(impConsumTaxRate).
                    divide(new BigDecimal(100).subtract(impConsumTaxRate),10, BigDecimal.ROUND_HALF_UP)
                    .multiply(new BigDecimal("0.7")).setScale(4, BigDecimal.ROUND_HALF_UP);
         }else {
             // 如果没有消费税   9.1%=0.13*0.7
-            valueAddedTaxRate.multiply(new BigDecimal("0.7")).divide(new BigDecimal("100"),4,BigDecimal.ROUND_HALF_UP);
+           return  valueAddedTaxRate.multiply(new BigDecimal("0.7")).divide(new BigDecimal("100"),4,BigDecimal.ROUND_HALF_UP);
         }
-
-
-        // 按照公式,打7折
-        final BigDecimal tax = grandConsumerTax.add(grandValueAddTax).multiply(new BigDecimal("0.7")).setScale(2, BigDecimal.ROUND_HALF_UP);
-        return tax.divide(actualPaymentAmount, 4, BigDecimal.ROUND_HALF_UP);
     }
 
 

+ 2 - 0
kmall-admin/src/main/webapp/WEB-INF/page/shop/goods.html

@@ -140,6 +140,8 @@
                 <i-button type="dashed" @click="unSale"><i class="fa fa-hand-o-down"></i>&nbsp;下架</i-button>
                 #end
 
+                <i-button type="primary" @click="syncGoodsRate"><i class="fa fa-pencil-square-o"></i>&nbsp;同步税率</i-button>
+
                 <!--<i-button type="info" @click="goodsExport"><i class="fa fa-plus"></i>&nbsp;商品导入</i-button>-->
                 <!--<i-button type="info" @click="sameGoodsExport"><i class="fa fa-plus"></i>&nbsp;普货商品导入</i-button>-->
 

+ 18 - 0
kmall-admin/src/main/webapp/js/shop/goods.js

@@ -365,6 +365,24 @@ var vm = new Vue({
                 });
             });
         },
+        syncGoodsRate: function () {
+            confirm('同步商品税率会影响线上收银,请谨慎确认,同步税率预需要数分钟,确定要同步商品税率?', function () {
+                $.ajax({
+                    type: "POST",
+                    url: "../goods/syncGoodsRate",
+                    contentType: "application/json",
+                    success: function (r) {
+                        if (r.code == 0) {
+                            alert('同步税率成功', function (index) {
+                                $("#jqGrid").trigger("reloadGrid");
+                            });
+                        } else {
+                            alert(r.msg);
+                        }
+                    }
+                });
+            });
+        },
         openSpe: function () {
             var id = getSelectedRow();
             if (id == null) {