客户绑定支行	客户电话	客户姓名	卡号	粉条	整包白菜	整包土豆	北方白菜	张北土豆	绑卡时间	客户微信OpenID	客户SID	客户昵称
裕西分理处	18031266678	普天	70001069			1			2024/1/15 12:42	o81zC69REd8ziAN9LhqUlxBs0cYA	96b4ef58-ea26-4c2e-86cb-27a38c6ec1b5	彩虹糖


SELECT 
  lc.wxMpOpenid,
  lc.nick,
  lc.mobile,
  lc.sid
FROM lpk_customer lc 
WHERE lc.mobile='18031266678'
;
"wxMpOpenid"	"nick"	"mobile"	"sid"
"o81zC69REd8ziAN9LhqUlxBs0cYA"	"彩虹糖"	"18031266678"	"96b4ef58-ea26-4c2e-86cb-27a38c6ec1b5"


SELECT 
  lc.wxMpOpenid,
  lc.nick,
  lc.mobile,
  lg.name,
  vc.goodsNumber 
from vegetable_cellar vc
LEFT JOIN lpk_customer lc ON lc.sid=vc.customerSid 
LEFT JOIN lpk_goods lg ON lg.sid=vc.goodsSid
WHERE 
 vc.customerSid='96b4ef58-ea26-4c2e-86cb-27a38c6ec1b5'
"wxMpOpenid"	"nick"	"mobile"	"name"	"goodsNumber"
"o81zC69REd8ziAN9LhqUlxBs0cYA"	"彩虹糖"	"18031266678"	"西瓜红蜜薯"	"125"
"o81zC69REd8ziAN9LhqUlxBs0cYA"	"彩虹糖"	"18031266678"	"惠享52度红薯"	"2"



-- 个人卡
	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='96b4ef58-ea26-4c2e-86cb-27a38c6ec1b5' 
-- 企业卡
	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='96b4ef58-ea26-4c2e-86cb-27a38c6ec1b5' 

-- 购买卡
	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='96b4ef58-ea26-4c2e-86cb-27a38c6ec1b5' 

-- 转赠卡（旧数据）
	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='96b4ef58-ea26-4c2e-86cb-27a38c6ec1b5' 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 ='96b4ef58-ea26-4c2e-86cb-27a38c6ec1b5' 
	
	
	-- 预约提货，(旧数据)
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='96b4ef58-ea26-4c2e-86cb-27a38c6ec1b5' 

	-- 预约单
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='96b4ef58-ea26-4c2e-86cb-27a38c6ec1b5' 
	-- 赠出的卡，数量为负值
	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='96b4ef58-ea26-4c2e-86cb-27a38c6ec1b5' AND d.isSenior = '2' 
	
	-- 赠出记录
		SELECT 
		   tr.createTime,
			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 ='96b4ef58-ea26-4c2e-86cb-27a38c6ec1b5' 

	-- 预约提货，(旧数据)
SELECT 
	r.wxMpOpenid 微信openid,
	d.customerSid 客户SID,
	d.reserveDate 预约日期,
	d.userName 提货人姓名,
	d.userPhone 提货人电话,
	d.storeSid 提货点SID,
	ls.name 提货点名称,
	s.goodsSid 商品SID,
	-s.goodsNumber AS 商品数量,
	e.NAME AS 商品名称
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  	
	LEFT JOIN lpk_store ls ON ls.sid = d.storeSid  	
WHERE d.customerSid='96b4ef58-ea26-4c2e-86cb-27a38c6ec1b5' 
union all
SELECT 
	r.wxMpOpenid 微信openid,
	d.customerSid 客户SID,
	d.reserveDate 预约日期,
	d.userName 提货人姓名,
	d.userPhone 提货人电话,
	d.storeSid 提货点SID,
	d.storeName 提货点名称,
	s.goodsSid 商品SID,
	-s.goodsNumber AS 商品数量,
	e.NAME AS 商品名称
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='96b4ef58-ea26-4c2e-86cb-27a38c6ec1b5' 
ORDER BY 预约日期