package com.bohuikeji.delivery.backstage.service.impl;

import com.bohuikeji.delivery.backstage.entity.*;
import com.bohuikeji.delivery.backstage.mapper.TExtractRecordMapper;
import com.bohuikeji.delivery.backstage.service.ITCustomerWalletService;
import com.bohuikeji.delivery.backstage.service.ITExtractRecordService;
import com.bohuikeji.delivery.backstage.service.ITwalletDetailService;
import com.bohuikeji.frame.module.admin.base.ServiceImplBase;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.time.LocalDate;
import java.time.LocalDateTime;

/**
 * <p>
 * 钱包明细 服务实现类
 * </p>
 *
 * @author 10552
 * @since 2019-12-27
 */
@Service
@Slf4j
public class TExtractRecordServiceImpl extends ServiceImplBase<TExtractRecordMapper, TExtractRecord> implements ITExtractRecordService {

    @Autowired
    ITCustomerWalletService customerWalletService;
    @Autowired
    ITwalletDetailService twalletDetailService;

    /**
     * 钱包明细
     * @param tCustomerPay
     * @param pay
     * @param tWxtransfers
     * @param tCustomerWallet
     * @param dace
     * @return
     */
    @Override
    public TWalletDetail saveDetail(TCustomerPay tCustomerPay, TPay pay, TWxtransfers tWxtransfers, TCustomerWallet tCustomerWallet, String dace) {
        LocalDate now = LocalDate.now();
        String time8 = now.getYear()+"年"+now.getMonthValue()+"月"+LocalDateTime.now().getDayOfMonth()+"日"+" "+LocalDateTime.now().getHour()+":"+LocalDateTime.now().getMinute();
        TWalletDetail tWalletDetail = new TWalletDetail();
        if("余额充值".equals(dace)){
            tWalletDetail.setDetailPrice("+"+tCustomerPay.getPayFactPrice());
            tWalletDetail.setDetailBalance(tCustomerWallet.getWalletPrice());
        }
        if("支付退款".equals(dace)){
            tWalletDetail.setDetailPrice("+"+pay.getPayFactPrice());
            tWalletDetail.setDetailBalance(tCustomerWallet.getWalletPrice());
        }
        if("订单支付".equals(dace)){
            tWalletDetail.setDetailPrice("-"+pay.getPayFactPrice());
            tWalletDetail.setDetailBalance(tCustomerWallet.getWalletPrice());
        }
        if("余额提现".equals(dace)){
            tWalletDetail.setDetailPrice("-"+tWxtransfers.getTransfersPrice());
            tWalletDetail.setDetailBalance(tCustomerWallet.getWalletPrice());
        }
        tWalletDetail.setDetailName(dace);
        tWalletDetail.setCustomerId(tCustomerWallet.getCustomerId());
        tWalletDetail.setFranId(tCustomerWallet.getFranId());
        tWalletDetail.setDateTime(time8);
        tWalletDetail.setCreateTime(LocalDateTime.now());
        twalletDetailService.save(tWalletDetail);
        return tWalletDetail;
    }
}
