This commit is contained in:
root 2019-12-12 19:47:32 +08:00
parent 1b92b6374c
commit aa07facebd
8 changed files with 123 additions and 4 deletions

View File

@ -2,8 +2,6 @@
namespace App\Http\Controllers\Admin; namespace App\Http\Controllers\Admin;
use App\Http\Requests\Admin\ServerSave;
use App\Http\Requests\Admin\ServerUpdate;
use Illuminate\Http\Request; use Illuminate\Http\Request;
use App\Http\Controllers\Controller; use App\Http\Controllers\Controller;
use App\Models\ServerGroup; use App\Models\ServerGroup;

View File

@ -0,0 +1,16 @@
<?php
namespace App\Http\Controllers\Admin;
use Illuminate\Http\Request;
use App\Http\Controllers\Controller;
use App\Models\Ticket;
use App\Models\TicketMessage;
use Illuminate\Support\Facades\Redis;
class TicketController extends Controller
{
public function index (Request $request) {
}
}

View File

@ -5,7 +5,6 @@ namespace App\Http\Controllers;
use Illuminate\Http\Request; use Illuminate\Http\Request;
use App\Http\Controllers\Controller; use App\Http\Controllers\Controller;
use App\Models\Plan; use App\Models\Plan;
use App\Models\User;
class PlanController extends Controller class PlanController extends Controller
{ {
@ -17,7 +16,6 @@ class PlanController extends Controller
if (!$plan) { if (!$plan) {
abort(500, '该订阅不存在'); abort(500, '该订阅不存在');
} }
$user = User::find($request->session()->get('id'));
return response([ return response([
'data' => $plan 'data' => $plan
]); ]);

View File

@ -0,0 +1,49 @@
<?php
namespace App\Http\Controllers;
use App\Http\Requests\TicketSave;
use Illuminate\Http\Request;
use App\Http\Controllers\Controller;
use App\Models\Ticket;
use App\Models\TicketMessage;
use App\Utils\Helper;
use Illuminate\Support\Facades\DB;
class TicketController extends Controller
{
public function index (Request $request) {
return response([
'data' => Ticket::where('user_id', $request->session()->get('id'))
->orderBy('created_at', 'DESC')
->get()
]);
}
public function save (TicketSave $request) {
DB::beginTransaction();
$ticket = Ticket::create(array_merge($request->only([
'subject',
'level'
]), [
'user_id' => $request->session()->get('id')
]));
if (!$ticket) {
DB::rollback();
abort(500, '工单创建失败');
}
$ticketMessage = TicketMessage::create([
'user_id' => $request->session()->get('id'),
'ticket_id' => $ticket->id,
'message' => $request->input('message')
]);
if (!$ticketMessage) {
DB::rollback();
abort(500, '工单创建失败');
}
DB::commit();
return response([
'data' => true
]);
}
}

View File

@ -0,0 +1,32 @@
<?php
namespace App\Http\Requests;
use Illuminate\Foundation\Http\FormRequest;
class TicketSave extends FormRequest
{
/**
* Get the validation rules that apply to the request.
*
* @return array
*/
public function rules()
{
return [
'subject' => 'required',
'level' => 'required|in:0,1,2',
'message' => 'required'
];
}
public function messages()
{
return [
'subject.required' => '工单主题不能为空',
'level.required' => '工单级别不能为空',
'level.in' => '工单级别格式不正确',
'message.required' => '消息不能为空'
];
}
}

12
app/Models/Ticket.php Normal file
View File

@ -0,0 +1,12 @@
<?php
namespace App\Models;
use Illuminate\Database\Eloquent\Model;
class Ticket extends Model
{
protected $table = 'v2_ticket';
protected $dateFormat = 'U';
protected $guarded = ['id'];
}

View File

@ -0,0 +1,12 @@
<?php
namespace App\Models;
use Illuminate\Database\Eloquent\Model;
class TicketMessage extends Model
{
protected $table = 'v2_ticket_message';
protected $dateFormat = 'U';
protected $guarded = ['id'];
}

View File

@ -80,6 +80,8 @@ Route::prefix('v1')
Route::get ('tutorial/getAppleID', 'TutorialController@getAppleID'); Route::get ('tutorial/getAppleID', 'TutorialController@getAppleID');
// Notice // Notice
Route::get ('notice', 'NoticeController@index'); Route::get ('notice', 'NoticeController@index');
// Ticket
Route::post('ticket/save', 'TicketController@save');
}); });
// Passport // Passport