正在显示
4 个修改的文件
包含
107 行增加
和
17 行删除
| @@ -14,10 +14,30 @@ use App\Http\Controllers\Bside\BaseController; | @@ -14,10 +14,30 @@ use App\Http\Controllers\Bside\BaseController; | ||
| 14 | use App\Http\Logic\Bside\Product\DetailLogic; | 14 | use App\Http\Logic\Bside\Product\DetailLogic; |
| 15 | use App\Models\Product\Column; | 15 | use App\Models\Product\Column; |
| 16 | use App\Models\Product\Detail; | 16 | use App\Models\Product\Detail; |
| 17 | +use Illuminate\Support\Facades\DB; | ||
| 17 | 18 | ||
| 18 | class DetailController extends BaseController | 19 | class DetailController extends BaseController |
| 19 | { | 20 | { |
| 20 | /** | 21 | /** |
| 22 | + * @remark :获取当前产品的描述详情 | ||
| 23 | + * @name :getDetail | ||
| 24 | + * @author :lyh | ||
| 25 | + * @method :post | ||
| 26 | + * @time :2024/11/13 9:53 | ||
| 27 | + */ | ||
| 28 | + public function getDetail(Detail $detail){ | ||
| 29 | + $this->request->validate([ | ||
| 30 | + 'product_id'=>'required', | ||
| 31 | + 'column_id'=>'required' | ||
| 32 | + ],[ | ||
| 33 | + 'product_id.required' => '产品id不能为空', | ||
| 34 | + 'column_id.required' => '栏目id不能为空', | ||
| 35 | + ]); | ||
| 36 | + $data = $detail->list($this->map,'id',['*'],'asc'); | ||
| 37 | + $this->response('success',Code::SUCCESS,$data); | ||
| 38 | + } | ||
| 39 | + | ||
| 40 | + /** | ||
| 21 | * @remark :获取产品描述页所有详情 | 41 | * @remark :获取产品描述页所有详情 |
| 22 | * @name :getType | 42 | * @name :getType |
| 23 | * @author :lyh | 43 | * @author :lyh |
| @@ -71,7 +91,7 @@ class DetailController extends BaseController | @@ -71,7 +91,7 @@ class DetailController extends BaseController | ||
| 71 | * @method :post | 91 | * @method :post |
| 72 | * @time :2024/11/12 16:24 | 92 | * @time :2024/11/12 16:24 |
| 73 | */ | 93 | */ |
| 74 | - public function saveDetail(){ | 94 | + public function saveDetail(DetailLogic $logic){ |
| 75 | $this->request->validate([ | 95 | $this->request->validate([ |
| 76 | 'product_id'=>'required', | 96 | 'product_id'=>'required', |
| 77 | 'data'=>'required', | 97 | 'data'=>'required', |
| @@ -79,7 +99,56 @@ class DetailController extends BaseController | @@ -79,7 +99,56 @@ class DetailController extends BaseController | ||
| 79 | 'product_id.required' => '产品id不能为空', | 99 | 'product_id.required' => '产品id不能为空', |
| 80 | 'data.required' => 'data不能为空', | 100 | 'data.required' => 'data不能为空', |
| 81 | ]); | 101 | ]); |
| 102 | + $data = $logic->saveDetail(); | ||
| 103 | + $this->response('success',Code::SUCCESS,$data); | ||
| 104 | + } | ||
| 82 | 105 | ||
| 106 | + /** | ||
| 107 | + * @remark :删除切换栏 | ||
| 108 | + * @name :delColumn | ||
| 109 | + * @author :lyh | ||
| 110 | + * @method :post | ||
| 111 | + * @time :2024/11/13 10:40 | ||
| 112 | + */ | ||
| 113 | + public function delColumn(Column $column,Detail $detail){ | ||
| 114 | + $this->request->validate([ | ||
| 115 | + 'id'=>'required', | ||
| 116 | + ],[ | ||
| 117 | + 'id.required' => 'id不能为空', | ||
| 118 | + ]); | ||
| 119 | + $info = $column->read($this->map); | ||
| 120 | + if($info === false){ | ||
| 121 | + $this->fail('当前数据不存在或已被删除'); | ||
| 122 | + } | ||
| 123 | + if($info['id'] == 1){ | ||
| 124 | + $this->fail('当前默认模块不允许删除'); | ||
| 125 | + } | ||
| 126 | + DB::beginTransaction(); | ||
| 127 | + try { | ||
| 128 | + $column->del(['id'=>$this->param['id']]); | ||
| 129 | + $detail->del(['product_id'=>$info['product_id'],'column_id'=>$info['column_id']]); | ||
| 130 | + DB::commit(); | ||
| 131 | + }catch (\Exception $e){ | ||
| 132 | + DB::rollBack(); | ||
| 133 | + $this->fail('删除失败,请联系管理员'); | ||
| 134 | + } | ||
| 135 | + $this->response('success'); | ||
| 136 | + } | ||
| 83 | 137 | ||
| 138 | + /*** | ||
| 139 | + * @remark :删除模块 | ||
| 140 | + * @name :delDetail | ||
| 141 | + * @author :lyh | ||
| 142 | + * @method :post | ||
| 143 | + * @time :2024/11/13 10:24 | ||
| 144 | + */ | ||
| 145 | + public function delDetail(Detail $detail){ | ||
| 146 | + $this->request->validate([ | ||
| 147 | + 'id'=>'required', | ||
| 148 | + ],[ | ||
| 149 | + 'id.required' => 'id不能为空', | ||
| 150 | + ]); | ||
| 151 | + $detail->del($this->map); | ||
| 152 | + $this->response('success'); | ||
| 84 | } | 153 | } |
| 85 | } | 154 | } |
| @@ -43,24 +43,36 @@ class DetailLogic extends BaseLogic | @@ -43,24 +43,36 @@ class DetailLogic extends BaseLogic | ||
| 43 | return $this->success(['id'=>$id]); | 43 | return $this->success(['id'=>$id]); |
| 44 | } | 44 | } |
| 45 | 45 | ||
| 46 | + /** | ||
| 47 | + * @remark :保存数据 | ||
| 48 | + * @name :saveDetail | ||
| 49 | + * @author :lyh | ||
| 50 | + * @method :post | ||
| 51 | + * @time :2024/11/13 9:30 | ||
| 52 | + */ | ||
| 46 | public function saveDetail(){ | 53 | public function saveDetail(){ |
| 47 | - foreach ($this->param['data'] as $k => $data){ | ||
| 48 | - $i = 1; | ||
| 49 | - $save_data = []; | ||
| 50 | - foreach ($data as $key => $v){ | ||
| 51 | - $save_data[] = [ | ||
| 52 | - 'sort'=>$i, | ||
| 53 | - 'column_id'=>$v['column_id'], | ||
| 54 | - 'product_id'=>$this->param['product_id'], | ||
| 55 | - 'title'=>$v['title'] ?? '', | ||
| 56 | - 'content'=>json_encode($v['content'] ?? []), | ||
| 57 | - 'css'=>json_encode($v['css'] ?? []), | ||
| 58 | - 'created_at'=>date('Y-m-d H:i:s'), | ||
| 59 | - 'updated_at'=>date('Y-m-d H:i:s') | ||
| 60 | - ]; | ||
| 61 | - $i++; | 54 | + try { |
| 55 | + foreach ($this->param['data'] as $data){ | ||
| 56 | + foreach ($data as $v){ | ||
| 57 | + $save_data = [ | ||
| 58 | + 'sort'=>$v['sort'], | ||
| 59 | + 'column_id'=>$v['column_id'], | ||
| 60 | + 'product_id'=>$this->param['product_id'], | ||
| 61 | + 'text_type'=>$v['text_type'], | ||
| 62 | + 'title'=>$v['title'] ?? '', | ||
| 63 | + 'content'=>json_encode($v['content'] ?? []), | ||
| 64 | + 'css'=>json_encode($v['css'] ?? []), | ||
| 65 | + ]; | ||
| 66 | + if(isset($v['id']) && !empty($v['id'])){ | ||
| 67 | + $this->edit($save_data,['id'=>$v['id']]); | ||
| 68 | + }else{ | ||
| 69 | + $this->model->add($save_data); | ||
| 70 | + } | ||
| 71 | + } | ||
| 62 | } | 72 | } |
| 63 | - $this->model->insert($save_data); | 73 | + }catch (\Exception $e){ |
| 74 | + $this->fail('保存失败,请联系管理员.错误:'.$e->getMessage()); | ||
| 64 | } | 75 | } |
| 76 | + $this->success(['product_id'=>$this->param['product_id']]); | ||
| 65 | } | 77 | } |
| 66 | } | 78 | } |
| @@ -498,6 +498,7 @@ Route::middleware(['aloginauth'])->group(function () { | @@ -498,6 +498,7 @@ Route::middleware(['aloginauth'])->group(function () { | ||
| 498 | Route::prefix('all_project')->group(function () { | 498 | Route::prefix('all_project')->group(function () { |
| 499 | Route::any('/', [Aside\Project\AllProjectController::class, 'lists'])->name('admin.all_project_lists'); | 499 | Route::any('/', [Aside\Project\AllProjectController::class, 'lists'])->name('admin.all_project_lists'); |
| 500 | }); | 500 | }); |
| 501 | + | ||
| 501 | }); | 502 | }); |
| 502 | 503 | ||
| 503 | //无需登录验证的路由组 | 504 | //无需登录验证的路由组 |
| @@ -300,6 +300,14 @@ Route::middleware(['bloginauth'])->group(function () { | @@ -300,6 +300,14 @@ Route::middleware(['bloginauth'])->group(function () { | ||
| 300 | Route::any('extend/save', [\App\Http\Controllers\Bside\Product\ExtendController::class, 'save'])->name('product_extend_save'); | 300 | Route::any('extend/save', [\App\Http\Controllers\Bside\Product\ExtendController::class, 'save'])->name('product_extend_save'); |
| 301 | Route::any('extend/del', [\App\Http\Controllers\Bside\Product\ExtendController::class, 'del'])->name('product_extend_del'); | 301 | Route::any('extend/del', [\App\Http\Controllers\Bside\Product\ExtendController::class, 'del'])->name('product_extend_del'); |
| 302 | Route::any('extend/search_filed', [\App\Http\Controllers\Bside\Product\ExtendController::class, 'search_filed'])->name('product_extend_search_filed'); | 302 | Route::any('extend/search_filed', [\App\Http\Controllers\Bside\Product\ExtendController::class, 'search_filed'])->name('product_extend_search_filed'); |
| 303 | + //产品描述 | ||
| 304 | + Route::any('detail/getColumn', [\App\Http\Controllers\Bside\Product\DetailController::class, 'getColumn'])->name('product_detail_getColumn'); | ||
| 305 | + Route::any('detail/getDetail', [\App\Http\Controllers\Bside\Product\DetailController::class, 'getDetail'])->name('product_detail_getDetail'); | ||
| 306 | + Route::any('detail/getType', [\App\Http\Controllers\Bside\Product\DetailController::class, 'getType'])->name('product_detail_getType'); | ||
| 307 | + Route::any('detail/saveColumn', [\App\Http\Controllers\Bside\Product\DetailController::class, 'saveColumn'])->name('product_detail_saveColumn'); | ||
| 308 | + Route::any('detail/saveDetail', [\App\Http\Controllers\Bside\Product\DetailController::class, 'saveDetail'])->name('product_detail_saveDetail'); | ||
| 309 | + Route::any('detail/delDetail', [\App\Http\Controllers\Bside\Product\DetailController::class, 'delDetail'])->name('product_detail_delDetail'); | ||
| 310 | + Route::any('detail/delColumn', [\App\Http\Controllers\Bside\Product\DetailController::class, 'delColumn'])->name('product_detail_delColumn'); | ||
| 303 | }); | 311 | }); |
| 304 | 312 | ||
| 305 | 313 |
-
请 注册 或 登录 后发表评论