parent
c96fbdf826
commit
e7c770b92f
@ -1 +1 @@ |
||||
package com.bweb.controller;
import com.alibaba.fastjson.JSONArray;
import com.alibaba.fastjson.JSONObject;
import com.hai.common.exception.ErrorCode;
import com.hai.common.exception.ErrorHelp;
import com.hai.common.exception.SysCode;
import com.hai.common.pay.util.XmlUtil;
import com.hai.common.pay.util.sdk.WXPayConstants;
import com.hai.common.utils.ResponseMsgUtil;
import com.hai.common.utils.WxUtils;
import com.hai.config.*;
import com.hai.dao.HighGasOrderPushMapper;
import com.hai.entity.*;
import com.hai.model.HighMerchantModel;
import com.hai.model.HighMerchantStoreModel;
import com.hai.model.ResponseData;
import com.hai.model.ResultProfitSharing;
import com.hai.service.*;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.apache.http.HttpEntity;
import org.apache.http.client.methods.CloseableHttpResponse;
import org.apache.http.client.methods.HttpPost;
import org.apache.http.conn.ssl.SSLConnectionSocketFactory;
import org.apache.http.entity.StringEntity;
import org.apache.http.impl.client.CloseableHttpClient;
import org.apache.http.impl.client.HttpClients;
import org.apache.http.ssl.SSLContexts;
import org.apache.http.util.EntityUtils;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.BeanUtils;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;
import javax.annotation.Resource;
import javax.net.ssl.SSLContext;
import java.io.FileInputStream;
import java.math.BigDecimal;
import java.security.KeyStore;
import java.util.*;
/**
* @Auther: 胡锐
* @Description:
* @Date: 2021/3/26 23:08
*/
@Controller
@RequestMapping(value = "/test")
@Api(value = "订单接口")
public class HighTestController {
private static Logger log = LoggerFactory.getLogger(HighTestController.class);
@RequestMapping(value = "/getBackendToken", method = RequestMethod.GET)
@ResponseBody
@ApiOperation(value = "获取访问令牌backendToken")
public ResponseData getBackendToken() {
try {
return ResponseMsgUtil.success(null);
} catch (Exception e) {
log.error("HighOrderController --> getBackendToken() error!", e);
@RequestMapping(value = "/getBackendToken", method = RequestMethod.GET)
@ResponseBody
@RequestMapping(value = "/TCheckEMsgUnionCardVipRights", method = RequestMethod.GET)
@ResponseBody
public ResponseData getBackendToken() {
try {
try {
return ResponseMsgUtil.success(null);
} catch (Exception e) {
);
} catch (Exception e) {
log.error("HighOrderController --> getBackendToken() error!", e);
return ResponseMsgUtil.exception(e);
}
}
@RequestMapping(value="/resolveResponse",method = RequestMethod.GET)
@ResponseBody
@ApiOperation(value = "解析")
public ResponseData resolveResponse(
@RequestParam(name = "data", required = false) String data
) {
try {
JSONObject cardInfoObject = HuiLianTongUnionCardConfig.resolveResponse(data);
return ResponseMsgUtil.success(cardInfoObject);
} catch (Exception e) {
log.error("getUserByTelephone",e);
return ResponseMsgUtil.exception(e);
}
}
} |
||||
package com.bweb.controller;
import com.alibaba.fastjson.JSONArray;
import com.alibaba.fastjson.JSONObject;
import com.hai.common.exception.ErrorCode;
import com.hai.common.exception.ErrorHelp;
import com.hai.common.exception.SysCode;
import com.hai.common.pay.util.XmlUtil;
import com.hai.common.pay.util.sdk.WXPayConstants;
import com.hai.common.utils.ResponseMsgUtil;
import com.hai.common.utils.WxUtils;
import com.hai.config.*;
import com.hai.dao.HighGasOrderPushMapper;
import com.hai.entity.*;
import com.hai.model.HighMerchantModel;
import com.hai.model.HighMerchantStoreModel;
import com.hai.model.ResponseData;
import com.hai.model.ResultProfitSharing;
import com.hai.service.*;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.apache.http.HttpEntity;
import org.apache.http.client.methods.CloseableHttpResponse;
import org.apache.http.client.methods.HttpPost;
import org.apache.http.conn.ssl.SSLConnectionSocketFactory;
import org.apache.http.entity.StringEntity;
import org.apache.http.impl.client.CloseableHttpClient;
import org.apache.http.impl.client.HttpClients;
import org.apache.http.ssl.SSLContexts;
import org.apache.http.util.EntityUtils;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.BeanUtils;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;
import javax.annotation.Resource;
import javax.net.ssl.SSLContext;
import java.io.FileInputStream;
import java.math.BigDecimal;
import java.security.KeyStore;
import java.util.*;
/**
* @Auther: 胡锐
* @Description:
* @Date: 2021/3/26 23:08
*/
@Controller
@RequestMapping(value = "/test")
@Api(value = "订单接口")
public class HighTestController {
private static Logger log = LoggerFactory.getLogger(HighTestController.class);
log.error("HighOrderController --> getBackendToken() error!", e);
@RequestMapping(value = "/getBackendToken", method = RequestMethod.GET)
@RequestMapping(value = "/getBackendToken", method = RequestMethod.GET)
@RequestMapping(value = "/getBackendToken", method = RequestMethod.GET)
@ResponseBody
@RequestMapping(value = "/getBackendToken", method = RequestMethod.GET)
@ApiOperation(value = "获取访问令牌backendToken")
@RequestMapping(value = "/getBackendToken", method = RequestMethod.GET)
public ResponseData getBackendToken() {
@RequestMapping(value = "/getBackendToken", method = RequestMethod.GET)
try {
@RequestMapping(value = "/getBackendToken", method = RequestMethod.GET)
return ResponseMsgUtil.success(null);
@RequestMapping(value = "/getBackendToken", method = RequestMethod.GET)
} catch (Exception e) {
@RequestMapping(value = "/getBackendToken", method = RequestMethod.GET)
log.error("HighOrderController --> getBackendToken() error!", e);
@ResponseBody
@ResponseBody
@ResponseBody
@RequestMapping(value = "/getBackendToken", method = RequestMethod.GET)
@RequestMapping(value = "/getBackendToken", method = RequestMethod.GET)
@ResponseBody
@ResponseBody
@ResponseBody
@ResponseBody
@ApiOperation(value = "获取访问令牌backendToken")
@ResponseBody
public ResponseData getBackendToken() {
@RequestMapping(value = "/getBackendToken", method = RequestMethod.GET)
try {
@ResponseBody
try {
@ResponseBody
return ResponseMsgUtil.success(null);
@ResponseBody
} catch (Exception e) {
} catch (Exception e) {
log.error("HighOrderController --> getBackendToken() error!", e);
return ResponseMsgUtil.exception(e);
}
}
@RequestMapping(value = "/GetMembershipLevel", method = RequestMethod.GET)
@ResponseBody
@ApiOperation(value = "请求会员体系")
public ResponseData GetMembershipLevel(@RequestParam(name = "phone", required = true) String phone , @RequestParam(name = "regionId", required = true) String regionId ) {
try {
return ResponseMsgUtil.success(hltUnionCardVipService.GetMembershipLevel(phone , regionId));
} catch (Exception e) {
log.error("HighOrderController --> getBackendToken() error!", e);
return ResponseMsgUtil.exception(e);
}
}
@RequestMapping(value="/resolveResponse",method = RequestMethod.GET)
@ResponseBody
@ApiOperation(value = "解析")
public ResponseData resolveResponse(
@RequestParam(name = "data", required = false) String data
) {
try {
JSONObject cardInfoObject = HuiLianTongUnionCardConfig.resolveResponse(data);
return ResponseMsgUtil.success(cardInfoObject);
} catch (Exception e) {
log.error("getUserByTelephone",e);
return ResponseMsgUtil.exception(e);
}
}
} |
@ -1,7 +1,33 @@ |
||||
package com.hai.dao; |
||||
|
||||
import com.hai.entity.HighDiscountPackage; |
||||
import com.hai.entity.HighDiscountPackageRecord; |
||||
import org.apache.ibatis.annotations.Param; |
||||
import org.apache.ibatis.annotations.Select; |
||||
|
||||
import java.util.List; |
||||
import java.util.Map; |
||||
|
||||
/** |
||||
* mapper扩展类 |
||||
*/ |
||||
public interface HighDiscountPackageRecordMapperExt { |
||||
} |
||||
|
||||
|
||||
@Select( |
||||
" SELECT *" + |
||||
" FROM high_discount_package_record" + |
||||
" WHERE" + |
||||
" status = 1 " + |
||||
" AND sales_type = 2 " + |
||||
" AND user_id = #{userId} " + |
||||
" AND using_attribution = #{usingAttribution} " + |
||||
" AND DATE_FORMAT(created_time, '%Y%m') = DATE_FORMAT(CURDATE(), '%Y%m'); " |
||||
) |
||||
/** |
||||
* 根据userId 查询当月是否赠送相关优惠券包 |
||||
* @param userId 用户id |
||||
* @return |
||||
*/ |
||||
List<HighDiscountPackageRecord> CheckCouponsMonth(@Param("userId") Long userId , @Param("usingAttribution") Integer usingAttribution); |
||||
} |
||||
|
@ -0,0 +1,26 @@ |
||||
package com.hai.service; |
||||
|
||||
|
||||
import com.alibaba.fastjson.JSONObject; |
||||
|
||||
/** |
||||
* @serviceName HltUnionCardVipService.java |
||||
* @author Sum1Dream |
||||
* @version 1.0.0 |
||||
* @Description // 汇联通会员体系
|
||||
* @createTime 4:49 下午 2021/11/30 |
||||
**/ |
||||
|
||||
public interface HltUnionCardVipService { |
||||
|
||||
/** |
||||
* @Author Sum1Dream |
||||
* @name GetMembershipLevel.java |
||||
* @Description // 获取会员等级
|
||||
* @Date 4:53 下午 2021/11/30 |
||||
* @Param [java.lang.String] |
||||
* @return com.alibaba.fastjson.JSONObject |
||||
*/ |
||||
JSONObject GetMembershipLevel(String phone , String regionId) throws Exception; |
||||
|
||||
} |
@ -0,0 +1,185 @@ |
||||
package com.hai.service.impl; |
||||
|
||||
import com.alibaba.fastjson.JSONArray; |
||||
import com.alibaba.fastjson.JSONObject; |
||||
import com.hai.common.exception.ErrorCode; |
||||
import com.hai.common.exception.ErrorHelp; |
||||
import com.hai.common.exception.SysCode; |
||||
import com.hai.common.utils.DateUtil; |
||||
import com.hai.common.utils.IDGenerator; |
||||
import com.hai.common.utils.ResponseMsgUtil; |
||||
import com.hai.config.HuiLianTongUnionCardConfig; |
||||
import com.hai.dao.HighDiscountPackageRecordMapper; |
||||
import com.hai.dao.HighDiscountUserRelMapper; |
||||
import com.hai.entity.*; |
||||
import com.hai.service.*; |
||||
import org.springframework.stereotype.Service; |
||||
import org.springframework.transaction.annotation.Isolation; |
||||
import org.springframework.transaction.annotation.Propagation; |
||||
import org.springframework.transaction.annotation.Transactional; |
||||
|
||||
import javax.annotation.Resource; |
||||
import java.util.*; |
||||
|
||||
@Service("hltUnionCardVipService") |
||||
public class HltUnionCardVipServiceImpl implements HltUnionCardVipService { |
||||
|
||||
@Resource |
||||
private HighDiscountPackageRecordMapper highDiscountPackageRecordMapper; |
||||
|
||||
@Resource |
||||
private HighUserService highUserService; |
||||
|
||||
@Resource |
||||
private HighDiscountPackageService highDiscountPackageService; |
||||
|
||||
@Resource |
||||
private CommonService commonService; |
||||
|
||||
@Resource |
||||
private BsCompanyService bsCompanyService; |
||||
|
||||
@Resource |
||||
private HighDiscountPackageDetailsService highDiscountPackageDetailsService; |
||||
|
||||
@Resource |
||||
private HighDiscountAgentRelService highDiscountAgentRelService; |
||||
|
||||
@Resource |
||||
private HighDiscountAgentCodeService highDiscountAgentCodeService; |
||||
|
||||
@Resource |
||||
private HighDiscountUserRelMapper highDiscountUserRelMapper; |
||||
|
||||
@Resource |
||||
private HighDiscountService highDiscountService; |
||||
|
||||
|
||||
@Override |
||||
@Transactional(propagation= Propagation.REQUIRES_NEW,isolation= Isolation.SERIALIZABLE) |
||||
public JSONObject GetMembershipLevel(String phone , String regionId) throws Exception { |
||||
|
||||
SecRegion region = commonService.getParentByRegion(Long.parseLong(regionId)); |
||||
|
||||
BsCompany bsCompany = bsCompanyService.selectCompanyByRegion(region.getRegionId().toString()); |
||||
|
||||
JSONObject consumptionRecord = HuiLianTongUnionCardConfig.TCheckEMsgUnionCardVipRights(phone); |
||||
JSONObject cardInfoObject = HuiLianTongUnionCardConfig.resolveResponse(consumptionRecord.getString("data")); |
||||
|
||||
|
||||
HighUser highUser = highUserService.findByPhone(phone); |
||||
|
||||
if (highUser == null) { |
||||
throw ErrorHelp.genException(SysCode.System, ErrorCode.COMMON_ERROR, "当前用户不存在"); |
||||
} |
||||
|
||||
boolean isVip = false; |
||||
|
||||
// 判断用户是否有会员权益
|
||||
for (Object dataObject : cardInfoObject.getJSONArray("data")) { |
||||
JSONObject d = (JSONObject) dataObject; |
||||
if (d.getInteger("level").equals(12)) { |
||||
isVip = true; |
||||
} |
||||
} |
||||
|
||||
// 判断汇联通会员等级 1-E信通会员,2-工会卡会员,12-E信通和工会卡会员
|
||||
if (isVip) { |
||||
|
||||
List<HighDiscountPackageRecord> list = highDiscountPackageRecordMapper.CheckCouponsMonth(highUser.getId() , 1); |
||||
|
||||
// 判断当月是否赠送会员权益
|
||||
if (list.size() > 0 ) { |
||||
throw ErrorHelp.genException(SysCode.System, ErrorCode.COMMON_ERROR, "用户当月已赠送"); |
||||
} else { |
||||
|
||||
Map<String,Object> map = new HashMap<>(); |
||||
map.put("companyId", bsCompany.getId()); |
||||
map.put("usingAttribution", 1); |
||||
map.put("salesType", 2); |
||||
|
||||
// 查询话费专属优惠券包
|
||||
List<HighDiscountPackage> highDiscountPackages = highDiscountPackageService.getDiscountPackageList(map); |
||||
|
||||
if (highDiscountPackages.size() == 0) { |
||||
throw ErrorHelp.genException(SysCode.System, ErrorCode.COMMON_ERROR, "暂未配置专属优惠券包"); |
||||
} |
||||
|
||||
HighDiscountPackage highDiscountPackage = highDiscountPackages.get(0); |
||||
|
||||
Map<String , Object> mapRule = new HashMap<>(); |
||||
mapRule.put("discountPackageId", highDiscountPackage.getId()); |
||||
|
||||
// 查询优惠券包规则
|
||||
List<HighDiscountPackageDetails> discountPackageDetailsList = highDiscountPackageDetailsService.getDiscountPackageDetailsList(mapRule); |
||||
|
||||
// 循环 优惠券包规则详情 列表
|
||||
for (HighDiscountPackageDetails detailsList: discountPackageDetailsList) { |
||||
|
||||
// 查询代理商与优惠券关系 列表
|
||||
List<HighDiscountAgentRel> discountAgentRels = highDiscountAgentRelService.getRelByDiscountId(detailsList.getDiscountId().longValue()); |
||||
|
||||
HighDiscountAgentRel discountAgentRel = new HighDiscountAgentRel(); |
||||
|
||||
for (HighDiscountAgentRel discountAgentRelList: discountAgentRels) { |
||||
// 判断当前是否足够库存赠送
|
||||
if (discountAgentRelList.getStockCount() > detailsList.getNum()) { |
||||
discountAgentRel = discountAgentRelList; |
||||
break; |
||||
} |
||||
} |
||||
|
||||
List<HighDiscountAgentCode> discountAgentCodeList = highDiscountAgentCodeService.getDiscountCodeByDiscountAgentId(discountAgentRel.getId()); |
||||
|
||||
// 赠送优惠券
|
||||
for (HighDiscountAgentCode discountAgentCode : discountAgentCodeList.subList(0, detailsList.getNum())) { |
||||
HighDiscountUserRel highDiscountUserRel = new HighDiscountUserRel(); |
||||
highDiscountUserRel.setDiscountId(discountAgentRel.getDiscountId()); |
||||
highDiscountUserRel.setUserId(highUser.getId()); |
||||
highDiscountUserRel.setAgentId(discountAgentRel.getAgentId()); |
||||
highDiscountUserRel.setDiscountAgentCodeId(discountAgentCode.getId()); |
||||
highDiscountUserRel.setStatus(1); |
||||
highDiscountUserRel.setCreateTime(new Date()); |
||||
|
||||
HighDiscount highDiscount = highDiscountService.getDiscountById(discountAgentRel.getDiscountId()); |
||||
|
||||
// 计算使用有效期
|
||||
Calendar userEndTime = Calendar.getInstance(); |
||||
userEndTime.setTime(new Date()); |
||||
userEndTime.set(Calendar.HOUR_OF_DAY, 23); |
||||
userEndTime.set(Calendar.MINUTE, 59); |
||||
userEndTime.set(Calendar.SECOND, 59); |
||||
userEndTime.add(Calendar.DATE, highDiscount.getEffectiveDay()); |
||||
highDiscountUserRel.setUseEndTime(userEndTime.getTime()); |
||||
|
||||
// 修改优惠券二维码状态
|
||||
discountAgentCode.setStatus(5); |
||||
highDiscountAgentCodeService.updateCode(discountAgentCode); |
||||
|
||||
// 新增优惠券与用户的绑定关系
|
||||
highDiscountUserRelMapper.insert(highDiscountUserRel); |
||||
} |
||||
|
||||
} |
||||
|
||||
// 增加赠送记录
|
||||
HighDiscountPackageRecord discountPackageRecord = new HighDiscountPackageRecord(); |
||||
discountPackageRecord.setDiscountPackageId(highDiscountPackage.getId()); |
||||
discountPackageRecord.setDiscountPackageTitle(highDiscountPackage.getTitle()); |
||||
discountPackageRecord.setCompanyId(highDiscountPackage.getCompanyId()); |
||||
discountPackageRecord.setStatus(1); |
||||
discountPackageRecord.setUsingAttribution(1); |
||||
discountPackageRecord.setRecordNo("DP" + DateUtil.date2String(new Date(),"yyyyMMddHHmmss") + IDGenerator.nextId(5) ); |
||||
discountPackageRecord.setSalesType(2); |
||||
discountPackageRecord.setUserId(highUser.getId().intValue()); |
||||
discountPackageRecord.setExt1(highUser.getPhone()); |
||||
discountPackageRecord.setCreatedTime(new Date()); |
||||
highDiscountPackageRecordMapper.insert(discountPackageRecord); |
||||
} |
||||
|
||||
} |
||||
|
||||
|
||||
return null; |
||||
} |
||||
} |
Loading…
Reference in new issue