【原 因】:根据学校要求 如站点改为地块管理 商铺改为单位 【过 程】: 【影 响】: # 类型 包含: # feat:新功能(feature) # fix:修补bug # docs:文档(documentation) # style: 格式(不影响代码运行的变动) # refactor:重构(即不是新增功能,也不是修改bug的代码变动) # test:增加测试 # chore:构建过程或辅助工具的变动
289 lines
9.3 KiB
JavaScript
289 lines
9.3 KiB
JavaScript
import store from '@/store'
|
||
import api from '@/utils/api'
|
||
// import { Message, MessageBox } from 'element-ui'
|
||
import { Message } from 'element-ui'
|
||
|
||
/**
|
||
* @description: 向对频api 提交数据
|
||
*/
|
||
export async function apiCrosFrequency (params) {
|
||
const data = new URLSearchParams()// post对象参数 转成 字符串连接
|
||
data.append('macAdd', params.macAdd)
|
||
data.append('id', params.id)
|
||
const res = await api.post('crosFrequency', data)
|
||
if (res.data.status === 1) {
|
||
Message.success(res.data.msg)
|
||
store.dispatch('fetchAirList')// 更新飞机列表
|
||
} else {
|
||
Message.error(res.data.msg)
|
||
}
|
||
return res
|
||
}
|
||
/**
|
||
* @description: 锁定地块 相关操作 同步操作订单表 和地块表接口
|
||
* @param {*} form 表单.地块信息
|
||
* @return {*} 服务器返回信息
|
||
*/
|
||
export async function lockSite (form) {
|
||
const params = new URLSearchParams()
|
||
params.append('site_id', form.site_id)
|
||
params.append('shop_id', form.shop_id)
|
||
params.append('runing', form.runing)
|
||
params.append('order_id', form.order_id)
|
||
params.append('shipment_status', form.shipment_status)
|
||
params.append('by_plane_id', form.by_plane_id)
|
||
const res = await api.post('lockSite', params)
|
||
if (res.data.status === 1) {
|
||
await store.dispatch('fetchSiteList')// 刷新地块列表
|
||
store.dispatch('fetchRouteList')// 刷新航线列表
|
||
store.dispatch('fetchPaidOrderList')// 刷订单点列表
|
||
Message.success(res.data.msg)
|
||
} else {
|
||
Message.error(res.data.msg)
|
||
}
|
||
return res
|
||
}
|
||
/**
|
||
* @description: 向改变订单承接任务api 提交数据,参数可以是数组 提交多个字段和字段内容 () ,并更新订单列表
|
||
* @param {*} id 订单id
|
||
* @param {array string} type 主状态"main_status" 货物状态"shipment_status" 退款状态"refund_status" 执行飞机"by_plane_id"
|
||
* @param {array string} val 修改字段的值 ps:by_plane_id值给'' 数据库改为null
|
||
*/
|
||
export async function questAss (id, type, val) {
|
||
const params = new URLSearchParams()// post对象参数 转成 字符串连接
|
||
params.append('id', id)
|
||
// 判断 type 和 val 是否为数组
|
||
if (Array.isArray(type) && Array.isArray(val)) {
|
||
if (type.length !== val.length) {
|
||
return
|
||
}
|
||
for (let i = 0; i < type.length; i++) {
|
||
params.append(type[i], val[i])
|
||
}
|
||
} else if (typeof type === 'string' && typeof val === 'string') {
|
||
params.append(type, val)
|
||
} else {
|
||
return
|
||
}
|
||
|
||
const res = await api.post('questAss', params)
|
||
if (res.data.status === 1) {
|
||
Message.success(res.data.msg)
|
||
store.dispatch('fetchPaidOrderList')// 更新订单列表
|
||
} else {
|
||
Message.error(res.data.msg)
|
||
store.dispatch('fetchPaidOrderList')// 更新订单列表
|
||
}
|
||
return res
|
||
}
|
||
/**
|
||
* @description: 获取订单列表
|
||
* @param {*} orderSerch 搜索条件
|
||
*/
|
||
export async function getOrderList (orderSerch = {}) {
|
||
const params = new URLSearchParams()// post对象参数 转成 字符串连接
|
||
params.append('shop_id', orderSerch.shop_id)
|
||
params.append('start_time', orderSerch.start_time)
|
||
params.append('end_time', orderSerch.end_time)
|
||
params.append('main_status', orderSerch.main_status)
|
||
params.append('shipment_status', orderSerch.shipment_status)
|
||
params.append('refund_status', orderSerch.refund_status)
|
||
params.append('search', orderSerch.search)
|
||
// 发送查询订单列表请求
|
||
const res = await api.post('getOrderList', params, 'Admin')
|
||
return res
|
||
}
|
||
|
||
/**
|
||
* @description: 获取订单详情
|
||
* @param {*} order_id 订单id
|
||
*/
|
||
export async function getOrderDetails (id) {
|
||
const params = new URLSearchParams()// post对象参数 转成 字符串连接
|
||
params.append('id', id)
|
||
// 发送查询订单详情 求情
|
||
const res = await api.post('getOrderDetails', params, 'Admin')
|
||
return res
|
||
}
|
||
|
||
/**
|
||
* @description: 退款函数
|
||
* @param {*} orderSn 订单号
|
||
* @param {*} shopId 单位id
|
||
* @param {*} refundPrice 退款金额 单位元
|
||
* @param {*} refundType 退款类型 'buyer'买家申请 'seller'卖家主动
|
||
*/
|
||
export async function refund (orderSn, shopId, refundPrice, refundType) {
|
||
// 构建请求参数
|
||
const params = new URLSearchParams()
|
||
params.append('order_sn', orderSn)
|
||
params.append('shop_id', shopId)
|
||
params.append('refund_price', refundPrice)
|
||
params.append('refund_type', refundType)
|
||
|
||
// 发送退款请求
|
||
const res = await api.post('refund', params, 'Pay')
|
||
if (res.data.status === 1) {
|
||
Message.success('退款申请中...')
|
||
console.log('退款成功', res.data.msg)
|
||
} else {
|
||
Message.error(res.data.msg)
|
||
console.error('退款失败:', res.data.msg)
|
||
}
|
||
return res
|
||
}
|
||
/**
|
||
* @abstract 录入日志
|
||
* @param {*} log 日志内容
|
||
*/
|
||
export async function addLog (log) {
|
||
// 构建请求参数
|
||
const params = new URLSearchParams()
|
||
params.append('log', log)
|
||
const res = await api.post('addLog', params)
|
||
return res
|
||
}
|
||
|
||
/**
|
||
* @description: 向管理员用户发布公告
|
||
* @param {*} shop_id 单位 ID
|
||
* @param {*} tit 公告标题
|
||
* @param {*} message 公告内容
|
||
* @param {*} idArr 接收公告的管理员ID数组
|
||
* @param {*} endTime 公告截止时间(时间戳,秒级)
|
||
*/
|
||
export async function pubMessage (shopId, tit, message, idArr, endTime) {
|
||
const params = new URLSearchParams()
|
||
params.append('shop_id', shopId)
|
||
params.append('tit', tit)
|
||
params.append('message', message)
|
||
params.append('idArr', idArr.join(',')) // 后端只收字符串
|
||
params.append('endTime', endTime)
|
||
|
||
const res = await api.post('pubMessage', params, 'Admin') // 第三个参数为模块名
|
||
return res
|
||
}
|
||
|
||
/**
|
||
* @description 获取全部公告列表(不限制过期、无admin_id限制)
|
||
* @returns {Promise} 返回接口响应对象
|
||
*/
|
||
export async function getAllMessageList () {
|
||
const res = await api.get('getAllMessageList', 'Admin')
|
||
return res
|
||
}
|
||
|
||
/**
|
||
* @description 删除指定公告
|
||
* @param {Array} delIdArr 要删除的公告 ID 数组
|
||
* @returns {Promise}
|
||
*/
|
||
export async function delMessage (delIdArr) {
|
||
const params = new URLSearchParams()
|
||
params.append('delIdArr', delIdArr.join(',')) // 后端通过 $_POST['delIdArr'] 接收
|
||
|
||
const res = await api.post('deleteMessage', params, 'Admin')
|
||
return res
|
||
}
|
||
|
||
/**
|
||
* @abstract 获取指定飞机组的飞行数据(按时间范围)
|
||
* @param {Array} idArr 飞机ID数组
|
||
* @param {Number} startTime 开始时间
|
||
* @param {Number} endTime 结束时间
|
||
* @returns 飞行数据列表
|
||
*/
|
||
export async function getFlyData (idArr, startTime, endTime) {
|
||
const params = new URLSearchParams()
|
||
params.append('idArr', idArr.join(',')) // 后端只收字符串,用逗号分隔
|
||
params.append('startTime', startTime)
|
||
params.append('endTime', endTime)
|
||
|
||
const res = await api.post('getFlyDataByIdArr', params, 'Plane')
|
||
return res
|
||
}
|
||
|
||
/**
|
||
* @abstract 删除指定的飞行数据记录
|
||
* @param {Array} idArr 飞行数据记录ID数组
|
||
* @returns 删除结果
|
||
*/
|
||
export async function deleteFlyData (idArr) {
|
||
if (!Array.isArray(idArr) || idArr.length === 0) {
|
||
throw new Error('参数错误,idArr 应为非空数组')
|
||
}
|
||
|
||
const params = new URLSearchParams()
|
||
params.append('idArr', idArr.join(',')) // 逗号分隔传给后端
|
||
|
||
const res = await api.post('deleteFlyDataByIdArr', params, 'Plane')
|
||
return res
|
||
}
|
||
/**
|
||
* @abstract 上传保存飞机飞行数据(解锁至加锁 即飞行结束触发)
|
||
* @param {Object} data 包含 id, start_time, end_time, gps_path, distance, power_used
|
||
*/
|
||
export async function saveFlyData (data) {
|
||
const params = new URLSearchParams()
|
||
for (const key in data) {
|
||
params.append(key, data[key])
|
||
}
|
||
const res = await api.post('saveFlyData', params, 'Plane')
|
||
return res
|
||
}
|
||
|
||
/**
|
||
* @description: 保存禁飞区数据
|
||
* @param {string|number} shop_id 单位ID
|
||
* @param {Array} nofly_data 禁飞区数据数组
|
||
* @param {Array} restrictfly_data 限制飞区数据数组
|
||
* @returns {Object|null} 返回接口响应数据 或 null 表示失败
|
||
*/
|
||
export async function setNoflyData (shopId, noflyData) {
|
||
try {
|
||
const params = new URLSearchParams()
|
||
params.append('shop_id', shopId || '')
|
||
params.append('nofly_data', JSON.stringify(noflyData || []))
|
||
|
||
const res = await api.post('setNoflyData', params)
|
||
if (res.data.status === 1) {
|
||
store.dispatch('fetchNoflyData', shopId)// 更新禁限飞区数据
|
||
Message.success(res.data.msg)
|
||
} else {
|
||
Message.warning(res.data.msg)
|
||
}
|
||
return res.data
|
||
} catch (error) {
|
||
Message.error('保存禁飞区数据失败')
|
||
return null
|
||
}
|
||
}
|
||
|
||
/**
|
||
* @description: 保存限飞区数据
|
||
* @param {string|number} shop_id 单位ID
|
||
* @param {Array} restrictfly_data 限制飞区数据数组
|
||
* @param {Array} restrictfly_height 限制飞区数据高度组
|
||
* @returns {Object|null} 返回接口响应数据 或 null 表示失败
|
||
*/
|
||
export async function setRestrictflyData (shopId, restrictflyData, restrictflyHeight) {
|
||
try {
|
||
const params = new URLSearchParams()
|
||
params.append('shop_id', shopId || '')
|
||
params.append('restrictfly_data', JSON.stringify(restrictflyData || []))
|
||
params.append('restrictfly_height', JSON.stringify(restrictflyHeight || []))
|
||
|
||
const res = await api.post('setNoflyData', params)
|
||
if (res.data.status === 1) {
|
||
store.dispatch('fetchNoflyData', shopId)// 更新禁限飞区数据
|
||
Message.success(res.data.msg)
|
||
} else {
|
||
Message.warning(res.data.msg)
|
||
}
|
||
return res.data
|
||
} catch (error) {
|
||
Message.error('保存限飞区数据失败')
|
||
return null
|
||
}
|
||
}
|