package com.duowenlvshi.duowenlszp.app.util;

import com.duowenlvshi.duowenlszp.model.Meal.server.MealServer;
import com.duowenlvshi.duowenlszp.app.alPay.alPay;
import com.duowenlvshi.duowenlszp.app.wxPay.WxServiceImpl;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.HashMap;
import java.util.Map;

/**
 * @author yang fang yu
 * @since 2019/9/19 14:46
 */
@Service
public class AllPay {
    @Autowired
    alPay alPay;
    @Autowired
    WxServiceImpl wxService;
    @Autowired
    MealServer mealServer;

    public Map allpay(Map map){
        Map payMap = new HashMap();
        //查询折扣率
       String dd = mealServer.selectDiscount();
       double discount = Double.parseDouble(dd);
       if("2".equals(map.get("payType"))){//支付宝
           payMap.put("Body",map.get("body"));
           payMap.put("Subject","招聘套餐");
           payMap.put("OutTradeNo",map.get("id"));//设置订单id
           String pp = map.get("Price")+"";
           double Price = Double.parseDouble(pp);
           payMap.put("TotalAmount",Price*discount);//设置金额支付宝金额
           Map map1 = new HashMap();
           map1.put("order_info",alPay.pay(payMap));
           return map1;
       }else if("1".equals(map.get("payType"))){//微信
           payMap.put("body",map.get("body"));
           payMap.put("out_trade_no",map.get("id"));//设置订单id
           double Price =(double)map.get("Price")*100*discount;//设置微信金额
           int price =(int)Price;
           payMap.put("total_fee",price);
           return wxService.doUnifiedOrder(payMap);
       }
       return null;
    }
}
