package com.sv.oms.controller;
import com.sv.service.oms.MemberWithdrawApplyService;
import com.ydd.framework.core.common.Pagination;
import com.ydd.framework.core.common.dto.ResponseDTO;
import com.ydd.framework.core.entity.enums.StatusEnum;
import com.ydd.oms.controller.OmsController;
import com.sv.entity.MemberWithdrawApply;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import javax.xml.crypto.Data;
import java.math.BigDecimal;

/**
 * Controller - 用户提现申请
 *
 * @author yechanglin
 * @since 2018-08-03
 */
@RestController
public class MemberWithdrawApplyController extends OmsController {

	private final Logger logger = LoggerFactory.getLogger(MemberWithdrawApplyController.class);
	
	@Resource
	private MemberWithdrawApplyService memberWithdrawApplyService;

	/**
	 * 分页查询用户提现申请
	 */
	@RequestMapping(value = "/member/withdraw/applys", method = RequestMethod.GET)
	public ResponseDTO findPage(Pagination pagination) {
		return ResponseDTO.ok()
				.setPagination(memberWithdrawApplyService.findPage(pagination));
	}

	/**
	 * 查询用户提现申请信息
	 */
	@RequestMapping(value = "/member/withdraw/apply/{id}", method = RequestMethod.GET)
	public ResponseDTO findById(@PathVariable("id") Integer id) {
		return ResponseDTO.ok()
				.addAttribute("memberWithdrawApply", memberWithdrawApplyService.findById(id));
	}

	/**
	 * 保存用户提现申请
	 */
	@RequestMapping(value = "/member/withdraw/apply", method = RequestMethod.POST)
	public ResponseDTO save(MemberWithdrawApply memberWithdrawApply) {
		memberWithdrawApplyService.save(memberWithdrawApply);
		return ResponseDTO.ok("保存成功");
	}

	/**
	 * 删除用户提现申请
	 */
	@RequestMapping(value = "/member/withdraw/apply/delete", method = RequestMethod.POST)
	public ResponseDTO delete(@RequestParam("id[]") Integer[] ids) {
		memberWithdrawApplyService.deleteByIds(ids);
		return ResponseDTO.ok("删除成功");
	}

	/**
	 * 变更用户提现申请状态
	 */
	@RequestMapping(value = "/member/withdraw/apply/status", method = RequestMethod.POST)
	public ResponseDTO updateStatus(@RequestParam("id[]") Integer[] ids, Byte status, String dataTime,
									@RequestParam("memberId") Integer memberId) {
		memberWithdrawApplyService.updateStatus(ids, status, dataTime, memberId);
		String operationName = (StatusEnum.ENABLE.value.equals(status) ? "已提现" : "已拒绝");
		return ResponseDTO.ok(operationName);
	}


}
