作者 赵彬吉

update

... ... @@ -25,13 +25,7 @@ class CategoryController extends BaseController
$map[] = ['title', 'like', "%{$this->param['search']}%"];
}
$sort = ['id' => 'desc'];
$data = $logic->getList($map, $sort, ['id', 'pid', 'title', 'image', 'keywords', 'describe', 'status','created_at'],0);
foreach ($data as &$v){
$v['product_num'] = $logic->getProductNum($v['id']);
}
if(!$map){
$data = Arr::listToTree($data);
}
$data = $logic->getList($map, $sort, ['id', 'project_id', 'pid', 'title', 'image', 'keywords', 'describe', 'status','created_at'],0);
return $this->success($data);
}
... ... @@ -42,7 +36,7 @@ class CategoryController extends BaseController
'id.required' => 'ID不能为空'
]);
$data = $logic->getInfo($this->param['id']);
return $this->success(Arr::twoKeepKeys($data, ['id', 'pid', 'title', 'image', 'keywords', 'describe', 'status']));
return $this->success(Arr::twoKeepKeys($data, ['id', 'project_id', 'pid', 'title', 'image', 'keywords', 'describe', 'status', 'route', 'url']));
}
public function save(CategoryRequest $request, CategoryLogic $logic)
... ...
... ... @@ -26,13 +26,7 @@ class KeywordController extends BaseController
$map[] = ['title', 'like', "%{$this->param['search']}%"];
}
$sort = ['id' => 'desc'];
$data = $logic->getList($map, $sort, ['id', 'title', 'seo_title', 'seo_keywords', 'seo_description', 'status', 'created_at']);
foreach ($data['list'] as &$v){
$v['product_num'] = $logic->getProductNum($v['id']);
$v['tdk'] = boolval($v['seo_title']) * boolval($v['seo_keywords']) * boolval($v['seo_description']);
//todo 获取域名 拼接链接
$v['url'] = $v['route'];
}
$data = $logic->getList($map, $sort, ['id', 'project_id', 'title', 'seo_title', 'seo_keywords', 'seo_description', 'status', 'created_at']);
return $this->success($data);
}
... ... @@ -43,7 +37,7 @@ class KeywordController extends BaseController
'id.required' => 'ID不能为空'
]);
$data = $logic->getInfo($this->param['id']);
return $this->success(Arr::twoKeepKeys($data, ['id', 'title', 'seo_title', 'seo_keywords', 'seo_description', 'created_at']));
return $this->success(Arr::twoKeepKeys($data, ['id', 'project_id', 'title', 'seo_title', 'seo_keywords', 'seo_description', 'created_at', 'route', 'url']));
}
public function save(KeywordRequest $request, KeywordLogic $logic)
... ...
... ... @@ -55,7 +55,7 @@ class ProductController extends BaseController
$map[] = ['status', $this->param['status']];
}
$sort = ['id' => 'desc'];
$data = $logic->getList($map, $sort, ['id', 'title', 'thumb', 'category_id', 'keyword_id', 'status', 'created_uid', 'created_at', 'updated_at']);
$data = $logic->getList($map, $sort, ['id', 'project_id', 'title', 'thumb', 'category_id', 'keyword_id', 'status', 'created_uid', 'created_at', 'updated_at']);
return $this->success($data);
}
... ... @@ -66,8 +66,8 @@ class ProductController extends BaseController
'id.required' => 'ID不能为空'
]);
$data = $logic->getInfo($this->param['id']);
return $this->success(Arr::twoKeepKeys($data, ['id', 'title', 'gallery', 'attrs', 'category_id', 'keyword_id', 'attr_id', 'describe_id', 'intro', 'content',
'describe', 'seo_mate', 'related_product_id', 'status', 'category_id_text', 'keyword_id_text', 'status_text', 'created_uid', 'created_uid_text', 'route']));
return $this->success(Arr::twoKeepKeys($data, ['id', 'project_id', 'title', 'gallery', 'attrs', 'category_id', 'keyword_id', 'attr_id', 'describe_id', 'intro', 'content',
'describe', 'seo_mate', 'related_product_id', 'status', 'category_id_text', 'keyword_id_text', 'status_text', 'created_uid', 'created_uid_text', 'route', 'url']));
}
public function save(ProductRequest $request, ProductLogic $logic)
... ...
... ... @@ -7,6 +7,7 @@ use App\Enums\Common\Code;
use App\Enums\Common\Common;
use App\Exceptions\BsideGlobalException;
use App\Http\Controllers\File\ImageController;
use App\Http\Logic\Aside\Project\ProjectLogic;
use App\Http\Logic\Logic;
use App\Models\File\Image as ImageModel;
use Illuminate\Support\Facades\Cache;
... ... @@ -25,6 +26,8 @@ class BaseLogic extends Logic
protected $user;
protected $project;
protected $side = Common::B;
public function __construct()
... ... @@ -32,6 +35,7 @@ class BaseLogic extends Logic
$this->request = request();
$this->requestAll = request()->all();
$this->user = Cache::get(request()->header('token'));
$this->project = (new ProjectLogic())->getInfo($this->user['project_id']);
}
... ... @@ -152,4 +156,14 @@ class BaseLogic extends Logic
}
return $rs;
}
public function getProjectDomain(){
if(!empty($this->project['deploy_optimize']['domain'])){
return $this->project['deploy_optimize']['domain'];
}
if(!empty($this->project['deploy_build']['test_domain'])){
return $this->project['deploy_build']['test_domain'];
}
return '';
}
}
... ...
... ... @@ -27,6 +27,26 @@ class CategoryLogic extends BaseLogic
$this->model = new Category();
}
public function getList(array $map = [], array $sort = ['id' => 'desc'], array $columns = ['*'], int $limit = 20)
{
$data = parent::getList($map, $sort, $columns, $limit);
foreach ($data as &$v){
$v['url'] = $this->getProjectDomain() . $v['route'] ;
$v['product_num'] = $this->getProductNum($v['id']);
}
if(!$map){
$data = Arr::listToTree($data);
}
return $this->success($data);
}
public function getInfo($id)
{
$info = parent::getInfo($id);
$info['url'] = $this->getProjectDomain() . $info['route'] ;
return $this->success($info);
}
public function save($param){
$param['pid'] = $param['pid'] ?? 0;
if(!empty($param['pid'])){
... ... @@ -57,13 +77,12 @@ class CategoryLogic extends BaseLogic
DB::beginTransaction();
try {
parent::delete($ids);
foreach ($ids as $id){
$info = $this->getCacheInfo($id);
if(!$info){
continue;
}
//是否有子分类
if(Category::where('project_id', $this->user['project_id'])->where('pid', $id)->count()){
$this->fail("分类{$info['title']}存在子分类,不能删除");
... ... @@ -72,10 +91,10 @@ class CategoryLogic extends BaseLogic
if(CategoryRelated::where('cate_id', $id)->count()){
$this->fail("分类{$info['title']}存在产品,不能删除");
}
//删除路由映射
RouteMap::delRoute(RouteMap::SOURCE_PRODUCT_CATE, $id, $this->user['project_id']);
}
parent::delete($ids);
DB::commit();
} catch (BsideGlobalException $e){
... ...
... ... @@ -25,6 +25,24 @@ class KeywordLogic extends BaseLogic
$this->model = new Keyword();
}
public function getList(array $map = [], array $sort = ['id' => 'desc'], array $columns = ['*'], int $limit = 20)
{
$data = parent::getList($map, $sort, $columns, $limit);
foreach ($data['list'] as &$v){
$v['product_num'] = $this->getProductNum($v['id']);
$v['tdk'] = boolval($v['seo_title']) * boolval($v['seo_keywords']) * boolval($v['seo_description']);
$v['url'] = $this->getProjectDomain() . $v['route'];
}
return $this->success($data);
}
public function getInfo($id)
{
$info = parent::getInfo($id);
$info['url'] = $this->getProjectDomain() . $info['route'];
return $this->success($info);
}
public function save($param){
DB::beginTransaction();
try {
... ... @@ -45,8 +63,6 @@ class KeywordLogic extends BaseLogic
DB::beginTransaction();
try {
parent::delete($ids);
foreach ($ids as $id){
$info = $this->getCacheInfo($id);
if(!$info){
... ... @@ -61,6 +77,7 @@ class KeywordLogic extends BaseLogic
//删除路由映射
RouteMap::delRoute(RouteMap::SOURCE_PRODUCT_KEYWORD, $id, $this->user['project_id']);
}
parent::delete($ids);
DB::commit();
} catch (BsideGlobalException $e){
... ...
... ... @@ -53,6 +53,7 @@ class ProductLogic extends BaseLogic
$info['keyword_id_text'] = Arr::arrToSet($info['keyword_id_text'], 'trim');
$info['status_text'] = Product::statusMap()[$info['status']] ?? '';
$info['created_uid_text'] = (new UserLogic())->getCacheInfo($info['created_uid'])['name'] ?? '';
$info['url'] = $this->getProjectDomain() . $info['route'] ;
return $info;
}
... ... @@ -85,8 +86,6 @@ class ProductLogic extends BaseLogic
DB::beginTransaction();
try {
parent::delete($ids);
foreach ($ids as $id){
//删除路由映射
RouteMap::delRoute(RouteMap::SOURCE_PRODUCT, $id, $this->user['project_id']);
... ... @@ -97,6 +96,7 @@ class ProductLogic extends BaseLogic
//删除关键词关联
KeywordRelated::where('product_id', $id)->delete();
}
parent::delete($ids);
DB::commit();
}catch (\Exception $e){
... ...
... ... @@ -4,6 +4,7 @@ namespace App\Models\Product;
use App\Models\Base;
use App\Models\RouteMap;
use App\Services\Facades\Upload;
use Illuminate\Database\Eloquent\SoftDeletes;
... ... @@ -22,6 +23,13 @@ class Category extends Base
*/
protected $child_ids_arr = [];
protected $appends = ['route'];
public function getRouteAttribute(){
return RouteMap::getRoute(RouteMap::SOURCE_PRODUCT_CATE, $this->id, $this->project_id);
}
public function getImageAttribute($value)
{
return Upload::path2url($value);
... ...