title = '列表'; $where = []; $where[] = ['f.is_deleted','=',0]; if($title = input('title')) $where[] = ['f.title','like','%'.$title.'%']; $query = $this->_query($this->table)->alias('f') ->field('f.*') ->where($where) ->order('sort desc,f.id desc ')->page(); } /** * 添加 * @auth true * @menu true * @throws \think\Exception * @throws \think\db\exception\DataNotFoundException * @throws \think\db\exception\ModelNotFoundException * @throws \think\exception\DbException * @throws \think\exception\PDOException */ public function add() { $this->title = '添加'; $this->_form($this->table, 'form'); } /** * 编辑 * @auth true * @menu true * @throws \think\Exception * @throws \think\db\exception\DataNotFoundException * @throws \think\db\exception\ModelNotFoundException * @throws \think\exception\DbException * @throws \think\exception\PDOException */ public function edit() { $this->title = '编辑'; if(input('test')) { $this->_form($this->table, 'form3'); }else{ $this->_form($this->table, 'form'); } } /** * 删除 * @auth true * @throws \think\Exception * @throws \think\exception\PDOException */ public function del() { \app\common\model\Recruit::where('id',input('id'))->update(['is_deleted'=>1]); \app\common\model\Recruit::esAdd(input('id')); \app\common\model\TopSearch::saveData(input('id'),'recruit'); $this->success('操作成功'); } /** * 删除 * @auth true * @throws \think\Exception * @throws \think\exception\PDOException */ public function remove() { $ids = input('id'); foreach (explode(',',$ids) as $id) { \app\common\model\Recruit::where('id',$id)->update(['is_deleted'=>1]); \app\common\model\Recruit::esAdd($id); \app\common\model\TopSearch::saveData($id,'recruit'); } $this->success('已删除!'); } /** * 表单数据处理 * @param array $data */ protected function _form_filter(&$data) { // if($this->request->isPost()) $this->error('页面调试中'); $this->education = ['不限','高中及以上','专科及以上','本科及以上','研究生及以上']; $all_area = $all_area = ChinaArea::where('level','<=',3)->select(); $this->all_area = make_tree($all_area); $all_cate = \app\common\model\RecruitCate::where(['is_deleted'=>0])->order('sort desc ,id desc')->select(); $this->cate_tree = make_tree($all_cate); if ($this->request->isGet() && $this->request->action() == 'add') { $this->isAddMode = 1; $this->ladder = []; } if ($this->request->isGet() && $this->request->action() == 'edit') { $this->isAddMode = 0; $this->ladder = isset_full($data,'ladder') ? json_decode($data['ladder'],true):[]; } if($this->request->isGet()) { $third_classify = input('third_classify'); if($third_classify) { if($third_classify) $data['third_classify'] = $third_classify; $third_info = \app\common\model\RecruitCate::where('id',$third_classify)->find()->toArray(); if($third_classify) $data['second_classify'] = $third_info['pid']; $data['first_classify'] = \app\common\model\RecruitCate::where('id',$data['second_classify'])->value('pid'); } } if($this->request->isPost()) { list($post,$ladder_data) = [$this->request->post(),[]]; if(!$data['longitude'] || !$data['latitude']) $this->error('请选择地图坐标'); if(!$data['release_time']) $data['release_time'] = date("Y-m-d H:i:s"); if($data['hot_num'] != $data['hot_num_old']) $data['hot_time'] = date("Y-m-d H:i:s"); if(!empty($post['user_phone'])) { $user_id = User::where('phone|email',$post['user_phone'])->value('id'); if(!$user_id) $this->error('账号未注册'); $data['user_id'] = $user_id; }else{ $data['user_id'] = ''; } //定时热搜 if(!$post['hot_num']){ $post['hot_num'] = 0; } if(isset($post['id'])){ $info = \app\common\model\Recruit::where('id',$data['id'])->find(); if(($post['regular_hot_end_time'] && $post['hot_target_num'] && $info['regular_hot_end_time'] != $post['regular_hot_end_time']) || ($info['hot_num'] != $post['hot_num'] && $post['regular_hot_end_time'] && $post['hot_target_num'])){ $data['regular_hot_start_time'] = date("Y-m-d H:i:s"); $startdate = strtotime($data['regular_hot_start_time']); $enddate = strtotime($post['regular_hot_end_time']); $diff_seconds = ($enddate-$startdate)/60; $min_num = ceil($diff_seconds/10); $hot_num = $post['hot_target_num'] - $post['hot_num']; $num = ceil($hot_num/$min_num); if($num < 0){ $num = 0; } $data['regular_num'] = $num; } }else{ if($post['regular_hot_end_time'] && $post['hot_target_num']){ $data['regular_hot_start_time'] = date("Y-m-d H:i:s"); $startdate = strtotime($data['regular_hot_start_time']); $enddate = strtotime($post['regular_hot_end_time']); $diff_seconds = ($enddate-$startdate)/60; $min_num = ceil($diff_seconds/10); $hot_num = $post['hot_target_num'] - $post['hot_num']; $num = ceil($hot_num/$min_num); if($num < 0){ $num = 0; } $data['regular_num'] = $num; } } if(!$post['regular_hot_end_time']){ unset($data['regular_hot_end_time']); } //定时热搜end } } protected function _form_result(&$data) { \app\common\model\Recruit::esAdd($data); \app\common\model\TopSearch::saveData($data,'recruit'); if($this->request->action() == 'add' ||$this->request->action() == 'edit' ){ if($this->request->post('third_classify')){ $third_title = \app\common\model\RecruitCate::where('id',$this->request->post('third_classify'))->value('title'); PlatformSwitch::followMsg(6,$this->request->post('third_classify'),$third_title,$this->request->post('title'),$data); } } $this->success('操作成功', 'javascript:history.back()'); } /** * 上架 * @auth true * @menu true * @throws \think\Exception * @throws \think\db\exception\DataNotFoundException * @throws \think\db\exception\ModelNotFoundException * @throws \think\exception\DbException * @throws \think\exception\PDOException */ public function up() { \app\common\model\Recruit::where('id',input('id'))->update(['status'=>1]); \app\common\model\Recruit::esAdd(input('id')); \app\common\model\TopSearch::saveData(input('id'),'recruit'); $this->success('操作成功'); } /** * 取消 * @auth true * @menu true * @throws \think\Exception * @throws \think\db\exception\DataNotFoundException * @throws \think\db\exception\ModelNotFoundException * @throws \think\exception\DbException * @throws \think\exception\PDOException */ public function down() { \app\common\model\Recruit::where('id',input('id'))->update(['status'=>0]); \app\common\model\Recruit::esAdd(input('id')); \app\common\model\TopSearch::saveData(input('id'),'recruit'); $this->success('操作成功'); } }