Merge branch 'dev' of http://47.244.231.31:8099/zhl/globalso-v6 into dev
正在显示
18 个修改的文件
包含
126 行增加
和
276 行删除
| @@ -25,7 +25,7 @@ class AttrController extends BaseController | @@ -25,7 +25,7 @@ class AttrController 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', 'title', 'remark', 'value_num']); | 28 | + $data = $logic->getList($map, $sort, ['id', 'title', 'attrs']); |
| 29 | return $this->success($data); | 29 | return $this->success($data); |
| 30 | } | 30 | } |
| 31 | 31 | ||
| @@ -36,7 +36,7 @@ class AttrController extends BaseController | @@ -36,7 +36,7 @@ class AttrController extends BaseController | ||
| 36 | 'id.required' => 'ID不能为空' | 36 | 'id.required' => 'ID不能为空' |
| 37 | ]); | 37 | ]); |
| 38 | $data = $logic->getInfo($this->param['id']); | 38 | $data = $logic->getInfo($this->param['id']); |
| 39 | - return $this->success(Arr::twoKeepKeys($data, ['id', 'title', 'remark', 'values'])); | 39 | + return $this->success(Arr::twoKeepKeys($data, ['id', 'title', 'attrs'])); |
| 40 | } | 40 | } |
| 41 | 41 | ||
| 42 | public function save(AttrRequest $request, AttrLogic $logic) | 42 | public function save(AttrRequest $request, AttrLogic $logic) |
| @@ -28,7 +28,7 @@ class KeywordController extends BaseController | @@ -28,7 +28,7 @@ class KeywordController extends BaseController | ||
| 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']); | 29 | $data = $logic->getList($map, $sort, ['id', 'title', 'seo_title', 'seo_keywords', 'seo_description', 'status', 'created_at']); |
| 30 | foreach ($data['list'] as &$v){ | 30 | foreach ($data['list'] as &$v){ |
| 31 | - $v['product_num'] = $logic->getProductNum($v['title']); | 31 | + $v['product_num'] = $logic->getProductNum($v['id']); |
| 32 | $v['tdk'] = boolval($v['seo_title']) * boolval($v['seo_keywords']) * boolval($v['seo_description']); | 32 | $v['tdk'] = boolval($v['seo_title']) * boolval($v['seo_keywords']) * boolval($v['seo_description']); |
| 33 | //todo 获取域名 拼接链接 | 33 | //todo 获取域名 拼接链接 |
| 34 | $v['url'] = $v['route']; | 34 | $v['url'] = $v['route']; |
| @@ -9,6 +9,7 @@ use App\Http\Controllers\Bside\BaseController; | @@ -9,6 +9,7 @@ use App\Http\Controllers\Bside\BaseController; | ||
| 9 | use App\Http\Logic\Bside\Product\ProductLogic; | 9 | use App\Http\Logic\Bside\Product\ProductLogic; |
| 10 | use App\Http\Requests\Bside\Product\ProductRequest; | 10 | use App\Http\Requests\Bside\Product\ProductRequest; |
| 11 | use App\Models\Product\CategoryRelated; | 11 | use App\Models\Product\CategoryRelated; |
| 12 | +use App\Models\Product\KeywordRelated; | ||
| 12 | use App\Rules\Ids; | 13 | use App\Rules\Ids; |
| 13 | use Illuminate\Http\Request; | 14 | use Illuminate\Http\Request; |
| 14 | 15 | ||
| @@ -34,6 +35,10 @@ class ProductController extends BaseController | @@ -34,6 +35,10 @@ class ProductController extends BaseController | ||
| 34 | $ids = CategoryRelated::where('cate_id', $this->param['category_id'])->pluck('product_id')->toArray(); | 35 | $ids = CategoryRelated::where('cate_id', $this->param['category_id'])->pluck('product_id')->toArray(); |
| 35 | $map[] = ['id', 'in', $ids]; | 36 | $map[] = ['id', 'in', $ids]; |
| 36 | } | 37 | } |
| 38 | + if(!empty($this->param['keyword_id'])){ | ||
| 39 | + $ids = KeywordRelated::where('keyword_id', $this->param['keyword_id'])->pluck('product_id')->toArray(); | ||
| 40 | + $map[] = ['id', 'in', $ids]; | ||
| 41 | + } | ||
| 37 | if(isset($this->param['status'])){ | 42 | if(isset($this->param['status'])){ |
| 38 | $map[] = ['status', $this->param['status']]; | 43 | $map[] = ['status', $this->param['status']]; |
| 39 | } | 44 | } |
| @@ -26,6 +26,8 @@ class ImageController | @@ -26,6 +26,8 @@ class ImageController | ||
| 26 | ]; | 26 | ]; |
| 27 | public $path = ''; | 27 | public $path = ''; |
| 28 | 28 | ||
| 29 | + public $config = ''; | ||
| 30 | + | ||
| 29 | public $thr_path = ''; | 31 | public $thr_path = ''; |
| 30 | 32 | ||
| 31 | public $request = ''; | 33 | public $request = ''; |
| @@ -33,7 +35,8 @@ class ImageController | @@ -33,7 +35,8 @@ class ImageController | ||
| 33 | public function __construct(Request $request) | 35 | public function __construct(Request $request) |
| 34 | { | 36 | { |
| 35 | $this->request = $request; | 37 | $this->request = $request; |
| 36 | - $this->path = config('filesystems.disks')['upload']['root'].config('upload'); | 38 | + $this->config = config('filesystems.disks.upload'); |
| 39 | + $this->path = $this->config['root']; | ||
| 37 | } | 40 | } |
| 38 | 41 | ||
| 39 | public function index($hash = '', $w = 0 ,$h = 0){ | 42 | public function index($hash = '', $w = 0 ,$h = 0){ |
| @@ -105,25 +108,30 @@ class ImageController | @@ -105,25 +108,30 @@ class ImageController | ||
| 105 | */ | 108 | */ |
| 106 | public function single($files){ | 109 | public function single($files){ |
| 107 | $hash = hash_file('md5', $files->getPathname()); | 110 | $hash = hash_file('md5', $files->getPathname()); |
| 111 | + //查看文件是否存在 | ||
| 112 | + $imageModel = new ImageModel(); | ||
| 113 | + $image_hash = $imageModel->read(['hash'=>$hash]); | ||
| 114 | + if($image_hash !== false){ | ||
| 115 | + return $hash; | ||
| 116 | + } | ||
| 108 | $url = $this->path; | 117 | $url = $this->path; |
| 109 | $filename = date('ymdHis').rand(10000,99999); | 118 | $filename = date('ymdHis').rand(10000,99999); |
| 110 | $res = $this->request->file('image')->move($url,$filename); | 119 | $res = $this->request->file('image')->move($url,$filename); |
| 111 | if ($res === false) { | 120 | if ($res === false) { |
| 112 | return $this->response($files->getError(), Code::USER_ERROR); | 121 | return $this->response($files->getError(), Code::USER_ERROR); |
| 113 | } | 122 | } |
| 114 | - $imageModel = new ImageModel(); | ||
| 115 | $data = [ | 123 | $data = [ |
| 116 | 'path' => $url.$filename, | 124 | 'path' => $url.$filename, |
| 117 | 'created_at' => date('Y-m-d H:i:s',time()), | 125 | 'created_at' => date('Y-m-d H:i:s',time()), |
| 118 | 'size' => $res->getSize(), | 126 | 'size' => $res->getSize(), |
| 119 | - 'hash' => $hash.$filename, | 127 | + 'hash' => $hash, |
| 120 | 'type'=>$files->getClientOriginalExtension(), | 128 | 'type'=>$files->getClientOriginalExtension(), |
| 121 | ]; | 129 | ]; |
| 122 | $rs = $imageModel->add($data); | 130 | $rs = $imageModel->add($data); |
| 123 | if ($rs === false) { | 131 | if ($rs === false) { |
| 124 | return $this->response('添加失败', Code::USER_ERROR); | 132 | return $this->response('添加失败', Code::USER_ERROR); |
| 125 | } | 133 | } |
| 126 | - return $hash.$filename; | 134 | + return $hash; |
| 127 | } | 135 | } |
| 128 | /** | 136 | /** |
| 129 | * 生成缩略图缓存 | 137 | * 生成缩略图缓存 |
| @@ -151,7 +159,13 @@ class ImageController | @@ -151,7 +159,13 @@ class ImageController | ||
| 151 | $save_data = []; | 159 | $save_data = []; |
| 152 | $data = []; | 160 | $data = []; |
| 153 | foreach ($files as $file) { | 161 | foreach ($files as $file) { |
| 162 | + $imageModel = new ImageModel(); | ||
| 154 | $hash = hash_file('md5', $file->getPathname()); | 163 | $hash = hash_file('md5', $file->getPathname()); |
| 164 | + $image_hash = $imageModel->read(['hash'=>$hash]); | ||
| 165 | + if($image_hash !== false){ | ||
| 166 | + $data[] = $hash; | ||
| 167 | + continue; | ||
| 168 | + } | ||
| 155 | $url = $this->path; | 169 | $url = $this->path; |
| 156 | $filename = date('ymdHis').rand(10000,99999); | 170 | $filename = date('ymdHis').rand(10000,99999); |
| 157 | $res = $file->move($url,$filename); | 171 | $res = $file->move($url,$filename); |
| @@ -162,12 +176,11 @@ class ImageController | @@ -162,12 +176,11 @@ class ImageController | ||
| 162 | 'path' => $url.$filename, | 176 | 'path' => $url.$filename, |
| 163 | 'created_at' => date('Y-m-d H:i:s',time()), | 177 | 'created_at' => date('Y-m-d H:i:s',time()), |
| 164 | 'size' => $res->getSize(), | 178 | 'size' => $res->getSize(), |
| 165 | - 'hash' => $hash.$filename, | 179 | + 'hash' => $hash, |
| 166 | 'type'=>$files->getClientOriginalExtension(), | 180 | 'type'=>$files->getClientOriginalExtension(), |
| 167 | ]; | 181 | ]; |
| 168 | - $data[] = $hash.$filename; | 182 | + $data[] = $hash; |
| 169 | } | 183 | } |
| 170 | - $imageModel = new ImageModel(); | ||
| 171 | $imageModel->insert($save_data); | 184 | $imageModel->insert($save_data); |
| 172 | return $data; | 185 | return $data; |
| 173 | } | 186 | } |
| @@ -5,7 +5,7 @@ namespace App\Http\Logic\Bside; | @@ -5,7 +5,7 @@ namespace App\Http\Logic\Bside; | ||
| 5 | use App\Enums\Common\Code; | 5 | use App\Enums\Common\Code; |
| 6 | use App\Exceptions\BsideGlobalException; | 6 | use App\Exceptions\BsideGlobalException; |
| 7 | use App\Helper\Common; | 7 | use App\Helper\Common; |
| 8 | -use App\Http\Controllers\ImageLogic; | 8 | +use App\Http\Controllers\ImageController; |
| 9 | use App\Http\Logic\Logic; | 9 | use App\Http\Logic\Logic; |
| 10 | use App\Models\Image as ImageModel; | 10 | use App\Models\Image as ImageModel; |
| 11 | use Illuminate\Http\Request; | 11 | use Illuminate\Http\Request; |
| @@ -99,8 +99,9 @@ class BaseLogic extends Logic | @@ -99,8 +99,9 @@ class BaseLogic extends Logic | ||
| 99 | * @method | 99 | * @method |
| 100 | */ | 100 | */ |
| 101 | public function upload(){ | 101 | public function upload(){ |
| 102 | - $imageLogic = new ImageLogic(); | ||
| 103 | - return $imageLogic->upload(); | 102 | + $image = new ImageController(); |
| 103 | + $hash = $image->upload(); | ||
| 104 | + return $hash; | ||
| 104 | } | 105 | } |
| 105 | 106 | ||
| 106 | /** | 107 | /** |
| @@ -36,10 +36,11 @@ class InquiryLogic extends BaseLogic | @@ -36,10 +36,11 @@ class InquiryLogic extends BaseLogic | ||
| 36 | 36 | ||
| 37 | public function save($param) | 37 | public function save($param) |
| 38 | { | 38 | { |
| 39 | + //todo 根据域名 判断 project_id | ||
| 39 | $param['ip_info'] = Arr::s2a($param['ip_info']); | 40 | $param['ip_info'] = Arr::s2a($param['ip_info']); |
| 40 | $param['ip'] = $param['ip_info']['ip'] ?? ''; | 41 | $param['ip'] = $param['ip_info']['ip'] ?? ''; |
| 41 | $param['ip_country'] = $param['ip_info']['country'] ?? ''; | 42 | $param['ip_country'] = $param['ip_info']['country'] ?? ''; |
| 42 | - return parent::save($param); | 43 | + Logic::save($param); |
| 43 | } | 44 | } |
| 44 | 45 | ||
| 45 | } | 46 | } |
| @@ -96,15 +96,6 @@ class NewsLogic extends BaseLogic | @@ -96,15 +96,6 @@ class NewsLogic extends BaseLogic | ||
| 96 | try { | 96 | try { |
| 97 | //上传图片 | 97 | //上传图片 |
| 98 | if(isset($this->param['image']) && is_file($this->param['image'])){ | 98 | if(isset($this->param['image']) && is_file($this->param['image'])){ |
| 99 | - //查看当前用户是否已有头像 | ||
| 100 | - if($info !== false && !empty($info['image'])){ | ||
| 101 | - //TODO::删除资源 | ||
| 102 | - $imageModel = new Image(); | ||
| 103 | - $image_info = $imageModel->read(['hash'=>$info['image']],['id','path']); | ||
| 104 | - shell_exec('rm -rf '.$image_info['path'] . ' ./../uploads/images/cache_'. $info['image'] . '*'); | ||
| 105 | - //清空数据库 | ||
| 106 | - $imageModel->del(['hash'=>$info['image']]); | ||
| 107 | - } | ||
| 108 | $this->param['image'] = $this->upload(); | 99 | $this->param['image'] = $this->upload(); |
| 109 | } | 100 | } |
| 110 | //设置路由 | 101 | //设置路由 |
| @@ -4,8 +4,6 @@ namespace App\Http\Logic\Bside\Product; | @@ -4,8 +4,6 @@ namespace App\Http\Logic\Bside\Product; | ||
| 4 | 4 | ||
| 5 | use App\Http\Logic\Bside\BaseLogic; | 5 | use App\Http\Logic\Bside\BaseLogic; |
| 6 | use App\Models\Product\Attr; | 6 | use App\Models\Product\Attr; |
| 7 | -use App\Models\Product\AttrValue; | ||
| 8 | -use Illuminate\Support\Facades\DB; | ||
| 9 | 7 | ||
| 10 | /** | 8 | /** |
| 11 | * Class AttrLogic | 9 | * Class AttrLogic |
| @@ -22,47 +20,5 @@ class AttrLogic extends BaseLogic | @@ -22,47 +20,5 @@ class AttrLogic extends BaseLogic | ||
| 22 | $this->model = new Attr(); | 20 | $this->model = new Attr(); |
| 23 | } | 21 | } |
| 24 | 22 | ||
| 25 | - public function getInfo($id){ | ||
| 26 | - $info = parent::getCacheInfo($id); | ||
| 27 | - if(!$info){ | ||
| 28 | - $this->fail('数据不存在或者已经删除'); | ||
| 29 | - } | ||
| 30 | - $info->values; | ||
| 31 | - return $this->success($info->toArray()); | ||
| 32 | - } | ||
| 33 | - | ||
| 34 | - public function save($param){ | ||
| 35 | - $param['values'] = array_unique($param['values']); | ||
| 36 | - DB::beginTransaction(); | ||
| 37 | - try { | ||
| 38 | - //删除之前的参数值 | ||
| 39 | - if(!empty($param['id'])){ | ||
| 40 | - AttrValue::where('attr_id', $param['id'])->delete(); | ||
| 41 | - } | ||
| 42 | - | ||
| 43 | - //保存参数名称 | ||
| 44 | - $data = $param; | ||
| 45 | - unset($data['values']); | ||
| 46 | - $data['value_num'] = count($param['values']); | ||
| 47 | - $res = parent::save($data); | ||
| 48 | - $attr_id = $res['id']; | ||
| 49 | 23 | ||
| 50 | - //保存参数值 | ||
| 51 | - $values = []; | ||
| 52 | - foreach ($param['values'] as $value){ | ||
| 53 | - $values[] = [ | ||
| 54 | - 'attr_id' => $attr_id, | ||
| 55 | - 'value' => $value | ||
| 56 | - ]; | ||
| 57 | - } | ||
| 58 | - AttrValue::insert($values); | ||
| 59 | - | ||
| 60 | - DB::commit(); | ||
| 61 | - }catch (\Exception $e){ | ||
| 62 | - DB::rollBack(); | ||
| 63 | - errorLog('产品参数保存失败', $param, $e); | ||
| 64 | - $this->fail('保存失败'); | ||
| 65 | - } | ||
| 66 | - return $this->success(); | ||
| 67 | - } | ||
| 68 | } | 24 | } |
| @@ -65,7 +65,6 @@ class CategoryLogic extends BaseLogic | @@ -65,7 +65,6 @@ class CategoryLogic extends BaseLogic | ||
| 65 | */ | 65 | */ |
| 66 | public function getProductNum($cate_id){ | 66 | public function getProductNum($cate_id){ |
| 67 | $cate_ids = $this->model->getChildIdsArr($cate_id); | 67 | $cate_ids = $this->model->getChildIdsArr($cate_id); |
| 68 | - $product_ids = CategoryRelated::whereIn('cate_id', $cate_ids)->pluck('id'); | ||
| 69 | - return Product::whereIn('id', $product_ids)->count(); | 68 | + return CategoryRelated::whereIn('cate_id', $cate_ids)->count(); |
| 70 | } | 69 | } |
| 71 | } | 70 | } |
| @@ -4,7 +4,7 @@ namespace App\Http\Logic\Bside\Product; | @@ -4,7 +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\Product\KeywordRelated; |
| 8 | use App\Models\RouteMap; | 8 | use App\Models\RouteMap; |
| 9 | use App\Models\Product\Keyword; | 9 | use App\Models\Product\Keyword; |
| 10 | use Illuminate\Support\Facades\DB; | 10 | use Illuminate\Support\Facades\DB; |
| @@ -47,6 +47,16 @@ class KeywordLogic extends BaseLogic | @@ -47,6 +47,16 @@ class KeywordLogic extends BaseLogic | ||
| 47 | parent::delete($ids); | 47 | parent::delete($ids); |
| 48 | 48 | ||
| 49 | foreach ($ids as $id){ | 49 | foreach ($ids as $id){ |
| 50 | + $info = $this->getCacheInfo($id); | ||
| 51 | + if(!$info){ | ||
| 52 | + continue; | ||
| 53 | + } | ||
| 54 | + | ||
| 55 | + //是否有对应商品 | ||
| 56 | + if(KeywordRelated::where('keyword_id', $id)->count()){ | ||
| 57 | + $this->fail("关键词{$info['title']}存在产品,不能删除"); | ||
| 58 | + } | ||
| 59 | + | ||
| 50 | //删除路由映射 | 60 | //删除路由映射 |
| 51 | RouteMap::delRoute(RouteMap::SOURCE_PRODUCT_KEYWORD, $id, $this->user['project_id']); | 61 | RouteMap::delRoute(RouteMap::SOURCE_PRODUCT_KEYWORD, $id, $this->user['project_id']); |
| 52 | } | 62 | } |
| @@ -60,7 +70,7 @@ class KeywordLogic extends BaseLogic | @@ -60,7 +70,7 @@ class KeywordLogic extends BaseLogic | ||
| 60 | return $this->success(); | 70 | return $this->success(); |
| 61 | } | 71 | } |
| 62 | 72 | ||
| 63 | - public function getProductNum($title){ | ||
| 64 | - return Product::whereRaw("find_in_set('{$title}',`keywords`)")->count(); | 73 | + public function getProductNum($keyword_id){ |
| 74 | + return KeywordRelated::where('keyword_id', $keyword_id)->count(); | ||
| 65 | } | 75 | } |
| 66 | } | 76 | } |
| @@ -6,6 +6,7 @@ use App\Helper\Arr; | @@ -6,6 +6,7 @@ use App\Helper\Arr; | ||
| 6 | use App\Http\Logic\Bside\BaseLogic; | 6 | use App\Http\Logic\Bside\BaseLogic; |
| 7 | use App\Http\Logic\Bside\User\UserLogic; | 7 | use App\Http\Logic\Bside\User\UserLogic; |
| 8 | use App\Models\Product\CategoryRelated; | 8 | use App\Models\Product\CategoryRelated; |
| 9 | +use App\Models\Product\KeywordRelated; | ||
| 9 | use App\Models\Product\Product; | 10 | use App\Models\Product\Product; |
| 10 | use App\Models\RouteMap; | 11 | use App\Models\RouteMap; |
| 11 | use Illuminate\Support\Facades\DB; | 12 | use Illuminate\Support\Facades\DB; |
| @@ -62,6 +63,8 @@ class ProductLogic extends BaseLogic | @@ -62,6 +63,8 @@ class ProductLogic extends BaseLogic | ||
| 62 | $res = parent::save($data); | 63 | $res = parent::save($data); |
| 63 | //关联分类 | 64 | //关联分类 |
| 64 | CategoryRelated::saveRelated($res['id'], $data['category_id']); | 65 | CategoryRelated::saveRelated($res['id'], $data['category_id']); |
| 66 | + //关联关键词 | ||
| 67 | + KeywordRelated::saveRelated($res['id'], $data['keyword_id']); | ||
| 65 | //路由映射 | 68 | //路由映射 |
| 66 | RouteMap::setRoute($param['route'], RouteMap::SOURCE_PRODUCT, $res['id'], $this->user['project_id']); | 69 | RouteMap::setRoute($param['route'], RouteMap::SOURCE_PRODUCT, $res['id'], $this->user['project_id']); |
| 67 | DB::commit(); | 70 | DB::commit(); |
| @@ -86,6 +89,9 @@ class ProductLogic extends BaseLogic | @@ -86,6 +89,9 @@ class ProductLogic extends BaseLogic | ||
| 86 | 89 | ||
| 87 | //删除分类关联 | 90 | //删除分类关联 |
| 88 | CategoryRelated::where('product_id', $id)->delete(); | 91 | CategoryRelated::where('product_id', $id)->delete(); |
| 92 | + | ||
| 93 | + //删除关键词关联 | ||
| 94 | + KeywordRelated::where('product_id', $id)->delete(); | ||
| 89 | } | 95 | } |
| 90 | 96 | ||
| 91 | DB::commit(); | 97 | DB::commit(); |
| @@ -61,8 +61,6 @@ class WebSettingServiceLogic extends BaseLogic | @@ -61,8 +61,6 @@ class WebSettingServiceLogic extends BaseLogic | ||
| 61 | $info = $image->read(['hash'=>$this->param['hash']]); | 61 | $info = $image->read(['hash'=>$this->param['hash']]); |
| 62 | if($info !== false){ | 62 | if($info !== false){ |
| 63 | $image->del(['id'=>$info['id']]); | 63 | $image->del(['id'=>$info['id']]); |
| 64 | - //删除资源文件 | ||
| 65 | - shell_exec('rm -rf '.$info['path']); | ||
| 66 | } | 64 | } |
| 67 | DB::commit(); | 65 | DB::commit(); |
| 68 | }catch (\Exception $e){ | 66 | }catch (\Exception $e){ |
| @@ -70,18 +70,9 @@ class UserLogic extends BaseLogic | @@ -70,18 +70,9 @@ class UserLogic extends BaseLogic | ||
| 70 | try { | 70 | try { |
| 71 | //上传图片 | 71 | //上传图片 |
| 72 | if(isset($this->param['image']) && is_file($this->param['image'])){ | 72 | if(isset($this->param['image']) && is_file($this->param['image'])){ |
| 73 | - //查看当前用户是否已有头像 | ||
| 74 | - $info = $this->model->read(['id'=>$this->param['id']],['id','image']); | ||
| 75 | - if($info !== false && !empty($info['image'])){ | ||
| 76 | - //TODO::删除资源 | ||
| 77 | - $imageModel = new Image(); | ||
| 78 | - $image_info = $imageModel->read(['hash'=>$info['image']],['id','path']); | ||
| 79 | - shell_exec('rm -rf '.$image_info['path'] .'./../uploads/images/cache_'. $info['image'] . '*'); | ||
| 80 | - $imageModel->del(['hash'=>$info['image']]); | ||
| 81 | - } | ||
| 82 | $this->param['image'] = $this->upload(); | 73 | $this->param['image'] = $this->upload(); |
| 83 | - $this->model->edits($this->param); | ||
| 84 | } | 74 | } |
| 75 | + $this->model->edits($this->param); | ||
| 85 | }catch (\exception $e){ | 76 | }catch (\exception $e){ |
| 86 | $this->fail('参数错误或其他服务器原因,编辑失败'); | 77 | $this->fail('参数错误或其他服务器原因,编辑失败'); |
| 87 | } | 78 | } |
app/Http/Logic/ImageLogic.php
已删除
100644 → 0
| 1 | -<?php | ||
| 2 | - | ||
| 3 | -namespace App\Http\Controllers; | ||
| 4 | - | ||
| 5 | -use App\Enums\Common\Code; | ||
| 6 | -use App\Models\Image as ImageModel; | ||
| 7 | -use Illuminate\Http\Exceptions\HttpResponseException; | ||
| 8 | -use Illuminate\Http\JsonResponse; | ||
| 9 | -use Illuminate\Http\Request; | ||
| 10 | -use Illuminate\Support\Facades\DB; | ||
| 11 | -use Illuminate\Support\Facades\Storage; | ||
| 12 | -use Intervention\Image\Facades\Image; | ||
| 13 | - | ||
| 14 | -class ImageLogic | ||
| 15 | -{ | ||
| 16 | - public $path = ''; | ||
| 17 | - | ||
| 18 | - public $request = ''; | ||
| 19 | - | ||
| 20 | - public function __construct(Request $request) | ||
| 21 | - { | ||
| 22 | - $this->request = $request; | ||
| 23 | - $this->path = config('filesystems.disks')['upload']['root'].config('upload'); | ||
| 24 | - } | ||
| 25 | - | ||
| 26 | - /** | ||
| 27 | - * 图片上传 | ||
| 28 | - */ | ||
| 29 | - public function upload() { | ||
| 30 | - $this->request->validate([ | ||
| 31 | - 'image'=>['required'], | ||
| 32 | - ],[ | ||
| 33 | - 'image.required'=>'图片必须填写', | ||
| 34 | - ]); | ||
| 35 | - $files = $this->request->file('image'); | ||
| 36 | - if (empty($files)) { | ||
| 37 | - $this->response('没有上传的文件!', 400); | ||
| 38 | - } | ||
| 39 | - $type = $this->request->post('type', 'single'); | ||
| 40 | - if ($type == 'multi') { | ||
| 41 | - return $this->multi($files); | ||
| 42 | - } else { | ||
| 43 | - return $this->single($files); | ||
| 44 | - } | ||
| 45 | - } | ||
| 46 | - /** | ||
| 47 | - * @name :上传图片 | ||
| 48 | - * @return void | ||
| 49 | - * @author :liyuhang | ||
| 50 | - * @method | ||
| 51 | - */ | ||
| 52 | - public function single($files){ | ||
| 53 | - $hash = hash_file('md5', $files->getPathname()); | ||
| 54 | - $url = $this->path; | ||
| 55 | - $filename = date('ymdHis').rand(10000,99999); | ||
| 56 | - $res = $this->request->file('image')->move($url,$filename); | ||
| 57 | - if ($res === false) { | ||
| 58 | - return $this->response($files->getError(), Code::USER_ERROR); | ||
| 59 | - } | ||
| 60 | - $imageModel = new ImageModel(); | ||
| 61 | - $data = [ | ||
| 62 | - 'path' => $url.$filename, | ||
| 63 | - 'created_at' => date('Y-m-d H:i:s',time()), | ||
| 64 | - 'size' => $res->getSize(), | ||
| 65 | - 'hash' => $hash.$filename, | ||
| 66 | - 'type'=>$files->getClientOriginalExtension(), | ||
| 67 | - ]; | ||
| 68 | - $rs = $imageModel->add($data); | ||
| 69 | - if ($rs === false) { | ||
| 70 | - return $this->response('添加失败', Code::USER_ERROR); | ||
| 71 | - } | ||
| 72 | - return $hash.$filename; | ||
| 73 | - } | ||
| 74 | - | ||
| 75 | - /** | ||
| 76 | - * @name :(删除资源及对应表数据)del | ||
| 77 | - * @author :lyh | ||
| 78 | - * @method :post | ||
| 79 | - * @time :2023/5/4 14:57 | ||
| 80 | - */ | ||
| 81 | - public function del($hash){ | ||
| 82 | - DB::beginTransaction(); | ||
| 83 | - $imageModel = new ImageModel(); | ||
| 84 | - try { | ||
| 85 | - if(is_array($hash)){ | ||
| 86 | - foreach ($hash as $k => $v){ | ||
| 87 | - $this->del($v); | ||
| 88 | - } | ||
| 89 | - }else{ | ||
| 90 | - $info = $imageModel->read(['hash'=>$hash]); | ||
| 91 | - if($info !== false){ | ||
| 92 | - shell_exec('sudo rm -rf '.$info['path']. ' '.$this->path . $info['hash'] .'*'); | ||
| 93 | - } | ||
| 94 | - } | ||
| 95 | - $imageModel->del(['hash'=>['in',$hash]]); | ||
| 96 | - DB::commit(); | ||
| 97 | - }catch (\Exception $e){ | ||
| 98 | - DB::rollBack(); | ||
| 99 | - $this->response('error',Code::USER_ERROR); | ||
| 100 | - } | ||
| 101 | - } | ||
| 102 | - /** | ||
| 103 | - * 生成缩略图缓存 | ||
| 104 | - * @param type $info | ||
| 105 | - * @param type $w | ||
| 106 | - * @param type $h | ||
| 107 | - * @return string | ||
| 108 | - */ | ||
| 109 | - private function cacheImage($info, $w, $h) { | ||
| 110 | - $path = $info['path']; | ||
| 111 | - $filename = $this->path . $info['hash'] . $w . '_' . $h; | ||
| 112 | - Image::make($path)->resize($w, $h)->save($filename); | ||
| 113 | - return $filename; | ||
| 114 | - } | ||
| 115 | - | ||
| 116 | - /** | ||
| 117 | - * 多图片上传 | ||
| 118 | - * @param type $files file对象集合 | ||
| 119 | - * @return type | ||
| 120 | - */ | ||
| 121 | - private function multi($files) { | ||
| 122 | - if (!is_array($files)) { | ||
| 123 | - $files = [$files]; | ||
| 124 | - } | ||
| 125 | - $save_data = []; | ||
| 126 | - $data = []; | ||
| 127 | - foreach ($files as $file) { | ||
| 128 | - $hash = hash_file('md5', $file->getPathname()); | ||
| 129 | - $url = $this->path; | ||
| 130 | - $filename = date('ymdHis').rand(10000,99999); | ||
| 131 | - $res = $file->move($url,$filename); | ||
| 132 | - if ($res === false) { | ||
| 133 | - return $this->response($file->getError(), Code::USER_ERROR); | ||
| 134 | - } | ||
| 135 | - $save_data[] = [ | ||
| 136 | - 'path' => $url.$filename, | ||
| 137 | - 'created_at' => date('Y-m-d H:i:s',time()), | ||
| 138 | - 'size' => $res->getSize(), | ||
| 139 | - 'hash' => $hash.$filename, | ||
| 140 | - 'type'=>$files->getClientOriginalExtension(), | ||
| 141 | - ]; | ||
| 142 | - $data[] = $hash.$filename; | ||
| 143 | - } | ||
| 144 | - $imageModel = new ImageModel(); | ||
| 145 | - $imageModel->insert($save_data); | ||
| 146 | - return $data; | ||
| 147 | - } | ||
| 148 | - | ||
| 149 | - //下载 | ||
| 150 | - public function download($filename){ | ||
| 151 | - $path = Storage::path($filename); | ||
| 152 | - return response()->download($path,time().rand(1,100000)); | ||
| 153 | - } | ||
| 154 | - /** | ||
| 155 | - * @name 统一返回参数 | ||
| 156 | - * @return JsonResponse | ||
| 157 | - * @author :liyuhang | ||
| 158 | - * @method | ||
| 159 | - */ | ||
| 160 | - public function response($msg = null,string $code = Code::SUCCESS,$data = [],$result_code = 200,$type = 'application/json'): JsonResponse | ||
| 161 | - { | ||
| 162 | - $code = Code::fromValue($code); | ||
| 163 | - $result = [ | ||
| 164 | - 'msg' => $msg == ' ' ? $code->description : $msg, | ||
| 165 | - 'code' => $code->value, | ||
| 166 | - 'data' => $data, | ||
| 167 | - ]; | ||
| 168 | - $this->header['Content-Type'] = $type; | ||
| 169 | - $response = response($result,$result_code,$this->header); | ||
| 170 | - throw new HttpResponseException($response); | ||
| 171 | - } | ||
| 172 | -} |
| @@ -31,8 +31,16 @@ class AttrRequest extends FormRequest | @@ -31,8 +31,16 @@ class AttrRequest extends FormRequest | ||
| 31 | { | 31 | { |
| 32 | return [ | 32 | return [ |
| 33 | 'title' => 'required|max:50', | 33 | 'title' => 'required|max:50', |
| 34 | - 'remark' => 'max:200', | ||
| 35 | - 'values' => 'required|array' | 34 | + 'attrs' => ['required', 'array', function ($attribute, $value, $fail) { |
| 35 | + foreach ($value as $v) { | ||
| 36 | + if (empty($v['key'])) { | ||
| 37 | + $fail('属性名不能为空'); | ||
| 38 | + } | ||
| 39 | + if (empty($v['value'])) { | ||
| 40 | + $fail('属性值不能为空'); | ||
| 41 | + } | ||
| 42 | + } | ||
| 43 | + }] | ||
| 36 | ]; | 44 | ]; |
| 37 | } | 45 | } |
| 38 | 46 | ||
| @@ -41,9 +49,8 @@ class AttrRequest extends FormRequest | @@ -41,9 +49,8 @@ class AttrRequest extends FormRequest | ||
| 41 | return [ | 49 | return [ |
| 42 | 'title.required' => '请输入参数名称', | 50 | 'title.required' => '请输入参数名称', |
| 43 | 'title.max' => '参数名称不能超过50个字符', | 51 | 'title.max' => '参数名称不能超过50个字符', |
| 44 | - 'remark.max' => '备注不能超过200个字符', | ||
| 45 | - 'values.required' => '请添加参数值', | ||
| 46 | - 'values.array' => '参数值格式异常', | 52 | + 'attrs.required' => '请添加属性参数', |
| 53 | + 'attrs.array' => '属性参数格式异常', | ||
| 47 | ]; | 54 | ]; |
| 48 | } | 55 | } |
| 49 | 56 |
| @@ -2,6 +2,7 @@ | @@ -2,6 +2,7 @@ | ||
| 2 | 2 | ||
| 3 | namespace App\Models\Product; | 3 | namespace App\Models\Product; |
| 4 | 4 | ||
| 5 | +use App\Helper\Arr; | ||
| 5 | use App\Models\Base; | 6 | use App\Models\Base; |
| 6 | use Illuminate\Database\Eloquent\SoftDeletes; | 7 | use Illuminate\Database\Eloquent\SoftDeletes; |
| 7 | 8 | ||
| @@ -9,12 +10,24 @@ class Attr extends Base | @@ -9,12 +10,24 @@ class Attr extends Base | ||
| 9 | { | 10 | { |
| 10 | use SoftDeletes; | 11 | use SoftDeletes; |
| 11 | 12 | ||
| 13 | + protected $appends = ['attr_num']; | ||
| 14 | + | ||
| 12 | //设置关联表名 | 15 | //设置关联表名 |
| 13 | protected $table = 'gl_product_attr'; | 16 | protected $table = 'gl_product_attr'; |
| 14 | 17 | ||
| 15 | - public function values() | 18 | + public function setAttrsAttribute($value) |
| 19 | + { | ||
| 20 | + $this->attributes['attrs'] = Arr::a2s($value); | ||
| 21 | + } | ||
| 22 | + | ||
| 23 | + public function getAttrsAttribute($value) | ||
| 24 | + { | ||
| 25 | + return Arr::s2a($value); | ||
| 26 | + } | ||
| 27 | + | ||
| 28 | + public function getAttrNumAttribute() | ||
| 16 | { | 29 | { |
| 17 | - return $this->hasMany(AttrValue::class, 'attr_id', 'id')->orderBy('id'); | 30 | + return count($this->attrs); |
| 18 | } | 31 | } |
| 19 | 32 | ||
| 20 | } | 33 | } |
app/Models/Product/AttrValue.php
已删除
100644 → 0
app/Models/Product/KeywordRelated.php
0 → 100644
| 1 | +<?php | ||
| 2 | + | ||
| 3 | +namespace App\Models\Product; | ||
| 4 | + | ||
| 5 | + | ||
| 6 | +use App\Helper\Arr; | ||
| 7 | +use App\Models\Base; | ||
| 8 | + | ||
| 9 | +class KeywordRelated extends Base | ||
| 10 | +{ | ||
| 11 | + | ||
| 12 | + //设置关联表名 | ||
| 13 | + protected $table = 'gl_product_keyword_related'; | ||
| 14 | + | ||
| 15 | + const CREATED_AT = null; | ||
| 16 | + const UPDATED_AT = null; | ||
| 17 | + | ||
| 18 | + | ||
| 19 | + /** | ||
| 20 | + * 关联产品关键词 | ||
| 21 | + * @param $product_id | ||
| 22 | + * @param $keyword_ids | ||
| 23 | + * @author zbj | ||
| 24 | + * @date 2023/5/4 | ||
| 25 | + */ | ||
| 26 | + public static function saveRelated($product_id, $keyword_ids) | ||
| 27 | + { | ||
| 28 | + if(!is_array($keyword_ids)){ | ||
| 29 | + $keyword_ids = array_filter(Arr::splitFilterToArray($keyword_ids), 'intval'); | ||
| 30 | + } | ||
| 31 | + //先删除 | ||
| 32 | + self::where('product_id', $product_id)->delete(); | ||
| 33 | + | ||
| 34 | + //批量保存 | ||
| 35 | + $data = []; | ||
| 36 | + foreach ($keyword_ids as $keyword_id){ | ||
| 37 | + $data[] = [ | ||
| 38 | + 'product_id' => $product_id, | ||
| 39 | + 'keyword_id' => $keyword_id | ||
| 40 | + ]; | ||
| 41 | + } | ||
| 42 | + self::insert($data); | ||
| 43 | + } | ||
| 44 | +} |
-
请 注册 或 登录 后发表评论