Merge branch 'dev' of http://47.244.231.31:8099/zhl/globalso-v6 into dev
正在显示
6 个修改的文件
包含
57 行增加
和
13 行删除
| @@ -16,11 +16,15 @@ class BaseLogic | @@ -16,11 +16,15 @@ class BaseLogic | ||
| 16 | 16 | ||
| 17 | protected $requestAll; | 17 | protected $requestAll; |
| 18 | 18 | ||
| 19 | + protected $user; | ||
| 20 | + | ||
| 19 | protected $is_cache = true; //是否缓存数据 | 21 | protected $is_cache = true; //是否缓存数据 |
| 20 | 22 | ||
| 21 | public function __construct() | 23 | public function __construct() |
| 22 | { | 24 | { |
| 23 | $this->requestAll = request()->all(); | 25 | $this->requestAll = request()->all(); |
| 26 | + | ||
| 27 | + $this->user = Cache::get(request()->header('token')); | ||
| 24 | } | 28 | } |
| 25 | 29 | ||
| 26 | /** | 30 | /** |
| @@ -57,6 +61,7 @@ class BaseLogic | @@ -57,6 +61,7 @@ class BaseLogic | ||
| 57 | */ | 61 | */ |
| 58 | public function getList(array $map = [], array $sort = ['id' => 'desc'], array $columns = ['*'], int $limit = 20) | 62 | public function getList(array $map = [], array $sort = ['id' => 'desc'], array $columns = ['*'], int $limit = 20) |
| 59 | { | 63 | { |
| 64 | + $map[] = ['project_id' => $this->user['project_id']]; | ||
| 60 | // 闭包查询条件格式化 | 65 | // 闭包查询条件格式化 |
| 61 | $query = $this->formatQuery($map); | 66 | $query = $this->formatQuery($map); |
| 62 | 67 | ||
| @@ -112,6 +117,9 @@ class BaseLogic | @@ -112,6 +117,9 @@ class BaseLogic | ||
| 112 | }else{ | 117 | }else{ |
| 113 | $info = $this->model->find($id); | 118 | $info = $this->model->find($id); |
| 114 | } | 119 | } |
| 120 | + if($info && $info['project_id'] != $this->user['project_id']) { | ||
| 121 | + $info = null; | ||
| 122 | + } | ||
| 115 | return $info; | 123 | return $info; |
| 116 | } | 124 | } |
| 117 | 125 | ||
| @@ -162,6 +170,8 @@ class BaseLogic | @@ -162,6 +170,8 @@ class BaseLogic | ||
| 162 | $this->fail('ID不能为空'); | 170 | $this->fail('ID不能为空'); |
| 163 | } | 171 | } |
| 164 | $map[] = ['id', 'in', $ids]; | 172 | $map[] = ['id', 'in', $ids]; |
| 173 | + $map[] = ['project_id' => $this->user['project_id']]; | ||
| 174 | + | ||
| 165 | $res = $this->formatQuery($map)->delete(); | 175 | $res = $this->formatQuery($map)->delete(); |
| 166 | if($res){ | 176 | if($res){ |
| 167 | 177 |
| @@ -25,6 +25,9 @@ class AttrLogic extends BaseLogic | @@ -25,6 +25,9 @@ class AttrLogic extends BaseLogic | ||
| 25 | 25 | ||
| 26 | public function getInfo($id){ | 26 | public function getInfo($id){ |
| 27 | $info = parent::getCacheInfo($id); | 27 | $info = parent::getCacheInfo($id); |
| 28 | + if(!$info){ | ||
| 29 | + $this->fail('数据不存在或者已经删除'); | ||
| 30 | + } | ||
| 28 | $info->values; | 31 | $info->values; |
| 29 | return $this->success($info->toArray()); | 32 | return $this->success($info->toArray()); |
| 30 | } | 33 | } |
| @@ -5,6 +5,7 @@ namespace App\Http\Logic\Bside\Product; | @@ -5,6 +5,7 @@ namespace App\Http\Logic\Bside\Product; | ||
| 5 | use App\Helper\Arr; | 5 | use App\Helper\Arr; |
| 6 | use App\Http\Logic\Bside\BaseLogic; | 6 | use App\Http\Logic\Bside\BaseLogic; |
| 7 | use App\Models\Product\Category; | 7 | use App\Models\Product\Category; |
| 8 | +use App\Models\Product\Product; | ||
| 8 | 9 | ||
| 9 | /** | 10 | /** |
| 10 | * Class CategoryLogic | 11 | * Class CategoryLogic |
| @@ -45,8 +46,10 @@ class CategoryLogic extends BaseLogic | @@ -45,8 +46,10 @@ class CategoryLogic extends BaseLogic | ||
| 45 | if(Category::where('pid', $id)->count()){ | 46 | if(Category::where('pid', $id)->count()){ |
| 46 | $this->fail("分类{$info['title']}存在子分类,不能删除"); | 47 | $this->fail("分类{$info['title']}存在子分类,不能删除"); |
| 47 | } | 48 | } |
| 48 | - //todo 是否有对应商品 | ||
| 49 | - | 49 | + //是否有对应商品 |
| 50 | + if(Product::whereRaw("FIND_IN_SET({$id},`category_id`)")->count()){ | ||
| 51 | + $this->fail("分类{$info['title']}存在产品,不能删除"); | ||
| 52 | + } | ||
| 50 | } | 53 | } |
| 51 | return parent::delete($ids); | 54 | return parent::delete($ids); |
| 52 | } | 55 | } |
| @@ -4,6 +4,7 @@ namespace App\Http\Logic\Bside\Product; | @@ -4,6 +4,7 @@ namespace App\Http\Logic\Bside\Product; | ||
| 4 | 4 | ||
| 5 | use App\Helper\Arr; | 5 | use App\Helper\Arr; |
| 6 | use App\Http\Logic\Bside\BaseLogic; | 6 | use App\Http\Logic\Bside\BaseLogic; |
| 7 | +use App\Models\Product\Product; | ||
| 7 | use App\Models\RouteMap; | 8 | use App\Models\RouteMap; |
| 8 | use App\Models\Product\Keyword; | 9 | use App\Models\Product\Keyword; |
| 9 | use Illuminate\Support\Facades\DB; | 10 | use Illuminate\Support\Facades\DB; |
| @@ -28,7 +29,7 @@ class KeywordLogic extends BaseLogic | @@ -28,7 +29,7 @@ class KeywordLogic extends BaseLogic | ||
| 28 | try { | 29 | try { |
| 29 | $res = parent::save($param); | 30 | $res = parent::save($param); |
| 30 | //路由映射 | 31 | //路由映射 |
| 31 | - RouteMap::setRoute($param['title'], RouteMap::SOURCE_PRODUCT_KEYWORD, $res['id'], $param['project_id']); | 32 | + RouteMap::setRoute($param['title'], RouteMap::SOURCE_PRODUCT_KEYWORD, $res['id'], $this->user['project_id']); |
| 32 | DB::commit(); | 33 | DB::commit(); |
| 33 | }catch (\Exception $e){ | 34 | }catch (\Exception $e){ |
| 34 | DB::rollBack(); | 35 | DB::rollBack(); |
| @@ -39,17 +40,22 @@ class KeywordLogic extends BaseLogic | @@ -39,17 +40,22 @@ class KeywordLogic extends BaseLogic | ||
| 39 | 40 | ||
| 40 | public function delete($ids){ | 41 | public function delete($ids){ |
| 41 | $ids= array_filter(Arr::splitFilterToArray($ids), 'intval'); | 42 | $ids= array_filter(Arr::splitFilterToArray($ids), 'intval'); |
| 42 | - foreach ($ids as $id){ | ||
| 43 | - $info = $this->getCacheInfo($id); | ||
| 44 | - if(!$info){ | ||
| 45 | - continue; | ||
| 46 | - } | ||
| 47 | 43 | ||
| 48 | - //todo 是否有关联商品 | 44 | + DB::beginTransaction(); |
| 45 | + try { | ||
| 46 | + parent::delete($ids); | ||
| 49 | 47 | ||
| 50 | - //todo 删除路由映射 事务 | 48 | + foreach ($ids as $id){ |
| 49 | + //删除路由映射 | ||
| 50 | + RouteMap::delRoute(RouteMap::SOURCE_PRODUCT_KEYWORD, $id, $this->user['project_id']); | ||
| 51 | + } | ||
| 51 | 52 | ||
| 53 | + DB::commit(); | ||
| 54 | + }catch (\Exception $e){ | ||
| 55 | + DB::rollBack(); | ||
| 56 | + $this->fail('删除失败'); | ||
| 52 | } | 57 | } |
| 53 | - return parent::delete($ids); | 58 | + |
| 59 | + return $this->success(); | ||
| 54 | } | 60 | } |
| 55 | } | 61 | } |
| @@ -2,6 +2,7 @@ | @@ -2,6 +2,7 @@ | ||
| 2 | 2 | ||
| 3 | namespace App\Http\Logic\Bside\Product; | 3 | namespace App\Http\Logic\Bside\Product; |
| 4 | 4 | ||
| 5 | +use App\Helper\Arr; | ||
| 5 | use App\Http\Logic\Bside\BaseLogic; | 6 | use App\Http\Logic\Bside\BaseLogic; |
| 6 | use App\Models\Product\Product; | 7 | use App\Models\Product\Product; |
| 7 | use App\Models\RouteMap; | 8 | use App\Models\RouteMap; |
| @@ -29,7 +30,7 @@ class ProductLogic extends BaseLogic | @@ -29,7 +30,7 @@ class ProductLogic extends BaseLogic | ||
| 29 | unset($data['route']); | 30 | unset($data['route']); |
| 30 | $res = parent::save($data); | 31 | $res = parent::save($data); |
| 31 | //路由映射 | 32 | //路由映射 |
| 32 | - RouteMap::setRoute($param['route'], RouteMap::SOURCE_PRODUCT, $res['id'], $param['project_id']); | 33 | + RouteMap::setRoute($param['route'], RouteMap::SOURCE_PRODUCT, $res['id'], $this->user['project_id']); |
| 33 | DB::commit(); | 34 | DB::commit(); |
| 34 | }catch (\Exception $e){ | 35 | }catch (\Exception $e){ |
| 35 | DB::rollBack(); | 36 | DB::rollBack(); |
| @@ -37,4 +38,25 @@ class ProductLogic extends BaseLogic | @@ -37,4 +38,25 @@ class ProductLogic extends BaseLogic | ||
| 37 | } | 38 | } |
| 38 | return $this->success(); | 39 | return $this->success(); |
| 39 | } | 40 | } |
| 41 | + | ||
| 42 | + public function delete($ids){ | ||
| 43 | + $ids= array_filter(Arr::splitFilterToArray($ids), 'intval'); | ||
| 44 | + | ||
| 45 | + DB::beginTransaction(); | ||
| 46 | + try { | ||
| 47 | + parent::delete($ids); | ||
| 48 | + | ||
| 49 | + foreach ($ids as $id){ | ||
| 50 | + //删除路由映射 | ||
| 51 | + RouteMap::delRoute(RouteMap::SOURCE_PRODUCT, $id, $this->user['project_id']); | ||
| 52 | + } | ||
| 53 | + | ||
| 54 | + DB::commit(); | ||
| 55 | + }catch (\Exception $e){ | ||
| 56 | + DB::rollBack(); | ||
| 57 | + $this->fail('删除失败'); | ||
| 58 | + } | ||
| 59 | + | ||
| 60 | + return $this->success(); | ||
| 61 | + } | ||
| 40 | } | 62 | } |
| @@ -145,7 +145,7 @@ class RouteMap extends Model | @@ -145,7 +145,7 @@ class RouteMap extends Model | ||
| 145 | * @author zbj | 145 | * @author zbj |
| 146 | * @date 2023/4/17 | 146 | * @date 2023/4/17 |
| 147 | */ | 147 | */ |
| 148 | - public function delRoute($source, $source_id, $project_id){ | 148 | + public static function delRoute($source, $source_id, $project_id){ |
| 149 | return self::where('project_id', $project_id)->where('source', $source)->where('source_id', $source_id)->delete(); | 149 | return self::where('project_id', $project_id)->where('source', $source)->where('source_id', $source_id)->delete(); |
| 150 | } | 150 | } |
| 151 | } | 151 | } |
-
请 注册 或 登录 后发表评论