正在显示
8 个修改的文件
包含
72 行增加
和
26 行删除
| @@ -25,13 +25,7 @@ class CategoryController extends BaseController | @@ -25,13 +25,7 @@ class CategoryController extends BaseController | ||
| 25 | $map[] = ['title', 'like', "%{$this->param['search']}%"]; | 25 | $map[] = ['title', 'like', "%{$this->param['search']}%"]; |
| 26 | } | 26 | } |
| 27 | $sort = ['id' => 'desc']; | 27 | $sort = ['id' => 'desc']; |
| 28 | - $data = $logic->getList($map, $sort, ['id', 'pid', 'title', 'image', 'keywords', 'describe', 'status','created_at'],0); | ||
| 29 | - foreach ($data as &$v){ | ||
| 30 | - $v['product_num'] = $logic->getProductNum($v['id']); | ||
| 31 | - } | ||
| 32 | - if(!$map){ | ||
| 33 | - $data = Arr::listToTree($data); | ||
| 34 | - } | 28 | + $data = $logic->getList($map, $sort, ['id', 'project_id', 'pid', 'title', 'image', 'keywords', 'describe', 'status','created_at'],0); |
| 35 | return $this->success($data); | 29 | return $this->success($data); |
| 36 | } | 30 | } |
| 37 | 31 | ||
| @@ -42,7 +36,7 @@ class CategoryController extends BaseController | @@ -42,7 +36,7 @@ class CategoryController extends BaseController | ||
| 42 | 'id.required' => 'ID不能为空' | 36 | 'id.required' => 'ID不能为空' |
| 43 | ]); | 37 | ]); |
| 44 | $data = $logic->getInfo($this->param['id']); | 38 | $data = $logic->getInfo($this->param['id']); |
| 45 | - return $this->success(Arr::twoKeepKeys($data, ['id', 'pid', 'title', 'image', 'keywords', 'describe', 'status'])); | 39 | + return $this->success(Arr::twoKeepKeys($data, ['id', 'project_id', 'pid', 'title', 'image', 'keywords', 'describe', 'status', 'route', 'url'])); |
| 46 | } | 40 | } |
| 47 | 41 | ||
| 48 | public function save(CategoryRequest $request, CategoryLogic $logic) | 42 | public function save(CategoryRequest $request, CategoryLogic $logic) |
| @@ -26,13 +26,7 @@ class KeywordController extends BaseController | @@ -26,13 +26,7 @@ class KeywordController extends BaseController | ||
| 26 | $map[] = ['title', 'like', "%{$this->param['search']}%"]; | 26 | $map[] = ['title', 'like', "%{$this->param['search']}%"]; |
| 27 | } | 27 | } |
| 28 | $sort = ['id' => 'desc']; | 28 | $sort = ['id' => 'desc']; |
| 29 | - $data = $logic->getList($map, $sort, ['id', 'title', 'seo_title', 'seo_keywords', 'seo_description', 'status', 'created_at']); | ||
| 30 | - foreach ($data['list'] as &$v){ | ||
| 31 | - $v['product_num'] = $logic->getProductNum($v['id']); | ||
| 32 | - $v['tdk'] = boolval($v['seo_title']) * boolval($v['seo_keywords']) * boolval($v['seo_description']); | ||
| 33 | - //todo 获取域名 拼接链接 | ||
| 34 | - $v['url'] = $v['route']; | ||
| 35 | - } | 29 | + $data = $logic->getList($map, $sort, ['id', 'project_id', 'title', 'seo_title', 'seo_keywords', 'seo_description', 'status', 'created_at']); |
| 36 | return $this->success($data); | 30 | return $this->success($data); |
| 37 | } | 31 | } |
| 38 | 32 | ||
| @@ -43,7 +37,7 @@ class KeywordController extends BaseController | @@ -43,7 +37,7 @@ class KeywordController extends BaseController | ||
| 43 | 'id.required' => 'ID不能为空' | 37 | 'id.required' => 'ID不能为空' |
| 44 | ]); | 38 | ]); |
| 45 | $data = $logic->getInfo($this->param['id']); | 39 | $data = $logic->getInfo($this->param['id']); |
| 46 | - return $this->success(Arr::twoKeepKeys($data, ['id', 'title', 'seo_title', 'seo_keywords', 'seo_description', 'created_at'])); | 40 | + return $this->success(Arr::twoKeepKeys($data, ['id', 'project_id', 'title', 'seo_title', 'seo_keywords', 'seo_description', 'created_at', 'route', 'url'])); |
| 47 | } | 41 | } |
| 48 | 42 | ||
| 49 | public function save(KeywordRequest $request, KeywordLogic $logic) | 43 | public function save(KeywordRequest $request, KeywordLogic $logic) |
| @@ -55,7 +55,7 @@ class ProductController extends BaseController | @@ -55,7 +55,7 @@ class ProductController extends BaseController | ||
| 55 | $map[] = ['status', $this->param['status']]; | 55 | $map[] = ['status', $this->param['status']]; |
| 56 | } | 56 | } |
| 57 | $sort = ['id' => 'desc']; | 57 | $sort = ['id' => 'desc']; |
| 58 | - $data = $logic->getList($map, $sort, ['id', 'title', 'thumb', 'category_id', 'keyword_id', 'status', 'created_uid', 'created_at', 'updated_at']); | 58 | + $data = $logic->getList($map, $sort, ['id', 'project_id', 'title', 'thumb', 'category_id', 'keyword_id', 'status', 'created_uid', 'created_at', 'updated_at']); |
| 59 | return $this->success($data); | 59 | return $this->success($data); |
| 60 | } | 60 | } |
| 61 | 61 | ||
| @@ -66,8 +66,8 @@ class ProductController extends BaseController | @@ -66,8 +66,8 @@ class ProductController extends BaseController | ||
| 66 | 'id.required' => 'ID不能为空' | 66 | 'id.required' => 'ID不能为空' |
| 67 | ]); | 67 | ]); |
| 68 | $data = $logic->getInfo($this->param['id']); | 68 | $data = $logic->getInfo($this->param['id']); |
| 69 | - return $this->success(Arr::twoKeepKeys($data, ['id', 'title', 'gallery', 'attrs', 'category_id', 'keyword_id', 'attr_id', 'describe_id', 'intro', 'content', | ||
| 70 | - 'describe', 'seo_mate', 'related_product_id', 'status', 'category_id_text', 'keyword_id_text', 'status_text', 'created_uid', 'created_uid_text', 'route'])); | 69 | + return $this->success(Arr::twoKeepKeys($data, ['id', 'project_id', 'title', 'gallery', 'attrs', 'category_id', 'keyword_id', 'attr_id', 'describe_id', 'intro', 'content', |
| 70 | + 'describe', 'seo_mate', 'related_product_id', 'status', 'category_id_text', 'keyword_id_text', 'status_text', 'created_uid', 'created_uid_text', 'route', 'url'])); | ||
| 71 | } | 71 | } |
| 72 | 72 | ||
| 73 | public function save(ProductRequest $request, ProductLogic $logic) | 73 | public function save(ProductRequest $request, ProductLogic $logic) |
| @@ -7,6 +7,7 @@ use App\Enums\Common\Code; | @@ -7,6 +7,7 @@ use App\Enums\Common\Code; | ||
| 7 | use App\Enums\Common\Common; | 7 | use App\Enums\Common\Common; |
| 8 | use App\Exceptions\BsideGlobalException; | 8 | use App\Exceptions\BsideGlobalException; |
| 9 | use App\Http\Controllers\File\ImageController; | 9 | use App\Http\Controllers\File\ImageController; |
| 10 | +use App\Http\Logic\Aside\Project\ProjectLogic; | ||
| 10 | use App\Http\Logic\Logic; | 11 | use App\Http\Logic\Logic; |
| 11 | use App\Models\File\Image as ImageModel; | 12 | use App\Models\File\Image as ImageModel; |
| 12 | use Illuminate\Support\Facades\Cache; | 13 | use Illuminate\Support\Facades\Cache; |
| @@ -25,6 +26,8 @@ class BaseLogic extends Logic | @@ -25,6 +26,8 @@ class BaseLogic extends Logic | ||
| 25 | 26 | ||
| 26 | protected $user; | 27 | protected $user; |
| 27 | 28 | ||
| 29 | + protected $project; | ||
| 30 | + | ||
| 28 | protected $side = Common::B; | 31 | protected $side = Common::B; |
| 29 | 32 | ||
| 30 | public function __construct() | 33 | public function __construct() |
| @@ -32,6 +35,7 @@ class BaseLogic extends Logic | @@ -32,6 +35,7 @@ class BaseLogic extends Logic | ||
| 32 | $this->request = request(); | 35 | $this->request = request(); |
| 33 | $this->requestAll = request()->all(); | 36 | $this->requestAll = request()->all(); |
| 34 | $this->user = Cache::get(request()->header('token')); | 37 | $this->user = Cache::get(request()->header('token')); |
| 38 | + $this->project = (new ProjectLogic())->getInfo($this->user['project_id']); | ||
| 35 | } | 39 | } |
| 36 | 40 | ||
| 37 | 41 | ||
| @@ -152,4 +156,14 @@ class BaseLogic extends Logic | @@ -152,4 +156,14 @@ class BaseLogic extends Logic | ||
| 152 | } | 156 | } |
| 153 | return $rs; | 157 | return $rs; |
| 154 | } | 158 | } |
| 159 | + | ||
| 160 | + public function getProjectDomain(){ | ||
| 161 | + if(!empty($this->project['deploy_optimize']['domain'])){ | ||
| 162 | + return $this->project['deploy_optimize']['domain']; | ||
| 163 | + } | ||
| 164 | + if(!empty($this->project['deploy_build']['test_domain'])){ | ||
| 165 | + return $this->project['deploy_build']['test_domain']; | ||
| 166 | + } | ||
| 167 | + return ''; | ||
| 168 | + } | ||
| 155 | } | 169 | } |
| @@ -27,6 +27,26 @@ class CategoryLogic extends BaseLogic | @@ -27,6 +27,26 @@ class CategoryLogic extends BaseLogic | ||
| 27 | $this->model = new Category(); | 27 | $this->model = new Category(); |
| 28 | } | 28 | } |
| 29 | 29 | ||
| 30 | + public function getList(array $map = [], array $sort = ['id' => 'desc'], array $columns = ['*'], int $limit = 20) | ||
| 31 | + { | ||
| 32 | + $data = parent::getList($map, $sort, $columns, $limit); | ||
| 33 | + foreach ($data as &$v){ | ||
| 34 | + $v['url'] = $this->getProjectDomain() . $v['route'] ; | ||
| 35 | + $v['product_num'] = $this->getProductNum($v['id']); | ||
| 36 | + } | ||
| 37 | + if(!$map){ | ||
| 38 | + $data = Arr::listToTree($data); | ||
| 39 | + } | ||
| 40 | + return $this->success($data); | ||
| 41 | + } | ||
| 42 | + | ||
| 43 | + public function getInfo($id) | ||
| 44 | + { | ||
| 45 | + $info = parent::getInfo($id); | ||
| 46 | + $info['url'] = $this->getProjectDomain() . $info['route'] ; | ||
| 47 | + return $this->success($info); | ||
| 48 | + } | ||
| 49 | + | ||
| 30 | public function save($param){ | 50 | public function save($param){ |
| 31 | $param['pid'] = $param['pid'] ?? 0; | 51 | $param['pid'] = $param['pid'] ?? 0; |
| 32 | if(!empty($param['pid'])){ | 52 | if(!empty($param['pid'])){ |
| @@ -57,13 +77,12 @@ class CategoryLogic extends BaseLogic | @@ -57,13 +77,12 @@ class CategoryLogic extends BaseLogic | ||
| 57 | 77 | ||
| 58 | DB::beginTransaction(); | 78 | DB::beginTransaction(); |
| 59 | try { | 79 | try { |
| 60 | - parent::delete($ids); | ||
| 61 | - | ||
| 62 | foreach ($ids as $id){ | 80 | foreach ($ids as $id){ |
| 63 | $info = $this->getCacheInfo($id); | 81 | $info = $this->getCacheInfo($id); |
| 64 | if(!$info){ | 82 | if(!$info){ |
| 65 | continue; | 83 | continue; |
| 66 | } | 84 | } |
| 85 | + | ||
| 67 | //是否有子分类 | 86 | //是否有子分类 |
| 68 | if(Category::where('project_id', $this->user['project_id'])->where('pid', $id)->count()){ | 87 | if(Category::where('project_id', $this->user['project_id'])->where('pid', $id)->count()){ |
| 69 | $this->fail("分类{$info['title']}存在子分类,不能删除"); | 88 | $this->fail("分类{$info['title']}存在子分类,不能删除"); |
| @@ -72,10 +91,10 @@ class CategoryLogic extends BaseLogic | @@ -72,10 +91,10 @@ class CategoryLogic extends BaseLogic | ||
| 72 | if(CategoryRelated::where('cate_id', $id)->count()){ | 91 | if(CategoryRelated::where('cate_id', $id)->count()){ |
| 73 | $this->fail("分类{$info['title']}存在产品,不能删除"); | 92 | $this->fail("分类{$info['title']}存在产品,不能删除"); |
| 74 | } | 93 | } |
| 75 | - | ||
| 76 | //删除路由映射 | 94 | //删除路由映射 |
| 77 | RouteMap::delRoute(RouteMap::SOURCE_PRODUCT_CATE, $id, $this->user['project_id']); | 95 | RouteMap::delRoute(RouteMap::SOURCE_PRODUCT_CATE, $id, $this->user['project_id']); |
| 78 | } | 96 | } |
| 97 | + parent::delete($ids); | ||
| 79 | 98 | ||
| 80 | DB::commit(); | 99 | DB::commit(); |
| 81 | } catch (BsideGlobalException $e){ | 100 | } catch (BsideGlobalException $e){ |
| @@ -25,6 +25,24 @@ class KeywordLogic extends BaseLogic | @@ -25,6 +25,24 @@ class KeywordLogic extends BaseLogic | ||
| 25 | $this->model = new Keyword(); | 25 | $this->model = new Keyword(); |
| 26 | } | 26 | } |
| 27 | 27 | ||
| 28 | + public function getList(array $map = [], array $sort = ['id' => 'desc'], array $columns = ['*'], int $limit = 20) | ||
| 29 | + { | ||
| 30 | + $data = parent::getList($map, $sort, $columns, $limit); | ||
| 31 | + foreach ($data['list'] as &$v){ | ||
| 32 | + $v['product_num'] = $this->getProductNum($v['id']); | ||
| 33 | + $v['tdk'] = boolval($v['seo_title']) * boolval($v['seo_keywords']) * boolval($v['seo_description']); | ||
| 34 | + $v['url'] = $this->getProjectDomain() . $v['route']; | ||
| 35 | + } | ||
| 36 | + return $this->success($data); | ||
| 37 | + } | ||
| 38 | + | ||
| 39 | + public function getInfo($id) | ||
| 40 | + { | ||
| 41 | + $info = parent::getInfo($id); | ||
| 42 | + $info['url'] = $this->getProjectDomain() . $info['route']; | ||
| 43 | + return $this->success($info); | ||
| 44 | + } | ||
| 45 | + | ||
| 28 | public function save($param){ | 46 | public function save($param){ |
| 29 | DB::beginTransaction(); | 47 | DB::beginTransaction(); |
| 30 | try { | 48 | try { |
| @@ -45,8 +63,6 @@ class KeywordLogic extends BaseLogic | @@ -45,8 +63,6 @@ class KeywordLogic extends BaseLogic | ||
| 45 | 63 | ||
| 46 | DB::beginTransaction(); | 64 | DB::beginTransaction(); |
| 47 | try { | 65 | try { |
| 48 | - parent::delete($ids); | ||
| 49 | - | ||
| 50 | foreach ($ids as $id){ | 66 | foreach ($ids as $id){ |
| 51 | $info = $this->getCacheInfo($id); | 67 | $info = $this->getCacheInfo($id); |
| 52 | if(!$info){ | 68 | if(!$info){ |
| @@ -61,6 +77,7 @@ class KeywordLogic extends BaseLogic | @@ -61,6 +77,7 @@ class KeywordLogic extends BaseLogic | ||
| 61 | //删除路由映射 | 77 | //删除路由映射 |
| 62 | RouteMap::delRoute(RouteMap::SOURCE_PRODUCT_KEYWORD, $id, $this->user['project_id']); | 78 | RouteMap::delRoute(RouteMap::SOURCE_PRODUCT_KEYWORD, $id, $this->user['project_id']); |
| 63 | } | 79 | } |
| 80 | + parent::delete($ids); | ||
| 64 | 81 | ||
| 65 | DB::commit(); | 82 | DB::commit(); |
| 66 | } catch (BsideGlobalException $e){ | 83 | } catch (BsideGlobalException $e){ |
| @@ -53,6 +53,7 @@ class ProductLogic extends BaseLogic | @@ -53,6 +53,7 @@ class ProductLogic extends BaseLogic | ||
| 53 | $info['keyword_id_text'] = Arr::arrToSet($info['keyword_id_text'], 'trim'); | 53 | $info['keyword_id_text'] = Arr::arrToSet($info['keyword_id_text'], 'trim'); |
| 54 | $info['status_text'] = Product::statusMap()[$info['status']] ?? ''; | 54 | $info['status_text'] = Product::statusMap()[$info['status']] ?? ''; |
| 55 | $info['created_uid_text'] = (new UserLogic())->getCacheInfo($info['created_uid'])['name'] ?? ''; | 55 | $info['created_uid_text'] = (new UserLogic())->getCacheInfo($info['created_uid'])['name'] ?? ''; |
| 56 | + $info['url'] = $this->getProjectDomain() . $info['route'] ; | ||
| 56 | return $info; | 57 | return $info; |
| 57 | } | 58 | } |
| 58 | 59 | ||
| @@ -85,8 +86,6 @@ class ProductLogic extends BaseLogic | @@ -85,8 +86,6 @@ class ProductLogic extends BaseLogic | ||
| 85 | 86 | ||
| 86 | DB::beginTransaction(); | 87 | DB::beginTransaction(); |
| 87 | try { | 88 | try { |
| 88 | - parent::delete($ids); | ||
| 89 | - | ||
| 90 | foreach ($ids as $id){ | 89 | foreach ($ids as $id){ |
| 91 | //删除路由映射 | 90 | //删除路由映射 |
| 92 | RouteMap::delRoute(RouteMap::SOURCE_PRODUCT, $id, $this->user['project_id']); | 91 | RouteMap::delRoute(RouteMap::SOURCE_PRODUCT, $id, $this->user['project_id']); |
| @@ -97,6 +96,7 @@ class ProductLogic extends BaseLogic | @@ -97,6 +96,7 @@ class ProductLogic extends BaseLogic | ||
| 97 | //删除关键词关联 | 96 | //删除关键词关联 |
| 98 | KeywordRelated::where('product_id', $id)->delete(); | 97 | KeywordRelated::where('product_id', $id)->delete(); |
| 99 | } | 98 | } |
| 99 | + parent::delete($ids); | ||
| 100 | 100 | ||
| 101 | DB::commit(); | 101 | DB::commit(); |
| 102 | }catch (\Exception $e){ | 102 | }catch (\Exception $e){ |
| @@ -4,6 +4,7 @@ namespace App\Models\Product; | @@ -4,6 +4,7 @@ namespace App\Models\Product; | ||
| 4 | 4 | ||
| 5 | 5 | ||
| 6 | use App\Models\Base; | 6 | use App\Models\Base; |
| 7 | +use App\Models\RouteMap; | ||
| 7 | use App\Services\Facades\Upload; | 8 | use App\Services\Facades\Upload; |
| 8 | use Illuminate\Database\Eloquent\SoftDeletes; | 9 | use Illuminate\Database\Eloquent\SoftDeletes; |
| 9 | 10 | ||
| @@ -22,6 +23,13 @@ class Category extends Base | @@ -22,6 +23,13 @@ class Category extends Base | ||
| 22 | */ | 23 | */ |
| 23 | protected $child_ids_arr = []; | 24 | protected $child_ids_arr = []; |
| 24 | 25 | ||
| 26 | + | ||
| 27 | + protected $appends = ['route']; | ||
| 28 | + | ||
| 29 | + public function getRouteAttribute(){ | ||
| 30 | + return RouteMap::getRoute(RouteMap::SOURCE_PRODUCT_CATE, $this->id, $this->project_id); | ||
| 31 | + } | ||
| 32 | + | ||
| 25 | public function getImageAttribute($value) | 33 | public function getImageAttribute($value) |
| 26 | { | 34 | { |
| 27 | return Upload::path2url($value); | 35 | return Upload::path2url($value); |
-
请 注册 或 登录 后发表评论