|
@@ -6,7 +6,10 @@ use catcher\base\CatchRequest as Request;
|
|
|
use catcher\CatchResponse;
|
|
|
use catcher\base\CatchController;
|
|
|
use catchAdmin\alarm\model\RfidWithBw as rfidWithBwModel;
|
|
|
-
|
|
|
+use catcher\Utils;
|
|
|
+use catcher\library\excel\Excel;
|
|
|
+use PhpOffice\PhpSpreadsheet\IOFactory;
|
|
|
+use think\facade\Db;
|
|
|
class RfidWithBw extends CatchController
|
|
|
{
|
|
|
protected $rfidWithBwModel;
|
|
@@ -83,4 +86,77 @@ class RfidWithBw extends CatchController
|
|
|
{
|
|
|
return CatchResponse::success($this->rfidWithBwModel->deleteBy($id));
|
|
|
}
|
|
|
+
|
|
|
+ * 导入标签
|
|
|
+ *
|
|
|
+ * @time 2022年02月15日
|
|
|
+ * @param Excel $excel
|
|
|
+ * @param DeviceExport $deviceExport
|
|
|
+ * @throws \PhpOffice\PhpSpreadsheet\Exception
|
|
|
+ * @return \think\response\Json
|
|
|
+ */
|
|
|
+ public function importRfid(Request $request)
|
|
|
+ {
|
|
|
+ $url = $request->post('url');
|
|
|
+ if (!$url) {
|
|
|
+ return CatchResponse::fail('请上传文件');
|
|
|
+ }
|
|
|
+ $bw_id = $request->post('bw_id');
|
|
|
+ if (!$bw_id) {
|
|
|
+ return CatchResponse::fail('缺少必要参数');
|
|
|
+ }
|
|
|
+
|
|
|
+ $creator_id = $request->post('creator_id');
|
|
|
+
|
|
|
+ $parse_url = parse_url($url)['path'];
|
|
|
+
|
|
|
+ $objPHPExcel = IOFactory::load(public_path() . $parse_url);
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+ $sheetCount = $objPHPExcel->getSheetCount();
|
|
|
+ $fail = 0;
|
|
|
+ $success = 0;
|
|
|
+ $total = 0;
|
|
|
+ $data = [];
|
|
|
+
|
|
|
+
|
|
|
+ for ($index = 0; $index < $sheetCount; $index++) {
|
|
|
+
|
|
|
+ $sheet = $objPHPExcel->getSheet($index);
|
|
|
+
|
|
|
+ $highestRow = $sheet->getHighestRow();
|
|
|
+
|
|
|
+ if ($highestRow <= 2) {
|
|
|
+ continue;
|
|
|
+ }
|
|
|
+ $total += $highestRow - 2;
|
|
|
+ for ($j = 3; $j <= $highestRow; $j++) {
|
|
|
+
|
|
|
+ $arr = array();
|
|
|
+ $arr['rfid'] = strtoupper(trim($sheet->getCell("A" . $j)->getFormattedValue()));
|
|
|
+ $arr['rfid_type'] = trim($sheet->getCell("B" . $j)->getFormattedValue());
|
|
|
+
|
|
|
+ $arr['created_at']=time();
|
|
|
+ $arr['creator_id']=$creator_id;
|
|
|
+ $arr['bw_id']=$bw_id;
|
|
|
+ $exist=Db::table('rfid_with_bw')->where('rfid',$arr['rfid'])->where('bw_id',$bw_id)->count();
|
|
|
+ if($exist){
|
|
|
+ continue;
|
|
|
+ }
|
|
|
+ array_push($data,$arr);
|
|
|
+
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ array_unique($data, SORT_REGULAR);
|
|
|
+
|
|
|
+ $count = Db::table('rfid_with_bw')->limit(100)->insertAll($data);
|
|
|
+ if ($count) {
|
|
|
+
|
|
|
+ return CatchResponse::success('共' . $total . '条数据,成功' . $count . '条,失败' . ($total-$count) . '条');
|
|
|
+
|
|
|
+ }
|
|
|
+ return CatchResponse::success(['error' => true, 'msg' => '导入失败']);
|
|
|
+ }
|
|
|
}
|