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.8 KiB
206 lines
5.8 KiB
<?php
|
|
|
|
|
|
namespace app\admin\logic\content;
|
|
|
|
|
|
use app\common\basics\Logic;
|
|
use app\common\model\content\Help;
|
|
use app\common\model\content\Resource;
|
|
use app\common\server\AreaServer;
|
|
use app\common\server\UrlServer;
|
|
use Exception;
|
|
|
|
class ResourceLogic 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['cid']) and is_numeric($get['cid']))
|
|
$where[] = ['cid', '=', $get['cid']];
|
|
|
|
|
|
$model = new Resource();
|
|
$lists = $model->field(true)
|
|
->where($where)
|
|
->with(['category'])
|
|
->order('sort', 'asc')
|
|
->paginate([
|
|
'page' => $get['page'],
|
|
'list_rows' => $get['limit'],
|
|
'var_page' => 'page'
|
|
])
|
|
->toArray();
|
|
|
|
|
|
foreach ($lists['data'] as &$item) {
|
|
$item['category'] = $item['category']['name'] ?? '未知';
|
|
if($item['cid2']){
|
|
$cates = ResourceCategoryLogic::detail($item['cid2']);
|
|
$item['category2'] = $cates ? $cates['name'] : '无';
|
|
}else{
|
|
$item['category2'] = '无';
|
|
}
|
|
|
|
$item['is_show'] = $item['is_show'] ? '显示' : '隐藏';
|
|
$item['path'] = $item['path']?UrlServer::getFileUrl($item['path']):'';
|
|
$item['path_name']= $item['path']?substr($item['path'],strrpos($item['path'],"/")+1):'';
|
|
|
|
$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()];
|
|
}
|
|
}
|
|
|
|
public static function getAddr(){
|
|
|
|
}
|
|
/**
|
|
* @Notes: 资料详细
|
|
* @Author:
|
|
* @param $id
|
|
* @return array
|
|
*/
|
|
public static function detail($id)
|
|
{
|
|
$model = new Resource();
|
|
$detail = $model->field(true)->findOrEmpty($id)->toArray();
|
|
// $detail['path'] = UrlServer::getFileUrl($detail['path']);
|
|
return $detail;
|
|
}
|
|
|
|
/**
|
|
* @Notes: 添加帮助
|
|
* @Author:
|
|
* @param $post
|
|
* @return bool
|
|
*/
|
|
public static function add($post)
|
|
{
|
|
try {
|
|
Resource::create([
|
|
'cid' => $post['cid'],
|
|
'cid2' => $post['cid2'],
|
|
'title' => $post['title'],
|
|
'image' => $post['image'] ?? '',
|
|
'path' => $post['path'] ?? '',
|
|
'intro' => $post['intro'] ?? '',
|
|
'content' => $post['content'] ?? '',
|
|
'price' => $post['price'] ?? 0.00,
|
|
'type' => $post['type'] ?? 0,
|
|
'province_id' => $post['province_id'] ?? 0,
|
|
'city_id' => $post['city_id'] ?? 0,
|
|
'district_id' => $post['district_id'] ?? 0,
|
|
'visit' => 0,
|
|
'likes' => 0,
|
|
'download' => 0,
|
|
'sort' => $post['sort'] ?? 0,
|
|
'is_show' => $post['is_show']
|
|
]);
|
|
|
|
return true;
|
|
} catch (\Exception $e) {
|
|
static::$error = $e->getMessage();
|
|
return false;
|
|
}
|
|
}
|
|
|
|
/**
|
|
* @Notes: 编辑帮助
|
|
* @Author: 张无忌
|
|
* @param $post
|
|
* @return bool
|
|
*/
|
|
public static function edit($post)
|
|
{
|
|
try {
|
|
Resource::update([
|
|
'cid' => $post['cid'],
|
|
'cid2' => $post['cid2'],
|
|
'title' => $post['title'],
|
|
'image' => $post['image'] ?? '',
|
|
'path' => $post['path'] ?? '',
|
|
'intro' => $post['intro'] ?? '',
|
|
'content' => $post['content'] ?? '',
|
|
'price' => $post['price'] ?? 0.00,
|
|
'type' => $post['type'] ?? 0,
|
|
'province_id' => $post['province_id'] ?? 0,
|
|
'city_id' => $post['city_id'] ?? 0,
|
|
'district_id' => $post['district_id'] ?? 0,
|
|
'visit' => 0,
|
|
'likes' => 0,
|
|
'download' => 0,
|
|
'sort' => $post['sort'] ?? 0,
|
|
'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 {
|
|
Resource::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 Resource();
|
|
$article = $model->findOrEmpty($id)->toArray();
|
|
|
|
Resource::update([
|
|
'is_show' => !$article['is_show'],
|
|
'update_time' => time()
|
|
], ['id'=>$id]);
|
|
|
|
return true;
|
|
} catch (\Exception $e) {
|
|
static::$error = $e->getMessage();
|
|
return false;
|
|
}
|
|
}
|
|
}
|