innovatorController.php 13 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292
  1. <?php
  2. namespace App\Admin\Controllers\Content;
  3. use App\Models\Category;
  4. use App\Models\Innovator;
  5. use App\Http\Controllers\Controller;
  6. use App\Models\InnovatorCategory;
  7. use Encore\Admin\Controllers\HasResourceActions;
  8. use Encore\Admin\Form;
  9. use Encore\Admin\Grid;
  10. use Encore\Admin\Layout\Content;
  11. use Encore\Admin\Show;
  12. use Illuminate\Http\Request;
  13. use Illuminate\Support\Facades\Input;
  14. class innovatorController extends Controller
  15. {
  16. use HasResourceActions;
  17. /**
  18. * Index interface.
  19. *
  20. * @param Content $content
  21. * @return Content
  22. */
  23. public function index(Content $content,Request $request)
  24. {
  25. return $content
  26. ->header('创业帮手')
  27. ->description(' ')
  28. ->body(view('admin.content.photo')->with(['grid'=>$this->grid($request)]));
  29. }
  30. /**
  31. * Show interface.
  32. *
  33. * @param mixed $id
  34. * @param Content $content
  35. * @return Content
  36. */
  37. public function show($id, Content $content)
  38. {
  39. return $content
  40. ->header('创业帮手')
  41. ->description(' ')
  42. ->body($this->detail($id));
  43. }
  44. /**
  45. * Edit interface.
  46. *
  47. * @param mixed $id
  48. * @param Content $content
  49. * @return Content
  50. */
  51. public function edit($id, Content $content)
  52. {
  53. return $content
  54. ->header('创业帮手')
  55. ->description(' ')
  56. ->body($this->editForm($id)->edit($id));
  57. }
  58. public function update($id)
  59. {
  60. return $this->editForm($id)->update($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('创业帮手')
  72. ->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 Innovator);
  83. $grid->model()->orderBy('display_order', 'DESC')->orderBy('created_at', 'DESC');
  84. $grid->id('ID');
  85. $grid->column('photo_img', '姓名')->display(function ($images) {
  86. $pbstr='';
  87. if($this->is_display==0){
  88. $pbstr= '<span style="color:#999999">&nbsp;&nbsp;&nbsp;&nbsp;[已屏蔽]</span>';
  89. }
  90. $params = '?type_id='.$this->type_id;
  91. $title_url = url(admin_base_path().'/content/innovator'.$params);
  92. $title_url1 = url('content/innovators/show?id='.$this->id);
  93. if ($images) {
  94. return '<span class="vtip" title="<img src='.upload_asset($images).' width=120 height=120>">
  95. <img class="avatar small" src="'.upload_asset($images).'" align="absmiddle" style="width: 36px;height: 36px;">
  96. </span>&nbsp;&nbsp;&nbsp;'.'<a href='.$title_url.' style="color: #006699;">['.$this->type_name.']</a><a target="_blank" href='.$title_url1.'><span>'.$this->name.'</span></a>'.$pbstr;
  97. } else {
  98. return '<a href='.$title_url.' style="color: #006699;">['.$this->type_name.']</a><span class="vtip" ></span>&nbsp;&nbsp;&nbsp;'. '<a target="_blank" href='.$title_url1.'><span >'.$this->name.'</span></a>'.$pbstr;
  99. }
  100. })->width(200);
  101. $grid->column('trade_cn', '所属行业');
  102. $grid->column('duty_name', '职务名称');
  103. $grid->display_order('排序');
  104. $grid->created_at('添加日期');
  105. $grid->disableCreateButton(false);
  106. $grid->actions(function ($actions) {
  107. $actions->disableEdit(false);
  108. $actions->disableDelete(false);
  109. });
  110. $grid->tools(function ($tools) {
  111. $tools->batch(function ($batch) {
  112. $batch->disableDelete(false);
  113. });
  114. });
  115. $grid->filter(function ($filter) {
  116. $filter->equal('id', 'ID');
  117. $filter->like('name', '名称');
  118. $innovatorcategory = InnovatorCategory::where(['parentid'=>0])->orderBy("id", 'asc')->get()->pluck('categoryname', 'id');
  119. $filter->where(function ($query) {
  120. $query->where('type_id', '=', "{$this->input}");
  121. }, '创业分类', 'type_id')->select($innovatorcategory);
  122. $date3 = date('Y-m-d', strtotime("-3 day"));
  123. $date7 = date('Y-m-d', strtotime("-7 day"));
  124. $date30 = date("Y-m-d", strtotime("-1 month"));
  125. $date180 = date("Y-m-d", strtotime("-6 month"));
  126. $date360 = date("Y-m-d", strtotime("-1 year"));
  127. $date_option = array(
  128. '' => '不限',
  129. $date3 => '三天内',
  130. $date7 => '一周内',
  131. $date30 => '一月内',
  132. $date180 => '半年内',
  133. $date360 => '一年内',
  134. );
  135. $filter->where(function ($query) {
  136. $query->where('created_at', '>=', "{$this->input}");
  137. }, '添加时间', 'created_at')->radio($date_option);
  138. });
  139. return $grid;
  140. }
  141. /**
  142. * Make a show builder.
  143. *
  144. * @param mixed $id
  145. * @return Show
  146. */
  147. protected function detail($id)
  148. {
  149. $show = new Show(Innovator::findOrFail($id));
  150. $show->id('ID');
  151. $show->created_at('Created at');
  152. $show->updated_at('Updated at');
  153. return $show;
  154. }
  155. /**
  156. * Make a form builder.
  157. *
  158. * @return Form
  159. */
  160. protected function form()
  161. {
  162. $form = new Form(new Innovator);
  163. $form->text('name', '姓名')->rules('required|max:100', array('required'=>'姓名不能为空。','max'=>'姓名长度不能大于100。'))->setWidth(6)->setMustMark();
  164. $form->image('photo_img', '头像')->help('(建议尺寸240*70)')->setWidth(6);
  165. $form->select('type_id', '所属分类')->options(InnovatorCategory::select()->pluck('categoryname', 'id'))->rules('required', array('required'=>'请选择所属分类'))->setWidth(6)->setMustMark();
  166. $form->text('duty_name', '职务名称')->rules('required|max:100', array('required'=>'职务名称不能为空。','max'=>'职务名称长度不能大于100。'))->setWidth(6)->setMustMark();
  167. $form->select('trade_id', '所属行业')->options(Category::categoryType('AIX_trade'))->setWidth(6)->rules('required', ['required'=>'请选择相应的所属行业'])->setMustMark();
  168. $form->text('points', '特长')->rules('required|max:100', array('required'=>'特长不能为空。','max'=>'特长长度不能大于100。'))->setWidth(6)->setMustMark();
  169. $form->text('company_name', '单位名称')->rules('required|max:100', array('required'=>'单位名称不能为空。','max'=>'单位名称长度不能大于100。'))->setWidth(6)->setMustMark();
  170. $form->mobile('mobile', '联系方式')->setWidth(6);
  171. $form->radio('mobile_display', '联系方式对外公开')->options([0=>'不公开', 1=>'公开' ])->default('1');
  172. $form->text('email', '联系邮箱')->setWidth(6);
  173. $form->radio('email_display', '邮箱对外公开')->options([0=>'不公开', 1=>'公开' ])->default('1');
  174. $form->editor('content', '业绩介绍')->rules('required', array('required'=>'业绩介绍不能为空。'))->setWidth(6)->setMustMark();
  175. $display_option = [
  176. 'on' => ['value' => 1, 'text' => '是', 'color' => 'success'],
  177. 'off' => ['value' => 0, 'text' => '否', 'color' => 'danger'],
  178. ];
  179. $form->switch('is_display', '是否显示')->default(1)->states($display_option)->setMustMark();
  180. // $form->date('created_at', '发布日期')->format('YYYY-MM-DD')->rules('required|date', array('required'=>'发布日期不能为空。', 'date'=>'发布日期格式不正确。'));
  181. $form->number('display_order', '新闻排序')->min(0)->default(255)->rules('required', array('required'=>'新闻排序不能为空。'))->help('(数字越大越靠前)');
  182. $form->url('is_url', '外部链接')->rules('max:250', array('max'=>'外部链接长度不能超过250。'))->help('(请输入包含http://或https://的完整链接)');
  183. $form->text('keywords', 'Keywords')->placeholder('合理设置Keywords有利于搜索引擎排名')->rules('max:80', array('max:Keywords不能大于80个字符。'));
  184. $form->textarea('description', 'Description')->placeholder('合理设置Description有利于搜索引擎排名')->rules('max:80', array('max'=>'Description不能大于80个字符。'));
  185. $form->hidden('addtime');//添加时间
  186. $form->hidden('parentid')->value(0);//设置为0
  187. $form->hidden('trade_cn');//所属行业名称
  188. $form->hidden('type_name');//所属分类名称
  189. $form->saving(function (Form $form){
  190. //设置添加时间
  191. $form->addtime=time();
  192. $type_id= Input::get('type_id');
  193. $InnovatorCategory= InnovatorCategory::where(['id'=>$type_id])->first();
  194. $form->type_name=$InnovatorCategory->categoryname;
  195. $trade_id= Input::get('trade_id');
  196. $form->trade_cn=get_category($trade_id);
  197. });
  198. return $form;
  199. }
  200. protected function editForm($id)
  201. {
  202. $form = new Form(new Innovator);
  203. $form->text('name', '姓名')->rules('required|max:100', array('required'=>'姓名不能为空。','max'=>'姓名长度不能大于100。'))->setWidth(6)->setMustMark();
  204. $form->image('photo_img', '头像')->help('(建议尺寸240*70)')->setWidth(6);
  205. $form->select('type_id', '所属分类')->options(InnovatorCategory::select()->pluck('categoryname', 'id'))->rules('required', array('required'=>'请选择所属分类'))->setWidth(6)->setMustMark();
  206. $form->text('duty_name', '职务名称')->rules('required|max:100', array('required'=>'职务名称不能为空。','max'=>'职务名称长度不能大于100。'))->setWidth(6)->setMustMark();
  207. $form->select('trade_id', '所属行业')->options(Category::categoryType('AIX_trade'))->setWidth(6)->rules('required', ['required'=>'请选择相应的所属行业'])->setMustMark();
  208. $form->text('points', '特长')->rules('required|max:100', array('required'=>'特长不能为空。','max'=>'特长长度不能大于100。'))->setWidth(6)->setMustMark();
  209. $form->text('company_name', '单位名称')->rules('required|max:100', array('required'=>'单位名称不能为空。','max'=>'单位名称长度不能大于100。'))->setWidth(6)->setMustMark();
  210. $form->mobile('mobile', '联系方式')->setWidth(6);
  211. $form->radio('mobile_display', '联系方式对外公开')->options([0=>'不公开', 1=>'公开' ])->default('1');
  212. $form->text('email', '联系邮箱')->setWidth(6);
  213. $form->radio('email_display', '邮箱对外公开')->options([0=>'不公开', 1=>'公开' ])->default('1');
  214. $form->editor('content', '业绩介绍')->rules('required', array('required'=>'业绩介绍不能为空。'))->setWidth(6)->setMustMark();
  215. $display_option = [
  216. 'on' => ['value' => 1, 'text' => '是', 'color' => 'success'],
  217. 'off' => ['value' => 0, 'text' => '否', 'color' => 'danger'],
  218. ];
  219. $form->switch('is_display', '是否显示')->states($display_option)->setMustMark();
  220. // $form->date('created_at', '发布日期')->format('YYYY-MM-DD')->rules('required|date', array('required'=>'发布日期不能为空。', 'date'=>'发布日期格式不正确。'));
  221. $form->number('display_order', '新闻排序')->min(0)->default(0)->rules('required', array('required'=>'新闻排序不能为空。'))->help('(数字越大越靠前)');
  222. $form->url('is_url', '外部链接')->rules('max:250', array('max'=>'外部链接长度不能超过250。'))->help('(请输入包含http://或https://的完整链接)');
  223. $form->text('keywords', 'Keywords')->placeholder('合理设置Keywords有利于搜索引擎排名')->rules('max:80', array('max:Keywords不能大于80个字符。'));
  224. $form->textarea('description', 'Description')->placeholder('合理设置Description有利于搜索引擎排名')->rules('max:80', array('max'=>'Description不能大于80个字符。'));
  225. $form->hidden('addtime');//添加时间
  226. $form->hidden('parentid')->value(0);//设置为0
  227. $form->hidden('trade_cn');//所属行业名称
  228. $form->hidden('type_name');//所属分类名称
  229. $form->saving(function (Form $form){
  230. $type_id= Input::get('type_id');
  231. $InnovatorCategory= InnovatorCategory::where(['id'=>$type_id])->first();
  232. $form->type_name=$InnovatorCategory->categoryname;
  233. $trade_id= Input::get('trade_id');
  234. $form->trade_cn=get_category($trade_id);
  235. });
  236. return $form;
  237. }
  238. public function destroy($id)
  239. {
  240. $ids = array();
  241. if ($id) {
  242. $ids = explode(',', $id);
  243. }
  244. if (!$ids) {
  245. return admin_toastr('请勾选需要删除的创业帮手', 'error');
  246. }
  247. \DB::beginTransaction();
  248. try {
  249. Innovator::whereIn('id', $ids)->delete();
  250. $data = [
  251. 'status' => true,
  252. 'message' => '删除成功!',
  253. ];
  254. \DB::commit();
  255. return response()->json($data);
  256. } catch (\Exception $e) {
  257. \DB::rollback();
  258. $data = [
  259. 'status' => false,
  260. 'message' => '删除失败!',
  261. ];
  262. return response()->json($data);
  263. }
  264. }
  265. }