diff --git a/app/Http/Controllers/Admin/TicketController.php b/app/Http/Controllers/Admin/TicketController.php index df71b777..ea9b81f2 100644 --- a/app/Http/Controllers/Admin/TicketController.php +++ b/app/Http/Controllers/Admin/TicketController.php @@ -7,7 +7,7 @@ use App\Http\Controllers\Controller; use App\Models\User; use App\Models\Ticket; use App\Models\TicketMessage; -use Illuminate\Support\Facades\Redis; +use Illuminate\Support\Facades\DB; class TicketController extends Controller { @@ -29,7 +29,6 @@ class TicketController extends Controller $ticket['user'] = User::select([ 'email' ])->find($ticket->user_id); - $ticket['avatar_url'] = 'https://cdn.v2ex.com/gravatar/' . md5($ticket['user']->email) . '?s=64&d=identicon'; return response([ 'data' => $ticket ]); @@ -52,14 +51,18 @@ class TicketController extends Controller if (!$ticket) { abort(500, '工单不存在'); } + DB::beginTransaction(); $ticketMessage = TicketMessage::create([ 'user_id' => $request->session()->get('id'), 'ticket_id' => $ticket->id, 'message' => $request->input('message') ]); - if (!$ticketMessage) { + $ticket->last_reply_user_id = $request->session()->get('id'); + if (!$ticketMessage || !$ticket->save()) { + DB::rollback(); abort(500, '工单回复失败'); } + DB::commit(); return response([ 'data' => true ]); diff --git a/app/Http/Controllers/TicketController.php b/app/Http/Controllers/TicketController.php index b21d5bee..6a29a9b9 100644 --- a/app/Http/Controllers/TicketController.php +++ b/app/Http/Controllers/TicketController.php @@ -45,7 +45,8 @@ class TicketController extends Controller 'subject', 'level' ]), [ - 'user_id' => $request->session()->get('id') + 'user_id' => $request->session()->get('id'), + 'last_reply_user_id' => $request->session()->get('id') ])); if (!$ticket) { DB::rollback(); @@ -82,14 +83,18 @@ class TicketController extends Controller if ($request->session()->get('id') == $this->getLastMessage($ticket->id)->user_id) { abort(500, '请等待技术支持回复'); } + DB::beginTransaction(); $ticketMessage = TicketMessage::create([ 'user_id' => $request->session()->get('id'), 'ticket_id' => $ticket->id, 'message' => $request->input('message') ]); - if (!$ticketMessage) { + $ticket->last_reply_user_id = $request->session()->get('id'); + if (!$ticketMessage || !$ticket->save()) { + DB::rollback(); abort(500, '工单回复失败'); } + DB::commit(); return response([ 'data' => true ]); diff --git a/install.sql b/install.sql index 3b6ad1c4..6ec190ad 100644 --- a/install.sql +++ b/install.sql @@ -22,6 +22,7 @@ CREATE TABLE `v2_notice` ( `id` int(11) NOT NULL AUTO_INCREMENT, `title` varchar(255) NOT NULL, `content` text NOT NULL, + `img_url` varchar(255) DEFAULT NULL, `created_at` int(11) NOT NULL, `updated_at` int(11) NOT NULL, PRIMARY KEY (`id`) @@ -110,6 +111,31 @@ CREATE TABLE `v2_server_log` ( ) ENGINE=InnoDB DEFAULT CHARSET=utf8; +DROP TABLE IF EXISTS `v2_ticket`; +CREATE TABLE `v2_ticket` ( + `id` int(11) NOT NULL AUTO_INCREMENT, + `user_id` int(11) NOT NULL, + `subject` varchar(255) NOT NULL, + `level` tinyint(1) NOT NULL, + `status` tinyint(1) NOT NULL DEFAULT '0', + `created_at` int(11) NOT NULL, + `updated_at` int(11) NOT NULL, + PRIMARY KEY (`id`) +) ENGINE=InnoDB DEFAULT CHARSET=utf8; + + +DROP TABLE IF EXISTS `v2_ticket_message`; +CREATE TABLE `v2_ticket_message` ( + `id` int(11) NOT NULL AUTO_INCREMENT, + `user_id` int(11) NOT NULL, + `ticket_id` int(11) NOT NULL, + `message` varchar(255) NOT NULL, + `created_at` int(11) NOT NULL, + `updated_at` int(11) NOT NULL, + PRIMARY KEY (`id`) +) ENGINE=InnoDB DEFAULT CHARSET=utf8; + + DROP TABLE IF EXISTS `v2_user`; CREATE TABLE `v2_user` ( `id` int(11) NOT NULL AUTO_INCREMENT, @@ -144,4 +170,4 @@ CREATE TABLE `v2_user` ( ) ENGINE=InnoDB DEFAULT CHARSET=utf8; --- 2019-12-12 05:40:39 \ No newline at end of file +-- 2019-12-13 08:54:25 \ No newline at end of file diff --git a/update.sql b/update.sql index 33c2098a..bc9dd484 100644 --- a/update.sql +++ b/update.sql @@ -25,4 +25,28 @@ CREATE TABLE `v2_notice` ( `content` text NOT NULL, `created_at` int(11) NOT NULL, `updated_at` int(11) NOT NULL -); \ No newline at end of file +); + +CREATE TABLE `v2_ticket` ( + `id` int(11) NOT NULL AUTO_INCREMENT, + `user_id` int(11) NOT NULL, + `subject` varchar(255) NOT NULL, + `level` tinyint(1) NOT NULL, + `status` tinyint(1) NOT NULL DEFAULT '0', + `created_at` int(11) NOT NULL, + `updated_at` int(11) NOT NULL, + PRIMARY KEY (`id`) +) ENGINE=InnoDB DEFAULT CHARSET=utf8; + +CREATE TABLE `v2_ticket_message` ( + `id` int(11) NOT NULL AUTO_INCREMENT, + `user_id` int(11) NOT NULL, + `ticket_id` int(11) NOT NULL, + `message` varchar(255) NOT NULL, + `created_at` int(11) NOT NULL, + `updated_at` int(11) NOT NULL, + PRIMARY KEY (`id`) +) ENGINE=InnoDB DEFAULT CHARSET=utf8; + +ALTER TABLE `v2_ticket` +ADD `status` tinyint(1) NOT NULL DEFAULT '0' AFTER `level`; \ No newline at end of file