
package com.tmerclub.cloud.supplier.controller.admin;

import com.tmerclub.cloud.common.constant.Constant;
import com.tmerclub.cloud.common.database.dto.PageDTO;
import com.tmerclub.cloud.common.database.vo.PageVO;
import com.tmerclub.cloud.common.response.ServerResponseEntity;
import com.tmerclub.cloud.common.security.AuthUserContext;
import com.tmerclub.cloud.supplier.dto.SupplierWithdrawCashDTO;
import com.tmerclub.cloud.supplier.service.SupplierWithdrawCashService;
import com.tmerclub.cloud.supplier.vo.SupplierWithdrawCashVO;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import java.util.Objects;

/**
 * 商家提现申请信息
 *
 * @Author lth
 * @Date 2021/6/11 9:23
 */
@RestController("adminSupplierWithdrawCashController")
@RequestMapping("/mp/supplier_withdraw_cash")
@Tag(name = "admin-供应商提现申请信息")
public class SupplierWithdrawCashController {

    @Autowired
    private SupplierWithdrawCashService supplierWithdrawCashService;

    @GetMapping("/page")
    @Operation(summary = "分页获取商家提现记录信息", description = "分页获取商家提现记录信息")
    public ServerResponseEntity<PageVO<SupplierWithdrawCashVO>> page(PageDTO pageDTO, SupplierWithdrawCashDTO supplierWithdrawCashDTO) {
        Long supplierId = AuthUserContext.get().getTenantId();
        if (!Objects.equals(supplierId, Constant.PLATFORM_SHOP_ID)) {
            supplierWithdrawCashDTO.setSupplierId(supplierId);
        }
        PageVO<SupplierWithdrawCashVO> pageVO = supplierWithdrawCashService.pageByParam(pageDTO, supplierWithdrawCashDTO);
        return ServerResponseEntity.success(pageVO);
    }

    @GetMapping("/info")
    @Operation(summary = "根据提现记录id查看提现记录", description = "根据提现记录id查看提现记录")
    public ServerResponseEntity<SupplierWithdrawCashVO> getById(@RequestParam("cashId") Long cashId) {
        SupplierWithdrawCashVO supplierWithdrawCashVO = supplierWithdrawCashService.getDetailByCashId(cashId);
        return ServerResponseEntity.success(supplierWithdrawCashVO);
    }
}
