/*
 * Copyright (c) 2018-2999 广州亚米信息科技有限公司 All rights reserved.
 *
 * https://www.gz-yami.com/
 *
 * 未经允许，不可做商业用途！
 *
 * 版权所有，侵权必究！
 */

package com.yami.shop.distribution.platform.controller;

import com.baomidou.mybatisplus.core.metadata.IPage;
import com.yami.shop.common.util.PageParam;
import com.yami.shop.distribution.comment.model.DistributionWithdrawCash;
import com.yami.shop.distribution.comment.param.RangeTimeParam;
import com.yami.shop.distribution.comment.service.DistributionUserService;
import com.yami.shop.distribution.comment.service.DistributionUserWalletService;
import com.yami.shop.distribution.comment.service.DistributionWithdrawCashService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.ResponseEntity;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

/**
 * @author lgh on 2019/04/01.
 */
@RestController
@RequestMapping("/platform/distributionWithdrawCash")
public class DistributionWithdrawCashController {

    @Autowired
    private DistributionWithdrawCashService distributionWithdrawCashService;
    @Autowired
    private DistributionUserWalletService distributionUserWalletService;
    @Autowired
    private DistributionUserService distributionUserService;

    /**
     * 分页获取
     */
    @GetMapping("/page")
    @PreAuthorize("@pms.hasPermission('platform:distributionWithdrawCash:page')")
    public ResponseEntity<IPage<DistributionWithdrawCash>> page(PageParam<DistributionWithdrawCash> page, RangeTimeParam rangeTimeParam,
                                                                String userMobile, DistributionWithdrawCash distributionWithdrawCash) {
        IPage<DistributionWithdrawCash> list = distributionWithdrawCashService.distributionWithdrawCashsPage(page, null, rangeTimeParam, userMobile, distributionWithdrawCash);
        return ResponseEntity.ok(list);
    }

//    /**
//     * 修改
//     */
//    @PutMapping("/toSuccess/{withdrawCashId}")
//    @PreAuthorize("@pms.hasPermission('distribution:distributionWithdrawCash:update')")
//    public ResponseEntity<Void> update(@PathVariable String withdrawCashId) {
//        DistributionWithdrawCash distributionWithdrawCash = distributionWithdrawCashService.getById(withdrawCashId);
//        if (distributionWithdrawCash == null) {
//            throw new GlobalException("无法获取提现信息");
//        }
//        Long walletId = distributionWithdrawCash.getWalletId();
//
//        DistributionUserWallet wallet = distributionUserWalletService.getById(walletId);
//
//        if (wallet == null) {
//            throw new GlobalException("无法获取用户钱包信息");
//        }
//
//        DistributionUser distributionUser = distributionUserService.getById(wallet.getDistributionUserId());
//
//        if (distributionUser == null) {
//            throw new GlobalException("无法获取用户信息");
//        }
//
//        if (!Objects.equals(distributionUser.getShopId(), Constant.PLATFORM_SHOP_ID)) {
//            throw new GlobalException("没有权限修改提现信息");
//        }
//
//        distributionWithdrawCash.setState(1);
//        distributionWithdrawCash.setUpdateTime(new Date());
//        distributionWithdrawCashService.updateById(distributionWithdrawCash);
//        return ResponseEntity.ok().build();
//    }

}
