Commit bd5ce321 by 张立顺

feat 功能联调

1 parent bf5016f0
......@@ -25,7 +25,8 @@ import {
import { enqueueServiceNoticePopup } from '~/utils/serviceNoticePopupHandler.js'
import {
loadAbnormalFlowTipState,
dismissAbnormalFlowTip
dismissAbnormalFlowTip,
openAbnormalFlowTransactionPopup
} from '../../../tabIndex/services/abnormalFlowTipService.js'
import {
shouldSkipStaffOrderValid,
......@@ -732,9 +733,9 @@ Page({
onAbnormalFlowTipClose() {
dismissAbnormalFlowTip(this)
},
/** 跳转异常流水审批清单 */
/** 异常流水吸底「去处理」:打开选流水弹窗 */
onAbnormalFlowTipAction() {
wx.$router.go('tabWorkOrder.abnormalFlowList')
openAbnormalFlowTransactionPopup(this)
},
/**
......
......@@ -3,7 +3,8 @@ import api from '~/api/api.js'
import { navigateToStaffDailyReport } from '~/utils/staffDailyReportNavigation.js'
import {
isAbnormalFlowLockActive,
shouldBypassAbnormalFlowLock
shouldBypassAbnormalFlowLock,
shouldCallAbnormalFlowShopLockApi
} from '~/utils/abnormalFlowLock.helpers.js'
// import {
// checkUsedCarStaffIsNew,
......@@ -294,6 +295,10 @@ const checkAbnormalFlowLock = (context = {}, priority = 3) => {
resolve(false)
return
}
if (!shouldCallAbnormalFlowShopLockApi()) {
resolve(false)
return
}
api
.checkAbnormalFlowShopLock({ merchantId })
.then(res => {
......
......@@ -19,7 +19,8 @@ import {
import { navigateToStaffDailyReport } from '~/utils/staffDailyReportNavigation.js'
import {
loadAbnormalFlowTipState,
dismissAbnormalFlowTip
dismissAbnormalFlowTip,
openAbnormalFlowTransactionPopup
} from '../../services/abnormalFlowTipService.js'
import { openOrderPromptWithRestrictState } from '../../services/newOrderAbnormalFlowRestrict.service.js'
import { confirmOrderPrompt } from '../../services/orderPromptConfirm.service.js'
......@@ -463,9 +464,9 @@ Page({
onAbnormalFlowTipClose() {
dismissAbnormalFlowTip(this)
},
/** 跳转异常流水审批清单 */
/** 异常流水吸底「去处理」:打开选流水弹窗 */
onAbnormalFlowTipAction() {
wx.$router.go('tabWorkOrder.abnormalFlowList')
openAbnormalFlowTransactionPopup(this)
},
// 确定是否要显示
showSelectType({ scene = '', item = {} }) {
......
......@@ -5,7 +5,6 @@ import { waitInputOrderUnionCount } from '~/api/abnormalFlowDeclaration.js'
import {
buildAbnormalFlowTipText,
hasUnprocessedAbnormalFlow,
isAbnormalFlowReminderDay,
markAbnormalFlowTipDismissed,
resolveAbnormalFlowTipCount,
shouldShowAbnormalFlowTip
......@@ -13,49 +12,32 @@ import {
const STORAGE_KEY = 'abnormalFlowPop'
/** 嘀加二维码收款,与新建工单补录选流水路径一致 */
const DJ_QR_PAYMENT_METHOD = 5
/**
* 当前登录会话 id(登录周期去重)
* 当前登录会话 id(与登录/登出 dj_boutique_sessionId 对齐)
* @returns {string}
*/
function getLoginSessionId() {
const sessionId = wx.$storage?.get?.('sessionId')
const sessionId = wx.$util?.getSessionId?.()
if (sessionId) return String(sessionId)
const fallback = wx.$storage?.get?.('sessionId')
if (fallback) return String(fallback)
const userInfo = wx.$util?.getUserInfo?.() || {}
return String(userInfo.uuid || userInfo.staffUuid || '')
}
/**
* 解析门店 id(精品 / 权益字段略有差异)
* @param {Object} userInfo
* @returns {string|number}
*/
function resolveMerchantId(userInfo) {
return (
userInfo?.shopMerchantId ||
userInfo?.default4SStoreInfo?.merchantId ||
''
)
}
/**
* onShow 拉取异常流水提醒(dj.api.smartcarlife.weapp.waitinputorder.union.count)
* @param {Object} page - Page / Component 实例
* @returns {Promise<{ show: boolean, count: number }>}
*/
export function loadAbnormalFlowTipState(page) {
const userInfo = wx.$util.getUserInfo()
const merchantId = resolveMerchantId(userInfo)
const sessionId = getLoginSessionId()
const storage = wx.$storage.get(STORAGE_KEY) || {}
if (!isAbnormalFlowReminderDay()) {
page.setData({
abnormalFlowTips: { show: false, count: 0, tipsText: '' }
})
return Promise.resolve({ show: false, count: 0 })
}
if (!shouldShowAbnormalFlowTip(storage, merchantId, sessionId)) {
if (!shouldShowAbnormalFlowTip(storage, sessionId)) {
page.setData({
abnormalFlowTips: { show: false, count: 0, tipsText: '' }
})
......@@ -86,15 +68,24 @@ export function loadAbnormalFlowTipState(page) {
* @param {Object} page
*/
export function dismissAbnormalFlowTip(page) {
const userInfo = wx.$util.getUserInfo()
const merchantId = resolveMerchantId(userInfo)
const sessionId = getLoginSessionId()
const storage = wx.$storage.get(STORAGE_KEY) || {}
wx.$storage.set(
STORAGE_KEY,
markAbnormalFlowTipDismissed(storage, merchantId, sessionId)
markAbnormalFlowTipDismissed(storage, sessionId)
)
page.setData({
'abnormalFlowTips.show': false
})
}
/**
* 吸底「去处理」:打开选流水弹窗(不调 API;确认后由页面 navigator 传参建单)
* @param {Object} page - tabIndex index 或 equityPage 实例(须实现 tipsEvent)
*/
export function openAbnormalFlowTransactionPopup(page) {
page.setData({ paymentMethod: DJ_QR_PAYMENT_METHOD })
if (typeof page.tipsEvent === 'function') {
page.tipsEvent()
}
}
......@@ -5,7 +5,10 @@ import {
checkAbnormalFlowShopLock,
waitInputOrderUnionCount
} from '~/api/abnormalFlowDeclaration.js'
import { shouldRestrictNewOrderToDjQrOnly } from '~/utils/abnormalFlowLock.helpers.js'
import {
shouldCallAbnormalFlowShopLockApi,
shouldRestrictNewOrderToDjQrOnly
} from '~/utils/abnormalFlowLock.helpers.js'
/**
* 解析门店 id(精品 / 权益字段略有差异)
......@@ -31,14 +34,21 @@ export async function loadNewOrderRestrictState() {
return { djQrOnlyMode: false }
}
const now = new Date()
const needShopLockApi = shouldCallAbnormalFlowShopLockApi(now)
try {
const [lockRes, countRes] = await Promise.all([
checkAbnormalFlowShopLock({ merchantId }),
waitInputOrderUnionCount()
])
const countRes = await waitInputOrderUnionCount()
const countData = countRes?.data
let shopLockData = null
if (needShopLockApi) {
const lockRes = await checkAbnormalFlowShopLock({ merchantId })
shopLockData = lockRes?.data
}
const djQrOnlyMode = shouldRestrictNewOrderToDjQrOnly(
lockRes?.data,
countRes?.data
shopLockData,
countData,
now
)
return { djQrOnlyMode }
} catch {
......
......@@ -142,6 +142,19 @@ export function formatPayAmount(amount) {
}
/**
* 格式化交易时间展示(统一 yyyy-MM-dd HH:mm:ss,兼容时间戳与接口字符串)
* @param {string|number|Date} value
* @returns {string}
*/
export function formatTradeTime(value) {
if (value === undefined || value === null || value === '') return ''
const date = new Date(value)
if (Number.isNaN(date.getTime())) return String(value)
const pad = n => String(n).padStart(2, '0')
return `${date.getFullYear()}-${pad(date.getMonth() + 1)}-${pad(date.getDate())} ${pad(date.getHours())}:${pad(date.getMinutes())}:${pad(date.getSeconds())}`
}
/**
* 分转元
* @param {string|number} fen
* @returns {number}
......@@ -190,7 +203,7 @@ export function mapPendingListItem(item = {}) {
merchantName:
item.shopMerchantName || item.yqMerchantName || item.merchantName || '',
tradeRefNo: item.tradeNo || '',
tradeTime: item.accountDate || '',
tradeTime: formatTradeTime(item.accountDate),
payAmount,
payAmountDisplay: formatPayAmount(payAmount),
statusStyle: PENDING_STATUS_STYLE,
......@@ -209,7 +222,7 @@ export function mapReportedListItem(item = {}) {
id: item.id,
merchantName: item.merchantName || '',
tradeRefNo: item.tradeNo || '',
tradeTime: item.accountDate || '',
tradeTime: formatTradeTime(item.accountDate),
payAmount: Number.isFinite(payAmount) ? payAmount : item.totalPrice,
payAmountDisplay: formatPayAmount(item.totalPrice),
approvalStatus: item.approvalStatus,
......@@ -253,7 +266,7 @@ export function mapDetailFromApi(data = {}) {
id: trade.declarationId || data.id,
merchantName: trade.merchantName || trade.yqMerchantName || '',
tradeRefNo: trade.tradeNo || '',
tradeTime: trade.payDate || '',
tradeTime: formatTradeTime(trade.payDate),
payAmount,
payAmountDisplay: formatPayAmount(payAmount),
abnormalType: decl.abnormalType,
......
......@@ -5,6 +5,8 @@ describe('abnormalFlowLock.helpers', async () => {
const {
ABNORMAL_FLOW_LOCK_BYPASS,
isAbnormalFlowReminderDay,
shouldCallAbnormalFlowShopLockApi,
shouldRestrictNewOrderToDjQrOnly,
shouldShowAbnormalFlowTip,
markAbnormalFlowTipDismissed,
isAbnormalFlowLockActive,
......@@ -18,13 +20,21 @@ describe('abnormalFlowLock.helpers', async () => {
it('reminder day Mon-Wed only', () => {
assert.equal(isAbnormalFlowReminderDay(new Date('2026-07-06')), true)
assert.equal(isAbnormalFlowReminderDay(new Date('2026-07-09')), false)
assert.equal(isAbnormalFlowReminderDay(new Date('2026-07-05')), false)
})
it('tip dismiss by session + merchant', () => {
assert.equal(shouldShowAbnormalFlowTip(null, '1001', 's1'), true)
const storage = markAbnormalFlowTipDismissed(null, '1001', 's1')
assert.equal(shouldShowAbnormalFlowTip(storage, '1001', 's1'), false)
assert.equal(shouldShowAbnormalFlowTip(storage, '1001', 's2'), true)
it('shouldCallAbnormalFlowShopLockApi Thu-Sun only', () => {
assert.equal(shouldCallAbnormalFlowShopLockApi(new Date('2026-07-06')), false)
assert.equal(shouldCallAbnormalFlowShopLockApi(new Date('2026-07-09')), true)
assert.equal(shouldCallAbnormalFlowShopLockApi(new Date('2026-07-05')), true)
})
it('tip dismiss for entire login session', () => {
assert.equal(shouldShowAbnormalFlowTip(null, 's1'), true)
const storage = markAbnormalFlowTipDismissed(null, 's1')
assert.equal(shouldShowAbnormalFlowTip(storage, 's1'), false)
assert.equal(shouldShowAbnormalFlowTip(storage, 's2'), true)
assert.equal(shouldShowAbnormalFlowTip(storage, 's1'), false)
})
it('lock active for boolean true and legacy flags', () => {
......@@ -83,32 +93,39 @@ describe('abnormalFlowLock.helpers', async () => {
assert.match(buildAbnormalFlowTipText(3), /3笔异常流水/)
})
it('shouldRestrictNewOrderToDjQrOnly when lock on and pending flows', async () => {
const { shouldRestrictNewOrderToDjQrOnly } = await import(
'../utils/abnormalFlowLock.helpers.js'
it('shouldRestrictNewOrderToDjQrOnly by weekday', () => {
const lockOn = { lockControlEnabled: 'Y', lockFlowFlag: 'Y' }
const countPending = { totalCount: 2 }
const countEmpty = { totalCount: 0 }
const mon = new Date('2026-07-06')
assert.equal(
shouldRestrictNewOrderToDjQrOnly(null, countPending, mon),
true
)
assert.equal(
shouldRestrictNewOrderToDjQrOnly(
{ lockControlEnabled: 'Y', lockFlowFlag: 'Y' },
{ totalCount: 2 }
),
shouldRestrictNewOrderToDjQrOnly(lockOn, countPending, mon),
true
)
assert.equal(
shouldRestrictNewOrderToDjQrOnly(
{ lockControlEnabled: 'Y', lockFlowFlag: 'Y' },
{ totalCount: 0 }
),
shouldRestrictNewOrderToDjQrOnly(lockOn, countEmpty, mon),
false
)
const thu = new Date('2026-07-09')
assert.equal(
shouldRestrictNewOrderToDjQrOnly(false, { totalCount: 5 }),
shouldRestrictNewOrderToDjQrOnly(null, countPending, thu),
false
)
assert.equal(
shouldRestrictNewOrderToDjQrOnly(lockOn, countPending, thu),
true
)
assert.equal(
shouldRestrictNewOrderToDjQrOnly(
{ lockControlEnabled: 'N', lockFlowFlag: 'Y' },
{ notDeclaredCount: 3 }
countPending,
thu
),
false
)
......
......@@ -8,6 +8,7 @@ describe('abnormalFlowReport.helpers', async () => {
getApprovalStatusStyle,
getBgApprovalStatusText,
getAbnormalTypeLabel,
formatTradeTime,
validateReportForm,
fenToYuan,
mapUnionCount,
......@@ -53,6 +54,17 @@ describe('abnormalFlowReport.helpers', async () => {
assert.equal(fenToYuan(152052), 1520.52)
})
it('formatTradeTime normalizes timestamp and date string', () => {
assert.equal(
formatTradeTime('2020-06-12 15:12:52'),
'2020-06-12 15:12:52'
)
const ts = new Date('2020-06-12 15:12:52').getTime()
assert.equal(formatTradeTime(ts), '2020-06-12 15:12:52')
assert.equal(formatTradeTime(''), '')
assert.equal(formatTradeTime(null), '')
})
it('mapUnionCount reads tab totals', () => {
assert.deepEqual(
mapUnionCount({
......@@ -76,6 +88,7 @@ describe('abnormalFlowReport.helpers', async () => {
assert.equal(item.tradeRefNo, 'TN1')
assert.equal(item.payAmount, 100)
assert.equal(item.merchantName, '门店A')
assert.equal(item.tradeTime, '2020-06-12 15:12:52')
assert.equal(item.statusStyle.text, '待报备')
})
......
......@@ -42,34 +42,36 @@ export function isAbnormalFlowReminderDay(date = new Date()) {
}
/**
* 是否应调用 checkShopLock 接口(周四~周日确认锁单;周一~周三不调)
* @param {Date} [date]
* @returns {boolean}
*/
export function shouldCallAbnormalFlowShopLockApi(date = new Date()) {
return !isAbnormalFlowReminderDay(date)
}
/**
* 登录周期内是否应展示吸底提醒(未手动关闭)
* @param {Object|null} storage - abnormalFlowPop
* @param {string|number} merchantId
* @param {string} [sessionId] - 当前登录会话标识
* @returns {boolean}
*/
export function shouldShowAbnormalFlowTip(storage, merchantId, sessionId = '') {
if (!storage || !merchantId) return true
const sid = sessionId || storage.sessionId || ''
if (!sid) return true
return storage.sessionId !== sid || !storage.dismissed?.[merchantId]
export function shouldShowAbnormalFlowTip(storage, sessionId = '') {
if (!storage || !sessionId) return true
if (storage.sessionId !== sessionId) return true
return !storage.dismissed
}
/**
* 关闭提醒后写入 storage(按登录周期 + 门店)
* 关闭提醒后写入 storage(整次登录周期内不再展示)
* @param {Object|null} storage
* @param {string|number} merchantId
* @param {string} sessionId
* @returns {Object}
*/
export function markAbnormalFlowTipDismissed(storage, merchantId, sessionId) {
const prev = storage && typeof storage === 'object' ? storage : {}
export function markAbnormalFlowTipDismissed(storage, sessionId) {
return {
sessionId,
dismissed: {
...(prev.dismissed || {}),
[merchantId]: true
}
dismissed: true
}
}
......@@ -157,16 +159,21 @@ export function shouldBypassAbnormalFlowLock(context = {}) {
}
/**
* 新建工单收款弹窗是否仅允许嘀加二维码(锁单 ON + 有待报备)
* 新建工单收款弹窗是否仅允许嘀加二维码
* 周一~周三:仅 union.count 有待报备即限制;周四~周日:需 checkShopLock 确认 + 有待报备
* @param {boolean|Object|null|undefined} shopLockData - checkShopLock 返回值
* @param {Object} [countData] - union.count 返回值
* @param {Date} [date]
* @returns {boolean}
*/
export function shouldRestrictNewOrderToDjQrOnly(shopLockData, countData) {
return (
isAbnormalFlowLockActive(shopLockData) &&
hasUnprocessedAbnormalFlow(countData)
)
export function shouldRestrictNewOrderToDjQrOnly(
shopLockData,
countData,
date = new Date()
) {
if (!hasUnprocessedAbnormalFlow(countData)) return false
if (isAbnormalFlowReminderDay(date)) return true
return isAbnormalFlowLockActive(shopLockData)
}
/**
......
Markdown is supported
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!