作者 liyuhang

gx

1 <?php 1 <?php
2 - 2 +namespace comCommon;
3 use Illuminate\Support\Facades\Log; 3 use Illuminate\Support\Facades\Log;
4 4
5 -function set_openai(){  
6 -// {  
7 -// "messages": [  
8 -// {  
9 -// "role": "system",  
10 -// "content": "You are a helpful assistant."  
11 -// },  
12 -// {  
13 -// "role": "user",  
14 -// "content": "宁波大学地址?"  
15 -// },  
16 -// {  
17 -// "role": "assistant",  
18 -// "content": "宁波大学的地址是浙江省宁波市江北区风华路818号。"  
19 -// },  
20 -// {  
21 -// "role": "user",  
22 -// "content": "占地面积是多少?"  
23 -// }  
24 -// ]  
25 -//}  
26 -}  
27 -/**  
28 - * 发送http post请求  
29 - * @param type $url  
30 - * @param type $post_data  
31 - */  
32 -function http_post($url, $post_data)  
33 -{  
34 - $header[] = "charset = UTF-8";  
35 - $ch = curl_init();  
36 - curl_setopt($ch, CURLOPT_URL, $url);  
37 - curl_setopt($ch, CURLOPT_CUSTOMREQUEST, "POST");  
38 - curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);  
39 - curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, 0);  
40 - curl_setopt($ch, CURLOPT_HTTPHEADER, $header);  
41 - curl_setopt($ch, CURLOPT_USERAGENT, 'Mozilla/5.0 (compatible; MSIE 5.01; Windows NT 5.0)');  
42 - curl_setopt($ch, CURLOPT_FOLLOWLOCATION, 1);  
43 - curl_setopt($ch, CURLOPT_AUTOREFERER, 1);  
44 - curl_setopt($ch, CURLOPT_POSTFIELDS, $post_data);  
45 - curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);  
46 - $res = curl_exec($ch);  
47 - if (curl_errno($ch)) {  
48 - Log::write(print_r(curl_errno($ch),1),'debug---1'); 5 +
  6 +if(!function_exists('http_post')){
  7 + /**
  8 + * 发送http post请求
  9 + * @param type $url
  10 + * @param type $post_data
  11 + */
  12 + function http_post($url, $post_data)
  13 + {
  14 + $header[] = "charset = UTF-8";
  15 + $ch = curl_init();
  16 + curl_setopt($ch, CURLOPT_URL, $url);
  17 + curl_setopt($ch, CURLOPT_CUSTOMREQUEST, "POST");
  18 + curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
  19 + curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, 0);
  20 + curl_setopt($ch, CURLOPT_HTTPHEADER, $header);
  21 + curl_setopt($ch, CURLOPT_USERAGENT, 'Mozilla/5.0 (compatible; MSIE 5.01; Windows NT 5.0)');
  22 + curl_setopt($ch, CURLOPT_FOLLOWLOCATION, 1);
  23 + curl_setopt($ch, CURLOPT_AUTOREFERER, 1);
  24 + curl_setopt($ch, CURLOPT_POSTFIELDS, $post_data);
  25 + curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
  26 + $res = curl_exec($ch);
  27 + if (curl_errno($ch)) {
  28 + Log::write(print_r(curl_errno($ch),1),'debug---1');
  29 + }
  30 + curl_close($ch);
  31 + return json_decode($res, true);
49 } 32 }
50 - curl_close($ch);  
51 - return json_decode($res, true);  
52 } 33 }
53 -/**  
54 - * 发送http get请求  
55 - * @param type $url  
56 - * @return type  
57 - */  
58 -function http_get($url)  
59 -{  
60 - $header[] = "content-type: application/x-www-form-urlencoded; 34 +
  35 +if(!function_exists('http_get')){
  36 + /**
  37 + * 发送http get请求
  38 + * @param type $url
  39 + * @return type
  40 + */
  41 + function http_get($url)
  42 + {
  43 + $header[] = "content-type: application/x-www-form-urlencoded;
61 charset = UTF-8"; 44 charset = UTF-8";
62 - $ch1 = curl_init();  
63 - $timeout = 5;  
64 - curl_setopt($ch1, CURLOPT_URL, $url);  
65 - curl_setopt($ch1, CURLOPT_RETURNTRANSFER, 1);  
66 - curl_setopt($ch1, CURLOPT_HTTPHEADER, $header);  
67 - curl_setopt($ch1, CURLOPT_CONNECTTIMEOUT, $timeout);  
68 - curl_setopt($ch1, CURLOPT_SSL_VERIFYPEER, false);  
69 - curl_setopt($ch1, CURLOPT_SSL_VERIFYHOST, false);  
70 - $access_txt = curl_exec($ch1);  
71 - curl_close($ch1);  
72 - return json_decode($access_txt, true); 45 + $ch1 = curl_init();
  46 + $timeout = 5;
  47 + curl_setopt($ch1, CURLOPT_URL, $url);
  48 + curl_setopt($ch1, CURLOPT_RETURNTRANSFER, 1);
  49 + curl_setopt($ch1, CURLOPT_HTTPHEADER, $header);
  50 + curl_setopt($ch1, CURLOPT_CONNECTTIMEOUT, $timeout);
  51 + curl_setopt($ch1, CURLOPT_SSL_VERIFYPEER, false);
  52 + curl_setopt($ch1, CURLOPT_SSL_VERIFYHOST, false);
  53 + $access_txt = curl_exec($ch1);
  54 + curl_close($ch1);
  55 + return json_decode($access_txt, true);
  56 + }
73 } 57 }
  58 +
  59 +if(!function_exists('_get_child')){
  60 + /**
  61 + * 菜单权限->得到子级数组
  62 + * @param int
  63 + * @return array
  64 + */
  65 + function _get_child($my_id, $arr)
  66 + {
  67 + $new_arr = array();
  68 + foreach ($arr as $k => $v) {
  69 + $v = (array)$v;
  70 + if ($v['pid'] == $my_id) {
  71 + $v['sub'] = _get_child($v['id'],$arr);
  72 + $new_arr[] = $v;
  73 + }
  74 + }
  75 + return $new_arr ? $new_arr : false;
  76 + }
  77 +}
  78 +
@@ -16,7 +16,6 @@ class BaseController extends Controller @@ -16,7 +16,6 @@ class BaseController extends Controller
16 protected $param = [];//所有请求参数 16 protected $param = [];//所有请求参数
17 protected $token = ''; //token 17 protected $token = ''; //token
18 protected $request = [];//助手函数 18 protected $request = [];//助手函数
19 - protected $allCount = 0;//总条数  
20 protected $page = 1;//当前页 19 protected $page = 1;//当前页
21 protected $row = 20;//每页条数 20 protected $row = 20;//每页条数
22 protected $header = [];//设置请求头参数 21 protected $header = [];//设置请求头参数
@@ -160,7 +159,7 @@ class BaseController extends Controller @@ -160,7 +159,7 @@ class BaseController extends Controller
160 $param = $this->request->post(); 159 $param = $this->request->post();
161 if($this->request->hasFile('image') && $files->isValid()){ 160 if($this->request->hasFile('image') && $files->isValid()){
162 $filename = date('ymdHis').rand(10000,99999).$this->request->file('image'); 161 $filename = date('ymdHis').rand(10000,99999).$this->request->file('image');
163 - $this->request->file('image')->move('./uploads/images/',$filename); 162 + $this->request->file('image')->move('./uploads/image/',$filename);
164 }else{ 163 }else{
165 return false; 164 return false;
166 } 165 }
@@ -30,16 +30,13 @@ class BlogCategoryController extends BaseController @@ -30,16 +30,13 @@ class BlogCategoryController extends BaseController
30 * @author :liyuhang 30 * @author :liyuhang
31 * @method 31 * @method
32 */ 32 */
33 - public function info(Request $request,BlogCategoryModel $blogCategoryModel){ 33 + public function info(Request $request,BlogCategoryLogic $blogCategoryLogic){
34 $request->validate([ 34 $request->validate([
35 'id'=>['required'] 35 'id'=>['required']
36 ],[ 36 ],[
37 'id.required' => 'ID不能为空' 37 'id.required' => 'ID不能为空'
38 ]); 38 ]);
39 - $info = $blogCategoryModel->read($this->param);  
40 - if($info === false){  
41 - $this->response('error',Code::USER_ERROR);  
42 - } 39 + $info = $blogCategoryLogic->info_blog_category();
43 $this->response('success',Code::SUCCESS,$info); 40 $this->response('success',Code::SUCCESS,$info);
44 } 41 }
45 /** 42 /**
@@ -61,19 +58,15 @@ class BlogCategoryController extends BaseController @@ -61,19 +58,15 @@ class BlogCategoryController extends BaseController
61 * @author :liyuhang 58 * @author :liyuhang
62 * @method 59 * @method
63 */ 60 */
64 - public function edit(BlogCategoryRequest $request,BlogCategoryModel $blogCategoryModel){ 61 + public function edit(BlogCategoryRequest $request,BlogCategoryLogic $blogCategoryLogic){
65 $request->validate([ 62 $request->validate([
66 'id'=>['required'] 63 'id'=>['required']
67 ],[ 64 ],[
68 'id.required' => 'ID不能为空' 65 'id.required' => 'ID不能为空'
69 ]); 66 ]);
70 - $this->param['operator_id'] = $this->uid;  
71 - $rs = $blogCategoryModel->edit($this->param,['id'=>$this->param['id']]);  
72 - if($rs === false){  
73 - $this->response('error',Code::USER_ERROR);  
74 - } 67 + $blogCategoryLogic->edit_blog_category();
75 //TODO::写入日志 68 //TODO::写入日志
76 - $this->response('success',Code::SUCCESS); 69 + $this->response('success');
77 } 70 }
78 71
79 /** 72 /**
@@ -82,17 +75,13 @@ class BlogCategoryController extends BaseController @@ -82,17 +75,13 @@ class BlogCategoryController extends BaseController
82 * @author :liyuhang 75 * @author :liyuhang
83 * @method 76 * @method
84 */ 77 */
85 - public function status(Request $request,BlogCategoryModel $blogCategoryModel){ 78 + public function status(Request $request,BlogCategoryLogic $blogCategoryLogic){
86 $request->validate([ 79 $request->validate([
87 'id'=>['required'], 80 'id'=>['required'],
88 ],[ 81 ],[
89 'id.required' => 'ID不能为空', 82 'id.required' => 'ID不能为空',
90 ]); 83 ]);
91 - $this->param['operator_id'] = $this->uid;  
92 - $rs = $blogCategoryModel->edit($this->param,['id'=>$this->param['id']]);  
93 - if($rs === false){  
94 - $this->response('error',Code::USER_ERROR);  
95 - } 84 + $blogCategoryLogic->status_blog_category();
96 $this->response('success'); 85 $this->response('success');
97 } 86 }
98 87
@@ -25,8 +25,19 @@ class BlogController extends BaseController @@ -25,8 +25,19 @@ class BlogController extends BaseController
25 } 25 }
26 26
27 /** 27 /**
28 - * @name :获取当前博客详情 28 + * @name :获取分页列表
29 * @return void 29 * @return void
  30 + * @throws \App\Exceptions\BsideGlobalException
  31 + * @author :liyuhang
  32 + * @method
  33 + */
  34 + public function get_category_list(BlogLogic $blogLogic){
  35 + $list = $blogLogic->blog_get_category_list();
  36 + $this->response('success',Code::SUCCESS,$list);
  37 + }
  38 + /**
  39 + * @name :获取当前博客详情
  40 + * @return json
30 * @author :liyuhang 41 * @author :liyuhang
31 * @method 42 * @method
32 */ 43 */
@@ -41,13 +52,14 @@ class BlogController extends BaseController @@ -41,13 +52,14 @@ class BlogController extends BaseController
41 } 52 }
42 /** 53 /**
43 * @name :添加博客 54 * @name :添加博客
44 - * @return json 55 + * @return void
45 * @author :liyuhang 56 * @author :liyuhang
46 * @method 57 * @method
47 */ 58 */
48 public function add(BlogRequest $request,BlogLogic $blogLogic){ 59 public function add(BlogRequest $request,BlogLogic $blogLogic){
49 $request->validated(); 60 $request->validated();
50 $blogLogic->blog_add(); 61 $blogLogic->blog_add();
  62 + //TODO::写入日志
51 $this->response('success'); 63 $this->response('success');
52 } 64 }
53 65
@@ -57,18 +69,13 @@ class BlogController extends BaseController @@ -57,18 +69,13 @@ class BlogController extends BaseController
57 * @author :liyuhang 69 * @author :liyuhang
58 * @method 70 * @method
59 */ 71 */
60 - public function edit(BlogRequest $request,BlogModel $blogModel){ 72 + public function edit(BlogRequest $request,BlogLogic $blogLogic){
61 $request->validate([ 73 $request->validate([
62 'id'=>['required'] 74 'id'=>['required']
63 ],[ 75 ],[
64 'id.required' => 'ID不能为空' 76 'id.required' => 'ID不能为空'
65 ]); 77 ]);
66 - $this->param['operator_id'] = $this->uid;  
67 - $rs = $blogModel->edit($this->param,['id'=>$this->param['id']]);  
68 - //TODO::路由映射  
69 - if($rs === false){  
70 - $this->response('error',Code::USER_ERROR);  
71 - } 78 + $blogLogic->blog_edit();
72 //TODO::写入日志 79 //TODO::写入日志
73 $this->response('success'); 80 $this->response('success');
74 } 81 }
@@ -79,17 +86,13 @@ class BlogController extends BaseController @@ -79,17 +86,13 @@ class BlogController extends BaseController
79 * @author :liyuhang 86 * @author :liyuhang
80 * @method 87 * @method
81 */ 88 */
82 - public function status(Request $request,BlogModel $blogModel){ 89 + public function status(Request $request,BlogLogic $blogLogic){
83 $request->validate([ 90 $request->validate([
84 'id'=>['required'], 91 'id'=>['required'],
85 ],[ 92 ],[
86 'id.required' => 'ID不能为空', 93 'id.required' => 'ID不能为空',
87 ]); 94 ]);
88 - $this->param['operator_id'] = $this->uid;  
89 - $rs = $blogModel->edit($this->param,['id'=>$this->param['id']]);  
90 - if($rs === false){  
91 - $this->response('error',Code::USER_ERROR);  
92 - } 95 + $blogLogic->blog_status();
93 //TODO::写入日志 96 //TODO::写入日志
94 $this->response('success'); 97 $this->response('success');
95 } 98 }
@@ -100,17 +103,13 @@ class BlogController extends BaseController @@ -100,17 +103,13 @@ class BlogController extends BaseController
100 * @author :liyuhang 103 * @author :liyuhang
101 * @method 104 * @method
102 */ 105 */
103 - public function del(Request $request,BlogModel $blogModel){ 106 + public function del(Request $request,BlogLogic $blogLogic){
104 $request->validate([ 107 $request->validate([
105 'id'=>['required'], 108 'id'=>['required'],
106 ],[ 109 ],[
107 'id.required' => 'ID不能为空', 110 'id.required' => 'ID不能为空',
108 ]); 111 ]);
109 - $this->param['id'] = ['in',$this->param['id']];  
110 - $rs = $blogModel->edit(['status'=>2],$this->param);  
111 - if($rs === false){  
112 - $this->response('error',Code::USER_ERROR);  
113 - } 112 + $blogLogic->blog_del();
114 $this->response('success'); 113 $this->response('success');
115 } 114 }
116 } 115 }
@@ -119,7 +119,4 @@ class ComController extends BaseController @@ -119,7 +119,4 @@ class ComController extends BaseController
119 $this->response('success'); 119 $this->response('success');
120 } 120 }
121 121
122 - public function uploads(){  
123 -  
124 - }  
125 } 122 }
@@ -32,16 +32,13 @@ class NewsCategoryController extends BaseController @@ -32,16 +32,13 @@ class NewsCategoryController extends BaseController
32 * @author :liyuhang 32 * @author :liyuhang
33 * @method 33 * @method
34 */ 34 */
35 - public function info(Request $request,NewsCategoryModel $newsCategory){ 35 + public function info(Request $request,NewsCategoryLogic $newsCategoryLogic){
36 $request->validate([ 36 $request->validate([
37 'id'=>['required'] 37 'id'=>['required']
38 ],[ 38 ],[
39 'id.required' => 'ID不能为空' 39 'id.required' => 'ID不能为空'
40 ]); 40 ]);
41 - $info = $newsCategory->read($this->param);  
42 - if($info === false){  
43 - $this->response('error',Code::USER_ERROR);  
44 - } 41 + $info = $newsCategoryLogic->info_news_category();
45 $this->response('success',Code::SUCCESS,$info); 42 $this->response('success',Code::SUCCESS,$info);
46 } 43 }
47 /** 44 /**
@@ -64,17 +61,13 @@ class NewsCategoryController extends BaseController @@ -64,17 +61,13 @@ class NewsCategoryController extends BaseController
64 * @author :liyuhang 61 * @author :liyuhang
65 * @method 62 * @method
66 */ 63 */
67 - public function edit(NewsCategoryRequest $request,NewsCategoryModel $newsCategory){ 64 + public function edit(NewsCategoryRequest $request,NewsCategoryLogic $newsCategoryLogic){
68 $request->validate([ 65 $request->validate([
69 'id'=>['required'] 66 'id'=>['required']
70 ],[ 67 ],[
71 'id.required' => 'ID不能为空' 68 'id.required' => 'ID不能为空'
72 ]); 69 ]);
73 - $this->param['operator_id'] = $this->uid;  
74 - $rs = $newsCategory->edit($this->param,['id'=>$this->param['id']]);  
75 - if($rs === false){  
76 - $this->response('error',Code::USER_ERROR);  
77 - } 70 + $newsCategoryLogic->edit_news_category();
78 //TODO::写入日志 71 //TODO::写入日志
79 $this->response('success'); 72 $this->response('success');
80 } 73 }
@@ -85,17 +78,13 @@ class NewsCategoryController extends BaseController @@ -85,17 +78,13 @@ class NewsCategoryController extends BaseController
85 * @author :liyuhang 78 * @author :liyuhang
86 * @method 79 * @method
87 */ 80 */
88 - public function status(Request $request,NewsCategoryModel $newsCategory){ 81 + public function status(Request $request,NewsCategoryLogic $newsCategoryLogic){
89 $request->validate([ 82 $request->validate([
90 'id'=>['required'], 83 'id'=>['required'],
91 ],[ 84 ],[
92 'id.required' => 'ID不能为空', 85 'id.required' => 'ID不能为空',
93 ]); 86 ]);
94 - $this->param['operator_id'] = $this->uid;  
95 - $rs = $newsCategory->edit($this->param,['id'=>$this->param['id']]);  
96 - if($rs === false){  
97 - $this->response('error',Code::USER_ERROR);  
98 - } 87 + $newsCategoryLogic->status_news_category();
99 $this->response('success'); 88 $this->response('success');
100 } 89 }
101 90
@@ -33,21 +33,8 @@ class NewsController extends BaseController @@ -33,21 +33,8 @@ class NewsController extends BaseController
33 * @author :liyuhang 33 * @author :liyuhang
34 * @method 34 * @method
35 */ 35 */
36 - public function get_category_list(NewsCategoryModel $newsCategoryModel){  
37 - $this->map['status'] = 0;  
38 - $this->map['project_id'] = $this->user['project_id'];  
39 - $cate_list = $newsCategoryModel->list($this->map,'sort');  
40 - if($cate_list === false){  
41 - $this->response('error',Code::USER_ERROR);  
42 - }  
43 - $list = [];  
44 - foreach ($cate_list as $k => $v){  
45 - $v = (array)$v;  
46 - if ($v['pid'] == 0) {  
47 - $v['sub'] = $this->_get_child($v['id'], $cate_list);  
48 - $list[] = $v;  
49 - }  
50 - } 36 + public function get_category_list(NewsLogic $newsLogic){
  37 + $list = $newsLogic->news_get_category_list();
51 $this->response('success',Code::SUCCESS,$list); 38 $this->response('success',Code::SUCCESS,$list);
52 } 39 }
53 /** 40 /**
@@ -85,19 +72,13 @@ class NewsController extends BaseController @@ -85,19 +72,13 @@ class NewsController extends BaseController
85 * @author :liyuhang 72 * @author :liyuhang
86 * @method 73 * @method
87 */ 74 */
88 - public function edit(NewsRequest $newsRequest,NewsModel $news){ 75 + public function edit(NewsRequest $newsRequest,NewsLogic $newsLogic){
89 $newsRequest->validate([ 76 $newsRequest->validate([
90 'id'=>['required'], 77 'id'=>['required'],
91 ],[ 78 ],[
92 'id.required' => 'ID不能为空', 79 'id.required' => 'ID不能为空',
93 ]); 80 ]);
94 - $this->param['operator_id'] = $this->uid;  
95 - //多个分类按逗号隔开  
96 - $this->param['category_id'] = ','.$this->param['category_id'].',';  
97 - $rs = $news->edit($this->param,['id'=>$this->param['id']]);  
98 - if($rs === false){  
99 - $this->response('error',Code::USER_ERROR);  
100 - } 81 + $newsLogic->news_edit();
101 //TODO::写入日志 82 //TODO::写入日志
102 $this->response('success',Code::SUCCESS); 83 $this->response('success',Code::SUCCESS);
103 } 84 }
@@ -108,17 +89,13 @@ class NewsController extends BaseController @@ -108,17 +89,13 @@ class NewsController extends BaseController
108 * @author :liyuhang 89 * @author :liyuhang
109 * @method 90 * @method
110 */ 91 */
111 - public function status(Request $request,NewsModel $news){ 92 + public function status(Request $request,NewsLogic $newsLogic){
112 $request->validate([ 93 $request->validate([
113 'id'=>['required'], 94 'id'=>['required'],
114 ],[ 95 ],[
115 'id.required' => 'ID不能为空', 96 'id.required' => 'ID不能为空',
116 ]); 97 ]);
117 - $this->param['operator_id'] = $this->uid;  
118 - $rs = $news->edit($this->param,['id'=>$this->param['id']]);  
119 - if($rs === false){  
120 - $this->response('error',Code::USER_ERROR);  
121 - } 98 + $newsLogic->news_status();
122 //TODO::写入日志 99 //TODO::写入日志
123 $this->response('success'); 100 $this->response('success');
124 } 101 }
@@ -128,17 +105,13 @@ class NewsController extends BaseController @@ -128,17 +105,13 @@ class NewsController extends BaseController
128 * @author :liyuhang 105 * @author :liyuhang
129 * @method 106 * @method
130 */ 107 */
131 - public function del(Request $request,NewsModel $news){ 108 + public function del(Request $request,NewsLogic $newsLogic){
132 $request->validate([ 109 $request->validate([
133 'id'=>['required'], 110 'id'=>['required'],
134 ],[ 111 ],[
135 'id.required' => 'ID不能为空', 112 'id.required' => 'ID不能为空',
136 ]); 113 ]);
137 - $this->param['id'] = ['in',$this->param['id']];d;  
138 - $rs = $news->edit(['status'=>2,'operator_id'=>$this->uid],$this->param);  
139 - if($rs === false){  
140 - $this->response('error',Code::USER_ERROR);  
141 - } 114 + $newsLogic->news_del();
142 //TODO::清空相关资源/写入日志 115 //TODO::清空相关资源/写入日志
143 $this->response('success'); 116 $this->response('success');
144 } 117 }
@@ -3,6 +3,7 @@ @@ -3,6 +3,7 @@
3 namespace App\Http\Controllers\Bside; 3 namespace App\Http\Controllers\Bside;
4 4
5 use App\Enums\Common\Code; 5 use App\Enums\Common\Code;
  6 +use App\Http\Logic\Bside\RoleLogic;
6 use App\Http\Requests\Bside\ProjectRoleRequest; 7 use App\Http\Requests\Bside\ProjectRoleRequest;
7 use App\Models\ProjectMenu as ProjectMenuModel; 8 use App\Models\ProjectMenu as ProjectMenuModel;
8 use App\Models\ProjectRole as ProjectRoleModel; 9 use App\Models\ProjectRole as ProjectRoleModel;
@@ -33,17 +34,14 @@ class ProjectRoleController extends BaseController @@ -33,17 +34,14 @@ class ProjectRoleController extends BaseController
33 * @author :liyuhang 34 * @author :liyuhang
34 * @method 35 * @method
35 */ 36 */
36 - public function info(Request $request,ProjectRoleModel $projectRoleModel){ 37 + public function info(Request $request,RoleLogic $roleLogic){
37 $request->validate([ 38 $request->validate([
38 'id'=>['required', new Ids()], 39 'id'=>['required', new Ids()],
39 ],[ 40 ],[
40 'id.required' => 'ID不能为空', 41 'id.required' => 'ID不能为空',
41 ]); 42 ]);
42 - $rs = $projectRoleModel->read($this->param);  
43 - if($rs === false){  
44 - $this->response('error',Code::USER_ERROR);  
45 - }  
46 - $this->response('success'); 43 + $info = $roleLogic->role_info();
  44 + $this->response('success',Code::SUCCESS,$info);
47 } 45 }
48 /** 46 /**
49 * @name :添加/编辑角色时获取菜单列表 47 * @name :添加/编辑角色时获取菜单列表
@@ -51,20 +49,8 @@ class ProjectRoleController extends BaseController @@ -51,20 +49,8 @@ class ProjectRoleController extends BaseController
51 * @author :liyuhang 49 * @author :liyuhang
52 * @method 50 * @method
53 */ 51 */
54 - public function get_role_menu(ProjectRoleModel $projectRoleModel,ProjectMenuModel $projectMenuModel){  
55 - //根据当前登录用户角色返回用户菜单列表  
56 - $info = $projectRoleModel->read(['id'=>$this->user['role_id']]);  
57 - $info['role_menu'] = trim($info['role_menu'],',');  
58 - $lists = $projectMenuModel->where(['status'=>0])->whereIn('id',explode(',',$info['role_menu']))->get();  
59 - $lists = $lists->toArray();  
60 - $menu = array();  
61 - foreach ($lists as $k => $v){  
62 - $v = (array)$v;  
63 - if ($v['pid'] == 0) {  
64 - $v['sub'] = $this->_get_child($v['id'], $lists);  
65 - $menu[] = $v;  
66 - }  
67 - } 52 + public function get_role_menu(RoleLogic $roleLogic){
  53 + $menu = $roleLogic->role_get_menu();
68 $this->response('当前用户菜单列表',Code::SUCCESS,$menu); 54 $this->response('当前用户菜单列表',Code::SUCCESS,$menu);
69 } 55 }
70 /** 56 /**
@@ -73,20 +59,9 @@ class ProjectRoleController extends BaseController @@ -73,20 +59,9 @@ class ProjectRoleController extends BaseController
73 * @author :liyuhang 59 * @author :liyuhang
74 * @method 60 * @method
75 */ 61 */
76 - public function add(ProjectRoleRequest $request){ 62 + public function add(ProjectRoleRequest $request,RoleLogic $roleLogic){
77 $request->validated(); 63 $request->validated();
78 - $this->param['project_id'] = $this->user['project_id'];  
79 - //获取当前项目下的角色超级管理员  
80 - $projectRoleModel = new ProjectRoleModel();  
81 - //验证当前角色是否存在  
82 - $info = $projectRoleModel->read(['name'=>$this->param['name']]);  
83 - if(!empty($info)){  
84 - $this->response('当前添加的角色已存在',Code::USER_PARAMS_ERROE);  
85 - }  
86 - $rs = $projectRoleModel->add($this->param);  
87 - if($rs === false){  
88 - $this->response('添加失败',Code::USER_PARAMS_ERROE);  
89 - } 64 + $roleLogic->role_add();
90 $this->response('添加成功'); 65 $this->response('添加成功');
91 } 66 }
92 67
@@ -96,26 +71,13 @@ class ProjectRoleController extends BaseController @@ -96,26 +71,13 @@ class ProjectRoleController extends BaseController
96 * @author :liyuhang 71 * @author :liyuhang
97 * @method 72 * @method
98 */ 73 */
99 - public function edit(ProjectRoleRequest $request,ProjectRoleModel $projectRoleModel){ 74 + public function edit(ProjectRoleRequest $request,RoleLogic $roleLogic){
100 $request->validate([ 75 $request->validate([
101 'id'=>['required'] 76 'id'=>['required']
102 ],[ 77 ],[
103 'id.required' => 'ID不能为空' 78 'id.required' => 'ID不能为空'
104 ]); 79 ]);
105 - //TODO::查询当前名称是否重复  
106 - $condition = [  
107 - ['id'=>['!=',$this->param['id']]],  
108 - ['name'=>$this->param['name']],  
109 - ['project_id'=>$this->user['project_id']],  
110 - ];  
111 - $info = $projectRoleModel->formatQuery($condition)->first();  
112 - if(!empty($info)){  
113 - $this->response('当前添加的角色已存在',Code::USER_PARAMS_ERROE);  
114 - }  
115 - $rs = $projectRoleModel->edit($this->param,['id'=>$this->param['id']]);  
116 - if($rs === false){  
117 - $this->response('编辑失败',Code::USER_PARAMS_ERROE);  
118 - } 80 + $roleLogic->role_edit();
119 $this->response('编辑成功'); 81 $this->response('编辑成功');
120 } 82 }
121 83
@@ -125,19 +87,14 @@ class ProjectRoleController extends BaseController @@ -125,19 +87,14 @@ class ProjectRoleController extends BaseController
125 * @author :liyuhang 87 * @author :liyuhang
126 * @method 88 * @method
127 */ 89 */
128 - public function status(Request $request,ProjectRoleModel $projectRoleModel){ 90 + public function status(Request $request,RoleLogic $roleLogic){
129 $request->validate([ 91 $request->validate([
130 'id'=>['required'], 92 'id'=>['required'],
131 - 'status'=>['required'],  
132 ],[ 93 ],[
133 'id.required' => 'ID不能为空', 94 'id.required' => 'ID不能为空',
134 - 'status.required' => 'status不能为空'  
135 ]); 95 ]);
136 - $rs = $projectRoleModel->edit(['status'=>$this->param['status']],['id'=>$this->param['id']]);  
137 - if($rs === false){  
138 - $this->response('编辑失败',Code::USER_PARAMS_ERROE);  
139 - }  
140 - $this->response($this->param['status'] == 0 ? '启用成功' : '禁用成功',Code::SUCCESS); 96 + $roleLogic->role_status();
  97 + $this->response($this->param['status'] == 0 ? '启用成功' : '禁用成功');
141 } 98 }
142 99
143 /** 100 /**
@@ -146,22 +103,13 @@ class ProjectRoleController extends BaseController @@ -146,22 +103,13 @@ class ProjectRoleController extends BaseController
146 * @author :liyuhang 103 * @author :liyuhang
147 * @method 104 * @method
148 */ 105 */
149 - public function del(Request $request,ProjectRoleModel $projectRoleModel){ 106 + public function del(Request $request,RoleLogic $roleLogic){
150 $request->validate([ 107 $request->validate([
151 'id'=>['required'] 108 'id'=>['required']
152 ],[ 109 ],[
153 'id.required' => 'ID不能为空' 110 'id.required' => 'ID不能为空'
154 ]); 111 ]);
155 - //查询当前角色下是否有用户  
156 - $userModel = new UserModel();  
157 - $user_info = $userModel->read(['role_id'=>$this->param['id']]);  
158 - if(!empty($user_info)){  
159 - $this->response('当前角色下有用户存在,不允许删除',Code::USER_ERROR);  
160 - }  
161 - $rs = $projectRoleModel->del(['id'=>$this->param['id']]);  
162 - if($rs === false){  
163 - $this->response('error',Code::USER_ERROR);  
164 - } 112 + $roleLogic->role_del();
165 $this->response('success'); 113 $this->response('success');
166 } 114 }
167 } 115 }
@@ -3,6 +3,7 @@ @@ -3,6 +3,7 @@
3 namespace App\Http\Controllers\Bside; 3 namespace App\Http\Controllers\Bside;
4 4
5 use App\Enums\Common\Code; 5 use App\Enums\Common\Code;
  6 +use App\Http\Logic\Bside\UserLogic;
6 use App\Http\Requests\Bside\UserRequest; 7 use App\Http\Requests\Bside\UserRequest;
7 use App\Models\User as UserModel; 8 use App\Models\User as UserModel;
8 use App\Rules\Ids; 9 use App\Rules\Ids;
@@ -32,14 +33,10 @@ class UserController extends BaseController @@ -32,14 +33,10 @@ class UserController extends BaseController
32 * @author :liyuhang 33 * @author :liyuhang
33 * @method 34 * @method
34 */ 35 */
35 - public function add(UserRequest $request,UserModel $userModel){ 36 + public function add(UserRequest $request,UserLogic $userLogic){
36 $request->validated(); 37 $request->validated();
37 - $this->param['project_id'] = $this->user['project_id'];  
38 - $rs = $userModel->adds($this->param);  
39 - if($rs === false){  
40 - $this->response('当前添加用户已存在或参数错误,添加失败',Code::USER_REGISTER_ERROE,[]);  
41 - }  
42 - $this->response('success',Code::SUCCESS); 38 + $userLogic->user_add();
  39 + $this->response('success');
43 } 40 }
44 41
45 /** 42 /**
@@ -48,22 +45,14 @@ class UserController extends BaseController @@ -48,22 +45,14 @@ class UserController extends BaseController
48 * @author :liyuhang 45 * @author :liyuhang
49 * @method 46 * @method
50 */ 47 */
51 - public function edit(UserRequest $request,UserModel $userModel){ 48 + public function edit(UserRequest $request,UserLogic $userLogic){
52 $request->validate([ 49 $request->validate([
53 'id'=>['required'] 50 'id'=>['required']
54 ],[ 51 ],[
55 'id.required' => 'ID不能为空' 52 'id.required' => 'ID不能为空'
56 ]); 53 ]);
57 - $info = $userModel->where('id','<>',$this->param['id'])  
58 - ->where(['mobile'=>$this->param['mobile']])->first();  
59 - if(!empty($info)){  
60 - $this->response('当前编辑的手机号码已存在',Code::USER_PARAMS_ERROE);  
61 - }  
62 - $rs = $userModel->edits($this->param);  
63 - if($rs === false){  
64 - $this->response('参数错误或其他服务器原因,编辑失败',Code::USER_ERROR,[]);  
65 - }  
66 - $this->response('编辑成功',Code::SUCCESS,[]); 54 + $userLogic->user_edit();
  55 + $this->response('success');
67 } 56 }
68 57
69 /** 58 /**
@@ -72,18 +61,13 @@ class UserController extends BaseController @@ -72,18 +61,13 @@ class UserController extends BaseController
72 * @author :liyuhang 61 * @author :liyuhang
73 * @method 62 * @method
74 */ 63 */
75 - public function status(Request $request,UserModel $userModel){ 64 + public function status(Request $request,UserLogic $userLogic){
76 $request->validate([ 65 $request->validate([
77 'id'=>['required'], 66 'id'=>['required'],
78 - 'status'=>['required'],  
79 ],[ 67 ],[
80 'id.required' => 'ID不能为空', 68 'id.required' => 'ID不能为空',
81 - 'status.required' => 'status不能为空'  
82 ]); 69 ]);
83 - $rs = $userModel->edit($this->param,['id'=>$this->param['id']]);  
84 - if($rs === false){  
85 - $this->response('error',Code::USER_ERROR);  
86 - } 70 + $userLogic->user_status();
87 $this->response($this->param['status'] == 0 ? '启用成功' : '禁用成功'); 71 $this->response($this->param['status'] == 0 ? '启用成功' : '禁用成功');
88 } 72 }
89 73
@@ -93,16 +77,13 @@ class UserController extends BaseController @@ -93,16 +77,13 @@ class UserController extends BaseController
93 * @author :liyuhang 77 * @author :liyuhang
94 * @method 78 * @method
95 */ 79 */
96 - public function info(Request $request,UserModel $userModel){ 80 + public function info(Request $request,UserLogic $userLogic){
97 $request->validate([ 81 $request->validate([
98 - 'id'=>['required', new Ids()], 82 + 'id'=>['required'],
99 ],[ 83 ],[
100 'id.required' => 'ID不能为空', 84 'id.required' => 'ID不能为空',
101 ]); 85 ]);
102 - $rs = $userModel->read($this->param);  
103 - if($rs === false){  
104 - $this->response('error',Code::USER_ERROR);  
105 - } 86 + $userLogic->user_info();
106 $this->response('success'); 87 $this->response('success');
107 } 88 }
108 /** 89 /**
@@ -111,16 +92,13 @@ class UserController extends BaseController @@ -111,16 +92,13 @@ class UserController extends BaseController
111 * @author :liyuhang 92 * @author :liyuhang
112 * @method 93 * @method
113 */ 94 */
114 - public function del(Request $request,UserModel $userModel){ 95 + public function del(Request $request,UserLogic $userLogic){
115 $request->validate([ 96 $request->validate([
116 - 'id'=>['required', new Ids()], 97 + 'id'=>['required'],
117 ],[ 98 ],[
118 'id.required' => 'ID不能为空', 99 'id.required' => 'ID不能为空',
119 ]); 100 ]);
120 - $rs = $userModel->del($this->param);  
121 - if($rs === false){  
122 - $this->response('error',Code::USER_ERROR);  
123 - } 101 + $userLogic->user_del();
124 $this->response('success'); 102 $this->response('success');
125 } 103 }
126 } 104 }
@@ -16,6 +16,8 @@ class BaseLogic @@ -16,6 +16,8 @@ class BaseLogic
16 16
17 protected $requestAll; 17 protected $requestAll;
18 18
  19 + protected $param;
  20 +
19 protected $user; 21 protected $user;
20 22
21 protected $is_cache = true; //是否缓存数据 23 protected $is_cache = true; //是否缓存数据
@@ -6,6 +6,7 @@ use App\Enums\Common\Code; @@ -6,6 +6,7 @@ use App\Enums\Common\Code;
6 use App\Http\Logic\Bside\BaseLogic; 6 use App\Http\Logic\Bside\BaseLogic;
7 use App\Models\Blog\BlogCategory as BlogCategoryModel; 7 use App\Models\Blog\BlogCategory as BlogCategoryModel;
8 use App\Models\Blog\Blog as BlogModel; 8 use App\Models\Blog\Blog as BlogModel;
  9 +use App\Models\News\NewsCategory as NewsCategoryModel;
9 use Illuminate\Support\Facades\DB; 10 use Illuminate\Support\Facades\DB;
10 11
11 class BlogCategoryLogic extends BaseLogic 12 class BlogCategoryLogic extends BaseLogic
@@ -15,8 +16,10 @@ class BlogCategoryLogic extends BaseLogic @@ -15,8 +16,10 @@ class BlogCategoryLogic extends BaseLogic
15 parent::__construct(); 16 parent::__construct();
16 17
17 $this->model = new BlogCategoryModel(); 18 $this->model = new BlogCategoryModel();
  19 + $this->param = $this->requestAll;
18 } 20 }
19 21
  22 +
20 /** 23 /**
21 * @name :添加时验证上级分类是否有商品,有则替换带当前分类下 24 * @name :添加时验证上级分类是否有商品,有则替换带当前分类下
22 * @return void 25 * @return void
@@ -25,7 +28,6 @@ class BlogCategoryLogic extends BaseLogic @@ -25,7 +28,6 @@ class BlogCategoryLogic extends BaseLogic
25 */ 28 */
26 public function add_blog_category(){ 29 public function add_blog_category(){
27 DB::beginTransaction(); 30 DB::beginTransaction();
28 - $this->param = $this->requestAll;  
29 $this->param['project_id'] = $this->user['project_id']; 31 $this->param['project_id'] = $this->user['project_id'];
30 $this->param['operator_id'] = $this->user['id']; 32 $this->param['operator_id'] = $this->user['id'];
31 $this->param['create_id'] = $this->user['id']; 33 $this->param['create_id'] = $this->user['id'];
@@ -62,6 +64,51 @@ class BlogCategoryLogic extends BaseLogic @@ -62,6 +64,51 @@ class BlogCategoryLogic extends BaseLogic
62 } 64 }
63 65
64 /** 66 /**
  67 + * @name :编辑分类
  68 + * @return void
  69 + * @throws \App\Exceptions\BsideGlobalException
  70 + * @author :liyuhang
  71 + * @method
  72 + */
  73 + public function edit_blog_category(){
  74 + $this->param['operator_id'] = $this->user['id'];
  75 + $rs = $this->model->edit($this->param,['id'=>$this->param['id']]);
  76 + if($rs === false){
  77 + $this->fail('error',Code::USER_ERROR);
  78 + }
  79 + return $this->success();
  80 + }
  81 +
  82 + /**
  83 + * @name :详情
  84 + * @return array
  85 + * @throws \App\Exceptions\BsideGlobalException
  86 + * @author :liyuhang
  87 + * @method
  88 + */
  89 + public function info_blog_category(){
  90 + $info = $this->model->read($this->param);
  91 + if($info === false){
  92 + $this->fail('error',Code::USER_ERROR);
  93 + }
  94 + return $this->success($info);
  95 + }
  96 +
  97 + /**
  98 + * @name :编辑状态与排序
  99 + * @return void
  100 + * @author :liyuhang
  101 + * @method
  102 + */
  103 + public function status_blog_category(){
  104 + $this->param['operator_id'] = $this->user['id'];
  105 + $rs = $this->model->edit($this->param,['id'=>$this->param['id']]);
  106 + if($rs === false){
  107 + $this->fail('error',Code::USER_ERROR);
  108 + }
  109 + return $this->success();
  110 + }
  111 + /**
65 * @name :删除博客分类 112 * @name :删除博客分类
66 * @return void 113 * @return void
67 * @author :liyuhang 114 * @author :liyuhang
@@ -87,5 +134,6 @@ class BlogCategoryLogic extends BaseLogic @@ -87,5 +134,6 @@ class BlogCategoryLogic extends BaseLogic
87 if($rs === false){ 134 if($rs === false){
88 $this->response('error',Code::USER_ERROR); 135 $this->response('error',Code::USER_ERROR);
89 } 136 }
  137 + return $this->success();
90 } 138 }
91 } 139 }
@@ -18,7 +18,31 @@ class BlogLogic extends BaseLogic @@ -18,7 +18,31 @@ class BlogLogic extends BaseLogic
18 $this->model = new Blog(); 18 $this->model = new Blog();
19 $this->param = $this->requestAll; 19 $this->param = $this->requestAll;
20 } 20 }
21 - 21 + /**
  22 + * @name :获取分类列表
  23 + * @return array
  24 + * @throws \App\Exceptions\BsideGlobalException
  25 + * @author :liyuhang
  26 + * @method
  27 + */
  28 + public function blog_get_category_list(){
  29 + $this->map['status'] = 0;
  30 + $this->map['project_id'] = $this->user['project_id'];
  31 + $blogCategoryModel = new BlogCategoryModel();
  32 + $cate_list = $blogCategoryModel->list($this->map,'sort');
  33 + if($cate_list === false){
  34 + $this->fail('error',Code::USER_ERROR);
  35 + }
  36 + $list = [];
  37 + foreach ($cate_list as $v){
  38 + $v = (array)$v;
  39 + if ($v['pid'] == 0) {
  40 + $v['sub'] = _get_child($v['id'], $cate_list);
  41 + $list[] = $v;
  42 + }
  43 + }
  44 + return $this->success($list);
  45 + }
22 /** 46 /**
23 * @name :添加博客 47 * @name :添加博客
24 * @return void 48 * @return void
@@ -41,6 +65,26 @@ class BlogLogic extends BaseLogic @@ -41,6 +65,26 @@ class BlogLogic extends BaseLogic
41 //TODO::写入日志 65 //TODO::写入日志
42 $this->success(); 66 $this->success();
43 } 67 }
  68 +
  69 + /**
  70 + * @name : 编辑用户
  71 + * @return void
  72 + * @throws \App\Exceptions\BsideGlobalException
  73 + * @author :liyuhang
  74 + * @method
  75 + */
  76 + public function blog_edit(){
  77 + $this->param['operator_id'] = $this->uid;
  78 + DB::beginTransaction();
  79 + try {
  80 + $this->model->edit($this->param,['id'=>$this->param['id']]);
  81 + RouteMap::setRoute($this->param['url'], RouteMap::SOURCE_BLOG, $this->param['id'], $this->user['project_id']);
  82 + DB::commit();
  83 + }catch (\Exception $e){
  84 + DB::rollBack();
  85 + $this->fail('error',Code::USER_ERROR);
  86 + }
  87 + }
44 /** 88 /**
45 * @name :获取数据详情 89 * @name :获取数据详情
46 * @return array 90 * @return array
@@ -64,4 +108,35 @@ class BlogLogic extends BaseLogic @@ -64,4 +108,35 @@ class BlogLogic extends BaseLogic
64 } 108 }
65 return $this->success($info); 109 return $this->success($info);
66 } 110 }
  111 +
  112 + /**
  113 + * @name :修改状态
  114 + * @return array
  115 + * @throws \App\Exceptions\BsideGlobalException
  116 + * @author :liyuhang
  117 + * @method
  118 + */
  119 + public function blog_status(){
  120 + $this->param['operator_id'] = $this->user['id'];
  121 + $rs = $this->model->edit($this->param,['id'=>$this->param['id']]);
  122 + if($rs === false){
  123 + $this->fail('error',Code::USER_ERROR);
  124 + }
  125 + return $this->success();
  126 + }
  127 +
  128 + /**
  129 + * @name :逻辑删除
  130 + * @return void
  131 + * @author :liyuhang
  132 + * @method
  133 + */
  134 + public function blog_del(){
  135 + $this->param['id'] = ['in',$this->param['id']];
  136 + $rs = $this->model->edit(['status'=>2],$this->param);
  137 + if($rs === false){
  138 + $this->fail('error',Code::USER_ERROR);
  139 + }
  140 + return $this->success();
  141 + }
67 } 142 }
  1 +<?php
  2 +
  3 +namespace App\Http\Logic\Bside;
  4 +
  5 +use App\Models\ProjectGroup;
  6 +
  7 +class GroupLogic extends BaseLogic
  8 +{
  9 + public function __construct()
  10 + {
  11 + parent::__construct();
  12 +
  13 + $this->model = new ProjectGroup();
  14 + $this->param = $this->requestAll;
  15 + }
  16 +}
@@ -15,6 +15,22 @@ class NewsCategoryLogic extends BaseLogic @@ -15,6 +15,22 @@ class NewsCategoryLogic extends BaseLogic
15 parent::__construct(); 15 parent::__construct();
16 16
17 $this->model = new NewsCategoryModel(); 17 $this->model = new NewsCategoryModel();
  18 + $this->param = $this->requestAll;
  19 + }
  20 +
  21 + /**
  22 + * @name :详情
  23 + * @return array
  24 + * @throws \App\Exceptions\BsideGlobalException
  25 + * @author :liyuhang
  26 + * @method
  27 + */
  28 + public function info_news_category(){
  29 + $info = $this->model->read($this->param);
  30 + if($info === false){
  31 + $this->fail('error',Code::USER_ERROR);
  32 + }
  33 + return $this->success($info);
18 } 34 }
19 /** 35 /**
20 * @name :添加时验证上级分类是否有商品,有则替换带当前分类下 36 * @name :添加时验证上级分类是否有商品,有则替换带当前分类下
@@ -24,7 +40,7 @@ class NewsCategoryLogic extends BaseLogic @@ -24,7 +40,7 @@ class NewsCategoryLogic extends BaseLogic
24 */ 40 */
25 public function add_news_category(){ 41 public function add_news_category(){
26 DB::beginTransaction(); 42 DB::beginTransaction();
27 - $this->param = $this->requestAll; 43 +
28 $this->param['project_id'] = $this->user['project_id']; 44 $this->param['project_id'] = $this->user['project_id'];
29 $this->param['operator_id'] = $this->user['id']; 45 $this->param['operator_id'] = $this->user['id'];
30 $this->param['create_id'] = $this->user['id']; 46 $this->param['create_id'] = $this->user['id'];
@@ -61,6 +77,36 @@ class NewsCategoryLogic extends BaseLogic @@ -61,6 +77,36 @@ class NewsCategoryLogic extends BaseLogic
61 } 77 }
62 78
63 /** 79 /**
  80 + * @name :编辑分类
  81 + * @return void
  82 + * @author :liyuhang
  83 + * @method
  84 + */
  85 + public function edit_news_category(){
  86 + $this->param['operator_id'] = $this->user['id'];
  87 + $rs = $this->model->edit($this->param,['id'=>$this->param['id']]);
  88 + if($rs === false){
  89 + $this->fail('error',Code::USER_ERROR);
  90 + }
  91 + return $this->success();
  92 + }
  93 +
  94 + /**
  95 + * @name :修改状态
  96 + * @return array
  97 + * @throws \App\Exceptions\BsideGlobalException
  98 + * @author :liyuhang
  99 + * @method
  100 + */
  101 + public function status_news_category(){
  102 + $this->param['operator_id'] = $this->user['id'];
  103 + $rs = $this->model->edit($this->param,['id'=>$this->param['id']]);
  104 + if($rs === false){
  105 + $this->fail('error',Code::USER_ERROR);
  106 + }
  107 + return $this->success();
  108 + }
  109 + /**
64 * @name :删除新闻分类 110 * @name :删除新闻分类
65 * @return array 111 * @return array
66 * @throws \App\Exceptions\BsideGlobalException 112 * @throws \App\Exceptions\BsideGlobalException
@@ -20,6 +20,32 @@ class NewsLogic extends BaseLogic @@ -20,6 +20,32 @@ class NewsLogic extends BaseLogic
20 } 20 }
21 21
22 /** 22 /**
  23 + * @name :获取分类列表
  24 + * @return array
  25 + * @throws \App\Exceptions\BsideGlobalException
  26 + * @author :liyuhang
  27 + * @method
  28 + */
  29 + public function news_get_category_list(){
  30 + $this->map['status'] = 0;
  31 + $this->map['project_id'] = $this->user['project_id'];
  32 + $newsCategoryModel = new NewsCategoryModel();
  33 + $cate_list = $newsCategoryModel->list($this->map,'sort');
  34 + if($cate_list === false){
  35 + $this->fail('error',Code::USER_ERROR);
  36 + }
  37 + $list = [];
  38 + foreach ($cate_list as $v){
  39 + $v = (array)$v;
  40 + if ($v['pid'] == 0) {
  41 + $v['sub'] = _get_child($v['id'], $cate_list);
  42 + $list[] = $v;
  43 + }
  44 + }
  45 + return $this->success($list);
  46 + }
  47 +
  48 + /**
23 * @name :添加博客 49 * @name :添加博客
24 * @return void 50 * @return void
25 * @author :liyuhang 51 * @author :liyuhang
@@ -44,6 +70,41 @@ class NewsLogic extends BaseLogic @@ -44,6 +70,41 @@ class NewsLogic extends BaseLogic
44 } 70 }
45 71
46 /** 72 /**
  73 + * @name :编辑
  74 + * @return void
  75 + * @throws \App\Exceptions\BsideGlobalException
  76 + * @author :liyuhang
  77 + * @method
  78 + */
  79 + public function news_edit(){
  80 + $this->param['operator_id'] = $this->user['id'];
  81 + //多个分类按逗号隔开
  82 + $this->param['category_id'] = ','.$this->param['category_id'].',';
  83 + $rs = $this->model->edit($this->param,['id'=>$this->param['id']]);
  84 + if($rs === false){
  85 + $this->fail('error',Code::USER_ERROR);
  86 + }
  87 + //TODO::写入日志
  88 + $this->success();
  89 + }
  90 +
  91 + /**
  92 + * @name :修改状态
  93 + * @return void
  94 + * @throws \App\Exceptions\BsideGlobalException
  95 + * @author :liyuhang
  96 + * @method
  97 + */
  98 + public function news_status(){
  99 + $this->param['operator_id'] = $this->user['id'];
  100 + $rs = $this->model->edit($this->param,['id'=>$this->param['id']]);
  101 + if($rs === false){
  102 + $this->fail('error',Code::USER_ERROR);
  103 + }
  104 + //TODO::写入日志
  105 + $this->success();
  106 + }
  107 + /**
47 * @name :获取详情 108 * @name :获取详情
48 * @return array 109 * @return array
49 * @throws \App\Exceptions\BsideGlobalException 110 * @throws \App\Exceptions\BsideGlobalException
@@ -67,4 +128,19 @@ class NewsLogic extends BaseLogic @@ -67,4 +128,19 @@ class NewsLogic extends BaseLogic
67 } 128 }
68 return $this->success($info); 129 return $this->success($info);
69 } 130 }
  131 +
  132 + /**
  133 + * @name :逻辑删除
  134 + * @return void
  135 + * @author :liyuhang
  136 + * @method
  137 + */
  138 + public function news_del(){
  139 + $this->param['id'] = ['in',$this->param['id']];
  140 + $rs = $this->model->edit(['status'=>2,'operator_id'=>$this->user['id']],$this->param);
  141 + if($rs === false){
  142 + $this->fail('error',Code::USER_ERROR);
  143 + }
  144 + return $this->success();
  145 + }
70 } 146 }
  1 +<?php
  2 +
  3 +namespace App\Http\Logic\Bside;
  4 +
  5 +use App\Enums\Common\Code;
  6 +use App\Models\ProjectMenu as ProjectMenuModel;
  7 +use App\Models\ProjectRole as ProjectRoleModel;
  8 +use App\Models\User;
  9 +use App\Models\User as UserModel;
  10 +
  11 +class RoleLogic extends BaseLogic
  12 +{
  13 + public function __construct()
  14 + {
  15 + parent::__construct();
  16 + $this->model = new ProjectRoleModel();
  17 + $this->param = $this->requestAll;
  18 + }
  19 +
  20 + /**
  21 + * @name :添加角色
  22 + * @return void
  23 + * @author :liyuhang
  24 + * @method
  25 + */
  26 + public function role_add(){
  27 + $this->param['create_id'] = $this->user['id'];
  28 + $this->param['operator_id'] = $this->user['id'];
  29 + $this->param['project_id'] = $this->user['project_id'];
  30 + //验证当前角色是否存在
  31 + $info = $this->model->read(['name'=>$this->param['name']]);
  32 + if($info !== false){
  33 + $this->fail('当前添加的角色已存在',Code::USER_ERROR);
  34 + }
  35 + $rs = $this->model->add($this->param);
  36 + if($rs === false){
  37 + $this->fail('添加失败',Code::USER_PARAMS_ERROE);
  38 + }
  39 + return $this->success();
  40 + }
  41 +
  42 + /**
  43 + * @name :编辑角色
  44 + * @return void
  45 + * @author :liyuhang
  46 + * @method
  47 + */
  48 + public function role_edit(){
  49 + //TODO::查询当前名称是否重复
  50 + $condition = [
  51 + ['id'=>['!=',$this->param['id']]],
  52 + ['name'=>$this->param['name']],
  53 + ['project_id'=>$this->user['project_id']],
  54 + ];
  55 + $info = $this->model->read($condition);
  56 + if($info !== false){
  57 + $this->fail('当前添加的角色已存在',Code::USER_PARAMS_ERROE);
  58 + }
  59 + $rs = $this->model->edit($this->param,['id'=>$this->param['id']]);
  60 + if($rs === false){
  61 + $this->fail('编辑失败',Code::USER_PARAMS_ERROE);
  62 + }
  63 + return $this->success();
  64 + }
  65 +
  66 + /**
  67 + * @name :修改状态/排序
  68 + * @return void
  69 + * @author :liyuhang
  70 + * @method
  71 + */
  72 + public function role_status(){
  73 + $rs = $this->model->edit($this->param,['id'=>$this->param['id']]);
  74 + if($rs === false){
  75 + $this->fail('error',Code::USER_PARAMS_ERROE);
  76 + }
  77 + return $this->success();
  78 + }
  79 +
  80 + /**
  81 + * @name :删除角色
  82 + * @return void
  83 + * @author :liyuhang
  84 + */
  85 + public function role_del(){
  86 + //查询当前角色下是否有用户
  87 + $userModel = new UserModel();
  88 + //批量删除
  89 + foreach ($this->param['id'] as $v){
  90 + $user_info = $userModel->read(['role_id'=>$v]);
  91 + if(!empty($user_info)){
  92 + $this->fail('当前角色下有用户存在,不允许删除',Code::USER_ERROR);
  93 + }
  94 + }
  95 + $this->param['id'] = ['in',$this->param['id']];
  96 + $rs = $this->model->del(['id'=>$this->param['id']]);
  97 + if($rs === false){
  98 + $this->fail('error',Code::USER_ERROR);
  99 + }
  100 + return $this->success();
  101 + }
  102 +
  103 + /**
  104 + * @name :获取角色详情
  105 + * @return void
  106 + * @author :liyuhang
  107 + * @method
  108 + */
  109 + public function role_info(){
  110 + $info = $this->model->read($this->param);
  111 + if($info === false){
  112 + $this->fail('error',Code::USER_ERROR);
  113 + }
  114 + return $this->success($info);
  115 + }
  116 +
  117 + /**
  118 + * @name :获取菜单列表
  119 + * @return array
  120 + * @author :liyuhang
  121 + * @method
  122 + */
  123 + public function role_get_menu(){
  124 + //根据当前登录用户角色返回用户菜单列表
  125 + $info = $this->model->read(['id'=>$this->user['role_id']]);
  126 + $info['role_menu'] = trim($info['role_menu'],',');
  127 + $menuModel = new ProjectMenu();
  128 + $lists = $menuModel->where(['status'=>0])->whereIn('id',explode(',',$info['role_menu']))->get();
  129 + $lists = $lists->toArray();
  130 + $menu = array();
  131 + foreach ($lists as $k => $v){
  132 + $v = (array)$v;
  133 + if ($v['pid'] == 0) {
  134 + $v['sub'] = $this->_get_child($v['id'], $lists);
  135 + $menu[] = $v;
  136 + }
  137 + }
  138 + return $this->success($menu);
  139 + }
  140 +}
  1 +<?php
  2 +
  3 +namespace App\Http\Logic\Bside;
  4 +
  5 +use App\Enums\Common\Code;
  6 +use App\Models\Department;
  7 +use App\Models\User;
  8 +
  9 +class UserLogic extends BaseLogic
  10 +{
  11 + public function __construct()
  12 + {
  13 + parent::__construct();
  14 +
  15 + $this->model = new User();
  16 + $this->param = $this->requestAll;
  17 + }
  18 +
  19 + /**
  20 + * @name :添加会员
  21 + * @author :liyuhang
  22 + */
  23 + public function user_add(){
  24 + $this->param['create_id'] = $this->user['id'];
  25 + $this->param['operator_id'] = $this->user['id'];
  26 + $this->param['project_id'] = $this->user['project_id'];
  27 + //验证当前用户是否存在
  28 + $info = $this->model->read(['mobile'=>$this->param['mobile']]);
  29 + if($info !== false){
  30 + $this->fail('error',Code::USER_ERROR);
  31 + }
  32 + //密码加密
  33 + $param['password'] = base64_encode(md5($this->param['password']));
  34 + $rs = $this->model->add($param);
  35 + if($rs === false){
  36 + $this->fail('error',Code::USER_ERROR);
  37 + }
  38 + return $this->success();
  39 + }
  40 +
  41 + /**
  42 + * @name :编辑用户
  43 + * @author :liyuhang
  44 + */
  45 + public function user_edit(){
  46 + $condition = [
  47 + ['id'=>['!=',$this->param['id']]],
  48 + ['mobile'=>$this->param['mobile']]
  49 + ];
  50 + $info = $this->model->read($condition);
  51 + if($info !== false){
  52 + $this->fail('当前编辑的手机号码已存在',Code::USER_PARAMS_ERROE);
  53 + }
  54 + $this->param['operator_id'] = $this->user['id'];
  55 + $rs = $this->model->edits($this->param);
  56 + if($rs === false){
  57 + $this->fail('参数错误或其他服务器原因,编辑失败',Code::USER_ERROR,[]);
  58 + }
  59 + return $this->success();
  60 + }
  61 +
  62 + /**
  63 + * @name :编辑状态/排序
  64 + * @author :liyuhang
  65 + */
  66 + public function user_status(){
  67 + $this->param['operator_id'] = $this->user['id'];
  68 + $rs = $this->model->edit($this->param,['id'=>$this->param['id']]);
  69 + if($rs === false){
  70 + $this->fail('error',Code::USER_ERROR);
  71 + }
  72 + return $this->success();
  73 + }
  74 +
  75 + /**
  76 + * @name :用户详情
  77 + * @return void
  78 + * @author :liyuhang
  79 + * @method
  80 + */
  81 + public function user_info(){
  82 + $rs = $this->model->read($this->param);
  83 + if($rs === false){
  84 + $this->fail('error',Code::USER_ERROR);
  85 + }
  86 + return $this->success();
  87 + }
  88 +
  89 + /**
  90 + * @name :删除用户(逻辑删除)
  91 + * @return void
  92 + * @author :liyuhang
  93 + * @method
  94 + */
  95 + public function user_del(){
  96 + $this->param['operator_id'] = $this->user['id'];
  97 + $rs = $this->model->edit($this->param,['id'=>$this->param['id']]);
  98 + if($rs === false){
  99 + $this->fail('error',Code::USER_ERROR);
  100 + }
  101 + return $this->success();
  102 + }
  103 +}
@@ -96,8 +96,7 @@ class Base extends Model @@ -96,8 +96,7 @@ class Base extends Model
96 public function edit($data,$condition){ 96 public function edit($data,$condition){
97 $query = $this->formatQuery($condition); 97 $query = $this->formatQuery($condition);
98 $data['updated_at'] = date('Y-m-d H:i:s'); 98 $data['updated_at'] = date('Y-m-d H:i:s');
99 - $rs = $query->update($data);  
100 - return $rs; 99 + return $query->update($data);
101 } 100 }
102 /** 101 /**
103 * @name : 删除数据 102 * @name : 删除数据
@@ -93,21 +93,6 @@ class User extends Base @@ -93,21 +93,6 @@ class User extends Base
93 return $info; 93 return $info;
94 } 94 }
95 95
96 - //新增用户  
97 - public function adds($param){  
98 - //验证当前用户是否存在  
99 - $info = $this->read(['mobile'=>$param['mobile']]);  
100 - if($info !== false){  
101 - return false;  
102 - }  
103 - //密码加密  
104 - $param['password'] = base64_encode(md5($param['password']));  
105 - $rs = $this->add($param);  
106 - if($rs === false){  
107 - return false;  
108 - }  
109 - return true;  
110 - }  
111 96
112 /** 97 /**
113 * @param $param 98 * @param $param