REAPI/database/migrations/20009999999986_install_stat_table.php

146 lines
7.6 KiB
PHP
Raw Normal View History

<?php
use think\admin\extend\PhinxExtend;
use think\migration\Migrator;
@set_time_limit(0);
@ini_set('memory_limit', -1);
class InstallStatTable extends Migrator
{
/**
* 创建数据库
*/
public function change()
{
$this->_create_stat();
$this->_create_stat_account();
$this->_create_stat_account_log();
$this->_create_stat_chnanel_account();
}
/**
* 创建数据对象
* @class Stat
* @table stat
* @return void
*/
private function _create_stat()
{
// 创建数据表对象
$table = $this->table('stat', [
'engine' => 'InnoDB', 'collation' => 'utf8mb4_general_ci', 'comment' => '',
]);
// 创建或更新数据表
PhinxExtend::upgrade($table, [
['day', 'string', ['limit' => 50, 'default' => NULL, 'null' => false, 'comment' => '']],
['total', 'decimal', ['precision' => 10, 'scale' => 2, 'default' => '0.00', 'null' => false, 'comment' => '总金额']],
['success', 'decimal', ['precision' => 10, 'scale' => 2, 'default' => '0.00', 'null' => false, 'comment' => '成功金额']],
['fail', 'decimal', ['precision' => 10, 'scale' => 2, 'default' => '0.00', 'null' => false, 'comment' => '失败金额']],
['product_cash', 'decimal', ['precision' => 10, 'scale' => 2, 'default' => '0.00', 'null' => false, 'comment' => '']],
['actual_cash', 'decimal', ['precision' => 10, 'scale' => 2, 'default' => '0.00', 'null' => false, 'comment' => '']],
['profit', 'decimal', ['precision' => 10, 'scale' => 3, 'default' => NULL, 'null' => false, 'comment' => '利润']],
['data', 'text', ['default' => NULL, 'null' => false, 'comment' => '记录的数据']],
['create_at', 'timestamp', ['default' => 'CURRENT_TIMESTAMP', 'null' => false, 'comment' => '']],
], [
'day',
], false);
}
/**
* 创建数据对象
* @class StatAccount
* @table stat_account
* @return void
*/
private function _create_stat_account()
{
// 创建数据表对象
$table = $this->table('stat_account', [
'engine' => 'InnoDB', 'collation' => 'utf8mb4_general_ci', 'comment' => '账户对账表',
]);
// 创建或更新数据表
PhinxExtend::upgrade($table, [
['day', 'string', ['limit' => 50, 'default' => NULL, 'null' => true, 'comment' => '']],
['merchant_shouru', 'string', ['limit' => 100, 'default' => NULL, 'null' => true, 'comment' => '收入']],
['merchant_zhichu', 'string', ['limit' => 100, 'default' => NULL, 'null' => true, 'comment' => '商户支出']],
['merchant_total', 'string', ['limit' => 100, 'default' => NULL, 'null' => true, 'comment' => '商户总计数据']],
['channel_shouru', 'string', ['limit' => 100, 'default' => NULL, 'null' => true, 'comment' => '渠道收入']],
['channel_zhichu', 'string', ['limit' => 100, 'default' => NULL, 'null' => true, 'comment' => '渠道支出']],
['channel_total', 'string', ['limit' => 100, 'default' => NULL, 'null' => true, 'comment' => '渠道总计']],
['account_shouru', 'string', ['limit' => 100, 'default' => NULL, 'null' => true, 'comment' => '银行收入']],
['account_zhichu', 'string', ['limit' => 100, 'default' => NULL, 'null' => true, 'comment' => '银行支出']],
['account_total', 'string', ['limit' => 100, 'default' => NULL, 'null' => true, 'comment' => '银行总计']],
['create_at', 'timestamp', ['default' => 'CURRENT_TIMESTAMP', 'null' => false, 'comment' => '']],
], [
'day',
], false);
}
/**
* 创建数据对象
* @class StatAccountLog
* @table stat_account_log
* @return void
*/
private function _create_stat_account_log()
{
// 创建数据表对象
$table = $this->table('stat_account_log', [
'engine' => 'InnoDB', 'collation' => 'utf8mb4_general_ci', 'comment' => '账户账目记录表',
]);
// 创建或更新数据表
PhinxExtend::upgrade($table, [
['name', 'string', ['limit' => 100, 'default' => NULL, 'null' => true, 'comment' => '标题']],
['day', 'string', ['limit' => 50, 'default' => NULL, 'null' => true, 'comment' => '天']],
['type', 'tinyinteger', ['limit' => 1, 'default' => 1, 'null' => false, 'comment' => '类型1是渠道2是商户3是公户']],
['type_id', 'integer', ['default' => '0', 'null' => false, 'comment' => '根据type不同而不同如type是1则type_id就是渠道id银行账户暂时固定为1']],
['type_name', 'string', ['limit' => 100, 'default' => NULL, 'null' => true, 'comment' => '类型名称']],
['oper', 'tinyinteger', ['limit' => 1, 'default' => 0, 'null' => false, 'comment' => '1增加2减少0是不加不减']],
['num', 'string', ['limit' => 100, 'default' => '0', 'null' => false, 'comment' => '数额']],
['desc', 'string', ['limit' => 500, 'default' => NULL, 'null' => true, 'comment' => '备注']],
['create_at', 'timestamp', ['default' => 'CURRENT_TIMESTAMP', 'null' => false, 'comment' => '']],
], [
'day', 'type', 'type_id',
], false);
}
/**
* 创建数据对象
* @class StatChnanelAccount
* @table stat_chnanel_account
* @return void
*/
private function _create_stat_chnanel_account()
{
// 创建数据表对象
$table = $this->table('stat_chnanel_account', [
'engine' => 'InnoDB', 'collation' => 'utf8mb4_general_ci', 'comment' => '',
]);
// 创建或更新数据表
PhinxExtend::upgrade($table, [
['cid', 'integer', ['default' => '0', 'null' => false, 'comment' => '渠道id']],
['pid', 'integer', ['default' => '0', 'null' => false, 'comment' => '产品id']],
['day', 'string', ['limit' => 50, 'default' => NULL, 'null' => true, 'comment' => '']],
['percent', 'string', ['limit' => 100, 'default' => '0', 'null' => false, 'comment' => '分成']],
['order_total', 'decimal', ['precision' => 10, 'scale' => 2, 'default' => '0.00', 'null' => false, 'comment' => '订单总金额']],
['order_success', 'decimal', ['precision' => 10, 'scale' => 2, 'default' => '0.00', 'null' => false, 'comment' => '订单成功金额']],
['order_fail', 'decimal', ['precision' => 10, 'scale' => 2, 'default' => '0.00', 'null' => false, 'comment' => '订单失败金额']],
['order_channel_cash', 'decimal', ['precision' => 10, 'scale' => 2, 'default' => '0.00', 'null' => false, 'comment' => '渠道计算完的成功金额']],
['account_total', 'decimal', ['precision' => 10, 'scale' => 2, 'default' => '0.00', 'null' => false, 'comment' => '账单总金额']],
['account_success', 'decimal', ['precision' => 10, 'scale' => 2, 'default' => '0.00', 'null' => false, 'comment' => '账单总成功金额']],
['account_fail', 'decimal', ['precision' => 10, 'scale' => 2, 'default' => '0.00', 'null' => false, 'comment' => '账单总失败金额']],
['account_product_success', 'decimal', ['precision' => 10, 'scale' => 3, 'default' => '0.000', 'null' => false, 'comment' => '账单计算完的值']],
['account_profit', 'decimal', ['precision' => 10, 'scale' => 2, 'default' => '0.00', 'null' => false, 'comment' => '账单利润']],
['yue', 'decimal', ['precision' => 10, 'scale' => 2, 'default' => '0.00', 'null' => false, 'comment' => '今天增加的余额']],
['channel_yue', 'decimal', ['precision' => 10, 'scale' => 2, 'default' => '0.00', 'null' => false, 'comment' => '当天渠道余额']],
['yesterday_channel_yue', 'decimal', ['precision' => 10, 'scale' => 2, 'default' => '0.00', 'null' => false, 'comment' => '昨日的余额']],
['create_at', 'timestamp', ['default' => 'CURRENT_TIMESTAMP', 'null' => false, 'comment' => '']],
], [
], false);
}
}