You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
 
 
sql-tools/商城转化.sql

234 lines
9.1 KiB

/*
_Demo
1
SELECT * FROM TMallOrderBill
SELECT * FROM TMallGoods
SELECT * FROM TMallOrderPayment
SELECT * FROM TMallOrder WHERE FOrderNo = '0012004300002'
UPDATE TMallOrder SET FOrderStatus = 'WaitConfirm' WHERE FOrderId = 5297918603522265493
UPDATE TMallOrderSkuRedeemCode SET FStatus = 'Normal' WHERE FOrderId = 5297918603522265493
UPDATE TMallOrderPayment SET FDeliveryStatus = 'Send' WHERE FId = 5297918603522265493
UPDATE A
SET A.FStatus = 'Confirm',FConfirmTime = B.FConfirmTime,A.FConfirmBillType = B.FConfirmBillType,A.FConfirmBillId = B.FConfirmBillId
FROM TMallOrderSkuRedeemCode AS A,TMallOrderPayment AS B
WHERE A.FCode = B.FVoucherCode
AND B.FDeliveryStatus = 'Confirm'
AND A.FStatus != 'Confirm'
UPDATE A
SET A.FOrderStatus = 'Finished'
FROM TMallOrder AS A,TMallOrderPayment AS B
WHERE B.FPayStatus = 'Success'
AND B.FDeliveryStatus = 'Confirm'
AND A.FOrderId = B.FId
AND A.FOrderStatus != 'Finished'
AND B.FDeliveryStatus = 'Confirm'
SELECT * FROM TMallOrderPayment
*/
INSERT TMallCategory(FId,FName,FParentId,FIcon,FImage,FLevel,FSortIndex,FCreatetIME,FUPdateTime)
SELECT A.FId,A.FName,0,'','',0,FOrder,GETDATE(),GETDATE()
FROM TBasicType AS A
WHERE FKey = 'MallGoodsType'
INSERT INTO TMallGoodsSpu(FId,FNo,FName,FCategoryId,FUseTarget,FImage,FDescription,FDetail,FUnit,FState,FFreightTemplateId,
FDeliveryMode,FRecommended,FPromId,FSeckillEnabled,FSeckillBeginTime,FSeckillEndTime,FCreateTime,FUpdateTime,FDeleted)
SELECT A.FId,
A.FNo,
A.FName,
A.FTypeId,
CASE A.FCategory WHEN 1 THEN 'Item' WHEN 2 THEN 'Goods' WHEN 3 THEN 'Card' ELSE 'Item' END AS FUseTarget,
FImage,
'' as FDescription,
CASE WHEN A.FDescText != '' THEN '<p><span style="font-size:10pt;">' + A.FDescText + '</span></p>' ELSE '' END
+ CASE WHEN A.FDescImage != '' THEN '<p><img src="' + replace(FDescImage,',','"/></p><p><img src="') + '"/></p>' ELSE '' END AS FDetail,
'¼þ' AS FUnit,
'Normal' AS FState,
0 AS FFreightTemplateId,
'Receive' AS FDeliveryMode,
0 AS FRecommended ,
0 AS FPromId ,
0 AS FSeckillEnabled,
NULL AS FSeckillBeginTime,
NULL AS FSeckillEndTime,
GETDATE() AS FCreateTime,
GETDATE() AS FUpdateTime,
FDeleted AS FDeleted
FROM TMallGoods AS A
INSERT INTO TMallGoodsSku(FId,FSpuId,FName,FBarCode,FImage,FOrigPrice,FCashPrice,FCashPoint,FMoneyCardPrice,FMoneyCardPoint,
FCourseCardPrice,FCourseCardPoint,FPointPrice,FSeckillPrice,FStock,FSales,FSortIndex)
SELECT dbo.FNNewId() AS FId,
FId AS FSpuId,
FName AS FName,
'' AS FBarCode,
'' AS FImage,
FOrigPrice AS FOrigPrice,
FSalePrice AS FCashPrice,
0 AS FCashPoint,
CASE WHEN FAllowCardPay = 1 THEN FCardPrice ELSE 0 END AS FMoneyCardPrice,
0 AS FMoneyCardPoint,
0 AS FCourseCardPrice,
0 AS FCourseCardPoint,
CASE WHEN FAllowPointPay = 1 THEN FPointPrice ELSE 0 END,
0 AS FSeckillPrice,
FTotal AS FStock,
FSold AS FSales,
0 AS FSortIndex
FROM TMallGoods
INSERT INTO TMallGoodsSkuGroupon(FId,FSpuId,FSkuId,FPeople,FPrice,FHours,FRobotOpen,FRobotJoin,FRobotJoinHours,FLeastPeople,FLimitNumber,FKeepNumber,FCreateTime)
SELECT dbo.FNNewId(),A.FSpuId,A.FId,B.FNumber, B.FPrice,12,0,0,11,1,0,0,getdate()
FROM TMallGoodsCollage AS B,TMallGoodsSku AS A
WHERE A.FSpuId = B.FGoodsId
--custId
IF NOT EXISTS(SELECT 1 FROM syscolumns WHERE id = object_id('TMallOrderBill') AND name = 'FCustId')
BEGIN
EXEC('
ALTER TABLE TMallOrderBill ADD FCustId BIGINT
ALTER TABLE TMallOrderPayment ADD FCustId BIGINT')
END
GO
INSERT TCustomer(FCustId,FMobile,FNickname,FAvatar,FCreateTime)
SELECT dbo.FNNewId(),M.FMobilePhone,M.FName,'',GETDATE()
FROM TMember AS M,TMallOrderBill AS A
WHERE A.FMemId = M.FMemId
AND M.FMobilePhone NOT IN(SELECT FMobile FROM TCustomer)
GROUP BY M.FMobilePhone,M.FName
INSERT TCustomer(FCustId,FMobile,FNickname,FAvatar,FCreateTime)
SELECT dbo.FNNewId(),M.FMobilePhone,M.FName,'',GETDATE()
FROM TMember AS M,TMallOrderPayment AS A
WHERE A.FMemId = M.FMemId
AND M.FMobilePhone NOT IN(SELECT FMobile FROM TCustomer)
GROUP BY M.FMobilePhone,M.FName
UPDATE A
SET A.FCustId = B.FCustId
FROM TMallOrderBill AS A,TMember AS C,TCustomer AS B
WHERE A.FMemId = C.FMemId
AND C.FMobilePhone = B.FMobile
UPDATE A
SET A.FCustId = B.FCustId
FROM TMallOrderPayment AS A,TMember AS C,TCustomer AS B
WHERE A.FMemId = C.FMemId
AND C.FMobilePhone = B.FMobile
--SKUID
IF NOT EXISTS(SELECT 1 FROM syscolumns WHERE id = object_id('TMallOrderBill') AND name = 'FSkuId')
BEGIN
ALTER TABLE TMallOrderBill ADD FSkuId BIGINT NOT NULL DEFAULT 0
END
GO
UPDATE A
SET A.FSkuId = B.FId
FROM TMallOrderBill AS A,TMallGoodsSku AS B
WHERE A.FGoodsId = B.FSpuId
--ÏȸãÆ´ÍÅ
INSERT INTO TMallOrderGroupon(FGrouponId,FCompId,FSpuId,FSkuId,FCustId,FPeople,FPrice,FHours,FJoinPeople,FRobotJoin,FRobotJoinHours,FLeastPeople,FGrouponStatus,FCreateTime,FFinishTime)
SELECT FBillId,FCompId,FGoodsId,FSkuId,FCustId,FCollageNumber,FSalePrice,5,FJoinNumber,0,5,FCollageNumber,'Grouponing',FCreateTime,NULL
FROM TMallOrderBill
WHERE FCollageNumber > 0
INSERT INTO TMallOrder(FOrderId,FOrderNo,FCompId,FCreateTime,FUpdateTime,FOrderTime,FGrouponId,
FBizType,FCustId,FWeChatAppId,FWeChatOpenId,FShareCustId,FConsignee,FMobile,FProvinceName,
FCityName,FDistrictName,FDetailAddress,FPostalCode,FRefundReason,
FOrderStatus,
FLastOrderStatus,
FBuyerMemo,FSellerMemo,
FDeliveryMode,
FDeliveryStatus,
FExpressCompany,FExpressNumber,FExpressTraces,
FExpressUpdateTime,FRedeemCode,FRedeemPW,FFreightAmount,FSendTime,FConfirmTime,
FPayType,FPayMemId,FPayPoint,FPayMoneyCardAmt,FPayMoneyCardId,FPayMoneyCardAcctId,FPayCourseCardAmt,FPayCourseCardId,FPayCourseCardPurTimes,FPayCourseCardFreeTimes,
FPayWeChatAmt,
FPayWeChatMchId,FPayWeChatAppId,FPayWeChatTradeNo,FPayWeChatStatus,FPayWeChatResult,FPayWeChatError,
FRefundPoint,FRefundMoneyCardAmt,FRefundCourseCardAmt,FRefundCourseCardPurTimes,FRefundCourseCardFreeTimes,FRefundWeChatAmt,FRefundWeChatTradeNo,FRefundWeChatResult,FRefundWeChatError)
SELECT A.FId,B.FBillNo,B.FCompId,A.FCreateTime,A.FCreateTime,A.FCreateTime,A.FBillId,
B.FBizType,A.FCustId,a. FWeChatAppId,'' AS FWeChatOpenId,0 AS FShareCustId,A. FConsignee,A.FTelephone,A. FProvinceName,
A. FCityName,A.FDistrictName,A.FDetailAddress,A. FPostalCode,'' AS FRefundReason,
CASE WHEN FBillStatus = 'Success' AND A.FDeliveryStatus = 'Confirm' THEN 'Finished'
WHEN FBillStatus = 'Success' AND A.FDeliveryStatus != 'Confirm' THEN 'WaitConfirm'
WHEN FBillStatus = 'Collaging' THEN 'Grouponing' ELSE '' END FOrderStatus,
'' as FLastOrderStatus,
'' AS FBuyerMemo,'' as FSellerMemo,
CASE FDeliveryMode WHEN 2 THEN 'Send' ELSE 'Receive' END AS FDeliveryMode,
a.FDeliveryStatus,
'' as FExpressCompany,'' as FExpressNumber,'' as FExpressTraces,
NULL AS FExpressUpdateTime,'' AS FRedeemCode,'' AS FRedeemPW,0 AS FFreightAmount,NULL AS FSendTime,NULL AS FConfirmTime,
CASE A.FPayTypeId WHEN 11 THEN 'Point' WHEN 20 THEN 'WeChat' WHEN 3 THEN 'MoneyCard' WHEN 6 THEN 'CourseCard' ELSE '' END,
A.FMemId AS FPayMemId,
CASE A.FPayTypeId WHEN 11 THEN FPayAmt ELSE 0 END AS FPayPoint,
CASE A.FPayTypeId WHEN 3 THEN FPayAmt ELSE 0 END AS FPayMoneyCardAmt,
A.FPayCardId AS FPayMoneyCardId,
CASE A.FPayTypeId WHEN 3 THEN A.FPayTypeId ELSE 0 END AS FPayMoneyCardAcctId,
CASE A.FPayTypeId WHEN 3 THEN A.FPayAmt ELSE 0 END AS FPayCourseCardAmt,
0 AS FPayCourseCardId,
0 AS FPayCourseCardPurTimes,
0 AS FPayCourseCardFreeTimes,
CASE A.FPayTypeId WHEN 20 THEN A.FPayAmt ELSE 0 END AS FPayWeChatAmt,
'' AS FPayWeChatMchId,A.FWeChatAppId AS FPayWeChatAppId,A.FTradeNo AS FPayWeChatTradeNo,A.FPayStatus AS FPayWeChatStatus,A.FPayResult AS FPayWeChatResult,A.FPayError AS FPayWeChatError,
0 as FRefundPoint,0 as FRefundMoneyCardAmt,0 as FRefundCourseCardAmt,0 as FRefundCourseCardPurTimes,0 as FRefundCourseCardFreeTimes,0 as FRefundWeChatAmt,'' as FRefundWeChatTradeNo,'' as FRefundWeChatResult,'' as FRefundWeChatError
FROM TMallOrderPayment as a,TMallOrderBill AS B
WHERE A.FBillId = B.FBillId
AND A.FPayStatus = 'Success'
INSERT INTO TMallOrderSku(FId,FOrderId,FSpuId,FSkuId,FSpuImage,FSpuName,FSkuImage,FSkuName,
FUnit,FBarCode,FNumber,FOrigPrice,
FCashPrice,FCashPoint,FMoneyCardPrice,FMoneyCardPoint,FCourseCardPrice,FCourseCardPoint,FPointPrice,
FSortIndex)
SELECT dbo.FNNewId(),A.FOrderId,SPU.FId AS FSpuId,SKU.FId AS FSkuId, SPU.FImage AS FSpuImage,SPU.FName AS FSpuName, SKU.FImage AS FSkuImage,SKU.FName AS FSkuName,
SPU.FUnit AS FUnit,'' AS FBarCode,1 AS FNumber ,b.FOrigPrice,
A.FPayWeChatAmt,0,A.FPayMoneyCardAmt,0,A.FPayCourseCardAmt,0,A.FPayPoint,0
FROM TMallOrder AS A,TMallOrderPayment AS P,TMallOrderBill AS B, TMallGoodsSpu AS SPU ,TMallGoodsSku AS SKU
WHERE A.FOrderId = P.FId
AND P.FBillId = B.FBillId
AND B.FGoodsId = SPU.FId
AND SPU.FId = SKU.FSPuId
INSERT INTO TMallOrderSkuRedeemCode(FId,FOrderId,FOrderSkuId,FCode,FStatus,FConfirmTime,FConfirmBillType,FConfirmBillId)
SELECT DBO.FNNewId(),B.FId,S.FId,B.FVoucherCode,CASE WHEN B.FDeliveryStatus = 'Confirm' THEN 'Confirm' ELSE 'Normal' END,FConfirmTime,FConfirmBillType,FConfirmBillId
FROM TMallOrderPayment AS B,TMallOrderSku AS S
WHERE S.FOrderId = B.FId
AND FVoucherCode != '' AND FVoucherCode NOT LIKE '%δ֧¸¶%'