作者 Your Name

gx

<?php
namespace App\Files;
use Illuminate\Http\Request;
class Image
{
protected $request = [];
public function __construct(Request $request)
{
$this->request = $request;
}
/**
* @name :上传图片
* @return void
* @author :liyuhang
* @method
*/
public function uploads(){
$url = './uploads/images/';
$param = $this->request->post();
if($this->request->hasFile('image') && $this->request->file('image')->isValid()){
$filename = date('ymdHis').rand(10000,99999).$this->request->file('image');
$this->request->file('image')->move('./uploads/images/',$filename);
}else{
return false;
}
return $url.$filename;
}
}
<?php
use Illuminate\Support\Facades\Log;
if(!function_exists('http_post')){
/**
* 发送http post请求
* @param type $url
* @param type $post_data
*/
function http_post($url, $post_data)
{
$header[] = "charset = UTF-8";
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_CUSTOMREQUEST, "POST");
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, 0);
curl_setopt($ch, CURLOPT_HTTPHEADER, $header);
curl_setopt($ch, CURLOPT_USERAGENT, 'Mozilla/5.0 (compatible; MSIE 5.01; Windows NT 5.0)');
curl_setopt($ch, CURLOPT_FOLLOWLOCATION, 1);
curl_setopt($ch, CURLOPT_AUTOREFERER, 1);
curl_setopt($ch, CURLOPT_POSTFIELDS, $post_data);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
$res = curl_exec($ch);
if (curl_errno($ch)) {
Log::write(print_r(curl_errno($ch),1),'debug---1');
}
curl_close($ch);
return json_decode($res, true);
}
}
if(!function_exists('http_get')){
/**
* 发送http get请求
* @param type $url
* @return type
*/
function http_get($url)
{
$header[] = "content-type: application/x-www-form-urlencoded;
charset = UTF-8";
$ch1 = curl_init();
$timeout = 5;
curl_setopt($ch1, CURLOPT_URL, $url);
curl_setopt($ch1, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch1, CURLOPT_HTTPHEADER, $header);
curl_setopt($ch1, CURLOPT_CONNECTTIMEOUT, $timeout);
curl_setopt($ch1, CURLOPT_SSL_VERIFYPEER, false);
curl_setopt($ch1, CURLOPT_SSL_VERIFYHOST, false);
$access_txt = curl_exec($ch1);
curl_close($ch1);
return json_decode($access_txt, true);
}
}
if(!function_exists('_get_child')){
/**
* 菜单权限->得到子级数组
* @param int
* @return array
*/
function _get_child($my_id, $arr)
{
$new_arr = array();
foreach ($arr as $k => $v) {
$v = (array)$v;
if ($v['pid'] == $my_id) {
$v['sub'] = _get_child($v['id'],$arr);
$new_arr[] = $v;
}
}
return $new_arr ? $new_arr : false;
}
}
... ...
... ... @@ -9,13 +9,13 @@ use Illuminate\Http\JsonResponse;
use Illuminate\Http\Request;
use Illuminate\Http\Exceptions\HttpResponseException;
use Illuminate\Support\Facades\Cache;
use Illuminate\Support\Facades\Log;
class BaseController extends Controller
{
protected $param = [];//所有请求参数
protected $token = ''; //token
protected $request = [];//助手函数
protected $allCount = 0;//总条数
protected $page = 1;//当前页
protected $row = 20;//每页条数
protected $header = [];//设置请求头参数
... ... @@ -144,25 +144,5 @@ class BaseController extends Controller
return $new_arr ? $new_arr : false;
}
/**
* @name :上传图片
* @return void
* @author :liyuhang
* @method
*/
public function uploads(){
$files = $this->request->file('file');
if(empty($files)){
return $this->response('没有上传文件',Code::USER_ERROR);
}
$url = './uploads/images/';
$param = $this->request->post();
if($this->request->hasFile('image') && $files->isValid()){
$filename = date('ymdHis').rand(10000,99999).$this->request->file('image');
$this->request->file('image')->move('./uploads/images/',$filename);
}else{
return false;
}
return $url.$filename;
}
}
... ...
... ... @@ -30,16 +30,13 @@ class BlogCategoryController extends BaseController
* @author :liyuhang
* @method
*/
public function info(Request $request,BlogCategoryModel $blogCategoryModel){
public function info(Request $request,BlogCategoryLogic $blogCategoryLogic){
$request->validate([
'id'=>['required']
],[
'id.required' => 'ID不能为空'
]);
$info = $blogCategoryModel->read($this->param);
if($info === false){
$this->response('error',Code::USER_ERROR);
}
$info = $blogCategoryLogic->info_blog_category();
$this->response('success',Code::SUCCESS,$info);
}
/**
... ... @@ -61,19 +58,15 @@ class BlogCategoryController extends BaseController
* @author :liyuhang
* @method
*/
public function edit(BlogCategoryRequest $request,BlogCategoryModel $blogCategoryModel){
public function edit(BlogCategoryRequest $request,BlogCategoryLogic $blogCategoryLogic){
$request->validate([
'id'=>['required']
],[
'id.required' => 'ID不能为空'
]);
$this->param['operator_id'] = $this->uid;
$rs = $blogCategoryModel->edit($this->param,['id'=>$this->param['id']]);
if($rs === false){
$this->response('error',Code::USER_ERROR);
}
$blogCategoryLogic->edit_blog_category();
//TODO::写入日志
$this->response('success',Code::SUCCESS);
$this->response('success');
}
/**
... ... @@ -82,17 +75,13 @@ class BlogCategoryController extends BaseController
* @author :liyuhang
* @method
*/
public function status(Request $request,BlogCategoryModel $blogCategoryModel){
public function status(Request $request,BlogCategoryLogic $blogCategoryLogic){
$request->validate([
'id'=>['required'],
],[
'id.required' => 'ID不能为空',
]);
$this->param['operator_id'] = $this->uid;
$rs = $blogCategoryModel->edit($this->param,['id'=>$this->param['id']]);
if($rs === false){
$this->response('error',Code::USER_ERROR);
}
$blogCategoryLogic->status_blog_category();
$this->response('success');
}
... ...
... ... @@ -4,9 +4,10 @@ namespace App\Http\Controllers\Bside\Blog;
use App\Enums\Common\Code;
use App\Http\Controllers\Bside\BaseController;
use App\Http\Logic\Bside\Blog\BlogLogic;
use App\Http\Requests\Bside\Blog\BlogRequest;
use App\Models\Blog\Blog as BlogModel;
use App\Models\Blog\BlogCategory as BlogCategoryModel;
use App\Models\RouteMap;
use Illuminate\Http\Request;
class BlogController extends BaseController
... ... @@ -24,39 +25,40 @@ class BlogController extends BaseController
}
/**
* @name :获取当前博客详情
* @name :获取分页列表
* @return void
* @throws \App\Exceptions\BsideGlobalException
* @author :liyuhang
* @method
*/
public function get_category_list(BlogLogic $blogLogic){
$list = $blogLogic->blog_get_category_list();
$this->response('success',Code::SUCCESS,$list);
}
/**
* @name :获取当前博客详情
* @return json
* @author :liyuhang
* @method
*/
public function info(Request $request,BlogModel $blogModel){
public function info(Request $request,BlogLogic $blogLogic){
$request->validate([
'id'=>['required']
],[
'id.required' => 'ID不能为空'
]);
$info = $blogModel->read($this->param);
if($info === false){
$this->response('error',Code::USER_ERROR);
}
$info = $blogLogic->blog_info();
$this->response('success',Code::SUCCESS,$info);
}
/**
* @name :添加博客
* @return json
* @return void
* @author :liyuhang
* @method
*/
public function add(BlogRequest $request,BlogModel $blogModel){
public function add(BlogRequest $request,BlogLogic $blogLogic){
$request->validated();
$this->param['create_id'] = $this->uid;
$this->param['operator_id'] = $this->uid;
$this->param['project_id'] = $this->user['project_id'];
//TODO::路由映射
$rs = $blogModel->add($this->param);
if($rs === false){
$this->response('error',Code::USER_ERROR);
}
$blogLogic->blog_add();
//TODO::写入日志
$this->response('success');
}
... ... @@ -67,18 +69,13 @@ class BlogController extends BaseController
* @author :liyuhang
* @method
*/
public function edit(BlogRequest $request,BlogModel $blogModel){
public function edit(BlogRequest $request,BlogLogic $blogLogic){
$request->validate([
'id'=>['required']
],[
'id.required' => 'ID不能为空'
]);
$this->param['operator_id'] = $this->uid;
$rs = $blogModel->edit($this->param,['id'=>$this->param['id']]);
//TODO::路由映射
if($rs === false){
$this->response('error',Code::USER_ERROR);
}
$blogLogic->blog_edit();
//TODO::写入日志
$this->response('success');
}
... ... @@ -89,17 +86,13 @@ class BlogController extends BaseController
* @author :liyuhang
* @method
*/
public function status(Request $request,BlogModel $blogModel){
public function status(Request $request,BlogLogic $blogLogic){
$request->validate([
'id'=>['required'],
],[
'id.required' => 'ID不能为空',
]);
$this->param['operator_id'] = $this->uid;
$rs = $blogModel->edit($this->param,['id'=>$this->param['id']]);
if($rs === false){
$this->response('error',Code::USER_ERROR);
}
$blogLogic->blog_status();
//TODO::写入日志
$this->response('success');
}
... ... @@ -110,17 +103,13 @@ class BlogController extends BaseController
* @author :liyuhang
* @method
*/
public function del(Request $request,BlogModel $blogModel){
public function del(Request $request,BlogLogic $blogLogic){
$request->validate([
'id'=>['required'],
],[
'id.required' => 'ID不能为空',
]);
$this->param['id'] = ['in',$this->param['id']];
$rs = $blogModel->edit(['status'=>2],$this->param);
if($rs === false){
$this->response('error',Code::USER_ERROR);
}
$blogLogic->blog_del();
$this->response('success');
}
}
... ...
... ... @@ -118,8 +118,4 @@ class ComController extends BaseController
}
$this->response('success');
}
public function uploads(){
}
}
... ...
... ... @@ -32,16 +32,13 @@ class NewsCategoryController extends BaseController
* @author :liyuhang
* @method
*/
public function info(Request $request,NewsCategoryModel $newsCategory){
public function info(Request $request,NewsCategoryLogic $newsCategoryLogic){
$request->validate([
'id'=>['required']
],[
'id.required' => 'ID不能为空'
]);
$info = $newsCategory->read($this->param);
if($info === false){
$this->response('error',Code::USER_ERROR);
}
$info = $newsCategoryLogic->info_news_category();
$this->response('success',Code::SUCCESS,$info);
}
/**
... ... @@ -64,17 +61,13 @@ class NewsCategoryController extends BaseController
* @author :liyuhang
* @method
*/
public function edit(NewsCategoryRequest $request,NewsCategoryModel $newsCategory){
public function edit(NewsCategoryRequest $request,NewsCategoryLogic $newsCategoryLogic){
$request->validate([
'id'=>['required']
],[
'id.required' => 'ID不能为空'
]);
$this->param['operator_id'] = $this->uid;
$rs = $newsCategory->edit($this->param,['id'=>$this->param['id']]);
if($rs === false){
$this->response('error',Code::USER_ERROR);
}
$newsCategoryLogic->edit_news_category();
//TODO::写入日志
$this->response('success');
}
... ... @@ -85,17 +78,13 @@ class NewsCategoryController extends BaseController
* @author :liyuhang
* @method
*/
public function status(Request $request,NewsCategoryModel $newsCategory){
public function status(Request $request,NewsCategoryLogic $newsCategoryLogic){
$request->validate([
'id'=>['required'],
],[
'id.required' => 'ID不能为空',
]);
$this->param['operator_id'] = $this->uid;
$rs = $newsCategory->edit($this->param,['id'=>$this->param['id']]);
if($rs === false){
$this->response('error',Code::USER_ERROR);
}
$newsCategoryLogic->status_news_category();
$this->response('success');
}
... ...
... ... @@ -4,6 +4,7 @@ namespace App\Http\Controllers\Bside\News;
use App\Enums\Common\Code;
use App\Http\Controllers\Bside\BaseController;
use App\Http\Logic\Bside\News\NewsLogic;
use App\Http\Requests\Bside\News\NewsRequest;
use App\Models\News\News as NewsModel;
use App\Models\News\NewsCategory as NewsCategoryModel;
... ... @@ -32,21 +33,8 @@ class NewsController extends BaseController
* @author :liyuhang
* @method
*/
public function get_category_list(NewsCategoryModel $newsCategoryModel){
$this->map['status'] = 0;
$this->map['project_id'] = $this->user['project_id'];
$cate_list = $newsCategoryModel->list($this->map,'sort');
if($cate_list === false){
$this->response('error',Code::USER_ERROR);
}
$list = [];
foreach ($cate_list as $k => $v){
$v = (array)$v;
if ($v['pid'] == 0) {
$v['sub'] = $this->_get_child($v['id'], $cate_list);
$list[] = $v;
}
}
public function get_category_list(NewsLogic $newsLogic){
$list = $newsLogic->news_get_category_list();
$this->response('success',Code::SUCCESS,$list);
}
/**
... ... @@ -55,18 +43,15 @@ class NewsController extends BaseController
* @author :liyuhang
* @method
*/
public function info(Request $request,NewsModel $news){
public function info(Request $request,NewsLogic $newsLogic){
$request->validate([
'id'=>['required'],
],[
'id.required' => 'ID不能为空',
]);
$rs = $news->read($this->param);
if($rs === false){
$this->response('error',Code::USER_ERROR);
}
$info = $newsLogic->news_info();
//TODO::清空相关资源
$this->response('success');
$this->response('success',Code::SUCCESS,$info);
}
/**
* @name :添加新闻
... ... @@ -74,18 +59,9 @@ class NewsController extends BaseController
* @author :liyuhang
* @method
*/
public function add(NewsRequest $newsRequest,NewsModel $news){
public function add(NewsRequest $newsRequest,NewsLogic $newsLogic){
$newsRequest->validated();
$this->param['create_id'] = $this->uid;
$this->param['operator_id'] = $this->uid;
$this->param['project_id'] = $this->user['project_id'];
//多个分类按逗号隔开
$this->param['category_id'] = ','.$this->param['category_id'].',';
//TODO::路由映射
$rs = $news->add($this->param);
if($rs === false){
$this->response('error',Code::USER_ERROR);
}
$newsLogic->news_add();
//TODO::写入日志
$this->response('success');
}
... ... @@ -96,19 +72,13 @@ class NewsController extends BaseController
* @author :liyuhang
* @method
*/
public function edit(NewsRequest $newsRequest,NewsModel $news){
public function edit(NewsRequest $newsRequest,NewsLogic $newsLogic){
$newsRequest->validate([
'id'=>['required'],
],[
'id.required' => 'ID不能为空',
]);
$this->param['operator_id'] = $this->uid;
//多个分类按逗号隔开
$this->param['category_id'] = ','.$this->param['category_id'].',';
$rs = $news->edit($this->param,['id'=>$this->param['id']]);
if($rs === false){
$this->response('error',Code::USER_ERROR);
}
$newsLogic->news_edit();
//TODO::写入日志
$this->response('success',Code::SUCCESS);
}
... ... @@ -119,17 +89,13 @@ class NewsController extends BaseController
* @author :liyuhang
* @method
*/
public function status(Request $request,NewsModel $news){
public function status(Request $request,NewsLogic $newsLogic){
$request->validate([
'id'=>['required'],
],[
'id.required' => 'ID不能为空',
]);
$this->param['operator_id'] = $this->uid;
$rs = $news->edit($this->param,['id'=>$this->param['id']]);
if($rs === false){
$this->response('error',Code::USER_ERROR);
}
$newsLogic->news_status();
//TODO::写入日志
$this->response('success');
}
... ... @@ -139,17 +105,13 @@ class NewsController extends BaseController
* @author :liyuhang
* @method
*/
public function del(Request $request,NewsModel $news){
public function del(Request $request,NewsLogic $newsLogic){
$request->validate([
'id'=>['required'],
],[
'id.required' => 'ID不能为空',
]);
$this->param['id'] = ['in',$this->param['id']];d;
$rs = $news->edit(['status'=>2,'operator_id'=>$this->uid],$this->param);
if($rs === false){
$this->response('error',Code::USER_ERROR);
}
$newsLogic->news_del();
//TODO::清空相关资源/写入日志
$this->response('success');
}
... ...
... ... @@ -3,6 +3,7 @@
namespace App\Http\Controllers\Bside;
use App\Enums\Common\Code;
use App\Http\Logic\Bside\RoleLogic;
use App\Http\Requests\Bside\ProjectRoleRequest;
use App\Models\ProjectMenu as ProjectMenuModel;
use App\Models\ProjectRole as ProjectRoleModel;
... ... @@ -33,17 +34,14 @@ class ProjectRoleController extends BaseController
* @author :liyuhang
* @method
*/
public function info(Request $request,ProjectRoleModel $projectRoleModel){
public function info(Request $request,RoleLogic $roleLogic){
$request->validate([
'id'=>['required', new Ids()],
],[
'id.required' => 'ID不能为空',
]);
$rs = $projectRoleModel->read($this->param);
if($rs === false){
$this->response('error',Code::USER_ERROR);
}
$this->response('success');
$info = $roleLogic->role_info();
$this->response('success',Code::SUCCESS,$info);
}
/**
* @name :添加/编辑角色时获取菜单列表
... ... @@ -51,20 +49,8 @@ class ProjectRoleController extends BaseController
* @author :liyuhang
* @method
*/
public function get_role_menu(ProjectRoleModel $projectRoleModel,ProjectMenuModel $projectMenuModel){
//根据当前登录用户角色返回用户菜单列表
$info = $projectRoleModel->read(['id'=>$this->user['role_id']]);
$info['role_menu'] = trim($info['role_menu'],',');
$lists = $projectMenuModel->where(['status'=>0])->whereIn('id',explode(',',$info['role_menu']))->get();
$lists = $lists->toArray();
$menu = array();
foreach ($lists as $k => $v){
$v = (array)$v;
if ($v['pid'] == 0) {
$v['sub'] = $this->_get_child($v['id'], $lists);
$menu[] = $v;
}
}
public function get_role_menu(RoleLogic $roleLogic){
$menu = $roleLogic->role_get_menu();
$this->response('当前用户菜单列表',Code::SUCCESS,$menu);
}
/**
... ... @@ -73,20 +59,9 @@ class ProjectRoleController extends BaseController
* @author :liyuhang
* @method
*/
public function add(ProjectRoleRequest $request){
public function add(ProjectRoleRequest $request,RoleLogic $roleLogic){
$request->validated();
$this->param['project_id'] = $this->user['project_id'];
//获取当前项目下的角色超级管理员
$projectRoleModel = new ProjectRoleModel();
//验证当前角色是否存在
$info = $projectRoleModel->read(['name'=>$this->param['name']]);
if(!empty($info)){
$this->response('当前添加的角色已存在',Code::USER_PARAMS_ERROE);
}
$rs = $projectRoleModel->add($this->param);
if($rs === false){
$this->response('添加失败',Code::USER_PARAMS_ERROE);
}
$roleLogic->role_add();
$this->response('添加成功');
}
... ... @@ -96,26 +71,13 @@ class ProjectRoleController extends BaseController
* @author :liyuhang
* @method
*/
public function edit(ProjectRoleRequest $request,ProjectRoleModel $projectRoleModel){
public function edit(ProjectRoleRequest $request,RoleLogic $roleLogic){
$request->validate([
'id'=>['required']
],[
'id.required' => 'ID不能为空'
]);
//TODO::查询当前名称是否重复
$condition = [
['id'=>['!=',$this->param['id']]],
['name'=>$this->param['name']],
['project_id'=>$this->user['project_id']],
];
$info = $projectRoleModel->formatQuery($condition)->first();
if(!empty($info)){
$this->response('当前添加的角色已存在',Code::USER_PARAMS_ERROE);
}
$rs = $projectRoleModel->edit($this->param,['id'=>$this->param['id']]);
if($rs === false){
$this->response('编辑失败',Code::USER_PARAMS_ERROE);
}
$roleLogic->role_edit();
$this->response('编辑成功');
}
... ... @@ -125,19 +87,14 @@ class ProjectRoleController extends BaseController
* @author :liyuhang
* @method
*/
public function status(Request $request,ProjectRoleModel $projectRoleModel){
public function status(Request $request,RoleLogic $roleLogic){
$request->validate([
'id'=>['required'],
'status'=>['required'],
],[
'id.required' => 'ID不能为空',
'status.required' => 'status不能为空'
]);
$rs = $projectRoleModel->edit(['status'=>$this->param['status']],['id'=>$this->param['id']]);
if($rs === false){
$this->response('编辑失败',Code::USER_PARAMS_ERROE);
}
$this->response($this->param['status'] == 0 ? '启用成功' : '禁用成功',Code::SUCCESS);
$roleLogic->role_status();
$this->response($this->param['status'] == 0 ? '启用成功' : '禁用成功');
}
/**
... ... @@ -146,22 +103,13 @@ class ProjectRoleController extends BaseController
* @author :liyuhang
* @method
*/
public function del(Request $request,ProjectRoleModel $projectRoleModel){
public function del(Request $request,RoleLogic $roleLogic){
$request->validate([
'id'=>['required']
],[
'id.required' => 'ID不能为空'
]);
//查询当前角色下是否有用户
$userModel = new UserModel();
$user_info = $userModel->read(['role_id'=>$this->param['id']]);
if(!empty($user_info)){
$this->response('当前角色下有用户存在,不允许删除',Code::USER_ERROR);
}
$rs = $projectRoleModel->del(['id'=>$this->param['id']]);
if($rs === false){
$this->response('error',Code::USER_ERROR);
}
$roleLogic->role_del();
$this->response('success');
}
}
... ...
... ... @@ -3,6 +3,7 @@
namespace App\Http\Controllers\Bside;
use App\Enums\Common\Code;
use App\Http\Logic\Bside\UserLogic;
use App\Http\Requests\Bside\UserRequest;
use App\Models\User as UserModel;
use App\Rules\Ids;
... ... @@ -32,14 +33,10 @@ class UserController extends BaseController
* @author :liyuhang
* @method
*/
public function add(UserRequest $request,UserModel $userModel){
public function add(UserRequest $request,UserLogic $userLogic){
$request->validated();
$this->param['project_id'] = $this->user['project_id'];
$rs = $userModel->adds($this->param);
if($rs === false){
$this->response('当前添加用户已存在或参数错误,添加失败',Code::USER_REGISTER_ERROE,[]);
}
$this->response('success',Code::SUCCESS);
$userLogic->user_add();
$this->response('success');
}
/**
... ... @@ -48,22 +45,14 @@ class UserController extends BaseController
* @author :liyuhang
* @method
*/
public function edit(UserRequest $request,UserModel $userModel){
public function edit(UserRequest $request,UserLogic $userLogic){
$request->validate([
'id'=>['required']
],[
'id.required' => 'ID不能为空'
]);
$info = $userModel->where('id','<>',$this->param['id'])
->where(['mobile'=>$this->param['mobile']])->first();
if(!empty($info)){
$this->response('当前编辑的手机号码已存在',Code::USER_PARAMS_ERROE);
}
$rs = $userModel->edits($this->param);
if($rs === false){
$this->response('参数错误或其他服务器原因,编辑失败',Code::USER_ERROR,[]);
}
$this->response('编辑成功',Code::SUCCESS,[]);
$userLogic->user_edit();
$this->response('success');
}
/**
... ... @@ -72,18 +61,13 @@ class UserController extends BaseController
* @author :liyuhang
* @method
*/
public function status(Request $request,UserModel $userModel){
public function status(Request $request,UserLogic $userLogic){
$request->validate([
'id'=>['required'],
'status'=>['required'],
],[
'id.required' => 'ID不能为空',
'status.required' => 'status不能为空'
]);
$rs = $userModel->edit($this->param,['id'=>$this->param['id']]);
if($rs === false){
$this->response('error',Code::USER_ERROR);
}
$userLogic->user_status();
$this->response($this->param['status'] == 0 ? '启用成功' : '禁用成功');
}
... ... @@ -93,16 +77,13 @@ class UserController extends BaseController
* @author :liyuhang
* @method
*/
public function info(Request $request,UserModel $userModel){
public function info(Request $request,UserLogic $userLogic){
$request->validate([
'id'=>['required', new Ids()],
'id'=>['required'],
],[
'id.required' => 'ID不能为空',
]);
$rs = $userModel->read($this->param);
if($rs === false){
$this->response('error',Code::USER_ERROR);
}
$userLogic->user_info();
$this->response('success');
}
/**
... ... @@ -111,16 +92,13 @@ class UserController extends BaseController
* @author :liyuhang
* @method
*/
public function del(Request $request,UserModel $userModel){
public function del(Request $request,UserLogic $userLogic){
$request->validate([
'id'=>['required', new Ids()],
'id'=>['required'],
],[
'id.required' => 'ID不能为空',
]);
$rs = $userModel->del($this->param);
if($rs === false){
$this->response('error',Code::USER_ERROR);
}
$userLogic->user_del();
$this->response('success');
}
}
... ...
... ... @@ -5,6 +5,7 @@ namespace App\Http\Logic\Bside;
use App\Enums\Common\Code;
use App\Exceptions\BsideGlobalException;
use App\Helper\Arr;
use Illuminate\Http\Request;
use Illuminate\Support\Facades\Cache;
/**
... ... @@ -16,6 +17,8 @@ class BaseLogic
protected $requestAll;
protected $param;
protected $user;
protected $is_cache = true; //是否缓存数据
... ... @@ -304,4 +307,28 @@ class BaseLogic
});
return $query;
}
/**
* @name :上传图片
* @return void
* @author :liyuhang
* @method
*/
public function upload(Request $request){
$image = $request->file('image');
if(empty($image)){
return $this->fail('没有上传图片',Code::USER_ERROR);
}
$url = './../uploads/images/';
$filename = date('ymdHis').rand(10000,99999);
$res = $request->file('image')->move($url,$filename);
if ($res === false) {
return $this->fail($image->getError(), 400);
}
$data = [
'path' => $url.$filename,
'create_time' => date('Y-m-d H:i:s',time()),
'size' => $res->getSize(),
];
return data;
}
}
... ...
... ... @@ -6,6 +6,7 @@ use App\Enums\Common\Code;
use App\Http\Logic\Bside\BaseLogic;
use App\Models\Blog\BlogCategory as BlogCategoryModel;
use App\Models\Blog\Blog as BlogModel;
use App\Models\News\NewsCategory as NewsCategoryModel;
use Illuminate\Support\Facades\DB;
class BlogCategoryLogic extends BaseLogic
... ... @@ -15,8 +16,10 @@ class BlogCategoryLogic extends BaseLogic
parent::__construct();
$this->model = new BlogCategoryModel();
$this->param = $this->requestAll;
}
/**
* @name :添加时验证上级分类是否有商品,有则替换带当前分类下
* @return void
... ... @@ -25,7 +28,6 @@ class BlogCategoryLogic extends BaseLogic
*/
public function add_blog_category(){
DB::beginTransaction();
$this->param = $this->requestAll;
$this->param['project_id'] = $this->user['project_id'];
$this->param['operator_id'] = $this->user['id'];
$this->param['create_id'] = $this->user['id'];
... ... @@ -62,6 +64,51 @@ class BlogCategoryLogic extends BaseLogic
}
/**
* @name :编辑分类
* @return void
* @throws \App\Exceptions\BsideGlobalException
* @author :liyuhang
* @method
*/
public function edit_blog_category(){
$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);
}
return $this->success();
}
/**
* @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);
}
return $this->success($info);
}
/**
* @name :编辑状态与排序
* @return void
* @author :liyuhang
* @method
*/
public function status_blog_category(){
$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);
}
return $this->success();
}
/**
* @name :删除博客分类
* @return void
* @author :liyuhang
... ... @@ -87,5 +134,6 @@ class BlogCategoryLogic extends BaseLogic
if($rs === false){
$this->response('error',Code::USER_ERROR);
}
return $this->success();
}
}
... ...
... ... @@ -2,9 +2,141 @@
namespace App\Http\Logic\Bside\Blog;
use App\Enums\Common\Code;
use App\Http\Logic\Bside\BaseLogic;
use App\Models\Blog\Blog;
use App\Models\Blog\BlogCategory as BlogCategoryModel;
use App\Models\RouteMap;
use Illuminate\Support\Facades\DB;
class BlogLogic extends BaseLogic
{
public function __construct()
{
parent::__construct();
$this->model = new Blog();
$this->param = $this->requestAll;
}
/**
* @name :获取分类列表
* @return array
* @throws \App\Exceptions\BsideGlobalException
* @author :liyuhang
* @method
*/
public function blog_get_category_list(){
$this->map['status'] = 0;
$this->map['project_id'] = $this->user['project_id'];
$blogCategoryModel = new BlogCategoryModel();
$cate_list = $blogCategoryModel->list($this->map,'sort');
if($cate_list === false){
$this->fail('error',Code::USER_ERROR);
}
$list = [];
foreach ($cate_list as $v){
$v = (array)$v;
if ($v['pid'] == 0) {
$v['sub'] = _get_child($v['id'], $cate_list);
$list[] = $v;
}
}
return $this->success($list);
}
/**
* @name :添加博客
* @return void
* @author :liyuhang
* @method
*/
public function blog_add(){
$this->param['create_id'] = $this->uid;
$this->param['operator_id'] = $this->uid;
$this->param['project_id'] = $this->user['project_id'];
DB::beginTransaction();
try {
$rs = $this->model->insertGetId($this->param);
RouteMap::setRoute($this->param['url'], RouteMap::SOURCE_BLOG, $rs, $this->user['project_id']);
DB::commit();
}catch (\Exception $e){
DB::rollBack();
$this->fail('error',Code::USER_ERROR);
}
//TODO::写入日志
$this->success();
}
/**
* @name : 编辑用户
* @return void
* @throws \App\Exceptions\BsideGlobalException
* @author :liyuhang
* @method
*/
public function blog_edit(){
$this->param['operator_id'] = $this->uid;
DB::beginTransaction();
try {
$this->model->edit($this->param,['id'=>$this->param['id']]);
RouteMap::setRoute($this->param['url'], RouteMap::SOURCE_BLOG, $this->param['id'], $this->user['project_id']);
DB::commit();
}catch (\Exception $e){
DB::rollBack();
$this->fail('error',Code::USER_ERROR);
}
}
/**
* @name :获取数据详情
* @return array
* @throws \App\Exceptions\BsideGlobalException
* @author :liyuhang
* @method
*/
public function blog_info(){
$info = $this->model->read($this->param);
//获取分类名称
$info['category_id'] = explode(',',trim($info['category_id'],','));
$blogCategoryModel = new BlogCategoryModel();
$category_list = $blogCategoryModel->list(['id'=>['in',$info['category_id']]],'id',['name']);
$str = '';
foreach ($category_list as $v){
$str .= $v['name'].',';
}
$info['category_id'] = trim($str,',');
if($info === false){
$this->fail('error',Code::USER_ERROR);
}
return $this->success($info);
}
/**
* @name :修改状态
* @return array
* @throws \App\Exceptions\BsideGlobalException
* @author :liyuhang
* @method
*/
public function blog_status(){
$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);
}
return $this->success();
}
/**
* @name :逻辑删除
* @return void
* @author :liyuhang
* @method
*/
public function blog_del(){
$this->param['id'] = ['in',$this->param['id']];
$rs = $this->model->edit(['status'=>2],$this->param);
if($rs === false){
$this->fail('error',Code::USER_ERROR);
}
return $this->success();
}
}
... ...
... ... @@ -15,6 +15,22 @@ class NewsCategoryLogic extends BaseLogic
parent::__construct();
$this->model = new NewsCategoryModel();
$this->param = $this->requestAll;
}
/**
* @name :详情
* @return array
* @throws \App\Exceptions\BsideGlobalException
* @author :liyuhang
* @method
*/
public function info_news_category(){
$info = $this->model->read($this->param);
if($info === false){
$this->fail('error',Code::USER_ERROR);
}
return $this->success($info);
}
/**
* @name :添加时验证上级分类是否有商品,有则替换带当前分类下
... ... @@ -24,7 +40,7 @@ class NewsCategoryLogic extends BaseLogic
*/
public function add_news_category(){
DB::beginTransaction();
$this->param = $this->requestAll;
$this->param['project_id'] = $this->user['project_id'];
$this->param['operator_id'] = $this->user['id'];
$this->param['create_id'] = $this->user['id'];
... ... @@ -61,6 +77,36 @@ class NewsCategoryLogic extends BaseLogic
}
/**
* @name :编辑分类
* @return void
* @author :liyuhang
* @method
*/
public function edit_news_category(){
$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);
}
return $this->success();
}
/**
* @name :修改状态
* @return array
* @throws \App\Exceptions\BsideGlobalException
* @author :liyuhang
* @method
*/
public function status_news_category(){
$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);
}
return $this->success();
}
/**
* @name :删除新闻分类
* @return array
* @throws \App\Exceptions\BsideGlobalException
... ...
... ... @@ -2,9 +2,145 @@
namespace App\Http\Logic\Bside\News;
use App\Enums\Common\Code;
use App\Http\Logic\Bside\BaseLogic;
use App\Models\News\News;
use App\Models\News\NewsCategory as NewsCategoryModel;
use App\Models\RouteMap;
use Illuminate\Support\Facades\DB;
class NewsLogic extends BaseLogic
{
public function __construct()
{
parent::__construct();
$this->model = new News();
$this->param = $this->requestAll;
}
/**
* @name :获取分类列表
* @return array
* @throws \App\Exceptions\BsideGlobalException
* @author :liyuhang
* @method
*/
public function news_get_category_list(){
$this->map['status'] = 0;
$this->map['project_id'] = $this->user['project_id'];
$newsCategoryModel = new NewsCategoryModel();
$cate_list = $newsCategoryModel->list($this->map,'sort');
if($cate_list === false){
$this->fail('error',Code::USER_ERROR);
}
$list = [];
foreach ($cate_list as $v){
$v = (array)$v;
if ($v['pid'] == 0) {
$v['sub'] = _get_child($v['id'], $cate_list);
$list[] = $v;
}
}
return $this->success($list);
}
/**
* @name :添加博客
* @return void
* @author :liyuhang
* @method
*/
public function news_add(){
$this->param['create_id'] = $this->uid;
$this->param['operator_id'] = $this->uid;
$this->param['project_id'] = $this->user['project_id'];
DB::beginTransaction();
try {
$rs = $this->model->insertGetId($this->param);
RouteMap::setRoute($this->param['url'], RouteMap::SOURCE_NEWS, $rs, $this->user['project_id']);
DB::commit();
}catch (\Exception $e){
DB::rollBack();
$this->fail('error',Code::USER_ERROR);
}
//TODO::写入日志
$this->success();
}
/**
* @name :编辑
* @return void
* @throws \App\Exceptions\BsideGlobalException
* @author :liyuhang
* @method
*/
public function news_edit(){
$this->param['operator_id'] = $this->user['id'];
//多个分类按逗号隔开
$this->param['category_id'] = ','.$this->param['category_id'].',';
$rs = $this->model->edit($this->param,['id'=>$this->param['id']]);
if($rs === false){
$this->fail('error',Code::USER_ERROR);
}
//TODO::写入日志
$this->success();
}
/**
* @name :修改状态
* @return void
* @throws \App\Exceptions\BsideGlobalException
* @author :liyuhang
* @method
*/
public function news_status(){
$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);
}
//TODO::写入日志
$this->success();
}
/**
* @name :获取详情
* @return array
* @throws \App\Exceptions\BsideGlobalException
* @author :liyuhang
* @method
*/
public function news_info(){
$this->param = $this->requestAll;
$info = $this->model->read($this->param);
//获取分类名称
$info['category_id'] = explode(',',trim($info['category_id'],','));
$newsCategoryModel = new NewsCategoryModel();
$category_list = $newsCategoryModel->list(['id'=>['in',$info['category_id']]],'id',['name']);
$str = '';
foreach ($category_list as $v){
$str .= $v['name'].',';
}
$info['category_id'] = trim($str,',');
if($info === false){
$this->fail('error',Code::USER_ERROR);
}
return $this->success($info);
}
/**
* @name :逻辑删除
* @return void
* @author :liyuhang
* @method
*/
public function news_del(){
$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);
}
return $this->success();
}
}
... ...
... ... @@ -32,7 +32,13 @@ class UserLogic extends BaseLogic
//密码加密
$param['password'] = base64_encode(md5($this->param['password']));
//上传头像
<<<<<<< HEAD
$rs = $this->model->add($param);
=======
$data = $this->upload();
$this->param['image'] = $data['path'];
$rs = $this->model->add($this->param);
>>>>>>> 035a3ec52f37cac95246eaab50090ce3f6c67bb2
if($rs === false){
$this->fail('error',Code::USER_ERROR);
}
... ...
... ... @@ -96,8 +96,7 @@ class Base extends Model
public function edit($data,$condition){
$query = $this->formatQuery($condition);
$data['updated_at'] = date('Y-m-d H:i:s');
$rs = $query->update($data);
return $rs;
return $query->update($data);
}
/**
* @name : 删除数据
... ...
... ... @@ -22,7 +22,9 @@ class RouteMap extends Model
const SOURCE_PRODUCT_CATE = 'product_category';
const SOURCE_PRODUCT_KEYWORD = 'product_keyword';
//路由类型
const SOURCE_BLOG = 'blog';
const SOURCE_NEWS = 'news';
/**
* 生成路由标识
* @param $title
... ...
... ... @@ -93,21 +93,6 @@ class User extends Base
return $info;
}
//新增用户
public function adds($param){
//验证当前用户是否存在
$info = $this->read(['mobile'=>$param['mobile']]);
if($info !== false){
return false;
}
//密码加密
$param['password'] = base64_encode(md5($param['password']));
$rs = $this->add($param);
if($rs === false){
return false;
}
return true;
}
/**
* @param $param
... ...
... ... @@ -28,7 +28,8 @@
"Database\\Seeders\\": "database/seeders/"
},
"files": [
"app/Helper/helper.php"
"app/Helper/helper.php",
"app/Helper/common.php"
]
},
"autoload-dev": {
... ...
... ... @@ -128,6 +128,4 @@ Route::middleware(['bloginauth'])->group(function () {
//无需登录验证的路由组
Route::group([], function () {
Route::any('/login', [\App\Http\Controllers\Bside\ComController::class, 'login'])->name('login');
});
... ...