Commit 3bdbee7f by 杨树贤

完成兑换配置的服务相关接口

parent 64d34878
<?php
namespace App\Http\Controllers;
use App\Http\Filters\ExchangeSettingFilter;
use App\Models\ExchangeSetting;
use App\Models\Integral;
use Illuminate\Http\Request;
use Illuminate\Support\Facades\DB;
use Illuminate\Support\Facades\Log;
class ExchangeSettingsController extends Controller
{
public function show($id)
{
$exchangeSetting = ExchangeSetting::find($id)->toArray();
return $this->Export(0, 'ok', ['data' => $exchangeSetting]);
}
public function index(Request $request, ExchangeSettingFilter $filter)
{
$page = $request->has('page') ? $request->page : 1;
$page_size = $request->has('page_size') ? $request->page_size : 10;
$settings = ExchangeSetting::filter($filter)
->page($page, $page_size)
->orderBy('id', 'desc')
->get()->toArray();
$count = ExchangeSetting::filter($filter)->count();
return $this->Export(0, 'ok', ['data' => $settings, 'count' => $count]);
}
public function store(Request $request)
{
$res = DB::table('exchange_settings')->insert([
'name' => $request->name,
'stock' => $request->stock,
'amount' => $request->amount,
'type' => $request->type,
'add_time' => time(),
'status' => $request->status,
]);
if ($res) {
return $this->Export(0, 'ok');
} else {
return $this->Export(ErrorCode(041, 5), '新增积分信息失败');
}
}
public function update(Request $request, $id)
{
$data = array_merge($request->all(), ['update_time' => time()]);
$res = DB::table('exchange_settings')->where('id', $id)
->update($data);
return $this->Export(0, 'ok');
}
public function destroy($ids)
{
$ids = explode(',', trim($ids));
$res = DB::table('exchange_settings')->whereIn('id', $ids)->delete();
if ($res) {
return $this->Export(0, 'ok');
} else {
return $this->Export(ErrorCode(043, 5), '删除积分信息失败');
}
}
public function batchUpdateStatus(Request $request)
{
$ids = $request->ids;
if (!is_array($ids)) {
return Log::Info('批量修改参数不是数组');
}
$status = $request->status;
$result = DB::table('exchange_settings')
->whereIn('id', $ids)
->update(['status' => (int)$status, 'update_time' => time()]);
return $this->Export(0, 'ok');
// return $this->Export(033, '批量修改用户积分失败');
}
}
\ No newline at end of file
...@@ -34,8 +34,9 @@ class UserIntegralsController extends Controller ...@@ -34,8 +34,9 @@ class UserIntegralsController extends Controller
public function update(Request $request, $id) public function update(Request $request, $id)
{ {
$data = array_merge($request->all(), ['update_time' => time()]);
$res = DB::table('user_integrals')->where('id', $id) $res = DB::table('user_integrals')->where('id', $id)
->update($request->all()); ->update($data);
return $this->Export(0, 'ok'); return $this->Export(0, 'ok');
} }
......
<?php
namespace App\Http\Filters;
class ExchangeSettingFilter extends QueryFilter
{
public function name($name)
{
return $this->builder->whereName($name);
}
public function status($status = 0)
{
return $this->builder->whereStatus($status);
}
public function type($type)
{
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 ExchangeSetting 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
...@@ -42,4 +42,13 @@ $router->delete('/integral_bills/{id}', 'IntegralBillsController@destroy'); ...@@ -42,4 +42,13 @@ $router->delete('/integral_bills/{id}', 'IntegralBillsController@destroy');
$router->get('/user_integrals/{id}', 'UserIntegralsController@show'); $router->get('/user_integrals/{id}', 'UserIntegralsController@show');
$router->get('/user_integrals', 'UserIntegralsController@index'); $router->get('/user_integrals', 'UserIntegralsController@index');
$router->patch('/user_integrals/{id}', 'UserIntegralsController@update'); $router->patch('/user_integrals/{id}', 'UserIntegralsController@update');
$router->post('user_integrals/batchUpdateStatus', 'UserIntegralsController@batchUpdateStatus'); $router->post('/user_integrals/batchUpdateStatus', 'UserIntegralsController@batchUpdateStatus');
\ No newline at end of file
//兑换配置
$router->get('/exchange_settings/{id}', 'ExchangeSettingsController@show');
$router->get('/exchange_settings', 'ExchangeSettingsController@index');
$router->post('/exchange_settings', 'ExchangeSettingsController@store');
$router->patch('/exchange_settings/{id}', 'ExchangeSettingsController@update');
$router->delete('/exchange_settings/{id}', 'ExchangeSettingsController@destroy');
$router->post('/exchange_settings/batchUpdateStatus', 'ExchangeSettingsController@batchUpdateStatus');
2721 17171
\ 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