update: sql

This commit is contained in:
tokumeikoi 2020-12-22 15:21:18 +08:00
parent 9a465d9bb4
commit b8b7033132
2 changed files with 61 additions and 44 deletions

View File

@ -4,7 +4,7 @@ namespace App\Console\Commands;
use App\Jobs\StatServerJob; use App\Jobs\StatServerJob;
use Illuminate\Console\Command; use Illuminate\Console\Command;
use App\Models\ServerLog; use App\Models\Order;
use Illuminate\Support\Facades\DB; use Illuminate\Support\Facades\DB;
class V2BoardStatistics extends Command class V2BoardStatistics extends Command
@ -40,12 +40,29 @@ class V2BoardStatistics extends Command
*/ */
public function handle() public function handle()
{ {
$this->statServer(); $this->statOrder();
// $this->statServer();
} }
private function statOrder() private function statOrder()
{ {
$endAt = strtotime(date('Y-m-d'));
$startAt = strtotime('-1 day', $endAt);
$builder = Order::where('updated_at', '>=', $startAt)
->where('updated_at', '<', $endAt)
->whereIn('status', [3, 4]);
$orderCount = $builder->count();
$orderAmount = $builder->sum('total_amount');
$builder = $builder->where('commission_balance', '!=', NULL)
->whereIn('commission_status', [1, 2]);
$commissionCount = $builder->count();
$commissionAmount = $builder->sum('commission_balance');
dd([
$orderCount,
$orderAmount,
$commissionCount,
$commissionAmount
]);
} }
private function statServer() private function statServer()

View File

@ -1,9 +1,9 @@
-- Adminer 4.7.8 MySQL dump -- Adminer 4.7.8 MySQL dump
SET NAMES utf8; SET NAMES utf8;
SET time_zone = ''+00:00''; SET time_zone = '+00:00';
SET foreign_key_checks = 0; SET foreign_key_checks = 0;
SET sql_mode = ''NO_AUTO_VALUE_ON_ZERO''; SET sql_mode = 'NO_AUTO_VALUE_ON_ZERO';
SET NAMES utf8mb4; SET NAMES utf8mb4;
@ -52,16 +52,16 @@ CREATE TABLE `v2_invite_code` (
DROP TABLE IF EXISTS `v2_knowledge`; DROP TABLE IF EXISTS `v2_knowledge`;
CREATE TABLE `v2_knowledge` ( CREATE TABLE `v2_knowledge` (
`id` int(11) NOT NULL AUTO_INCREMENT, `id` int(11) NOT NULL AUTO_INCREMENT,
`language` char(5) NOT NULL COMMENT '''', `language` char(5) NOT NULL COMMENT '語言',
`category` varchar(255) NOT NULL COMMENT '''', `category` varchar(255) NOT NULL COMMENT '分類名',
`title` varchar(255) NOT NULL COMMENT '''', `title` varchar(255) NOT NULL COMMENT '標題',
`body` text NOT NULL COMMENT '''', `body` text NOT NULL COMMENT '內容',
`sort` int(11) DEFAULT NULL COMMENT '''', `sort` int(11) DEFAULT NULL COMMENT '排序',
`show` tinyint(1) NOT NULL DEFAULT 0 COMMENT '''', `show` tinyint(1) NOT NULL DEFAULT 0 COMMENT '顯示',
`created_at` int(11) NOT NULL COMMENT '''', `created_at` int(11) NOT NULL COMMENT '創建時間',
`updated_at` int(11) NOT NULL COMMENT '''', `updated_at` int(11) NOT NULL COMMENT '更新時間',
PRIMARY KEY (`id`) PRIMARY KEY (`id`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COMMENT=''''; ) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COMMENT='知識庫';
DROP TABLE IF EXISTS `v2_mail_log`; DROP TABLE IF EXISTS `v2_mail_log`;
@ -96,18 +96,18 @@ CREATE TABLE `v2_order` (
`user_id` int(11) NOT NULL, `user_id` int(11) NOT NULL,
`plan_id` int(11) NOT NULL, `plan_id` int(11) NOT NULL,
`coupon_id` int(11) DEFAULT NULL, `coupon_id` int(11) DEFAULT NULL,
`type` int(11) NOT NULL COMMENT ''123'', `type` int(11) NOT NULL COMMENT '1新购2续费3升级',
`cycle` varchar(255) NOT NULL, `cycle` varchar(255) NOT NULL,
`trade_no` varchar(36) NOT NULL, `trade_no` varchar(36) NOT NULL,
`callback_no` varchar(255) DEFAULT NULL, `callback_no` varchar(255) DEFAULT NULL,
`total_amount` int(11) NOT NULL, `total_amount` int(11) NOT NULL,
`discount_amount` int(11) DEFAULT NULL, `discount_amount` int(11) DEFAULT NULL,
`surplus_amount` int(11) DEFAULT NULL COMMENT '''', `surplus_amount` int(11) DEFAULT NULL COMMENT '剩余价值',
`refund_amount` int(11) DEFAULT NULL COMMENT ''退'', `refund_amount` int(11) DEFAULT NULL COMMENT '退款金额',
`balance_amount` int(11) DEFAULT NULL COMMENT ''使'', `balance_amount` int(11) DEFAULT NULL COMMENT '使用余额',
`surplus_order_ids` text DEFAULT NULL COMMENT '''', `surplus_order_ids` text DEFAULT NULL COMMENT '折抵订单',
`status` tinyint(1) NOT NULL DEFAULT 0 COMMENT ''01234'', `status` tinyint(1) NOT NULL DEFAULT 0 COMMENT '0待支付1开通中2已取消3已完成4已折抵',
`commission_status` tinyint(1) NOT NULL DEFAULT 0 COMMENT ''0123'', `commission_status` tinyint(1) NOT NULL DEFAULT 0 COMMENT '0待确认1发放中2有效3无效',
`commission_balance` int(11) NOT NULL DEFAULT 0, `commission_balance` int(11) NOT NULL DEFAULT 0,
`created_at` int(11) NOT NULL, `created_at` int(11) NOT NULL,
`updated_at` int(11) NOT NULL, `updated_at` int(11) NOT NULL,
@ -216,57 +216,57 @@ CREATE TABLE `v2_server_shadowsocks` (
DROP TABLE IF EXISTS `v2_server_trojan`; DROP TABLE IF EXISTS `v2_server_trojan`;
CREATE TABLE `v2_server_trojan` ( CREATE TABLE `v2_server_trojan` (
`id` int(11) NOT NULL AUTO_INCREMENT COMMENT ''ID'', `id` int(11) NOT NULL AUTO_INCREMENT COMMENT '节点ID',
`group_id` varchar(255) NOT NULL COMMENT '''', `group_id` varchar(255) NOT NULL COMMENT '节点组',
`parent_id` int(11) DEFAULT NULL COMMENT '''', `parent_id` int(11) DEFAULT NULL COMMENT '父节点',
`tags` varchar(255) DEFAULT NULL COMMENT '''', `tags` varchar(255) DEFAULT NULL COMMENT '节点标签',
`name` varchar(255) NOT NULL COMMENT '''', `name` varchar(255) NOT NULL COMMENT '节点名称',
`rate` varchar(11) NOT NULL COMMENT '''', `rate` varchar(11) NOT NULL COMMENT '倍率',
`host` varchar(255) NOT NULL COMMENT '''', `host` varchar(255) NOT NULL COMMENT '主机名',
`port` int(11) NOT NULL COMMENT '''', `port` int(11) NOT NULL COMMENT '连接端口',
`server_port` int(11) NOT NULL COMMENT '''', `server_port` int(11) NOT NULL COMMENT '服务端口',
`allow_insecure` tinyint(1) NOT NULL DEFAULT 0 COMMENT '''', `allow_insecure` tinyint(1) NOT NULL DEFAULT 0 COMMENT '是否允许不安全',
`server_name` varchar(255) DEFAULT NULL, `server_name` varchar(255) DEFAULT NULL,
`show` tinyint(1) NOT NULL DEFAULT 0 COMMENT '''', `show` tinyint(1) NOT NULL DEFAULT 0 COMMENT '是否显示',
`sort` int(11) DEFAULT NULL, `sort` int(11) DEFAULT NULL,
`created_at` int(11) NOT NULL, `created_at` int(11) NOT NULL,
`updated_at` int(11) NOT NULL, `updated_at` int(11) NOT NULL,
PRIMARY KEY (`id`) PRIMARY KEY (`id`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COMMENT=''trojan伺服器表''; ) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COMMENT='trojan伺服器表';
DROP TABLE IF EXISTS `v2_stat_order`; DROP TABLE IF EXISTS `v2_stat_order`;
CREATE TABLE `v2_stat_order` ( CREATE TABLE `v2_stat_order` (
`id` int(11) NOT NULL AUTO_INCREMENT, `id` int(11) NOT NULL AUTO_INCREMENT,
`order_count` int(11) NOT NULL COMMENT '''', `order_count` int(11) NOT NULL COMMENT '订单数量',
`order_amount` int(11) NOT NULL COMMENT '''', `order_amount` int(11) NOT NULL COMMENT '订单合计',
`commission_count` int(11) NOT NULL, `commission_count` int(11) NOT NULL,
`commission_amount` int(11) NOT NULL COMMENT '''', `commission_amount` int(11) NOT NULL COMMENT '佣金合计',
`record_type` char(1) NOT NULL, `record_type` char(1) NOT NULL,
`record_at` int(11) NOT NULL, `record_at` int(11) NOT NULL,
`created_at` int(11) NOT NULL, `created_at` int(11) NOT NULL,
`updated_at` int(11) NOT NULL, `updated_at` int(11) NOT NULL,
PRIMARY KEY (`id`), PRIMARY KEY (`id`),
UNIQUE KEY `record_at` (`record_at`) UNIQUE KEY `record_at` (`record_at`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8 COMMENT=''''; ) ENGINE=InnoDB DEFAULT CHARSET=utf8 COMMENT='订单统计';
DROP TABLE IF EXISTS `v2_stat_server`; DROP TABLE IF EXISTS `v2_stat_server`;
CREATE TABLE `v2_stat_server` ( CREATE TABLE `v2_stat_server` (
`id` int(11) NOT NULL AUTO_INCREMENT, `id` int(11) NOT NULL AUTO_INCREMENT,
`server_id` int(11) NOT NULL COMMENT ''id'', `server_id` int(11) NOT NULL COMMENT '节点id',
`server_type` char(11) NOT NULL COMMENT '''', `server_type` char(11) NOT NULL COMMENT '节点类型',
`u` varchar(255) NOT NULL, `u` varchar(255) NOT NULL,
`d` varchar(255) NOT NULL, `d` varchar(255) NOT NULL,
`record_type` char(1) NOT NULL COMMENT ''d day m month'', `record_type` char(1) NOT NULL COMMENT 'd day m month',
`record_at` int(11) NOT NULL COMMENT '''', `record_at` int(11) NOT NULL COMMENT '记录时间',
`created_at` int(11) NOT NULL, `created_at` int(11) NOT NULL,
`updated_at` int(11) NOT NULL, `updated_at` int(11) NOT NULL,
PRIMARY KEY (`id`), PRIMARY KEY (`id`),
UNIQUE KEY `server_id_server_type_record_at` (`server_id`,`server_type`,`record_at`), UNIQUE KEY `server_id_server_type_record_at` (`server_id`,`server_type`,`record_at`),
KEY `record_at` (`record_at`), KEY `record_at` (`record_at`),
KEY `server_id` (`server_id`) KEY `server_id` (`server_id`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8 COMMENT=''''; ) ENGINE=InnoDB DEFAULT CHARSET=utf8 COMMENT='节点数据统计';
DROP TABLE IF EXISTS `v2_ticket`; DROP TABLE IF EXISTS `v2_ticket`;
@ -276,7 +276,7 @@ CREATE TABLE `v2_ticket` (
`last_reply_user_id` int(11) NOT NULL, `last_reply_user_id` int(11) NOT NULL,
`subject` varchar(255) NOT NULL, `subject` varchar(255) NOT NULL,
`level` tinyint(1) NOT NULL, `level` tinyint(1) NOT NULL,
`status` tinyint(1) NOT NULL DEFAULT 0 COMMENT ''0: 1:'', `status` tinyint(1) NOT NULL DEFAULT 0 COMMENT '0:已开启 1:已关闭',
`created_at` int(11) NOT NULL, `created_at` int(11) NOT NULL,
`updated_at` int(11) NOT NULL, `updated_at` int(11) NOT NULL,
PRIMARY KEY (`id`) PRIMARY KEY (`id`)
@ -330,4 +330,4 @@ CREATE TABLE `v2_user` (
) ENGINE=InnoDB DEFAULT CHARSET=utf8; ) ENGINE=InnoDB DEFAULT CHARSET=utf8;
-- 2020-12-20 08:56:10 -- 2020-12-22 07:19:34