|
...
|
...
|
@@ -28,20 +28,21 @@ class NewsLogic extends BaseLogic |
|
|
|
* @author :liyuhang
|
|
|
|
* @method
|
|
|
|
*/
|
|
|
|
public function news_get_category_list(){
|
|
|
|
public function news_get_category_list()
|
|
|
|
{
|
|
|
|
$this->map['status'] = 0;
|
|
|
|
$this->map['project_id'] = $this->user['project_id'];
|
|
|
|
$newsCategoryModel = new NewsCategoryModel();
|
|
|
|
$cate_list = $newsCategoryModel->list($this->map,'sort');
|
|
|
|
if($cate_list === false){
|
|
|
|
$this->fail('error',Code::USER_ERROR);
|
|
|
|
$cate_list = $newsCategoryModel->list($this->map, 'sort');
|
|
|
|
if ($cate_list === false) {
|
|
|
|
$this->fail('error', Code::USER_ERROR);
|
|
|
|
}
|
|
|
|
$list = [];
|
|
|
|
foreach ($cate_list as $v){
|
|
|
|
foreach ($cate_list as $v) {
|
|
|
|
$v = (array)$v;
|
|
|
|
if ($v['pid'] == 0) {
|
|
|
|
$v['sub'] = _get_child($v['id'], $cate_list);
|
|
|
|
$list[] = $v;
|
|
|
|
$list[] = $v;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return $this->success($list);
|
|
...
|
...
|
@@ -54,28 +55,29 @@ class NewsLogic extends BaseLogic |
|
|
|
* @method :post
|
|
|
|
* @time :2023/9/7 11:02
|
|
|
|
*/
|
|
|
|
public function newsSave(){
|
|
|
|
public function newsSave()
|
|
|
|
{
|
|
|
|
//拼接参数
|
|
|
|
DB::beginTransaction();
|
|
|
|
try {
|
|
|
|
$this->param = $this->paramProcessing($this->param);
|
|
|
|
if(isset($this->param['id']) && !empty($this->param['id'])){
|
|
|
|
if (isset($this->param['id']) && !empty($this->param['id'])) {
|
|
|
|
//是否更新路由
|
|
|
|
$id = $this->editNewsRoute($this->param['id'],$this->param['url']);
|
|
|
|
$this->edit($this->param,['id'=>$this->param['id']]);
|
|
|
|
}else{
|
|
|
|
$id = $this->editNewsRoute($this->param['id'], $this->param['url']);
|
|
|
|
$this->edit($this->param, ['id' => $this->param['id']]);
|
|
|
|
} else {
|
|
|
|
$id = $this->model->addReturnId($this->param);
|
|
|
|
}
|
|
|
|
//更新路由
|
|
|
|
$route = RouteMap::setRoute($this->param['url'], RouteMap::SOURCE_NEWS, $id, $this->user['project_id']);
|
|
|
|
$this->edit(['url'=>$route],['id'=>$id]);
|
|
|
|
$this->edit(['url' => $route], ['id' => $id]);
|
|
|
|
DB::commit();
|
|
|
|
}catch (\Exception $e){
|
|
|
|
} catch (\Exception $e) {
|
|
|
|
DB::rollBack();
|
|
|
|
$this->fail('添加失败');
|
|
|
|
}
|
|
|
|
//通知更新
|
|
|
|
$this->updateNotify(['project_id'=>$this->user['project_id'], 'type'=>RouteMap::SOURCE_NEWS, 'route'=>$route]);
|
|
|
|
$this->updateNotify(['project_id' => $this->user['project_id'], 'type' => RouteMap::SOURCE_NEWS, 'route' => $route]);
|
|
|
|
return $this->success();
|
|
|
|
}
|
|
|
|
|
|
...
|
...
|
@@ -86,13 +88,14 @@ class NewsLogic extends BaseLogic |
|
|
|
* @method :post
|
|
|
|
* @time :2023/9/7 11:05
|
|
|
|
*/
|
|
|
|
public function editNewsRoute($id,$route){
|
|
|
|
public function editNewsRoute($id, $route)
|
|
|
|
{
|
|
|
|
//生成一条删除路由记录
|
|
|
|
$info = $this->model->read(['id'=>$id],['id','url']);
|
|
|
|
if($info['url'] != $route){
|
|
|
|
$info = $this->model->read(['id' => $id], ['id', 'url']);
|
|
|
|
if ($info['url'] != $route) {
|
|
|
|
$data = [
|
|
|
|
'source'=>RouteMap::SOURCE_NEWS,
|
|
|
|
'route'=>$info['url'],
|
|
|
|
'source' => RouteMap::SOURCE_NEWS,
|
|
|
|
'route' => $info['url'],
|
|
|
|
];
|
|
|
|
$this->setRouteDeleteSave($data);
|
|
|
|
}
|
|
...
|
...
|
@@ -106,10 +109,11 @@ class NewsLogic extends BaseLogic |
|
|
|
* @author :liyuhang
|
|
|
|
* @method
|
|
|
|
*/
|
|
|
|
public function edit_seo(){
|
|
|
|
public function edit_seo()
|
|
|
|
{
|
|
|
|
$this->param['operator_id'] = $this->user['id'];
|
|
|
|
$rs = $this->model->edit($this->param,['id'=>$this->param['id']]);
|
|
|
|
if($rs === false){
|
|
|
|
$rs = $this->model->edit($this->param, ['id' => $this->param['id']]);
|
|
|
|
if ($rs === false) {
|
|
|
|
$this->fail('error');
|
|
|
|
}
|
|
|
|
return $this->success();
|
|
...
|
...
|
@@ -122,10 +126,11 @@ class NewsLogic extends BaseLogic |
|
|
|
* @author :liyuhang
|
|
|
|
* @method
|
|
|
|
*/
|
|
|
|
public function news_status(){
|
|
|
|
public function news_status()
|
|
|
|
{
|
|
|
|
$this->param['operator_id'] = $this->user['id'];
|
|
|
|
$rs = $this->model->edit($this->param,['id'=>['in',$this->param['id']]]);
|
|
|
|
if($rs === false){
|
|
|
|
$rs = $this->model->edit($this->param, ['id' => ['in', $this->param['id']]]);
|
|
|
|
if ($rs === false) {
|
|
|
|
$this->fail('error');
|
|
|
|
}
|
|
|
|
return $this->success();
|
|
...
|
...
|
@@ -138,7 +143,8 @@ class NewsLogic extends BaseLogic |
|
|
|
* @author :liyuhang
|
|
|
|
* @method
|
|
|
|
*/
|
|
|
|
public function newsInfo(){
|
|
|
|
public function newsInfo()
|
|
|
|
{
|
|
|
|
$info = $this->model->read($this->param);
|
|
|
|
$info['image_link'] = getImageUrl($info['image']);
|
|
|
|
$newsCategoryLogic = new NewsCategoryLogic();
|
|
...
|
...
|
@@ -152,15 +158,16 @@ class NewsLogic extends BaseLogic |
|
|
|
* @author :liyuhang
|
|
|
|
* @method
|
|
|
|
*/
|
|
|
|
public function newsDel(){
|
|
|
|
public function newsDel()
|
|
|
|
{
|
|
|
|
DB::beginTransaction();
|
|
|
|
try {
|
|
|
|
foreach ($this->param['id'] as $id){
|
|
|
|
foreach ($this->param['id'] as $id) {
|
|
|
|
$this->delRoute($id);
|
|
|
|
$this->model->del(['id'=>$id]);
|
|
|
|
$this->model->del(['id' => $id]);
|
|
|
|
}
|
|
|
|
DB::commit();
|
|
|
|
}catch (Exception $e){
|
|
|
|
} catch (Exception $e) {
|
|
|
|
DB::rollBack();
|
|
|
|
$this->fail('error');
|
|
|
|
}
|
|
...
|
...
|
@@ -173,18 +180,19 @@ class NewsLogic extends BaseLogic |
|
|
|
* @method :post
|
|
|
|
* @time :2023/6/13 11:30
|
|
|
|
*/
|
|
|
|
public function paramProcessing($param){
|
|
|
|
if(isset($this->param['id'])){
|
|
|
|
public function paramProcessing($param)
|
|
|
|
{
|
|
|
|
if (isset($this->param['id'])) {
|
|
|
|
$param['operator_id'] = $this->user['id'];
|
|
|
|
if(isset($param['category_id']) && !empty($param['category_id'])){
|
|
|
|
$param['category_id'] = ','.trim($param['category_id'],',').',';
|
|
|
|
if (isset($param['category_id']) && !empty($param['category_id'])) {
|
|
|
|
$param['category_id'] = ',' . trim($param['category_id'], ',') . ',';
|
|
|
|
}
|
|
|
|
}else{
|
|
|
|
} else {
|
|
|
|
$param['create_id'] = $this->user['id'];
|
|
|
|
$param['operator_id'] = $this->user['id'];
|
|
|
|
$param['project_id'] = $this->user['project_id'];
|
|
|
|
if(isset($param['category_id']) && !empty($param['category_id'])){
|
|
|
|
$param['category_id'] = ','.$param['category_id'].',';
|
|
|
|
if (isset($param['category_id']) && !empty($param['category_id'])) {
|
|
|
|
$param['category_id'] = ',' . $param['category_id'] . ',';
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return $this->success($param);
|
|
...
|
...
|
@@ -197,14 +205,15 @@ class NewsLogic extends BaseLogic |
|
|
|
* @method :post
|
|
|
|
* @time :2023/6/19 9:42
|
|
|
|
*/
|
|
|
|
public function getStatusNumber(){
|
|
|
|
public function getStatusNumber()
|
|
|
|
{
|
|
|
|
//三种状态 0:草稿 1:发布 2:回收站
|
|
|
|
$data = ['dra'=>0,'pub'=>1,'del'=>2,'tal'=>3];
|
|
|
|
foreach ($data as $k => $v){
|
|
|
|
if($v == 3){
|
|
|
|
$data[$k] = $this->model->where(['project_id'=>$this->user['project_id']])->count();
|
|
|
|
}else{
|
|
|
|
$data[$k] = $this->model->where(['status'=>$v,'project_id'=>$this->user['project_id']])->count();
|
|
|
|
$data = ['dra' => 0, 'pub' => 1, 'del' => 2, 'tal' => 3];
|
|
|
|
foreach ($data as $k => $v) {
|
|
|
|
if ($v == 3) {
|
|
|
|
$data[$k] = $this->model->where(['project_id' => $this->user['project_id']])->count();
|
|
|
|
} else {
|
|
|
|
$data[$k] = $this->model->where(['status' => $v, 'project_id' => $this->user['project_id']])->count();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return $this->success($data);
|
|
...
|
...
|
@@ -217,9 +226,10 @@ class NewsLogic extends BaseLogic |
|
|
|
* @method :post
|
|
|
|
* @time :2023/8/19 11:16
|
|
|
|
*/
|
|
|
|
public function setSort(){
|
|
|
|
$rs = $this->model->edit(['sort'=>$this->param['sort']],['id'=>$this->param['id']]);
|
|
|
|
if($rs === false){
|
|
|
|
public function setSort()
|
|
|
|
{
|
|
|
|
$rs = $this->model->edit(['sort' => $this->param['sort']], ['id' => $this->param['id']]);
|
|
|
|
if ($rs === false) {
|
|
|
|
$this->fail('error');
|
|
|
|
}
|
|
|
|
return $this->success();
|
|
...
|
...
|
@@ -232,16 +242,28 @@ class NewsLogic extends BaseLogic |
|
|
|
* @method :post
|
|
|
|
* @time :2023/9/7 10:50
|
|
|
|
*/
|
|
|
|
public function delRoute($id){
|
|
|
|
public function delRoute($id)
|
|
|
|
{
|
|
|
|
//删除路由映射
|
|
|
|
RouteMap::delRoute(RouteMap::SOURCE_NEWS, $id, $this->user['project_id']);
|
|
|
|
//生成一条删除路由记录
|
|
|
|
$info = $this->model->read(['id'=>$id],['id','url']);
|
|
|
|
$info = $this->model->read(['id' => $id], ['id', 'url']);
|
|
|
|
$data = [
|
|
|
|
'source'=>RouteMap::SOURCE_NEWS,
|
|
|
|
'route'=>$info['url'],
|
|
|
|
'source' => RouteMap::SOURCE_NEWS,
|
|
|
|
'route' => $info['url'],
|
|
|
|
];
|
|
|
|
$this->setRouteDeleteSave($data);
|
|
|
|
return $this->success();
|
|
|
|
}
|
|
|
|
|
|
|
|
public function importNews($project_id, $user_id, $data)
|
|
|
|
{
|
|
|
|
$category_id = '';
|
|
|
|
if (!empty($data[2])) {
|
|
|
|
//处理分类
|
|
|
|
$newsCategoryLogic = new NewsCategoryLogic();
|
|
|
|
$category_id = $newsCategoryLogic->importNewsCategory($project_id, $user_id, $data[2]);
|
|
|
|
}
|
|
|
|
dd($category_id);
|
|
|
|
}
|
|
|
|
} |
...
|
...
|
|