Commit 0078b858 by 杨树贤

完善积分信息所需要的服务接口

parent 889d5c2e
...@@ -10,22 +10,32 @@ use Illuminate\Support\Facades\DB; ...@@ -10,22 +10,32 @@ use Illuminate\Support\Facades\DB;
class IntegralsController extends Controller class IntegralsController extends Controller
{ {
public function index() public function show($id)
{
$integral = Integral::find($id)->toArray();
return $this->Export(0, 'ok', ['data' => $integral]);
}
public function index(Request $request)
{ {
$integrals = Integral::with('integralType:id,name') $integrals = Integral::with('integralType:id,name')
->whereStatus(1) ->page($request->page, $request->page_size)
->orderBy('id','desc')
->get()->toArray(); ->get()->toArray();
$count = Integral::count();
return $this->Export(0, 'ok', ['data' => $integrals]); return $this->Export(0, 'ok', ['data' => $integrals, 'count' => $count]);
} }
public function create(Request $request) public function create(Request $request)
{ {
$res = DB::table('integrals')->insert([ $res = DB::table('integrals')->insert([
'name' => $request->name, 'name' => $request->name,
'integral_type_id' => $request->integral_type_id, 'daily_limit' => $request->daily_limit,
'integral_amount' => $request->integral_amount,
'add_time' => time(), 'add_time' => time(),
'status' => 1, 'status' => $request->status,
]); ]);
if ($res) { if ($res) {
...@@ -40,7 +50,9 @@ class IntegralsController extends Controller ...@@ -40,7 +50,9 @@ class IntegralsController extends Controller
$res = DB::table('integrals')->where('id', $id) $res = DB::table('integrals')->where('id', $id)
->update([ ->update([
'name' => $request->name, 'name' => $request->name,
'integral_type_id' => $request->integral_type_id, 'daily_limit' => $request->daily_limit,
'integral_amount' => $request->integral_amount,
'update_time' => time(),
]); ]);
if ($res) { if ($res) {
return $this->Export(0, 'ok'); return $this->Export(0, 'ok');
......
<?php
namespace App\Http\Filters;
class IntegralFilter extends QueryFilter
{
}
\ No newline at end of file
<?php
namespace App\Http\Filters;
use Illuminate\Database\Eloquent\Builder;
use Illuminate\Http\Request;
abstract class QueryFilter
{
protected $request;
protected $builder;
public function __construct(Request $request)
{
$this->request = $request;
}
public function apply(Builder $builder)
{
$this->builder = $builder;
foreach ($this->filters() as $name => $value) {
if (method_exists($this, $name)) {
call_user_func_array([$this, $name], array_filter([$value]));
}
}
return $this->builder;
}
public function filters()
{
return $this->request->all();
}
}
\ No newline at end of file
...@@ -10,7 +10,12 @@ class Integral extends Model ...@@ -10,7 +10,12 @@ class Integral extends Model
{ {
public $timestamps = false; public $timestamps = false;
protected $hidden = ['id']; protected $hidden = [];
public function scopePage($query, $page = 1, $pageSize = 10)
{
return $query->offset(($page - 1) * $pageSize)->limit($pageSize);
}
public function integralType() public function integralType()
{ {
......
...@@ -21,6 +21,7 @@ $router->get('/key', function () { ...@@ -21,6 +21,7 @@ $router->get('/key', function () {
//积分信息 //积分信息
$router->get('/integrals', 'IntegralsController@index'); $router->get('/integrals', 'IntegralsController@index');
$router->get('/integrals/{id}', 'IntegralsController@show');
$router->post('/integrals', 'IntegralsController@create'); $router->post('/integrals', 'IntegralsController@create');
$router->patch('/integrals/{id}', 'IntegralsController@update'); $router->patch('/integrals/{id}', 'IntegralsController@update');
$router->delete('/integrals/{id}', 'IntegralsController@destroy'); $router->delete('/integrals/{id}', 'IntegralsController@destroy');
......
3671 18189
\ No newline at end of file \ No newline at end of file
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 sign in to comment