Initialization.php
2.79 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
<?php
namespace App\Console\Commands;
use Illuminate\Console\Command;
use Illuminate\Support\Facades\Redis;
use Illuminate\Support\Facades\DB;
class Initialization extends Command
{
/**
* The name and signature of the console command.
*
* @var string
*/
protected $signature = 'Initialization';
/**
* The console command description.
*
* @var string
*/
protected $description = 'Command description';
/**
* Create a new command instance.
*
* @return void
*/
public function __construct()
{
parent::__construct();
}
/**
* Execute the console command.
*
* @return mixed
*/
public function handle()
{
$Redis= Redis::connection();
echo 'Start initialization supplier->';
$info= DB::connection('spu')->table('lie_supplier')->select('supplier_id','supplier_name')->get();
$datas=[];
foreach ($info as $k=>$v){
$datas[$v->supplier_id]=$v->supplier_name;
}
$result=$Redis->hmset('supplier',$datas);
if(!$result){
echo 'fail->';
}else{
echo 'Success->';
}
echo 'Start initialization brand->';
$info=[];
$datas=[];
$info= DB::connection('spu')->table('lie_brand')->select('brand_id','brand_name')->get();
foreach ($info as $k=>$v){
$datas[$v->brand_id]=$v->brand_name;
}
$result=null;
$result=$Redis->hmset('brand',$datas);
if(!$result){
echo 'fail->';
}else{
echo 'Success->';
}
echo 'Start initialization class->';
$info= DB::connection('spu')->table('lie_classify')->select('class_id','class_name')->get();
foreach ($info as $k=>$v){
$datas[$v->class_id]=$v->class_name;
}
$result=$Redis->hmset('class',$datas);
if(!$result){
echo 'fail->';
}else{
echo 'Success->';
}
echo 'Start initialization class_mapping->';
$list=DB::connection('spu')->table('lie_classify')->get();
$class=tree_class($list);
foreach ($class as $k1=>$v1){
$class[$k1]=(array)$class[$k1];
foreach ($class[$k1]['lower'] as $k2=>$v2){
$data=[];
$class[$k1]['lower'][$k2]=(array)$class[$k1]['lower'][$k2];
foreach ($class[$k1]['lower'][$k2]['lower'] as $k3=>$v3){
$class[$k1]['lower'][$k2]['lower'][$k3]=(array)$class[$k1]['lower'][$k2]['lower'][$k3];
$value=$v1->class_id.','.$v2->class_id;
$data[$v3->class_id]=$value;
}
$Redis->hmset('class_ing',$data);
}
}
echo 'complete';
}
}