Ejemplo n.º 1
0
 public function uploadLog(Request $request)
 {
     $file = $request->file('file');
     $ext = strtolower($file->getClientOriginalExtension());
     $size = $file->getSize();
     $validator = Validator::make(['file' => $file, 'extension' => $ext, 'size' => $size], ['file' => 'required', 'extension' => 'required|in:log', 'size' => 'max:100000']);
     if ($validator->fails()) {
         //dd($validator->errors());
         return Ajax::info('file format error');
     }
     $destinationPath = Config::get('app.pclog_path') . '/' . date('Ym', time());
     $save_path = public_path() . '/' . $destinationPath;
     $file_name = md5($file->getClientOriginalName() . time()) . '.' . $ext;
     if (!is_dir($save_path)) {
         mkdir($save_path, 755, true);
     }
     if ($file->move($save_path, $file_name)) {
         $url = url($destinationPath . '/' . $file_name);
         $file = new DeviceFile();
         $file->ext = $ext;
         $file->name = $file_name;
         $file->path = $destinationPath . '/' . $file_name;
         $file->did = $request->pc->id;
         $file->size = $size;
         $file->created_at = time();
         $fid = $file->save();
         if ($fid) {
             return AJAX::success($result = array('url' => $url));
         } else {
             return AJAX::serverError();
         }
     } else {
         return AJAX::info('upload file error');
     }
 }
Ejemplo n.º 2
0
 public function productSearchByURL(Request $request)
 {
     $url = $request['url'];
     $connection = getSiteName(getDomain($url));
     $sn = getSn($url);
     if (empty($connection) || empty($sn)) {
         return AJAX::argumentError();
     }
     $termModule = new ProductModule($connection);
     $result = $termModule->getProductInfo(array('sn' => $sn));
     if (count($result) > 0) {
         return AJAX::success(array('info' => $result));
     } else {
         return AJAX::notExist();
     }
 }
Ejemplo n.º 3
0
 public function termSearchByUrl(Request $request)
 {
     $url = $request['url'];
     $connection = getSiteName(getDomain($url));
     $path_alias = getUri($url);
     if (empty($connection) || empty($path_alias)) {
         return AJAX::argumentError();
     }
     $termModule = new TermModule($connection);
     $result = $termModule->getTermInfo(array('path_alias' => $path_alias));
     if (count($result) > 0) {
         return AJAX::success(array('info' => $result));
     } else {
         return AJAX::notExist();
     }
 }
Ejemplo n.º 4
0
 public function addComments(Request $request)
 {
     $name = $request->name;
     $end = isset($request->end) ? strtotime($request->end) : time();
     $start = isset($request->start) ? strtotime($request->start) : $end - 86400 * 180;
     $site = isset($request->site) ? $request->site : '';
     $mode = isset($request->mode) ? $request->mode : '';
     $f = $s = 0;
     if (empty($name) || empty($site) || empty($mode)) {
         return AJAX::argumentError();
     }
     $file = File::where(array('name' => $name))->first();
     if (empty($file) || empty($file->path)) {
         return AJAX::notExist();
     }
     $list = $this->getFileContents($file->path);
     switch ($mode) {
         case 'insertComments':
             $result = $this->checkCommentsFile($list, 4);
             break;
         case 'insertCommentsWithTid':
             $result = $this->checkCommentsFile($list, 5);
             break;
         default:
             $result['code'] = 500;
             $result['data'] = 'arguments error';
             break;
     }
     if ($result['code'] != 200) {
         return AJAX::badData(array('message' => $result['message']));
     }
     $commentModule = new CommentModule($site);
     foreach ($list as $line) {
         $comment_time = $this->getCommentRandTime($start, $end);
         $res = $commentModule->addCommentByLine($line, $comment_time, $mode);
         if ($res['code'] != 200) {
             Log::error($site . ':' . $name . $res['message']);
             $f++;
             continue;
         }
         $s++;
     }
     return AJAX::success(array('success' => $s, 'fail' => $f));
 }