67 lines
1.8 KiB
PHP
Executable File
67 lines
1.8 KiB
PHP
Executable File
<?php
|
|
|
|
namespace App\Console\Commands;
|
|
|
|
use App\Contracts\LcardActionLogsInterface;
|
|
use App\Contracts\LoyaltyCardResourceInterface;
|
|
use App\Contracts\MobileAnalyticsResourceInterface;
|
|
use Carbon\Carbon;
|
|
use Illuminate\Console\Command;
|
|
use Illuminate\Support\Facades\DB;
|
|
|
|
class InactiveLoyaltyCard extends Command
|
|
{
|
|
/**
|
|
* The name and signature of the console command.
|
|
*
|
|
* @var string
|
|
*/
|
|
protected $signature = 'inactive:loyaltycard';
|
|
|
|
/**
|
|
* The console command description.
|
|
*
|
|
* @var string
|
|
*/
|
|
protected $description = 'Inactived loyalty card that has no transactions in the log';
|
|
|
|
/**
|
|
* Create a new command instance.
|
|
*
|
|
* @return void
|
|
*/
|
|
public function __construct()
|
|
{
|
|
parent::__construct();
|
|
}
|
|
|
|
/**
|
|
* Execute the console command.
|
|
*
|
|
* @return mixed
|
|
*/
|
|
public function handle(LcardActionLogsInterface $lcardActionLogscard, LoyaltyCardResourceInterface $loyalty_card,MobileAnalyticsResourceInterface $mobile_usage)
|
|
{
|
|
|
|
$now = Carbon::now()->subYear();
|
|
$orders = DB::select(
|
|
"SELECT *
|
|
FROM lcard_action_logs t1
|
|
WHERE t1.created_at = (
|
|
SELECT MAX(t2.created_at)
|
|
FROM lcard_action_logs t2
|
|
WHERE t2.created_by = t1.created_by)
|
|
and created_at < '".$now."'
|
|
and created_by <> 0
|
|
group by created_by");
|
|
echo "-------start-------";
|
|
foreach ($orders as $key => $value){
|
|
$mobile_usage->add_inactive();
|
|
$loyalty_card->setInactive($value->created_by);
|
|
$lcardActionLogscard->log($value->created_by,'CRONJOB','INACTIVE');
|
|
print_r($value);
|
|
}
|
|
echo "-------finish-------";
|
|
}
|
|
}
|