IndexController.php 8.3 KB

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