package com.younike.merchant;

import com.younike.common.core.controller.BaseController;
import com.younike.common.core.domain.AjaxResult;
import com.younike.common.core.page.TableDataInfo;
import com.younike.system.domain.vo.ReconciliationVo;
import com.younike.system.service.IMerchantOrderService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.apache.commons.lang3.ObjectUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * 店铺管理
 * 财务对账
 */
@Api("财务对账")
@RestController
@RequestMapping("/merchant/reconciliation")
public class MerchantReconciliationController extends BaseController {

    @Autowired
    private IMerchantOrderService orderService;

    /**
     * 财务对账：查询订单账单
     */
    @GetMapping("/orderList")
    @PreAuthorize("@ss.hasRole('merchant')")
    public TableDataInfo orderList(ReconciliationVo vo) {
        startPage();
        if (ObjectUtils.isEmpty(vo) || vo.getMerchantId() == null) {
            throw new ArithmeticException("参数错误");
        }
        List<ReconciliationVo> list = orderService.selectReconciliationOrderList(vo);
        return getDataTable(list);
    }

    /**
     * 统计店铺入账总金额，以及平台抽成
     */
    @ApiOperation("统计店铺入账总金额，以及平台抽成")
    @GetMapping("/orderStatistics")
    @PreAuthorize("@ss.hasRole('merchant')")
    public AjaxResult getInfo(ReconciliationVo vo) {
        if (ObjectUtils.isEmpty(vo) || vo.getMerchantId() == null) {
            throw new ArithmeticException("参数错误");
        }
        return AjaxResult.success(orderService.orderStatistics(vo));
    }
}
