Commit 92da4001 by 庄欣

完成90%

parent a084214a
......@@ -31,10 +31,10 @@ class Article extends \Illuminate\Routing\Controller
{
$query = request()->query();
$where = $this->filter($query);
$where = $this->setBlurSearch($where,"title");
$model = $this->setBlurSearch(ArtModel::class,$where,"title");
is_null($where) && $where = [];
$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)
......
......@@ -17,11 +17,7 @@ class City extends Controller
{
$query = request()->query();
$where = $this->filter($query);
$model = CityModel::where($where);
if (isset($where['city_name'])) {
$model->where($where,"like",$where['city_name']."%");
}
$res = $model->get();
return Response::success($res->toArray());
$model = $this->setBlurSearch(CityModel::class,$where,"city_name");
return Response::success($model->get()->toArray());
}
}
......@@ -15,6 +15,7 @@ class Kernel extends HttpKernel
*/
protected $middleware = [
\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
* cover string required
* extra_truing_price float required
* count int required
*
*/
public function store(Request $request)
{
......
......@@ -34,10 +34,10 @@ class Sets extends \Illuminate\Routing\Controller
{
$query = request()->query();
$where = $this->filter($query);
$where = $this->setBlurSearch($where,"title");
$model = $this->setBlurSearch(SetsModel::class,$where,"title");
is_null($where) && $where = [];
$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
return $where;
}
public function setBlurSearch($where,$key,$condition = "eq")
public function setBlurSearch($model,$where,$key,$condition = "like")
{
if (is_null($where)) {
return null;
return $model;
}
if (!in_array($key,array_keys($where))) {
return $where;
return $model::where($where);
}
$where[$key] = trim($where[$key]);
$result_model = null;
switch ($condition) {
case "eq":
$where["_condition"] = [$key,"like","'%.$where[$key].%'"];
case "like":
$result_model = $model::where($key,"like","%".$where[$key]."%");
break;
case "elt":
$where["_condition"] = [$key,"<=","'$where[$key]'"];
$result_model = $model::where($key,"<=","'$where[$key]'");
break;
case "lt":
$where["_condition"] = [$key,"<","'$where[$key]'"];
$result_model = $model::where($key,"<=","'$where[$key]'");
break;
case "gt":
$where["_condition"] = [$key,"<","'$where[$key]'"];
$result_model = $model::where($key,">","'$where[$key]'");
break;
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;
}
return $where;
unset($where[$key]);
try {
$result_model = $result_model->where($where);
} catch (\Exception $e) {
}
return $result_model;
}
public function csrf($data,$key) {
......
......@@ -35,10 +35,10 @@ class Works extends \Illuminate\Routing\Controller
{
$query = request()->query();
$where = $this->filter($query);
$where = $this->setBlurSearch($where,"name");
$model = $this->setBlurSearch(WorksModel::class,$where,"name");
is_null($where) && $where = [];
$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