贵州中石化分销

dev-discount
胡锐 3 years ago
parent 90db938450
commit c1275e416c
  1. 55
      hai-bweb/src/main/java/com/bweb/controller/HighCouponAgentController.java
  2. 8
      hai-service/src/main/java/com/hai/service/HighCouponAgentService.java
  3. 7
      hai-service/src/main/java/com/hai/service/HighCouponCodeOtherService.java
  4. 94
      hai-service/src/main/java/com/hai/service/impl/HighCouponAgentServiceImpl.java
  5. 11
      hai-service/src/main/java/com/hai/service/impl/HighCouponCodeOtherServiceImpl.java

@ -9,6 +9,7 @@ import com.hai.common.exception.SysCode;
import com.hai.common.security.SessionObject; import com.hai.common.security.SessionObject;
import com.hai.common.security.UserCenter; import com.hai.common.security.UserCenter;
import com.hai.common.utils.DateUtil; import com.hai.common.utils.DateUtil;
import com.hai.common.utils.MemberValidateUtil;
import com.hai.common.utils.ResponseMsgUtil; import com.hai.common.utils.ResponseMsgUtil;
import com.hai.entity.*; import com.hai.entity.*;
import com.hai.model.ResponseData; import com.hai.model.ResponseData;
@ -16,6 +17,7 @@ import com.hai.model.UserInfoModel;
import com.hai.service.*; import com.hai.service.*;
import io.swagger.annotations.Api; import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation; import io.swagger.annotations.ApiOperation;
import org.apache.commons.lang3.StringUtils;
import org.slf4j.Logger; import org.slf4j.Logger;
import org.slf4j.LoggerFactory; import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Autowired;
@ -57,6 +59,8 @@ public class HighCouponAgentController {
@Resource @Resource
private HighCouponService highCouponService; private HighCouponService highCouponService;
@Resource
private HighCouponCodeOtherService couponCodeOtherService;
@RequestMapping(value = "/getAgentCount", method = RequestMethod.GET) @RequestMapping(value = "/getAgentCount", method = RequestMethod.GET)
@ResponseBody @ResponseBody
@ -404,6 +408,7 @@ public class HighCouponAgentController {
Map<String, Object> map = new HashMap<>(); Map<String, Object> map = new HashMap<>();
map.put("couponInfo", highCouponService.getCouponById(couponAgentCode.getCouponId())); map.put("couponInfo", highCouponService.getCouponById(couponAgentCode.getCouponId()));
map.put("couponCode", highCouponCodeService.getCouponCodeById(couponAgentCode.getCouponCodeId())); map.put("couponCode", highCouponCodeService.getCouponCodeById(couponAgentCode.getCouponCodeId()));
map.put("couponCodeOther", couponCodeOtherService.getDetailByCouponAgentCodeId(couponAgentCode.getId()));
map.put("couponAgentCode", couponAgentCode); map.put("couponAgentCode", couponAgentCode);
return ResponseMsgUtil.success(map); return ResponseMsgUtil.success(map);
@ -413,7 +418,6 @@ public class HighCouponAgentController {
} }
} }
@RequestMapping(value = "/remark", method = RequestMethod.POST) @RequestMapping(value = "/remark", method = RequestMethod.POST)
@ResponseBody @ResponseBody
@ApiOperation(value = "填写备注") @ApiOperation(value = "填写备注")
@ -444,44 +448,51 @@ public class HighCouponAgentController {
} }
} }
@RequestMapping(value = "/getRecordByCouponAgentId", method = RequestMethod.GET) @RequestMapping(value = "/pushGzSinopec", method = RequestMethod.POST)
@ResponseBody @ResponseBody
@ApiOperation(value = "根据卡券与代理商关系 查询分发记录") @ApiOperation(value = "推送贵州中石化")
public ResponseData getRecordByCouponAgentId(@RequestParam(name = "couponAgentId", required = true) Long couponAgentId, public ResponseData pushGzSinopec(@RequestBody String reqBody) {
@RequestParam(name = "pageNum", required = true) Integer pageNum,
@RequestParam(name = "pageSize", required = true) Integer pageSize,
HttpServletRequest request) {
try { try {
Map<String,Object> map = new HashMap<>(); JSONObject jsonObject = JSONObject.parseObject(reqBody);
map.put("couponAgentId", couponAgentId); Long couponAgentCodeId = jsonObject.getLong("couponAgentCodeId");
PageHelper.startPage(pageNum,pageSize); String phone = jsonObject.getString("phone");
return ResponseMsgUtil.success(new PageInfo<>(highCouponAgentService.getRecordList(map))); String remark = jsonObject.getString("remark");
if (couponAgentCodeId == null || StringUtils.isBlank(phone) || StringUtils.isBlank(remark)) {
log.error("HighMerchantStoreController -> useCouponCode() error!","参数错误");
throw ErrorHelp.genException(SysCode.System, ErrorCode.REQ_PARAMS_ERROR, "");
}
if (!MemberValidateUtil.validatePhone(phone)) {
log.error("HighMerchantStoreController -> useCouponCode() error!","手机号格式错误");
throw ErrorHelp.genException(SysCode.System, ErrorCode.COMMON_ERROR, "手机号格式错误");
}
highCouponAgentService.pushGzSinopec(couponAgentCodeId, phone, remark);
return ResponseMsgUtil.success("操作成功");
} catch (Exception e) { } catch (Exception e) {
log.error("HighCouponAgentController --> getRecordByCouponAgentId() error!", e); log.error("HighCouponAgentController --> pushGzSinopec() error!", e);
return ResponseMsgUtil.exception(e); return ResponseMsgUtil.exception(e);
} }
} }
@RequestMapping(value = "/getRecordByCouponAgentId", method = RequestMethod.GET)
@RequestMapping(value = "/getCouponByRecord", method = RequestMethod.GET)
@ResponseBody @ResponseBody
@ApiOperation(value = "根据分发记录 查询卡券") @ApiOperation(value = "根据卡券与代理商关系 查询分发记录")
public ResponseData getCouponByRecord(@RequestParam(name = "recordId", required = true) Long recordId, public ResponseData getRecordByCouponAgentId(@RequestParam(name = "couponAgentId", required = true) Long couponAgentId,
@RequestParam(name = "pageNum", required = true) Integer pageNum, @RequestParam(name = "pageNum", required = true) Integer pageNum,
@RequestParam(name = "pageSize", required = true) Integer pageSize) { @RequestParam(name = "pageSize", required = true) Integer pageSize,
HttpServletRequest request) {
try { try {
Map<String,Object> map = new HashMap<>(); Map<String,Object> map = new HashMap<>();
map.put("recordId", recordId); map.put("couponAgentId", couponAgentId);
PageHelper.startPage(pageNum,pageSize); PageHelper.startPage(pageNum,pageSize);
return ResponseMsgUtil.success(new PageInfo<>(highCouponAgentService.getCouponAgentCodeList(map))); return ResponseMsgUtil.success(new PageInfo<>(highCouponAgentService.getRecordList(map)));
} catch (Exception e) { } catch (Exception e) {
log.error("HighCouponAgentController --> getCouponByRecord() error!", e); log.error("HighCouponAgentController --> getRecordByCouponAgentId() error!", e);
return ResponseMsgUtil.exception(e); return ResponseMsgUtil.exception(e);
} }
} }
} }

@ -127,4 +127,12 @@ public interface HighCouponAgentService {
*/ */
Map<String, Object> useConvertCode(String phone, String code) throws Exception; Map<String, Object> useConvertCode(String phone, String code) throws Exception;
/**
* 推送贵州中石化
* @param phone 手机号
* @param remark 备注
* @return
*/
Map<String, Object> pushGzSinopec(Long couponAgentRelId, String phone, String remark) throws Exception;
} }

@ -14,4 +14,11 @@ public interface HighCouponCodeOtherService {
*/ */
List<HighCouponCodeOther> getList(Map<String,Object> map); List<HighCouponCodeOther> getList(Map<String,Object> map);
/**
* 查询详情
* @param couponAgentCodeId
* @return
*/
HighCouponCodeOther getDetailByCouponAgentCodeId(Long couponAgentCodeId);
} }

@ -66,6 +66,9 @@ public class HighCouponAgentServiceImpl implements HighCouponAgentService {
@Resource @Resource
private HighCouponCodeOtherMapper highCouponCodeOtherMapper; private HighCouponCodeOtherMapper highCouponCodeOtherMapper;
@Resource
private HighCouponCodeOtherService couponCodeOtherService;
@Override @Override
@Transactional(propagation= Propagation.REQUIRES_NEW) @Transactional(propagation= Propagation.REQUIRES_NEW)
public void assignCouponAgent(HighCouponAgentRel highCouponAgentRel,Integer stockCount) { public void assignCouponAgent(HighCouponAgentRel highCouponAgentRel,Integer stockCount) {
@ -454,7 +457,7 @@ public class HighCouponAgentServiceImpl implements HighCouponAgentService {
Map<String,Object> push = new HashMap<>(); Map<String,Object> push = new HashMap<>();
push.put("token", token); push.put("token", token);
push.put("orderNo", coupon.getCouponKey()); push.put("orderNo", convertCode.getConvertCode());
push.put("couTypeCode", coupon.getCouponKey()); push.put("couTypeCode", coupon.getCouponKey());
push.put("distCouCount", 1); push.put("distCouCount", 1);
push.put("userPhone", phone); push.put("userPhone", phone);
@ -524,4 +527,93 @@ public class HighCouponAgentServiceImpl implements HighCouponAgentService {
return map; return map;
} }
@Override
public Map<String, Object> pushGzSinopec(Long couponAgentRelId, String phone, String remark) throws Exception {
// 查询兑换码
HighCouponAgentCode convertCode = getCodeById(couponAgentRelId);
if (convertCode == null) {
throw ErrorHelp.genException(SysCode.System, ErrorCode.COMMON_ERROR, "无效的数据");
}
if (convertCode.getStatus() == 3) {
throw ErrorHelp.genException(SysCode.System, ErrorCode.COMMON_ERROR, "卡券已被使用");
}
// 查询卡券
HighCoupon coupon = highCouponService.getCouponById(convertCode.getCouponId());
if (coupon == null) {
throw ErrorHelp.genException(SysCode.System, ErrorCode.COMMON_ERROR, "未知的卡券");
}
// 卡券来源:1.中石化 2.消费券 3.其他 4:贵州中石化
if (!coupon.getCouponSource().equals(4)) {
throw ErrorHelp.genException(SysCode.System, ErrorCode.COMMON_ERROR, "不是中石化卡券");
}
if (StringUtils.isBlank(phone)) {
throw ErrorHelp.genException(SysCode.System, ErrorCode.COMMON_ERROR, "需要填写手机手机号");
}
convertCode.setConvertUserPhone(phone);
convertCode.setRemark(remark);
convertCode.setCouponCode(System.currentTimeMillis()+"");
convertCode.setStatus(2);
highCouponAgentCodeMapper.updateByPrimaryKey(convertCode);
HighCouponAgentRel couponAgent = highCouponAgentRelMapper.selectByPrimaryKey(convertCode.getCouponAgentId());
couponAgent.setStockCount(couponAgent.getStockCount() - 1);
couponAgent.setSalesCount(couponAgent.getSalesCount() + 1);
highCouponAgentRelMapper.updateByPrimaryKey(couponAgent);
// 获取token
String token = huiLianTongConfig.getToken();
Map<String,Object> push = new HashMap<>();
push.put("token", token);
push.put("orderNo", convertCode.getConvertCode());
push.put("couTypeCode", coupon.getCouponKey());
push.put("distCouCount", 1);
push.put("userPhone", phone);
push.put("thirdUserId", phone);
// 推送给高速
JSONObject returnParam = HuiLianTongConfig.couJointDist(token,
MapUtils.getString(push, "orderNo"),
MapUtils.getString(push, "couTypeCode"),
MapUtils.getInteger(push, "distCouCount"),
MapUtils.getString(push, "userPhone"),
MapUtils.getString(push, "userPhone")
);
if (returnParam != null && returnParam.getString("result").equals("success")) {
JSONArray dataArray = returnParam.getJSONArray("data");
for (Object data : dataArray) {
JSONObject dataObject = (JSONObject) data;
HighCouponCodeOther couponCodeOther = new HighCouponCodeOther();
couponCodeOther.setType(1);
couponCodeOther.setCouponAgentCodeId(convertCode.getId());
couponCodeOther.setCouTypeCode(dataObject.getString("couTypeCode"));
couponCodeOther.setCouNo(dataObject.getString("couNo"));
couponCodeOther.setActiveTime(dataObject.getDate("activeTime"));
couponCodeOther.setValidStartDate(dataObject.getDate("validStartDate"));
couponCodeOther.setValidEndDate(dataObject.getDate("validEndDate"));
couponCodeOther.setStatus(20);
couponCodeOther.setCreateTime(new Date());
highCouponCodeOtherMapper.insert(couponCodeOther);
}
}
// 推送记录
HighGasOrderPush highGasOrderPush = new HighGasOrderPush();
highGasOrderPush.setType(OrderPushType.type6.getType());
highGasOrderPush.setOrderNo(convertCode.getCouponCode());
highGasOrderPush.setCreateTime(new Date());
highGasOrderPush.setCode(returnParam.getString("result"));
highGasOrderPush.setRequestContent(JSONObject.toJSONString(push));
highGasOrderPush.setReturnContent(returnParam.toJSONString());
highGasOrderPushMapper.insert(highGasOrderPush);
// 查询卡券销售码
Map<String, Object> map = new HashMap<>();
map.put("couponInfo", highCouponService.getCouponById(convertCode.getCouponId()));
map.put("couponCode", highCouponCodeService.getCouponCodeById(convertCode.getCouponCodeId()));
map.put("couponCodeOther", couponCodeOtherService.getDetailByCouponAgentCodeId(couponAgentRelId));
map.put("couponAgentCode", convertCode);
return map;
}
} }

@ -35,4 +35,15 @@ public class HighCouponCodeOtherServiceImpl implements HighCouponCodeOtherServic
} }
return highCouponCodeOtherMapper.selectByExample(example); return highCouponCodeOtherMapper.selectByExample(example);
} }
@Override
public HighCouponCodeOther getDetailByCouponAgentCodeId(Long couponAgentCodeId) {
HighCouponCodeOtherExample example = new HighCouponCodeOtherExample();
example.createCriteria().andCouponAgentCodeIdEqualTo(couponAgentCodeId);
List<HighCouponCodeOther> list = highCouponCodeOtherMapper.selectByExample(example);
if (list.size() > 0) {
return list.get(0);
}
return null;
}
} }

Loading…
Cancel
Save