feat: QR 토큰 API에서 클라이언트 items 우선 처리
- /api/admin/qr/generate에서 client_items 파라미터 추가 - 클라이언트 전달 items 우선, 없으면 MSSQL 조회 - get_sale_items 쿼리 컬럼명 수정 (DrugCode, GoodsName 등)
This commit is contained in:
@@ -54,6 +54,56 @@ except ImportError as e:
|
||||
OTC_LABEL_AVAILABLE = False
|
||||
logging.warning(f"OTC 라벨 프린터 모듈 로드 실패: {e}")
|
||||
|
||||
|
||||
# 약국 코드 가져오기 (config.json)
|
||||
def get_pharmacy_code():
|
||||
import json
|
||||
config_path = os.path.join(os.path.dirname(__file__), 'config.json')
|
||||
try:
|
||||
with open(config_path, 'r', encoding='utf-8') as f:
|
||||
config = json.load(f)
|
||||
return config.get('pharmacy_code', 'P0001')
|
||||
except:
|
||||
return 'P0001'
|
||||
|
||||
|
||||
# 판매 품목 조회 (MSSQL)
|
||||
def get_sale_items(transaction_id):
|
||||
"""MSSQL에서 판매 품목 조회"""
|
||||
try:
|
||||
from db.dbsetup import db_manager
|
||||
from sqlalchemy import text
|
||||
|
||||
mssql_engine = db_manager.get_engine('PM_PRES')
|
||||
with mssql_engine.connect() as conn:
|
||||
result = conn.execute(text("""
|
||||
SELECT
|
||||
s.DrugCode as item_code,
|
||||
g.GoodsName as item_name,
|
||||
s.QUAN as quantity,
|
||||
s.SL_INPUT_PRICE as unit_price,
|
||||
s.SL_TOTAL_PRICE as total_price
|
||||
FROM SALE_SUB s
|
||||
LEFT JOIN PM_DRUG.dbo.CD_GOODS g ON g.DrugCode = s.DrugCode
|
||||
WHERE s.SL_NO_order = :tx_id
|
||||
"""), {'tx_id': transaction_id})
|
||||
|
||||
items = []
|
||||
for row in result:
|
||||
items.append({
|
||||
'item_code': row.item_code or '',
|
||||
'item_name': row.item_name or '상품',
|
||||
'quantity': int(row.quantity) if row.quantity else 1,
|
||||
'unit_price': int(row.unit_price) if row.unit_price else 0,
|
||||
'total_price': int(row.total_price) if row.total_price else 0
|
||||
})
|
||||
print(f"[QR] 품목 조회 성공: {transaction_id} → {len(items)}개")
|
||||
return items
|
||||
except Exception as e:
|
||||
print(f"[QR] 품목 조회 실패: {e}")
|
||||
return []
|
||||
|
||||
|
||||
app = Flask(__name__)
|
||||
app.secret_key = 'pharmacy-qr-mileage-secret-key-2026'
|
||||
|
||||
@@ -2796,7 +2846,9 @@ def api_kiosk_trigger():
|
||||
else:
|
||||
# 새 토큰 생성 + 서버 동기화 (v2)
|
||||
from utils.qr_token_generator import generate_and_sync_token
|
||||
token_info = generate_and_sync_token(transaction_id, float(amount), "P0001")
|
||||
# 품목 조회
|
||||
sale_items = get_sale_items(transaction_id)
|
||||
token_info = generate_and_sync_token(transaction_id, float(amount), get_pharmacy_code(), items=sale_items)
|
||||
|
||||
if not token_info.get('local_saved'):
|
||||
return jsonify({'success': False, 'message': token_info.get('local_error', 'DB 저장 실패')}), 500
|
||||
@@ -7720,6 +7772,7 @@ def api_admin_qr_generate():
|
||||
order_no = data.get('order_no')
|
||||
amount = data.get('amount', 0)
|
||||
preview = data.get('preview', True) # 기본: 미리보기
|
||||
client_items = data.get('items') # 클라이언트에서 전달한 품목
|
||||
|
||||
if not order_no:
|
||||
return jsonify({'success': False, 'error': '주문번호가 필요합니다'}), 400
|
||||
@@ -7747,7 +7800,14 @@ def api_admin_qr_generate():
|
||||
amount = float(row[1]) if row[1] else 0
|
||||
|
||||
# 1. 토큰 생성 + 로컬 저장 + 서버 동기화 (v2)
|
||||
token_info = generate_and_sync_token(order_no, amount, "P0001")
|
||||
# 품목 조회: 클라이언트가 전달한 items 우선, 없으면 MSSQL 조회
|
||||
if client_items:
|
||||
sale_items = client_items
|
||||
print(f"[QR] 클라이언트 품목 사용: {len(sale_items)}개")
|
||||
else:
|
||||
sale_items = get_sale_items(order_no)
|
||||
print(f"[QR] MSSQL 품목 조회: {len(sale_items)}개")
|
||||
token_info = generate_and_sync_token(order_no, amount, get_pharmacy_code(), items=sale_items)
|
||||
|
||||
if not token_info.get('local_saved'):
|
||||
return jsonify({'success': False, 'error': token_info.get('local_error', 'DB 저장 실패')}), 400
|
||||
|
||||
11
backend/config.json
Normal file
11
backend/config.json
Normal file
@@ -0,0 +1,11 @@
|
||||
{
|
||||
"pharmacy_code": "P0001",
|
||||
"pharmacy_name": "청춘약국",
|
||||
"cloud_api_url": "https://pos.pharmq.kr",
|
||||
"pos_printer": {
|
||||
"ip": "192.168.0.174",
|
||||
"port": 9100
|
||||
},
|
||||
"pharmacist_name": "김영빈",
|
||||
"license_number": "72672"
|
||||
}
|
||||
@@ -21,9 +21,18 @@ from db.dbsetup import DatabaseManager
|
||||
MILEAGE_RATE = 0.03 # 3% 적립
|
||||
TOKEN_EXPIRY_DAYS = 30 # 30일 유효기간
|
||||
|
||||
# 서버 설정 (v2)
|
||||
CLOUD_API_URL = "https://pos.pharmq.kr"
|
||||
PHARMACY_CODE = "P0001"
|
||||
# 서버 설정 (v2) - config.json에서 읽기
|
||||
import json
|
||||
_config_path = os.path.join(os.path.dirname(__file__), '..', 'config.json')
|
||||
try:
|
||||
with open(_config_path, 'r', encoding='utf-8') as f:
|
||||
_config = json.load(f)
|
||||
CLOUD_API_URL = _config.get('cloud_api_url', 'https://pos.pharmq.kr')
|
||||
PHARMACY_CODE = _config.get('pharmacy_code', 'P0001')
|
||||
except:
|
||||
CLOUD_API_URL = "https://pos.pharmq.kr"
|
||||
PHARMACY_CODE = "P0001"
|
||||
|
||||
QR_BASE_URL = f"{CLOUD_API_URL}/{PHARMACY_CODE}/claim"
|
||||
|
||||
# 로거
|
||||
|
||||
Reference in New Issue
Block a user