FeatureController.php 14 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345
  1. <?php
  2. namespace App\Admin\Controllers\Content;
  3. use App\Models\Category;
  4. use App\Models\CategoryDistrict;
  5. use App\Models\Feature;
  6. use App\Http\Controllers\Controller;
  7. use App\Models\FeatureSort;
  8. use Encore\Admin\Controllers\HasResourceActions;
  9. use Encore\Admin\Form;
  10. use Encore\Admin\Grid;
  11. use Encore\Admin\Layout\Content;
  12. use Encore\Admin\Show;
  13. use Illuminate\Http\Request;
  14. class FeatureController 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 Feature);
  83. $grid->id('ID');
  84. $grid->column('photo', '特色人才信息')->display(function ($images) {
  85. $pbstr='';
  86. if($this->is_display==0){
  87. $pbstr= '<span style="color:#039990">&nbsp;&nbsp;&nbsp;&nbsp;' .$this->name.'</span><span style="color:#999999">&nbsp;&nbsp;&nbsp;&nbsp;[已屏蔽]</span>';
  88. }else{
  89. $pbstr= '<span style="color:#039990">&nbsp;&nbsp;&nbsp;&nbsp;' .$this->name.'</span>';
  90. }
  91. $params = '?rc_show='.$this->rc_show;
  92. $title_url = url(admin_base_path().'/content/feature'.$params);
  93. $title_url1 = url('content/features/show?id='.$this->id);
  94. if ($images) {
  95. return '<span class="vtip" title="<img src='.upload_asset($images).' width=120 height=120>">
  96. <img class="avatar small" src="'.upload_asset($images).'" align="absmiddle" style="width: 36px;height: 36px;">
  97. </span>&nbsp;&nbsp;&nbsp;'. '<a href='.$title_url.' style="color: #b67647;">[' .get_category($this->rc_show).']</a><a target="_blank" href='.$title_url1.'><span>'.$this->title.'</span></a>'.$pbstr;
  98. } else {
  99. return '<a href='.$title_url.' style="color: #b67647;">['.get_category($this->rc_show).']</a><span class="vtip" ></span>&nbsp;&nbsp;&nbsp;'. '<a target="_blank" href='.$title_url1.'><span >'.$this->title.'</span></a>'.$pbstr;
  100. }
  101. })->width(300);
  102. $grid->district('所属地区')->display(function ($district) {
  103. if($district!=0 && $district!=''){
  104. return get_district_cn($district);
  105. }else{
  106. return '未作选择';
  107. }
  108. })->width(150);
  109. $grid->occupation('职位')->display(function ($occupation) {
  110. if($occupation!=''){
  111. return $occupation;
  112. }else{
  113. return '未评职称';
  114. }
  115. })->width(150);
  116. $grid->type_id('行业')->display(function ($type_id) {
  117. if($type_id!=0 && $type_id!=''){
  118. $category = \App\Models\FeatureSort::where('id', $type_id)->select(['categoryname'])->first();
  119. return $category?$category['categoryname']:null;
  120. }else{
  121. return '未选行业';
  122. }
  123. })->width(150);
  124. $grid->personal('人才类别')->display(function ($personal) {
  125. if($personal!=0 && $personal!=''){
  126. $category =get_category($personal);
  127. return $category?$category:null;
  128. }else{
  129. return '未作分类';
  130. }
  131. })->width(150);
  132. $grid->read('阅读');
  133. $grid->tools(function ($tools) {
  134. $tools->batch(function ($batch) {
  135. $batch->disableDelete(false);
  136. });
  137. });
  138. $grid->disableCreateButton(false);
  139. $grid->actions(function ($actions) {
  140. $actions->disableEdit(false);
  141. $actions->disableDelete(false);
  142. });
  143. $grid->filter(function ($filter) {
  144. $filter->equal('id', 'ID');
  145. $filter->like('title', '标题');
  146. $filter->like('name', '名称');
  147. $filter->equal('parentid', '行业分类')->select(FeatureSort::where('parent_id','0')->pluck('categoryname', 'id'));
  148. $filter->equal('rc_show', '人才展示')->select(Category::where('alias', 'RC_show')->pluck('demand', 'id'));
  149. $filter->equal('personal', '人才分类')->select(Category::where('alias', 'RC_category')->pluck('demand', 'id'));
  150. $filter->equal('district', '所属地区')->select(CategoryDistrict::where('parent_id', 623)->pluck('name', 'id'));
  151. });
  152. return $grid;
  153. }
  154. /**
  155. * Make a show builder.
  156. *
  157. * @param mixed $id
  158. * @return Show
  159. */
  160. protected function detail($id)
  161. {
  162. $show = new Show(Feature::findOrFail($id));
  163. $show->id('ID');
  164. $show->created_at('Created at');
  165. $show->updated_at('Updated at');
  166. return $show;
  167. }
  168. /**
  169. * Make a form builder.
  170. *
  171. * @return Form
  172. */
  173. protected function form()
  174. {
  175. $form = new Form(new Feature);
  176. $form->text('name', '姓名')->rules('required|max:100', array('required'=>'姓名不能为空。','max'=>'姓名长度不能大于100。'))->setWidth(6)->setMustMark();
  177. $form->text('occupation', '职称')->rules('required|max:200', array('required'=>'职称不能为空。','max'=>'职称长度不能大于100。'))->setWidth(6)->setMustMark();
  178. $form->text('title', '主题')->rules('required|max:300', array('required'=>'主题不能为空。','max'=>'主题长度不能大于300。'))->setWidth(6)->setMustMark();
  179. $district= CategoryDistrict::where('parent_id', 623)->pluck('name', 'id');
  180. $district['0'] = '请选择';
  181. $form->select('district', '所属乡镇')->options($district)->default('0')->setWidth(6);
  182. $trade= FeatureSort::select()->pluck('categoryname', 'id');
  183. $trade['0'] = '请选择';
  184. $form->select('type_id', '所属行业')->options($trade)->default('0')->setWidth(6);
  185. $personal= Category::where('alias', 'RC_category')->pluck('demand', 'id');
  186. $personal['0'] = '请选择';
  187. $form->select('personal', '所属五类人才')->options($personal)->default('0')->setWidth(6);
  188. $rc_show= Category::where('alias', 'RC_show')->pluck('demand', 'id');
  189. $rc_show['0'] = '请选择';
  190. $form->select('rc_show', '文章类型')->options($rc_show)->default('0')->setWidth(6);
  191. $form->image('photo', '人才照片')->help('(建议尺寸240*70)')->setWidth(6);
  192. $form->textarea('summary', '人物简介')->rules('max:80', array('max'=>'Description不能大于80个字符。'))->setWidth(6);
  193. $form->editor('content', '履历介绍')->rules('required', array('required'=>'业绩介绍不能为空。'))->setWidth(6)->setMustMark();
  194. $display_option = [
  195. 'on' => ['value' => 1, 'text' => '是', 'color' => 'success'],
  196. 'off' => ['value' => 0, 'text' => '否', 'color' => 'danger'],
  197. ];
  198. $form->switch('is_display', '是否显示')->default(1)->states($display_option)->setMustMark();
  199. // $form->date('created_at', '发布日期')->format('YYYY-MM-DD')->rules('required|date', array('required'=>'发布日期不能为空。', 'date'=>'发布日期格式不正确。'));
  200. $form->number('article_order', '排序')->min(0)->default(255)->rules('required', array('required'=>'排序不能为空。'))->help('(数字越大越靠前)');
  201. $form->url('is_url', '外部链接')->rules('max:250', array('max'=>'外部链接长度不能超过250。'))->help('(请输入包含http://或https://的完整链接)');
  202. $form->text('seo_keywords', 'Keywords')->placeholder('合理设置Keywords有利于搜索引擎排名')->rules('max:80', array('max:Keywords不能大于80个字符。'));
  203. $form->textarea('seo_description', 'Description')->placeholder('合理设置Description有利于搜索引擎排名')->rules('max:80', array('max'=>'Description不能大于80个字符。'));
  204. $form->hidden('addtime');//添加时间
  205. $form->hidden('parentid');//行业大类
  206. $form->saving(function (Form $form){
  207. //设置添加时间
  208. $form->addtime=time();
  209. if($form->type_id!=0){
  210. // 设置行业大类
  211. $featureSort= FeatureSort::where(['id'=>$form->type_id])->first();
  212. if($featureSort->parent_id==0){
  213. $form->parentid=$form->type_id;
  214. }else{
  215. $form->parentid=$featureSort->parent_id;
  216. }
  217. }else{
  218. $form->parentid=0;
  219. }
  220. });
  221. return $form;
  222. }
  223. protected function editForm($id)
  224. {
  225. $form = new Form(new Feature);
  226. $form->text('name', '姓名')->rules('required|max:100', array('required'=>'姓名不能为空。','max'=>'姓名长度不能大于100。'))->setWidth(6)->setMustMark();
  227. $form->text('occupation', '职称')->rules('required|max:200', array('required'=>'职称不能为空。','max'=>'职称长度不能大于100。'))->setWidth(6)->setMustMark();
  228. $form->text('title', '主题')->rules('required|max:300', array('required'=>'主题不能为空。','max'=>'主题长度不能大于300。'))->setWidth(6)->setMustMark();
  229. $district= CategoryDistrict::where('parent_id', 623)->pluck('name', 'id');
  230. $district['0'] = '请选择';
  231. $form->select('district', '所属乡镇')->options($district)->default('0')->setWidth(6);
  232. $trade= FeatureSort::select()->pluck('categoryname', 'id');
  233. $trade['0'] = '请选择';
  234. $form->select('type_id', '所属行业')->options($trade)->default('0')->setWidth(6);
  235. $personal= Category::where('alias', 'RC_category')->pluck('demand', 'id');
  236. $personal['0'] = '请选择';
  237. $form->select('personal', '所属五类人才')->options($personal)->default('0')->setWidth(6);
  238. $rc_show= Category::where('alias', 'RC_show')->pluck('demand', 'id');
  239. $rc_show['0'] = '请选择';
  240. $form->select('rc_show', '文章类型')->options($rc_show)->default('0')->setWidth(6);
  241. $form->image('photo', '人才照片')->help('(建议尺寸240*70)')->setWidth(6);
  242. $form->textarea('summary', '人物简介')->rules('max:80', array('max'=>'Description不能大于80个字符。'))->setWidth(6);
  243. $form->editor('content', '履历介绍')->rules('required', array('required'=>'业绩介绍不能为空。'))->setWidth(6)->setMustMark();
  244. $display_option = [
  245. 'on' => ['value' => 1, 'text' => '是', 'color' => 'success'],
  246. 'off' => ['value' => 0, 'text' => '否', 'color' => 'danger'],
  247. ];
  248. $form->switch('is_display', '是否显示')->states($display_option)->setMustMark();
  249. // $form->date('created_at', '发布日期')->format('YYYY-MM-DD')->rules('required|date', array('required'=>'发布日期不能为空。', 'date'=>'发布日期格式不正确。'));
  250. $form->number('article_order', '排序')->min(0)->default(0)->rules('required', array('required'=>'排序不能为空。'))->help('(数字越大越靠前)');
  251. $form->url('is_url', '外部链接')->rules('max:250', array('max'=>'外部链接长度不能超过250。'))->help('(请输入包含http://或https://的完整链接)');
  252. $form->text('seo_keywords', 'Keywords')->placeholder('合理设置Keywords有利于搜索引擎排名')->rules('max:80', array('max:Keywords不能大于80个字符。'));
  253. $form->textarea('seo_description', 'Description')->placeholder('合理设置Description有利于搜索引擎排名')->rules('max:80', array('max'=>'Description不能大于80个字符。'));
  254. $form->hidden('addtime');//添加时间
  255. $form->hidden('parentid');//行业大类
  256. $form->saving(function (Form $form){
  257. if($form->type_id!=0){
  258. // 设置行业大类
  259. $featureSort= FeatureSort::where(['id'=>$form->type_id])->first();
  260. if($featureSort->parent_id==0){
  261. $form->parentid=$form->type_id;
  262. }else{
  263. $form->parentid=$featureSort->parent_id;
  264. }
  265. }else{
  266. $form->parentid=0;
  267. }
  268. });
  269. return $form;
  270. }
  271. public function destroy($id)
  272. {
  273. $ids = array();
  274. if ($id) {
  275. $ids = explode(',', $id);
  276. }
  277. if (!$ids) {
  278. return admin_toastr('请勾选需要删除的人才展示', 'error');
  279. }
  280. \DB::beginTransaction();
  281. try {
  282. Feature::whereIn('id', $ids)->delete();
  283. $data = [
  284. 'status' => true,
  285. 'message' => '删除成功!',
  286. ];
  287. \DB::commit();
  288. return response()->json($data);
  289. } catch (\Exception $e) {
  290. \DB::rollback();
  291. $data = [
  292. 'status' => false,
  293. 'message' => '删除失败!',
  294. ];
  295. return response()->json($data);
  296. }
  297. }
  298. }