99namespace App \Http \Repository ;
1010
1111
12+ use App \Models \ApiExcelLogs ;
1213use GuzzleHttp \Pool ;
1314use GuzzleHttp \Client ;
1415use Illuminate \Support \Facades \Log ;
@@ -27,6 +28,7 @@ class MultithreadingRepository
2728 */
2829 public $ data = [];
2930
31+ public $ api_excel_id = 0 ;
3032 public $ fileName ;
3133 public $ config ;
3234
@@ -53,6 +55,11 @@ public static function getInstent()
5355 return self ::$ instance ;
5456 }
5557
58+ public function setApiExcelId ($ id )
59+ {
60+ $ this ->api_excel_id = $ id ;
61+ }
62+
5663 /**
5764 * 设置参数
5865 *
@@ -297,12 +304,30 @@ public function newRequest($url, $appkey)
297304 'fulfilled ' => function ($ response , $ index ) {
298305 // this is delivered each successful response
299306 $ result = $ response ->getBody ()->getContents ();
300- Log::info ($ index .'-result ' , ['result ' => $ result ]);
307+ // 记录返回数据到数据库 api_excel_logs 中
308+ $ para = array_values ($ this ->dataSet ['data ' ][$ index ]);
309+ $ logs = [
310+ 'api_excel_id ' => $ this ->api_excel_id ,
311+ 'sort_index ' => $ index ,
312+ 'param ' => implode ('| ' , $ para ),
313+ 'result ' => $ result ,
314+ 'created_at ' => date ('Y-m-d H:i:s ' ),
315+ ];
316+ ApiExcelLogs::insert ($ logs );
301317 // var_dump($result);
302318 // var_dump($index);
303319 $ this ->data [$ index ] = $ result ;
304320 },
305321 'rejected ' => function ($ reason , $ index ) {
322+ $ para = array_values ($ this ->dataSet ['data ' ][$ index ]);
323+ $ logs = [
324+ 'api_excel_id ' => $ this ->api_excel_id ,
325+ 'sort_index ' => $ index ,
326+ 'param ' => implode ('| ' , $ para ),
327+ 'result ' => '' ,
328+ 'created_at ' => date ('Y-m-d H:i:s ' ),
329+ ];
330+ ApiExcelLogs::insert ($ logs );
306331 // this is delivered each failed request
307332 if (is_object ($ reason ) && is_callable ([$ reason , 'getMessage ' ])) {
308333 $ reason = 'Line: ' .$ reason ->getLine ().' in ' .$ reason ->getFile ().'; Message: ' .$ reason ->getMessage ();
0 commit comments