Commit 0f81938f by 杨树贤

完成用户兑换的相关服务

parent 84ec7bbd
<?php
namespace App\Http\Controllers;
use App\Http\Filters\UserExchangeFilter;
use App\Models\UserExchange;
use Illuminate\Http\Request;
use Illuminate\Support\Facades\DB;
use Illuminate\Support\Facades\Log;
class UserExchangesController extends Controller
{
public function show($id)
{
$userExchange = UserExchange::where('user_id', $id)->first()->toArray();
return $this->Export(0, 'ok', ['data' => $userExchange]);
}
public function index(Request $request, UserExchangeFilter $filter)
{
$page = $request->has('page') ? $request->page : 1;
$pageSize = $request->has('page_size') ? $request->page_size : 10;
$userExchanges = UserExchange::filter($filter)->page($page, $pageSize)
->orderBy('id', 'desc')
->get()->toArray();
$count = UserExchange::filter($filter)->count();
return $this->Export(0, 'ok', ['data' => $userExchanges, 'count' => $count]);
}
public function update(Request $request, $id)
{
$data = array_merge($request->all(), ['update_time' => time()]);
$res = DB::table('user_exchanges')->where('id', $id)
->update($data);
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_exchanges')
->whereIn('id', $ids)
->update(['status' => (int)$status]);
return $this->Export(0, 'ok');
// return $this->Export(033, '批量修改用户积分失败');
}
}
\ No newline at end of file
...@@ -15,7 +15,8 @@ class UserIntegralsController extends Controller ...@@ -15,7 +15,8 @@ class UserIntegralsController extends Controller
{ {
public function show($id) public function show($id)
{ {
$integral = UserIntegral::where('user_id', $id)->first()->toArray(); $integral = UserIntegral::where('user_id', $id)->first();
$integral = $integral ?: [];
return $this->Export(0, 'ok', ['data' => $integral]); return $this->Export(0, 'ok', ['data' => $integral]);
......
<?php
namespace App\Http\Filters;
class UserExchangeFilter extends QueryFilter
{
public function user_id($userId = 0)
{
return $this->builder->whereUserId($userId);
}
public function status($status = 0)
{
return $this->builder->whereStatus($status);
}
public function type($type = 0)
{
return $this->builder->whereType($type);
}
}
\ No newline at end of file
<?php
namespace App\Models;
use App\Http\Filters\QueryFilter;
use Illuminate\Database\Eloquent\Model;
class UserExchange 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
...@@ -54,3 +54,9 @@ $router->post('/exchange_settings', 'ExchangeSettingsController@store'); ...@@ -54,3 +54,9 @@ $router->post('/exchange_settings', 'ExchangeSettingsController@store');
$router->patch('/exchange_settings/{id}', 'ExchangeSettingsController@update'); $router->patch('/exchange_settings/{id}', 'ExchangeSettingsController@update');
$router->delete('/exchange_settings/{id}', 'ExchangeSettingsController@destroy'); $router->delete('/exchange_settings/{id}', 'ExchangeSettingsController@destroy');
$router->post('/exchange_settings/batchUpdateStatus', 'ExchangeSettingsController@batchUpdateStatus'); $router->post('/exchange_settings/batchUpdateStatus', 'ExchangeSettingsController@batchUpdateStatus');
//用户兑换记录
$router->get('/user_exchanges/{id}', 'UserExchangesController@show');
$router->get('/user_exchanges', 'UserExchangesController@index');
$router->patch('/user_exchanges/{id}', 'UserExchangesController@update');
$router->post('/user_exchanges/batchUpdateStatus', 'UserExchangesController@batchUpdateStatus');
17955 28382
\ 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