Пример #1
0
 /**
  * Execute the job.
  *
  * @return void
  */
 public function handle()
 {
     $order_id = $this->order->id;
     //
     try {
         //解析文件 录入数据库
         Excel::filter('chunk')->selectSheets('Sheet1')->load(public_path($this->order->sub_file))->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()));
                     }
                 }
             }
         });
     } catch (\Exception $e) {
         return array('success' => false, 'errors' => array($e->getMessage()));
     }
     //文件解析成功 更新子订单数量
     //获取分单数量
     $sub_total = SubOrder::where('order_id', $this->order->id)->count();
     $this->order->sub_total = $sub_total;
     $this->order->save();
 }
Пример #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文件
     //检查身份证照片
 }