isAjax()) { $list = CrmRemoveImportLog::where('root_id', '=', request()->employee->root_id)->order('addtime desc')->select()->toArray(); return json(['code'=> 0, 'data'=> $list, 'msg'=> 'success']); } else { return View::fetch(); } } /** * 导入前日志存储 */ public function importLog() { $file = request()->file('file'); $root_id = request()->employee->root_id; if (empty($file)) { return json(['code' => 1, 'msg' => '请上传导入文件', 'data' => []]); } $log['employee_id'] = request()->employee->id; $log['name'] = $file->getOriginalName(); $log['count'] = 0; $log['avaliable_count'] = 0; $log['bad_phone_num'] = 0; $log['repeat_phone_number'] = 0; $log['status'] = 0; $log['root_id'] = $root_id; $log['path'] = Request::param('file'); $log['execute_rows'] = 0; $log_id = CrmRemoveImportLog::insertGetId($log); return json(['code' => 0, 'msg' => '上传成功', 'data' => $log_id]); } /** * 导入 */ public function add() { $log_id = input('log_id', '', 'intval'); $root_id = request()->employee['root_id']; $log = CrmRemoveImportLog::find($log_id); if (empty($log)) { return json(['code'=> 1, 'msg'=> '文件不存在']); } if ($root_id != $log['root_id']) { return json(['code'=> 1, 'msg'=> '导入失败']); } $ali_oss_bindurl = config('app.ali_oss_bindurl'); $path = 'https://' . $ali_oss_bindurl . '/' . $log['path']; // 抓取远程Excel文件的内容 try { $content = file_get_contents($path); if (!$content) { return json(['code'=> 1, 'msg'=> '文件不存在']); } } catch (\Exception $e) { return json(['code'=> 1, 'msg'=> '文件不存在']); } if ($log['status'] == 0) { $log->status = 1; $log->save(); $jobHandlerClassName = 'app\jobs\CrmRemove'; $jobQueueName = 'crm_remove'; $orderData = ['id'=> $log_id]; //这个是需要传到消费者的数据 Queue::later(0, $jobHandlerClassName, $orderData, $jobQueueName); } return json(['code' => 0, 'msg' => '上传中,请手动刷新结果']); } } ?>