jingcai-php/app/Console/Commands/Table/OptimizeBills.php

68 lines
1.8 KiB
PHP

<?php
namespace App\Console\Commands\Table;
use App\Model\Config;
use App\Model\Customer\CustomerBill;
use App\Model\Customer\CustomerFreeze;
use App\Model\Customer\CustomerRecharge;
use App\Model\Customer\CustomerWithdraw;
use App\Model\Seller\ShopBill;
use App\Model\Seller\ShopCooperateBill;
use App\Model\Seller\ShopFreeze;
use App\Model\Seller\ShopRecharge;
use App\Model\ShopAgentBill;
use Illuminate\Console\Command;
class OptimizeBills extends Command
{
/**
* 这个就是命令名称
*/
protected $signature = 'optimize:bills';
/**
* 命令的说明描述
* @var string
*/
protected $description = '优化流水相关的表,物理删除数据';
/**
* 创建命令的构造方法。
* @param string $words 传入的字符参数
* @return void
*/
public function __construct()
{
parent::__construct();
}
public function handle()
{
$currentDate = Config::keepDataDate();
// 账单流水
CustomerBill::where('created_at', '<', $currentDate)
->forceDelete();
ShopAgentBill::where('created_at', '<', $currentDate)
->forceDelete();
ShopBill::where('created_at', '<', $currentDate)
->forceDelete();
ShopCooperateBill::where('created_at', '<', $currentDate)
->forceDelete();
// 充值记录
CustomerRecharge::where('created_at', '<', $currentDate)
->forceDelete();
ShopRecharge::where('created_at', '<', $currentDate)
->forceDelete();
// 提现
CustomerWithdraw::where('created_at', '<', $currentDate)
->forceDelete();
CustomerFreeze::where('created_at', '<', $currentDate)
->forceDelete();
ShopFreeze::where('created_at', '<', $currentDate)
->forceDelete();
}
}