consumer模块完成度95%,优化安卓端界面和小程序测试2
This commit is contained in:
@@ -1,5 +1,6 @@
|
||||
import supa from '@/components/supadb/aksupainstance.uts'
|
||||
import type { AkReqResponse } from '@/uni_modules/ak-req/index.uts'
|
||||
import type { OrderOptions } from '@/components/supadb/aksupa.uts'
|
||||
|
||||
const OLD_URL = '192.168.1.61:18000'
|
||||
const NEW_URL = '119.146.131.237:9126'
|
||||
@@ -3513,7 +3514,10 @@ class SupabaseService {
|
||||
}
|
||||
itemJson.set('image_url', imgUrl)
|
||||
|
||||
const iPrice = item.getNumber('price') ?? 0
|
||||
const iPriceRaw = item.getNumber('price') ?? 0
|
||||
const iMemberPrice = item.getNumber('member_price') ?? 0
|
||||
// 优先使用会员价
|
||||
const iPrice = (iMemberPrice > 0 && iMemberPrice < iPriceRaw) ? iMemberPrice : iPriceRaw
|
||||
const iQty = item.getNumber('quantity') ?? 1
|
||||
itemJson.set('price', iPrice)
|
||||
itemJson.set('quantity', iQty)
|
||||
@@ -3594,7 +3598,12 @@ class SupabaseService {
|
||||
|
||||
for(let gi = 0; gi < gItems.length; gi++) {
|
||||
const it = JSON.parse(JSON.stringify(gItems[gi])) as UTSJSONObject
|
||||
const itPrice = it.getNumber('price') ?? 0
|
||||
// 优先使用会员价
|
||||
let itPrice = it.getNumber('price') ?? 0
|
||||
const itMemberPrice = it.getNumber('member_price') ?? 0
|
||||
if (itMemberPrice > 0 && itMemberPrice < itPrice) {
|
||||
itPrice = itMemberPrice
|
||||
}
|
||||
const itQty = it.getNumber('quantity') ?? 1
|
||||
grandTotal += itPrice * itQty
|
||||
}
|
||||
@@ -3610,7 +3619,12 @@ class SupabaseService {
|
||||
let productAmount = 0.0
|
||||
for(let j = 0; j < shopItems.length; j++) {
|
||||
const sItem = JSON.parse(JSON.stringify(shopItems[j])) as UTSJSONObject
|
||||
const siPrice = sItem.getNumber('price') ?? 0
|
||||
// 优先使用会员价
|
||||
let siPrice = sItem.getNumber('price') ?? 0
|
||||
const siMemberPrice = sItem.getNumber('member_price') ?? 0
|
||||
if (siMemberPrice > 0 && siMemberPrice < siPrice) {
|
||||
siPrice = siMemberPrice
|
||||
}
|
||||
const siQty = sItem.getNumber('quantity') ?? 1
|
||||
productAmount += siPrice * siQty
|
||||
}
|
||||
@@ -5495,6 +5509,42 @@ class SupabaseService {
|
||||
}
|
||||
}
|
||||
|
||||
// 上传聊天图片
|
||||
async uploadChatImage(filePath: string): Promise<string> {
|
||||
const userId = this.getCurrentUserId()
|
||||
if (userId == null) {
|
||||
console.error("uploadChatImage failed: user not logged in")
|
||||
return ''
|
||||
}
|
||||
|
||||
try {
|
||||
// 生成唯一文件名
|
||||
const timestamp = Date.now()
|
||||
const randomStr = Math.random().toString(36).substring(2, 8)
|
||||
const fileName = `chat_${userId}_${timestamp}_${randomStr}.jpg`
|
||||
const storagePath = `chat-images/${fileName}`
|
||||
|
||||
console.log('[uploadChatImage] 开始上传:', filePath, '->', storagePath)
|
||||
|
||||
const response = await supa.storage
|
||||
.from('chat')
|
||||
.upload(storagePath, filePath, {})
|
||||
|
||||
if (response.error != null) {
|
||||
console.error('[uploadChatImage] 上传失败:', response.error)
|
||||
return ''
|
||||
}
|
||||
|
||||
// 构建公开访问URL
|
||||
const publicUrl = `${supa.baseUrl}/storage/v1/object/public/chat/${storagePath}`
|
||||
console.log('[uploadChatImage] 上传成功:', publicUrl)
|
||||
return publicUrl
|
||||
} catch (e) {
|
||||
console.error('[uploadChatImage] 上传异常:', e)
|
||||
return ''
|
||||
}
|
||||
}
|
||||
|
||||
// 标记会话已读
|
||||
async markRead(merchantId: string): Promise<boolean> {
|
||||
const userId = this.getCurrentUserId()
|
||||
@@ -7496,8 +7546,8 @@ class SupabaseService {
|
||||
const res = await supa
|
||||
.from('ml_member_levels')
|
||||
.select('*')
|
||||
.eq('status', 1)
|
||||
.order('sort_order', { ascending: true })
|
||||
.eq('is_active', true)
|
||||
.order('level_rank', { ascending: true } as OrderOptions)
|
||||
.execute()
|
||||
|
||||
if (res.error != null || res.data == null) {
|
||||
@@ -7528,15 +7578,15 @@ class SupabaseService {
|
||||
const userId = this.getCurrentUserId()
|
||||
if (userId == null) return result
|
||||
|
||||
// 获取用户信息
|
||||
// 获取用户信息(包括 tier_id)
|
||||
const userRes = await supa
|
||||
.from('ml_user_profiles')
|
||||
.select('member_level, total_spent, manual_level')
|
||||
.select('tier_id, total_spent, manual_level')
|
||||
.eq('user_id', userId!)
|
||||
.limit(1)
|
||||
.execute()
|
||||
|
||||
let memberLevel = 0
|
||||
let tierId: string = ''
|
||||
let totalSpent = 0
|
||||
let manualLevel = false
|
||||
|
||||
@@ -7546,7 +7596,7 @@ class SupabaseService {
|
||||
const item = arr[0]
|
||||
const itemAny = item as any
|
||||
if (itemAny instanceof UTSJSONObject) {
|
||||
memberLevel = itemAny.getNumber('member_level') ?? 0
|
||||
tierId = itemAny.getString('tier_id') ?? ''
|
||||
totalSpent = itemAny.getNumber('total_spent') ?? 0
|
||||
manualLevel = itemAny.getBoolean('manual_level') ?? false
|
||||
}
|
||||
@@ -7559,46 +7609,57 @@ class SupabaseService {
|
||||
let discount = 1.0
|
||||
let nextLevel: UTSJSONObject | null = null
|
||||
let progressPercent = 0
|
||||
let currentLevelRank = 0
|
||||
|
||||
// 通过 tier_id 匹配等级
|
||||
for (let i = 0; i < levels.length; i++) {
|
||||
const level = levels[i]
|
||||
const levelAny = level as any
|
||||
let levelId = 0
|
||||
let levelId = ''
|
||||
let levelNameStr = ''
|
||||
let levelRank = 0
|
||||
let levelDiscount = 1.0
|
||||
let levelMinAmount = 0
|
||||
|
||||
if (levelAny instanceof UTSJSONObject) {
|
||||
levelId = levelAny.getNumber('id') ?? 0
|
||||
levelId = levelAny.getString('id') ?? ''
|
||||
levelNameStr = levelAny.getString('name') ?? ''
|
||||
levelDiscount = levelAny.getNumber('discount') ?? 1.0
|
||||
levelMinAmount = levelAny.getNumber('min_amount') ?? 0
|
||||
levelRank = levelAny.getNumber('level_rank') ?? 0
|
||||
levelDiscount = levelAny.getNumber('discount_rate') ?? 1.0
|
||||
}
|
||||
|
||||
if (levelId === memberLevel) {
|
||||
// 通过 tier_id 匹配当前等级
|
||||
if (levelId == tierId) {
|
||||
levelName = levelNameStr
|
||||
discount = levelDiscount
|
||||
}
|
||||
|
||||
// 找下一等级
|
||||
if (levelId > memberLevel && nextLevel == null) {
|
||||
const nextLevelObj = new UTSJSONObject()
|
||||
nextLevelObj.set('id', levelId)
|
||||
nextLevelObj.set('name', levelNameStr)
|
||||
nextLevelObj.set('min_amount', levelMinAmount)
|
||||
nextLevel = nextLevelObj
|
||||
|
||||
// 计算进度
|
||||
if (levelMinAmount > 0) {
|
||||
const currentLevelMinAmount = this.getCurrentLevelMinAmount(levels, memberLevel)
|
||||
const progressRange = levelMinAmount - currentLevelMinAmount
|
||||
const currentProgress = totalSpent - currentLevelMinAmount
|
||||
progressPercent = Math.min(100, Math.round((currentProgress / progressRange) * 100))
|
||||
}
|
||||
currentLevelRank = levelRank
|
||||
}
|
||||
}
|
||||
|
||||
result.set('member_level', memberLevel)
|
||||
// 找下一等级(level_rank 更大的第一个等级)
|
||||
for (let i = 0; i < levels.length; i++) {
|
||||
const level = levels[i]
|
||||
const levelAny = level as any
|
||||
let levelRank = 0
|
||||
let levelNameStr = ''
|
||||
let levelMinAmount = 0
|
||||
|
||||
if (levelAny instanceof UTSJSONObject) {
|
||||
levelRank = levelAny.getNumber('level_rank') ?? 0
|
||||
levelNameStr = levelAny.getString('name') ?? ''
|
||||
levelMinAmount = levelAny.getNumber('min_amount') ?? 0
|
||||
}
|
||||
|
||||
if (levelRank > currentLevelRank && nextLevel == null) {
|
||||
const nextLevelObj = new UTSJSONObject()
|
||||
const levelObj = level as UTSJSONObject
|
||||
nextLevelObj.set('id', levelObj.getString('id') ?? '')
|
||||
nextLevelObj.set('name', levelNameStr)
|
||||
nextLevelObj.set('min_amount', levelMinAmount)
|
||||
nextLevel = nextLevelObj
|
||||
}
|
||||
}
|
||||
|
||||
result.set('member_level', currentLevelRank)
|
||||
result.set('level_name', levelName)
|
||||
result.set('discount', discount)
|
||||
result.set('total_spent', totalSpent)
|
||||
|
||||
Reference in New Issue
Block a user