-- 指定日期线上支付信息
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 AND oo.payTime>='2024-01-30' AND oo.payTime<'2024-01-31';

-- 指定日期线上支付信息含商品信息
SELECT 
  oo.outTradeNo 订单编号,
  oo.payTime 支付时间,
  oo.meet 支付金额,
  oo.openId 微信Openid,
  lc.nick 用户昵称,
  lc.mobile 用户电话,
  ood.goodsName 商品名, 
  ood.partNumber 份数,
  ood.numofPart 每份斤数
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
WHERE oo.payStatus=4 AND oo.payTime>='2024-01-30' AND oo.payTime<'2024-01-31';


-- 指定日期绑卡信息
SELECT 
  vr.createTime 绑卡时间,
  CASE 
    WHEN vr.cardtype = 0 THEN '个人卡'
	 WHEN vr.cardtype = 1 THEN '企业卡'
  END 卡类型,
  vr.cardCode 卡编码,
  vr.customerSid 客户sid,
  lc.wxMpOpenid 微信OpenID,
  lc.nick 客户昵称,
  lc.mobile 客户手机号,
  lcb.name 客户所属支行
FROM vege_replenish vr 
LEFT JOIN lpk_customer lc ON lc.sid=vr.customerSid 
LEFT JOIN lpk_customer_bank lcb ON lcb.sid=lc.customerBankSid
WHERE (cardtype=0 OR cardtype=1) 
  and vr.createTime>='2024-01-30' AND vr.createTime<'2024-01-31';

-- 指定日期绑卡信息含商品信息
SELECT 
	vr.createTime 绑卡时间,
	CASE 
		WHEN vr.cardtype = 0 THEN '个人卡'
	 WHEN vr.cardtype = 1 THEN '企业卡'
	END 卡类型,
	vr.cardCode 卡编码,
	vr.customerSid 客户sid,
	lc.wxMpOpenid 微信OpenID,
	lc.nick 客户昵称,
	lc.mobile 客户手机号,
	lcb.name 客户所属支行,
	vrd.goodsName 商品名,
	vrd.goodsNumber 商品数量
FROM vege_replenish vr 
LEFT JOIN lpk_customer lc ON lc.sid=vr.customerSid 
LEFT JOIN lpk_customer_bank lcb ON lcb.sid=lc.customerBankSid
LEFT JOIN vege_replenish_detail vrd ON vrd.orderSid=vr.sid
WHERE (cardtype=0 OR cardtype=1) 
	AND vr.createTime>='2024-01-30' AND vr.createTime<'2024-01-31';

-- 预约提货信息
select
	date_format(vo.reserveDate,'%Y-%m-%d') 预约日期,
	vo.customerSid 客户SID,
	vo.storeSid 提货点SID,
	max(ls.name) 提货点名称,
	max(ls.linker) 提货点联系人,
	max(ls.phone) 提货点联系电话,
	max(ls.address) 提货点地址,
	max(vo.affiliation) 菜窖类别编号,
	max(pb.name) 菜窖类别,
	max(vo.userName) 提货人名,
	max(vo.userPhone) 提货电话,
	max(lb.sid) 支行SID,
	max(lb.name) 支行名,
	max(lb.linker) 支行联系人,
	max(lb.linkPhone) 支行电话,
	max(lb.address) 支行地址,
	vd.goodsSid 商品SID,
	max(vd.goodsName) 商品名,
	sum(vd.goodsNumber) 商品数,
	max(lcb.name) 客户所属支行
from vege_cellar_reserve_order vo
LEFT JOIN lpk_store ls ON ls.sid=vo.storeSid
LEFT JOIN lpk_bank lb ON lb.sid=ls.bankSid
left join vege_cellar_reserve_details vd on vo.sid=vd.orderSid
left join lpk_goods lg on vd.goodsSid=lg.sid
left join pms_brand pb on pb.id=vo.affiliation
LEFT JOIN lpk_customer lc ON lc.sid=vo.customerSid
LEFT JOIN lpk_customer_bank lcb ON lcb.sid = lc.customerBankSid
WHERE vo.reserveDate>='2024-01-30' AND vo.reserveDate<'2024-01-31'
GROUP BY vo.reserveDate,vo.storeSid,vo.customerSid,vd.goodsSid ;
