-- 转赠记录
SELECT 
 tr.createTime,
 tr.customerSid,
 lc.wxMpOpenid,
 lc.nick,
 lc.mobile,
 tr.recipientTime,
 tr.recipientSid,
 lcr.wxMpOpenid,
 lcr.nick,
 lcr.mobile,
 tr.state
FROM transfer_records tr 
LEFT JOIN lpk_customer lc ON lc.sid = tr.customerSid 
LEFT JOIN lpk_customer lcr ON lcr.sid = tr.recipientSid

-- 预约记录（旧）
SELECT 
 lro.createTime,
 lro.reserveDate,
 ls.name,
 lro.userName,
 lro.userPhone,
 lro.customerSid,
 lc.wxMpOpenid,
 lc.nick,
 lc.mobile
FROM lpk_reserve_order lro
LEFT JOIN lpk_store ls ON ls.sid = lro.storeSid 
LEFT JOIN lpk_customer lc ON lc.sid = lro.customerSid

-- 预约记录（新）
SELECT 
 vcro.createTime,
 vcro.reserveDate,
 vcro.storeName,
 vcro.userName,
 vcro.userPhone,
 vcro.customerSid,
 lc.wxMpOpenid,
 lc.nick,
 lc.mobile
FROM vege_cellar_reserve_order vcro
LEFT JOIN lpk_customer lc ON lc.sid = vcro.customerSid

--线上购买
SELECT 
  oo.payTime 支付时间,
  oo.meet 支付金额,
  oo.openId 微信Openid,
  lc.nick 用户昵称,
  lc.mobile 用户电话
FROM ord_order oo 
LEFT JOIN lpk_customer lc ON lc.sid=oo.userSid 
WHERE oo.payStatus=4 



-- 购买人数-累计    线上下单加上绑定个人卡和企业卡的用户数(同一用户记一条) 
SELECT COUNT(1) FROM (
SELECT 
  oo.openId openid 
FROM ord_order oo WHERE oo.payStatus=4
UNION
SELECT 
  lc.wxMpOpenid openid
FROM emp_card ec 
LEFT JOIN lpk_customer lc ON lc.sid = ec.customerSid	
WHERE ec.customerSid IS NOT NULL AND ec.customerSid <> '' 
UNION
SELECT 
	lc.wxMpOpenid openid
FROM lpk_giftcard lg 
	LEFT JOIN lpk_customer lc ON lc.sid = lg.customerSid	
WHERE lg.customerSid IS NOT NULL AND lg.customerSid <> '' 
) t1


-- 个人卡绑卡记录
	SELECT 
		lg.serialNumber,
		lg.bindDate,
		lg.customerSid,
		lc.wxMpOpenid,
		lc.nick,
		lc.mobile,
		lcb.name
	FROM lpk_giftcard lg 
		LEFT JOIN lpk_customer lc ON lc.sid = lg.customerSid	
		LEFT JOIN lpk_customer_bank lcb ON lcb.sid = lc.customerBankSid
	WHERE lg.customerSid IS NOT NULL AND lg.customerSid <> '' 
-- 企业卡绑卡记录
	SELECT 
		lg.serialNumber,
		lg.bindDate,
		lg.customerSid,
		lc.wxMpOpenid,
		lc.nick,
		lc.mobile,
		lcb.name
	FROM emp_card lg 
		LEFT JOIN lpk_customer lc ON lc.sid = lg.customerSid	
		LEFT JOIN lpk_customer_bank lcb ON lcb.sid = lc.customerBankSid
	WHERE lg.customerSid IS NOT NULL AND lg.customerSid <> '' 