<?php
 namespace App\Http\Controllers\Admin; use TechOnline\Laravel\Dao\ModelUtil; use TechOnline\Laravel\Http\Response; use TechSoft\Laravel\Admin\Cms\BasicCms; use TechSoft\Laravel\Admin\Cms\Field\FieldDatetime; use TechSoft\Laravel\Admin\Cms\Field\FieldRichtext; use TechSoft\Laravel\Admin\Cms\Field\FieldText; use TechSoft\Laravel\Admin\Cms\Field\FieldTextarea; use TechSoft\Laravel\Admin\Support\AdminCheckController; use TechSoft\Laravel\Admin\Util\AdminCmsUtil; use TechSoft\Laravel\Admin\Util\AdminPowerUtil; use TechSoft\Laravel\Forum\ForumUtil; use TechSoft\Laravel\Forum\Types\ThreadStatus; class ForumThreadController extends AdminCheckController { private $cmsConfigData = [ 'model' => 'forum_thread', 'pageTitle' => '帖子列表', 'group' => 'data', 'canView' => true, 'canDelete' => true, 'batchOperate' => true, 'batchDelete' => true, 'fields' => [ 'title' => ['type' => FieldText::class, 'title' => '名称', 'list' => true, 'add' => true, 'edit' => true, 'view' => true, 'search' => true,], 'created_at' => ['type' => FieldDatetime::class, 'title' => '时间', 'list' => true, 'add' => true, 'edit' => true, 'view' => true], 'content' => ['type' => FieldTextarea::class, 'title' => '内容', 'view' => true], ] ]; public function dataPostDelete(&$data) { ModelUtil::delete('forum_post', ['threadId' => $data['id']]); ModelUtil::delete('forum_thread_member_data', ['threadId' => $data['id']]); } public function dataProcessView(&$item, &$record) { $item['title'] = '<a href="' . action('\App\Http\Controllers\Main\ThreadController@index', ['id' => $record['id']]) . '" target="_blank">' . htmlspecialchars($record['title']) . '</a>'; if ($record['status'] === ThreadStatus::WAIT_VERIFY) { $item['title'] .= ' ' . AdminCmsUtil::pass(action('\App\Http\Controllers\Admin\ForumThreadController@verifyPass', ['id' => $record['id']])); $item['title'] .= ' ' . AdminCmsUtil::reject(action('\App\Http\Controllers\Admin\ForumThreadController@verifyReject', ['id' => $record['id']])); } } public function verifyList(BasicCms $basicCms) { $this->cmsConfigData['listFilter']['where']['status'] = ThreadStatus::WAIT_VERIFY; return $basicCms->executeList($this, $this->cmsConfigData); } public function verifyPass($id) { if (AdminPowerUtil::isDemo()) { return AdminPowerUtil::demoResponse(); } ForumUtil::updateThread($id, ['status' => ThreadStatus::VERIFY_PASS]); return Response::send(0, null, null, '[js]window.__cms.action.refresh();'); } public function verifyReject($id) { if (AdminPowerUtil::isDemo()) { return AdminPowerUtil::demoResponse(); } ForumUtil::deleteThread($id); return Response::send(0, null, null, '[js]window.__cms.action.refresh();'); } public function dataList(BasicCms $basicCms) { return $basicCms->executeList($this, $this->cmsConfigData); } public function dataAdd(BasicCms $basicCms) { return $basicCms->executeAdd($this, $this->cmsConfigData); } public function dataEdit(BasicCms $basicCms) { return $basicCms->executeEdit($this, $this->cmsConfigData); } public function dataDelete(BasicCms $basicCms) { return $basicCms->executeDelete($this, $this->cmsConfigData); } public function dataView(BasicCms $basicCms) { return $basicCms->executeView($this, $this->cmsConfigData); } }