作者 zhl

u

正在显示 126 个修改的文件 包含 5210 行增加988 行删除
1 -APP_NAME=Laravel  
2 -APP_ENV=test  
3 -APP_KEY=base64:+ouoKlz2sFDOisnROMRpxT/u9xkZJVrXlzP4cfTqPow=  
4 -APP_DEBUG=false  
5 -APP_URL=http://localhost  
6 -  
7 -LOG_CHANNEL=stack  
8 -LOG_DEPRECATIONS_CHANNEL=null  
9 -LOG_LEVEL=debug  
10 -  
11 -DB_CONNECTION=mysql  
12 -DB_HOST=127.0.0.1  
13 -DB_PORT=3306  
14 -DB_DATABASE=globalso  
15 -DB_USERNAME=debian-sys-maint  
16 -DB_PASSWORD=WtujxV73XIclQet0  
17 -  
18 -BROADCAST_DRIVER=log  
19 -CACHE_DRIVER=file  
20 -FILESYSTEM_DRIVER=local  
21 -QUEUE_CONNECTION=sync  
22 -SESSION_DRIVER=file  
23 -SESSION_LIFETIME=120  
24 -  
25 -MEMCACHED_HOST=127.0.0.1  
26 -  
27 -REDIS_HOST=127.0.0.1  
28 -REDIS_PASSWORD=null  
29 -REDIS_PORT=6379  
30 -  
31 -MAIL_MAILER=smtp  
32 -MAIL_HOST=mailhog  
33 -MAIL_PORT=1025  
34 -MAIL_USERNAME=null  
35 -MAIL_PASSWORD=null  
36 -MAIL_ENCRYPTION=null  
37 -MAIL_FROM_ADDRESS=null  
38 -MAIL_FROM_NAME="${APP_NAME}"  
39 -  
40 -AWS_ACCESS_KEY_ID=  
41 -AWS_SECRET_ACCESS_KEY=  
42 -AWS_DEFAULT_REGION=us-east-1  
43 -AWS_BUCKET=  
44 -AWS_USE_PATH_STYLE_ENDPOINT=false  
45 -  
46 -PUSHER_APP_ID=  
47 -PUSHER_APP_KEY=  
48 -PUSHER_APP_SECRET=  
49 -PUSHER_APP_CLUSTER=mt1  
50 -  
51 -MIX_PUSHER_APP_KEY="${PUSHER_APP_KEY}"  
52 -MIX_PUSHER_APP_CLUSTER="${PUSHER_APP_CLUSTER}"  
@@ -15,3 +15,4 @@ yarn-error.log @@ -15,3 +15,4 @@ yarn-error.log
15 /.vscode 15 /.vscode
16 composer.lock 16 composer.lock
17 app/Console/Commands/Test/Demo.php 17 app/Console/Commands/Test/Demo.php
  18 +/public/upload
  1 +<?php
  2 +/**
  3 + * Created by PhpStorm.
  4 + * User: zhl
  5 + * Date: 2023/4/19
  6 + * Time: 15:04
  7 + */
  8 +namespace App\Console\Commands;
  9 +
  10 +use App\Models\Project;
  11 +use App\Services\ProjectServer;
  12 +use Illuminate\Console\Command;
  13 +use Illuminate\Support\Facades\DB;
  14 +
  15 +/**
  16 + * Class ProjectDatabaseUpdate
  17 + * @package App\Console\Commands
  18 + */
  19 +class ProjectDatabaseUpdate extends Command
  20 +{
  21 + /**
  22 + * The name and signature of the console command.
  23 + *
  24 + * @var string
  25 + */
  26 + protected $signature = 'project:database_update';
  27 +
  28 + /**
  29 + * The console command description.
  30 + *
  31 + * @var string
  32 + */
  33 + protected $description = '项目数据库更新';
  34 +
  35 + /**
  36 + * Create a new command instance.
  37 + *
  38 + * @return void
  39 + */
  40 + public function __construct()
  41 + {
  42 + parent::__construct();
  43 + }
  44 +
  45 + /**
  46 + * @return bool
  47 + */
  48 + public function handle()
  49 + {
  50 + #TODO 未处理更新 更新对象(base, project) 更新内容
  51 + return true;
  52 + }
  53 +
  54 + /**
  55 + * 主库内容更新
  56 + * @param $sql
  57 + * @return array
  58 + */
  59 + public function baseUpdate($sql)
  60 + {
  61 + return DB::select($sql);
  62 + }
  63 +
  64 + /**
  65 + * 客户数据表更新
  66 + * @param $sql
  67 + * @return bool
  68 + */
  69 + public function projectDatabaseUpdate($sql)
  70 + {
  71 + $project = Project::get();
  72 + foreach ($project as $val) {
  73 + ProjectServer::useProject($val->id);
  74 + DB::connection('custom_mysql')->select($sql);
  75 + }
  76 + return true;
  77 + }
  78 +
  79 + /**
  80 + * 指定项目数据库更新
  81 + * @param $project_id
  82 + * @param $sql
  83 + */
  84 + public function appointProjectUpdate($project_id, $sql)
  85 + {
  86 + ProjectServer::useProject($project_id);
  87 + DB::connection('custom_mysql')->select($sql);
  88 + }
  89 +}
@@ -113,7 +113,7 @@ class Handler extends ExceptionHandler @@ -113,7 +113,7 @@ class Handler extends ExceptionHandler
113 $code = $exception->getCode(); 113 $code = $exception->getCode();
114 } elseif ($exception instanceof ValidationException) { 114 } elseif ($exception instanceof ValidationException) {
115 $code = Code::USER_PARAMS_ERROE(); 115 $code = Code::USER_PARAMS_ERROE();
116 - $message = Arr::first(Arr::first($exception->errors())); 116 + $message = $code->description = Arr::first(Arr::first($exception->errors()));
117 } elseif ($exception instanceof NotFoundHttpException || $exception instanceof MethodNotAllowedHttpException) { 117 } elseif ($exception instanceof NotFoundHttpException || $exception instanceof MethodNotAllowedHttpException) {
118 return response('404 Not Found', 404); 118 return response('404 Not Found', 404);
119 } else { 119 } else {
1 -<?php  
2 -  
3 -namespace App\Files;  
4 -  
5 -use Illuminate\Http\Request;  
6 -  
7 -class Image  
8 -{  
9 - protected $request = [];  
10 -  
11 - public function __construct(Request $request)  
12 - {  
13 - $this->request = $request;  
14 - }  
15 -  
16 - /**  
17 - * @name :上传图片  
18 - * @return void  
19 - * @author :liyuhang  
20 - * @method  
21 - */  
22 - public function uploads(){  
23 - $url = './uploads/images/';  
24 - $param = $this->request->post();  
25 - if($this->request->hasFile('image') && $this->request->file('image')->isValid()){  
26 - $filename = date('ymdHis').rand(10000,99999).$this->request->file('image');  
27 - $this->request->file('image')->move('./uploads/images/',$filename);  
28 - }else{  
29 - return false;  
30 - }  
31 - return $url.$filename;  
32 - }  
33 -}  
@@ -125,4 +125,64 @@ class Arr extends \Illuminate\Support\Arr @@ -125,4 +125,64 @@ class Arr extends \Illuminate\Support\Arr
125 125
126 return $signle ? $rows[0] : $rows; 126 return $signle ? $rows[0] : $rows;
127 } 127 }
  128 +
  129 +
  130 + /**
  131 + * 数组转字符串
  132 + * @param $arr
  133 + * @return string
  134 + * @author zbj
  135 + * @date 2023/4/17
  136 + */
  137 + public static function a2s($arr): string
  138 + {
  139 + return json_encode($arr, JSON_UNESCAPED_UNICODE);
  140 + }
  141 +
  142 +
  143 + /**
  144 + * 字符串转数组
  145 + * @param $str
  146 + * @return array|mixed
  147 + * @author zbj
  148 + * @date 2023/4/17
  149 + */
  150 + public static function s2a($str)
  151 + {
  152 + if (is_array($str)) {
  153 + return $str;
  154 + }
  155 + return is_object($str) ? (array)$str : json_decode($str, true);
  156 + }
  157 +
  158 +
  159 + /**
  160 + * 数组转set形式字符串
  161 + * @param $arr
  162 + * @param string $format
  163 + * @return string
  164 + * @author zbj
  165 + * @date 2023/4/17
  166 + */
  167 + public static function arrToSet($arr, string $format = 'intval'): string
  168 + {
  169 + $arr = array_unique(array_filter(Arr::splitFilterToArray($arr, $format, ',')));
  170 + return $arr ? implode(',', $arr) : '';
  171 + }
  172 +
  173 + /**
  174 + * set形式字符串转数组
  175 + * @param $str
  176 + * @param string $format
  177 + * @return array
  178 + * @author zbj
  179 + * @date 2023/4/17
  180 + */
  181 + public static function setToArr($str, string $format = 'intval')
  182 + {
  183 + if (is_string($str)) {
  184 + return Arr::splitFilterToArray($str, $format, ',');
  185 + }
  186 + return $str ?: [];
  187 + }
128 } 188 }
  1 +<?php
  2 +
  3 +
  4 +namespace App\Helper;
  5 +
  6 +/**
  7 + * 计算文件hash
  8 + *
  9 + * 七牛云的计算规则
  10 + */
  11 +class FileEtag
  12 +{
  13 + const BLOCK_SIZE = 4194304; //4*1024*1024 分块上传块大小,该参数为接口规格,不能修改
  14 +
  15 + private static function packArray($v, $a)
  16 + {
  17 + return call_user_func_array('pack', array_merge(array($v), (array)$a));
  18 + }
  19 +
  20 + private static function blockCount($fsize)
  21 + {
  22 + return intval(($fsize + (self::BLOCK_SIZE - 1)) / self::BLOCK_SIZE);
  23 + }
  24 +
  25 + private static function calcSha1($data)
  26 + {
  27 + $sha1Str = sha1($data, true);
  28 + $err = error_get_last();
  29 + if ($err !== null) {
  30 + return array(null, $err);
  31 + }
  32 + $byteArray = unpack('C*', $sha1Str);
  33 + return array($byteArray, null);
  34 + }
  35 +
  36 + private static function base64_urlSafeEncode($data)
  37 + {
  38 + $find = array('+', '/');
  39 + $replace = array('-', '_');
  40 + return str_replace($find, $replace, base64_encode($data));
  41 + }
  42 +
  43 + public static function sum($filename)
  44 + {
  45 + $fhandler = fopen($filename, 'r');
  46 + $err = error_get_last();
  47 + if ($err !== null) {
  48 + return array(null, $err);
  49 + }
  50 +
  51 + $fstat = fstat($fhandler);
  52 + $fsize = $fstat['size'];
  53 + if ((int)$fsize === 0) {
  54 + fclose($fhandler);
  55 + return array('Fto5o-5ea0sNMlW_75VgGJCv2AcJ', null);
  56 + }
  57 + $blockCnt = self::blockCount($fsize);
  58 + $sha1Buf = array();
  59 +
  60 + if ($blockCnt <= 1) {
  61 + array_push($sha1Buf, 0x16);
  62 + $fdata = fread($fhandler, self::BLOCK_SIZE);
  63 + if ($err !== null) {
  64 + fclose($fhandler);
  65 + return array(null, $err);
  66 + }
  67 + list($sha1Code,) = self::calcSha1($fdata);
  68 + $sha1Buf = array_merge($sha1Buf, $sha1Code);
  69 + } else {
  70 + array_push($sha1Buf, 0x96);
  71 + $sha1BlockBuf = array();
  72 + for ($i = 0; $i < $blockCnt; $i++) {
  73 + $fdata = fread($fhandler, self::BLOCK_SIZE);
  74 + list($sha1Code, $err) = self::calcSha1($fdata);
  75 + if ($err !== null) {
  76 + fclose($fhandler);
  77 + return array(null, $err);
  78 + }
  79 + $sha1BlockBuf = array_merge($sha1BlockBuf, $sha1Code);
  80 + }
  81 + $tmpData = self::packArray('C*', $sha1BlockBuf);
  82 + list($sha1Final,) = self::calcSha1($tmpData);
  83 + $sha1Buf = array_merge($sha1Buf, $sha1Final);
  84 + }
  85 + $etag = self::base64_urlSafeEncode(self::packArray('C*', $sha1Buf));
  86 + return array($etag, null);
  87 + }
  88 +}
1 <?php 1 <?php
2 - 2 +define('HTTP_OPENAI_URL','http://openai.waimaoq.com/');
3 /** 3 /**
4 * 生成路由标识 4 * 生成路由标识
5 * @param $string 5 * @param $string
@@ -10,3 +10,81 @@ @@ -10,3 +10,81 @@
10 function generateRoute($string){ 10 function generateRoute($string){
11 return trim(strtolower(preg_replace( '/[\W]+/', '-', trim($string))), '-'); 11 return trim(strtolower(preg_replace( '/[\W]+/', '-', trim($string))), '-');
12 } 12 }
  13 +
  14 +
  15 +if(!function_exists('http_post')){
  16 + /**
  17 + * 发送http post请求
  18 + * @param type $url
  19 + * @param type $post_data
  20 + */
  21 + function http_post($url, $post_data)
  22 + {
  23 + $header = array(
  24 + "Accept: application/json",
  25 + "Content-Type:application/json;charset=utf-8",
  26 + );
  27 + $ch = curl_init();
  28 + curl_setopt($ch, CURLOPT_URL, $url);
  29 + curl_setopt($ch, CURLOPT_CUSTOMREQUEST, "POST");
  30 + curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
  31 + curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, 0);
  32 + curl_setopt($ch, CURLOPT_HTTPHEADER, $header);
  33 + curl_setopt($ch, CURLOPT_USERAGENT, 'Mozilla/5.0 (compatible; MSIE 5.01; Windows NT 5.0)');
  34 + curl_setopt($ch, CURLOPT_FOLLOWLOCATION, 1);
  35 + curl_setopt($ch, CURLOPT_AUTOREFERER, 1);
  36 + curl_setopt($ch, CURLOPT_POSTFIELDS, $post_data);
  37 + curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
  38 + $res = curl_exec($ch);
  39 + if (curl_errno($ch)) {
  40 + Log::write(print_r(curl_errno($ch),1),'debug---1');
  41 + }
  42 + curl_close($ch);
  43 + return json_decode($res, true);
  44 + }
  45 +}
  46 +
  47 +if(!function_exists('http_get')){
  48 + /**
  49 + * 发送http get请求
  50 + * @param type $url
  51 + * @return type
  52 + */
  53 + function http_get($url)
  54 + {
  55 + $header[] = "content-type: application/x-www-form-urlencoded;
  56 + charset = UTF-8";
  57 + $ch1 = curl_init();
  58 + $timeout = 5;
  59 + curl_setopt($ch1, CURLOPT_URL, $url);
  60 + curl_setopt($ch1, CURLOPT_RETURNTRANSFER, 1);
  61 + curl_setopt($ch1, CURLOPT_HTTPHEADER, $header);
  62 + curl_setopt($ch1, CURLOPT_CONNECTTIMEOUT, $timeout);
  63 + curl_setopt($ch1, CURLOPT_SSL_VERIFYPEER, false);
  64 + curl_setopt($ch1, CURLOPT_SSL_VERIFYHOST, false);
  65 + $access_txt = curl_exec($ch1);
  66 + curl_close($ch1);
  67 + return json_decode($access_txt, true);
  68 + }
  69 +}
  70 +
  71 +
  72 +if(!function_exists('_get_child')){
  73 + /**
  74 + * 菜单权限->得到子级数组
  75 + * @param int
  76 + * @return array
  77 + */
  78 + function _get_child($my_id, $arr)
  79 + {
  80 + $new_arr = array();
  81 + foreach ($arr as $k => $v) {
  82 + $v = (array)$v;
  83 + if ($v['pid'] == $my_id) {
  84 + $v['sub'] = _get_child($v['id'],$arr);
  85 + $new_arr[] = $v;
  86 + }
  87 + }
  88 + return $new_arr ? $new_arr : false;
  89 + }
  90 +}
  1 +<?php
  2 +
  3 +namespace App\Http\Controllers\Aside;
  4 +
  5 +use App\Enums\Common\Code;
  6 +use App\Http\Controllers\Aside\BaseController;
  7 +use App\Models\AiCommand as AiCommandModel;
  8 +use function App\Helper\send_openai_msg;
  9 +
  10 +class AiCommandController extends BaseController
  11 +{
  12 + /**
  13 + * @name :指令列表
  14 + * @return void
  15 + * @author :liyuhang
  16 + * @method
  17 + */
  18 + public function lists(AiCommandModel $aiCommandModel){
  19 + $lists = $aiCommandModel->lists($this->map);
  20 + $this->response('success',Code::SUCCESS,$lists);
  21 + }
  22 +
  23 + /**
  24 + * @name
  25 + * @return void
  26 + * @author :liyuhang
  27 + * @method
  28 + */
  29 + public function add(){
  30 +
  31 + }
  32 +
  33 + /**
  34 + * @name
  35 + * @return void
  36 + * @author :liyuhang
  37 + * @method
  38 + */
  39 + public function edit(){
  40 +
  41 + }
  42 +
  43 + /**
  44 + * @name
  45 + * @return void
  46 + * @author :liyuhang
  47 + * @method
  48 + */
  49 + public function del(){
  50 +
  51 + }
  52 +}
@@ -4,19 +4,18 @@ namespace App\Http\Controllers\Aside; @@ -4,19 +4,18 @@ namespace App\Http\Controllers\Aside;
4 4
5 use App\Enums\Common\Code; 5 use App\Enums\Common\Code;
6 use App\Http\Controllers\Controller; 6 use App\Http\Controllers\Controller;
7 -use App\Utils\EncryptUtils;  
8 -use Illuminate\Http\Exceptions\HttpResponseException;  
9 use Illuminate\Http\JsonResponse; 7 use Illuminate\Http\JsonResponse;
10 use Illuminate\Http\Request; 8 use Illuminate\Http\Request;
11 -use Illuminate\Http\Response; 9 +use Illuminate\Http\Exceptions\HttpResponseException;
12 use Illuminate\Support\Facades\Cache; 10 use Illuminate\Support\Facades\Cache;
  11 +use Illuminate\Support\Facades\Session;
13 12
14 class BaseController extends Controller 13 class BaseController extends Controller
15 { 14 {
16 protected $param = [];//所有请求参数 15 protected $param = [];//所有请求参数
17 protected $token = ''; //token 16 protected $token = ''; //token
18 protected $request = [];//助手函数 17 protected $request = [];//助手函数
19 - protected $p = 1;//当前页 18 + protected $page = 1;//当前页
20 protected $row = 20;//每页条数 19 protected $row = 20;//每页条数
21 protected $header = [];//设置请求头参数 20 protected $header = [];//设置请求头参数
22 protected $order = 'id'; 21 protected $order = 'id';
@@ -31,23 +30,27 @@ class BaseController extends Controller @@ -31,23 +30,27 @@ class BaseController extends Controller
31 $this->request = $request; 30 $this->request = $request;
32 $this->param = $this->request->all(); 31 $this->param = $this->request->all();
33 $this->token = $this->request->header('token'); 32 $this->token = $this->request->header('token');
  33 + if(!empty($this->token) && !empty(Cache::get($this->token))){
  34 + $info = Cache::get($this->token);
  35 + $this->user = $info;
  36 + $this->uid = $info['id'];
  37 + }else{
  38 + return response(['code'=>Code::USER_ERROR,'msg'=>'当前用户未登录']);
  39 + }
34 $this->get_param(); 40 $this->get_param();
35 - $this->auth_token();  
36 } 41 }
37 42
38 /** 43 /**
39 - * @name  
40 - * @return void  
41 - * @author :liyuhang  
42 - * @method 44 + * admin端用渲染 不走接口
  45 + * @return mixed
  46 + * @author zbj
  47 + * @date 2023/4/19
43 */ 48 */
44 - public function auth_token(){  
45 - $info = Cache::get($this->token);  
46 - if(isset($info) && !empty($info)){  
47 - $this->user = $info;  
48 - $this->uid = $info['id'];  
49 - } 49 + public function manage(){
  50 + return Session::get('manage');
50 } 51 }
  52 +
  53 +
51 /** 54 /**
52 * 成功返回 55 * 成功返回
53 * @param array $data 56 * @param array $data
@@ -68,16 +71,9 @@ class BaseController extends Controller @@ -68,16 +71,9 @@ class BaseController extends Controller
68 'data' => $data, 71 'data' => $data,
69 'msg' => $code->description, 72 'msg' => $code->description,
70 ]; 73 ];
71 - //加密-返回数据  
72 - if (config('app.params_encrypt')) {  
73 - $k = config('app.params_encrypt_key');  
74 - $i = config('app.params_encrypt_iv');  
75 - $response = [  
76 - 'p' => (new EncryptUtils())->openssl_en($response, $k, $i)];  
77 - } 74 + $this->header['token'] = $this->token;
78 return response()->json($response,200,$this->header); 75 return response()->json($response,200,$this->header);
79 } 76 }
80 -  
81 /** 77 /**
82 * @name 参数过滤 78 * @name 参数过滤
83 * @return void 79 * @return void
@@ -94,20 +90,23 @@ class BaseController extends Controller @@ -94,20 +90,23 @@ class BaseController extends Controller
94 case "order": 90 case "order":
95 $this->order = $v; 91 $this->order = $v;
96 break; 92 break;
97 - case 'p':  
98 - $this->p = $v; 93 + case 'page':
  94 + $this->page = $v;
99 break; 95 break;
100 case 'row': 96 case 'row':
101 $this->row = $v; 97 $this->row = $v;
102 break; 98 break;
103 - case "created_at": 99 + case "name":
  100 + $this->map['name'] = ['like','%'.$v.'%'];
  101 + break;
  102 + case "start_at":
104 $this->_btw[0] = $v; 103 $this->_btw[0] = $v;
105 $this->_btw[1] = date('Y-m-d H:i:s',time()); 104 $this->_btw[1] = date('Y-m-d H:i:s',time());
106 - $this->map['create_at'] = ['between', $this->_btw]; 105 + $this->map['created_at'] = ['between', $this->_btw];
107 break; 106 break;
108 - case "updated_at": 107 + case "end_at":
109 $this->_btw[1] = $v; 108 $this->_btw[1] = $v;
110 - $this->map['update_at'] = ['between', $this->_btw]; 109 + $this->map['updated_at'] = ['between', $this->_btw];
111 break; 110 break;
112 default: 111 default:
113 if (!empty($v)) { 112 if (!empty($v)) {
@@ -116,20 +115,20 @@ class BaseController extends Controller @@ -116,20 +115,20 @@ class BaseController extends Controller
116 break; 115 break;
117 } 116 }
118 } 117 }
119 -  
120 } 118 }
121 /** 119 /**
122 * @name 统一返回参数 120 * @name 统一返回参数
123 - * @return void 121 + * @return JsonResponse
124 * @author :liyuhang 122 * @author :liyuhang
125 * @method 123 * @method
126 */ 124 */
127 - public function response($msg,$code = 200,$data = [],$result_code = null,$type = 'application/json'){  
128 - $result_code === null && $result_code = $code; 125 + public function response($msg = null,string $code = Code::SUCCESS,$data = [],$result_code = 200,$type = 'application/json'): JsonResponse
  126 + {
  127 + $code = Code::fromValue($code);
129 $result = [ 128 $result = [
130 - 'msg' =>$msg,  
131 - 'code'=>$result_code,  
132 - 'data'=>$data 129 + 'msg' => $msg == ' ' ? $code->description : $msg,
  130 + 'code' => $code->value,
  131 + 'data' => $this->_extents($data),
133 ]; 132 ];
134 $this->header['Content-Type'] = $type; 133 $this->header['Content-Type'] = $type;
135 $this->header['token'] = $this->token; 134 $this->header['token'] = $this->token;
@@ -137,25 +136,45 @@ class BaseController extends Controller @@ -137,25 +136,45 @@ class BaseController extends Controller
137 throw new HttpResponseException($response); 136 throw new HttpResponseException($response);
138 } 137 }
139 138
  139 +
140 /** 140 /**
141 - * @name :上传图片  
142 - * @return void  
143 - * @author :liyuhang  
144 - * @method 141 + * 菜单权限->得到子级数组
  142 + * @param int
  143 + * @return array
145 */ 144 */
146 - public function uploads(){  
147 - $files = $this->request->file('file');  
148 - if(empty($files)){  
149 - return $this->response('没有上传文件',Code::USER_ERROR);  
150 - }  
151 - $url = './uploads/images/';  
152 - $param = $this->request->post();  
153 - if($this->request->hasFile('image') && $files->isValid()){  
154 - $filename = date('ymdHis').rand(10000,99999).$this->request->file('image');  
155 - $this->request->file('image')->move('./uploads/images/',$filename);  
156 - }else{  
157 - return false; 145 + public function _get_child($my_id, $arr)
  146 + {
  147 + $new_arr = array();
  148 + foreach ($arr as $k => $v) {
  149 + $v = (array)$v;
  150 + if ($v['pid'] == $my_id) {
  151 + $v['sub'] = $this->_get_child($v['id'],$arr);
  152 + $new_arr[] = $v;
  153 + }
  154 + }
  155 + return $new_arr ? $new_arr : false;
  156 + }
  157 +
  158 + protected function _extents($data) {
  159 +
  160 + if (empty($data) || !is_array($data)) {
  161 + return empty($data) ? is_array($data) ? [] : '' : $data;
  162 + }
  163 + foreach ($data as $k => $v) {
  164 + if (is_array($v)) {
  165 + $data[$k] = $this->_extents($v);
  166 + } else {
  167 + if (is_null($v)) {
  168 + $data[$k] = '';
  169 + continue;
  170 + }
  171 + switch ((string) $k) {
  172 + case 'image':
  173 + $v['image_link'] = file_get_contents($v);
  174 + break;
  175 + }
  176 + }
158 } 177 }
159 - return $url.$filename; 178 + return $data;
160 } 179 }
161 } 180 }
1 -<?php  
2 -  
3 -namespace App\Http\Controllers\Aside;  
4 -  
5 -use App\Http\Logic\Aside\DemoLogic;  
6 -use App\Http\Requests\Aside\DemoRequest;  
7 -  
8 -class DemoController extends BaseController  
9 -{  
10 - /**  
11 - * Deom控制器  
12 - * @param DemoRequest $request  
13 - * @param DemoLogic $logic  
14 - * @return \Illuminate\Http\JsonResponse  
15 - * @throws \Psr\Container\ContainerExceptionInterface  
16 - * @throws \Psr\Container\NotFoundExceptionInterface  
17 - */  
18 - public function test(DemoRequest $request,DemoLogic $logic)  
19 - {  
20 - $request->validated();  
21 - $data=$logic->testLogic();  
22 - return $this->success($data);  
23 - }  
24 -}  
  1 +<?php
  2 +
  3 +namespace App\Http\Controllers\Aside;
  4 +
  5 +use App\Http\Controllers\Controller;
  6 +use Illuminate\Http\Request;
  7 +
  8 +/**
  9 + * Class IndexController
  10 + * @package App\Http\Controllers\Aside
  11 + * @author zbj
  12 + * @date 2023/4/19
  13 + */
  14 +class IndexController extends Controller
  15 +{
  16 + /**
  17 + * 首页
  18 + * @param Request $request
  19 + * @return \Illuminate\Http\JsonResponse
  20 + */
  21 + public function index(Request $request)
  22 + {
  23 +
  24 + }
  25 +
  26 +}
  1 +<?php
  2 +
  3 +
  4 +namespace App\Http\Controllers\Aside;
  5 +
  6 +use App\Http\Logic\Aside\LoginLogic;
  7 +use App\Rules\Mobile;
  8 +use Illuminate\Http\Request;
  9 +
  10 +/**
  11 + * Class LoginController
  12 + * @package App\Http\Controllers\Aside
  13 + * @author zbj
  14 + * @date 2023/4/19
  15 + */
  16 +class LoginController extends BaseController
  17 +{
  18 +
  19 + function login(Request $request, LoginLogic $logic)
  20 + {
  21 + if ($request->isMethod('POST')) {
  22 + $request->validate([
  23 + 'mobile' => ['required', new Mobile()],
  24 + 'password' => 'required',
  25 + ], [
  26 + 'mobile.required' => '请输入手机号',
  27 + 'password.required' => '请输入密码',
  28 + ]);
  29 +
  30 + $logic->login();
  31 +
  32 + return $this->success();
  33 + }
  34 + return view('admin.login');
  35 + }
  36 +
  37 + public function logout(LoginLogic $logic)
  38 + {
  39 + return $logic->logout();
  40 + }
  41 +}
  1 +<?php
  2 +
  3 +namespace App\Http\Controllers\Aside\Manage;
  4 +
  5 +use App\Helper\Arr;
  6 +use App\Http\Controllers\Aside\BaseController;
  7 +use App\Http\Logic\Aside\DeptLogic;
  8 +use App\Http\Requests\Aside\DeptRequest;
  9 +use App\Rules\Ids;
  10 +use Illuminate\Http\Request;
  11 +
  12 +/**
  13 + * Class DeptController
  14 + * @package App\Http\Controllers\Aside
  15 + * @author zbj
  16 + * @date 2023/4/20
  17 + */
  18 +class DeptController extends BaseController
  19 +{
  20 +
  21 + public function list(DeptLogic $logic)
  22 + {
  23 + $map = [];
  24 + if(!empty($this->param['search'])){
  25 + $map[] = ['title', 'like', "%{$this->param['search']}%"];
  26 + }
  27 + $sort = ['id' => 'desc'];
  28 + $data = $logic->getList($map, $sort, ['id', 'pid', 'title'],0);
  29 +
  30 + return view("admin.dept", ["list" => Arr::listToTree($data)]);
  31 + }
  32 +
  33 + public function info(Request $request, DeptLogic $logic){
  34 + $request->validate([
  35 + 'id'=>'required'
  36 + ],[
  37 + 'id.required' => 'ID不能为空'
  38 + ]);
  39 + $data = $logic->getInfo($this->param['id']);
  40 + return $this->success(Arr::twoKeepKeys($data, ['id', 'pid', 'title', 'manager_uids', 'remark']));
  41 + }
  42 +
  43 + public function save(DeptRequest $request, DeptLogic $logic)
  44 + {
  45 + $data = $logic->save($this->param);
  46 + return $this->success($data);
  47 + }
  48 +
  49 + public function delete(Request $request, DeptLogic $logic)
  50 + {
  51 + $request->validate([
  52 + 'ids'=>['required', new Ids()]
  53 + ],[
  54 + 'ids.required' => 'ID不能为空'
  55 + ]);
  56 +
  57 + $data = $logic->delete($this->param['ids']);
  58 + return $this->success($data);
  59 + }
  60 +}
  1 +<?php
  2 +
  3 +namespace App\Http\Controllers\Aside\Manage;
  4 +
  5 +use App\Helper\Arr;
  6 +use App\Http\Controllers\Aside\BaseController;
  7 +use App\Http\Logic\Aside\GroupLogic;
  8 +use App\Http\Requests\Aside\GroupRequest;
  9 +use App\Rules\Ids;
  10 +use Illuminate\Http\Request;
  11 +
  12 +/**
  13 + * 用户组
  14 + * Class Group
  15 + * @package App\Http\Controllers\Aside
  16 + * @author zbj
  17 + * @date 2023/4/19
  18 + */
  19 +class GroupController extends BaseController
  20 +{
  21 +
  22 + public function list(Request $request, GroupLogic $logic)
  23 + {
  24 + $list = $logic->getList();
  25 + return view("admin.group", ["list" => $list]);
  26 + }
  27 +
  28 + public function info(Request $request, GroupLogic $logic){
  29 + $request->validate([
  30 + 'id'=>'required'
  31 + ],[
  32 + 'id.required' => 'ID不能为空'
  33 + ]);
  34 + $data = $logic->getInfo($this->param['id']);
  35 + return $this->success($data);
  36 + }
  37 +
  38 + public function save(GroupRequest $request, GroupLogic $logic){
  39 + $data = $logic->save($this->param);
  40 + return $this->success($data);
  41 + }
  42 +
  43 + public function delete(Request $request, GroupLogic $logic){
  44 + $request->validate([
  45 + 'ids'=>['required', new Ids()]
  46 + ],[
  47 + 'ids.required' => 'ID不能为空'
  48 + ]);
  49 +
  50 + $data = $logic->delete($this->param['ids']);
  51 + return $this->success($data);
  52 + }
  53 +
  54 +}
  1 +<?php
  2 +
  3 +namespace App\Http\Controllers\Aside\Manage;
  4 +
  5 +use App\Helper\Arr;
  6 +use App\Http\Controllers\Aside\BaseController;
  7 +use App\Http\Logic\Aside\ManageLogic;
  8 +use App\Http\Requests\Aside\ManageRequest;
  9 +use App\Rules\Ids;
  10 +use Illuminate\Http\Request;
  11 +
  12 +/**
  13 + * 后台用户
  14 + * Class ManageController
  15 + * @package App\Http\Controllers\Aside
  16 + * @author zbj
  17 + * @date 2023/4/20
  18 + */
  19 +class ManageController extends BaseController
  20 +{
  21 +
  22 + public function list(Request $request, ManageLogic $logic)
  23 + {
  24 + $list = $logic->getList();
  25 + return view("admin.manage", ["list" => $list]);
  26 + }
  27 +
  28 + public function info(Request $request, ManageLogic $logic){
  29 + $request->validate([
  30 + 'id'=>'required'
  31 + ],[
  32 + 'id.required' => 'ID不能为空'
  33 + ]);
  34 + $data = $logic->getInfo($this->param['id']);
  35 + return $this->success($data);
  36 + }
  37 +
  38 + public function save(ManageRequest $request, ManageLogic $logic){
  39 + $data = $logic->save($this->param);
  40 + return $this->success($data);
  41 + }
  42 +
  43 + public function delete(Request $request, ManageLogic $logic){
  44 + $request->validate([
  45 + 'ids'=>['required', new Ids()]
  46 + ],[
  47 + 'ids.required' => 'ID不能为空'
  48 + ]);
  49 +
  50 + $data = $logic->delete($this->param['ids']);
  51 + return $this->success($data);
  52 + }
  53 +
  54 +}
  1 +<?php
  2 +
  3 +namespace App\Http\Controllers\Aside\Manage;
  4 +
  5 +use App\Helper\Arr;
  6 +use App\Http\Controllers\Aside\BaseController;
  7 +use App\Http\Logic\Aside\MenuLogic;
  8 +use App\Http\Requests\Aside\MenuRequest;
  9 +use App\Rules\Ids;
  10 +use Illuminate\Http\Request;
  11 +
  12 +/**
  13 + * 后台菜单
  14 + * Class MenuController
  15 + * @package App\Http\Controllers\Aside
  16 + * @author zbj
  17 + * @date 2023/4/19
  18 + */
  19 +class MenuController extends BaseController
  20 +{
  21 +
  22 + public function list(Request $request, MenuLogic $logic)
  23 + {
  24 + $map = [];
  25 + $sort = ['id' => 'desc'];
  26 + $list = $logic->getList($map, $sort, ['*'],0);
  27 + return view("admin.menu", ["list" => Arr::listToTree($list)]);
  28 + }
  29 +
  30 + public function info(Request $request, MenuLogic $logic){
  31 + $request->validate([
  32 + 'id'=>'required'
  33 + ],[
  34 + 'id.required' => 'ID不能为空'
  35 + ]);
  36 + $data = $logic->getInfo($this->param['id']);
  37 + return $this->success($data);
  38 + }
  39 +
  40 + public function save(MenuRequest $request, MenuLogic $logic){
  41 + $data = $logic->save($this->param);
  42 + return $this->success($data);
  43 + }
  44 +
  45 + public function delete(Request $request, MenuLogic $logic){
  46 + $request->validate([
  47 + 'ids'=>['required', new Ids()]
  48 + ],[
  49 + 'ids.required' => 'ID不能为空'
  50 + ]);
  51 +
  52 + $data = $logic->delete($this->param['ids']);
  53 + return $this->success($data);
  54 + }
  55 +
  56 +}
@@ -2,6 +2,7 @@ @@ -2,6 +2,7 @@
2 2
3 namespace App\Http\Controllers\Aside; 3 namespace App\Http\Controllers\Aside;
4 4
  5 +use App\Enums\Common\Code;
5 use App\Http\Controllers\Bside\BaseController; 6 use App\Http\Controllers\Bside\BaseController;
6 7
7 use App\Models\Project as ProjectModel; 8 use App\Models\Project as ProjectModel;
@@ -20,6 +21,16 @@ class ProjectController extends BaseController @@ -20,6 +21,16 @@ class ProjectController extends BaseController
20 public function lists(){ 21 public function lists(){
21 $projectModel = new ProjectModel(); 22 $projectModel = new ProjectModel();
22 $lists = $projectModel->lists($this->map,$this->p,$this->row,$this->order); 23 $lists = $projectModel->lists($this->map,$this->p,$this->row,$this->order);
23 - $this->result($lists); 24 + $this->response('success',Code::SUCCESS,$lists);
  25 + }
  26 +
  27 + /**
  28 + * @name :添加项目
  29 + * @return void
  30 + * @author :liyuhang
  31 + * @method
  32 + */
  33 + public function add(){
  34 + $projectModel = new ProjectModel();
24 } 35 }
25 } 36 }
  1 +<?php
  2 +
  3 +namespace App\Http\Controllers\Aside;
  4 +
  5 +class ProjectMenuController extends BaseController
  6 +{
  7 + /**
  8 + * @name :用户菜单列表
  9 + * @return void
  10 + * @author :liyuhang
  11 + * @method
  12 + */
  13 + public function lists(){
  14 +
  15 + }
  16 +}
  1 +<?php
  2 +
  3 +namespace App\Http\Controllers\Aside;
  4 +
  5 +class ProjectRoleController extends BaseController
  6 +{
  7 + /**
  8 + * @name :列表
  9 + * @return void
  10 + * @author :liyuhang
  11 + * @method
  12 + */
  13 + public function lists (){
  14 +
  15 + }
  16 +}
  1 +<?php
  2 +
  3 +namespace App\Http\Controllers\Aside;
  4 +
  5 +class ProjectUserController extends BaseController
  6 +{
  7 + /**
  8 + * @name :用户列表
  9 + * @return void
  10 + * @author :liyuhang
  11 + * @method
  12 + */
  13 + public function lists(){
  14 +
  15 + }
  16 +}
  1 +<?php
  2 +
  3 +namespace App\Http\Controllers\Bside;
  4 +
  5 +use App\Enums\Common\Code;
  6 +use Illuminate\Http\Request;
  7 +
  8 +class AiCommandController extends BaseController
  9 +{
  10 + public $chat_url = 'v2/openai_chat';
  11 + /**
  12 + * @name :ai生成
  13 + * @return void
  14 + * @author :liyuhang
  15 + * @method
  16 + */
  17 + public function ai_http_post(Request $request){
  18 + $request->validate([
  19 + 'keywords'=>['required'],
  20 + 'key'=>['required']
  21 + ],[
  22 + 'keywords.required' => '关键字不能为空',
  23 + 'key.required' => '场景不能为空',
  24 + ]);
  25 + #TODO 通过key获取到ai指令对象
  26 + $data = $this->send_openai_msg($this->chat_url);
  27 + $this->response('success',Code::SUCCESS,$data);
  28 + }
  29 +}
@@ -4,7 +4,7 @@ namespace App\Http\Controllers\Bside; @@ -4,7 +4,7 @@ namespace App\Http\Controllers\Bside;
4 4
5 use App\Enums\Common\Code; 5 use App\Enums\Common\Code;
6 use App\Http\Controllers\Controller; 6 use App\Http\Controllers\Controller;
7 -use App\Utils\EncryptUtils; 7 +use App\Models\AiCommand as AiCommandModel;
8 use Illuminate\Http\JsonResponse; 8 use Illuminate\Http\JsonResponse;
9 use Illuminate\Http\Request; 9 use Illuminate\Http\Request;
10 use Illuminate\Http\Exceptions\HttpResponseException; 10 use Illuminate\Http\Exceptions\HttpResponseException;
@@ -15,8 +15,7 @@ class BaseController extends Controller @@ -15,8 +15,7 @@ class BaseController extends Controller
15 protected $param = [];//所有请求参数 15 protected $param = [];//所有请求参数
16 protected $token = ''; //token 16 protected $token = ''; //token
17 protected $request = [];//助手函数 17 protected $request = [];//助手函数
18 - protected $allCount = 0;//总条数  
19 - protected $p = 1;//当前页 18 + protected $page = 1;//当前页
20 protected $row = 20;//每页条数 19 protected $row = 20;//每页条数
21 protected $header = [];//设置请求头参数 20 protected $header = [];//设置请求头参数
22 protected $order = 'id'; 21 protected $order = 'id';
@@ -35,7 +34,6 @@ class BaseController extends Controller @@ -35,7 +34,6 @@ class BaseController extends Controller
35 $info = Cache::get($this->token); 34 $info = Cache::get($this->token);
36 $this->user = $info; 35 $this->user = $info;
37 $this->uid = $info['id']; 36 $this->uid = $info['id'];
38 - $this->param['project_id'] = $this->user['project_id'];  
39 }else{ 37 }else{
40 return response(['code'=>Code::USER_ERROR,'msg'=>'当前用户未登录']); 38 return response(['code'=>Code::USER_ERROR,'msg'=>'当前用户未登录']);
41 } 39 }
@@ -80,20 +78,23 @@ class BaseController extends Controller @@ -80,20 +78,23 @@ class BaseController extends Controller
80 case "order": 78 case "order":
81 $this->order = $v; 79 $this->order = $v;
82 break; 80 break;
83 - case 'p':  
84 - $this->p = $v; 81 + case 'page':
  82 + $this->page = $v;
85 break; 83 break;
86 case 'row': 84 case 'row':
87 $this->row = $v; 85 $this->row = $v;
88 break; 86 break;
89 - case "created_at": 87 + case "name":
  88 + $this->map['name'] = ['like','%'.$v.'%'];
  89 + break;
  90 + case "start_at":
90 $this->_btw[0] = $v; 91 $this->_btw[0] = $v;
91 $this->_btw[1] = date('Y-m-d H:i:s',time()); 92 $this->_btw[1] = date('Y-m-d H:i:s',time());
92 - $this->map['create_at'] = ['between', $this->_btw]; 93 + $this->map['created_at'] = ['between', $this->_btw];
93 break; 94 break;
94 - case "updated_at": 95 + case "end_at":
95 $this->_btw[1] = $v; 96 $this->_btw[1] = $v;
96 - $this->map['update_at'] = ['between', $this->_btw]; 97 + $this->map['updated_at'] = ['between', $this->_btw];
97 break; 98 break;
98 default: 99 default:
99 if (!empty($v)) { 100 if (!empty($v)) {
@@ -102,7 +103,6 @@ class BaseController extends Controller @@ -102,7 +103,6 @@ class BaseController extends Controller
102 break; 103 break;
103 } 104 }
104 } 105 }
105 -  
106 } 106 }
107 /** 107 /**
108 * @name 统一返回参数 108 * @name 统一返回参数
@@ -116,7 +116,7 @@ class BaseController extends Controller @@ -116,7 +116,7 @@ class BaseController extends Controller
116 $result = [ 116 $result = [
117 'msg' => $msg == ' ' ? $code->description : $msg, 117 'msg' => $msg == ' ' ? $code->description : $msg,
118 'code' => $code->value, 118 'code' => $code->value,
119 - 'data' => $data, 119 + 'data' => $this->_extents($data),
120 ]; 120 ];
121 $this->header['Content-Type'] = $type; 121 $this->header['Content-Type'] = $type;
122 $this->header['token'] = $this->token; 122 $this->header['token'] = $this->token;
@@ -143,25 +143,51 @@ class BaseController extends Controller @@ -143,25 +143,51 @@ class BaseController extends Controller
143 return $new_arr ? $new_arr : false; 143 return $new_arr ? $new_arr : false;
144 } 144 }
145 145
  146 + protected function _extents($data) {
  147 +
  148 + if (empty($data) || !is_array($data)) {
  149 + return empty($data) ? is_array($data) ? [] : '' : $data;
  150 + }
  151 + foreach ($data as $k => $v) {
  152 + if (is_array($v)) {
  153 + $data[$k] = $this->_extents($v);
  154 + } else {
  155 + if (is_null($v)) {
  156 + $data[$k] = '';
  157 + continue;
  158 + }
  159 + switch ((string) $k) {
  160 + case 'image':
  161 + $v['image_link'] = url('/image/' . $v);
  162 + break;
  163 + }
  164 + }
  165 + }
  166 + return $data;
  167 + }
  168 +
146 /** 169 /**
147 - * @name :上传图片  
148 - * @return void 170 + * @name :ai自动生成
  171 + * @return mixed
149 * @author :liyuhang 172 * @author :liyuhang
150 * @method 173 * @method
151 */ 174 */
152 - public function uploads(){  
153 - $files = $this->request->file('file');  
154 - if(empty($files)){  
155 - return $this->response('没有上传文件',Code::USER_ERROR);  
156 - }  
157 - $url = './uploads/images/';  
158 - $param = $this->request->post();  
159 - if($this->request->hasFile('image') && $files->isValid()){  
160 - $filename = date('ymdHis').rand(10000,99999).$this->request->file('image');  
161 - $this->request->file('image')->move('./uploads/images/',$filename);  
162 - }else{  
163 - return false;  
164 - }  
165 - return $url.$filename; 175 + public function send_openai_msg($url){
  176 + $url = HTTP_OPENAI_URL.$url;
  177 + $aiCommandModel = New AiCommandModel();
  178 + //指定库获取指令
  179 + $info = $aiCommandModel->read(['key'=>$this->param['key']]);
  180 + if($info === false){
  181 + $this->response('指令不存在',Code::USER_ERROR);
  182 + }
  183 + //替换关键字
  184 + $content = str_replace('$keyword$', $this->param['keywords'], $info['ai']);
  185 + $data = [
  186 + 'messages'=>[
  187 + ['role'=>'system','content'=>$info['scene']],
  188 + ['role'=>'assistant','content'=>$content],
  189 + ]
  190 + ];
  191 + return http_post($url,json_encode($data));
166 } 192 }
167 } 193 }
  1 +<?php
  2 +
  3 +namespace App\Http\Controllers\Bside\Blog;
  4 +
  5 +use App\Enums\Common\Code;
  6 +use App\Http\Controllers\Bside\BaseController;
  7 +use App\Http\Logic\Bside\Blog\BlogCategoryLogic;
  8 +use App\Http\Requests\Bside\Blog\BlogCategoryRequest;
  9 +use App\Models\Blog\Blog as BlogModel;
  10 +use App\Models\Blog\BlogCategory as BlogCategoryModel;
  11 +use Illuminate\Http\Request;
  12 +
  13 +class BlogCategoryController extends BaseController
  14 +{
  15 + /**
  16 + * @name :博客分类列表
  17 + * @return json
  18 + * @author :liyuhang
  19 + * @method
  20 + */
  21 + public function lists(BlogCategoryModel $blogCategoryModel){
  22 + //搜索条件
  23 + $this->map['project_id'] = $this->user['project_id'];
  24 + $lists = $blogCategoryModel->lists($this->map,$this->page,$this->row);
  25 + $this->response('success',Code::SUCCESS,$lists);
  26 + }
  27 +
  28 + /**
  29 + * @name :获取当前分类详情
  30 + * @return void
  31 + * @author :liyuhang
  32 + * @method
  33 + */
  34 + public function info(Request $request,BlogCategoryLogic $blogCategoryLogic){
  35 + $request->validate([
  36 + 'id'=>['required']
  37 + ],[
  38 + 'id.required' => 'ID不能为空'
  39 + ]);
  40 + $info = $blogCategoryLogic->info_blog_category();
  41 + $this->response('success',Code::SUCCESS,$info);
  42 + }
  43 + /**
  44 + * @name :添加分类
  45 + * @return json
  46 + * @author :liyuhang
  47 + * @method
  48 + */
  49 + public function add(BlogCategoryRequest $request,BlogCategoryLogic $blogCategoryLogic){
  50 + $request->validated();
  51 + //添加时,验证分类上级分类是否有,有则更新到当前分类中,没有时直接添加
  52 + $blogCategoryLogic->add_blog_category();
  53 + $this->response('success');
  54 + }
  55 +
  56 + /**
  57 + * @name :编辑分类
  58 + * @return void
  59 + * @author :liyuhang
  60 + * @method
  61 + */
  62 + public function edit(BlogCategoryRequest $request,BlogCategoryLogic $blogCategoryLogic){
  63 + $request->validate([
  64 + 'id'=>['required']
  65 + ],[
  66 + 'id.required' => 'ID不能为空'
  67 + ]);
  68 + $blogCategoryLogic->edit_blog_category();
  69 + //TODO::写入日志
  70 + $this->response('success');
  71 + }
  72 +
  73 + /**
  74 + * @name :编辑状态/与排序
  75 + * @return void
  76 + * @author :liyuhang
  77 + * @method
  78 + */
  79 + public function status(Request $request,BlogCategoryLogic $blogCategoryLogic){
  80 + $request->validate([
  81 + 'id'=>['required'],
  82 + ],[
  83 + 'id.required' => 'ID不能为空',
  84 + ]);
  85 + $blogCategoryLogic->status_blog_category();
  86 + $this->response('success');
  87 + }
  88 +
  89 + /**
  90 + * @name :删除分类
  91 + * @return void
  92 + * @author :liyuhang
  93 + * @method
  94 + */
  95 + public function del(Request $request,BlogCategoryLogic $blogCategoryLogic){
  96 + $request->validate([
  97 + 'id'=>['required'],
  98 + ],[
  99 + 'id.required' => 'ID不能为空',
  100 + ]);
  101 + $blogCategoryLogic->del_blog_category();
  102 + //TODO::写入操作日志
  103 + $this->response('success');
  104 + }
  105 +}
  1 +<?php
  2 +
  3 +namespace App\Http\Controllers\Bside\Blog;
  4 +
  5 +use App\Enums\Common\Code;
  6 +use App\Http\Controllers\Bside\BaseController;
  7 +use App\Http\Logic\Bside\Blog\BlogLogic;
  8 +use App\Http\Requests\Bside\Blog\BlogRequest;
  9 +use App\Models\Blog\Blog as BlogModel;
  10 +use App\Models\Blog\BlogCategory as BlogCategoryModel;
  11 +use Illuminate\Http\Request;
  12 +class BlogController extends BaseController
  13 +{
  14 + /**
  15 + * @name :博客列表
  16 + * @return json
  17 + * @author :liyuhang
  18 + * @method
  19 + */
  20 + public function lists(BlogModel $blogModel){
  21 + //搜索条件
  22 + $this->map['project_id'] = $this->user['project_id'];
  23 + $lists = $blogModel->lists($this->map,$this->page,$this->row);
  24 + if(!empty($lists['list'])){
  25 + foreach ($lists['list'] as $k => $v){
  26 + $blogCategoryModel= new BlogCategoryModel();
  27 + //获取用户已读还是未读
  28 + $category_info = $blogCategoryModel->
  29 + list(['id'=>['in',explode(',',trim($v['category_id'],','))]],'id',['name']);
  30 + $str = '';
  31 + foreach ($category_info as $v1){
  32 + $str .= $v1['name'].',';
  33 + }
  34 + $v['category_id'] = trim($str,',');
  35 + $lists['list'][$k] = $v;
  36 + }
  37 + }
  38 + $this->response('success',Code::SUCCESS,$lists);
  39 + }
  40 +
  41 + /**
  42 + * @name :获取分页列表
  43 + * @return void
  44 + * @throws \App\Exceptions\BsideGlobalException
  45 + * @author :liyuhang
  46 + * @method
  47 + */
  48 + public function get_category_list(BlogLogic $blogLogic){
  49 + $list = $blogLogic->blog_get_category_list();
  50 + $this->response('success',Code::SUCCESS,$list);
  51 + }
  52 + /**
  53 + * @name :获取当前博客详情
  54 + * @return json
  55 + * @author :liyuhang
  56 + * @method
  57 + */
  58 + public function info(Request $request,BlogLogic $blogLogic){
  59 + $request->validate([
  60 + 'id'=>['required']
  61 + ],[
  62 + 'id.required' => 'ID不能为空'
  63 + ]);
  64 + $info = $blogLogic->blog_info();
  65 + $this->response('success',Code::SUCCESS,$info);
  66 + }
  67 + /**
  68 + * @name :添加博客
  69 + * @return void
  70 + * @author :liyuhang
  71 + * @method
  72 + */
  73 + public function add(BlogRequest $request,BlogLogic $blogLogic){
  74 + $request->validated();
  75 + $blogLogic->blog_add();
  76 + //TODO::写入日志
  77 + $this->response('success');
  78 + }
  79 +
  80 + /**
  81 + * @name :编辑博客
  82 + * @return void
  83 + * @author :liyuhang
  84 + * @method
  85 + */
  86 + public function edit(BlogRequest $request,BlogLogic $blogLogic){
  87 + $request->validate([
  88 + 'id'=>['required']
  89 + ],[
  90 + 'id.required' => 'ID不能为空'
  91 + ]);
  92 + $blogLogic->blog_edit();
  93 + //TODO::写入日志
  94 + $this->response('success');
  95 + }
  96 +
  97 + /**
  98 + * @name :编辑博客状态/排序
  99 + * @return void
  100 + * @author :liyuhang
  101 + * @method
  102 + */
  103 + public function status(Request $request,BlogLogic $blogLogic){
  104 + $request->validate([
  105 + 'id'=>['required'],
  106 + ],[
  107 + 'id.required' => 'ID不能为空',
  108 + ]);
  109 + $blogLogic->blog_status();
  110 + //TODO::写入日志
  111 + $this->response('success');
  112 + }
  113 +
  114 + /**
  115 + * @name :删除博客(批量逻辑删除)
  116 + * @return void
  117 + * @author :liyuhang
  118 + * @method
  119 + */
  120 + public function del(Request $request,BlogLogic $blogLogic){
  121 + $request->validate([
  122 + 'id'=>['required'],
  123 + ],[
  124 + 'id.required' => 'ID不能为空',
  125 + ]);
  126 + $blogLogic->blog_del();
  127 + $this->response('success');
  128 + }
  129 + /**
  130 + * @name :ai生成
  131 + * @return void
  132 + * @author :liyuhang
  133 + * @method
  134 + */
  135 + public function ai_blog(Request $request){
  136 + $request->validate([
  137 + 'keywords'=>['required'],
  138 + 'key'=>['required']
  139 + ],[
  140 + 'keywords.required' => '关键字不能为空',
  141 + 'key.required' => '场景不能为空',
  142 + ]);
  143 + #TODO 通过key获取到ai指令对象
  144 + $url = 'v2/openai_chat';
  145 + $data = $this->send_openai_msg($url);
  146 + $this->response('success',Code::SUCCESS,$data);
  147 + }
  148 +
  149 +}
  1 +<?php
  2 +
  3 +namespace App\Http\Controllers\Bside\Blog;
  4 +
  5 +use App\Enums\Common\Code;
  6 +use App\Http\Controllers\Bside\BaseController;
  7 +use App\Http\Logic\Bside\Blog\BlogLabelLogic;
  8 +use App\Http\Requests\Bside\Blog\BlogLabelRequest;
  9 +use App\Models\Blog\BlogLabel as BlogLabelModel;
  10 +use Illuminate\Http\Request;
  11 +
  12 +class BlogLabelController extends BaseController
  13 +{
  14 + /**
  15 + * @name :博客标签列表
  16 + * @return json
  17 + * @author :liyuhang
  18 + * @method
  19 + */
  20 + public function lists(BlogLabelModel $blogLabelModel){
  21 + $this->map['project_id'] = $this->user['project_id'];
  22 + $lists = $blogLabelModel->lists($this->map,$this->page,$this->row,$this->order,['id','name','created_at','updated_at']);
  23 + $this->response('success',Code::SUCCESS,$lists);
  24 + }
  25 +
  26 + /**
  27 + * @name :添加标签
  28 + * @return void
  29 + * @author :liyuhang
  30 + * @method
  31 + */
  32 + public function add(BlogLabelRequest $request,BlogLabelLogic $blogLabelLogic){
  33 + $request->validated();
  34 + $blogLabelLogic->add_blog_label();
  35 + //TODO::写入日志
  36 + $this->response('success');
  37 + }
  38 +
  39 + /**
  40 + * @name :编辑标签
  41 + * @return void
  42 + * @author :liyuhang
  43 + * @method
  44 + */
  45 + public function edit(BlogLabelRequest $request,BlogLabelLogic $blogLabelLogic){
  46 + $request->validate([
  47 + 'id'=>['required']
  48 + ],[
  49 + 'id.required' => 'ID不能为空'
  50 + ]);
  51 + $blogLabelLogic->edit_blog_label();
  52 + //TODO::写入日志
  53 + $this->response('success');
  54 + }
  55 +
  56 + /**
  57 + * @name :编辑标签状态/排序
  58 + * @return void
  59 + * @author :liyuhang
  60 + * @method
  61 + */
  62 + public function status(Request $request,BlogLabelLogic $blogLabelLogic){
  63 + $request->validate([
  64 + 'id'=>['required'],
  65 + ],[
  66 + 'id.required' => 'ID不能为空',
  67 + ]);
  68 + $blogLabelLogic->edit_blog_label();
  69 + //TODO::写入日志
  70 + $this->response('success');
  71 + }
  72 +
  73 + /**
  74 + * @name :删除标签(批量删除)
  75 + * @return void
  76 + * @author :liyuhang
  77 + * @method
  78 + */
  79 + public function del(Request $request,BlogLabelLogic $blogLabelLogic){
  80 + $request->validate([
  81 + 'id'=>['required'],
  82 + ],[
  83 + 'id.required' => 'ID不能为空',
  84 + ]);
  85 + $blogLabelLogic->del_blog_label();
  86 + $this->response('success');
  87 + }
  88 +}
@@ -3,15 +3,13 @@ @@ -3,15 +3,13 @@
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\Models\Project;
6 use App\Models\Project as ProjectModel; 7 use App\Models\Project as ProjectModel;
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;
9 use App\Models\User as UserModel; 10 use App\Models\User as UserModel;
10 use Illuminate\Http\Request; 11 use Illuminate\Http\Request;
11 use Illuminate\Support\Facades\Cache; 12 use Illuminate\Support\Facades\Cache;
12 -use Illuminate\Support\Facades\DB;  
13 -use Illuminate\Support\Facades\Validator;  
14 -  
15 /*** 13 /***
16 * 当前为公共类 所有方法均不需要验证登录token 14 * 当前为公共类 所有方法均不需要验证登录token
17 */ 15 */
@@ -25,8 +23,8 @@ class ComController extends BaseController @@ -25,8 +23,8 @@ class ComController extends BaseController
25 */ 23 */
26 public function login(Request $request){ 24 public function login(Request $request){
27 $request->validate([ 25 $request->validate([
28 - 'mobile'=>['required,string,max:12'],  
29 - 'password'=>['required,string'], 26 + 'mobile'=>['required'],
  27 + 'password'=>['required'],
30 ],[ 28 ],[
31 'mobile.required'=>'标题必须填写', 29 'mobile.required'=>'标题必须填写',
32 'mobile.string'=>'标题中含有非法文字', 30 'mobile.string'=>'标题中含有非法文字',
@@ -73,8 +71,7 @@ class ComController extends BaseController @@ -73,8 +71,7 @@ class ComController extends BaseController
73 * @author :liyuhang 71 * @author :liyuhang
74 * @method 72 * @method
75 */ 73 */
76 - public function get_project(){  
77 - $projectModel = new ProjectModel(); 74 + public function get_project(ProjectModel $projectModel){
78 $info = $projectModel->read(['id'=>$this->user['project_id']]); 75 $info = $projectModel->read(['id'=>$this->user['project_id']]);
79 if(empty($info)){ 76 if(empty($info)){
80 $this->response('error',Code::USER_ERROR); 77 $this->response('error',Code::USER_ERROR);
@@ -90,14 +87,11 @@ class ComController extends BaseController @@ -90,14 +87,11 @@ class ComController extends BaseController
90 */ 87 */
91 public function edit_info(Request $request){ 88 public function edit_info(Request $request){
92 $request->validate([ 89 $request->validate([
93 - 'password'=>['required,string,min:5'],  
94 - 'name'=>['required,max:20'], 90 + 'password'=>['required'],
  91 + 'name'=>['required'],
95 ],[ 92 ],[
96 'password.required'=>'密码必须填写', 93 'password.required'=>'密码必须填写',
97 - 'password.string'=>'密码中含有非法文字',  
98 - 'password.min' => '密码不小于5字符.',  
99 'name.required'=>'名称必须填写', 94 'name.required'=>'名称必须填写',
100 - 'name.min' => '名称不小于5字符.',  
101 ]); 95 ]);
102 $userModel = new UserModel(); 96 $userModel = new UserModel();
103 $this->param['id'] = $this->uid; 97 $this->param['id'] = $this->uid;
@@ -121,4 +115,5 @@ class ComController extends BaseController @@ -121,4 +115,5 @@ class ComController extends BaseController
121 } 115 }
122 $this->response('success'); 116 $this->response('success');
123 } 117 }
  118 +
124 } 119 }
  1 +<?php
  2 +
  3 +namespace App\Http\Controllers\Bside;
  4 +
  5 +use App\Helper\Arr;
  6 +use App\Http\Logic\Bside\DeptLogic;
  7 +use App\Http\Requests\Bside\DeptRequest;
  8 +use App\Rules\Ids;
  9 +use Illuminate\Http\Request;
  10 +
  11 +/**
  12 + * Class DeptController
  13 + * @package App\Http\Controllers\Bside
  14 + * @author zbj
  15 + * @date 2023/4/18
  16 + */
  17 +class DeptController extends BaseController
  18 +{
  19 +
  20 + public function index(DeptLogic $logic)
  21 + {
  22 + $map = [];
  23 + if(!empty($this->param['search'])){
  24 + $map[] = ['title', 'like', "%{$this->param['search']}%"];
  25 + }
  26 + $sort = ['id' => 'desc'];
  27 + $data = $logic->getList($map, $sort, ['id', 'pid', 'title'],0);
  28 + return $this->success(Arr::listToTree($data));
  29 + }
  30 +
  31 + public function info(Request $request, DeptLogic $logic){
  32 + $request->validate([
  33 + 'id'=>'required'
  34 + ],[
  35 + 'id.required' => 'ID不能为空'
  36 + ]);
  37 + $data = $logic->getInfo($this->param['id']);
  38 + return $this->success(Arr::twoKeepKeys($data, ['id', 'pid', 'title', 'manager_uids', 'remark']));
  39 + }
  40 +
  41 + public function save(DeptRequest $request, DeptLogic $logic)
  42 + {
  43 + $data = $logic->save($this->param);
  44 + return $this->success($data);
  45 + }
  46 +
  47 + public function delete(Request $request, DeptLogic $logic)
  48 + {
  49 + $request->validate([
  50 + 'ids'=>['required', new Ids()]
  51 + ],[
  52 + 'ids.required' => 'ID不能为空'
  53 + ]);
  54 +
  55 + $data = $logic->delete($this->param['ids']);
  56 + return $this->success($data);
  57 + }
  58 +}
  1 +<?php
  2 +
  3 +
  4 +namespace App\Http\Controllers\Bside;
  5 +
  6 +
  7 +use App\Services\Facades\Upload;
  8 +use Illuminate\Http\Request;
  9 +use Illuminate\Support\Facades\Storage;
  10 +
  11 +class FileController extends BaseController
  12 +{
  13 + /**
  14 + * 上传
  15 + * @param Request $request
  16 + * @return \Illuminate\Http\JsonResponse
  17 + * @throws \Psr\Container\ContainerExceptionInterface
  18 + * @throws \Psr\Container\NotFoundExceptionInterface
  19 + * @author zbj
  20 + * @date 2023/4/20
  21 + */
  22 + public function upload(Request $request){
  23 + // 上传文件
  24 + $files = Upload::puts('files', $this->param['config']);
  25 + foreach ($files as &$file){
  26 + $file = Upload::path2url($file);
  27 + }
  28 + return $this->success($files);
  29 + }
  30 +
  31 + /**
  32 + * 下载
  33 + * @param Request $request
  34 + * @return \Symfony\Component\HttpFoundation\StreamedResponse
  35 + * @author zbj
  36 + * @date 2023/4/20
  37 + */
  38 + public function download(Request $request){
  39 + $path = Upload::url2path($this->param['url']);
  40 + return Storage::disk('upload')->download($path);
  41 + }
  42 +}
  1 +<?php
  2 +
  3 +namespace App\Http\Controllers\Bside;
  4 +
  5 +use App\Enums\Common\Code;
  6 +use App\Http\Logic\Bside\MailLogic;
  7 +use App\Models\Mail as MailModel;
  8 +use App\Models\MailUser as MailUserModel;
  9 +use Illuminate\Http\Request;
  10 +
  11 +class MailController extends BaseController
  12 +{
  13 + const STATUS_ZERO = 0; //状态为未读状态
  14 + const STATUS_ONE = 1; //状态为已读状态
  15 + /**
  16 + * @name :当前用户站内信列表
  17 + * @return void
  18 + * @author :liyuhang
  19 + * @method
  20 + */
  21 + public function lists(){
  22 + $mailModel = new MailModel();
  23 + //获取当前用户下的所有站内信
  24 + $this->map['user_list'] = ['like','%,'.$this->uid.',%'];
  25 + $this->map['status'] = $this::STATUS_ZERO;
  26 + $lists = $mailModel->lists($this->map,$this->page,$this->row);
  27 + if(!empty($lists['list'])){
  28 + foreach ($lists['list'] as $k => $v){
  29 + $mailUserModel = new MailUserModel();
  30 + //获取用户已读还是未读
  31 + $info = $mailUserModel->read(['mail_id'=>$v['id'],'user_id'=>$this->uid]);
  32 + if($info !== false){
  33 + $v['read_status'] = $this::STATUS_ONE;//
  34 + }else{
  35 + $v['read_status'] = $this::STATUS_ZERO;
  36 + }
  37 + $lists['list'][$k] = $v;
  38 + }
  39 + }
  40 + $this->response('success',Code::SUCCESS,$lists);
  41 + }
  42 +
  43 + /**
  44 + * @name :获取站内信详情
  45 + * @return void
  46 + * @author :liyuhang
  47 + * @method
  48 + */
  49 + public function info(Request $request,MailLogic $mailLogic){
  50 + $request->validate([
  51 + 'id'=>['required']
  52 + ],[
  53 + 'id.required' => 'ID不能为空'
  54 + ]);
  55 + $info = $mailLogic->mail_info();
  56 + $this->response('success',Code::SUCCESS,$info);
  57 + }
  58 +
  59 +}
  1 +<?php
  2 +
  3 +namespace App\Http\Controllers\Bside\News;
  4 +
  5 +use App\Enums\Common\Code;
  6 +use App\Http\Controllers\Bside\BaseController;
  7 +use App\Http\Logic\Bside\News\NewsCategoryLogic;
  8 +use App\Http\Requests\Bside\News\NewsCategoryRequest;
  9 +use App\Models\News\NewsCategory as NewsCategoryModel;
  10 +use Illuminate\Http\Request;
  11 +
  12 +class NewsCategoryController extends BaseController
  13 +{
  14 + /**
  15 + * @name :新闻分类列表
  16 + * @return json
  17 + * @author :liyuhang
  18 + * @method
  19 + */
  20 + public function lists(NewsCategoryModel $newsCategory){
  21 + //搜索条件
  22 + $this->map['project_id'] = $this->user['project_id'];
  23 + $lists = $newsCategory->lists($this->map,$this->page,$this->row,'sort');
  24 + $this->response('success',Code::SUCCESS,$lists);
  25 + }
  26 +
  27 + /**
  28 + * @name :获取当前分类详情
  29 + * @return void
  30 + * @author :liyuhang
  31 + * @method
  32 + */
  33 + public function info(Request $request,NewsCategoryLogic $newsCategoryLogic){
  34 + $request->validate([
  35 + 'id'=>['required']
  36 + ],[
  37 + 'id.required' => 'ID不能为空'
  38 + ]);
  39 + $info = $newsCategoryLogic->info_news_category();
  40 + $this->response('success',Code::SUCCESS,$info);
  41 + }
  42 + /**
  43 + * @name :添加分类
  44 + * @return json
  45 + * @author :liyuhang
  46 + * @method
  47 + */
  48 + public function add(NewsCategoryRequest $request,NewsCategoryLogic $newsCategoryLogic){
  49 + $request->validated();
  50 + //添加时,验证分类上级分类是否有,有则更新到当前分类中,没有时直接添加
  51 + $newsCategoryLogic->add_news_category();
  52 + //TODO::写入日志
  53 + $this->response('success',Code::SUCCESS,[]);
  54 + }
  55 +
  56 + /**
  57 + * @name :编辑分类
  58 + * @return void
  59 + * @author :liyuhang
  60 + * @method
  61 + */
  62 + public function edit(NewsCategoryRequest $request,NewsCategoryLogic $newsCategoryLogic){
  63 + $request->validate([
  64 + 'id'=>['required']
  65 + ],[
  66 + 'id.required' => 'ID不能为空'
  67 + ]);
  68 + $newsCategoryLogic->edit_news_category();
  69 + //TODO::写入日志
  70 + $this->response('success');
  71 + }
  72 +
  73 + /**
  74 + * @name :编辑状态/排序
  75 + * @return void
  76 + * @author :liyuhang
  77 + * @method
  78 + */
  79 + public function status(Request $request,NewsCategoryLogic $newsCategoryLogic){
  80 + $request->validate([
  81 + 'id'=>['required'],
  82 + ],[
  83 + 'id.required' => 'ID不能为空',
  84 + ]);
  85 + $newsCategoryLogic->status_news_category();
  86 + $this->response('success');
  87 + }
  88 +
  89 + /**
  90 + * @name :删除分类
  91 + * @return void
  92 + * @author :liyuhang
  93 + * @method
  94 + */
  95 + public function del(Request $request,NewsCategoryLogic $newsCategoryLogic){
  96 + $request->validate([
  97 + 'id'=>['required'],
  98 + ],[
  99 + 'id.required' => 'ID不能为空',
  100 + ]);
  101 + $newsCategoryLogic->del_news_category();
  102 + $this->response('success');
  103 + }
  104 +
  105 +}
  1 +<?php
  2 +
  3 +namespace App\Http\Controllers\Bside\News;
  4 +
  5 +use App\Enums\Common\Code;
  6 +use App\Http\Controllers\Bside\BaseController;
  7 +use App\Http\Logic\Bside\News\NewsLogic;
  8 +use App\Http\Requests\Bside\News\NewsRequest;
  9 +use App\Models\News\News as NewsModel;
  10 +use App\Models\News\NewsCategory as NewsCategoryModel;
  11 +use Illuminate\Http\Request;
  12 +
  13 +/**
  14 + * @name:新闻管理
  15 + */
  16 +class NewsController extends BaseController
  17 +{
  18 + /**
  19 + * @name :获取新闻列表
  20 + * @return json
  21 + * @author :liyuhang
  22 + * @method
  23 + */
  24 + public function lists(NewsModel $news){
  25 + $this->map['project_id'] = $this->user['project_id'];
  26 + $lists = $news->lists($this->map,$this->page,$this->row,$this->order);
  27 + if(!empty($lists['list'])){
  28 + foreach ($lists['list'] as $k => $v){
  29 + $newsCategoryModel= new NewsCategoryModel();
  30 + //获取用户已读还是未读
  31 + $category_info = $newsCategoryModel->
  32 + list(['id'=>['in',explode(',',trim($v['category_id'],','))]],'id',['name']);
  33 + $str = '';
  34 + foreach ($category_info as $v1){
  35 + $str .= $v1['name'].',';
  36 + }
  37 + $v['category_id'] = trim($str,',');
  38 + $lists['list'][$k] = $v;
  39 + }
  40 + }
  41 + $this->response('success',Code::SUCCESS,$lists);
  42 + }
  43 +
  44 + /**
  45 + * @name :添加新闻时获取分类列表
  46 + * @return void
  47 + * @author :liyuhang
  48 + * @method
  49 + */
  50 + public function get_category_list(NewsLogic $newsLogic){
  51 + $list = $newsLogic->news_get_category_list();
  52 + $this->response('success',Code::SUCCESS,$list);
  53 + }
  54 + /**
  55 + * @name :获取详情
  56 + * @return void
  57 + * @author :liyuhang
  58 + * @method
  59 + */
  60 + public function info(Request $request,NewsLogic $newsLogic){
  61 + $request->validate([
  62 + 'id'=>['required'],
  63 + ],[
  64 + 'id.required' => 'ID不能为空',
  65 + ]);
  66 + $info = $newsLogic->news_info();
  67 + //TODO::清空相关资源
  68 + $this->response('success',Code::SUCCESS,$info);
  69 + }
  70 + /**
  71 + * @name :添加新闻
  72 + * @return json
  73 + * @author :liyuhang
  74 + * @method
  75 + */
  76 + public function add(NewsRequest $newsRequest,NewsLogic $newsLogic){
  77 + $newsRequest->validated();
  78 + $newsLogic->news_add();
  79 + //TODO::写入日志
  80 + $this->response('success');
  81 + }
  82 +
  83 + /**
  84 + * @name :编辑
  85 + * @return void
  86 + * @author :liyuhang
  87 + * @method
  88 + */
  89 + public function edit(NewsRequest $newsRequest,NewsLogic $newsLogic){
  90 + $newsRequest->validate([
  91 + 'id'=>['required'],
  92 + ],[
  93 + 'id.required' => 'ID不能为空',
  94 + ]);
  95 + $newsLogic->news_edit();
  96 + //TODO::写入日志
  97 + $this->response('success',Code::SUCCESS);
  98 + }
  99 +
  100 + /**
  101 + * @name :编辑状态/与排序
  102 + * @return void
  103 + * @author :liyuhang
  104 + * @method
  105 + */
  106 + public function status(Request $request,NewsLogic $newsLogic){
  107 + $request->validate([
  108 + 'id'=>['required'],
  109 + ],[
  110 + 'id.required' => 'ID不能为空',
  111 + ]);
  112 + $newsLogic->news_status();
  113 + //TODO::写入日志
  114 + $this->response('success');
  115 + }
  116 + /**
  117 + * @name :删除新闻(逻辑删除)
  118 + * @return void
  119 + * @author :liyuhang
  120 + * @method
  121 + */
  122 + public function del(Request $request,NewsLogic $newsLogic){
  123 + $request->validate([
  124 + 'id'=>['required'],
  125 + ],[
  126 + 'id.required' => 'ID不能为空',
  127 + ]);
  128 + $newsLogic->news_del();
  129 + //TODO::清空相关资源/写入日志
  130 + $this->response('success');
  131 + }
  132 +
  133 + /**
  134 + * @name :ai生成
  135 + * @return void
  136 + * @author :liyuhang
  137 + * @method
  138 + */
  139 + public function ai_news(Request $request){
  140 + # id, key, scene, ai
  141 + $request->validate([
  142 + 'keywords'=>['required'],
  143 + 'key'=>['required']
  144 + ],[
  145 + 'keywords.required' => '关键字不能为空',
  146 + 'key.required' => '场景不能为空',
  147 + ]);
  148 + #TODO 通过key获取到ai指令对象
  149 + $url = 'v2/openai_chat';
  150 + $data = $this->send_openai_msg($url);
  151 + $this->response('success',Code::SUCCESS,$data);
  152 + }
  153 +
  154 +}
@@ -56,6 +56,4 @@ class CategoryController extends BaseController @@ -56,6 +56,4 @@ class CategoryController extends BaseController
56 $data = $logic->delete($this->param['ids']); 56 $data = $logic->delete($this->param['ids']);
57 return $this->success($data); 57 return $this->success($data);
58 } 58 }
59 -  
60 - //todo Ai生成 关键词和描述  
61 } 59 }
@@ -2,6 +2,8 @@ @@ -2,6 +2,8 @@
2 2
3 namespace App\Http\Controllers\Bside\Product; 3 namespace App\Http\Controllers\Bside\Product;
4 4
  5 +use App\Enums\Common\Code;
  6 +use App\Exceptions\BsideGlobalException;
5 use App\Helper\Arr; 7 use App\Helper\Arr;
6 use App\Http\Controllers\Bside\BaseController; 8 use App\Http\Controllers\Bside\BaseController;
7 use App\Http\Logic\Bside\Product\ProductLogic; 9 use App\Http\Logic\Bside\Product\ProductLogic;
@@ -13,7 +15,7 @@ use Illuminate\Http\Request; @@ -13,7 +15,7 @@ use Illuminate\Http\Request;
13 * Class ProductController 15 * Class ProductController
14 * @package App\Http\Controllers\Bside 16 * @package App\Http\Controllers\Bside
15 * @author zbj 17 * @author zbj
16 - * @date 2023/4/12 18 + * @date 2023/4/17
17 */ 19 */
18 class ProductController extends BaseController 20 class ProductController extends BaseController
19 { 21 {
@@ -24,9 +26,12 @@ class ProductController extends BaseController @@ -24,9 +26,12 @@ class ProductController extends BaseController
24 if(!empty($this->param['search'])){ 26 if(!empty($this->param['search'])){
25 $map[] = ['title', 'like', "%{$this->param['search']}%"]; 27 $map[] = ['title', 'like', "%{$this->param['search']}%"];
26 } 28 }
  29 + if(!empty($this->param['created_at'])){
  30 + $map[] = ['created_at', 'between', $this->param['created_at']];
  31 + }
27 $sort = ['id' => 'desc']; 32 $sort = ['id' => 'desc'];
28 - $data = $logic->getList($map, $sort, ['id', 'pid', 'title', 'image', 'keywords', 'describe', 'status','created_at'],0);  
29 - return $this->success(Arr::listToTree($data)); 33 + $data = $logic->getList($map, $sort, ['id', 'title', 'thumb', 'category_id', 'keywords', 'status', 'created_at', 'updated_at']);
  34 + return $this->success($data);
30 } 35 }
31 36
32 public function info(Request $request, ProductLogic $logic){ 37 public function info(Request $request, ProductLogic $logic){
@@ -36,11 +41,15 @@ class ProductController extends BaseController @@ -36,11 +41,15 @@ class ProductController extends BaseController
36 'id.required' => 'ID不能为空' 41 'id.required' => 'ID不能为空'
37 ]); 42 ]);
38 $data = $logic->getInfo($this->param['id']); 43 $data = $logic->getInfo($this->param['id']);
39 - return $this->success(Arr::twoKeepKeys($data, ['id', 'pid', 'title', 'image', 'keywords', 'describe', 'status'])); 44 + return $this->success(Arr::twoKeepKeys($data, ['id', 'title', 'gallery', 'attrs', 'category_id', 'keywords', 'intro', 'content',
  45 + 'describe', 'seo_mate', 'related_product_id', 'status']));
40 } 46 }
41 47
42 public function save(ProductRequest $request, ProductLogic $logic) 48 public function save(ProductRequest $request, ProductLogic $logic)
43 { 49 {
  50 + //封面取第一个图片
  51 + $this->param['thumb'] = $this->param['gallery'][0] ?? '';
  52 +
44 $data = $logic->save($this->param); 53 $data = $logic->save($this->param);
45 return $this->success($data); 54 return $this->success($data);
46 } 55 }
@@ -57,5 +66,4 @@ class ProductController extends BaseController @@ -57,5 +66,4 @@ class ProductController extends BaseController
57 return $this->success($data); 66 return $this->success($data);
58 } 67 }
59 68
60 - //todo Ai生成 关键词和描述  
61 } 69 }
1 -<?php  
2 -  
3 -namespace App\Http\Controllers\Bside;  
4 -  
5 -use App\Enums\Common\Code;  
6 -use App\Models\Product as ProductModel;  
7 -use App\Models\ProductClassify as ProductClassifyModel;  
8 -use Illuminate\Support\Facades\Validator;  
9 -  
10 -/**  
11 - * @name:产品表  
12 - */  
13 -class ProductController extends BaseController  
14 -{  
15 - /**  
16 - * @name : 产品列表  
17 - * @return void  
18 - * @author :liyuhang  
19 - * @method  
20 - */  
21 - public function lists(){  
22 - //获取当前登录用户下的产品列表  
23 - $this->map['project_id'] = $this->user['project_id'];  
24 - $productModel = new ProductModel();  
25 - $lists = $productModel->lists($this->map,$this->p,$this->row,$this->order);  
26 - $this->allCount = $productModel->allCount;  
27 - $this->response('success',Code::SUCCESS, $lists);  
28 - }  
29 -  
30 - /**  
31 - * @name :添加产品  
32 - * @return void  
33 - * @author :liyuhang  
34 - * @method  
35 - */  
36 - public function add(){  
37 - //参数验证  
38 - $rules = [  
39 - 'name'=>'required|max:11',  
40 - 'image'=>'required',  
41 - 'describe'=>'required',  
42 - 'keywords'=>'required|max:50',  
43 - ];  
44 - //验证的提示信息  
45 - $message = [  
46 - 'name.required'=>'名称必须填写',  
47 - 'name.max' => '名称不大于16字符.',  
48 - 'image.required'=>'图片必须上传',  
49 - 'describe.required'=>'描述必须填写',  
50 - 'keywords.required'=>'关键字必须填写',  
51 - ];  
52 - $validate = Validator::make($this->param, $rules, $message);  
53 - if($validate->fails()){  
54 - return $this->response($validate->errors()->first(),Code::USER_PARAMS_ERROE,$this->param);  
55 - }  
56 - //TODO::关联项目  
57 - $this->param['project_id'] = $this->user['project_id'];  
58 - $productModel = new ProductModel();  
59 - $this->param['image'] = $this->uploads();  
60 - $rs = $productModel->add($this->param);  
61 - if($rs === false){  
62 - $this->response('error',Code::USER_ERROR);  
63 - }  
64 - $this->response('success',Code::SUCCESS);  
65 - }  
66 -  
67 - public function edit(){  
68 - //参数验证  
69 - $rules = [  
70 - 'name'=>'required|max:11',  
71 - 'image'=>'required',  
72 - 'describe'=>'required',  
73 - 'keywords'=>'required|max:50',  
74 - ];  
75 - //验证的提示信息  
76 - $message = [  
77 - 'name.required'=>'名称必须填写',  
78 - 'name.max' => '名称不大于16字符.',  
79 - 'image.required'=>'图片必须上传',  
80 - 'describe.required'=>'描述必须填写',  
81 - 'keywords.required'=>'关键字必须填写',  
82 - ];  
83 - $validate = Validator::make($this->param, $rules, $message);  
84 - if($validate->fails()){  
85 - return $this->response($validate->errors()->first(),Code::USER_PARAMS_ERROE,$this->param);  
86 - }  
87 - if(isset($this->param['image'])){  
88 - //TODO::删除上一次的图片  
89 - $this->param['image'] = $this->uploads();  
90 - }  
91 - $productModel = new ProductModel();  
92 - $rs = $productModel->edit($this->param,['id'=>$this->param['id']]);  
93 - if($rs === false){  
94 - $this->response('error',Code::USER_ERROR);  
95 - }  
96 - $this->response('success',Code::SUCCESS);  
97 - }  
98 -  
99 - /**  
100 - * @name :修改产品状态  
101 - * @return void  
102 - * @author :liyuhang  
103 - * @method  
104 - */  
105 - public function status(){  
106 - //参数验证  
107 - $rules = [  
108 - 'id'=>'required',  
109 - 'status'=>'required',  
110 - ];  
111 - //验证的提示信息  
112 - $message = [  
113 - 'id.required'=>'主键必须填写',  
114 - 'status.required'=>'状态必须填写',  
115 - ];  
116 - $validate = Validator::make($this->param, $rules, $message);  
117 - if($validate->fails()){  
118 - return $this->response($validate->errors()->first(),Code::USER_PARAMS_ERROE,$this->param);  
119 - }  
120 - $productModel = new ProductModel();  
121 - $rs = $productModel->edit(['status'=>$this->param['status']],['id'=>$this->param['id']]);  
122 - if($rs === false){  
123 - $this->response('error',Code::USER_ERROR);  
124 - }  
125 - $this->response('success',Code::SUCCESS);  
126 - }  
127 -  
128 - /**  
129 - * @name :删除产品  
130 - * @return void  
131 - * @author :liyuhang  
132 - * @method  
133 - */  
134 - public function del(){  
135 - //参数验证  
136 - $rules = [  
137 - 'id'=>'required',  
138 - ];  
139 - //验证的提示信息  
140 - $message = [  
141 - 'id.required'=>'主键必须填写',  
142 - ];  
143 - $validate = Validator::make($this->param, $rules, $message);  
144 - if($validate->fails()){  
145 - return $this->response($validate->errors()->first(),Code::USER_PARAMS_ERROE,$this->param);  
146 - }  
147 - $productModel = new ProductModel();  
148 - $info = $productModel->read(['id'=>$this->param['id']],['image']);  
149 - //TODO::删除添加的图片  
150 - shell_exec('rm -rf '.request()->path().'../../'.$info['image']);  
151 - $rs = $productModel->del(['id'=>$this->param['id']]);  
152 - if($rs === false){  
153 - $this->response('error',Code::USER_ERROR);  
154 - }  
155 - $this->response('success',Code::SUCCESS);  
156 - }  
157 -}  
@@ -2,8 +2,13 @@ @@ -2,8 +2,13 @@
2 2
3 namespace App\Http\Controllers\Bside; 3 namespace App\Http\Controllers\Bside;
4 4
  5 +use App\Enums\Common\Code;
5 use App\Http\Logic\Bside\ProjectGroupLogic; 6 use App\Http\Logic\Bside\ProjectGroupLogic;
6 use App\Http\Requests\Bside\ProjectGroupRequest; 7 use App\Http\Requests\Bside\ProjectGroupRequest;
  8 +use App\Models\ProjectGroup as ProjectGroupModel;
  9 +use App\Models\User as UserModel;
  10 +use Illuminate\Http\Request;
  11 +
7 12
8 /** 13 /**
9 * @name:用户组相关 14 * @name:用户组相关
@@ -16,12 +21,43 @@ class ProjectGroupController extends BaseController @@ -16,12 +21,43 @@ class ProjectGroupController extends BaseController
16 * @author :liyuhang 21 * @author :liyuhang
17 * @method 22 * @method
18 */ 23 */
19 - public function lists() 24 + public function lists(ProjectGroupModel $projectGroupModel)
20 { 25 {
21 - 26 + $lists = $projectGroupModel->lists($this->map,$this->page,$this->row);
  27 + $this->response('success',Code::SUCCESS,$lists);
22 } 28 }
23 29
24 /** 30 /**
  31 + * @name :详情
  32 + * @return json
  33 + * @author :liyuhang
  34 + * @method
  35 + */
  36 + public function info(Request $request,ProjectGroupModel $projectGroupModel){
  37 + $request->validate([
  38 + 'id'=>['required', new Ids()],
  39 + ],[
  40 + 'id.required' => 'ID不能为空',
  41 + ]);
  42 + $rs = $projectGroupModel->read($this->param);
  43 + if($rs === false){
  44 + $this->response('error',Code::USER_ERROR);
  45 + }
  46 + $this->response('success');
  47 + }
  48 + /**
  49 + * @name:添加用户组获取用户列表
  50 + * @return void
  51 + * @author :liyuhang
  52 + * @method
  53 + */
  54 + public function get_user_lists(UserModel $userModel){
  55 + $this->map['project_id'] = $this->user['project_id'];
  56 + //获取当前项目下的所有用户
  57 + $lists = $userModel->list($this->map);
  58 + $this->response('success',Code::SUCCESS,$lists);
  59 + }
  60 + /**
25 * @param ProjectGroupRequest $request 61 * @param ProjectGroupRequest $request
26 * @param ProjectGroupLogic $logic 62 * @param ProjectGroupLogic $logic
27 * @name : 添加用户组 63 * @name : 添加用户组
@@ -29,8 +65,18 @@ class ProjectGroupController extends BaseController @@ -29,8 +65,18 @@ class ProjectGroupController extends BaseController
29 * @author :liyuhang 65 * @author :liyuhang
30 * @method 66 * @method
31 */ 67 */
32 - public function add(ProjectGroupRequest $request){ 68 + public function add(ProjectGroupRequest $request,ProjectGroupModel $projectGroupModel){
33 $request->validated(); 69 $request->validated();
  70 + $this->param['project_id'] = $this->user['project_id'];
  71 + //TODO::成员列表:user_list
  72 + if(!isset($this->param['user_list']) || empty($this->param['user_list'])){
  73 + $this->param['user_list'] = $this->uid;
  74 + }
  75 + $this->param['admin_id'] = $this->uid;
  76 + $rs = $projectGroupModel->add($this->param);
  77 + if($rs === false){
  78 + $this->response('error',Code::USER_ERROR);
  79 + }
34 $this->response('success'); 80 $this->response('success');
35 } 81 }
36 82
@@ -42,8 +88,16 @@ class ProjectGroupController extends BaseController @@ -42,8 +88,16 @@ class ProjectGroupController extends BaseController
42 * @author :liyuhang 88 * @author :liyuhang
43 * @method 89 * @method
44 */ 90 */
45 - public function edit(ProjectGroupRequest $request){  
46 - $request->validated(); 91 + public function edit(ProjectGroupRequest $request,ProjectGroupModel $projectGroupModel){
  92 + $request->validate([
  93 + 'id'=>['required'],
  94 + ],[
  95 + 'id.required' => 'ID不能为空',
  96 + ]);
  97 + $rs = $projectGroupModel->edit($this->param,['id'=>$this->param['id']]);
  98 + if($rs === false){
  99 + $this->response('error',Code::USER_ERROR);
  100 + }
47 $this->response('success'); 101 $this->response('success');
48 } 102 }
49 103
@@ -53,7 +107,16 @@ class ProjectGroupController extends BaseController @@ -53,7 +107,16 @@ class ProjectGroupController extends BaseController
53 * @author :liyuhang 107 * @author :liyuhang
54 * @method 108 * @method
55 */ 109 */
56 - public function del(){  
57 - 110 + public function del(Request $request,ProjectGroupModel $projectGroupModel){
  111 + $request->validate([
  112 + 'id'=>['required'],
  113 + ],[
  114 + 'id.required' => 'ID不能为空',
  115 + ]);
  116 + $rs = $projectGroupModel->del($this->param);
  117 + if($rs === false){
  118 + $this->response('error',Code::USER_ERROR);
  119 + }
  120 + $this->response('success');
58 } 121 }
59 } 122 }
@@ -3,18 +3,17 @@ @@ -3,18 +3,17 @@
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\ProjectRole as ProjectRoleModel; 8 use App\Models\ProjectRole as ProjectRoleModel;
9 use App\Models\User as UserModel; 9 use App\Models\User as UserModel;
10 use Illuminate\Http\Request; 10 use Illuminate\Http\Request;
11 -use Illuminate\Support\Facades\Validator;  
12 11
13 class ProjectRoleController extends BaseController 12 class ProjectRoleController extends BaseController
14 { 13 {
15 /** 14 /**
16 * @name :用户角色列表() 15 * @name :用户角色列表()
17 - * @return void 16 + * @return json
18 * @author :liyuhang 17 * @author :liyuhang
19 * @method 18 * @method
20 */ 19 */
@@ -24,32 +23,44 @@ class ProjectRoleController extends BaseController @@ -24,32 +23,44 @@ class ProjectRoleController extends BaseController
24 $this->map['status'] = 0; 23 $this->map['status'] = 0;
25 $this->map['project_id'] = $this->user['project_id']; 24 $this->map['project_id'] = $this->user['project_id'];
26 //获取当前登录用户自己的菜单栏 25 //获取当前登录用户自己的菜单栏
27 - $lists = $projectRoleModel->lists($this->map,$this->p,$this->row,$this->order); 26 + $lists = $projectRoleModel->lists($this->map,$this->page,$this->row,$this->order);
28 $this->response('success',Code::SUCCESS,$lists); 27 $this->response('success',Code::SUCCESS,$lists);
29 } 28 }
30 29
31 /** 30 /**
32 - * @name :添加/编辑角色时获取菜单列表 31 + * @name :根据角色获取会员列表
33 * @return void 32 * @return void
34 * @author :liyuhang 33 * @author :liyuhang
35 * @method 34 * @method
36 */ 35 */
37 - public function get_role_menu(){  
38 - //根据当前登录用户角色返回用户菜单列表  
39 - $projectRoleModel = new ProjectRoleModel();  
40 - $info = $projectRoleModel->read(['id'=>$this->user['role_id']]);  
41 - $projectMenuModel = new ProjectMenuModel();  
42 - $info['role_menu'] = trim($info['role_menu'],',');  
43 - $lists = $projectMenuModel->where(['status'=>0])->whereIn('id',explode(',',$info['role_menu']))->get();  
44 - $lists = $lists->toArray();  
45 - $menu = array();  
46 - foreach ($lists as $k => $v){  
47 - $v = (array)$v;  
48 - if ($v['pid'] == 0) {  
49 - $v['sub'] = $this->_get_child($v['id'], $lists);  
50 - $menu[] = $v; 36 + public function get_user_list(){
  37 + $userModel = new UserModel();
  38 + $list = $userModel->list(['role_id'=>$this->param['id']],'id',['id','name','mobile']);
  39 + $this->response('success',Code::SUCCESS,$list);
51 } 40 }
  41 + /**
  42 + * @name :详情
  43 + * @return json
  44 + * @author :liyuhang
  45 + * @method
  46 + */
  47 + public function info(Request $request,RoleLogic $roleLogic){
  48 + $request->validate([
  49 + 'id'=>['required'],
  50 + ],[
  51 + 'id.required' => 'ID不能为空',
  52 + ]);
  53 + $info = $roleLogic->role_info();
  54 + $this->response('success',Code::SUCCESS,$info);
52 } 55 }
  56 + /**
  57 + * @name :添加/编辑角色时获取菜单列表
  58 + * @return void
  59 + * @author :liyuhang
  60 + * @method
  61 + */
  62 + public function get_role_menu(RoleLogic $roleLogic){
  63 + $menu = $roleLogic->role_get_menu();
53 $this->response('当前用户菜单列表',Code::SUCCESS,$menu); 64 $this->response('当前用户菜单列表',Code::SUCCESS,$menu);
54 } 65 }
55 /** 66 /**
@@ -58,20 +69,9 @@ class ProjectRoleController extends BaseController @@ -58,20 +69,9 @@ class ProjectRoleController extends BaseController
58 * @author :liyuhang 69 * @author :liyuhang
59 * @method 70 * @method
60 */ 71 */
61 - public function add(ProjectRoleRequest $request){ 72 + public function add(ProjectRoleRequest $request,RoleLogic $roleLogic){
62 $request->validated(); 73 $request->validated();
63 - $this->param['project_id'] = $this->user['project_id'];  
64 - //获取当前项目下的角色超级管理员  
65 - $projectRoleModel = new ProjectRoleModel();  
66 - //验证当前角色是否存在  
67 - $info = $projectRoleModel->read(['name'=>$this->param['name']]);  
68 - if(!empty($info)){  
69 - $this->response('当前添加的角色已存在',Code::USER_PARAMS_ERROE);  
70 - }  
71 - $rs = $projectRoleModel->add($this->param);  
72 - if($rs === false){  
73 - $this->response('添加失败',Code::USER_PARAMS_ERROE);  
74 - } 74 + $roleLogic->role_add();
75 $this->response('添加成功'); 75 $this->response('添加成功');
76 } 76 }
77 77
@@ -81,24 +81,14 @@ class ProjectRoleController extends BaseController @@ -81,24 +81,14 @@ class ProjectRoleController extends BaseController
81 * @author :liyuhang 81 * @author :liyuhang
82 * @method 82 * @method
83 */ 83 */
84 - public function edit(ProjectRoleRequest $request){ 84 + public function edit(ProjectRoleRequest $request,RoleLogic $roleLogic){
85 $request->validate([ 85 $request->validate([
86 'id'=>['required'] 86 'id'=>['required']
87 ],[ 87 ],[
88 'id.required' => 'ID不能为空' 88 'id.required' => 'ID不能为空'
89 ]); 89 ]);
90 - $projectRoleModel = new ProjectRoleModel();  
91 - //TODO::查询当前名称是否重复  
92 - $info = $projectRoleModel->where('id','<>',$this->param['id'])  
93 - ->where(['name'=>$this->param['name'],'project_id'=>$this->user['project_id']])->first();  
94 - if(!empty($info)){  
95 - $this->response('当前添加的角色已存在',Code::USER_PARAMS_ERROE);  
96 - }  
97 - $rs = $projectRoleModel->edit($this->param,['id'=>$this->param['id']]);  
98 - if($rs === false){  
99 - $this->response('编辑失败',Code::USER_PARAMS_ERROE);  
100 - }  
101 - $this->response('编辑成功',Code::SUCCESS); 90 + $roleLogic->role_edit();
  91 + $this->response('编辑成功');
102 } 92 }
103 93
104 /** 94 /**
@@ -107,20 +97,14 @@ class ProjectRoleController extends BaseController @@ -107,20 +97,14 @@ class ProjectRoleController extends BaseController
107 * @author :liyuhang 97 * @author :liyuhang
108 * @method 98 * @method
109 */ 99 */
110 - public function status(Request $request){ 100 + public function status(Request $request,RoleLogic $roleLogic){
111 $request->validate([ 101 $request->validate([
112 'id'=>['required'], 102 'id'=>['required'],
113 - 'status'=>['required'],  
114 ],[ 103 ],[
115 'id.required' => 'ID不能为空', 104 'id.required' => 'ID不能为空',
116 - 'status.required' => 'status不能为空'  
117 ]); 105 ]);
118 - $projectRoleModel = new ProjectRoleModel();  
119 - $rs = $projectRoleModel->edit(['status'=>$this->param['status']],['id'=>$this->param['id']]);  
120 - if($rs === false){  
121 - $this->response('编辑失败',Code::USER_PARAMS_ERROE);  
122 - }  
123 - $this->response($this->param['status'] == 0 ? '启用成功' : '禁用成功',Code::SUCCESS); 106 + $roleLogic->role_status();
  107 + $this->response($this->param['status'] == 0 ? '启用成功' : '禁用成功');
124 } 108 }
125 109
126 /** 110 /**
@@ -129,23 +113,13 @@ class ProjectRoleController extends BaseController @@ -129,23 +113,13 @@ class ProjectRoleController extends BaseController
129 * @author :liyuhang 113 * @author :liyuhang
130 * @method 114 * @method
131 */ 115 */
132 - public function del(Request $request){ 116 + public function del(Request $request,RoleLogic $roleLogic){
133 $request->validate([ 117 $request->validate([
134 'id'=>['required'] 118 'id'=>['required']
135 ],[ 119 ],[
136 'id.required' => 'ID不能为空' 120 'id.required' => 'ID不能为空'
137 ]); 121 ]);
138 - $projectRoleModel = new ProjectRoleModel();  
139 - //查询当前角色下是否有用户  
140 - $userModel = new UserModel();  
141 - $user_info = $userModel->read(['role_id'=>$this->param['id']]);  
142 - if(!empty($user_info)){  
143 - $this->response('当前角色下有用户存在,不允许删除',Code::USER_ERROR);  
144 - }  
145 - $rs = $projectRoleModel->del(['id'=>$this->param['id']]);  
146 - if($rs === false){  
147 - $this->response('error',Code::USER_ERROR);  
148 - } 122 + $roleLogic->role_del();
149 $this->response('success'); 123 $this->response('success');
150 } 124 }
151 } 125 }
@@ -3,9 +3,9 @@ @@ -3,9 +3,9 @@
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 Illuminate\Http\Request; 9 use Illuminate\Http\Request;
10 10
11 class UserController extends BaseController 11 class UserController extends BaseController
@@ -16,15 +16,14 @@ class UserController extends BaseController @@ -16,15 +16,14 @@ class UserController extends BaseController
16 * @author :liyuhang 16 * @author :liyuhang
17 * @method 17 * @method
18 */ 18 */
19 - public function lists(){ 19 + public function lists(UserModel $userModel){
20 //TODO::搜索参数处理 20 //TODO::搜索参数处理
21 - $userModel = new UserModel();  
22 $this->map['project_id'] = $this->user['project_id']; 21 $this->map['project_id'] = $this->user['project_id'];
23 - $lists = $userModel->lists($this->map,$this->p,$this->row,$this->order,['id','name','mobile','created_at']); 22 + $lists = $userModel->lists($this->map,$this->page,$this->row,$this->order,['id','name','mobile','created_at']);
24 if(empty($lists)){ 23 if(empty($lists)){
25 - $this->response('请求失败',Code::USER_ERROR,[]); 24 + $this->response('error',Code::USER_ERROR,[]);
26 } 25 }
27 - $this->response('列表',Code::SUCCESS,$lists); 26 + $this->response('success',Code::SUCCESS,$lists);
28 } 27 }
29 28
30 /** 29 /**
@@ -33,15 +32,10 @@ class UserController extends BaseController @@ -33,15 +32,10 @@ class UserController extends BaseController
33 * @author :liyuhang 32 * @author :liyuhang
34 * @method 33 * @method
35 */ 34 */
36 - public function add(UserRequest $request){ 35 + public function add(UserRequest $request,UserLogic $userLogic){
37 $request->validated(); 36 $request->validated();
38 - $userModel = new UserModel();  
39 - $this->param['project_id'] = $this->user['project_id'];  
40 - $rs = $userModel->adds($this->param);  
41 - if($rs === false){  
42 - $this->response('当前添加用户已存在或参数错误,添加失败',Code::USER_REGISTER_ERROE,[]);  
43 - }  
44 - $this->response('添加成功',Code::SUCCESS,[]); 37 + $userLogic->user_add();
  38 + $this->response('success');
45 } 39 }
46 40
47 /** 41 /**
@@ -50,23 +44,14 @@ class UserController extends BaseController @@ -50,23 +44,14 @@ class UserController extends BaseController
50 * @author :liyuhang 44 * @author :liyuhang
51 * @method 45 * @method
52 */ 46 */
53 - public function edit(UserRequest $request){ 47 + public function edit(UserRequest $request,UserLogic $userLogic){
54 $request->validate([ 48 $request->validate([
55 'id'=>['required'] 49 'id'=>['required']
56 ],[ 50 ],[
57 'id.required' => 'ID不能为空' 51 'id.required' => 'ID不能为空'
58 ]); 52 ]);
59 - $userModel = new UserModel();  
60 - $info = $userModel->where('id','<>',$this->param['id'])  
61 - ->where(['mobile'=>$this->param['mobile']])->first();  
62 - if(!empty($info)){  
63 - $this->response('当前编辑的手机号码已存在',Code::USER_PARAMS_ERROE);  
64 - }  
65 - $rs = $userModel->edits($this->param);  
66 - if($rs === false){  
67 - $this->response('参数错误或其他服务器原因,编辑失败',Code::USER_ERROR,[]);  
68 - }  
69 - $this->response('编辑成功',Code::SUCCESS,[]); 53 + $userLogic->user_edit();
  54 + $this->response('success');
70 } 55 }
71 56
72 /** 57 /**
@@ -75,38 +60,44 @@ class UserController extends BaseController @@ -75,38 +60,44 @@ class UserController extends BaseController
75 * @author :liyuhang 60 * @author :liyuhang
76 * @method 61 * @method
77 */ 62 */
78 - public function status(Request $request){ 63 + public function status(Request $request,UserLogic $userLogic){
79 $request->validate([ 64 $request->validate([
80 'id'=>['required'], 65 'id'=>['required'],
81 - 'status'=>['required'],  
82 ],[ 66 ],[
83 'id.required' => 'ID不能为空', 67 'id.required' => 'ID不能为空',
84 - 'status.required' => 'status不能为空'  
85 ]); 68 ]);
86 - $userLogic = new UserModel();  
87 - $rs = $userLogic->edit($this->param,['id'=>$this->param['id']]);  
88 - if($rs === false){  
89 - $this->response('error',Code::USER_ERROR);  
90 - } 69 + $userLogic->user_status();
91 $this->response($this->param['status'] == 0 ? '启用成功' : '禁用成功'); 70 $this->response($this->param['status'] == 0 ? '启用成功' : '禁用成功');
92 } 71 }
  72 +
93 /** 73 /**
94 - * @name :删除管理员  
95 - * @return void 74 + * @name :详情
  75 + * @return json
96 * @author :liyuhang 76 * @author :liyuhang
97 * @method 77 * @method
98 */ 78 */
99 - public function del(Request $request){ 79 + public function info(Request $request,UserLogic $userLogic){
100 $request->validate([ 80 $request->validate([
101 - 'id'=>['required', new Ids()], 81 + 'id'=>['required'],
102 ],[ 82 ],[
103 'id.required' => 'ID不能为空', 83 'id.required' => 'ID不能为空',
104 ]); 84 ]);
105 - $userModel = new UserModel();  
106 - $rs = $userModel->del($this->param);  
107 - if($rs === false){  
108 - $this->response('删除失败',Code::USER_ERROR); 85 + $userLogic->user_info();
  86 + $this->response('success');
109 } 87 }
110 - $this->response('删除成功'); 88 + /**
  89 + * @name :删除管理员
  90 + * @return json
  91 + * @author :liyuhang
  92 + * @method
  93 + */
  94 + public function del(Request $request,UserLogic $userLogic){
  95 + $request->validate([
  96 + 'id'=>['required'],
  97 + ],[
  98 + 'id.required' => 'ID不能为空',
  99 + ]);
  100 + $userLogic->user_del();
  101 + $this->response('success');
111 } 102 }
112 } 103 }
  1 +<?php
  2 +
  3 +namespace App\Http\Controllers;
  4 +
  5 +use App\Enums\Common\Code;
  6 +use App\Models\Image as ImageModel;
  7 +use Illuminate\Http\Exceptions\HttpResponseException;
  8 +use Illuminate\Http\JsonResponse;
  9 +use Illuminate\Http\Request;
  10 +use Intervention\Image\Facades\Image;
  11 +
  12 +class ImageController
  13 +{
  14 + public $upload_img = [
  15 + //验证
  16 + 'rule' => [
  17 + 'size' => 3 * 1024 * 1024, //大小限制
  18 + 'ext' => 'jpeg,jpg,png,gif', //文件类型限制
  19 + ],
  20 + //生成文件规则
  21 + 'savename' => 'uniqid',
  22 + //设置静态缓存参数(304)
  23 + 'header' => [
  24 + 'Cache-Control' => 'max-age=2592000',
  25 + 'Pragma' => 'cache',
  26 + 'Expires' => "%Expires%", // cache 1 month
  27 + 'etag' => "%etag%",
  28 + 'Last-Modified' => "%Last-Modified%",
  29 + 'Content-Description' => 'File Transfer',
  30 + ],
  31 + //图片保存根路径
  32 + 'path' => './uploads/images/',
  33 + //图片上传变量名
  34 + 'name' => 'image',
  35 + ];
  36 + public $request = '';
  37 +
  38 + public function __construct(Request $request)
  39 + {
  40 + $this->request = $request;
  41 + }
  42 +
  43 + public function index($hash = '', $w = 0 ,$h = 0){
  44 + if (isset($_SERVER['HTTP_IF_MODIFIED_SINCE']) || isset($_SERVER['HTTP_IF_NONE_MATCH'])) {
  45 + header("HTTP/1.1 304 Not Modified");
  46 + exit;
  47 + }
  48 + $imageModel = new ImageModel();
  49 + $info = $imageModel->read(['hash'=>$hash]);
  50 + if ($info === false) {
  51 + $this->response('指定图片不存在!', 404);
  52 + }
  53 + //查看缩略图是否存在
  54 + $filename = './../uploads/images/cache_'. $info['hash'] . $w . '_' . $h;
  55 + if(is_file($filename)){
  56 + $last_modified_time = gmdate(time() + ((30 * 60 * 60 * 24))) . " GMT";
  57 + $header = str_replace(['%Expires%', "%etag%", '%Last-Modified%'],
  58 + [$last_modified_time, $hash . ':' . $w . '_' . $h . '_' . 2, $last_modified_time], $this->upload_img['header']);
  59 + $content = file_get_contents($filename);
  60 + $header['Content-Length'] = $info['size'];
  61 + return response($content, 200, $header);
  62 + }
  63 + $path = './../'.$info['path'];
  64 + if (!is_file($path)) {
  65 + $this->response('指定图片已被系统删除!', 404);
  66 + }
  67 + $content = '';
  68 + $last_modified_time = gmdate(time() + ((30 * 60 * 60 * 24))) . " GMT";
  69 + $header = str_replace(['%Expires%', "%etag%", '%Last-Modified%'],
  70 + [$last_modified_time, $hash . ':' . $w . '_' . $h . '_' . 2, $last_modified_time], $this->upload_img['header']);
  71 + if ($w > 0 && $h > 0) {
  72 + $path = $this->cacheImage($info, $w, $h);
  73 + $content = file_get_contents($path);
  74 + $header['Content-Length'] = strlen($content);
  75 + } else {
  76 + $content = file_get_contents($path);
  77 + $header['Content-Length'] = $info['size'];
  78 + }
  79 + $img_type = $info['type'];
  80 + $content = base64_encode($content);
  81 + $img_base64 = 'data:image/' . $img_type . ';base64,' . $content;
  82 + return response($img_base64, 200, $header);
  83 + }
  84 + /**
  85 + * 图片上传
  86 + */
  87 + public function upload() {
  88 + $this->request->validate([
  89 + 'image'=>['required'],
  90 + ],[
  91 + 'image.required'=>'图片必须填写',
  92 + ]);
  93 + $files = $this->request->file('image');
  94 + if (empty($files)) {
  95 + $this->response('没有上传的文件!', 400);
  96 + }
  97 + $type = $this->request->post('type', 'single');
  98 + if ($type == 'multi') {
  99 + return $this->multi($files);
  100 + } else {
  101 + return $this->single($files);
  102 + }
  103 + }
  104 + /**
  105 + * @name :上传图片
  106 + * @return void
  107 + * @author :liyuhang
  108 + * @method
  109 + */
  110 + public function single($files){
  111 + if (is_array($files)) {
  112 + $file = current($files);
  113 + }
  114 + $url = './../uploads/images/';
  115 + $filename = date('ymdHis').rand(10000,99999);
  116 + $res = $files->move($url,$filename);
  117 + if ($res === false) {
  118 + return $this->fail($files->getError(), 400);
  119 + }
  120 + $data = [
  121 + 'path' => $url.$filename,
  122 + 'created_at' => date('Y-m-d H:i:s',time()),
  123 + 'size' => $res->getSize(),
  124 + 'hash' => $files->hashName(),
  125 + 'mime'=>$files->extension()
  126 + ];
  127 + $imageModel = new ImageModel();
  128 + $imageModel->add($data);
  129 + return $data['hash'];
  130 + }
  131 + /**
  132 + * 生成缩略图缓存
  133 + * @param type $info
  134 + * @param type $w
  135 + * @param type $h
  136 + * @return string
  137 + */
  138 + private function cacheImage($info, $w, $h) {
  139 + $path = './../'.$info['path'];
  140 + $filename = './../uploads/images/cache_'. $info['hash'] . $w . '_' . $h;
  141 + Image::make($path)->resize($w, $h)->save($filename);
  142 + return $filename;
  143 + }
  144 +
  145 + /**
  146 + * @name 统一返回参数
  147 + * @return JsonResponse
  148 + * @author :liyuhang
  149 + * @method
  150 + */
  151 + public function response($msg = null,string $code = Code::SUCCESS,$data = [],$result_code = 200,$type = 'application/json'): JsonResponse
  152 + {
  153 + $code = Code::fromValue($code);
  154 + $result = [
  155 + 'msg' => $msg == ' ' ? $code->description : $msg,
  156 + 'code' => $code->value,
  157 + 'data' => $this->_extents($data),
  158 + ];
  159 + $this->header['Content-Type'] = $type;
  160 + $this->header['token'] = $this->token;
  161 + $response = response($result,$result_code,$this->header);;
  162 + throw new HttpResponseException($response);
  163 + }
  164 +}
@@ -2,15 +2,16 @@ @@ -2,15 +2,16 @@
2 2
3 namespace App\Http\Logic\Aside; 3 namespace App\Http\Logic\Aside;
4 4
5 -class DemoLogic extends BaseLogic 5 +use App\Http\Logic\Aside\BaseLogic;
  6 +use App\Models\AiCommand as AiCommandModel;
  7 +
  8 +class AiCommandLogic extends BaseLogic
6 { 9 {
7 - protected $requestAll;  
8 public function __construct() 10 public function __construct()
9 { 11 {
10 - $this->requestAll=request()->all();  
11 - }  
12 - public function testLogic():array  
13 - {  
14 - return $this->success($this->requestAll); 12 + parent::__construct();
  13 +
  14 + $this->model = new AiCommandModel();
15 } 15 }
  16 +
16 } 17 }
@@ -2,35 +2,24 @@ @@ -2,35 +2,24 @@
2 2
3 namespace App\Http\Logic\Aside; 3 namespace App\Http\Logic\Aside;
4 4
5 -use App\Enums\Common\Code;  
6 -use App\Exceptions\AsideGlobalException; 5 +
  6 +use App\Enums\Common\Common;
  7 +use App\Http\Logic\Logic;
7 8
8 /** 9 /**
9 * @notes: 逻辑层基类 控制器调用 统一返回 统一抛出异常 10 * @notes: 逻辑层基类 控制器调用 统一返回 统一抛出异常
10 * Class BaseLogic 11 * Class BaseLogic
11 * @package App\Http\Logic\Aside 12 * @package App\Http\Logic\Aside
12 */ 13 */
13 -class BaseLogic 14 +class BaseLogic extends Logic
14 { 15 {
15 protected $requestAll; 16 protected $requestAll;
16 - public function __construct()  
17 - {  
18 - $this->requestAll=request()->all();  
19 - }  
20 17
21 - /**  
22 - * @notes: 统一格式化分页返回  
23 - * @return array  
24 - */  
25 - function getPageData($pagninate): array  
26 - {  
27 - $p = $pagninate->toArray();  
28 - $result['list'] = $p ['data'];  
29 - $result['pager']['total'] = $p ['total'];  
30 - $result['pager']['page'] = $p ['current_page'];  
31 - $result['pager']['pagesize'] = $p ['per_page']; 18 + protected $side = Common::A;
32 19
33 - return $result; 20 + public function __construct()
  21 + {
  22 + $this->requestAll = request()->all();
34 } 23 }
35 24
36 } 25 }
  1 +<?php
  2 +
  3 +namespace App\Http\Logic\Aside;
  4 +
  5 +use App\Helper\Arr;
  6 +use App\Models\Manage\Dept;
  7 +use Illuminate\Database\Eloquent\Model;
  8 +
  9 +/**
  10 + * Class DeptLogic
  11 + * @package App\Http\Logic\Aside\dept
  12 + * @author zbj
  13 + * @date 2023/4/20
  14 + */
  15 +class DeptLogic extends BaseLogic
  16 +{
  17 + public function __construct()
  18 + {
  19 + parent::__construct();
  20 +
  21 + $this->model = new Dept();
  22 + }
  23 +
  24 + public function save($param){
  25 + if(!empty($param['pid'])){
  26 + if(!empty($param['id']) && $param['pid'] == $param['id']){
  27 + $this->fail('上级部门不能是本部门');
  28 + }
  29 + $p_cate = $this->getCacheInfo($param['pid']);
  30 + if(!$p_cate){
  31 + $this->fail('上级部门不存在');
  32 + }
  33 + }
  34 + return parent::save($param);
  35 + }
  36 +
  37 + public function delete($ids, $map = []){
  38 + $ids= array_filter(Arr::splitFilterToArray($ids), 'intval');
  39 + foreach ($ids as $id){
  40 + $info = $this->getCacheInfo($id);
  41 + if(!$info){
  42 + continue;
  43 + }
  44 + //是否有子部门
  45 + if(Dept::where('pid', $id)->count()){
  46 + $this->fail("部门{$info['title']}存在下级部门,不能删除");
  47 + }
  48 + }
  49 + return parent::delete($ids);
  50 + }
  51 +}
  1 +<?php
  2 +
  3 +namespace App\Http\Logic\Aside;
  4 +
  5 +
  6 +use App\Helper\Arr;
  7 +use App\Models\Manage\Group;
  8 +
  9 +/**
  10 + * Class GroupLogic
  11 + * @package App\Http\Logic\Aside
  12 + * @author zbj
  13 + * @date 2023/4/19
  14 + */
  15 +class GroupLogic extends BaseLogic
  16 +{
  17 + public function __construct()
  18 + {
  19 + parent::__construct();
  20 +
  21 + $this->model = new Group();
  22 + }
  23 +}
  1 +<?php
  2 +
  3 +namespace App\Http\Logic\Aside;
  4 +
  5 +use App\Models\Manage\Manage;
  6 +use App\Models\Manage\LoginLog;
  7 +use Illuminate\Support\Facades\Hash;
  8 +use Illuminate\Support\Facades\Session;
  9 +
  10 +
  11 +/**
  12 + * Class LoginLogic
  13 + * @package App\Http\Logic\Aside
  14 + * @author zbj
  15 + * @date 2023/4/19
  16 + */
  17 +class LoginLogic extends BaseLogic
  18 +{
  19 + public function __construct()
  20 + {
  21 + parent::__construct();
  22 +
  23 + $this->model = new Manage();
  24 + }
  25 +
  26 +
  27 + public function login()
  28 + {
  29 + $manage = $this->model->where('mobile', $this->requestAll['mobile'])->first();
  30 +
  31 + if (!$manage){
  32 + $this->fail('登录用户名不存在');
  33 + }
  34 + if (Manage::STATUS_DISABLE == $manage->status) {
  35 + $this->fail('帐号已被禁用');
  36 + }
  37 + if (!Hash::check($this->requestAll['password'], $manage->password)) {
  38 + $this->fail('登录密码不正确');
  39 + }
  40 + Session::put('manage', $manage->toArray());
  41 +
  42 + LoginLog::addLog($manage->id);
  43 +
  44 + return $this->success();
  45 + }
  46 +
  47 + public function logout(){
  48 + Session::forget('manage');
  49 + return redirect(route('admin.login'));
  50 + }
  51 +}
  1 +<?php
  2 +
  3 +namespace App\Http\Logic\Aside;
  4 +
  5 +use App\Helper\Arr;
  6 +use App\Models\Manage\Manage;
  7 +use Illuminate\Database\Eloquent\Model;
  8 +use Illuminate\Support\Facades\Hash;
  9 +
  10 +/**
  11 + * Class ManageLogic
  12 + * @package App\Http\Logic\Aside\Manage
  13 + * @author zbj
  14 + * @date 2023/4/20
  15 + */
  16 +class ManageLogic extends BaseLogic
  17 +{
  18 + public function __construct()
  19 + {
  20 + parent::__construct();
  21 +
  22 + $this->model = new Manage();
  23 + }
  24 +
  25 + public function save($param){
  26 + if(!empty($param['password'])){
  27 + $param['password'] = Hash::make($param['password']);
  28 + }
  29 + return parent::save($param);
  30 + }
  31 +}
  1 +<?php
  2 +
  3 +namespace App\Http\Logic\Aside;
  4 +
  5 +
  6 +use App\Helper\Arr;
  7 +use App\Models\Manage\Menu;
  8 +use Illuminate\Support\Facades\Route;
  9 +use Illuminate\Support\Str;
  10 +
  11 +/**
  12 + * Class MenuLogic
  13 + * @package App\Http\Logic\Aside
  14 + * @author zbj
  15 + * @date 2023/4/19
  16 + */
  17 +class MenuLogic extends BaseLogic
  18 +{
  19 + public function __construct()
  20 + {
  21 + parent::__construct();
  22 +
  23 + $this->model = new Menu();
  24 + }
  25 +
  26 + public function getInfo($id)
  27 + {
  28 + $info = parent::getInfo($id);
  29 +
  30 + //已绑定菜单的路由
  31 + $menu_route = array_filter(Menu::pluck('route_name')->toArray());
  32 + //路由
  33 + $info['route'] = [];
  34 + $routes = Route::getRoutes()->getRoutesByName();
  35 + foreach ($routes as $name => $route) {
  36 + if(Str::startsWith($name, 'admin.') && !Str::endsWith($name, '.white') && !in_array($name, $menu_route)){
  37 + $info['route'][] = $name;
  38 + }
  39 + }
  40 +
  41 + return $this->success($info);
  42 + }
  43 +
  44 + public function save($param){
  45 + if(!empty($param['pid'])){
  46 + if(!empty($param['id']) && $param['pid'] == $param['id']){
  47 + $this->fail('上级菜单不能是本菜单');
  48 + }
  49 + $p_menu = $this->getCacheInfo($param['pid']);
  50 + if(!$p_menu){
  51 + $this->fail('上级菜单不存在');
  52 + }
  53 + }
  54 + return parent::save($param);
  55 + }
  56 +
  57 + public function delete($ids, $map = []){
  58 + $ids= array_filter(Arr::splitFilterToArray($ids), 'intval');
  59 + foreach ($ids as $id){
  60 + $info = $this->getCacheInfo($id);
  61 + if(!$info){
  62 + continue;
  63 + }
  64 + //是否有子菜单
  65 + if(Menu::where('pid', $id)->count()){
  66 + $this->fail("菜单{$info['title']}存在子菜单,不能删除");
  67 + }
  68 + }
  69 + return parent::delete($ids);
  70 + }
  71 +}
  1 +<?php
  2 +
  3 +namespace App\Http\Logic\Aside;
  4 +
  5 +
  6 +use App\Models\Project;
  7 +
  8 +class ProjectLogic extends BaseLogic
  9 +{
  10 + public function __construct()
  11 + {
  12 + parent::__construct();
  13 + $this->model = new Project();
  14 + $this->param = $this->requestAll;
  15 + }
  16 +
  17 +}
  1 +<?php
  2 +
  3 +namespace App\Http\Logic\Aside;
  4 +
  5 +use App\Models\ProjectRole;
  6 +
  7 +class ProjectRoleLogic extends BaseLogic
  8 +{
  9 + public function __construct()
  10 + {
  11 + parent::__construct();
  12 +
  13 + $this->model = new ProjectRole();
  14 + $this->param = $this->requestAll;
  15 + }
  16 +
  17 +}
  1 +<?php
  2 +
  3 +namespace App\Http\Logic\Aside;
  4 +
  5 +use App\Models\User;
  6 +
  7 +class UserLogic extends BaseLogic
  8 +{
  9 + public function __construct()
  10 + {
  11 + parent::__construct();
  12 +
  13 + $this->model = new User();
  14 + $this->param = $this->requestAll;
  15 + }
  16 +
  17 +}
@@ -4,44 +4,28 @@ namespace App\Http\Logic\Bside; @@ -4,44 +4,28 @@ namespace App\Http\Logic\Bside;
4 4
5 use App\Enums\Common\Code; 5 use App\Enums\Common\Code;
6 use App\Exceptions\BsideGlobalException; 6 use App\Exceptions\BsideGlobalException;
7 -use App\Helper\Arr; 7 +use App\Http\Logic\Logic;
  8 +use App\Models\Image as ImageModel;
  9 +use Illuminate\Http\Request;
8 use Illuminate\Support\Facades\Cache; 10 use Illuminate\Support\Facades\Cache;
9 11
10 /** 12 /**
11 * @notes: 逻辑层基类 控制器调用 统一返回 统一抛出异常 13 * @notes: 逻辑层基类 控制器调用 统一返回 统一抛出异常
12 */ 14 */
13 -class BaseLogic 15 +class BaseLogic extends Logic
14 { 16 {
15 - protected $model;  
16 17
17 protected $requestAll; 18 protected $requestAll;
18 19
19 - protected $is_cache = true; //是否缓存数据 20 + protected $param;
  21 +
  22 + protected $user;
20 23
21 public function __construct() 24 public function __construct()
22 { 25 {
23 $this->requestAll = request()->all(); 26 $this->requestAll = request()->all();
24 - }  
25 27
26 - /**  
27 - * @notes: 请简要描述方法功能  
28 - * @param array $data  
29 - * @return array  
30 - */  
31 - public function success(array $data = [])  
32 - {  
33 - return $data;  
34 - }  
35 -  
36 - /**  
37 - * @notes: 错误抛出  
38 - * @param string $code  
39 - * @param string $message  
40 - * @throws BsideGlobalException  
41 - */  
42 - public function fail(string $message = "", string $code = Code::SYSTEM_ERROR)  
43 - {  
44 - throw new BsideGlobalException($code, $message); 28 + $this->user = Cache::get(request()->header('token'));
45 } 29 }
46 30
47 31
@@ -57,41 +41,8 @@ class BaseLogic @@ -57,41 +41,8 @@ class BaseLogic
57 */ 41 */
58 public function getList(array $map = [], array $sort = ['id' => 'desc'], array $columns = ['*'], int $limit = 20) 42 public function getList(array $map = [], array $sort = ['id' => 'desc'], array $columns = ['*'], int $limit = 20)
59 { 43 {
60 - // 闭包查询条件格式化  
61 - $query = $this->formatQuery($map);  
62 -  
63 - // 排序(支持多重排序)  
64 - $query = $query->when($sort, function ($query, $sort) {  
65 - foreach ($sort as $k=>$v) {  
66 - $query->orderBy($k, $v);  
67 - }  
68 - });  
69 -  
70 - // 数据分页设置  
71 - if ($limit) {  
72 - $result = $query->select($columns)->paginate($limit);  
73 - }else{  
74 - $result = $query->select($columns)->get();  
75 - }  
76 -  
77 - return $this->success($result ? $result->toArray() : []);  
78 - }  
79 -  
80 -  
81 - /**  
82 - * 详情  
83 - * @param $id  
84 - * @return array  
85 - * @author zbj  
86 - * @date 2023/4/13  
87 - */  
88 - public function getInfo($id)  
89 - {  
90 - $info = $this->getCacheInfo($id);  
91 - if(!$info){  
92 - $this->fail('数据不存在或者已经删除');  
93 - }  
94 - return $this->success($info->toArray()); 44 + $map[] = ['project_id' => $this->user['project_id']];
  45 + return parent::getList($map, $sort, $columns, $limit);
95 } 46 }
96 47
97 /** 48 /**
@@ -100,17 +51,11 @@ class BaseLogic @@ -100,17 +51,11 @@ class BaseLogic
100 * @author zbj 51 * @author zbj
101 * @date 2023/4/15 52 * @date 2023/4/15
102 */ 53 */
103 - public function getCacheInfo($id){  
104 - if($this->is_cache){  
105 - $info = Cache::get($this->getInfoCacheKey($id));  
106 - if (!$info) {  
107 - $info = $this->model->find($id);  
108 - if($info){  
109 - Cache::put($this->getInfoCacheKey($id), $info);  
110 - }  
111 - }  
112 - }else{  
113 - $info = $this->model->find($id); 54 + public function getCacheInfo($id)
  55 + {
  56 + $info = parent::getCacheInfo($id);
  57 + if ($info && $info['project_id'] != $this->user['project_id']) {
  58 + $info = null;
114 } 59 }
115 return $info; 60 return $info;
116 } 61 }
@@ -123,175 +68,53 @@ class BaseLogic @@ -123,175 +68,53 @@ class BaseLogic
123 * @author zbj 68 * @author zbj
124 * @date 2023/4/13 69 * @date 2023/4/13
125 */ 70 */
126 - public function save($param){  
127 - if(!empty($param['id'])){  
128 - $this->model = $this->getCacheInfo($param['id']);  
129 - if(!$this->model){  
130 - $this->fail('数据不存在或者已经删除');  
131 - }  
132 - }  
133 -  
134 - foreach ($param as $name => $value){  
135 - $this->model[$name] = $value;  
136 - }  
137 -  
138 - $res = $this->model->save();  
139 -  
140 - if($res){  
141 - //清缓存  
142 - if($this->is_cache && !empty($param['id'])){  
143 - Cache::forget($this->getInfoCacheKey($param['id']));  
144 - }  
145 - return $this->success(['id' => $this->model->id]); //返回保存的数据id  
146 - }else{  
147 - $this->fail('保存失败');  
148 - } 71 + public function save($param)
  72 + {
  73 + $param['project_id'] = $this->user['project_id'];
  74 + return parent::save($param);
149 } 75 }
150 76
151 /** 77 /**
152 * 批量删除 78 * 批量删除
153 * @param $ids 79 * @param $ids
  80 + * @param array $map
154 * @return array 81 * @return array
155 - * @throws BsideGlobalException  
156 - * @author zbj  
157 - * @date 2023/4/13  
158 - */  
159 - public function delete($ids){  
160 - $ids = array_filter(Arr::splitFilterToArray($ids), 'intval');  
161 - if(!$ids){  
162 - $this->fail('ID不能为空');  
163 - }  
164 - $map[] = ['id', 'in', $ids];  
165 - $res = $this->formatQuery($map)->delete();  
166 - if($res){  
167 -  
168 - if($this->is_cache){  
169 - foreach ($ids as $id){  
170 - Cache::forget($this->getInfoCacheKey($id));  
171 - }  
172 - }  
173 - return $this->success();  
174 - }else{  
175 - $this->fail('删除失败');  
176 - }  
177 - }  
178 -  
179 - /**  
180 - * @param $id  
181 - * @return string  
182 * @author zbj 82 * @author zbj
183 * @date 2023/4/13 83 * @date 2023/4/13
184 */ 84 */
185 - public function getInfoCacheKey($id){  
186 - return $this->model->getTable() . '_info_' . $id; 85 + public function delete($ids, $map = [])
  86 + {
  87 + $map[] = ['project_id' => $this->user['project_id']];
  88 + return parent::delete($ids, $map);
187 } 89 }
188 -  
189 /** 90 /**
190 - * 格式化查询条件  
191 - * @param $map  
192 - * @param $query  
193 - * @return mixed  
194 - * @author zbj  
195 - * @date 2023/4/13 91 + * @name :上传图片
  92 + * @return void
  93 + * @author :liyuhang
  94 + * @method
196 */ 95 */
197 - public function formatQuery($map, $query = '')  
198 - {  
199 - $model = $query ?: $this->model;  
200 - $query = $model->where(function ($query) use ($map) {  
201 - foreach ($map as $v) {  
202 - if ($v instanceof \Closure) {  
203 - $query = $query->where($v);  
204 - continue;  
205 - }  
206 - // 判断是否是键值对类型  
207 - if (key($v) !== 0) {  
208 - $key = key($v);  
209 - $val = $v[$key];  
210 - $v = [$key, is_array($val) ? 'in' : '=', $val];  
211 - }  
212 - switch ($v[1]) {  
213 - case 'like':  
214 - // like查询 ['name|title', 'like', '%a%']  
215 - if (strpos($v[0], '|') !== false) {  
216 - $query->where(function ($query) use ($v) {  
217 - $item = explode('|', $v[0]);  
218 - foreach ($item as $vo) {  
219 - $query->orWhere($vo, $v[1], $v[2]);  
220 - }  
221 - });  
222 - } else {  
223 - $query->where($v[0], $v[1], $v[2]);  
224 - }  
225 - break;  
226 - case 'in':  
227 - // in查询 ['id', 'in', [1,2,3]]  
228 - if (!is_array($v[2])) {  
229 - $v[2] = explode(',', $v[2]);  
230 - }  
231 - $query->whereIn($v[0], $v[2]);  
232 - break;  
233 - case 'not in':  
234 - // not in查询 ['id', 'not in', [1,2,3]]  
235 - if (!is_array($v[2])) {  
236 - $v[2] = explode(',', $v[2]);  
237 - }  
238 - $query->whereNotIn($v[0], $v[2]);  
239 - break;  
240 - case 'between':  
241 - // between查询 ['created_at', 'between', ['xxx', 'xxx]]  
242 - if (!is_array($v[2])) {  
243 - $v[2] = explode(',', $v[2]);  
244 - }  
245 - $query->whereBetween($v[0], $v[2]);  
246 - break;  
247 - case 'not between':  
248 - // not between查询 ['created_at', 'not between', ['xxx', 'xxx]]  
249 - if (!is_array($v[2])) {  
250 - $v[2] = explode(',', $v[2]);  
251 - }  
252 - $query->whereNotBetween($v[0], $v[2]);  
253 - break;  
254 - case 'null':  
255 - // null查询 ['deleted_at', 'null']  
256 - $query->whereNull($v[0]);  
257 - break;  
258 - case "not null":  
259 - // not null查询 ['deleted_at', 'not null']  
260 - $query->whereNotNull($v[0]);  
261 - break;  
262 - case "or":  
263 - // or查询 [[['status'=>1],['status'=>2]], 'or'];  
264 - //格式:or (status=1 and status=2)  
265 - $where = $v[0];  
266 - $query->orWhere(function ($query) use ($where) {  
267 - // 递归解析查询条件  
268 - $this->formatQuery($where, $query);  
269 - });  
270 - break;  
271 - case 'xor':  
272 - // xor查询 [[['status'=>1],['status'=>2]], 'xor'];  
273 - // 格式:and (status=1 or status=2)  
274 - $where = $v[0];  
275 - $query->where(function ($query) use ($where) {  
276 - foreach ($where as $w) {  
277 - $query->orWhere(function ($query) use ($w) {  
278 - // 递归解析查询条件  
279 - $this->formatQuery([$w], $query);  
280 - });  
281 - }  
282 - });  
283 - break;  
284 - default:  
285 - // 常规查询  
286 - if (count($v) == 2) {  
287 - $query->where($v[0], '=', $v[1]);  
288 - } else {  
289 - $query->where($v[0], $v[1], $v[2]);  
290 - }  
291 - break;  
292 - }  
293 - }  
294 - });  
295 - return $query; 96 + public function upload(Request $request,ImageModel $imageModel){
  97 + $image = $request->file('image');
  98 + if(empty($image)){
  99 + return $this->fail('没有上传图片',Code::USER_ERROR);
  100 + }
  101 + $url = './../uploads/images/';
  102 + $filename = date('ymdHis').rand(10000,99999);
  103 + $res = $request->file('image')->move($url,$filename);
  104 + if ($res === false) {
  105 + return $this->fail($image->getError(), Code::USER_ERROR);
  106 + }
  107 + $data = [
  108 + 'path' => $url.$filename,
  109 + 'created_at' => date('Y-m-d H:i:s',time()),
  110 + 'size' => $res->getSize(),
  111 + 'hash' => $image->hashName(),
  112 + 'mime'=>$image->extension()
  113 + ];
  114 + $rs = $imageModel->add($data);
  115 + if ($rs === false) {
  116 + return $this->fail('添加失败', Code::USER_ERROR);
  117 + }
  118 + return $data['hash'];
296 } 119 }
297 } 120 }
  1 +<?php
  2 +
  3 +namespace App\Http\Logic\Bside\Blog;
  4 +
  5 +use App\Enums\Common\Code;
  6 +use App\Http\Logic\Bside\BaseLogic;
  7 +use App\Models\Blog\BlogCategory as BlogCategoryModel;
  8 +use App\Models\Blog\Blog as BlogModel;
  9 +use App\Models\News\NewsCategory as NewsCategoryModel;
  10 +use Illuminate\Support\Facades\DB;
  11 +
  12 +class BlogCategoryLogic extends BaseLogic
  13 +{
  14 + public function __construct()
  15 + {
  16 + parent::__construct();
  17 +
  18 + $this->model = new BlogCategoryModel();
  19 + $this->param = $this->requestAll;
  20 + }
  21 +
  22 +
  23 + /**
  24 + * @name :添加时验证上级分类是否有商品,有则替换带当前分类下
  25 + * @return void
  26 + * @author :liyuhang
  27 + * @method
  28 + */
  29 + public function add_blog_category(){
  30 + DB::beginTransaction();
  31 + $this->param['project_id'] = $this->user['project_id'];
  32 + $this->param['operator_id'] = $this->user['id'];
  33 + $this->param['create_id'] = $this->user['id'];
  34 + $this->param['created_at'] = date('Y-m-d H:i:s');
  35 + $this->param['updated_at'] = date('Y-m-d H:i:s');
  36 + $cate_id = $this->model->insertGetId($this->param);
  37 + if($cate_id === false){
  38 + DB::rollBack();
  39 + $this->fail('error',Code::USER_ERROR);
  40 + }
  41 + //判断为子分类时
  42 + if(isset($this->param['pid']) && !empty($this->param['pid'])) {
  43 + //查看当前上级分类下是否有其他分类
  44 + $cate_info = $this->model->read(['pid' => $this->param['pid'], 'id' => ['!=', $cate_id]]);
  45 + if ($cate_info === false) {
  46 + //查看当前上一级分类下是否有新闻
  47 + $blogModel = new BlogModel();
  48 + $news_info = $blogModel->read(['category_id' => ['like', ',' . $this->param['pid'] . ',']]);
  49 + if ($news_info !== false) {
  50 + $replacement = ',' . $cate_id . ',';
  51 + $old = ',' . $this->param['pid'] . ',';
  52 + //更新所有商品到当前分类
  53 + $rs = DB::table('gl_Blog')->where('category_id', 'like', '%' . $old . '%')
  54 + ->update(['category_id' => DB::raw("REPLACE(category_id, '$old', '$replacement')")]);
  55 + if ($rs === false) {
  56 + DB::rollBack();
  57 + $this->fail('error', Code::USER_ERROR);
  58 + }
  59 + }
  60 + }
  61 + }
  62 + DB::commit();
  63 + return $this->success();
  64 + }
  65 +
  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 + /**
  112 + * @name :删除博客分类
  113 + * @return void
  114 + * @author :liyuhang
  115 + * @method
  116 + */
  117 + public function del_blog_category(){
  118 + $this->param = $this->requestAll;
  119 + foreach ($this->param['id'] as $v){
  120 + //查询是否有子分类
  121 + $rs = $this->model->read(['pid'=>$v],['id']);
  122 + if($rs !== false){
  123 + $this->response('当前分类拥有子分类不允许删除',Code::USER_ERROR);
  124 + }
  125 + //查看当前分内下是否有博客
  126 + $blogModel = new BlogModel();
  127 + $rs = $blogModel->read(['category_id'=>$v],['id']);
  128 + if($rs !== false){
  129 + $this->response('当前分类拥有博客',Code::USER_ERROR);
  130 + }
  131 + }
  132 + $this->param['id'] = ['in',$this->param['id']];
  133 + $rs = $this->model->del($this->param);
  134 + if($rs === false){
  135 + $this->response('error',Code::USER_ERROR);
  136 + }
  137 + return $this->success();
  138 + }
  139 +}
  1 +<?php
  2 +
  3 +namespace App\Http\Logic\Bside\Blog;
  4 +
  5 +use App\Enums\Common\Code;
  6 +use App\Http\Logic\Bside\BaseLogic;
  7 +use App\Models\Blog\BlogLabel as BlogLabelModel;
  8 +
  9 +class BlogLabelLogic extends BaseLogic
  10 +{
  11 + public function __construct()
  12 + {
  13 + parent::__construct();
  14 +
  15 + $this->model = new BlogLabelModel();
  16 + $this->param = $this->requestAll;
  17 + }
  18 +
  19 + /**
  20 + * @name :新增标签
  21 + * @return void
  22 + * @author :liyuhang
  23 + * @method
  24 + */
  25 + public function add_blog_label(){
  26 + $this->param['create_id'] = $this->user['id'];
  27 + $this->param['Operator_id'] = $this->user['id'];
  28 + $this->param['project_id'] = $this->user['project_id'];
  29 + $rs = $this->model->add($this->param);
  30 + if($rs === false){
  31 + $this->fail('error',Code::USER_ERROR);
  32 + }
  33 + return $this->success();
  34 + }
  35 +
  36 + /**
  37 + * @name :编辑标签
  38 + * @return void
  39 + * @author :liyuhang
  40 + * @method
  41 + */
  42 + public function edit_blog_label(){
  43 + $this->param['operator_id'] = $this->user['id'];
  44 + $rs = $this->model->edit($this->param,['id'=>$this->param['id']]);
  45 + //TODO::路由映射
  46 + if($rs === false){
  47 + $this->fail('error',Code::USER_ERROR);
  48 + }
  49 + return $this->success();
  50 + }
  51 +
  52 + /**
  53 + * @name :删除标签
  54 + * @return array
  55 + * @author :liyuhang
  56 + * @method
  57 + */
  58 + public function del_blog_label(){
  59 + $this->param['id'] = ['in',$this->param['id']];
  60 + $rs = $this->model->del($this->param);
  61 + if($rs === false){
  62 + $this->fail('error',Code::USER_ERROR);
  63 + }
  64 + return $this->success();
  65 + }
  66 +}
  1 +<?php
  2 +
  3 +namespace App\Http\Logic\Bside\Blog;
  4 +
  5 +use App\Enums\Common\Code;
  6 +use App\Http\Logic\Bside\BaseLogic;
  7 +use App\Models\Blog\Blog;
  8 +use App\Models\Blog\BlogCategory as BlogCategoryModel;
  9 +use App\Models\RouteMap;
  10 +use Illuminate\Support\Facades\DB;
  11 +
  12 +class BlogLogic extends BaseLogic
  13 +{
  14 + public function __construct()
  15 + {
  16 + parent::__construct();
  17 +
  18 + $this->model = new Blog();
  19 + $this->param = $this->requestAll;
  20 + }
  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 + }
  46 + /**
  47 + * @name :添加博客
  48 + * @return void
  49 + * @author :liyuhang
  50 + * @method
  51 + */
  52 + public function blog_add(){
  53 + $this->param['create_id'] = $this->uid;
  54 + $this->param['operator_id'] = $this->uid;
  55 + $this->param['project_id'] = $this->user['project_id'];
  56 + DB::beginTransaction();
  57 + try {
  58 + $rs = $this->model->insertGetId($this->param);
  59 + RouteMap::setRoute($this->param['url'], RouteMap::SOURCE_BLOG, $rs, $this->user['project_id']);
  60 + DB::commit();
  61 + }catch (\Exception $e){
  62 + DB::rollBack();
  63 + $this->fail('error',Code::USER_ERROR);
  64 + }
  65 + //TODO::写入日志
  66 + $this->success();
  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 + }
  88 + /**
  89 + * @name :获取数据详情
  90 + * @return array
  91 + * @throws \App\Exceptions\BsideGlobalException
  92 + * @author :liyuhang
  93 + * @method
  94 + */
  95 + public function blog_info(){
  96 + $info = $this->model->read($this->param);
  97 + //获取分类名称
  98 + $info['category_id'] = explode(',',trim($info['category_id'],','));
  99 + $blogCategoryModel = new BlogCategoryModel();
  100 + $category_list = $blogCategoryModel->list(['id'=>['in',$info['category_id']]],'id',['name']);
  101 + $str = '';
  102 + foreach ($category_list as $v){
  103 + $str .= $v['name'].',';
  104 + }
  105 + $info['category_id'] = trim($str,',');
  106 + if($info === false){
  107 + $this->fail('error',Code::USER_ERROR);
  108 + }
  109 + return $this->success($info);
  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 + }
  142 +}
  1 +<?php
  2 +
  3 +namespace App\Http\Logic\Bside;
  4 +
  5 +use App\Helper\Arr;
  6 +use App\Models\ProjectDept;
  7 +
  8 +/**
  9 + * Class DeptLogic
  10 + * @package App\Http\Logic\Bside\dept
  11 + * @author zbj
  12 + * @date 2023/4/18
  13 + */
  14 +class DeptLogic extends BaseLogic
  15 +{
  16 + public function __construct()
  17 + {
  18 + parent::__construct();
  19 +
  20 + $this->model = new ProjectDept();
  21 + }
  22 +
  23 + public function save($param){
  24 + if(!empty($param['pid'])){
  25 + if(!empty($param['id']) && $param['pid'] == $param['id']){
  26 + $this->fail('上级部门不能是本部门');
  27 + }
  28 + $p_cate = $this->getCacheInfo($param['pid']);
  29 + if(!$p_cate){
  30 + $this->fail('上级部门不存在');
  31 + }
  32 + }
  33 + return parent::save($param);
  34 + }
  35 +
  36 + public function delete($ids, $map =[]){
  37 + $ids= array_filter(Arr::splitFilterToArray($ids), 'intval');
  38 + foreach ($ids as $id){
  39 + $info = $this->getCacheInfo($id);
  40 + if(!$info){
  41 + continue;
  42 + }
  43 + //是否有子部门
  44 + if(ProjectDept::where('project_id', $this->user['project_id'])->where('pid', $id)->count()){
  45 + $this->fail("部门{$info['title']}存在下级部门,不能删除");
  46 + }
  47 + }
  48 + return parent::delete($ids);
  49 + }
  50 +}
  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 +}
  1 +<?php
  2 +
  3 +namespace App\Http\Logic\Bside;
  4 +
  5 +use App\Enums\Common\Code;
  6 +use App\Models\Mail as MailModel;
  7 +use App\Models\MailUser as MailUserModel;
  8 +
  9 +class MailLogic extends BaseLogic
  10 +{
  11 +
  12 + public function __construct()
  13 + {
  14 + parent::__construct();
  15 + $this->model = new MailModel();
  16 + $this->param = $this->requestAll;
  17 + }
  18 +
  19 + /**
  20 + * @name :详情
  21 + * @author :liyuhang
  22 + */
  23 + public function mail_info(){
  24 + $info = $this->model->read($this->param);
  25 + if($info === false){
  26 + $this->fail('当前数据不存在',Code::USER_ERROR);
  27 + }
  28 + //生成一条阅读记录
  29 + $mailUserModel = new MailUserModel();
  30 + $data = [
  31 + 'user_id'=>$info['id'],
  32 + 'mail_id'=>$this->user['id'],
  33 + ];
  34 + //查询当前记录是否存在
  35 + $read_info = $mailUserModel->read($data);
  36 + if($read_info === false){
  37 + $rs = $mailUserModel->add($data);
  38 + if($rs === false){
  39 + $this->fail('error',Code::USER_ERROR);
  40 + }
  41 + }
  42 + return $this->success($info);
  43 + }
  44 +}
  1 +<?php
  2 +
  3 +namespace App\Http\Logic\Bside\News;
  4 +
  5 +use App\Enums\Common\Code;
  6 +use App\Http\Logic\Bside\BaseLogic;
  7 +use App\Models\News\News as NewsModel;
  8 +use App\Models\News\NewsCategory as NewsCategoryModel;
  9 +use Illuminate\Support\Facades\DB;
  10 +
  11 +class NewsCategoryLogic extends BaseLogic
  12 +{
  13 + public function __construct()
  14 + {
  15 + parent::__construct();
  16 +
  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);
  34 + }
  35 + /**
  36 + * @name :添加时验证上级分类是否有商品,有则替换带当前分类下
  37 + * @return void
  38 + * @author :liyuhang
  39 + * @method
  40 + */
  41 + public function add_news_category(){
  42 + DB::beginTransaction();
  43 +
  44 + $this->param['project_id'] = $this->user['project_id'];
  45 + $this->param['operator_id'] = $this->user['id'];
  46 + $this->param['create_id'] = $this->user['id'];
  47 + $this->param['created_at'] = date('Y-m-d H:i:s');
  48 + $this->param['updated_at'] = date('Y-m-d H:i:s');
  49 + $cate_id = $this->model->insertGetId($this->param);
  50 + if($cate_id === false){
  51 + DB::rollBack();
  52 + $this->fail('error',Code::USER_ERROR);
  53 + }
  54 + //判断为子分类时
  55 + if(isset($this->param['pid']) && !empty($this->param['pid'])) {
  56 + //查看当前上级分类下是否有其他分类
  57 + $cate_info = $this->model->read(['pid' => $this->param['pid'], 'id' => ['!=', $cate_id]]);
  58 + if ($cate_info === false) {
  59 + //查看当前上一级分类下是否有新闻
  60 + $newsModel = new NewsModel();
  61 + $news_info = $newsModel->read(['category_id' => ['like', ',' . $this->param['pid'] . ',']]);
  62 + if ($news_info !== false) {
  63 + $replacement = ',' . $cate_id . ',';
  64 + $old = ',' . $this->param['pid'] . ',';
  65 + //更新所有商品到当前分类
  66 + $rs = DB::table('gl_news')->where('category_id', 'like', '%' . $old . '%')
  67 + ->update(['category_id' => DB::raw("REPLACE(category_id, '$old', '$replacement')")]);
  68 + if ($rs === false) {
  69 + DB::rollBack();
  70 + $this->fail('error', Code::USER_ERROR);
  71 + }
  72 + }
  73 + }
  74 + }
  75 + DB::commit();
  76 + return $this->success();
  77 + }
  78 +
  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 + /**
  110 + * @name :删除新闻分类
  111 + * @return array
  112 + * @throws \App\Exceptions\BsideGlobalException
  113 + * @author :liyuhang
  114 + * @method
  115 + */
  116 + public function del_news_category(){
  117 + $this->param = $this->requestAll;
  118 + foreach ($this->param['id'] as $v){
  119 + //查询是否有子分类
  120 + $rs = $this->model->read(['pid'=>$v],['id']);
  121 + if($rs !== false){
  122 + $this->fail('当前分类拥有子分类不允许删除',Code::USER_ERROR);
  123 + }
  124 + //查看当前分内下是否有商品
  125 + $newsModel = new NewsModel();
  126 + $rs = $newsModel->read(['category_id'=>$v],['id']);
  127 + if($rs !== false){
  128 + $this->fail('当前分类拥有商品',Code::USER_ERROR);
  129 + }
  130 + }
  131 + $this->param['id'] = ['in',$this->param['id']];
  132 + $rs = $this->model->del($this->param);
  133 + if($rs === false){
  134 + $this->fail('error',Code::USER_ERROR);
  135 + }
  136 + return $this->success();
  137 + }
  138 +}
  1 +<?php
  2 +
  3 +namespace App\Http\Logic\Bside\News;
  4 +
  5 +use App\Enums\Common\Code;
  6 +use App\Http\Logic\Bside\BaseLogic;
  7 +use App\Models\News\News;
  8 +use App\Models\News\NewsCategory as NewsCategoryModel;
  9 +use App\Models\RouteMap;
  10 +use Illuminate\Support\Facades\DB;
  11 +
  12 +class NewsLogic extends BaseLogic
  13 +{
  14 + public function __construct()
  15 + {
  16 + parent::__construct();
  17 +
  18 + $this->model = new News();
  19 + $this->param = $this->requestAll;
  20 + }
  21 +
  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 + /**
  49 + * @name :添加博客
  50 + * @return void
  51 + * @author :liyuhang
  52 + * @method
  53 + */
  54 + public function news_add(){
  55 + $this->param['create_id'] = $this->uid;
  56 + $this->param['operator_id'] = $this->uid;
  57 + $this->param['project_id'] = $this->user['project_id'];
  58 + DB::beginTransaction();
  59 + try {
  60 + if(isset($this->param['image'])){
  61 + $data = $this->upload();
  62 + $this->param['image'] = $data['path'];
  63 + }
  64 + $rs = $this->model->insertGetId($this->param);
  65 + RouteMap::setRoute($this->param['url'], RouteMap::SOURCE_NEWS, $rs, $this->user['project_id']);
  66 + DB::commit();
  67 + }catch (\Exception $e){
  68 + DB::rollBack();
  69 + $this->fail('error',Code::USER_ERROR);
  70 + }
  71 + //TODO::写入日志
  72 + $this->success();
  73 + }
  74 +
  75 + /**
  76 + * @name :编辑
  77 + * @return void
  78 + * @throws \App\Exceptions\BsideGlobalException
  79 + * @author :liyuhang
  80 + * @method
  81 + */
  82 + public function news_edit(){
  83 + $this->param['operator_id'] = $this->user['id'];
  84 + //多个分类按逗号隔开
  85 + $this->param['category_id'] = ','.$this->param['category_id'].',';
  86 + $rs = $this->model->edit($this->param,['id'=>$this->param['id']]);
  87 + if($rs === false){
  88 + $this->fail('error',Code::USER_ERROR);
  89 + }
  90 + //TODO::写入日志
  91 + $this->success();
  92 + }
  93 +
  94 + /**
  95 + * @name :修改状态
  96 + * @return void
  97 + * @throws \App\Exceptions\BsideGlobalException
  98 + * @author :liyuhang
  99 + * @method
  100 + */
  101 + public function news_status(){
  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 + //TODO::写入日志
  108 + $this->success();
  109 + }
  110 + /**
  111 + * @name :获取详情
  112 + * @return array
  113 + * @throws \App\Exceptions\BsideGlobalException
  114 + * @author :liyuhang
  115 + * @method
  116 + */
  117 + public function news_info(){
  118 + $this->param = $this->requestAll;
  119 + $info = $this->model->read($this->param);
  120 + //获取分类名称
  121 + $info['category_id'] = explode(',',trim($info['category_id'],','));
  122 + $newsCategoryModel = new NewsCategoryModel();
  123 + $category_list = $newsCategoryModel->list(['id'=>['in',$info['category_id']]],'id',['name']);
  124 + $str = '';
  125 + foreach ($category_list as $v){
  126 + $str .= $v['name'].',';
  127 + }
  128 + $info['category_id'] = trim($str,',');
  129 + if($info === false){
  130 + $this->fail('error',Code::USER_ERROR);
  131 + }
  132 + return $this->success($info);
  133 + }
  134 +
  135 + /**
  136 + * @name :逻辑删除
  137 + * @return void
  138 + * @author :liyuhang
  139 + * @method
  140 + */
  141 + public function news_del(){
  142 + $this->param['id'] = ['in',$this->param['id']];
  143 + $rs = $this->model->edit(['status'=>2,'operator_id'=>$this->user['id']],$this->param);
  144 + if($rs === false){
  145 + $this->fail('error',Code::USER_ERROR);
  146 + }
  147 + return $this->success();
  148 + }
  149 +}
@@ -2,7 +2,6 @@ @@ -2,7 +2,6 @@
2 2
3 namespace App\Http\Logic\Bside\Product; 3 namespace App\Http\Logic\Bside\Product;
4 4
5 -use App\Helper\Arr;  
6 use App\Http\Logic\Bside\BaseLogic; 5 use App\Http\Logic\Bside\BaseLogic;
7 use App\Models\Product\Attr; 6 use App\Models\Product\Attr;
8 use App\Models\Product\AttrValue; 7 use App\Models\Product\AttrValue;
@@ -25,6 +24,9 @@ class AttrLogic extends BaseLogic @@ -25,6 +24,9 @@ class AttrLogic extends BaseLogic
25 24
26 public function getInfo($id){ 25 public function getInfo($id){
27 $info = parent::getCacheInfo($id); 26 $info = parent::getCacheInfo($id);
  27 + if(!$info){
  28 + $this->fail('数据不存在或者已经删除');
  29 + }
28 $info->values; 30 $info->values;
29 return $this->success($info->toArray()); 31 return $this->success($info->toArray());
30 } 32 }
@@ -62,17 +64,4 @@ class AttrLogic extends BaseLogic @@ -62,17 +64,4 @@ class AttrLogic extends BaseLogic
62 } 64 }
63 return $this->success(); 65 return $this->success();
64 } 66 }
65 -  
66 - public function delete($ids){  
67 - $ids= array_filter(Arr::splitFilterToArray($ids), 'intval');  
68 - foreach ($ids as $id){  
69 - $info = $this->getCacheInfo($id);  
70 - if(!$info){  
71 - continue;  
72 - }  
73 -  
74 - //todo 是否有关联商品  
75 - }  
76 - return parent::delete($ids);  
77 - }  
78 } 67 }
@@ -5,6 +5,7 @@ namespace App\Http\Logic\Bside\Product; @@ -5,6 +5,7 @@ namespace App\Http\Logic\Bside\Product;
5 use App\Helper\Arr; 5 use App\Helper\Arr;
6 use App\Http\Logic\Bside\BaseLogic; 6 use App\Http\Logic\Bside\BaseLogic;
7 use App\Models\Product\Category; 7 use App\Models\Product\Category;
  8 +use App\Models\Product\Product;
8 9
9 /** 10 /**
10 * Class CategoryLogic 11 * Class CategoryLogic
@@ -26,7 +27,7 @@ class CategoryLogic extends BaseLogic @@ -26,7 +27,7 @@ class CategoryLogic extends BaseLogic
26 if(!empty($param['id']) && $param['pid'] == $param['id']){ 27 if(!empty($param['id']) && $param['pid'] == $param['id']){
27 $this->fail('上级分类不能是本分类'); 28 $this->fail('上级分类不能是本分类');
28 } 29 }
29 - $p_cate = Category::find($param['pid']); 30 + $p_cate = $this->getCacheInfo($param['pid']);
30 if(!$p_cate){ 31 if(!$p_cate){
31 $this->fail('上级分类不存在'); 32 $this->fail('上级分类不存在');
32 } 33 }
@@ -34,7 +35,7 @@ class CategoryLogic extends BaseLogic @@ -34,7 +35,7 @@ class CategoryLogic extends BaseLogic
34 return parent::save($param); 35 return parent::save($param);
35 } 36 }
36 37
37 - public function delete($ids){ 38 + public function delete($ids, $map = []){
38 $ids= array_filter(Arr::splitFilterToArray($ids), 'intval'); 39 $ids= array_filter(Arr::splitFilterToArray($ids), 'intval');
39 foreach ($ids as $id){ 40 foreach ($ids as $id){
40 $info = $this->getCacheInfo($id); 41 $info = $this->getCacheInfo($id);
@@ -42,11 +43,13 @@ class CategoryLogic extends BaseLogic @@ -42,11 +43,13 @@ class CategoryLogic extends BaseLogic
42 continue; 43 continue;
43 } 44 }
44 //是否有子分类 45 //是否有子分类
45 - if(Category::where('pid', $id)->count()){ 46 + if(Category::where('project_id', $this->user['project_id'])->where('pid', $id)->count()){
46 $this->fail("分类{$info['title']}存在子分类,不能删除"); 47 $this->fail("分类{$info['title']}存在子分类,不能删除");
47 } 48 }
48 - //todo 是否有对应商品  
49 - 49 + //是否有对应商品
  50 + if(Product::whereRaw("FIND_IN_SET({$id},`category_id`)")->count()){
  51 + $this->fail("分类{$info['title']}存在产品,不能删除");
  52 + }
50 } 53 }
51 return parent::delete($ids); 54 return parent::delete($ids);
52 } 55 }
@@ -20,18 +20,4 @@ class DescribeLogic extends BaseLogic @@ -20,18 +20,4 @@ class DescribeLogic extends BaseLogic
20 20
21 $this->model = new Describe(); 21 $this->model = new Describe();
22 } 22 }
23 -  
24 - public function delete($ids){  
25 - $ids= array_filter(Arr::splitFilterToArray($ids), 'intval');  
26 - foreach ($ids as $id){  
27 - $info = $this->getCacheInfo($id);  
28 - if(!$info){  
29 - continue;  
30 - }  
31 -  
32 - //todo 是否有关联商品  
33 -  
34 - }  
35 - return parent::delete($ids);  
36 - }  
37 } 23 }
@@ -4,6 +4,7 @@ namespace App\Http\Logic\Bside\Product; @@ -4,6 +4,7 @@ namespace App\Http\Logic\Bside\Product;
4 4
5 use App\Helper\Arr; 5 use App\Helper\Arr;
6 use App\Http\Logic\Bside\BaseLogic; 6 use App\Http\Logic\Bside\BaseLogic;
  7 +use App\Models\Product\Product;
7 use App\Models\RouteMap; 8 use App\Models\RouteMap;
8 use App\Models\Product\Keyword; 9 use App\Models\Product\Keyword;
9 use Illuminate\Support\Facades\DB; 10 use Illuminate\Support\Facades\DB;
@@ -28,7 +29,7 @@ class KeywordLogic extends BaseLogic @@ -28,7 +29,7 @@ class KeywordLogic extends BaseLogic
28 try { 29 try {
29 $res = parent::save($param); 30 $res = parent::save($param);
30 //路由映射 31 //路由映射
31 - RouteMap::setRoute($param['title'], RouteMap::SOURCE_PRODUCT_KEYWORD, $res['id'], $param['project_id'], true); 32 + RouteMap::setRoute($param['title'], RouteMap::SOURCE_PRODUCT_KEYWORD, $res['id'], $this->user['project_id']);
32 DB::commit(); 33 DB::commit();
33 }catch (\Exception $e){ 34 }catch (\Exception $e){
34 DB::rollBack(); 35 DB::rollBack();
@@ -37,19 +38,24 @@ class KeywordLogic extends BaseLogic @@ -37,19 +38,24 @@ class KeywordLogic extends BaseLogic
37 return $this->success(); 38 return $this->success();
38 } 39 }
39 40
40 - public function delete($ids){ 41 + public function delete($ids, $map = []){
41 $ids= array_filter(Arr::splitFilterToArray($ids), 'intval'); 42 $ids= array_filter(Arr::splitFilterToArray($ids), 'intval');
42 - foreach ($ids as $id){  
43 - $info = $this->getCacheInfo($id);  
44 - if(!$info){  
45 - continue;  
46 - }  
47 43
48 - //todo 是否有关联商品 44 + DB::beginTransaction();
  45 + try {
  46 + parent::delete($ids);
49 47
50 - //todo 删除路由映射 事务 48 + foreach ($ids as $id){
  49 + //删除路由映射
  50 + RouteMap::delRoute(RouteMap::SOURCE_PRODUCT_KEYWORD, $id, $this->user['project_id']);
  51 + }
51 52
  53 + DB::commit();
  54 + }catch (\Exception $e){
  55 + DB::rollBack();
  56 + $this->fail('删除失败');
52 } 57 }
53 - return parent::delete($ids); 58 +
  59 + return $this->success();
54 } 60 }
55 } 61 }
@@ -5,6 +5,8 @@ namespace App\Http\Logic\Bside\Product; @@ -5,6 +5,8 @@ namespace App\Http\Logic\Bside\Product;
5 use App\Helper\Arr; 5 use App\Helper\Arr;
6 use App\Http\Logic\Bside\BaseLogic; 6 use App\Http\Logic\Bside\BaseLogic;
7 use App\Models\Product\Product; 7 use App\Models\Product\Product;
  8 +use App\Models\RouteMap;
  9 +use Illuminate\Support\Facades\DB;
8 10
9 /** 11 /**
10 * Class ProductLogic 12 * Class ProductLogic
@@ -22,32 +24,39 @@ class ProductLogic extends BaseLogic @@ -22,32 +24,39 @@ class ProductLogic extends BaseLogic
22 } 24 }
23 25
24 public function save($param){ 26 public function save($param){
25 - if(!empty($param['pid'])){  
26 - if(!empty($param['id']) && $param['pid'] == $param['id']){  
27 - $this->fail('上级分类不能是本分类');  
28 - }  
29 - $p_cate = Product::find($param['pid']);  
30 - if(!$p_cate){  
31 - $this->fail('上级分类不存在');  
32 - }  
33 - }  
34 - return parent::save($param); 27 + DB::beginTransaction();
  28 + try {
  29 + $data = $param;
  30 + unset($data['route']);
  31 + $res = parent::save($data);
  32 + //路由映射
  33 + RouteMap::setRoute($param['route'], RouteMap::SOURCE_PRODUCT, $res['id'], $this->user['project_id']);
  34 + DB::commit();
  35 + }catch (\Exception $e){
  36 + DB::rollBack();
  37 + $this->fail('保存失败');
  38 + }
  39 + return $this->success();
35 } 40 }
36 41
37 - public function delete($ids){ 42 + public function delete($ids, $map =[]){
38 $ids= array_filter(Arr::splitFilterToArray($ids), 'intval'); 43 $ids= array_filter(Arr::splitFilterToArray($ids), 'intval');
  44 +
  45 + DB::beginTransaction();
  46 + try {
  47 + parent::delete($ids);
  48 +
39 foreach ($ids as $id){ 49 foreach ($ids as $id){
40 - $info = $this->getCacheInfo($id);  
41 - if(!$info){  
42 - continue;  
43 - }  
44 - //是否有子分类  
45 - if(Product::where('pid', $id)->count()){  
46 - $this->fail("分类{$info['title']}存在子分类,不能删除"); 50 + //删除路由映射
  51 + RouteMap::delRoute(RouteMap::SOURCE_PRODUCT, $id, $this->user['project_id']);
47 } 52 }
48 - //todo 是否有对应商品  
49 53
  54 + DB::commit();
  55 + }catch (\Exception $e){
  56 + DB::rollBack();
  57 + $this->fail('删除失败');
50 } 58 }
51 - return parent::delete($ids); 59 +
  60 + return $this->success();
52 } 61 }
53 } 62 }
  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($this->param);
  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 ProjectMenuModel();
  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'] = _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\User;
  7 +use Illuminate\Support\Facades\DB;
  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 + if(isset($this->param['image'])){
  34 + $this->param['image'] = $this->upload();
  35 + }
  36 + //密码加密
  37 + $this->param['password'] = base64_encode(md5($this->param['password']));
  38 + $rs = $this->model->add($this->param);
  39 + if($rs === false){
  40 + $this->fail('error',Code::USER_ERROR);
  41 + }
  42 + return $this->success();
  43 + }
  44 +
  45 + /**
  46 + * @name :编辑用户
  47 + * @author :liyuhang
  48 + */
  49 + public function user_edit(){
  50 + $condition = [
  51 + 'id'=>['!=',$this->param['id']],
  52 + 'mobile'=>$this->param['mobile']
  53 + ];
  54 + $info = $this->model->read($condition);
  55 + if($info !== false){
  56 + $this->fail('当前编辑的手机号码已存在',Code::USER_PARAMS_ERROE);
  57 + }
  58 + $this->param['operator_id'] = $this->user['id'];
  59 + //上传图片
  60 + if(isset($this->param['image'])){
  61 + //查看当前用户是否已有头像
  62 + $info = $this->model->read(['id'=>$this->param['id']],'hash');
  63 + if($info !== false){
  64 + DB::table('gl_image')->where(['hash'=>$info['hash']])->first();
  65 + }
  66 + $this->param['image'] = $this->upload();
  67 + }
  68 + $rs = $this->model->edits($this->param);
  69 + if($rs === false){
  70 + $this->fail('参数错误或其他服务器原因,编辑失败',Code::USER_ERROR,[]);
  71 + }
  72 + return $this->success();
  73 + }
  74 +
  75 + /**
  76 + * @name :编辑状态/排序
  77 + * @author :liyuhang
  78 + */
  79 + public function user_status(){
  80 + $this->param['operator_id'] = $this->user['id'];
  81 + $rs = $this->model->edit($this->param,['id'=>$this->param['id']]);
  82 + if($rs === false){
  83 + $this->fail('error',Code::USER_ERROR);
  84 + }
  85 + return $this->success();
  86 + }
  87 +
  88 + /**
  89 + * @name :用户详情
  90 + * @return void
  91 + * @author :liyuhang
  92 + * @method
  93 + */
  94 + public function user_info(){
  95 + $info = $this->model->read($this->param);
  96 + if($info === false){
  97 + $this->fail('error',Code::USER_ERROR);
  98 + }
  99 + return $this->success($info);
  100 + }
  101 +
  102 + /**
  103 + * @name :删除用户(逻辑删除)
  104 + * @return void
  105 + * @author :liyuhang
  106 + * @method
  107 + */
  108 + public function user_del(){
  109 + $this->param['operator_id'] = $this->user['id'];
  110 + $rs = $this->model->edit(['status'=>2],['id'=>['in',$this->param['id']]]);
  111 + if($rs === false){
  112 + $this->fail('error',Code::USER_ERROR);
  113 + }
  114 + return $this->success();
  115 + }
  116 +}
  1 +<?php
  2 +
  3 +namespace App\Http\Logic;
  4 +
  5 +use App\Enums\Common\Code;
  6 +use App\Enums\Common\Common;
  7 +use App\Exceptions\AsideGlobalException;
  8 +use App\Exceptions\BsideGlobalException;
  9 +use App\Helper\Arr;
  10 +use Illuminate\Support\Facades\Cache;
  11 +
  12 +/**
  13 + * @notes: 逻辑层基类 控制器调用 统一返回 统一抛出异常
  14 + */
  15 +class Logic
  16 +{
  17 + protected $model;
  18 +
  19 + protected $side;
  20 +
  21 + protected $is_cache = true; //是否缓存数据
  22 +
  23 + /**
  24 + * @notes: 请简要描述方法功能
  25 + * @param array $data
  26 + * @return array
  27 + */
  28 + public function success(array $data = [])
  29 + {
  30 + return $data;
  31 + }
  32 +
  33 + /**
  34 + * @notes: 错误抛出
  35 + * @param string $code
  36 + * @param string $message
  37 + * @throws AsideGlobalException|BsideGlobalException
  38 + */
  39 + public function fail(string $message = "", string $code = Code::SYSTEM_ERROR)
  40 + {
  41 + if((request()->path()[0]) == Common::B){
  42 + throw new BsideGlobalException($code, $message);
  43 + }
  44 + throw new AsideGlobalException($code, $message);
  45 + }
  46 +
  47 + /**
  48 + * 列表
  49 + * @param array $map
  50 + * @param array $sort
  51 + * @param array $columns
  52 + * @param int $limit
  53 + * @return array
  54 + * @author zbj
  55 + * @date 2023/4/13
  56 + */
  57 + public function getList(array $map = [], array $sort = ['id' => 'desc'], array $columns = ['*'], int $limit = 20)
  58 + {
  59 + // 闭包查询条件格式化
  60 + $query = $this->formatQuery($map);
  61 +
  62 + // 排序(支持多重排序)
  63 + $query = $query->when($sort, function ($query, $sort) {
  64 + foreach ($sort as $k=>$v) {
  65 + $query->orderBy($k, $v);
  66 + }
  67 + });
  68 +
  69 + // 数据分页设置
  70 + if ($limit) {
  71 + $result = $query->select($columns)->paginate($limit);
  72 + }else{
  73 + $result = $query->select($columns)->get();
  74 + }
  75 + if($this->side == Common::A){
  76 + return $this->success($result);
  77 + }
  78 + return $this->success($result ? $result->toArray() : []);
  79 + }
  80 +
  81 +
  82 + /**
  83 + * 详情
  84 + * @param $id
  85 + * @return array
  86 + * @throws AsideGlobalException|BsideGlobalException
  87 + * @author zbj
  88 + * @date 2023/4/13
  89 + */
  90 + public function getInfo($id)
  91 + {
  92 + $info = $this->getCacheInfo($id);
  93 + if(!$info){
  94 + $this->fail('数据不存在或者已经删除');
  95 + }
  96 + return $this->success($info->toArray());
  97 + }
  98 +
  99 + /**
  100 + * @param $id
  101 + * @return mixed
  102 + * @author zbj
  103 + * @date 2023/4/15
  104 + */
  105 + public function getCacheInfo($id){
  106 + if($this->is_cache){
  107 + $info = Cache::get($this->getInfoCacheKey($id));
  108 + if (!$info) {
  109 + $info = $this->model->find($id);
  110 + if($info){
  111 + Cache::put($this->getInfoCacheKey($id), $info);
  112 + }
  113 + }
  114 + }else{
  115 + $info = $this->model->find($id);
  116 + }
  117 + return $info;
  118 + }
  119 +
  120 + /**
  121 + * 保存
  122 + * @param $param
  123 + * @return array
  124 + * @throws BsideGlobalException|AsideGlobalException
  125 + * @author zbj
  126 + * @date 2023/4/13
  127 + */
  128 + public function save($param){
  129 + if(!empty($param['id'])){
  130 + $this->model = $this->getCacheInfo($param['id']);
  131 + if(!$this->model){
  132 + $this->fail('数据不存在或者已经删除');
  133 + }
  134 + }
  135 + foreach ($param as $name => $value){
  136 + $this->model[$name] = $value;
  137 + }
  138 +
  139 + $res = $this->model->save();
  140 +
  141 + if($res){
  142 + //清缓存
  143 + if($this->is_cache && !empty($param['id'])){
  144 + Cache::forget($this->getInfoCacheKey($param['id']));
  145 + }
  146 + return $this->success(['id' => $this->model->id]); //返回保存的数据id
  147 + }else{
  148 + $this->fail('保存失败');
  149 + }
  150 + }
  151 +
  152 + /**
  153 + * 批量删除
  154 + * @param $ids
  155 + * @param array $map
  156 + * @return array
  157 + * @throws AsideGlobalException|BsideGlobalException
  158 + * @author zbj
  159 + * @date 2023/4/13
  160 + */
  161 + public function delete($ids, $map = []){
  162 + $ids = array_filter(Arr::splitFilterToArray($ids), 'intval');
  163 + if(!$ids){
  164 + $this->fail('ID不能为空');
  165 + }
  166 + $map[] = ['id', 'in', $ids];
  167 +
  168 + $res = $this->formatQuery($map)->delete();
  169 + if($res){
  170 +
  171 + if($this->is_cache){
  172 + foreach ($ids as $id){
  173 + Cache::forget($this->getInfoCacheKey($id));
  174 + }
  175 + }
  176 + return $this->success();
  177 + }else{
  178 + $this->fail('删除失败');
  179 + }
  180 + }
  181 +
  182 + /**
  183 + * @param $id
  184 + * @return string
  185 + * @author zbj
  186 + * @date 2023/4/13
  187 + */
  188 + public function getInfoCacheKey($id){
  189 + return $this->model->getTable() . '_info_' . $id;
  190 + }
  191 +
  192 + /**
  193 + * 格式化查询条件
  194 + * @param $map
  195 + * @param $query
  196 + * @return mixed
  197 + * @author zbj
  198 + * @date 2023/4/13
  199 + */
  200 + public function formatQuery($map, $query = '')
  201 + {
  202 + $model = $query ?: $this->model;
  203 + $query = $model->where(function ($query) use ($map) {
  204 + foreach ($map as $v) {
  205 + if ($v instanceof \Closure) {
  206 + $query = $query->where($v);
  207 + continue;
  208 + }
  209 + // 判断是否是键值对类型
  210 + if (key($v) !== 0) {
  211 + $key = key($v);
  212 + $val = $v[$key];
  213 + $v = [$key, is_array($val) ? 'in' : '=', $val];
  214 + }
  215 + switch ($v[1]) {
  216 + case 'like':
  217 + // like查询 ['name|title', 'like', '%a%']
  218 + if (strpos($v[0], '|') !== false) {
  219 + $query->where(function ($query) use ($v) {
  220 + $item = explode('|', $v[0]);
  221 + foreach ($item as $vo) {
  222 + $query->orWhere($vo, $v[1], $v[2]);
  223 + }
  224 + });
  225 + } else {
  226 + $query->where($v[0], $v[1], $v[2]);
  227 + }
  228 + break;
  229 + case 'in':
  230 + // in查询 ['id', 'in', [1,2,3]]
  231 + if (!is_array($v[2])) {
  232 + $v[2] = explode(',', $v[2]);
  233 + }
  234 + $query->whereIn($v[0], $v[2]);
  235 + break;
  236 + case 'not in':
  237 + // not in查询 ['id', 'not in', [1,2,3]]
  238 + if (!is_array($v[2])) {
  239 + $v[2] = explode(',', $v[2]);
  240 + }
  241 + $query->whereNotIn($v[0], $v[2]);
  242 + break;
  243 + case 'between':
  244 + // between查询 ['created_at', 'between', ['xxx', 'xxx]]
  245 + if (!is_array($v[2])) {
  246 + $v[2] = explode(',', $v[2]);
  247 + }
  248 + $query->whereBetween($v[0], $v[2]);
  249 + break;
  250 + case 'not between':
  251 + // not between查询 ['created_at', 'not between', ['xxx', 'xxx]]
  252 + if (!is_array($v[2])) {
  253 + $v[2] = explode(',', $v[2]);
  254 + }
  255 + $query->whereNotBetween($v[0], $v[2]);
  256 + break;
  257 + case 'null':
  258 + // null查询 ['deleted_at', 'null']
  259 + $query->whereNull($v[0]);
  260 + break;
  261 + case "not null":
  262 + // not null查询 ['deleted_at', 'not null']
  263 + $query->whereNotNull($v[0]);
  264 + break;
  265 + case "or":
  266 + // or查询 [[['status'=>1],['status'=>2]], 'or'];
  267 + //格式:or (status=1 and status=2)
  268 + $where = $v[0];
  269 + $query->orWhere(function ($query) use ($where) {
  270 + // 递归解析查询条件
  271 + $this->formatQuery($where, $query);
  272 + });
  273 + break;
  274 + case 'xor':
  275 + // xor查询 [[['status'=>1],['status'=>2]], 'xor'];
  276 + // 格式:and (status=1 or status=2)
  277 + $where = $v[0];
  278 + $query->where(function ($query) use ($where) {
  279 + foreach ($where as $w) {
  280 + $query->orWhere(function ($query) use ($w) {
  281 + // 递归解析查询条件
  282 + $this->formatQuery([$w], $query);
  283 + });
  284 + }
  285 + });
  286 + break;
  287 + default:
  288 + // 常规查询
  289 + if (count($v) == 2) {
  290 + $query->where($v[0], '=', $v[1]);
  291 + } else {
  292 + $query->where($v[0], $v[1], $v[2]);
  293 + }
  294 + break;
  295 + }
  296 + }
  297 + });
  298 + return $query;
  299 + }
  300 +}
@@ -2,8 +2,15 @@ @@ -2,8 +2,15 @@
2 2
3 namespace App\Http\Middleware\Aside; 3 namespace App\Http\Middleware\Aside;
4 4
  5 +use App\Enums\Common\Code;
  6 +use App\Models\Manage\Group;
  7 +use App\Models\Manage\Manage;
  8 +use App\Models\Manage\Menu;
5 use Closure; 9 use Closure;
6 use Illuminate\Http\Request; 10 use Illuminate\Http\Request;
  11 +use Illuminate\Support\Facades\Route;
  12 +use Illuminate\Support\Facades\Session;
  13 +use Illuminate\Support\Str;
7 14
8 class LoginAuthMiddleware 15 class LoginAuthMiddleware
9 { 16 {
@@ -16,6 +23,33 @@ class LoginAuthMiddleware @@ -16,6 +23,33 @@ class LoginAuthMiddleware
16 */ 23 */
17 public function handle(Request $request, Closure $next) 24 public function handle(Request $request, Closure $next)
18 { 25 {
  26 + $manage = Session::get('manage');
  27 +
  28 + if (!$manage) {
  29 + if($request->ajax()){
  30 + return response(['status'=> Code::USER_ERROR,'msg'=>'当前用户未登录']);
  31 + }else{
  32 + return redirect(route('admin.login.white'));
  33 + }
  34 + }
  35 + //权限
  36 + $manage['id'] = 2;
  37 + $manage['gid'] = 1;
  38 +
  39 + if($manage['id'] != Manage::ADMINISTRATOR_ID){ //排除超级管理员
  40 + $route = Route::getCurrentRoute()->getName();
  41 + if(!Str::endsWith($route, '.white')){ //排除白名单路由
  42 + $routes = Group::getRouteByGroupId($manage['gid']);
  43 + if(!in_array($route, $routes)){
  44 + if($request->ajax()){
  45 + return response(['status'=> Code::USER_ERROR,'msg'=>'无权限']);
  46 + }else{
  47 + return response(view('admin/no_auth'));
  48 + }
  49 + }
  50 + }
  51 + }
  52 +
19 return $next($request); 53 return $next($request);
20 } 54 }
21 } 55 }
@@ -31,8 +31,7 @@ class LoginAuthMiddleware @@ -31,8 +31,7 @@ class LoginAuthMiddleware
31 return response(['code'=>Code::USER_ERROR,'msg'=>'当前用户未登录']); 31 return response(['code'=>Code::USER_ERROR,'msg'=>'当前用户未登录']);
32 } 32 }
33 // 设置数据信息 33 // 设置数据信息
34 - ProjectServer::useProject($info['project_id']);  
35 - 34 +// ProjectServer::useProject($info['project_id']);
36 //操作权限设置 35 //操作权限设置
37 $projectRoleModel = new ProjectRoleModel(); 36 $projectRoleModel = new ProjectRoleModel();
38 $role_info = $projectRoleModel->read(['id'=>$info['role_id']]); 37 $role_info = $projectRoleModel->read(['id'=>$info['role_id']]);
  1 +<?php
  2 +
  3 +namespace App\Http\Requests\Aside;
  4 +
  5 +use Illuminate\Foundation\Http\FormRequest;
  6 +
  7 +/**
  8 + * Class DeptRequest
  9 + * @package App\Http\Requests\Aside\product
  10 + * @author zbj
  11 + * @date 2023/4/20
  12 + */
  13 +class DeptRequest extends FormRequest
  14 +{
  15 + /**
  16 + * Determine if the user is authorized to make this request.
  17 + *
  18 + * @return bool
  19 + */
  20 + public function authorize()
  21 + {
  22 + return true;
  23 + }
  24 +
  25 + /**
  26 + * Get the validation rules that apply to the request.
  27 + *
  28 + * @return array
  29 + */
  30 + public function rules()
  31 + {
  32 + return [
  33 + 'title'=>'required|max:50',
  34 + 'remark'=>'max:200',
  35 + ];
  36 + }
  37 +
  38 + public function messages()
  39 + {
  40 + return [
  41 + 'title.required' => '请输入部门名称',
  42 + 'title.max' => '部门名称不能超过50个字符',
  43 + 'remark.max' => '备注不能超过200个字符',
  44 + ];
  45 + }
  46 +
  47 +}
  1 +<?php
  2 +
  3 +namespace App\Http\Requests\Aside;
  4 +
  5 +use App\Models\Manage\Group;
  6 +use Illuminate\Foundation\Http\FormRequest;
  7 +use Illuminate\Validation\Rule;
  8 +
  9 +/**
  10 + * Class GroupRequest
  11 + * @package App\Http\Requests\Bside\product
  12 + * @author zbj
  13 + * @date 2023/4/19
  14 + */
  15 +class GroupRequest extends FormRequest
  16 +{
  17 + /**
  18 + * Determine if the user is authorized to make this request.
  19 + *
  20 + * @return bool
  21 + */
  22 + public function authorize()
  23 + {
  24 + return true;
  25 + }
  26 +
  27 + /**
  28 + * Get the validation rules that apply to the request.
  29 + *
  30 + * @return array
  31 + */
  32 + public function rules()
  33 + {
  34 + return [
  35 + 'title' => ['required', 'max:32'],
  36 + 'rights' => ['required', 'array'],
  37 + 'status' => ['required', Rule::in(array_keys(Group::statusMap()))],
  38 + ];
  39 + }
  40 +
  41 + public function messages()
  42 + {
  43 + return [
  44 + 'title.required' => '请输入权限组名称',
  45 + 'title.max' => '权限组名称长度不超过32个字符',
  46 + 'rights.required' => '请输入选择权限节点',
  47 + 'rights.array' => '权限节点无效',
  48 + 'status.required' => '请选择状态',
  49 + 'status.in' => '状态值无效',
  50 + ];
  51 + }
  52 +
  53 +}
  1 +<?php
  2 +
  3 +namespace App\Http\Requests\Aside;
  4 +
  5 +use App\Models\Manage\Manage;
  6 +use App\Rules\Mobile;
  7 +use Illuminate\Foundation\Http\FormRequest;
  8 +use Illuminate\Validation\Rule;
  9 +
  10 +/**
  11 + * Class ManageRequest
  12 + * @package App\Http\Requests\Aside\product
  13 + * @author zbj
  14 + * @date 2023/4/20
  15 + */
  16 +class ManageRequest extends FormRequest
  17 +{
  18 + /**
  19 + * Determine if the user is authorized to make this request.
  20 + *
  21 + * @return bool
  22 + */
  23 + public function authorize()
  24 + {
  25 + return true;
  26 + }
  27 +
  28 + /**
  29 + * Get the validation rules that apply to the request.
  30 + *
  31 + * @return array
  32 + */
  33 + public function rules()
  34 + {
  35 + return [
  36 + 'name'=>'required|max:20',
  37 + 'email'=>'email|max:64',
  38 + 'mobile' => ['required', new Mobile()],
  39 + 'password' => 'required|min:6',
  40 + 'status' => ['required', Rule::in(array_keys(Manage::statusMap()))],
  41 + ];
  42 + }
  43 +
  44 + public function messages()
  45 + {
  46 + return [
  47 + 'name.required' => '请输入姓名',
  48 + 'name.max' => '姓名不能超过20个字符',
  49 + 'email.email' => '邮箱格式不正确',
  50 + 'email.max' => '邮箱不能超过64个字',
  51 + 'mobile.required' => '请输入手机号',
  52 + 'password.required' => '请输入密码',
  53 + 'password.min' => '密码长度不能小于6位',
  54 + 'status.required' => '请选择状态',
  55 + 'status.in' => '状态值不正确',
  56 + ];
  57 + }
  58 +
  59 +}
  1 +<?php
  2 +
  3 +namespace App\Http\Requests\Aside;
  4 +
  5 +use App\Models\Manage\Menu;
  6 +use Illuminate\Foundation\Http\FormRequest;
  7 +use Illuminate\Validation\Rule;
  8 +
  9 +/**
  10 + * Class MenuRequest
  11 + * @package App\Http\Requests\Bside\product
  12 + * @author zbj
  13 + * @date 2023/4/19
  14 + */
  15 +class MenuRequest extends FormRequest
  16 +{
  17 + /**
  18 + * Determine if the user is authorized to make this request.
  19 + *
  20 + * @return bool
  21 + */
  22 + public function authorize()
  23 + {
  24 + return true;
  25 + }
  26 +
  27 + /**
  28 + * Get the validation rules that apply to the request.
  29 + *
  30 + * @return array
  31 + */
  32 + public function rules()
  33 + {
  34 + return [
  35 + 'title' => ['required', 'max:32'],
  36 + 'icon' => ['max:32'],
  37 + 'route_name' => ['max:32'],
  38 + 'type' => ['required', Rule::in(array_keys(Menu::typeMap()))],
  39 + 'status' => ['required', Rule::in(array_keys(Menu::statusMap()))],
  40 + ];
  41 + }
  42 +
  43 + public function messages()
  44 + {
  45 + return [
  46 + 'title.required' => '请输入菜单名称',
  47 + 'title.max' => '菜单名称长度不超过32个字符',
  48 + 'pid.exists' => '父菜单不存在',
  49 + 'icon.max' => '图标长度不超过32个字符',
  50 + 'route_name.max' => '路由长度不超过32个字符',
  51 + 'type.required' => '请选择类型',
  52 + 'type.in' => '类型值无效',
  53 + 'status.required' => '请选择状态',
  54 + 'status.in' => '状态值无效',
  55 + ];
  56 + }
  57 +
  58 +}
1 <?php 1 <?php
2 2
3 -namespace App\Http\Requests\Aside; 3 +namespace App\Http\Requests\Bside\Blog;
4 4
5 -use App\Enums\Common\Demo;  
6 -use BenSampo\Enum\Rules\EnumValue;  
7 use Illuminate\Foundation\Http\FormRequest; 5 use Illuminate\Foundation\Http\FormRequest;
8 6
9 -class DemoRequest extends FormRequest 7 +class BlogCategoryRequest extends FormRequest
10 { 8 {
11 /** 9 /**
12 * Determine if the user is authorized to make this request. 10 * Determine if the user is authorized to make this request.
@@ -26,8 +24,15 @@ class DemoRequest extends FormRequest @@ -26,8 +24,15 @@ class DemoRequest extends FormRequest
26 public function rules() 24 public function rules()
27 { 25 {
28 return [ 26 return [
29 - 'name'=>['required'],  
30 - 'status'=>['required','integer',new EnumValue(Demo::class)] 27 + 'name'=>'required|max:100',
  28 + ];
  29 + }
  30 +
  31 + public function messages()
  32 + {
  33 + return [
  34 + 'name.required'=>'请填写名称',
  35 + 'name.max'=>'名称最大100字',
31 ]; 36 ];
32 } 37 }
33 } 38 }
  1 +<?php
  2 +
  3 +namespace App\Http\Requests\Bside\Blog;
  4 +
  5 +use Illuminate\Foundation\Http\FormRequest;
  6 +
  7 +class BlogLabelRequest extends FormRequest
  8 +{
  9 + /**
  10 + * Determine if the user is authorized to make this request.
  11 + *
  12 + * @return bool
  13 + */
  14 + public function authorize()
  15 + {
  16 + return true;
  17 + }
  18 +
  19 + /**
  20 + * Get the validation rules that apply to the request.
  21 + *
  22 + * @return array
  23 + */
  24 + public function rules()
  25 + {
  26 + return [
  27 + 'name'=>'required|max:100',
  28 + ];
  29 + }
  30 +
  31 + public function messages()
  32 + {
  33 + return [
  34 + 'name.required'=>'请填写名称',
  35 + 'name.max'=>'名称最大100字',
  36 +
  37 + ];
  38 + }
  39 +}
  1 +<?php
  2 +
  3 +namespace App\Http\Requests\Bside\Blog;
  4 +
  5 +use Illuminate\Foundation\Http\FormRequest;
  6 +
  7 +class BlogRequest extends FormRequest
  8 +{
  9 + /**
  10 + * Determine if the user is authorized to make this request.
  11 + *
  12 + * @return bool
  13 + */
  14 + public function authorize()
  15 + {
  16 + return true;
  17 + }
  18 +
  19 + /**
  20 + * Get the validation rules that apply to the request.
  21 + *
  22 + * @return array
  23 + */
  24 + public function rules()
  25 + {
  26 + return [
  27 + 'name'=>'required|max:100',
  28 + 'remark'=>'required|max:100',
  29 + 'text'=>'required|min:10',
  30 + ];
  31 + }
  32 +
  33 + public function messages()
  34 + {
  35 + return [
  36 + 'name.required'=>'请填写名称',
  37 + 'remark.required'=>'请填写简介',
  38 + 'text.required'=>'内容不能为空',
  39 + 'name.max'=>'名称最大100字',
  40 + 'remark.max'=>'简介最大100字',
  41 + 'text.max'=>'内容最小100字',
  42 + ];
  43 + }
  44 +}
  1 +<?php
  2 +
  3 +namespace App\Http\Requests\Bside;
  4 +
  5 +use Illuminate\Foundation\Http\FormRequest;
  6 +
  7 +/**
  8 + * Class DeptRequest
  9 + * @package App\Http\Requests\Bside\product
  10 + * @author zbj
  11 + * @date 2023/4/18
  12 + */
  13 +class DeptRequest extends FormRequest
  14 +{
  15 + /**
  16 + * Determine if the user is authorized to make this request.
  17 + *
  18 + * @return bool
  19 + */
  20 + public function authorize()
  21 + {
  22 + return true;
  23 + }
  24 +
  25 + /**
  26 + * Get the validation rules that apply to the request.
  27 + *
  28 + * @return array
  29 + */
  30 + public function rules()
  31 + {
  32 + return [
  33 + 'title'=>'required|max:50',
  34 + 'remark'=>'max:200',
  35 + ];
  36 + }
  37 +
  38 + public function messages()
  39 + {
  40 + return [
  41 + 'title.required' => '请输入部门名称',
  42 + 'title.max' => '部门名称不能超过50个字符',
  43 + 'remark.max' => '备注不能超过200个字符',
  44 + ];
  45 + }
  46 +
  47 +}
  1 +<?php
  2 +
  3 +namespace App\Http\Requests\Bside\News;
  4 +
  5 +use Illuminate\Foundation\Http\FormRequest;
  6 +
  7 +class NewsCategoryRequest extends FormRequest
  8 +{
  9 + /**
  10 + * Determine if the user is authorized to make this request.
  11 + *
  12 + * @return bool
  13 + */
  14 + public function authorize()
  15 + {
  16 + return true;
  17 + }
  18 +
  19 + /**
  20 + * Get the validation rules that apply to the request.
  21 + *
  22 + * @return array
  23 + */
  24 + public function rules()
  25 + {
  26 + return [
  27 + 'name'=>'required|max:100||unique:gl_news_category',
  28 + ];
  29 + }
  30 +
  31 + public function messages()
  32 + {
  33 + return [
  34 + 'name.required'=>'请填写名称',
  35 + 'name.max'=>'名称最大100字',
  36 + ];
  37 + }
  38 +}
  1 +<?php
  2 +
  3 +namespace App\Http\Requests\Bside\News;
  4 +
  5 +use Illuminate\Foundation\Http\FormRequest;
  6 +
  7 +class NewsLabelRequest extends FormRequest
  8 +{
  9 + /**
  10 + * Determine if the user is authorized to make this request.
  11 + *
  12 + * @return bool
  13 + */
  14 + public function authorize()
  15 + {
  16 + return true;
  17 + }
  18 +
  19 + /**
  20 + * Get the validation rules that apply to the request.
  21 + *
  22 + * @return array
  23 + */
  24 + public function rules()
  25 + {
  26 + return [
  27 + 'name'=>'required|max:100',
  28 + ];
  29 + }
  30 +
  31 + public function messages()
  32 + {
  33 + return [
  34 + 'name.required'=>'请填写名称',
  35 + 'name.max'=>'名称最大100字',
  36 + ];
  37 + }
  38 +}
  1 +<?php
  2 +
  3 +namespace App\Http\Requests\Bside\News;
  4 +
  5 +use Illuminate\Foundation\Http\FormRequest;
  6 +
  7 +class NewsRequest extends FormRequest
  8 +{
  9 + /**
  10 + * Determine if the user is authorized to make this request.
  11 + *
  12 + * @return bool
  13 + */
  14 + public function authorize()
  15 + {
  16 + return true;
  17 + }
  18 +
  19 + /**
  20 + * Get the validation rules that apply to the request.
  21 + *
  22 + * @return array
  23 + */
  24 + public function rules()
  25 + {
  26 + return [
  27 + 'name'=>'required|max:100',
  28 + 'remark'=>'required|max:100',
  29 + 'text'=>'required|min:10',
  30 + ];
  31 + }
  32 +
  33 + public function messages()
  34 + {
  35 + return [
  36 + 'name.required'=>'请填写名称',
  37 + 'remark.required'=>'请填写简介',
  38 + 'text.required'=>'内容不能为空',
  39 + 'name.max'=>'名称最大100字',
  40 + 'remark.max'=>'简介最大100字',
  41 + 'text.max'=>'内容最小100字',
  42 + ];
  43 + }
  44 +}
@@ -19,15 +19,14 @@ class ProjectGroupRequest extends FormRequest @@ -19,15 +19,14 @@ class ProjectGroupRequest extends FormRequest
19 public function rules() 19 public function rules()
20 { 20 {
21 return [ 21 return [
22 - 'name' => 'required|max:255', 22 + 'name' => 'required|max:255||unique:gl_project_group',
23 ]; 23 ];
24 } 24 }
25 25
26 public function messages() 26 public function messages()
27 { 27 {
28 return [ 28 return [
29 - 'name.required' => '请输入文章标题',  
30 -// 'body.required' => '请输入文章内容', 29 + 'name.required' => '请输入用户组名称',
31 ]; 30 ];
32 } 31 }
33 } 32 }
@@ -19,7 +19,7 @@ class ProjectRoleRequest extends FormRequest @@ -19,7 +19,7 @@ class ProjectRoleRequest extends FormRequest
19 public function rules() 19 public function rules()
20 { 20 {
21 return [ 21 return [
22 - 'name'=>'required|max:11', 22 + 'name'=>'required|max:11||unique:gl_project_role',
23 'role_menu'=>'required|string', 23 'role_menu'=>'required|string',
24 ]; 24 ];
25 } 25 }
@@ -24,7 +24,7 @@ class UserRequest extends FormRequest @@ -24,7 +24,7 @@ class UserRequest extends FormRequest
24 public function rules() 24 public function rules()
25 { 25 {
26 return [ 26 return [
27 - 'mobile'=>'required|string|max:11', 27 + 'mobile'=>'required|string|max:11||unique:gl_project_user',
28 'password'=>'required|string|min:5', 28 'password'=>'required|string|min:5',
29 'name'=>'required|max:20', 29 'name'=>'required|max:20',
30 'role_id'=>'required' 30 'role_id'=>'required'
@@ -30,7 +30,7 @@ class AttrRequest extends FormRequest @@ -30,7 +30,7 @@ class AttrRequest extends FormRequest
30 public function rules() 30 public function rules()
31 { 31 {
32 return [ 32 return [
33 - 'title' => 'required|max:30', 33 + 'title' => 'required|max:50',
34 'remark' => 'max:200', 34 'remark' => 'max:200',
35 'values' => 'required|array' 35 'values' => 'required|array'
36 ]; 36 ];
@@ -40,7 +40,7 @@ class AttrRequest extends FormRequest @@ -40,7 +40,7 @@ class AttrRequest extends FormRequest
40 { 40 {
41 return [ 41 return [
42 'title.required' => '请输入参数名称', 42 'title.required' => '请输入参数名称',
43 - 'title.max' => '参数名称不能超过30个字符', 43 + 'title.max' => '参数名称不能超过50个字符',
44 'remark.max' => '备注不能超过200个字符', 44 'remark.max' => '备注不能超过200个字符',
45 'values.required' => '请添加参数值', 45 'values.required' => '请添加参数值',
46 'values.array' => '参数值格式异常', 46 'values.array' => '参数值格式异常',
@@ -30,7 +30,7 @@ class CategoryRequest extends FormRequest @@ -30,7 +30,7 @@ class CategoryRequest extends FormRequest
30 public function rules() 30 public function rules()
31 { 31 {
32 return [ 32 return [
33 - 'title'=>'required|max:20', 33 + 'title'=>'required|max:50',
34 'image'=>'required', 34 'image'=>'required',
35 'keywords'=>'required|max:50', 35 'keywords'=>'required|max:50',
36 'describe'=>'required|max:200', 36 'describe'=>'required|max:200',
@@ -41,7 +41,7 @@ class CategoryRequest extends FormRequest @@ -41,7 +41,7 @@ class CategoryRequest extends FormRequest
41 { 41 {
42 return [ 42 return [
43 'title.required' => '请输入分类名称', 43 'title.required' => '请输入分类名称',
44 - 'title.max' => '分类名称不能超过20个字符', 44 + 'title.max' => '分类名称不能超过50个字符',
45 'image.required' => '请上传分类图片', 45 'image.required' => '请上传分类图片',
46 'keywords.required' => '请输入分类关键词', 46 'keywords.required' => '请输入分类关键词',
47 'keywords.max' => '分类关键词不能超过50个字符', 47 'keywords.max' => '分类关键词不能超过50个字符',
@@ -30,7 +30,7 @@ class DescribeRequest extends FormRequest @@ -30,7 +30,7 @@ class DescribeRequest extends FormRequest
30 public function rules() 30 public function rules()
31 { 31 {
32 return [ 32 return [
33 - 'title'=>'required|max:30', 33 + 'title'=>'required|max:50',
34 'describe'=>'required', 34 'describe'=>'required',
35 ]; 35 ];
36 } 36 }
@@ -39,7 +39,7 @@ class DescribeRequest extends FormRequest @@ -39,7 +39,7 @@ class DescribeRequest extends FormRequest
39 { 39 {
40 return [ 40 return [
41 'title.required' => '请输入描述名称', 41 'title.required' => '请输入描述名称',
42 - 'title.max' => '描述名称不能超过30个字符', 42 + 'title.max' => '描述名称不能超过50个字符',
43 'seo_title.required' => '请输入描述内容', 43 'seo_title.required' => '请输入描述内容',
44 ]; 44 ];
45 } 45 }
@@ -30,7 +30,7 @@ class KeywordRequest extends FormRequest @@ -30,7 +30,7 @@ class KeywordRequest extends FormRequest
30 public function rules() 30 public function rules()
31 { 31 {
32 return [ 32 return [
33 - 'title'=>'required|max:30', 33 + 'title'=>'required|max:50',
34 'seo_title'=>'max:200', 34 'seo_title'=>'max:200',
35 'seo_keywords'=>'max:200', 35 'seo_keywords'=>'max:200',
36 'seo_description'=>'max:200', 36 'seo_description'=>'max:200',
@@ -41,7 +41,7 @@ class KeywordRequest extends FormRequest @@ -41,7 +41,7 @@ class KeywordRequest extends FormRequest
41 { 41 {
42 return [ 42 return [
43 'title.required' => '请输入关键词', 43 'title.required' => '请输入关键词',
44 - 'title.max' => '关键词不能超过30个字符', 44 + 'title.max' => '关键词不能超过50个字符',
45 'seo_title.max' => 'SEO标题不能超过200个字符', 45 'seo_title.max' => 'SEO标题不能超过200个字符',
46 'seo_keywords.max' => 'SEO关键词不能超过200个字符', 46 'seo_keywords.max' => 'SEO关键词不能超过200个字符',
47 'seo_description.max' => 'SEO描述不能超过200个字符', 47 'seo_description.max' => 'SEO描述不能超过200个字符',
@@ -2,7 +2,13 @@ @@ -2,7 +2,13 @@
2 2
3 namespace App\Http\Requests\Bside\product; 3 namespace App\Http\Requests\Bside\product;
4 4
  5 +use App\Enums\Common\Code;
  6 +use App\Exceptions\BsideGlobalException;
  7 +use App\Helper\Arr;
  8 +use App\Models\Product\Product;
5 use Illuminate\Foundation\Http\FormRequest; 9 use Illuminate\Foundation\Http\FormRequest;
  10 +use Illuminate\Support\Str;
  11 +use Illuminate\Validation\Rule;
6 12
7 /** 13 /**
8 * Class ProductRequest 14 * Class ProductRequest
@@ -30,23 +36,77 @@ class ProductRequest extends FormRequest @@ -30,23 +36,77 @@ class ProductRequest extends FormRequest
30 public function rules() 36 public function rules()
31 { 37 {
32 return [ 38 return [
33 - 'title'=>'required|max:20',  
34 - 'image'=>'required',  
35 - 'keywords'=>'required|max:50',  
36 - 'describe'=>'required|max:200', 39 + 'title' => 'required|max:200',
  40 + 'route' => 'required|max:100',
  41 + 'gallery' => ['required', 'array', function ($attribute, $value, $fail) {
  42 + foreach ($value as $v) {
  43 + if (empty($v['url'])) {
  44 + $fail('图片链接不能为空');
  45 + }
  46 + if (Str::contains($v['url'], env('APP_URL'))) {
  47 + $fail('图片链接不正确');
  48 + }
  49 + }
  50 + }],
  51 + 'attrs' => ['required', 'array', function ($attribute, $value, $fail) {
  52 + foreach ($value as $v) {
  53 + if (empty($v['key'])) {
  54 + $fail('产品属性名不能为空');
  55 + }
  56 + if (empty($v['value'])) {
  57 + $fail('产品属性值不能为空');
  58 + }
  59 + }
  60 + }],
  61 + 'category_id' => 'required',
  62 + 'keywords' => 'required',
  63 + 'intro' => 'required|max:500',
  64 + 'content' => 'required',
  65 + 'describe' => 'required|array',
  66 + 'seo_mate' => ['required', 'array', function ($attribute, $value, $fail) {
  67 + if(empty($value['title'])){
  68 + $fail('SEO标题不能为空');
  69 + }
  70 + if(empty($value['description'])){
  71 + $fail('SEO描述不能为空');
  72 + }
  73 + if(empty($value['keyword'])){
  74 + $fail('SEO关键词不能为空');
  75 + }
  76 + }],
  77 + 'related_product_id' => ['required', function ($attribute, $value, $fail) {
  78 + $value = array_filter(Arr::splitFilterToArray($value), 'intval');
  79 + if(count($value) > 16){
  80 + $fail('关联产品不能超过16个');
  81 + }
  82 + }],
  83 + 'status' => ['required', Rule::in(array_keys(Product::statusMap()))],
37 ]; 84 ];
38 } 85 }
39 86
40 public function messages() 87 public function messages()
41 { 88 {
42 return [ 89 return [
43 - 'title.required' => '请输入分类名称',  
44 - 'title.max' => '分类名称不能超过20个字符',  
45 - 'image.required' => '请上传分类图片',  
46 - 'keywords.required' => '请输入分类关键词',  
47 - 'keywords.max' => '分类关键词不能超过50个字符',  
48 - 'describe.required' => '请输入分类描述',  
49 - 'describe.max' => '分类描述不能超过200个字符', 90 + 'title.required' => '请输入产品标题',
  91 + 'title.max' => '产品标题不能超过20个字符',
  92 + 'route.required' => '请输入产品链接',
  93 + 'route.max' => '产品链接不能超过100个字符',
  94 + 'gallery.required' => '请上传产品图片',
  95 + 'gallery.array' => '产品图片格式异常',
  96 + 'attrs.required' => '请添加产品参数',
  97 + 'attrs.array' => '产品参数格式异常',
  98 + 'category_id.required' => '请选择分类',
  99 + 'keywords.required' => '请添加关键词标签',
  100 + 'intro.required' => '请输入短描述',
  101 + 'intro.max' => '短描述不能超过500个字符',
  102 + 'content.required' => '请输入产品描述',
  103 + 'describe.required' => '请添加描述切换栏',
  104 + 'describe.array' => '描述切换栏格式异常',
  105 + 'seo_mate.required' => '请输入SEO',
  106 + 'seo_mate.array' => 'SEO格式异常',
  107 + 'related_product_id.required' => '请选择相关产品',
  108 + 'status.required' => '请选择产品状态',
  109 + 'status.in' => '产品状态值异常',
50 ]; 110 ];
51 } 111 }
52 112
@@ -2,10 +2,10 @@ @@ -2,10 +2,10 @@
2 2
3 namespace App\Models; 3 namespace App\Models;
4 4
5 -class Manager extends Base 5 +class AiCommand extends Base
6 { 6 {
7 //设置关联表名 7 //设置关联表名
8 - protected $table = 'gl_manager'; 8 + protected $table = 'gl_ai_command';
9 //自动维护create_at创建时间 updated_at修改时间 9 //自动维护create_at创建时间 updated_at修改时间
10 public $timestamps = true; 10 public $timestamps = true;
11 11
@@ -15,7 +15,6 @@ class Base extends Model @@ -15,7 +15,6 @@ class Base extends Model
15 'created_at' => 'datetime:Y-m-d H:i:s', 15 'created_at' => 'datetime:Y-m-d H:i:s',
16 'updated_at' => 'datetime:Y-m-d H:i:s', 16 'updated_at' => 'datetime:Y-m-d H:i:s',
17 ]; 17 ];
18 -  
19 /** 18 /**
20 * 日期序列化 勿删 删了时间就不是东八区时间了哈 19 * 日期序列化 勿删 删了时间就不是东八区时间了哈
21 * @param \DateTimeInterface $date 20 * @param \DateTimeInterface $date
@@ -27,30 +26,26 @@ class Base extends Model @@ -27,30 +26,26 @@ class Base extends Model
27 { 26 {
28 return $date->format('Y-m-d H:i:s'); 27 return $date->format('Y-m-d H:i:s');
29 } 28 }
30 -  
31 /** 29 /**
32 * @name 列表数据 30 * @name 列表数据
33 * @return void 31 * @return void
34 * @author :liyuhang 32 * @author :liyuhang
35 * @method 33 * @method
36 */ 34 */
37 - public function lists($map, $p, $row, $order = 'id', $fields = ['*']){  
38 - //TODO::where(['id'=>'','name'=>'']) 35 + public function lists($map, $page, $row, $order = 'id', $fields = ['*']){
39 $query = $this->formatQuery($map); 36 $query = $this->formatQuery($map);
40 - $lists = $query->select($fields)->orderBy($order)->paginate($row, ['*'], 'page', $p); 37 + $lists = $query->select($fields)->orderBy($order)->paginate($row, ['*'], 'page', $page);
41 if (empty($lists)) { 38 if (empty($lists)) {
42 - return false; 39 + return [];
43 } 40 }
44 $lists = $lists->toArray(); 41 $lists = $lists->toArray();
45 return $lists; 42 return $lists;
46 } 43 }
47 -  
48 -  
49 /** 44 /**
  45 + * @name :无分页列表
50 * @param $map 46 * @param $map
51 * @param $order 47 * @param $order
52 * @param $fields 48 * @param $fields
53 - * @name :无分页列表  
54 * @return mixed 49 * @return mixed
55 * @author :liyuhang 50 * @author :liyuhang
56 * @method 51 * @method
@@ -59,14 +54,14 @@ class Base extends Model @@ -59,14 +54,14 @@ class Base extends Model
59 $query = $this->formatQuery($map); 54 $query = $this->formatQuery($map);
60 $lists = $query->select($fields)->orderBy($order)->get(); 55 $lists = $query->select($fields)->orderBy($order)->get();
61 if (empty($lists)) { 56 if (empty($lists)) {
62 - return false; 57 + return [];
63 } 58 }
64 $lists = $lists->toArray(); 59 $lists = $lists->toArray();
65 return $lists; 60 return $lists;
66 } 61 }
67 /** 62 /**
68 - * @param array:$condition  
69 * @name :获取单条数据详情 63 * @name :获取单条数据详情
  64 + * @param array
70 * @return mixed 65 * @return mixed
71 * @author :liyuhang 66 * @author :liyuhang
72 * @method get 67 * @method get
@@ -81,8 +76,6 @@ class Base extends Model @@ -81,8 +76,6 @@ class Base extends Model
81 $info = $info->toArray(); 76 $info = $info->toArray();
82 return $info; 77 return $info;
83 } 78 }
84 -  
85 -  
86 /** 79 /**
87 * @name :新增 80 * @name :新增
88 * @return void 81 * @return void
@@ -94,7 +87,6 @@ class Base extends Model @@ -94,7 +87,6 @@ class Base extends Model
94 $data['updated_at'] = date('Y-m-d H:i:s'); 87 $data['updated_at'] = date('Y-m-d H:i:s');
95 return $this->insert($data); 88 return $this->insert($data);
96 } 89 }
97 -  
98 /** 90 /**
99 * @name :编辑 91 * @name :编辑
100 * @return void 92 * @return void
@@ -104,10 +96,8 @@ class Base extends Model @@ -104,10 +96,8 @@ class Base extends Model
104 public function edit($data,$condition){ 96 public function edit($data,$condition){
105 $query = $this->formatQuery($condition); 97 $query = $this->formatQuery($condition);
106 $data['updated_at'] = date('Y-m-d H:i:s'); 98 $data['updated_at'] = date('Y-m-d H:i:s');
107 - $rs = $query->update($data);  
108 - return $rs; 99 + return $query->update($data);
109 } 100 }
110 -  
111 /** 101 /**
112 * @name : 删除数据 102 * @name : 删除数据
113 * @return void 103 * @return void
@@ -118,12 +108,10 @@ class Base extends Model @@ -118,12 +108,10 @@ class Base extends Model
118 $query = $this->formatQuery($condition); 108 $query = $this->formatQuery($condition);
119 return $query->delete(); 109 return $query->delete();
120 } 110 }
121 -  
122 -  
123 /** 111 /**
  112 + * @name :参数处理查询
124 * @param $map = ['$k'=>['like',$v],$k1] 113 * @param $map = ['$k'=>['like',$v],$k1]
125 * @param $val 114 * @param $val
126 - * @name :参数处理查询  
127 * @return Base 115 * @return Base
128 * @author :liyuhang 116 * @author :liyuhang
129 * @method 117 * @method
@@ -132,47 +120,45 @@ class Base extends Model @@ -132,47 +120,45 @@ class Base extends Model
132 $model = $query ?: $this; 120 $model = $query ?: $this;
133 $query = $model->where(function ($query) use ($map){ 121 $query = $model->where(function ($query) use ($map){
134 foreach ($map as $k => $v){ 122 foreach ($map as $k => $v){
135 - if(is_array($v)){  
136 - //拼接数据  
137 - foreach ($v as $k1 => $v1){  
138 - switch ($k1){ 123 + if(!is_array($v)){
  124 + $query->where($k,$v);
  125 + continue;
  126 + }
  127 + switch ($v[0]){
139 case 'like': 128 case 'like':
140 // like查询 ['name|title'=> ['like','%a%']] 129 // like查询 ['name|title'=> ['like','%a%']]
141 if (strpos($k, '|') !== false) { 130 if (strpos($k, '|') !== false) {
142 - $query->where(function ($query) use ($k,$v1) { 131 + $query->where(function ($query) use ($k,$v) {
143 $item = explode('|', $k); 132 $item = explode('|', $k);
144 foreach ($item as $vo) { 133 foreach ($item as $vo) {
145 - $query->orWhere($vo, $v1[0], $v1[1]); 134 + $query->orWhere($vo, $v[0], $v[1]);
146 } 135 }
147 }); 136 });
148 } else { 137 } else {
149 - $query->where($k,$v1[0], $v1[1]); 138 + $query->where($k, $v[0], $v[1]);
150 } 139 }
151 break; 140 break;
152 case 'in': 141 case 'in':
153 - // in查询 ['id'=>['in'=>[1,2,3]]]  
154 - $query->whereIn($k, $v1[1]); 142 + // in查询 ['id'=>['in',[1,2,3]]]
  143 + $query->whereIn($k, $v[1]);
155 break; 144 break;
156 case 'no in': 145 case 'no in':
157 - // in查询 ['id'=>['not in'=>[1,2,3]]]  
158 - $query->whereNotIn($k, $v1[1]); 146 + // in查询 ['id'=>['not in',[1,2,3]]]
  147 + $query->whereNotIn($k, $v[1]);
159 break; 148 break;
160 case 'between': 149 case 'between':
161 - // in查询 ['id'=>['between'=>[create1,create2]]]  
162 - $query->whereBetween($k, $v1[1]); 150 + // in查询 ['id'=>['between',[create1,create2]]]
  151 + $query->whereBetween($k, $v[1]);
163 case 'not between': 152 case 'not between':
164 - // not between查询 ['created_at'=>['not between'=>['xxx', 'xxx]]]  
165 - $query->whereNotBetween($k, $v1[1]); 153 + // not between查询 ['created_at'=>['not between',['xxx', 'xxx]]]
  154 + $query->whereNotBetween($k, $v[1]);
166 break; 155 break;
167 default: 156 default:
168 - $query->where($k,$k1,$v1[1]); 157 + $query->where($k,$v[0],$v[1]);
169 break; 158 break;
170 } 159 }
171 } 160 }
172 - }else{  
173 - $query->where($k,$v);  
174 - }  
175 - } 161 +
176 }); 162 });
177 return $query; 163 return $query;
178 } 164 }
  1 +<?php
  2 +
  3 +namespace App\Models\Blog;
  4 +
  5 +use App\Models\Base;
  6 +
  7 +class Blog extends Base
  8 +{
  9 + protected $table = 'gl_blog';
  10 +}
  1 +<?php
  2 +
  3 +namespace App\Models\Blog;
  4 +
  5 +use App\Models\Base;
  6 +
  7 +class BlogCategory extends Base
  8 +{
  9 + protected $table = 'gl_blog_category';
  10 +}
  1 +<?php
  2 +
  3 +namespace App\Models\Blog;
  4 +
  5 +use App\Models\Base;
  6 +
  7 +class BlogLabel extends Base
  8 +{
  9 + protected $table = 'gl_blog_label';
  10 +}
@@ -2,7 +2,9 @@ @@ -2,7 +2,9 @@
2 2
3 namespace App\Models; 3 namespace App\Models;
4 4
5 -class Menu extends Base 5 +class Image extends Base
6 { 6 {
7 - protected $table = 'gl_menu'; 7 + protected $table = 'gl_image';
  8 +
  9 + public $timestamps = true;
8 } 10 }
  1 +<?php
  2 +
  3 +namespace App\Models;
  4 +
  5 +class Mail extends Base
  6 +{
  7 + protected $table = 'gl_mail';
  8 + //自动维护create_at创建时间 updated_at修改时间
  9 + public $timestamps = true;
  10 +}
  1 +<?php
  2 +
  3 +namespace App\Models;
  4 +
  5 +class MailUser extends Base
  6 +{
  7 + protected $table = 'gl_mail_user';
  8 + //自动维护create_at创建时间 updated_at修改时间
  9 + public $timestamps = true;
  10 +}
  1 +<?php
  2 +
  3 +namespace App\Models\Manage;
  4 +
  5 +use App\Models\Base;
  6 +use Illuminate\Database\Eloquent\SoftDeletes;
  7 +
  8 +class Dept extends Base
  9 +{
  10 + use SoftDeletes;
  11 +
  12 + //设置关联表名
  13 + protected $table = 'gl_manage_dept';
  14 +
  15 +}
  1 +<?php
  2 +
  3 +namespace App\Models\Manage;
  4 +
  5 +
  6 +
  7 +use App\Helper\Arr;
  8 +use App\Models\Base;
  9 +
  10 +class Group extends Base
  11 +{
  12 + protected $table = 'gl_manage_group';
  13 +
  14 + const STATUS_NORMAL = 0;
  15 + const STATUS_ABNORMAL = 1;
  16 +
  17 + /**
  18 + * @return string[]
  19 + */
  20 + public static function statusMap(){
  21 + return [
  22 + self::STATUS_NORMAL => '正常',
  23 + self::STATUS_ABNORMAL => '禁用',
  24 + ];
  25 + }
  26 +
  27 + /**
  28 + * 获取用户组路由权限
  29 + * @param $gid
  30 + * @return array
  31 + */
  32 + public static function getRouteByGroupId($gid)
  33 + {
  34 + $group = self::where(['id' => $gid, 'status' => self::STATUS_NORMAL])->first();
  35 + if(!$group){
  36 + return [];
  37 + }
  38 + $routes = Menu::where(['status' => Menu::STATUS_NORMAL])->whereIn('id', $group->rights)->pluck('route_name')->toArray();
  39 + return array_filter($routes);
  40 + }
  41 +
  42 + public function getRightsAttribute($value)
  43 + {
  44 + return Arr::setToArr($value);
  45 + }
  46 +
  47 + public function setRightsAttribute($value)
  48 + {
  49 + $this->attributes['rights'] = Arr::arrToSet($value);
  50 + }
  51 +}
  1 +<?php
  2 +
  3 +namespace App\Models\Manage;
  4 +
  5 +use App\Models\Base;
  6 +use Illuminate\Support\Facades\Session;
  7 +
  8 +class LoginLog extends Base
  9 +{
  10 + //设置关联表名
  11 + protected $table = 'gl_manage_login_log';
  12 +
  13 + const UPDATED_AT = null;
  14 +
  15 + /**
  16 + * 登录日志
  17 + * @param $manage_id
  18 + * @author zbj
  19 + * @date 2023/4/20
  20 + */
  21 + public function addLog($manage_id){
  22 + $log = new self();
  23 + $log->manage_id = $manage_id;
  24 + $log->session_id = Session::getId();
  25 + $log->ip = request()->ip();
  26 + $log->save();
  27 + }
  28 +}
  1 +<?php
  2 +
  3 +namespace App\Models\Manage;
  4 +
  5 +use App\Models\Base;
  6 +
  7 +class Manage extends Base
  8 +{
  9 + //设置关联表名
  10 + protected $table = 'gl_manage';
  11 +
  12 + protected $hidden = ['password'];
  13 +
  14 + const STATUS_ACTIVE = 0;
  15 + const STATUS_DISABLE = 1;
  16 +
  17 + /**
  18 + * 超级管理员ID, 当前ID拥有所有权限, 不能进行修改
  19 + */
  20 + const ADMINISTRATOR_ID = 1;
  21 +
  22 + public function statusMap(){
  23 + return [
  24 + self::STATUS_ACTIVE => '正常',
  25 + self::STATUS_DISABLE => '禁用',
  26 + ];
  27 + }
  28 +}
  1 +<?php
  2 +
  3 +namespace App\Models\Manage;
  4 +
  5 +use App\Models\Base;
  6 +
  7 +class Menu extends Base
  8 +{
  9 + protected $table = 'gl_manage_menu';
  10 +
  11 + const STATUS_NORMAL = 0;
  12 + const STATUS_ABNORMAL = 1;
  13 +
  14 + const TYPE_SHOW = 'show';
  15 + const TYPE_SAVE = 'save';
  16 + const TYPE_DELETE = 'delete';
  17 +
  18 + /**
  19 + * @return string[]
  20 + */
  21 + public static function statusMap(): array
  22 + {
  23 + return [
  24 + self::STATUS_NORMAL => '正常',
  25 + self::STATUS_ABNORMAL => '禁用',
  26 + ];
  27 + }
  28 +
  29 + /**
  30 + * @return string[]
  31 + */
  32 + public static function typeMap(): array
  33 + {
  34 + return [
  35 + self::TYPE_SHOW => '查看',
  36 + self::TYPE_SAVE => '保存',
  37 + self::TYPE_DELETE => '删除',
  38 + ];
  39 + }
  40 +}
  1 +<?php
  2 +
  3 +namespace App\Models\News;
  4 +
  5 +use App\Models\Base;
  6 +
  7 +class News extends Base
  8 +{
  9 + protected $table = 'gl_news';
  10 +}
  1 +<?php
  2 +
  3 +namespace App\Models\News;
  4 +
  5 +use App\Models\Base;
  6 +
  7 +class NewsCategory extends Base
  8 +{
  9 + protected $table = 'gl_news_category';
  10 +}
  1 +<?php
  2 +
  3 +namespace App\Models\News;
  4 +
  5 +use App\Models\Base;
  6 +
  7 +class NewsLabel extends Base
  8 +{
  9 + protected $table = 'gl_news_label';
  10 +}
@@ -2,7 +2,9 @@ @@ -2,7 +2,9 @@
2 2
3 namespace App\Models\Product; 3 namespace App\Models\Product;
4 4
  5 +
5 use App\Models\Base; 6 use App\Models\Base;
  7 +use App\Services\Facades\Upload;
6 use Illuminate\Database\Eloquent\SoftDeletes; 8 use Illuminate\Database\Eloquent\SoftDeletes;
7 9
8 class Category extends Base 10 class Category extends Base
@@ -12,4 +14,13 @@ class Category extends Base @@ -12,4 +14,13 @@ class Category extends Base
12 //设置关联表名 14 //设置关联表名
13 protected $table = 'gl_product_category'; 15 protected $table = 'gl_product_category';
14 16
  17 + public function getImageAttribute($value)
  18 + {
  19 + return Upload::path2url($value);
  20 + }
  21 +
  22 + public function setImageAttribute($value)
  23 + {
  24 + $this->attributes['image'] = Upload::url2path($value);
  25 + }
15 } 26 }
@@ -2,7 +2,9 @@ @@ -2,7 +2,9 @@
2 2
3 namespace App\Models\Product; 3 namespace App\Models\Product;
4 4
  5 +use App\Helper\Arr;
5 use App\Models\Base; 6 use App\Models\Base;
  7 +use App\Services\Facades\Upload;
6 use Illuminate\Database\Eloquent\SoftDeletes; 8 use Illuminate\Database\Eloquent\SoftDeletes;
7 9
8 class Product extends Base 10 class Product extends Base
@@ -12,4 +14,91 @@ class Product extends Base @@ -12,4 +14,91 @@ class Product extends Base
12 //设置关联表名 14 //设置关联表名
13 protected $table = 'gl_product'; 15 protected $table = 'gl_product';
14 16
  17 + const STATUS_DRAFT = 0;
  18 + const STATUS_ON = 1;
  19 + const STATUS_OFF = 2;
  20 +
  21 +
  22 + public static function statusMap(){
  23 + return [
  24 + self::STATUS_DRAFT => '草稿',
  25 + self::STATUS_ON => '已上架',
  26 + self::STATUS_OFF => '未上架',
  27 + ];
  28 + }
  29 +
  30 + public function setThumbAttribute($value){
  31 + $value['url'] = Upload::url2path($value['url']);
  32 + $this->attributes['thumb'] = Arr::a2s($value);
  33 + }
  34 +
  35 + public function getThumbAttribute($value){
  36 + $value = Arr::s2a($value);
  37 + $value['url'] = Upload::path2url($value['url']);
  38 + return $value;
  39 + }
  40 +
  41 + public function setGalleryAttribute($value){
  42 + foreach ($value as &$v){
  43 + $v['url'] = Upload::url2path($v['url']);
  44 + }
  45 + $this->attributes['gallery'] = Arr::a2s($value);
  46 + }
  47 +
  48 + public function getGalleryAttribute($value){
  49 + $value = Arr::s2a($value);
  50 + foreach ($value as &$v){
  51 + $v['url'] = Upload::path2url($v['url']);
  52 + }
  53 + return $value;
  54 + }
  55 +
  56 + public function setAttrsAttribute($value){
  57 + $this->attributes['attrs'] = Arr::a2s($value);
  58 + }
  59 +
  60 + public function getAttrsAttribute($value){
  61 + return Arr::s2a($value);
  62 + }
  63 +
  64 + public function setDescribeAttribute($value){
  65 + $this->attributes['describe'] = Arr::a2s($value);
  66 + }
  67 +
  68 + public function getDescribeAttribute($value){
  69 + return Arr::s2a($value);
  70 + }
  71 +
  72 + public function setSeoMateAttribute($value){
  73 + $this->attributes['seo_mate'] = Arr::a2s($value);
  74 + }
  75 +
  76 + public function getSeoMateAttribute($value){
  77 + return Arr::s2a($value);
  78 + }
  79 +
  80 + public function setCategoryIdAttribute($value){
  81 + $this->attributes['category_id'] = Arr::arrToSet($value);
  82 + }
  83 +
  84 + public function getCategoryIdAttribute($value){
  85 + return Arr::setToArr($value);
  86 + }
  87 +
  88 + public function setKeywordsAttribute($value){
  89 + $this->attributes['keywords'] = Arr::arrToSet($value, 'trim');
  90 + }
  91 +
  92 + public function getKeywordsAttribute($value){
  93 + return Arr::setToArr($value, 'trim');
  94 + }
  95 +
  96 + public function setRelatedProductIdAttribute($value){
  97 + $this->attributes['related_product_id'] = Arr::arrToSet($value);
  98 + }
  99 +
  100 + public function getRelatedProductIdAttribute($value){
  101 + return Arr::setToArr($value);
  102 + }
  103 +
15 } 104 }
  1 +<?php
  2 +
  3 +namespace App\Models;
  4 +
  5 +use Illuminate\Database\Eloquent\SoftDeletes;
  6 +
  7 +class ProjectDept extends Base
  8 +{
  9 + use SoftDeletes;
  10 +
  11 + //设置关联表名
  12 + protected $table = 'gl_project_dept';
  13 +
  14 +}
@@ -22,7 +22,9 @@ class RouteMap extends Model @@ -22,7 +22,9 @@ class RouteMap extends Model
22 const SOURCE_PRODUCT_CATE = 'product_category'; 22 const SOURCE_PRODUCT_CATE = 'product_category';
23 const SOURCE_PRODUCT_KEYWORD = 'product_keyword'; 23 const SOURCE_PRODUCT_KEYWORD = 'product_keyword';
24 24
25 - 25 + //路由类型
  26 + const SOURCE_BLOG = 'blog';
  27 + const SOURCE_NEWS = 'news';
26 /** 28 /**
27 * 生成路由标识 29 * 生成路由标识
28 * @param $title 30 * @param $title
@@ -74,18 +76,13 @@ class RouteMap extends Model @@ -74,18 +76,13 @@ class RouteMap extends Model
74 * @param $source 76 * @param $source
75 * @param $source_id 77 * @param $source_id
76 * @param int $project_id 78 * @param int $project_id
77 - * @param bool $auto  
78 * @return bool 79 * @return bool
79 * @throws \Exception 80 * @throws \Exception
80 * @author zbj 81 * @author zbj
81 * @date 2023/4/17 82 * @date 2023/4/17
82 */ 83 */
83 - public static function setRoute($title, $source, $source_id, $project_id = 0, $auto=false){  
84 - $route = $title;  
85 -  
86 - if($auto){ 84 + public static function setRoute($title, $source, $source_id, $project_id = 0){
87 $route = self::generateRoute($title, $source, $source_id, $project_id); 85 $route = self::generateRoute($title, $source, $source_id, $project_id);
88 - }  
89 if(!$route){ 86 if(!$route){
90 throw new \Exception('路由不能为空'); 87 throw new \Exception('路由不能为空');
91 } 88 }
@@ -150,7 +147,7 @@ class RouteMap extends Model @@ -150,7 +147,7 @@ class RouteMap extends Model
150 * @author zbj 147 * @author zbj
151 * @date 2023/4/17 148 * @date 2023/4/17
152 */ 149 */
153 - public function delRoute($source, $source_id, $project_id){ 150 + public static function delRoute($source, $source_id, $project_id){
154 return self::where('project_id', $project_id)->where('source', $source)->where('source_id', $source_id)->delete(); 151 return self::where('project_id', $project_id)->where('source', $source)->where('source_id', $source_id)->delete();
155 } 152 }
156 } 153 }
@@ -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
@@ -2,7 +2,7 @@ @@ -2,7 +2,7 @@
2 2
3 namespace App\Providers; 3 namespace App\Providers;
4 4
5 -use App\Services\PaginatorServer; 5 +use App\Services\PaginatorService;
6 use Illuminate\Support\ServiceProvider; 6 use Illuminate\Support\ServiceProvider;
7 7
8 class AppServiceProvider extends ServiceProvider 8 class AppServiceProvider extends ServiceProvider
@@ -16,7 +16,7 @@ class AppServiceProvider extends ServiceProvider @@ -16,7 +16,7 @@ class AppServiceProvider extends ServiceProvider
16 { 16 {
17 //自定义分页 17 //自定义分页
18 $this->app->bind('Illuminate\Pagination\LengthAwarePaginator',function ($app,$options){ 18 $this->app->bind('Illuminate\Pagination\LengthAwarePaginator',function ($app,$options){
19 - return new PaginatorServer($options['items'], $options['total'], $options['perPage'], $options['currentPage'] , $options['options']); 19 + return new PaginatorService($options['items'], $options['total'], $options['perPage'], $options['currentPage'] , $options['options']);
20 }); 20 });
21 } 21 }
22 22
  1 +<?php
  2 +
  3 +namespace App\Rules;
  4 +
  5 +use Illuminate\Contracts\Validation\Rule;
  6 +
  7 +/**
  8 + * 验证手机号
  9 + * Class Mobile
  10 + * @package App\Rules
  11 + * @author zbj
  12 + * @date 2023/4/19
  13 + */
  14 +class Mobile implements Rule
  15 +{
  16 +
  17 + /**
  18 + * Determine if the validation rule passes.
  19 + *
  20 + * @param string $attribute
  21 + * @param mixed $value
  22 + * @return bool
  23 + */
  24 + public function passes($attribute, $value)
  25 + {
  26 + $cardReg = '/^1(3|4|5|7|8)\d{9}$/';
  27 + return preg_match($cardReg, $value);
  28 + }
  29 +
  30 + /**
  31 + * Get the validation error message.
  32 + *
  33 + * @return string
  34 + */
  35 + public function message()
  36 + {
  37 + return '手机号码格式不正确';
  38 + }
  39 +}
@@ -13,13 +13,14 @@ class BaseService @@ -13,13 +13,14 @@ class BaseService
13 { 13 {
14 /** 14 /**
15 * @notes: 手动抛出异常 15 * @notes: 手动抛出异常
  16 + * @param string $msg
16 * @param string $code 17 * @param string $code
17 * @throws BsideGlobalException 18 * @throws BsideGlobalException
18 * @author:wlj 19 * @author:wlj
19 * @date: 2022/7/19 14:25 20 * @date: 2022/7/19 14:25
20 */ 21 */
21 - public function fail(string $code = Code::SYSTEM_ERROR) 22 + public function fail(string $msg, string $code = Code::SYSTEM_ERROR)
22 { 23 {
23 - throw new BsideGlobalException($code); 24 + throw new BsideGlobalException($code, $msg);
24 } 25 }
25 } 26 }
  1 +<?php
  2 +
  3 +namespace App\Services\Facades;
  4 +
  5 +use Illuminate\Support\Facades\Facade;
  6 +
  7 +/**
  8 + * @see \App\Services\UploadService
  9 + * @method static string put(string $input_name="file", string|array $config="default") 单个文件上传
  10 + * @method static array puts(string $input_name="file", string|array $config="default") 批量获取上传的文件
  11 + * @method static array filePut(string $filename, string $content, string|array $config="default")
  12 + * @method static string url2path(string $url, string|array $disk="upload")
  13 + * @method static string path2url(string $path, string|array $disk="upload")
  14 + */
  15 +class Upload extends Facade
  16 +{
  17 + protected static function getFacadeAccessor()
  18 + {
  19 + return '\App\Services\UploadService';
  20 + }
  21 +}
@@ -11,7 +11,7 @@ use Illuminate\Pagination\LengthAwarePaginator; @@ -11,7 +11,7 @@ use Illuminate\Pagination\LengthAwarePaginator;
11 * @author zbj 11 * @author zbj
12 * @date 2023/4/14 12 * @date 2023/4/14
13 */ 13 */
14 -class PaginatorServer extends LengthAwarePaginator 14 +class PaginatorService extends LengthAwarePaginator
15 { 15 {
16 public function toArray() 16 public function toArray()
17 { 17 {
  1 +<?php
  2 +
  3 +namespace App\Services;
  4 +
  5 +
  6 +use App\Helper\FileEtag;
  7 +use Illuminate\Support\Facades\DB;
  8 +use Illuminate\Support\Facades\Storage;
  9 +use Illuminate\Support\Str;
  10 +use Illuminate\Http\UploadedFile;
  11 +
  12 +/**
  13 + * Class UploadServer
  14 + * @package App\Services
  15 + */
  16 +class UploadService extends BaseService
  17 +{
  18 +
  19 + /**
  20 + * 默认配置
  21 + * @see $defaultConfig
  22 + * @var array
  23 + */
  24 + public $config = [];
  25 +
  26 + /**
  27 + * 默认配置
  28 + * @var array
  29 + */
  30 + public $defaultConfig = [
  31 + // 上传文件的大小范围
  32 + 'size' => [
  33 + 'max' => 1024 * 1024 * 2, // 2M
  34 + ],
  35 + // 磁盘
  36 + 'disk' => 'upload',
  37 + // 扩展名
  38 + 'ext' => [
  39 + 'png', 'jpg', 'jpeg', 'gif'
  40 + ],
  41 + // 目录
  42 + 'path' => '',
  43 + ];
  44 +
  45 + /**
  46 + * @param string|array $config
  47 + * @author:dc
  48 + * @time 2022/1/7 14:38
  49 + */
  50 + private function config($config = 'default')
  51 + {
  52 + if (is_array($config)) {
  53 + $driver = $config['driver'];
  54 + } else {
  55 + $driver = $config;
  56 + }
  57 +
  58 + // 加载配置
  59 + $this->config = $this->defaultConfig;
  60 + if ($driver != 'default') {
  61 + $conf = config('upload.' . $driver);
  62 + if ($conf) {
  63 + // 合并默认配置
  64 + $this->config = array_merge($this->config, $conf);
  65 + }
  66 + }
  67 +
  68 + // 追加目录
  69 + if ($config['path'] ?? '') {
  70 + $this->config['path'] = $this->config['path'] . (strpos($config['path'], '/') !== 0 ? '/' : '') . $config['path'];
  71 + }
  72 + }
  73 +
  74 + /**
  75 + *
  76 + * @param string $input_file
  77 + * @param string $config
  78 + * @return string
  79 + * @throws \Exception
  80 + * @author:dc
  81 + * @time 2021/12/30 16:37
  82 + */
  83 + public function put($input_file = "file", $config = 'default'): string
  84 + {
  85 + $this->config($config);
  86 +
  87 + if ($input_file instanceof UploadedFile) {
  88 + $file = &$input_file;
  89 + } else {
  90 + // 是否是已存在服务器的图片
  91 + if (Str::contains($input_file, env('APP_URL'))) {
  92 + return $input_file;
  93 + } else {
  94 + // 获取post上传文件
  95 + $file = request()->file($input_file);
  96 + // 如果不是上传,是否本地文件
  97 + if (!$file && is_file($input_file)) {
  98 + // 获取文件的名字
  99 + $origin_name = explode(DIRECTORY_SEPARATOR, $input_file);
  100 + !is_array($origin_name) && $origin_name = [$origin_name];
  101 + // 创建一个上传对象
  102 + $file = UploadedFile::createFromBase(new \Symfony\Component\HttpFoundation\File\UploadedFile($input_file, array_pop($origin_name)));
  103 + }
  104 + }
  105 +
  106 + }
  107 +
  108 + if ($file) {
  109 + // 验证扩展名
  110 + if (!in_array($file->extension(), $this->config['ext'])) {
  111 + $this->fail('文件扩展名不匹配,文件扩展名支持' . implode(',', $this->config['ext']));
  112 + }
  113 +
  114 + // 验证文件大小
  115 + if ($file->getSize() > $this->config['size']['max']) {
  116 + $this->fail('文件大小超出' . ($this->config['size']['max'] / 1024 / 1024) . 'M');
  117 + }
  118 +
  119 + //判断文件hash是否已存在
  120 + if ($filename = $this->getFileHash($file)) {
  121 + return $filename;
  122 + }
  123 +
  124 + $pathDate = date('Y-m');
  125 +
  126 + // 保存处理过的图片
  127 + if (!empty($img)) {
  128 + // 保存的图片名称
  129 + $save_name = $this->config['path'] . '/' . $pathDate . '/' . $file->hashName();
  130 + // 保存文件
  131 + if (!Storage::disk($this->config['disk'])
  132 + ->put($save_name, $img->getEncoded())) {
  133 + $save_name = '';
  134 + }
  135 + } else {
  136 + // 保存文件
  137 + $save_name = $file->storeAs($this->config['path'] . '/' . $pathDate, $file->hashName(), $this->config['disk']);
  138 + }
  139 +
  140 + if ($save_name) {
  141 + //保存文件hash
  142 + $this->setFileHash($file, $save_name);
  143 + // 返回地址
  144 + return $save_name;
  145 + }
  146 +
  147 + $this->fail( '上传失败');
  148 +
  149 + }
  150 + // 异常
  151 + $this->fail('请上传文件');
  152 + }
  153 +
  154 + /**
  155 + * 批量上传
  156 + * @param string $input_file
  157 + * @param string $config
  158 + * @return array
  159 + * @throws \Exception
  160 + * @author:dc
  161 + * @time 2021/12/30 16:36
  162 + */
  163 + public function puts($input_file = "file", $config = 'default'): array
  164 + {
  165 + $request = request();
  166 + $files = $request->post($input_file, []);
  167 + $files_ = $request->file($input_file);
  168 + if ($files_) {
  169 + $files = array_merge($files, $files_);
  170 + }
  171 + $filename = [];
  172 + if ($files instanceof UploadedFile) {
  173 + $filename[] = $this->put($files, $config);
  174 + } else if ($files) {
  175 + foreach ($files as $file) {
  176 + $filename[] = $this->put($file, $config);
  177 + }
  178 + } else {
  179 + // 异常
  180 + $this->fail('请上传文件');
  181 + }
  182 +
  183 + return $filename;
  184 + }
  185 +
  186 + /**
  187 + * 上传文件,文件内容
  188 + * @param string $filename
  189 + * @param string $content
  190 + * @param string $config
  191 + * @return string
  192 + * @throws \App\Exceptions\BsideGlobalException
  193 + * @author:dc
  194 + * @time 2022/1/7 14:45
  195 + */
  196 + public function filePut(string $filename, string $content, $config = 'default')
  197 + {
  198 + if ($content) {
  199 + $this->config($config);
  200 + $save_name = $this->config['path'] . '/' . $filename;
  201 + // 保存文件
  202 + $result = Storage::disk($this->config['disk'])->put($save_name, $content);
  203 +
  204 + if ($result) {
  205 + // 返回地址
  206 + return $save_name;
  207 + }
  208 +
  209 + $this->fail('上传失败');
  210 +
  211 + }
  212 + // 异常
  213 + $this->fail('请上传文件');
  214 + }
  215 +
  216 + /**
  217 + * 文件hash是否存在 存在返回文件路径
  218 + * @param $file
  219 + * @return mixed|string|null
  220 + */
  221 + protected function getFileHash($file)
  222 + {
  223 + $hash = FileEtag::sum($file)[0];
  224 + if (!$hash) {
  225 + return '';
  226 + }
  227 + return DB::table('gl_file_hash')->where('hash', $hash)->value('filename');
  228 + }
  229 +
  230 + /**
  231 + * 保存文件hash
  232 + * @param $file
  233 + * @param $save_path
  234 + * @return bool
  235 + */
  236 + protected function setFileHash($file, $save_path): bool
  237 + {
  238 + $hash = FileEtag::sum($file)[0];
  239 +
  240 + if (!$hash) {
  241 + return false;
  242 + }
  243 + $data = [
  244 + 'filename' => $save_path,
  245 + 'hash' => $hash,
  246 + ];
  247 + DB::table('gl_file_hash')->insert($data);
  248 + return true;
  249 + }
  250 +
  251 + /**
  252 + * 文件地址转本地路径
  253 + * @param $url
  254 + * @return array|string|string[]
  255 + * @author zbj
  256 + * @date 2023/4/20
  257 + */
  258 + public function url2path($url){
  259 + $upload_url = config('filesystems')['disks'][$this->config['disk']]['url'];
  260 + return str_replace($upload_url . '/', '', $url);
  261 + }
  262 +
  263 + /**
  264 + * 本地路径转链接
  265 + * @param $path
  266 + * @return string
  267 + * @author zbj
  268 + * @date 2023/4/20
  269 + */
  270 + public function path2url($path){
  271 + return Storage::disk($this->config['disk'])->url($path);
  272 + }
  273 +}
@@ -2,6 +2,7 @@ @@ -2,6 +2,7 @@
2 namespace App\Utils; 2 namespace App\Utils;
3 3
4 use App\Enums\Common\Common; 4 use App\Enums\Common\Common;
  5 +use App\Helper\Arr;
5 use Illuminate\Support\Facades\Log; 6 use Illuminate\Support\Facades\Log;
6 use Illuminate\Support\Facades\Route; 7 use Illuminate\Support\Facades\Route;
7 8
@@ -17,7 +18,12 @@ class LogUtils @@ -17,7 +18,12 @@ class LogUtils
17 public static function error($title, $params = [], $response = []) 18 public static function error($title, $params = [], $response = [])
18 { 19 {
19 $route=Route::current(); 20 $route=Route::current();
20 - $side=$route->action['prefix']??Common::A; 21 + if(!empty($route->action['prefix'])){
  22 + $prefix = Arr::splitFilterToArray($route->action['prefix'], 'trim', '/');
  23 + $side = $prefix[0];
  24 + }else{
  25 + $side = Common::A;
  26 + }
21 $params = is_array($params) ? json_encode($params, JSON_UNESCAPED_UNICODE) : $params; 27 $params = is_array($params) ? json_encode($params, JSON_UNESCAPED_UNICODE) : $params;
22 $response = is_array($response) || is_object($response) ? json_encode($response, JSON_UNESCAPED_UNICODE) : $response; 28 $response = is_array($response) || is_object($response) ? json_encode($response, JSON_UNESCAPED_UNICODE) : $response;
23 Log::channel($side.'side')->error("$title::请求参数:$params--------响应:$response"); 29 Log::channel($side.'side')->error("$title::请求参数:$params--------响应:$response");
@@ -33,7 +39,12 @@ class LogUtils @@ -33,7 +39,12 @@ class LogUtils
33 public static function info($title, $params = [], $response = []) 39 public static function info($title, $params = [], $response = [])
34 { 40 {
35 $route=Route::current(); 41 $route=Route::current();
36 - $side=$route->action['prefix']??Common::A; 42 + if(!empty($route->action['prefix'])){
  43 + $prefix = Arr::splitFilterToArray($route->action['prefix'], 'trim', '/');
  44 + $side = $prefix[0];
  45 + }else{
  46 + $side = Common::A;
  47 + }
37 $params = is_array($params) ? json_encode($params, JSON_UNESCAPED_UNICODE) : $params; 48 $params = is_array($params) ? json_encode($params, JSON_UNESCAPED_UNICODE) : $params;
38 $response = is_array($response) || is_object($response) ? json_encode($response, JSON_UNESCAPED_UNICODE) : $response; 49 $response = is_array($response) || is_object($response) ? json_encode($response, JSON_UNESCAPED_UNICODE) : $response;
39 Log::channel($side.'side')->info("$title::请求参数:$params--------响应:$response"); 50 Log::channel($side.'side')->info("$title::请求参数:$params--------响应:$response");
1 -#!/usr/bin/env php  
2 -<?php  
3 -  
4 -define('LARAVEL_START', microtime(true));  
5 -  
6 -/*  
7 -|--------------------------------------------------------------------------  
8 -| Register The Auto Loader  
9 -|--------------------------------------------------------------------------  
10 -|  
11 -| Composer provides a convenient, automatically generated class loader  
12 -| for our application. We just need to utilize it! We'll require it  
13 -| into the script here so that we do not have to worry about the  
14 -| loading of any of our classes manually. It's great to relax.  
15 -|  
16 -*/  
17 -  
18 -require __DIR__.'/vendor/autoload.php';  
19 -  
20 -$app = require_once __DIR__.'/bootstrap/app.php';  
21 -  
22 -/*  
23 -|--------------------------------------------------------------------------  
24 -| Run The Artisan Application  
25 -|--------------------------------------------------------------------------  
26 -|  
27 -| When we run the console application, the current CLI command will be  
28 -| executed in this console and the response sent back to a terminal  
29 -| or another output device for the developers. Here goes nothing!  
30 -|  
31 -*/  
32 -  
33 -$kernel = $app->make(Illuminate\Contracts\Console\Kernel::class);  
34 -  
35 -$status = $kernel->handle(  
36 - $input = new Symfony\Component\Console\Input\ArgvInput,  
37 - new Symfony\Component\Console\Output\ConsoleOutput  
38 -);  
39 -  
40 -/*  
41 -|--------------------------------------------------------------------------  
42 -| Shutdown The Application  
43 -|--------------------------------------------------------------------------  
44 -|  
45 -| Once Artisan has finished running, we will fire off the shutdown events  
46 -| so that any final work may be done by the application before we shut  
47 -| down the process. This is the last thing to happen to the request.  
48 -|  
49 -*/  
50 -  
51 -$kernel->terminate($input, $status);  
52 -  
53 -exit($status);  
@@ -10,6 +10,7 @@ @@ -10,6 +10,7 @@
10 "doctrine/dbal": "^3.6", 10 "doctrine/dbal": "^3.6",
11 "fruitcake/laravel-cors": "^2.0", 11 "fruitcake/laravel-cors": "^2.0",
12 "guzzlehttp/guzzle": "^7.0.1", 12 "guzzlehttp/guzzle": "^7.0.1",
  13 + "intervention/image": "^2.7",
13 "laravel/framework": "^8.75", 14 "laravel/framework": "^8.75",
14 "laravel/sanctum": "^2.11", 15 "laravel/sanctum": "^2.11",
15 "laravel/tinker": "^2.5" 16 "laravel/tinker": "^2.5"
此 diff 太大无法显示。
@@ -174,6 +174,7 @@ return [ @@ -174,6 +174,7 @@ return [
174 // App\Providers\BroadcastServiceProvider::class, 174 // App\Providers\BroadcastServiceProvider::class,
175 App\Providers\EventServiceProvider::class, 175 App\Providers\EventServiceProvider::class,
176 App\Providers\RouteServiceProvider::class, 176 App\Providers\RouteServiceProvider::class,
  177 +// Intervention\Image\ImageServiceProvider::class,
177 178
178 ], 179 ],
179 180
@@ -229,7 +230,7 @@ return [ @@ -229,7 +230,7 @@ return [
229 'URL' => Illuminate\Support\Facades\URL::class, 230 'URL' => Illuminate\Support\Facades\URL::class,
230 'Validator' => Illuminate\Support\Facades\Validator::class, 231 'Validator' => Illuminate\Support\Facades\Validator::class,
231 'View' => Illuminate\Support\Facades\View::class, 232 'View' => Illuminate\Support\Facades\View::class,
232 - 233 +// 'Image'=>Intervention\Image\ImageManagerStatic::class,
233 ], 234 ],
234 235
235 ]; 236 ];
@@ -53,6 +53,13 @@ return [ @@ -53,6 +53,13 @@ return [
53 'use_path_style_endpoint' => env('AWS_USE_PATH_STYLE_ENDPOINT', false), 53 'use_path_style_endpoint' => env('AWS_USE_PATH_STYLE_ENDPOINT', false),
54 ], 54 ],
55 55
  56 + 'upload' => [
  57 + 'driver' => 'local',
  58 + 'root' => env('UPLOAD_ROOT_PATH') ?: public_path('upload'),
  59 + 'url' => env('UPLOAD_LOCAL_URL') ?: env('APP_URL') . '/upload',
  60 + 'visibility' => 'public',
  61 + ]
  62 +
56 ], 63 ],
57 64
58 /* 65 /*
  1 +<?php
  2 +
  3 +/**
  4 + * 上传配置
  5 + * 如果其他配置没有设置某一项则使用default的
  6 + * 默认配置见下
  7 + * @see \App\Services\UploadService::$config
  8 + */
  9 +return [
  10 + // 产品图集
  11 + 'product' => [
  12 + 'size' => [
  13 + 'max' => 1024*1024*2, // 2M
  14 + ],
  15 + 'path' => '/product'
  16 + ],
  17 +];
  1 +<form method="post" action="">
  2 + @csrf
  3 + <input type="text" name="mobile" value="15680871314">
  4 + <input type="text" name="password" value="123456">
  5 + <input type="submit">
  6 +</form>
  1 +{{--@extends('admin.app')--}}
  2 +
  3 +{{--@section('content')--}}
  4 +
  5 + <div id="content" class="main-content">
  6 + <div style="text-align: center;font-size: 40px;color: #afafaf;padding: 100px 0;">
  7 + 无权限
  8 + </div>
  9 + </div>
  10 +
  11 +{{--@endsection--}}
  12 +
  13 +
  14 +{{--@section('script')--}}
  15 +
  16 +{{--@endsection--}}
@@ -5,12 +5,49 @@ @@ -5,12 +5,49 @@
5 use \Illuminate\Support\Facades\Route; 5 use \Illuminate\Support\Facades\Route;
6 use \App\Http\Controllers\Aside; 6 use \App\Http\Controllers\Aside;
7 //必须登录验证的路由组 7 //必须登录验证的路由组
8 -Route::middleware(['aloginauth'])->group(function ($route) { 8 +Route::middleware(['web'])->group(function (){ //admin用渲染默认要加上web的中间件
  9 + Route::middleware(['aloginauth'])->group(function () {
  10 + Route::get('/', [Aside\IndexController::class, 'index'])->name('admin.home.white');
  11 + Route::get('/logout', [Aside\LoginController::class, 'logout'])->name('admin.logout.white');
9 12
10 -}); 13 + //管理员
  14 + Route::prefix('manage')->group(function () {
  15 + Route::get('/', [Aside\Manage\ManageController::class, 'list'])->name('admin.manage');
  16 + Route::get('/info', [Aside\Manage\ManageController::class, 'info'])->name('admin.manage_info');
  17 + Route::post('/save', [Aside\Manage\ManageController::class, 'save'])->name('admin.manage_save');
  18 + Route::any('/delete', [Aside\Manage\ManageController::class, 'delete'])->name('admin.manage_delete');
  19 +
  20 + //菜单
  21 + Route::prefix('menu')->group(function () {
  22 + Route::get('/', [Aside\Manage\MenuController::class, 'list'])->name('admin.menu');
  23 + Route::get('/info', [Aside\Manage\MenuController::class, 'info'])->name('admin.menu_info');
  24 + Route::post('/save', [Aside\Manage\MenuController::class, 'save'])->name('admin.menu_save');
  25 + Route::any('/delete', [Aside\Manage\MenuController::class, 'delete'])->name('admin.menu_delete');
  26 + });
  27 +
  28 + //权限组
  29 + Route::prefix('group')->group(function () {
  30 + Route::get('/', [Aside\Manage\GroupController::class, 'list'])->name('admin.group');
  31 + Route::get('/info', [Aside\Manage\GroupController::class, 'info'])->name('admin.group_info');
  32 + Route::post('/save', [Aside\Manage\GroupController::class, 'save'])->name('admin.group_save');
  33 + Route::any('/delete', [Aside\Manage\GroupController::class, 'delete'])->name('admin.group_delete');
  34 + });
  35 +
  36 + //部门
  37 + Route::prefix('dept')->group(function () {
  38 + Route::get('/', [Aside\Manage\DeptController::class, 'list'])->name('admin.dept');
  39 + Route::get('/info', [Aside\Manage\DeptController::class, 'info'])->name('admin.dept_info');
  40 + Route::post('/save', [Aside\Manage\DeptController::class, 'save'])->name('admin.dept_save');
  41 + Route::any('/delete', [Aside\Manage\DeptController::class, 'delete'])->name('admin.dept_delete');
  42 + });
  43 + });
  44 +
  45 +
  46 + });
11 47
12 //无需登录验证的路由组 48 //无需登录验证的路由组
13 -Route::group([], function ($route) {  
14 - //demo  
15 - $route->post('/demo', [Aside\DemoController::class, 'test']); 49 + Route::group([], function () {
  50 + Route::any('/login', [Aside\LoginController::class, 'login'])->name('admin.login.white');
  51 + });
16 }); 52 });
  53 +
@@ -2,7 +2,8 @@ @@ -2,7 +2,8 @@
2 /** 2 /**
3 * B端用户路由文件 3 * B端用户路由文件
4 */ 4 */
5 -use \Illuminate\Support\Facades\Route; 5 +
  6 +use Illuminate\Support\Facades\Route;
6 7
7 //必须登录验证的路由组 8 //必须登录验证的路由组
8 Route::middleware(['bloginauth'])->group(function () { 9 Route::middleware(['bloginauth'])->group(function () {
@@ -13,26 +14,101 @@ Route::middleware(['bloginauth'])->group(function () { @@ -13,26 +14,101 @@ Route::middleware(['bloginauth'])->group(function () {
13 Route::any('/get_menu', [\App\Http\Controllers\Bside\ComController::class, 'get_menu'])->name('get_menu'); 14 Route::any('/get_menu', [\App\Http\Controllers\Bside\ComController::class, 'get_menu'])->name('get_menu');
14 //获取当前登录用户项目详情 15 //获取当前登录用户项目详情
15 Route::any('/get_project', [\App\Http\Controllers\Bside\ComController::class, 'get_project'])->name('get_project'); 16 Route::any('/get_project', [\App\Http\Controllers\Bside\ComController::class, 'get_project'])->name('get_project');
  17 + //消息通知列表
  18 + Route::any('/notice/', [\App\Http\Controllers\Bside\NoticeController::class, 'lists'])->name('notice_lists');
16 //用户相关路由 19 //用户相关路由
17 - Route::any('/user/add', [\App\Http\Controllers\Bside\UserController::class, 'add'])->name('user_add');  
18 - Route::any('/user/edit', [\App\Http\Controllers\Bside\UserController::class, 'edit'])->name('user_edit');  
19 - Route::any('/user/status', [\App\Http\Controllers\Bside\UserController::class, 'status'])->name('user_status');  
20 - Route::any('/user/lists', [\App\Http\Controllers\Bside\UserController::class, 'lists'])->name('user_lists');  
21 - Route::any('/user/del', [\App\Http\Controllers\Bside\UserController::class, 'del'])->name('user_del'); 20 + Route::prefix('user')->group(function () {
  21 + Route::any('/', [\App\Http\Controllers\Bside\UserController::class, 'lists'])->name('user_lists');
  22 + Route::any('/add', [\App\Http\Controllers\Bside\UserController::class, 'add'])->name('user_add');
  23 + Route::any('/edit', [\App\Http\Controllers\Bside\UserController::class, 'edit'])->name('user_edit');
  24 + Route::any('/status', [\App\Http\Controllers\Bside\UserController::class, 'status'])->name('user_status');
  25 + Route::any('/info', [\App\Http\Controllers\Bside\UserController::class, 'info'])->name('user_info');
  26 + Route::any('/del', [\App\Http\Controllers\Bside\UserController::class, 'del'])->name('user_del');
  27 + });
  28 +
  29 + //站内信
  30 + Route::prefix('mail')->group(function () {
  31 + Route::any('/', [\App\Http\Controllers\Bside\MailController::class, 'lists'])->name('mail_lists');
  32 + Route::any('/info', [\App\Http\Controllers\Bside\MailController::class, 'info'])->name('mail_info');
  33 + });
  34 +
22 //用户角色相关路由 35 //用户角色相关路由
23 - Route::any('/project_role/lists', [\App\Http\Controllers\Bside\ProjectRoleController::class, 'lists'])->name('project_role_lists');  
24 - Route::any('/project_role/get_role_menu', [\App\Http\Controllers\Bside\ProjectRoleController::class, 'get_role_menu'])->name('project_get_role_add');  
25 - Route::any('/project_role/add', [\App\Http\Controllers\Bside\ProjectRoleController::class, 'add'])->name('project_role_add');  
26 - Route::any('/project_role/edit', [\App\Http\Controllers\Bside\ProjectRoleController::class, 'edit'])->name('project_role_edit');  
27 - Route::any('/project_role/status', [\App\Http\Controllers\Bside\ProjectRoleController::class, 'status'])->name('project_role_status');  
28 - Route::any('/project_role/del', [\App\Http\Controllers\Bside\ProjectRoleController::class, 'del'])->name('project_role_del');  
29 -  
30 - //group相关路由  
31 - Route::any('/project_group/add', [\App\Http\Controllers\Bside\ProjectGroupController::class, 'add'])->name('project_group_add');  
32 - Route::any('/project_group/edit', [\App\Http\Controllers\Bside\ProjectGroupController::class, 'edit'])->name('project_group_edit');  
33 - Route::any('/project_group/status', [\App\Http\Controllers\Bside\ProjectGroupController::class, 'status'])->name('project_group_status');  
34 - Route::any('/project_group/lists', [\App\Http\Controllers\Bside\ProjectGroupController::class, 'lists'])->name('project_group_lists');  
35 - Route::any('/project_group/del', [\App\Http\Controllers\Bside\ProjectGroupController::class, 'del'])->name('project_group_del'); 36 + Route::prefix('role')->group(function () {
  37 + Route::any('/', [\App\Http\Controllers\Bside\ProjectRoleController::class, 'lists'])->name('project_role_lists');
  38 + Route::any('/get_role_menu', [\App\Http\Controllers\Bside\ProjectRoleController::class, 'get_role_menu'])->name('project_get_role_add');
  39 + Route::any('/add', [\App\Http\Controllers\Bside\ProjectRoleController::class, 'add'])->name('project_role_add');
  40 + Route::any('/edit', [\App\Http\Controllers\Bside\ProjectRoleController::class, 'edit'])->name('project_role_edit');
  41 + Route::any('/info', [\App\Http\Controllers\Bside\ProjectRoleController::class, 'status'])->name('project_role_info');
  42 + Route::any('/status', [\App\Http\Controllers\Bside\ProjectRoleController::class, 'status'])->name('project_role_status');
  43 + Route::any('/del', [\App\Http\Controllers\Bside\ProjectRoleController::class, 'del'])->name('project_role_del');
  44 + Route::any('/get_user_list', [\App\Http\Controllers\Bside\ProjectRoleController::class, 'get_user_list'])->name('project_role_get_user_list');
  45 + });
  46 +
  47 + //group相关路
  48 + Route::prefix('group')->group(function () {
  49 + Route::any('/', [\App\Http\Controllers\Bside\ProjectGroupController::class, 'lists'])->name('project_group_lists');
  50 + Route::any('/add', [\App\Http\Controllers\Bside\ProjectGroupController::class, 'add'])->name('project_group_add');
  51 + Route::any('/edit', [\App\Http\Controllers\Bside\ProjectGroupController::class, 'edit'])->name('project_group_edit');
  52 + Route::any('/info', [\App\Http\Controllers\Bside\ProjectGroupController::class, 'info'])->name('project_group_info');
  53 + Route::any('/del', [\App\Http\Controllers\Bside\ProjectGroupController::class, 'del'])->name('project_group_del');
  54 + Route::any('/get_user_lists', [\App\Http\Controllers\Bside\ProjectGroupController::class, 'get_user_lists'])->name('project_group_get_user_lists');
  55 + });
  56 +
  57 + //新闻相关路由
  58 + Route::prefix('news')->group(function () {
  59 + //分类
  60 + Route::any('/category/', [\App\Http\Controllers\Bside\News\NewsCategoryController::class, 'lists'])->name('news_category_lists');
  61 + Route::any('/category/add', [\App\Http\Controllers\Bside\News\NewsCategoryController::class, 'add'])->name('news_category_add');
  62 + Route::any('/category/info', [\App\Http\Controllers\Bside\News\NewsCategoryController::class, 'info'])->name('news_category_info');
  63 + Route::any('/category/edit', [\App\Http\Controllers\Bside\News\NewsCategoryController::class, 'edit'])->name('news_category_edit');
  64 + Route::any('/category/del', [\App\Http\Controllers\Bside\News\NewsCategoryController::class, 'del'])->name('news_category_del');
  65 + Route::any('/category/status', [\App\Http\Controllers\Bside\News\NewsCategoryController::class, 'status'])->name('news_category_status');
  66 +
  67 + //新闻
  68 + Route::any('/', [\App\Http\Controllers\Bside\News\NewsController::class, 'lists'])->name('news_category_lists');
  69 + Route::any('/get_category_list', [\App\Http\Controllers\Bside\News\NewsController::class, 'get_category_list'])->name('news_get_category_list');
  70 + Route::any('/add', [\App\Http\Controllers\Bside\News\NewsController::class, 'add'])->name('news_add');
  71 + Route::any('/info', [\App\Http\Controllers\Bside\News\NewsController::class, 'info'])->name('news_info');
  72 + Route::any('/edit', [\App\Http\Controllers\Bside\News\NewsController::class, 'edit'])->name('news_edit');
  73 + Route::any('/del', [\App\Http\Controllers\Bside\News\NewsController::class, 'del'])->name('news_del');
  74 + Route::any('/status', [\App\Http\Controllers\Bside\News\NewsController::class, 'status'])->name('news_status');
  75 + });
  76 +
  77 + //博客相关路由
  78 + Route::prefix('blog')->group(function () {
  79 + //分类
  80 + Route::any('/category/', [\App\Http\Controllers\Bside\Blog\BlogCategoryController::class, 'lists'])->name('blog_category_lists');
  81 + Route::any('/category/add', [\App\Http\Controllers\Bside\Blog\BlogCategoryController::class, 'add'])->name('blog_category_add');
  82 + Route::any('/category/info', [\App\Http\Controllers\Bside\Blog\BlogCategoryController::class, 'info'])->name('blog_category_info');
  83 + Route::any('/category/edit', [\App\Http\Controllers\Bside\Blog\BlogCategoryController::class, 'edit'])->name('blog_category_edit');
  84 + Route::any('/category/del', [\App\Http\Controllers\Bside\Blog\BlogCategoryController::class, 'del'])->name('blog_category_del');
  85 + Route::any('/category/status', [\App\Http\Controllers\Bside\Blog\BlogCategoryController::class, 'status'])->name('blog_category_status');
  86 +
  87 + //博客
  88 + Route::any('/', [\App\Http\Controllers\Bside\Blog\BlogController::class, 'lists'])->name('blog_lists');
  89 + Route::any('/add', [\App\Http\Controllers\Bside\Blog\BlogController::class, 'add'])->name('blog_add');
  90 + Route::any('/info', [\App\Http\Controllers\Bside\Blog\BlogController::class, 'info'])->name('blog_info');
  91 + Route::any('/edit', [\App\Http\Controllers\Bside\Blog\BlogController::class, 'edit'])->name('blog_edit');
  92 + Route::any('/del', [\App\Http\Controllers\Bside\Blog\BlogController::class, 'del'])->name('blog_del');
  93 + Route::any('/status', [\App\Http\Controllers\Bside\Blog\BlogController::class, 'status'])->name('blog_status');
  94 +
  95 + //博客标签
  96 + Route::any('/label/', [\App\Http\Controllers\Bside\Blog\BlogLabelController::class, 'lists'])->name('blog_lists');
  97 + Route::any('/label/add', [\App\Http\Controllers\Bside\Blog\BlogLabelController::class, 'add'])->name('blog_add');
  98 + Route::any('/label/info', [\App\Http\Controllers\Bside\Blog\BlogLabelController::class, 'info'])->name('blog_info');
  99 + Route::any('/label/edit', [\App\Http\Controllers\Bside\Blog\BlogLabelController::class, 'edit'])->name('blog_edit');
  100 + Route::any('/label/del', [\App\Http\Controllers\Bside\Blog\BlogLabelController::class, 'del'])->name('blog_del');
  101 + Route::any('/label/status', [\App\Http\Controllers\Bside\Blog\BlogLabelController::class, 'status'])->name('blog_status');
  102 + });
  103 + //ai指令
  104 + Route::prefix('command')->group(function () {
  105 + //公用ai自动生成
  106 + Route::any('/ai_http_post', [\App\Http\Controllers\Bside\AiCommandController::class, 'ai_http_post'])->name('ai_http_post');
  107 + //新闻自动生成
  108 + Route::any('/ai_news', [\App\Http\Controllers\Bside\News\NewsController::class, 'ai_news'])->name('ai_news');
  109 + //博客自动生成
  110 + Route::any('/ai_blog', [\App\Http\Controllers\Bside\Blog\BlogController::class, 'ai_blog'])->name('ai_blog');
  111 + });
36 112
37 //产品 113 //产品
38 Route::prefix('product')->group(function () { 114 Route::prefix('product')->group(function () {
@@ -66,11 +142,27 @@ Route::middleware(['bloginauth'])->group(function () { @@ -66,11 +142,27 @@ Route::middleware(['bloginauth'])->group(function () {
66 Route::post('describe/save', [\App\Http\Controllers\Bside\Product\DescribeController::class, 'save'])->name('product_describe_save'); 142 Route::post('describe/save', [\App\Http\Controllers\Bside\Product\DescribeController::class, 'save'])->name('product_describe_save');
67 Route::any('describe/delete', [\App\Http\Controllers\Bside\Product\DescribeController::class, 'delete'])->name('product_describe_delete'); 143 Route::any('describe/delete', [\App\Http\Controllers\Bside\Product\DescribeController::class, 'delete'])->name('product_describe_delete');
68 }); 144 });
  145 +
  146 + //组织架构
  147 + Route::prefix('dept')->group(function () {
  148 + Route::get('/', [\App\Http\Controllers\Bside\DeptController::class, 'index'])->name('dept');
  149 + Route::get('/info', [\App\Http\Controllers\Bside\DeptController::class, 'info'])->name('dept_info');
  150 + Route::post('/save', [\App\Http\Controllers\Bside\DeptController::class, 'save'])->name('dept_save');
  151 + Route::any('/delete', [\App\Http\Controllers\Bside\DeptController::class, 'delete'])->name('dept_delete');
  152 + });
  153 +
  154 + //文件操作
  155 + Route::prefix('file')->group(function () {
  156 + Route::post('/upload', [\App\Http\Controllers\Bside\FileController::class, 'upload'])->name('file_upload');
  157 + });
  158 + Route::prefix('images')->group(function () {
  159 + Route::post('/upload', [\App\Http\Controllers\ImageController::class, 'upload'])->name('image_upload');
  160 + });
69 }); 161 });
70 162
71 //无需登录验证的路由组 163 //无需登录验证的路由组
72 Route::group([], function () { 164 Route::group([], function () {
73 Route::any('/login', [\App\Http\Controllers\Bside\ComController::class, 'login'])->name('login'); 165 Route::any('/login', [\App\Http\Controllers\Bside\ComController::class, 'login'])->name('login');
74 -  
75 - 166 + Route::get('/file/download', [\App\Http\Controllers\Bside\FileController::class, 'download'])->name('file_download');
  167 + Route::get('/image/{hash}/{w}/{h}', [\App\Http\Controllers\ImageController::class,'index'])->name('image_show');
76 }); 168 });