package com.hfkj.service.impl;

import com.alibaba.fastjson.JSONObject;
import com.hfkj.common.exception.ErrorCode;
import com.hfkj.common.exception.ErrorHelp;
import com.hfkj.common.exception.SysCode;
import com.hfkj.common.utils.HttpsUtils;
import com.hfkj.config.CommonSysConst;
import com.hfkj.service.UserDiscountService;
import org.springframework.stereotype.Service;

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

/**
 * @className: UserDiscountServiceImpl
 * @author: HuRui
 * @date: 2023/3/29
 **/
@Service("userDiscountService")
public class UserDiscountServiceImpl implements UserDiscountService {
    @Override
    public void userDiscountUse(Long userDiscountId, String userPhone) {
        try {
            Map<String, Object> param = new HashMap<>();
            param.put("userDiscountId", userDiscountId);
            param.put("userPhone", userPhone);
            JSONObject jsonObject = HttpsUtils.doGet(CommonSysConst.getSysConfig().getHsg_domain_name() + "user/discount/hzfUserDiscountUse", param);
            if (!jsonObject.getString("return_code").equals("000000")) {
                throw ErrorHelp.genException(SysCode.System, ErrorCode.COMMON_ERROR, jsonObject.getString("return_data"));
            }
        } catch (Exception e) {
            System.out.println(e);
        }
    }

    @Override
    public void userDiscountReturn(Long userDiscountId, String userPhone) {
        try {
            Map<String, Object> param = new HashMap<>();
            param.put("userDiscountId", userDiscountId);
            param.put("userPhone", userPhone);
            JSONObject jsonObject = HttpsUtils.doGet(CommonSysConst.getSysConfig().getHsg_domain_name() + "user/discount/hzfUserDiscountReturn", param);
            if (!jsonObject.getString("return_code").equals("000000")) {
                throw ErrorHelp.genException(SysCode.System, ErrorCode.COMMON_ERROR, jsonObject.getString("return_data"));
            }
        } catch (Exception e) {
            System.out.println(e);
        }
    }
}
