コード例 #1
0
ファイル: UserController.php プロジェクト: zhangyuxiao/qoros
 /**
  * 导入用户
  * @author bzhang
  */
 public function importUserAction()
 {
     $request = $this->getRequest();
     if ($request->isPost()) {
         $user = $this->authentication()->getIdentity();
         if (empty($_FILES['userList'])) {
             throw new BusinessException('请选择用户列表文件', 1021);
         }
         $fileHandler = new ExcelFileHandler($user->id);
         $uploader = new Uploader($fileHandler);
         $data = $uploader->processUpload($_FILES['userList']);
         $attachment = new AttachmentEntity();
         $attachment->exchangeArray($data);
         $attachment->filepath = str_replace("\\", "/", $attachment->filepath);
         if (!isset($attachment->filename) || !isset($attachment->filepath)) {
             throw new BusinessException('用户列表Excel导入失败', 1303);
         }
         $userArr = $this->userModel->getUserAndAddressFromExcel($attachment);
         $this->userModel->batchCreateUsers($userArr);
         return new UnifyJsonModel();
     }
     $view = new ViewModel();
     return $view;
 }