跪拜 Guibai
← All articles
Frontend

A WeChat Mini Program Replaces Industrial PDAs for Warehouse Scanning: Concurrency Control and Four Pitfalls

By baiyunfan ·
Read original on juejin.cn ↗ Google Translate ↗ Alt translation

Any team building a thin mobile client on top of an existing ERP will hit the same hard constraints: only whitelisted, ICP-filed HTTPS domains, no direct database access, and no safe way to let a client compute inventory deltas. The six-API template gateway is a reusable pattern for keeping the client thin while preserving server-side authority.

Summary

Barcode-driven warehouse work usually means buying an industrial PDA at 2,000–5,000 RMB per unit, then installing, configuring, and upgrading each device. One implementation for small manufacturers and distributors skipped that entirely: warehouse staff scan with a WeChat Mini Program on phones they already carry. Hardware cost drops to zero, no APK is installed, upgrades happen server-side, and training disappears because the staff already live in WeChat.

The mini program only captures and displays. Inventory decrements are computed in server-side transactions with version checks, because two warehouse staff submitting 'read 100, deduct 30' and 'read 100, deduct 20' at the same time will otherwise silently overwrite one update and leave stock at 70 instead of 50. The mini program cannot reach an internal database, so a gateway exposes six generic APIs: login, menu, meta, query, save, and exec. Queries and saves are driven by server-side templates; adding a new query page takes a template row, not backend code.

The production traps are concrete: HTTPS domains must be ICP-filed and whitelisted before review submission; scan calls need camera-only mode and restricted symbologies; low-quality self-printed labels demand a manual-entry and fuzzy-search fallback; shared accounts destroy the audit trail. The same boundary applies in reverse: a phone-based mini program is wrong for high-frequency sorting centers and signal-free cold storage, where industrial PDAs or local caching are necessary.

Takeaways
— A WeChat Mini Program on employee phones eliminates the 2,000–5,000 RMB per-unit cost of industrial PDAs for small warehouses; install, upgrade, and training overhead disappear.
— wx.scanCode should set onlyFromCamera: true to prevent selecting stale album photos, and restrict scanType to the barcode symbologies actually used.
— Chinese characters in scanned codes can encode inconsistently across Android devices; alphanumeric part numbers avoid the problem at the source.
— A barcode lookup that returns part number, name, specification, unit, and current stock reduces entry to a single quantity field.
— Mapping customer part numbers to internal part numbers lets one 50-person customer remove a full-time reconciliation role.
— Client-side inventory math (read 100, compute 90, submit 90) silently loses updates under concurrency; the server must apply deltas in a transaction with optimistic locking.
— Mini Programs can only reach HTTPS domains that are ICP-filed and whitelisted in the Mini Program backend; self-signed certificates do not count.
— The whitelist must be configured before first submission; changing a domain later requires a new review and release.
— Six generic APIs (login, menu, meta, query, save, exec) driven by server-side templates let new query pages be added with zero backend code.
— Every scanning workflow needs a manual-entry plus fuzzy-search fallback, because poor labels will otherwise make staff abandon the system.
— Shared warehouse accounts break the ERP audit trail; one account per person plus permission scoping is cheap compared to a stocktake discrepancy.
— Phone-based mini programs fit lightweight, multi-person, real-time warehouse work, not high-frequency sorting or offline basements and cold storage.
Conclusions

The biggest cost of industrial PDAs is not the 2,000–5,000 RMB price tag but the maintenance and training burden that follows; a tool already in employees' pockets wins because the interaction model is familiar.

The template-driven six-API gateway only pays off when SQL is already centralized; teams with scattered queries will find the gateway becomes the mess instead of the solution.

Treating scan failure as a normal workflow path rather than an error is what keeps a warehouse system alive; if the only way in is a perfect scan, employees will walk away.

The solution's boundary is as important as its functionality: it deliberately gives up high-frequency sorting and offline operation, which is why it can stay simple.

Concepts & terms
wx.scanCode
WeChat Mini Program API that opens the camera to scan barcodes or QR codes. It returns the raw result, the detected symbology, and the character set, and can be configured to scan only from the camera and only for specific code types.
ICP filing
A Chinese government registration required for domains serving mainland China. WeChat Mini Programs only allow requests to HTTPS domains that have completed ICP filing and been added to a whitelist in the Mini Program admin console.
Optimistic locking
A concurrency control technique where an update includes a version number in the WHERE clause. If another transaction has already changed the row, the version no longer matches, the update affects zero rows, and the operation rolls back.
Template-driven generic API
A server-side pattern where query statements, visible fields, and other metadata are stored as templates. The client sends a template ID plus parameters, so adding a new query page needs a configuration row rather than a new endpoint.
Source: juejin.cn ↗ Google Translate ↗ Backup ↗