作者 赵彬吉

update

@@ -35,6 +35,7 @@ class BaseController extends Controller @@ -35,6 +35,7 @@ class BaseController extends Controller
35 $info = Cache::get($this->token); 35 $info = Cache::get($this->token);
36 $this->user = $info; 36 $this->user = $info;
37 $this->uid = $info['id']; 37 $this->uid = $info['id'];
  38 + $this->param['project_id'] = $this->user['project_id'];
38 }else{ 39 }else{
39 return response(['code'=>Code::USER_ERROR,'msg'=>'当前用户未登录']); 40 return response(['code'=>Code::USER_ERROR,'msg'=>'当前用户未登录']);
40 } 41 }
@@ -28,7 +28,7 @@ class KeywordLogic extends BaseLogic @@ -28,7 +28,7 @@ class KeywordLogic extends BaseLogic
28 try { 28 try {
29 $res = parent::save($param); 29 $res = parent::save($param);
30 //路由映射 30 //路由映射
31 - RouteMap::setRoute($param['title'], RouteMap::SOURCE_PRODUCT_KEYWORD, $res['id'], $param['project_id'] ?? 0); 31 + RouteMap::setRoute($param['title'], RouteMap::SOURCE_PRODUCT_KEYWORD, $res['id'], $param['project_id'], true);
32 DB::commit(); 32 DB::commit();
33 }catch (\Exception $e){ 33 }catch (\Exception $e){
34 DB::rollBack(); 34 DB::rollBack();
@@ -47,6 +47,8 @@ class KeywordLogic extends BaseLogic @@ -47,6 +47,8 @@ class KeywordLogic extends BaseLogic
47 47
48 //todo 是否有关联商品 48 //todo 是否有关联商品
49 49
  50 + //todo 删除路由映射 事务
  51 +
50 } 52 }
51 return parent::delete($ids); 53 return parent::delete($ids);
52 } 54 }
@@ -3,6 +3,7 @@ @@ -3,6 +3,7 @@
3 namespace App\Models\Product; 3 namespace App\Models\Product;
4 4
5 use App\Models\Base; 5 use App\Models\Base;
  6 +use App\Models\RouteMap;
6 use Illuminate\Database\Eloquent\SoftDeletes; 7 use Illuminate\Database\Eloquent\SoftDeletes;
7 8
8 class Keyword extends Base 9 class Keyword extends Base
@@ -12,4 +13,9 @@ class Keyword extends Base @@ -12,4 +13,9 @@ class Keyword extends Base
12 //设置关联表名 13 //设置关联表名
13 protected $table = 'gl_product_keyword'; 14 protected $table = 'gl_product_keyword';
14 15
  16 + protected $appends = ['route'];
  17 +
  18 + public function getRouteAttribute(){
  19 + return RouteMap::getRoute(RouteMap::SOURCE_PRODUCT_KEYWORD, $this->id, $this->project_id);
  20 + }
15 } 21 }
@@ -37,7 +37,7 @@ class RouteMap extends Model @@ -37,7 +37,7 @@ class RouteMap extends Model
37 $i=1; 37 $i=1;
38 $sign = generateRoute($title); 38 $sign = generateRoute($title);
39 $route = $sign; 39 $route = $sign;
40 - while(self::isExist($route, $project_id, $source, $source_id)){ 40 + while(self::isExist($route, $source, $source_id, $project_id)){
41 $route = $sign .'-'.$i; 41 $route = $sign .'-'.$i;
42 $i++; 42 $i++;
43 } 43 }
@@ -113,8 +113,8 @@ class RouteMap extends Model @@ -113,8 +113,8 @@ class RouteMap extends Model
113 * @author zbj 113 * @author zbj
114 * @date 2023/4/17 114 * @date 2023/4/17
115 */ 115 */
116 - public function getRouteInfo($route, $project_id = 0){  
117 - return self::whereIn('project_id', [0, $project_id])->where('route', $route)->get(); 116 + public function getRouteInfo($route, $project_id){
  117 + return self::where('project_id',$project_id)->where('route', $route)->get();
118 } 118 }
119 119
120 /** 120 /**
@@ -125,15 +125,8 @@ class RouteMap extends Model @@ -125,15 +125,8 @@ class RouteMap extends Model
125 * @author zbj 125 * @author zbj
126 * @date 2023/4/17 126 * @date 2023/4/17
127 */ 127 */
128 - public static function getRoute($source, $source_id, $project_id = 0){  
129 - if(!$project_id){  
130 - return self::where([  
131 - 'project_id' => 0,  
132 - 'source' => $source,  
133 - 'source_id' => $source_id  
134 - ])->value('route');  
135 - }  
136 - return self::whereIn('project_id', [0, $project_id])->where('source', $source)->where('source_id', $source_id)->value('route'); 128 + public static function getRoute($source, $source_id, $project_id){
  129 + return self::where('project_id', $project_id)->where('source', $source)->where('source_id', $source_id)->value('route');
137 } 130 }
138 131
139 /** 132 /**
@@ -144,7 +137,20 @@ class RouteMap extends Model @@ -144,7 +137,20 @@ class RouteMap extends Model
144 * @author zbj 137 * @author zbj
145 * @date 2023/4/17 138 * @date 2023/4/17
146 */ 139 */
147 - public static function getSourceId($route, $source, $project_id = 0){  
148 - return self::whereIn('project_id', [0, $project_id])->where('source', $source)->where('route', $route)->value('source_id'); 140 + public static function getSourceId($route, $source, $project_id){
  141 + return self::where('project_id', $project_id)->where('source', $source)->where('route', $route)->value('source_id');
  142 + }
  143 +
  144 +
  145 + /**
  146 + * @param $source
  147 + * @param $source_id
  148 + * @param $project_id
  149 + * @return mixed
  150 + * @author zbj
  151 + * @date 2023/4/17
  152 + */
  153 + public function delRoute($source, $source_id, $project_id){
  154 + return self::where('project_id', $project_id)->where('source', $source)->where('source_id', $source_id)->delete();
149 } 155 }
150 } 156 }
@@ -34,12 +34,6 @@ Route::middleware(['bloginauth'])->group(function () { @@ -34,12 +34,6 @@ Route::middleware(['bloginauth'])->group(function () {
34 Route::any('/project_group/lists', [\App\Http\Controllers\Bside\ProjectGroupController::class, 'lists'])->name('project_group_lists'); 34 Route::any('/project_group/lists', [\App\Http\Controllers\Bside\ProjectGroupController::class, 'lists'])->name('project_group_lists');
35 Route::any('/project_group/del', [\App\Http\Controllers\Bside\ProjectGroupController::class, 'del'])->name('project_group_del'); 35 Route::any('/project_group/del', [\App\Http\Controllers\Bside\ProjectGroupController::class, 'del'])->name('project_group_del');
36 36
37 -});  
38 -  
39 -//无需登录验证的路由组  
40 -Route::group([], function () {  
41 - Route::any('/login', [\App\Http\Controllers\Bside\ComController::class, 'login'])->name('login');  
42 -  
43 //产品 37 //产品
44 Route::prefix('product')->group(function () { 38 Route::prefix('product')->group(function () {
45 //产品 39 //产品
@@ -73,3 +67,10 @@ Route::group([], function () { @@ -73,3 +67,10 @@ Route::group([], function () {
73 Route::any('describe/delete', [\App\Http\Controllers\Bside\Product\DescribeController::class, 'delete'])->name('product_describe_delete'); 67 Route::any('describe/delete', [\App\Http\Controllers\Bside\Product\DescribeController::class, 'delete'])->name('product_describe_delete');
74 }); 68 });
75 }); 69 });
  70 +
  71 +//无需登录验证的路由组
  72 +Route::group([], function () {
  73 + Route::any('/login', [\App\Http\Controllers\Bside\ComController::class, 'login'])->name('login');
  74 +
  75 +
  76 +});