|
@@ -442,17 +442,31 @@ class DwyController extends BaseController
|
|
|
|
|
|
public function getBoxTrademark(Request $request){
|
|
|
$data = $request->all();
|
|
|
+ if(empty($data['box_nos']) && empty($data['mac'])) return ['status' => 201,'data' => []];
|
|
|
+
|
|
|
$box_nos = $data['box_nos'];
|
|
|
$dv = $data['mac'];
|
|
|
$detail = [];
|
|
|
- foreach ($box_nos as $v){
|
|
|
-// var_dump(file_get_contents('/'.$dv.'_'.$box_nos.'.txt'));die;
|
|
|
- $detail[] = [
|
|
|
- 'detail'=>json_decode(file_get_contents(''.$dv.'_'.$v.'.txt'),true),
|
|
|
- 'code'=>$v,
|
|
|
- ];
|
|
|
+
|
|
|
+ //测试写入文件
|
|
|
+// foreach ($box_nos as $v) {
|
|
|
+// $filePath = storage_path( "app/box_trade/"."{$dv}_{$v}.txt");
|
|
|
+// if (! file_exists(storage_path('box_trade'))) Storage::makeDirectory('box_trade');
|
|
|
+// file_put_contents($filePath,json_encode(['a' => '测试','b'=>'测试2']));
|
|
|
+// }
|
|
|
+
|
|
|
+ //读取文件
|
|
|
+ foreach ($box_nos as $v) {
|
|
|
+ // $filePath = public_path($file_path . "{$dv}_{$v}.txt");
|
|
|
+ $filePath = storage_path("app/box_trade/"."{$dv}_{$v}.txt");
|
|
|
+ if(file_exists($filePath)){
|
|
|
+ if (($content = file_get_contents($filePath)) === false) continue;
|
|
|
+ $decodedContent = json_decode($content, true);
|
|
|
+ if (json_last_error() !== JSON_ERROR_NONE) continue;
|
|
|
+ $detail[$v] = $decodedContent;
|
|
|
+ }
|
|
|
}
|
|
|
|
|
|
- return ['status'=>200, 'data' => $detail];
|
|
|
+ return ['status' => 200, 'data' => $detail];
|
|
|
}
|
|
|
}
|