// +---------------------------------------------------------------------- // | 单店商城API接口 // +---------------------------------------------------------------------- // | 创建时间: 2025-11-08 // +---------------------------------------------------------------------- import request from "@/utils/request.js"; import { HTTP_REQUEST_URL } from '@/config/app.js' // ==================== 一、用户认证模块 ==================== /** * 用户登录 * @param {Object} data - {account: 手机号, password: 密码} * @returns {Promise} */ export function userLogin(data) { return request.post('user/login', data, { noAuth: true }); } /** * 用户注册 * @param {Object} data - {mobile: 手机号, code: 验证码, password: 密码, invite_code: 邀请码(选填)} * @returns {Promise} */ export function userRegister(data) { return request.post('user/register', data, { noAuth: true }); } /** * 获取用户信息 * @returns {Promise} */ export function userInfo() { return request.post('user/info'); } /** * 修改用户昵称 * @param {Object} data - {nickname: 昵称} * @returns {Promise} */ export function updateNickname(data) { return request.post('user/nickname', data); } /** * 修改密码 * @param {Object} data - {old_password: 原密码, new_password: 新密码, code: 验证码} * @returns {Promise} */ export function changePassword(data) { return request.post('user/changepwd', data); } /** * 重置密码 * @param {Object} data - {mobile: 手机号, code: 验证码, password: 新密码} * @returns {Promise} */ export function resetPassword(data) { return request.post('user/resetpwd', data, { noAuth: true }); } /** * 上传用户头像 * @param {Object} data - {file: 头像文件} * @returns {Promise} */ export function uploadAvatar(data) { return request.post('user/avatar', data); } // ==================== 二、商品模块 ==================== /** * 获取商品分类列表 * @returns {Promise} */ export function getGoodsCategory() { return request.get('goods/category', {}, { noAuth: true }); } /** * 获取商品列表 * @param {Object} params - {page: 页码, limit: 每页数量, category_id: 分类ID, keyword: 关键词} * @returns {Promise} */ export function getGoodsList(params) { return request.get('goods/list', params, { noAuth: true }); } /** * 获取商品详情 * @param {Number} id - 商品ID * @returns {Promise} */ export function getGoodsDetail(id) { return request.get('goods/detail', { id }, { noAuth: true }); } // ==================== 三、订单模块 ==================== /** * 获取订单首页数据(营业时间等) * @returns {Promise} */ export function getOrderIndex() { return request.post('order/index'); } /** * 获取可购买商品列表(抢购列表) * @param {Object} params - {page: 页码, limit: 每页数量, type: 类型(1:可购买 0:全部)} * @returns {Promise} */ export function getOrderGoods(params) { return request.get('order/goods', params); } /** * 购买商品(抢单) * @param {Object} data - {id: 寄卖商品ID, seller_id: 卖家用户ID} * @returns {Promise} */ export function buyGoods(data) { return request.post('order/buy', data); } /** * 获取订单列表 * @param {Object} params - {page: 页码, limit: 每页数量, cate: 类型(1:买方仓库 2:卖方仓库), type: 状态(1:寄卖中/交易中 2:已完成)} * @returns {Promise} */ export function getOrderList(params) { return request.get('order/list', params); } /** * 获取订单详情 * @param {Number} order_id - 订单ID * @returns {Promise} */ export function getOrderDetail(order_id) { return request.get('order/detail', { order_id }); } /** * 支付订单 * @param {Object} data - {id: 订单ID} * @returns {Promise} */ export function payOrder(data) { return request.post('order/pay', data); } /** * 确认订单(卖家发货) * @param {Object} data - {id: 订单ID} * @returns {Promise} */ export function confirmOrder(data) { return request.post('order/confirm', data); } /** * 取消订单 * @param {Object} data - {id: 订单ID} * @returns {Promise} */ export function cancelOrder(data) { return request.post('order/cancel', data); } /** * 转卖订单 * @param {Object} data - {id: 订单ID} * @returns {Promise} */ export function resellOrder(data) { return request.post('order/resell', data); } /** * 获取订单统计数量 * @returns {Promise} */ export function getOrderCount() { return request.get('order/count'); } // ==================== 四、地址管理模块 ==================== /** * 获取地址列表 * @returns {Promise} */ export function getAddressList() { return request.get('address/list'); } /** * 获取默认地址 * @returns {Promise} */ export function getDefaultAddress() { return request.post('address/default'); } /** * 新增地址 * @param {Object} data - {name: 姓名, mobile: 手机号, province: 省, city: 市, district: 区, detail: 详细地址, is_default: 是否默认} * @returns {Promise} */ export function addAddress(data) { return request.post('address/insert', data); } /** * 更新地址 * @param {Object} data - {id: 地址ID, name, mobile, province, city, district, detail, is_default} * @returns {Promise} */ export function updateAddress(data) { return request.post('address/update', data); } /** * 删除地址 * @param {Object} data - {id: 地址ID} * @returns {Promise} */ export function deleteAddress(data) { return request.post('address/delete', data); } /** * 获取地址详情 * @param {Number} id - 地址ID * @returns {Promise} */ export function getAddressDetail(id) { return request.get('address/detail', { id }); } // ==================== 五、财务模块 ==================== /** * 获取财务记录列表 * @param {Object} params - {page: 页码, limit: 每页数量, cate: 类型(1:分红 2:优惠券 3:推广), type: 收支(1:收入 2:支出)} * @returns {Promise} */ export function getMoneyList(params) { return request.get('money/list', params); } /** * 获取提现记录 * @param {Object} params - {page: 页码, limit: 每页数量} * @returns {Promise} */ export function getWithdrawLog(params) { return request.get('money/log', params); } /** * 申请提现 * @param {Object} data - {amount: 金额, type: 方式(1:支付宝 2:银行卡)} * @returns {Promise} */ export function applyWithdraw(data) { return request.post('money/withdraw', data); } // ==================== 六、支付方式模块 ==================== /** * 获取支付宝信息 * @returns {Promise} */ export function getAlipayInfo() { return request.get('alipay/index'); } /** * 绑定支付宝 * @param {Object} data - {account: 支付宝账号, real_name: 真实姓名} * @returns {Promise} */ export function bindAlipay(data) { return request.post('alipay/bind', data); } /** * 获取银行卡信息 * @returns {Promise} */ export function getBankInfo() { return request.get('bank/index'); } /** * 绑定银行卡 * @param {Object} data - {bank_name: 银行名称, card_no: 卡号, real_name: 真实姓名, bank_branch: 开户支行} * @returns {Promise} */ export function bindBank(data) { return request.post('bank/bind', data); } // ==================== 七、分享推广模块 ==================== /** * 获取分享首页数据(邀请码、统计等) * @returns {Promise} */ export function getShareIndex() { return request.get('share/index'); } /** * 获取我的粉丝列表 * @param {Object} params - {page: 页码, limit: 每页数量, level: 等级(1,2,3)} * @returns {Promise} */ export function getFansList(params) { return request.get('share/select', params); } // ==================== 八、首页模块 ==================== /** * 获取轮播图 * @returns {Promise} */ export function getBannerList() { return request.get('index/banner', {}, { noAuth: true }); } /** * 获取首页配置数据 * @returns {Promise} */ export function getIndexConfig() { return request.post('index/get', {}, { noAuth: true }); } // ==================== 九、短信模块 ==================== /** * 发送短信验证码 * @param {Object} data - {mobile: 手机号, event: 事件类型(register/resetpwd/changepwd)} * @returns {Promise} */ export function sendSms(data) { return request.post('sms/send', data, { noAuth: true }); } // ==================== 十、设置模块 ==================== /** * 获取协议内容 * @param {Object} params - {type: 类型(user/privacy/sale)} * @returns {Promise} */ export function getAgreement(params) { return request.get('setting/agreement', params, { noAuth: true }); } /** * 获取系统配置 * @returns {Promise} */ export function getSetting() { return request.get('setting/index', {}, { noAuth: true }); } // ==================== 十一、合同模块 ==================== /** * 获取合同列表 * @returns {Promise} */ export function getContractList() { return request.get('contract/list'); } /** * 获取合同详情 * @param {Number} id - 合同ID * @returns {Promise} */ export function getContractDetail(id) { return request.get('contract/detail', { id }); } // ==================== 十二、奖品模块 ==================== /** * 获取奖品列表 * @param {Object} params - {page: 页码, limit: 每页数量} * @returns {Promise} */ export function getPrizeList(params) { return request.get('prize/list', params); } // ==================== 十三、签名回调 ==================== /** * 签名回调 * @param {Object} data - 签名数据 * @returns {Promise} */ export function signNotify(data) { return request.post('notify/sign', data, { noAuth: true }); } // ==================== 辅助函数 ==================== /** * 通用上传文件 * @param {String} filePath - 文件路径 * @param {String} uploadUrl - 上传接口(可选,默认 upload/image) * @returns {Promise} */ export function uploadFile(filePath, uploadUrl = 'upload/image') { return new Promise((resolve, reject) => { const token = uni.getStorageSync('token'); uni.uploadFile({ url: request.baseUrl + uploadUrl, filePath: filePath, name: 'file', header: { 'Authori-zation': 'Bearer ' + token }, success: (uploadRes) => { try { const data = JSON.parse(uploadRes.data); if (data.code === 0) { resolve(data); } else { reject(data); } } catch (error) { reject(error); } }, fail: (error) => { reject(error); } }); }); } export function uploadUserImage(filePath, pid, model = 'user') { return new Promise((resolve, reject) => { const token = uni.getStorageSync('token'); uni.uploadFile({ url: HTTP_REQUEST_URL + '/api/front/wa/user/image', filePath, name: 'multipart', header: { 'Authori-zation': 'Bearer ' + token }, formData: { model, pid }, success: (res) => { try { const data = JSON.parse(res.data) if (data.code === 0) resolve(data) else reject(data) } catch (e) { reject(e) } }, fail: (err) => reject(err) }) }) } /** * 批量导出所有API(兼容旧代码) */ export default { // 用户认证 userLogin, userRegister, userInfo, updateNickname, changePassword, resetPassword, uploadAvatar, // 商品 getGoodsCategory, getGoodsList, getGoodsDetail, // 订单 getOrderIndex, getOrderGoods, buyGoods, getOrderList, getOrderDetail, payOrder, confirmOrder, cancelOrder, resellOrder, getOrderCount, // 地址 getAddressList, getDefaultAddress, addAddress, updateAddress, deleteAddress, getAddressDetail, // 财务 getMoneyList, getWithdrawLog, applyWithdraw, // 支付方式 getAlipayInfo, bindAlipay, getBankInfo, bindBank, // 分享推广 getShareIndex, getFansList, // 首页 getBannerList, getIndexConfig, // 短信 sendSms, // 设置 getAgreement, getSetting, // 合同 getContractList, getContractDetail, // 奖品 getPrizeList, // 签名 signNotify, // 工具 uploadFile, uploadUserImage };