SELECT 
  * 
FROM  vege_cellar_reserve_order vcro
LEFT JOIN vege_cellar_reserve_details vcrd ON vcrd.orderSid=vcro.sid
WHERE date(vcro.reserveDate)='2024-02-02' 
AND vcro.userPhone='13932147290'

13315167779 - c92992b9-6392-4d25-ac5d-f89f20578ab0

-- 个人卡
	SELECT 
		r.wxMpOpenid,
		d.customerSid,
		d.bindDate,
		d.giftbagSid,
		d.serialNumber,
		d.code,
		s.goodsSid,
		s.goodsNumber,
		e.NAME AS goodsName,
		'个人卡' cardtype
	FROM lpk_giftcard d 
		LEFT JOIN lpk_customer r ON r.sid = d.customerSid	
		LEFT JOIN lpk_giftbag_goods s ON s.giftbagSid=d.giftbagSid 	
		LEFT JOIN lpk_goods e ON e.sid = s.goodsSid  	
	WHERE d.customerSid='e337fbdd-7676-4f9a-a766-8c8a0115564f' 
-- 企业卡
	SELECT 
		r.wxMpOpenid,
		d.customerSid,
		d.bindDate,
		d.giftbagSid,
		d.serialNumber,
		d.code,
		s.goodsSid,
		s.goodsNumber,
		e.NAME AS goodsName,
		'企业卡' cardtype
	FROM emp_card d 
		LEFT JOIN lpk_customer r ON r.sid = d.customerSid	
		LEFT JOIN lpk_giftbag_goods s ON s.giftbagSid=d.giftbagSid 	
		LEFT JOIN lpk_goods e ON e.sid = s.goodsSid  	
	WHERE d.customerSid='e337fbdd-7676-4f9a-a766-8c8a0115564f' 

-- 购买卡
	SELECT 
		oo.payTime,
		oo.totalTee,
		oo.openId,
		lc.nick,
		lc.mobile,
		ood.goodsName,
		ood.partNumber
	FROM ord_order oo 
		LEFT JOIN lpk_customer lc ON lc.sid = oo.userSid 	
		LEFT JOIN ord_order_detail ood ON ood.orderSid=oo.sid 	
		LEFT JOIN lpk_goods e ON e.sid = ood.goodsSid  	
	WHERE oo.payStatus=4
	  AND oo.userSid='e337fbdd-7676-4f9a-a766-8c8a0115564f' 

-- 转赠卡（旧数据）
	SELECT 
		r.wxMpOpenid,
		d.customerSid,
		d.bindDate,
		d.sid,
		d.serialNumber,
		d.code,
		s.goodsSid,
		s.goodsNumber,
		e.NAME AS goodsName,
		'转赠卡' cardtype
	FROM emp_card_gift d 
		LEFT JOIN lpk_customer r ON r.sid = d.customerSid	
		LEFT JOIN emp_card_gift_goods s ON s.empCardGiftSid=d.sid 	
		LEFT JOIN lpk_goods e ON e.sid = s.goodsSid  	
	WHERE d.customerSid='e337fbdd-7676-4f9a-a766-8c8a0115564f' AND d.isSenior = '2' 
	
-- 转赠记录
	SELECT 
		tr.recipientTime,
		lc.wxMpOpenid,
		lc.nick,
		lc.mobile,
		lg.name,
		trgd.goodsNumber
	FROM transfer_records tr 
	LEFT JOIN lpk_customer lc ON lc.sid = tr.recipientSid 	
	LEFT JOIN transfer_records_goods_details trgd ON trgd.orderSid=tr.sid 	
	LEFT JOIN lpk_goods lg ON lg.sid = trgd.goodsSid  	
	WHERE  tr.recipientSid ='e337fbdd-7676-4f9a-a766-8c8a0115564f' 
	
	
	-- 预约提货，(旧数据)
SELECT 
	r.wxMpOpenid,
	d.customerSid,
	d.reserveDate,
	d.sid,
	d.storeSid,
	d.cardCode,
	s.goodsSid,
	-s.goodsNumber AS goodsNumber,
	e.NAME AS goodsName,
	d.cardType cardtype
FROM lpk_reserve_order d 
	LEFT JOIN lpk_customer r ON r.sid = d.customerSid	
	LEFT JOIN lpk_reserve_order_goods s ON s.orderSid=d.sid 	
	LEFT JOIN lpk_goods e ON e.sid = s.goodsSid  	
WHERE d.customerSid='e337fbdd-7676-4f9a-a766-8c8a0115564f' 

	-- 预约单
SELECT 
	r.wxMpOpenid,
	d.customerSid,
	d.reserveDate,
	d.sid,
	s.goodsSid,
	-s.goodsNumber AS goodsNumber,
	e.NAME AS goodsName
FROM vege_cellar_reserve_order d 
	LEFT JOIN lpk_customer r ON r.sid = d.customerSid	
	LEFT JOIN vege_cellar_reserve_details s ON s.orderSid=d.sid 	
	LEFT JOIN lpk_goods e ON e.sid = s.goodsSid  	
WHERE d.customerSid='e337fbdd-7676-4f9a-a766-8c8a0115564f' 

	-- 赠出的卡，数量为负值
	SELECT 
		r.wxMpOpenid,
		d.empCardCustomerSid,
		d.grantDate,
		d.sid,
		d.serialNumber,
		d.code,
		s.goodsSid,
		-s.goodsNumber AS goodsNumber,
		e.NAME AS goodsName,
		'赠出' cardtype
	FROM emp_card_gift d 
		LEFT JOIN lpk_customer r ON r.sid = d.empCardCustomerSid	
		LEFT JOIN emp_card_gift_goods s ON s.empCardGiftSid=d.sid 	
		LEFT JOIN lpk_goods e ON e.sid = s.goodsSid  	
	WHERE d.empCardCustomerSid='e337fbdd-7676-4f9a-a766-8c8a0115564f' AND d.isSenior = '2' 
	
	-- 赠出记录
		SELECT 
			tr.recipientTime,
			lc.wxMpOpenid,
			lc.nick,
			lc.mobile,
			lg.name,
			trgd.goodsNumber
		FROM transfer_records tr 
		LEFT JOIN lpk_customer lc ON lc.sid = tr.customerSid 	
		LEFT JOIN transfer_records_goods_details trgd ON trgd.orderSid=tr.sid 	
		LEFT JOIN lpk_goods lg ON lg.sid = trgd.goodsSid  	
		WHERE  tr.customerSid ='e337fbdd-7676-4f9a-a766-8c8a0115564f' 
			
			