|
@@ -7,7 +7,10 @@ import com.platform.yijia.pojo.*;
|
|
|
import com.platform.yijia.service.*;
|
|
|
import com.platform.yijia.utils.CodeMsg;
|
|
|
import com.platform.yijia.utils.ResultData;
|
|
|
+import com.platform.yijia.utils.weixinapp.WxPushUtil;
|
|
|
+import me.chanjar.weixin.mp.bean.template.WxMpTemplateData;
|
|
|
import org.apache.commons.lang3.StringUtils;
|
|
|
+import org.apache.ibatis.javassist.util.HotSwapAgent;
|
|
|
import org.slf4j.Logger;
|
|
|
import org.slf4j.LoggerFactory;
|
|
|
import org.springframework.stereotype.Controller;
|
|
@@ -16,6 +19,7 @@ import org.springframework.web.bind.annotation.*;
|
|
|
import javax.annotation.Resource;
|
|
|
import javax.naming.ldap.HasControls;
|
|
|
import java.math.BigDecimal;
|
|
|
+import java.text.SimpleDateFormat;
|
|
|
import java.util.*;
|
|
|
|
|
|
@Controller
|
|
@@ -34,6 +38,12 @@ public class PayOrderController {
|
|
|
private PayOrderMapper payOrderMapper;
|
|
|
@Resource
|
|
|
private ElectronicMembershipCardService electronicMembershipCardService;
|
|
|
+ @Resource
|
|
|
+ private WxPushUtil wxPushUtil;
|
|
|
+ @Resource
|
|
|
+ private IntegralRuleService integralRuleService;
|
|
|
+ @Resource
|
|
|
+ private CustomerPointsService customerPointsService;
|
|
|
|
|
|
//一键支付,生成订单
|
|
|
@RequestMapping(value = "/AddPayOrderInfo", consumes = "application/json", method = RequestMethod.POST)
|
|
@@ -259,8 +269,19 @@ public class PayOrderController {
|
|
|
electronicMembershipCardService.updateElectronicCardInfoByUnionId(c);
|
|
|
payOrder.setStatus("1");
|
|
|
payOrderMapper.insertSelective(payOrder);
|
|
|
+ //计算积分
|
|
|
+ CalculateIntegral calculateIntegral = new CalculateIntegral();
|
|
|
+ calculateIntegral.setAmt(new BigDecimal(payOrder.getAmt()));
|
|
|
+ calculateIntegral.setReceivableAmt(new BigDecimal(payOrder.getReceivableAmt()));
|
|
|
+ calculateIntegral.setOilLiters(new BigDecimal(payOrder.getOrderLiters()));
|
|
|
+ calculateIntegral.setOilName(payOrder.getOilName());
|
|
|
+ calculateIntegral.setOilType(payOrder.getOrderType());
|
|
|
+ calculateIntegral.setStationId(payOrder.getStationId());
|
|
|
+ int integral = this.calculateIntegral(calculateIntegral);
|
|
|
resultMap.put("ordNo", ordNo);
|
|
|
resultData = ResultData.success(resultMap);
|
|
|
+ //推送加油赠送积分
|
|
|
+ pushIntegral(payOrderRequest.getStationId(), integral, payOrderRequest.getOpenId());
|
|
|
}else {
|
|
|
resultData=ResultData.error(CodeMsg.BALANCE_NOT_EENOUGH);
|
|
|
}
|
|
@@ -490,6 +511,156 @@ public class PayOrderController {
|
|
|
}
|
|
|
|
|
|
/**
|
|
|
+ * 计算使用电子会员卡消费生成积分
|
|
|
+ */
|
|
|
+ public int calculateIntegral(CalculateIntegral calculateIntegral){
|
|
|
+ int integral =0;
|
|
|
+ IntegralRule integralRule = new IntegralRule();
|
|
|
+ integralRule.setStationId(calculateIntegral.getStationId());
|
|
|
+ integralRule.setEmptyDate(new Date());
|
|
|
+ integralRule.setOilName(calculateIntegral.getOilName());
|
|
|
+ integralRule.setOilType(calculateIntegral.getOilType());
|
|
|
+ //获取该油站的积分规则
|
|
|
+ List<IntegralRule> integralRuleList = integralRuleService.getIntegralRule(integralRule);
|
|
|
+ if(integralRuleList !=null && integralRuleList.size() >0){
|
|
|
+ List<IntegralRuleDetail> integralRuleDetailList = integralRuleList.get(0).getIntegralRuleDetailList();
|
|
|
+ String currentTime = new SimpleDateFormat("yyyy-MM-dd").format(new Date()); //当前时间
|
|
|
+ String datePicker=null; //活动时间
|
|
|
+ String[] datePickerArray ={};
|
|
|
+ String integralActivity = integralRuleList.get(0).getIntegralActivity();
|
|
|
+ String integralProportion =null;
|
|
|
+ if(integralActivity.equals("1")){
|
|
|
+ datePicker = integralRuleList.get(0).getDatePicker();
|
|
|
+ integralProportion = integralRuleList.get(0).getIntegralProportion();
|
|
|
+ if(datePicker.contains(",")){
|
|
|
+ datePickerArray = datePicker.split(",");
|
|
|
+ }else {
|
|
|
+ datePickerArray= new String[1];
|
|
|
+ datePickerArray[0] = datePicker;
|
|
|
+ }
|
|
|
+ }
|
|
|
+ if(integralRuleDetailList !=null && integralRuleDetailList.size() >0){
|
|
|
+ for (IntegralRuleDetail integralRuleDetail : integralRuleDetailList){
|
|
|
+ if(integralRuleDetail.getOilType().equals("1")){ //油品
|
|
|
+ if (integralRuleDetail.getRuleType().equals("1")){ //按照实收金额
|
|
|
+ if(calculateIntegral.getAmt().compareTo(integralRuleDetail.getRuleTerms()) == 1 || calculateIntegral.getAmt().compareTo(integralRuleDetail.getRuleTerms()) == 0){
|
|
|
+ BigDecimal divide = calculateIntegral.getAmt().divide(integralRuleDetail.getSaleAmt(), 0, BigDecimal.ROUND_HALF_DOWN);
|
|
|
+ BigDecimal multiply = divide.multiply(integralRuleDetail.getIntegral());
|
|
|
+ if(integralActivity.equals("1") && datePickerArray !=null && integralProportion !=null){
|
|
|
+ for (String s : datePickerArray){
|
|
|
+ if(s.contains(currentTime)){
|
|
|
+ multiply = multiply.multiply(new BigDecimal(integralProportion));
|
|
|
+ break;
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ integral =multiply.intValue();
|
|
|
+ break;
|
|
|
+ }
|
|
|
+ }else if (integralRuleDetail.getRuleType().equals("2")){ //按应收金额
|
|
|
+ if(calculateIntegral.getReceivableAmt().compareTo(integralRuleDetail.getRuleTerms()) ==1 || calculateIntegral.getReceivableAmt().compareTo(integralRuleDetail.getRuleTerms()) ==0){
|
|
|
+ BigDecimal divide = calculateIntegral.getReceivableAmt().divide(integralRuleDetail.getSaleAmt(), 0, BigDecimal.ROUND_HALF_DOWN);
|
|
|
+ BigDecimal multiply = divide.multiply(integralRuleDetail.getIntegral());
|
|
|
+ if(integralActivity.equals("1") && datePickerArray !=null && integralProportion !=null){
|
|
|
+ for (String s : datePickerArray){
|
|
|
+ if(s.contains(currentTime)){
|
|
|
+ multiply = multiply.multiply(new BigDecimal(integralProportion));
|
|
|
+ break;
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ integral = multiply.intValue();
|
|
|
+ break;
|
|
|
+ }
|
|
|
+ }else if (integralRuleDetail.getRuleType().equals("3")){ //按照加油升数
|
|
|
+ if(calculateIntegral.getOilLiters().compareTo(integralRuleDetail.getRuleTerms()) ==1 || calculateIntegral.getOilLiters().compareTo(integralRuleDetail.getRuleTerms()) ==0){
|
|
|
+ BigDecimal divide = calculateIntegral.getOilLiters().divide(integralRuleDetail.getSaleAmt(), 0, BigDecimal.ROUND_HALF_DOWN);
|
|
|
+ BigDecimal multiply = divide.multiply(integralRuleDetail.getIntegral());
|
|
|
+ if(integralActivity.equals("1") && datePickerArray !=null && integralProportion !=null){
|
|
|
+ for (String s : datePickerArray){
|
|
|
+ if(s.contains(currentTime)){
|
|
|
+ multiply = multiply.multiply(new BigDecimal(integralProportion));
|
|
|
+ break;
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ integral =multiply.intValue();
|
|
|
+ break;
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }else if (integralRuleDetail.getOilType().equals("2")){ //非油品
|
|
|
+ if (calculateIntegral.getReceivableAmt().compareTo(integralRuleDetail.getRuleTerms()) ==1 || calculateIntegral.getReceivableAmt().compareTo(integralRuleDetail.getRuleTerms()) ==0){
|
|
|
+ BigDecimal divide = calculateIntegral.getReceivableAmt().divide(integralRuleDetail.getSaleAmt(), 0, BigDecimal.ROUND_HALF_DOWN);
|
|
|
+ BigDecimal multiply = divide.multiply(integralRuleDetail.getIntegral());
|
|
|
+ if(integralActivity.equals("1") && datePickerArray !=null && integralProportion !=null){
|
|
|
+ for (String s : datePickerArray){
|
|
|
+ if(s.contains(currentTime)){
|
|
|
+ multiply = multiply.multiply(new BigDecimal(integralProportion));
|
|
|
+ break;
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ integral = multiply.intValue();
|
|
|
+ break;
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ return integral;
|
|
|
+ }
|
|
|
+
|
|
|
+ /*
|
|
|
+ * 公众号推送积分
|
|
|
+ * @param stationId 油站ID
|
|
|
+ * @param integral 本次所得积分
|
|
|
+ * @param openId 用户openID
|
|
|
+ */
|
|
|
+ public void pushIntegral(Integer stationId, int integral, String openId){
|
|
|
+ String gzhAppId ="";
|
|
|
+ String gzhAppSecret ="";
|
|
|
+ String stationName = ""; //油站名称
|
|
|
+ BigDecimal surplusIntegral=null;
|
|
|
+ String customerName =null;
|
|
|
+ if(StringUtils.isNotBlank(openId)){
|
|
|
+ Map<String, String> m = stationService.getStationAppIdAndAppSecret(stationId);
|
|
|
+ if(m !=null && m.containsKey("stationName") && m.containsKey("gzhAppId") && m.containsKey("gzhAppSecret")){
|
|
|
+ stationName = m.get("stationName");
|
|
|
+ gzhAppId = m.get("gzhAppId");
|
|
|
+ gzhAppSecret = m.get("gzhAppSecret");
|
|
|
+ }
|
|
|
+ CustomerPoints customerPoints = new CustomerPoints();
|
|
|
+ customerPoints.setStationId(stationId);
|
|
|
+ customerPoints.setMinaOpenId(openId);
|
|
|
+ CustomerPoints customerPointsInfo = customerPointsService.getCustomerPointsInfoByMinaOpenId(customerPoints);
|
|
|
+ if(customerPointsInfo !=null){
|
|
|
+ customerName =customerPointsInfo.getCustomerName();
|
|
|
+ surplusIntegral =new BigDecimal(customerPointsInfo.getPoints()).add(new BigDecimal(integral));
|
|
|
+ customerPoints.setUnionId(customerPointsInfo.getUnionId());
|
|
|
+ customerPoints.setPoints(surplusIntegral.intValue());
|
|
|
+ //更新客户积分
|
|
|
+ customerPointsService.updateCustomerPointsInfo(customerPoints);
|
|
|
+ String blogOpenId = customerPointsInfo.getBlogOpenId(); //公众号openId
|
|
|
+ if(blogOpenId !=null){
|
|
|
+ //推送模板
|
|
|
+ List<WxMpTemplateData> wxMpTemplate = new ArrayList<>();
|
|
|
+ wxMpTemplate.add(new WxMpTemplateData("first","尊敬的"+customerName+",您好:\n" + "您在"+stationName+"的积分最新交易信息如下"));
|
|
|
+ wxMpTemplate.add(new WxMpTemplateData("time", new SimpleDateFormat("yyyy年MM月dd日HH时mm分").format(new Date())));
|
|
|
+ wxMpTemplate.add(new WxMpTemplateData("type", "增加"));
|
|
|
+ wxMpTemplate.add(new WxMpTemplateData("Point", String.valueOf(integral)));
|
|
|
+ wxMpTemplate.add(new WxMpTemplateData("From", stationName));
|
|
|
+ wxMpTemplate.add(new WxMpTemplateData("remark",
|
|
|
+ "截止至" + new SimpleDateFormat(" yyyy年MM月dd日HH时mm分").format(new Date())+",您在"+stationName+"的可用积分为 "+surplusIntegral.toString()+" 分"));
|
|
|
+ String templateId = "G9tN--a3tGM5BN3otqZr73b4ErQCYWISSgyshbTqLYc"; //积分兑换成功通知模板
|
|
|
+ wxPushUtil.push(gzhAppId, gzhAppSecret, templateId, blogOpenId, wxMpTemplate); //oJR5R6r4EJhaORFcPap70r_mtFZo
|
|
|
+ }
|
|
|
+
|
|
|
+ }
|
|
|
+
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
* 根据订单号获取订单信息
|
|
|
* produces="application/json;charset=UTF-8",consumes = "application/json",
|
|
|
* @RequestBody String orderno
|