123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292 |
- <?php
- namespace App\Admin\Controllers\Content;
- use App\Models\Category;
- use App\Models\Innovator;
- use App\Http\Controllers\Controller;
- use App\Models\InnovatorCategory;
- use Encore\Admin\Controllers\HasResourceActions;
- use Encore\Admin\Form;
- use Encore\Admin\Grid;
- use Encore\Admin\Layout\Content;
- use Encore\Admin\Show;
- use Illuminate\Http\Request;
- use Illuminate\Support\Facades\Input;
- class innovatorController extends Controller
- {
- use HasResourceActions;
- /**
- * Index interface.
- *
- * @param Content $content
- * @return Content
- */
- public function index(Content $content,Request $request)
- {
- return $content
- ->header('创业帮手')
- ->description(' ')
- ->body(view('admin.content.photo')->with(['grid'=>$this->grid($request)]));
- }
- /**
- * Show interface.
- *
- * @param mixed $id
- * @param Content $content
- * @return Content
- */
- public function show($id, Content $content)
- {
- return $content
- ->header('创业帮手')
- ->description(' ')
- ->body($this->detail($id));
- }
- /**
- * Edit interface.
- *
- * @param mixed $id
- * @param Content $content
- * @return Content
- */
- public function edit($id, Content $content)
- {
- return $content
- ->header('创业帮手')
- ->description(' ')
- ->body($this->editForm($id)->edit($id));
- }
- public function update($id)
- {
- return $this->editForm($id)->update($id);
- }
- /**
- * Create interface.
- *
- * @param Content $content
- * @return Content
- */
- public function create(Content $content)
- {
- return $content
- ->header('创业帮手')
- ->description(' ')
- ->body($this->form());
- }
- /**
- * Make a grid builder.
- *
- * @return Grid
- */
- protected function grid()
- {
- $grid = new Grid(new Innovator);
- $grid->model()->orderBy('display_order', 'DESC')->orderBy('created_at', 'DESC');
- $grid->id('ID');
- $grid->column('photo_img', '姓名')->display(function ($images) {
- $pbstr='';
- if($this->is_display==0){
- $pbstr= '<span style="color:#999999"> [已屏蔽]</span>';
- }
- $params = '?type_id='.$this->type_id;
- $title_url = url(admin_base_path().'/content/innovator'.$params);
- $title_url1 = url('content/innovators/show?id='.$this->id);
- if ($images) {
- return '<span class="vtip" title="<img src='.upload_asset($images).' width=120 height=120>">
- <img class="avatar small" src="'.upload_asset($images).'" align="absmiddle" style="width: 36px;height: 36px;">
- </span> '.'<a href='.$title_url.' style="color: #006699;">['.$this->type_name.']</a><a target="_blank" href='.$title_url1.'><span>'.$this->name.'</span></a>'.$pbstr;
- } else {
- return '<a href='.$title_url.' style="color: #006699;">['.$this->type_name.']</a><span class="vtip" ></span> '. '<a target="_blank" href='.$title_url1.'><span >'.$this->name.'</span></a>'.$pbstr;
- }
- })->width(200);
- $grid->column('trade_cn', '所属行业');
- $grid->column('duty_name', '职务名称');
- $grid->display_order('排序');
- $grid->created_at('添加日期');
- $grid->disableCreateButton(false);
- $grid->actions(function ($actions) {
- $actions->disableEdit(false);
- $actions->disableDelete(false);
- });
- $grid->tools(function ($tools) {
- $tools->batch(function ($batch) {
- $batch->disableDelete(false);
- });
- });
- $grid->filter(function ($filter) {
- $filter->equal('id', 'ID');
- $filter->like('name', '名称');
- $innovatorcategory = InnovatorCategory::where(['parentid'=>0])->orderBy("id", 'asc')->get()->pluck('categoryname', 'id');
- $filter->where(function ($query) {
- $query->where('type_id', '=', "{$this->input}");
- }, '创业分类', 'type_id')->select($innovatorcategory);
- $date3 = date('Y-m-d', strtotime("-3 day"));
- $date7 = date('Y-m-d', strtotime("-7 day"));
- $date30 = date("Y-m-d", strtotime("-1 month"));
- $date180 = date("Y-m-d", strtotime("-6 month"));
- $date360 = date("Y-m-d", strtotime("-1 year"));
- $date_option = array(
- '' => '不限',
- $date3 => '三天内',
- $date7 => '一周内',
- $date30 => '一月内',
- $date180 => '半年内',
- $date360 => '一年内',
- );
- $filter->where(function ($query) {
- $query->where('created_at', '>=', "{$this->input}");
- }, '添加时间', 'created_at')->radio($date_option);
- });
- return $grid;
- }
- /**
- * Make a show builder.
- *
- * @param mixed $id
- * @return Show
- */
- protected function detail($id)
- {
- $show = new Show(Innovator::findOrFail($id));
- $show->id('ID');
- $show->created_at('Created at');
- $show->updated_at('Updated at');
- return $show;
- }
- /**
- * Make a form builder.
- *
- * @return Form
- */
- protected function form()
- {
- $form = new Form(new Innovator);
- $form->text('name', '姓名')->rules('required|max:100', array('required'=>'姓名不能为空。','max'=>'姓名长度不能大于100。'))->setWidth(6)->setMustMark();
- $form->image('photo_img', '头像')->help('(建议尺寸240*70)')->setWidth(6);
- $form->select('type_id', '所属分类')->options(InnovatorCategory::select()->pluck('categoryname', 'id'))->rules('required', array('required'=>'请选择所属分类'))->setWidth(6)->setMustMark();
- $form->text('duty_name', '职务名称')->rules('required|max:100', array('required'=>'职务名称不能为空。','max'=>'职务名称长度不能大于100。'))->setWidth(6)->setMustMark();
- $form->select('trade_id', '所属行业')->options(Category::categoryType('AIX_trade'))->setWidth(6)->rules('required', ['required'=>'请选择相应的所属行业'])->setMustMark();
- $form->text('points', '特长')->rules('required|max:100', array('required'=>'特长不能为空。','max'=>'特长长度不能大于100。'))->setWidth(6)->setMustMark();
- $form->text('company_name', '单位名称')->rules('required|max:100', array('required'=>'单位名称不能为空。','max'=>'单位名称长度不能大于100。'))->setWidth(6)->setMustMark();
- $form->mobile('mobile', '联系方式')->setWidth(6);
- $form->radio('mobile_display', '联系方式对外公开')->options([0=>'不公开', 1=>'公开' ])->default('1');
- $form->text('email', '联系邮箱')->setWidth(6);
- $form->radio('email_display', '邮箱对外公开')->options([0=>'不公开', 1=>'公开' ])->default('1');
- $form->editor('content', '业绩介绍')->rules('required', array('required'=>'业绩介绍不能为空。'))->setWidth(6)->setMustMark();
- $display_option = [
- 'on' => ['value' => 1, 'text' => '是', 'color' => 'success'],
- 'off' => ['value' => 0, 'text' => '否', 'color' => 'danger'],
- ];
- $form->switch('is_display', '是否显示')->default(1)->states($display_option)->setMustMark();
- // $form->date('created_at', '发布日期')->format('YYYY-MM-DD')->rules('required|date', array('required'=>'发布日期不能为空。', 'date'=>'发布日期格式不正确。'));
- $form->number('display_order', '新闻排序')->min(0)->default(255)->rules('required', array('required'=>'新闻排序不能为空。'))->help('(数字越大越靠前)');
- $form->url('is_url', '外部链接')->rules('max:250', array('max'=>'外部链接长度不能超过250。'))->help('(请输入包含http://或https://的完整链接)');
- $form->text('keywords', 'Keywords')->placeholder('合理设置Keywords有利于搜索引擎排名')->rules('max:80', array('max:Keywords不能大于80个字符。'));
- $form->textarea('description', 'Description')->placeholder('合理设置Description有利于搜索引擎排名')->rules('max:80', array('max'=>'Description不能大于80个字符。'));
- $form->hidden('addtime');//添加时间
- $form->hidden('parentid')->value(0);//设置为0
- $form->hidden('trade_cn');//所属行业名称
- $form->hidden('type_name');//所属分类名称
- $form->saving(function (Form $form){
- //设置添加时间
- $form->addtime=time();
- $type_id= Input::get('type_id');
- $InnovatorCategory= InnovatorCategory::where(['id'=>$type_id])->first();
- $form->type_name=$InnovatorCategory->categoryname;
- $trade_id= Input::get('trade_id');
- $form->trade_cn=get_category($trade_id);
- });
- return $form;
- }
- protected function editForm($id)
- {
- $form = new Form(new Innovator);
- $form->text('name', '姓名')->rules('required|max:100', array('required'=>'姓名不能为空。','max'=>'姓名长度不能大于100。'))->setWidth(6)->setMustMark();
- $form->image('photo_img', '头像')->help('(建议尺寸240*70)')->setWidth(6);
- $form->select('type_id', '所属分类')->options(InnovatorCategory::select()->pluck('categoryname', 'id'))->rules('required', array('required'=>'请选择所属分类'))->setWidth(6)->setMustMark();
- $form->text('duty_name', '职务名称')->rules('required|max:100', array('required'=>'职务名称不能为空。','max'=>'职务名称长度不能大于100。'))->setWidth(6)->setMustMark();
- $form->select('trade_id', '所属行业')->options(Category::categoryType('AIX_trade'))->setWidth(6)->rules('required', ['required'=>'请选择相应的所属行业'])->setMustMark();
- $form->text('points', '特长')->rules('required|max:100', array('required'=>'特长不能为空。','max'=>'特长长度不能大于100。'))->setWidth(6)->setMustMark();
- $form->text('company_name', '单位名称')->rules('required|max:100', array('required'=>'单位名称不能为空。','max'=>'单位名称长度不能大于100。'))->setWidth(6)->setMustMark();
- $form->mobile('mobile', '联系方式')->setWidth(6);
- $form->radio('mobile_display', '联系方式对外公开')->options([0=>'不公开', 1=>'公开' ])->default('1');
- $form->text('email', '联系邮箱')->setWidth(6);
- $form->radio('email_display', '邮箱对外公开')->options([0=>'不公开', 1=>'公开' ])->default('1');
- $form->editor('content', '业绩介绍')->rules('required', array('required'=>'业绩介绍不能为空。'))->setWidth(6)->setMustMark();
- $display_option = [
- 'on' => ['value' => 1, 'text' => '是', 'color' => 'success'],
- 'off' => ['value' => 0, 'text' => '否', 'color' => 'danger'],
- ];
- $form->switch('is_display', '是否显示')->states($display_option)->setMustMark();
- // $form->date('created_at', '发布日期')->format('YYYY-MM-DD')->rules('required|date', array('required'=>'发布日期不能为空。', 'date'=>'发布日期格式不正确。'));
- $form->number('display_order', '新闻排序')->min(0)->default(0)->rules('required', array('required'=>'新闻排序不能为空。'))->help('(数字越大越靠前)');
- $form->url('is_url', '外部链接')->rules('max:250', array('max'=>'外部链接长度不能超过250。'))->help('(请输入包含http://或https://的完整链接)');
- $form->text('keywords', 'Keywords')->placeholder('合理设置Keywords有利于搜索引擎排名')->rules('max:80', array('max:Keywords不能大于80个字符。'));
- $form->textarea('description', 'Description')->placeholder('合理设置Description有利于搜索引擎排名')->rules('max:80', array('max'=>'Description不能大于80个字符。'));
- $form->hidden('addtime');//添加时间
- $form->hidden('parentid')->value(0);//设置为0
- $form->hidden('trade_cn');//所属行业名称
- $form->hidden('type_name');//所属分类名称
- $form->saving(function (Form $form){
- $type_id= Input::get('type_id');
- $InnovatorCategory= InnovatorCategory::where(['id'=>$type_id])->first();
- $form->type_name=$InnovatorCategory->categoryname;
- $trade_id= Input::get('trade_id');
- $form->trade_cn=get_category($trade_id);
- });
- return $form;
- }
- public function destroy($id)
- {
- $ids = array();
- if ($id) {
- $ids = explode(',', $id);
- }
- if (!$ids) {
- return admin_toastr('请勾选需要删除的创业帮手', 'error');
- }
- \DB::beginTransaction();
- try {
- Innovator::whereIn('id', $ids)->delete();
- $data = [
- 'status' => true,
- 'message' => '删除成功!',
- ];
- \DB::commit();
- return response()->json($data);
- } catch (\Exception $e) {
- \DB::rollback();
- $data = [
- 'status' => false,
- 'message' => '删除失败!',
- ];
- return response()->json($data);
- }
- }
- }
|