Commit 4f74f3b2 authored by hangjun83's avatar hangjun83

1、修复分页功能 2、增加查看日志

parent 6551960b
...@@ -98,9 +98,14 @@ class BhOrdersController extends Controller ...@@ -98,9 +98,14 @@ class BhOrdersController extends Controller
*/ */
public function getBhSorderRefundTaskToPage(Request $request) public function getBhSorderRefundTaskToPage(Request $request)
{ {
$message = [
'type.required' => "类型无效",
];
$this->validateRequest($request, $message);
try{ try{
$order = $this->bhOrdersService->getSordersRefundTask($request); $task = $this->bhOrdersService->getSordersRefundTask($request);
return Response::success($order, '添加成功'); return Response::success($task, '添加成功');
}catch(\Exception $exception){ }catch(\Exception $exception){
return Response::fail($exception->getMessage(),500); return Response::fail($exception->getMessage(),500);
} }
...@@ -145,4 +150,19 @@ class BhOrdersController extends Controller ...@@ -145,4 +150,19 @@ class BhOrdersController extends Controller
return Response::fail($exception->getMessage(),500); return Response::fail($exception->getMessage(),500);
} }
} }
public function getSorderRefundTaskLogsToPage(Request $request)
{
$message = [
'taskId.required' => "任务id必填",
];
$this->validateRequest($request, $message);
try{
$logs = $this->bhOrdersService->getBhSorderTaskLog($request);
return Response::success($this->formatKeysfromArray($logs), '操作成功');
}catch(\Exception $exception){
return Response::fail($exception->getMessage(),500);
}
}
} }
...@@ -13,6 +13,7 @@ namespace App\Repositories\Eloquent; ...@@ -13,6 +13,7 @@ namespace App\Repositories\Eloquent;
use App\Repositories\Presenters\Presenter; use App\Repositories\Presenters\Presenter;
use Illuminate\Database\Eloquent\Builder; use Illuminate\Database\Eloquent\Builder;
use Illuminate\Pagination\LengthAwarePaginator;
use Prettus\Repository\Eloquent\BaseRepository as BaseRepositoryEloquent; use Prettus\Repository\Eloquent\BaseRepository as BaseRepositoryEloquent;
abstract class BaseRepository extends BaseRepositoryEloquent abstract class BaseRepository extends BaseRepositoryEloquent
...@@ -29,13 +30,12 @@ abstract class BaseRepository extends BaseRepositoryEloquent ...@@ -29,13 +30,12 @@ abstract class BaseRepository extends BaseRepositoryEloquent
* @param array $columns * @param array $columns
* @return mixed * @return mixed
*/ */
public function cursorPaginate($current, $limit = null, $columns = ['*']) public function cursorPaginate($limit = null, $columns = ['*'])
{ {
$this->applyCriteria(); $this->applyCriteria();
$this->applyScope(); $this->applyScope();
$limit = is_null($limit) ? config('repository.pagination.limit', 15) : (int) $limit; $limit = is_null($limit) ? config('repository.pagination.limit', 15) : (int) $limit;
$results = $this->model->select($columns)->limit($limit)->get(); $results = $this->model->select($columns)->limit($limit)->get();
if ($this->model instanceof Builder) { if ($this->model instanceof Builder) {
...@@ -46,12 +46,39 @@ abstract class BaseRepository extends BaseRepositoryEloquent ...@@ -46,12 +46,39 @@ abstract class BaseRepository extends BaseRepositoryEloquent
$count = $results->count(); $count = $results->count();
$next = $count === $limit ? optional($results->last())->{$primaryKey} : null; $next = $count === $limit ? optional($results->last())->{$primaryKey} : null;
$this->resetModel();
$dataResult = $this->parserResult($results);
$prev = request('prev'); $page = request('page')?:1;
$this->presenter->makeCursor((int) $current, $prev ? (int) $prev : '', $next, $count); //每页的条数
$perPage = $limit;
//计算每页分页的初始位置
$offset = ($page * $perPage) - $perPage;
//实例化Paginator类,(删掉上一步的count($video_list)参数即可 )并传入对应的参数
$data = new LengthAwarePaginator(array_slice($dataResult, $offset, $perPage, true), count($dataResult), $perPage, $page);
return $data;
}
$this->resetModel();
return $this->parserResult($results); public function customPaginate($limit = null, $columns = ['*'])
{
$paginateResult = $this->paginate($limit,$columns);
$dataList = [];
// 将model对象转换城数组
foreach($paginateResult->items() as $data){
$dataList[] = $data->toArray();
}
$returnRecord = [];
$returnRecord['data'] = $dataList;
$returnRecord['current_page'] = $paginateResult->currentPage();
$returnRecord['total'] = $paginateResult->total();
$returnRecord['page'] = $paginateResult->currentPage() + 1;
if($returnRecord['page'] >= $paginateResult->lastPage()){
$returnRecord['page'] = $paginateResult->lastPage();
}
return $returnRecord;
} }
} }
...@@ -24,6 +24,7 @@ $api->version('v1', function($api) { ...@@ -24,6 +24,7 @@ $api->version('v1', function($api) {
$api->post('/adminapi/tools/bh/getBhSordersDetail', ['permission' => 'tools.bh.order.search', 'uses'=>'BhOrdersController@getBhSordersDetail']); $api->post('/adminapi/tools/bh/getBhSordersDetail', ['permission' => 'tools.bh.order.search', 'uses'=>'BhOrdersController@getBhSordersDetail']);
$api->get('/adminapi/tools/bh/getBhSorderRefundTask', ['permission' => 'tools.bh.order.search', 'uses'=>'BhOrdersController@getBhSorderRefundTaskToPage']); $api->get('/adminapi/tools/bh/getBhSorderRefundTask', ['permission' => 'tools.bh.order.search', 'uses'=>'BhOrdersController@getBhSorderRefundTaskToPage']);
$api->post('/adminapi/tools/bh/execBhSorderRefundTask', ['permission' => 'tools.bh.order.search', 'uses'=>'BhOrdersController@execBhSorderRefundTask']); $api->post('/adminapi/tools/bh/execBhSorderRefundTask', ['permission' => 'tools.bh.order.search', 'uses'=>'BhOrdersController@execBhSorderRefundTask']);
$api->get('/adminapi/tools/bh/getSorderRefundTaskLogs', ['permission' => 'tools.bh.order.search', 'uses'=>'BhOrdersController@getSorderRefundTaskLogs']);
}); });
......
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