FeedbackController.php 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319
  1. <?php
  2. namespace App\Admin\Controllers\Content;
  3. use App\Admin\Extensions\Tools\DialogTool;
  4. use App\Http\Controllers\Controller;
  5. use App\Models\AuditReason;
  6. use App\Models\Feedback;
  7. use App\Models\Subsite;
  8. use Encore\Admin\Controllers\HasResourceActions;
  9. use Encore\Admin\Facades\Admin;
  10. use Encore\Admin\Form;
  11. use Encore\Admin\Grid;
  12. use Encore\Admin\Grid\Filter;
  13. use Encore\Admin\Layout\Content;
  14. use Encore\Admin\Show;
  15. use Illuminate\Http\Request;
  16. use Illuminate\Support\Facades\Cache;
  17. class FeedbackController extends Controller
  18. {
  19. use HasResourceActions;
  20. /**
  21. * Index interface.
  22. *
  23. * @param Content $content
  24. * @return Content
  25. */
  26. public function index(Content $content)
  27. {
  28. return $content
  29. ->header('意见建议')
  30. ->description(' ')
  31. //->body($this->grid());
  32. ->body(view('admin.content.feedback')->with(['grid'=>$this->grid()]));
  33. }
  34. /**
  35. * Show interface.
  36. *
  37. * @param mixed $id
  38. * @param Content $content
  39. * @return Content
  40. */
  41. public function show($id, Content $content)
  42. {
  43. return $content
  44. ->header('Detail')
  45. ->description('description')
  46. ->body($this->detail($id));
  47. }
  48. /**
  49. * Edit interface.
  50. *
  51. * @param mixed $id
  52. * @param Content $content
  53. * @return Content
  54. */
  55. public function edit($id, Content $content)
  56. {
  57. return $content
  58. ->header('Edit')
  59. ->description('description')
  60. ->body($this->form()->edit($id));
  61. }
  62. /**
  63. * Create interface.
  64. *
  65. * @param Content $content
  66. * @return Content
  67. */
  68. public function create(Content $content)
  69. {
  70. return $content
  71. ->header('Create')
  72. ->description('description')
  73. ->body($this->form());
  74. }
  75. /**
  76. * Make a grid builder.
  77. *
  78. * @return Grid
  79. */
  80. protected function grid()
  81. {
  82. $grid = new Grid(new Feedback);
  83. if (get_subsite_id() != 0) {
  84. $where['subsite_id'] = get_subsite_id();
  85. $grid->model()->where($where)->orderBy('audit', 'asc')->orderBy('created_at', 'desc');
  86. } else {
  87. $grid->model()->orderBy('audit', 'asc')->orderBy('created_at', 'desc');
  88. }
  89. $grid->type('类型')->display(function ($type) {
  90. switch ($type){
  91. case '1':
  92. return '建议';
  93. break;
  94. case '2':
  95. return '意见';
  96. break;
  97. case '3':
  98. return '求助';
  99. break;
  100. case '4':
  101. return '投诉';
  102. break;
  103. case '0':
  104. return '未知';
  105. break;
  106. }
  107. });
  108. $grid->audit('处理状态')->display(function () {
  109. $audit_html = '';
  110. if ($this->audit) {
  111. $audit_html = '已处理';
  112. } else {
  113. $audit_html = '<span style="color:#ff0000;">未处理</span>';
  114. }
  115. return $audit_html;
  116. });
  117. $grid->content('内容')->display(function () {
  118. return '<span class="vtip" title="'.$this->content.'">'.cut_str($this->content, 40, 0, "...").'</span>';
  119. })->width(400);
  120. $grid->contact('联系方式');
  121. if(get_subsite_open()){
  122. $grid->subsite_id('所属分站')->display(function () {
  123. $subsites = Cache::get('subsites_list');
  124. if (array_has($subsites, $this->subsite_id)) {
  125. return $subsites[$this->subsite_id]['sitename'];
  126. }
  127. return '';
  128. });
  129. }
  130. $grid->created_at('添加时间');
  131. /*$grid->tools(function (Grid\Tools $tools) {
  132. $tools->disableRefreshButton();
  133. });*/
  134. $grid->actions(function ($actions) {
  135. if (Admin::user()->can('content_appeal_audit')) {
  136. $actions->append("<button class='btn btn-primary btn-xs jobaudit' data-code=".$actions->row['id'].">处理</button>");
  137. }
  138. });
  139. if (Admin::user()->can('content_feedback_delete')) {
  140. $grid->tools(function ($tools) {
  141. $tools->batch(function ($batch) {
  142. $batch->disableDelete(false);
  143. });
  144. });
  145. }
  146. if (!Admin::user()->can('content_feedback_audit') && !Admin::user()->can('content_feedback_delete')) {
  147. $grid->disableRowSelector();
  148. }
  149. $grid->filter(function (Filter $filter) {
  150. $filter->disableIdFilter();
  151. $filter->column(2/3, function ($filter) {
  152. /*if (get_subsite_id() == 0) {
  153. $subsites = Subsite::where(array('effective'=>1))->orderBy('order', 'asc')->get()->pluck('sitename', 'id')->toArray();
  154. if ($subsites) {
  155. $subsites = array('' => '不限', '0' => '总站') + $subsites;
  156. $filter->equal('subsite_id', '所属分站')->radio($subsites);
  157. }
  158. }*/
  159. $subsites = Subsite::where(array('effective'=>1))->orderBy('order', 'asc')->get()->pluck('sitename', 'id')->toArray();
  160. if ($subsites) {
  161. $subsites = array('' => '不限', '0' => '总站') + $subsites;
  162. $filter->equal('subsite_id', '所属分站')->select($subsites);
  163. }
  164. $cate_option = array(''=>'不限','1'=>'建议', '2' => '意见', '3' => '求助', '4' => '投诉');
  165. $filter->equal('type', '所属分类')->radio($cate_option)->default('');
  166. $where['audit'] = 0;
  167. if (get_subsite_id() > 0) {
  168. $where['subsite_id'] = get_subsite_id();
  169. }
  170. $nums = Feedback::where($where)->get()->count();
  171. $num_html ='';
  172. if ($nums>0) {
  173. $num_html = '('.$nums.')';
  174. }
  175. $status_option = array('0'=>'未处理'.$num_html,'1'=>'已处理');
  176. $status_option = array(''=>'不限')+$status_option;
  177. $filter->equal('audit', '处理状态')->radio($status_option);
  178. $date3 = date('Y-m-d', strtotime("-3 day"));
  179. $date7 = date('Y-m-d', strtotime("-7 day"));
  180. $date30 = date("Y-m-d", strtotime("-1 month"));
  181. $date180 = date("Y-m-d", strtotime("-6 month"));
  182. $date360 = date("Y-m-d", strtotime("-1 year"));
  183. $date_option = array(
  184. '' => '不限',
  185. $date3 => '三天内',
  186. $date7 => '一周内',
  187. $date30 => '一月内',
  188. $date180 => '半年内',
  189. $date360 => '一年内',
  190. );
  191. $filter->where(function ($query) {
  192. $query->where('created_at', '>=', "{$this->input}");
  193. }, '添加时间', 'created_at')->radio($date_option);
  194. });
  195. });
  196. //审核功能
  197. if (Admin::user()->can('content_feedback_audit')) {
  198. $grid->tools(function ($tools) {
  199. $form = new \Encore\Admin\Widgets\Form();
  200. $form->action(route('feedback.audit'));
  201. $audit_option = array('0'=>'未处理','1'=>'已处理');
  202. $form->radio('audit', '将所选意见建议设置为:')->options($audit_option)->default(1)->setWidth(8, 4);
  203. $form->json('val');
  204. $config = array('title'=>'处理意见建议','button'=>'处理','dialog_cancel' => "取消", 'dialog_ok' => "确认", 'is_batch' => true);
  205. $tools->append(new DialogTool($form, $config));
  206. });
  207. }
  208. return $grid;
  209. }
  210. public function audit(Request $request)
  211. {
  212. $rst = $request->validate(['audit'=>'required'], array('audit.required'=>'请选择处理状态'));
  213. $ids = $request->input('ids');
  214. if (empty($ids)) {
  215. if($request->type){
  216. admin_toastr('请选择需要处理的数据', 'error');
  217. return back();
  218. }else{
  219. return admin_toastr('请选择需要处理的数据', 'error');
  220. }
  221. }
  222. $id_arr = explode(',', $ids);
  223. $update_data = array(
  224. 'audit' => $request->input('audit'),
  225. 'updated_at' =>date('Y-m-d H:i:s', time())
  226. );
  227. if (Feedback::whereIn('id', $id_arr)->update($update_data) === false) {
  228. if($request->type){
  229. admin_toastr('处理失败', 'error');
  230. return back();
  231. }else{
  232. return admin_toastr('处理失败', 'error');
  233. }
  234. } else {
  235. //添加审核日志
  236. $reason_data = array('ids'=>$id_arr,'status'=>$request->input('audit'),'type'=>'5');
  237. if ($request->input('audit')=='1') {
  238. $reason_data['reason'] = '将所选意见建议设置为已处理';
  239. } else {
  240. $reason_data['reason'] = '将所选意见建议设置为未处理';
  241. }
  242. AuditReason::addData($reason_data);
  243. if($request->type){
  244. admin_toastr('处理成功', 'success');
  245. return back();
  246. }else{
  247. return admin_toastr('处理成功', 'success');
  248. }
  249. }
  250. }
  251. /**
  252. * Make a show builder.
  253. *
  254. * @param mixed $id
  255. * @return Show
  256. */
  257. protected function detail($id)
  258. {
  259. $show = new Show(Feedback::findOrFail($id));
  260. $show->id('ID');
  261. $show->type('类型');
  262. $show->content('内容');
  263. $show->contact('联系方式');
  264. $show->audit('处理状态')->as(function ($audit) {
  265. if ($audit) {
  266. return '已处理';
  267. }
  268. return '未处理';
  269. });
  270. if(get_subsite_open()){
  271. $show->subsite_id('所属分站')->as(function ($subsite_id) {
  272. if ($subsite_id) {
  273. $Subsite = Subsite::findOrFail($subsite_id);
  274. return $Subsite->sitename;
  275. }
  276. return '总站';
  277. });
  278. }
  279. $show->created_at('添加时间');
  280. $show->updated_at('处理时间');
  281. $show->panel()->tools(function ($tools) {
  282. $tools->disableEdit();
  283. $tools->disableDelete();
  284. });
  285. return $show;
  286. }
  287. /**
  288. * Make a form builder.
  289. *
  290. * @return Form
  291. */
  292. protected function form()
  293. {
  294. $form = new Form(new Feedback);
  295. $form->display('ID');
  296. $form->display('Created at');
  297. $form->display('Updated at');
  298. return $form;
  299. }
  300. }