| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462 | 
							- <?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 App\Services\Common\Sm4Service;
 
- use Encore\Admin\Controllers\HasResourceActions;
 
- use Encore\Admin\Form;
 
- use Encore\Admin\Grid;
 
- use Encore\Admin\Layout\Content;
 
- use Illuminate\Http\Request;
 
- use Illuminate\Support\Facades\DB;
 
- 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');
 
-         $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 (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>");
 
-             }
 
-             if (strtotime($actions->row['supply_time']) <= time()) {
 
-                 $actions->append(" <button class='btn btn-primary btn-xs export_pass' data-id=" . $actions->row['id'] . ">导出通过名单</button>");
 
-                 $actions->append(" <button class='btn btn-danger btn-xs export_no_pass' 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]);
 
-         }
 
-         //释放名额
 
-         if ($house['is_sock'] == 1) {
 
-             TalentHouse::where('id', $id)->update(['is_sock' => 2]);
 
-             TalentHouseApply::where('house_id', $id)->update(['is_sock' => 2]);
 
-         }
 
-         //TODO:同步选房系统,等接口
 
-         $apply = TalentHouseApply::with('idcard')->where('house_id', $id)->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) : [];
 
-             $data_item['card3'] = $data_item['xm3'] = $data_item['card2'] = $data_item['xm2'] = '';
 
-             //家庭关系
 
-             if (!empty($family)) {
 
-                 $child_names = [];
 
-                 $child_cards = [];
 
-                 foreach ($family as $fa) {
 
-                     if ($fa['relation'] == '配偶') {
 
-                         $data_item['xm2']   = $fa['realname'] == '无' ? '' : $fa['realname'];
 
-                         $data_item['card2'] = $fa['idcard'] == '无' ? '' : $fa['idcard'];
 
-                     } else {
 
-                         if ($fa['realname'] != '无') {
 
-                             $child_names[] = $fa['realname'] == '无' ? '' : $fa['realname'];
 
-                             $child_cards[] = $fa['idcard'] == '无' ? '' : $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;
 
-         }
 
-         $sm4     = new Sm4Service();
 
-         $sm4_key = 'ydkjjjrcgjrcdrjk';
 
-         $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, $sm4->encrypt($sm4_key, json_encode($api_data)));
 
-         $result = curl_exec($ch);
 
-         curl_close($ch);
 
-         if (empty($result)) {
 
-             return response()->json(['code' => 0, 'content' => '连接对方服务器失败,请联系管理员']);
 
-         }
 
-         $ret = json_decode($sm4->decrypt($sm4_key, $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']]);
 
-         }
 
-     }
 
-     /**
 
-      * 导出
 
-      */
 
-     public function export(Request $request)
 
-     {
 
-         //数据获取
 
-         $id     = $request->id;
 
-         $status = $request->status;
 
-         $house  = TalentHouse::find($id);
 
-         $query  = TalentHouseApply::with(['house', 'idcard'])
 
-             ->where('house_id', $id)
 
-             ->where('is_back', 2)
 
-             ->where('is_draft', 2)
 
-             ->orderByRaw(DB::raw("FIELD(talent_level,'第一层次','第二层次','第三层次','第四层次','第五层次','第六层次','第七层次') asc"));
 
-         if ($status == 1) {
 
-             $filename = $house['name'].'审核不通过名单.xls';
 
-             $query    = $query->whereIn('status', [1, 3]);
 
-         } else {
 
-             $filename = $house['name'].'审核通过名单.xls';
 
-             $query    = $query->where('status', 2);
 
-         }
 
-         $data = $query->get();
 
-         if ($data->isEmpty()) {
 
-             return '暂无数据';
 
-         }
 
-         //数据处理
 
-         $status = ['', '待审核', '审核通过', '审核驳回', '审核不通过'];
 
-         $marry  = ['未知', '未婚', '已婚', '离异', '丧偶'];
 
-         $type   = ['', '优秀人才', '集成电路优秀人才'];
 
-         $no     = 1;
 
-         foreach ($data as $row) {
 
-             $family = empty($row->family) ? '' : json_decode($row->family, true);
 
-             if (!empty($family)) {
 
-                 $relation = [];
 
-                 $child    = [];
 
-                 $id_card  = [];
 
-                 foreach ($family as $v) {
 
-                     $relation[] = $v['relation'];
 
-                     $child[]    = $v['realname'];
 
-                     $id_card[]  = $v['idcard'];
 
-                 }
 
-                 $row['relation']         = implode('/', $relation);
 
-                 $row['relation_name']    = implode('/', $child);
 
-                 $row['relation_id_card'] = implode('/', $id_card);
 
-             }
 
-             $row['no'] = $no;
 
-             $no++;
 
-             $row['marry_text'] = $marry[$row['marry']];
 
-             $row['type_text']  = $type[$row['type']];
 
-         }
 
-         header("Content-type: application/vnd.ms-excel; charset=utf-8");
 
-         header("Content-Disposition: attachment; filename=$filename");
 
-         $view = view('admin.content.export_house_result')->with(['data' => $data, 'house' => $house, 'status' => $status]);
 
-         $str  = response($view)->getContent();
 
-         echo $str;
 
-         exit;
 
-     }
 
-     /**
 
-      * 图片
 
-      */
 
-     public function image(Request $request)
 
-     {
 
-         $src = $request->src;
 
-         $photo_data[] = [
 
-             'alt' => '',
 
-             'pid' => 1,
 
-             'src' => $src,
 
-         ];
 
-         $photos = [
 
-             'title' => '图片信息',
 
-             'id' => 1,
 
-             'start' => 0,
 
-             'data' =>$photo_data
 
-         ];
 
-         return view('admin.content.buy_house_image',['src'=>$src,'photos'=>$photos]);
 
-     }
 
- }
 
 
  |