BlogLogic.php
1.9 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
<?php
namespace App\Http\Logic\Bside\Blog;
use App\Enums\Common\Code;
use App\Http\Logic\Bside\BaseLogic;
use App\Models\Blog\Blog;
use App\Models\Blog\BlogCategory as BlogCategoryModel;
use App\Models\RouteMap;
use Illuminate\Support\Facades\DB;
class BlogLogic extends BaseLogic
{
public function __construct()
{
parent::__construct();
$this->model = new Blog();
$this->param = $this->requestAll;
}
/**
* @name :添加博客
* @return void
* @author :liyuhang
* @method
*/
public function blog_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_BLOG, $rs, $this->user['project_id']);
DB::commit();
}catch (\Exception $e){
DB::rollBack();
$this->fail('error',Code::USER_ERROR);
}
//TODO::写入日志
$this->success();
}
/**
* @name :获取数据详情
* @return array
* @throws \App\Exceptions\BsideGlobalException
* @author :liyuhang
* @method
*/
public function blog_info(){
$info = $this->model->read($this->param);
//获取分类名称
$info['category_id'] = explode(',',trim($info['category_id'],','));
$blogCategoryModel = new BlogCategoryModel();
$category_list = $blogCategoryModel->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);
}
}