// 引入 request 文件
import request from '@/common/api/request.js'
const url = '/order'

let platformType = '';
let payType='';
// #ifdef MP-WEIXIN
platformType = 'wechat'
payType='WECHAT'
// #endif
// #ifdef MP-ALIPAY
platformType = 'alipay'
payType='ALIPAY'
// #endif

//订单列表
export const APIuserorder = (data) => {
	return request({
		url: url + '/user/order',
		method: 'get',
		data: data
	})
}

//生成订单
export const APIcreateOrder = (data) => {
	return request({
		url: url + '/user/order/createOrder',
		method: 'post',
		data: data
	})
}

//删除订单
export const APIputuserorder = (data) => {
	return request({
		url: url + '/user/order/' + data,
		method: 'put'
	})
}

//历史订单(多次下单使用)
export const APIhistoryOrder = (data) => {
	return request({
		url: url + '/user/order/historyOrder',
		method: 'get',
		data: data,
		toast: false
	})
}

//订单详情
export const APIgetOrderById = (data) => {
	return request({
		url: url + '/user/order/getOrderById',
		method: 'get',
		data: data
	})
}

//删除所有待支付订单
export const APIcancelOrder = (data) => {
	return request({
		url: url + '/user/order/cancelOrder',
		method: 'post',
		data: data
	})
}

//删除某一个待支付订单
export const APIrmPlaceOrder = (data) => {
	return request({
		url: url + '/user/order/rmPlaceOrder',
		method: 'post',
		data: data
	})
}
//会员开通
export const joinMember = (data) => {
	return request({
		url: url + '/user/order/joinMember',
		method: 'post',
		data: data
	})
}
//会员购买支付
export const ltPayMember = (data) => {
	// #ifdef MP-WEIXIN
	const openId=uni.cache.get('userInfo').wechatOpenId;
	// #endif
	// #ifdef MP-ALIPAY
	const openId=uni.cache.get('userInfo').alipayOpenId;
	// #endif
	return request({
		url: url + '/pay/ltPayMember',
		method: 'post',
		data: {
			platformType,
			payType,
			openId,
			...data
		}
	})
}
//智慧充值
export const recharge = (data) => {
	// #ifdef MP-WEIXIN
	const openId=uni.cache.get('userInfo').wechatOpenId;
	// #endif
	// #ifdef MP-ALIPAY
	const openId=uni.cache.get('userInfo').alipayOpenId;
	// #endif
	return request({
		url: url + '/pay/recharge',
		method: 'post',
		data: {
			platformType,
			payType,
			openId,
			...data
		}
	})
}



export const rechargePayOrder = (data) => {
	return request({
		url: url + '/pay/rechargePayOrder',
		method: 'post',
		data: {
			platformType,
			payType,
			openId: uni.cache.get('userInfo').wechatOpenId,
			...data
		}
	})
}

//分销员支付订单
export const distributionLtPayOrder = (data) => {
	return request({
		url: url + '/pay/distribution/ltPayOrder',
		method: 'post',
		data: {
			platformType,
			payType,
			openId: uni.cache.get('userInfo').wechatOpenId,
			...data
		}
	})
}
