作者 李宇航

合并分支 'lyh-server' 到 'master'

gx分类查看是否拥有下级



查看合并请求 !1516
@@ -11,6 +11,7 @@ use App\Models\Template\BTemplate; @@ -11,6 +11,7 @@ use App\Models\Template\BTemplate;
11 use App\Rules\Ids; 11 use App\Rules\Ids;
12 use Illuminate\Http\Request; 12 use Illuminate\Http\Request;
13 13
  14 +
14 /** 15 /**
15 * Class CategoryController 16 * Class CategoryController
16 * @package App\Http\Controllers\Bside 17 * @package App\Http\Controllers\Bside
@@ -19,6 +20,15 @@ use Illuminate\Http\Request; @@ -19,6 +20,15 @@ use Illuminate\Http\Request;
19 */ 20 */
20 class CategoryController extends BaseController 21 class CategoryController extends BaseController
21 { 22 {
  23 + public $model;
  24 + public $logic;
  25 +
  26 + public function __construct(Request $request)
  27 + {
  28 + parent::__construct($request);
  29 + $this->model = new Category();
  30 + $this->logic = new CategoryLogic();
  31 + }
22 32
23 /** 33 /**
24 * @remark :分类列表 34 * @remark :分类列表
@@ -27,16 +37,16 @@ class CategoryController extends BaseController @@ -27,16 +37,16 @@ class CategoryController extends BaseController
27 * @method :post 37 * @method :post
28 * @time :2023/8/17 10:59 38 * @time :2023/8/17 10:59
29 */ 39 */
30 - public function index(Category $category) 40 + public function index()
31 { 41 {
32 $this->map = $this->searchParam(); 42 $this->map = $this->searchParam();
33 $filed = ['id', 'project_id', 'pid', 'title', 'image', 'route', 'status','created_at','sort']; 43 $filed = ['id', 'project_id', 'pid', 'title', 'image', 'route', 'status','created_at','sort'];
34 $this->map['deleted_at'] = null; 44 $this->map['deleted_at'] = null;
35 if($this->user['project_id'] == 3283){//分类太多加载失败 45 if($this->user['project_id'] == 3283){//分类太多加载失败
36 - $list = $this->get3283Lists($category,$filed); 46 + $list = $this->get3283Lists($filed);
37 return $this->response('success',Code::SUCCESS,$list); 47 return $this->response('success',Code::SUCCESS,$list);
38 }else{ 48 }else{
39 - $data = $this->getList($category,$filed); 49 + $data = $this->getList($filed);
40 return $this->response('success',Code::SUCCESS,$data); 50 return $this->response('success',Code::SUCCESS,$data);
41 } 51 }
42 } 52 }
@@ -48,14 +58,14 @@ class CategoryController extends BaseController @@ -48,14 +58,14 @@ class CategoryController extends BaseController
48 * @method :post 58 * @method :post
49 * @time :2025/3/19 14:41 59 * @time :2025/3/19 14:41
50 */ 60 */
51 - public function getList(&$category,$filed){  
52 - $list = $category->list($this->map,['sort','id'],$filed); 61 + public function getList($filed){
  62 + $list = $this->model->list($this->map,['sort','id'],$filed);
53 $data = []; 63 $data = [];
54 if(!empty($list)){ 64 if(!empty($list)){
55 $template_id = $this->getTemplateId(BTemplate::SOURCE_PRODUCT,BTemplate::IS_LIST);//获取模版id 65 $template_id = $this->getTemplateId(BTemplate::SOURCE_PRODUCT,BTemplate::IS_LIST);//获取模版id
56 foreach ($list as $k =>$v){ 66 foreach ($list as $k =>$v){
57 $v['url'] = $this->user['domain'] . $v['route'].'/'; 67 $v['url'] = $this->user['domain'] . $v['route'].'/';
58 - $v['product_num'] = $category->getProductNum($list,$v['id']); 68 + $v['product_num'] = $this->model->getProductNum($list,$v['id']);
59 $v['image_link'] = getImageUrl($v['image'],$this->user['storage_type'],$this->user['project_location']); 69 $v['image_link'] = getImageUrl($v['image'],$this->user['storage_type'],$this->user['project_location']);
60 $v['is_renovation'] = $this->getIsRenovation(BTemplate::SOURCE_PRODUCT,BTemplate::IS_LIST,$template_id,$v['id']); 70 $v['is_renovation'] = $this->getIsRenovation(BTemplate::SOURCE_PRODUCT,BTemplate::IS_LIST,$template_id,$v['id']);
61 $list[$k] = $v; 71 $list[$k] = $v;
@@ -76,16 +86,16 @@ class CategoryController extends BaseController @@ -76,16 +86,16 @@ class CategoryController extends BaseController
76 * @method :post 86 * @method :post
77 * @time :2025/3/19 14:38 87 * @time :2025/3/19 14:38
78 */ 88 */
79 - public function get3283Lists(&$category,$filed){ 89 + public function get3283Lists($filed){
80 if(!isset($this->map['title'])){ 90 if(!isset($this->map['title'])){
81 $this->map['pid'] = $this->map['pid'] ?? 0; 91 $this->map['pid'] = $this->map['pid'] ?? 0;
82 } 92 }
83 - $list = $category->list($this->map,['sort','id'],$filed); 93 + $list = $this->model->list($this->map,['sort','id'],$filed);
84 $template_id = $this->getTemplateId(BTemplate::SOURCE_PRODUCT,BTemplate::IS_LIST);//获取模版id 94 $template_id = $this->getTemplateId(BTemplate::SOURCE_PRODUCT,BTemplate::IS_LIST);//获取模版id
85 foreach ($list as $k =>$v){ 95 foreach ($list as $k =>$v){
86 $v['url'] = $this->user['domain'] . $v['route'].'/'; 96 $v['url'] = $this->user['domain'] . $v['route'].'/';
87 - $v['product_num'] = $category->getProductNum($list,$v['id']);  
88 - $v['hasChildren'] = $this->getCategoryHasChildren($category,$v['id']); 97 + $v['product_num'] = $this->model->getProductNum($list,$v['id']);
  98 + $v['hasChildren'] = $this->getCategoryHasChildren($v['id']);
89 $v['image_link'] = getImageUrl($v['image'],$this->user['storage_type'],$this->user['project_location']); 99 $v['image_link'] = getImageUrl($v['image'],$this->user['storage_type'],$this->user['project_location']);
90 $v['is_renovation'] = $this->getIsRenovation(BTemplate::SOURCE_PRODUCT,BTemplate::IS_LIST,$template_id,$v['id']); 100 $v['is_renovation'] = $this->getIsRenovation(BTemplate::SOURCE_PRODUCT,BTemplate::IS_LIST,$template_id,$v['id']);
91 $list[$k] = $v; 101 $list[$k] = $v;
@@ -100,8 +110,8 @@ class CategoryController extends BaseController @@ -100,8 +110,8 @@ class CategoryController extends BaseController
100 * @method :post 110 * @method :post
101 * @time :2025/3/20 9:18 111 * @time :2025/3/20 9:18
102 */ 112 */
103 - public function getCategoryHasChildren(&$category,$id){  
104 - $count = $category->counts(['pid'=>$id]); 113 + public function getCategoryHasChildren($id){
  114 + $count = $this->model->counts(['pid'=>$id]);
105 if($count != 0){ 115 if($count != 0){
106 return true; 116 return true;
107 } 117 }
@@ -147,8 +157,8 @@ class CategoryController extends BaseController @@ -147,8 +157,8 @@ class CategoryController extends BaseController
147 * @method :post 157 * @method :post
148 * @time :2023/6/13 9:03 158 * @time :2023/6/13 9:03
149 */ 159 */
150 - public function categoryTopList(CategoryLogic $logic){  
151 - $list = $logic->categoryTopList(); 160 + public function categoryTopList(){
  161 + $list = $this->logic->categoryTopList();
152 $this->response('success',Code::SUCCESS,$list); 162 $this->response('success',Code::SUCCESS,$list);
153 } 163 }
154 164
@@ -159,13 +169,13 @@ class CategoryController extends BaseController @@ -159,13 +169,13 @@ class CategoryController extends BaseController
159 * @method :post 169 * @method :post
160 * @time :2023/8/21 17:12 170 * @time :2023/8/21 17:12
161 */ 171 */
162 - public function info(CategoryLogic $logic){ 172 + public function info(){
163 $this->request->validate([ 173 $this->request->validate([
164 'id'=>'required' 174 'id'=>'required'
165 ],[ 175 ],[
166 'id.required' => 'ID不能为空' 176 'id.required' => 'ID不能为空'
167 ]); 177 ]);
168 - $data = $logic->getCateInfo($this->param['id']); 178 + $data = $this->logic->getCateInfo($this->param['id']);
169 $this->response('success',Code::SUCCESS,$data); 179 $this->response('success',Code::SUCCESS,$data);
170 } 180 }
171 181
@@ -176,10 +186,10 @@ class CategoryController extends BaseController @@ -176,10 +186,10 @@ class CategoryController extends BaseController
176 * @method :post 186 * @method :post
177 * @time :2023/8/21 17:13 187 * @time :2023/8/21 17:13
178 */ 188 */
179 - public function save(CategoryRequest $request, CategoryLogic $logic) 189 + public function save(CategoryRequest $request)
180 { 190 {
181 $request->validated(); 191 $request->validated();
182 - $data = $logic->categorySave(); 192 + $data = $this->logic->categorySave();
183 $this->response('success',Code::SUCCESS,$data); 193 $this->response('success',Code::SUCCESS,$data);
184 } 194 }
185 195
@@ -190,7 +200,7 @@ class CategoryController extends BaseController @@ -190,7 +200,7 @@ class CategoryController extends BaseController
190 * @method :post 200 * @method :post
191 * @time :2023/9/26 17:35 201 * @time :2023/9/26 17:35
192 */ 202 */
193 - public function sort(CategoryLogic $logic){ 203 + public function sort(){
194 $this->request->validate([ 204 $this->request->validate([
195 'id'=>'required', 205 'id'=>'required',
196 'sort'=>'numeric|min:0', 206 'sort'=>'numeric|min:0',
@@ -199,7 +209,7 @@ class CategoryController extends BaseController @@ -199,7 +209,7 @@ class CategoryController extends BaseController
199 'sort.numeric' => 'sort位数字', 209 'sort.numeric' => 'sort位数字',
200 'sort.min' => 'sort最小值为0', 210 'sort.min' => 'sort最小值为0',
201 ]); 211 ]);
202 - $logic->categorySort(); 212 + $this->logic->categorySort();
203 $this->response('success'); 213 $this->response('success');
204 } 214 }
205 215
@@ -210,14 +220,14 @@ class CategoryController extends BaseController @@ -210,14 +220,14 @@ class CategoryController extends BaseController
210 * @method :post 220 * @method :post
211 * @time :2023/8/21 17:20 221 * @time :2023/8/21 17:20
212 */ 222 */
213 - public function delete(Request $request, CategoryLogic $logic) 223 + public function delete()
214 { 224 {
215 - $request->validate([ 225 + $this->request->validate([
216 'ids'=>['required', new Ids()] 226 'ids'=>['required', new Ids()]
217 ],[ 227 ],[
218 'ids.required' => 'ID不能为空' 228 'ids.required' => 'ID不能为空'
219 ]); 229 ]);
220 - $data = $logic->categoryDelete(); 230 + $data = $this->logic->categoryDelete();
221 $this->response('success',Code::SUCCESS,$data); 231 $this->response('success',Code::SUCCESS,$data);
222 } 232 }
223 233
@@ -229,8 +239,8 @@ class CategoryController extends BaseController @@ -229,8 +239,8 @@ class CategoryController extends BaseController
229 * @method :post 239 * @method :post
230 * @time :2024/1/10 15:34 240 * @time :2024/1/10 15:34
231 */ 241 */
232 - public function allSort(CategoryLogic $logic){  
233 - $logic->setAllSort(); 242 + public function allSort(){
  243 + $this->logic->setAllSort();
234 $this->response('success'); 244 $this->response('success');
235 } 245 }
236 246
@@ -241,13 +251,13 @@ class CategoryController extends BaseController @@ -241,13 +251,13 @@ class CategoryController extends BaseController
241 * @method :post 251 * @method :post
242 * @time :2024/5/8 17:49 252 * @time :2024/5/8 17:49
243 */ 253 */
244 - public function copyCategory(CategoryLogic $logic){ 254 + public function copyCategory(){
245 $this->request->validate([ 255 $this->request->validate([
246 'id'=>['required'], 256 'id'=>['required'],
247 ],[ 257 ],[
248 'id.required' => 'ID不能为空', 258 'id.required' => 'ID不能为空',
249 ]); 259 ]);
250 - $logic->copyCategoryInfo(); 260 + $this->logic->copyCategoryInfo();
251 $this->response('success'); 261 $this->response('success');
252 } 262 }
253 } 263 }