11
This commit is contained in:
parent
11d3d35433
commit
cbb6a29e0b
146
公司/工作/友达/脚本/common.sql
Normal file
146
公司/工作/友达/脚本/common.sql
Normal file
|
|
@ -0,0 +1,146 @@
|
|||
CREATE TABLE `diamond_products` (
|
||||
`id` INT UNSIGNED AUTO_INCREMENT PRIMARY KEY COMMENT '商品ID',
|
||||
`name` VARCHAR(50) NOT NULL COMMENT '商品名称,例如:200钻',
|
||||
`products_id` VARCHAR(64) NOT NULL COMMENT '产品ID',
|
||||
`products_type` VARCHAR(64) NOT NULL COMMENT '商品ID',
|
||||
`base_reward` VARCHAR(64) NOT NULL COMMENT '基础奖励数量',
|
||||
`price` DECIMAL(10,2) NOT NULL COMMENT '价格,单位:元',
|
||||
`is_first` TINYINT(1) DEFAULT 0 COMMENT '是否有首充,1=有,0=无',
|
||||
`first_bonus_reward` VARCHAR(64) COMMENT '首充额外赠送钻石数量',
|
||||
`first_charge_image` VARCHAR(255) COMMENT '首充展示图URL',
|
||||
`first_select_charge_image` VARCHAR(255) COMMENT '首充选中展示图URL',
|
||||
`normal_image` VARCHAR(255) COMMENT '非首充展示图URL',
|
||||
`normal_select_image` VARCHAR(255) COMMENT '非首充选中展示图URL',
|
||||
`sort_order` INT DEFAULT 0 COMMENT '排序值,越小越靠前',
|
||||
`status` TINYINT(1) DEFAULT 1 COMMENT '是否启用,1=启用,0=禁用',
|
||||
`created_at` DATETIME DEFAULT CURRENT_TIMESTAMP,
|
||||
`updated_at` DATETIME DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP
|
||||
) COMMENT='钻石商品表';
|
||||
|
||||
CREATE TABLE `diamond_orders` (
|
||||
`id` BIGINT UNSIGNED AUTO_INCREMENT PRIMARY KEY,
|
||||
`order_no` VARCHAR(64) NOT NULL COMMENT '订单号',
|
||||
`user_id` BIGINT UNSIGNED NOT NULL COMMENT '用户ID',
|
||||
`diamond_id` INT UNSIGNED NOT NULL COMMENT '商品ID',
|
||||
`product_id` VARCHAR(64) NOT NULL COMMENT '产品ID',
|
||||
`amount_paid` DECIMAL(10,2) NOT NULL COMMENT '实际支付金额',
|
||||
`pay_method` VARCHAR(20) NOT NULL COMMENT '支付方式,例如 alipay / wechat',
|
||||
`reward_log` VARCHAR(300) NULL COMMENT '奖励发送记录',
|
||||
`is_first_charge` TINYINT(1) DEFAULT 0 COMMENT '是否为首充',
|
||||
`status` VARCHAR(20) DEFAULT 'pending' COMMENT '支付状态,如 pending / success / failed',
|
||||
`created_at` DATETIME DEFAULT CURRENT_TIMESTAMP,
|
||||
`paid_at` DATETIME NULL COMMENT '支付成功时间',
|
||||
UNIQUE KEY (`order_no`)
|
||||
) COMMENT='钻石支付订单记录';
|
||||
|
||||
# 亏损补贴计算
|
||||
SELECT IFNULL(sum(price)+SUM(use_money),0) FROM `order` o LEFT join `user` u ON o.user_id=u.id where u.status=1 and u.istest=0
|
||||
and o.addtime>1746090058;
|
||||
|
||||
select c.* from (
|
||||
select t.*,
|
||||
(CASE
|
||||
WHEN t.use_money>0 THEN (t.use_money-t.fh_money-t.bb_money-t.money2)
|
||||
ELSE 0
|
||||
END) yue_money
|
||||
from (
|
||||
SELECT o.user_id,u.uid,u.nickname,u.headimg, u.mobile,
|
||||
u.money,
|
||||
u.integral,
|
||||
count(1) orderCount,
|
||||
sum(IFNULL(order_zhe_total,0)) order_zhe_total,
|
||||
IFNULL(sum(price),0) money_1,
|
||||
IFNULL(sum(use_money),0) money_2,
|
||||
IFNULL(sum(price)+SUM(use_money),0) use_money,
|
||||
( select IFNULL(sum(goodslist_money),0) sc_money from order_list where addtime<1746374399 and user_id=o.user_id and status=2) fh_money,
|
||||
( select IFNULL(sum(goodslist_money),0) sc_money from order_list where addtime<1746374399 and user_id=o.user_id and status=0) bb_money,
|
||||
(TRUNCATE(u.money2/100, 2)) money2
|
||||
|
||||
FROM `order` o LEFT join `user` u ON o.user_id=u.id where u.status=1 and u.istest=0 and o.status=1
|
||||
and o.addtime>1745550000 and o.addtime<1746374399 group by o.user_id ) t where use_money>0
|
||||
) c order by yue_money desc;
|
||||
# 订单列表
|
||||
select o.id,o.goods_title,o.order_num,o.user_id,u.nickname,u.mobile, o.order_total,o.order_zhe_total,o.price,o.use_money,o.use_integral,o.use_money2,
|
||||
o.goods_id,o.num,o.goods_price,o.goods_imgurl,o.prize_num,o.status,o.addtime,o.pay_time,o.pay_type,o.order_type,o.coupon_id,o.use_coupon,
|
||||
o.is_shou_zhe,o.is_flw,
|
||||
CASE
|
||||
WHEN o.status=1 THEN (select IFNULL(sum(goodslist_money),0) from order_list ol where ol.order_id=o.id and ol.goodslist_type<3)
|
||||
ELSE 0
|
||||
END sc_money,u.status,u.istest,u.uid
|
||||
from `order` o inner join `user` u ON o.user_id=u.id
|
||||
where u.status=1 and u.istest=0 o.status ;
|
||||
|
||||
select `key`,`value` from config;
|
||||
select * from goods_type;
|
||||
# 发起订单数
|
||||
SELECT count(1) orderCount FROM `order` o LEFT join `user` u ON o.user_id=u.id where u.status=1 and u.istest=0 and o.addtime>UNIX_TIMESTAMP(CURDATE());
|
||||
# 今日消费数据 use_money 钻石 use_integral UU币 use_money2 达达券 price 微信支付 use_coupon 优惠卷抵扣 userCount消费人数 orderCount订单次数 order_zhe_total 订单总金额
|
||||
SELECT count(DISTINCT(user_id)) userCount, count(1) orderCount,sum(order_zhe_total) order_zhe_total, IFNULL(sum(use_money),0) use_money,IFNULL(sum(use_integral),0) use_integral,IFNULL(sum(use_money2),0) use_money2,IFNULL(sum(price),0) price,sum(use_coupon) use_coupon FROM `order` o LEFT join `user` u ON o.user_id=u.id where u.status=1 and u.istest=0 and o.status=1 and o.addtime>UNIX_TIMESTAMP(CURDATE());
|
||||
# 今日收入
|
||||
SELECT IFNULL(sum(ol.price),0)+IFNULL(sum(ol.use_money),0) FROM `order` ol LEFT join `user` us ON ol.user_id=us.id where us.status=1 and us.istest=0 and ol.status=1 and ol.pay_time>UNIX_TIMESTAMP(CURDATE());
|
||||
# RMB 收入
|
||||
SELECT IFNULL(sum(ol.price),0) FROM `order` ol LEFT join `user` us ON ol.user_id=us.id where us.status=1 and us.istest=0 and ol.status=1 and ol.pay_time>UNIX_TIMESTAMP(CURDATE());
|
||||
# 其它收入
|
||||
SELECT IFNULL(sum(price),0) from profit_revenue where profit_date = CURDATE();
|
||||
|
||||
|
||||
|
||||
# 今日出货总额
|
||||
SELECT IFNULL(sum(goodslist_money),0) FROM order_list oll LEFT join `user` us on oll.user_id=us.id where us.status=1 and us.istest=0 and oll.goodslist_type<3 and oll.addtime>UNIX_TIMESTAMP(CURDATE());
|
||||
# 今日发货总金额
|
||||
SELECT IFNULL(sum(goodslist_money),0) FROM order_list oll LEFT join `user` us on oll.user_id=us.id where us.status=1 and us.istest=0 and oll.status=2 and oll.goodslist_type<3 and oll.choice_time>UNIX_TIMESTAMP(CURDATE());;
|
||||
# 今日兑换达达券
|
||||
SELECT IFNULL(sum(goodslist_money),0) FROM order_list oll LEFT join `user` us on oll.user_id=us.id where us.status=1 and us.istest=0 and oll.status=1 and oll.goodslist_type<3 and oll.choice_time>UNIX_TIMESTAMP(CURDATE());;
|
||||
# 今日盒柜剩余价值
|
||||
SELECT IFNULL(sum(goodslist_money),0) FROM order_list oll LEFT join `user` us on oll.user_id=us.id where us.status=1 and us.istest=0 and oll.status=0 and oll.goodslist_type<3 and oll.addtime>UNIX_TIMESTAMP(CURDATE());;
|
||||
|
||||
-- 今日达达券货币发放
|
||||
select IFNULL(sum(change_money),0) from profit_money2 m LEFT join `user` u on m.user_id=u.id where u.status=1 and u.istest=0 and m.change_money>0 and m.addtime>UNIX_TIMESTAMP(CURDATE());
|
||||
|
||||
|
||||
-- 今日达达券货币消费
|
||||
select IFNULL(sum(ABS(change_money)),0) from profit_money2 m LEFT join `user` u on m.user_id=u.id where u.status=1 and u.istest=0 and m.change_money<0 and m.addtime>UNIX_TIMESTAMP(CURDATE());
|
||||
|
||||
# 今日钻石发放
|
||||
select IFNULL(sum(change_money),0) from profit_money m LEFT join `user` u on m.user_id=u.id where u.status=1 and u.istest=0 and m.change_money>0 and m.addtime>UNIX_TIMESTAMP(CURDATE());
|
||||
# 今日钻石消费
|
||||
select IFNULL(sum(ABS(change_money)),0) from profit_money m LEFT join `user` u on m.user_id=u.id where u.status=1 and u.istest=0 and m.change_money<0 and m.addtime>UNIX_TIMESTAMP(CURDATE());
|
||||
|
||||
# 今日UU币发放
|
||||
select IFNULL(sum(change_money),0) from profit_integral m LEFT join `user` u on m.user_id=u.id where u.status=1 and u.istest=0 and m.change_money>0 and m.addtime>UNIX_TIMESTAMP(CURDATE());
|
||||
# 今日UU币消费
|
||||
select IFNULL(sum(ABS(change_money)),0) from profit_integral m LEFT join `user` u on m.user_id=u.id where u.status=1 and u.istest=0 and m.change_money<0 and m.addtime>UNIX_TIMESTAMP(CURDATE());
|
||||
|
||||
|
||||
-- 昨日达达券货币发放
|
||||
select IFNULL(sum(change_money),0) from profit_money2 m LEFT join user u on m.user_id=u.id where u.status=1 and u.istest=0 and m.change_money>0 and m.addtime>=UNIX_TIMESTAMP(DATE_SUB(CURDATE(), INTERVAL 1 DAY)) and m.addtime<UNIX_TIMESTAMP(CURDATE());
|
||||
|
||||
-- 昨日达达券货币消费
|
||||
select IFNULL(sum(ABS(change_money)),0) from profit_money2 m LEFT join user u on m.user_id=u.id where u.status=1 and u.istest=0 and m.change_money<0 and m.addtime>=UNIX_TIMESTAMP(DATE_SUB(CURDATE(), INTERVAL 1 DAY)) and m.addtime<UNIX_TIMESTAMP(CURDATE());
|
||||
|
||||
-- 昨日钻石发放
|
||||
select IFNULL(sum(change_money),0) from profit_money m LEFT join user u on m.user_id=u.id where u.status=1 and u.istest=0 and m.change_money>0 and m.addtime>=UNIX_TIMESTAMP(DATE_SUB(CURDATE(), INTERVAL 1 DAY)) and m.addtime<UNIX_TIMESTAMP(CURDATE());
|
||||
|
||||
-- 昨日钻石消费
|
||||
select IFNULL(sum(ABS(change_money)),0) from profit_money m LEFT join user u on m.user_id=u.id where u.status=1 and u.istest=0 and m.change_money<0 and m.addtime>=UNIX_TIMESTAMP(DATE_SUB(CURDATE(), INTERVAL 1 DAY)) and m.addtime<UNIX_TIMESTAMP(CURDATE());
|
||||
|
||||
-- 昨日UU币发放
|
||||
select IFNULL(sum(change_money),0) from profit_integral m LEFT join user u on m.user_id=u.id where u.status=1 and u.istest=0 and m.change_money>0 and m.addtime>=UNIX_TIMESTAMP(DATE_SUB(CURDATE(), INTERVAL 1 DAY)) and m.addtime<UNIX_TIMESTAMP(CURDATE());
|
||||
|
||||
-- 昨日UU币消费
|
||||
select IFNULL(sum(ABS(change_money)),0) from profit_integral m LEFT join user u on m.user_id=u.id where u.status=1 and u.istest=0 and m.change_money<0 and m.addtime>=UNIX_TIMESTAMP(DATE_SUB(CURDATE(), INTERVAL 1 DAY)) and m.addtime<UNIX_TIMESTAMP(CURDATE());
|
||||
|
||||
|
||||
CREATE TABLE `user_address` (
|
||||
`id` int(10) NOT NULL AUTO_INCREMENT COMMENT '地址ID',
|
||||
`user_id` int(10) NOT NULL COMMENT '用户ID',
|
||||
`receiver_name` varchar(50) NOT NULL COMMENT '收货人姓名',
|
||||
`receiver_phone` varchar(20) NOT NULL COMMENT '收货人电话',
|
||||
`detailed_address` varchar(255) NOT NULL COMMENT '详细地址',
|
||||
`is_default` tinyint(1) DEFAULT '0' COMMENT '是否默认地址(0:否 1:是)',
|
||||
`create_time` datetime NOT NULL DEFAULT CURRENT_TIMESTAMP COMMENT '创建时间',
|
||||
`update_time` datetime NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP COMMENT '更新时间',
|
||||
`is_deleted` tinyint(1) DEFAULT '0' COMMENT '是否删除(0:否 1:是)',
|
||||
PRIMARY KEY (`id`),
|
||||
KEY `idx_user_id` (`user_id`) COMMENT '用户ID索引'
|
||||
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COMMENT='用户收货地址表';
|
||||
Loading…
Reference in New Issue
Block a user