1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace App\Console\Commands; |
4
|
|
|
|
5
|
|
|
use Illuminate\Console\Command; |
6
|
|
|
use Illuminate\Support\Facades\Storage; |
7
|
|
|
use App\Account; |
8
|
|
|
|
9
|
|
|
abstract class AbstractExportCommand extends Command |
10
|
|
|
{ |
11
|
|
|
|
12
|
|
|
/** |
13
|
|
|
* The name and signature of the console command. |
14
|
|
|
* |
15
|
|
|
* @var string |
16
|
|
|
*/ |
17
|
|
|
protected $signature = ''; |
18
|
|
|
|
19
|
|
|
/** |
20
|
|
|
* The console command description. |
21
|
|
|
* |
22
|
|
|
* @var string |
23
|
|
|
*/ |
24
|
|
|
protected $description = ''; |
25
|
|
|
|
26
|
|
|
/** |
27
|
|
|
* The export folder location. |
28
|
|
|
* |
29
|
|
|
* @var string |
30
|
|
|
*/ |
31
|
|
|
protected $exportFolder = ''; |
32
|
|
|
|
33
|
|
|
/** |
34
|
|
|
* The export file name. |
35
|
|
|
* |
36
|
|
|
* @var string |
37
|
|
|
*/ |
38
|
|
|
protected $exportFileName = ''; |
39
|
|
|
|
40
|
|
|
|
41
|
|
|
/** |
42
|
|
|
* The export extension file. |
43
|
|
|
* |
44
|
|
|
* @var string |
45
|
|
|
*/ |
46
|
|
|
protected $exportFileExt = '.txt'; |
47
|
|
|
|
48
|
|
|
/** |
49
|
|
|
* The export storage disk name. |
50
|
|
|
* |
51
|
|
|
* @var string |
52
|
|
|
*/ |
53
|
|
|
protected $storageDisk = 'export'; |
54
|
|
|
|
55
|
|
|
/** |
56
|
|
|
* The export storage location. |
57
|
|
|
* |
58
|
|
|
* @var Illuminate\Contracts\Filesystem\Filesystem |
59
|
|
|
*/ |
60
|
|
|
protected $storage; |
61
|
|
|
|
62
|
|
|
/** |
63
|
|
|
* Create a new command instance. |
64
|
|
|
* |
65
|
|
|
* @return void |
|
|
|
|
66
|
|
|
*/ |
67
|
|
|
public function __construct() |
68
|
|
|
{ |
69
|
|
|
parent::__construct(); |
70
|
|
|
$this->storage = Storage::disk($this->storageDisk); |
|
|
|
|
71
|
|
|
} |
72
|
|
|
|
73
|
|
|
/** |
74
|
|
|
* Execute the console command. |
75
|
|
|
* |
76
|
|
|
* @return mixed |
77
|
|
|
*/ |
78
|
|
|
abstract public function handle(); |
79
|
|
|
|
80
|
|
|
final protected function exportAccounts($accounts, $filename, $password = false, $flagCI = false) |
81
|
|
|
{ |
82
|
|
|
$this->storage->put($filename, ''); |
83
|
|
|
|
84
|
|
|
$count = count($accounts); |
85
|
|
|
|
86
|
|
|
if ($flagCI === false) { |
87
|
|
|
$bar = $this->output->createProgressBar($count); |
88
|
|
|
} |
89
|
|
|
|
90
|
|
|
foreach ($accounts as $account) { |
91
|
|
|
$record = "{$account->netlogin}"; |
92
|
|
|
$record .= $password ? ":{$account->netpass}" : ''; |
93
|
|
|
$this->storage->prepend($filename, $record); |
94
|
|
|
if (isset($bar)) { |
95
|
|
|
$bar->advance(); |
96
|
|
|
} |
97
|
|
|
} |
98
|
|
|
|
99
|
|
|
if (isset($bar)) { |
100
|
|
|
$bar->finish(); |
101
|
|
|
$this->info("\n"); |
102
|
|
|
} |
103
|
|
|
|
104
|
|
|
return $count; |
105
|
|
|
} |
106
|
|
|
|
107
|
|
|
final protected function fecthAccounts($filter=null) |
108
|
|
|
{ |
109
|
|
|
$query = Account::where('status', Account::ACCOUNT_ENABLE); |
110
|
|
|
|
111
|
|
|
if(is_null($filter) === false && is_array($filter)) { |
112
|
|
|
$query = $query->where($filter); |
113
|
|
|
} |
114
|
|
|
|
115
|
|
|
return $query->orderBy('netlogin', 'desc')->get(); |
116
|
|
|
} |
117
|
|
|
} |
118
|
|
|
|
Adding a
@return
annotation to a constructor is not recommended, since a constructor does not have a meaningful return value.Please refer to the PHP core documentation on constructors.