BuyHouseRsController.php 5.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167
  1. <?php
  2. namespace App\Admin\Controllers\Content;
  3. use App\Admin\Exports\Content\HouseApplyRsExport;
  4. use App\Http\Controllers\Controller;
  5. use App\Models\SmsTemplate;
  6. use App\Models\TalentHouse;
  7. use App\Models\TalentHouseApply;
  8. use App\Services\Common\SmsService;
  9. use Encore\Admin\Controllers\HasResourceActions;
  10. use Encore\Admin\Facades\Admin;
  11. use Encore\Admin\Grid;
  12. use Encore\Admin\Layout\Content;
  13. use Illuminate\Http\Request;
  14. use Illuminate\Support\Facades\DB;
  15. class BuyHouseRsController extends Controller
  16. {
  17. use HasResourceActions;
  18. private $status = ['未知', '待审核', '审核通过', '审核驳回', '审核不通过'];
  19. private $marry = ['未知', '未婚', '已婚', '离异', '丧偶'];
  20. /**
  21. * Index interface.
  22. *
  23. * @param Content $content
  24. * @return Content
  25. */
  26. public function index(Content $content)
  27. {
  28. return $content
  29. ->header('申报列表')
  30. ->description(' ')
  31. ->body(view('admin.content.buy_house_rs')->with(['grid' => $this->grid()]));
  32. }
  33. /**
  34. * Make a grid builder.
  35. *
  36. * @return Grid
  37. */
  38. protected function grid()
  39. {
  40. $grid = new Grid(new TalentHouseApply());
  41. $grid->model()->with(['house', 'idcard'])->where('type', 1)->where('is_back', 2)->where('is_draft', 2)->orderBy('rs_check_status', 'ASC');
  42. $status_text = $this->status;
  43. $grid->id('ID');
  44. $grid->name('姓名');
  45. $grid->mobile('联系电话');
  46. $grid->talent_level('人才层次');
  47. $grid->column('房源')->display(function () {
  48. return $this->house->name;
  49. });
  50. $grid->rs_check_status('状态')->display(function () use ($status_text) {
  51. return $status_text[$this->rs_check_status];
  52. });
  53. $grid->rs_check_comment('备注')->style('max-width:400px');
  54. $grid->actions(function ($actions) {
  55. $actions->append("&nbsp;<button class='btn btn-primary btn-xs detail' id=" . $actions->row['id'] . ">详情审核</button>");
  56. });
  57. $grid->filter(function ($filter) {
  58. $filter->disableIdFilter();
  59. $filter->like('name', '姓名');
  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('rs_check_status', '=', $this->input);
  65. }
  66. }, '状态', 'status')->radio($status_option);
  67. });
  68. $grid->disableExport(false); //显示导出按钮
  69. $grid->exporter(new HouseApplyRsExport()); //传入自己在第1步创建的导出类
  70. return $grid;
  71. }
  72. /**
  73. * 审核
  74. */
  75. public function audit(Request $request, SmsService $smsService)
  76. {
  77. $id = $request->id;
  78. $status = $request->status;
  79. $reason = $request->reason;
  80. $url = empty($request->url) ? admin_base_path('content/buy_house_rs') : $request->url;
  81. if (empty($id)) {
  82. admin_toastr('数据异常', 'error');
  83. return redirect(admin_base_path('content/buy_house_rs'));
  84. }
  85. $apply = TalentHouseApply::find($id);
  86. $apply->rs_check_status = $status;
  87. $apply->rs_check_comment = $reason;
  88. $apply->rs_check_time = date('Y-m-d H:i:s');
  89. $apply->status = $status == 2 ? 1 : $status;
  90. if ($status == 4) {
  91. $apply->is_sock = 2;
  92. }
  93. $result = $apply->save();
  94. //日志
  95. $house = TalentHouse::find($apply['house_id']);
  96. $admin = Admin::user();
  97. $log = [
  98. 'house_name' => $house['name'],
  99. 'user_name' => $apply['name'],
  100. 'check_name' => $admin['name'],
  101. 'data' => json_encode($apply),
  102. 'created_at' => date('Y-m-d H:i:s'),
  103. 'check_status' => $apply['rs_check_status'],
  104. 'check_comment' => $apply['rs_check_comment'],
  105. ];
  106. DB::table('talent_house_check_log')->insert($log);
  107. //审核发送短信
  108. if ($status == 3) {
  109. $time = strtotime($house['supply_time']);
  110. $smsService->sendSms($apply['mobile'], 'sms_buyhouse_supply', ['name' => $apply['name'], 'month' => date('m', $time), 'day' => date('d', $time)]);
  111. }
  112. if ($status == 2) {
  113. SmsTemplate::buyHouseCheck('zj');
  114. SmsTemplate::buyHouseCheck('zr');
  115. }
  116. if ($result) {
  117. admin_toastr('审核成功', 'success');
  118. } else {
  119. admin_toastr('该信息不存在或已审核', 'error');
  120. }
  121. return redirect($url);
  122. }
  123. /**
  124. * 详情
  125. */
  126. public function detail(Request $request)
  127. {
  128. $id = $request->id;
  129. $info = TalentHouseApply::with('idcard')->where('id', $id)->first();
  130. $info->family = json_decode($info->family);
  131. $info->marry_text = $this->marry[$info->marry];
  132. //json
  133. $json = ['certificates', 'marry_prove', 'household_register', 'work_prove'];
  134. foreach ($json as $v) {
  135. if (!empty(json_decode($info->$v))) {
  136. $info->$v = json_decode($info->$v);
  137. } else {
  138. $info->$v = [];
  139. }
  140. }
  141. $with = ['info' => $info, 'form_url' => route('content.buy_house_rs.audit'), 'status' => $this->status];
  142. $with['check_status'] = $info['rs_check_status'];
  143. $html = view('admin.ajax.buy_house_detail')->with($with)->render();
  144. return response()->json(['code' => 1, 'data' => $html]);
  145. }
  146. }