123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107 |
- <?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
- {
-
- protected $signature = 'report:books';
-
- protected $description = '上报书籍';
-
- public function handle()
- {
- $client = new Client(['timeout' => 10, 'verify' => false]);
-
- $offset_time = 30;
- $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'))),
- ];
-
-
- if($num >=500){
-
- $client->post(env('REPORT_URI') . '/api/reportBooks', [
- 'headers' => [
- 'x-code' => 'Mvnx1Yr3O8i!TS5u'
- ],
- 'json' => $reportData
- ]);
-
- $num = 1;
- $reportData['list'] = [];
- }
-
- $num++;
-
- }
-
-
-
- $client->post(env('REPORT_URI') . '/api/reportBooks', [
- 'headers' => [
- 'x-code' => 'Mvnx1Yr3O8i!TS5u'
- ],
- 'json' => $reportData
- ]);
-
- }
- }
- }
|