-- 移动端小程序:配送定位与客户坐标 ALTER TABLE customers ADD COLUMN IF NOT EXISTS lat DECIMAL(10,7); ALTER TABLE customers ADD COLUMN IF NOT EXISTS lng DECIMAL(10,7); UPDATE customers SET lat = 39.9042, lng = 116.4074 WHERE customer_code = 'CUST001' AND lat IS NULL; UPDATE customers SET lat = 39.9836, lng = 116.3163 WHERE customer_code = 'CUST002' AND lat IS NULL; ALTER TABLE delivery_tasks ADD COLUMN IF NOT EXISTS person_code VARCHAR(50); CREATE TABLE IF NOT EXISTS delivery_person_locations ( person_code VARCHAR(50) PRIMARY KEY, task_code VARCHAR(50), order_code VARCHAR(50), lat DECIMAL(10,7) NOT NULL, lng DECIMAL(10,7) NOT NULL, accuracy DECIMAL(8,2), speed DECIMAL(8,2), heading DECIMAL(8,2), is_delivering BOOLEAN DEFAULT false, updated_at TIMESTAMPTZ DEFAULT NOW() ); CREATE TABLE IF NOT EXISTS delivery_location_history ( id UUID PRIMARY KEY DEFAULT gen_random_uuid(), person_code VARCHAR(50) NOT NULL, task_code VARCHAR(50), lat DECIMAL(10,7) NOT NULL, lng DECIMAL(10,7) NOT NULL, recorded_at TIMESTAMPTZ DEFAULT NOW() ); CREATE INDEX IF NOT EXISTS idx_delivery_location_history_person ON delivery_location_history(person_code, recorded_at DESC); ALTER TABLE delivery_person_locations ENABLE ROW LEVEL SECURITY; ALTER TABLE delivery_location_history ENABLE ROW LEVEL SECURITY; CREATE POLICY anon_all_delivery_person_locations ON delivery_person_locations FOR ALL USING (true); CREATE POLICY anon_all_delivery_location_history ON delivery_location_history FOR ALL USING (true);