package com.fs.store.service.handler;

import com.fs.common.core.domain.R;
import com.fs.common.core.redis.RedisCache;
import com.fs.huifuPay.domain.HuiFuCreateOrder;
import com.fs.huifuPay.domain.HuifuCreateOrderResult;
import com.fs.huifuPay.service.impl.HuiFuServiceImpl;
import com.fs.store.domain.FsStoreOrder;
import com.fs.store.domain.FsStorePayment;
import com.fs.store.domain.FsUser;
import com.fs.store.mapper.FsStorePaymentMapper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.concurrent.TimeUnit;

@Service
public class HfPaymentHandler extends PaymentHandler{


//    @Override
//    public R process(FsStoreOrder order, FsUser user, String payCode, FsStorePayment storePayment) {
//        HuiFuCreateOrder o = new HuiFuCreateOrder();
//        o.setTradeType("T_MINIAPP");
//        o.setOpenid(user.getMaOpenId());
//        o.setReqSeqId("store-"+ storePayment.getPayCode());
//        o.setTransAmt(storePayment.getPayMoney().toString());
//        o.setGoodsDesc("商城订单支付");
//        HuifuCreateOrderResult result = huiFuService.createOrder(o);
//        //创建订单
//        if(result.getResp_code()!=null&&(result.getResp_code().equals("00000000")||result.getResp_code().equals("00000100"))){
//            FsStorePayment mt=new FsStorePayment();
//            mt.setPaymentId(storePayment.getPaymentId());
//            mt.setTradeNo(result.getHf_seq_id());
//            fsStorePaymentMapper.updateFsStorePayment(mt);
//            redisCache.setCacheObject("isPaying:"+ order.getId(), order.getId().toString(),1, TimeUnit.MINUTES);
//            return R.ok().put("payType", param.getPayType()).put("result", result.getPay_info());
//        }
//        else{
//            return R.error(result.getResp_desc());
//        }
//
//        return null;
//    }

    @Override
    public boolean support(String code) {
        return "hf".equals(code);
    }
}
