123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209 |
- <?php
- namespace App\Admin\Controllers\Presentation;
- use App\Admin\Extensions\Form\ValidateForm;
- use App\Http\Controllers\Controller;
- use App\Models\ArticleCategory;
- use App\Models\Presentation;
- use App\Models\PresentationAppoint;
- use Encore\Admin\Auth\Permission;
- use Encore\Admin\Form;
- use Encore\Admin\Grid;
- use Encore\Admin\Layout\Content;
- use Encore\Admin\Facades\Admin;
- use Illuminate\Http\Request;
- use Illuminate\Support\Facades\DB;
- class IndexController extends Controller
- {
- /**
- * 宣讲会管理
- * @param Content $content
- * @return Content
- */
- public function index(Content $content)
- {
- return $content
- ->header('宣讲会管理')
- ->description('')
- ->body($this->grid());
- }
- protected function grid()
- {
- $grid = new Grid(new Presentation);
- $grid->model()->orderBy('created_at', 'DESC');
- $grid->model()->paginate(20);
- if (Admin::user()->can('recruit_manager_create')) {
- $grid->disableCreateButton(false);
- }
- $grid->perPages([10, 20, 30, 40, 50, 100]);
- $grid->id('ID');
- $grid->name('名称');
- $grid->time('时间');
- $grid->address('地址');
- $grid->contact_info('联系方式');
- $grid->column('status','状态')->display(function ($status) {
- return $status ? '显示' : '隐藏';
- });
- $grid->created_at('创建时间');
- $grid->actions(function ($actions) {
- $actions->append('<a href="/ST3IXxKlOa4eGEv0eTw0CfORI9444Mgj/presentation/appoint_list?id=' . $actions->row['id'] . '" class="btn btn-primary btn-xs" >报名管理</a>');
- $actions->disableEdit(false);
- $actions->disableDelete(false);
- $actions->disableView();
- });
- return $grid;
- }
- public function create(Content $content)
- {
- return $content
- ->header('宣讲会创建')
- ->description('带*号必填项')
- ->body($this->form());
- }
- public function edit($id, Content $content)
- {
- return $content
- ->header('宣讲会编辑')
- ->description('')
- ->body($this->editForm($id)->edit($id));
- }
- protected function editForm($id){
- $info = Presentation::find($id);
- $form = new ValidateForm(new Presentation);
- $form->text('name', '宣讲会标题')->rules('required|max:100', array('required'=>'标题不能为空。','max'=>'标题长度不能大于100。'))->setMustMark();
- $form->text('time', '宣讲时间段')->rules('required', array('required'=>'时间段不能为空。'))->setMustMark();
- $form->text('address', '宣讲会地址')->rules('required', array('required'=>'宣讲会地址不能为空。'))->setMustMark();
- $form->text('contact_info', '联系方式')->rules('required', array('required'=>'联系方式不能为空。'))->setMustMark();
- $display_option = [
- 'on' => ['value' => 1, 'text' => '是', 'color' => 'success'],
- 'off' => ['value' => 0, 'text' => '否', 'color' => 'danger'],
- ];
- $form->switch('status', '是否显示')->states($display_option)->default('1')->setMustMark();
- return $form;
- }
- protected function form()
- {
- $form = new ValidateForm(new Presentation);
- $form->text('name', '宣讲会标题')->rules('required|max:100', array('required'=>'标题不能为空。','max'=>'标题长度不能大于100。'))->setMustMark();
- $form->text('time', '宣讲时间段')->rules('required', array('required'=>'时间段不能为空。'))->setMustMark();
- $form->text('address', '宣讲会地址')->rules('required', array('required'=>'宣讲会地址不能为空。'))->setMustMark();
- $form->text('contact_info', '联系方式')->rules('required', array('required'=>'联系方式不能为空。'))->setMustMark();
- $display_option = [
- 'on' => ['value' => 1, 'text' => '是', 'color' => 'success'],
- 'off' => ['value' => 0, 'text' => '否', 'color' => 'danger'],
- ];
- $form->switch('status', '是否显示')->states($display_option)->default('1')->setMustMark();
- return $form;
- }
- public function store(Request $request){
- $verify = $this->form()->getValidateInput();
- $data = [
- 'name' => $verify['name'],
- 'time' => $verify['time'],
- 'address' => $verify['address'],
- 'contact_info' => $verify['contact_info'],
- 'status' => $verify['status']
- ];
- try {
- Presentation::create($data);
- DB::commit();
- }catch (\Exception $e) {
- DB::rollback();
- return admin_toastr($e->getMessage(), 'error');
- }
- }
- public function update($id)
- {
- return $this->editForm($id)->update($id);
- }
- public function destroy($id)
- {
- if ($this->form()->destroy($id)) {
- $data = [
- 'status' => true,
- 'message' => trans('admin.delete_succeeded'),
- ];
- } else {
- $data = [
- 'status' => false,
- 'message' => trans('admin.delete_failed'),
- ];
- }
- return response()->json($data);
- }
- public function appointList(Content $content, Request $request)
- {
- Permission::check('presentation_appoint_list');
- $id = $request->id;
- $presentation = Presentation::find($id);
- if (empty($presentation)) {
- return back();
- }
- $search_data = $request->all();
- $where = [];
- $where[] = ['pid','=',$presentation->id];
- if (isset($search_data['id'])) {
- foreach ($search_data as $k => $v) {
- if ($k == 'realname') {
- $where[] = [$k, 'like', "%$v%"];
- } elseif ($k != '_pjax' and $k != 'page' && $k != 'perpage') {
- $where[] = [$k, '=', $v];
- }
- }
- }
- $perpage = 20;
- $list = PresentationAppoint::where($where)
- ->select('*')
- ->orderBy('updated_at','desc')
- ->paginate($perpage);
- foreach ($list as $k => $v){
- if($v->sex == 0){
- $list[$k]['sex'] = '女';
- }else{
- $list[$k]['sex'] = '男';
- }
- if($v->fresh == 0){
- $list[$k]['fresh'] = '否';
- }else{
- $list[$k]['fresh'] = '是';
- }
- if($v->status == 0){
- $list[$k]['status'] = '未下载';
- }else{
- $list[$k]['status'] = '已下载';
- }
- }
- return $content
- ->header('报名管理')
- ->description('人员信息列表')
- ->body(view('admin.presentation.appoint_list')->with([
- 'list' => $list,
- 'search_data' => $search_data,
- 'recruit' => $presentation
- ]));
- }
- }
|