FeedbackController.php 10 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301
  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('类型');
  90. $grid->audit('处理状态')->display(function () {
  91. $audit_html = '';
  92. if ($this->audit) {
  93. $audit_html = '已处理';
  94. } else {
  95. $audit_html = '<span style="color:#ff0000;">未处理</span>';
  96. }
  97. return $audit_html;
  98. });
  99. $grid->content('内容')->display(function () {
  100. return '<span class="vtip" title="'.$this->content.'">'.cut_str($this->content, 40, 0, "...").'</span>';
  101. })->width(400);
  102. $grid->contact('联系方式');
  103. if(get_subsite_open()){
  104. $grid->subsite_id('所属分站')->display(function () {
  105. $subsites = Cache::get('subsites_list');
  106. if (array_has($subsites, $this->subsite_id)) {
  107. return $subsites[$this->subsite_id]['sitename'];
  108. }
  109. return '';
  110. });
  111. }
  112. $grid->created_at('添加时间');
  113. /*$grid->tools(function (Grid\Tools $tools) {
  114. $tools->disableRefreshButton();
  115. });*/
  116. $grid->actions(function ($actions) {
  117. if (Admin::user()->can('content_appeal_audit')) {
  118. $actions->append("<button class='btn btn-primary btn-xs jobaudit' data-code=".$actions->row['id'].">处理</button>");
  119. }
  120. });
  121. if (Admin::user()->can('content_feedback_delete')) {
  122. $grid->tools(function ($tools) {
  123. $tools->batch(function ($batch) {
  124. $batch->disableDelete(false);
  125. });
  126. });
  127. }
  128. if (!Admin::user()->can('content_feedback_audit') && !Admin::user()->can('content_feedback_delete')) {
  129. $grid->disableRowSelector();
  130. }
  131. $grid->filter(function (Filter $filter) {
  132. $filter->disableIdFilter();
  133. $filter->column(2/3, function ($filter) {
  134. /*if (get_subsite_id() == 0) {
  135. $subsites = Subsite::where(array('effective'=>1))->orderBy('order', 'asc')->get()->pluck('sitename', 'id')->toArray();
  136. if ($subsites) {
  137. $subsites = array('' => '不限', '0' => '总站') + $subsites;
  138. $filter->equal('subsite_id', '所属分站')->radio($subsites);
  139. }
  140. }*/
  141. $subsites = Subsite::where(array('effective'=>1))->orderBy('order', 'asc')->get()->pluck('sitename', 'id')->toArray();
  142. if ($subsites) {
  143. $subsites = array('' => '不限', '0' => '总站') + $subsites;
  144. $filter->equal('subsite_id', '所属分站')->select($subsites);
  145. }
  146. $cate_option = array(''=>'不限','1'=>'建议', '2' => '意见', '3' => '求助', '4' => '投诉');
  147. $filter->equal('type', '所属分类')->radio($cate_option)->default('');
  148. $where['audit'] = 0;
  149. if (get_subsite_id() > 0) {
  150. $where['subsite_id'] = get_subsite_id();
  151. }
  152. $nums = Feedback::where($where)->get()->count();
  153. $num_html ='';
  154. if ($nums>0) {
  155. $num_html = '('.$nums.')';
  156. }
  157. $status_option = array('0'=>'未处理'.$num_html,'1'=>'已处理');
  158. $status_option = array(''=>'不限')+$status_option;
  159. $filter->equal('audit', '处理状态')->radio($status_option);
  160. $date3 = date('Y-m-d', strtotime("-3 day"));
  161. $date7 = date('Y-m-d', strtotime("-7 day"));
  162. $date30 = date("Y-m-d", strtotime("-1 month"));
  163. $date180 = date("Y-m-d", strtotime("-6 month"));
  164. $date360 = date("Y-m-d", strtotime("-1 year"));
  165. $date_option = array(
  166. '' => '不限',
  167. $date3 => '三天内',
  168. $date7 => '一周内',
  169. $date30 => '一月内',
  170. $date180 => '半年内',
  171. $date360 => '一年内',
  172. );
  173. $filter->where(function ($query) {
  174. $query->where('created_at', '>=', "{$this->input}");
  175. }, '添加时间', 'created_at')->radio($date_option);
  176. });
  177. });
  178. //审核功能
  179. if (Admin::user()->can('content_feedback_audit')) {
  180. $grid->tools(function ($tools) {
  181. $form = new \Encore\Admin\Widgets\Form();
  182. $form->action(route('feedback.audit'));
  183. $audit_option = array('0'=>'未处理','1'=>'已处理');
  184. $form->radio('audit', '将所选意见建议设置为:')->options($audit_option)->default(1)->setWidth(8, 4);
  185. $form->json('val');
  186. $config = array('title'=>'处理意见建议','button'=>'处理','dialog_cancel' => "取消", 'dialog_ok' => "确认", 'is_batch' => true);
  187. $tools->append(new DialogTool($form, $config));
  188. });
  189. }
  190. return $grid;
  191. }
  192. public function audit(Request $request)
  193. {
  194. $rst = $request->validate(['audit'=>'required'], array('audit.required'=>'请选择处理状态'));
  195. $ids = $request->input('ids');
  196. if (empty($ids)) {
  197. if($request->type){
  198. admin_toastr('请选择需要处理的数据', 'error');
  199. return back();
  200. }else{
  201. return admin_toastr('请选择需要处理的数据', 'error');
  202. }
  203. }
  204. $id_arr = explode(',', $ids);
  205. $update_data = array(
  206. 'audit' => $request->input('audit'),
  207. 'updated_at' =>date('Y-m-d H:i:s', time())
  208. );
  209. if (Feedback::whereIn('id', $id_arr)->update($update_data) === false) {
  210. if($request->type){
  211. admin_toastr('处理失败', 'error');
  212. return back();
  213. }else{
  214. return admin_toastr('处理失败', 'error');
  215. }
  216. } else {
  217. //添加审核日志
  218. $reason_data = array('ids'=>$id_arr,'status'=>$request->input('audit'),'type'=>'5');
  219. if ($request->input('audit')=='1') {
  220. $reason_data['reason'] = '将所选意见建议设置为已处理';
  221. } else {
  222. $reason_data['reason'] = '将所选意见建议设置为未处理';
  223. }
  224. AuditReason::addData($reason_data);
  225. if($request->type){
  226. admin_toastr('处理成功', 'success');
  227. return back();
  228. }else{
  229. return admin_toastr('处理成功', 'success');
  230. }
  231. }
  232. }
  233. /**
  234. * Make a show builder.
  235. *
  236. * @param mixed $id
  237. * @return Show
  238. */
  239. protected function detail($id)
  240. {
  241. $show = new Show(Feedback::findOrFail($id));
  242. $show->id('ID');
  243. $show->type('类型');
  244. $show->content('内容');
  245. $show->contact('联系方式');
  246. $show->audit('处理状态')->as(function ($audit) {
  247. if ($audit) {
  248. return '已处理';
  249. }
  250. return '未处理';
  251. });
  252. if(get_subsite_open()){
  253. $show->subsite_id('所属分站')->as(function ($subsite_id) {
  254. if ($subsite_id) {
  255. $Subsite = Subsite::findOrFail($subsite_id);
  256. return $Subsite->sitename;
  257. }
  258. return '总站';
  259. });
  260. }
  261. $show->created_at('添加时间');
  262. $show->updated_at('处理时间');
  263. $show->panel()->tools(function ($tools) {
  264. $tools->disableEdit();
  265. $tools->disableDelete();
  266. });
  267. return $show;
  268. }
  269. /**
  270. * Make a form builder.
  271. *
  272. * @return Form
  273. */
  274. protected function form()
  275. {
  276. $form = new Form(new Feedback);
  277. $form->display('ID');
  278. $form->display('Created at');
  279. $form->display('Updated at');
  280. return $form;
  281. }
  282. }