Commit 8d7fc044 by 杨树贤

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

parent 1f1f3359
...@@ -7,4 +7,19 @@ use Laravel\Lumen\Routing\Controller as BaseController; ...@@ -7,4 +7,19 @@ use Laravel\Lumen\Routing\Controller as BaseController;
class Controller extends BaseController class Controller extends BaseController
{ {
// //
public function Export( $Errcode=0,$ErrMsg='', $dataArr=[]) {
if(!empty($dataArr) && !is_array($dataArr)) {
$Errcode = -1;
$ErrMsg = '系统错误';
}
$data=['errcode'=>$Errcode, 'errmsg'=>$ErrMsg];
if(($data['errcode'] < 10000 || $data['errcode'] >= 50000) && $data['errcode'] !==0 )//非正常返回码,上报
ErrorLog($Errcode,$ErrMsg);
if(!empty($dataArr)) foreach ($dataArr as $k=>$v) $data[$k]=$v;
return json_encode($data);
}
} }
<?php
namespace App\Http\Controllers;
use App\Models\Integral;
use Illuminate\Http\Request;
use Illuminate\Support\Facades\DB;
class IntegralsController extends Controller
{
public function index()
{
$integrals = Integral::with('integralType')
->whereStatus(1)
->get()->toArray();
return $this->Export(0, 'ok', ['data' => $integrals]);
}
public function create(Request $request)
{
$res = DB::table('integrals')->insert([
'name' => $request->name,
'integral_type_id' => $request->integral_type_id,
'add_time' => time(),
'status' => 1,
]);
if ($res) {
return $this->Export(0, 'ok');
} else {
return $this->Export(ErrorCode(001, 5), '新增积分信息失败');
}
}
public function update(Request $request, $id)
{
$res = DB::table('integrals')->where('id', $id)
->update([
'name' => $request->name,
'integral_type_id' => $request->integral_type_id,
]);
if ($res) {
return $this->Export(0, 'ok');
} else {
return $this->Export(ErrorCode(002, 5), '更新积分信息失败');
}
}
public function destroy($ids)
{
$ids = explode(',', $ids);
$res = DB::table('integrals')->whereIn('id', $ids)->delete();
if ($res) {
return $this->Export(0, 'ok');
} else {
return $this->Export(ErrorCode(003, 5), '删除积分信息失败');
}
}
}
\ No newline at end of file
<?php
namespace App\Models;
use Illuminate\Database\Eloquent\Model;
class Integral extends Model
{
public $timestamps = false;
protected $hidden = ['id'];
public function integralType()
{
return $this->belongsTo(IntegralType::class, 'integral_type_id', 'id');
}
}
\ No newline at end of file
<?php
namespace App\Models;
use Illuminate\Database\Eloquent\Model;
class IntegralType extends Model
{
public $timestamps = false;
}
\ No newline at end of file
<?php <?php
function ErrorCode($code = 0, $level = 1){ function ErrorCode($code = 0, $level = 1){
$systemcode = config('system.code'); $systemcode = config('system.code');
return errCode($code , $level , $systemcode); return errCode($code , $level , $systemcode);
} }
\ No newline at end of file
...@@ -17,8 +17,14 @@ ...@@ -17,8 +17,14 @@
}, },
"autoload": { "autoload": {
"psr-4": { "psr-4": {
"App\\": "app/" "App\\": "app/",
} "Common\\": "common/"
},
"files": [
"common/function.php",
"common/LogReport.php",
"app/helpers.php"
]
}, },
"autoload-dev": { "autoload-dev": {
"classmap": [ "classmap": [
......
<?php <?php
return [ return [
'code' => env('SYSTEM_CODE'), 'code' => env('SYSTEM_CODE'),
]; ];
\ No newline at end of file
...@@ -15,6 +15,11 @@ $router->get('/', function () use ($router) { ...@@ -15,6 +15,11 @@ $router->get('/', function () use ($router) {
return $router->app->version(); return $router->app->version();
}); });
$router->get('/key', function() { $router->get('/key', function () {
return str_random(32); return str_random(32);
}); });
\ No newline at end of file
$router->get('/integrals', 'IntegralsController@index');
$router->post('/integrals', 'IntegralsController@create');
$router->patch('/integrals/{id}', 'IntegralsController@update');
$router->delete('/integrals/{id}', 'IntegralsController@destroy');
7307 3671
\ 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