net.groupbuy.controller.shop.member.DepositController.java Source code

Java tutorial

Introduction

Here is the source code for net.groupbuy.controller.shop.member.DepositController.java

Source

/*
 * Copyright 2005-2013 shopxx.net. All rights reserved.
 * Support: http://www.shopxx.net
 * License: http://www.shopxx.net/license
 */
package net.groupbuy.controller.shop.member;

import java.math.BigDecimal;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import javax.annotation.Resource;

import net.groupbuy.Pageable;
import net.groupbuy.controller.shop.BaseController;
import net.groupbuy.entity.Member;
import net.groupbuy.plugin.PaymentPlugin;
import net.groupbuy.service.DepositService;
import net.groupbuy.service.MemberService;
import net.groupbuy.service.PluginService;

import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.ResponseBody;

/**
 * Controller -  - 
 * 
 * @author SHOP++ Team
 * @version 3.0
 */
@Controller("shopMemberDepositController")
@RequestMapping("/member/deposit")
public class DepositController extends BaseController {

    /** ? */
    private static final int PAGE_SIZE = 10;

    @Resource(name = "memberServiceImpl")
    private MemberService memberService;
    @Resource(name = "depositServiceImpl")
    private DepositService depositService;
    @Resource(name = "pluginServiceImpl")
    private PluginService pluginService;

    /**
     * 
     */
    @RequestMapping(value = "/calculate_fee", method = RequestMethod.POST)
    public @ResponseBody Map<String, Object> calculateFee(String paymentPluginId, BigDecimal amount) {
        Map<String, Object> data = new HashMap<String, Object>();
        PaymentPlugin paymentPlugin = pluginService.getPaymentPlugin(paymentPluginId);
        if (paymentPlugin == null || !paymentPlugin.getIsEnabled() || amount == null
                || amount.compareTo(new BigDecimal(0)) < 0) {
            data.put("message", ERROR_MESSAGE);
            return data;
        }
        data.put("message", SUCCESS_MESSAGE);
        data.put("fee", paymentPlugin.calculateFee(amount));
        return data;
    }

    /**
     * ?
     */
    @RequestMapping(value = "/check_balance", method = RequestMethod.POST)
    public @ResponseBody Map<String, Object> checkBalance() {
        Map<String, Object> data = new HashMap<String, Object>();
        Member member = memberService.getCurrent();
        data.put("balance", member.getBalance());
        return data;
    }

    /**
     * 
     */
    @RequestMapping(value = "/recharge", method = RequestMethod.GET)
    public String recharge(ModelMap model) {
        List<PaymentPlugin> paymentPlugins = pluginService.getPaymentPlugins(true);
        if (!paymentPlugins.isEmpty()) {
            model.addAttribute("defaultPaymentPlugin", paymentPlugins.get(0));
            model.addAttribute("paymentPlugins", paymentPlugins);
        }
        return "shop/member/deposit/recharge";
    }

    /**
     * 
     */
    @RequestMapping(value = "/list", method = RequestMethod.GET)
    public String list(Integer pageNumber, ModelMap model) {
        Member member = memberService.getCurrent();
        Pageable pageable = new Pageable(pageNumber, PAGE_SIZE);
        model.addAttribute("page", depositService.findPage(member, pageable));
        return "shop/member/deposit/list";
    }

}