|
@@ -0,0 +1,107 @@
|
|
|
|
+<?php
|
|
|
|
+
|
|
|
|
+
|
|
|
|
+namespace App\Console\Commands\Report;
|
|
|
|
+
|
|
|
|
+
|
|
|
|
+use App\Modules\Book\Models\Book;
|
|
|
|
+use App\Modules\Book\Models\BookConfig;
|
|
|
|
+use GuzzleHttp\Client;
|
|
|
|
+use Illuminate\Console\Command;
|
|
|
|
+use Illuminate\Support\Facades\Redis;
|
|
|
|
+use Hashids;
|
|
|
|
+
|
|
|
|
+class ReportBooks extends Command
|
|
|
|
+{
|
|
|
|
+ /**
|
|
|
|
+ * The name and signature of the console command.
|
|
|
|
+ *
|
|
|
|
+ * @var string
|
|
|
|
+ */
|
|
|
|
+ protected $signature = 'report:books';
|
|
|
|
+
|
|
|
|
+ /**
|
|
|
|
+ * The console command description.
|
|
|
|
+ *
|
|
|
|
+ * @var string
|
|
|
|
+ */
|
|
|
|
+ protected $description = '上报书籍';
|
|
|
|
+
|
|
|
|
+ /**
|
|
|
|
+ * Execute the console command.
|
|
|
|
+ *
|
|
|
|
+ * @return mixed
|
|
|
|
+ */
|
|
|
|
+ public function handle()
|
|
|
|
+ {
|
|
|
|
+
|
|
|
|
+ $client = new Client(['timeout' => 10, 'verify' => false]);
|
|
|
|
+
|
|
|
|
+ // 获取书籍id
|
|
|
|
+ $offset_time = 30;//min
|
|
|
|
+ $is_full_push = true;
|
|
|
|
+ $bookConfigs = BookConfig::getBooksByOffsetTime($offset_time,$is_full_push);
|
|
|
|
+ $bids = collect($bookConfigs)->pluck('bid')->all();
|
|
|
|
+
|
|
|
|
+ \Log::info('report:books:bids:'.json_encode($bids));
|
|
|
|
+ \Log::info('report:books:bids_all_num:'.count($bids));
|
|
|
|
+
|
|
|
|
+ // 书籍列表
|
|
|
|
+ $books = Book::getBooksByIds($bids);
|
|
|
|
+ if ($books) {
|
|
|
|
+ $reportData = [
|
|
|
|
+ 'platform' => 'wangduyun',
|
|
|
|
+ 'list' => []
|
|
|
|
+ ];
|
|
|
|
+
|
|
|
|
+ $num = 1;
|
|
|
|
+ foreach ($books as $book) {
|
|
|
|
+ $bid = getProp($book, 'id');
|
|
|
|
+ $book_config = BookConfig::getOneByBid($bid);
|
|
|
|
+
|
|
|
|
+ $reportData['list'][] = [
|
|
|
|
+ 'bid' => getProp($book, 'id'),
|
|
|
|
+ 'name' => getProp($book_config, 'book_name'),
|
|
|
|
+ 'category_id' => getProp($book, 'category_id'),
|
|
|
|
+ 'category_name' => getProp($book, 'category_name'),
|
|
|
|
+ 'shelf_time' => !empty(getProp($book_config, 'shelf_time'))?getProp($book_config, 'shelf_time'):'1970-01-01',
|
|
|
|
+ 'shelf_status' => getProp($book_config, 'is_on_shelf'),
|
|
|
|
+ 'hash_bid' => Hashids::encode($bid),
|
|
|
|
+ 'created_at' => date("Y-m-d H:i:s", strtotime(getProp($book_config, 'created_at'))),
|
|
|
|
+ 'updated_at' => date("Y-m-d H:i:s", strtotime(getProp($book_config, 'updated_at'))),
|
|
|
|
+ ];
|
|
|
|
+
|
|
|
|
+// \Log::info('$reportData:'.$num);\Log::info($reportData);
|
|
|
|
+ // 循环推,兼容全量
|
|
|
|
+ if($num >=500){
|
|
|
|
+ // 执行上报
|
|
|
|
+ $client->post(env('REPORT_URI') . '/api/reportBooks', [
|
|
|
|
+ 'headers' => [
|
|
|
|
+ 'x-code' => 'Mvnx1Yr3O8i!TS5u'
|
|
|
|
+ ],
|
|
|
|
+ 'json' => $reportData
|
|
|
|
+ ]);
|
|
|
|
+
|
|
|
|
+ $num = 1;
|
|
|
|
+ $reportData['list'] = [];
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ $num++;
|
|
|
|
+
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ // 最后一波500内的推送
|
|
|
|
+ // 执行上报
|
|
|
|
+ $client->post(env('REPORT_URI') . '/api/reportBooks', [
|
|
|
|
+ 'headers' => [
|
|
|
|
+ 'x-code' => 'Mvnx1Yr3O8i!TS5u'
|
|
|
|
+ ],
|
|
|
|
+ 'json' => $reportData
|
|
|
|
+ ]);
|
|
|
|
+
|
|
|
|
+
|
|
|
|
+
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+}
|