作者 liyuhang

gx

... ... @@ -10,6 +10,7 @@ use App\Utils\LogUtils;
use Illuminate\Database\Eloquent\ModelNotFoundException;
use Illuminate\Foundation\Exceptions\Handler as ExceptionHandler;
use Illuminate\Support\Arr;
use Illuminate\Support\Facades\Cache;
use Illuminate\Support\Facades\Route;
use Illuminate\Validation\ValidationException;
use Symfony\Component\HttpKernel\Exception\MethodNotAllowedHttpException;
... ... @@ -128,10 +129,18 @@ class Handler extends ExceptionHandler
$exception->getLine();
(new DingService())->handle(['keyword' => "ERROR", 'msg' => config('app.env') . '环境报错:' . $exceptionMessage, 'isAtAll' => false]);
}
$log = config('logging.operator_log');
if(isset($log,$log['log'],$log['action']) && $log['log'] == true){
if(empty($log['action']) || (strpos($log['action'],Route::currentRouteName()) < 0)){
$info = Cache::get($request->header('token'));
if(!empty($info)){
\App\Helper\Common::set_user_log(['model'=>Route::currentRouteName(),'remark'=>'请求的参数:param = '.json_encode($request->all()),'operator_id'=>$info['id']]);
}
}
}
//开启debug 错误原样输出
$debub = config('app.debug');
$message = $debub ? $message : ($code->description ?? $message);
$response = [
'code' => $code,
'message' => $message
... ...
<?php
namespace App\Helper;
use App\Enums\Common\Code;
use App\Models\AiCommand as AiCommandModel;
use App\Models\User\UserLog as UserLogModel;
use App\Models\User\UserLogin as UserLoginModel;
class Common
{
/**
* @name :生成用户操作日志
* @return void
* @author :liyuhang
* @method
*/
public static function set_user_log($param = []){
$data = [
'operator_id'=>$param['operator_id'],
'model'=>$param['model'],
'remark'=>$param['remark']
];
$model = new UserLogModel();
return $model->add($data);
}
/**
* @name :写入登录日志
* @return void
* @author :liyuhang
* @method
*/
public static function set_user_login($param = []){
$data = [
'user_id'=>$param['id'],
'ip'=>$param['ip']
];
$model = new UserLoginModel();
return $model->add($data);
}
/**
* @name :ai自动生成
* @return mixed
* @author :liyuhang
* @method
*/
public function send_openai_msg($url){
$url = HTTP_OPENAI_URL.$url;
$aiCommandModel = New AiCommandModel();
//指定库获取指令
$info = $aiCommandModel->read(['key'=>$this->param['key']]);
if($info === false){
response('指令不存在',400);
}
//替换关键字
$content = str_replace('$keyword$', $this->param['keywords'], $info['ai']);
$data = [
'messages'=>[
['role'=>'system','content'=>$info['scene']],
['role'=>'assistant','content'=>$content],
]
];
return http_post($url,json_encode($data));
}
}
... ...
... ... @@ -4,8 +4,11 @@ namespace App\Http\Controllers\Aside\User;
use App\Enums\Common\Code;
use App\Http\Controllers\Aside\BaseController;
use App\Http\Logic\Aside\User\ProjectMenuLogic;
use App\Http\Requests\Aside\User\ProjectRoleRequest;
use App\Models\User\ProjectMenu;
use App\Models\User\ProjectMenu as ProjectMenuModel;
use Illuminate\Http\Request;
class ProjectMenuController extends BaseController
{
... ... @@ -27,12 +30,14 @@ class ProjectMenuController extends BaseController
* @author :liyuhang
* @method
*/
public function info(ProjectRoleRequest $request){
public function info(Request $request,ProjectMenuLogic $projectMenuLogic){
$request->validate([
'id'=>'required'
],[
'id.required' => 'ID不能为空'
]);
$info = $projectMenuLogic->menu_info();
$this->response('success',Code::SUCCESS,$info);
}
/**
... ... @@ -41,8 +46,10 @@ class ProjectMenuController extends BaseController
* @author :liyuhang
* @method
*/
public function add(){
public function add(ProjectRoleRequest $request,ProjectMenuLogic $projectMenuLogic){
$request->validated();
$projectMenuLogic->menu_add();
$this->response('success');
}
/**
... ... @@ -51,8 +58,14 @@ class ProjectMenuController extends BaseController
* @author :liyuhang
* @method
*/
public function edit(){
public function edit(ProjectRoleRequest $request,ProjectMenuLogic $projectMenuLogic){
$request->validate([
'id'=>'required'
],[
'id.required' => 'ID不能为空'
]);
$projectMenuLogic->menu_edit();
$this->response('success');
}
/**
... ... @@ -61,7 +74,13 @@ class ProjectMenuController extends BaseController
* @author :liyuhang
* @method
*/
public function del(){
public function del(Request $request,ProjectMenuLogic $projectMenuLogic){
$request->validate([
'id'=>'required'
],[
'id.required' => 'ID不能为空'
]);
$projectMenuLogic->menu_del();
$this->response('success');
}
}
... ...
... ... @@ -7,6 +7,7 @@ use App\Http\Controllers\Aside\BaseController;
use App\Http\Logic\Aside\User\ProjectRoleLogic;
use App\Http\Requests\Aside\User\ProjectRoleRequest;
use App\Models\User\ProjectRole as ProjectRoleModel;
use Illuminate\Http\Request;
class ProjectRoleController extends BaseController
{
... ... @@ -23,6 +24,23 @@ class ProjectRoleController extends BaseController
}
/**
* @name :详情
* @return void
* @author :liyuhang
* @method
*/
public function info(Request $request,ProjectRoleLogic $roleLogic){
$request->validate([
'id'=>'required'
],[
'id.required' => 'ID不能为空'
]);
//TODO::详情
$roleLogic->role_info();
$this->response('success');
}
/**
* @name :添加角色时获取菜单列表
* @return void
* @author :liyuhang
... ... @@ -62,23 +80,13 @@ class ProjectRoleController extends BaseController
$this->response('success');
}
public function info(ProjectRoleRequest $request,ProjectRoleLogic $roleLogic){
$request->validate([
'id'=>'required'
],[
'id.required' => 'ID不能为空'
]);
//TODO::详情
$roleLogic->role_info();
$this->response('success');
}
/**
* @name :删除角色
* @return void
* @author :liyuhang
* @method
*/
public function del(ProjectRoleRequest $request,ProjectRoleLogic $roleLogic){
public function del(Request $request,ProjectRoleLogic $roleLogic){
$request->validate([
'id'=>'required'
],[
... ...
... ... @@ -7,6 +7,7 @@ use App\Http\Controllers\Aside\BaseController;
use App\Http\Logic\Aside\User\UserLogic;
use App\Http\Requests\Aside\User\UserRequest;
use App\Models\User\User as UserModel;
use Illuminate\Http\Request;
class ProjectUserController extends BaseController
{
... ... @@ -29,7 +30,7 @@ class ProjectUserController extends BaseController
* @author :liyuhang
* @method
*/
public function info(UserRequest $request,UserLogic $userLogic){
public function info(Request $request,UserLogic $userLogic){
$request->validate([
'id'=>'required'
],[
... ... @@ -72,7 +73,7 @@ class ProjectUserController extends BaseController
* @author :liyuhang
* @method
*/
public function del(UserRequest $request,UserLogic $userLogic){
public function del(Request $request,UserLogic $userLogic){
$request->validate([
'id'=>'required'
],[
... ...
... ... @@ -153,6 +153,13 @@ class BaseController extends Controller
return $new_arr ? $new_arr : false;
}
/**
* @param $data
* @name :返回参数处理
* @return array|string
* @author :liyuhang
* @method
*/
protected function _extents($data) {
if (empty($data) || !is_array($data)) {
... ...
... ... @@ -4,8 +4,8 @@ namespace App\Http\Controllers\Bside;
use App\Enums\Common\Code;
use App\Http\Logic\Bside\MailLogic;
use App\Models\Mail as MailModel;
use App\Models\MailUser as MailUserModel;
use App\Models\Mail\Mail as MailModel;
use App\Models\Mail\MailUser as MailUserModel;
use Illuminate\Http\Request;
class MailController extends BaseController
... ...
... ... @@ -49,7 +49,6 @@ class NewsCategoryController extends BaseController
$request->validated();
//添加时,验证分类上级分类是否有,有则更新到当前分类中,没有时直接添加
$newsCategoryLogic->add_news_category();
//TODO::写入日志
$this->response('success',Code::SUCCESS,[]);
}
... ... @@ -66,7 +65,6 @@ class NewsCategoryController extends BaseController
'id.required' => 'ID不能为空'
]);
$newsCategoryLogic->edit_news_category();
//TODO::写入日志
$this->response('success');
}
... ...
... ... @@ -3,6 +3,7 @@
namespace App\Http\Controllers\Bside\News;
use App\Enums\Common\Code;
use App\Helper\Common;
use App\Http\Controllers\Bside\BaseController;
use App\Http\Logic\Bside\News\NewsLogic;
use App\Http\Requests\Bside\News\NewsRequest;
... ... @@ -64,7 +65,6 @@ class NewsController extends BaseController
'id.required' => 'ID不能为空',
]);
$info = $newsLogic->news_info();
//TODO::清空相关资源
$this->response('success',Code::SUCCESS,$info);
}
/**
... ... @@ -76,7 +76,6 @@ class NewsController extends BaseController
public function add(NewsRequest $newsRequest,NewsLogic $newsLogic){
$newsRequest->validated();
$newsLogic->news_add();
//TODO::写入日志
$this->response('success');
}
... ... @@ -93,7 +92,6 @@ class NewsController extends BaseController
'id.required' => 'ID不能为空',
]);
$newsLogic->news_edit();
//TODO::写入日志
$this->response('success',Code::SUCCESS);
}
... ...
<?php
namespace App\Http\Controllers\Bside\User;
use App\Http\Controllers\Bside\BaseController;
use App\Models\User\UserLogin as UserLoginModel;
/**
* @name:用户登录日志
*/
class UserLoginController extends BaseController
{
public function lists(){
}
}
... ...
... ... @@ -14,4 +14,71 @@ class ProjectMenuLogic extends BaseLogic
$this->model = new ProjectMenu();
$this->param = $this->requestAll;
}
/**
* @name :获取详情
* @return void
* @author :liyuhang
* @method
*/
public function menu_info(){
$info = $this->model->read($this->param);
if($info === false){
$this->fail('当前数据不存在');
}
$this->success($info);
}
/**
* @name :添加菜单
* @return void
* @author :liyuhang
* @method
*/
public function menu_add(){
//查询当前名称是否存在
$info = $this->model->read(['name'=>$this->param['name']]);
if($info !== false){
$this->fail('当前菜单名称已存在');
}
$rs = $this->model->add($this->param);
if($rs === false){
$this->fail('添加失败');
}
$this->success();
}
/**
* @name :编辑菜单
* @return void
* @author :liyuhang
* @method
*/
public function menu_edit(){
//查询当前名称是否存在
$info = $this->model->read(['name'=>$this->param['name'],'id'=>['!=',$this->param['id']]]);
if($info !== false){
$this->fail('当前菜单名称已存在');
}
$rs = $this->model->edit($this->param,['id'=>$this->param['id']]);
if($rs === false){
$this->fail('编辑失败');
}
$this->success();
}
/**
* @name :删除菜单
* @return void
* @author :liyuhang
* @method
*/
public function menu_del(){
$this->param['id'] = ['in',$this->param['id']];
$rs = $this->model->del($this->param);
if($rs === false){
$this->fail('编辑失败');
}
$this->success();
}
}
... ...
... ... @@ -5,6 +5,7 @@ namespace App\Http\Logic\Aside\User;
use App\Http\Logic\Aside\BaseLogic;
use App\Models\User\ProjectMenu as ProjectMenuModel;
use App\Models\User\ProjectRole;
use App\Models\User\User as UserModel;
class ProjectRoleLogic extends BaseLogic
{
... ... @@ -61,6 +62,11 @@ class ProjectRoleLogic extends BaseLogic
* @method
*/
public function role_add(){
//查询当前名称是否存在
$info = $this->model->read(['name'=>$this->param['name']]);
if($info !== false){
$this->fail('当前菜单名称已存在');
}
$rs = $this->model->add($this->param);
if($rs === false){
$this->fail('添加失败');
... ... @@ -75,6 +81,11 @@ class ProjectRoleLogic extends BaseLogic
* @method
*/
public function role_edit(){
//查询当前名称是否存在
$info = $this->model->read(['name'=>$this->param['name'],'id'=>['!=',$this->param['id']]]);
if($info !== false){
$this->fail('当前菜单名称已存在');
}
$rs = $this->model->edit($this->param,['id'=>$this->param['id']]);
if($rs === false){
$this->fail('编辑失败');
... ... @@ -89,6 +100,14 @@ class ProjectRoleLogic extends BaseLogic
* @method
*/
public function role_del(){
//查询当前角色下是否有用户
$userModel = new UserModel();
foreach ($this->param['id'] as $v){
$user_info = $userModel->read(['role_id'=>$v]);
if($user_info !== false){
$this->fail('id为{'.$v.'}'.'的角色拥有用户'.$user_info['name'].',不允许删除');
}
}
$this->param['id'] = ['in',$this->param['id']];
$rs = $this->model->del($this->param);
if($rs === false){
... ...
... ... @@ -98,14 +98,14 @@ class BaseLogic extends Logic
public function upload(){
$image = $this->request->file('image');
if(empty($image)){
return $this->fail('没有上传图片',Code::USER_ERROR);
return $this->fail('没有上传图片');
}
$hash = hash_file('md5', $image->getPathname());
$url = './../uploads/images/';
$filename = date('ymdHis').rand(10000,99999);
$res = $this->request->file('image')->move($url,$filename);
if ($res === false) {
return $this->fail($image->getError(), Code::USER_ERROR);
return $this->fail($image->getError());
}
$imageModel = new ImageModel();
$data = [
... ... @@ -117,7 +117,7 @@ class BaseLogic extends Logic
];
$rs = $imageModel->add($data);
if ($rs === false) {
return $this->fail('添加失败', Code::USER_ERROR);
return $this->fail('error');
}
return $hash.$filename;
}
... ...
... ... @@ -27,54 +27,66 @@ class BlogCategoryLogic extends BaseLogic
* @method
*/
public function add_blog_category(){
DB::beginTransaction();
$condition = [
'name'=>$this->param['name']
];
$info = $this->model->read($condition);
if($info !== false){
$this->fail('当前分类名称已存在');
}
$this->param['project_id'] = $this->user['project_id'];
$this->param['operator_id'] = $this->user['id'];
$this->param['create_id'] = $this->user['id'];
$this->param['created_at'] = date('Y-m-d H:i:s');
$this->param['updated_at'] = date('Y-m-d H:i:s');
$cate_id = $this->model->insertGetId($this->param);
if($cate_id === false){
DB::rollBack();
$this->fail('error',Code::USER_ERROR);
}
//判断为子分类时
if(isset($this->param['pid']) && !empty($this->param['pid'])) {
//查看当前上级分类下是否有其他分类
$cate_info = $this->model->read(['pid' => $this->param['pid'], 'id' => ['!=', $cate_id]]);
if ($cate_info === false) {
//查看当前上一级分类下是否有新闻
$blogModel = new BlogModel();
$news_info = $blogModel->read(['category_id' => ['like', ',' . $this->param['pid'] . ',']]);
if ($news_info !== false) {
$replacement = ',' . $cate_id . ',';
$old = ',' . $this->param['pid'] . ',';
//更新所有商品到当前分类
$rs = DB::table('gl_Blog')->where('category_id', 'like', '%' . $old . '%')
->update(['category_id' => DB::raw("REPLACE(category_id, '$old', '$replacement')")]);
if ($rs === false) {
DB::rollBack();
$this->fail('error', Code::USER_ERROR);
DB::beginTransaction();
try {
$cate_id = $this->model->insertGetId($this->param);
//判断为子分类时
if(isset($this->param['pid']) && !empty($this->param['pid'])) {
//查看当前上级分类下是否有其他分类
$cate_info = $this->model->read(['pid' => $this->param['pid'], 'id' => ['!=', $cate_id]]);
if ($cate_info === false) {
//查看当前上一级分类下是否有新闻
$blogModel = new BlogModel();
$blog_info = $blogModel->read(['category_id' => ['like', ',' . $this->param['pid'] . ',']]);
if ($blog_info !== false) {
$replacement = ',' . $cate_id . ',';
$old = ',' . $this->param['pid'] . ',';
//更新所有商品到当前分类
DB::table('gl_Blog')->where('category_id', 'like', '%' . $old . '%')
->update(['category_id' => DB::raw("REPLACE(category_id, '$old', '$replacement')")]);
}
}
}
DB::commit();
}catch (\Exception $e){
DB::rollBack();
$this->fail('error');
}
DB::commit();
return $this->success();
}
/**
* @name :编辑分类
* @return void
* @throws \App\Exceptions\BsideGlobalException
* @author :liyuhang
* @method
*/
public function edit_blog_category(){
$condition = [
'id'=>['!=',$this->param['id']],
'name'=>$this->param['name']
];
//查看当前分类名称是否存在
$info = $this->model->read($condition);
if($info !== false){
$this->fail('当前分类名称已存在');
}
$this->param['operator_id'] = $this->user['id'];
$rs = $this->model->edit($this->param,['id'=>$this->param['id']]);
if($rs === false){
$this->fail('error',Code::USER_ERROR);
$this->fail('error');
}
return $this->success();
}
... ... @@ -82,14 +94,13 @@ class BlogCategoryLogic extends BaseLogic
/**
* @name :详情
* @return array
* @throws \App\Exceptions\BsideGlobalException
* @author :liyuhang
* @method
*/
public function info_blog_category(){
$info = $this->model->read($this->param);
if($info === false){
$this->fail('error',Code::USER_ERROR);
$this->fail('error');
}
return $this->success($info);
}
... ... @@ -104,7 +115,7 @@ class BlogCategoryLogic extends BaseLogic
$this->param['operator_id'] = $this->user['id'];
$rs = $this->model->edit($this->param,['id'=>$this->param['id']]);
if($rs === false){
$this->fail('error',Code::USER_ERROR);
$this->fail('error');
}
return $this->success();
}
... ... @@ -115,24 +126,23 @@ class BlogCategoryLogic extends BaseLogic
* @method
*/
public function del_blog_category(){
$this->param = $this->requestAll;
foreach ($this->param['id'] as $v){
//查询是否有子分类
$rs = $this->model->read(['pid'=>$v],['id']);
if($rs !== false){
$this->response('当前分类拥有子分类不允许删除',Code::USER_ERROR);
$this->response('当前分类拥有子分类不允许删除');
}
//查看当前分内下是否有博客
$blogModel = new BlogModel();
$rs = $blogModel->read(['category_id'=>$v],['id']);
if($rs !== false){
$this->response('当前分类拥有博客',Code::USER_ERROR);
$this->response('当前分类拥有博客');
}
}
$this->param['id'] = ['in',$this->param['id']];
$rs = $this->model->del($this->param);
if($rs === false){
$this->response('error',Code::USER_ERROR);
$this->response('error');
}
return $this->success();
}
... ...
... ... @@ -4,6 +4,7 @@ namespace App\Http\Logic\Bside\Blog;
use App\Enums\Common\Code;
use App\Http\Logic\Bside\BaseLogic;
use App\Models\Blog\Blog as BlogModel;
use App\Models\Blog\BlogLabel as BlogLabelModel;
class BlogLabelLogic extends BaseLogic
... ... @@ -23,12 +24,20 @@ class BlogLabelLogic extends BaseLogic
* @method
*/
public function add_blog_label(){
$condition = [
'name'=>$this->param['name']
];
//查看当前分类名称是否存在
$info = $this->model->read($condition);
if($info !== false){
$this->fail('当前标签名称已存在');
}
$this->param['create_id'] = $this->user['id'];
$this->param['Operator_id'] = $this->user['id'];
$this->param['project_id'] = $this->user['project_id'];
$rs = $this->model->add($this->param);
if($rs === false){
$this->fail('error',Code::USER_ERROR);
$this->fail('error');
}
return $this->success();
}
... ... @@ -40,11 +49,20 @@ class BlogLabelLogic extends BaseLogic
* @method
*/
public function edit_blog_label(){
$condition = [
'id'=>['!=',$this->param['id']],
'name'=>$this->param['name']
];
//查看当前分类名称是否存在
$info = $this->model->read($condition);
if($info !== false){
$this->fail('当前标签名称已存在');
}
$this->param['operator_id'] = $this->user['id'];
$rs = $this->model->edit($this->param,['id'=>$this->param['id']]);
//TODO::路由映射
if($rs === false){
$this->fail('error',Code::USER_ERROR);
$this->fail('error');
}
return $this->success();
}
... ... @@ -56,10 +74,18 @@ class BlogLabelLogic extends BaseLogic
* @method
*/
public function del_blog_label(){
foreach ($this->param['id'] as $v){
//查看当前分内下是否有博客
$blogModel = new BlogModel();
$rs = $blogModel->read(['label_id'=>$v],['id']);
if($rs !== false){
$this->response('当前标签拥有博客,不允许删除');
}
}
$this->param['id'] = ['in',$this->param['id']];
$rs = $this->model->del($this->param);
if($rs === false){
$this->fail('error',Code::USER_ERROR);
$this->fail('error');
}
return $this->success();
}
... ...
... ... @@ -3,6 +3,7 @@
namespace App\Http\Logic\Bside\Blog;
use App\Enums\Common\Code;
use App\Helper\Common;
use App\Http\Logic\Bside\BaseLogic;
use App\Models\Blog\Blog;
use App\Models\Blog\BlogCategory as BlogCategoryModel;
... ... @@ -12,6 +13,8 @@ use Illuminate\Support\Facades\DB;
class BlogLogic extends BaseLogic
{
const STATUS_TWO = 2;
public function __construct()
{
parent::__construct();
... ... @@ -45,12 +48,20 @@ class BlogLogic extends BaseLogic
return $this->success($list);
}
/**
* @name 添加博客
* @name :添加博客
* @return void
* @author :liyuhang
* @method
*/
public function blog_add(){
$condition = [
'name'=>$this->param['name']
];
//查看当前名称是否存在
$info = $this->model->read($condition);
if($info !== false){
$this->fail('当前名称已存在');
}
$this->param['create_id'] = $this->user['id'];
$this->param['operator_id'] = $this->user['id'];
$this->param['project_id'] = $this->user['project_id'];
... ... @@ -63,25 +74,32 @@ class BlogLogic extends BaseLogic
$data = $this->upload();
$this->param['image'] = $data;
}
$this->model->insertGetId($this->param);
$rs = $this->model->insertGetId($this->param);
RouteMap::setRoute($this->param['url'], RouteMap::SOURCE_BLOG, $rs, $this->user['project_id']);
DB::commit();
}catch (\Exception $e){
DB::rollBack();
$this->fail('error',Code::USER_ERROR);
$this->fail('error');
}
//TODO::写入日志
$this->success();
}
/**
* @name : 编辑用户
* @name : 编辑博客
* @return void
* @throws \App\Exceptions\BsideGlobalException
* @author :liyuhang
* @method
*/
public function blog_edit(){
$condition = [
'id'=>['!=',$this->param['id']],
'name'=>$this->param['name']
];
$info = $this->model->read($condition);
if($info !== false){
$this->fail('当前名称已存在');
}
$this->param['operator_id'] = $this->uid;
DB::beginTransaction();
try {
... ... @@ -102,8 +120,9 @@ class BlogLogic extends BaseLogic
DB::commit();
}catch (\Exception $e){
DB::rollBack();
$this->fail('error',Code::USER_ERROR);
$this->fail('error');
}
$this->success();
}
/**
* @name :获取数据详情
... ... @@ -114,6 +133,9 @@ class BlogLogic extends BaseLogic
*/
public function blog_info(){
$info = $this->model->read($this->param);
if($info === false){
$this->fail('error');
}
//获取分类名称
$info['category_id'] = explode(',',trim($info['category_id'],','));
$blogCategoryModel = new BlogCategoryModel();
... ... @@ -122,10 +144,7 @@ class BlogLogic extends BaseLogic
foreach ($category_list as $v){
$str .= $v['name'].',';
}
$info['category_id'] = trim($str,',');
if($info === false){
$this->fail('error',Code::USER_ERROR);
}
$info['category_name'] = trim($str,',');
return $this->success($info);
}
... ... @@ -153,7 +172,7 @@ class BlogLogic extends BaseLogic
*/
public function blog_del(){
$this->param['id'] = ['in',$this->param['id']];
$rs = $this->model->edit(['status'=>2],$this->param);
$rs = $this->model->edit(['status'=>$this::STATUS_TWO],$this->param);
if($rs === false){
$this->fail('error',Code::USER_ERROR);
}
... ...
... ... @@ -3,8 +3,8 @@
namespace App\Http\Logic\Bside;
use App\Enums\Common\Code;
use App\Models\Mail as MailModel;
use App\Models\MailUser as MailUserModel;
use App\Models\Mail\Mail as MailModel;
use App\Models\Mail\MailUser as MailUserModel;
class MailLogic extends BaseLogic
{
... ... @@ -36,7 +36,7 @@ class MailLogic extends BaseLogic
if($read_info === false){
$rs = $mailUserModel->add($data);
if($rs === false){
$this->fail('添加失败');
$this->fail('error');
}
}
return $this->success($info);
... ...
... ... @@ -3,6 +3,7 @@
namespace App\Http\Logic\Bside\News;
use App\Enums\Common\Code;
use App\Helper\Common;
use App\Http\Logic\Bside\BaseLogic;
use App\Models\News\News as NewsModel;
use App\Models\News\NewsCategory as NewsCategoryModel;
... ... @@ -39,40 +40,43 @@ class NewsCategoryLogic extends BaseLogic
* @method
*/
public function add_news_category(){
$condition = [
'name'=>$this->param['name']
];
$info = $this->model->read($condition);
if($info !== false){
$this->fail('当前分类名称已存在');
}
DB::beginTransaction();
$this->param['project_id'] = $this->user['project_id'];
$this->param['operator_id'] = $this->user['id'];
$this->param['create_id'] = $this->user['id'];
$this->param['created_at'] = date('Y-m-d H:i:s');
$this->param['updated_at'] = date('Y-m-d H:i:s');
$cate_id = $this->model->insertGetId($this->param);
if($cate_id === false){
DB::rollBack();
$this->fail('error',Code::USER_ERROR);
}
//判断为子分类时
if(isset($this->param['pid']) && !empty($this->param['pid'])) {
//查看当前上级分类下是否有其他分类
$cate_info = $this->model->read(['pid' => $this->param['pid'], 'id' => ['!=', $cate_id]]);
if ($cate_info === false) {
//查看当前上一级分类下是否有新闻
$newsModel = new NewsModel();
$news_info = $newsModel->read(['category_id' => ['like', ',' . $this->param['pid'] . ',']]);
if ($news_info !== false) {
$replacement = ',' . $cate_id . ',';
$old = ',' . $this->param['pid'] . ',';
//更新所有商品到当前分类
$rs = DB::table('gl_news')->where('category_id', 'like', '%' . $old . '%')
->update(['category_id' => DB::raw("REPLACE(category_id, '$old', '$replacement')")]);
if ($rs === false) {
DB::rollBack();
$this->fail('error', Code::USER_ERROR);
try {
$cate_id = $this->model->insertGetId($this->param);
//判断为子分类时
if(isset($this->param['pid']) && !empty($this->param['pid'])) {
//查看当前上级分类下是否有其他分类
$cate_info = $this->model->read(['pid' => $this->param['pid'], 'id' => ['!=', $cate_id]]);
if ($cate_info === false) {
//查看当前上一级分类下是否有新闻
$newsModel = new NewsModel();
$news_info = $newsModel->read(['category_id' => ['like', ',' . $this->param['pid'] . ',']]);
if ($news_info !== false) {
$replacement = ',' . $cate_id . ',';
$old = ',' . $this->param['pid'] . ',';
//更新所有商品到当前分类
DB::table('gl_news')->where('category_id', 'like', '%' . $old . '%')
->update(['category_id' => DB::raw("REPLACE(category_id, '$old', '$replacement')")]);
}
}
}
DB::commit();
}catch (\Exception $e){
DB::rollBack();
$this->fail('error');
}
DB::commit();
return $this->success();
}
... ... @@ -83,10 +87,19 @@ class NewsCategoryLogic extends BaseLogic
* @method
*/
public function edit_news_category(){
$condition = [
'id'=>['!=',$this->param['id']],
'name'=>$this->param['name']
];
//查看当前分类名称是否存在
$info = $this->model->read($condition);
if($info !== false){
$this->fail('当前分类名称已存在');
}
$this->param['operator_id'] = $this->user['id'];
$rs = $this->model->edit($this->param,['id'=>$this->param['id']]);
if($rs === false){
$this->fail('error',Code::USER_ERROR);
$this->fail('error');
}
return $this->success();
}
... ... @@ -102,7 +115,7 @@ class NewsCategoryLogic extends BaseLogic
$this->param['operator_id'] = $this->user['id'];
$rs = $this->model->edit($this->param,['id'=>$this->param['id']]);
if($rs === false){
$this->fail('error',Code::USER_ERROR);
$this->fail('error');
}
return $this->success();
}
... ... @@ -114,24 +127,23 @@ class NewsCategoryLogic extends BaseLogic
* @method
*/
public function del_news_category(){
$this->param = $this->requestAll;
foreach ($this->param['id'] as $v){
//查询是否有子分类
$rs = $this->model->read(['pid'=>$v],['id']);
if($rs !== false){
$this->fail('当前分类拥有子分类不允许删除',Code::USER_ERROR);
$this->fail('当前分类拥有子分类不允许删除');
}
//查看当前分内下是否有商品
$newsModel = new NewsModel();
$rs = $newsModel->read(['category_id'=>$v],['id']);
if($rs !== false){
$this->fail('当前分类拥有商品',Code::USER_ERROR);
$this->fail('当前分类拥有商品');
}
}
$this->param['id'] = ['in',$this->param['id']];
$rs = $this->model->del($this->param);
if($rs === false){
$this->fail('error',Code::USER_ERROR);
$this->fail('error');
}
return $this->success();
}
... ...
... ... @@ -3,6 +3,7 @@
namespace App\Http\Logic\Bside\News;
use App\Enums\Common\Code;
use App\Helper\Common;
use App\Http\Logic\Bside\BaseLogic;
use App\Models\Image;
use App\Models\News\News;
... ... @@ -59,31 +60,37 @@ class NewsLogic extends BaseLogic
$this->param['created_at'] = date('Y-m-d H:i:s',time());
$this->param['updated_at'] = date('Y-m-d H:i:s',time());
$this->param['category_id'] = ','.$this->param['category_id'].',';
// DB::beginTransaction();
// try {
DB::beginTransaction();
try {
if(isset($this->param['image'])){
$data = $this->upload();
$this->param['image'] = $data;
}
$rs = $this->model->insertGetId($this->param);
RouteMap::setRoute($this->param['url'], RouteMap::SOURCE_NEWS, $rs, $this->user['project_id']);
// DB::commit();
// }catch (\Exception $e){
// DB::rollBack();
// $this->fail('添加失败',Code::USER_ERROR);
// }
//TODO::写入日志
DB::commit();
}catch (\Exception $e){
DB::rollBack();
$this->fail('添加失败');
}
$this->success();
}
/**
* @name :编辑
* @return void
* @throws \App\Exceptions\BsideGlobalException
* @author :liyuhang
* @method
*/
public function news_edit(){
$condition = [
'id'=>['!=',$this->param['id']],
'name'=>$this->param['name']
];
$info = $this->model->read($condition);
if($info !== false){
$this->fail('当前名称已存在');
}
$this->param['operator_id'] = $this->user['id'];
//多个分类按逗号隔开
$this->param['category_id'] = ','.$this->param['category_id'].',';
... ... @@ -108,7 +115,7 @@ class NewsLogic extends BaseLogic
DB::commit();
}catch (\exception $e){
DB::rollBack();
$this->fail('参数错误或其他服务器原因,编辑失败',Code::USER_ERROR,[]);
$this->fail('参数错误或其他服务器原因,编辑失败');
}
//TODO::写入日志
$this->success();
... ... @@ -127,7 +134,6 @@ class NewsLogic extends BaseLogic
if($rs === false){
$this->fail('error',Code::USER_ERROR);
}
//TODO::写入日志
$this->success();
}
/**
... ... @@ -138,7 +144,6 @@ class NewsLogic extends BaseLogic
* @method
*/
public function news_info(){
$this->param = $this->requestAll;
$info = $this->model->read($this->param);
//获取分类名称
$info['category_id'] = explode(',',trim($info['category_id'],','));
... ... @@ -150,7 +155,7 @@ class NewsLogic extends BaseLogic
}
$info['category_id'] = trim($str,',');
if($info === false){
$this->fail('error',Code::USER_ERROR);
$this->fail('error');
}
return $this->success($info);
}
... ... @@ -165,7 +170,7 @@ class NewsLogic extends BaseLogic
$this->param['id'] = ['in',$this->param['id']];
$rs = $this->model->edit(['status'=>2,'operator_id'=>$this->user['id']],$this->param);
if($rs === false){
$this->fail('error',Code::USER_ERROR);
$this->fail('error');
}
return $this->success();
}
... ...
... ... @@ -6,7 +6,7 @@ use App\Enums\Common\Code;
use App\Http\Logic\Bside\BaseLogic;
use App\Models\User\ProjectMenu as ProjectMenuModel;
use App\Models\User\ProjectRole as ProjectRoleModel;
use App\Models\User\User;
use App\Models\User\User as UserModel;
class RoleLogic extends BaseLogic
{
... ... @@ -24,17 +24,25 @@ class RoleLogic extends BaseLogic
* @method
*/
public function role_add(){
$condition = [
'name'=>$this->param['name'],
'project_id'=>$this->user['project_id'],
];
$info = $this->model->read($condition);
if($info !== false){
$this->fail('当前添加的角色已存在');
}
$this->param['create_id'] = $this->user['id'];
$this->param['operator_id'] = $this->user['id'];
$this->param['project_id'] = $this->user['project_id'];
//验证当前角色是否存在
$info = $this->model->read(['name'=>$this->param['name']]);
if($info !== false){
$this->fail('当前添加的角色已存在',Code::USER_ERROR);
$this->fail('当前添加的角色已存在');
}
$rs = $this->model->add($this->param);
if($rs === false){
$this->fail('添加失败',Code::USER_PARAMS_ERROE);
$this->fail('添加失败');
}
return $this->success();
}
... ... @@ -54,11 +62,11 @@ class RoleLogic extends BaseLogic
];
$info = $this->model->read($condition);
if($info !== false){
$this->fail('当前添加的角色已存在',Code::USER_PARAMS_ERROE);
$this->fail('当前添加的角色已存在');
}
$rs = $this->model->edit($this->param,['id'=>$this->param['id']]);
if($rs === false){
$this->fail('编辑失败',Code::USER_PARAMS_ERROE);
$this->fail('error');
}
return $this->success();
}
... ... @@ -84,7 +92,7 @@ class RoleLogic extends BaseLogic
*/
public function role_del(){
//查询当前角色下是否有用户
$userModel = new User();
$userModel = new UserModel();
//批量删除
foreach ($this->param['id'] as $v){
$user_info = $userModel->read(['role_id'=>$v]);
... ...
... ... @@ -3,6 +3,7 @@
namespace App\Http\Logic\Bside\User;
use App\Enums\Common\Code;
use App\Helper\Common;
use App\Http\Logic\Bside\BaseLogic;
use App\Models\Image;
use App\Models\User\User;
... ... @@ -16,20 +17,32 @@ class UserLogic extends BaseLogic
$this->model = new User();
$this->param = $this->requestAll;
}
/**
* @name :用户详情
* @return void
* @author :liyuhang
* @method
*/
public function user_info(){
$info = $this->model->read($this->param);
if($info === false){
$this->fail('error',Code::USER_ERROR);
}
return $this->success($info);
}
/**
* @name :添加会员
* @author :liyuhang
*/
public function user_add(){
$this->param['create_id'] = $this->user['id'];
$this->param['operator_id'] = $this->user['id'];
$this->param['project_id'] = $this->user['project_id'];
//验证当前用户是否存在
$info = $this->model->read(['mobile'=>$this->param['mobile']]);
if($info !== false){
$this->fail('error',Code::USER_ERROR);
$this->fail('当前手机号码已注册');
}
$this->param['create_id'] = $this->user['id'];
$this->param['operator_id'] = $this->user['id'];
$this->param['project_id'] = $this->user['project_id'];
//上传图片
if(isset($this->param['image'])){
$this->param['image'] = $this->upload();
... ... @@ -38,7 +51,7 @@ class UserLogic extends BaseLogic
$this->param['password'] = base64_encode(md5($this->param['password']));
$rs = $this->model->add($this->param);
if($rs === false){
$this->fail('error',Code::USER_ERROR);
$this->fail('error');
}
return $this->success();
}
... ... @@ -54,7 +67,7 @@ class UserLogic extends BaseLogic
];
$info = $this->model->read($condition);
if($info !== false){
$this->fail('当前编辑的手机号码已存在',Code::USER_PARAMS_ERROE);
$this->fail('当前编辑的手机号码已存在');
}
$this->param['operator_id'] = $this->user['id'];
try {
... ... @@ -73,7 +86,7 @@ class UserLogic extends BaseLogic
$this->model->edits($this->param);
}
}catch (\exception $e){
$this->fail('参数错误或其他服务器原因,编辑失败',Code::USER_ERROR,[]);
$this->fail('参数错误或其他服务器原因,编辑失败');
}
return $this->success();
}
... ... @@ -92,20 +105,6 @@ class UserLogic extends BaseLogic
}
/**
* @name :用户详情
* @return void
* @author :liyuhang
* @method
*/
public function user_info(){
$info = $this->model->read($this->param);
if($info === false){
$this->fail('error',Code::USER_ERROR);
}
return $this->success($info);
}
/**
* @name :删除用户(逻辑删除)
* @return void
* @author :liyuhang
... ...
<?php
namespace App\Http\Logic\Bside\User;
use App\Http\Logic\Bside\BaseLogic;
use App\Models\User\UserLogin;
class UserLoginLogic extends BaseLogic
{
public function __construct()
{
parent::__construct();
$this->model = new UserLogin();
$this->param = $this->requestAll;
}
}
... ...
... ... @@ -24,7 +24,7 @@ class NewsCategoryRequest extends FormRequest
public function rules()
{
return [
'name'=>'required|max:100||unique:gl_news_category',
'name'=>'required|max:100',
];
}
... ...
... ... @@ -19,7 +19,7 @@ class ProjectGroupRequest extends FormRequest
public function rules()
{
return [
'name' => 'required|max:255||unique:gl_project_group',
'name' => 'required|max:255',
];
}
... ...
... ... @@ -19,7 +19,7 @@ class ProjectRoleRequest extends FormRequest
public function rules()
{
return [
'name'=>'required|max:11||unique:gl_project_role',
'name'=>'required|max:11',
'role_menu'=>'required|string',
];
}
... ...
... ... @@ -24,7 +24,7 @@ class UserRequest extends FormRequest
public function rules()
{
return [
'mobile'=>'required|string|max:11||unique:gl_project_user',
'mobile'=>'required|string|max:11',
'password'=>'required|string|min:5',
'name'=>'required|max:20',
'role_id'=>'required'
... ...
<?php
namespace App\Models;
namespace App\Models\Mail;
use App\Models\Base;
class Mail extends Base
{
... ...
<?php
namespace App\Models;
namespace App\Models\Mail;
use App\Models\Base;
class MailUser extends Base
{
... ...
... ... @@ -3,6 +3,7 @@
namespace App\Models\User;
//use Illuminate\Contracts\Auth\MustVerifyEmail;
use App\Helper\Common;
use App\Models\Base;
use App\Models\User\ProjectRole as ProjectRoleModel;
use Illuminate\Database\Eloquent\Factories\HasFactory;
... ... @@ -89,7 +90,8 @@ class User extends Base
if($rs === false){
return false;
}
unset($info['password']);
//写入日志
Common::set_user_login(['user_id'=>$info['id'],'ip'=>request()->ip()]);
return $info;
}
... ...
<?php
namespace App\Models\User;
use App\Models\Base;
class UserLog extends Base
{
protected $table = 'gl_user_log';
//自动维护create_at创建时间 updated_at修改时间
public $timestamps = true;
}
... ...
<?php
namespace App\Models\User;
use App\Models\Base;
class UserLogin extends Base
{
protected $table = 'gl_user_login';
//自动维护create_at创建时间 updated_at修改时间
public $timestamps = true;
}
... ...
... ... @@ -127,5 +127,9 @@ return [
'path' => storage_path('logs/laravel.log'),
],
],
//操作日志
'operator_log' =>[
'log'=>true,//true开启
'action' => [],//不需要写入日志的方法
],
];
... ...