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

188 lines
5.1 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\model\legal\LegalCase;
use app\common\server\AreaServer;
use Exception;
use think\facade\Db;
class LegalCaseLogic 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 LegalCase();
$lists = $model->field(true)
->where($where)
->order('sort', 'asc')
->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['is_show'] = $item['is_show'] ? '显示' : '隐藏';
$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 LegalCase();
$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 {
LegalCase::create([
'title' => $post['title'],
'cate_id' => $post['cate_id'] ?? 0,
'content' => $post['content'] ?? '',
'image' => $post['image'] ?? '',
'images' => $post['images'] ?? '',
'contact' => $post['contact'] ?? '',
'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 {
LegalCase::update([
'title' => $post['title'],
'cate_id' => $post['cate_id'] ?? 0,
'content' => $post['content'] ?? '',
'image' => $post['image'] ?? '',
'images' => $post['images'] ?? '',
'contact' => $post['contact'] ?? '',
'is_show' => $post['is_show'],
], ['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 {
LegalCase::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 LegalCase();
$article = $model->findOrEmpty($id)->toArray();
LegalCase::update([
'is_show' => !$article['is_show'],
'update_time' => time()
], ['id'=>$id]);
return true;
} catch (\Exception $e) {
static::$error = $e->getMessage();
return false;
}
}
}