NewsLogic.php
4.2 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
<?php
namespace App\Http\Logic\Bside\News;
use App\Enums\Common\Code;
use App\Http\Logic\Bside\BaseLogic;
use App\Models\News\News;
use App\Models\News\NewsCategory as NewsCategoryModel;
use App\Models\RouteMap;
use Illuminate\Support\Facades\DB;
class NewsLogic extends BaseLogic
{
public function __construct()
{
parent::__construct();
$this->model = new News();
$this->param = $this->requestAll;
}
/**
* @name :获取分类列表
* @return array
* @throws \App\Exceptions\BsideGlobalException
* @author :liyuhang
* @method
*/
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);
}
$list = [];
foreach ($cate_list as $v){
$v = (array)$v;
if ($v['pid'] == 0) {
$v['sub'] = _get_child($v['id'], $cate_list);
$list[] = $v;
}
}
return $this->success($list);
}
/**
* @name :添加博客
* @return void
* @author :liyuhang
* @method
*/
public function news_add(){
$this->param['create_id'] = $this->uid;
$this->param['operator_id'] = $this->uid;
$this->param['project_id'] = $this->user['project_id'];
DB::beginTransaction();
try {
$rs = $this->model->insertGetId($this->param);
RouteMap::setRoute($this->param['url'], RouteMap::SOURCE_NEWS, $rs, $this->user['project_id']);
DB::commit();
}catch (\Exception $e){
DB::rollBack();
$this->fail('error',Code::USER_ERROR);
}
//TODO::写入日志
$this->success();
}
/**
* @name :编辑
* @return void
* @throws \App\Exceptions\BsideGlobalException
* @author :liyuhang
* @method
*/
public function news_edit(){
$this->param['operator_id'] = $this->user['id'];
//多个分类按逗号隔开
$this->param['category_id'] = ','.$this->param['category_id'].',';
$rs = $this->model->edit($this->param,['id'=>$this->param['id']]);
if($rs === false){
$this->fail('error',Code::USER_ERROR);
}
//TODO::写入日志
$this->success();
}
/**
* @name :修改状态
* @return void
* @throws \App\Exceptions\BsideGlobalException
* @author :liyuhang
* @method
*/
public function news_status(){
$this->param['operator_id'] = $this->user['id'];
$rs = $this->model->edit($this->param,['id'=>$this->param['id']]);
if($rs === false){
$this->fail('error',Code::USER_ERROR);
}
//TODO::写入日志
$this->success();
}
/**
* @name :获取详情
* @return array
* @throws \App\Exceptions\BsideGlobalException
* @author :liyuhang
* @method
*/
public function news_info(){
$this->param = $this->requestAll;
$info = $this->model->read($this->param);
//获取分类名称
$info['category_id'] = explode(',',trim($info['category_id'],','));
$newsCategoryModel = new NewsCategoryModel();
$category_list = $newsCategoryModel->list(['id'=>['in',$info['category_id']]],'id',['name']);
$str = '';
foreach ($category_list as $v){
$str .= $v['name'].',';
}
$info['category_id'] = trim($str,',');
if($info === false){
$this->fail('error',Code::USER_ERROR);
}
return $this->success($info);
}
/**
* @name :逻辑删除
* @return void
* @author :liyuhang
* @method
*/
public function news_del(){
$this->param['id'] = ['in',$this->param['id']];
$rs = $this->model->edit(['status'=>2,'operator_id'=>$this->user['id']],$this->param);
if($rs === false){
$this->fail('error',Code::USER_ERROR);
}
return $this->success();
}
}