Browse Source

1.税率小数点
2.批量导出

zcb 4 năm trước cách đây
mục cha
commit
3b09472c4b

+ 12 - 12
kmall-admin/src/main/java/com/kmall/admin/controller/OrderController.java

@@ -671,10 +671,10 @@ public class OrderController {
 
             for (OrderGoodsEntity orderGoodsEntity : goodsList) {
                 GoodsEntity goodsEntity = goodsService.queryObject(orderGoodsEntity.getGoodsId());
-                BigDecimal goodsTax = CalculateTax.calculateFinalTax(goodsEntity,orderGoodsEntity.getMarketPrice(),goodsService);
-                goodsTax = goodsTax.multiply(new BigDecimal(orderGoodsEntity.getNumber()));
+                BigDecimal goodsTax = CalculateTax.calculateFinalTax(goodsEntity,orderGoodsEntity.getMarketPrice(),goodsService).setScale(3,RoundingMode.HALF_UP);
+                goodsTax = goodsTax.multiply(new BigDecimal(orderGoodsEntity.getNumber())).setScale(2,RoundingMode.HALF_UP);
                 orderGoodsEntity.setTax(goodsTax);
-                tax = tax.add(goodsTax);
+                tax = tax.add(goodsTax).setScale(2,RoundingMode.HALF_UP);
 
 //                BigDecimal goodsTax = orderGoodsEntity.getMarketPrice().divide(new BigDecimal(1).add(orderGoodsEntity.getGoodsRate()),2,RoundingMode.HALF_DOWN).multiply(orderGoodsEntity.getGoodsRate())
 //                        .multiply(new BigDecimal(orderGoodsEntity.getNumber())).setScale(2,RoundingMode.HALF_DOWN);
@@ -700,10 +700,10 @@ public class OrderController {
 
         for (OrderGoodsEntity orderGoodsEntity : goodsList) {
             GoodsEntity goodsEntity = goodsService.queryObject(orderGoodsEntity.getGoodsId());
-            BigDecimal goodsTax = CalculateTax.calculateFinalTax(goodsEntity,orderGoodsEntity.getMarketPrice(),goodsService);
-            goodsTax = goodsTax.multiply(new BigDecimal(orderGoodsEntity.getNumber()));
+            BigDecimal goodsTax = CalculateTax.calculateFinalTax(goodsEntity,orderGoodsEntity.getMarketPrice(),goodsService).setScale(3,RoundingMode.HALF_UP);
+            goodsTax = goodsTax.multiply(new BigDecimal(orderGoodsEntity.getNumber())).setScale(2,RoundingMode.HALF_UP);
             orderGoodsEntity.setTax(goodsTax);
-            tax = tax.add(goodsTax);
+            tax = tax.add(goodsTax).setScale(2,RoundingMode.HALF_UP);
 
 //            BigDecimal goodsTax = orderGoodsEntity.getMarketPrice().divide(new BigDecimal(1).add(orderGoodsEntity.getGoodsRate()),2,RoundingMode.HALF_DOWN).multiply(orderGoodsEntity.getGoodsRate())
 //                    .multiply(new BigDecimal(orderGoodsEntity.getNumber())).setScale(2,RoundingMode.HALF_DOWN);
@@ -1098,11 +1098,11 @@ public class OrderController {
             BigDecimal goodsRate = orderGoodsEntity.getGoodsRate();
             Integer number = orderGoodsEntity.getNumber();
 
-            GoodsEntity goodsEntity = goodsService.queryObject(orderEntity.getGoodsId());
-            BigDecimal goodsTax = CalculateTax.calculateFinalTax(goodsEntity,retailPrice,goodsService);
-            goodsTax = goodsTax.multiply(new BigDecimal(number));
+            GoodsEntity goodsEntity = goodsService.queryObject(orderGoodsEntity.getGoodsId());
+            BigDecimal goodsTax = CalculateTax.calculateFinalTax(goodsEntity,retailPrice,goodsService).setScale(3,RoundingMode.HALF_UP);
+            goodsTax = goodsTax.multiply(new BigDecimal(number)).setScale(2,RoundingMode.HALF_UP);
             orderGoodsEntity.setTax(goodsTax);
-            tax = tax.add(goodsTax);
+            tax = tax.add(goodsTax).setScale(2,RoundingMode.HALF_UP);
 //            BigDecimal goodsTax = retailPrice.divide(new BigDecimal(1).add(goodsRate),2,RoundingMode.HALF_DOWN).multiply(goodsRate).multiply(new BigDecimal(number)).setScale(0,RoundingMode.HALF_DOWN);
         }
         String response = null;
@@ -1329,8 +1329,8 @@ public class OrderController {
                     BigDecimal totalSalesIncTax = new BigDecimal(systemFormat.getTotalSalesInclTax());
 //                    BigDecimal taxRate = new BigDecimal(systemFormat.getTaxRate());
                     GoodsEntity goodsEntity = goodsService.queryObject(systemFormat.getGoodsId());
-                    BigDecimal goodsTax = CalculateTax.calculateFinalTax(goodsEntity,totalSalesIncTax.divide(unitSold,2,RoundingMode.HALF_UP),goodsService);
-                    goodsTax = goodsTax.multiply(unitSold);
+                    BigDecimal goodsTax = CalculateTax.calculateFinalTax(goodsEntity,totalSalesIncTax.divide(unitSold,2,RoundingMode.HALF_UP),goodsService).setScale(3,RoundingMode.HALF_UP);
+                    goodsTax = goodsTax.multiply(unitSold).setScale(2,RoundingMode.HALF_UP);
 
                     systemFormat.setSales(totalSalesIncTax.subtract(goodsTax).setScale(2,BigDecimal.ROUND_HALF_UP).toString());
                     systemFormat.setTaxAmount(totalSalesIncTax.subtract(new BigDecimal(systemFormat.getSales())).setScale(2,BigDecimal.ROUND_HALF_UP).toString());

+ 71 - 9
kmall-admin/src/main/java/com/kmall/admin/controller/SalesDataUploadController.java

@@ -1,8 +1,14 @@
 package com.kmall.admin.controller;
 
+import java.io.BufferedInputStream;
+import java.io.BufferedOutputStream;
+import java.io.ByteArrayInputStream;
 import java.net.InetAddress;
+import java.net.URLEncoder;
 import java.text.SimpleDateFormat;
 import java.util.*;
+import java.util.zip.ZipEntry;
+import java.util.zip.ZipOutputStream;
 
 import com.kmall.admin.entity.SalesDataDownloadEntity;
 import com.kmall.admin.entity.SalesDataUploadEntity;
@@ -19,6 +25,8 @@ import org.springframework.stereotype.Controller;
 import org.springframework.web.bind.annotation.*;
 import org.springframework.web.multipart.MultipartFile;
 
+import javax.servlet.http.HttpServletResponse;
+
 /**
  * 销售数据上传表Controller
  *
@@ -155,19 +163,73 @@ public class SalesDataUploadController {
      * @throws Exception
      */
     @RequestMapping("/download")
-    public ResponseEntity<byte[]> download(@RequestParam("filePath") String filePath, @RequestParam("fileName") String fileName, @RequestParam("fileId") String fileId) throws Exception {
+    public ResponseEntity<byte[]> download(
+            HttpServletResponse response,
+            @RequestParam("filePath") String filePath, @RequestParam("fileName") String fileName, @RequestParam("fileId") String fileId) throws Exception {
         if(StringUtils.isNotEmpty(filePath)){
-            SalesDataDownloadEntity salesDataDownloadEntity = new SalesDataDownloadEntity();
-            salesDataDownloadEntity.setFileId(Integer.valueOf(fileId));
-            salesDataDownloadEntity.setDownloadSn(ShiroUtils.getUserId().intValue());
-            salesDataDownloadEntity.setDownloadTime(new Date());
 
-            InetAddress localHost = InetAddress.getLocalHost();
-            salesDataDownloadEntity.setDownloadIP(localHost.getHostAddress());
-            salesDataUploadService.saveSalesDownload(salesDataDownloadEntity);
+            Map<String, byte[]> files = new HashMap<String, byte[]>();
+
+            String[] filePaths = filePath.split(",");
+            String[] fileNames = fileName.split(",");
+            String[] fileIds = fileId.split(",");
+
+
+            for(int i = 0 ; i < filePaths.length ; i++){
+                SalesDataDownloadEntity salesDataDownloadEntity = new SalesDataDownloadEntity();
+                salesDataDownloadEntity.setFileId(Integer.valueOf(fileIds[i]));
+                salesDataDownloadEntity.setDownloadSn(ShiroUtils.getUserId().intValue());
+                salesDataDownloadEntity.setDownloadTime(new Date());
 
-            return FileManager.download(filePath, fileName.substring(0,fileName.lastIndexOf(".")));
+                InetAddress localHost = InetAddress.getLocalHost();
+                salesDataDownloadEntity.setDownloadIP(localHost.getHostAddress());
+                salesDataUploadService.saveSalesDownload(salesDataDownloadEntity);
+
+                ResponseEntity<byte[]> download = FileManager.download(filePaths[i], fileNames[i].substring(0, fileNames[i].lastIndexOf(".")));
+                byte[] msg = download.getBody();
+                files.put(fileNames[i],msg);
+            }
+
+
+            downloadBatchByFile(response,files,"CW保税+新零售销售额统计.zip");
         }
         return null;
     }
+
+
+
+    /**
+     * 根据文件,进行压缩,批量下载
+     * @param response
+     * @param files
+     * @throws Exception
+     */
+    public void downloadBatchByFile(HttpServletResponse response, Map<String, byte[]> files, String zipName){
+        try{
+            response.setContentType("application/x-msdownload");
+            response.setHeader("content-disposition", "attachment;filename="+ URLEncoder.encode(zipName, "utf-8"));
+
+            ZipOutputStream zos = new ZipOutputStream(response.getOutputStream());
+            BufferedOutputStream bos = new BufferedOutputStream(zos);
+
+            for(Map.Entry<String, byte[]> entry : files.entrySet()){
+                String fileName = entry.getKey();            //每个zip文件名
+                byte[]    file = entry.getValue();            //这个zip文件的字节
+
+                BufferedInputStream bis = new BufferedInputStream(new ByteArrayInputStream(file));
+                zos.putNextEntry(new ZipEntry(fileName));
+
+                int len = 0;
+                byte[] buf = new byte[10 * 1024];
+                while( (len=bis.read(buf, 0, buf.length)) != -1){
+                    bos.write(buf, 0, len);
+                }
+                bis.close();
+                bos.flush();
+            }
+            bos.close();
+        }catch(Exception e){
+            e.printStackTrace();
+        }
+    }
 }

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

@@ -1720,7 +1720,7 @@ public class GoodsServiceImpl implements GoodsService {
 
         // 计算税费
         GoodsEntity goodsEntity = goodsDao.queryByBarcodeAndSku(prodBarcode, goods.getGoodsSn());
-        BigDecimal tax = CalculateTax.calculateFinalTax(goodsEntity,goods.getActualPaymentAmount(),this);
+        BigDecimal tax = CalculateTax.calculateFinalTax(goodsEntity,goods.getActualPaymentAmount(),this).setScale(3,RoundingMode.HALF_UP);
         goods.setGoodstaxes(tax.toString());
 
 

Những thai đổi đã bị hủy bỏ vì nó quá lớn
+ 200 - 201
kmall-admin/src/main/java/com/kmall/admin/service/impl/OrderServiceImpl.java


+ 23 - 12
kmall-admin/src/main/java/com/kmall/admin/utils/CalculateTax.java

@@ -281,6 +281,12 @@ public class CalculateTax {
                             // 如果不是。重新用23.06计算一次
                             gramOrMlUnitPrice = getUnitPrice(retailPrice, consumerGoodsRate, cusGoodsName, qty1, qty2);
                             if (gramOrMlUnitPrice.compareTo(cosmThresholdValue) >= 0) {
+
+
+                                GoodsEntity updateGoods = new GoodsEntity();
+                                updateGoods.setGoodsRate(consumerGoodsRate);
+                                updateGoods.setId(goods.getId());
+                                goodsService.updateByEntity(updateGoods);
                                 // 如果用23.06去计算,还是大于阈值,那就是用23.06去计税
                                 return getTax(retailPrice, consumerGoodsRate);
                             }else{
@@ -303,6 +309,10 @@ public class CalculateTax {
                                 return tax;
 
                             }else{
+                                GoodsEntity updateGoods = new GoodsEntity();
+                                updateGoods.setGoodsRate(noConsumerGoodsRate);
+                                updateGoods.setId(goods.getId());
+                                goodsService.updateByEntity(updateGoods);
                                 return getTax(retailPrice, noConsumerGoodsRate);
                             }
 
@@ -349,13 +359,14 @@ public class CalculateTax {
         BigDecimal goodsRate;
         // 当使用0.091的时候,发现要收消费税。当使用0.2306的时候,不收消费税
         // 然后分别用两种计税方式去算税前价,然后算税费,最后去一个更接近税后价的来计算
-        BigDecimal noConsumerTaxPrice = retailPrice.divide(BigDecimal.ONE.add(noConsumerGoodsRate),3,RoundingMode.HALF_UP).setScale(2,RoundingMode.HALF_UP);
-        BigDecimal tax1 = noConsumerTaxPrice.multiply(consumerGoodsRate).setScale(2,RoundingMode.HALF_UP);
+        BigDecimal noConsumerTaxPrice = retailPrice.divide(BigDecimal.ONE.add(noConsumerGoodsRate),10,RoundingMode.HALF_UP).setScale(2,RoundingMode.HALF_UP);
+        BigDecimal tax1 = noConsumerTaxPrice.multiply(consumerGoodsRate).setScale(10,RoundingMode.HALF_UP);
         BigDecimal finalPrice1 = tax1.add(noConsumerTaxPrice);
+// 394.78
+// 310.29
 
-
-        BigDecimal consumerTaxPrice = retailPrice.divide(BigDecimal.ONE.add(consumerGoodsRate),3,RoundingMode.HALF_UP).setScale(2,RoundingMode.HALF_UP);
-        BigDecimal tax2 = consumerTaxPrice.multiply(noConsumerGoodsRate).setScale(2,RoundingMode.HALF_UP);
+        BigDecimal consumerTaxPrice = retailPrice.divide(BigDecimal.ONE.add(consumerGoodsRate),10,RoundingMode.HALF_UP).setScale(2,RoundingMode.HALF_UP);
+        BigDecimal tax2 = consumerTaxPrice.multiply(noConsumerGoodsRate).setScale(10,RoundingMode.HALF_UP);
         BigDecimal finalPrice2 = tax2.add(consumerTaxPrice);
 
         // 比较两个价格哪个比较接近税后价
@@ -381,10 +392,10 @@ public class CalculateTax {
         taxErrorRecordEntity.setErrorTime(new Date());
         goodsService.insertTaxErrorRecord(taxErrorRecordEntity);
 
-//        GoodsEntity updateGoods = new GoodsEntity();
-//        updateGoods.setGoodsRate(goodsRate);
-//        updateGoods.setId(goods.getId());
-//        goodsService.updateByEntity(updateGoods);
+        GoodsEntity updateGoods = new GoodsEntity();
+        updateGoods.setGoodsRate(goodsRate);
+        updateGoods.setId(goods.getId());
+        goodsService.updateByEntity(updateGoods);
         return tax;
     }
 
@@ -397,8 +408,8 @@ public class CalculateTax {
      */
     private static BigDecimal getTax(BigDecimal retailPrice, BigDecimal goodsRate) {
         return goodsRate.multiply(retailPrice
-                .divide(new BigDecimal(1).add(goodsRate), 2, RoundingMode.HALF_DOWN))
-                .setScale(2, RoundingMode.HALF_DOWN);
+                .divide(new BigDecimal(1).add(goodsRate), 10, RoundingMode.HALF_DOWN))
+                .setScale(10, RoundingMode.HALF_DOWN);
     }
 
 
@@ -417,7 +428,7 @@ public class CalculateTax {
 
         // 根据税后价计算出税前价
         BigDecimal productUnitPrice = retailPrice
-                .divide(new BigDecimal(1).add(goodsRate),2, RoundingMode.HALF_DOWN) ; // TODO 需要得到公式计算出税前价
+                .divide(new BigDecimal(1).add(goodsRate),10, RoundingMode.HALF_DOWN) ; // TODO 需要得到公式计算出税前价
 
         if (StringUtils.isNotBlank(cusGoodsName) && (cusGoodsName.contains("“片”") || cusGoodsName.contains("“张”") || cusGoodsName.contains("片") || cusGoodsName.contains("张"))) {
             //片、张的单价

+ 2 - 2
kmall-admin/src/main/resources/mybatis/mapper/OrderDao.xml

@@ -426,7 +426,7 @@
             AND o.merch_sn = #{merchSn}
         </if>
         <if test="goodsSn != null and goodsSn.trim() != ''">
-            AND gs.goods_sn = #{goodsSn}
+            AND g.goods_sn = #{goodsSn}
         </if>
         <if test="sku != null and sku.trim() != ''">
             AND gs.sku = #{sku}
@@ -496,7 +496,7 @@
             AND o.merch_sn = #{merchSn}
         </if>
         <if test="goodsSn != null and goodsSn.trim() != ''">
-            AND gs.goods_sn = #{goodsSn}
+            AND g.goods_sn = #{goodsSn}
         </if>
         <if test="sku != null and sku.trim() != ''">
             AND gs.sku = #{sku}

+ 3 - 0
kmall-admin/src/main/webapp/WEB-INF/page/shop/offilineOrderList.html

@@ -13,6 +13,9 @@
                     <i-input v-model="q.orderSn" @on-enter="query" placeholder="订单号"/>
                 </i-col>
                 <i-col span="4">
+                    <i-input v-model="q.goodsSn" @on-enter="query" placeholder="sku"/>
+                </i-col>
+                <i-col span="4">
                     <i-select v-model="q.orderStatus" placeholder="订单状态">
                         <i-option value="0">待付款</i-option>
                         <i-option value="101">订单已取消</i-option>

+ 1 - 1
kmall-admin/src/main/webapp/js/sale/sale.js

@@ -1255,7 +1255,7 @@ function openWebSocket() {
         //无法使用wss,浏览器打开WebSocket时报错
         //ws对应http、wss对应https。
         // webSocket = new WebSocket("ws://183.62.225.124:8080/ws/server/"+storeId);
-        webSocket = new WebSocket("ws://127.0.0.1:8070//ws/server/"+storeId);
+        webSocket = new WebSocket("ws://8.135.102.238:8080//ws/server/"+storeId);
         // webSocket = new WebSocket("wss://cb.k1net.cn/ws/server/"+storeId);
         if (webSocket.readyState === webSocket.CONNECTING) {
             console.log('1.连接正在打开......');

+ 35 - 4
kmall-admin/src/main/webapp/js/sale/salesdataupload.js

@@ -171,11 +171,42 @@ let vm = new Vue({
             handleResetForm(this, name);
         },
 		download: function (event){
-			let fileData = getSelectedRowData();
-			if (fileData.length != 1 && fileData.length != undefined){
+
+			var grid = $("#jqGrid");
+			var rowKey = grid.getGridParam("selrow");
+			if (!rowKey) {
+				iview.Message.error("请选择一条记录");
 				return;
 			}
-			window.location.href = "../salesdataupload/download?filePath="+fileData.uploadAddress+"&fileName="+fileData.fileName+"&fileId="+fileData.fileId;
+
+			var selectedIDs = grid.getGridParam("selarrrow");
+			if (selectedIDs.length > 1) {
+				// iview.Message.error("只能选择一条记录");
+				// return;
+			}
+
+			let filePaths = new Array();
+			let fileNames = new Array();
+			let fileIds = new Array();
+
+			for(var i = 0 ; i < selectedIDs.length ; i++){
+				let fileData = $("#jqGrid").jqGrid('getRowData', selectedIDs[i])
+				filePaths.push(fileData.uploadAddress);
+				fileNames.push(fileData.fileName);
+				fileIds.push(fileData.fileId);
+			}
+
+			console.log(filePaths);
+			console.log(fileNames);
+			console.log(fileIds);
+
+
+
+			// let fileData = getSelectedRowData();
+			// if (fileData.length != 1 && fileData.length != undefined){
+			// 	return;
+			// }
+			window.location.href = "../salesdataupload/download?filePath="+filePaths+"&fileName="+fileNames+"&fileId="+fileIds;
 			/*let fileIds = getSelectedRows();
 			if(null != fileIds && fileIds.length < 3){
 				for(let i=0; i<fileIds.length; i++){
@@ -257,4 +288,4 @@ let vm = new Vue({
 			});
 		}
 	}
-});
+});

+ 4 - 1
kmall-admin/src/main/webapp/js/shop/offilineOrderList.js

@@ -194,6 +194,7 @@ let vm = new Vue({
             orderType: '',
             startTime: '',
             endTime: '',
+            goodsSn:'',
         },
         refundMoney: 0,
         shipping: {},
@@ -250,6 +251,7 @@ let vm = new Vue({
                     'orderType': vm.q.orderType,
                     'startTime': vm.q.startTime,
                     'endTime': vm.q.endTime,
+                    'goodsSn':vm.q.goodsSn,
                 },
                 page: page
             }).trigger("reloadGrid");
@@ -258,7 +260,8 @@ let vm = new Vue({
             vm.q = {
                 orderSn: '',
                 orderStatus: '',
-                orderType: ''
+                orderType: '',
+                goodsSn:''
             };
         },
         lookDetail: function (rowId) { //第三步:定义编辑操作

Một số tệp đã không được hiển thị bởi vì quá nhiều tập tin thay đổi trong này khác