コード例 #1
0
ファイル: OrderController.php プロジェクト: abcn/excel
 /**
  * 上传分单文件 身份证照片
  */
 public function upload(Request $request)
 {
     ini_set('max_execution_time', 0);
     ini_set("memory_limit", "1024M");
     //获取主单号
     $order_id = $request->get('order_id');
     $order = $this->orders->findOrFail($order_id);
     if ($request->hasFile('sub_order')) {
         $data = uploadExcel($request->file('sub_order'));
         //保存excel文件地址到数据库
         $order->sub_file = $data['filename'];
         if (!$order->save()) {
             //身份证上传失败
             return array('success' => false, 'errors' => array('分单文件上传失败'));
         }
         //将解析文件 加入至队列
         $job_excel = new ImportExcel($order);
         $this->dispatch($job_excel);
         //变更订单导入状态
         $order->import_state = 1;
         $order->save();
     }
     //默认返回无图片上传错误
     $data = array('success' => false, 'errors' => array('没有上传文件'));
     //检查身份证是否上传
     if ($request->hasFile('id_image')) {
         $data = uploadID($request->file('id_image'));
         //检查文件是否已存在 插入数据库
         //替换身份证图片
         $order->id_image = $data['filename'];
         $order->id_image_dir = $data['extractDir'];
         if (!$order->save()) {
             //身份证上传失败
             return array('success' => false, 'errors' => array('身份证上传失败'));
         }
         //将解压文件任务添加到队列
         $job = (new ZipArchive($order, $data['extractDir']))->delay(5);
         $this->dispatch($job);
     }
     return $data;
     //检查xlsx文件
     //检查身份证照片
 }
コード例 #2
0
 /**
  * 上传分单文件 身份证照片
  */
 public function upload(Request $request)
 {
     ini_set('max_execution_time', 0);
     ini_set("memory_limit", "1024M");
     //获取主单号
     $order_id = $request->get('order_id');
     $order = $this->orders->findOrFail($order_id);
     //默认返回无图片上传错误
     $data = array('success' => false, 'errors' => array('没有上传文件'));
     $image = $request->file('id_image');
     dd();
     //检查身份证是否上传
     if ($request->hasFile('id_image')) {
         $data = uploadID($request->file('id_image'));
         //检查文件是否已存在 插入数据库
         //替换身份证图片
         $order->id_image = $data['filename'];
         if (!$order->save()) {
             //身份证上传失败
             return array('success' => false, 'errors' => array('身份证上传失败'));
         }
     }
     if ($request->hasFile('sub_order')) {
         $data = uploadExcel($request->file('sub_order'));
         //解析文件 录入数据库
         Excel::filter('chunk')->selectSheets('Sheet1')->load($data['filename'])->chunk(300, function ($results) use($order_id) {
             foreach ($results as $row) {
                 if ($row['序号'] != null) {
                     $subOrder = new SubOrder();
                     $subOrder->order_id = $order_id;
                     $subOrder->excel_id = (int) $row['序号'];
                     $subOrder->fw_number = $row['国外运单号'];
                     $subOrder->name = $row['姓名'];
                     $subOrder->mobile = $row['电话'];
                     $subOrder->address = $row['地址'];
                     $subOrder->zip_code = $row['邮编'];
                     $subOrder->weight = $row['重量'];
                     $subOrder->id_number = $row['身份证号'];
                     try {
                         $subOrder->save();
                     } catch (\Exception $exception) {
                         return array('success' => false, 'errors' => array($exception->getMessage()));
                     }
                     //存入订单产品
                     $product = new OrderProduct();
                     $product->sub_order_id = $subOrder->id;
                     $product->name = $row['品名'];
                     $product->count = $row['数量'];
                     try {
                         $product->save();
                     } catch (\Exception $exception) {
                         return array('success' => false, 'errors' => array($exception->getMessage()));
                     }
                 } else {
                     //存入子订单
                     $subOrder = SubOrder::where('excel_id', (int) $row['子序号'])->where('order_id', $order_id)->first();
                     //TODO 检查子订单是否存在
                     //存入订单产品
                     $product = new OrderProduct();
                     $product->sub_order_id = $subOrder['id'];
                     $product->name = $row['品名'];
                     $product->count = $row['数量'];
                     try {
                         $product->save();
                     } catch (\Exception $exception) {
                         return array('success' => false, 'errors' => array($exception->getMessage()));
                     }
                 }
             }
         });
         //变更订单导入状态
         $order->import_state = 1;
         $order->save();
     }
     return $data;
     //检查xlsx文件
     //检查身份证照片
 }
コード例 #3
0
ファイル: AdminAction.class.php プロジェクト: sysuzjz/soya
 public function upload_quiz_()
 {
     eval(ADMIN);
     try {
         $upload = uploadExcel();
         // dump($upload);
         if (is_string($upload)) {
             throw new Exception($upload);
         }
         #var_dump($upload);
         $data["filepath"] = "/" . $upload[0]["savepath"] . $upload[0]["savename"];
         $model = D("cernet_quiz_meta");
         $model->where(array("id" => 1))->save($data);
         if ($result != 0 && $result == false) {
             throw new Exception("请检查数据库连接是否正确。");
         }
         $qm = new QuizModel();
         $qm->readQuizFromExcelNSave();
         $this->success(Success("upload"), "__URL__/manage_quiz");
     } catch (Exception $e) {
         #$this->error(Error("upload"), $e->getMessage());
         throw_exception($e->getMessage());
     }
 }