Commit 92da4001 by 庄欣

完成90%

parent a084214a
...@@ -31,10 +31,10 @@ class Article extends \Illuminate\Routing\Controller ...@@ -31,10 +31,10 @@ class Article extends \Illuminate\Routing\Controller
{ {
$query = request()->query(); $query = request()->query();
$where = $this->filter($query); $where = $this->filter($query);
$where = $this->setBlurSearch($where,"title"); $model = $this->setBlurSearch(ArtModel::class,$where,"title");
is_null($where) && $where = []; is_null($where) && $where = [];
$row = isset($query["size"])?$query["size"]:config("app.default_perpage"); $row = isset($query["size"])?$query["size"]:config("app.default_perpage");
return Response::success(ArtModel::where($where)->paginate($row)->toArray()); return Response::success($model->paginate($row)->toArray());
} }
public function store(Request $request) public function store(Request $request)
......
...@@ -17,11 +17,7 @@ class City extends Controller ...@@ -17,11 +17,7 @@ class City extends Controller
{ {
$query = request()->query(); $query = request()->query();
$where = $this->filter($query); $where = $this->filter($query);
$model = CityModel::where($where); $model = $this->setBlurSearch(CityModel::class,$where,"city_name");
if (isset($where['city_name'])) { return Response::success($model->get()->toArray());
$model->where($where,"like",$where['city_name']."%");
}
$res = $model->get();
return Response::success($res->toArray());
} }
} }
...@@ -15,6 +15,7 @@ class Kernel extends HttpKernel ...@@ -15,6 +15,7 @@ class Kernel extends HttpKernel
*/ */
protected $middleware = [ protected $middleware = [
\Illuminate\Foundation\Http\Middleware\CheckForMaintenanceMode::class, \Illuminate\Foundation\Http\Middleware\CheckForMaintenanceMode::class,
\App\Http\Middleware\ParseNull::class
]; ];
/** /**
......
<?php
/**
* Created by PhpStorm.
* User: zhuangxin
* Date: 16-9-21
* Time: 上午10:34
*/
namespace App\Http\Middleware;
use Closure;
class ParseNull
{
public function handle($request, Closure $next)
{
$response = $next($request);
return $response;
}
}
\ No newline at end of file
<?php
namespace App\Kw\Controller;
use App\Http\Response\Response;
class Keywords extends \Illuminate\Routing\Controller
{
public function index()
{
}
public function info($id)
{
}
public function child($id)
{
}
}
...@@ -39,7 +39,6 @@ class Photo extends \Illuminate\Routing\Controller ...@@ -39,7 +39,6 @@ class Photo extends \Illuminate\Routing\Controller
* cover string required * cover string required
* extra_truing_price float required * extra_truing_price float required
* count int required * count int required
*
*/ */
public function store(Request $request) public function store(Request $request)
{ {
......
...@@ -34,10 +34,10 @@ class Sets extends \Illuminate\Routing\Controller ...@@ -34,10 +34,10 @@ class Sets extends \Illuminate\Routing\Controller
{ {
$query = request()->query(); $query = request()->query();
$where = $this->filter($query); $where = $this->filter($query);
$where = $this->setBlurSearch($where,"title"); $model = $this->setBlurSearch(SetsModel::class,$where,"title");
is_null($where) && $where = []; is_null($where) && $where = [];
$row = isset($query["size"])?$query["size"]:config("app.default_perpage"); $row = isset($query["size"])?$query["size"]:config("app.default_perpage");
return Response::success(SetsModel::where($where)->paginate($row)->toArray()); return Response::success($model->paginate($row)->toArray());
} }
/** /**
......
...@@ -29,32 +29,46 @@ trait Controller ...@@ -29,32 +29,46 @@ trait Controller
return $where; return $where;
} }
public function setBlurSearch($where,$key,$condition = "eq") public function setBlurSearch($model,$where,$key,$condition = "like")
{ {
if (is_null($where)) { if (is_null($where)) {
return null; return $model;
} }
if (!in_array($key,array_keys($where))) { if (!in_array($key,array_keys($where))) {
return $where; return $model::where($where);
} }
$where[$key] = trim($where[$key]);
$result_model = null;
switch ($condition) { switch ($condition) {
case "eq": case "like":
$where["_condition"] = [$key,"like","'%.$where[$key].%'"]; $result_model = $model::where($key,"like","%".$where[$key]."%");
break; break;
case "elt": case "elt":
$where["_condition"] = [$key,"<=","'$where[$key]'"]; $result_model = $model::where($key,"<=","'$where[$key]'");
break; break;
case "lt": case "lt":
$where["_condition"] = [$key,"<","'$where[$key]'"]; $result_model = $model::where($key,"<=","'$where[$key]'");
break; break;
case "gt": case "gt":
$where["_condition"] = [$key,"<","'$where[$key]'"]; $result_model = $model::where($key,">","'$where[$key]'");
break; break;
case "egt": case "egt":
$where["_condition"] = [$key,">=","'$where[$key]'"]; $result_model = $model::where($key,">=","'$where[$key]'");
break;
case "eq":
$result_model = $model::where($where);
break;
case "in":
$result_model = $model::whereIn($key,"in",$where[$key]);
break; break;
} }
return $where; unset($where[$key]);
try {
$result_model = $result_model->where($where);
} catch (\Exception $e) {
}
return $result_model;
} }
public function csrf($data,$key) { public function csrf($data,$key) {
......
...@@ -35,10 +35,10 @@ class Works extends \Illuminate\Routing\Controller ...@@ -35,10 +35,10 @@ class Works extends \Illuminate\Routing\Controller
{ {
$query = request()->query(); $query = request()->query();
$where = $this->filter($query); $where = $this->filter($query);
$where = $this->setBlurSearch($where,"name"); $model = $this->setBlurSearch(WorksModel::class,$where,"name");
is_null($where) && $where = []; is_null($where) && $where = [];
$row = isset($query["size"])?$query["size"]:config("app.default_perpage"); $row = isset($query["size"])?$query["size"]:config("app.default_perpage");
return Response::success(WorksModel::where($where)->paginate($row)->toArray()); return Response::success($model->paginate($row)->toArray());
} }
/** /**
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment