BuyHouseZjController.php 8.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233
  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. if ($actions->row['zj_check_status'] == 1) {
  55. $actions->append("<button class='btn btn-primary btn-xs applyaudit' data-code=" . $actions->row['id'] . ">审核</button>");
  56. }
  57. $actions->append("&nbsp;<button class='btn btn-primary btn-xs detail' id=" . $actions->row['id'] . ">详情</button>");
  58. });
  59. $grid->filter(function ($filter) {
  60. $filter->disableIdFilter();
  61. $filter->equal('house_id', '房源')->select(TalentHouse::all()->pluck('name', 'id'));
  62. $status_option = ['全部', '待审核', '审核通过', '审核驳回'];
  63. $filter->where(function ($query) {
  64. if ($this->input > 0) {
  65. $query->where('zj_check_status', '=', $this->input);
  66. }
  67. }, '状态', 'status')->radio($status_option);
  68. });
  69. $grid->disableExport(false); //显示导出按钮
  70. $grid->exporter(new HouseApplyZjExport()); //传入自己在第1步创建的导出类
  71. return $grid;
  72. }
  73. /**
  74. * 审核
  75. */
  76. public function audit(Request $request, SmsService $smsService)
  77. {
  78. $id = $request->id;
  79. $status = $request->status;
  80. $reason = $request->reason;
  81. $url = empty($request->url) ? admin_base_path('content/buy_house_zj') : $request->url;
  82. if (empty($id)) {
  83. admin_toastr('数据异常', 'error');
  84. return redirect(admin_base_path('content/buy_house_zj'));
  85. }
  86. $result = TalentHouseApply::where('id', '=', $id)
  87. ->update([
  88. 'zj_check_status' => $status,
  89. 'zj_check_comment' => $reason,
  90. 'zj_check_time' => date('Y-m-d H:i:s'),
  91. 'status' => $status,
  92. ]);
  93. //日志
  94. $apply = TalentHouseApply::find($id);
  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['zj_check_status'],
  104. 'check_comment' => $apply['zj_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 ($result) {
  113. admin_toastr('审核成功', 'success');
  114. } else {
  115. admin_toastr('该信息不存在或已审核', 'error');
  116. }
  117. return redirect($url);
  118. }
  119. /**
  120. * 详情
  121. */
  122. public function detail(Request $request)
  123. {
  124. $id = $request->id;
  125. $info = TalentHouseApply::with('idcard')->where('id',$id)->first();
  126. $info->family = json_decode($info->family);
  127. $info->marry_text = $this->marry[$info->marry];
  128. //layer相册层
  129. $photos = [
  130. 'certificates' => [],
  131. 'marry_prove' => [],
  132. 'household_register' => [],
  133. 'work_prove' => [],
  134. ];
  135. if (!empty(json_decode($info->certificates))) {
  136. $info->certificates = json_decode($info->certificates);
  137. $photo_data = [];
  138. foreach ($info->certificates as $k => $v) {
  139. $photo_data[] = [
  140. 'alt' => $v->name,
  141. 'pid' => $v->uid,
  142. 'src' => $v->response->path,
  143. ];
  144. }
  145. $photos['certificates'] = [
  146. 'title' => '证件信息',
  147. 'id' => 1,
  148. 'start' => 0,
  149. 'data' => $photo_data,
  150. ];
  151. } else {
  152. $info->certificates = [];
  153. }
  154. if (!empty(json_decode($info->marry_prove))) {
  155. $info->marry_prove = json_decode($info->marry_prove);
  156. $photo_data = [];
  157. foreach ($info->marry_prove as $k => $v) {
  158. $photo_data[] = [
  159. 'alt' => $v->name,
  160. 'pid' => $v->uid,
  161. 'src' => $v->response->path,
  162. ];
  163. }
  164. $photos['marry_prove'] = [
  165. 'title' => '婚姻证明',
  166. 'id' => 1,
  167. 'start' => 0,
  168. 'data' => $photo_data,
  169. ];
  170. } else {
  171. $info->marry_prove = [];
  172. }
  173. if (!empty(json_decode($info->household_register))) {
  174. $info->household_register = json_decode($info->household_register);
  175. $photo_data = [];
  176. foreach ($info->household_register as $k => $v) {
  177. $photo_data[] = [
  178. 'alt' => $v->name,
  179. 'pid' => $v->uid,
  180. 'src' => $v->response->path,
  181. ];
  182. }
  183. $photos['household_register'] = [
  184. 'title' => '户口本',
  185. 'id' => 1,
  186. 'start' => 0,
  187. 'data' => $photo_data,
  188. ];
  189. } else {
  190. $info->household_register = [];
  191. }
  192. if (!empty(json_decode($info->work_prove))) {
  193. $info->work_prove = json_decode($info->work_prove);
  194. $photo_data = [];
  195. foreach ($info->work_prove as $k => $v) {
  196. $photo_data[] = [
  197. 'alt' => $v->name,
  198. 'pid' => $v->uid,
  199. 'src' => $v->response->path,
  200. ];
  201. }
  202. $photos['work_prove'] = [
  203. 'title' => '在职证明',
  204. 'id' => 1,
  205. 'start' => 0,
  206. 'data' => $photo_data,
  207. ];
  208. } else {
  209. $info->work_prove = [];
  210. }
  211. $html = view('admin.ajax.buy_house_detail')->with(['info' => $info, 'photos' => $photos, 'status' => $this->status])->render();
  212. return response()->json(['code' => 1, 'data' => $html]);
  213. }
  214. }