Monterey 3 سال پیش
والد
کامیت
16e8a447cc

+ 38 - 12
ruoyi-admin/src/main/java/com/ruoyi/web/H5Api/api/H5HomeController.java

@@ -1,19 +1,32 @@
 package com.ruoyi.web.H5Api.api;
 
-import com.ruoyi.common.core.controller.BaseController;
-import com.ruoyi.common.core.domain.AjaxResult;
-import com.ruoyi.common.core.domain.model.LoginCustomerManage;
-import com.ruoyi.common.utils.SecurityUtils;
-import com.ruoyi.web.pcApi.domain.*;
-import com.ruoyi.web.pcApi.service.*;
-import org.springframework.beans.factory.annotation.Autowired;
-import org.springframework.security.core.Authentication;
-import org.springframework.web.bind.annotation.*;
-
 import java.util.HashMap;
 import java.util.List;
 import java.util.Map;
 
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.web.bind.annotation.CrossOrigin;
+import org.springframework.web.bind.annotation.GetMapping;
+import org.springframework.web.bind.annotation.PathVariable;
+import org.springframework.web.bind.annotation.RequestMapping;
+import org.springframework.web.bind.annotation.RestController;
+
+import com.ruoyi.common.core.controller.BaseController;
+import com.ruoyi.common.core.domain.AjaxResult;
+import com.ruoyi.common.core.domain.model.LoginCustomerManage;
+import com.ruoyi.web.pcApi.domain.TCommodityManage;
+import com.ruoyi.web.pcApi.domain.TCommoditySchedul;
+import com.ruoyi.web.pcApi.domain.TCommodityType;
+import com.ruoyi.web.pcApi.domain.TCustomerCollectionOrFootprint;
+import com.ruoyi.web.pcApi.domain.TCustomerCoupon;
+import com.ruoyi.web.pcApi.domain.TOrderEvaluate;
+import com.ruoyi.web.pcApi.service.ITCommodityManageService;
+import com.ruoyi.web.pcApi.service.ITCommoditySchedulService;
+import com.ruoyi.web.pcApi.service.ITCommodityTypeService;
+import com.ruoyi.web.pcApi.service.ITCustomerCollectionOrFootprintService;
+import com.ruoyi.web.pcApi.service.ITCustomerCouponService;
+import com.ruoyi.web.pcApi.service.ITOrderEvaluateService;
+
 /**
  * h5端-商品信息api
  *
@@ -34,7 +47,9 @@ public class H5HomeController extends BaseController {
     private ITCustomerCouponService customerCouponService;
     @Autowired
     private ITCustomerCollectionOrFootprintService customerCollectionOrFootprintService;
-
+    @Autowired
+    private ITCommoditySchedulService commoditySchedulService;
+    
     /**
      * 查询商品列表
      * /优选列表  isPreferred='1'
@@ -91,6 +106,12 @@ public class H5HomeController extends BaseController {
         commodityManage.setCouponUser("0");
         commodityManage.setCollectionUser("0");
 
+        //座位信息取得。
+        TCommoditySchedul schedulSeat = new TCommoditySchedul();
+        schedulSeat.setCommodityId(commodityManage.getId());
+        List<TCommoditySchedul> seatList = commoditySchedulService.selectTCommoditySchedulList(schedulSeat);
+        commodityManage.setSeatInfoLst(seatList);
+        
         // 同类型推荐列表
         List<TCommodityManage> sameTypeList = commodityManageService.selectSameTypeCommodityTop5(id, commodityManage.getTypeId(),commodityManage.getDeptId());
 
@@ -150,7 +171,12 @@ public class H5HomeController extends BaseController {
         if (collections.size() > 0) {
             commodityManage.setCollectionUser("1");
         }
-
+        //座位信息取得。
+        TCommoditySchedul schedulSeat = new TCommoditySchedul();
+        schedulSeat.setCommodityId(commodityManage.getId());
+        List<TCommoditySchedul> seatList = commoditySchedulService.selectTCommoditySchedulList(schedulSeat);
+        commodityManage.setSeatInfoLst(seatList);
+        
         // 同类型推荐列表
         List<TCommodityManage> sameTypeList = commodityManageService.selectSameTypeCommodityTop5(id, commodityManage.getTypeId(),commodityManage.getDeptId());
 

+ 36 - 156
ruoyi-admin/src/main/java/com/ruoyi/web/H5Api/api/H5OrderController.java

@@ -1,15 +1,10 @@
 package com.ruoyi.web.H5Api.api;
 
-import java.io.StringWriter;
-import java.math.BigDecimal;
 import java.util.Date;
 import java.util.List;
 import java.util.Map;
 
 import org.apache.commons.collections.map.HashedMap;
-import org.apache.velocity.Template;
-import org.apache.velocity.VelocityContext;
-import org.apache.velocity.app.Velocity;
 import org.redisson.api.RLock;
 import org.redisson.api.RedissonClient;
 import org.springframework.beans.factory.annotation.Autowired;
@@ -21,43 +16,29 @@ import org.springframework.web.bind.annotation.RequestBody;
 import org.springframework.web.bind.annotation.RequestMapping;
 import org.springframework.web.bind.annotation.RestController;
 
-import com.linecorp.bot.client.LineMessagingClient;
-import com.linecorp.bot.model.PushMessage;
-import com.linecorp.bot.model.message.TextMessage;
 import com.ruoyi.common.annotation.Log;
 import com.ruoyi.common.annotation.RepeatSubmit;
 import com.ruoyi.common.core.controller.BaseController;
 import com.ruoyi.common.core.domain.AjaxResult;
 import com.ruoyi.common.enums.BusinessType;
 import com.ruoyi.common.enums.OperatorType;
-import com.ruoyi.generator.util.VelocityInitializer;
 import com.ruoyi.web.line.LineCallBankParam;
 import com.ruoyi.web.line.LinePay;
 import com.ruoyi.web.line.LinePayAPOD;
 import com.ruoyi.web.line.LinePayConfirmAPOD;
+import com.ruoyi.web.line.PayApi;
 import com.ruoyi.web.pcApi.domain.TCommodityManage;
+import com.ruoyi.web.pcApi.domain.TCommoditySchedul;
 import com.ruoyi.web.pcApi.domain.TCustomerCollectionOrFootprint;
 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;
-import com.ruoyi.web.pcApi.domain.TCustomerNotice;
 import com.ruoyi.web.pcApi.domain.TCustomerShoppingCart;
 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.mapper.TCommodityManageMapper;
 import com.ruoyi.web.pcApi.service.ITCommodityManageService;
+import com.ruoyi.web.pcApi.service.ITCommoditySchedulService;
 import com.ruoyi.web.pcApi.service.ITCustomerCollectionOrFootprintService;
 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;
-import com.ruoyi.web.pcApi.service.ITCustomerNoticeService;
 import com.ruoyi.web.pcApi.service.ITCustomerShoppingCartService;
 import com.ruoyi.web.pcApi.service.ITOrderEvaluateService;
 import com.ruoyi.web.pcApi.service.ITOrderManageService;
@@ -86,28 +67,16 @@ public class H5OrderController extends BaseController {
     @Autowired
     private RedissonClient redissonClient;
     @Autowired
-    private TCommodityManageMapper commodityManageMapper;
-    @Autowired
     private ITOrderEvaluateService orderEvaluateService;
     @Autowired
-    private ITCustomerDistributionRecordService customerDistributionRecordService;
-    @Autowired
-    private ITCustomerDistributionSetService customerDistributionSetService;
-    @Autowired
-    private ITCustomerManageService customerManageService;
-    @Autowired
-    private ITCustomerIntegralRecordService customerIntegralRecordService;
-    @Autowired
-    private ITCustomerNoticeService customerNoticeService;
-    @Autowired
     private ITOrderManageTotalService orderManageTotalService;
     @Autowired
-    private ITCustomerIntegralSetService customerIntegralSetService;
-    @Autowired
     private LinePay linePay;
     @Autowired
-    private LineMessagingClient lineMessagingClient;
-
+    private ITCommoditySchedulService commoditySchedulService;
+    @Autowired
+    private PayApi payApi;
+    
     /**
      * 增加收藏
      *
@@ -232,16 +201,22 @@ public class H5OrderController extends BaseController {
 
                 // 减掉库存
                 Integer orderNum = order.getAdultNum() + order.getChildNum();
-                if (commodityManage.getStock() - orderNum >= 0) {
-                    commodityManage.setStock(commodityManage.getStock() - orderNum);
-                    // 增加销售数量
-                    commodityManage.setSaleNum(commodityManage.getSaleNum() == null ? 0 + orderNum : commodityManage.getSaleNum() + orderNum);
-                    commodityManageMapper.updateTCommodityManage(commodityManage);
-                } else {
-                    return AjaxResult.error(commodityManage.getCommodityName() + "库存不足" + orderNum);
+                //座位信息取得。
+                TCommoditySchedul schedulSeat = new TCommoditySchedul();
+                schedulSeat.setCommodityId(commodityManage.getId());
+                schedulSeat.setDepartureDate(order.getDepartureDate());
+                List<TCommoditySchedul> seatList = commoditySchedulService.selectTCommoditySchedulList(schedulSeat);
+                long stock = 0;
+                for (TCommoditySchedul seatRcd : seatList) {
+                	stock = seatRcd.getSeatNum();
+                	if (stock - orderNum >= 0) {
+                		seatRcd.setSeatNum(stock - orderNum);
+                        commoditySchedulService.updateTCommoditySchedul(seatRcd);
+                    } else {
+                        return AjaxResult.error(commodityManage.getCommodityName() + "在庫がございません" + orderNum);
+                    }
                 }
 
-
                 /**  优惠券失效*/
                 if (customerCoupon != null) {
                     customerCoupon.setStatus("1");
@@ -301,7 +276,13 @@ public class H5OrderController extends BaseController {
     @RepeatSubmit
     @PostMapping("/aiPay")
     public AjaxResult aiPay(@RequestBody TOrderManageTotal orderManageTotal) {
-
+    	//0元LINE支付不要。
+    	if (orderManageTotal.getOrderMoney().longValue() == 0) {
+    		//
+    		payApi.pay(orderManageTotal, getLoginUser());
+    		
+    		return AjaxResult.success("Line支払不要");
+    	}
         // 接入支付接口
     	LinePayAPOD resp = linePay.pay(orderManageTotal, orderManageTotalService.getDeptName(orderManageTotal.getId()));
     	
@@ -362,115 +343,14 @@ public class H5OrderController extends BaseController {
     	TOrderManageTotal orderManageTotal = lst.get(0);
     	
         // 接入支付接口
-    	LinePayConfirmAPOD resp = linePay.payConfirm(orderManageTotal.getTransactionId(), orderManageTotal.getOrderMoney().longValue());
-
-    	if ("0000".equals(resp.returnCode)) {
-    		//set order list
-        	TOrderManage orderPram = new TOrderManage();
-        	orderPram.setOrderTotalId(param.getOrderId());
-        	
-        	List<TOrderManage> orderList = orderManageService.selectTOrderManageList(orderPram);
-        	
-        	orderManageTotal.setOrderList(orderList);
-            TCustomerManage customer = customerManageService.selectTCustomerManageById(getLoginUser().getLoginCustomer().getId());
-            // 多/单订单支付
-            for (TOrderManage order : orderManageTotal.getOrderList()) {
-                TOrderManage orderManage = orderManageService.selectTOrderManageById(order.getId());
-                /**  通知待使用*/
-                customerNoticeService.insertTCustomerNotice(TCustomerNotice.builder().customerId(customer.getId()).commodityId(order.getId())
-                        .content("您有一张" + orderManage.getCommodityName() + "商品待使用。").title("订单信息")
-                        .createBy(orderManage.getCreateBy()).status("0")
-                        .build());
-                // 若使用积分 则订单金额减去积分金额
-                if(orderManageTotal.getIntegralDeduction() != BigDecimal.ZERO && orderManageTotal.getIntegralDeduction() != null){
-                    order.setOrderMoney(orderManage.getOrderMoney().subtract(orderManageTotal.getIntegralDeduction()));
-                    order.setIntegralDeduction(orderManageTotal.getIntegralDeduction());
-                }
-                order.setStatus("1");// 已支付   支付状态,若接入支付回调,则变更为支付中状态-9,支付回调成功后变更为1-已支付
-                order.setPayDate(new Date());
-                orderManageService.updateTOrderManage(order);
-            }
-
-        	
-            // 获取场馆积分获取比例
-            List<TCustomerIntegralSet> tCustomerIntegralSets = customerIntegralSetService.selectTCustomerIntegralSetList(TCustomerIntegralSet.builder().deptId(getLoginUser().getLoginCustomer().getDeptId()).build());
-            BigDecimal orderIntegral = orderManageTotal.getOrderMoney();
-            if (tCustomerIntegralSets.size() > 0) {
-                // 计算分销人员奖励
-                BigDecimal proportion = new BigDecimal(tCustomerIntegralSets.get(0).getProportion()).divide(new BigDecimal("100"));
-                orderIntegral= (orderManageTotal.getOrderMoney().multiply(proportion)).setScale(0, BigDecimal.ROUND_DOWN);
-
-            }
-                // 记录用户积分
-            customerIntegralRecordService.insertTCustomerIntegralRecord(TCustomerIntegralRecord.builder().
-                    supIntegral(customer.getIntegral()==null?"0":customer.getIntegral().toString()).integralNum(String.valueOf(orderIntegral.longValue())).integralType("1")
-                    .createBy(getLoginUser().getLoginCustomer().getUsername()).orderId(orderManageTotal.getId()).customerId(customer.getId()).deptId(getLoginUser().getDeptId())
-                    .build());
-            /**  增加用户积分*/
-            customer.setIntegral(customer.getIntegral()==null?0:customer.getIntegral() + orderIntegral.longValue());
-            customerManageService.updateTCustomerManage(customer);
-
-            // 会员减去积分
-            if(orderManageTotal.getIntegralDeduction() != null && orderManageTotal.getIntegralDeduction() != BigDecimal.ZERO){
-                customer.setIntegral(customer.getIntegral() - orderManageTotal.getIntegralDeduction().longValue());
-                customerManageService.updateTCustomerManage(customer);
-                // 记录减去用户积分
-                customerIntegralRecordService.insertTCustomerIntegralRecord(TCustomerIntegralRecord.builder().
-                        supIntegral(customer.getIntegral().toString()).integralNum(orderManageTotal.getIntegralDeduction().toString()).integralType("4")
-                        .createBy(getLoginUser().getLoginCustomer().getUsername()).orderId(orderManageTotal.getOrderList().get(0).getId()).customerId(customer.getId()).deptId(getLoginUser().getDeptId())
-                        .build());
-            }
-
-            // 是否有分销
-            if (orderManageTotal.getDistributionId() != null) {
-                // 获取场馆分销比例
-                List<TCustomerDistributionSet> tCustomerDistributionSets = customerDistributionSetService.selectTCustomerDistributionSetList(TCustomerDistributionSet.builder().deptId(getLoginUser().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(getLoginUser().getLoginCustomer().getDeptId())
-                                    .distributionIntegral(integral.toString()).createBy(getLoginUser().getLoginCustomer().getUsername()).orderId(orderManageTotal.getId()).build());
-                }
-            }
-
-            // 查询总订单下-是否还有未支付的信息
-            List<TOrderManage> orderManageList = orderManageService.selectTOrderManageList(TOrderManage.builder().
-                    orderTotalId(orderManageTotal.getId()).status("0").build());
-            if(orderManageList.size() <= 0){
-                orderManageTotal.setStatus("1");
-                orderManageTotalService.updateTOrderManageTotal(orderManageTotal);
-            }
-            
-            //
-            VelocityInitializer.initVelocity();
-    		//Velocityの初期化
-          	Velocity.init();
-          	//Velocityコンテキストに値を設定
-          	VelocityContext context = new VelocityContext();
-          	
-          	StringWriter sw = new StringWriter();
-          	//テンプレートの作成
-          	Template template = Velocity.getTemplate("vm/orderAlertMsg.vm", "UTF-8");
-          	
-          	List<TOrderManage> list = orderManageService.selectByManagerTotalId(orderManageTotal.getId());
-          	
-          	context.put("orders", list);
-          	
-          	//テンプレートとマージ
-          	template.merge(context, sw);
-          	//マージしたデータはWriterオブジェクトであるswが持っているのでそれを文字列として出力
-          	System.out.println(sw.toString());
-          	
-          	lineMessagingClient.pushMessage(new PushMessage(list.get(0).getPhone(), new TextMessage(sw.toString())));
+    	LinePayConfirmAPOD resp = null;
+    	//0元支付不要。
+    	if (orderManageTotal.getOrderMoney().longValue() > 0) {
+    		resp = linePay.payConfirm(orderManageTotal.getTransactionId(), orderManageTotal.getOrderMoney().longValue());
+    	}
+    	if (resp == null || "0000".equals(resp.returnCode)) {
+    		
+    		payApi.pay(orderManageTotal, getLoginUser());
           	
     		return AjaxResult.success("支払成功");
     	} else {

+ 43 - 53
ruoyi-admin/src/main/java/com/ruoyi/web/H5Api/api/H5PersonalController.java

@@ -1,5 +1,6 @@
 package com.ruoyi.web.H5Api.api;
 
+import java.util.ArrayList;
 import java.util.Date;
 import java.util.HashMap;
 import java.util.List;
@@ -15,6 +16,9 @@ import org.springframework.web.bind.annotation.RequestBody;
 import org.springframework.web.bind.annotation.RequestMapping;
 import org.springframework.web.bind.annotation.RestController;
 
+import com.linecorp.bot.client.LineMessagingClient;
+import com.linecorp.bot.model.PushMessage;
+import com.linecorp.bot.model.message.TextMessage;
 import com.ruoyi.common.annotation.Log;
 import com.ruoyi.common.annotation.RepeatSubmit;
 import com.ruoyi.common.core.controller.BaseController;
@@ -23,8 +27,10 @@ import com.ruoyi.common.enums.BusinessType;
 import com.ruoyi.common.enums.OperatorType;
 import com.ruoyi.web.line.LinePay;
 import com.ruoyi.web.line.LinePayRefundAPOD;
+import com.ruoyi.web.line.PayApi;
+import com.ruoyi.web.line.SendMessage;
 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.TCustomerCollectionOrFootprint;
 import com.ruoyi.web.pcApi.domain.TCustomerCoupon;
 import com.ruoyi.web.pcApi.domain.TCustomerDistributionRecord;
@@ -35,7 +41,7 @@ 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.ITCommodityManageService;
+import com.ruoyi.web.pcApi.service.ITCommoditySchedulService;
 import com.ruoyi.web.pcApi.service.ITCustomerCollectionOrFootprintService;
 import com.ruoyi.web.pcApi.service.ITCustomerCouponService;
 import com.ruoyi.web.pcApi.service.ITCustomerDistributionRecordService;
@@ -74,15 +80,17 @@ public class H5PersonalController extends BaseController
     @Autowired
     private ITOrderEvaluateService orderEvaluateService;
     @Autowired
-    private ITCommodityManageService commodityManageService;
-    @Autowired
     private ITCommodityCouponService commodityCouponService;
     @Autowired
-    private ITCustomerIntegralRecordService customerIntegralRecordService;
-    @Autowired
     private LinePay linePay;
     @Autowired
     private ITOrderManageTotalService orderManageTotalService;
+    @Autowired
+    private PayApi payBackApi;
+    @Autowired
+    private LineMessagingClient lineMessagingClient;
+    @Autowired
+    private ITCommoditySchedulService commoditySchedulService;
     
     /**
      *  完善用户信息
@@ -146,17 +154,21 @@ public class H5PersonalController extends BaseController
     @DeleteMapping("/delOrder/{id}")
     public AjaxResult delOrder(@PathVariable Long id){
         TOrderManage orderManage = orderManageService.selectTOrderManageById(id);
-        // 减少销售数量
-        TCommodityManage commodityManage = commodityManageService.selectTCommodityManageById(orderManage.getCommodityId());
-        Integer orderNum = orderManage.getAdultNum() + orderManage.getChildNum();
-        commodityManage.setStock(commodityManage.getStock() + orderNum);
-        // 增加销售数量
-        commodityManage.setSaleNum(commodityManage.getSaleNum() - orderNum);
-        commodityManageService.updateTCommodityManage(commodityManage);
+        //座位信息取得。
+        TCommoditySchedul schedulSeat = new TCommoditySchedul();
+        schedulSeat.setCommodityId(orderManage.getCommodityId());
+        schedulSeat.setDepartureDate(orderManage.getDepartureDate());
+        List<TCommoditySchedul> seatList = commoditySchedulService.selectTCommoditySchedulList(schedulSeat);
+        long stock = 0;
+        for (TCommoditySchedul seatRcd : seatList) {
+        	stock = seatRcd.getSeatNum();
+    		seatRcd.setSeatNum(stock + orderManage.getAdultNum() + orderManage.getChildNum());
+            commoditySchedulService.updateTCommoditySchedul(seatRcd);
+        }
         // 重置用户商品优惠券
         if(orderManage.getIsCoupon().equals("1")){
             List<TCommodityCoupon> commodityCouponList =
-                    commodityCouponService.selectTCommodityCouponList(TCommodityCoupon.builder().commodityId(commodityManage.getId()).build());
+                    commodityCouponService.selectTCommodityCouponList(TCommodityCoupon.builder().commodityId(orderManage.getCommodityId()).build());
             if(commodityCouponList.size()>0){
                 List<TCustomerCoupon> tCustomerCoupons =
                         customerCouponService.selectTCustomerCouponList(TCustomerCoupon.builder().couponId(commodityCouponList.get(0).getId()).customerId(orderManage.getCustomerId()).build());
@@ -176,52 +188,30 @@ public class H5PersonalController extends BaseController
      */
     @GetMapping("/returnPay/{id}")
     public AjaxResult returnPay(@PathVariable Long id){
+    	//
         TOrderManage orderManage = orderManageService.selectTOrderManageById(id);
-        // 减少销售数量
-        TCommodityManage commodityManage = commodityManageService.selectTCommodityManageById(orderManage.getCommodityId());
-        Integer orderNum = orderManage.getAdultNum() + orderManage.getChildNum();
-        commodityManage.setStock(commodityManage.getStock() + orderNum);
-        // 增加销售数量
-        commodityManage.setSaleNum(commodityManage.getSaleNum() - orderNum);
-        commodityManageService.updateTCommodityManage(commodityManage);
-
-        // 减去增加的积分  订单金额为增加的积分数量
-        TCustomerManage customerManage = customerManageService.selectTCustomerManageById(orderManage.getCustomerId());
-        customerManage.setIntegral(customerManage.getIntegral() - orderManage.getOrderMoney().longValue());
-        // 加上用户使用的积分
-        customerManage.setIntegral(customerManage.getIntegral() + orderManage.getIntegralDeduction().longValue());
-        customerManageService.updateTCustomerManage(customerManage);
-
-        // 记录减去用户积分
-        customerIntegralRecordService.insertTCustomerIntegralRecord(TCustomerIntegralRecord.builder().
-                supIntegral(customerManage.getIntegral().toString()).integralNum(orderManage.getOrderMoney().toString()).integralType("9")// 退款类型
-                .createBy(getLoginUser().getLoginCustomer().getUsername()).orderId(orderManage.getId()).customerId(customerManage.getId()).deptId(getLoginUser().getDeptId())
-                .build());
-
-        // 重置用户商品优惠券
-        if(orderManage.getIsCoupon().equals("1")){
-            List<TCommodityCoupon> commodityCouponList =
-                    commodityCouponService.selectTCommodityCouponList(TCommodityCoupon.builder().commodityId(commodityManage.getId()).build());
-            if(commodityCouponList.size()>0){
-                List<TCustomerCoupon> tCustomerCoupons =
-                        customerCouponService.selectTCustomerCouponList(TCustomerCoupon.builder().couponId(commodityCouponList.get(0).getId()).customerId(customerManage.getId()).build());
-                // 有优惠券,且已使用,则重置
-                if(tCustomerCoupons.size()>0 && tCustomerCoupons.get(0).getStatus().equals("1")){
-                    customerCouponService.updateTCustomerCoupon(TCustomerCoupon.builder().id(tCustomerCoupons.get(0).getId()).status("0").build());
-                }
-            }
-
-        }
+        
+    	payBackApi.payBack(orderManage, getLoginUser().getLoginCustomer().getUsername(), getLoginUser().getDeptId());
 
         //
         TOrderManageTotal totalManager = orderManageTotalService.selectTOrderManageTotalById(orderManage.getOrderTotalId());
         //
-        LinePayRefundAPOD resp = linePay.payRefund(totalManager.getTransactionId(), orderManage.getOrderMoney().longValue());
-        
-        if ("0000".equals(resp.returnCode)) {
+        LinePayRefundAPOD resp = null;
+        if (totalManager.getOrderMoney().longValue() > 0) {
+            resp = linePay.payRefund(totalManager.getTransactionId(), orderManage.getOrderMoney().longValue());
+        }
+        if (resp != null && !"0000".equals(resp.returnCode)) {
         	AjaxResult.error("LINE PAY取引返金失敗しました。");
         }
-        
+ 
+        //send cancel message
+      	List<TOrderManage> list = new ArrayList<TOrderManage>();
+      	
+      	list.add(orderManage);
+      	
+      	lineMessagingClient.pushMessage(new PushMessage(list.get(0).getPhone(),
+      			new TextMessage(SendMessage.getCancelMessage(list))));
+      	
         return AjaxResult.success(orderManageService.updateTOrderManage(TOrderManage.builder().id(id)
                 .status("99").returnDate(new Date()).build()));
     }

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

@@ -20,6 +20,6 @@ public class LineConfig {
     @Value("${line.password}")
     public String password;
     @Value("${line.refundUrl}")
-    public String refund;
+    public String refundUrl;
 
 }

+ 25 - 6
ruoyi-admin/src/main/java/com/ruoyi/web/line/LinePay.java

@@ -47,21 +47,41 @@ 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(orderManageTotal.getOrderMoney().intValue());
+		sendBody.setAmount(total);
 		//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++;
+			
 			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;
+			}
 			//send order
 			Orders ord = new Orders();
 			//注文番号 
 			ord.setId(order.getOrderNo());
 			//決済金額
-			ord.setAmount(order.getOrderMoney().intValue());
+			ord.setAmount(amount);
 			//パッケージの名前(または、加盟店内の出店業者の名前)
 			ord.setName(deptName);
 			//add the packages
@@ -75,10 +95,9 @@ public class LinePay  implements Serializable {
 			//商品数
 			detail.setQuantity(1);
 			//各商品の決済金額
-			detail.setPrice(order.getOrderMoney().intValue());
+			detail.setPrice(amount);
 			
 			ord.add(detail);
-			
 		}
 		//call back urls
 		RedirectUrls callBack = new RedirectUrls();
@@ -209,7 +228,7 @@ public class LinePay  implements Serializable {
 		
 		ObjectMapper mapper = new ObjectMapper();
 
-		MessageFormat form = new MessageFormat(lineConfig.confirmUrl);
+		MessageFormat form = new MessageFormat(lineConfig.refundUrl);
 				
 		String formatStr = form.format(new Object[] {transactionId}); 
 		

+ 264 - 0
ruoyi-admin/src/main/java/com/ruoyi/web/line/PayApi.java

@@ -0,0 +1,264 @@
+package com.ruoyi.web.line;
+
+import java.io.Serializable;
+import java.math.BigDecimal;
+import java.util.Date;
+import java.util.List;
+
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.stereotype.Component;
+
+import com.linecorp.bot.client.LineMessagingClient;
+import com.linecorp.bot.model.PushMessage;
+import com.linecorp.bot.model.message.TextMessage;
+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;
+import com.ruoyi.web.pcApi.domain.TCustomerNotice;
+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.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;
+import com.ruoyi.web.pcApi.service.ITCustomerNoticeService;
+import com.ruoyi.web.pcApi.service.ITOrderManageService;
+import com.ruoyi.web.pcApi.service.ITOrderManageTotalService;
+
+@Component
+public class PayApi implements Serializable {
+	
+    private static final long serialVersionUID = 1L;
+    /** log */
+    private static final Logger log = LoggerFactory.getLogger(PayApi.class);
+
+    @Autowired
+    private ITCustomerManageService customerManageService;
+    @Autowired
+    private ITCustomerIntegralRecordService customerIntegralRecordService;
+    @Autowired
+    private ITCommodityCouponService commodityCouponService;
+    @Autowired
+    private ITCustomerCouponService customerCouponService;
+    @Autowired
+    private ITCustomerDistributionRecordService customerDistributionRecordService;
+    @Autowired
+    private ITCommoditySchedulService commoditySchedulService;
+    @Autowired
+    private ITOrderManageService orderManageService;
+    @Autowired
+    private ITCustomerNoticeService customerNoticeService;
+    @Autowired
+    private ITCustomerIntegralSetService customerIntegralSetService;
+    @Autowired
+    private ITCustomerDistributionSetService customerDistributionSetService;
+    @Autowired
+    private ITOrderManageTotalService orderManageTotalService;
+    @Autowired
+    private LineMessagingClient lineMessagingClient;
+	/**
+	 * 
+	 * @param orderManage 订单管理对象
+	 * @param loginUser 登录用户身份权限
+	 * 
+	 */
+	public void payBack(TOrderManage orderManage, String userName, Long deptId) {
+
+        //座位信息取得。
+        TCommoditySchedul schedulSeat = new TCommoditySchedul();
+        schedulSeat.setCommodityId(orderManage.getCommodityId());
+        schedulSeat.setDepartureDate(orderManage.getDepartureDate());
+        List<TCommoditySchedul> seatList = commoditySchedulService.selectTCommoditySchedulList(schedulSeat);
+        long stock = 0;
+        for (TCommoditySchedul seatRcd : seatList) {
+        	stock = seatRcd.getSeatNum();
+    		seatRcd.setSeatNum(stock + orderManage.getAdultNum() + orderManage.getChildNum());
+            commoditySchedulService.updateTCommoditySchedul(seatRcd);
+        }
+        
+        // 减去增加的积分  订单金额为增加的积分数量
+        TCustomerManage customerManage = customerManageService.selectTCustomerManageById(orderManage.getCustomerId());
+        // 取得下单时的积分记录
+        TCustomerIntegralRecord tCustomerIntegral = new TCustomerIntegralRecord();
+        tCustomerIntegral.setOrderId(orderManage.getOrderTotalId());
+        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());
+        	//如果是下单记录则则退款减算
+        	if ("1".equals(recd.getIntegralType())) {
+                //用户积分更新 减算
+                customerManage.setIntegral(customerManage.getIntegral() - val);
+                ret = ret + val;
+                isHasChange = true;
+        	} else if ("4".equals(recd.getIntegralType())) {
+        		//如果是利用积分记录退款则加算
+                //用户积分更新 加算
+                customerManage.setIntegral(customerManage.getIntegral() + val);
+                ret = ret + val;
+                isHasChange = true;
+        	}
+        }
+        //有积分变化
+        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());
+        }
+        // 重置用户商品优惠券
+        if(orderManage.getIsCoupon().equals("1")){
+            List<TCommodityCoupon> commodityCouponList =
+                    commodityCouponService.selectTCommodityCouponList(TCommodityCoupon.builder().commodityId(orderManage.getCommodityId()).build());
+            if(commodityCouponList.size()>0){
+                List<TCustomerCoupon> tCustomerCoupons =
+                        customerCouponService.selectTCustomerCouponList(TCustomerCoupon.builder().couponId(commodityCouponList.get(0).getId()).customerId(customerManage.getId()).build());
+                // 有优惠券,且已使用,则重置
+                if(tCustomerCoupons.size()>0 && tCustomerCoupons.get(0).getStatus().equals("1")){
+                    customerCouponService.updateTCustomerCoupon(TCustomerCoupon.builder().id(tCustomerCoupons.get(0).getId()).status("0").build());
+                }
+            }
+        }
+        //
+        log.info("订单[" + orderManage.getId() + "]がキャンセルしました。");
+	}
+
+	/**
+	 *  支付表更新。
+	 * @param orderTotalId 总支付管理表ID
+	 * @param orderManageTotal  总支付管理表
+	 * @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())
+                    .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());
+            }
+            order.setStatus("1");// 已支付   支付状态,若接入支付回调,则变更为支付中状态-9,支付回调成功后变更为1-已支付
+            order.setPayDate(new Date());
+            orderManageService.updateTOrderManage(order);
+        }
+
+        // 获取场馆积分获取比例
+        List<TCustomerIntegralSet> tCustomerIntegralSets = customerIntegralSetService.selectTCustomerIntegralSetList(
+        		TCustomerIntegralSet.builder().deptId(loginuser.getLoginCustomer().getDeptId()).build());
+        
+        //只有有积分奖励的才可以积分
+        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);
+            }
+        }
+
+        // 会员减去积分
+        if(orderManageTotal.getIntegralDeduction() != null && 
+        		orderManageTotal.getIntegralDeduction().compareTo(BigDecimal.ZERO) > 0){
+            customer.setIntegral(customer.getIntegral() - orderManageTotal.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(
+                    		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().
+                orderTotalId(orderManageTotal.getId()).status("0").build());
+        if(orderManageList.size() <= 0){
+            orderManageTotal.setStatus("1");
+            orderManageTotalService.updateTOrderManageTotal(orderManageTotal);
+        }
+        
+      	List<TOrderManage> list = orderManageService.selectByManagerTotalId(orderManageTotal.getId());
+      	
+      	lineMessagingClient.pushMessage(new PushMessage(list.get(0).getPhone(),
+      			new TextMessage(SendMessage.getOrderMessage(list))));
+	}
+}

+ 86 - 0
ruoyi-admin/src/main/java/com/ruoyi/web/line/SendMessage.java

@@ -0,0 +1,86 @@
+package com.ruoyi.web.line;
+
+import java.io.StringWriter;
+import java.util.List;
+
+import org.apache.velocity.Template;
+import org.apache.velocity.VelocityContext;
+import org.apache.velocity.app.Velocity;
+
+import com.ruoyi.generator.util.VelocityInitializer;
+import com.ruoyi.web.pcApi.domain.TOrderManage;
+
+public class SendMessage {
+	static {
+	    //
+	    VelocityInitializer.initVelocity();
+		//Velocityの初期化
+	  	Velocity.init();
+	}
+	
+	/**
+	 *  create message
+	 * @param list 订单管理对象
+	 * @return message
+	 */
+	public static String getOrderMessage(List<TOrderManage> list) {
+
+      	StringWriter sw = new StringWriter();
+      	//テンプレートの作成
+      	Template template = Velocity.getTemplate("vm/orderAlertMsg.vm", "UTF-8");
+
+	  	//Velocityコンテキストに値を設定
+	  	VelocityContext context = new VelocityContext();
+	  	
+      	context.put("orders", list);
+      	
+      	//テンプレートとマージ
+      	template.merge(context, sw);
+      	
+      	return sw.toString();
+	}
+	
+	/**
+	 *  create message
+	 * @param list 订单管理对象
+	 * @return message
+	 */
+	public static String getCancelMessage(List<TOrderManage> list) {
+
+      	StringWriter sw = new StringWriter();
+      	//テンプレートの作成
+      	Template template = Velocity.getTemplate("vm/cancelMsg.vm", "UTF-8");
+
+	  	//Velocityコンテキストに値を設定
+	  	VelocityContext context = new VelocityContext();
+	  	
+      	context.put("orders", list);
+      	
+      	//テンプレートとマージ
+      	template.merge(context, sw);
+      	
+      	return sw.toString();
+	}
+	
+	/**
+	 *  create message
+	 * @param list 订单管理对象
+	 * @return message
+	 */
+	public static String getPayBackMessage(List<TOrderManage> list) {
+
+      	StringWriter sw = new StringWriter();
+      	//テンプレートの作成
+      	Template template = Velocity.getTemplate("vm/payBackMsg.vm", "UTF-8");
+
+	  	//Velocityコンテキストに値を設定
+	  	VelocityContext context = new VelocityContext();
+	  	
+      	context.put("orders", list);
+      	
+      	//テンプレートとマージ
+      	template.merge(context, sw);
+      	
+      	return sw.toString();
+	}
+}

+ 9 - 2
ruoyi-admin/src/main/java/com/ruoyi/web/pcApi/domain/TCommodityManage.java

@@ -2,10 +2,16 @@ package com.ruoyi.web.pcApi.domain;
 
 import java.math.BigDecimal;
 import java.util.List;
-import lombok.*;
+
 import com.ruoyi.common.annotation.Excel;
 import com.ruoyi.common.core.domain.BaseEntity;
 
+import lombok.AllArgsConstructor;
+import lombok.Builder;
+import lombok.Data;
+import lombok.NoArgsConstructor;
+import lombok.ToString;
+
 /**
  * 商品信息管理对象 t_commodity_manage
  * 
@@ -121,7 +127,8 @@ public class TCommodityManage extends BaseEntity
     private List<TCommodityCoupon> commodityCouponList;
     /** 评论信息*/
     private List<TOrderEvaluate> orderEvaluateList;
-
+    /** 座位数信息*/
+    private List<TCommoditySchedul> seatInfoLst;
 
     // 临时字段
     // 商品类型名称

+ 44 - 0
ruoyi-admin/src/main/java/com/ruoyi/web/pcApi/domain/TCommoditySchedul.java

@@ -0,0 +1,44 @@
+package com.ruoyi.web.pcApi.domain;
+
+import com.ruoyi.common.core.domain.BaseEntity;
+
+import lombok.AllArgsConstructor;
+import lombok.Builder;
+import lombok.Data;
+import lombok.NoArgsConstructor;
+import lombok.ToString;
+
+/**
+ * 旅游日程详细 t_commodity_schedul
+ * 
+ * @author lzp
+ * @date 2022-08-24
+ */
+@Data
+@ToString
+@Builder
+@NoArgsConstructor
+@AllArgsConstructor
+public class TCommoditySchedul extends BaseEntity
+{
+    private static final long serialVersionUID = 1L;
+
+    /** id */
+    private Long id;
+
+    /** 商品类型id */
+    private Long commodityId;
+
+    /** 出发日期 */
+    private String departureDate;
+
+    /** 库存 */
+    private Long seatNum;
+
+    /** bus公司id */
+    private Long deptId;
+
+    /** 删除标志:0-正常 1-删除 */
+    private String delFlag;
+
+}

+ 55 - 0
ruoyi-admin/src/main/java/com/ruoyi/web/pcApi/mapper/TCommoditySchedulMapper.java

@@ -0,0 +1,55 @@
+package com.ruoyi.web.pcApi.mapper;
+
+import java.util.List;
+
+import com.ruoyi.web.pcApi.domain.TCommoditySchedul;
+
+/**
+ * 旅游日程详细Mapper接口
+ * 
+ * @author lzp
+ * @date 2022-08-24
+ */
+public interface TCommoditySchedulMapper 
+{
+    /**
+     * 旅游日程详细
+     * 
+     * @param id 旅游日程详细主键
+     * @return 旅游日程详细
+     */
+    public TCommoditySchedul selectTCommoditySchedulById(Long id);
+
+    /**
+     * 旅游日程详细
+     * 
+     * @param tCommoditySchedul 旅游日程详细
+     * @return 旅游日程详细集合
+     */
+    public List<TCommoditySchedul> selectTCommoditySchedulList(TCommoditySchedul tCommoditySchedul);
+
+    /**
+     * 旅游日程详细
+     * 
+     * @param tCommoditySchedul 旅游日程详细
+     * @return 结果
+     */
+    public int insertTCommoditySchedul(TCommoditySchedul tCommoditySchedul);
+
+    /**
+     * 修改旅游日程详细
+     * 
+     * @param tCommoditySchedul 旅游日程详细
+     * @return 结果
+     */
+    public int updateTCommoditySchedul(TCommoditySchedul tCommoditySchedul);
+
+    /**
+     * 删除旅游日程详细
+     * 
+     * @param id 旅游日程详细主键
+     * @return 结果
+     */
+    public int deleteTCommoditySchedulId(Long id);
+
+}

+ 54 - 0
ruoyi-admin/src/main/java/com/ruoyi/web/pcApi/service/ITCommoditySchedulService.java

@@ -0,0 +1,54 @@
+package com.ruoyi.web.pcApi.service;
+
+import java.util.List;
+
+import com.ruoyi.web.pcApi.domain.TCommoditySchedul;
+
+/**
+ * 旅游日程详细Service接口
+ * 
+ * @author lzp
+ * @date 2022-08-24
+ */
+public interface ITCommoditySchedulService 
+{
+    /**
+     * 旅游日程详细
+     * 
+     * @param id 旅游日程详细主键
+     * @return 旅游日程详细
+     */
+    public TCommoditySchedul selectTCommoditySchedulById(Long id);
+
+    /**
+     * 旅游日程详细
+     * 
+     * @param tCommoditySchedul 旅游日程详细
+     * @return 旅游日程详细集合
+     */
+    public List<TCommoditySchedul> selectTCommoditySchedulList(TCommoditySchedul tCommoditySchedul);
+
+    /**
+     * 旅游日程详细
+     * 
+     * @param tCommoditySchedul 旅游日程详细
+     * @return 结果
+     */
+    public int insertTCommoditySchedul(TCommoditySchedul tCommoditySchedul);
+
+    /**
+     * 修改旅游日程详细
+     * 
+     * @param tCommoditySchedul 旅游日程详细
+     * @return 结果
+     */
+    public int updateTCommoditySchedul(TCommoditySchedul tCommoditySchedul);
+
+    /**
+     * 删除旅游日程详细
+     * 
+     * @param id 旅游日程详细主键
+     * @return 结果
+     */
+    public int deleteTCommoditySchedulId(Long id);
+}

+ 84 - 0
ruoyi-admin/src/main/java/com/ruoyi/web/pcApi/service/impl/TCommoditySchedulServiceImpl.java

@@ -0,0 +1,84 @@
+package com.ruoyi.web.pcApi.service.impl;
+
+import java.util.List;
+
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.stereotype.Service;
+import org.springframework.transaction.annotation.Transactional;
+
+import com.ruoyi.common.utils.DateUtils;
+import com.ruoyi.web.pcApi.domain.TCommoditySchedul;
+import com.ruoyi.web.pcApi.mapper.TCommoditySchedulMapper;
+import com.ruoyi.web.pcApi.service.ITCommoditySchedulService;
+
+/**
+ * 旅游日程详细Service业务层处理
+ * 
+ * @author lzp
+ * @date 2022-08-24
+ */
+@Service
+public class TCommoditySchedulServiceImpl implements ITCommoditySchedulService 
+{
+    @Autowired
+    private TCommoditySchedulMapper tCommoditySchedulMapper;
+
+    /**
+     * 查询旅游日程详细
+     * 
+     * @param id 旅游日程详细主键
+     * @return 旅游日程详细
+     */
+    @Override
+    public TCommoditySchedul selectTCommoditySchedulById(Long id)
+    {
+    	TCommoditySchedul tCommoditySchedul = tCommoditySchedulMapper.selectTCommoditySchedulById(id);
+        return tCommoditySchedul;
+    }
+
+    /**
+     * 查询旅游日程详细列表
+     * 
+     * @param TCommoditySchedul 旅游日程详细
+     * @return 旅游日程详细
+     */
+    @Override
+    public List<TCommoditySchedul> selectTCommoditySchedulList(TCommoditySchedul TCommoditySchedul)
+    {
+        return tCommoditySchedulMapper.selectTCommoditySchedulList(TCommoditySchedul);
+    }
+
+    /**
+     * 新增旅游日程详细
+     * 
+     * @param TCommoditySchedul 旅游日程详细
+     * @return 结果
+     */
+    @Transactional
+    @Override
+    public int insertTCommoditySchedul(TCommoditySchedul TCommoditySchedul)
+    {
+    	TCommoditySchedul.setCreateTime(DateUtils.getNowDate());
+        int rows = tCommoditySchedulMapper.insertTCommoditySchedul(TCommoditySchedul);
+        return rows;
+    }
+
+    /**
+     * 修改旅游日程详细
+     * 
+     * @param TCommoditySchedul 旅游日程详细
+     * @return 结果
+     */
+    @Transactional
+    @Override
+    public int updateTCommoditySchedul(TCommoditySchedul TCommoditySchedul)
+    {
+    	TCommoditySchedul.setUpdateTime(DateUtils.getNowDate());
+        return tCommoditySchedulMapper.updateTCommoditySchedul(TCommoditySchedul);
+    }
+
+	@Override
+	public int deleteTCommoditySchedulId(Long id) {
+		return tCommoditySchedulMapper.deleteTCommoditySchedulId(id);
+	}
+}

+ 51 - 12
ruoyi-admin/src/main/java/com/ruoyi/web/schedulTask/schedulTask.java

@@ -4,6 +4,7 @@ package com.ruoyi.web.schedulTask;
 import java.text.SimpleDateFormat;
 import java.time.LocalDate;
 import java.time.format.DateTimeFormatter;
+import java.util.ArrayList;
 import java.util.Calendar;
 import java.util.Date;
 import java.util.List;
@@ -19,14 +20,22 @@ import com.linecorp.bot.client.LineMessagingClient;
 import com.linecorp.bot.model.PushMessage;
 import com.linecorp.bot.model.message.TextMessage;
 import com.ruoyi.common.utils.StringUtils;
+import com.ruoyi.web.line.LinePay;
+import com.ruoyi.web.line.LinePayRefundAPOD;
+import com.ruoyi.web.line.PayApi;
+import com.ruoyi.web.line.SendMessage;
 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.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.ITOrderManageService;
+import com.ruoyi.web.pcApi.service.ITOrderManageTotalService;
 
 /**
  * 定时调度任务
@@ -49,6 +58,14 @@ public class schedulTask
     private LineMessagingClient lineMessagingClient;
     @Autowired
     MessageSource messages;
+    @Autowired
+    private PayApi payBackApi;
+    @Autowired
+    private LinePay linePay;
+    @Autowired
+    private ITOrderManageTotalService orderManageTotalService;
+    @Autowired
+    private ITCommoditySchedulService commoditySchedulService;
     
     private static final SimpleDateFormat dateSdf = new SimpleDateFormat("yyyy-MM-dd");
 
@@ -60,7 +77,7 @@ public class schedulTask
      */
     @Transactional
     @SuppressWarnings("all")
-   @Scheduled(cron = "0 0 0 * * ?")
+   @Scheduled(cron = "0 */10 * * * ?")
     public void dateScheduleTask() throws Exception{
         TCustomerCoupon customerCoupon = new TCustomerCoupon();
         TOrderManage order = new TOrderManage();
@@ -104,22 +121,41 @@ public class schedulTask
         for (TCommodityManage tCommodityManage : tCommodityManages) {
             // 判断有效结束日期是否超过当天
             if(StringUtils.isEmpty(tCommodityManage.getPeriodEnd()))continue;
-            if(new Date().compareTo(dateSdf.parse(tCommodityManage.getPeriodEnd())) >= 0){
+            // 判断旅行是否还是有效
+            if(new Date().compareTo(dateSdf.parse(tCommodityManage.getPeriodEnd())) <= 0){
                 // 判断提前截至日期
                 Calendar calendar = Calendar.getInstance();
-                calendar.setTime(dateSdf.parse(tCommodityManage.getPeriodEnd()));
-                calendar.add(Calendar.DATE, tCommodityManage.getAdvancePeriod());// num为增加的天数,可以改变的
+                calendar.add(Calendar.DATE, -tCommodityManage.getAdvancePeriod());// num为增加的天数,可以改变的
                 Date d = calendar.getTime();
                 if(new Date().compareTo(d)>= 0){
                     order.setCommodityId(tCommodityManage.getId());
                     order.setStatus("1");// 查询已支付的订单
+                    order.setDepartureDate(dateSdf.format(d));
                     List<TOrderManage> orderManageList = orderManageService.selectTOrderManageList4H5(order);
                     // 判断出行人数是否达标
                     if(orderManageList.size() < tCommodityManage.getAdvancePeriod()){
                         // 自动退款
                         for (TOrderManage orderManage : orderManageList) {
+                        	//
+                        	payBackApi.payBack(orderManage, "schedultask", orderManage.getDeptId());
+
                             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());
+                            }
+                            if (resp == null || "0000".equals(resp.returnCode)) {
+                            	List<TOrderManage> lst = new ArrayList<TOrderManage>();
+                            	lst.add(orderManage);
+                                //send message
+                            	lineMessagingClient.pushMessage(new PushMessage(orderManage.getPhone(),
+                              			new TextMessage(SendMessage.getPayBackMessage(lst))));
+                            }
                         }
                     }
                 }
@@ -142,14 +178,17 @@ public class schedulTask
             // 判断时间是否超过支付时间 1小时
             if((new Date().getTime() - orderManage.getCreateTime().getTime()) >= 3600*1000){
                 orderManageService.deleteTOrderManageById(orderManage.getId());
-                // 减少销售数量
-                TCommodityManage commodityManage = commodityManageService.selectTCommodityManageById(orderManage.getCommodityId());
-                Integer orderNum = orderManage.getAdultNum() + orderManage.getChildNum();
-                commodityManage.setStock(commodityManage.getStock() + orderNum);
-                // 增加销售数量
-                commodityManage.setSaleNum(commodityManage.getSaleNum() - orderNum);
-                commodityManageService.updateTCommodityManage(commodityManage);
-
+                //座位信息取得。
+                TCommoditySchedul schedulSeat = new TCommoditySchedul();
+                schedulSeat.setCommodityId(orderManage.getCommodityId());
+                schedulSeat.setDepartureDate(orderManage.getDepartureDate());
+                List<TCommoditySchedul> seatList = commoditySchedulService.selectTCommoditySchedulList(schedulSeat);
+                long stock = 0;
+                for (TCommoditySchedul seatRcd : seatList) {
+                	stock = seatRcd.getSeatNum();
+            		seatRcd.setSeatNum(stock + orderManage.getAdultNum() + orderManage.getChildNum());
+                    commoditySchedulService.updateTCommoditySchedul(schedulSeat);
+                }
             }
         }
 

+ 102 - 0
ruoyi-admin/src/main/resources/mapper/commoditySchedul/TCommoditySchedulMapper.xml

@@ -0,0 +1,102 @@
+<?xml version="1.0" encoding="UTF-8" ?>
+<!DOCTYPE mapper
+PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
+"http://mybatis.org/dtd/mybatis-3-mapper.dtd">
+<mapper namespace="com.ruoyi.web.pcApi.mapper.TCommoditySchedulMapper">
+    
+    <resultMap type="TCommoditySchedul" id="TCustomerSchedulResult">
+        <result property="id"    column="id"    />
+        <result property="commodityId"    column="commodity_id"    />
+        <result property="departureDate"    column="departure_date"    />
+        <result property="deptId"    column="dept_id"    />
+        <result property="createBy"    column="create_by"    />
+        <result property="createTime"    column="create_time"    />
+        <result property="updateBy"    column="update_by"    />
+        <result property="updateTime"    column="update_time"    />
+        <result property="remark"    column="remark"    />
+        <result property="seatNum"    column="seat_num"    />
+        <result property="delFlag"    column="del_flag"    />
+    </resultMap>
+
+    <sql id="selectTCustomerSchedulVo">
+        SELECT
+            a.id,
+            a.commodity_id,
+            a.departure_date,
+            a.seat_num,
+            a.dept_id,
+            a.create_by,
+            a.create_time,
+            a.update_by,
+            a.update_time,
+            a.remark,
+            a.del_flag
+        FROM
+            t_commodity_schedul a
+                INNER JOIN t_commodity_manage b on a.commodity_id = b.id
+    </sql>
+
+    <select id="selectTCommoditySchedulList" parameterType="TCommoditySchedul" resultMap="TCustomerSchedulResult">
+        <include refid="selectTCustomerSchedulVo"/>
+        <where>  
+            a.del_flag = '0'
+            <if test="commodityId != null "> and a.commodity_id = #{commodityId}</if>
+            <if test="departureDate != null "> and a.departure_date = #{departureDate}</if>
+        </where>
+        order by a.departure_date
+    </select>
+    
+    <select id="selectTCommoditySchedulById" parameterType="Long" resultMap="TCustomerSchedulResult">
+        <include refid="selectTCustomerSchedulVo"/>
+        where a.id = #{id}
+    </select>
+        
+    <insert id="insertTCommoditySchedul" parameterType="TCommoditySchedul" useGeneratedKeys="true" keyProperty="id">
+        insert into t_commodity_schedul
+        <trim prefix="(" suffix=")" suffixOverrides=",">
+            <if test="commodityId != null">commodity_id,</if>
+            <if test="departureDate != null">departure_date,</if>
+            <if test="deptId != null">dept_id,</if>
+            <if test="createBy != null">create_by,</if>
+            <if test="createTime != null">create_time,</if>
+            <if test="updateBy != null">update_by,</if>
+            <if test="updateTime != null">update_time,</if>
+            <if test="remark != null">remark,</if>
+            <if test="seatNum != null">seat_num,</if>
+         </trim>
+        <trim prefix="values (" suffix=")" suffixOverrides=",">
+            <if test="commodityId != null">#{commodityId},</if>
+            <if test="departureDate != null">#{departureDate},</if>
+            <if test="deptId != null">#{deptId},</if>
+            <if test="createBy != null">#{createBy},</if>
+            <if test="createTime != null">#{createTime},</if>
+            <if test="updateBy != null">#{updateBy},</if>
+            <if test="updateTime != null">#{updateTime},</if>
+            <if test="remark != null">#{remark},</if>
+            <if test="seatNum != null">#{seatNum},</if>
+         </trim>
+    </insert>
+
+    <update id="updateTCommoditySchedul" parameterType="TCommoditySchedul">
+        update t_commodity_schedul
+        <trim prefix="SET" suffixOverrides=",">
+            <if test="commodityId != null">commodity_id = #{commodityId},</if>
+            <if test="departureDate != null">departure_date = #{departureDate},</if>
+            <if test="seatNum != null">seat_num = #{seatNum},</if>
+            <if test="deptId != null">dept_id = #{deptId},</if>
+            <if test="createBy != null">create_by = #{createBy},</if>
+            <if test="createTime != null">create_time = #{createTime},</if>
+            <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="delFlag != null">del_flag = #{delFlag},</if>
+        </trim>
+        where id = #{id}
+    </update>
+
+    <delete id="deleteTCommoditySchedulId" parameterType="Long">
+        delete from t_commodity_schedul where id = #{id}
+    </delete>
+
+
+</mapper>

+ 10 - 0
ruoyi-admin/src/main/resources/vm/cancelMsg.vm

@@ -0,0 +1,10 @@
+ご利用いただきありがとうございます。
+下記のツーアはキャンセルいたしました。
+お支払い金額はLINEPAYに全額返金されました。ご確認ください。
+#foreach ($order in $orders)
+「$order.commodityName」
+出発日:$order.departureDate
+出発地:$order.departurePlace
+大人:$order.adultNum人
+ことも:$order.childNum人
+#end

+ 13 - 0
ruoyi-admin/src/main/resources/vm/payBackMsg.vm

@@ -0,0 +1,13 @@
+大変申し訳ございません。
+ご購入いただいたコースは
+成約人数に足したないため、
+キャンセルさせて頂きました。
+お支払い金額はLINEPAYに全額返金されました。ご確認ください。
+#foreach ($order in $orders)
+「$order.commodityName」
+出発日:$order.departureDate
+出発地:$order.departurePlace
+大人:$order.adultNum人
+ことも:$order.childNum人
+#end
+ご利用いただきありがとうございました。