Commit a26cd2df by 杨树贤

完成简单的积分类型信息增删改查

parent 8d7fc044
<?php
namespace App\Http\Controllers;
use App\Models\IntegralType;
use Illuminate\Http\Request;
use Illuminate\Support\Facades\DB;
class IntegralTypesController extends Controller
{
public function index()
{
$integrals = IntegralType::all()->toArray();
return $this->Export(0, 'ok', ['data' => $integrals]);
}
public function create(Request $request)
{
$res = DB::table('integral_types')->insert([
'name' => $request->name,
'add_time' => time(),
'status' => 1,
]);
if ($res) {
return $this->Export(0, 'ok');
} else {
return $this->Export(ErrorCode(011, 5), '新增积分信息失败');
}
}
public function update(Request $request, $id)
{
$res = DB::table('integral_types')->where('id', $id)
->update([
'name' => $request->name,
'status' => $request->status,
]);
if ($res) {
return $this->Export(0, 'ok');
} else {
return $this->Export(ErrorCode(012, 5), '更新积分信息失败');
}
}
public function destroy($ids)
{
$ids = explode(',', trim($ids));
$res = DB::table('integral_types')->whereIn('id', $ids)->delete();
if ($res) {
return $this->Export(0, 'ok');
} else {
return $this->Export(ErrorCode(013, 5), '删除积分信息失败');
}
}
}
\ No newline at end of file
......@@ -12,7 +12,7 @@ class IntegralsController extends Controller
{
public function index()
{
$integrals = Integral::with('integralType')
$integrals = Integral::with('integralType:id,name')
->whereStatus(1)
->get()->toArray();
......@@ -51,7 +51,7 @@ class IntegralsController extends Controller
public function destroy($ids)
{
$ids = explode(',', $ids);
$ids = explode(',', trim($ids));
$res = DB::table('integrals')->whereIn('id', $ids)->delete();
if ($res) {
return $this->Export(0, 'ok');
......
......@@ -9,4 +9,6 @@ use Illuminate\Database\Eloquent\Model;
class IntegralType extends Model
{
public $timestamps = false;
protected $fillable = ['name','status'];
}
\ No newline at end of file
......@@ -19,7 +19,14 @@ $router->get('/key', function () {
return str_random(32);
});
//积分信息
$router->get('/integrals', 'IntegralsController@index');
$router->post('/integrals', 'IntegralsController@create');
$router->patch('/integrals/{id}', 'IntegralsController@update');
$router->delete('/integrals/{id}', 'IntegralsController@destroy');
//积分类型
$router->get('/integral_types', 'IntegralTypesController@index');
$router->post('/integral_types', 'IntegralTypesController@create');
$router->patch('/integral_types/{id}', 'IntegralTypesController@update');
$router->delete('/integral_types/{id}', 'IntegralTypesController@destroy');
\ 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