IndexController.php 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345
  1. <?php
  2. namespace App\Admin\Controllers\Health;
  3. use App\Admin\Extensions\Form\ValidateForm;
  4. use App\Http\Controllers\Controller;
  5. use App\Models\ArticleCategory;
  6. use App\Models\PostAppoint;
  7. use App\Models\Presentation;
  8. use App\Models\PresentationAppoint;
  9. use Encore\Admin\Auth\Permission;
  10. use Encore\Admin\Form;
  11. use Encore\Admin\Grid;
  12. use Encore\Admin\Layout\Content;
  13. use Encore\Admin\Facades\Admin;
  14. use Illuminate\Http\Request;
  15. use Illuminate\Support\Facades\DB;
  16. use App\Models\QjwjAppoint;
  17. use App\Models\JyyxAppoint;
  18. class IndexController extends Controller
  19. {
  20. /**
  21. * 宣讲会管理
  22. * @param Content $content
  23. * @return Content
  24. */
  25. public function index(Content $content)
  26. {
  27. return $content
  28. ->header('宣讲会管理')
  29. ->description('')
  30. ->body($this->grid());
  31. }
  32. protected function grid()
  33. {
  34. $grid = new Grid(new Presentation);
  35. $grid->model()->orderBy('created_at', 'DESC');
  36. $grid->model()->paginate(20);
  37. if (Admin::user()->can('recruit_manager_create')) {
  38. $grid->disableCreateButton(false);
  39. }
  40. $grid->perPages([10, 20, 30, 40, 50, 100]);
  41. $grid->id('ID');
  42. $grid->name('名称');
  43. $grid->time('时间');
  44. $grid->address('地址');
  45. $grid->contact_info('联系方式');
  46. $grid->column('status','状态')->display(function ($status) {
  47. return $status ? '显示' : '隐藏';
  48. });
  49. $grid->created_at('创建时间');
  50. $grid->actions(function ($actions) {
  51. $actions->append('<a href="/ST3IXxKlOa4eGEv0eTw0CfORI9444Mgj/health/presentation_appoint_list?id=' . $actions->row['id'] . '" class="btn btn-primary btn-xs" >报名管理</a>');
  52. $actions->disableEdit(false);
  53. $actions->disableDelete(false);
  54. $actions->disableView();
  55. });
  56. return $grid;
  57. }
  58. public function create(Content $content)
  59. {
  60. return $content
  61. ->header('宣讲会创建')
  62. ->description('带*号必填项')
  63. ->body($this->form());
  64. }
  65. public function edit($id, Content $content)
  66. {
  67. return $content
  68. ->header('宣讲会编辑')
  69. ->description('')
  70. ->body($this->editForm($id)->edit($id));
  71. }
  72. protected function editForm($id){
  73. $info = Presentation::find($id);
  74. $form = new ValidateForm(new Presentation);
  75. $form->text('name', '宣讲会标题')->rules('required|max:100', array('required'=>'标题不能为空。','max'=>'标题长度不能大于100。'))->setMustMark();
  76. $form->text('time', '宣讲时间段')->rules('required', array('required'=>'时间段不能为空。'))->setMustMark();
  77. $form->text('address', '宣讲会地址')->rules('required', array('required'=>'宣讲会地址不能为空。'))->setMustMark();
  78. $form->text('contact_info', '联系方式')->rules('required', array('required'=>'联系方式不能为空。'))->setMustMark();
  79. $display_option = [
  80. 'on' => ['value' => 1, 'text' => '是', 'color' => 'success'],
  81. 'off' => ['value' => 0, 'text' => '否', 'color' => 'danger'],
  82. ];
  83. $form->switch('status', '是否显示')->states($display_option)->default('1')->setMustMark();
  84. return $form;
  85. }
  86. protected function form()
  87. {
  88. $form = new ValidateForm(new Presentation);
  89. $form->text('name', '宣讲会标题')->rules('required|max:100', array('required'=>'标题不能为空。','max'=>'标题长度不能大于100。'))->setMustMark();
  90. $form->text('time', '宣讲时间段')->rules('required', array('required'=>'时间段不能为空。'))->setMustMark();
  91. $form->text('address', '宣讲会地址')->rules('required', array('required'=>'宣讲会地址不能为空。'))->setMustMark();
  92. $form->text('contact_info', '联系方式')->rules('required', array('required'=>'联系方式不能为空。'))->setMustMark();
  93. $display_option = [
  94. 'on' => ['value' => 1, 'text' => '是', 'color' => 'success'],
  95. 'off' => ['value' => 0, 'text' => '否', 'color' => 'danger'],
  96. ];
  97. $form->switch('status', '是否显示')->states($display_option)->default('1')->setMustMark();
  98. return $form;
  99. }
  100. public function store(Request $request){
  101. $verify = $this->form()->getValidateInput();
  102. $data = [
  103. 'name' => $verify['name'],
  104. 'time' => $verify['time'],
  105. 'address' => $verify['address'],
  106. 'contact_info' => $verify['contact_info'],
  107. 'status' => $verify['status']
  108. ];
  109. try {
  110. Presentation::create($data);
  111. DB::commit();
  112. }catch (\Exception $e) {
  113. DB::rollback();
  114. return admin_toastr($e->getMessage(), 'error');
  115. }
  116. }
  117. public function update($id)
  118. {
  119. return $this->editForm($id)->update($id);
  120. }
  121. public function destroy($id)
  122. {
  123. if ($this->form()->destroy($id)) {
  124. $data = [
  125. 'status' => true,
  126. 'message' => trans('admin.delete_succeeded'),
  127. ];
  128. } else {
  129. $data = [
  130. 'status' => false,
  131. 'message' => trans('admin.delete_failed'),
  132. ];
  133. }
  134. return response()->json($data);
  135. }
  136. public function appointList(Content $content, Request $request)
  137. {
  138. Permission::check('presentation_appoint_list');
  139. $id = $request->id;
  140. $presentation = Presentation::find($id);
  141. if (empty($presentation)) {
  142. return back();
  143. }
  144. $search_data = $request->all();
  145. $where = [];
  146. $where[] = ['pid','=',$presentation->id];
  147. if (isset($search_data['id'])) {
  148. foreach ($search_data as $k => $v) {
  149. if ($k == 'realname') {
  150. $where[] = [$k, 'like', "%$v%"];
  151. } elseif ($k != '_pjax' and $k != 'page' && $k != 'perpage') {
  152. $where[] = [$k, '=', $v];
  153. }
  154. }
  155. }
  156. $perpage = 20;
  157. $list = PresentationAppoint::where($where)
  158. ->select('*')
  159. ->orderBy('updated_at','desc')
  160. ->paginate($perpage);
  161. foreach ($list as $k => $v){
  162. if($v->sex == 0){
  163. $list[$k]['sex'] = '女';
  164. }else{
  165. $list[$k]['sex'] = '男';
  166. }
  167. if($v->fresh == 0){
  168. $list[$k]['fresh'] = '否';
  169. }else{
  170. $list[$k]['fresh'] = '是';
  171. }
  172. if($v->status == 0){
  173. $list[$k]['status'] = '未下载';
  174. }else{
  175. $list[$k]['status'] = '已下载';
  176. }
  177. }
  178. return $content
  179. ->header('报名管理')
  180. ->description('人员信息列表')
  181. ->body(view('admin.health.appoint_list')->with([
  182. 'list' => $list,
  183. 'search_data' => $search_data,
  184. 'recruit' => $presentation
  185. ]));
  186. }
  187. public function qjwjInfoList(Content $content, Request $request){
  188. Permission::check('presentation_appoint_list');
  189. $search_data = $request->all();
  190. $where = [];
  191. if (isset($search_data['id'])) {
  192. foreach ($search_data as $k => $v) {
  193. if ($k == 'realname') {
  194. $where[] = [$k, 'like', "%$v%"];
  195. } elseif ($k != '_pjax' and $k != 'page' && $k != 'perpage') {
  196. $where[] = [$k, '=', $v];
  197. }
  198. }
  199. }
  200. $perpage = 20;
  201. $list = QjwjAppoint::where($where)
  202. ->select('*')
  203. ->orderBy('updated_at','desc')
  204. ->paginate($perpage);
  205. foreach ($list as $k => $v){
  206. $v->native_place_cn = get_district_cn($v->native_place);
  207. if($v->sex == 0){
  208. $list[$k]['sex'] = '女';
  209. }else{
  210. $list[$k]['sex'] = '男';
  211. }
  212. if($v->status == 0){
  213. $list[$k]['status'] = '未下载';
  214. }else{
  215. $list[$k]['status'] = '已下载';
  216. }
  217. }
  218. return $content
  219. ->header('信息管理')
  220. ->description('泉籍卫技人员信息列表')
  221. ->body(view('admin.health.qjwj_appoint_list')->with([
  222. 'list' => $list,
  223. 'search_data' => $search_data
  224. ]));
  225. }
  226. public function jyyxInfoList(Content $content, Request $request){
  227. Permission::check('presentation_appoint_list');
  228. $search_data = $request->all();
  229. $where = [];
  230. if (isset($search_data['id'])) {
  231. foreach ($search_data as $k => $v) {
  232. if ($k == 'realname') {
  233. $where[] = [$k, 'like', "%$v%"];
  234. } elseif ($k != '_pjax' and $k != 'page' && $k != 'perpage') {
  235. $where[] = [$k, '=', $v];
  236. }
  237. }
  238. }
  239. $perpage = 20;
  240. $list = JyyxAppoint::where($where)
  241. ->select('*')
  242. ->orderBy('updated_at','desc')
  243. ->paginate($perpage);
  244. foreach ($list as $k => $v){
  245. if($v->sex == 0){
  246. $list[$k]['sex'] = '女';
  247. }else{
  248. $list[$k]['sex'] = '男';
  249. }
  250. if($v->status == 0){
  251. $list[$k]['status'] = '未下载';
  252. }else{
  253. $list[$k]['status'] = '已下载';
  254. }
  255. }
  256. return $content
  257. ->header('信息管理')
  258. ->description('就业单身人员信息列表')
  259. ->body(view('admin.health.jyyx_appoint_list')->with([
  260. 'list' => $list,
  261. 'search_data' => $search_data
  262. ]));
  263. }
  264. public function postInfoList(Content $content, Request $request){
  265. Permission::check('presentation_appoint_list');
  266. $search_data = $request->all();
  267. $where = [];
  268. if (isset($search_data['id'])) {
  269. foreach ($search_data as $k => $v) {
  270. if ($k == 'realname') {
  271. $where[] = [$k, 'like', "%$v%"];
  272. } elseif ($k != '_pjax' and $k != 'page' && $k != 'perpage') {
  273. $where[] = [$k, '=', $v];
  274. }
  275. }
  276. }
  277. $perpage = 20;
  278. $list = PostAppoint::where($where)
  279. ->select('*')
  280. ->orderBy('updated_at','desc')
  281. ->paginate($perpage);
  282. foreach ($list as $k => $v){
  283. if($v->sex == 0){
  284. $list[$k]['sex'] = '女';
  285. }else{
  286. $list[$k]['sex'] = '男';
  287. }
  288. if($v->status == 0){
  289. $list[$k]['status'] = '未下载';
  290. }else{
  291. $list[$k]['status'] = '已下载';
  292. }
  293. }
  294. return $content
  295. ->header('信息管理')
  296. ->description('投递岗位人员信息列表')
  297. ->body(view('admin.health.post_appoint_list')->with([
  298. 'list' => $list,
  299. 'search_data' => $search_data
  300. ]));
  301. }
  302. }