|
@@ -15,6 +15,7 @@ import org.apache.commons.lang3.StringUtils;
|
|
|
import org.slf4j.Logger;
|
|
|
import org.slf4j.LoggerFactory;
|
|
|
import org.springframework.stereotype.Controller;
|
|
|
+import org.springframework.transaction.annotation.Transactional;
|
|
|
import org.springframework.web.bind.annotation.*;
|
|
|
import javax.annotation.Resource;
|
|
|
import java.math.BigDecimal;
|
|
@@ -24,7 +25,7 @@ import java.text.SimpleDateFormat;
|
|
|
import java.util.*;
|
|
|
|
|
|
@Controller
|
|
|
-@RequestMapping("/api")
|
|
|
+@RequestMapping("/demo")
|
|
|
public class PayController {
|
|
|
private static Logger logger =(Logger) LoggerFactory.getLogger(PayController.class);
|
|
|
@Resource
|
|
@@ -211,8 +212,8 @@ public class PayController {
|
|
|
|
|
|
//reqData.put("outFrontUrl", ""); //js 支付,前台 成功通知地址
|
|
|
//reqData.put("outFrontFailUrl", ""); //js 支付,前台 事变通知地址
|
|
|
- reqData.put("notifyUrl", "https://www.huijy.net/api/getCallback"); //回调地址
|
|
|
- //reqData.put("notifyUrl", "https://www.huijy.net/demo/getCallback"); //回调地址
|
|
|
+ //reqData.put("notifyUrl", "https://www.huijy.net/api/getCallback"); //回调地址
|
|
|
+ reqData.put("notifyUrl", "https://www.huijy.net/demo/getCallback"); //回调地址
|
|
|
//reqData.put("needReceipt", "00"); //电子发票功能 微信开具电子 发票使用
|
|
|
//reqData.put("ledgerAccountFlag", "00"); //是否做分账 分账交易使 用;00:做; 01:不做;不传默认为不做分账
|
|
|
//reqData.put("ledgerAccountEffectTime", "00"); //分账有效时间 单位为天;是 否做分账选择 00 时该字段必传
|
|
@@ -400,6 +401,7 @@ public class PayController {
|
|
|
*/
|
|
|
@RequestMapping(value = "/getCallback", consumes = "application/json", method = RequestMethod.POST)
|
|
|
@ResponseBody
|
|
|
+ @Transactional
|
|
|
public void getCallback(@RequestBody JSONObject request){
|
|
|
logger.info("-------------------------------回调开始----------------------------------------------");
|
|
|
logger.info("回调返回过来的参数"+request);
|
|
@@ -661,7 +663,7 @@ public class PayController {
|
|
|
logger.info("不存在客户 新增时参数: " + customerManage.toString());
|
|
|
payOrderService.insertCustomer(customerManage);
|
|
|
}
|
|
|
-/*/==========================================================================================================================================================//
|
|
|
+//==========================================================================================================================================================//
|
|
|
//客户积分
|
|
|
IntegralRule integralRule =new IntegralRule();
|
|
|
integralRule.setStationId(Integer.valueOf(infoMap.get("stationId").toString()));
|
|
@@ -675,6 +677,7 @@ public class PayController {
|
|
|
//获取该油站的积分规则
|
|
|
integralRule.setEmptyDate(new Date());
|
|
|
List<IntegralRule> rule = integralRuleService.getIntegralRule(integralRule);
|
|
|
+ logger.info("当前油站油品的积分规则:" + rule);
|
|
|
if(rule !=null && rule.size() > 0 && rule.get(0).getEmptyDate().compareTo(new Date()) ==1){
|
|
|
CustomerPoints customerPoints = new CustomerPoints(); //客户积分实体表
|
|
|
CustomerPointsRecord customerPointsRecord = new CustomerPointsRecord(); //客户积分记录实体表
|
|
@@ -709,55 +712,79 @@ public class PayController {
|
|
|
//String ruleType = rule.get(0).getRuleType(); //获取积分规则类型
|
|
|
String[] datePicker={}; //积分比例时间
|
|
|
if(rule.get(0).getDatePicker() != null && rule.get(0).getDatePicker() !=""){
|
|
|
- datePicker = rule.get(0).getDatePicker().split(",");
|
|
|
+ if(rule.get(0).getDatePicker().contains(",")){
|
|
|
+ datePicker = rule.get(0).getDatePicker().split(",");
|
|
|
+ }else {
|
|
|
+ datePicker= new String[1];
|
|
|
+ datePicker[0] = rule.get(0).getDatePicker();
|
|
|
+ }
|
|
|
}
|
|
|
String currentTime = new SimpleDateFormat("yyyy-MM-dd").format(new Date()); //当前时间
|
|
|
List<IntegralRuleDetail> integralRuleDetailList = rule.get(0).getIntegralRuleDetailList(); //积分规则详细计算信息
|
|
|
if(integralRuleDetailList !=null && integralRuleDetailList.size() > 0){
|
|
|
BigDecimal realAmt = new BigDecimal(infoMap.get("amt").toString()); //本次消费实收金额
|
|
|
BigDecimal receivableAmt = new BigDecimal(infoMap.get("receivableAmt").toString()); //本次消费实收金额
|
|
|
- BigDecimal orderLiters = new BigDecimal(infoMap.get("orderLiters").toString()); //本次加油升数
|
|
|
+ BigDecimal orderLiters = null; //本次加油升数
|
|
|
+ if(infoMap.containsKey("orderType") && infoMap.get("orderType").toString().equals("1")){
|
|
|
+ orderLiters = new BigDecimal(infoMap.get("orderLiters").toString()); //本次加油升数
|
|
|
+ }
|
|
|
//循环规则明细
|
|
|
for(IntegralRuleDetail integralRuleDetail : integralRuleDetailList){
|
|
|
if(integralRuleDetail.getOilType().equals("1")){ //油品
|
|
|
//规则类型
|
|
|
+ logger.info("当前生成积分类型:油品");
|
|
|
String ruleType = integralRuleDetail.getRuleType();
|
|
|
- if(ruleType !=null && ruleType =="1" && realAmt.compareTo(integralRuleDetail.getRuleTerms()) ==1){
|
|
|
+ logger.info("当前油品规则类型ruleType: " + ruleType);
|
|
|
+ if(ruleType !=null && ruleType.equals("1") && realAmt.compareTo(integralRuleDetail.getRuleTerms()) ==1 || realAmt.compareTo(integralRuleDetail.getRuleTerms()) ==0){
|
|
|
//以实收金额为准时
|
|
|
+ logger.info("以实收金额为准时");
|
|
|
if(discountPlanType == "1" && integralRuleDetail.getGread() !=null && customerManage.getGrade().equals(integralRuleDetail.getGread())){
|
|
|
//计算积分并取整
|
|
|
+ logger.info("油站使用等级");
|
|
|
countIntegral (realAmt, integralRuleDetail, datePicker, currentTime, rule, customerPoints, customerPointsRecord, customerPointsInfo);
|
|
|
break;
|
|
|
}else {
|
|
|
//计算积分并取整
|
|
|
+ logger.info("油站没有使用等级");
|
|
|
countIntegral (realAmt, integralRuleDetail, datePicker, currentTime, rule, customerPoints, customerPointsRecord, customerPointsInfo);
|
|
|
break;
|
|
|
}
|
|
|
- }else if(ruleType !=null && ruleType =="2" && receivableAmt.compareTo(integralRuleDetail.getRuleTerms()) ==1){
|
|
|
+ }else if(ruleType !=null && ruleType.equals("2") && receivableAmt.compareTo(integralRuleDetail.getRuleTerms()) ==1 || receivableAmt.compareTo(integralRuleDetail.getRuleTerms()) ==0){
|
|
|
//应收金额为准时
|
|
|
+ logger.info("应收金额为准");
|
|
|
if(discountPlanType == "1" && integralRuleDetail.getGread() !=null && customerManage.getGrade().equals(integralRuleDetail.getGread())){
|
|
|
//计算积分并取整
|
|
|
+ logger.info("油站使用等级");
|
|
|
countIntegral (receivableAmt, integralRuleDetail, datePicker, currentTime, rule, customerPoints, customerPointsRecord, customerPointsInfo);
|
|
|
break;
|
|
|
}else {
|
|
|
//计算积分并取整
|
|
|
+ logger.info("油站没有使用等级");
|
|
|
countIntegral (receivableAmt, integralRuleDetail, datePicker, currentTime, rule, customerPoints, customerPointsRecord, customerPointsInfo);
|
|
|
break;
|
|
|
}
|
|
|
|
|
|
- }else if(ruleType !=null && ruleType =="3" && orderLiters.compareTo(integralRuleDetail.getRuleTerms()) ==1){
|
|
|
+ }else if(ruleType !=null && ruleType.equals("3") && orderLiters.compareTo(integralRuleDetail.getRuleTerms()) ==1 || orderLiters.compareTo(integralRuleDetail.getRuleTerms()) ==0){
|
|
|
//加油升数为准时
|
|
|
+ logger.info("加油升数为准");
|
|
|
if(discountPlanType == "1" && integralRuleDetail.getGread() !=null && customerManage.getGrade().equals(integralRuleDetail.getGread())){
|
|
|
//计算积分并取整
|
|
|
+ logger.info("油站使用等级");
|
|
|
countIntegral (orderLiters, integralRuleDetail, datePicker, currentTime, rule, customerPoints, customerPointsRecord, customerPointsInfo);
|
|
|
break;
|
|
|
}else {
|
|
|
//计算积分并取整
|
|
|
+ logger.info("油站没有使用等级");
|
|
|
countIntegral (orderLiters, integralRuleDetail, datePicker, currentTime, rule, customerPoints, customerPointsRecord, customerPointsInfo);
|
|
|
break;
|
|
|
}
|
|
|
+ }else {
|
|
|
+ customerPoints.setPoints(customerPointsInfo.getPoints());
|
|
|
+ customerPoints.setAccumulatePoints(customerPointsInfo.getPoints());
|
|
|
+ customerPointsRecord.setIntegral(0);
|
|
|
}
|
|
|
}else if(integralRuleDetail.getOilType().equals("2")){ //非油品
|
|
|
+ logger.info("当前生成积分类型:非油品");
|
|
|
//计算积分并取整
|
|
|
countIntegral (realAmt, integralRuleDetail, datePicker, currentTime, rule, customerPoints, customerPointsRecord, customerPointsInfo);
|
|
|
break;
|
|
@@ -765,35 +792,24 @@ public class PayController {
|
|
|
}
|
|
|
}
|
|
|
|
|
|
+ logger.info("客户积分customerPoints:"+ customerPoints);
|
|
|
+ logger.info("客户积分记录customerPointsRecord:"+ customerPointsRecord);
|
|
|
//更新客户余额积分
|
|
|
customerPointsService.updateCustomerPointsInfo(customerPoints);
|
|
|
//插入客户积分记录表
|
|
|
customerPointsRecordService.insertCustomerPointsInfo(customerPointsRecord);
|
|
|
-
|
|
|
//客户公众号积分增加通知
|
|
|
- String gzhAppId ="";
|
|
|
- String gzhAppSecret ="";
|
|
|
- String stationName = ""; //油站名称
|
|
|
- Map<String, String> m = stationService.getStationAppIdAndAppSecret(Integer.valueOf(infoMap.get("stationId").toString()));
|
|
|
- if(m !=null && m.containsKey("stationName") && m.containsKey("gzhAppId") && m.containsKey("gzhAppSecret")){
|
|
|
- stationName = m.get("stationName");
|
|
|
- gzhAppId = m.get("gzhAppId");
|
|
|
- gzhAppSecret = m.get("gzhAppSecret");
|
|
|
- }
|
|
|
- List<WxMpTemplateData> wxMpTemplate = new ArrayList<>();
|
|
|
- wxMpTemplate.add(new WxMpTemplateData("first","尊敬的"+infoMap.get("consumer").toString()+",您好:\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", customerPointsRecord.getIntegral().toString()));
|
|
|
- wxMpTemplate.add(new WxMpTemplateData("From", stationName));
|
|
|
- wxMpTemplate.add(new WxMpTemplateData("remark",
|
|
|
- "截止至" + new SimpleDateFormat(" yyyy年MM月dd日HH时mm分").format(new Date())+",您在"+stationName+"的可用积分为 "+customerPoints.getPoints().toString()+" 分"));
|
|
|
- String templateId = "G9tN--a3tGM5BN3otqZr73b4ErQCYWISSgyshbTqLYc"; //积分兑换成功通知模板
|
|
|
- wxPushUtil.push(gzhAppId, gzhAppSecret, templateId, customerPoints.getBlogOpenId(), wxMpTemplate);
|
|
|
+ //customerPoints.getBlogOpenId()
|
|
|
+ //weiXinPushIntegralInfo(infoMap.get("stationId").toString(), infoMap.get("consumer").toString(), customerPointsRecord.getIntegral().toString(), customerPoints.getPoints().toString(), customerPoints.getBlogOpenId());
|
|
|
+ this.weiXinPushIntegralInfo(infoMap.get("stationId").toString()
|
|
|
+ , infoMap.get("consumer").toString()
|
|
|
+ , customerPointsRecord.getIntegral().toString()
|
|
|
+ , customerPoints.getPoints().toString()
|
|
|
+ , "oJR5R6r4EJhaORFcPap70r_mtFZo");
|
|
|
}
|
|
|
}
|
|
|
|
|
|
-*///========================================================================================================================================================//
|
|
|
+///========================================================================================================================================================//
|
|
|
//打印机打印小票
|
|
|
String content1;
|
|
|
String content2;
|
|
@@ -958,7 +974,9 @@ public class PayController {
|
|
|
String[] datePicker, String currentTime, List<IntegralRule> rule,
|
|
|
CustomerPoints customerPoints, CustomerPointsRecord customerPointsRecord, CustomerPoints customerPointsInfo){
|
|
|
BigDecimal integral = b1.divide(integralRuleDetail.getSaleAmt(), 0).multiply(integralRuleDetail.getIntegral()).setScale(0, BigDecimal.ROUND_DOWN);
|
|
|
+ logger.info("该用户本次消费获取积分值:"+integral.toString());
|
|
|
//设置积分多倍时间时
|
|
|
+ logger.info("积分双倍时间:" +datePicker);
|
|
|
if(datePicker !=null){
|
|
|
for(String str: datePicker){
|
|
|
if (str.contains(currentTime) && rule.get(0).getIntegralProportion() !=null ){
|
|
@@ -972,4 +990,36 @@ public class PayController {
|
|
|
customerPointsRecord.setIntegral(Integer.valueOf(integral.toString()));
|
|
|
}
|
|
|
|
|
|
+ /*
|
|
|
+ * 微信公众号消息推送
|
|
|
+ * @param stationId 油站ID
|
|
|
+ * @param consumer 用户昵称
|
|
|
+ * @param customerPointsRecordIntegral 用户积分记录
|
|
|
+ * @param customerPointsIntegral 用户当前还剩余的积分
|
|
|
+ */
|
|
|
+ public void weiXinPushIntegralInfo (String stationId, String consumer, String customerPointsRecordIntegral, String customerPointsIntegral, String openId){
|
|
|
+ //客户公众号积分增加通知
|
|
|
+ String gzhAppId ="";
|
|
|
+ String gzhAppSecret ="";
|
|
|
+ String stationName = ""; //油站名称
|
|
|
+ Map<String, String> m = stationService.getStationAppIdAndAppSecret(Integer.valueOf(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");
|
|
|
+ }
|
|
|
+ List<WxMpTemplateData> wxMpTemplate = new ArrayList<>();
|
|
|
+ wxMpTemplate.add(new WxMpTemplateData("first","尊敬的"+consumer+",您好:\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", customerPointsRecordIntegral));
|
|
|
+ wxMpTemplate.add(new WxMpTemplateData("From", stationName));
|
|
|
+ wxMpTemplate.add(new WxMpTemplateData("remark",
|
|
|
+ "截止至" + new SimpleDateFormat(" yyyy年MM月dd日HH时mm分").format(new Date())+",您在"+stationName+"的可用积分为 "+customerPointsIntegral+" 分"));
|
|
|
+ String templateId = "G9tN--a3tGM5BN3otqZr73b4ErQCYWISSgyshbTqLYc"; //积分兑换成功通知模板
|
|
|
+ //wxPushUtil.push(gzhAppId, gzhAppSecret, templateId, customerPoints.getBlogOpenId(), wxMpTemplate);
|
|
|
+ wxPushUtil.push(gzhAppId, gzhAppSecret, templateId, openId, wxMpTemplate); //oJR5R6r4EJhaORFcPap70r_mtFZo
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
}
|