Merge branch 'dev' of http://47.244.231.31:8099/zhl/globalso-v6 into dev
正在显示
19 个修改的文件
包含
525 行增加
和
146 行删除
| @@ -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 { |
| @@ -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 | } |
| @@ -35,7 +35,6 @@ class BaseController extends Controller | @@ -35,7 +35,6 @@ class BaseController extends Controller | ||
| 35 | $info = Cache::get($this->token); | 35 | $info = Cache::get($this->token); |
| 36 | $this->user = $info; | 36 | $this->user = $info; |
| 37 | $this->uid = $info['id']; | 37 | $this->uid = $info['id']; |
| 38 | - $this->param['project_id'] = $this->user['project_id']; | ||
| 39 | }else{ | 38 | }else{ |
| 40 | return response(['code'=>Code::USER_ERROR,'msg'=>'当前用户未登录']); | 39 | return response(['code'=>Code::USER_ERROR,'msg'=>'当前用户未登录']); |
| 41 | } | 40 | } |
| @@ -86,14 +85,17 @@ class BaseController extends Controller | @@ -86,14 +85,17 @@ class BaseController extends Controller | ||
| 86 | case 'row': | 85 | case 'row': |
| 87 | $this->row = $v; | 86 | $this->row = $v; |
| 88 | break; | 87 | break; |
| 88 | + case "name": | ||
| 89 | + $this->map['name'] = ['like','%'.$v.'%']; | ||
| 90 | + break; | ||
| 89 | case "created_at": | 91 | case "created_at": |
| 90 | $this->_btw[0] = $v; | 92 | $this->_btw[0] = $v; |
| 91 | $this->_btw[1] = date('Y-m-d H:i:s',time()); | 93 | $this->_btw[1] = date('Y-m-d H:i:s',time()); |
| 92 | - $this->map['create_at'] = ['between', $this->_btw]; | 94 | + $this->map['created_at'] = ['between', $this->_btw]; |
| 93 | break; | 95 | break; |
| 94 | case "updated_at": | 96 | case "updated_at": |
| 95 | $this->_btw[1] = $v; | 97 | $this->_btw[1] = $v; |
| 96 | - $this->map['update_at'] = ['between', $this->_btw]; | 98 | + $this->map['updated_at'] = ['between', $this->_btw]; |
| 97 | break; | 99 | break; |
| 98 | default: | 100 | default: |
| 99 | if (!empty($v)) { | 101 | if (!empty($v)) { |
| @@ -102,7 +104,6 @@ class BaseController extends Controller | @@ -102,7 +104,6 @@ class BaseController extends Controller | ||
| 102 | break; | 104 | break; |
| 103 | } | 105 | } |
| 104 | } | 106 | } |
| 105 | - | ||
| 106 | } | 107 | } |
| 107 | /** | 108 | /** |
| 108 | * @name 统一返回参数 | 109 | * @name 统一返回参数 |
| @@ -8,6 +8,7 @@ use App\Http\Requests\Bside\News\NewsCategoryRequest; | @@ -8,6 +8,7 @@ use App\Http\Requests\Bside\News\NewsCategoryRequest; | ||
| 8 | use App\Models\News\News as NewsModel; | 8 | use App\Models\News\News as NewsModel; |
| 9 | use App\Models\News\NewsCategory as NewsCategoryModel; | 9 | use App\Models\News\NewsCategory as NewsCategoryModel; |
| 10 | use Illuminate\Http\Request; | 10 | use Illuminate\Http\Request; |
| 11 | +use Illuminate\Support\Facades\DB; | ||
| 11 | 12 | ||
| 12 | class NewsCategoryController extends BaseController | 13 | class NewsCategoryController extends BaseController |
| 13 | { | 14 | { |
| @@ -18,22 +19,64 @@ class NewsCategoryController extends BaseController | @@ -18,22 +19,64 @@ class NewsCategoryController extends BaseController | ||
| 18 | * @method | 19 | * @method |
| 19 | */ | 20 | */ |
| 20 | public function lists(NewsCategoryModel $newsCategory){ | 21 | public function lists(NewsCategoryModel $newsCategory){ |
| 22 | + //搜索条件 | ||
| 21 | $lists = $newsCategory->lists($this->map,$this->page,$this->row); | 23 | $lists = $newsCategory->lists($this->map,$this->page,$this->row); |
| 22 | $this->response('success',Code::SUCCESS,$lists); | 24 | $this->response('success',Code::SUCCESS,$lists); |
| 23 | } | 25 | } |
| 24 | 26 | ||
| 25 | /** | 27 | /** |
| 28 | + * @name :获取当前分类详情 | ||
| 29 | + * @return void | ||
| 30 | + * @author :liyuhang | ||
| 31 | + * @method | ||
| 32 | + */ | ||
| 33 | + public function info(Request $request,NewsCategoryModel $newsCategory){ | ||
| 34 | + $request->validate([ | ||
| 35 | + 'id'=>['required'] | ||
| 36 | + ],[ | ||
| 37 | + 'id.required' => 'ID不能为空' | ||
| 38 | + ]); | ||
| 39 | + $info = $newsCategory->read($this->param); | ||
| 40 | + if($info === false){ | ||
| 41 | + $this->response('error',Code::USER_ERROR); | ||
| 42 | + } | ||
| 43 | + $this->response('success',Code::SUCCESS,$info); | ||
| 44 | + } | ||
| 45 | + /** | ||
| 26 | * @name :添加分类 | 46 | * @name :添加分类 |
| 27 | * @return json | 47 | * @return json |
| 28 | * @author :liyuhang | 48 | * @author :liyuhang |
| 29 | * @method | 49 | * @method |
| 30 | */ | 50 | */ |
| 31 | - public function add(NewsCategoryRequest $request,NewsCategoryModel $newsCategory){ | 51 | + public function add(NewsCategoryRequest $request,NewsCategoryModel $newsCategory,NewsModel $news){ |
| 32 | $request->validated(); | 52 | $request->validated(); |
| 53 | + $this->param['project_id'] = $this->user['project_id']; | ||
| 54 | + $this->param['Operator_id'] = $this->uid; | ||
| 55 | + $this->param['create_id'] = $this->uid; | ||
| 56 | + DB::beginTransaction(); | ||
| 33 | $rs = $newsCategory->add($this->param); | 57 | $rs = $newsCategory->add($this->param); |
| 34 | if($rs === false){ | 58 | if($rs === false){ |
| 59 | + DB::rollBack(); | ||
| 60 | + $this->response('error',Code::USER_ERROR); | ||
| 61 | + } | ||
| 62 | + //TODO::判断当前分内是否为一级分类 | ||
| 63 | + if(isset($this->param['pid']) && !empty($this->param['pid'])){ | ||
| 64 | + //查看当前上级分类下是否有其他分类 | ||
| 65 | + $cate_info = $newsCategory->read(['pid'=>$this->param['pid'],'id'=>['!=',$newsCategory->id]]); | ||
| 66 | + if($cate_info === false){ | ||
| 67 | + //查看当前上一级分类下是否有商品 | ||
| 68 | + $news_info = $news->read(['category_id'=>$this->param['pid'],'pid'=>0]); | ||
| 69 | + if($news_info !== false){ | ||
| 70 | + //更新所有商品到当前分类 | ||
| 71 | + $rs = $news->edit(['category_id'=>$newsCategory->id],['category_id'=>$this->param['pid']]); | ||
| 72 | + if($rs === false){ | ||
| 73 | + DB::rollBack(); | ||
| 35 | $this->response('error',Code::USER_ERROR); | 74 | $this->response('error',Code::USER_ERROR); |
| 36 | } | 75 | } |
| 76 | + } | ||
| 77 | + } | ||
| 78 | + } | ||
| 79 | + DB::commit(); | ||
| 37 | $this->response('success',Code::SUCCESS); | 80 | $this->response('success',Code::SUCCESS); |
| 38 | } | 81 | } |
| 39 | 82 | ||
| @@ -49,10 +92,12 @@ class NewsCategoryController extends BaseController | @@ -49,10 +92,12 @@ class NewsCategoryController extends BaseController | ||
| 49 | ],[ | 92 | ],[ |
| 50 | 'id.required' => 'ID不能为空' | 93 | 'id.required' => 'ID不能为空' |
| 51 | ]); | 94 | ]); |
| 95 | + $this->param['Operator_id'] = $this->uid; | ||
| 52 | $rs = $newsCategory->edit($this->param,['id'=>$this->param['id']]); | 96 | $rs = $newsCategory->edit($this->param,['id'=>$this->param['id']]); |
| 53 | if($rs === false){ | 97 | if($rs === false){ |
| 54 | $this->response('error',Code::USER_ERROR); | 98 | $this->response('error',Code::USER_ERROR); |
| 55 | } | 99 | } |
| 100 | + //写入日志 | ||
| 56 | $this->response('success',Code::SUCCESS); | 101 | $this->response('success',Code::SUCCESS); |
| 57 | } | 102 | } |
| 58 | 103 | ||
| @@ -70,7 +115,8 @@ class NewsCategoryController extends BaseController | @@ -70,7 +115,8 @@ class NewsCategoryController extends BaseController | ||
| 70 | 'id.required' => 'ID不能为空', | 115 | 'id.required' => 'ID不能为空', |
| 71 | 'status.required' => 'status不能为空' | 116 | 'status.required' => 'status不能为空' |
| 72 | ]); | 117 | ]); |
| 73 | - $rs = $newsCategory->edit(['status'=>$this->param['status']],['id'=>$this->param['id']]); | 118 | + $this->param['Operator_id'] = $this->uid; |
| 119 | + $rs = $newsCategory->edit($this->param,['id'=>$this->param['id']]); | ||
| 74 | if($rs === false){ | 120 | if($rs === false){ |
| 75 | $this->response('error',Code::USER_ERROR); | 121 | $this->response('error',Code::USER_ERROR); |
| 76 | } | 122 | } |
| @@ -89,19 +135,19 @@ class NewsCategoryController extends BaseController | @@ -89,19 +135,19 @@ class NewsCategoryController extends BaseController | ||
| 89 | ],[ | 135 | ],[ |
| 90 | 'id.required' => 'ID不能为空', | 136 | 'id.required' => 'ID不能为空', |
| 91 | ]); | 137 | ]); |
| 92 | - foreach ($this->param['id'] as $k=>$v){ | 138 | + foreach ($this->param['id'] as $v){ |
| 93 | //查询是否有子分类 | 139 | //查询是否有子分类 |
| 94 | - $id = $newsCategory->read(['pid'=>$this->param['id']],['id']); | ||
| 95 | - if($id !== false){ | 140 | + $rs = $newsCategory->read(['pid'=>$v],['id']); |
| 141 | + if($rs !== false){ | ||
| 96 | $this->response('当前分类拥有子分类不允许删除',Code::USER_ERROR); | 142 | $this->response('当前分类拥有子分类不允许删除',Code::USER_ERROR); |
| 97 | } | 143 | } |
| 98 | //查看当前分内下是否有商品 | 144 | //查看当前分内下是否有商品 |
| 99 | - $news->read(['category_id'=>$this->param['id']],['id']); | ||
| 100 | - if($id !== false){ | 145 | + $rs = $news->read(['category_id'=>$v],['id']); |
| 146 | + if($rs !== false){ | ||
| 101 | $this->response('当前分类拥有商品',Code::USER_ERROR); | 147 | $this->response('当前分类拥有商品',Code::USER_ERROR); |
| 102 | } | 148 | } |
| 103 | } | 149 | } |
| 104 | - $this->param['id'] = ['in',$id]; | 150 | + $this->param['id'] = ['in',$this->param['id']]; |
| 105 | $rs = $newsCategory->del($this->param); | 151 | $rs = $newsCategory->del($this->param); |
| 106 | if($rs === false){ | 152 | if($rs === false){ |
| 107 | $this->response('error',Code::USER_ERROR); | 153 | $this->response('error',Code::USER_ERROR); |
| @@ -2,17 +2,100 @@ | @@ -2,17 +2,100 @@ | ||
| 2 | 2 | ||
| 3 | namespace App\Http\Controllers\Bside\News; | 3 | namespace App\Http\Controllers\Bside\News; |
| 4 | 4 | ||
| 5 | +use App\Enums\Common\Code; | ||
| 5 | use App\Http\Controllers\Bside\BaseController; | 6 | use App\Http\Controllers\Bside\BaseController; |
| 7 | +use App\Http\Requests\Bside\News\NewsRequest; | ||
| 8 | +use App\Models\News\News as NewsModel; | ||
| 9 | +use Illuminate\Http\Request; | ||
| 6 | 10 | ||
| 7 | class NewsController extends BaseController | 11 | class NewsController extends BaseController |
| 8 | { | 12 | { |
| 9 | /** | 13 | /** |
| 10 | * @name :获取新闻列表 | 14 | * @name :获取新闻列表 |
| 15 | + * @return json | ||
| 16 | + * @author :liyuhang | ||
| 17 | + * @method | ||
| 18 | + */ | ||
| 19 | + public function lists(NewsModel $news){ | ||
| 20 | + $lists = $news->lists($this->map,$this->page,$this->row,$this->order); | ||
| 21 | + $this->response('success',Code::SUCCESS,$lists); | ||
| 22 | + } | ||
| 23 | + | ||
| 24 | + /** | ||
| 25 | + * @name :添加分类 | ||
| 26 | + * @return json | ||
| 27 | + * @author :liyuhang | ||
| 28 | + * @method | ||
| 29 | + */ | ||
| 30 | + public function add(NewsRequest $newsRequest,NewsModel $news){ | ||
| 31 | + $newsRequest->validated(); | ||
| 32 | + $this->param['user_id'] = $this->uid; | ||
| 33 | + $this->param['Operator_id'] = $this->uid; | ||
| 34 | + $rs = $news->add($this->param); | ||
| 35 | + if($rs === false){ | ||
| 36 | + $this->response('error',Code::USER_ERROR); | ||
| 37 | + } | ||
| 38 | + $this->response('success'); | ||
| 39 | + } | ||
| 40 | + | ||
| 41 | + /** | ||
| 42 | + * @name :编辑分类 | ||
| 11 | * @return void | 43 | * @return void |
| 12 | * @author :liyuhang | 44 | * @author :liyuhang |
| 13 | * @method | 45 | * @method |
| 14 | */ | 46 | */ |
| 15 | - public function lists(){ | 47 | + public function edit(NewsRequest $newsRequest,NewsModel $news){ |
| 48 | + $newsRequest->validate([ | ||
| 49 | + 'id'=>['required'], | ||
| 50 | + ],[ | ||
| 51 | + 'id.required' => 'ID不能为空', | ||
| 52 | + ]); | ||
| 53 | + $this->param['Operator_id'] = $this->uid; | ||
| 54 | + $rs = $news->edit($this->param,['id'=>$this->param['id']]); | ||
| 55 | + if($rs === false){ | ||
| 56 | + $this->response('error',Code::USER_ERROR); | ||
| 57 | + } | ||
| 58 | + //写入日志 | ||
| 59 | + $this->response('success',Code::SUCCESS); | ||
| 60 | + } | ||
| 16 | 61 | ||
| 62 | + /** | ||
| 63 | + * @name :编辑状态/与排序 | ||
| 64 | + * @return void | ||
| 65 | + * @author :liyuhang | ||
| 66 | + * @method | ||
| 67 | + */ | ||
| 68 | + public function status(Request $request,NewsModel $news){ | ||
| 69 | + $request->validate([ | ||
| 70 | + 'id'=>['required'], | ||
| 71 | + ],[ | ||
| 72 | + 'id.required' => 'ID不能为空', | ||
| 73 | + ]); | ||
| 74 | + $this->param['Operator_id'] = $this->uid; | ||
| 75 | + $rs = $news->edit($this->param,['id'=>$this->param['id']]); | ||
| 76 | + if($rs === false){ | ||
| 77 | + $this->response('error',Code::USER_ERROR); | ||
| 78 | + } | ||
| 79 | + $this->response('success'); | ||
| 80 | + } | ||
| 81 | + /** | ||
| 82 | + * @name :删除分类 | ||
| 83 | + * @return void | ||
| 84 | + * @author :liyuhang | ||
| 85 | + * @method | ||
| 86 | + */ | ||
| 87 | + public function del(Request $request,NewsModel $news){ | ||
| 88 | + $request->validate([ | ||
| 89 | + 'id'=>['required'], | ||
| 90 | + ],[ | ||
| 91 | + 'id.required' => 'ID不能为空', | ||
| 92 | + ]); | ||
| 93 | + $this->param['id'] = ['in',$this->param['id']]; | ||
| 94 | + $rs = $news->del($this->param); | ||
| 95 | + if($rs === false){ | ||
| 96 | + $this->response('error',Code::USER_ERROR); | ||
| 97 | + } | ||
| 98 | + //TODO::清空相关资源 | ||
| 99 | + $this->response('success'); | ||
| 17 | } | 100 | } |
| 18 | } | 101 | } |
| @@ -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 | } |
| @@ -21,9 +21,9 @@ class UserController extends BaseController | @@ -21,9 +21,9 @@ class UserController extends BaseController | ||
| 21 | $this->map['project_id'] = $this->user['project_id']; | 21 | $this->map['project_id'] = $this->user['project_id']; |
| 22 | $lists = $userModel->lists($this->map,$this->page,$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']); |
| 23 | if(empty($lists)){ | 23 | if(empty($lists)){ |
| 24 | - $this->response('请求失败',Code::USER_ERROR,[]); | 24 | + $this->response('error',Code::USER_ERROR,[]); |
| 25 | } | 25 | } |
| 26 | - $this->response('列表',Code::SUCCESS,$lists); | 26 | + $this->response('success',Code::SUCCESS,$lists); |
| 27 | } | 27 | } |
| 28 | 28 | ||
| 29 | /** | 29 | /** |
| @@ -39,7 +39,7 @@ class UserController extends BaseController | @@ -39,7 +39,7 @@ class UserController extends BaseController | ||
| 39 | if($rs === false){ | 39 | if($rs === false){ |
| 40 | $this->response('当前添加用户已存在或参数错误,添加失败',Code::USER_REGISTER_ERROE,[]); | 40 | $this->response('当前添加用户已存在或参数错误,添加失败',Code::USER_REGISTER_ERROE,[]); |
| 41 | } | 41 | } |
| 42 | - $this->response('添加成功',Code::SUCCESS,[]); | 42 | + $this->response('success',Code::SUCCESS); |
| 43 | } | 43 | } |
| 44 | 44 | ||
| 45 | /** | 45 | /** |
| @@ -86,9 +86,28 @@ class UserController extends BaseController | @@ -86,9 +86,28 @@ class UserController extends BaseController | ||
| 86 | } | 86 | } |
| 87 | $this->response($this->param['status'] == 0 ? '启用成功' : '禁用成功'); | 87 | $this->response($this->param['status'] == 0 ? '启用成功' : '禁用成功'); |
| 88 | } | 88 | } |
| 89 | + | ||
| 90 | + /** | ||
| 91 | + * @name :详情 | ||
| 92 | + * @return json | ||
| 93 | + * @author :liyuhang | ||
| 94 | + * @method | ||
| 95 | + */ | ||
| 96 | + public function info(Request $request,UserModel $userModel){ | ||
| 97 | + $request->validate([ | ||
| 98 | + 'id'=>['required', new Ids()], | ||
| 99 | + ],[ | ||
| 100 | + 'id.required' => 'ID不能为空', | ||
| 101 | + ]); | ||
| 102 | + $rs = $userModel->read($this->param); | ||
| 103 | + if($rs === false){ | ||
| 104 | + $this->response('error',Code::USER_ERROR); | ||
| 105 | + } | ||
| 106 | + $this->response('success'); | ||
| 107 | + } | ||
| 89 | /** | 108 | /** |
| 90 | * @name :删除管理员 | 109 | * @name :删除管理员 |
| 91 | - * @return void | 110 | + * @return json |
| 92 | * @author :liyuhang | 111 | * @author :liyuhang |
| 93 | * @method | 112 | * @method |
| 94 | */ | 113 | */ |
| @@ -100,8 +119,8 @@ class UserController extends BaseController | @@ -100,8 +119,8 @@ class UserController extends BaseController | ||
| 100 | ]); | 119 | ]); |
| 101 | $rs = $userModel->del($this->param); | 120 | $rs = $userModel->del($this->param); |
| 102 | if($rs === false){ | 121 | if($rs === false){ |
| 103 | - $this->response('删除失败',Code::USER_ERROR); | 122 | + $this->response('error',Code::USER_ERROR); |
| 104 | } | 123 | } |
| 105 | - $this->response('删除成功'); | 124 | + $this->response('success'); |
| 106 | } | 125 | } |
| 107 | } | 126 | } |
| @@ -16,11 +16,15 @@ class BaseLogic | @@ -16,11 +16,15 @@ class BaseLogic | ||
| 16 | 16 | ||
| 17 | protected $requestAll; | 17 | protected $requestAll; |
| 18 | 18 | ||
| 19 | + protected $user; | ||
| 20 | + | ||
| 19 | protected $is_cache = true; //是否缓存数据 | 21 | protected $is_cache = true; //是否缓存数据 |
| 20 | 22 | ||
| 21 | public function __construct() | 23 | public function __construct() |
| 22 | { | 24 | { |
| 23 | $this->requestAll = request()->all(); | 25 | $this->requestAll = request()->all(); |
| 26 | + | ||
| 27 | + $this->user = Cache::get(request()->header('token')); | ||
| 24 | } | 28 | } |
| 25 | 29 | ||
| 26 | /** | 30 | /** |
| @@ -57,6 +61,7 @@ class BaseLogic | @@ -57,6 +61,7 @@ class BaseLogic | ||
| 57 | */ | 61 | */ |
| 58 | public function getList(array $map = [], array $sort = ['id' => 'desc'], array $columns = ['*'], int $limit = 20) | 62 | public function getList(array $map = [], array $sort = ['id' => 'desc'], array $columns = ['*'], int $limit = 20) |
| 59 | { | 63 | { |
| 64 | + $map[] = ['project_id' => $this->user['project_id']]; | ||
| 60 | // 闭包查询条件格式化 | 65 | // 闭包查询条件格式化 |
| 61 | $query = $this->formatQuery($map); | 66 | $query = $this->formatQuery($map); |
| 62 | 67 | ||
| @@ -112,6 +117,9 @@ class BaseLogic | @@ -112,6 +117,9 @@ class BaseLogic | ||
| 112 | }else{ | 117 | }else{ |
| 113 | $info = $this->model->find($id); | 118 | $info = $this->model->find($id); |
| 114 | } | 119 | } |
| 120 | + if($info && $info['project_id'] != $this->user['project_id']) { | ||
| 121 | + $info = null; | ||
| 122 | + } | ||
| 115 | return $info; | 123 | return $info; |
| 116 | } | 124 | } |
| 117 | 125 | ||
| @@ -162,6 +170,8 @@ class BaseLogic | @@ -162,6 +170,8 @@ class BaseLogic | ||
| 162 | $this->fail('ID不能为空'); | 170 | $this->fail('ID不能为空'); |
| 163 | } | 171 | } |
| 164 | $map[] = ['id', 'in', $ids]; | 172 | $map[] = ['id', 'in', $ids]; |
| 173 | + $map[] = ['project_id' => $this->user['project_id']]; | ||
| 174 | + | ||
| 165 | $res = $this->formatQuery($map)->delete(); | 175 | $res = $this->formatQuery($map)->delete(); |
| 166 | if($res){ | 176 | if($res){ |
| 167 | 177 |
| @@ -25,6 +25,9 @@ class AttrLogic extends BaseLogic | @@ -25,6 +25,9 @@ class AttrLogic extends BaseLogic | ||
| 25 | 25 | ||
| 26 | public function getInfo($id){ | 26 | public function getInfo($id){ |
| 27 | $info = parent::getCacheInfo($id); | 27 | $info = parent::getCacheInfo($id); |
| 28 | + if(!$info){ | ||
| 29 | + $this->fail('数据不存在或者已经删除'); | ||
| 30 | + } | ||
| 28 | $info->values; | 31 | $info->values; |
| 29 | return $this->success($info->toArray()); | 32 | return $this->success($info->toArray()); |
| 30 | } | 33 | } |
| @@ -62,17 +65,4 @@ class AttrLogic extends BaseLogic | @@ -62,17 +65,4 @@ class AttrLogic extends BaseLogic | ||
| 62 | } | 65 | } |
| 63 | return $this->success(); | 66 | return $this->success(); |
| 64 | } | 67 | } |
| 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 | } | 68 | } |
| @@ -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 |
| @@ -45,8 +46,10 @@ class CategoryLogic extends BaseLogic | @@ -45,8 +46,10 @@ class CategoryLogic extends BaseLogic | ||
| 45 | if(Category::where('pid', $id)->count()){ | 46 | if(Category::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(); |
| @@ -39,17 +40,22 @@ class KeywordLogic extends BaseLogic | @@ -39,17 +40,22 @@ class KeywordLogic extends BaseLogic | ||
| 39 | 40 | ||
| 40 | public function delete($ids){ | 41 | public function delete($ids){ |
| 41 | $ids= array_filter(Arr::splitFilterToArray($ids), 'intval'); | 42 | $ids= array_filter(Arr::splitFilterToArray($ids), 'intval'); |
| 42 | - foreach ($ids as $id){ | ||
| 43 | - $info = $this->getCacheInfo($id); | ||
| 44 | - if(!$info){ | ||
| 45 | - continue; | ||
| 46 | - } | ||
| 47 | 43 | ||
| 48 | - //todo 是否有关联商品 | 44 | + DB::beginTransaction(); |
| 45 | + try { | ||
| 46 | + parent::delete($ids); | ||
| 49 | 47 | ||
| 50 | - //todo 删除路由映射 事务 | 48 | + foreach ($ids as $id){ |
| 49 | + //删除路由映射 | ||
| 50 | + RouteMap::delRoute(RouteMap::SOURCE_PRODUCT_KEYWORD, $id, $this->user['project_id']); | ||
| 51 | + } | ||
| 51 | 52 | ||
| 53 | + DB::commit(); | ||
| 54 | + }catch (\Exception $e){ | ||
| 55 | + DB::rollBack(); | ||
| 56 | + $this->fail('删除失败'); | ||
| 52 | } | 57 | } |
| 53 | - return parent::delete($ids); | 58 | + |
| 59 | + return $this->success(); | ||
| 54 | } | 60 | } |
| 55 | } | 61 | } |
| @@ -5,6 +5,8 @@ namespace App\Http\Logic\Bside\Product; | @@ -5,6 +5,8 @@ namespace App\Http\Logic\Bside\Product; | ||
| 5 | use App\Helper\Arr; | 5 | use App\Helper\Arr; |
| 6 | use App\Http\Logic\Bside\BaseLogic; | 6 | use App\Http\Logic\Bside\BaseLogic; |
| 7 | use App\Models\Product\Product; | 7 | use App\Models\Product\Product; |
| 8 | +use App\Models\RouteMap; | ||
| 9 | +use Illuminate\Support\Facades\DB; | ||
| 8 | 10 | ||
| 9 | /** | 11 | /** |
| 10 | * Class ProductLogic | 12 | * Class ProductLogic |
| @@ -22,32 +24,39 @@ class ProductLogic extends BaseLogic | @@ -22,32 +24,39 @@ class ProductLogic extends BaseLogic | ||
| 22 | } | 24 | } |
| 23 | 25 | ||
| 24 | public function save($param){ | 26 | public function save($param){ |
| 25 | - if(!empty($param['pid'])){ | ||
| 26 | - if(!empty($param['id']) && $param['pid'] == $param['id']){ | ||
| 27 | - $this->fail('上级分类不能是本分类'); | ||
| 28 | - } | ||
| 29 | - $p_cate = Product::find($param['pid']); | ||
| 30 | - if(!$p_cate){ | ||
| 31 | - $this->fail('上级分类不存在'); | ||
| 32 | - } | ||
| 33 | - } | ||
| 34 | - return parent::save($param); | 27 | + DB::beginTransaction(); |
| 28 | + try { | ||
| 29 | + $data = $param; | ||
| 30 | + unset($data['route']); | ||
| 31 | + $res = parent::save($data); | ||
| 32 | + //路由映射 | ||
| 33 | + RouteMap::setRoute($param['route'], RouteMap::SOURCE_PRODUCT, $res['id'], $this->user['project_id']); | ||
| 34 | + DB::commit(); | ||
| 35 | + }catch (\Exception $e){ | ||
| 36 | + DB::rollBack(); | ||
| 37 | + $this->fail('保存失败'); | ||
| 38 | + } | ||
| 39 | + return $this->success(); | ||
| 35 | } | 40 | } |
| 36 | 41 | ||
| 37 | public function delete($ids){ | 42 | public function delete($ids){ |
| 38 | $ids= array_filter(Arr::splitFilterToArray($ids), 'intval'); | 43 | $ids= array_filter(Arr::splitFilterToArray($ids), 'intval'); |
| 44 | + | ||
| 45 | + DB::beginTransaction(); | ||
| 46 | + try { | ||
| 47 | + parent::delete($ids); | ||
| 48 | + | ||
| 39 | foreach ($ids as $id){ | 49 | foreach ($ids as $id){ |
| 40 | - $info = $this->getCacheInfo($id); | ||
| 41 | - if(!$info){ | ||
| 42 | - continue; | ||
| 43 | - } | ||
| 44 | - //是否有子分类 | ||
| 45 | - if(Product::where('pid', $id)->count()){ | ||
| 46 | - $this->fail("分类{$info['title']}存在子分类,不能删除"); | 50 | + //删除路由映射 |
| 51 | + RouteMap::delRoute(RouteMap::SOURCE_PRODUCT, $id, $this->user['project_id']); | ||
| 47 | } | 52 | } |
| 48 | - //todo 是否有对应商品 | ||
| 49 | 53 | ||
| 54 | + DB::commit(); | ||
| 55 | + }catch (\Exception $e){ | ||
| 56 | + DB::rollBack(); | ||
| 57 | + $this->fail('删除失败'); | ||
| 50 | } | 58 | } |
| 51 | - return parent::delete($ids); | 59 | + |
| 60 | + return $this->success(); | ||
| 52 | } | 61 | } |
| 53 | } | 62 | } |
| @@ -2,7 +2,12 @@ | @@ -2,7 +2,12 @@ | ||
| 2 | 2 | ||
| 3 | namespace App\Http\Requests\Bside\product; | 3 | namespace App\Http\Requests\Bside\product; |
| 4 | 4 | ||
| 5 | +use App\Enums\Common\Code; | ||
| 6 | +use App\Exceptions\BsideGlobalException; | ||
| 7 | +use App\Helper\Arr; | ||
| 8 | +use App\Models\Product\Product; | ||
| 5 | use Illuminate\Foundation\Http\FormRequest; | 9 | use Illuminate\Foundation\Http\FormRequest; |
| 10 | +use Illuminate\Validation\Rule; | ||
| 6 | 11 | ||
| 7 | /** | 12 | /** |
| 8 | * Class ProductRequest | 13 | * Class ProductRequest |
| @@ -30,23 +35,74 @@ class ProductRequest extends FormRequest | @@ -30,23 +35,74 @@ class ProductRequest extends FormRequest | ||
| 30 | public function rules() | 35 | public function rules() |
| 31 | { | 36 | { |
| 32 | return [ | 37 | return [ |
| 33 | - 'title'=>'required|max:20', | ||
| 34 | - 'image'=>'required', | ||
| 35 | - 'keywords'=>'required|max:50', | ||
| 36 | - 'describe'=>'required|max:200', | 38 | + 'title' => 'required|max:200', |
| 39 | + 'route' => 'required|max:100', | ||
| 40 | + 'gallery' => ['required', 'array', function ($attribute, $value, $fail) { | ||
| 41 | + foreach ($value as $v) { | ||
| 42 | + if (empty($v['url'])) { | ||
| 43 | + $fail('图片链接不能为空'); | ||
| 44 | + } | ||
| 45 | + } | ||
| 46 | + }], | ||
| 47 | + 'attrs' => ['required', 'array', function ($attribute, $value, $fail) { | ||
| 48 | + foreach ($value as $v) { | ||
| 49 | + if (empty($v['key'])) { | ||
| 50 | + $fail('产品属性名不能为空'); | ||
| 51 | + } | ||
| 52 | + if (empty($v['value'])) { | ||
| 53 | + $fail('产品属性值不能为空'); | ||
| 54 | + } | ||
| 55 | + } | ||
| 56 | + }], | ||
| 57 | + 'category_id' => 'required', | ||
| 58 | + 'keywords' => 'required', | ||
| 59 | + 'intro' => 'required|max:500', | ||
| 60 | + 'content' => 'required', | ||
| 61 | + 'describe' => 'required|array', | ||
| 62 | + 'seo_mate' => ['required', 'array', function ($attribute, $value, $fail) { | ||
| 63 | + if(empty($value['title'])){ | ||
| 64 | + $fail('SEO标题不能为空'); | ||
| 65 | + } | ||
| 66 | + if(empty($value['description'])){ | ||
| 67 | + $fail('SEO描述不能为空'); | ||
| 68 | + } | ||
| 69 | + if(empty($value['keyword'])){ | ||
| 70 | + $fail('SEO关键词不能为空'); | ||
| 71 | + } | ||
| 72 | + }], | ||
| 73 | + 'related_product_id' => ['required', function ($attribute, $value, $fail) { | ||
| 74 | + $value = array_filter(Arr::splitFilterToArray($value), 'intval'); | ||
| 75 | + if(count($value) > 16){ | ||
| 76 | + $fail('关联产品不能超过16个'); | ||
| 77 | + } | ||
| 78 | + }], | ||
| 79 | + 'status' => ['required', Rule::in(array_keys(Product::statusMap()))], | ||
| 37 | ]; | 80 | ]; |
| 38 | } | 81 | } |
| 39 | 82 | ||
| 40 | public function messages() | 83 | public function messages() |
| 41 | { | 84 | { |
| 42 | return [ | 85 | return [ |
| 43 | - 'title.required' => '请输入分类名称', | ||
| 44 | - 'title.max' => '分类名称不能超过20个字符', | ||
| 45 | - 'image.required' => '请上传分类图片', | ||
| 46 | - 'keywords.required' => '请输入分类关键词', | ||
| 47 | - 'keywords.max' => '分类关键词不能超过50个字符', | ||
| 48 | - 'describe.required' => '请输入分类描述', | ||
| 49 | - 'describe.max' => '分类描述不能超过200个字符', | 86 | + 'title.required' => '请输入产品标题', |
| 87 | + 'title.max' => '产品标题不能超过20个字符', | ||
| 88 | + 'route.required' => '请输入产品链接', | ||
| 89 | + 'route.max' => '产品链接不能超过100个字符', | ||
| 90 | + 'gallery.required' => '请上传产品图片', | ||
| 91 | + 'gallery.array' => '产品图片格式异常', | ||
| 92 | + 'attrs.required' => '请添加产品参数', | ||
| 93 | + 'attrs.array' => '产品参数格式异常', | ||
| 94 | + 'category_id.required' => '请选择分类', | ||
| 95 | + 'keywords.required' => '请添加关键词标签', | ||
| 96 | + 'intro.required' => '请输入短描述', | ||
| 97 | + 'intro.max' => '短描述不能超过20个字符', | ||
| 98 | + 'content.required' => '请输入产品描述', | ||
| 99 | + 'describe.required' => '请添加描述切换栏', | ||
| 100 | + 'describe.array' => '描述切换栏格式异常', | ||
| 101 | + 'seo_mate.required' => '请输入SEO', | ||
| 102 | + 'seo_mate.array' => 'SEO格式异常', | ||
| 103 | + 'related_product_id.required' => '请选择相关产品', | ||
| 104 | + 'status.required' => '请选择产品状态', | ||
| 105 | + 'status.in' => '产品状态值异常', | ||
| 50 | ]; | 106 | ]; |
| 51 | } | 107 | } |
| 52 | 108 |
| @@ -125,46 +125,41 @@ class Base extends Model | @@ -125,46 +125,41 @@ class Base extends Model | ||
| 125 | $query->where($k,$v); | 125 | $query->where($k,$v); |
| 126 | continue; | 126 | continue; |
| 127 | } | 127 | } |
| 128 | - foreach ($v as $k1 => $v1){ | ||
| 129 | - if(!is_array($v1)){ | ||
| 130 | - $query->where($k1,$v1); | ||
| 131 | - continue; | ||
| 132 | - } | ||
| 133 | - switch ($v1[0]){ | 128 | + switch ($v[0]){ |
| 134 | case 'like': | 129 | case 'like': |
| 135 | // like查询 ['name|title'=> ['like','%a%']] | 130 | // like查询 ['name|title'=> ['like','%a%']] |
| 136 | - if (strpos($k1, '|') !== false) { | ||
| 137 | - $query->where(function ($query) use ($k1,$v1) { | ||
| 138 | - $item = explode('|', $k1); | 131 | + if (strpos($k, '|') !== false) { |
| 132 | + $query->where(function ($query) use ($k,$v) { | ||
| 133 | + $item = explode('|', $k); | ||
| 139 | foreach ($item as $vo) { | 134 | foreach ($item as $vo) { |
| 140 | - $query->orWhere($vo, $v1[0], $v1[1]); | 135 | + $query->orWhere($vo, $v[0], $v[1]); |
| 141 | } | 136 | } |
| 142 | }); | 137 | }); |
| 143 | } else { | 138 | } else { |
| 144 | - $query->where($k1,$v1[0], $v1[1]); | 139 | + $query->where($k, $v[0], $v[1]); |
| 145 | } | 140 | } |
| 146 | break; | 141 | break; |
| 147 | case 'in': | 142 | case 'in': |
| 148 | - // in查询 ['id'=>['in'=>[1,2,3]]] | ||
| 149 | - $query->whereIn($k1, $v1[1]); | 143 | + // in查询 ['id'=>['in',[1,2,3]]] |
| 144 | + $query->whereIn($k, $v[1]); | ||
| 150 | break; | 145 | break; |
| 151 | case 'no in': | 146 | case 'no in': |
| 152 | - // in查询 ['id'=>['not in'=>[1,2,3]]] | ||
| 153 | - $query->whereNotIn($k1, $v1[1]); | 147 | + // in查询 ['id'=>['not in',[1,2,3]]] |
| 148 | + $query->whereNotIn($k, $v[1]); | ||
| 154 | break; | 149 | break; |
| 155 | case 'between': | 150 | case 'between': |
| 156 | - // in查询 ['id'=>['between'=>[create1,create2]]] | ||
| 157 | - $query->whereBetween($k1, $v1[1]); | 151 | + // in查询 ['id'=>['between',[create1,create2]]] |
| 152 | + $query->whereBetween($k, $v[1]); | ||
| 158 | case 'not between': | 153 | case 'not between': |
| 159 | - // not between查询 ['created_at'=>['not between'=>['xxx', 'xxx]]] | ||
| 160 | - $query->whereNotBetween($k1, $v1[1]); | 154 | + // not between查询 ['created_at'=>['not between',['xxx', 'xxx]]] |
| 155 | + $query->whereNotBetween($k, $v[1]); | ||
| 161 | break; | 156 | break; |
| 162 | default: | 157 | default: |
| 163 | - $query->where($k1,$v1[0],$v1[1]); | 158 | + $query->where($k,$v[0],$v[1]); |
| 164 | break; | 159 | break; |
| 165 | } | 160 | } |
| 166 | } | 161 | } |
| 167 | - } | 162 | + |
| 168 | }); | 163 | }); |
| 169 | return $query; | 164 | return $query; |
| 170 | } | 165 | } |
| @@ -2,6 +2,7 @@ | @@ -2,6 +2,7 @@ | ||
| 2 | 2 | ||
| 3 | namespace App\Models\Product; | 3 | namespace App\Models\Product; |
| 4 | 4 | ||
| 5 | +use App\Helper\Arr; | ||
| 5 | use App\Models\Base; | 6 | use App\Models\Base; |
| 6 | use Illuminate\Database\Eloquent\SoftDeletes; | 7 | use Illuminate\Database\Eloquent\SoftDeletes; |
| 7 | 8 | ||
| @@ -12,4 +13,81 @@ class Product extends Base | @@ -12,4 +13,81 @@ class Product extends Base | ||
| 12 | //设置关联表名 | 13 | //设置关联表名 |
| 13 | protected $table = 'gl_product'; | 14 | protected $table = 'gl_product'; |
| 14 | 15 | ||
| 16 | + const STATUS_DRAFT = 0; | ||
| 17 | + const STATUS_ON = 1; | ||
| 18 | + const STATUS_OFF = 2; | ||
| 19 | + | ||
| 20 | + | ||
| 21 | + public static function statusMap(){ | ||
| 22 | + return [ | ||
| 23 | + self::STATUS_DRAFT => '草稿', | ||
| 24 | + self::STATUS_ON => '已上架', | ||
| 25 | + self::STATUS_OFF => '未上架', | ||
| 26 | + ]; | ||
| 27 | + } | ||
| 28 | + | ||
| 29 | + public function setThumbAttribute($value){ | ||
| 30 | + $this->attributes['thumb'] = Arr::a2s($value); | ||
| 31 | + } | ||
| 32 | + | ||
| 33 | + public function getThumbAttribute($value){ | ||
| 34 | + return Arr::s2a($value); | ||
| 35 | + } | ||
| 36 | + | ||
| 37 | + public function setGalleryAttribute($value){ | ||
| 38 | + $this->attributes['gallery'] = Arr::a2s($value); | ||
| 39 | + } | ||
| 40 | + | ||
| 41 | + public function getGalleryAttribute($value){ | ||
| 42 | + return Arr::s2a($value); | ||
| 43 | + } | ||
| 44 | + | ||
| 45 | + public function setAttrsAttribute($value){ | ||
| 46 | + $this->attributes['attrs'] = Arr::a2s($value); | ||
| 47 | + } | ||
| 48 | + | ||
| 49 | + public function getAttrsAttribute($value){ | ||
| 50 | + return Arr::s2a($value); | ||
| 51 | + } | ||
| 52 | + | ||
| 53 | + public function setDescribeAttribute($value){ | ||
| 54 | + $this->attributes['describe'] = Arr::a2s($value); | ||
| 55 | + } | ||
| 56 | + | ||
| 57 | + public function getDescribeAttribute($value){ | ||
| 58 | + return Arr::s2a($value); | ||
| 59 | + } | ||
| 60 | + | ||
| 61 | + public function setSeoMateAttribute($value){ | ||
| 62 | + $this->attributes['seo_mate'] = Arr::a2s($value); | ||
| 63 | + } | ||
| 64 | + | ||
| 65 | + public function getSeoMateAttribute($value){ | ||
| 66 | + return Arr::s2a($value); | ||
| 67 | + } | ||
| 68 | + | ||
| 69 | + public function setCategoryIdAttribute($value){ | ||
| 70 | + $this->attributes['category_id'] = Arr::arrToSet($value); | ||
| 71 | + } | ||
| 72 | + | ||
| 73 | + public function getCategoryIdAttribute($value){ | ||
| 74 | + return Arr::setToArr($value); | ||
| 75 | + } | ||
| 76 | + | ||
| 77 | + public function setKeywordsAttribute($value){ | ||
| 78 | + $this->attributes['keywords'] = Arr::arrToSet($value, 'trim'); | ||
| 79 | + } | ||
| 80 | + | ||
| 81 | + public function getKeywordsAttribute($value){ | ||
| 82 | + return Arr::setToArr($value, 'trim'); | ||
| 83 | + } | ||
| 84 | + | ||
| 85 | + public function setRelatedProductIdAttribute($value){ | ||
| 86 | + $this->attributes['related_product_id'] = Arr::arrToSet($value); | ||
| 87 | + } | ||
| 88 | + | ||
| 89 | + public function getRelatedProductIdAttribute($value){ | ||
| 90 | + return Arr::setToArr($value); | ||
| 91 | + } | ||
| 92 | + | ||
| 15 | } | 93 | } |
| @@ -74,18 +74,13 @@ class RouteMap extends Model | @@ -74,18 +74,13 @@ class RouteMap extends Model | ||
| 74 | * @param $source | 74 | * @param $source |
| 75 | * @param $source_id | 75 | * @param $source_id |
| 76 | * @param int $project_id | 76 | * @param int $project_id |
| 77 | - * @param bool $auto | ||
| 78 | * @return bool | 77 | * @return bool |
| 79 | * @throws \Exception | 78 | * @throws \Exception |
| 80 | * @author zbj | 79 | * @author zbj |
| 81 | * @date 2023/4/17 | 80 | * @date 2023/4/17 |
| 82 | */ | 81 | */ |
| 83 | - public static function setRoute($title, $source, $source_id, $project_id = 0, $auto=false){ | ||
| 84 | - $route = $title; | ||
| 85 | - | ||
| 86 | - if($auto){ | 82 | + public static function setRoute($title, $source, $source_id, $project_id = 0){ |
| 87 | $route = self::generateRoute($title, $source, $source_id, $project_id); | 83 | $route = self::generateRoute($title, $source, $source_id, $project_id); |
| 88 | - } | ||
| 89 | if(!$route){ | 84 | if(!$route){ |
| 90 | throw new \Exception('路由不能为空'); | 85 | throw new \Exception('路由不能为空'); |
| 91 | } | 86 | } |
| @@ -150,7 +145,7 @@ class RouteMap extends Model | @@ -150,7 +145,7 @@ class RouteMap extends Model | ||
| 150 | * @author zbj | 145 | * @author zbj |
| 151 | * @date 2023/4/17 | 146 | * @date 2023/4/17 |
| 152 | */ | 147 | */ |
| 153 | - public function delRoute($source, $source_id, $project_id){ | 148 | + public static function delRoute($source, $source_id, $project_id){ |
| 154 | return self::where('project_id', $project_id)->where('source', $source)->where('source_id', $source_id)->delete(); | 149 | return self::where('project_id', $project_id)->where('source', $source)->where('source_id', $source_id)->delete(); |
| 155 | } | 150 | } |
| 156 | } | 151 | } |
| @@ -2,6 +2,7 @@ | @@ -2,6 +2,7 @@ | ||
| 2 | namespace App\Utils; | 2 | namespace App\Utils; |
| 3 | 3 | ||
| 4 | use App\Enums\Common\Common; | 4 | use App\Enums\Common\Common; |
| 5 | +use App\Helper\Arr; | ||
| 5 | use Illuminate\Support\Facades\Log; | 6 | use Illuminate\Support\Facades\Log; |
| 6 | use Illuminate\Support\Facades\Route; | 7 | use Illuminate\Support\Facades\Route; |
| 7 | 8 | ||
| @@ -17,7 +18,12 @@ class LogUtils | @@ -17,7 +18,12 @@ class LogUtils | ||
| 17 | public static function error($title, $params = [], $response = []) | 18 | public static function error($title, $params = [], $response = []) |
| 18 | { | 19 | { |
| 19 | $route=Route::current(); | 20 | $route=Route::current(); |
| 20 | - $side=$route->action['prefix']??Common::A; | 21 | + if(!empty($route->action['prefix'])){ |
| 22 | + $prefix = Arr::splitFilterToArray($route->action['prefix'], 'trim', '/'); | ||
| 23 | + $side = $prefix[0]; | ||
| 24 | + }else{ | ||
| 25 | + $side = Common::A; | ||
| 26 | + } | ||
| 21 | $params = is_array($params) ? json_encode($params, JSON_UNESCAPED_UNICODE) : $params; | 27 | $params = is_array($params) ? json_encode($params, JSON_UNESCAPED_UNICODE) : $params; |
| 22 | $response = is_array($response) || is_object($response) ? json_encode($response, JSON_UNESCAPED_UNICODE) : $response; | 28 | $response = is_array($response) || is_object($response) ? json_encode($response, JSON_UNESCAPED_UNICODE) : $response; |
| 23 | Log::channel($side.'side')->error("$title::请求参数:$params--------响应:$response"); | 29 | Log::channel($side.'side')->error("$title::请求参数:$params--------响应:$response"); |
| @@ -33,7 +39,12 @@ class LogUtils | @@ -33,7 +39,12 @@ class LogUtils | ||
| 33 | public static function info($title, $params = [], $response = []) | 39 | public static function info($title, $params = [], $response = []) |
| 34 | { | 40 | { |
| 35 | $route=Route::current(); | 41 | $route=Route::current(); |
| 36 | - $side=$route->action['prefix']??Common::A; | 42 | + if(!empty($route->action['prefix'])){ |
| 43 | + $prefix = Arr::splitFilterToArray($route->action['prefix'], 'trim', '/'); | ||
| 44 | + $side = $prefix[0]; | ||
| 45 | + }else{ | ||
| 46 | + $side = Common::A; | ||
| 47 | + } | ||
| 37 | $params = is_array($params) ? json_encode($params, JSON_UNESCAPED_UNICODE) : $params; | 48 | $params = is_array($params) ? json_encode($params, JSON_UNESCAPED_UNICODE) : $params; |
| 38 | $response = is_array($response) || is_object($response) ? json_encode($response, JSON_UNESCAPED_UNICODE) : $response; | 49 | $response = is_array($response) || is_object($response) ? json_encode($response, JSON_UNESCAPED_UNICODE) : $response; |
| 39 | Log::channel($side.'side')->info("$title::请求参数:$params--------响应:$response"); | 50 | Log::channel($side.'side')->info("$title::请求参数:$params--------响应:$response"); |
| @@ -14,32 +14,55 @@ Route::middleware(['bloginauth'])->group(function () { | @@ -14,32 +14,55 @@ Route::middleware(['bloginauth'])->group(function () { | ||
| 14 | //获取当前登录用户项目详情 | 14 | //获取当前登录用户项目详情 |
| 15 | Route::any('/get_project', [\App\Http\Controllers\Bside\ComController::class, 'get_project'])->name('get_project'); | 15 | Route::any('/get_project', [\App\Http\Controllers\Bside\ComController::class, 'get_project'])->name('get_project'); |
| 16 | //用户相关路由 | 16 | //用户相关路由 |
| 17 | - Route::any('/user/add', [\App\Http\Controllers\Bside\UserController::class, 'add'])->name('user_add'); | ||
| 18 | - Route::any('/user/edit', [\App\Http\Controllers\Bside\UserController::class, 'edit'])->name('user_edit'); | ||
| 19 | - Route::any('/user/status', [\App\Http\Controllers\Bside\UserController::class, 'status'])->name('user_status'); | ||
| 20 | - Route::any('/user/lists', [\App\Http\Controllers\Bside\UserController::class, 'lists'])->name('user_lists'); | ||
| 21 | - Route::any('/user/del', [\App\Http\Controllers\Bside\UserController::class, 'del'])->name('user_del'); | 17 | + Route::prefix('user')->group(function () { |
| 18 | + Route::any('/', [\App\Http\Controllers\Bside\UserController::class, 'lists'])->name('user_lists'); | ||
| 19 | + Route::any('/add', [\App\Http\Controllers\Bside\UserController::class, 'add'])->name('user_add'); | ||
| 20 | + Route::any('/edit', [\App\Http\Controllers\Bside\UserController::class, 'edit'])->name('user_edit'); | ||
| 21 | + Route::any('/status', [\App\Http\Controllers\Bside\UserController::class, 'status'])->name('user_status'); | ||
| 22 | + Route::any('/info', [\App\Http\Controllers\Bside\UserController::class, 'info'])->name('user_info'); | ||
| 23 | + Route::any('/del', [\App\Http\Controllers\Bside\UserController::class, 'del'])->name('user_del'); | ||
| 24 | + }); | ||
| 25 | + | ||
| 22 | //用户角色相关路由 | 26 | //用户角色相关路由 |
| 23 | - Route::any('/project_role/lists', [\App\Http\Controllers\Bside\ProjectRoleController::class, 'lists'])->name('project_role_lists'); | ||
| 24 | - Route::any('/project_role/get_role_menu', [\App\Http\Controllers\Bside\ProjectRoleController::class, 'get_role_menu'])->name('project_get_role_add'); | ||
| 25 | - Route::any('/project_role/add', [\App\Http\Controllers\Bside\ProjectRoleController::class, 'add'])->name('project_role_add'); | ||
| 26 | - Route::any('/project_role/edit', [\App\Http\Controllers\Bside\ProjectRoleController::class, 'edit'])->name('project_role_edit'); | ||
| 27 | - Route::any('/project_role/status', [\App\Http\Controllers\Bside\ProjectRoleController::class, 'status'])->name('project_role_status'); | ||
| 28 | - Route::any('/project_role/del', [\App\Http\Controllers\Bside\ProjectRoleController::class, 'del'])->name('project_role_del'); | 27 | + Route::prefix('role')->group(function () { |
| 28 | + Route::any('/', [\App\Http\Controllers\Bside\ProjectRoleController::class, 'lists'])->name('project_role_lists'); | ||
| 29 | + Route::any('/get_role_menu', [\App\Http\Controllers\Bside\ProjectRoleController::class, 'get_role_menu'])->name('project_get_role_add'); | ||
| 30 | + Route::any('/add', [\App\Http\Controllers\Bside\ProjectRoleController::class, 'add'])->name('project_role_add'); | ||
| 31 | + Route::any('/edit', [\App\Http\Controllers\Bside\ProjectRoleController::class, 'edit'])->name('project_role_edit'); | ||
| 32 | + Route::any('/info', [\App\Http\Controllers\Bside\ProjectRoleController::class, 'status'])->name('project_role_info'); | ||
| 33 | + Route::any('/status', [\App\Http\Controllers\Bside\ProjectRoleController::class, 'status'])->name('project_role_status'); | ||
| 34 | + Route::any('/del', [\App\Http\Controllers\Bside\ProjectRoleController::class, 'del'])->name('project_role_del'); | ||
| 35 | + }); | ||
| 29 | 36 | ||
| 30 | - //group相关路由 | ||
| 31 | - Route::any('/project_group/add', [\App\Http\Controllers\Bside\ProjectGroupController::class, 'add'])->name('project_group_add'); | ||
| 32 | - Route::any('/project_group/edit', [\App\Http\Controllers\Bside\ProjectGroupController::class, 'edit'])->name('project_group_edit'); | ||
| 33 | - Route::any('/project_group/lists', [\App\Http\Controllers\Bside\ProjectGroupController::class, 'lists'])->name('project_group_lists'); | ||
| 34 | - Route::any('/project_group/del', [\App\Http\Controllers\Bside\ProjectGroupController::class, 'del'])->name('project_group_del'); | ||
| 35 | - Route::any('/project_group/get_user_lists', [\App\Http\Controllers\Bside\ProjectGroupController::class, 'get_user_lists'])->name('project_group_get_user_lists'); | 37 | + //group相关路 |
| 38 | + Route::prefix('group')->group(function () { | ||
| 39 | + Route::any('/', [\App\Http\Controllers\Bside\ProjectGroupController::class, 'lists'])->name('project_group_lists'); | ||
| 40 | + Route::any('/add', [\App\Http\Controllers\Bside\ProjectGroupController::class, 'add'])->name('project_group_add'); | ||
| 41 | + Route::any('/edit', [\App\Http\Controllers\Bside\ProjectGroupController::class, 'edit'])->name('project_group_edit'); | ||
| 42 | + Route::any('/info', [\App\Http\Controllers\Bside\ProjectGroupController::class, 'info'])->name('project_group_info'); | ||
| 43 | + Route::any('/del', [\App\Http\Controllers\Bside\ProjectGroupController::class, 'del'])->name('project_group_del'); | ||
| 44 | + Route::any('/get_user_lists', [\App\Http\Controllers\Bside\ProjectGroupController::class, 'get_user_lists'])->name('project_group_get_user_lists'); | ||
| 45 | + }); | ||
| 46 | + | ||
| 47 | + //新闻相关路由 | ||
| 48 | + Route::prefix('news')->group(function () { | ||
| 49 | + //分类 | ||
| 50 | + Route::any('/category/add', [\App\Http\Controllers\Bside\News\NewsCategoryController::class, 'add'])->name('news_category_add'); | ||
| 51 | + Route::any('/category/info', [\App\Http\Controllers\Bside\News\NewsCategoryController::class, 'info'])->name('news_category_info'); | ||
| 52 | + Route::any('/category/edit', [\App\Http\Controllers\Bside\News\NewsCategoryController::class, 'edit'])->name('news_category_edit'); | ||
| 53 | + Route::any('/category/lists', [\App\Http\Controllers\Bside\News\NewsCategoryController::class, 'lists'])->name('news_category_lists'); | ||
| 54 | + Route::any('/category/del', [\App\Http\Controllers\Bside\News\NewsCategoryController::class, 'del'])->name('news_category_del'); | ||
| 55 | + Route::any('/category/status', [\App\Http\Controllers\Bside\News\NewsCategoryController::class, 'status'])->name('news_category_status'); | ||
| 56 | + | ||
| 57 | + //新闻 | ||
| 58 | + Route::any('/add', [\App\Http\Controllers\Bside\News\NewsController::class, 'add'])->name('news_category_add'); | ||
| 59 | + Route::any('/info', [\App\Http\Controllers\Bside\News\NewsController::class, 'info'])->name('news_category_info'); | ||
| 60 | + Route::any('/edit', [\App\Http\Controllers\Bside\News\NewsController::class, 'edit'])->name('news_category_edit'); | ||
| 61 | + Route::any('/lists', [\App\Http\Controllers\Bside\News\NewsController::class, 'lists'])->name('news_category_lists'); | ||
| 62 | + Route::any('/del', [\App\Http\Controllers\Bside\News\NewsController::class, 'del'])->name('news_category_del'); | ||
| 63 | + Route::any('/status', [\App\Http\Controllers\Bside\News\NewsController::class, 'status'])->name('news_category_status'); | ||
| 64 | + }); | ||
| 36 | 65 | ||
| 37 | - //新闻分类相关路由 | ||
| 38 | - Route::any('/news_category/add', [\App\Http\Controllers\Bside\News\NewsCategoryController::class, 'add'])->name('news_category_add'); | ||
| 39 | - Route::any('/news_category/edit', [\App\Http\Controllers\Bside\News\NewsCategoryController::class, 'edit'])->name('news_category_edit'); | ||
| 40 | - Route::any('/news_category/lists', [\App\Http\Controllers\Bside\News\NewsCategoryController::class, 'lists'])->name('news_category_lists'); | ||
| 41 | - Route::any('/news_category/del', [\App\Http\Controllers\Bside\News\NewsCategoryController::class, 'del'])->name('news_category_del'); | ||
| 42 | - Route::any('/news_category/status', [\App\Http\Controllers\Bside\News\NewsCategoryController::class, 'get_user_lists'])->name('news_category_status'); | ||
| 43 | 66 | ||
| 44 | 67 | ||
| 45 | //产品 | 68 | //产品 |
-
请 注册 或 登录 后发表评论