Recruit.php 6.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210
  1. <?php
  2. namespace app\operate\controller;
  3. use app\common\model\ChinaArea;
  4. use app\common\model\User;
  5. use library\Controller;
  6. use think\Db;
  7. /**
  8. * 招聘
  9. * Class Activity
  10. * @package app\operate\controller
  11. */
  12. class Recruit extends Controller
  13. {
  14. protected $table = 'Recruit';
  15. /**
  16. * 列表
  17. * @auth true
  18. * @menu true
  19. * @throws \think\Exception
  20. * @throws \think\db\exception\DataNotFoundException
  21. * @throws \think\db\exception\ModelNotFoundException
  22. * @throws \think\exception\DbException
  23. * @throws \think\exception\PDOException
  24. */
  25. public function index()
  26. {
  27. $this->title = '列表';
  28. $where = [];
  29. $where[] = ['f.is_deleted','=',0];
  30. if($title = input('title')) $where[] = ['f.title','like','%'.$title.'%'];
  31. $query = $this->_query($this->table)->alias('f')
  32. ->field('f.*')
  33. ->where($where)
  34. ->order('sort desc,f.id desc ')->page();
  35. }
  36. /**
  37. * 添加
  38. * @auth true
  39. * @menu true
  40. * @throws \think\Exception
  41. * @throws \think\db\exception\DataNotFoundException
  42. * @throws \think\db\exception\ModelNotFoundException
  43. * @throws \think\exception\DbException
  44. * @throws \think\exception\PDOException
  45. */
  46. public function add()
  47. {
  48. $this->title = '添加';
  49. $this->_form($this->table, 'form');
  50. }
  51. /**
  52. * 编辑
  53. * @auth true
  54. * @menu true
  55. * @throws \think\Exception
  56. * @throws \think\db\exception\DataNotFoundException
  57. * @throws \think\db\exception\ModelNotFoundException
  58. * @throws \think\exception\DbException
  59. * @throws \think\exception\PDOException
  60. */
  61. public function edit()
  62. {
  63. $this->title = '编辑';
  64. if(input('test'))
  65. {
  66. $this->_form($this->table, 'form3');
  67. }else{
  68. $this->_form($this->table, 'form');
  69. }
  70. }
  71. /**
  72. * 删除
  73. * @auth true
  74. * @throws \think\Exception
  75. * @throws \think\exception\PDOException
  76. */
  77. public function del()
  78. {
  79. \app\common\model\Recruit::where('id',input('id'))->update(['is_deleted'=>1]);
  80. \app\common\model\Recruit::esAdd(input('id'));
  81. \app\common\model\TopSearch::saveData(input('id'),'recruit');
  82. $this->success('操作成功');
  83. }
  84. /**
  85. * 删除
  86. * @auth true
  87. * @throws \think\Exception
  88. * @throws \think\exception\PDOException
  89. */
  90. public function remove()
  91. {
  92. $ids = input('id');
  93. foreach (explode(',',$ids) as $id) {
  94. \app\common\model\Recruit::where('id',$id)->update(['is_deleted'=>1]);
  95. \app\common\model\Recruit::esAdd($id);
  96. \app\common\model\TopSearch::saveData($id,'recruit');
  97. }
  98. $this->success('已删除!');
  99. }
  100. /**
  101. * 表单数据处理
  102. * @param array $data
  103. */
  104. protected function _form_filter(&$data)
  105. {
  106. // if($this->request->isPost()) $this->error('页面调试中');
  107. $this->education = ['不限','高中及以上','专科及以上','本科及以上','研究生及以上'];
  108. $all_area = $all_area = ChinaArea::where('level','<=',3)->select();
  109. $this->all_area = make_tree($all_area);
  110. $all_cate = \app\common\model\RecruitCate::where(['is_deleted'=>0])->order('sort desc ,id desc')->select();
  111. $this->cate_tree = make_tree($all_cate);
  112. if ($this->request->isGet() && $this->request->action() == 'add') {
  113. $this->isAddMode = 1;
  114. $this->ladder = [];
  115. }
  116. if ($this->request->isGet() && $this->request->action() == 'edit') {
  117. $this->isAddMode = 0;
  118. $this->ladder = isset_full($data,'ladder') ? json_decode($data['ladder'],true):[];
  119. }
  120. if($this->request->isGet()) {
  121. $third_classify = input('third_classify');
  122. if($third_classify) {
  123. if($third_classify) $data['third_classify'] = $third_classify;
  124. $third_info = \app\common\model\RecruitCate::where('id',$third_classify)->find()->toArray();
  125. if($third_classify) $data['second_classify'] = $third_info['pid'];
  126. $data['first_classify'] = \app\common\model\RecruitCate::where('id',$data['second_classify'])->value('pid');
  127. }
  128. }
  129. if($this->request->isPost())
  130. {
  131. list($post,$ladder_data) = [$this->request->post(),[]];
  132. if(!$data['longitude'] || !$data['latitude']) $this->error('请选择地图坐标');
  133. if(!$data['release_time']) $data['release_time'] = date("Y-m-d H:i:s");
  134. if($data['hot_num'] != $data['hot_num_old']) $data['hot_time'] = date("Y-m-d H:i:s");
  135. if(!empty($post['user_phone'])) {
  136. $user_id = User::where('phone|email',$post['user_phone'])->value('id');
  137. if(!$user_id) $this->error('账号未注册');
  138. $data['user_id'] = $user_id;
  139. }else{
  140. $data['user_id'] = '';
  141. }
  142. }
  143. }
  144. protected function _form_result(&$data)
  145. {
  146. \app\common\model\Recruit::esAdd($data);
  147. \app\common\model\TopSearch::saveData($data,'recruit');
  148. $this->success('操作成功', 'javascript:history.back()');
  149. }
  150. /**
  151. * 上架
  152. * @auth true
  153. * @menu true
  154. * @throws \think\Exception
  155. * @throws \think\db\exception\DataNotFoundException
  156. * @throws \think\db\exception\ModelNotFoundException
  157. * @throws \think\exception\DbException
  158. * @throws \think\exception\PDOException
  159. */
  160. public function up()
  161. {
  162. \app\common\model\Recruit::where('id',input('id'))->update(['status'=>1]);
  163. \app\common\model\Recruit::esAdd(input('id'));
  164. \app\common\model\TopSearch::saveData(input('id'),'recruit');
  165. $this->success('操作成功');
  166. }
  167. /**
  168. * 取消
  169. * @auth true
  170. * @menu true
  171. * @throws \think\Exception
  172. * @throws \think\db\exception\DataNotFoundException
  173. * @throws \think\db\exception\ModelNotFoundException
  174. * @throws \think\exception\DbException
  175. * @throws \think\exception\PDOException
  176. */
  177. public function down()
  178. {
  179. \app\common\model\Recruit::where('id',input('id'))->update(['status'=>0]);
  180. \app\common\model\Recruit::esAdd(input('id'));
  181. \app\common\model\TopSearch::saveData(input('id'),'recruit');
  182. $this->success('操作成功');
  183. }
  184. }