Indexcontroller.php 7.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209
  1. <?php
  2. namespace App\Admin\Controllers\Presentation;
  3. use App\Admin\Extensions\Form\ValidateForm;
  4. use App\Http\Controllers\Controller;
  5. use App\Models\ArticleCategory;
  6. use App\Models\Presentation;
  7. use App\Models\PresentationAppoint;
  8. use Encore\Admin\Auth\Permission;
  9. use Encore\Admin\Form;
  10. use Encore\Admin\Grid;
  11. use Encore\Admin\Layout\Content;
  12. use Encore\Admin\Facades\Admin;
  13. use Illuminate\Http\Request;
  14. use Illuminate\Support\Facades\DB;
  15. class IndexController extends Controller
  16. {
  17. /**
  18. * 宣讲会管理
  19. * @param Content $content
  20. * @return Content
  21. */
  22. public function index(Content $content)
  23. {
  24. return $content
  25. ->header('宣讲会管理')
  26. ->description('')
  27. ->body($this->grid());
  28. }
  29. protected function grid()
  30. {
  31. $grid = new Grid(new Presentation);
  32. $grid->model()->orderBy('created_at', 'DESC');
  33. $grid->model()->paginate(20);
  34. if (Admin::user()->can('recruit_manager_create')) {
  35. $grid->disableCreateButton(false);
  36. }
  37. $grid->perPages([10, 20, 30, 40, 50, 100]);
  38. $grid->id('ID');
  39. $grid->name('名称');
  40. $grid->time('时间');
  41. $grid->address('地址');
  42. $grid->contact_info('联系方式');
  43. $grid->column('status','状态')->display(function ($status) {
  44. return $status ? '显示' : '隐藏';
  45. });
  46. $grid->created_at('创建时间');
  47. $grid->actions(function ($actions) {
  48. $actions->append('<a href="/ST3IXxKlOa4eGEv0eTw0CfORI9444Mgj/presentation/appoint_list?id=' . $actions->row['id'] . '" class="btn btn-primary btn-xs" >报名管理</a>');
  49. $actions->disableEdit(false);
  50. $actions->disableDelete(false);
  51. $actions->disableView();
  52. });
  53. return $grid;
  54. }
  55. public function create(Content $content)
  56. {
  57. return $content
  58. ->header('宣讲会创建')
  59. ->description('带*号必填项')
  60. ->body($this->form());
  61. }
  62. public function edit($id, Content $content)
  63. {
  64. return $content
  65. ->header('宣讲会编辑')
  66. ->description('')
  67. ->body($this->editForm($id)->edit($id));
  68. }
  69. protected function editForm($id){
  70. $info = Presentation::find($id);
  71. $form = new ValidateForm(new Presentation);
  72. $form->text('name', '宣讲会标题')->rules('required|max:100', array('required'=>'标题不能为空。','max'=>'标题长度不能大于100。'))->setMustMark();
  73. $form->text('time', '宣讲时间段')->rules('required', array('required'=>'时间段不能为空。'))->setMustMark();
  74. $form->text('address', '宣讲会地址')->rules('required', array('required'=>'宣讲会地址不能为空。'))->setMustMark();
  75. $form->text('contact_info', '联系方式')->rules('required', array('required'=>'联系方式不能为空。'))->setMustMark();
  76. $display_option = [
  77. 'on' => ['value' => 1, 'text' => '是', 'color' => 'success'],
  78. 'off' => ['value' => 0, 'text' => '否', 'color' => 'danger'],
  79. ];
  80. $form->switch('status', '是否显示')->states($display_option)->default('1')->setMustMark();
  81. return $form;
  82. }
  83. protected function form()
  84. {
  85. $form = new ValidateForm(new Presentation);
  86. $form->text('name', '宣讲会标题')->rules('required|max:100', array('required'=>'标题不能为空。','max'=>'标题长度不能大于100。'))->setMustMark();
  87. $form->text('time', '宣讲时间段')->rules('required', array('required'=>'时间段不能为空。'))->setMustMark();
  88. $form->text('address', '宣讲会地址')->rules('required', array('required'=>'宣讲会地址不能为空。'))->setMustMark();
  89. $form->text('contact_info', '联系方式')->rules('required', array('required'=>'联系方式不能为空。'))->setMustMark();
  90. $display_option = [
  91. 'on' => ['value' => 1, 'text' => '是', 'color' => 'success'],
  92. 'off' => ['value' => 0, 'text' => '否', 'color' => 'danger'],
  93. ];
  94. $form->switch('status', '是否显示')->states($display_option)->default('1')->setMustMark();
  95. return $form;
  96. }
  97. public function store(Request $request){
  98. $verify = $this->form()->getValidateInput();
  99. $data = [
  100. 'name' => $verify['name'],
  101. 'time' => $verify['time'],
  102. 'address' => $verify['address'],
  103. 'contact_info' => $verify['contact_info'],
  104. 'status' => $verify['status']
  105. ];
  106. try {
  107. Presentation::create($data);
  108. DB::commit();
  109. }catch (\Exception $e) {
  110. DB::rollback();
  111. return admin_toastr($e->getMessage(), 'error');
  112. }
  113. }
  114. public function update($id)
  115. {
  116. return $this->editForm($id)->update($id);
  117. }
  118. public function destroy($id)
  119. {
  120. if ($this->form()->destroy($id)) {
  121. $data = [
  122. 'status' => true,
  123. 'message' => trans('admin.delete_succeeded'),
  124. ];
  125. } else {
  126. $data = [
  127. 'status' => false,
  128. 'message' => trans('admin.delete_failed'),
  129. ];
  130. }
  131. return response()->json($data);
  132. }
  133. public function appointList(Content $content, Request $request)
  134. {
  135. Permission::check('presentation_appoint_list');
  136. $id = $request->id;
  137. $presentation = Presentation::find($id);
  138. if (empty($presentation)) {
  139. return back();
  140. }
  141. $search_data = $request->all();
  142. $where = [];
  143. $where[] = ['pid','=',$presentation->id];
  144. if (isset($search_data['id'])) {
  145. foreach ($search_data as $k => $v) {
  146. if ($k == 'realname') {
  147. $where[] = [$k, 'like', "%$v%"];
  148. } elseif ($k != '_pjax' and $k != 'page' && $k != 'perpage') {
  149. $where[] = [$k, '=', $v];
  150. }
  151. }
  152. }
  153. $perpage = 20;
  154. $list = PresentationAppoint::where($where)
  155. ->select('*')
  156. ->orderBy('updated_at','desc')
  157. ->paginate($perpage);
  158. foreach ($list as $k => $v){
  159. if($v->sex == 0){
  160. $list[$k]['sex'] = '女';
  161. }else{
  162. $list[$k]['sex'] = '男';
  163. }
  164. if($v->fresh == 0){
  165. $list[$k]['fresh'] = '否';
  166. }else{
  167. $list[$k]['fresh'] = '是';
  168. }
  169. if($v->status == 0){
  170. $list[$k]['status'] = '未下载';
  171. }else{
  172. $list[$k]['status'] = '已下载';
  173. }
  174. }
  175. return $content
  176. ->header('报名管理')
  177. ->description('人员信息列表')
  178. ->body(view('admin.presentation.appoint_list')->with([
  179. 'list' => $list,
  180. 'search_data' => $search_data,
  181. 'recruit' => $presentation
  182. ]));
  183. }
  184. }