Monterey %!s(int64=3) %!d(string=hai) anos
pai
achega
2165666885

+ 63 - 21
ruoyi-admin/src/main/java/com/ruoyi/web/H5Api/api/H5OrderController.java

@@ -1,5 +1,7 @@
 package com.ruoyi.web.H5Api.api;
 
+import java.math.BigDecimal;
+import java.util.ArrayList;
 import java.util.Date;
 import java.util.List;
 import java.util.Map;
@@ -276,8 +278,42 @@ public class H5OrderController extends BaseController {
     @RepeatSubmit
     @PostMapping("/aiPay")
     public AjaxResult aiPay(@RequestBody TOrderManageTotal orderManageTotal) {
+		//按分
+		int len = orderManageTotal.getOrderList().size();
+		//total
+		BigDecimal total = orderManageTotal.getOrderMoney();
+		
+		BigDecimal sendAmout = BigDecimal.ZERO;
+		//提交多条数据的时候要进行按分。
+		if (len > 1) {
+			int cnt = 0;
+			BigDecimal anbun = BigDecimal.ZERO;
+			//
+			BigDecimal preTotal = BigDecimal.ZERO;
+			for (TOrderManage orderManageTemp : orderManageTotal.getOrderList()) {
+				preTotal=preTotal.add(orderManageTemp.getOrderMoney());
+			}
+			for (TOrderManage orderManage : orderManageTotal.getOrderList()) {
+				cnt++;
+				//amount
+				BigDecimal amount = BigDecimal.ZERO;
+				if (cnt == len) {
+					amount = total.subtract(anbun);
+				} else {
+					amount = orderManage.getOrderMoney().multiply(total).divide(preTotal, BigDecimal.ROUND_UP);
+					anbun = anbun.add(amount);
+				}
+				
+				orderManage.setOrderMoney(amount);
+				
+				sendAmout = sendAmout.add(amount);
+			}
+		} else {
+			orderManageTotal.getOrderList().get(0).setOrderMoney(total);
+			sendAmout = total;
+		}
     	//0元LINE支付不要。
-    	if (orderManageTotal.getOrderMoney().longValue() == 0) {
+    	if (sendAmout.intValue() == 0) {
     		//
     		payApi.pay(orderManageTotal, getLoginUser());
     		
@@ -289,10 +325,12 @@ public class H5OrderController extends BaseController {
     	//ok
     	if (resp != null && "0000".equals(resp.returnCode)) {
     		//set the transactionId to the db.
-    		orderManageTotal.setTransactionId(resp.info.transactionId);
-    		
+    		for (TOrderManage order : orderManageTotal.getOrderList()) {
+    			order.setTransactionId(resp.info.transactionId);
+    			orderManageService.updateTOrderManage(order);
+    		}
+    		//update ordermoney
     		orderManageTotalService.updateTOrderManageTotal(orderManageTotal);
-    		
     		return AjaxResult.success(resp.info);
     	}
     	//line支付error
@@ -309,15 +347,18 @@ public class H5OrderController extends BaseController {
     @RepeatSubmit
     @PostMapping("/cancel")
     public AjaxResult apayCancelCallBack(@RequestBody LineCallBankParam param) {
-    	//
-    	TOrderManageTotal select = new TOrderManageTotal();
     	
-    	select.setTransactionId(param.getTransactionId());
-    	select.setId(param.getOrderId());
-    	select.setDelFlag("1");
+    	String[] orderIds = param.getOrderId().split("_");
     	
-    	orderManageTotalService.updateTOrderManageTotal(select);
-
+    	for (int i = 1; i < orderIds.length; i++) {
+        	//
+        	TOrderManage select = new TOrderManage();
+        	
+        	select.setTransactionId(param.getTransactionId());
+        	select.setId(Long.valueOf(orderIds[i]));
+        	select.setDelFlag("1");
+        	orderManageService.updateTOrderManage(select);
+    	}
     	return AjaxResult.success("支払キャンセルしました。");
     }
  
@@ -332,21 +373,22 @@ public class H5OrderController extends BaseController {
     @RepeatSubmit
     @PostMapping("/confirm")
     public AjaxResult aiPayCallBack(@RequestBody LineCallBankParam param) {
-    	//
-    	TOrderManageTotal select = new TOrderManageTotal();
-    	
-    	select.setTransactionId(param.getTransactionId());
-    	select.setId(param.getOrderId());
-    	
-    	List<TOrderManageTotal> lst = orderManageTotalService.selectTOrderManageTotalList(select);
-    	
-    	TOrderManageTotal orderManageTotal = lst.get(0);
+
+    	String[] orderIds = param.getOrderId().split("_");
+    	List<TOrderManage> orderList = new ArrayList<TOrderManage>();
+    	for (int i = 1; i < orderIds.length; i++) {
+        	//
+        	TOrderManage order = orderManageService.selectTOrderManageById(Long.valueOf(orderIds[i]));
+        	orderList.add(order);
+    	}
+    	TOrderManageTotal orderManageTotal = orderManageTotalService.selectTOrderManageTotalById(Long.valueOf(orderIds[0]));
+    	orderManageTotal.setOrderList(orderList);
     	
         // 接入支付接口
     	LinePayConfirmAPOD resp = null;
     	//0元支付不要。
     	if (orderManageTotal.getOrderMoney().longValue() > 0) {
-    		resp = linePay.payConfirm(orderManageTotal.getTransactionId(), orderManageTotal.getOrderMoney().longValue());
+    		resp = linePay.payConfirm(param.getTransactionId(), orderManageTotal.getOrderMoney().longValue());
     	}
     	if (resp == null || "0000".equals(resp.returnCode)) {
     		

+ 2 - 6
ruoyi-admin/src/main/java/com/ruoyi/web/H5Api/api/H5PersonalController.java

@@ -39,7 +39,6 @@ import com.ruoyi.web.pcApi.domain.TCustomerManage;
 import com.ruoyi.web.pcApi.domain.TCustomerNotice;
 import com.ruoyi.web.pcApi.domain.TOrderEvaluate;
 import com.ruoyi.web.pcApi.domain.TOrderManage;
-import com.ruoyi.web.pcApi.domain.TOrderManageTotal;
 import com.ruoyi.web.pcApi.service.ITCommodityCouponService;
 import com.ruoyi.web.pcApi.service.ITCommoditySchedulService;
 import com.ruoyi.web.pcApi.service.ITCustomerCollectionOrFootprintService;
@@ -193,12 +192,9 @@ public class H5PersonalController extends BaseController
         
     	payBackApi.payBack(orderManage, getLoginUser().getLoginCustomer().getUsername(), getLoginUser().getDeptId());
 
-        //
-        TOrderManageTotal totalManager = orderManageTotalService.selectTOrderManageTotalById(orderManage.getOrderTotalId());
-        //
         LinePayRefundAPOD resp = null;
-        if (totalManager.getOrderMoney().longValue() > 0) {
-            resp = linePay.payRefund(totalManager.getTransactionId(), orderManage.getOrderMoney().longValue());
+        if (orderManage.getOrderMoney().longValue() > 0) {
+            resp = linePay.payRefund(orderManage.getTransactionId(), orderManage.getOrderMoney().longValue());
         }
         if (resp != null && !"0000".equals(resp.returnCode)) {
         	AjaxResult.error("LINE PAY取引返金失敗しました。");

+ 1 - 1
ruoyi-admin/src/main/java/com/ruoyi/web/line/LineCallBankParam.java

@@ -8,5 +8,5 @@ import lombok.Setter;
 @Setter
 public class LineCallBankParam {
 	private String transactionId;
-	private long orderId;
+	private String orderId;
 }

+ 12 - 21
ruoyi-admin/src/main/java/com/ruoyi/web/line/LinePay.java

@@ -47,35 +47,23 @@ public class LinePay  implements Serializable {
 	public SendBody createSendBody(TOrderManageTotal orderManageTotal, String deptName) {
 		//create line pay request body
 		SendBody sendBody = new SendBody();
+		
 		//total
-		int total = orderManageTotal.getOrderMoney().intValue();
-		//订单金额
-		sendBody.setAmount(total);
+		int total = 0;
 		//order id
 		sendBody.setOrderId(String.valueOf(orderManageTotal.getId()));
-		//按分
-		int len = orderManageTotal.getOrderList().size();
-		int cnt = 0;
-		int anbun = 0;
-		//
-		int preTotal = 0;
-		for (TOrderManage orderManageTemp : orderManageTotal.getOrderList()) {
-			preTotal += orderManageTemp.getOrderMoney().toBigInteger().intValue();
-		}
+
 		for (TOrderManage orderManage : orderManageTotal.getOrderList()) {
 			
-			cnt++;
-			
+			sendBody.setOrderId(sendBody.getOrderId() + "_" + String.valueOf(orderManage.getId()));
+
 			TOrderManage order = orderManageService.selectTOrderManageById(orderManage.getId());
 			
 			//amount
-			int amount = 0;
-			if (cnt == len) {
-				amount = total - anbun;
-			} else {
-				amount = order.getOrderMoney().toBigInteger().intValue()/preTotal*total;
-				anbun += amount;
-			}
+			int amount = orderManage.getOrderMoney().intValue();
+
+			total += amount;
+			
 			//send order
 			Orders ord = new Orders();
 			//注文番号 
@@ -99,6 +87,9 @@ public class LinePay  implements Serializable {
 			
 			ord.add(detail);
 		}
+		//订单金额
+		sendBody.setAmount(total);
+
 		//call back urls
 		RedirectUrls callBack = new RedirectUrls();
 		//confirm url

+ 60 - 98
ruoyi-admin/src/main/java/com/ruoyi/web/line/PayApi.java

@@ -17,8 +17,6 @@ import com.ruoyi.common.core.domain.model.LoginUser;
 import com.ruoyi.web.pcApi.domain.TCommodityCoupon;
 import com.ruoyi.web.pcApi.domain.TCommoditySchedul;
 import com.ruoyi.web.pcApi.domain.TCustomerCoupon;
-import com.ruoyi.web.pcApi.domain.TCustomerDistributionRecord;
-import com.ruoyi.web.pcApi.domain.TCustomerDistributionSet;
 import com.ruoyi.web.pcApi.domain.TCustomerIntegralRecord;
 import com.ruoyi.web.pcApi.domain.TCustomerIntegralSet;
 import com.ruoyi.web.pcApi.domain.TCustomerManage;
@@ -28,8 +26,6 @@ import com.ruoyi.web.pcApi.domain.TOrderManageTotal;
 import com.ruoyi.web.pcApi.service.ITCommodityCouponService;
 import com.ruoyi.web.pcApi.service.ITCommoditySchedulService;
 import com.ruoyi.web.pcApi.service.ITCustomerCouponService;
-import com.ruoyi.web.pcApi.service.ITCustomerDistributionRecordService;
-import com.ruoyi.web.pcApi.service.ITCustomerDistributionSetService;
 import com.ruoyi.web.pcApi.service.ITCustomerIntegralRecordService;
 import com.ruoyi.web.pcApi.service.ITCustomerIntegralSetService;
 import com.ruoyi.web.pcApi.service.ITCustomerManageService;
@@ -53,8 +49,6 @@ public class PayApi implements Serializable {
     @Autowired
     private ITCustomerCouponService customerCouponService;
     @Autowired
-    private ITCustomerDistributionRecordService customerDistributionRecordService;
-    @Autowired
     private ITCommoditySchedulService commoditySchedulService;
     @Autowired
     private ITOrderManageService orderManageService;
@@ -63,8 +57,6 @@ public class PayApi implements Serializable {
     @Autowired
     private ITCustomerIntegralSetService customerIntegralSetService;
     @Autowired
-    private ITCustomerDistributionSetService customerDistributionSetService;
-    @Autowired
     private ITOrderManageTotalService orderManageTotalService;
     @Autowired
     private LineMessagingClient lineMessagingClient;
@@ -92,52 +84,47 @@ public class PayApi implements Serializable {
         TCustomerManage customerManage = customerManageService.selectTCustomerManageById(orderManage.getCustomerId());
         // 取得下单时的积分记录
         TCustomerIntegralRecord tCustomerIntegral = new TCustomerIntegralRecord();
-        tCustomerIntegral.setOrderId(orderManage.getOrderTotalId());
+        tCustomerIntegral.setOrderId(orderManage.getId());
         List<TCustomerIntegralRecord> lst = customerIntegralRecordService.selectTCustomerIntegralRecordList(tCustomerIntegral);
-        //
-        //是否有积分变化
-        boolean isHasChange = false;
         //原始积分
         long jifen = customerManage.getIntegral();
-        //退款钱和积分合计
-        long ret = 0;
+
         for (TCustomerIntegralRecord recd : lst) {
     		//下订单是的积分
-    		Long val = Long.valueOf(recd.getIntegralNum());
+            Long val = Long.valueOf(recd.getIntegralNum());
         	//如果是下单记录则则退款减算
         	if ("1".equals(recd.getIntegralType())) {
-                //用户积分更新 减算
-                customerManage.setIntegral(customerManage.getIntegral() - val);
-                ret = ret + val;
-                isHasChange = true;
+//                //用户积分更新 减算
+//                customerManage.setIntegral(customerManage.getIntegral() - val);
+        		// 记录减去用户积分
+                customerIntegralRecordService.insertTCustomerIntegralRecord(TCustomerIntegralRecord.builder().
+                        supIntegral(String.valueOf(jifen)).integralNum(recd.getIntegralNum()).integralType("9")// 退款类型
+                        .createBy(userName).orderId(orderManage.getOrderTotalId()).customerId(customerManage.getId()).deptId(deptId)
+                        .build());
         	} else if ("4".equals(recd.getIntegralType())) {
         		//如果是利用积分记录退款则加算
                 //用户积分更新 加算
                 customerManage.setIntegral(customerManage.getIntegral() + val);
-                ret = ret + val;
-                isHasChange = true;
+        		// 记录减去用户积分
+                customerIntegralRecordService.insertTCustomerIntegralRecord(TCustomerIntegralRecord.builder().
+                        supIntegral(String.valueOf(jifen)).integralNum(recd.getIntegralNum()).integralType("5")// 积分还原
+                        .createBy(userName).orderId(orderManage.getOrderTotalId()).customerId(customerManage.getId()).deptId(deptId)
+                        .build());
+                //用户积分更新
+                customerManageService.updateTCustomerManage(customerManage);
         	}
         }
-        //有积分变化
-        if (isHasChange) {
-    		// 记录减去用户积分
-            customerIntegralRecordService.insertTCustomerIntegralRecord(TCustomerIntegralRecord.builder().
-                    supIntegral(String.valueOf(jifen)).integralNum(String.valueOf(ret)).integralType("9")// 退款类型
-                    .createBy(userName).orderId(orderManage.getOrderTotalId()).customerId(customerManage.getId()).deptId(deptId)
-                    .build());
-            
-            customerManageService.updateTCustomerManage(customerManage);
-        }
+
         //分销返还
-        TCustomerDistributionRecord distribution = new TCustomerDistributionRecord();
-        distribution.setOrderId(orderManage.getOrderTotalId());
-        List<TCustomerDistributionRecord> distributionLst = customerDistributionRecordService.selectTCustomerDistributionRecordList(distribution);
-        for (TCustomerDistributionRecord recd : distributionLst) {
-        	//这里不是删除,进行减算
-        	customerDistributionRecordService.insertTCustomerDistributionRecord(
-                    TCustomerDistributionRecord.builder().customerId(recd.getCustomerId()).deptId(deptId)
-                            .distributionIntegral("-" + recd.getDistributionIntegral()).createBy(userName).orderId(orderManage.getOrderTotalId()).build());
-        }
+//        TCustomerDistributionRecord distribution = new TCustomerDistributionRecord();
+//        distribution.setOrderId(orderManage.getId());
+//        List<TCustomerDistributionRecord> distributionLst = customerDistributionRecordService.selectTCustomerDistributionRecordList(distribution);
+//        for (TCustomerDistributionRecord recd : distributionLst) {
+//        	//这里不是删除,进行减算
+//        	customerDistributionRecordService.insertTCustomerDistributionRecord(
+//                    TCustomerDistributionRecord.builder().customerId(recd.getCustomerId()).deptId(deptId)
+//                            .distributionIntegral("-" + recd.getDistributionIntegral()).createBy(userName).orderId(orderManage.getId()).build());
+//        }
         // 重置用户商品优惠券
         if(orderManage.getIsCoupon().equals("1")){
             List<TCommodityCoupon> commodityCouponList =
@@ -162,30 +149,23 @@ public class PayApi implements Serializable {
 	 * @param loginuser Login用户
 	 */
 	public void pay(TOrderManageTotal orderManageTotal, LoginUser loginuser) {
-		//set order list
-    	TOrderManage orderPram = new TOrderManage();
-    	orderPram.setOrderTotalId(orderManageTotal.getId());
-    	
-    	List<TOrderManage> orderList = orderManageService.selectTOrderManageList(orderPram);
-    	
-    	orderManageTotal.setOrderList(orderList);
         TCustomerManage customer = customerManageService.selectTCustomerManageById(loginuser.getLoginCustomer().getId());
         // 多/单订单支付
         for (TOrderManage order : orderManageTotal.getOrderList()) {
             TOrderManage orderManage = orderManageService.selectTOrderManageById(order.getId());
             /**  通知待使用*/
-            customerNoticeService.insertTCustomerNotice(TCustomerNotice.builder().customerId(customer.getId()).commodityId(order.getId())
+            customerNoticeService.insertTCustomerNotice(TCustomerNotice.builder().customerId(customer.getId()).commodityId(orderManage.getId())
                     .content("您有一张" + orderManage.getCommodityName() + "商品待使用。").title("订单信息")
                     .createBy(orderManage.getCreateBy()).status("0")
                     .build());
             // 若使用积分 则订单金额减去积分金额
             if(orderManageTotal.getIntegralDeduction().compareTo(BigDecimal.ZERO) > 0 && orderManageTotal.getIntegralDeduction() != null){
-                order.setOrderMoney(orderManage.getOrderMoney().subtract(orderManageTotal.getIntegralDeduction()));
-                order.setIntegralDeduction(orderManageTotal.getIntegralDeduction());
+            	orderManage.setOrderMoney(orderManage.getOrderMoney().subtract(orderManageTotal.getIntegralDeduction()));
+            	orderManage.setIntegralDeduction(orderManageTotal.getIntegralDeduction());
             }
-            order.setStatus("1");// 已支付   支付状态,若接入支付回调,则变更为支付中状态-9,支付回调成功后变更为1-已支付
-            order.setPayDate(new Date());
-            orderManageService.updateTOrderManage(order);
+            orderManage.setStatus("1");// 已支付   支付状态,若接入支付回调,则变更为支付中状态-9,支付回调成功后变更为1-已支付
+            orderManage.setPayDate(new Date());
+            orderManageService.updateTOrderManage(orderManage);
         }
 
         // 获取场馆积分获取比例
@@ -194,59 +174,41 @@ public class PayApi implements Serializable {
         
         //只有有积分奖励的才可以积分
         if (tCustomerIntegralSets.size() > 0) {
-            // 计算积分奖励
-        	BigDecimal orderIntegral = orderManageTotal.getOrderMoney();
-        	
-            BigDecimal proportion = new BigDecimal(tCustomerIntegralSets.get(0).getProportion()).divide(new BigDecimal("100"));
-            orderIntegral= (orderManageTotal.getOrderMoney().multiply(proportion)).setScale(0, BigDecimal.ROUND_DOWN);
-
-            if (orderIntegral.compareTo(BigDecimal.ZERO) != 0) {
-	            // 记录用户积分
-	            customerIntegralRecordService.insertTCustomerIntegralRecord(TCustomerIntegralRecord.builder().
-	                    supIntegral(customer.getIntegral()==null?"0":customer.getIntegral().toString()).integralNum(String.valueOf(orderIntegral.longValue())).integralType("1")
-	                    .createBy(loginuser.getLoginCustomer().getUsername()).orderId(orderManageTotal.getId()).customerId(customer.getId()).deptId(loginuser.getDeptId())
-	                    .build());
-	            /**  增加用户积分*/
-	            customer.setIntegral(customer.getIntegral()==null?0:customer.getIntegral() + orderIntegral.longValue());
-	            customerManageService.updateTCustomerManage(customer);
-            }
+        	for (TOrderManage order : orderManageTotal.getOrderList()) {
+	            // 计算积分奖励
+	        	BigDecimal orderIntegral = order.getOrderMoney();
+	        	
+	            BigDecimal proportion = new BigDecimal(tCustomerIntegralSets.get(0).getProportion()).divide(new BigDecimal("100"));
+	            orderIntegral= (order.getOrderMoney().multiply(proportion)).setScale(0, BigDecimal.ROUND_DOWN);
+	
+	            if (orderIntegral.compareTo(BigDecimal.ZERO) != 0) {
+		            // 记录用户积分
+		            customerIntegralRecordService.insertTCustomerIntegralRecord(TCustomerIntegralRecord.builder().
+		                    supIntegral(customer.getIntegral()==null?"0":customer.getIntegral().toString()).integralNum(String.valueOf(orderIntegral.longValue())).integralType("1")
+		                    .createBy(loginuser.getLoginCustomer().getUsername()).orderId(order.getId()).customerId(customer.getId()).deptId(loginuser.getDeptId())
+		                    .build());
+		            /**  增加用户积分*/
+		            //customer.setIntegral(customer.getIntegral()==null?0:customer.getIntegral() + orderIntegral.longValue());
+		            //customerManageService.updateTCustomerManage(customer);
+	            }
+        	}
         }
 
         // 会员减去积分
-        if(orderManageTotal.getIntegralDeduction() != null && 
-        		orderManageTotal.getIntegralDeduction().compareTo(BigDecimal.ZERO) > 0){
-            customer.setIntegral(customer.getIntegral() - orderManageTotal.getIntegralDeduction().longValue());
+    	for (TOrderManage order : orderManageTotal.getOrderList()) {
+    		TOrderManage orderManage = orderManageService.selectTOrderManageById(order.getId());
+    		if (orderManage.getIntegralDeduction().compareTo(BigDecimal.ZERO) == 0) {
+    			continue;
+    		}
+            customer.setIntegral(customer.getIntegral() - orderManage.getIntegralDeduction().longValue());
             customerManageService.updateTCustomerManage(customer);
             // 记录减去用户积分
             customerIntegralRecordService.insertTCustomerIntegralRecord(TCustomerIntegralRecord.builder().
-                    supIntegral(customer.getIntegral().toString()).integralNum(String.valueOf(orderManageTotal.getIntegralDeduction().longValue())).integralType("4")
-                    .createBy(loginuser.getLoginCustomer().getUsername()).orderId(orderManageTotal.getId()).customerId(
+                    supIntegral(customer.getIntegral().toString()).integralNum(String.valueOf(orderManage.getIntegralDeduction().longValue())).integralType("4")
+                    .createBy(loginuser.getLoginCustomer().getUsername()).orderId(orderManage.getId()).customerId(
                     		customer.getId()).deptId(loginuser.getDeptId())
                     .build());
-        }
-
-        // 是否有分销
-        if (orderManageTotal.getDistributionId() != null) {
-            // 获取场馆分销比例
-            List<TCustomerDistributionSet> tCustomerDistributionSets = customerDistributionSetService.selectTCustomerDistributionSetList(
-            		TCustomerDistributionSet.builder().deptId(
-            				loginuser.getLoginCustomer().getDeptId()).build());
-            if (tCustomerDistributionSets.size() > 0) {
-                // 计算分销人员奖励
-                BigDecimal proportion = new BigDecimal(tCustomerDistributionSets.get(0).getProportion()).divide(new BigDecimal("100"));
-                BigDecimal integral = (orderManageTotal.getOrderMoney().multiply(proportion)).setScale(0, BigDecimal.ROUND_DOWN);
-
-                // 增加用户积分
-                TCustomerManage customerManage = customerManageService.selectTCustomerManageById(orderManageTotal.getDistributionId());
-                customerManage.setIntegral(customerManage.getIntegral() + integral.longValue());
-                customerManageService.updateTCustomerManage(customerManage);
-
-                // 记录分销
-                customerDistributionRecordService.insertTCustomerDistributionRecord(
-                        TCustomerDistributionRecord.builder().customerId(orderManageTotal.getDistributionId()).deptId(loginuser.getLoginCustomer().getDeptId())
-                                .distributionIntegral(integral.toString()).createBy(loginuser.getLoginCustomer().getUsername()).orderId(orderManageTotal.getId()).build());
-            }
-        }
+    	}
 
         // 查询总订单下-是否还有未支付的信息
         List<TOrderManage> orderManageList = orderManageService.selectTOrderManageList(TOrderManage.builder().

+ 12 - 1
ruoyi-admin/src/main/java/com/ruoyi/web/pcApi/domain/TOrderManage.java

@@ -6,7 +6,12 @@ import java.util.Date;
 import com.fasterxml.jackson.annotation.JsonFormat;
 import com.ruoyi.common.annotation.Excel;
 import com.ruoyi.common.core.domain.BaseEntity;
-import lombok.*;
+
+import lombok.AllArgsConstructor;
+import lombok.Builder;
+import lombok.Data;
+import lombok.NoArgsConstructor;
+import lombok.ToString;
 
 /**
  * 订单管理对象 t_order_manage
@@ -97,6 +102,12 @@ public class TOrderManage extends BaseEntity
     @Excel(name = "退款时间", width = 30, dateFormat = "yyyy-MM-dd")
     private Date returnDate;
 
+    /** LINE交易单号 */
+    @Excel(name = "LINE交易单号")
+    private String transactionId;
+    /** 本记录是否已经赋予过积分  1以外-否  1-是 */
+    private String pointScalReady;
+    
     // 临时字段
     /** 商品类型*/
     private String typeName;

+ 0 - 4
ruoyi-admin/src/main/java/com/ruoyi/web/pcApi/domain/TOrderManageTotal.java

@@ -44,10 +44,6 @@ public class TOrderManageTotal extends BaseEntity
     @Excel(name = "支付宝支付号")
     private String aipayNo;
 
-    /** LINE交易单号 */
-    @Excel(name = "LINE交易单号")
-    private String transactionId;
-
     /** 订单状态:0-待支付 1-已支付 99-已退款  */
     @Excel(name = "订单状态:0-待支付 1-已支付 99-已退款 ")
     private String status;

+ 76 - 9
ruoyi-admin/src/main/java/com/ruoyi/web/schedulTask/schedulTask.java

@@ -1,6 +1,7 @@
 
 package com.ruoyi.web.schedulTask;
 
+import java.math.BigDecimal;
 import java.text.SimpleDateFormat;
 import java.time.LocalDate;
 import java.time.format.DateTimeFormatter;
@@ -28,12 +29,20 @@ import com.ruoyi.web.pcApi.domain.TCommodityCoupon;
 import com.ruoyi.web.pcApi.domain.TCommodityManage;
 import com.ruoyi.web.pcApi.domain.TCommoditySchedul;
 import com.ruoyi.web.pcApi.domain.TCustomerCoupon;
+import com.ruoyi.web.pcApi.domain.TCustomerDistributionRecord;
+import com.ruoyi.web.pcApi.domain.TCustomerDistributionSet;
+import com.ruoyi.web.pcApi.domain.TCustomerIntegralRecord;
+import com.ruoyi.web.pcApi.domain.TCustomerManage;
 import com.ruoyi.web.pcApi.domain.TOrderManage;
 import com.ruoyi.web.pcApi.domain.TOrderManageTotal;
 import com.ruoyi.web.pcApi.service.ITCommodityCouponService;
 import com.ruoyi.web.pcApi.service.ITCommodityManageService;
 import com.ruoyi.web.pcApi.service.ITCommoditySchedulService;
 import com.ruoyi.web.pcApi.service.ITCustomerCouponService;
+import com.ruoyi.web.pcApi.service.ITCustomerDistributionRecordService;
+import com.ruoyi.web.pcApi.service.ITCustomerDistributionSetService;
+import com.ruoyi.web.pcApi.service.ITCustomerIntegralRecordService;
+import com.ruoyi.web.pcApi.service.ITCustomerManageService;
 import com.ruoyi.web.pcApi.service.ITOrderManageService;
 import com.ruoyi.web.pcApi.service.ITOrderManageTotalService;
 
@@ -63,9 +72,17 @@ public class schedulTask
     @Autowired
     private LinePay linePay;
     @Autowired
+    private ITCommoditySchedulService commoditySchedulService;
+    @Autowired
+    private ITCustomerIntegralRecordService customerIntegralRecordService;
+    @Autowired
+    private ITCustomerManageService customerManageService;
+    @Autowired
     private ITOrderManageTotalService orderManageTotalService;
     @Autowired
-    private ITCommoditySchedulService commoditySchedulService;
+    private ITCustomerDistributionRecordService customerDistributionRecordService;
+    @Autowired
+    private ITCustomerDistributionSetService customerDistributionSetService;
     
     private static final SimpleDateFormat dateSdf = new SimpleDateFormat("yyyy-MM-dd");
 
@@ -77,7 +94,7 @@ public class schedulTask
      */
     @Transactional
     @SuppressWarnings("all")
-   @Scheduled(cron = "0 */10 * * * ?")
+   @Scheduled(cron = "0 0 0 * * ?")
     public void dateScheduleTask() throws Exception{
         TCustomerCoupon customerCoupon = new TCustomerCoupon();
         TOrderManage order = new TOrderManage();
@@ -109,6 +126,7 @@ public class schedulTask
         for (TOrderManage orderManage : orderManages) {
             if(new Date().compareTo(dateSdf.parse(orderManage.getDepartureDate())) >= 0){
                 orderManage.setStatus("2"); // 已完成
+                payThePoint(orderManage);
                 orderManageService.updateTOrderManage(orderManage);
             }
         }
@@ -142,12 +160,9 @@ public class schedulTask
                             orderManage.setStatus("99");
                             orderManageService.updateTOrderManage(orderManage);
                         	//line pay back
-                            //
-                            TOrderManageTotal totalManager = orderManageTotalService.selectTOrderManageTotalById(orderManage.getOrderTotalId());
-                            //
                             LinePayRefundAPOD resp = null;
                             if (orderManage.getOrderMoney().longValue() > 0) {
-                                resp = linePay.payRefund(totalManager.getTransactionId(), orderManage.getOrderMoney().longValue());
+                                resp = linePay.payRefund(orderManage.getTransactionId(), orderManage.getOrderMoney().longValue());
                             }
                             if (resp == null || "0000".equals(resp.returnCode)) {
                             	List<TOrderManage> lst = new ArrayList<TOrderManage>();
@@ -206,7 +221,7 @@ public class schedulTask
     	LocalDate tomorrow = LocalDate.now().plusDays(1);
     	
     	String tomorrowStr = tomorrow.format(DateTimeFormatter.ofPattern("yyyy-MM-dd"));
-        // 查询未支付的订单
+        // 查询明天出发的订单
         List<TOrderManage> orderManageList = orderManageService.selectTomorrowDeparture(tomorrowStr);
         for (TOrderManage orderManage : orderManageList) {
         	String msg = messages.getMessage(
@@ -217,7 +232,59 @@ public class schedulTask
         	
         	lineMessagingClient.pushMessage(new PushMessage(orderManage.getPhone(), new TextMessage(msg)));
         }
-        
-        
+    }
+    
+    /**
+     * 对行程完了的用户赋予积分并计算分销积分。
+     * @throws Exception
+     */
+    private void payThePoint(TOrderManage orderManage) {
+    	//未计算积分
+    	if (!"1".equals(orderManage.getPointScalReady())) {
+            // 取得下单时的积分记录
+            TCustomerIntegralRecord tCustomerIntegral = new TCustomerIntegralRecord();
+            //订单ID
+            tCustomerIntegral.setOrderId(orderManage.getId());
+            //下单区分
+            tCustomerIntegral.setIntegralType("1");
+            
+            List<TCustomerIntegralRecord> lst = customerIntegralRecordService.selectTCustomerIntegralRecordList(tCustomerIntegral);
+            // 减去增加的积分  订单金额为增加的积分数量
+            TCustomerManage customerManage = customerManageService.selectTCustomerManageById(orderManage.getCustomerId());
+            
+            for (TCustomerIntegralRecord record : lst) {
+            	//
+            	customerManage.setIntegral(customerManage.getIntegral() + Long.valueOf(record.getIntegralNum()));
+            }
+            //update
+            if (lst.size() > 0) {
+            	//积分更新
+            	customerManageService.updateTCustomerManage(customerManage);
+             }
+            TOrderManageTotal orderManageTotal = orderManageTotalService.selectTOrderManageTotalById(orderManage.getOrderTotalId());
+            // 是否有分销
+            if (orderManageTotal.getDistributionId() != null) {
+                // 获取场馆分销比例
+                List<TCustomerDistributionSet> tCustomerDistributionSets = customerDistributionSetService.selectTCustomerDistributionSetList(
+                		TCustomerDistributionSet.builder().deptId(orderManage.getDeptId()).build());
+                if (tCustomerDistributionSets.size() > 0) {
+	                // 计算分销人员奖励
+	                BigDecimal proportion = new BigDecimal(tCustomerDistributionSets.get(0).getProportion()).divide(new BigDecimal("100"));
+	                BigDecimal integral = (orderManage.getOrderMoney().multiply(proportion)).setScale(0, BigDecimal.ROUND_DOWN);
+	
+	                // 增加用户积分
+	                TCustomerManage customerManageBun = customerManageService.selectTCustomerManageById(orderManageTotal.getDistributionId());
+	                customerManageBun.setIntegral(customerManageBun.getIntegral() + integral.longValue());
+	                customerManageService.updateTCustomerManage(customerManageBun);
+	
+	                // 记录分销
+	                customerDistributionRecordService.insertTCustomerDistributionRecord(
+	                        TCustomerDistributionRecord.builder().customerId(orderManageTotal.getDistributionId()).deptId(orderManage.getDeptId())
+	                                .distributionIntegral(integral.toString()).createBy("schedulTask").orderId(orderManage.getId()).build());
+                }
+            }
+           	//积分计算完成更新
+        	orderManage.setPointScalReady("1");
+        }
     }
 }

+ 0 - 5
ruoyi-admin/src/main/resources/mapper/OrderManageTotal/TOrderManageTotalMapper.xml

@@ -19,7 +19,6 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
         <result property="updateBy"    column="update_by"    />
         <result property="updateTime"    column="update_time"    />
         <result property="remark"    column="remark"    />
-        <result property="transactionId"    column="transaction_id"    />
     </resultMap>
 
     <sql id="selectTOrderManageTotalVo">
@@ -36,7 +35,6 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
             <if test="payDate != null "> and pay_date = #{payDate}</if>
             <if test="returnDate != null "> and return_date = #{returnDate}</if>
             <if test="deptId != null "> and dept_id = #{deptId}</if>
-            <if test="transactionId != null">and transaction_id = #{transactionId}</if>
         </where>
     </select>
     
@@ -61,7 +59,6 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
             <if test="updateBy != null">update_by,</if>
             <if test="updateTime != null">update_time,</if>
             <if test="remark != null">remark,</if>
-            <if test="transactionId != null">transaction_id,</if>
          </trim>
         <trim prefix="values (" suffix=")" suffixOverrides=",">
             <if test="integralDeduction != null">#{integralDeduction},</if>
@@ -77,7 +74,6 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
             <if test="updateBy != null">#{updateBy},</if>
             <if test="updateTime != null">#{updateTime},</if>
             <if test="remark != null">#{remark},</if>
-            <if test="transactionId != null">#{transactionId},</if>
          </trim>
     </insert>
 
@@ -97,7 +93,6 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
             <if test="updateBy != null">update_by = #{updateBy},</if>
             <if test="updateTime != null">update_time = #{updateTime},</if>
             <if test="remark != null">remark = #{remark},</if>
-            <if test="transactionId != null">transaction_id = #{transactionId},</if>
         </trim>
         where id = #{id}
     </update>

+ 14 - 0
ruoyi-admin/src/main/resources/mapper/order/TOrderManageMapper.xml

@@ -37,6 +37,8 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
         <result property="orderTotalId"    column="order_total_id"    />
         <result property="payDate"    column="pay_date"    />
         <result property="returnDate"    column="return_date"    />
+        <result property="transactionId"    column="transaction_id"    />
+        <result property="pointScalReady"    column="point_scal_ready"    />
     </resultMap>
 
     <sql id="selectTOrderManageVo">
@@ -62,6 +64,8 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
             a.update_by,
             a.update_time,
             a.remark,
+            a.transaction_id,
+            a.point_scal_ready,
             b.commodity_name,
             c.type_name,
             a.del_flag,
@@ -96,6 +100,8 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
             <if test="status != null  and status != ''"> and a.status = #{status}</if>
             <if test="deptId != null "> and a.dept_id = #{deptId}</if>
             <if test="orderTotalId != null "> and a.order_total_id = #{orderTotalId}</if>
+            <if test="transactionId != null">and transaction_id = #{transactionId}</if>
+            <if test="pointScalReady != null">and point_scal_ready = #{pointScalReady}</if>
             <if test="params.beginDate != null and params.beginDate != ''"><!-- 开始时间检索 -->
                 and date_format(a.create_time,'%y%m%d') &gt;= date_format(#{params.beginDate},'%y%m%d')
             </if>
@@ -122,6 +128,8 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
         <if test="status != null  and status != ''"> and a.status = #{status}</if>
         <if test="deptId != null "> and a.dept_id = #{deptId}</if>
         <if test="orderTotalId != null "> and a.order_total_id = #{orderTotalId}</if>
+        <if test="transactionId != null">and transaction_id = #{transactionId}</if>
+        <if test="pointScalReady != null">and point_scal_ready = #{pointScalReady}</if>
         <if test="params.beginDate != null and params.beginDate != ''"><!-- 开始时间检索 -->
             and date_format(a.create_time,'%y%m%d') &gt;= date_format(#{params.beginDate},'%y%m%d')
         </if>
@@ -161,6 +169,8 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
             <if test="orderTotalId != null">order_total_id,</if>
             <if test="payDate != null">pay_date,</if>
             <if test="returnDate != null">return_date,</if>
+            <if test="transactionId != null">transaction_id,</if>
+            <if test="pointScalReady != null">point_scal_ready,</if>
          </trim>
         <trim prefix="values (" suffix=")" suffixOverrides=",">
             <if test="orderNo != null">#{orderNo},</if>
@@ -185,6 +195,8 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
             <if test="orderTotalId != null">#{orderTotalId},</if>
             <if test="payDate != null">#{payDate},</if>
             <if test="returnDate != null">#{returnDate},</if>
+            <if test="transactionId != null">#{transactionId},</if>
+            <if test="pointScalReady != null">#{pointScalReady},</if>
          </trim>
     </insert>
 
@@ -213,6 +225,8 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
             <if test="orderTotalId != null">order_total_id = #{orderTotalId},</if>
             <if test="payDate != null">pay_date = #{payDate},</if>
             <if test="returnDate != null">return_date = #{returnDate},</if>
+            <if test="transactionId != null">transaction_id = #{transactionId},</if>
+            <if test="pointScalReady != null">point_scal_ready = #{pointScalReady},</if>
         </trim>
         where id = #{id}
     </update>