BuyHouseJcController.php 7.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228
  1. <?php
  2. namespace App\Admin\Controllers\Content;
  3. use App\Http\Controllers\Controller;
  4. use App\Models\TalentHouse;
  5. use App\Models\TalentHouseApply;
  6. use App\Services\Common\SmsService;
  7. use Encore\Admin\Controllers\HasResourceActions;
  8. use Encore\Admin\Facades\Admin;
  9. use Encore\Admin\Grid;
  10. use Encore\Admin\Layout\Content;
  11. use Illuminate\Http\Request;
  12. use Illuminate\Support\Facades\DB;
  13. class BuyHouseJcController extends Controller
  14. {
  15. use HasResourceActions;
  16. private $status = ['未知', '待审核', '审核通过', '审核驳回'];
  17. private $marry = ['未知', '未婚', '已婚', '离异', '丧偶'];
  18. /**
  19. * Index interface.
  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(view('admin.content.buy_house_jc')->with(['grid' => $this->grid()]));
  30. }
  31. /**
  32. * Make a grid builder.
  33. *
  34. * @return Grid
  35. */
  36. protected function grid()
  37. {
  38. $grid = new Grid(new TalentHouseApply());
  39. $grid->model()->with('house')->where('type', 2)->where('is_back', 2)->where('is_draft', 2)->orderBy('rs_check_status', 'ASC');
  40. $status_text = $this->status;
  41. $grid->id('ID');
  42. $grid->name('姓名');
  43. $grid->mobile('联系电话');
  44. $grid->talent_level('人才层次');
  45. $grid->column('房源')->display(function () {
  46. return $this->house->name;
  47. });
  48. $grid->rs_check_status('状态')->display(function () use ($status_text) {
  49. return $status_text[$this->rs_check_status];
  50. });
  51. $grid->rs_check_comment('备注');
  52. $grid->actions(function ($actions) {
  53. if ($actions->row['rs_check_status'] == 1) {
  54. $actions->append("<button class='btn btn-primary btn-xs applyaudit' data-code=" . $actions->row['id'] . ">审核</button>");
  55. }
  56. $actions->append("&nbsp;<button class='btn btn-primary btn-xs detail' id=" . $actions->row['id'] . ">详情</button>");
  57. });
  58. $grid->filter(function ($filter) {
  59. $filter->disableIdFilter();
  60. $filter->equal('house_id', '房源')->select(TalentHouse::all()->pluck('name', 'id'));
  61. $status_option = ['全部', '待审核', '审核通过', '审核不通过'];
  62. $filter->where(function ($query) {
  63. if ($this->input > 0) {
  64. $query->where('status', '=', $this->input);
  65. }
  66. }, '状态', 'status')->radio($status_option);
  67. });
  68. return $grid;
  69. }
  70. /**
  71. * 审核
  72. */
  73. public function audit(Request $request, SmsService $smsService)
  74. {
  75. $id = $request->id;
  76. $status = $request->status;
  77. $reason = $request->reason;
  78. $url = empty($request->url) ? admin_base_path('content/buy_house_jc') : $request->url;
  79. if (empty($id)) {
  80. admin_toastr('数据异常', 'error');
  81. return redirect(admin_base_path('content/buy_house_jc'));
  82. }
  83. $result = TalentHouseApply::where('id', '=', $id)
  84. ->update([
  85. 'rs_check_status' => $status,
  86. 'rs_check_comment' => $reason,
  87. 'rs_check_time' => date('Y-m-d H:i:s'),
  88. 'status' => $status == 2 ? 1 : 3,
  89. ]);
  90. //日志
  91. $apply = TalentHouseApply::find($id);
  92. $house = TalentHouse::find($apply['house_id']);
  93. $admin = Admin::user();
  94. $log = [
  95. 'house_name' => $house['name'],
  96. 'user_name' => $apply['name'],
  97. 'check_name' => $admin['name'],
  98. 'data' => json_encode($apply),
  99. 'created_at' => date('Y-m-d H:i:s'),
  100. 'check_status' => $apply['rs_check_status'],
  101. 'check_comment' => $apply['rs_check_comment'],
  102. ];
  103. DB::table('talent_house_check_log')->insert($log);
  104. //审核不通过发送短信
  105. if ($status == 3) {
  106. $time = strtotime($house['supply_time']);
  107. $smsService->sendSms($apply['mobile'], 'sms_buyhouse_supply', ['name' => $apply['name'], 'month' => date('m', $time), 'day' => date('d', $time)]);
  108. }
  109. if ($result) {
  110. admin_toastr('审核成功', 'success');
  111. } else {
  112. admin_toastr('该信息不存在或已审核', 'error');
  113. }
  114. return redirect($url);
  115. }
  116. /**
  117. * 详情
  118. */
  119. public function detail(Request $request)
  120. {
  121. $id = $request->id;
  122. $info = TalentHouseApply::with('idcard')->where('id', $id)->first();
  123. $info->family = json_decode($info->family);
  124. $info->marry_text = $this->marry[$info->marry];
  125. //layer相册层
  126. $photos = [
  127. 'certificates' => [],
  128. 'marry_prove' => [],
  129. 'household_register' => [],
  130. 'work_prove' => [],
  131. ];
  132. if (!empty(json_decode($info->certificates))) {
  133. $info->certificates = json_decode($info->certificates);
  134. $photo_data = [];
  135. foreach ($info->certificates as $k => $v) {
  136. $photo_data[] = [
  137. 'alt' => $v->name,
  138. 'pid' => $v->uid,
  139. 'src' => $v->response->path,
  140. ];
  141. }
  142. $photos['certificates'] = [
  143. 'title' => '证件信息',
  144. 'id' => 1,
  145. 'start' => 0,
  146. 'data' => $photo_data,
  147. ];
  148. } else {
  149. $info->certificates = [];
  150. }
  151. if (!empty(json_decode($info->marry_prove))) {
  152. $info->marry_prove = json_decode($info->marry_prove);
  153. $photo_data = [];
  154. foreach ($info->marry_prove as $k => $v) {
  155. $photo_data[] = [
  156. 'alt' => $v->name,
  157. 'pid' => $v->uid,
  158. 'src' => $v->response->path,
  159. ];
  160. }
  161. $photos['marry_prove'] = [
  162. 'title' => '婚姻证明',
  163. 'id' => 1,
  164. 'start' => 0,
  165. 'data' => $photo_data,
  166. ];
  167. } else {
  168. $info->marry_prove = [];
  169. }
  170. if (!empty(json_decode($info->household_register))) {
  171. $info->household_register = json_decode($info->household_register);
  172. $photo_data = [];
  173. foreach ($info->household_register as $k => $v) {
  174. $photo_data[] = [
  175. 'alt' => $v->name,
  176. 'pid' => $v->uid,
  177. 'src' => $v->response->path,
  178. ];
  179. }
  180. $photos['household_register'] = [
  181. 'title' => '户口本',
  182. 'id' => 1,
  183. 'start' => 0,
  184. 'data' => $photo_data,
  185. ];
  186. } else {
  187. $info->household_register = [];
  188. }
  189. if (!empty(json_decode($info->work_prove))) {
  190. $info->work_prove = json_decode($info->work_prove);
  191. $photo_data = [];
  192. foreach ($info->work_prove as $k => $v) {
  193. $photo_data[] = [
  194. 'alt' => $v->name,
  195. 'pid' => $v->uid,
  196. 'src' => $v->response->path,
  197. ];
  198. }
  199. $photos['work_prove'] = [
  200. 'title' => '在职证明',
  201. 'id' => 1,
  202. 'start' => 0,
  203. 'data' => $photo_data,
  204. ];
  205. } else {
  206. $info->work_prove = [];
  207. }
  208. $html = view('admin.ajax.buy_house_detail')->with(['info' => $info, 'photos' => $photos])->render();
  209. return response()->json(['code' => 1, 'data' => $html]);
  210. }
  211. }