BuyHouseSelectController.php 6.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196
  1. <?php
  2. namespace App\Admin\Controllers\Content;
  3. use App\Admin\Exports\Content\SelectHouseExport;
  4. use App\Http\Controllers\Controller;
  5. use App\Models\TalentHouseApply;
  6. use Encore\Admin\Controllers\HasResourceActions;
  7. use Encore\Admin\Grid;
  8. use Encore\Admin\Layout\Content;
  9. use Illuminate\Http\Request;
  10. class BuyHouseSelectController extends Controller
  11. {
  12. use HasResourceActions;
  13. private $marry = ['未知', '未婚', '已婚', '离异', '丧偶'];
  14. /**
  15. * Index interface.
  16. *
  17. * @param Content $content
  18. * @return Content
  19. */
  20. public function index($id,Content $content)
  21. {
  22. return $content
  23. ->header('选房顺序号')
  24. ->description(' ')
  25. ->body(view('admin.content.buy_house_select')->with(['grid' => $this->grid($id)]));
  26. }
  27. /**
  28. * Make a grid builder.
  29. *
  30. * @return Grid
  31. */
  32. protected function grid($id)
  33. {
  34. $grid = new Grid(new TalentHouseApply());
  35. $grid->model()->where('house_id',$id)->where('status',2)->orderBy('select_house_no', 'ASC');
  36. $grid->id('ID');
  37. $grid->name('姓名');
  38. $grid->mobile('联系电话');
  39. $grid->talent_level('人才层次');
  40. $grid->select_house_no('顺序号')->display(function (){
  41. if ($this->select_house_no == 999999) {
  42. return '无';
  43. }
  44. return $this->select_house_no;
  45. });
  46. $grid->actions(function ($actions) {
  47. $actions->append("&nbsp;<button class='btn btn-primary btn-xs detail' id=" . $actions->row['id'] . ">详情</button>");
  48. if ($actions->row['select_house_no'] == 999999) {
  49. $actions->append("<button class='btn btn-default btn-xs select_no' data-code=" . $actions->row['id'] . ">填写顺序号</button>");
  50. }
  51. });
  52. $grid->filter(function ($filter) {
  53. $filter->disableIdFilter();
  54. $filter->like('name', '姓名');
  55. $filter->like('mobile', '电话');
  56. });
  57. $grid->disableExport(false); //显示导出按钮
  58. $grid->exporter(new SelectHouseExport()); //传入自己在第1步创建的导出类
  59. return $grid;
  60. }
  61. /**
  62. * 详情
  63. */
  64. public function detail(Request $request)
  65. {
  66. $id = $request->id;
  67. $info = TalentHouseApply::find($id);;
  68. $info->family = json_decode($info->family);
  69. $info->marry_text = $this->marry[$info->marry];
  70. //layer相册层
  71. $photos = [
  72. 'certificates' => [],
  73. 'marry_prove' => [],
  74. 'household_register' => [],
  75. 'work_prove' => [],
  76. ];
  77. if (!empty(json_decode($info->certificates))) {
  78. $info->certificates = json_decode($info->certificates);
  79. $photo_data = [];
  80. foreach ($info->certificates as $k => $v) {
  81. $photo_data[] = [
  82. 'alt' => $v->name,
  83. 'pid' => $v->uid,
  84. 'src' => $v->response->path,
  85. ];
  86. }
  87. $photos['certificates'] = [
  88. 'title' => '证件信息',
  89. 'id' => 1,
  90. 'start' => 0,
  91. 'data' => $photo_data,
  92. ];
  93. } else {
  94. $info->certificates = [];
  95. }
  96. if (!empty(json_decode($info->marry_prove))) {
  97. $info->marry_prove = json_decode($info->marry_prove);
  98. $photo_data = [];
  99. foreach ($info->marry_prove as $k => $v) {
  100. $photo_data[] = [
  101. 'alt' => $v->name,
  102. 'pid' => $v->uid,
  103. 'src' => $v->response->path,
  104. ];
  105. }
  106. $photos['marry_prove'] = [
  107. 'title' => '婚姻证明',
  108. 'id' => 1,
  109. 'start' => 0,
  110. 'data' => $photo_data,
  111. ];
  112. } else {
  113. $info->marry_prove = [];
  114. }
  115. if (!empty(json_decode($info->household_register))) {
  116. $info->household_register = json_decode($info->household_register);
  117. $photo_data = [];
  118. foreach ($info->household_register as $k => $v) {
  119. $photo_data[] = [
  120. 'alt' => $v->name,
  121. 'pid' => $v->uid,
  122. 'src' => $v->response->path,
  123. ];
  124. }
  125. $photos['household_register'] = [
  126. 'title' => '户口本',
  127. 'id' => 1,
  128. 'start' => 0,
  129. 'data' => $photo_data,
  130. ];
  131. } else {
  132. $info->household_register = [];
  133. }
  134. if (!empty(json_decode($info->work_prove))) {
  135. $info->work_prove = json_decode($info->work_prove);
  136. $photo_data = [];
  137. foreach ($info->work_prove as $k => $v) {
  138. $photo_data[] = [
  139. 'alt' => $v->name,
  140. 'pid' => $v->uid,
  141. 'src' => $v->response->path,
  142. ];
  143. }
  144. $photos['work_prove'] = [
  145. 'title' => '在职证明',
  146. 'id' => 1,
  147. 'start' => 0,
  148. 'data' => $photo_data,
  149. ];
  150. } else {
  151. $info->work_prove = [];
  152. }
  153. $html = view('admin.ajax.buy_house_detail')->with(['info' => $info, 'photos' => $photos])->render();
  154. return response()->json(['code' => 1, 'data' => $html]);
  155. }
  156. /**
  157. * 选房顺序号
  158. */
  159. public function select(Request $request)
  160. {
  161. $id = $request->id;
  162. $select_house_no = $request->select_house_no;
  163. $url = empty($request->url) ? admin_base_path('content/buy_house') : $request->url;
  164. $apply = TalentHouseApply::find($id);
  165. if ($apply->select_house_no != 999999) {
  166. admin_toastr('数据错误,请重试', 'error');
  167. } else {
  168. $check = TalentHouseApply::where('select_house_no',$select_house_no)->where('house_id',$apply['house_id'])->first();
  169. if ($check) {
  170. admin_toastr('该顺序号已存在!', 'error');
  171. } else {
  172. $apply->select_house_no = $select_house_no;
  173. $apply->save();
  174. admin_toastr('操作成功', 'success');
  175. }
  176. }
  177. return redirect($url);
  178. }
  179. }