Commit 64d34878 by 杨树贤

修改代码逻辑以适配后台需要用到的接口

parent da603647
...@@ -7,6 +7,8 @@ use Laravel\Lumen\Routing\Controller as BaseController; ...@@ -7,6 +7,8 @@ use Laravel\Lumen\Routing\Controller as BaseController;
class Controller extends BaseController class Controller extends BaseController
{ {
// //
const DEFAULT_PAGE_SIZE = 10;
const DEFAULT_PAGE = 1;
public function Export( $Errcode=0,$ErrMsg='', $dataArr=[]) { public function Export( $Errcode=0,$ErrMsg='', $dataArr=[]) {
if(!empty($dataArr) && !is_array($dataArr)) { if(!empty($dataArr) && !is_array($dataArr)) {
......
...@@ -4,17 +4,26 @@ ...@@ -4,17 +4,26 @@
namespace App\Http\Controllers; namespace App\Http\Controllers;
use App\Http\Filters\IntegralBillFilter;
use App\Http\Filters\UserIntegralFilter;
use App\Models\IntegralBill; use App\Models\IntegralBill;
use App\Models\UserIntegral;
use Illuminate\Http\Request; use Illuminate\Http\Request;
use Illuminate\Support\Facades\DB; use Illuminate\Support\Facades\DB;
class IntegralBillsController extends Controller class IntegralBillsController extends Controller
{ {
public function index() public function index(Request $request, IntegralBillFilter $filter)
{ {
$integrals = IntegralBill::all()->toArray(); $page = $request->has('page') ? $request->page : 1;
$page_size = $request->has('page_size') ? $request->page_size : 10;
$bills = IntegralBill::with('integral')->filter($filter)->page($page, $page_size)
->orderBy('id', 'desc')
->get()->toArray();
$count = IntegralBill::filter($filter)->count();
return $this->Export(0, 'ok', ['data' => $bills, 'count' => $count]);
return $this->Export(0, 'ok', ['data' => $integrals]);
} }
public function create(Request $request) public function create(Request $request)
......
...@@ -56,14 +56,11 @@ class IntegralsController extends Controller ...@@ -56,14 +56,11 @@ class IntegralsController extends Controller
->update([ ->update([
'name' => $request->name, 'name' => $request->name,
'daily_limit' => $request->daily_limit, 'daily_limit' => $request->daily_limit,
'integral_amount' => $request->integral_amount, 'amount' => $request->amount,
'update_time' => time(), 'update_time' => time(),
]); ]);
if ($res) {
return $this->Export(0, 'ok'); return $this->Export(0, 'ok');
} else {
return $this->Export(ErrorCode(002, 5), '更新积分信息失败');
}
} }
public function destroy($ids) public function destroy($ids)
......
<?php
namespace App\Http\Controllers;
use App\Http\Filters\UserIntegralFilter;
use App\Models\Integral;
use App\Models\UserIntegral;
use Illuminate\Http\Request;
use Illuminate\Support\Facades\DB;
use Illuminate\Support\Facades\Log;
class UserIntegralsController extends Controller
{
public function show($id)
{
$integral = UserIntegral::where('user_id', $id)->first()->toArray();
return $this->Export(0, 'ok', ['data' => $integral]);
}
public function index(Request $request, UserIntegralFilter $filter)
{
$integrals = UserIntegral::filter($filter)->page($request->page, $request->page_size)
->orderBy('id', 'desc')
->get()->toArray();
$count = UserIntegral::filter($filter)->count();
return $this->Export(0, 'ok', ['data' => $integrals, 'count' => $count]);
}
public function update(Request $request, $id)
{
$res = DB::table('user_integrals')->where('id', $id)
->update($request->all());
return $this->Export(0, 'ok');
}
public function batchUpdateStatus(Request $request)
{
$ids = $request->ids;
if (!is_array($ids)) {
return Log::Info('批量修改参数不是数组');
}
$status = $request->status;
$result = DB::table('user_integrals')
->whereIn('id', $ids)
->update(['status' => (int)$status]);
return $this->Export(0, 'ok');
// return $this->Export(033, '批量修改用户积分失败');
}
}
\ No newline at end of file
<?php
namespace App\Http\Filters;
class IntegralBillFilter extends QueryFilter
{
public function integral_id($integralId = 0)
{
return $this->builder->whereIntegralId($integralId);
}
public function user_id($userId = 0)
{
return $this->builder->whereUserId($userId);
}
}
\ No newline at end of file
...@@ -12,7 +12,7 @@ class IntegralFilter extends QueryFilter ...@@ -12,7 +12,7 @@ class IntegralFilter extends QueryFilter
return $this->builder->where('name', 'like', "%{$name}%"); return $this->builder->where('name', 'like', "%{$name}%");
} }
public function exchange_status($status = 0) public function status($status = 0)
{ {
return $this->builder->where('status', '=', $status); return $this->builder->where('status', '=', $status);
} }
......
...@@ -6,14 +6,14 @@ namespace App\Http\Filters; ...@@ -6,14 +6,14 @@ namespace App\Http\Filters;
class UserIntegralFilter extends QueryFilter class UserIntegralFilter extends QueryFilter
{ {
public function user_id($user_id = 0) public function user_id($userId = 0)
{ {
return $this->builder->where('user_id', '=', $user_id); return $this->builder->where('user_id', '=', $userId);
} }
public function exchange_status($exchangeStatus = 0) public function status($status = 0)
{ {
return $this->builder->where('exchange_status', '=', $exchangeStatus); return $this->builder->where('status', '=', $status);
} }
} }
\ No newline at end of file
...@@ -4,9 +4,25 @@ ...@@ -4,9 +4,25 @@
namespace App\Models; namespace App\Models;
use App\Http\Filters\QueryFilter;
use Illuminate\Database\Eloquent\Model; use Illuminate\Database\Eloquent\Model;
class IntegralBill extends Model class IntegralBill extends Model
{ {
public $timestamps = false; public $timestamps = false;
public function integral()
{
return $this->belongsTo(Integral::class, 'integral_id', 'id');
}
public function scopePage($query, $page = 1, $pageSize = 10)
{
return $query->offset(($page - 1) * $pageSize)->limit($pageSize);
}
public function scopeFilter($query, QueryFilter $filters)
{
return $filters->apply($query);
}
} }
\ No newline at end of file
<?php
namespace App\Models;
use App\Http\Filters\QueryFilter;
use Illuminate\Database\Eloquent\Model;
class UserIntegral extends Model
{
public $timestamps = false;
public function scopePage($query, $page = 1, $pageSize = 10)
{
return $query->offset(($page - 1) * $pageSize)->limit($pageSize);
}
public function scopeFilter($query, QueryFilter $filters)
{
return $filters->apply($query);
}
}
\ No newline at end of file
...@@ -37,3 +37,9 @@ $router->get('/integral_bills', 'IntegralBillsController@index'); ...@@ -37,3 +37,9 @@ $router->get('/integral_bills', 'IntegralBillsController@index');
$router->post('/integral_bills', 'IntegralBillsController@create'); $router->post('/integral_bills', 'IntegralBillsController@create');
$router->patch('/integral_bills/{id}', 'IntegralBillsController@update'); $router->patch('/integral_bills/{id}', 'IntegralBillsController@update');
$router->delete('/integral_bills/{id}', 'IntegralBillsController@destroy'); $router->delete('/integral_bills/{id}', 'IntegralBillsController@destroy');
//用户积分信息
$router->get('/user_integrals/{id}', 'UserIntegralsController@show');
$router->get('/user_integrals', 'UserIntegralsController@index');
$router->patch('/user_integrals/{id}', 'UserIntegralsController@update');
$router->post('user_integrals/batchUpdateStatus', 'UserIntegralsController@batchUpdateStatus');
\ No newline at end of file
18189 2721
\ 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