mirror of https://github.com/4xmen/xshop.git
added ticket controller
parent
3bfdd29e17
commit
b634056dd1
@ -0,0 +1,142 @@
|
||||
<?php
|
||||
|
||||
namespace App\Http\Controllers\Admin;
|
||||
|
||||
use App\Http\Controllers\Controller;
|
||||
use App\Http\Controllers\XController;
|
||||
use App\Http\Requests\TicketSaveRequest;
|
||||
use App\Models\Access;
|
||||
use App\Models\Ticket;
|
||||
use Illuminate\Http\Request;
|
||||
use App\Helper;
|
||||
use function App\Helpers\hasCreateRoute;
|
||||
|
||||
class TicketController extends XController
|
||||
{
|
||||
|
||||
// protected $_MODEL_ = Ticket::class;
|
||||
// protected $SAVE_REQUEST = TicketSaveRequest::class;
|
||||
|
||||
protected $cols = ['title','status','customer_id'];
|
||||
protected $extra_cols = ['id'];
|
||||
|
||||
protected $searchable = [];
|
||||
|
||||
protected $listView = 'admin.tickets.ticket-list';
|
||||
protected $formView = 'admin.tickets.ticket-form';
|
||||
|
||||
|
||||
protected $buttons = [
|
||||
'edit' =>
|
||||
['title' => "Edit", 'class' => 'btn-outline-primary', 'icon' => 'ri-edit-2-line'],
|
||||
// 'show' =>
|
||||
// ['title' => "Detail", 'class' => 'btn-outline-light', 'icon' => 'ri-eye-line'],
|
||||
'destroy' =>
|
||||
['title' => "Remove", 'class' => 'btn-outline-danger delete-confirm', 'icon' => 'ri-close-line'],
|
||||
];
|
||||
|
||||
|
||||
public function __construct()
|
||||
{
|
||||
parent::__construct(Ticket::class, TicketSaveRequest::class);
|
||||
}
|
||||
|
||||
/**
|
||||
* @param $ticket Ticket
|
||||
* @param $request TicketSaveRequest
|
||||
* @return Ticket
|
||||
*/
|
||||
public function save($ticket, $request)
|
||||
{
|
||||
|
||||
$ticket->save();
|
||||
return $ticket;
|
||||
|
||||
}
|
||||
|
||||
public function index()
|
||||
{
|
||||
$query = $this->makeSortAndFilter();
|
||||
$query = $query->whereNull('parent_id');
|
||||
return $this->showList($query);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Show the form for creating a new resource.
|
||||
*/
|
||||
public function create()
|
||||
{
|
||||
//
|
||||
return view($this->formView);
|
||||
}
|
||||
|
||||
/**
|
||||
* Show the form for editing the specified resource.
|
||||
*/
|
||||
public function edit(Ticket $item)
|
||||
{
|
||||
//
|
||||
return view($this->formView, compact('item'));
|
||||
}
|
||||
|
||||
public function bulk(Request $request)
|
||||
{
|
||||
|
||||
// dd($request->all());
|
||||
$data = explode('.', $request->input('action'));
|
||||
$action = $data[0];
|
||||
$ids = $request->input('id');
|
||||
switch ($action) {
|
||||
case 'delete':
|
||||
$msg = __(':COUNT items deleted successfully', ['COUNT' => count($ids)]);
|
||||
$this->_MODEL_::destroy($ids);
|
||||
break;
|
||||
case 'close':
|
||||
$this->_MODEL_::whereIn('id', $request->input('id'))->update(['status' => 'CLOSED']);
|
||||
$msg = __(':COUNT items closed successfully', ['COUNT' => count($ids)]);
|
||||
break;
|
||||
case 'pending':
|
||||
$this->_MODEL_::whereIn('id', $request->input('id'))->update(['status' => 'PENDING']);
|
||||
$msg = __(':COUNT items pending successfully', ['COUNT' => count($ids)]);
|
||||
break;
|
||||
case 'answered':
|
||||
$this->_MODEL_::whereIn('id', $request->input('id'))->update(['status' => 'ANSWERED']);
|
||||
$msg = __(':COUNT items answered successfully', ['COUNT' => count($ids)]);
|
||||
break;
|
||||
default:
|
||||
$msg = __('Unknown bulk action : :ACTION', ["ACTION" => $action]);
|
||||
}
|
||||
|
||||
return $this->do_bulk($msg, $action, $ids);
|
||||
}
|
||||
|
||||
public function destroy(Ticket $item)
|
||||
{
|
||||
return parent::delete($item);
|
||||
}
|
||||
|
||||
|
||||
public function update(Request $request, Ticket $item)
|
||||
{
|
||||
$item->answer = $request->answer;
|
||||
$item->status = $request->status;
|
||||
$item->save();
|
||||
if ($request->has('answers')){
|
||||
foreach ($request->answers as $id => $answer) {
|
||||
Ticket::whereId($id)->update(['answer' => $answer]);
|
||||
}
|
||||
}
|
||||
logAdmin(__METHOD__,Ticket::class,$item->id);
|
||||
if ($request->ajax()) {
|
||||
return ['OK' => true,
|
||||
"data" => modelWithCustomAttrs($item) ,
|
||||
"message" => __('As you wished updated successfully'), "id" => $item->id];
|
||||
} else {
|
||||
return redirect(getRoute('edit', $item->{$item->getRouteKeyName()}))
|
||||
->with(['message' => __('As you wished updated successfully')]);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
}
|
@ -0,0 +1,28 @@
|
||||
<?php
|
||||
|
||||
namespace App\Http\Requests;
|
||||
|
||||
use Illuminate\Foundation\Http\FormRequest;
|
||||
|
||||
class TicketSaveRequest extends FormRequest
|
||||
{
|
||||
/**
|
||||
* Determine if the user is authorized to make this request.
|
||||
*/
|
||||
public function authorize(): bool
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the validation rules that apply to the request.
|
||||
*
|
||||
* @return array<string, \Illuminate\Contracts\Validation\ValidationRule|array<mixed>|string>
|
||||
*/
|
||||
public function rules(): array
|
||||
{
|
||||
return [
|
||||
//
|
||||
];
|
||||
}
|
||||
}
|
@ -0,0 +1,21 @@
|
||||
<?php
|
||||
|
||||
namespace App\Models;
|
||||
|
||||
use Illuminate\Database\Eloquent\Factories\HasFactory;
|
||||
use Illuminate\Database\Eloquent\Model;
|
||||
|
||||
class Ticket extends Model
|
||||
{
|
||||
// use HasFactory;
|
||||
public static $ticket_statuses = [['PENDING','ANSWERED','CLOSED']];
|
||||
|
||||
|
||||
public function customer(){
|
||||
return $this->belongsTo(Customer::class);
|
||||
}
|
||||
|
||||
public function subTickets(){
|
||||
return $this->hasMany(Ticket::class,'parent_id','id')->orderBy('id');
|
||||
}
|
||||
}
|
@ -0,0 +1,35 @@
|
||||
<?php
|
||||
|
||||
use Illuminate\Database\Migrations\Migration;
|
||||
use Illuminate\Database\Schema\Blueprint;
|
||||
use Illuminate\Support\Facades\Schema;
|
||||
|
||||
return new class extends Migration
|
||||
{
|
||||
/**
|
||||
* Run the migrations.
|
||||
*/
|
||||
public function up(): void
|
||||
{
|
||||
Schema::create('tickets', function (Blueprint $table) {
|
||||
$table->id();
|
||||
$table->string('title',128)->nullable()->default(null);
|
||||
$table->unsignedBigInteger('customer_id');
|
||||
$table->text('body');
|
||||
$table->enum('status',['PENDING','ANSWERED','CLOSED'])->default('PENDING');
|
||||
$table->text('answer')->nullable()->default(null);
|
||||
$table->unsignedInteger('parent_id')->nullable()->default(null)->index();
|
||||
$table->timestamps();
|
||||
$table->foreign('customer_id')->on('customers')
|
||||
->references('id')->onDelete('cascade');
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* Reverse the migrations.
|
||||
*/
|
||||
public function down(): void
|
||||
{
|
||||
Schema::dropIfExists('tickets');
|
||||
}
|
||||
};
|
@ -0,0 +1,70 @@
|
||||
@extends('admin.templates.panel-form-template')
|
||||
@section('title')
|
||||
@if(isset($item))
|
||||
{{__("Edit ticket")}} [{{$item->title}}]
|
||||
@else
|
||||
{{__("Add new ticket")}}
|
||||
@endif -
|
||||
@endsection
|
||||
@section('form')
|
||||
|
||||
<div class="row">
|
||||
<div class="col-lg-3">
|
||||
|
||||
@include('components.err')
|
||||
<div class="item-list mb-3">
|
||||
<h3 class="p-3">
|
||||
<i class="ri-message-3-line"></i>
|
||||
{{__("Tips")}}
|
||||
</h3>
|
||||
<ul>
|
||||
<li>
|
||||
{{__("Recommends")}}
|
||||
</li>
|
||||
</ul>
|
||||
</div>
|
||||
|
||||
</div>
|
||||
<div class="col-lg-9 ps-xl-1 ps-xxl-1">
|
||||
<div class="general-form ">
|
||||
|
||||
<h1>
|
||||
@if(isset($item))
|
||||
{{__("Edit ticket")}} [{{$item->title}}]
|
||||
@else
|
||||
{{__("Add new ticket")}}
|
||||
@endif
|
||||
</h1>
|
||||
|
||||
<div class="card">
|
||||
<div class="card-body txt-area">{{$item->body}}</div>
|
||||
<div class="card-footer">
|
||||
<textarea name="answer" class="form-control" rows="7" placeholder="{{__("Answer")}}..." minlength="5">{{$item->answer}}</textarea>
|
||||
</div>
|
||||
</div>
|
||||
@foreach($item->subTickets as $t)
|
||||
<div class="card mt-2">
|
||||
<div class="card-body txt-area">{{$t->body}}</div>
|
||||
<div class="card-footer">
|
||||
<textarea name="answers[{{$t->id}}]" class="form-control" rows="7" placeholder="{{__("Answer")}}..." minlength="5">{{$t->answer}}</textarea>
|
||||
</div>
|
||||
|
||||
</div>
|
||||
@endforeach
|
||||
<div class="row mt-3">
|
||||
<div class="col-md">
|
||||
<button class="btn btn-primary w-100" name="status" value="ANSWERED">
|
||||
{{__("Send Answer")}}
|
||||
</button>
|
||||
</div>
|
||||
<div class="col-md">
|
||||
<button class="btn btn-success w-100 " name="status" value="CLOSED">
|
||||
{{__("Send Answer and close")}}
|
||||
</button>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
@endsection
|
@ -0,0 +1,17 @@
|
||||
@extends('admin.templates.panel-list-template')
|
||||
|
||||
@section('list-title')
|
||||
<i class="ri-user-3-line"></i>
|
||||
{{__("Tickets list")}}
|
||||
@endsection
|
||||
@section('title')
|
||||
{{__("Tickets list")}} -
|
||||
@endsection
|
||||
@section('filter')
|
||||
{{-- Other filters --}}
|
||||
@endsection
|
||||
@section('bulk')
|
||||
<option value="close"> {{__("Close")}} </option>
|
||||
<option value="pending"> {{__("Pending")}} </option>
|
||||
<option value="answered"> {{__("Answered")}} </option>
|
||||
@endsection
|
Loading…
Reference in New Issue