|
|
@@ -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 {
|