diff --git a/app/admin/controller/BarrageController.php b/app/admin/controller/BarrageController.php new file mode 100644 index 0000000..a2ab076 --- /dev/null +++ b/app/admin/controller/BarrageController.php @@ -0,0 +1,33 @@ +service = new BarrageService(); + } + + /** + * 列表页数据格式化 + * + * @param array $data + * @return array + */ + protected function indexFormat($data) + { + if (isset($data['created_at'])) + $data['created_at'] = date('Y-m-d H:i:s', $data['created_at']); + if (isset($data['updated_at'])) + $data['updated_at'] = date('Y-m-d H:i:s', $data['updated_at']); + return $data; + } +} \ No newline at end of file diff --git a/app/admin/controller/PostCategoryController.php b/app/admin/controller/PostCategoryController.php index 23ef772..c2c3606 100644 --- a/app/admin/controller/PostCategoryController.php +++ b/app/admin/controller/PostCategoryController.php @@ -35,6 +35,27 @@ class PostCategoryController extends BaseController } } + /** + * 分类树 + * @param Request $request + * @return \support\Response + */ + public function preset(Request $request) + { + try { + $params = $request->all(); + $result = $this->service->preset($params); + foreach ($result as $k => $r){ + unset($r['created_at']); + unset($r['updated_at']); + $result[$k] = $this->indexFormat($r); + } + return $this->success($result, '获取分类下拉'); + } catch (\Throwable $e) { + return $this->error($e->getMessage()); + } + } + /** * 列表页数据格式化 * diff --git a/app/admin/controller/SkuAttributeController.php b/app/admin/controller/SkuAttributeController.php index 0b46eb9..ebf4bd3 100644 --- a/app/admin/controller/SkuAttributeController.php +++ b/app/admin/controller/SkuAttributeController.php @@ -4,6 +4,7 @@ namespace app\admin\controller; use app\common\controller\BaseController; use app\common\traits\crud\CrudControllerTrait; use app\common\service\SkuAttributeService; +use support\Request; class SkuAttributeController extends BaseController { @@ -16,18 +17,63 @@ class SkuAttributeController extends BaseController $this->service = new SkuAttributeService(); } + + /** + * 分类树 + * @param Request $request + * @return \support\Response + */ + public function preset(Request $request) + { + try { + $params = $request->all(); + $result = $this->service->preset($params); + foreach ($result as $k => $r){ + unset($r['created_at']); + unset($r['updated_at']); + $result[$k] = $this->indexFormat($r); + } + return $this->success($result, '获取分类下拉'); + } catch (\Throwable $e) { + return $this->error($e->getMessage()); + } + } + /** * 列表页数据格式化 * * @param array $data * @return array */ - // protected function indexFormat($data) - // { - // if (isset($data['created_at'])) - // $data['created_at'] = date('Y-m-d H:i:s', $data['created_at']); - // if (isset($data['updated_at'])) - // $data['updated_at'] = date('Y-m-d H:i:s', $data['updated_at']); - // return $data; - // } + protected function indexFormat($data) + { + if (isset($data['created_at'])) + $data['created_at'] = date('Y-m-d H:i:s', $data['created_at']); + if (isset($data['updated_at'])) + $data['updated_at'] = date('Y-m-d H:i:s', $data['updated_at']); + if (isset($data['options_json'])){ + $data['options_json'] = json_decode($data['options_json'], true); +// foreach ($data['options_json'] as $k => $v){ +// $data['options_json'][$k] = ['value' => $v]; +// } + } + return $data; + } + + /** + * 创建 + * + * @param Request $request 请求对象 + * @return mixed 返回创建成功的数据或信息 + */ + public function store(Request $request) + { + try { + $data = $this->validate($this->service->getValidator(), $request->post(), 'store'); + $res = $this->service->serviceStore($request, $data); + return $this->success($res, '创建成功'); + } catch (\Throwable $e) { + return $this->error($e->getMessage().$e->getFile().$e->getLine()); + } + } } \ No newline at end of file diff --git a/app/common/controller/BarrageController.php b/app/common/controller/BarrageController.php new file mode 100644 index 0000000..6c97853 --- /dev/null +++ b/app/common/controller/BarrageController.php @@ -0,0 +1,33 @@ +service = new BarrageService(); + } + + /** + * 列表页数据格式化 + * + * @param array $data + * @return array + */ + protected function indexFormat($data) + { + if (isset($data['created_at'])) + $data['created_at'] = date('Y-m-d H:i:s', $data['created_at']); + if (isset($data['updated_at'])) + $data['updated_at'] = date('Y-m-d H:i:s', $data['updated_at']); + return $data; + } +} \ No newline at end of file diff --git a/app/common/logic/BarrageLogic.php b/app/common/logic/BarrageLogic.php new file mode 100644 index 0000000..9253473 --- /dev/null +++ b/app/common/logic/BarrageLogic.php @@ -0,0 +1,17 @@ +orderBy('sort','desc')->get(); + } } \ No newline at end of file diff --git a/app/common/model/Barrage.php b/app/common/model/Barrage.php new file mode 100644 index 0000000..6036be2 --- /dev/null +++ b/app/common/model/Barrage.php @@ -0,0 +1,49 @@ +validator; + } + + + /** + * 添加前置处理 + */ + public function beforeServiceStore($data, Request $request) + { + $data['user_id'] = $request->user->uid;; + return $data; + } +} \ No newline at end of file diff --git a/app/common/service/PostCategoryService.php b/app/common/service/PostCategoryService.php index d98cf8a..1c694bd 100644 --- a/app/common/service/PostCategoryService.php +++ b/app/common/service/PostCategoryService.php @@ -39,6 +39,21 @@ class PostCategoryService return new $this->validator; } + /** + * 获取系统list + */ + public function preset($params) + { + $where = []; + if(isset($params['parent_id']) && $params['parent_id']) { + $where['parent_id'] = $params['parent_id']; + }else{ + $where['parent_id'] = 0; + } + $result = $this->logic->getList($where)->toArray(); + return $result; + } + /** * 获取系统list */ diff --git a/app/common/service/SkuAttributeService.php b/app/common/service/SkuAttributeService.php index bd9a3ab..52d1361 100644 --- a/app/common/service/SkuAttributeService.php +++ b/app/common/service/SkuAttributeService.php @@ -2,6 +2,8 @@ namespace app\common\service; +use app\common\logic\PostCategoryLogic; +use app\common\logic\SkuAttributeLogic; use app\common\validate\SkuAttributeValidate; use app\common\traits\crud\CrudServiceTrait; use app\common\model\SkuAttribute; @@ -12,6 +14,7 @@ class SkuAttributeService use CrudServiceTrait; + protected $logic; /** * 指定当前要操作的模型 */ @@ -22,6 +25,11 @@ class SkuAttributeService */ protected $validator = SkuAttributeValidate::class; + public function __construct() + { + $this->logic = (new SkuAttributeLogic()); + } + /** * 获取验证器 */ @@ -58,4 +66,43 @@ class SkuAttributeService return $config; } + + /** + * 添加前置处理 + */ + public function beforeServiceStore($data, Request $request) + { +// $options = []; +// foreach ($data['options_json'] as $v){ +// $options[] = $v['value']; +// } +// $data['options_json'] = json_encode($options, JSON_UNESCAPED_UNICODE); + return $data; + } + + /** + * 添加前置处理 + */ + public function beforeServiceUpdate($data, Request $request) + { +// $options = []; +// foreach ($data['options_json'] as $v){ +// $options[] = $v['value']; +// } +// $data['options_json'] = json_encode($options, JSON_UNESCAPED_UNICODE); + return $data; + } + + /** + * 获取系统list + */ + public function preset($params) + { + $where = []; + if(isset($params['category_id']) && $params['category_id']) { + $where['category_id'] = $params['category_id']; + } + $result = $this->logic->getList($where)->toArray(); + return $result; + } } \ No newline at end of file diff --git a/app/common/validate/BarrageValidate.php b/app/common/validate/BarrageValidate.php new file mode 100644 index 0000000..2b31717 --- /dev/null +++ b/app/common/validate/BarrageValidate.php @@ -0,0 +1,29 @@ + [ + + ], + + 'update' => [ + + ] + ]; +} \ No newline at end of file diff --git a/app/controller/IndexController.php b/app/controller/IndexController.php index d7dce21..4b69e17 100644 --- a/app/controller/IndexController.php +++ b/app/controller/IndexController.php @@ -26,7 +26,7 @@ class IndexController { $options = [ 'controller' => [ - 'module' => 'common', + 'module' => 'admin', 'name' => 'barrage' ], 'model' => [ diff --git a/config/route.php b/config/route.php index 6d8b7e9..626b1a6 100644 --- a/config/route.php +++ b/config/route.php @@ -104,6 +104,12 @@ Route::group('/common', function () { Route::group('/sku', function () { Route::any('/list', [app\common\controller\SkuController::class, 'index']); }); + + // 弹幕 + Route::group('/barrage', function () { + Route::any('/list', [app\common\controller\BarrageController::class, 'index']); + Route::any('/store', [app\common\controller\BarrageController::class, 'store']); + }); }); @@ -170,6 +176,7 @@ Route::group('/admin', function () { // 帖子分类 Route::group('/category', function () { Route::any('/list', [app\admin\controller\PostCategoryController::class, 'index']); + Route::any('/preset', [app\admin\controller\PostCategoryController::class, 'preset']); Route::any('/tree', [app\admin\controller\PostCategoryController::class, 'tree']); Route::any('/show', [app\admin\controller\PostCategoryController::class, 'show']); Route::any('/store', [app\admin\controller\PostCategoryController::class, 'store']); @@ -191,6 +198,7 @@ Route::group('/admin', function () { // sku属性 Route::group('/sku/attribute', function () { Route::any('/list', [app\admin\controller\SkuAttributeController::class, 'index']); + Route::any('/preset', [app\admin\controller\SkuAttributeController::class, 'preset']); Route::any('/show', [app\admin\controller\SkuAttributeController::class, 'show']); Route::any('/store', [app\admin\controller\SkuAttributeController::class, 'store']); Route::any('/update', [app\admin\controller\SkuAttributeController::class, 'update']); @@ -233,6 +241,15 @@ Route::group('/admin', function () { Route::any('/update', [app\admin\controller\AgreementController::class, 'update']); Route::any('/destroy', [app\admin\controller\AgreementController::class, 'destroy']); }); + + // 弹幕 + Route::group('/barrage', function () { + Route::any('/list', [app\admin\controller\BarrageController::class, 'index']); + Route::any('/show', [app\admin\controller\BarrageController::class, 'show']); + Route::any('/store', [app\admin\controller\BarrageController::class, 'store']); + Route::any('/update', [app\admin\controller\BarrageController::class, 'update']); + Route::any('/destroy', [app\admin\controller\BarrageController::class, 'destroy']); + }); });