BuyHouseZjController.php 8.2 KB

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