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

import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.bohuikeji.delivery.backstage.entity.*;
import com.bohuikeji.delivery.backstage.mapper.TStoreWalletDetailMapper;
import com.bohuikeji.delivery.backstage.mapper.TWalletDetailMapper;
import com.bohuikeji.delivery.backstage.service.ITCustomerWalletService;
import com.bohuikeji.delivery.backstage.service.ITStoreWalletDetailService;
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 TStoreWalletDetailServiceImpl extends ServiceImplBase<TStoreWalletDetailMapper, TStoreWalletDetail> implements ITStoreWalletDetailService {

    @Autowired
    ITCustomerWalletService customerWalletService;
    @Autowired
    ITwalletDetailService twalletDetailService;
    @Autowired
    ITStoreWalletDetailService storeWalletDetailService;

    /**
     *
     * @param courierWithdraw
     * @param storeWallet
     * @return
     */
    @Override
    public TStoreWalletDetail saveDetail(TCourierWithdraw courierWithdraw,TStoreWallet storeWallet) {
        if(storeWallet ==null){
            return null;
        }
        LocalDate now = LocalDate.now();
        String time8 = now.getYear()+"年"+now.getMonthValue()+"月"+LocalDateTime.now().getDayOfMonth()+"日"+" "+LocalDateTime.now().getHour()+":"+LocalDateTime.now().getMinute();
        TStoreWalletDetail storeWalletDetail = new TStoreWalletDetail();
        if("惩罚".equals(courierWithdraw.getWithdrawType())){
            storeWalletDetail.setDetailPrice("+"+courierWithdraw.getApplyAmount());
            storeWalletDetail.setDetailBalance(storeWallet.getWalletPrice());
        }
        if("奖励".equals(courierWithdraw.getWithdrawType())){
            storeWalletDetail.setDetailPrice("-"+courierWithdraw.getApplyAmount());
            storeWalletDetail.setDetailBalance(storeWallet.getWalletPrice());
        }
        storeWalletDetail.setDetailType(courierWithdraw.getWithdrawType());
        storeWalletDetail.setWallletType(storeWallet.getWalletType());
        storeWalletDetail.setFranId(courierWithdraw.getFranId());
        storeWalletDetail.setDateTime(time8);
        storeWalletDetail.setCreateTime(LocalDateTime.now());
        storeWalletDetailService.save(storeWalletDetail);
        return storeWalletDetail;
    }

    @Override
    public TStoreWalletDetail savewalletDetail(TStoreWalletPay walletPay,TStoreWallet storeWallet) {
        TStoreWalletDetail storeWalletDetail = new TStoreWalletDetail();
        LocalDate now = LocalDate.now();
        String time8 = now.getYear()+"年"+now.getMonthValue()+"月"+LocalDateTime.now().getDayOfMonth()+"日"+" "+LocalDateTime.now().getHour()+":"+LocalDateTime.now().getMinute();
        if("门店钱包".equals(storeWallet.getWalletType())){
            storeWalletDetail.setDetailPrice("+"+walletPay.getPayFactPrice());
            storeWalletDetail.setDetailBalance(storeWallet.getWalletPrice());
        }
        storeWalletDetail.setDetailType("充值");
        storeWalletDetail.setWallletType(storeWallet.getWalletType());
        storeWalletDetail.setFranId(storeWallet.getFranId());
        storeWalletDetail.setDateTime(time8);
        storeWalletDetail.setCreateTime(LocalDateTime.now());
        storeWalletDetailService.save(storeWalletDetail);
        return storeWalletDetail;
    }
}
