IndexController.php 9.7 KB

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