You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
264 lines
8.0 KiB
264 lines
8.0 KiB
<?php
|
|
|
|
|
|
namespace app\admin\logic\job;
|
|
|
|
|
|
use app\common\basics\Logic;
|
|
use app\common\model\job\Job;
|
|
use app\common\model\job\JobSalary;
|
|
use app\common\server\AreaServer;
|
|
use Exception;
|
|
use think\facade\Db;
|
|
|
|
class JobLogic extends Logic
|
|
{
|
|
/**
|
|
* 获取文章分类
|
|
* @param $get
|
|
* @return array
|
|
*/
|
|
public static function lists($get)
|
|
{
|
|
try {
|
|
$where = [
|
|
['del', '=', 0]
|
|
];
|
|
|
|
if (!empty($get['name']) and $get['name'])
|
|
$where[] = ['name', 'like', '%'.$get['name'].'%'];
|
|
|
|
if (!empty($get['cate_id']) and is_numeric($get['cate_id']))
|
|
$where[] = ['cate_id', '=', $get['cate_id']];
|
|
|
|
if (isset($get['industry_id']) and is_numeric($get['industry_id']))
|
|
$where[] = ['industry_id', '=', $get['industry_id']];
|
|
|
|
if (isset($get['salary_id']) and is_numeric($get['salary_id']))
|
|
$where[] = ['salary_id', '=', $get['salary_id']];
|
|
|
|
$model = new Job();
|
|
$lists = $model->field(true)
|
|
->where($where)
|
|
->order('sort', 'asc')
|
|
->paginate([
|
|
'page' => $get['page'],
|
|
'list_rows' => $get['limit'],
|
|
'var_page' => 'page'
|
|
])
|
|
->toArray();
|
|
|
|
$cates1 = Db::name("job_cate")->where(['del'=>0,'is_show'=>1])->select()->toArray();
|
|
$cates = array_column($cates1,"name","id");
|
|
|
|
$salarys1 = Db::name("job_salary")->where(['del'=>0,'is_show'=>1])->select()->toArray();
|
|
$salarys = array_column($salarys1,"value","id");
|
|
|
|
$industry1 = Db::name("job_industry")->where(['del'=>0,'is_show'=>1])->select()->toArray();
|
|
$industry = array_column($industry1,"name","id");
|
|
|
|
$education1 = Db::name("job_education")->where(['del'=>0,'is_show'=>1])->select()->toArray();
|
|
$education = array_column($education1,"name","id");
|
|
|
|
foreach ($lists['data'] as &$item) {
|
|
$item['cate_name'] = $cates[$item['cate_id']] ?? "未知";
|
|
$item['salary_value'] = $salarys[$item['salary_id']] ?? "未知";
|
|
$item['industry_name'] = $industry[$item['industry_id']] ?? "未知";
|
|
$item['education_name'] = $education[$item['education']] ?? "不限";
|
|
$item['is_show'] = $item['is_show'] ? '显示' : '隐藏';
|
|
|
|
$item['username'] = '平台';
|
|
if($item['uid']>0){
|
|
$user = Db::name("user")->field('*')->where('id',$item['uid'])->find();
|
|
if(!empty($user)){
|
|
$item['username'] = $user['nickname'];
|
|
}
|
|
}
|
|
$item['address'] = $item['province_id']?AreaServer::getAddress([
|
|
$item['province_id'],
|
|
$item['city_id'],
|
|
$item['district_id']]):'';
|
|
}
|
|
|
|
return ['count'=>$lists['total'], 'lists'=>$lists['data']];
|
|
} catch (Exception $e) {
|
|
return ['error'=>$e->getMessage()];
|
|
}
|
|
}
|
|
|
|
/**
|
|
* @Notes: 文章详细
|
|
* @Author: 张无忌
|
|
* @param $id
|
|
* @return array
|
|
*/
|
|
public static function detail($id)
|
|
{
|
|
$model = new Job();
|
|
$data = $model->field(true)->findOrEmpty($id)->toArray();
|
|
return $data;
|
|
}
|
|
|
|
/**
|
|
* @Notes: 添加文章
|
|
* @Author: 张无忌
|
|
* @param $post
|
|
* @return bool
|
|
*/
|
|
public static function add($post)
|
|
{
|
|
try {
|
|
Job::create([
|
|
'uid' => 0,
|
|
'name' => $post['name'],
|
|
'intro' => $post['intro'] ?? '',
|
|
'content' => $post['content'] ?? '',
|
|
'contact' => $post['contact'] ?? '',
|
|
'visit' => 0,
|
|
'cate_id' => $post['cate_id'] ?? 0,
|
|
'industry_id' => $post['industry_id'] ?? 0,
|
|
'salary_id' => $post['salary_id'] ?? 0,
|
|
'education' => $post['education'] ?? 1,
|
|
'num' => $post['num'] ?? 1,
|
|
'sort' => $post['sort'] ?? 0,
|
|
'is_show' => $post['is_show'],
|
|
'province_id' => $post['province_id'] ?? 0,
|
|
'city_id' => $post['city_id'] ?? 0,
|
|
'district_id' => $post['district_id'] ?? 0,
|
|
'address_detail' => $post['address_detail'] ?? '',
|
|
]);
|
|
|
|
return true;
|
|
} catch (\Exception $e) {
|
|
static::$error = $e->getMessage();
|
|
return false;
|
|
}
|
|
}
|
|
|
|
/**
|
|
* @Notes: 编辑文章
|
|
* @Author: 张无忌
|
|
* @param $post
|
|
* @return bool
|
|
*/
|
|
public static function edit($post)
|
|
{
|
|
try {
|
|
Job::update([
|
|
'uid' => 0,
|
|
'name' => $post['name'],
|
|
'intro' => $post['intro'] ?? '',
|
|
'content' => $post['content'] ?? '',
|
|
'contact' => $post['contact'] ?? '',
|
|
'visit' => 0,
|
|
'cate_id' => $post['cate_id'] ?? 0,
|
|
'industry_id' => $post['industry_id'] ?? 0,
|
|
'salary_id' => $post['salary_id'] ?? 0,
|
|
'education' => $post['education'] ?? 1,
|
|
'num' => $post['num'] ?? 1,
|
|
'sort' => $post['sort'] ?? 0,
|
|
'is_show' => $post['is_show'],
|
|
'province_id' => $post['province_id'] ?? 0,
|
|
'city_id' => $post['city_id'] ?? 0,
|
|
'district_id' => $post['district_id'] ?? 0,
|
|
'address_detail' => $post['address_detail'] ?? '',
|
|
], ['id'=>$post['id']]);
|
|
|
|
return true;
|
|
} catch (\Exception $e) {
|
|
static::$error = $e->getMessage();
|
|
return false;
|
|
}
|
|
}
|
|
|
|
/**
|
|
* @Notes: 删除
|
|
* @Author: 张无忌
|
|
* @param $id
|
|
* @return bool
|
|
*/
|
|
public static function del($id)
|
|
{
|
|
try {
|
|
Job::update([
|
|
'del' => 1,
|
|
'update_time' => time()
|
|
], ['id'=>$id]);
|
|
|
|
return true;
|
|
} catch (\Exception $e) {
|
|
static::$error = $e->getMessage();
|
|
return false;
|
|
}
|
|
}
|
|
|
|
/**
|
|
* @Notes: 隐藏
|
|
* @Author: 张无忌
|
|
* @param $id
|
|
* @return bool
|
|
*/
|
|
public static function hide($id)
|
|
{
|
|
try {
|
|
$model = new Job();
|
|
$article = $model->findOrEmpty($id)->toArray();
|
|
|
|
Job::update([
|
|
'is_show' => !$article['is_show'],
|
|
'update_time' => time()
|
|
], ['id'=>$id]);
|
|
|
|
return true;
|
|
} catch (\Exception $e) {
|
|
static::$error = $e->getMessage();
|
|
return false;
|
|
}
|
|
}
|
|
|
|
|
|
/**
|
|
* @notes 审核文章
|
|
* @param $post
|
|
* @return bool
|
|
* @author 段誉
|
|
* @date 2022/5/12 16:57
|
|
*/
|
|
public static function audit($post)
|
|
{
|
|
$article = Job::findOrEmpty($post['id']);
|
|
$article->audit_status = $post['audit_status'];
|
|
$article->audit_remark = $post['audit_remark'] ?? '';
|
|
$article->audit_time = time();
|
|
$article->save();
|
|
return true;
|
|
}
|
|
|
|
|
|
/**
|
|
* @Notes: 获取分类
|
|
* @Author: 张无忌
|
|
* @return array
|
|
*/
|
|
public static function getEducation($pid=0)
|
|
{
|
|
try {
|
|
if($pid == 0){
|
|
return Db::name("job_education")->field(true)
|
|
->where(['del'=>0, 'is_show'=>1])
|
|
->order('id', 'desc')
|
|
->select()
|
|
->toArray();
|
|
}else{
|
|
return Db::name("job_education")->field(true)
|
|
->where(['del'=>0, 'is_show'=>1,'id'=>$pid])
|
|
->find();
|
|
}
|
|
|
|
} catch (\Exception $e) {
|
|
return [];
|
|
}
|
|
}
|
|
|
|
|
|
}
|
|
|