
客户绑定支行	客户电话	客户姓名	卡号	粉条	整包白菜	整包土豆	北方白菜	张北土豆	绑卡时间	客户微信OpenID	客户SID	客户昵称
留营支行	15130120263	路春红	66004063	100					2023/12/25 13:09	o81zC69RY2vclV6I_j58PYaec-fM	47547f4b-160f-45f0-9d03-d303420ff7b9	惠享客户000188


SELECT 
  lc.wxMpOpenid,
  lc.nick,
  lc.mobile,
  lc.sid
FROM lpk_customer lc 
WHERE lc.mobile='15130120263'
;
"wxMpOpenid"	"nick"	"mobile"	"sid"
"o81zC69RY2vclV6I_j58PYaec-fM"	"惠享客户000188"	"15130120263"	"47547f4b-160f-45f0-9d03-d303420ff7b9"


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='47547f4b-160f-45f0-9d03-d303420ff7b9'
"wxMpOpenid"	"nick"	"mobile"	"name"	"goodsNumber"
"o81zC69RY2vclV6I_j58PYaec-fM"	"惠享客户000188"	"15130120263"	"纯红薯粉条"	"80"
"o81zC69RY2vclV6I_j58PYaec-fM"	"惠享客户000188"	"15130120263"	"惠享52度红薯"	"23"


-- 个人卡
	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='47547f4b-160f-45f0-9d03-d303420ff7b9' 
-- 企业卡
	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='47547f4b-160f-45f0-9d03-d303420ff7b9' 

-- 购买卡
	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='47547f4b-160f-45f0-9d03-d303420ff7b9' 

-- 转赠卡（旧数据）
	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='47547f4b-160f-45f0-9d03-d303420ff7b9' 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 ='47547f4b-160f-45f0-9d03-d303420ff7b9' 
	
	
	-- 预约提货，(旧数据)
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='47547f4b-160f-45f0-9d03-d303420ff7b9' 

	-- 预约单
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='47547f4b-160f-45f0-9d03-d303420ff7b9' 
	-- 赠出的卡，数量为负值
	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='47547f4b-160f-45f0-9d03-d303420ff7b9' 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 ='47547f4b-160f-45f0-9d03-d303420ff7b9' 



	-- 预约提货，(旧数据)
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='47547f4b-160f-45f0-9d03-d303420ff7b9' 
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='47547f4b-160f-45f0-9d03-d303420ff7b9' 
ORDER BY 预约日期



SELECT 
	 tr.createTime 转赠时间,
	lc.wxMpOpenid 转赠人微信,
	lc.nick 转赠人昵称,
	lc.mobile 转赠人电话,
	lg.name 转赠商品名称,
	-trgd.goodsNumber 转赠商品数量,
	tr.recipientTime 接收时间,
	lcr.nick  接收人昵称,
	lcr.mobile 接收人电话,
	lcr.wxMpOpenid 接收人微信
FROM transfer_records tr 
LEFT JOIN lpk_customer lc ON lc.sid = tr.customerSid 	
LEFT JOIN lpk_customer lcr ON lcr.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.customerSid ='47547f4b-160f-45f0-9d03-d303420ff7b9' 