123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366 |
- <?php
- namespace App\Admin\Controllers\Content;
- use App\Admin\Extensions\Form\ValidateForm;
- use App\Http\Controllers\Controller;
- use App\Models\TalentHouse;
- use App\Models\TalentHouseApply;
- use Encore\Admin\Controllers\HasResourceActions;
- use Encore\Admin\Form;
- use Encore\Admin\Grid;
- use Encore\Admin\Layout\Content;
- use Illuminate\Http\Request;
- class BuyHouseController extends Controller
- {
- use HasResourceActions;
- private $house_status = ['未知', '未开始', '申报中', '已结束'];
- /**
- * Index interface.
- *
- * @param Content $content
- * @return Content
- */
- public function index(Content $content)
- {
- return $content
- ->header('房源列表')
- ->description(' ')
- ->body(view('admin.content.buy_house')->with(['grid' => $this->grid()]));
- }
- /**
- * Edit interface.
- *
- * @param mixed $id
- * @param Content $content
- * @return Content
- */
- public function edit($id, Content $content)
- {
- return $content
- ->header('房源')
- ->description(' ')
- ->body($this->editForm($id)->edit($id));
- }
- /**
- * Create interface.
- *
- * @param Content $content
- * @return Content
- */
- public function create(Content $content)
- {
- return $content
- ->header('房源')
- ->description(' ')
- ->body($this->form());
- }
- /**
- * Make a grid builder.
- *
- * @return Grid
- */
- protected function grid()
- {
- $grid = new Grid(new TalentHouse());
- $grid->model()->orderBy('updated_at', 'DESC');
- $status_text = $this->house_status;
- $grid->id('ID');
- $grid->name('项目名称');
- $grid->small_img('缩略图')->display(function () {
- if ($this->small_img) {
- return '<span class="vtip" title="<img src=\'' . upload_asset($this->small_img) . '\' height=120>">
- <img class="avatar small" src="' . upload_asset($this->small_img) . '" align="absmiddle" style="width: 22px;height: 22px;">
- </span>';
- } else {
- return '';
- }
- });
- $grid->status('状态')->display(function () {
- $time = time();
- if (strtotime($this->apply_time_start) > $time) {
- return '未开始';
- }
- if (strtotime($this->apply_time_end) < $time) {
- return '已结束';
- }
- return '申报中';
- });
- $grid->declare_time('申报时间')->display(function () {
- return date('Y-m-d', strtotime($this->declare_time));
- });
- $grid->column('报名时间')->display(function () {
- return date('Y-m-d', strtotime($this->apply_time_start)) . '至' . date('Y-m-d', strtotime($this->apply_time_end));
- });
- //新增按钮
- $grid->disableCreateButton(false);
- //批量删除
- $grid->tools(function ($tools) {
- $tools->batch(function ($batch) {
- $batch->disableDelete(false);
- });
- });
- $grid->actions(function ($actions) {
- $actions->disableEdit(false);
- $actions->disableDelete(false);
- if ($actions->row['is_sock'] == 1) {
- $actions->append(" <button class='btn btn-primary btn-xs sock' data-id=" . $actions->row['id'] . ">释放名额</button>");
- }
- if (strtotime($actions->row['supply_time']) <= time() && $actions->row['sync_status'] == 2) {
- $actions->append(" <button class='btn btn-default btn-xs select_house' data-id=" . $actions->row['id'] . ">选房顺序号</button>");
- $actions->append(" <button class='btn btn-warning btn-xs sync' data-id=" . $actions->row['id'] . ">同步到选房系统</button>");
- }
- });
- $grid->filter(function ($filter) {
- $filter->disableIdFilter();
- $filter->like('name', '项目名称');
- $status_option = ['全部', '未开始', '申报中', '已结束'];
- $filter->where(function ($query) {
- $date = date('Y-m-d H:i:s');
- if ($this->input == 1) {
- $query->where('apply_time_start', '>', $date);
- }
- if ($this->input == 2) {
- $query->where('apply_time_start', '<', $date)->where('apply_time_end', '>', $date);
- }
- if ($this->input == 3) {
- $query->where('apply_time_end', '<', $date);
- }
- }, '状态', 'status')->radio($status_option);
- });
- return $grid;
- }
- /**
- * Make a form builder.
- *
- * @return Form
- */
- protected function form()
- {
- $form = new ValidateForm(new TalentHouse());
- $form->text('name', '项目名称')->rules('required|max:100', ['required' => '标题不能为空。', 'max' => '标题长度不能大于100。'])->setWidth(4)->setMustMark();
- $form->number('project_id', '选房系统项目id')->rules('required', ['required' => '项目id不能为空。若未确定id,请填0'])->setWidth(4)->setMustMark();
- $form->datetime('declare_time', '申报时间')->rules('required', ['required' => '申报时间不能为空。'])->setWidth(4)->setMustMark();
- $form->datetime('apply_time_start', '报名开始时间')->rules('required', ['required' => '报名开始时间不能为空。'])->setWidth(4)->setMustMark();
- $form->datetime('apply_time_end', '报名结束时间')->rules('required', ['required' => '报名结束时间不能为空。'])->setWidth(4)->setMustMark();
- $form->datetime('supply_time', '补件截止时间')->rules('required', ['required' => '补件截止时间不能为空。'])->setWidth(4)->setMustMark();
- $form->text('address', '地址')->rules('required|max:100', ['required' => '地址不能为空。', 'max' => '地址长度不能大于100。'])->setWidth(8)->setMustMark();
- $form->image('small_img', '缩略图')->uniqueName()->rules('image|mimes:jpeg,bmp,png', ['image' => '缩略图请选择图片文件。', 'mimes' => '请选择jpeg,bmp,png格式的缩略图上传。'])->setWidth(4);
- $form->textarea('describe', '描述')->rules('required|max:1024', ['required' => '描述不能为空。', 'max' => '描述长度不能大于1024。'])->setWidth(8)->setMustMark();
- $form->editor('content', '内容')->rules('required', ['required' => '内容不能为空。'])->setMustMark();
- $form->saved(function (Form $form) {
- //如果没有上传logo,判断是否
- $small_img = \Illuminate\Support\Facades\Request::input('small_img');
- if (!$form->model()->small_img && $small_img) {
- $form->model()->small_img = $small_img;
- $form->model()->save();
- }
- });
- $form->footer(function ($footer) {
- $footer->disableViewCheck();
- $footer->disableEditingCheck();
- $footer->disableCreatingCheck();
- $footer->disableReset();
- });
- return $form;
- }
- protected function editForm($id)
- {
- $form = new ValidateForm(new TalentHouse());
- $form->text('name', '项目名称')->rules('required|max:100', ['required' => '标题不能为空。', 'max' => '标题长度不能大于100。'])->setWidth(4)->setMustMark();
- $form->number('project_id', '选房系统项目id')->rules('required', ['required' => '项目id不能为空。若未确定id,请填0'])->setWidth(4)->setMustMark();
- $form->datetime('declare_time', '申报时间')->rules('required', ['required' => '申报时间不能为空。'])->setWidth(4)->setMustMark();
- $form->datetime('apply_time_start', '报名开始时间')->rules('required', ['required' => '报名开始时间不能为空。'])->setWidth(4)->setMustMark();
- $form->datetime('apply_time_end', '报名结束时间')->rules('required', ['required' => '报名结束时间不能为空。'])->setWidth(4)->setMustMark();
- $form->datetime('supply_time', '补件截止时间')->rules('required', ['required' => '补件截止时间不能为空。'])->setWidth(4)->setMustMark();
- $form->text('address', '地址')->rules('required|max:100', ['required' => '地址不能为空。', 'max' => '地址长度不能大于100。'])->setWidth(8)->setMustMark();
- $form->image('small_img', '缩略图')->uniqueName()->rules('image|mimes:jpeg,bmp,png', ['image' => '缩略图请选择图片文件。', 'mimes' => '请选择jpeg,bmp,png格式的缩略图上传。'])->setWidth(4);
- $form->textarea('describe', '描述')->rules('required|max:1024', ['required' => '描述不能为空。', 'max' => '描述长度不能大于1024。'])->setWidth(8)->setMustMark();
- $form->editor('content', '内容')->rules('required', ['required' => '内容不能为空。'])->setMustMark();
- $form->saved(function (Form $form) {
- //如果没有上传logo,判断是否
- $small_img = \Illuminate\Support\Facades\Request::input('small_img');
- if (!$form->model()->small_img && $small_img) {
- $form->model()->small_img = $small_img;
- $form->model()->save();
- }
- });
- $form->footer(function ($footer) {
- $footer->disableViewCheck();
- $footer->disableEditingCheck();
- $footer->disableCreatingCheck();
- $footer->disableReset();
- });
- $form->tools(function (Form\Tools $tools) {
- $tools->disableDelete();
- $tools->disableView();
- });
- return $form;
- }
- public function update($id)
- {
- return $this->editForm($id)->update($id);
- }
- public function destroy($id)
- {
- //是否存在报名列表
- $ids = explode(',', $id);
- $check = TalentHouseApply::whereIn('house_id', $ids)->count();
- if ($check > 0) {
- return response()->json([
- 'status' => false,
- 'message' => '存在申报信息的房源不允许删除!',
- ]);
- }
- if ($this->form()->destroy($id)) {
- $data = [
- 'status' => true,
- 'message' => trans('admin.delete_succeeded'),
- ];
- } else {
- $data = [
- 'status' => false,
- 'message' => trans('admin.delete_failed'),
- ];
- }
- return response()->json($data);
- }
- /**
- * 释放名额
- */
- public function sock(Request $request)
- {
- $id = $request->id;
- if (empty($id)) {
- return response()->json(['code' => 0, 'content' => '数据异常']);
- }
- $house = TalentHouse::find($id);
- if (strtotime($house['supply_time']) > time()) {
- return response()->json(['code' => 0, 'content' => '报名还未结束']);
- }
- if ($house['is_sock'] == 2) {
- return response()->json(['code' => 1]);
- }
- //释放名额
- TalentHouse::where('id', $id)->update(['is_sock' => 2]);
- TalentHouseApply::where('house_id', $id)->update(['is_sock' => 2]);
- return response()->json(['code' => 1]);
- }
- /**
- * 同步选房系统
- */
- public function sync(Request $request)
- {
- $id = $request->id;
- if (empty($id)) {
- return response()->json(['code' => 0, 'content' => '数据异常']);
- }
- $house = TalentHouse::find($id);
- if ($house['project_id'] == 0) {
- return response()->json(['code' => 0, 'content' => '请先填选房系统项目id']);
- }
- if (strtotime($house['supply_time']) > time()) {
- return response()->json(['code' => 0, 'content' => '报名还未结束']);
- }
- if ($house['sync_status'] == 1) {
- return response()->json(['code' => 1]);
- }
- //TODO:同步选房系统,等接口
- $apply = TalentHouseApply::with('idcard')->where('select_house_no', '<', 999999)->orderBy('select_house_no', 'asc')->get();
- if (empty($apply)) {
- return response()->json(['code' => 0, 'content' => '请先填写选房顺序号']);
- }
- $api_data = [
- 'xmId' => $house['project_id'],
- 'xmName' => $house['name'],
- 'data' => [],
- ];
- foreach ($apply as $v) {
- $data_item = [];
- $data_item['index'] = $v['select_house_no'];
- $data_item['xm1'] = $v['name'];
- $data_item['card1'] = $v['idcard']['id_card'];
- $family = $v['family'] ? json_decode($v['family'],true) : [];
- //家庭关系
- if (empty($family)) {
- $data_item['xm2'] = $data_item['card2'] = $data_item['xm3'] = $data_item['card3'] = '';
- } else {
- $child_names = [];
- $child_cards = [];
- foreach ($family as $fa) {
- if ($fa['relation'] == '配偶') {
- $data_item['xm2'] = $fa['realname'];
- $data_item['card2'] = $fa['idcard'];
- } else {
- $child_names[] = $fa['realname'];
- $child_cards[] = $fa['idcard'];
- }
- }
- $data_item['xm3'] = implode('/', $child_names);
- $data_item['card3'] = implode('/', $child_cards);
- }
- $data_item['hjh'] = '';
- $data_item['phone'] = $v['mobile'];
- $data_item['hunyin'] = $v['marry'] == 1 ? '未婚' : '已婚';
- $data_item['kx'] = '是';
- $api_data['data'][] = $data_item;
- }
- $ch = curl_init();
- curl_setopt($ch, CURLOPT_URL, "http://jjzf.fjeda.com:9001/admin/xuanfang/importGaojiRencai");
- curl_setopt($ch, CURLOPT_HTTPHEADER, [
- 'Content-Type: application/json; charset=utf-8' //json版本需要填写 Content-Type: application/json;
- ]
- );
- curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
- curl_setopt($ch, CURLOPT_TIMEOUT, 60);
- curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, 0);
- curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, 0);
- curl_setopt($ch,CURLOPT_POST, true);
- curl_setopt($ch,CURLOPT_POSTFIELDS, json_encode($api_data));
- $result = curl_exec($ch);
- curl_close($ch);
- $ret = json_decode($result, true);
- if ($ret['code'] == '0000') {
- TalentHouse::where('id', $id)->update(['sync_status' => 1]);
- return response()->json(['code' => 1]);
- } else {
- return response()->json(['code' => 0, 'content' => $ret['msg']]);
- }
- }
- }
|