| @@ -8,9 +8,11 @@ import com.iformall.common.ResultData; | |||||
| import com.iformall.controller.base.BaseController; | import com.iformall.controller.base.BaseController; | ||||
| import com.iformall.domain.po.WxCoupon; | import com.iformall.domain.po.WxCoupon; | ||||
| import com.iformall.domain.po.WxCouponChannel; | import com.iformall.domain.po.WxCouponChannel; | ||||
| import com.iformall.domain.po.WxCouponPassword; | |||||
| import com.iformall.domain.vo.WxCouponStatisVo; | import com.iformall.domain.vo.WxCouponStatisVo; | ||||
| import com.iformall.enums.*; | import com.iformall.enums.*; | ||||
| import com.iformall.mapper.WxCouponChannelMapper; | import com.iformall.mapper.WxCouponChannelMapper; | ||||
| import com.iformall.service.WxCouponPasswordService; | |||||
| import com.iformall.service.WxCouponService; | import com.iformall.service.WxCouponService; | ||||
| import com.iformall.service.WxFlowService; | import com.iformall.service.WxFlowService; | ||||
| import com.iformall.utils.DateUtils; | import com.iformall.utils.DateUtils; | ||||
| @@ -24,6 +26,9 @@ 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; | ||||
| import org.springframework.web.bind.annotation.*; | import org.springframework.web.bind.annotation.*; | ||||
| import javax.servlet.http.HttpServletRequest; | |||||
| import javax.servlet.http.HttpServletResponse; | |||||
| import java.util.*; | import java.util.*; | ||||
| @RestController | @RestController | ||||
| @@ -35,6 +40,8 @@ public class WxCouponController extends BaseController { | |||||
| @Autowired | @Autowired | ||||
| private WxCouponService wxCouponService; | private WxCouponService wxCouponService; | ||||
| @Autowired | @Autowired | ||||
| private WxCouponPasswordService couponPasswordService; | |||||
| @Autowired | |||||
| private WxCouponChannelMapper wxCouponChannelMapper; | private WxCouponChannelMapper wxCouponChannelMapper; | ||||
| @Autowired | @Autowired | ||||
| private WxFlowService wxFlowService; | private WxFlowService wxFlowService; | ||||
| @@ -79,6 +86,7 @@ public class WxCouponController extends BaseController { | |||||
| @SystemControllerLog(description = "券投放-新增") | @SystemControllerLog(description = "券投放-新增") | ||||
| public ResultData add(@RequestBody WxCoupon wxCoupon) { | public ResultData add(@RequestBody WxCoupon wxCoupon) { | ||||
| logger.debug("[" + getIpAddr() + "] WxCouponController::add"); | logger.debug("[" + getIpAddr() + "] WxCouponController::add"); | ||||
| wxCoupon.setTenantId(getTenantId()); | |||||
| ResultData resultData = wxCouponService.saveOrUpdate(wxCoupon); | ResultData resultData = wxCouponService.saveOrUpdate(wxCoupon); | ||||
| if(resultData.code != 200){ | if(resultData.code != 200){ | ||||
| @@ -257,7 +265,7 @@ public class WxCouponController extends BaseController { | |||||
| @ApiImplicitParam(name = "id", value = "id", dataType = "Long", paramType = "query", required = true) | @ApiImplicitParam(name = "id", value = "id", dataType = "Long", paramType = "query", required = true) | ||||
| @SystemControllerLog(description = "券投放-查询") | @SystemControllerLog(description = "券投放-查询") | ||||
| public ResultData findById(@RequestParam Long id) { | public ResultData findById(@RequestParam Long id) { | ||||
| logger.debug("[" + getIpAddr() + "] WxCouponController::findById");; | |||||
| logger.debug("[" + getIpAddr() + "] WxCouponController::findById"); | |||||
| return new ResultData(wxCouponService.getVoById(id)); | return new ResultData(wxCouponService.getVoById(id)); | ||||
| } | } | ||||
| @@ -334,4 +342,15 @@ public class WxCouponController extends BaseController { | |||||
| return new ResultData(pages); | return new ResultData(pages); | ||||
| } | } | ||||
| @GetMapping("exportCouponPassword") | |||||
| @SystemControllerLog(description = "卡券兑换码-导出数据") | |||||
| public void exportCouponPassword(@ModelAttribute WxCouponPassword wxCouponPassword, HttpServletRequest request, HttpServletResponse response) { | |||||
| wxCouponPassword.setTenantId(getTenantId()); | |||||
| wxCouponPassword.setExpireDate(new Date()); | |||||
| if (wxCouponPassword.getCouponId() == null) { | |||||
| wxCouponPassword.setCouponId(0L); | |||||
| } | |||||
| couponPasswordService.exportData(request, response, wxCouponPassword); | |||||
| } | |||||
| } | } | ||||
| @@ -0,0 +1,62 @@ | |||||
| package com.iformall.controller.market; | |||||
| import com.github.pagehelper.PageInfo; | |||||
| import com.iformall.annotation.SystemControllerLog; | |||||
| import com.iformall.common.Result; | |||||
| import com.iformall.common.ResultData; | |||||
| import com.iformall.controller.base.BaseController; | |||||
| import com.iformall.domain.po.BaseEntity; | |||||
| import com.iformall.domain.po.WxCouponPassword; | |||||
| import com.iformall.domain.vo.WxCouponPasswordCountInfoVO; | |||||
| import com.iformall.service.WxCouponPasswordService; | |||||
| import io.swagger.annotations.Api; | |||||
| import io.swagger.annotations.ApiImplicitParam; | |||||
| import io.swagger.annotations.ApiImplicitParams; | |||||
| import io.swagger.annotations.ApiOperation; | |||||
| import org.slf4j.Logger; | |||||
| import org.slf4j.LoggerFactory; | |||||
| import org.springframework.beans.factory.annotation.Autowired; | |||||
| import org.springframework.web.bind.annotation.GetMapping; | |||||
| import org.springframework.web.bind.annotation.ModelAttribute; | |||||
| import org.springframework.web.bind.annotation.RequestMapping; | |||||
| import org.springframework.web.bind.annotation.RestController; | |||||
| import java.util.List; | |||||
| /** | |||||
| * @author gongbiao | |||||
| */ | |||||
| @RestController | |||||
| @RequestMapping("couponPassword") | |||||
| @Api(description = "免费卡接口") | |||||
| public class WxCouponPasswordController extends BaseController { | |||||
| private final Logger logger = LoggerFactory.getLogger(this.getClass()); | |||||
| @Autowired | |||||
| private WxCouponPasswordService wxCouponPasswordService; | |||||
| @ApiOperation("分页列表接口") | |||||
| @GetMapping("/list") | |||||
| @ApiImplicitParams({ | |||||
| @ApiImplicitParam(name = "pageNum", value = "页数", dataType = "int", paramType = "query", required = true), | |||||
| @ApiImplicitParam(name = "pageSize", value = "每页条数", dataType = "int", paramType = "query", required = true)}) | |||||
| @SystemControllerLog(description = "列表") | |||||
| public ResultData list(@ModelAttribute WxCouponPassword wxCouponPassword, Integer pageNum, Integer pageSize) { | |||||
| logger.debug("[" + getIpAddr() + "] WxCouponPasswordController::list"); | |||||
| wxCouponPassword.setTenantId(getTenantId()); | |||||
| wxCouponPassword.setSortColumns(BaseEntity.SortField.CreateDate_DESC, BaseEntity.SortField.Id_DESC); | |||||
| final PageInfo<WxCouponPassword> page = wxCouponPasswordService.listAsPage(wxCouponPassword, pageNum, pageSize); | |||||
| return new ResultData(page); | |||||
| } | |||||
| @ApiOperation("可发送卡数据") | |||||
| @GetMapping("/findCouponList") | |||||
| @SystemControllerLog(description = "可发送卡数据") | |||||
| public ResultData findCouponList() { | |||||
| logger.debug("[" + getIpAddr() + "] WxCouponPasswordController::findCouponList"); | |||||
| List<WxCouponPasswordCountInfoVO> voList = wxCouponPasswordService.findCouponList(getTenantId()); | |||||
| return new ResultData(Result.SUCCESS, "查询成功", voList); | |||||
| } | |||||
| } | |||||
| @@ -0,0 +1,78 @@ | |||||
| package com.iformall.controller.market; | |||||
| import com.github.pagehelper.PageInfo; | |||||
| import com.iformall.annotation.SystemControllerLog; | |||||
| import com.iformall.common.ErrorCode; | |||||
| import com.iformall.common.ResultData; | |||||
| import com.iformall.controller.base.BaseController; | |||||
| import com.iformall.domain.po.BaseEntity; | |||||
| import com.iformall.domain.po.MallUserInfo; | |||||
| import com.iformall.domain.po.WxCouponPresent; | |||||
| import com.iformall.service.WxCouponPresentService; | |||||
| import io.swagger.annotations.Api; | |||||
| import io.swagger.annotations.ApiImplicitParam; | |||||
| import io.swagger.annotations.ApiImplicitParams; | |||||
| import io.swagger.annotations.ApiOperation; | |||||
| import org.slf4j.Logger; | |||||
| import org.slf4j.LoggerFactory; | |||||
| import org.springframework.beans.factory.annotation.Autowired; | |||||
| import org.springframework.web.bind.annotation.*; | |||||
| /** | |||||
| * @author gongbiao | |||||
| */ | |||||
| @RestController | |||||
| @RequestMapping("couponPresent") | |||||
| @Api(description = "卡投放接口") | |||||
| public class WxCouponPresentController extends BaseController { | |||||
| private final Logger logger = LoggerFactory.getLogger(this.getClass()); | |||||
| @Autowired | |||||
| private WxCouponPresentService wxCouponPresentService; | |||||
| @ApiOperation("分页列表接口") | |||||
| @GetMapping("/list") | |||||
| @ApiImplicitParams({ | |||||
| @ApiImplicitParam(name = "pageNum", value = "页数", dataType = "int", paramType = "query", required = true), | |||||
| @ApiImplicitParam(name = "pageSize", value = "每页条数", dataType = "int", paramType = "query", required = true)}) | |||||
| @SystemControllerLog(description = "列表") | |||||
| public ResultData list(@ModelAttribute WxCouponPresent wxCouponPresent, Integer pageNum, Integer pageSize) { | |||||
| logger.debug("[" + getIpAddr() + "] WxCouponPresentController::list"); | |||||
| wxCouponPresent.setTenantId(getTenantId()); | |||||
| wxCouponPresent.setSortColumns(BaseEntity.SortField.CreateTime_DESC, BaseEntity.SortField.Id_DESC); | |||||
| final PageInfo<WxCouponPresent> page = wxCouponPresentService.listAsPage(wxCouponPresent, pageNum, pageSize); | |||||
| return new ResultData(page); | |||||
| } | |||||
| @ApiOperation("根据id查询接口") | |||||
| @GetMapping("/findById") | |||||
| @ApiImplicitParam(name = "id", value = "id", dataType = "Long", paramType = "query", required = true) | |||||
| @SystemControllerLog(description = "查询") | |||||
| public ResultData findById(@RequestParam Long id) { | |||||
| logger.debug("[" + getIpAddr() + "] WxCouponPresentController::findById"); | |||||
| return new ResultData(wxCouponPresentService.findById(id)); | |||||
| } | |||||
| @ApiOperation("新增接口") | |||||
| @PostMapping("add") | |||||
| @SystemControllerLog(description = "新增") | |||||
| public ResultData add(@RequestBody WxCouponPresent wxCouponPresent) { | |||||
| logger.debug("[" + getIpAddr() + "] WxCouponInjectController::add"); | |||||
| if (wxCouponPresent.getCouponId() == null) { | |||||
| return new ResultData(ErrorCode.SYS_PARAMETER_ERROR.getCode(), "请选择卡"); | |||||
| } | |||||
| if (wxCouponPresent.getPhones().isEmpty()) { | |||||
| return new ResultData(ErrorCode.SYS_PARAMETER_ERROR.getCode(), "请填写手机号"); | |||||
| } | |||||
| MallUserInfo user = getUser(); | |||||
| wxCouponPresent.setTenantId(user.getTenantId()); | |||||
| wxCouponPresent.setUserId(user.getId()); | |||||
| return wxCouponPresentService.add(wxCouponPresent); | |||||
| } | |||||
| } | |||||
| @@ -164,7 +164,7 @@ public class WxOrderController extends BaseController { | |||||
| if (!wxOrderService.checkCouponIsFree(coupon)) | if (!wxOrderService.checkCouponIsFree(coupon)) | ||||
| return new ResultData(ErrorCode.COUPON_IS_NOT_FREE); | return new ResultData(ErrorCode.COUPON_IS_NOT_FREE); | ||||
| // 免费券 | // 免费券 | ||||
| order = wxOrderService.saveFreeOrderForCoupon(user, coupon, orderSaveDto.getCouponChannelId(), orderSaveDto.getFormId()); | |||||
| order = wxOrderService.saveFreeOrderForCoupon(user, coupon, orderSaveDto.getCouponChannelId(), orderSaveDto.getFormId(), null); | |||||
| return new ResultData(order); | return new ResultData(order); | ||||
| } catch (MallinkException e) { | } catch (MallinkException e) { | ||||
| logger.error(e.getMessage()); | logger.error(e.getMessage()); | ||||
| @@ -0,0 +1,2 @@ | |||||
| alter table wx_coupon_present | |||||
| add column send_amount int(11) default 0 not null comment '发送数量'; | |||||
| @@ -0,0 +1,2 @@ | |||||
| alter table wx_msg_callback | |||||
| add column business_id bigint(20) default 0 not null comment '业务ID'; | |||||
| @@ -0,0 +1,95 @@ | |||||
| package com.iformall.controller; | |||||
| import com.iformall.common.ErrorCode; | |||||
| import com.iformall.common.ResultData; | |||||
| import com.iformall.domain.po.*; | |||||
| import com.iformall.enums.*; | |||||
| import com.iformall.exception.MallinkException; | |||||
| import com.iformall.service.*; | |||||
| import com.iformall.utils.Constant; | |||||
| import io.swagger.annotations.Api; | |||||
| import io.swagger.annotations.ApiOperation; | |||||
| import org.apache.commons.lang3.StringUtils; | |||||
| import org.slf4j.Logger; | |||||
| import org.slf4j.LoggerFactory; | |||||
| import org.springframework.beans.factory.annotation.Autowired; | |||||
| import org.springframework.web.bind.annotation.*; | |||||
| import java.util.Date; | |||||
| import java.util.Map; | |||||
| @RestController | |||||
| @RequestMapping("/api/couponPassword") | |||||
| @Api(description = "卡密相关接口") | |||||
| public class WxCouponPasswordController extends BaseController { | |||||
| private final Logger logger = LoggerFactory.getLogger(this.getClass()); | |||||
| @Autowired | |||||
| private WxCouponPasswordService couponPasswordService; | |||||
| @Autowired | |||||
| private WxCouponService couponService; | |||||
| @Autowired | |||||
| private WxOrderService orderService; | |||||
| @ApiOperation(value = "根据卡密领卡", notes = "{\"password\":\"String\",\"formId\":\"String\"}") | |||||
| @PostMapping("getCouponOrderByPassword") | |||||
| public ResultData getCouponOrderByPassword(@RequestBody Map<String, String> params) { | |||||
| logger.info("getCouponOrderByPassword: " + getIpAddr() + params.toString()); | |||||
| String password = params.get("password"); | |||||
| String formId = params.get("formId"); | |||||
| if (StringUtils.isBlank(password) || password.equalsIgnoreCase(Constant.UNDEFINED)) { | |||||
| return new ResultData(ErrorCode.SYS_PARAMETER_NOT_NULL.getCode(), "password不能为空"); | |||||
| } | |||||
| // 1. 根据password获取领取的couponId | |||||
| WxCouponPassword couponPasswordQ = new WxCouponPassword(); | |||||
| couponPasswordQ.setTenantId(getTenantId()); | |||||
| couponPasswordQ.setPassword(password); | |||||
| couponPasswordQ.setExpireDate(new Date()); | |||||
| WxCouponPassword couponPassword = null; | |||||
| try { | |||||
| couponPassword = couponPasswordService.getByObj(couponPasswordQ); | |||||
| } catch (MallinkException e) { | |||||
| logger.error(e.getMessage()); | |||||
| return new ResultData(e.getErrorCode(), e.getMessage()); | |||||
| } catch (Exception e) { | |||||
| logger.error(e.getMessage()); | |||||
| return new ResultData(500, e.getMessage()); | |||||
| } | |||||
| WxCUser cuUser = getUser(); | |||||
| WxCoupon coupon = couponService.getById(couponPassword.getCouponId()); | |||||
| if (coupon == null) { | |||||
| return new ResultData(ErrorCode.COUPON_IS_EMPTY); | |||||
| } | |||||
| if (coupon.getStatus().equals(EnumCouponStatus.COUPON_STATUS_TAKE_OFFF.getCode())) { | |||||
| logger.error("此券已作废:" + coupon.getId()); | |||||
| return new ResultData(ErrorCode.COUPON_IS_TAKE_OFF); | |||||
| } | |||||
| // 2. 设置已使用 | |||||
| try { | |||||
| WxCouponPassword updateCouponPwd = new WxCouponPassword(); | |||||
| updateCouponPwd.setId(couponPassword.getId()); | |||||
| updateCouponPwd.setStatus(EnumCouponPasswordStatus.USED.getCode()); | |||||
| couponPassword.setStatus(EnumCouponPasswordStatus.USED.getCode()); | |||||
| couponPasswordService.saveOrUpdate(updateCouponPwd); | |||||
| } catch (Exception e) { | |||||
| logger.error(e.getMessage()); | |||||
| return new ResultData(ErrorCode.DB_FAIL); | |||||
| } | |||||
| // 3. 领取free coupon | |||||
| try { | |||||
| WxOrder order = orderService.saveFreeOrderForCoupon(cuUser, coupon, null, formId, couponPassword.getId()); | |||||
| } catch (MallinkException e) { | |||||
| logger.error(e.getMessage()); | |||||
| return new ResultData(e.getErrorCode(), e.getMessage()); | |||||
| } catch (Exception e) { | |||||
| logger.error(e.getMessage()); | |||||
| return new ResultData(500, e.getMessage()); | |||||
| } | |||||
| return new ResultData(); | |||||
| } | |||||
| } | |||||
| @@ -83,6 +83,9 @@ public class WxOrderController extends BaseController { | |||||
| if (coupon == null) { | if (coupon == null) { | ||||
| return new ResultData(ErrorCode.COUPON_IS_EMPTY); | return new ResultData(ErrorCode.COUPON_IS_EMPTY); | ||||
| } | } | ||||
| if (coupon.getStatus().equals(EnumCouponStatus.COUPON_STATUS_TAKE_OFFF.getCode())) { | |||||
| return new ResultData(ErrorCode.COUPON_IS_TAKE_OFF); | |||||
| } | |||||
| WxOrder order = wxOrderService.saveOrderForCoupon(user, coupon, orderSaveDto, isPress); | WxOrder order = wxOrderService.saveOrderForCoupon(user, coupon, orderSaveDto, isPress); | ||||
| return new ResultData(order); | return new ResultData(order); | ||||
| } catch (MallinkException e) { | } catch (MallinkException e) { | ||||
| @@ -12,7 +12,7 @@ import com.iformall.enums.EnumCouponSendSendType; | |||||
| import com.iformall.enums.EnumETCPCode; | import com.iformall.enums.EnumETCPCode; | ||||
| import com.iformall.service.*; | import com.iformall.service.*; | ||||
| import com.iformall.utils.DateUtils; | import com.iformall.utils.DateUtils; | ||||
| import com.iformall.utils.car.ETCPUtil; | |||||
| import com.iformall.utils.car.TJDCarUtil; | |||||
| import org.apache.commons.collections.CollectionUtils; | import org.apache.commons.collections.CollectionUtils; | ||||
| import org.apache.commons.lang3.StringUtils; | import org.apache.commons.lang3.StringUtils; | ||||
| import org.slf4j.Logger; | import org.slf4j.Logger; | ||||
| @@ -139,7 +139,7 @@ public class WxCarTJDCallBackController extends BaseController { | |||||
| WxCarCmdLog wxCarCmdLog = new WxCarCmdLog(); | WxCarCmdLog wxCarCmdLog = new WxCarCmdLog(); | ||||
| wxCarCmdLog.setTenantId(park.getTenantId()); | wxCarCmdLog.setTenantId(park.getTenantId()); | ||||
| wxCarCmdLog.setVendorType(EnumCarVendor.CAR_TJD.getCode()); | wxCarCmdLog.setVendorType(EnumCarVendor.CAR_TJD.getCode()); | ||||
| wxCarCmdLog.setCmdType(EnumCarCmd.CAR_ETCP_CALLBACK_PARK_IN.getCode()); | |||||
| wxCarCmdLog.setCmdType(EnumCarCmd.CAR_TJD_CALLBACK_PARK_IN.getCode()); | |||||
| wxCarCmdLog.setCmdJson(JSON.toJSONString(paramMap)); | wxCarCmdLog.setCmdJson(JSON.toJSONString(paramMap)); | ||||
| wxCarCmdLog.setCreateDate(currentDate); | wxCarCmdLog.setCreateDate(currentDate); | ||||
| wxCarCmdLog.setUpdateDate(currentDate); | wxCarCmdLog.setUpdateDate(currentDate); | ||||
| @@ -185,7 +185,7 @@ public class WxCarTJDCallBackController extends BaseController { | |||||
| Date currentDate = new Date(); | Date currentDate = new Date(); | ||||
| WxCarCmdLog wxCarCmdLog = new WxCarCmdLog(); | WxCarCmdLog wxCarCmdLog = new WxCarCmdLog(); | ||||
| wxCarCmdLog.setVendorType(EnumCarVendor.CAR_TJD.getCode()); | wxCarCmdLog.setVendorType(EnumCarVendor.CAR_TJD.getCode()); | ||||
| wxCarCmdLog.setCmdType(EnumCarCmd.CAR_ETCP_CALLBACK_PARK_OUT.getCode()); | |||||
| wxCarCmdLog.setCmdType(EnumCarCmd.CAR_TJD_CALLBACK_PARK_OUT.getCode()); | |||||
| wxCarCmdLog.setCmdJson(JSON.toJSONString(paramMap)); | wxCarCmdLog.setCmdJson(JSON.toJSONString(paramMap)); | ||||
| wxCarCmdLog.setCreateDate(currentDate); | wxCarCmdLog.setCreateDate(currentDate); | ||||
| wxCarCmdLog.setUpdateDate(currentDate); | wxCarCmdLog.setUpdateDate(currentDate); | ||||
| @@ -219,8 +219,12 @@ public enum ErrorCode{ | |||||
| COUPON_PRESS_IS_OVERTIME(9071, "砍价已超时"), | COUPON_PRESS_IS_OVERTIME(9071, "砍价已超时"), | ||||
| COUPON_PRESS_IS_EXIST(9072, "此人已参与此次砍价"), | COUPON_PRESS_IS_EXIST(9072, "此人已参与此次砍价"), | ||||
| /** | |||||
| * 卡密 | |||||
| */ | |||||
| COUPON_PASSWORD_NOT_FOUND(9501, "兑换码未找到"), | |||||
| COUPON_PASSWORD_HAD_USED(9502, "兑换码已失效"), | |||||
| COUPON_PASSWORD_IS_CANCELED(9503, "兑换码已失效"), | |||||
| /** | /** | ||||
| * 微信 | * 微信 | ||||
| @@ -139,6 +139,9 @@ public class WxCoupon extends BaseEntity { | |||||
| @io.swagger.annotations.ApiModelProperty(value="最后一次审批操作类型,取值同EnumFlowKey",name="approvalType") | @io.swagger.annotations.ApiModelProperty(value="最后一次审批操作类型,取值同EnumFlowKey",name="approvalType") | ||||
| private Integer approvalType; | private Integer approvalType; | ||||
| @io.swagger.annotations.ApiModelProperty(value="卡密是否支持(0:不支持,1支持)",name="passwordSupport") | |||||
| private Integer passwordSupport; | |||||
| @TableField(exist = false) | @TableField(exist = false) | ||||
| private String merchantParams; | private String merchantParams; | ||||
| @@ -0,0 +1,43 @@ | |||||
| package com.iformall.domain.po; | |||||
| import cn.afterturn.easypoi.excel.annotation.Excel; | |||||
| import com.baomidou.mybatisplus.annotation.TableField; | |||||
| import com.baomidou.mybatisplus.annotation.TableName; | |||||
| import lombok.Data; | |||||
| import lombok.EqualsAndHashCode; | |||||
| import java.util.Date; | |||||
| @TableName(value = "wx_coupon_password") | |||||
| @Data | |||||
| @EqualsAndHashCode(callSuper = true) | |||||
| public class WxCouponPassword extends BaseEntity { | |||||
| protected Long id; | |||||
| @io.swagger.annotations.ApiModelProperty(value="租户ID",name="tenantId") | |||||
| private String tenantId; | |||||
| @io.swagger.annotations.ApiModelProperty(value="卡券ID",name="couponId") | |||||
| private Long couponId; | |||||
| @io.swagger.annotations.ApiModelProperty(value="卡券短ID",name="couponShort") | |||||
| private String couponShort; | |||||
| @Excel(name = "兑换码", width = 20, orderNum = "1") | |||||
| @io.swagger.annotations.ApiModelProperty(value="商户名称",name="password") | |||||
| private String password; | |||||
| @io.swagger.annotations.ApiModelProperty(value="卡密状态: 0初始1信息发出中2信息已发出3已使用",name="status") | |||||
| private Integer status; | |||||
| @io.swagger.annotations.ApiModelProperty(value="卡密发送到手机",name="sendedPhone") | |||||
| private String sendedPhone; | |||||
| @io.swagger.annotations.ApiModelProperty(value="卡包ID(coupon_order_id/card_id)",name="cardId") | |||||
| private Long cardId; | |||||
| @io.swagger.annotations.ApiModelProperty(value="创建时间",name="createDate") | |||||
| private Date createDate; | |||||
| @io.swagger.annotations.ApiModelProperty(value="更新时间",name="updateDate") | |||||
| private Date updateDate; | |||||
| @io.swagger.annotations.ApiModelProperty(value="过期时间",name="expireDate") | |||||
| private Date expireDate; | |||||
| @TableField(exist = false) | |||||
| private String statusStr; | |||||
| } | |||||
| @@ -0,0 +1,41 @@ | |||||
| package com.iformall.domain.po; | |||||
| import com.baomidou.mybatisplus.annotation.TableField; | |||||
| import com.baomidou.mybatisplus.annotation.TableName; | |||||
| import io.swagger.annotations.ApiModelProperty; | |||||
| import lombok.Data; | |||||
| import lombok.EqualsAndHashCode; | |||||
| import java.util.Date; | |||||
| @TableName(value = "wx_coupon_present") | |||||
| @Data | |||||
| @EqualsAndHashCode(callSuper = true) | |||||
| public class WxCouponPresent extends BaseEntity { | |||||
| protected Long id; | |||||
| @ApiModelProperty(value = "租户ID", name = "tenantId") | |||||
| private String tenantId; | |||||
| @ApiModelProperty(value = "用户ID", name = "userId") | |||||
| private Long userId; | |||||
| @ApiModelProperty(value = "卡券ID", name = "couponId") | |||||
| private Long couponId; | |||||
| @ApiModelProperty(value = "卡券名称", name = "couponName") | |||||
| private String couponName; | |||||
| @ApiModelProperty(value = "手机", name = "phones") | |||||
| private String phones; | |||||
| @ApiModelProperty(value = "创建时间", name = "createDate") | |||||
| private Date createTime; | |||||
| @ApiModelProperty(value = "更新时间", name = "updateDate") | |||||
| private Date updateTime; | |||||
| @ApiModelProperty(value = "发送数量", name = "sendAmount") | |||||
| private Integer sendAmount; | |||||
| @TableField(exist = false) | |||||
| protected Date sendTimeStart; | |||||
| @TableField(exist = false) | |||||
| protected Date sendTimeEnd; | |||||
| } | |||||
| @@ -46,4 +46,7 @@ public class WxMsgCallback extends BaseEntity { | |||||
| @io.swagger.annotations.ApiModelProperty(value="msgId",name="msgId") | @io.swagger.annotations.ApiModelProperty(value="msgId",name="msgId") | ||||
| private Long msgId; | private Long msgId; | ||||
| @io.swagger.annotations.ApiModelProperty(value = "业务ID", name = "businessId") | |||||
| private Long businessId; | |||||
| } | } | ||||
| @@ -0,0 +1,14 @@ | |||||
| package com.iformall.domain.vo; | |||||
| import lombok.Data; | |||||
| /** | |||||
| * @author gongbiao | |||||
| */ | |||||
| @Data | |||||
| public class WxCouponPasswordCountInfoVO { | |||||
| private Long couponId; | |||||
| private String couponName; | |||||
| private Long couponCount; | |||||
| } | |||||
| @@ -3,16 +3,17 @@ package com.iformall.enums; | |||||
| /** | /** | ||||
| * Created by Stormeye on 2019/09/17. | * Created by Stormeye on 2019/09/17. | ||||
| */ | */ | ||||
| public enum EnumCardPasswordStatus { | |||||
| public enum EnumCouponPasswordStatus { | |||||
| INIT(0, "初始"), | INIT(0, "初始"), | ||||
| MSG_SENDING(1, "消息发送中"), | MSG_SENDING(1, "消息发送中"), | ||||
| MSG_SENDED(2, "消息已发送"), | MSG_SENDED(2, "消息已发送"), | ||||
| USED(3, "已使用"); | |||||
| USED(3, "已使用"), | |||||
| CANCEL(4, "已作废"); | |||||
| public static EnumCardPasswordStatus getEnum(Integer code) { | |||||
| for (EnumCardPasswordStatus value : values()) { | |||||
| public static EnumCouponPasswordStatus getEnum(Integer code) { | |||||
| for (EnumCouponPasswordStatus value : values()) { | |||||
| if (value.getCode().equals(code)) { | if (value.getCode().equals(code)) { | ||||
| return value; | return value; | ||||
| } | } | ||||
| @@ -23,7 +24,7 @@ public enum EnumCardPasswordStatus { | |||||
| private Integer code; | private Integer code; | ||||
| private String message; | private String message; | ||||
| EnumCardPasswordStatus(Integer code, String message) { | |||||
| EnumCouponPasswordStatus(Integer code, String message) { | |||||
| this.code = code; | this.code = code; | ||||
| this.message = message; | this.message = message; | ||||
| } | } | ||||
| @@ -0,0 +1,36 @@ | |||||
| package com.iformall.enums; | |||||
| /** | |||||
| * Created by Stormeye on 2018/08/09. | |||||
| */ | |||||
| public enum EnumCouponPasswordSupport { | |||||
| NOT_SUPPORT(0, "不支持"), | |||||
| SUPPORTED(1, "支持"), | |||||
| ; | |||||
| public static EnumCouponPasswordSupport getEnum(Integer code) { | |||||
| for (EnumCouponPasswordSupport value : values()) { | |||||
| if (value.getCode().equals(code)) { | |||||
| return value; | |||||
| } | |||||
| } | |||||
| return null; | |||||
| } | |||||
| private Integer code; | |||||
| private String message; | |||||
| EnumCouponPasswordSupport(Integer code, String message) { | |||||
| this.code = code; | |||||
| this.message = message; | |||||
| } | |||||
| public Integer getCode() { | |||||
| return code; | |||||
| } | |||||
| public String getMessage() { | |||||
| return message; | |||||
| } | |||||
| } | |||||
| @@ -34,6 +34,8 @@ public enum EnumMsgModel { | |||||
| //会员生日券 | //会员生日券 | ||||
| COUPON_BIRTHDAY_OPENED(28, "会员生日券倍率开启"), | COUPON_BIRTHDAY_OPENED(28, "会员生日券倍率开启"), | ||||
| COUPON_BIRTHDAY_OPENED_NO(29, "会员生日券倍率未开启"), | COUPON_BIRTHDAY_OPENED_NO(29, "会员生日券倍率未开启"), | ||||
| COUPON_CARD_SEND(30, "系统发卡"), | |||||
| ; | ; | ||||
| public static EnumMsgModel getEnum(Integer code) { | public static EnumMsgModel getEnum(Integer code) { | ||||
| @@ -44,5 +44,11 @@ public interface WxCUserBasicInfoMapper extends CommonMapper<WxCUserBasicInfo, S | |||||
| long findImportUserCount(WxCUserBasicInfoDto dto); | long findImportUserCount(WxCUserBasicInfoDto dto); | ||||
| void incActRecordById(Long id); | void incActRecordById(Long id); | ||||
| /** | |||||
| * 查找wx_c_user中不存在的用户 | |||||
| * @return | |||||
| */ | |||||
| List<WxCUserBasicInfo> selectNotCUserList(); | |||||
| } | } | ||||
| @@ -0,0 +1,23 @@ | |||||
| package com.iformall.mapper; | |||||
| import com.iformall.common.CommonMapper; | |||||
| import com.iformall.domain.po.WxCouponPassword; | |||||
| import com.iformall.domain.vo.WxCouponPasswordCountInfoVO; | |||||
| import java.util.List; | |||||
| public interface WxCouponPasswordMapper extends CommonMapper<WxCouponPassword, Long> { | |||||
| List<WxCouponPassword> findList(WxCouponPassword wxCouponPassword); | |||||
| List<WxCouponPassword> findAvaPasswordListByCouponId(WxCouponPassword wxCouponPassword); | |||||
| void insertCouponPasswds(List<WxCouponPassword> pwdlist); | |||||
| int updateStatusByCouponId(Long couponId); | |||||
| List<WxCouponPassword> findCouponGroupList(WxCouponPassword wxCouponPassword); | |||||
| List<WxCouponPasswordCountInfoVO> findCouponCountInfo(WxCouponPassword wxCouponPassword); | |||||
| void updateStatus(List<WxCouponPassword> tempList); | |||||
| } | |||||
| @@ -0,0 +1,13 @@ | |||||
| package com.iformall.mapper; | |||||
| import com.iformall.common.CommonMapper; | |||||
| import com.iformall.domain.po.WxCouponPassword; | |||||
| import com.iformall.domain.po.WxCouponPresent; | |||||
| import java.util.List; | |||||
| public interface WxCouponPresentMapper extends CommonMapper<WxCouponPresent, Long> { | |||||
| List<WxCouponPresent> findList(WxCouponPresent wxCouponPresent); | |||||
| } | |||||
| @@ -4,6 +4,7 @@ import com.iformall.common.CommonMapper; | |||||
| import com.iformall.domain.po.WxCreditHistory; | import com.iformall.domain.po.WxCreditHistory; | ||||
| import com.iformall.domain.vo.WxCreditHistoryNewIdVo; | import com.iformall.domain.vo.WxCreditHistoryNewIdVo; | ||||
| import com.iformall.domain.vo.WxCreditHistoryVo; | import com.iformall.domain.vo.WxCreditHistoryVo; | ||||
| import org.apache.ibatis.annotations.Param; | |||||
| import java.util.Date; | import java.util.Date; | ||||
| import java.util.List; | import java.util.List; | ||||
| @@ -31,4 +32,6 @@ public interface WxCreditHistoryMapper extends CommonMapper<WxCreditHistory, Lon | |||||
| long getPeopleCount(WxCreditHistory wxCreditHistory); | long getPeopleCount(WxCreditHistory wxCreditHistory); | ||||
| List<WxCreditHistory> findListAfter(Integer creditType, String dateTime); | List<WxCreditHistory> findListAfter(Integer creditType, String dateTime); | ||||
| List<WxCreditHistory> findListByIds(@Param("userIds") List<Long> userIds); | |||||
| } | } | ||||
| @@ -0,0 +1,72 @@ | |||||
| package com.iformall.service; | |||||
| import com.github.pagehelper.PageInfo; | |||||
| import com.iformall.domain.po.WxCouponPassword; | |||||
| import com.iformall.domain.vo.WxCouponPasswordCountInfoVO; | |||||
| import javax.servlet.http.HttpServletRequest; | |||||
| import javax.servlet.http.HttpServletResponse; | |||||
| import java.util.List; | |||||
| public interface WxCouponPasswordService { | |||||
| /** | |||||
| * 根据实体查询分页列表 | |||||
| * | |||||
| * @param record | |||||
| * @param pageIndex | |||||
| * @param pageSize | |||||
| * @return | |||||
| */ | |||||
| PageInfo<WxCouponPassword> listAsPage(WxCouponPassword record, Integer pageIndex, Integer pageSize); | |||||
| /** | |||||
| * 根据Id获得实体 | |||||
| * | |||||
| * @param id | |||||
| * @return | |||||
| */ | |||||
| WxCouponPassword getById(Long id); | |||||
| /** | |||||
| * 根据密码获取卡密信息 | |||||
| * | |||||
| * @param obj | |||||
| * @return | |||||
| */ | |||||
| WxCouponPassword getByObj(WxCouponPassword obj); | |||||
| /** | |||||
| * 保存或更新实体 | |||||
| * | |||||
| * @param record | |||||
| */ | |||||
| void saveOrUpdate(WxCouponPassword record); | |||||
| /** | |||||
| * 根据Id删除实体 | |||||
| * | |||||
| * @param id | |||||
| */ | |||||
| void deleteById(Long id); | |||||
| /** | |||||
| * 生产卡密 | |||||
| * @param tenantId | |||||
| * @param couponId | |||||
| * @param inventory | |||||
| */ | |||||
| void mkPasswords(String tenantId, Long couponId, Integer inventory); | |||||
| List<WxCouponPasswordCountInfoVO> findCouponList(String tenantId); | |||||
| /** | |||||
| * 导出兑换码 | |||||
| * @param request | |||||
| * @param response | |||||
| * @param couponPassword | |||||
| */ | |||||
| void exportData(HttpServletRequest request, HttpServletResponse response, WxCouponPassword couponPassword); | |||||
| } | |||||
| @@ -0,0 +1,19 @@ | |||||
| package com.iformall.service; | |||||
| import com.github.pagehelper.PageInfo; | |||||
| import com.iformall.common.ResultData; | |||||
| import com.iformall.domain.po.WxCouponPresent; | |||||
| /** | |||||
| * @author gongbiao | |||||
| */ | |||||
| public interface WxCouponPresentService { | |||||
| PageInfo<WxCouponPresent> listAsPage(WxCouponPresent wxCouponPresent, Integer pageNum, Integer pageSize); | |||||
| WxCouponPresent findById(Long id); | |||||
| ResultData add(WxCouponPresent wxCouponPresent); | |||||
| } | |||||
| @@ -4,8 +4,6 @@ import com.github.pagehelper.PageInfo; | |||||
| import com.iformall.common.ResultData; | import com.iformall.common.ResultData; | ||||
| import com.iformall.domain.po.WxMsgValidationcode; | import com.iformall.domain.po.WxMsgValidationcode; | ||||
| import java.util.Map; | |||||
| public interface WxMsgValidationcodeService { | public interface WxMsgValidationcodeService { | ||||
| /** | /** | ||||
| * 根据实体查询分页列表 | * 根据实体查询分页列表 | ||||
| @@ -44,6 +42,6 @@ public interface WxMsgValidationcodeService { | |||||
| ResultData hasvalidationcode(WxMsgValidationcode record); | ResultData hasvalidationcode(WxMsgValidationcode record); | ||||
| void addMsgCallback(WxMsgValidationcode wxmsg, String batchNo); | |||||
| void addMsgCallback(WxMsgValidationcode wxmsg, String batchNo, String id); | |||||
| } | } | ||||
| @@ -176,7 +176,7 @@ public interface WxOrderService { | |||||
| boolean checkCouponIsFree(WxCoupon coupon); | boolean checkCouponIsFree(WxCoupon coupon); | ||||
| // 2. 创建免费订单, 领取 couponOrder | // 2. 创建免费订单, 领取 couponOrder | ||||
| WxOrder saveFreeOrderForCoupon(WxCUser user, WxCoupon coupon, Long couponChannelId, String formId); | |||||
| WxOrder saveFreeOrderForCoupon(WxCUser user, WxCoupon coupon, Long couponChannelId, String formId, Long couponPasswordId); | |||||
| // 3. 创建有价订单 | // 3. 创建有价订单 | ||||
| WxOrder saveNoFreeOrderForCoupon(WxCUser user, WxCoupon coupon, Long couponChannelId, boolean isPress, Long orderGroupId, String formId); | WxOrder saveNoFreeOrderForCoupon(WxCUser user, WxCoupon coupon, Long couponChannelId, boolean isPress, Long orderGroupId, String formId); | ||||
| @@ -0,0 +1,178 @@ | |||||
| package com.iformall.service.impl; | |||||
| import com.github.pagehelper.PageHelper; | |||||
| import com.github.pagehelper.PageInfo; | |||||
| import com.iformall.common.IdWorker; | |||||
| import com.iformall.domain.po.WxCouponPassword; | |||||
| import com.iformall.enums.EnumCouponPasswordStatus; | |||||
| import com.iformall.domain.vo.WxCouponPasswordCountInfoVO; | |||||
| import com.iformall.common.ErrorCode; | |||||
| import com.iformall.exception.MallinkException; | |||||
| import com.iformall.mapper.WxCouponPasswordMapper; | |||||
| import com.iformall.service.ExcelService; | |||||
| import com.iformall.service.WxCouponPasswordService; | |||||
| import org.slf4j.Logger; | |||||
| import org.slf4j.LoggerFactory; | |||||
| import org.springframework.beans.factory.annotation.Autowired; | |||||
| import org.springframework.stereotype.Service; | |||||
| import javax.servlet.http.HttpServletRequest; | |||||
| import javax.servlet.http.HttpServletResponse; | |||||
| import java.util.ArrayList; | |||||
| import java.util.Date; | |||||
| import java.util.List; | |||||
| import java.util.Random; | |||||
| @Service | |||||
| public class WxCouponPasswordServiceImpl implements WxCouponPasswordService { | |||||
| private final Logger logger = LoggerFactory.getLogger(this.getClass()); | |||||
| @Autowired | |||||
| WxCouponPasswordMapper wxCouponPasswordMapper; | |||||
| @Autowired | |||||
| ExcelService excelService; | |||||
| @Override | |||||
| public PageInfo<WxCouponPassword> listAsPage(WxCouponPassword record, Integer pageIndex, Integer pageSize) { | |||||
| return PageHelper.startPage(pageIndex, pageSize).doSelectPageInfo(() -> wxCouponPasswordMapper.findList(record)); | |||||
| } | |||||
| @Override | |||||
| public WxCouponPassword getById(Long id) { | |||||
| return wxCouponPasswordMapper.selectById(id); | |||||
| } | |||||
| @Override | |||||
| public WxCouponPassword getByObj(WxCouponPassword obj) { | |||||
| List<WxCouponPassword> pwdList = wxCouponPasswordMapper.findList(obj); | |||||
| if (pwdList.size() <= 0) { | |||||
| throw new MallinkException(ErrorCode.COUPON_PASSWORD_NOT_FOUND); | |||||
| } | |||||
| WxCouponPassword password = null; | |||||
| Integer errCode = EnumCouponPasswordStatus.INIT.getCode(); | |||||
| for( WxCouponPassword pwd: pwdList) { | |||||
| if (pwd.getStatus().equals(EnumCouponPasswordStatus.USED.getCode())) { | |||||
| errCode = EnumCouponPasswordStatus.USED.getCode(); | |||||
| continue; | |||||
| } | |||||
| if (!pwd.getStatus().equals(EnumCouponPasswordStatus.USED.getCode()) && | |||||
| !pwd.getStatus().equals(EnumCouponPasswordStatus.CANCEL.getCode())) { | |||||
| password = pwd; | |||||
| } | |||||
| } | |||||
| if (password == null) { | |||||
| if (errCode.equals(EnumCouponPasswordStatus.USED.getCode())) { | |||||
| logger.error("卡券已使用"); | |||||
| throw new MallinkException(ErrorCode.COUPON_PASSWORD_HAD_USED); | |||||
| } else { | |||||
| logger.error("卡券已过期或已作废"); | |||||
| throw new MallinkException(ErrorCode.COUPON_PASSWORD_IS_CANCELED); | |||||
| } | |||||
| } | |||||
| return password; | |||||
| } | |||||
| @Override | |||||
| public void saveOrUpdate(WxCouponPassword record) { | |||||
| if (record.getId() == null) { | |||||
| //record.setId(UUID.randomUUID().toString().replaceAll("-", "")); | |||||
| final IdWorker idWorker = IdWorker.get(); | |||||
| record.setId(idWorker.nextId()); | |||||
| wxCouponPasswordMapper.insert(record); | |||||
| } else { | |||||
| wxCouponPasswordMapper.updateById(record); | |||||
| } | |||||
| } | |||||
| @Override | |||||
| public void deleteById(Long id) { | |||||
| wxCouponPasswordMapper.deleteById(id); | |||||
| } | |||||
| @Override | |||||
| public List<WxCouponPasswordCountInfoVO> findCouponList(String tenantId) { | |||||
| WxCouponPassword wxCouponPassword = new WxCouponPassword(); | |||||
| wxCouponPassword.setTenantId(tenantId); | |||||
| return wxCouponPasswordMapper.findCouponCountInfo(wxCouponPassword); | |||||
| } | |||||
| @Override | |||||
| public void mkPasswords(String tenantId, Long couponId, Integer inventory) { | |||||
| String strAll = "0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ"; | |||||
| // 1.获取 coupon short 1 | |||||
| int couponShort = 0; | |||||
| String couponShortStr = "0"; | |||||
| WxCouponPassword pwQ = new WxCouponPassword(); | |||||
| pwQ.setTenantId(tenantId); | |||||
| List<WxCouponPassword> pwgList = wxCouponPasswordMapper.findCouponGroupList(pwQ); | |||||
| couponShort = pwgList.size(); | |||||
| couponShortStr = String.valueOf(strAll.charAt(couponShort)); | |||||
| // 2.随机字符 | |||||
| Random rand = new Random(); | |||||
| List<String> pwList = new ArrayList<>(); | |||||
| while (true) { | |||||
| StringBuilder sb = new StringBuilder(); | |||||
| for (int j = 0; j < 9; j++) { | |||||
| int f = (int) (Math.random() * 62); | |||||
| sb.append(strAll.charAt(f)); | |||||
| if (j == 4) { | |||||
| sb.append(couponShortStr); | |||||
| } | |||||
| } | |||||
| String pwd = sb.toString(); | |||||
| if (!pwList.stream().anyMatch(oPwd->oPwd.equals(pwd))) { | |||||
| pwList.add(pwd); | |||||
| } else { | |||||
| continue; | |||||
| } | |||||
| if (pwList.size() >= inventory) { | |||||
| break; | |||||
| } | |||||
| } | |||||
| // 3. save to db | |||||
| final IdWorker idWorker = IdWorker.get(); | |||||
| Date curDate = new Date(); | |||||
| List<WxCouponPassword> couponPasswords = new ArrayList<>(); | |||||
| for (int i=0;i<pwList.size();i++) { | |||||
| WxCouponPassword newOne = new WxCouponPassword(); | |||||
| newOne.setId(idWorker.nextId()); | |||||
| newOne.setTenantId(tenantId); | |||||
| newOne.setCouponId(couponId); | |||||
| newOne.setCouponShort(couponShortStr); | |||||
| newOne.setPassword(pwList.get(i)); | |||||
| newOne.setStatus(EnumCouponPasswordStatus.INIT.getCode()); | |||||
| newOne.setCreateDate(curDate); | |||||
| newOne.setUpdateDate(curDate); | |||||
| couponPasswords.add(newOne); | |||||
| } | |||||
| wxCouponPasswordMapper.insertCouponPasswds(couponPasswords); | |||||
| } | |||||
| @Override | |||||
| public void exportData(HttpServletRequest request, HttpServletResponse response, WxCouponPassword couponPassword) { | |||||
| List<WxCouponPassword> pwdList = wxCouponPasswordMapper.findAvaPasswordListByCouponId(couponPassword); | |||||
| if (pwdList.isEmpty()) { | |||||
| throw new MallinkException(ErrorCode.COUPON_PASSWORD_NOT_FOUND); | |||||
| } | |||||
| excelService.exportExcel(pwdList, null, "兑换码", WxCouponPassword.class, "卡兑换码.xlsx", response, false); | |||||
| } | |||||
| /* | |||||
| public static void main(String[] args) { | |||||
| WxCouponPasswordServiceImpl ll = new WxCouponPasswordServiceImpl(); | |||||
| long startTime = System.currentTimeMillis(); | |||||
| System.out.println(startTime); | |||||
| ll.mkPasswords("456", 12345L, 100); | |||||
| long endTime = System.currentTimeMillis(); | |||||
| System.out.println(endTime); | |||||
| long usedTime = (endTime-startTime)/1000; | |||||
| System.out.println("耗时:" + usedTime + "s"); | |||||
| } | |||||
| */ | |||||
| } | |||||
| @@ -0,0 +1,148 @@ | |||||
| package com.iformall.service.impl; | |||||
| import com.github.pagehelper.PageHelper; | |||||
| import com.github.pagehelper.PageInfo; | |||||
| import com.iformall.common.ErrorCode; | |||||
| import com.iformall.common.IdWorker; | |||||
| import com.iformall.common.ResultData; | |||||
| import com.iformall.domain.po.WxAppinfo; | |||||
| import com.iformall.domain.po.WxCoupon; | |||||
| import com.iformall.domain.po.WxCouponPassword; | |||||
| import com.iformall.domain.po.WxCouponPresent; | |||||
| import com.iformall.domain.po.msg.WxMsgRecord; | |||||
| import com.iformall.enums.*; | |||||
| import com.iformall.exception.MallinkException; | |||||
| import com.iformall.mapper.WxCouponPasswordMapper; | |||||
| import com.iformall.mapper.WxCouponPresentMapper; | |||||
| import com.iformall.mq.MqBaseProducer; | |||||
| import com.iformall.service.PushLimitService; | |||||
| import com.iformall.service.WxAppinfoService; | |||||
| import com.iformall.service.WxCouponPresentService; | |||||
| import com.iformall.service.WxCouponService; | |||||
| import org.slf4j.Logger; | |||||
| import org.slf4j.LoggerFactory; | |||||
| import org.springframework.beans.factory.annotation.Autowired; | |||||
| import org.springframework.stereotype.Service; | |||||
| import java.util.*; | |||||
| /** | |||||
| * @author gongbiao | |||||
| */ | |||||
| @Service | |||||
| public class WxCouponPresentServiceImpl implements WxCouponPresentService { | |||||
| private final Logger logger = LoggerFactory.getLogger(this.getClass()); | |||||
| @Autowired | |||||
| WxCouponPresentMapper wxCouponPresentMapper; | |||||
| @Autowired | |||||
| PushLimitService pushLimitService; | |||||
| @Autowired | |||||
| WxCouponService wxCouponService; | |||||
| @Autowired | |||||
| WxCouponPasswordMapper wxCouponPasswordMapper; | |||||
| @Autowired | |||||
| WxAppinfoService wxAppinfoService; | |||||
| @Autowired | |||||
| private MqBaseProducer mqBaseProducer; | |||||
| @Override | |||||
| public PageInfo<WxCouponPresent> listAsPage(WxCouponPresent record, Integer pageIndex, Integer pageSize) { | |||||
| return PageHelper.startPage(pageIndex, pageSize).doSelectPageInfo(() -> wxCouponPresentMapper.findList(record)); | |||||
| } | |||||
| @Override | |||||
| public WxCouponPresent findById(Long id) { | |||||
| return wxCouponPresentMapper.selectById(id); | |||||
| } | |||||
| @Override | |||||
| public ResultData add(WxCouponPresent record) { | |||||
| String tenantId = record.getTenantId(); | |||||
| try { | |||||
| pushLimitService.checkSendTime(tenantId); | |||||
| } catch (MallinkException e) { | |||||
| logger.error(e.getMessage()); | |||||
| return new ResultData(e.getErrorCode(), e.getMessage()); | |||||
| } | |||||
| WxCoupon wxCoupon = wxCouponService.getById(record.getCouponId()); | |||||
| if (wxCoupon.getValidType().equals(EnumCouponValidType.BETWEEN_TWO_TIME.getCode())) { //时间范围 | |||||
| if (new Date().after(wxCoupon.getValidEndDate())) { | |||||
| return new ResultData(ErrorCode.COUPON_IS_EXPIRED); | |||||
| } | |||||
| } | |||||
| if (!wxCoupon.getStatus().equals(EnumCouponStatus.COUPON_STATUS_THROW_IN.getCode())) { | |||||
| return new ResultData(ErrorCode.COUPON_IS_TAKE_OFF); | |||||
| } | |||||
| //获取手机号 | |||||
| record.setCouponName(wxCoupon.getTitle()); | |||||
| String phones = record.getPhones(); | |||||
| String[] phoneSplit = phones.split(","); | |||||
| Set<String> phoneSet = new HashSet<>(phoneSplit.length); | |||||
| for (String phone : phoneSplit) { | |||||
| if (!phone.isEmpty()) { | |||||
| phoneSet.add(phone); | |||||
| } | |||||
| } | |||||
| //查询有效券数量 | |||||
| WxCouponPassword wxCouponPassword = new WxCouponPassword(); | |||||
| wxCouponPassword.setTenantId(tenantId); | |||||
| wxCouponPassword.setCouponId(record.getCouponId()); | |||||
| wxCouponPassword.setStatus(EnumCouponPasswordStatus.INIT.getCode()); | |||||
| List<WxCouponPassword> list = wxCouponPasswordMapper.findList(wxCouponPassword); | |||||
| if (phoneSet.size() > list.size()) { | |||||
| return new ResultData(ErrorCode.REMAIN_IS_EMPTY); | |||||
| } | |||||
| //添加记录 | |||||
| final IdWorker idWorker = IdWorker.get(); | |||||
| record.setId(idWorker.nextId()); | |||||
| record.setCouponName(wxCoupon.getTitle()); | |||||
| record.setSendAmount(phoneSet.size()); | |||||
| wxCouponPresentMapper.insert(record); | |||||
| //小程序 | |||||
| WxAppinfo appInfo = wxAppinfoService.getCAppInfo(tenantId); | |||||
| String priceStr = wxCoupon.getPriceStr(); | |||||
| String name = appInfo.getName(); | |||||
| List<WxCouponPassword> tempList = wxCouponPasswordMapper.findList(wxCouponPassword); | |||||
| //循环发送 | |||||
| int i = 0; | |||||
| for (String phone : phoneSet) { | |||||
| WxCouponPassword couponPassword = list.get(i); | |||||
| //发送 | |||||
| sendMsg(tenantId, phone, priceStr, name, couponPassword.getPassword()); | |||||
| //记录发送数据便于更新状态 | |||||
| couponPassword.setSendedPhone(phone); | |||||
| tempList.add(couponPassword); | |||||
| i++; | |||||
| } | |||||
| //修改状态 | |||||
| wxCouponPasswordMapper.updateStatus(tempList); | |||||
| return new ResultData(); | |||||
| } | |||||
| private void sendMsg(String tenantId, String phone, String money, String appName, String password) { | |||||
| logger.info("》》》》》》》》》》》"); | |||||
| logger.info("系统发卡发送短信开始"); | |||||
| logger.info("》》》》》》》》》》》"); | |||||
| Map<String, String> msgReplaceMap = new HashMap(); | |||||
| msgReplaceMap.put("app", appName); | |||||
| msgReplaceMap.put("money", money); | |||||
| msgReplaceMap.put("password", password); | |||||
| WxMsgRecord wxMsgRecord = new WxMsgRecord(); | |||||
| wxMsgRecord.setMsgType(EnumMsgRecordType.SMS.getCode()); | |||||
| wxMsgRecord.setModelType(EnumMsgModel.COUPON_CARD_SEND.getCode()); | |||||
| wxMsgRecord.setReceiver(phone); | |||||
| wxMsgRecord.setTenantId(tenantId); | |||||
| wxMsgRecord.setDynamicContentMap(msgReplaceMap); | |||||
| mqBaseProducer.sendMessage(wxMsgRecord, EnumMsgMqTopic.DEFAULT.getCode(), EnumMsgMqTag.DEFAULT.getCode(), EnumMsgMqKey.DEFAULT.getCode()); | |||||
| logger.info("》》》》》》》》》》》"); | |||||
| logger.info("系统发卡发送短信结束"); | |||||
| logger.info("》》》》》》》》》》》"); | |||||
| } | |||||
| } | |||||
| @@ -64,6 +64,12 @@ import java.util.stream.Collectors; | |||||
| @Autowired | @Autowired | ||||
| WxCardInfoMapper wxCardInfoMapper; | WxCardInfoMapper wxCardInfoMapper; | ||||
| @Autowired | |||||
| WxCouponPasswordMapper couponPasswordMapper; | |||||
| @Autowired | |||||
| WxCouponPasswordService couponPasswordService; | |||||
| @Override | @Override | ||||
| public ResultData list(WxCoupon wxCoupon, Integer pageNum, Integer pageSize) { | public ResultData list(WxCoupon wxCoupon, Integer pageNum, Integer pageSize) { | ||||
| if (null == wxCoupon) wxCoupon = new WxCoupon(); | if (null == wxCoupon) wxCoupon = new WxCoupon(); | ||||
| @@ -326,6 +332,11 @@ import java.util.stream.Collectors; | |||||
| return new ResultData(ErrorCode.SYS_PARAMETER_NOT_NULL); | return new ResultData(ErrorCode.SYS_PARAMETER_NOT_NULL); | ||||
| } | } | ||||
| if (record.getPasswordSupport() != null && record.getPasswordSupport().equals(EnumCouponPasswordSupport.SUPPORTED.getCode())) { | |||||
| // 如果用户启用卡密,生成数据并保存 | |||||
| couponPasswordService.mkPasswords(record.getTenantId(), record.getId(), record.getInventory()); | |||||
| } | |||||
| record.setCreateDate(new Date()); | record.setCreateDate(new Date()); | ||||
| record.setUpdateDate(new Date()); | record.setUpdateDate(new Date()); | ||||
| wxCouponMapper.insert(record); | wxCouponMapper.insert(record); | ||||
| @@ -408,9 +419,10 @@ import java.util.stream.Collectors; | |||||
| wxScreenAdService.updateStatusByCouponId(record.getId(), record.getTenantId(), EnumScreenAdStatus.INVALID.getCode()); | wxScreenAdService.updateStatusByCouponId(record.getId(), record.getTenantId(), EnumScreenAdStatus.INVALID.getCode()); | ||||
| //下架拼团券 | //下架拼团券 | ||||
| wxOrderService.updateOrderGroupStatusByCouponId(record.getId(), record.getTenantId(), EnumOrderStatus.ORDER_STATUS_COOPERATING_CANCEL.getCode()); | wxOrderService.updateOrderGroupStatusByCouponId(record.getId(), record.getTenantId(), EnumOrderStatus.ORDER_STATUS_COOPERATING_CANCEL.getCode()); | ||||
| //修改卡状态 | |||||
| // 卡下架后,转赠找不到卡相关信息,所以修改卡转赠状态为不可转赠 | |||||
| wxCardInfoMapper.updateTransferStatusByCouponId(record.getId()); | wxCardInfoMapper.updateTransferStatusByCouponId(record.getId()); | ||||
| // 卡券下架,未使用的卡密要下架 | |||||
| couponPasswordMapper.updateStatusByCouponId(record.getId()); | |||||
| } | } | ||||
| record.setUpdateDate(new Date()); | record.setUpdateDate(new Date()); | ||||
| wxCouponMapper.updateById(record); | wxCouponMapper.updateById(record); | ||||
| @@ -4,10 +4,8 @@ import com.alibaba.fastjson.JSONArray; | |||||
| import com.github.pagehelper.PageHelper; | import com.github.pagehelper.PageHelper; | ||||
| import com.github.pagehelper.PageInfo; | import com.github.pagehelper.PageInfo; | ||||
| import com.iformall.common.IdWorker; | import com.iformall.common.IdWorker; | ||||
| import com.iformall.domain.po.WxMsgCallback; | |||||
| import com.iformall.domain.po.WxMsgConfig; | |||||
| import com.iformall.domain.po.WxMsgModel; | |||||
| import com.iformall.domain.po.WxMsgValidationcodeModel; | |||||
| import com.iformall.domain.po.*; | |||||
| import com.iformall.enums.EnumCouponPasswordStatus; | |||||
| import com.iformall.enums.EnumMsgSendStatus; | import com.iformall.enums.EnumMsgSendStatus; | ||||
| import com.iformall.mapper.*; | import com.iformall.mapper.*; | ||||
| import com.iformall.service.WxMsgCallbackService; | import com.iformall.service.WxMsgCallbackService; | ||||
| @@ -38,6 +36,9 @@ public class WxMsgCallbackServiceImpl implements WxMsgCallbackService { | |||||
| @Autowired | @Autowired | ||||
| WxMsgMapper wxMsgMapper; | WxMsgMapper wxMsgMapper; | ||||
| @Autowired | |||||
| WxCouponPasswordMapper wxCouponPasswordMapper; | |||||
| @Override | @Override | ||||
| public PageInfo<WxMsgCallback> listAsPage(WxMsgCallback record, Integer pageIndex, Integer pageSize) { | public PageInfo<WxMsgCallback> listAsPage(WxMsgCallback record, Integer pageIndex, Integer pageSize) { | ||||
| return PageHelper.startPage(pageIndex, pageSize).doSelectPageInfo(() -> wxMsgCallbackMapper.findList(record)); | return PageHelper.startPage(pageIndex, pageSize).doSelectPageInfo(() -> wxMsgCallbackMapper.findList(record)); | ||||
| @@ -93,6 +94,14 @@ public class WxMsgCallbackServiceImpl implements WxMsgCallbackService { | |||||
| callback.setCallbackId(wxMsgCallback.getId()); | callback.setCallbackId(wxMsgCallback.getId()); | ||||
| callback.setUpdatetime(new Date()); | callback.setUpdatetime(new Date()); | ||||
| wxMsgCallbackMapper.updateById(callback); | wxMsgCallbackMapper.updateById(callback); | ||||
| //更新业务 | |||||
| if (!callback.getBusinessId().equals(0L)) { | |||||
| WxCouponPassword couponPassword = new WxCouponPassword(); | |||||
| couponPassword.setId(callback.getBusinessId()); | |||||
| couponPassword.setStatus(EnumCouponPasswordStatus.MSG_SENDED.getCode()); | |||||
| couponPassword.setUpdateDate(new Date()); | |||||
| wxCouponPasswordMapper.updateById(couponPassword); | |||||
| } | |||||
| }else{ | }else{ | ||||
| Long callbackId = wxMsgCallback.getId(); | Long callbackId = wxMsgCallback.getId(); | ||||
| wxMsgCallback.setId(idWorker.nextId()); | wxMsgCallback.setId(idWorker.nextId()); | ||||
| @@ -6,8 +6,7 @@ import com.iformall.common.ErrorCode; | |||||
| import com.iformall.common.IdWorker; | import com.iformall.common.IdWorker; | ||||
| import com.iformall.common.Result; | import com.iformall.common.Result; | ||||
| import com.iformall.common.ResultData; | import com.iformall.common.ResultData; | ||||
| import com.iformall.domain.po.WxMsgCallback; | |||||
| import com.iformall.domain.po.WxMsgValidationcode; | |||||
| import com.iformall.domain.po.*; | |||||
| import com.iformall.domain.po.msg.WxMsgRecord; | import com.iformall.domain.po.msg.WxMsgRecord; | ||||
| import com.iformall.enums.*; | import com.iformall.enums.*; | ||||
| import com.iformall.mapper.*; | import com.iformall.mapper.*; | ||||
| @@ -15,6 +14,7 @@ import com.iformall.mq.MqBaseProducer; | |||||
| import com.iformall.service.WxMsgValidationcodeService; | import com.iformall.service.WxMsgValidationcodeService; | ||||
| import com.iformall.utils.DateUtils; | import com.iformall.utils.DateUtils; | ||||
| import org.apache.commons.collections.map.HashedMap; | import org.apache.commons.collections.map.HashedMap; | ||||
| 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; | ||||
| @@ -117,7 +117,7 @@ public class WxMsgValidationcodeServiceImpl implements WxMsgValidationcodeServic | |||||
| } | } | ||||
| @Override | @Override | ||||
| public void addMsgCallback(WxMsgValidationcode wxmsg, String batchNo){ | |||||
| public void addMsgCallback(WxMsgValidationcode wxmsg, String batchNo, String id) { | |||||
| logger.info("验证码发送时主动添加回调记录开始..."); | logger.info("验证码发送时主动添加回调记录开始..."); | ||||
| String phone = wxmsg.getPhone(); | String phone = wxmsg.getPhone(); | ||||
| final IdWorker idWorker = IdWorker.get(); | final IdWorker idWorker = IdWorker.get(); | ||||
| @@ -129,6 +129,9 @@ public class WxMsgValidationcodeServiceImpl implements WxMsgValidationcodeServic | |||||
| wxMsgCallback.setMsgId(wxmsg.getId()); | wxMsgCallback.setMsgId(wxmsg.getId()); | ||||
| wxMsgCallback.setStatus(EnumMsgSendStatus.MSG_SEND_FAIL.getCode()); | wxMsgCallback.setStatus(EnumMsgSendStatus.MSG_SEND_FAIL.getCode()); | ||||
| wxMsgCallback.setCreatetime(new Date()); | wxMsgCallback.setCreatetime(new Date()); | ||||
| if (StringUtils.isNotEmpty(id)) { | |||||
| wxMsgCallback.setBusinessId(Long.parseLong(id)); | |||||
| } | |||||
| wxMsgCallbackMapper.insert(wxMsgCallback); | wxMsgCallbackMapper.insert(wxMsgCallback); | ||||
| logger.info("验证码发送时主动添加回调记录结束..."); | logger.info("验证码发送时主动添加回调记录结束..."); | ||||
| } | } | ||||
| @@ -119,6 +119,8 @@ public class WxOrderServiceImpl implements WxOrderService { | |||||
| @Autowired | @Autowired | ||||
| private WxMsgLimitService wxMsgLimitService; | private WxMsgLimitService wxMsgLimitService; | ||||
| @Autowired | |||||
| private WxCouponPasswordMapper couponPasswordMapper; | |||||
| @Override | @Override | ||||
| public PageInfo<WxOrder> listAsPage(WxOrder record, Integer pageIndex, Integer pageSize) { | public PageInfo<WxOrder> listAsPage(WxOrder record, Integer pageIndex, Integer pageSize) { | ||||
| @@ -637,7 +639,7 @@ public class WxOrderServiceImpl implements WxOrderService { | |||||
| * @param order | * @param order | ||||
| * @param coupon | * @param coupon | ||||
| */ | */ | ||||
| private WxCouponOrder createCouponOrder(WxOrder order, WxCUser user, WxCoupon coupon) { | |||||
| private WxCouponOrder createCouponOrder(WxOrder order, WxCUser user, WxCoupon coupon, Long couponPasswordId) { | |||||
| Date curr = new Date(); | Date curr = new Date(); | ||||
| Date valid_date = null; | Date valid_date = null; | ||||
| int limit_days = Constant.WX_LIMIT_DAYS; | int limit_days = Constant.WX_LIMIT_DAYS; | ||||
| @@ -721,6 +723,12 @@ public class WxOrderServiceImpl implements WxOrderService { | |||||
| cardInfo.setShareFeeAmount(0); | cardInfo.setShareFeeAmount(0); | ||||
| cardInfo.setRemainingShareFeeAmount(0); | cardInfo.setRemainingShareFeeAmount(0); | ||||
| cardInfo.setRateAmount(0); | cardInfo.setRateAmount(0); | ||||
| if (coupon.getPasswordSupport().equals(EnumCouponPasswordSupport.SUPPORTED.getCode())) { | |||||
| WxCouponPassword updateCPwd = new WxCouponPassword(); | |||||
| updateCPwd.setId(couponPasswordId); | |||||
| updateCPwd.setStatus(EnumCouponPasswordStatus.USED.getCode()); | |||||
| couponPasswordMapper.updateById(updateCPwd); | |||||
| } | |||||
| } | } | ||||
| cardInfo.setServiceFeeAmount(fee); | cardInfo.setServiceFeeAmount(fee); | ||||
| @@ -813,7 +821,7 @@ public class WxOrderServiceImpl implements WxOrderService { | |||||
| // 创建couponOrder | // 创建couponOrder | ||||
| WxCouponOrder couponOrder = null; | WxCouponOrder couponOrder = null; | ||||
| try { | try { | ||||
| couponOrder = createCouponOrder(record, user, coupon); | |||||
| couponOrder = createCouponOrder(record, user, coupon, null); | |||||
| } catch (Exception e) { | } catch (Exception e) { | ||||
| logger.error("保存订单:" + e.getMessage()); | logger.error("保存订单:" + e.getMessage()); | ||||
| throw new MallinkException(ErrorCode.COUPON_ORDER_SAVE_ERR.getCode(), coupon.getTitle() + ErrorCode.COUPON_ORDER_SAVE_ERR.getMessage()); | throw new MallinkException(ErrorCode.COUPON_ORDER_SAVE_ERR.getCode(), coupon.getTitle() + ErrorCode.COUPON_ORDER_SAVE_ERR.getMessage()); | ||||
| @@ -860,7 +868,7 @@ public class WxOrderServiceImpl implements WxOrderService { | |||||
| // 创建couponOrder | // 创建couponOrder | ||||
| try { | try { | ||||
| createCouponOrder(updateOrder, user, coupon); | |||||
| createCouponOrder(updateOrder, user, coupon, null); | |||||
| } catch (Exception e) { | } catch (Exception e) { | ||||
| logger.error("创建券包:" + e.getMessage()); | logger.error("创建券包:" + e.getMessage()); | ||||
| throw new MallinkException(ErrorCode.COUPON_ORDER_SAVE_ERR); | throw new MallinkException(ErrorCode.COUPON_ORDER_SAVE_ERR); | ||||
| @@ -1361,7 +1369,7 @@ public class WxOrderServiceImpl implements WxOrderService { | |||||
| WxOrder order = null; | WxOrder order = null; | ||||
| if (checkCouponIsFree(coupon)) { | if (checkCouponIsFree(coupon)) { | ||||
| // 免费券 | // 免费券 | ||||
| order = saveFreeOrderForCoupon(user, coupon, orderSaveDto.getCouponChannelId(), orderSaveDto.getFormId()); | |||||
| order = saveFreeOrderForCoupon(user, coupon, orderSaveDto.getCouponChannelId(), orderSaveDto.getFormId(), null); | |||||
| if(order != null) { | if(order != null) { | ||||
| // 6. 下订单完成,发送内部消息 | // 6. 下订单完成,发送内部消息 | ||||
| // 下订单完成,发送内部消息 | // 下订单完成,发送内部消息 | ||||
| @@ -1395,7 +1403,7 @@ public class WxOrderServiceImpl implements WxOrderService { | |||||
| @Override | @Override | ||||
| @Transactional(propagation = Propagation.REQUIRED, readOnly = false, rollbackFor = {Exception.class}) | @Transactional(propagation = Propagation.REQUIRED, readOnly = false, rollbackFor = {Exception.class}) | ||||
| public WxOrder saveFreeOrderForCoupon(WxCUser user, WxCoupon coupon, Long couponChannelId, String formId) { | |||||
| public WxOrder saveFreeOrderForCoupon(WxCUser user, WxCoupon coupon, Long couponChannelId, String formId, Long couponPasswordId) { | |||||
| // 1. check user info and coupon info | // 1. check user info and coupon info | ||||
| userCouponMerchantCheck(user, coupon); | userCouponMerchantCheck(user, coupon); | ||||
| if (coupon.checkIsCreditCoupon()) { | if (coupon.checkIsCreditCoupon()) { | ||||
| @@ -1435,7 +1443,7 @@ public class WxOrderServiceImpl implements WxOrderService { | |||||
| // 5. 创建couponOrder | // 5. 创建couponOrder | ||||
| try { | try { | ||||
| createCouponOrder(record, user, coupon); | |||||
| createCouponOrder(record, user, coupon, couponPasswordId); | |||||
| } catch (Exception e) { | } catch (Exception e) { | ||||
| logger.error("couponOrder失败:" + e.getMessage()); | logger.error("couponOrder失败:" + e.getMessage()); | ||||
| throw new MallinkException(ErrorCode.COUPON_ORDER_SAVE_ERR); | throw new MallinkException(ErrorCode.COUPON_ORDER_SAVE_ERR); | ||||
| @@ -56,7 +56,7 @@ public class SendSmsServiceImpl implements MsgSendService { | |||||
| throw new MallinkException(ErrorCode.MSG_CONFIG_NOT_FOUND); | throw new MallinkException(ErrorCode.MSG_CONFIG_NOT_FOUND); | ||||
| } | } | ||||
| wxMsgConfig = wxMsgConfigs.get(0); | wxMsgConfig = wxMsgConfigs.get(0); | ||||
| if(wxMsgConfig.getRemains() <=0l){ | |||||
| if (wxMsgConfig.getRemains() <= 0L) { | |||||
| throw new MallinkException(ErrorCode.MSG_CONFIG_ACCOUNT); | throw new MallinkException(ErrorCode.MSG_CONFIG_ACCOUNT); | ||||
| } | } | ||||
| @@ -106,9 +106,10 @@ public class SendSmsServiceImpl implements MsgSendService { | |||||
| wxMsgValidationcode.setExpiretime(expiredate); | wxMsgValidationcode.setExpiretime(expiredate); | ||||
| } | } | ||||
| wxMsgValidationcodeMapper.insert(wxMsgValidationcode); | wxMsgValidationcodeMapper.insert(wxMsgValidationcode); | ||||
| wxMsgValidationcodeService.addMsgCallback(wxMsgValidationcode,batchNo); | |||||
| String id = record.getDynamicContentMap().get("id"); | |||||
| wxMsgValidationcodeService.addMsgCallback(wxMsgValidationcode, batchNo, id); | |||||
| //扣减剩余条数 | //扣减剩余条数 | ||||
| wxMsgConfig.setRemains(1l); | |||||
| wxMsgConfig.setRemains(1L); | |||||
| wxMsgConfigMapper.updateRemains(wxMsgConfig); | wxMsgConfigMapper.updateRemains(wxMsgConfig); | ||||
| }else{ | }else{ | ||||
| throw new MallinkException(1001,"运营商返回失败:"+result); | throw new MallinkException(1001,"运营商返回失败:"+result); | ||||
| @@ -526,5 +526,8 @@ | |||||
| UPDATE wx_c_user_basic_info set act_record = act_record +1 where id = #{id} | UPDATE wx_c_user_basic_info set act_record = act_record +1 where id = #{id} | ||||
| </update> | </update> | ||||
| <select id="selectNotCUserList" resultMap="BaseResultMap"> | |||||
| select id,credit from wx_c_user_basic_info cub where not exists (select * from wx_c_user c where c.id=cub.id) and cub.credit is null | |||||
| </select> | |||||
| </mapper> | </mapper> | ||||
| @@ -43,6 +43,7 @@ | |||||
| <result column="cancle_apply_status" property="cancleApplyStatus"/> | <result column="cancle_apply_status" property="cancleApplyStatus"/> | ||||
| <result column="conditions" jdbcType="VARCHAR" property="conditions"/> | <result column="conditions" jdbcType="VARCHAR" property="conditions"/> | ||||
| <result column="approval_type" property="approvalType"/> | <result column="approval_type" property="approvalType"/> | ||||
| <result column="password_support" property="passwordSupport"/> | |||||
| </resultMap> | </resultMap> | ||||
| <resultMap id="statisMap" type="com.iformall.domain.vo.WxCouponStatisVo"> | <resultMap id="statisMap" type="com.iformall.domain.vo.WxCouponStatisVo"> | ||||
| <id column="id" jdbcType="BIGINT" property="id"/> | <id column="id" jdbcType="BIGINT" property="id"/> | ||||
| @@ -0,0 +1,143 @@ | |||||
| <?xml version="1.0" encoding="UTF-8"?> | |||||
| <!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd"> | |||||
| <mapper namespace="com.iformall.mapper.WxCouponPasswordMapper"> | |||||
| <resultMap id="BaseResultMap" type="com.iformall.domain.po.WxCouponPassword"> | |||||
| <id column="id" jdbcType="BIGINT" property="id" /> | |||||
| <result column="tenant_id" jdbcType="VARCHAR" property="tenantId" /> | |||||
| <result column="coupon_id" jdbcType="BIGINT" property="couponId" /> | |||||
| <result column="coupon_short" jdbcType="VARCHAR" property="couponShort" /> | |||||
| <result column="password" jdbcType="VARCHAR" property="password" /> | |||||
| <result column="status" jdbcType="INTEGER" property="status" /> | |||||
| <result column="sended_phone" jdbcType="VARCHAR" property="sendedPhone" /> | |||||
| <result column="card_id" jdbcType="BIGINT" property="cardId" /> | |||||
| <result column="create_date" jdbcType="TIMESTAMP" property="createDate" /> | |||||
| <result column="update_date" jdbcType="TIMESTAMP" property="updateDate" /> | |||||
| <result column="expire_date" jdbcType="TIMESTAMP" property="expireDate" /> | |||||
| </resultMap> | |||||
| <sql id="allColumns"> | |||||
| `id`,`tenant_id`,`coupon_id`,`coupon_short`,`password`,`status`,`sended_phone`,`card_id`,`create_date`,`update_date`,`expire_date` | |||||
| </sql> | |||||
| <sql id="dynamicWhereConditions"> | |||||
| where 1 = 1 | |||||
| <if test=" null != id "> | |||||
| and `id` = #{id} | |||||
| </if> | |||||
| <if test=" null != tenantId "> | |||||
| and `tenant_id` = #{tenantId} | |||||
| </if> | |||||
| <if test=" null != couponId "> | |||||
| and `coupon_id` = #{couponId} | |||||
| </if> | |||||
| <if test=" null != couponShort "> | |||||
| and `coupon_short` = #{couponShort} | |||||
| </if> | |||||
| <if test=" null != password "> | |||||
| and `password` = #{password} | |||||
| </if> | |||||
| <if test=" null != status "> | |||||
| and `status` = #{status} | |||||
| </if> | |||||
| <if test=" null != sendedPhone "> | |||||
| and `sended_phone` = #{sendedPhone} | |||||
| </if> | |||||
| <if test=" null != cardId "> | |||||
| and `card_id` = #{cardId} | |||||
| </if> | |||||
| <if test=" null != createDate "> | |||||
| and `create_date` = #{createDate} | |||||
| </if> | |||||
| <if test=" null != updateDate "> | |||||
| and `update_date` = #{updateDate} | |||||
| </if> | |||||
| <if test=" null != expireDate "> | |||||
| and `expire_date` > #{expireDate} | |||||
| </if> | |||||
| <if test=" null != ids "> | |||||
| and id in | |||||
| <foreach collection="ids" index="index" item="idItem" open="(" separator="," close=")"> | |||||
| #{idItem} | |||||
| </foreach> | |||||
| </if> | |||||
| <if test=" null != statusStr and ''!=statusStr"> | |||||
| and status in (${statusStr}) | |||||
| </if> | |||||
| <if test=" null != sortColumns"> order by ${sortColumns} </if> | |||||
| </sql> | |||||
| <select id="findList" parameterType="com.iformall.domain.po.WxCouponPassword" resultMap="BaseResultMap"> | |||||
| select <include refid="allColumns" /> | |||||
| from wx_coupon_password | |||||
| <include refid="dynamicWhereConditions" /> | |||||
| </select> | |||||
| <select id="findAvaPasswordListByCouponId" parameterType="com.iformall.domain.po.WxCouponPassword" resultMap="BaseResultMap"> | |||||
| select <include refid="allColumns" /> | |||||
| from wx_coupon_password | |||||
| <where> `status` not in (3,4) | |||||
| <if test=" null != tenantId "> | |||||
| and `tenant_id` = #{tenantId} | |||||
| </if> | |||||
| <if test=" null != couponId "> | |||||
| and `coupon_id` = #{couponId} | |||||
| </if> | |||||
| <if test=" null != expireDate "> | |||||
| and `expire_date` > #{expireDate} | |||||
| </if> | |||||
| </where> | |||||
| </select> | |||||
| <insert id="insertCouponPasswds" parameterType="java.util.List"> | |||||
| INSERT INTO wx_coupon_password (`id`,`coupon_id`,`coupon_short`,`password`,`status`,`create_date`,`update_date`) | |||||
| VALUES | |||||
| <foreach collection="list" item="item" index="index" separator=","> | |||||
| ( | |||||
| #{item.id},#{item.couponId},#{item.couponShort},#{item.password},#{item.status}, | |||||
| #{item.createDate},#{item.updateDate} | |||||
| ) | |||||
| </foreach> | |||||
| </insert> | |||||
| <update id="updateStatusByCouponId" parameterType="Long"> | |||||
| update wx_coupon_password | |||||
| set status=4, update_date=now() | |||||
| where status != 3 and tenant_id = #{tenantId} and coupon_id=#{couponId} | |||||
| </update> | |||||
| <select id="findCouponGroupList" parameterType="com.iformall.domain.po.WxCouponPassword" resultMap="BaseResultMap"> | |||||
| select `coupon_id`,`coupon_short` | |||||
| from wx_coupon_password | |||||
| where `tenant_id` = #{tenantId} | |||||
| group by `coupon_id`,`coupon_short` | |||||
| </select> | |||||
| <resultMap id="CouponCountInfoMap" type="com.iformall.domain.vo.WxCouponPasswordCountInfoVO"> | |||||
| <result column="coupon_count" jdbcType="BIGINT" property="couponCount"/> | |||||
| <result column="title" jdbcType="VARCHAR" property="couponName"/> | |||||
| <result column="coupon_id" jdbcType="BIGINT" property="couponId"/> | |||||
| </resultMap> | |||||
| <select id="findCouponCountInfo" parameterType="com.iformall.domain.po.WxCouponPassword" | |||||
| resultMap="CouponCountInfoMap"> | |||||
| select cp.coupon_id,c.title,cp.coupon_count from | |||||
| (select count(*) as coupon_count,coupon_id from wx_coupon_password | |||||
| where tenant_id#{tenantId} and status=0) cp | |||||
| inner join wx_coupon c on cp.coupon_id = c.id | |||||
| where c.tenant_id=#{tenantId} and c.status=1 | |||||
| <if test=" null != couponId "> | |||||
| and cp.`coupon_id` = #{couponId} | |||||
| </if> | |||||
| group by cp.coupon_id | |||||
| </select> | |||||
| <update id="updateStatus" parameterType="java.util.List"> | |||||
| <foreach collection="list" item="item" index="index" open="" close="" separator=";"> | |||||
| update wx_coupon_password set status=1,send_phone=#{sendPhone},update_date=now() where id = ${item.id} | |||||
| </foreach> | |||||
| </update> | |||||
| </mapper> | |||||
| @@ -0,0 +1,58 @@ | |||||
| <?xml version="1.0" encoding="UTF-8"?> | |||||
| <!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd"> | |||||
| <mapper namespace="com.iformall.mapper.WxCouponPresentMapper"> | |||||
| <resultMap id="BaseResultMap" type="com.iformall.domain.po.WxCouponPresent"> | |||||
| <id column="id" jdbcType="BIGINT" property="id"/> | |||||
| <result column="tenant_id" jdbcType="VARCHAR" property="tenantId"/> | |||||
| <result column="user_id" jdbcType="BIGINT" property="userId"/> | |||||
| <result column="coupon_id" jdbcType="BIGINT" property="couponId"/> | |||||
| <result column="coupon_name" jdbcType="VARCHAR" property="couponName"/> | |||||
| <result column="create_time" jdbcType="TIMESTAMP" property="createTime"/> | |||||
| <result column="update_time" jdbcType="TIMESTAMP" property="updateTime"/> | |||||
| <result column="send_amount" jdbcType="INTEGER" property="sendAmount"/> | |||||
| </resultMap> | |||||
| <sql id="allColumns"> | |||||
| `id`,`tenant_id`,`coupon_id`,`coupon_name`,`user_id`,`create_time`,`update_time`,`send_amount` | |||||
| </sql> | |||||
| <sql id="dynamicWhereConditions"> | |||||
| where 1 = 1 | |||||
| <if test=" null != id "> | |||||
| and `id` = #{id} | |||||
| </if> | |||||
| <if test=" null != tenantId "> | |||||
| and `tenant_id` = #{tenantId} | |||||
| </if> | |||||
| <if test=" null != couponId "> | |||||
| and `coupon_id` = #{couponId} | |||||
| </if> | |||||
| <if test=" null != couponName "> | |||||
| and `coupon_name` like concat('%', #{couponName},'%') | |||||
| </if> | |||||
| <if test=" null != phones "> | |||||
| and `phones` like concat('%', #{phones},'%') | |||||
| </if> | |||||
| <if test=" null != sendTimeStart and null!=sendTimeEnd "> | |||||
| and `create_date` between #{sendTimeStart} and #{sendTimeEnd} | |||||
| </if> | |||||
| <if test=" null != updateTime "> | |||||
| and `update_date` = #{updateTime} | |||||
| </if> | |||||
| <if test=" null != ids "> | |||||
| and id in | |||||
| <foreach collection="ids" index="index" item="idItem" open="(" separator="," close=")"> | |||||
| #{idItem} | |||||
| </foreach> | |||||
| </if> | |||||
| <if test=" null != sortColumns">order by ${sortColumns}</if> | |||||
| </sql> | |||||
| <select id="findList" parameterType="com.iformall.domain.po.WxCouponPresent" resultMap="BaseResultMap"> | |||||
| select | |||||
| <include refid="allColumns"/> | |||||
| from wx_coupon_present | |||||
| <include refid="dynamicWhereConditions"/> | |||||
| </select> | |||||
| </mapper> | |||||
| @@ -213,7 +213,7 @@ | |||||
| select credit.credit_amount as amount,credit.c_user_id from wx_credit_history credit | select credit.credit_amount as amount,credit.c_user_id from wx_credit_history credit | ||||
| INNER join (select max(create_date) create_date,credit.c_user_id | INNER join (select max(create_date) create_date,credit.c_user_id | ||||
| from wx_credit_history credit group by credit.c_user_id) credit_max_id | from wx_credit_history credit group by credit.c_user_id) credit_max_id | ||||
| on credit.create_date=credit_max_id.create_date | |||||
| on credit.create_date=credit_max_id.create_date and credit.c_user_id=credit_max_id.c_user_id | |||||
| INNER JOIN wx_c_user_basic_info basic ON basic.id = credit.c_user_id | INNER JOIN wx_c_user_basic_info basic ON basic.id = credit.c_user_id | ||||
| LEFT JOIN wx_merchant merchant ON credit.merchant_id = merchant.id | LEFT JOIN wx_merchant merchant ON credit.merchant_id = merchant.id | ||||
| <include refid="customWhereConditions"/> | <include refid="customWhereConditions"/> | ||||
| @@ -253,4 +253,13 @@ | |||||
| select <include refid="allColumns" /> from wx_credit_history where create_date > #{dateTime} and credit_type = #{creditType} | select <include refid="allColumns" /> from wx_credit_history where create_date > #{dateTime} and credit_type = #{creditType} | ||||
| </select> | </select> | ||||
| <select id="findListByIds" parameterType="java.util.List" resultMap="BaseResultMap"> | |||||
| select <include refid="allColumns" /> from wx_credit_history | |||||
| where c_user_id in | |||||
| <foreach collection="userIds" index="index" item="item" open="(" separator="," close=")"> | |||||
| #{item} | |||||
| </foreach> | |||||
| order by create_date desc | |||||
| </select> | |||||
| </mapper> | </mapper> | ||||
| @@ -1,6 +1,8 @@ | |||||
| package com.iformall.controller.sys; | package com.iformall.controller.sys; | ||||
| import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper; | import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper; | ||||
| import com.google.common.base.Function; | |||||
| import com.google.common.collect.*; | |||||
| import com.iformall.common.ErrorCode; | import com.iformall.common.ErrorCode; | ||||
| import com.iformall.common.IdWorker; | import com.iformall.common.IdWorker; | ||||
| import com.iformall.common.ResultData; | import com.iformall.common.ResultData; | ||||
| @@ -14,14 +16,17 @@ import com.iformall.mapper.*; | |||||
| import com.iformall.service.WxCreditHistoryService; | import com.iformall.service.WxCreditHistoryService; | ||||
| import com.iformall.utils.DateUtils; | import com.iformall.utils.DateUtils; | ||||
| import lombok.extern.slf4j.Slf4j; | import lombok.extern.slf4j.Slf4j; | ||||
| import org.springframework.beans.factory.annotation.Autowired; | |||||
| import org.apache.commons.collections.CollectionUtils; | |||||
| import org.checkerframework.checker.nullness.qual.Nullable; | |||||
| import org.springframework.transaction.annotation.Transactional; | import org.springframework.transaction.annotation.Transactional; | ||||
| import org.springframework.web.bind.annotation.GetMapping; | import org.springframework.web.bind.annotation.GetMapping; | ||||
| import org.springframework.web.bind.annotation.RequestMapping; | import org.springframework.web.bind.annotation.RequestMapping; | ||||
| import org.springframework.web.bind.annotation.RestController; | import org.springframework.web.bind.annotation.RestController; | ||||
| import javax.annotation.Resource; | import javax.annotation.Resource; | ||||
| import java.math.BigDecimal; | |||||
| import java.util.*; | import java.util.*; | ||||
| import java.util.concurrent.atomic.AtomicInteger; | |||||
| import java.util.stream.Collectors; | import java.util.stream.Collectors; | ||||
| /** | /** | ||||
| @@ -100,6 +105,28 @@ public class DataInitController extends BaseController { | |||||
| return new ResultData(); | return new ResultData(); | ||||
| } | } | ||||
| /** | |||||
| * 修复wx_c_user_basic_info积分数据 | |||||
| * | |||||
| * @return | |||||
| */ | |||||
| @GetMapping("/fixCredit4CUserBasic") | |||||
| public ResultData fixCredit4CUserBasic() { | |||||
| try { | |||||
| MallUserInfo userInfo = getUser(); | |||||
| if (userInfo.isFmSuperAdmin()) { | |||||
| doFixCredit4CUserBasic(); | |||||
| return new ResultData(); | |||||
| } | |||||
| } catch (Exception e) { | |||||
| log.error("DataInitController::fixCredit4CUserBasic error ", e); | |||||
| return new ResultData(ErrorCode.MSG_METHOD_REQUEST_ERROR, e.getMessage()); | |||||
| } | |||||
| return new ResultData(); | |||||
| } | |||||
| /** | /** | ||||
| * 核销积分数据修复 | * 核销积分数据修复 | ||||
| * | * | ||||
| @@ -121,6 +148,47 @@ public class DataInitController extends BaseController { | |||||
| return new ResultData(); | return new ResultData(); | ||||
| } | } | ||||
| @Transactional(rollbackFor = Exception.class) | |||||
| public void doFixCredit4CUserBasic() { | |||||
| log.debug("cUserBasic积分更新, begin --------------》"); | |||||
| // 1 查找c_user_basic中c_user不存在且积分为null的用户用户 | |||||
| List<WxCUserBasicInfo> userBasicInfoList = cUserBasicInfoMapper.selectNotCUserList(); | |||||
| List<Long> ids = userBasicInfoList.stream().map(WxCUserBasicInfo::getId).collect(Collectors.toList()); | |||||
| //log.debug("ids {}", JSON.toJSONString(ids)); | |||||
| // 2 获取对应用户的积分记录 | |||||
| List<WxCreditHistory> creditList = creditHistoryMapper.findListByIds(ids); | |||||
| ImmutableListMultimap<Long, WxCreditHistory> userCreditHistory = Multimaps.index(creditList, new Function<WxCreditHistory, Long>() { | |||||
| @Nullable | |||||
| @Override | |||||
| public Long apply(@Nullable WxCreditHistory input) { | |||||
| return input.getCUserId(); | |||||
| } | |||||
| }); | |||||
| //3 将历史记录最好积分重设积分 | |||||
| AtomicInteger count = new AtomicInteger(0); | |||||
| userBasicInfoList.forEach(wxCUserBasicInfo -> { | |||||
| ImmutableList<WxCreditHistory> historyList = userCreditHistory.get(wxCUserBasicInfo.getId()); | |||||
| WxCUserBasicInfo toUpdateUser = new WxCUserBasicInfo(); | |||||
| toUpdateUser.setId(wxCUserBasicInfo.getId()); | |||||
| //用户积分不存在,跳过 | |||||
| if (CollectionUtils.isEmpty(historyList)) { | |||||
| //log.debug("cUserBasic积分更新,id: {} 积分记录不存在", wxCUserBasicInfo.getId()); | |||||
| return; | |||||
| } | |||||
| //积分记录存在,使用最新的总积分重新赋值 | |||||
| WxCreditHistory wxCreditHistory = historyList.get(0); | |||||
| toUpdateUser.setCredit(wxCreditHistory.getCreditAmount()); | |||||
| cUserBasicInfoMapper.updateById(toUpdateUser); | |||||
| log.debug("cUserBasic积分更新,id: {},原积分: {},新积分: {}, 积分时间: {}", wxCUserBasicInfo.getId(), wxCUserBasicInfo.getCredit(), toUpdateUser.getCredit(), DateUtils.format(wxCreditHistory.getCreateDate())); | |||||
| count.getAndIncrement(); | |||||
| }); | |||||
| log.debug("cUserBasic积分更新,更新用户 {}", count.intValue()); | |||||
| log.debug("cUserBasic积分更新, end --------------》"); | |||||
| } | |||||
| @Transactional(rollbackFor = Exception.class) | @Transactional(rollbackFor = Exception.class) | ||||
| public void doFixCredit() { | public void doFixCredit() { | ||||
| // 1 获取积分记录 | // 1 获取积分记录 | ||||
| @@ -144,7 +212,7 @@ public class DataInitController extends BaseController { | |||||
| return; | return; | ||||
| } | } | ||||
| //根据商户id和花费金额计算需要新增的积分 | //根据商户id和花费金额计算需要新增的积分 | ||||
| Map<String, Integer> result = creditHistoryService.findByMerchantIdAndSpend(wxCreditHistory.getMerchantId(), String.valueOf(wxCreditHistory.getSpend()), wxCreditHistory.getCUserId(),wxCreditHistory.getTenantId()); | |||||
| Map<String, Integer> result = creditHistoryService.findByMerchantIdAndSpend(wxCreditHistory.getMerchantId(), String.valueOf(new BigDecimal(wxCreditHistory.getSpend()/100)), wxCreditHistory.getCUserId(),wxCreditHistory.getTenantId()); | |||||
| //Map<String, Integer> result = creditHistoryService.findByMerchantIdAndSpend(wxCreditHistory.getMerchantId(), String.valueOf(wxCreditHistory.getSpend()), wxCreditHistory.getCUserId(), wxCreditHistory.getTenantId()); | //Map<String, Integer> result = creditHistoryService.findByMerchantIdAndSpend(wxCreditHistory.getMerchantId(), String.valueOf(wxCreditHistory.getSpend()), wxCreditHistory.getCUserId(), wxCreditHistory.getTenantId()); | ||||
| Integer creditDB = wxCreditHistory.getCreditNum(); | Integer creditDB = wxCreditHistory.getCreditNum(); | ||||