package com.sv.api.controller;

import com.sv.entity.MemberRefund;
import com.sv.service.api.MemberRefundService;
import com.ydd.framework.core.common.Pagination;
import com.ydd.framework.core.common.dto.ResponseDTO;
import com.ydd.framework.core.controller.BaseApiController;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;

/**
 * Controller - 用户退款记录表
 *
 * @author lihong
 * @since 2018-08-07
 */
@RestController
public class MemberRefundController extends BaseApiController {

	private final Logger logger = LoggerFactory.getLogger(MemberRefundController.class);
	
	@Resource
	private MemberRefundService memberRefundService;

	/**
	 * 分页查询用户退款记录表
	 */
	@RequestMapping(value = "/member/refunds", method = RequestMethod.GET)
	public ResponseDTO findPage(Pagination pagination) {
		return ResponseDTO.ok()
				.setPagination(memberRefundService.findPage(pagination));
	}

	/**
	 * 查询用户退款记录表信息
	 */
	@RequestMapping(value = "/member/refund/{id}", method = RequestMethod.GET)
	public ResponseDTO findById(@PathVariable("id") Integer id) {
		return ResponseDTO.ok()
				.addAttribute("memberRefund", memberRefundService.findById(id));
	}

	/**
	 * 保存用户退款记录表
	 */
	@RequestMapping(value = "/member/refund", method = RequestMethod.POST)
	public ResponseDTO save(MemberRefund memberRefund) {
		memberRefundService.save(memberRefund);
		return ResponseDTO.ok("保存成功");
	}

	/**
	 * 删除用户退款记录表
	 */
	@RequestMapping(value = "/member/refund/delete", method = RequestMethod.POST)
	public ResponseDTO delete(@RequestParam("id[]") Integer[] ids) {
		memberRefundService.deleteByIds(ids);
		return ResponseDTO.ok("删除成功");
	}

}
