作者 赵彬吉

update

@@ -18,6 +18,7 @@ use App\Services\ProjectServer; @@ -18,6 +18,7 @@ use App\Services\ProjectServer;
18 use Illuminate\Console\Command; 18 use Illuminate\Console\Command;
19 use Illuminate\Database\QueryException; 19 use Illuminate\Database\QueryException;
20 use Illuminate\Support\Facades\DB; 20 use Illuminate\Support\Facades\DB;
  21 +use Illuminate\Support\Str;
21 22
22 /** 23 /**
23 * 测试 24 * 测试
@@ -57,65 +58,52 @@ class Test extends Command @@ -57,65 +58,52 @@ class Test extends Command
57 */ 58 */
58 public function handle() 59 public function handle()
59 { 60 {
60 - $projects = Project::all();  
61 - foreach ($projects as $project){  
62 - echo "project " . $project->id;  
63 -  
64 - if(!ProjectServer::useProject($project->id)){  
65 - echo '-->' . '未配置数据库' . PHP_EOL;  
66 - continue; 61 + $domains = DB::table('gl_customer_visit')->groupBy('domain')->select('domain')->pluck('domain')->toArray();
  62 + foreach($domains as $domain){
  63 + if(!Str::contains($domain, 'globalso.site')){
  64 + $this->sync($domain);
67 } 65 }
  66 + }
  67 + }
  68 +
  69 + public function sync($domain){
  70 + echo date('Y-m-d H:i:s') . "同步项目{$domain}" . PHP_EOL;
  71 + if(!Str::startsWith($domain,'www.')){
  72 + $domain = 'www.'.$domain;
  73 + }
  74 + $project_id = DomainInfo::where('domain', $domain)->value('project_id');
  75 + if(!$project_id){
  76 + echo date('Y-m-d H:i:s') . "项目{$domain}不存在" . PHP_EOL;
  77 + return true;
  78 + }
  79 + if(!ProjectServer::useProject($project_id)){
  80 + echo date('Y-m-d H:i:s') . "项目{$domain}数据库配置无效" . PHP_EOL;
  81 + return true;
  82 + }
  83 + $visit = 0;
  84 + $visit_item = 0;
  85 + $list = DB::table('gl_customer_visit')->whereIn('domain', [$domain, str_replace('www.','',$domain)])->get();
  86 + foreach ($list as $v){
  87 + $v = (array) $v;
  88 +
  89 + $items = DB::table('gl_customer_visit_item')->where('customer_visit_id', $v['id'])->get();
  90 +
  91 + unset($v['id']);
  92 + $id = DB::connection('custom_mysql')->table('gl_customer_visit')->insertGetId($v);
68 93
69 - try {  
70 - $page = BCustomTemplate::where('url', '404')->first();  
71 - if(!$page){  
72 - $page = new BCustomTemplate();  
73 - }  
74 - $page->project_id = $project->id;  
75 - $page->name = '404';  
76 - $page->status = 1;  
77 - $page->url = '404';  
78 - $page->html = '<main>  
79 - <section data-section="section" data-screen="screen-large" class="section-404-wrap-block section-block-error404"  
80 - id="sectionIdyxqu938">  
81 - <div class="layout" data-unable="demo01-error404">  
82 - <img src="https://ecdn6.globalso.com/upload/m/image_other/2023-10/6528a87e594db30162.png" />  
83 - </div>  
84 - <p style="text-align: center">SORRY. THE PAGE HAS EITHER MOVED OR CANNOT BE FOUND.</p>  
85 - <style>  
86 - .section-block-error404 .layout {  
87 - height: 700px;  
88 - display: flex;  
89 - align-items: center;  
90 - justify-content: center;  
91 - }  
92 - .section-block-error404 img {  
93 - width: 400px;  
94 - }  
95 - @media only screen and (max-width:500) {  
96 - .section-block-error404 img {  
97 - max-width: 100%;  
98 - }  
99 - }  
100 - </style>  
101 - <script>  
102 - </script>  
103 - </section>  
104 - </main>';  
105 - $page->html_style = '<style id="globalsojs-styles"></style>';  
106 - $page->description = 'Sorry. The page has either moved or cannot be found.';  
107 - $page->title = '404-Page not found';  
108 - $page->save(); 94 + $visit++;
109 95
110 - $domain = (new DomainInfo())->getDomain($project['deploy_optimize']['domain']);  
111 - $url = $domain.'api/delHtml/?project_id='.$project->id.'&route=404';  
112 - curlGet($url);  
113 - }catch (QueryException | \Exception $e){  
114 - echo '-->' . $e->getMessage() . PHP_EOL;  
115 - continue; 96 + $data = [];
  97 + foreach ($items as $item){
  98 + $item = (array) $item;
  99 + unset($item['id']);
  100 + $item['customer_visit_id'] = $id;
  101 + $data[] = $item;
  102 + $visit_item++;
116 } 103 }
117 - echo '-->成功:' . PHP_EOL; 104 + DB::connection('custom_mysql')->table('gl_customer_visit_item')->insert($data);
118 } 105 }
  106 + echo date('Y-m-d H:i:s') . "visit:{$visit};item:{$visit_item}" . PHP_EOL;exit;
119 } 107 }
120 108
121 } 109 }
@@ -27,7 +27,7 @@ class VisitController extends BaseController @@ -27,7 +27,7 @@ class VisitController extends BaseController
27 */ 27 */
28 public function index(VisitLogic $logic) 28 public function index(VisitLogic $logic)
29 { 29 {
30 - $data = $logic->getVisitList($this->map,$this->page,$this->row,$this->order); 30 + $data = $logic->getVisitList($this->map,$this->page,$this->row,['created_at' => 'desc']);
31 $this->response('success',Code::SUCCESS,$data); 31 $this->response('success',Code::SUCCESS,$data);
32 } 32 }
33 33
@@ -35,7 +35,7 @@ class VisitLogic extends BaseLogic @@ -35,7 +35,7 @@ class VisitLogic extends BaseLogic
35 'customer_visit_id' => $this->param['id'], 35 'customer_visit_id' => $this->param['id'],
36 // 'domain' => $this->user['domain'], 36 // 'domain' => $this->user['domain'],
37 ]; 37 ];
38 - $data = $this->model->list($map); 38 + $data = $this->model->list($map, 'created_at');
39 return $this->success($data); 39 return $this->success($data);
40 } 40 }
41 41