正在显示
65 个修改的文件
包含
3368 行增加
和
805 行删除
.env.test
已删除
100644 → 0
| 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}" |
| 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 { |
app/Files/Image.php
已删除
100644 → 0
| 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 | } |
app/Helper/FileEtag.php
0 → 100644
| 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); | 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 | + } | ||
| 150 | } | 154 | } |
| 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; | 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\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); | 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); | ||
| 156 | } | 182 | } |
| 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; | 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 | /** |
| 31 | + * @name :根据角色获取会员列表 | ||
| 32 | + * @return void | ||
| 33 | + * @author :liyuhang | ||
| 34 | + * @method | ||
| 35 | + */ | ||
| 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); | ||
| 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); | ||
| 55 | + } | ||
| 56 | + /** | ||
| 32 | * @name :添加/编辑角色时获取菜单列表 | 57 | * @name :添加/编辑角色时获取菜单列表 |
| 33 | * @return void | 58 | * @return void |
| 34 | * @author :liyuhang | 59 | * @author :liyuhang |
| 35 | * @method | 60 | * @method |
| 36 | */ | 61 | */ |
| 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; | ||
| 51 | - } | ||
| 52 | - } | 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 | + | ||
| 73 | + /** | ||
| 74 | + * @name :详情 | ||
| 75 | + * @return json | ||
| 76 | + * @author :liyuhang | ||
| 77 | + * @method | ||
| 78 | + */ | ||
| 79 | + public function info(Request $request,UserLogic $userLogic){ | ||
| 80 | + $request->validate([ | ||
| 81 | + 'id'=>['required'], | ||
| 82 | + ],[ | ||
| 83 | + 'id.required' => 'ID不能为空', | ||
| 84 | + ]); | ||
| 85 | + $userLogic->user_info(); | ||
| 86 | + $this->response('success'); | ||
| 87 | + } | ||
| 93 | /** | 88 | /** |
| 94 | * @name :删除管理员 | 89 | * @name :删除管理员 |
| 95 | - * @return void | 90 | + * @return json |
| 96 | * @author :liyuhang | 91 | * @author :liyuhang |
| 97 | * @method | 92 | * @method |
| 98 | */ | 93 | */ |
| 99 | - public function del(Request $request){ | 94 | + public function del(Request $request,UserLogic $userLogic){ |
| 100 | $request->validate([ | 95 | $request->validate([ |
| 101 | - 'id'=>['required', new Ids()], | 96 | + 'id'=>['required'], |
| 102 | ],[ | 97 | ],[ |
| 103 | 'id.required' => 'ID不能为空', | 98 | 'id.required' => 'ID不能为空', |
| 104 | ]); | 99 | ]); |
| 105 | - $userModel = new UserModel(); | ||
| 106 | - $rs = $userModel->del($this->param); | ||
| 107 | - if($rs === false){ | ||
| 108 | - $this->response('删除失败',Code::USER_ERROR); | ||
| 109 | - } | ||
| 110 | - $this->response('删除成功'); | 100 | + $userLogic->user_del(); |
| 101 | + $this->response('success'); | ||
| 111 | } | 102 | } |
| 112 | } | 103 | } |
app/Http/Controllers/ImageController.php
0 → 100644
| 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 | - public function __construct() | ||
| 17 | - { | ||
| 18 | - $this->requestAll=request()->all(); | ||
| 19 | - } | 16 | + protected $requestAll; |
| 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 | } |
app/Http/Logic/Aside/DeptLogic.php
0 → 100644
| 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 | +} |
app/Http/Logic/Aside/GroupLogic.php
0 → 100644
| 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 | +} |
app/Http/Logic/Aside/LoginLogic.php
0 → 100644
| 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 | +} |
app/Http/Logic/Aside/ManageLogic.php
0 → 100644
| 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 | +} |
app/Http/Logic/Aside/MenuLogic.php
0 → 100644
| 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 | +} |
app/Http/Logic/Aside/ProjectLogic.php
0 → 100644
app/Http/Logic/Aside/ProjectRoleLogic.php
0 → 100644
| 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 | +} |
app/Http/Logic/Aside/UserLogic.php
0 → 100644
| @@ -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 | - | ||
| 26 | - /** | ||
| 27 | - * @notes: 请简要描述方法功能 | ||
| 28 | - * @param array $data | ||
| 29 | - * @return array | ||
| 30 | - */ | ||
| 31 | - public function success(array $data = []) | ||
| 32 | - { | ||
| 33 | - return $data; | ||
| 34 | - } | ||
| 35 | 27 | ||
| 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 | +} |
app/Http/Logic/Bside/Blog/BlogLabelLogic.php
0 → 100644
| 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 | +} |
app/Http/Logic/Bside/Blog/BlogLogic.php
0 → 100644
| 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 | +} |
app/Http/Logic/Bside/DeptLogic.php
0 → 100644
| 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 | +} |
app/Http/Logic/Bside/GroupLogic.php
0 → 100644
app/Http/Logic/Bside/MailLogic.php
0 → 100644
| 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 | +} |
app/Http/Logic/Bside/News/NewsLogic.php
0 → 100644
| 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 | - } | 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('保存失败'); | ||
| 33 | } | 38 | } |
| 34 | - return parent::save($param); | 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'); |
| 39 | - 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']}存在子分类,不能删除"); | 44 | + |
| 45 | + DB::beginTransaction(); | ||
| 46 | + try { | ||
| 47 | + parent::delete($ids); | ||
| 48 | + | ||
| 49 | + foreach ($ids as $id){ | ||
| 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 | } |
app/Http/Logic/Bside/RoleLogic.php
0 → 100644
| 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 | +} |
app/Http/Logic/Bside/UserLogic.php
0 → 100644
| 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 | +} |
-
请 注册 或 登录 后发表评论