安徽博创起重服务端程序
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.
 
 
 
 
 

206 lines
5.5 KiB

<?php
namespace app\admin\logic\legal;
use app\common\basics\Logic;
use app\common\model\job\Job;
use app\common\model\job\JobSalary;
use app\common\model\legal\Legal;
use app\common\server\AreaServer;
use Exception;
use think\facade\Db;
class LegalLogic extends Logic
{
/**
* 获取文章分类
* @param $get
* @return array
*/
public static function lists($get)
{
try {
$where = [
['del', '=', 0]
];
if (!empty($get['title']) and $get['title'])
$where[] = ['title', 'like', '%'.$get['title'].'%'];
if (!empty($get['cate_id']) and is_numeric($get['cate_id']))
$where[] = ['cate_id', '=', $get['cate_id']];
$model = new Legal();
$lists = $model->field(true)
->where($where)
->paginate([
'page' => $get['page'],
'list_rows' => $get['limit'],
'var_page' => 'page'
])
->toArray();
$cates1 = Db::name("legal_cate")->where(['del'=>0,'is_show'=>1])->select()->toArray();
$cates = array_column($cates1,"name","id");
foreach ($lists['data'] as &$item) {
$item['cate_name'] = $cates[$item['cate_id']] ?? "未知";
$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 Legal();
$data= $model->field(true)->findOrEmpty($id)->toArray();
$data['address'] = $data['province_id']?AreaServer::getAddress([
$data['province_id'],
$data['city_id'],
$data['district_id']]):'';
// $data['images_arr'] = $data['images']? explode(",",$data['images']):[];
return $data;
}
/**
* @Notes: 添加文章
* @Author: 张无忌
* @param $post
* @return bool
*/
public static function add($post)
{
try {
Legal::create([
'title' => $post['title'],
'cate_id' => $post['cate_id'] ?? 0,
'content' => $post['content'] ?? '',
'username' => $post['username'] ?? '',
'mobile' => $post['mobile'] ?? '',
'contact' => $post['contact'] ?? '',
'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 {
Legal::update([
'title' => $post['title'],
'cate_id' => $post['cate_id'] ?? 0,
'content' => $post['content'] ?? '',
'username' => $post['username'] ?? '',
'mobile' => $post['mobile'] ?? '',
'contact' => $post['contact'] ?? '',
'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 {
Legal::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 Legal();
$article = $model->findOrEmpty($id)->toArray();
Legal::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 handle($post)
{
$article = Legal::findOrEmpty($post['id']);
$article->handle_status = 1;
$article->handle_remark = $post['handle_remark'] ?? '';
$article->handle_time = time();
$article->save();
return true;
}
}