wangzhuo 2 лет назад
Родитель
Сommit
d6961d82ed

+ 18 - 0
blade-service-api/blade-purchase-sales-api/src/main/java/org/springblade/purchase/sales/feign/IOrderCheckClient.java

@@ -46,4 +46,22 @@ public interface IOrderCheckClient {
 	 */
 	@PostMapping("/agencyOrder/reject")
 	R reject(@RequestParam("id") Long id);
+
+	/**
+	 * 销售退单审批中
+	 */
+	@PostMapping("order/underChargeBackReview")
+	R underChargeBackReview(@RequestParam("id") Long id);
+
+	/**
+	 * 销售退单审批不通过
+	 */
+	@PostMapping("order/passChargeBackCancel")
+	R passChargeBackCancel(@RequestParam("id") Long id);
+
+	/**
+	 * 销售退单审批通过
+	 */
+	@PostMapping("order/checkRepealCancel")
+	R checkRepealCancel(@RequestParam("id") Long id);
 }

+ 4 - 0
blade-service/blade-check/src/main/java/org/springblade/check/controller/AuditProecessController.java

@@ -311,6 +311,10 @@ public class AuditProecessController extends BladeController {
 		else if ("xsqh".equals(proecess.getCheckType()) || "cgqh".equals(proecess.getCheckType()) || "xstpqh".equals(proecess.getCheckType())) {
 			auditProecessService.orderCheckProcess(auditProecess);
 		}
+		//销售退单
+		else if ("XSTD".equals(proecess.getCheckType())){
+			auditProecessService.chargeBackCheck(auditProecess);
+		}
 		// 通济学校 小学 初中 高中 后勤工资审核
 		else if ("xsgz".equals(proecess.getCheckType()) || "czgz".equals(proecess.getCheckType()) || "gzgz".equals(proecess.getCheckType()) || "hqgz".equals(proecess.getCheckType())) {
 			auditProecessService.salaryCheck(auditProecess);

+ 6 - 0
blade-service/blade-check/src/main/java/org/springblade/check/service/IAuditProecessService.java

@@ -49,6 +49,12 @@ public interface IAuditProecessService extends IService<AuditProecess> {
 
 	void orderCheckProcess(AuditProecess auditProecess);
 
+	/**
+	 * 销售退单审核
+	 * @param auditProecess
+	 */
+	void chargeBackCheck(AuditProecess auditProecess);
+
 	void batchOperation(List<AuditProecess> processLis, Integer operate, String auditMsg);
 
 	void changeAuditUser(AuditProecess auditProecess);

+ 171 - 1
blade-service/blade-check/src/main/java/org/springblade/check/service/impl/AuditProecessServiceImpl.java

@@ -975,6 +975,176 @@ public class AuditProecessServiceImpl extends ServiceImpl<AuditProecessMapper, A
 		baseMapper.updateById(auditProecess);
 	}
 
+	/**
+	 * 销售退单审核
+	 */
+	@Override
+	@Transactional(rollbackFor = Exception.class)
+	@GlobalTransactional(rollbackFor = Exception.class, timeoutMills = 12000000)
+	public void  chargeBackCheck(AuditProecess auditProecess) {
+		//查看最新操作记录,防止重复提交
+		AuditProecess proecessTemp = baseMapper.selectById(auditProecess.getId());
+		if (proecessTemp == null) {
+			throw new SecurityException("未查到此审批记录,禁止操作");
+		}
+		if ("A".equals(proecessTemp.getAuditStatus()) || "B".equals(proecessTemp.getAuditStatus())) {
+			throw new SecurityException("当前记录已经完成审批,禁止重复操作");
+		}
+
+		if (auditProecess.getAuditStatus() == null || !"S".equals(auditProecess.getAuditStatus())) {
+			throw new SecurityException("审批状态非待审,禁止操作");
+		}
+		//信息
+		Message sendMessage = new Message();
+		sendMessage.setParameter(String.valueOf(auditProecess.getBillId()));
+		sendMessage.setUserName(AuthUtil.getUserName());
+		sendMessage.setUserId(AuthUtil.getUserId());
+		sendMessage.setToUserId(auditProecess.getSendUserId());
+		sendMessage.setToUserName(auditProecess.getSendName());
+		sendMessage.setMessageType(1);
+		sendMessage.setTenantId(AuthUtil.getTenantId());
+		sendMessage.setCreateUser(AuthUtil.getUserId());
+		sendMessage.setCreateTime(new Date());
+		sendMessage.setUrl(auditProecess.getUrl());
+		sendMessage.setPageLabel(auditProecess.getPageLabel());
+		sendMessage.setPageStatus(auditProecess.getPageStatus());
+
+		//用户操作 1.通过  2.驳回
+		Integer operate = auditProecess.getOperate();
+		//查看当前审批是否为最后一级
+		String iffinalItem = auditProecess.getIffinalItem();
+		//审批人
+		auditProecess.setAuditUserId(String.valueOf(AuthUtil.getUserId()));
+		//审批时间
+		auditProecess.setAuditOpTime(new Date());
+
+		Order order = orderDescClient.getById(proecessTemp.getBillId());
+
+		//不是最后一级
+		if ("F".equals(iffinalItem)) {
+
+			//通过
+			if (operate == 1) {
+				//如果是第一级, 则修改状态为审批中
+				if (auditProecess.getLevelId() == 1) {
+					R submit = orderCheckClient.underChargeBackReview(auditProecess.getSrcBillId());//审批中
+					if (!submit.isSuccess()) {
+						throw new SecurityException("审批开始修改审核状态失败");
+					}
+				}
+
+				auditProecess.setAuditStatus("A");
+				//查询下一级,开启待审
+				LambdaQueryWrapper<AuditProecess> auditProecessLambdaQueryWrapper = new LambdaQueryWrapper<>();
+				auditProecessLambdaQueryWrapper
+					.eq(AuditProecess::getBatchNo, auditProecess.getBatchNo())
+					.eq(AuditProecess::getSrcBillId, auditProecess.getSrcBillId())
+					.eq(AuditProecess::getIsDelete, 0)
+					.eq(AuditProecess::getActId, auditProecess.getActId())
+					.eq(AuditProecess::getBillId, auditProecess.getBillId())
+					.eq(AuditProecess::getBillNo, auditProecess.getBillNo())
+					.eq(AuditProecess::getTenantId, AuthUtil.getTenantId())
+					.eq(AuditProecess::getLevelId, auditProecess.getLevelId() + 1);
+				Integer count = baseMapper.selectCount(auditProecessLambdaQueryWrapper);
+				if (count != null && count > 1) {
+					throw new SecurityException("审核失败,获取下一级信息失败");
+				}
+				AuditProecess proecess = baseMapper.selectOne(auditProecessLambdaQueryWrapper);
+				if (proecess == null) {
+					throw new SecurityException("审批通过=>获取下一级信息失败");
+				}
+				proecess.setAuditStatus("S");
+				baseMapper.updateById(proecess);
+
+				SimpleDateFormat simpleDateFormat = new SimpleDateFormat();
+
+				//获得订单创建日期
+				String orderDate = null;
+				if (proecessTemp.getBillId() != null) {
+					if (order != null) {
+						orderDate = simpleDateFormat.format(order.getCreateTime());
+					}
+				}
+
+				Message message = new Message();
+				message.setUserName(AuthUtil.getUserName());
+				message.setUserId(AuthUtil.getUserId());
+				message.setParameter(String.valueOf(auditProecess.getBillId()));
+				message.setMessageType(1);
+				message.setTenantId(AuthUtil.getTenantId());
+				//报关模板
+				message.setMessageBody("您有销售退单审核,订单单号:" + "" + proecessTemp.getBillNo() + ","
+					+ "订单日期:" + orderDate + ",请审核。"
+					+ "提交人:" + proecessTemp.getSendName() + "  " + "提交时间" + simpleDateFormat.format(proecessTemp.getSendTime())
+				);
+
+				message.setCreateUser(AuthUtil.getUserId());
+				message.setUrl("/businessManagement/salesOrder/index");
+				message.setCreateTime(new Date());
+
+				// 消息批量通知下一级
+				sendMsgToGroup(message, proecess.getAuditUserId());
+			}
+			//不通过
+			else if (operate == 2) {
+				auditProecess.setAuditStatus("B");
+				//todo 调用feign取消
+				R r = orderCheckClient.passChargeBackCancel(auditProecess.getSrcBillId());//审批不通过
+				if (!r.isSuccess()) {
+					throw new SecurityException("修改订单数据失败");
+				}
+
+				sendMessage.setMessageBody("您的销售退单审核未通过" + ",订单号:" + proecessTemp.getBillNo() + ",驳回原因:" + auditProecess.getAuditMsg());
+				R save = messageClient.save(sendMessage);
+				if (!save.isSuccess()) {
+					throw new SecurityException("发送消息失败");
+				}
+			}
+
+		}
+		//是最后一级
+		else if ("T".equals(iffinalItem)) {
+			//通过
+			if (operate == 1) {
+				//todo 调用feign直接通过
+				auditProecess.setAuditStatus("A");
+				R r = orderCheckClient.checkRepealCancel(auditProecess.getSrcBillId());//审批通过
+				if (!r.isSuccess()) {
+					throw new SecurityException("修改订单数据失败");
+				}
+
+				sendMessage.setMessageBody("您的销售退单审核已通过" + ",订单号:" + proecessTemp.getBillNo() + ",请继续操作");
+				R save = messageClient.save(sendMessage);
+				if (!save.isSuccess()) {
+					throw new SecurityException("发送消息失败");
+				}
+			}
+			//不通过
+			else if (operate == 2) {
+				//todo 调用feign取消
+				auditProecess.setAuditStatus("B");
+				R r = orderCheckClient.passChargeBackCancel(auditProecess.getSrcBillId());
+				if (!r.isSuccess()) {
+					throw new SecurityException("修改订单数据失败");
+				}
+				sendMessage.setMessageBody("您的销售退单审核未通过" + ",订单号:" + proecessTemp.getBillNo() + ",驳回原因:" + auditProecess.getAuditMsg());
+				R save = messageClient.save(sendMessage);
+				if (!save.isSuccess()) {
+					throw new SecurityException("发送消息失败");
+				}
+			}
+		} else {
+			throw new SecurityException("审批异常,请联系管理员");
+		}
+
+		cleanMsg(proecessTemp.getAuditUserId(), AuthUtil.getUserId(), proecessTemp.getSrcBillId());
+
+		//保存操作记录
+		auditProecess.setAuditMsg(auditProecess.getAuditMsg());
+		auditProecess.setAuditItem(new Date());
+		baseMapper.updateById(auditProecess);
+	}
+
 	@Override
 	@Transactional(rollbackFor = Exception.class)
 	@GlobalTransactional(rollbackFor = Exception.class)
@@ -2320,7 +2490,7 @@ public class AuditProecessServiceImpl extends ServiceImpl<AuditProecessMapper, A
 			if (operate == 1) {
 				//todo 调用feign直接通过
 				auditProecess.setAuditStatus("A");
-				R r = agreementClient.agreementUnderReview(auditProecess.getSrcBillId());
+				R r = agreementClient.agreementPassCheck(auditProecess.getSrcBillId());
 				if (!r.isSuccess()) {
 					throw new SecurityException("修改订单数据失败");
 				}

+ 1 - 1
blade-service/blade-purchase-sales/src/main/java/org/springblade/purchase/sales/export/ExportOrderController.java

@@ -1228,7 +1228,7 @@ public class ExportOrderController extends BladeController {
 	/**
 	 * 统计分析明细导出统一接口
 	 */
-	@GetMapping("/统计分析明细导出统一接口")
+	@GetMapping("/timeUnifiedExport")
 	@ApiOperation(value = "统计分析明细导出统一接口", notes = "统计分析明细导出统一接口")
 	public void timeUnifiedExport(OrderStatisticsVo statisticsVo, HttpServletResponse response){
 		statisticsVo.setTenantId(SecureUtil.getTenantId());

+ 234 - 186
blade-service/blade-purchase-sales/src/main/java/org/springblade/purchase/sales/mapper/OrderMapper.xml

@@ -2392,328 +2392,352 @@ ORDER BY
         FROM
         business_order BO
         LEFT JOIN (
-        SELECT
-        b.id,
-        bt.item_id,
-        sum( b.debit_amount ) AS amount,
-        sum( bt.quantity ) AS quantity
-        FROM
-        business_order b
-        LEFT JOIN (
-        SELECT
-        pid,
-        item_id,
-        IF
-        ( actual_quantity = 0, IFNULL( sum( order_quantity ), 0 ), IFNULL( sum( actual_quantity ), 0 ) ) AS quantity
-        FROM
-        business_order_items
-        WHERE
-        is_deleted = 0
-        GROUP BY
-        pid
-        ) bt ON bt.pid = b.id
-        WHERE
-        IF
-        ( receipt_time IS NOT NULL, MONTH ( receipt_time ) = 1, MONTH ( create_time ) = 1 )
-        GROUP BY
-        b.id
+            SELECT
+                b.id,
+                bt.id as btid,
+                bt.item_id,
+                bt.amount AS amount,
+                bt.quantity AS quantity
+            FROM
+                business_order b
+            LEFT JOIN (
+                SELECT
+                    id,
+                    pid,
+                    item_id,
+                    actual_quantity AS quantity,
+                    Round(actual_quantity * price, 2) AS amount
+                FROM
+                    business_order_items
+                WHERE
+                    is_deleted = 0
+                GROUP BY
+                    id
+            ) bt ON bt.pid = b.id
+            WHERE
+                IF
+                ( b.receipt_time IS NOT NULL, MONTH ( b.receipt_time ) = 1, MONTH ( b.create_time ) = 1 )
+            GROUP BY
+                btid
         ) BOI1 ON BOI1.id = BO.id
         LEFT JOIN (
         SELECT
         b.id,
+        bt.id as btid,
         bt.item_id,
-        sum( b.debit_amount ) AS amount,
-        sum( bt.quantity ) AS quantity
+        bt.amount AS amount,
+        bt.quantity AS quantity
         FROM
         business_order b
         LEFT JOIN (
         SELECT
+        id,
         pid,
         item_id,
-        IF
-        ( actual_quantity = 0, IFNULL( sum( order_quantity ), 0 ), IFNULL( sum( actual_quantity ), 0 ) ) AS quantity
+        actual_quantity AS quantity,
+        Round(actual_quantity * price, 2) AS amount
         FROM
         business_order_items
         WHERE
         is_deleted = 0
         GROUP BY
-        pid
+        id
         ) bt ON bt.pid = b.id
         WHERE
         IF
-        ( receipt_time IS NOT NULL, MONTH ( receipt_time ) = 2, MONTH ( create_time ) = 2 )
+        ( b.receipt_time IS NOT NULL, MONTH ( b.receipt_time ) = 2, MONTH ( b.create_time ) = 2 )
         GROUP BY
-        b.id
+        btid
         ) BOI2 ON BOI2.id = BO.id
         LEFT JOIN (
         SELECT
         b.id,
+        bt.id as btid,
         bt.item_id,
-        sum( b.debit_amount ) AS amount,
-        sum( bt.quantity ) AS quantity
+        bt.amount AS amount,
+        bt.quantity AS quantity
         FROM
         business_order b
         LEFT JOIN (
         SELECT
+        id,
         pid,
         item_id,
-        IF
-        ( actual_quantity = 0, IFNULL( sum( order_quantity ), 0 ), IFNULL( sum( actual_quantity ), 0 ) ) AS quantity
+        actual_quantity AS quantity,
+        Round(actual_quantity * price, 2) AS amount
         FROM
         business_order_items
         WHERE
         is_deleted = 0
         GROUP BY
-        pid
+        id
         ) bt ON bt.pid = b.id
         WHERE
         IF
-        ( receipt_time IS NOT NULL, MONTH ( receipt_time ) = 3, MONTH ( create_time ) = 3 )
+        ( b.receipt_time IS NOT NULL, MONTH ( b.receipt_time ) = 3, MONTH ( b.create_time ) = 3 )
         GROUP BY
-        b.id
+        btid
         ) BOI3 ON BOI3.id = BO.id
         LEFT JOIN (
         SELECT
         b.id,
+        bt.id as btid,
         bt.item_id,
-        sum( b.debit_amount ) AS amount,
-        sum( bt.quantity ) AS quantity
+        bt.amount AS amount,
+        bt.quantity AS quantity
         FROM
         business_order b
         LEFT JOIN (
         SELECT
+        id,
         pid,
         item_id,
-        IF
-        ( actual_quantity = 0, IFNULL( sum( order_quantity ), 0 ), IFNULL( sum( actual_quantity ), 0 ) ) AS quantity
+        actual_quantity AS quantity,
+        Round(actual_quantity * price, 2) AS amount
         FROM
         business_order_items
         WHERE
         is_deleted = 0
         GROUP BY
-        pid
+        id
         ) bt ON bt.pid = b.id
         WHERE
         IF
-        ( receipt_time IS NOT NULL, MONTH ( receipt_time ) = 4, MONTH ( create_time ) = 4 )
+        ( b.receipt_time IS NOT NULL, MONTH ( b.receipt_time ) = 4, MONTH ( b.create_time ) = 4 )
         GROUP BY
-        b.id
+        btid
         ) BOI4 ON BOI4.id = BO.id
         LEFT JOIN (
         SELECT
         b.id,
+        bt.id as btid,
         bt.item_id,
-        sum( b.debit_amount ) AS amount,
-        sum( bt.quantity ) AS quantity
+        bt.amount AS amount,
+        bt.quantity AS quantity
         FROM
         business_order b
         LEFT JOIN (
         SELECT
+        id,
         pid,
         item_id,
-        IF
-        ( actual_quantity = 0, IFNULL( sum( order_quantity ), 0 ), IFNULL( sum( actual_quantity ), 0 ) ) AS quantity
+        actual_quantity AS quantity,
+        Round(actual_quantity * price, 2) AS amount
         FROM
         business_order_items
         WHERE
         is_deleted = 0
         GROUP BY
-        pid
+        id
         ) bt ON bt.pid = b.id
         WHERE
         IF
-        ( receipt_time IS NOT NULL, MONTH ( receipt_time ) = 5, MONTH ( create_time ) = 5 )
+        ( b.receipt_time IS NOT NULL, MONTH ( b.receipt_time ) = 5, MONTH ( b.create_time ) = 5 )
         GROUP BY
-        b.id
+        btid
         ) BOI5 ON BOI5.id = BO.id
         LEFT JOIN (
         SELECT
         b.id,
+        bt.id as btid,
         bt.item_id,
-        sum( b.debit_amount ) AS amount,
-        sum( bt.quantity ) AS quantity
+        bt.amount AS amount,
+        bt.quantity AS quantity
         FROM
         business_order b
         LEFT JOIN (
         SELECT
+        id,
         pid,
         item_id,
-        IF
-        ( actual_quantity = 0, IFNULL( sum( order_quantity ), 0 ), IFNULL( sum( actual_quantity ), 0 ) ) AS quantity
+        actual_quantity AS quantity,
+        Round(actual_quantity * price, 2) AS amount
         FROM
         business_order_items
         WHERE
         is_deleted = 0
         GROUP BY
-        pid
+        id
         ) bt ON bt.pid = b.id
         WHERE
         IF
-        ( receipt_time IS NOT NULL, MONTH ( receipt_time ) = 6, MONTH ( create_time ) = 6 )
+        ( b.receipt_time IS NOT NULL, MONTH ( b.receipt_time ) = 6, MONTH ( b.create_time ) = 6 )
         GROUP BY
-        b.id
+        btid
         ) BOI6 ON BOI6.id = BO.id
         LEFT JOIN (
         SELECT
         b.id,
+        bt.id as btid,
         bt.item_id,
-        sum( b.debit_amount ) AS amount,
-        sum( bt.quantity ) AS quantity
+        bt.amount AS amount,
+        bt.quantity AS quantity
         FROM
         business_order b
         LEFT JOIN (
         SELECT
+        id,
         pid,
         item_id,
-        IF
-        ( actual_quantity = 0, IFNULL( sum( order_quantity ), 0 ), IFNULL( sum( actual_quantity ), 0 ) ) AS quantity
+        actual_quantity AS quantity,
+        Round(actual_quantity * price, 2) AS amount
         FROM
         business_order_items
         WHERE
         is_deleted = 0
         GROUP BY
-        pid
+        id
         ) bt ON bt.pid = b.id
         WHERE
         IF
-        ( receipt_time IS NOT NULL, MONTH ( receipt_time ) = 7, MONTH ( create_time ) = 7 )
+        ( b.receipt_time IS NOT NULL, MONTH ( b.receipt_time ) = 7, MONTH ( b.create_time ) = 7 )
         GROUP BY
-        b.id
+        btid
         ) BOI7 ON BOI7.id = BO.id
         LEFT JOIN (
         SELECT
         b.id,
+        bt.id as btid,
         bt.item_id,
-        sum( b.debit_amount ) AS amount,
-        sum( bt.quantity ) AS quantity
+        bt.amount AS amount,
+        bt.quantity AS quantity
         FROM
         business_order b
         LEFT JOIN (
         SELECT
+        id,
         pid,
         item_id,
-        IF
-        ( actual_quantity = 0, IFNULL( sum( order_quantity ), 0 ), IFNULL( sum( actual_quantity ), 0 ) ) AS quantity
+        actual_quantity AS quantity,
+        Round(actual_quantity * price, 2) AS amount
         FROM
         business_order_items
         WHERE
         is_deleted = 0
         GROUP BY
-        pid
+        id
         ) bt ON bt.pid = b.id
         WHERE
         IF
-        ( receipt_time IS NOT NULL, MONTH ( receipt_time ) = 8, MONTH ( create_time ) = 8 )
+        ( b.receipt_time IS NOT NULL, MONTH ( b.receipt_time ) = 8, MONTH ( b.create_time ) = 8 )
         GROUP BY
-        b.id
+        btid
         ) BOI8 ON BOI8.id = BO.id
         LEFT JOIN (
         SELECT
         b.id,
+        bt.id as btid,
         bt.item_id,
-        sum( b.debit_amount ) AS amount,
-        sum( bt.quantity ) AS quantity
+        bt.amount AS amount,
+        bt.quantity AS quantity
         FROM
         business_order b
         LEFT JOIN (
         SELECT
+        id,
         pid,
         item_id,
-        IF
-        ( actual_quantity = 0, IFNULL( sum( order_quantity ), 0 ), IFNULL( sum( actual_quantity ), 0 ) ) AS quantity
+        actual_quantity AS quantity,
+        Round(actual_quantity * price, 2) AS amount
         FROM
         business_order_items
         WHERE
         is_deleted = 0
         GROUP BY
-        pid
+        id
         ) bt ON bt.pid = b.id
         WHERE
         IF
-        ( receipt_time IS NOT NULL, MONTH ( receipt_time ) = 9, MONTH ( create_time ) = 9 )
+        ( b.receipt_time IS NOT NULL, MONTH ( b.receipt_time ) = 9, MONTH ( b.create_time ) = 9 )
         GROUP BY
-        b.id
+        btid
         ) BOI9 ON BOI9.id = BO.id
         LEFT JOIN (
         SELECT
         b.id,
+        bt.id as btid,
         bt.item_id,
-        sum( b.debit_amount ) AS amount,
-        sum( bt.quantity ) AS quantity
+        bt.amount AS amount,
+        bt.quantity AS quantity
         FROM
         business_order b
         LEFT JOIN (
         SELECT
+        id,
         pid,
         item_id,
-        IF
-        ( actual_quantity = 0, IFNULL( sum( order_quantity ), 0 ), IFNULL( sum( actual_quantity ), 0 ) ) AS quantity
+        actual_quantity AS quantity,
+        Round(actual_quantity * price, 2) AS amount
         FROM
         business_order_items
         WHERE
         is_deleted = 0
         GROUP BY
-        pid
+        id
         ) bt ON bt.pid = b.id
         WHERE
         IF
-        ( receipt_time IS NOT NULL, MONTH ( receipt_time ) = 10, MONTH ( create_time ) = 10 )
+        ( b.receipt_time IS NOT NULL, MONTH ( b.receipt_time ) = 10, MONTH ( b.create_time ) = 10 )
         GROUP BY
-        b.id
+        btid
         ) BOI10 ON BOI10.id = BO.id
         LEFT JOIN (
         SELECT
         b.id,
+        bt.id as btid,
         bt.item_id,
-        sum( b.debit_amount ) AS amount,
-        sum( bt.quantity ) AS quantity
+        bt.amount AS amount,
+        bt.quantity AS quantity
         FROM
         business_order b
         LEFT JOIN (
         SELECT
+        id,
         pid,
         item_id,
-        IF
-        ( actual_quantity = 0, IFNULL( sum( order_quantity ), 0 ), IFNULL( sum( actual_quantity ), 0 ) ) AS quantity
+        actual_quantity AS quantity,
+        Round(actual_quantity * price, 2) AS amount
         FROM
         business_order_items
         WHERE
         is_deleted = 0
         GROUP BY
-        pid
+        id
         ) bt ON bt.pid = b.id
         WHERE
         IF
-        ( receipt_time IS NOT NULL, MONTH ( receipt_time ) = 11, MONTH ( create_time ) = 11 )
+        ( b.receipt_time IS NOT NULL, MONTH ( b.receipt_time ) = 11, MONTH ( b.create_time ) = 11 )
         GROUP BY
-        b.id
+        btid
         ) BOI11 ON BOI11.id = BO.id
         LEFT JOIN (
         SELECT
         b.id,
+        bt.id as btid,
         bt.item_id,
-        sum( b.debit_amount ) AS amount,
-        sum( bt.quantity ) AS quantity
+        bt.amount AS amount,
+        bt.quantity AS quantity
         FROM
         business_order b
         LEFT JOIN (
         SELECT
+        id,
         pid,
         item_id,
-        IF
-        ( actual_quantity = 0, IFNULL( sum( order_quantity ), 0 ), IFNULL( sum( actual_quantity ), 0 ) ) AS quantity
+        actual_quantity AS quantity,
+        Round(actual_quantity * price, 2) AS amount
         FROM
         business_order_items
         WHERE
         is_deleted = 0
         GROUP BY
-        pid
+        id
         ) bt ON bt.pid = b.id
         WHERE
         IF
-        ( receipt_time IS NOT NULL, MONTH ( receipt_time ) = 12, MONTH ( create_time ) = 12 )
+        ( b.receipt_time IS NOT NULL, MONTH ( b.receipt_time ) = 12, MONTH ( b.create_time ) = 12 )
         GROUP BY
-        b.id
+        btid
         ) BOI12 ON BOI12.id = BO.id
         LEFT JOIN basic_goods_desc BGD ON BOI1.Item_id = BGD.id
         OR BOI2.Item_id = BGD.id
@@ -2840,326 +2864,350 @@ ORDER BY
         LEFT JOIN (
         SELECT
         b.id,
+        bt.id as btid,
         bt.item_id,
-        sum( b.debit_amount ) AS amount,
-        sum( bt.quantity ) AS quantity
+        bt.amount AS amount,
+        bt.quantity AS quantity
         FROM
         business_order b
         LEFT JOIN (
         SELECT
+        id,
         pid,
         item_id,
-        IF
-        ( actual_quantity = 0, IFNULL( sum( order_quantity ), 0 ), IFNULL( sum( actual_quantity ), 0 ) ) AS quantity
+        actual_quantity AS quantity,
+        Round(actual_quantity * price, 2) AS amount
         FROM
         business_order_items
         WHERE
         is_deleted = 0
         GROUP BY
-        pid
+        id
         ) bt ON bt.pid = b.id
         WHERE
         IF
-        ( receipt_time IS NOT NULL, MONTH ( receipt_time ) = 1, MONTH ( create_time ) = 1 )
+        ( b.receipt_time IS NOT NULL, MONTH ( b.receipt_time ) = 1, MONTH ( b.create_time ) = 1 )
         GROUP BY
-        b.id
+        btid
         ) BOI1 ON BOI1.id = BO.id
         LEFT JOIN (
         SELECT
         b.id,
+        bt.id as btid,
         bt.item_id,
-        sum( b.debit_amount ) AS amount,
-        sum( bt.quantity ) AS quantity
+        bt.amount AS amount,
+        bt.quantity AS quantity
         FROM
         business_order b
         LEFT JOIN (
         SELECT
+        id,
         pid,
         item_id,
-        IF
-        ( actual_quantity = 0, IFNULL( sum( order_quantity ), 0 ), IFNULL( sum( actual_quantity ), 0 ) ) AS quantity
+        actual_quantity AS quantity,
+        Round(actual_quantity * price, 2) AS amount
         FROM
         business_order_items
         WHERE
         is_deleted = 0
         GROUP BY
-        pid
+        id
         ) bt ON bt.pid = b.id
         WHERE
         IF
-        ( receipt_time IS NOT NULL, MONTH ( receipt_time ) = 2, MONTH ( create_time ) = 2 )
+        ( b.receipt_time IS NOT NULL, MONTH ( b.receipt_time ) = 2, MONTH ( b.create_time ) = 2 )
         GROUP BY
-        b.id
+        btid
         ) BOI2 ON BOI2.id = BO.id
         LEFT JOIN (
         SELECT
         b.id,
+        bt.id as btid,
         bt.item_id,
-        sum( b.debit_amount ) AS amount,
-        sum( bt.quantity ) AS quantity
+        bt.amount AS amount,
+        bt.quantity AS quantity
         FROM
         business_order b
         LEFT JOIN (
         SELECT
+        id,
         pid,
         item_id,
-        IF
-        ( actual_quantity = 0, IFNULL( sum( order_quantity ), 0 ), IFNULL( sum( actual_quantity ), 0 ) ) AS quantity
+        actual_quantity AS quantity,
+        Round(actual_quantity * price, 2) AS amount
         FROM
         business_order_items
         WHERE
         is_deleted = 0
         GROUP BY
-        pid
+        id
         ) bt ON bt.pid = b.id
         WHERE
         IF
-        ( receipt_time IS NOT NULL, MONTH ( receipt_time ) = 3, MONTH ( create_time ) = 3 )
+        ( b.receipt_time IS NOT NULL, MONTH ( b.receipt_time ) = 3, MONTH ( b.create_time ) = 3 )
         GROUP BY
-        b.id
+        btid
         ) BOI3 ON BOI3.id = BO.id
         LEFT JOIN (
         SELECT
         b.id,
+        bt.id as btid,
         bt.item_id,
-        sum( b.debit_amount ) AS amount,
-        sum( bt.quantity ) AS quantity
+        bt.amount AS amount,
+        bt.quantity AS quantity
         FROM
         business_order b
         LEFT JOIN (
         SELECT
+        id,
         pid,
         item_id,
-        IF
-        ( actual_quantity = 0, IFNULL( sum( order_quantity ), 0 ), IFNULL( sum( actual_quantity ), 0 ) ) AS quantity
+        actual_quantity AS quantity,
+        Round(actual_quantity * price, 2) AS amount
         FROM
         business_order_items
         WHERE
         is_deleted = 0
         GROUP BY
-        pid
+        id
         ) bt ON bt.pid = b.id
         WHERE
         IF
-        ( receipt_time IS NOT NULL, MONTH ( receipt_time ) = 4, MONTH ( create_time ) = 4 )
+        ( b.receipt_time IS NOT NULL, MONTH ( b.receipt_time ) = 4, MONTH ( b.create_time ) = 4 )
         GROUP BY
-        b.id
+        btid
         ) BOI4 ON BOI4.id = BO.id
         LEFT JOIN (
         SELECT
         b.id,
+        bt.id as btid,
         bt.item_id,
-        sum( b.debit_amount ) AS amount,
-        sum( bt.quantity ) AS quantity
+        bt.amount AS amount,
+        bt.quantity AS quantity
         FROM
         business_order b
         LEFT JOIN (
         SELECT
+        id,
         pid,
         item_id,
-        IF
-        ( actual_quantity = 0, IFNULL( sum( order_quantity ), 0 ), IFNULL( sum( actual_quantity ), 0 ) ) AS quantity
+        actual_quantity AS quantity,
+        Round(actual_quantity * price, 2) AS amount
         FROM
         business_order_items
         WHERE
         is_deleted = 0
         GROUP BY
-        pid
+        id
         ) bt ON bt.pid = b.id
         WHERE
         IF
-        ( receipt_time IS NOT NULL, MONTH ( receipt_time ) = 5, MONTH ( create_time ) = 5 )
+        ( b.receipt_time IS NOT NULL, MONTH ( b.receipt_time ) = 5, MONTH ( b.create_time ) = 5 )
         GROUP BY
-        b.id
+        btid
         ) BOI5 ON BOI5.id = BO.id
         LEFT JOIN (
         SELECT
         b.id,
+        bt.id as btid,
         bt.item_id,
-        sum( b.debit_amount ) AS amount,
-        sum( bt.quantity ) AS quantity
+        bt.amount AS amount,
+        bt.quantity AS quantity
         FROM
         business_order b
         LEFT JOIN (
         SELECT
+        id,
         pid,
         item_id,
-        IF
-        ( actual_quantity = 0, IFNULL( sum( order_quantity ), 0 ), IFNULL( sum( actual_quantity ), 0 ) ) AS quantity
+        actual_quantity AS quantity,
+        Round(actual_quantity * price, 2) AS amount
         FROM
         business_order_items
         WHERE
         is_deleted = 0
         GROUP BY
-        pid
+        id
         ) bt ON bt.pid = b.id
         WHERE
         IF
-        ( receipt_time IS NOT NULL, MONTH ( receipt_time ) = 6, MONTH ( create_time ) = 6 )
+        ( b.receipt_time IS NOT NULL, MONTH ( b.receipt_time ) = 6, MONTH ( b.create_time ) = 6 )
         GROUP BY
-        b.id
+        btid
         ) BOI6 ON BOI6.id = BO.id
         LEFT JOIN (
         SELECT
         b.id,
+        bt.id as btid,
         bt.item_id,
-        sum( b.debit_amount ) AS amount,
-        sum( bt.quantity ) AS quantity
+        bt.amount AS amount,
+        bt.quantity AS quantity
         FROM
         business_order b
         LEFT JOIN (
         SELECT
+        id,
         pid,
         item_id,
-        IF
-        ( actual_quantity = 0, IFNULL( sum( order_quantity ), 0 ), IFNULL( sum( actual_quantity ), 0 ) ) AS quantity
+        actual_quantity AS quantity,
+        Round(actual_quantity * price, 2) AS amount
         FROM
         business_order_items
         WHERE
         is_deleted = 0
         GROUP BY
-        pid
+        id
         ) bt ON bt.pid = b.id
         WHERE
         IF
-        ( receipt_time IS NOT NULL, MONTH ( receipt_time ) = 7, MONTH ( create_time ) = 7 )
+        ( b.receipt_time IS NOT NULL, MONTH ( b.receipt_time ) = 7, MONTH ( b.create_time ) = 7 )
         GROUP BY
-        b.id
+        btid
         ) BOI7 ON BOI7.id = BO.id
         LEFT JOIN (
         SELECT
         b.id,
+        bt.id as btid,
         bt.item_id,
-        sum( b.debit_amount ) AS amount,
-        sum( bt.quantity ) AS quantity
+        bt.amount AS amount,
+        bt.quantity AS quantity
         FROM
         business_order b
         LEFT JOIN (
         SELECT
+        id,
         pid,
         item_id,
-        IF
-        ( actual_quantity = 0, IFNULL( sum( order_quantity ), 0 ), IFNULL( sum( actual_quantity ), 0 ) ) AS quantity
+        actual_quantity AS quantity,
+        Round(actual_quantity * price, 2) AS amount
         FROM
         business_order_items
         WHERE
         is_deleted = 0
         GROUP BY
-        pid
+        id
         ) bt ON bt.pid = b.id
         WHERE
         IF
-        ( receipt_time IS NOT NULL, MONTH ( receipt_time ) = 8, MONTH ( create_time ) = 8 )
+        ( b.receipt_time IS NOT NULL, MONTH ( b.receipt_time ) = 8, MONTH ( b.create_time ) = 8 )
         GROUP BY
-        b.id
+        btid
         ) BOI8 ON BOI8.id = BO.id
         LEFT JOIN (
         SELECT
         b.id,
+        bt.id as btid,
         bt.item_id,
-        sum( b.debit_amount ) AS amount,
-        sum( bt.quantity ) AS quantity
+        bt.amount AS amount,
+        bt.quantity AS quantity
         FROM
         business_order b
         LEFT JOIN (
         SELECT
+        id,
         pid,
         item_id,
-        IF
-        ( actual_quantity = 0, IFNULL( sum( order_quantity ), 0 ), IFNULL( sum( actual_quantity ), 0 ) ) AS quantity
+        actual_quantity AS quantity,
+        Round(actual_quantity * price, 2) AS amount
         FROM
         business_order_items
         WHERE
         is_deleted = 0
         GROUP BY
-        pid
+        id
         ) bt ON bt.pid = b.id
         WHERE
         IF
-        ( receipt_time IS NOT NULL, MONTH ( receipt_time ) = 9, MONTH ( create_time ) = 9 )
+        ( b.receipt_time IS NOT NULL, MONTH ( b.receipt_time ) = 9, MONTH ( b.create_time ) = 9 )
         GROUP BY
-        b.id
+        btid
         ) BOI9 ON BOI9.id = BO.id
         LEFT JOIN (
         SELECT
         b.id,
+        bt.id as btid,
         bt.item_id,
-        sum( b.debit_amount ) AS amount,
-        sum( bt.quantity ) AS quantity
+        bt.amount AS amount,
+        bt.quantity AS quantity
         FROM
         business_order b
         LEFT JOIN (
         SELECT
+        id,
         pid,
         item_id,
-        IF
-        ( actual_quantity = 0, IFNULL( sum( order_quantity ), 0 ), IFNULL( sum( actual_quantity ), 0 ) ) AS quantity
+        actual_quantity AS quantity,
+        Round(actual_quantity * price, 2) AS amount
         FROM
         business_order_items
         WHERE
         is_deleted = 0
         GROUP BY
-        pid
+        id
         ) bt ON bt.pid = b.id
         WHERE
         IF
-        ( receipt_time IS NOT NULL, MONTH ( receipt_time ) = 10, MONTH ( create_time ) = 10 )
+        ( b.receipt_time IS NOT NULL, MONTH ( b.receipt_time ) = 10, MONTH ( b.create_time ) = 10 )
         GROUP BY
-        b.id
+        btid
         ) BOI10 ON BOI10.id = BO.id
         LEFT JOIN (
         SELECT
         b.id,
+        bt.id as btid,
         bt.item_id,
-        sum( b.debit_amount ) AS amount,
-        sum( bt.quantity ) AS quantity
+        bt.amount AS amount,
+        bt.quantity AS quantity
         FROM
         business_order b
         LEFT JOIN (
         SELECT
+        id,
         pid,
         item_id,
-        IF
-        ( actual_quantity = 0, IFNULL( sum( order_quantity ), 0 ), IFNULL( sum( actual_quantity ), 0 ) ) AS quantity
+        actual_quantity AS quantity,
+        Round(actual_quantity * price, 2) AS amount
         FROM
         business_order_items
         WHERE
         is_deleted = 0
         GROUP BY
-        pid
+        id
         ) bt ON bt.pid = b.id
         WHERE
         IF
-        ( receipt_time IS NOT NULL, MONTH ( receipt_time ) = 11, MONTH ( create_time ) = 11 )
+        ( b.receipt_time IS NOT NULL, MONTH ( b.receipt_time ) = 11, MONTH ( b.create_time ) = 11 )
         GROUP BY
-        b.id
+        btid
         ) BOI11 ON BOI11.id = BO.id
         LEFT JOIN (
         SELECT
         b.id,
+        bt.id as btid,
         bt.item_id,
-        sum( b.debit_amount ) AS amount,
-        sum( bt.quantity ) AS quantity
+        bt.amount AS amount,
+        bt.quantity AS quantity
         FROM
         business_order b
         LEFT JOIN (
         SELECT
+        id,
         pid,
         item_id,
-        IF
-        ( actual_quantity = 0, IFNULL( sum( order_quantity ), 0 ), IFNULL( sum( actual_quantity ), 0 ) ) AS quantity
+        actual_quantity AS quantity,
+        Round(actual_quantity * price, 2) AS amount
         FROM
         business_order_items
         WHERE
         is_deleted = 0
         GROUP BY
-        pid
+        id
         ) bt ON bt.pid = b.id
         WHERE
         IF
-        ( receipt_time IS NOT NULL, MONTH ( receipt_time ) = 12, MONTH ( create_time ) = 12 )
+        ( b.receipt_time IS NOT NULL, MONTH ( b.receipt_time ) = 12, MONTH ( b.create_time ) = 12 )
         GROUP BY
-        b.id
+        btid
         ) BOI12 ON BOI12.id = BO.id
         LEFT JOIN basic_goods_desc BGD ON BOI1.Item_id = BGD.id
         OR BOI2.Item_id = BGD.id

+ 2 - 2
blade-service/blade-purchase-sales/src/main/java/org/springblade/purchase/sales/service/impl/OrderServiceImpl.java

@@ -1030,7 +1030,7 @@ public class OrderServiceImpl extends ServiceImpl<OrderMapper, Order> implements
 						// 更新库存
 						boolean goods = stockGoodsClient.updateStock(oneStock);
 						if (!goods) {
-							throw new SecurityException("锁定库存失败: 更新失败");
+							throw new SecurityException("锁定库存失败: " + oneStock.getCode() + "更新失败");
 						}
 					});
 				}
@@ -1208,7 +1208,7 @@ public class OrderServiceImpl extends ServiceImpl<OrderMapper, Order> implements
 			}
 
 			// 绑定审核类型
-			auditProecessDTO.setCheckType("XSTD");//代理订
+			auditProecessDTO.setCheckType("XSTD");//销售退
 			// 追加跳转路由url
 			auditProecessDTO.setUrl(salesOrder.getUrl());
 			auditProecessDTO.setPageStatus(salesOrder.getPageStatus());

+ 2 - 2
blade-service/trade-finance/src/main/java/org/springblade/finance/mapper/AccMapper.xml

@@ -68,10 +68,10 @@
         BCD.cname AS corpName,
         IFNULL( BC.amount, 0 ) AS amount,
         IFNULL( FS.settlementAmount, 0 ) AS settlementAmount,
-        IFNULL( IFNULL( BC.amount, 0 ) - IFNULL( FS.settlementAmount, 0 ), 0 ) AS balance,
+        IFNULL( IFNULL( BC.amount, 0 ) - IFNULL( FS.settlementAmount, 0 ) - IFNULL( FS.caseOverPayment, 0 ) + IFNULL( BCD.opening_amount, 0 ), 0 ) AS balance,
         IFNULL( FS.caseOverPayment, 0 ) AS caseOverPayment,
         IFNULL( BO.balance_overpaymen, 0 ) AS inOverpayment,
-        BCD.opening_amount AS openingAmount
+        IFNULL( BCD.opening_amount, 0 ) AS openingAmount
         FROM finance_acc FC
         LEFT JOIN basic_corps_desc BCD ON BCD.id = FC.Corpid
         LEFT JOIN business_overpayment BO ON BO.corp_id = FC.Corpid