后端 + 前端:优惠劵更新状态功能

This commit is contained in:
YunaiV 2019-04-06 01:08:13 +08:00
parent f8ae2153ba
commit 5c8828c2ec
7 changed files with 68 additions and 26 deletions

View File

@ -1,8 +1,8 @@
import {message} from 'antd'; import {message} from 'antd';
import { import {
updateProductRecommendStatus,
addCouponCardTemplate, addCouponCardTemplate,
updateCouponCardTemplate, updateCouponCardTemplate,
updateCouponCardTemplateStatus,
getCouponCardTemplatePage, getCouponCardTemplatePage,
} from '../../services/promotion'; } from '../../services/promotion';
import PaginationHelper from '../../../helpers/PaginationHelper'; import PaginationHelper from '../../../helpers/PaginationHelper';
@ -123,7 +123,7 @@ export default {
* updateStatus({ payload }, { call, put }) { * updateStatus({ payload }, { call, put }) {
// 请求 // 请求
const response = yield call(updateProductRecommendStatus, payload); const response = yield call(updateCouponCardTemplateStatus, payload);
// 响应 // 响应
if (response.code === 0) { if (response.code === 0) {
message.info('更新状态成功!'); message.info('更新状态成功!');

View File

@ -48,7 +48,7 @@ function List ({ dataSource, loading, pagination, searchParams, dispatch,
function handleStatus(record) { function handleStatus(record) {
Modal.confirm({ Modal.confirm({
title: record.status === 1 ? '确认禁用' : '取消禁用', title: record.status === 1 ? '确认禁用' : '取消禁用',
content: `${record.productSpuId}`, content: `${record.title}`,
onOk() { onOk() {
dispatch({ dispatch({
type: 'couponCardTemplateList/updateStatus', type: 'couponCardTemplateList/updateStatus',

View File

@ -84,3 +84,9 @@ export async function updateCouponCardTemplate(params) {
method: 'POST', method: 'POST',
}); });
} }
export async function updateCouponCardTemplateStatus(params) {
return request(`/promotion-api/admins/coupon/template/update_status?${stringify(params)}`, {
method: 'POST',
});
}

View File

@ -2,6 +2,7 @@ package cn.iocoder.mall.promotion.application.controller.admins;
import cn.iocoder.common.framework.util.DateUtil; import cn.iocoder.common.framework.util.DateUtil;
import cn.iocoder.common.framework.vo.CommonResult; import cn.iocoder.common.framework.vo.CommonResult;
import cn.iocoder.mall.admin.sdk.context.AdminSecurityContextHolder;
import cn.iocoder.mall.promotion.api.CouponService; import cn.iocoder.mall.promotion.api.CouponService;
import cn.iocoder.mall.promotion.api.bo.CouponTemplateBO; import cn.iocoder.mall.promotion.api.bo.CouponTemplateBO;
import cn.iocoder.mall.promotion.api.bo.CouponTemplatePageBO; import cn.iocoder.mall.promotion.api.bo.CouponTemplatePageBO;
@ -131,6 +132,17 @@ public class AdminsCouponTemplateController {
return couponService.updateCouponCardTemplate(couponCardTemplateUpdateDTO); return couponService.updateCouponCardTemplate(couponCardTemplateUpdateDTO);
} }
@PostMapping("/template/update_status")
@ApiOperation(value = "更新优惠劵(码)模板状态")
@ApiImplicitParams({
@ApiImplicitParam(name = "id", value = "Banner 编号", required = true, example = "1"),
@ApiImplicitParam(name = "status", value = "状态。1 - 开启2 - 禁用", required = true, example = "1"),
})
public CommonResult<Boolean> updateStatus(@RequestParam("id") Integer id,
@RequestParam("status") Integer status) {
return couponService.updateCouponTemplateStatus(AdminSecurityContextHolder.getContext().getAdminId(), id, status);
}
// ========== 优惠劵 ========== // ========== 优惠劵 ==========
// ========== 优惠码 ========== // ========== 优惠码 ==========

View File

@ -1,9 +1,11 @@
package cn.iocoder.mall.promotion.api; package cn.iocoder.mall.promotion.api;
import cn.iocoder.common.framework.validator.InEnum;
import cn.iocoder.common.framework.vo.CommonResult; import cn.iocoder.common.framework.vo.CommonResult;
import cn.iocoder.mall.promotion.api.bo.CouponCardBO; import cn.iocoder.mall.promotion.api.bo.CouponCardBO;
import cn.iocoder.mall.promotion.api.bo.CouponTemplateBO; import cn.iocoder.mall.promotion.api.bo.CouponTemplateBO;
import cn.iocoder.mall.promotion.api.bo.CouponTemplatePageBO; import cn.iocoder.mall.promotion.api.bo.CouponTemplatePageBO;
import cn.iocoder.mall.promotion.api.constant.CouponTemplateStatusEnum;
import cn.iocoder.mall.promotion.api.dto.*; import cn.iocoder.mall.promotion.api.dto.*;
public interface CouponService { public interface CouponService {
@ -52,7 +54,8 @@ public interface CouponService {
* @param status 状态 * @param status 状态
* @return 是否成功 * @return 是否成功
*/ */
CommonResult<Boolean> updateCouponTemplateStatus(Integer adminId, Integer couponTemplateId, Integer status); CommonResult<Boolean> updateCouponTemplateStatus(Integer adminId, Integer couponTemplateId,
@InEnum(value = CouponTemplateStatusEnum.class, message = "修改状态必须是 {value}") Integer status);
// ========== 优惠劵 ========== // ========== 优惠劵 ==========

View File

@ -1,8 +1,10 @@
package cn.iocoder.mall.promotion.api.constant; package cn.iocoder.mall.promotion.api.constant;
import cn.iocoder.common.framework.core.IntArrayValuable;
import java.util.Arrays; import java.util.Arrays;
public enum CouponTemplateStatusEnum { public enum CouponTemplateStatusEnum implements IntArrayValuable {
ENABLE(1, "开启中"), ENABLE(1, "开启中"),
DISABLE(2, "禁用中"), DISABLE(2, "禁用中"),
@ -33,4 +35,8 @@ public enum CouponTemplateStatusEnum {
return name; return name;
} }
@Override
public int[] array() {
return ARRAYS;
}
} }

View File

@ -24,6 +24,8 @@ public class CouponServiceImpl implements CouponService {
@Autowired @Autowired
private CouponTemplateMapper couponTemplateMapper; private CouponTemplateMapper couponTemplateMapper;
// ========== 优惠劵模板 ==========
@Override @Override
public CommonResult<CouponTemplatePageBO> getCouponTemplatePage(CouponTemplatePageDTO couponTemplatePageDTO) { public CommonResult<CouponTemplatePageBO> getCouponTemplatePage(CouponTemplatePageDTO couponTemplatePageDTO) {
CouponTemplatePageBO couponTemplatePageBO = new CouponTemplatePageBO(); CouponTemplatePageBO couponTemplatePageBO = new CouponTemplatePageBO();
@ -102,27 +104,16 @@ public class CouponServiceImpl implements CouponService {
@Override @Override
public CommonResult<Boolean> updateCouponTemplateStatus(Integer adminId, Integer couponTemplateId, Integer status) { public CommonResult<Boolean> updateCouponTemplateStatus(Integer adminId, Integer couponTemplateId, Integer status) {
return null; // 校验 CouponCardTemplate 存在
CouponTemplateDO template = couponTemplateMapper.selectById(couponTemplateId);
if (template == null) {
return ServiceExceptionUtil.error(PromotionErrorCodeEnum.PRODUCT_TEMPLATE_NOT_EXISTS.getCode());
} }
// 更新到数据库
@Override CouponTemplateDO updateTemplateDO = new CouponTemplateDO().setId(couponTemplateId).setStatus(status);
public CommonResult<CouponCardBO> addCouponCard(Integer userId, Integer couponTemplateId) { couponTemplateMapper.update(updateTemplateDO);
return null; // 返回成功
} return CommonResult.success(true);
@Override
public CommonResult<Boolean> useCouponCard(Integer userId, Integer couponCardId, Integer usedOrderId, Integer usedPrice) {
return null;
}
@Override
public CommonResult<Boolean> cancelUseCouponCard(Integer userId, Integer couponCardId) {
return null;
}
@Override
public CommonResult<CouponCardBO> useCouponCode(Integer userId, String code) {
return null;
} }
private CommonResult<Boolean> checkCouponTemplateDateType(Integer dateType, Date validStartTime, Date validEndTime, Integer fixedBeginTerm, Integer fixedEndTerm) { private CommonResult<Boolean> checkCouponTemplateDateType(Integer dateType, Date validStartTime, Date validEndTime, Integer fixedBeginTerm, Integer fixedEndTerm) {
@ -168,4 +159,28 @@ public class CouponServiceImpl implements CouponService {
return CommonResult.success(true); return CommonResult.success(true);
} }
// ========== 优惠劵 ==========
@Override
public CommonResult<CouponCardBO> addCouponCard(Integer userId, Integer couponTemplateId) {
return null;
}
@Override
public CommonResult<Boolean> useCouponCard(Integer userId, Integer couponCardId, Integer usedOrderId, Integer usedPrice) {
return null;
}
@Override
public CommonResult<Boolean> cancelUseCouponCard(Integer userId, Integer couponCardId) {
return null;
}
// ========== 优惠码 ==========
@Override
public CommonResult<CouponCardBO> useCouponCode(Integer userId, String code) {
return null;
}
} }